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

Subversion Repositories pci

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

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 63 mihad
// Revision 1.9  2002/10/08 17:17:02  mihad
43
// Added BIST signals for RAMs.
44
//
45 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
46
// Added completion expiration test for WB Slave unit. Changed expiration signalling
47
//
48 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
49
// Oops, never before noticed that OC header is missing
50 52 mihad
//
51 57 mihad
//
52 52 mihad
 
53 15 mihad
`include "pci_constants.v"
54
`include "bus_commands.v"
55
`include "pci_testbench_defines.v"
56
`include "timescale.v"
57
 
58 51 mihad
`ifdef HOST
59
    `ifdef NO_CNF_IMAGE
60
    `else
61
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
62
    `endif
63
`else
64
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
65
`endif
66
 
67 15 mihad
module SYSTEM ;
68
 
69
`include "pci_blue_constants.vh"
70
`include "pci_blue_options.vh"
71
 
72
integer tests_successfull ;
73
integer tests_failed ;
74
integer tb_log_file ;
75
reg [799:0] test_name ;
76
 
77
reg pci_clock ;
78
reg wb_clock ;
79
reg reset ;
80
 
81
wire [4:0] arb_grant_out ;
82
 
83
wire [31:0] AD ;
84
wire [3:0]  CBE ;
85
pullup(INTA) ;
86
pullup(MAS0_REQ) ;
87
pullup(MAS1_REQ) ;
88
pullup(MAS2_REQ) ;
89
pullup(MAS3_REQ) ;
90
 
91
wire MAS0_GNT = ~arb_grant_out[0];
92
wire MAS1_GNT = ~arb_grant_out[1] ;
93
wire MAS2_GNT = ~arb_grant_out[2] ;
94
wire MAS3_GNT = ~arb_grant_out[3] ;
95
 
96
pullup(FRAME) ;
97
pullup(IRDY) ;
98 45 mihad
 
99
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
100
 
101 15 mihad
pullup(DEVSEL) ;
102
pullup(TRDY) ;
103
pullup(STOP) ;
104
wire   PAR ;
105
pullup(PERR) ;
106
pullup(SERR) ;
107
wire [3:0] MAS1_IDSEL ;
108
 
109
pullup lockpu ( LOCK ) ;
110
 
111
wire        RST_O ;
112
wire        INT_O ;
113
reg         INT_I ;
114
wire [31:0] ADR_I ;
115
wire [31:0] SDAT_I ;
116
wire [31:0] SDAT_O ;
117
wire [3:0]  SEL_I ;
118
wire        CYC_I ;
119
wire        STB_I ;
120
wire        WE_I ;
121
wire        CAB_I ;
122
wire        ACK_O ;
123
wire        RTY_O ;
124
wire        ERR_O ;
125
 
126
wire [31:0] ADR_O ;
127
wire [31:0] MDAT_I ;
128
wire [31:0] MDAT_O ;
129
wire [3:0]  SEL_O ;
130
wire        CYC_O ;
131
wire        STB_O ;
132
wire        WE_O ;
133
wire        CAB_O ;
134
wire        ACK_I ;
135
wire        RTY_I ;
136
wire        ERR_I ;
137
 
138 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
139
 
140
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
141
 
142 15 mihad
wire        reset_wb ; // reset to Wb devices
143
 
144 62 mihad
`ifdef PCI_BIST
145
wire SO ;
146
reg  SI ;
147 63 mihad
wire trst = reset_wb ;
148 62 mihad
reg  shift_DR ;
149
reg  capture_DR ;
150
reg  extest ;
151
reg  tck ;
152
`endif
153
 
154 15 mihad
`ifdef GUEST
155
    wire    RST = ~reset ;
156
    assign  reset_wb = RST_O ;
157
`else
158
    pullup(RST) ;
159
    assign  reset_wb = reset ;
160
`endif
161
 
162
`define PCI_BRIDGE_INSTANCE bridge32_top
163
 
164
TOP `PCI_BRIDGE_INSTANCE
165
(
166
    .CLK    ( pci_clock),
167
    .AD     ( AD ),
168
    .CBE    ( CBE ),
169
    .RST    ( RST ),
170
    .INTA   ( INTA ),
171
    .REQ    ( MAS0_REQ ),
172
    .GNT    ( MAS0_GNT ),
173
    .FRAME  ( FRAME ),
174
    .IRDY   ( IRDY ),
175
    .IDSEL  ( TAR0_IDSEL),
176
    .DEVSEL ( DEVSEL ),
177
    .TRDY   ( TRDY ),
178
    .STOP   ( STOP ),
179
    .PAR    ( PAR ),
180
    .PERR   ( PERR ),
181
    .SERR   ( SERR ),
182
 
183
    .CLK_I  ( wb_clock ),
184
    .RST_I  ( reset ),
185
    .RST_O  ( RST_O ),
186
    .INT_I  ( INT_I ),
187
    .INT_O  ( INT_O ),
188
 
189
    // WISHBONE slave interface
190
    .ADR_I  ( ADR_I ),
191
    .SDAT_I ( SDAT_I ),
192
    .SDAT_O ( SDAT_O ),
193
    .SEL_I  ( SEL_I ),
194
    .CYC_I  ( CYC_I ),
195
    .STB_I  ( STB_I ),
196
    .WE_I   ( WE_I ),
197
    .CAB_I  ( CAB_I),
198
    .ACK_O  ( ACK_O ),
199
    .RTY_O  ( RTY_O ),
200
    .ERR_O  ( ERR_O ),
201
 
202
    // WISHBONE master interface
203
    .ADR_O  ( ADR_O ),
204
    .MDAT_I ( MDAT_I ),
205
    .MDAT_O ( MDAT_O ),
206
    .SEL_O  ( SEL_O ),
207
    .CYC_O  ( CYC_O ),
208
    .STB_O  ( STB_O ),
209
    .WE_O   ( WE_O ),
210
    .CAB_O  ( CAB_O ),
211
    .ACK_I  ( ACK_I ),
212
    .RTY_I  ( RTY_I ),
213
    .ERR_I  ( ERR_I )
214 62 mihad
 
215
`ifdef PCI_BIST
216
    ,
217 63 mihad
    .trst       (trst),
218 62 mihad
    .SO         (SO),
219
    .SI         (SI),
220
    .shift_DR   (shift_DR),
221
    .capture_DR (capture_DR),
222
    .extest     (extest),
223
    .tck        (tck)
224
`endif
225 15 mihad
) ;
226
 
227
WB_MASTER_BEHAVIORAL wishbone_master
228
(
229
    .CLK_I(wb_clock),
230
    .RST_I(reset_wb),
231
    .TAG_I(4'b0000),
232
    .TAG_O(),
233
    .ACK_I(ACK_O),
234
    .ADR_O(ADR_I),
235
    .CYC_O(CYC_I),
236
    .DAT_I(SDAT_O),
237
    .DAT_O(SDAT_I),
238
    .ERR_I(ERR_O),
239
    .RTY_I(RTY_O),
240
    .SEL_O(SEL_I),
241
    .STB_O(STB_I),
242
    .WE_O (WE_I),
243
    .CAB_O(CAB_I)
244
);
245
 
246
WB_SLAVE_BEHAVIORAL wishbone_slave
247
(
248
    .CLK_I              (wb_clock),
249
    .RST_I              (reset_wb),
250
    .ACK_O              (ACK_I),
251
    .ADR_I              (ADR_O),
252
    .CYC_I              (CYC_O),
253
    .DAT_O              (MDAT_I),
254
    .DAT_I              (MDAT_O),
255
    .ERR_O              (ERR_I),
256
    .RTY_O              (RTY_I),
257
    .SEL_I              (SEL_O),
258
    .STB_I              (STB_O),
259
    .WE_I               (WE_O),
260
    .CAB_I              (CAB_O)
261
);
262
 
263
integer wbu_mon_log_file_desc ;
264
integer pciu_mon_log_file_desc ;
265
WB_BUS_MON wbu_wb_mon(
266
                    .CLK_I(wb_clock),
267
                    .RST_I(reset_wb),
268
                    .ACK_I(ACK_O),
269
                    .ADDR_O(ADR_I),
270
                    .CYC_O(CYC_I),
271
                    .DAT_I(SDAT_O),
272
                    .DAT_O(SDAT_I),
273
                    .ERR_I(ERR_O),
274
                    .RTY_I(RTY_O),
275
                    .SEL_O(SEL_I),
276
                    .STB_O(STB_I),
277
                    .WE_O (WE_I),
278
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
279
                    .TAG_O(),
280
                    .CAB_O(CAB_I),
281
                    .log_file_desc ( wbu_mon_log_file_desc )
282
                  ) ;
283
 
284
WB_BUS_MON pciu_wb_mon(
285
                    .CLK_I(wb_clock),
286
                    .RST_I(reset_wb),
287
                    .ACK_I(ACK_I),
288
                    .ADDR_O(ADR_O),
289
                    .CYC_O(CYC_O),
290
                    .DAT_I(MDAT_I),
291
                    .DAT_O(MDAT_O),
292
                    .ERR_I(ERR_I),
293
                    .RTY_I(RTY_I),
294
                    .SEL_O(SEL_O),
295
                    .STB_O(STB_O),
296
                    .WE_O (WE_O),
297
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
298
                    .TAG_O(),
299
                    .CAB_O(CAB_O),
300
                    .log_file_desc( pciu_mon_log_file_desc )
301
                  ) ;
302
 
303
// some aditional signals are needed here because of the arbiter
304
reg [3:0] pci_ext_req_prev ;
305
always@(posedge pci_clock)
306
begin
307
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
308
end
309
reg pci_frame_prev ;
310
always@(posedge pci_clock)
311
begin
312
    pci_frame_prev <= FRAME ;
313
end
314
reg pci_irdy_prev ;
315
always@(posedge pci_clock)
316
begin
317
    pci_irdy_prev <= IRDY ;
318
end
319
 
320
pci_blue_arbiter pci_arbiter
321
(
322
  .pci_int_req_direct(1'b0),
323
  .pci_ext_req_prev(pci_ext_req_prev),
324
  .pci_int_gnt_direct_out(arb_grant_out[4]),
325
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
326
  .pci_frame_prev(~pci_frame_prev),
327
  .pci_irdy_prev(~pci_irdy_prev),
328
  .pci_irdy_now(~IRDY),
329
  .arbitration_enable(1'b1),
330
  .pci_clk(pci_clock),
331
  .pci_reset_comb(~RST)
332
);
333
 
334
reg [31:0] target_message ;
335
 
336
// define output enable signals for monitor inputs
337
// real output enable signals
338
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
339
`ifdef ACTIVE_LOW_OE
340
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
341
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
342
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
343
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
344
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
345
                        !devsel_t_s_oe,
346
                        !ad_oe,
347
                        !cbe_oe,
348
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
349
                        ;
350
`else
351
`ifdef ACTIVE_HIGH_OE
352
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
353
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
354
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
355
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
356
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
357
                        devsel_t_s_oe,
358
                        ad_oe,
359
                        cbe_oe,
360
                        `PCI_BRIDGE_INSTANCE.PERR_en}
361
                        ;
362
`endif
363
`endif
364
/*wire [5:0] oe_sigs_0 = {1'b0,
365
                        1'b0,
366
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
367
                        pci_target32.ad_enable,
368
                        1'b0,
369
                        pci_target32.err_enable | pci_target32.r_err_enable
370
                       } ;
371
*/
372
 
373
wire [5:0] oe_sigs_2 ;
374
wire [5:0] oe_sigs_1 ;
375
 
376
// signals which are used by test modules to know what to do
377
triand  test_accepted_l_int, error_event_int;
378
pullup  (test_accepted_l_int), (error_event_int);
379
 
380
wire    pci_reset_comb  = ~RST;
381
wire    pci_ext_clk     = pci_clock;
382
 
383
integer pci_mon_log_file_desc ;
384
pci_bus_monitor monitor32
385
(
386
    .pci_ext_ad                 (AD),
387
    .pci_ext_cbe_l              (CBE),
388
    .pci_ext_par                (PAR),
389
    .pci_ext_frame_l            (FRAME),
390
    .pci_ext_irdy_l             (IRDY),
391
    .pci_ext_devsel_l           (DEVSEL),
392
    .pci_ext_trdy_l             (TRDY),
393
    .pci_ext_stop_l             (STOP),
394
    .pci_ext_perr_l             (PERR),
395
    .pci_ext_serr_l             (SERR),
396
    .pci_real_req_l             (MAS0_REQ),
397
    .pci_real_gnt_l             (MAS0_GNT),
398
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
399
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
400
    .test_error_event           (error_event_int),
401
    .test_observe_r_oe_sigs     (r_oe_sigs),
402
    .test_observe_0_oe_sigs     (6'h00),
403
    .test_observe_1_oe_sigs     (oe_sigs_1),
404
    .test_observe_2_oe_sigs     (oe_sigs_2),
405
    .test_observe_3_oe_sigs     (6'h00),
406
    .pci_ext_reset_l            (RST),
407
    .pci_ext_clk                (pci_clock),
408
    .log_file_desc              (pci_mon_log_file_desc)
409
) ;
410
 
411
reg [2:0]  test_master_number ;
412
reg [31:0] test_address ;
413
reg [3:0]  test_command ;
414
reg [31:0] test_data ;
415
reg [3:0]  test_byte_enables_l ;
416
reg [9:0]  test_size ;
417
reg        test_make_addr_par_error ;
418
reg        test_make_data_par_error ;
419
reg [3:0]  test_master_initial_wait_states ;
420
reg [3:0]  test_master_subsequent_wait_states ;
421
reg [3:0]  test_target_initial_wait_states ;
422
reg [3:0]  test_target_subsequent_wait_states ;
423
reg [1:0]  test_target_devsel_speed ;
424
reg        test_fast_back_to_back ;
425
reg [2:0]  test_target_termination ;
426
reg        test_expect_master_abort ;
427
reg        test_start ;
428
reg [25:0] test_target_response ;
429
 
430
wire [31:0] master2_received_data ;
431
wire        master2_received_data_valid ;
432
reg         master2_check_received_data ;
433
pci_behaviorial_device pci_behaviorial_device2
434
(
435
    .pci_ext_ad(AD),
436
    .pci_ext_cbe_l(CBE),
437
    .pci_ext_par(PAR),
438
    .pci_ext_frame_l(FRAME),
439
    .pci_ext_irdy_l(IRDY),
440
    .pci_ext_devsel_l(DEVSEL),
441
    .pci_ext_trdy_l(TRDY),
442
    .pci_ext_stop_l(STOP),
443
    .pci_ext_perr_l(PERR),
444
    .pci_ext_serr_l(SERR),
445
    .pci_ext_idsel(TAR2_IDSEL),
446
    .pci_ext_inta_l(INTA),
447
    .pci_ext_req_l(MAS2_REQ),
448
    .pci_ext_gnt_l(MAS2_GNT),
449
    .pci_ext_reset_l(RST),
450
    .pci_ext_clk(pci_clock),
451
 
452
// Signals used by the test bench instead of using "." notation
453
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
454
    .test_master_number                 (test_master_number[2:0]),
455
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
456
    .test_command                       (test_command[3:0]),
457
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
458
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
459
    .test_size                          (test_size),
460
    .test_make_addr_par_error           (test_make_addr_par_error),
461
    .test_make_data_par_error           (test_make_data_par_error),
462
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
463
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
464
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
465
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
466
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
467
    .test_fast_back_to_back             (test_fast_back_to_back),
468
    .test_target_termination            (test_target_termination[2:0]),
469
    .test_expect_master_abort           (test_expect_master_abort),
470
    .test_start                         (test_start),
471
    .test_accepted_l                    (test_accepted_l_int),
472
    .test_error_event                   (error_event_int),
473
    .test_device_id                     (`Test_Master_2),
474
    .test_target_response               (test_target_response),
475
 
476
    .master_received_data               (master2_received_data),
477
    .master_received_data_valid         (master2_received_data_valid),
478
    .master_check_received_data         (master2_check_received_data)
479
);
480
 
481
wire [31:0] master1_received_data ;
482
wire        master1_received_data_valid ;
483
reg         master1_check_received_data ;
484
pci_behaviorial_device pci_behaviorial_device1
485
(
486
    .pci_ext_ad(AD),
487
    .pci_ext_cbe_l(CBE),
488
    .pci_ext_par(PAR),
489
    .pci_ext_frame_l(FRAME),
490
    .pci_ext_irdy_l(IRDY),
491
    .pci_ext_devsel_l(DEVSEL),
492
    .pci_ext_trdy_l(TRDY),
493
    .pci_ext_stop_l(STOP),
494
    .pci_ext_perr_l(PERR),
495
    .pci_ext_serr_l(SERR),
496
    .pci_ext_idsel(TAR1_IDSEL),
497
    .pci_ext_inta_l(INTA),
498
    .pci_ext_req_l(MAS1_REQ),
499
    .pci_ext_gnt_l(MAS1_GNT),
500
    .pci_ext_reset_l(RST),
501
    .pci_ext_clk(pci_clock),
502
 
503
// Signals used by the test bench instead of using "." notation
504
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
505
    .test_master_number                 (test_master_number[2:0]),
506
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
507
    .test_command                       (test_command[3:0]),
508
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
509
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
510
    .test_size                          (test_size),
511
    .test_make_addr_par_error           (test_make_addr_par_error),
512
    .test_make_data_par_error           (test_make_data_par_error),
513
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
514
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
515
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
516
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
517
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
518
    .test_fast_back_to_back             (test_fast_back_to_back),
519
    .test_target_termination            (test_target_termination[2:0]),
520
    .test_expect_master_abort           (test_expect_master_abort),
521
    .test_start                         (test_start),
522
    .test_accepted_l                    (test_accepted_l_int),
523
    .test_error_event                   (error_event_int),
524
    .test_device_id                     (`Test_Master_1),
525
    .test_target_response               (test_target_response),
526
 
527
    .master_received_data               (master1_received_data),
528
    .master_received_data_valid         (master1_received_data_valid),
529
    .master_check_received_data         (master1_check_received_data)
530
);
531
 
532
pci_unsupported_commands_master ipci_unsupported_commands_master
533
(
534
    .CLK    ( pci_clock),
535
    .AD     ( AD ),
536
    .CBE    ( CBE ),
537
    .RST    ( RST ),
538
    .REQ    ( MAS3_REQ ),
539
    .GNT    ( MAS3_GNT ),
540
    .FRAME  ( FRAME ),
541
    .IRDY   ( IRDY ),
542
    .DEVSEL ( DEVSEL ),
543
    .TRDY   ( TRDY ),
544
    .STOP   ( STOP ),
545
    .PAR    ( PAR )
546
) ;
547
 
548 45 mihad
`ifdef HOST
549
 
550
reg     [1:0]   conf_cyc_type1_target_response ;
551
reg     [31:0]  conf_cyc_type1_target_data ;
552
reg     [7:0]   conf_cyc_type1_target_bus_num ;
553
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
554
 
555
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
556
(
557
    .CLK              ( pci_clock),
558
    .AD               ( AD ),
559
    .CBE              ( CBE ),
560
    .RST              ( RST ),
561
    .FRAME            ( FRAME ),
562
    .IRDY             ( IRDY ),
563
    .DEVSEL           ( DEVSEL ),
564
    .TRDY             ( TRDY ),
565
    .STOP             ( STOP ),
566
    .PAR              ( PAR ),
567
 
568
    .response         ( conf_cyc_type1_target_response ),
569
    .data_out         ( conf_cyc_type1_target_data ),
570
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
571
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
572
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
573
    .bus_number       ( conf_cyc_type1_target_bus_num )
574
);
575
`endif
576
 
577 15 mihad
// pci clock generator
578 63 mihad
`ifdef PCI_CLOCK_FOLLOWS_WB_CLOCK
579
    always@(posedge wb_clock)
580
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b1 ;
581
 
582
    always@(negedge wb_clock)
583
        #`PCI_CLOCK_FOLLOWS_WB_CLOCK pci_clock = 1'b0 ;
584 15 mihad
`else
585 63 mihad
    always
586
    `ifdef PCI33
587
        #15 pci_clock = ~pci_clock ;
588
    `else
589
    `ifdef PCI66
590
        #7.5 pci_clock = ~pci_clock ;
591
    `endif
592
    `endif
593 15 mihad
`endif
594
 
595
// WISHBONE clock generation
596 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
597
always@(posedge pci_clock)
598
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b1 ;
599 15 mihad
 
600 63 mihad
always@(negedge pci_clock)
601
    #`WB_CLOCK_FOLLOWS_PCI_CLOCK wb_clock = 1'b0 ;
602
 
603
`else
604
    always
605
        #(((1/`WB_FREQ)/2)) wb_clock = !wb_clock ;
606
`endif
607
 
608 15 mihad
// Make test name visible when the Master starts working on it
609
reg     [79:0] present_test_name;
610
reg     [79:0] next_test_name;
611
wire    test_accepted = ~test_accepted_l_int;
612
always @(posedge test_accepted)
613
begin
614
    present_test_name <= next_test_name;
615
end
616
 
617
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
618
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
619
 
620
// basic configuration parameters for both behavioral devices
621
parameter [2:0] Master_ID_A                           = `Test_Master_1;
622
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
623
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
624
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
625
 
626
parameter [2:0] Master_ID_B                           = `Test_Master_2;
627
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
628
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
629
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
630
 
631
// basic configuration parameters for REAL device
632
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
633
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
634
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
635
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
636
 
637
// reg  [2:0]   ack_err_rty_termination ;
638
// reg          wait_cycles ;
639
// reg  [7:0]   num_of_retries ;
640
 
641
//reg [19:0] pci_config_base ;
642
reg [7:0] system_burst_size ;
643
reg [7:0] bridge_latency ;
644
integer   target_mem_image ;
645
integer   target_io_image ;
646
 
647
initial
648
begin
649 62 mihad
 
650
`ifdef PCI_BIST
651
    SI          = 0 ;
652
    shift_DR    = 0 ;
653
    capture_DR  = 0 ;
654
    extest      = 0 ;
655
    tck         = 0 ;
656
`endif
657 15 mihad
    next_test_name[79:0] <= "Nowhere___";
658
    reset = 1'b1 ;
659
    pci_clock = 1'b0 ;
660
    wb_clock  = 1'b1 ;
661
    target_message = 32'h0000_0000 ;
662
//  num_of_retries = 8'h01 ;
663
//  ack_err_rty_termination = 3'b100 ;
664
//  wait_cycles = 1'b0 ;
665
 
666
    // system paameters
667
    system_burst_size = 16 ;
668
    bridge_latency    = 8 ;
669
 
670
    // set initial values for controling the behavioral PCI master
671
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
672
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
673
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
674
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
675
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
676
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
677
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
678
 
679
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
680
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
681
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
682
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
683
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
684
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
685
 
686
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
687
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
688
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
689
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
690
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
691
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
692
 
693
    test_master_number = `Test_Master_2 ;
694
    test_address = 32'h0000_0000 ;
695
    test_command = `BC_RESERVED0 ;
696
    test_data = 32'h0000_0000 ;
697
    test_byte_enables_l   = 4'hF ;
698
    test_size = 0 ;
699
    test_make_addr_par_error = 0 ;
700
    test_make_data_par_error = 0;
701
    test_master_initial_wait_states = 0 ;
702
    test_master_subsequent_wait_states = 0 ;
703
    test_target_initial_wait_states = 0 ;
704
    test_target_subsequent_wait_states = 0;
705
    test_target_devsel_speed = `Test_Devsel_Fast ;
706
    test_fast_back_to_back = 0 ;
707
    test_target_termination = `Test_Target_Normal_Completion ;
708
    test_expect_master_abort = 0 ;
709
    test_start = 0 ;
710
    test_target_response = 0 ;
711
 
712
    master1_check_received_data = 0 ;
713
    master2_check_received_data = 0 ;
714
 
715 45 mihad
    `ifdef HOST
716
        conf_cyc_type1_target_response = 0 ;
717
        conf_cyc_type1_target_data = 0 ;
718
        conf_cyc_type1_target_bus_num = 255 ;
719
    `endif
720 15 mihad
 
721
    // fill memory and IO data with random values
722
    fill_memory ;
723
 
724
    INT_I = 0 ;
725
 
726
    // extract from constants which target image can be used as IO and which as memory
727
    `ifdef HOST
728
        target_mem_image = 1 ;
729
        target_io_image  = 1 ;
730
    `else
731
        target_mem_image = -1 ;
732
        target_io_image     = -1 ;
733
        if ( `PCI_BA1_MEM_IO === 0 )
734
            target_mem_image = 1 ;
735
        else
736
            target_io_image = 1 ;
737
 
738
        if ( target_mem_image === -1 )
739
        begin
740
            `ifdef PCI_IMAGE2
741
                if ( `PCI_BA2_MEM_IO === 0 )
742
                    target_mem_image = 2 ;
743
                else if ( target_io_image === -1 )
744
                    target_io_image = 2 ;
745
            `endif
746
        end
747
 
748
        if ( target_mem_image === -1 )
749
        begin
750
            `ifdef PCI_IMAGE3
751
                if ( `PCI_BA3_MEM_IO === 0 )
752
                    target_mem_image = 3 ;
753
                else if ( target_io_image === -1 )
754
                    target_io_image = 3 ;
755
            `endif
756
        end
757
 
758
        if ( target_mem_image === -1 )
759
        begin
760
            `ifdef PCI_IMAGE4
761
                if ( `PCI_BA4_MEM_IO === 0 )
762
                    target_mem_image = 4 ;
763
                else if ( target_io_image === -1 )
764
                    target_io_image = 4 ;
765
            `endif
766
        end
767
 
768
        if ( target_mem_image === -1 )
769
        begin
770
            `ifdef PCI_IMAGE5
771
                if ( `PCI_BA5_MEM_IO === 0 )
772
                    target_mem_image = 5 ;
773
                else if ( target_io_image === -1 )
774
                    target_io_image = 5 ;
775
            `endif
776
        end
777
    `endif
778
 
779
    tests_successfull = 0 ;
780
    tests_failed = 0 ;
781
 
782
    tb_log_file = $fopen("../log/pci_tb.log") ;
783
 
784
    if ( tb_log_file < 2 )
785
    begin
786
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
787
        $finish ;
788
    end
789
 
790
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
791
    $fdisplay( tb_log_file,"" ) ;
792
 
793
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
794
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
795
 
796
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
797
    begin
798
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
799
        $finish ;
800
    end
801
 
802
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
803
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
804
 
805
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
806
    if ( pci_mon_log_file_desc < 2 )
807
    begin
808
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
809
        $finish ;
810
    end
811
 
812
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
813
 
814
    run_tests ;
815
end
816
 
817
task fill_memory ;
818
    integer temp_index ;
819
begin
820
    // fill write memories with random data
821
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
822
    begin
823
        wmem_data[temp_index[9:0]] = $random ;
824 26 mihad
        # 1;
825 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
826 26 mihad
        # 1;
827 15 mihad
    end
828
    // fill WB slave behavioral MEMORY
829
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
830
    begin
831
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
832
        # 1;
833
    end
834
end
835
endtask // fill_memory
836
 
837
reg [2:0] tb_init_waits ;
838
reg [2:0] tb_subseq_waits ;
839
reg [2:0] tb_target_decode_speed ;
840
 
841
task run_tests ;
842
begin
843
    // first - reset logic
844
    do_reset ;
845 62 mihad
 
846
    // if BIST is implemented, give it a go
847
`ifdef PCI_BIST
848
    run_bist_test ;
849
`endif
850 45 mihad
    test_initial_conf_values ;
851
 
852 15 mihad
    next_test_name[79:0] <= "Initing...";
853
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
854
 
855
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
856
    begin
857
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
858
        begin
859
 
860
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
861
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
862
 
863
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
864
            begin
865
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
866
 
867
                `ifdef HOST
868
                    configure_bridge_target ;
869
                    find_pci_devices ;
870 45 mihad
                    test_configuration_cycle_target_abort ;
871
                    test_configuration_cycle_type1_generation ;
872 15 mihad
                `endif
873
 
874
                @(posedge pci_clock) ;
875
                configure_target(1) ;
876
                @(posedge pci_clock) ;
877
                configure_target(2) ;
878
 
879
                `ifdef GUEST
880
                    configure_bridge_target ;
881
                `endif
882
 
883
               next_test_name[79:0] <= "WB_SLAVE..";
884
 
885
                $display("Testing WISHBONE slave images' features!") ;
886
                test_wb_image(1) ;
887
 
888
                `ifdef WB_IMAGE2
889
                    test_wb_image(2) ;
890
                `else
891
                    $display(" WB IMAGE 2 not implemented! ") ;
892
                `endif
893
 
894
                `ifdef WB_IMAGE3
895
                    test_wb_image(3) ;
896
                `else
897
                    $display(" WB IMAGE 3 not implemented! ") ;
898
                `endif
899
 
900
                `ifdef WB_IMAGE4
901
                    test_wb_image(4) ;
902
                `else
903
                    $display(" WB IMAGE 4 not implemented! ") ;
904
                `endif
905
 
906
                `ifdef WB_IMAGE5
907
                    test_wb_image(5) ;
908
                `else
909
                    $display(" WB IMAGE 5 not implemented! ") ;
910
                `endif
911
 
912
                wb_slave_errors ;
913
                wb_to_pci_error_handling ;
914
 
915
                parity_checking ;
916
 
917
                wb_to_pci_transactions ;
918
 
919
                `ifdef HOST
920
                iack_cycle ;
921
                `endif
922
 
923
            end
924 57 mihad
 
925 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
926
        `else
927 57 mihad
            master_completion_expiration ;
928 63 mihad
        `endif
929 57 mihad
 
930 15 mihad
            $display(" ") ;
931
            $display("WB slave images' tests finished!") ;
932
 
933
            $display("########################################################################") ;
934
            $display("########################################################################") ;
935
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
936
            $display("########################################################################") ;
937
            $display("########################################################################") ;
938
 
939
            $display("Testing PCI target images' features!") ;
940
            configure_bridge_target_base_addresses ;
941
 
942 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
943
                test_conf_cycle_type1_reference ;
944
            `endif
945
 
946 15 mihad
            `ifdef HOST
947
             `ifdef NO_CNF_IMAGE
948
              `ifdef PCI_IMAGE0
949
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
950
            test_pci_image(0) ;
951
              `else
952
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
953
              `endif
954
             `else
955
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
956
             `endif
957
            `endif
958
 
959
            $display("PCI image 1 is ALWAYS implemented!") ;
960
            test_pci_image(1) ;
961
 
962
            `ifdef PCI_IMAGE2
963
            $display("PCI image 2 is implemented!") ;
964
            test_pci_image(2) ;
965
            `else
966
            $display("PCI image 2 is NOT implemented!") ;
967
            `endif
968
 
969
            `ifdef PCI_IMAGE3
970
            $display("PCI image 3 is implemented!") ;
971
            test_pci_image(3) ;
972
            `else
973
            $display("PCI image 3 is NOT implemented!") ;
974
            `endif
975
 
976
            `ifdef PCI_IMAGE4
977
            $display("PCI image 4 is implemented!") ;
978
            test_pci_image(4) ;
979
            `else
980
            $display("PCI image 4 is NOT implemented!") ;
981
            `endif
982
 
983
            `ifdef PCI_IMAGE5
984
            $display("PCI image 5 is implemented!") ;
985
            test_pci_image(5) ;
986
            `else
987
            $display("PCI image 5 is NOT implemented!") ;
988
            `endif
989
 
990
            test_wb_error_rd ;
991
 
992
            target_fast_back_to_back ;
993
            target_disconnects ;
994
 
995
            if ( target_io_image !== -1 )
996
                test_target_abort( target_io_image ) ;
997
            $display(" ") ;
998
            $display("PCI target images' tests finished!") ;
999
 
1000
            transaction_ordering ;
1001 33 mihad
 
1002 63 mihad
        `ifdef DISABLE_COMPLETION_EXPIRED_TESTS
1003
        `else
1004 33 mihad
            target_completion_expiration ;
1005 63 mihad
        `endif
1006
 
1007 15 mihad
            $display(" ") ;
1008
            $display("PCI transaction ordering tests finished!") ;
1009
        end
1010
    end
1011
 
1012 63 mihad
    `ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
1013
        test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
1014
        test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 0 ;
1015
        test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 0 ;
1016
        test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = 0 ;
1017
 
1018
        `ifdef HOST
1019
            configure_bridge_target ;
1020
        `endif
1021
 
1022
        @(posedge pci_clock) ;
1023
        configure_target(1) ;
1024
        @(posedge pci_clock) ;
1025
        configure_target(2) ;
1026
 
1027
        `ifdef GUEST
1028
            configure_bridge_target ;
1029
        `endif
1030
 
1031
        target_special_corner_case_test ;
1032
    `endif
1033
 
1034 15 mihad
    test_summary ;
1035
 
1036
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
1037
    $stop ;
1038
end
1039
endtask // run_tests
1040
 
1041
task do_reset;
1042
begin
1043
    next_test_name[79:0] <= "Reset.....";
1044
 
1045
    reset = 1'b1 ;
1046
    #100 ;
1047
    `ifdef HOST
1048
        @(posedge wb_clock) ;
1049
    `else
1050
    `ifdef GUEST
1051
        @(posedge pci_clock) ;
1052
    `endif
1053
    `endif
1054
 
1055
    reset <= 1'b0 ;
1056
 
1057 45 mihad
    `ifdef HOST
1058
        @(posedge wb_clock) ;
1059
    `else
1060
    `ifdef GUEST
1061
        @(posedge pci_clock) ;
1062
    `endif
1063
    `endif
1064
 
1065 15 mihad
end
1066
endtask
1067
 
1068
/*############################################################################
1069
WB SLAVE UNIT tasks
1070
===================
1071
############################################################################*/
1072
 
1073
task configure_target ;
1074 45 mihad
    input [1:0]  beh_dev_num ;
1075 15 mihad
    reg   [31:0] base_address1 ;
1076
    reg   [31:0] base_address2 ;
1077
    reg   [2:0]  Master_ID;
1078
    reg   [31:0] Target_Config_Addr;
1079 45 mihad
    reg   [4:0]  device_num ;
1080 15 mihad
begin
1081 45 mihad
    if (beh_dev_num === 1)
1082 15 mihad
    begin
1083
        base_address1       = `BEH_TAR1_MEM_START ;
1084
        base_address2       = `BEH_TAR1_IO_START  ;
1085
        Master_ID           = `Test_Master_2 ;
1086
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1087 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1088 15 mihad
    end
1089
    else
1090 45 mihad
    if (beh_dev_num === 2)
1091 15 mihad
    begin
1092
        base_address1       = `BEH_TAR2_MEM_START ;
1093
        base_address2       = `BEH_TAR2_IO_START  ;
1094
        Master_ID           = `Test_Master_1 ;
1095
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1096 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1097 15 mihad
    end
1098
 
1099
    // write target's base addresses
1100
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1101
    // type 0 cycle, byte enables, base address
1102
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1103
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1104
 
1105
    // enable target's response and master
1106
    // enable parity errors, disable system error
1107
 
1108
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1109
 
1110
end
1111
endtask //configure_target
1112
 
1113
task test_wb_image ;
1114
    input [2:0]  image_num ;
1115
    reg   [11:0] ctrl_offset ;
1116
    reg   [11:0] ba_offset ;
1117
    reg   [11:0] am_offset ;
1118
    reg   [11:0] ta_offset ;
1119
    reg   [11:0] err_cs_offset ;
1120
    reg `WRITE_STIM_TYPE write_data ;
1121
    reg `READ_STIM_TYPE  read_data ;
1122
    reg `READ_RETURN_TYPE read_status ;
1123
 
1124
    reg `WRITE_RETURN_TYPE write_status ;
1125
    reg `WB_TRANSFER_FLAGS write_flags ;
1126
    reg [31:0] temp_val ;
1127
    reg        ok   ;
1128
    reg [11:0] pci_ctrl_offset ;
1129
    reg [31:0] image_base ;
1130
    reg [31:0] target_address ;
1131
    reg [31:0] translation_address ;
1132
    integer    i ;
1133
    integer    j ;
1134
begin:main
1135
    pci_ctrl_offset = 12'h4 ;
1136
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1137
    // image 0 can only be configuration image - start with 1
1138
    if (image_num === 1)
1139
    begin
1140
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1141
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1142
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1143
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1144
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1145
    end
1146
    else if (image_num === 2)
1147
    begin
1148
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1149
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1150
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1151
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1152
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1153
    end
1154
    else if (image_num === 3)
1155
    begin
1156
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1157
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1158
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1159
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1160
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1161
    end
1162
    else if (image_num === 4)
1163
    begin
1164
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1165
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1166
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1167
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1168
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1169
    end
1170
    else if (image_num === 5)
1171
    begin
1172
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1173
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1174
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1175
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1176
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1177
    end
1178
    else
1179
    begin
1180
        test_name   = "WB IMAGES' FEATURES TEST" ;
1181
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1182
        disable main ;
1183
    end
1184
 
1185
    target_address  = `BEH_TAR1_MEM_START ;
1186
    image_base      = 0 ;
1187
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1188
 
1189
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1190
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1191
    write_flags                      = 0 ;
1192
    write_flags`INIT_WAITS           = tb_init_waits ;
1193
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1194
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1195
 
1196
    test_name = "WB IMAGE CONFIGURATION" ;
1197
    // enable master & target operation
1198
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1199
    if ( ok !== 1 )
1200
    begin
1201
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1202
        test_fail("write to PCI Device Control register didn't succeede");
1203
        disable main ;
1204
    end
1205
 
1206
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1207
    if ( ok !== 1 )
1208
    begin
1209
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1210
        test_fail("write to WB Error Control and Status register didn't succeede");
1211
        disable main ;
1212
    end
1213
 
1214
    // prepare image control register
1215
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1216
    if ( ok !== 1 )
1217
    begin
1218
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1219
        test_fail("write to WB Image Control register didn't succeede");
1220
        disable main ;
1221
    end
1222
 
1223
    // prepare base address register
1224
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1225
    if ( ok !== 1 )
1226
    begin
1227
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1228
        test_fail("write to WB Base Address register didn't succeede");
1229
        disable main ;
1230
    end
1231
 
1232
    // write address mask register
1233
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1234
    if ( ok !== 1 )
1235
    begin
1236
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1237
        test_fail("write to WB Address Mask register didn't succeede");
1238
        disable main ;
1239
    end
1240
 
1241
    fork
1242
    begin
1243
        write_data`WRITE_ADDRESS = target_address ;
1244
        write_data`WRITE_DATA    = wmem_data[0] ;
1245
        write_data`WRITE_SEL     = 4'hF ;
1246
 
1247
        // handle retries from now on
1248
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1249
 
1250
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1251
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1252
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1253
        begin
1254
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1255
            test_fail("WB Slave state machine failed to post single memory write");
1256
            disable main ;
1257
        end
1258
 
1259
        // read written data back
1260
        read_data`READ_ADDRESS  = target_address ;
1261
        read_data`READ_SEL      = 4'hF ;
1262
        read_data`READ_TAG_STIM = 0 ;
1263
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1264
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1265
        begin
1266
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1267
            test_fail("PCI bridge didn't process the read as expected");
1268
            disable main ;
1269
        end
1270
 
1271
        if (read_status`READ_DATA !== wmem_data[0])
1272
        begin
1273
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1274
            test_fail("PCI bridge returned unexpected Read Data");
1275
        end
1276
        else
1277
            test_ok ;
1278
    end
1279
    begin
1280
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1281
        if ( ok !== 1 )
1282
        begin
1283
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1284
        end
1285
        else
1286
            test_ok ;
1287
 
1288
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1289
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1290
        if ( ok !== 1 )
1291
        begin
1292
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1293
        end
1294
    end
1295
    join
1296
 
1297
    // if address translation is implemented - try it out
1298
    translation_address = image_base ;
1299
    `ifdef ADDR_TRAN_IMPL
1300
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1301
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1302
    if ( ok !== 1 )
1303
    begin
1304
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1305
        test_fail("write to WB Image Translation Address Register failed") ;
1306
        disable main ;
1307
    end
1308
 
1309
    target_address  = `BEH_TAR2_MEM_START ;
1310
    image_base      = 0 ;
1311
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1312
 
1313
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1314
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1315
 
1316
    write_flags                      = 0 ;
1317
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1318
 
1319
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1320
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1321
    if ( ok !== 1 )
1322
    begin
1323
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1324
        test_fail("write to WB Image Base Address Register failed") ;
1325
        disable main ;
1326
    end
1327
 
1328
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1329
    // enable address translation
1330
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1331
    if ( ok !== 1 )
1332
    begin
1333
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1334
        test_fail("write to WB Image Control Register failed") ;
1335
        disable main ;
1336
    end
1337
 
1338
    `endif
1339
 
1340
    fork
1341
    begin
1342
        write_data`WRITE_ADDRESS = target_address + 4 ;
1343
        write_data`WRITE_DATA    = wmem_data[1] ;
1344
        write_data`WRITE_SEL     = 4'hF ;
1345
 
1346
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1347
 
1348
        `ifdef ADDR_TRAN_IMPL
1349
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1350
        `else
1351
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1352
        `endif
1353
 
1354
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1355
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1356
        begin
1357
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1358
            test_fail("WB Slave state machine failed to post single memory write") ;
1359
            disable main ;
1360
        end
1361
 
1362
        // read written data back
1363
        read_data`READ_ADDRESS  = target_address + 4 ;
1364
        read_data`READ_SEL      = 4'hF ;
1365
        read_data`READ_TAG_STIM = 0 ;
1366
 
1367
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1368
 
1369
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1370
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1371
        begin
1372
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1373
            test_fail("PCI bridge failed to process single delayed memory read") ;
1374
            disable main ;
1375
        end
1376
 
1377
        if (read_status`READ_DATA !== wmem_data[1])
1378
        begin
1379
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1380
            test_fail("PCI bridge returned unexpected Read Data");
1381
        end
1382
        else
1383
            test_ok ;
1384
    end
1385
    begin
1386
        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 ) ;
1387
        if ( ok !== 1 )
1388
        begin
1389
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1390
        end
1391
        else
1392
            test_ok ;
1393
 
1394
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1395
        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 ) ;
1396
        if ( ok !== 1 )
1397
        begin
1398
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1399
        end
1400
    end
1401
    join
1402
 
1403
    // 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
1404
    // prepare write data
1405
    for ( i = 0 ; i < 6 ; i = i + 1 )
1406
    begin
1407
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1408
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1409
        write_data`WRITE_SEL     = 4'hF ;
1410
        wishbone_master.blk_write_data[i] = write_data ;
1411
    end
1412
 
1413
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1414
    write_flags`WB_TRANSFER_CAB    = 1 ;
1415
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1416
 
1417
    fork
1418
    begin
1419
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1420
        wishbone_master.wb_block_write(write_flags, write_status) ;
1421
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1422
        begin
1423
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1424
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1425
            disable main ;
1426
        end
1427
    end
1428
    begin
1429
        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 ) ;
1430
        if ( ok !== 1 )
1431
        begin
1432
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1433
        end
1434
        else
1435
            test_ok ;
1436
    end
1437
    join
1438
 
1439
    // set burst size and latency timer
1440
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1441
 
1442
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1443
    write_flags`WB_TRANSFER_CAB    = 1 ;
1444
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1445
 
1446
    // prepare read data
1447
    for ( i = 0 ; i < 4 ; i = i + 1 )
1448
    begin
1449
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1450
        read_data`READ_SEL     = 4'hF ;
1451
        wishbone_master.blk_read_data_in[i] = read_data ;
1452
    end
1453
 
1454
    fork
1455
    begin
1456
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1457
        wishbone_master.wb_block_read(write_flags, read_status) ;
1458
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1459
        begin
1460
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1461
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1462
            disable main ;
1463
        end
1464
 
1465
        // check data read from target
1466
        for ( i = 0 ; i < 4 ; i = i + 1 )
1467
        begin
1468
            read_status = wishbone_master.blk_read_data_out[i] ;
1469
            if (read_status`READ_DATA !== wmem_data[2 + i])
1470
            begin
1471
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1472
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1473
            end
1474
        end
1475
    end
1476
    begin
1477
        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 ) ;
1478
        if ( ok !== 1 )
1479
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1480
        else
1481
            test_ok ;
1482
 
1483
        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 ) ;
1484
        if ( ok !== 1 )
1485
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1486
        else
1487
            test_ok ;
1488
 
1489
        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 ) ;
1490
        if ( ok !== 1 )
1491
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1492
        else
1493
            test_ok ;
1494
 
1495
        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 ) ;
1496
        if ( ok !== 1 )
1497
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1498
        else
1499
            test_ok ;
1500
 
1501
    end
1502
    join
1503
 
1504
    // now repeat this same burst read with various image features enabled or disabled
1505
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1506
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1507
    if (ok !== 1)
1508
    begin
1509
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1510
        test_fail("write to WB Image control register failed") ;
1511
        disable main ;
1512
    end
1513
 
1514
    fork
1515
    begin
1516
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1517
        wishbone_master.wb_block_read(write_flags, read_status) ;
1518
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1519
        begin
1520
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1521
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1522
            disable main ;
1523
        end
1524
 
1525
        // check data read from target
1526
        for ( i = 0 ; i < 4 ; i = i + 1 )
1527
        begin
1528
            read_status = wishbone_master.blk_read_data_out[i] ;
1529
            if (read_status`READ_DATA !== wmem_data[2 + i])
1530
            begin
1531
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1532
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1533
            end
1534
            else
1535
                test_ok ;
1536
        end
1537
    end
1538
    begin
1539
        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 ) ;
1540
        if ( ok !== 1 )
1541
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1542
    end
1543
    join
1544
 
1545
    read_data`READ_ADDRESS  = target_address ;
1546
    read_data`READ_SEL      = 4'hF ;
1547
    read_data`READ_TAG_STIM = 0 ;
1548
 
1549
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1550
    fork
1551
    begin
1552
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1553
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1554
        begin
1555
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1556
            test_fail("delayed single memory read wasn't processed as expected") ;
1557
            disable main ;
1558
        end
1559
 
1560
        if (read_status`READ_DATA !== wmem_data[0])
1561
        begin
1562
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1563
            test_fail("delayed single memory read data value returned was not as expected") ;
1564
        end
1565
        else
1566
            test_ok ;
1567
    end
1568
    begin
1569
        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 ) ;
1570
        if ( ok !== 1 )
1571
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1572
    end
1573
    join
1574
 
1575
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1576
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1577
    if (ok !== 1)
1578
    begin
1579
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1580
        test_fail("write to WB Image control register failed") ;
1581
        disable main ;
1582
    end
1583
 
1584
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1585
    fork
1586
    begin
1587
        wishbone_master.wb_block_read(write_flags, read_status) ;
1588
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1589
        begin
1590
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1591
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1592
            disable main ;
1593
        end
1594
 
1595
        // check data read from target
1596
        for ( i = 0 ; i < 4 ; i = i + 1 )
1597
        begin
1598
            read_status = wishbone_master.blk_read_data_out[i] ;
1599
            if (read_status`READ_DATA !== wmem_data[2 + i])
1600
            begin
1601
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1602
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1603
            end
1604
            else
1605
                test_ok ;
1606
        end
1607
    end
1608
    begin
1609
        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 ) ;
1610
        if ( ok !== 1 )
1611
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1612
    end
1613
    join
1614
 
1615
    read_data`READ_ADDRESS  = target_address + 4 ;
1616
    read_data`READ_SEL      = 4'hF ;
1617
    read_data`READ_TAG_STIM = 0 ;
1618
 
1619
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1620
    fork
1621
    begin
1622
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1623
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1624
        begin
1625
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1626
            test_fail("delayed single memory read wasn't processed as expected") ;
1627
            disable main ;
1628
        end
1629
 
1630
        if (read_status`READ_DATA !== wmem_data[1])
1631
        begin
1632
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1633
            test_fail("delayed single memory read data value returned was not as expected") ;
1634
        end
1635
        else
1636
            test_ok ;
1637
    end
1638
    begin
1639
        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 ) ;
1640
        if ( ok !== 1 )
1641
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1642
    end
1643
    join
1644
 
1645
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1646
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1647
    if (ok !== 1)
1648
    begin
1649
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1650
        test_fail("write to WB Image control register failed") ;
1651
        disable main ;
1652
    end
1653
 
1654
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1655
    fork
1656
    begin
1657
        wishbone_master.wb_block_read(write_flags, read_status) ;
1658
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1659
        begin
1660
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1661
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1662
            disable main ;
1663
        end
1664
 
1665
        // check data read from target
1666
        for ( i = 0 ; i < 4 ; i = i + 1 )
1667
        begin
1668
            read_status = wishbone_master.blk_read_data_out[i] ;
1669
            if (read_status`READ_DATA !== wmem_data[2 + i])
1670
            begin
1671
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1672
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1673
            end
1674
            else
1675
                test_ok ;
1676
        end
1677
    end
1678
    begin
1679
        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 ) ;
1680
        if ( ok !== 1 )
1681
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1682
    end
1683
    join
1684
 
1685
    read_data`READ_ADDRESS  = target_address + 8 ;
1686
    read_data`READ_SEL      = 4'hF ;
1687
    read_data`READ_TAG_STIM = 0 ;
1688
 
1689
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1690
    fork
1691
    begin
1692
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1693
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1694
        begin
1695
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1696
            test_fail("delayed single memory read wasn't processed as expected") ;
1697
            disable main ;
1698
        end
1699
 
1700
        if (read_status`READ_DATA !== wmem_data[2])
1701
        begin
1702
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1703
            test_fail("delayed single memory read data value returned was not as expected") ;
1704
        end
1705
        else
1706
            test_ok ;
1707
    end
1708
    begin
1709
        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 ) ;
1710
        if ( ok !== 1 )
1711
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1712
    end
1713
    join
1714
 
1715
    // map image to IO space
1716
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1717
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1718
    if ( ok !== 1 )
1719
    begin
1720
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1721
        test_fail("write to WB Image Base Address register failed") ;
1722
        disable main ;
1723
    end
1724
 
1725
    write_data`WRITE_ADDRESS = target_address ;
1726
    write_data`WRITE_DATA    = wmem_data[11] ;
1727
    write_data`WRITE_SEL     = 4'hF ;
1728
 
1729
    // handle retries from now on
1730
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1731
 
1732
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1733
    fork
1734
    begin
1735
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1736
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1737
        begin
1738
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1739
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1740
            disable main ;
1741
        end
1742
    end
1743
    begin
1744
        // currently IO commands not supported in behavioral models - master abort
1745
        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 ) ;
1746
        if ( ok !== 1 )
1747
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1748
        else
1749
            test_ok ;
1750
    end
1751
    join
1752
 
1753
    read_data`READ_ADDRESS  = target_address ;
1754
    read_data`READ_SEL      = 4'hF ;
1755
    read_data`READ_TAG_STIM = 0 ;
1756
 
1757
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1758
 
1759
    // currently io commands are not supported by behavioral target - transfer should not be completed
1760
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1761
    fork
1762
    begin
1763
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1764
        if (read_status`CYC_ERR !== 1)
1765
        begin
1766
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1767
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1768
            disable main ;
1769
        end
1770
        else
1771
            test_ok ;
1772
    end
1773
    begin
1774
        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 ) ;
1775
        if ( ok !== 1 )
1776
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1777
    end
1778
    join
1779
 
1780
    // test byte addressing
1781
    read_data`READ_ADDRESS = target_address + 2 ;
1782
    read_data`READ_SEL     = 4'b1100 ;
1783
 
1784
    fork
1785
    begin
1786
        // currently io commands are not supported by behavioral target - transfer should not be completed
1787
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1788
        if (read_status`CYC_ERR !== 1)
1789
        begin
1790
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1791
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1792
            disable main ;
1793
        end
1794
        else test_ok ;
1795
    end
1796
    begin
1797
        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 ) ;
1798
        if ( ok !== 1 )
1799
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1800
    end
1801
    join
1802
 
1803
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1804
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1805
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1806
    if ( ok !== 1 )
1807
    begin
1808
        test_fail("WB Base address register could not be written") ;
1809
        disable main ;
1810
    end
1811
 
1812
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1813
    if ( ok !== 1 )
1814
    begin
1815
        test_fail("WB Address Mask register could not be written") ;
1816
        disable main ;
1817
    end
1818
 
1819
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1820
    if ( ok !== 1 )
1821
    begin
1822
        test_fail("WB Image Control register could not be written") ;
1823
        disable main ;
1824
    end
1825
 
1826
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1827
    write_data`WRITE_DATA    = wmem_data[11] ;
1828
    write_data`WRITE_SEL     = 4'b1000 ;
1829
 
1830
    // handle retries from now on
1831
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1832
 
1833
    fork
1834
    begin
1835
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1836
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1837
        begin
1838
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1839
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1840
            disable main ;
1841
        end
1842
    end
1843
    begin
1844
        // currently IO commands not supported in behavioral models - master abort
1845
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1846
        if ( ok !== 1 )
1847
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1848
        else
1849
            test_ok ;
1850
    end
1851
    join
1852
 
1853
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1854
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1855
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1856
 
1857
    fork
1858
    begin
1859
        // currently io commands are not supported by behavioral target - transfer should not be completed
1860
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1861
        if (read_status`CYC_ERR !== 1)
1862
        begin
1863
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1864
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1865
            disable main ;
1866
        end
1867
        else test_ok ;
1868
    end
1869
    begin
1870
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1871
        if ( ok !== 1 )
1872
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1873
    end
1874
    join
1875
 
1876
    test_name = "DISABLING WB IMAGE" ;
1877
 
1878
    // disable current image
1879
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1880
    if ( ok !== 1 )
1881
    begin
1882
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1883
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1884
        disable main ;
1885
    end
1886
 
1887
    // clear master abort status bit
1888
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1889
    if ( ok !== 1 )
1890
    begin
1891
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1892
        test_fail("write to PCI Device Status register not accepted as expected") ;
1893
        disable main ;
1894
    end
1895
 
1896
end //main
1897
endtask //test_wb_image
1898
 
1899
task wb_slave_errors ;
1900
    reg   [11:0] ctrl_offset ;
1901
    reg   [11:0] ba_offset ;
1902
    reg   [11:0] am_offset ;
1903
    reg   [11:0] ta_offset ;
1904
    reg `WRITE_STIM_TYPE write_data ;
1905
    reg `READ_STIM_TYPE  read_data ;
1906
    reg `READ_RETURN_TYPE read_status ;
1907
 
1908
    reg `WRITE_RETURN_TYPE write_status ;
1909
    reg `WB_TRANSFER_FLAGS write_flags ;
1910
    reg [31:0] temp_val1 ;
1911
    reg [31:0] temp_val2 ;
1912
    reg        ok   ;
1913
    reg [11:0] pci_ctrl_offset ;
1914
    reg [31:0] image_base ;
1915
    reg [31:0] target_address ;
1916
    integer    i ;
1917
    reg skip ;
1918
fork
1919
begin:main
1920
 
1921
    `ifdef GUEST
1922
        skip = 1 ;
1923
    `else
1924
        skip = 0 ;
1925
    `endif
1926
 
1927
    pci_ctrl_offset = 12'h4 ;
1928
 
1929
    // image 1 is used for error testing, since it is always implemented
1930
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1931
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1932
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1933
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1934
 
1935
    target_address  = `BEH_TAR1_MEM_START ;
1936
    image_base      = 0 ;
1937
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1938
 
1939
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1940
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1941
    write_flags                    = 0 ;
1942
    write_flags`INIT_WAITS         = tb_init_waits ;
1943
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1944
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1945
 
1946
    // enable master & target operation
1947
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1948
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1949
    if ( ok !== 1 )
1950
    begin
1951
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1952
        test_fail("PCI Device Control register couldn't be written") ;
1953
        disable no_transaction ;
1954
        disable main ;
1955
    end
1956
 
1957
    // prepare image control register
1958
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1959
    if ( ok !== 1 )
1960
    begin
1961
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1962
        test_fail("WB Image Control register couldn't be written") ;
1963
        disable no_transaction ;
1964
        disable main ;
1965
    end
1966
 
1967
    // prepare base address register
1968
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1969
    if ( ok !== 1 )
1970
    begin
1971
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1972
        test_fail("WB Base Address register couldn't be written") ;
1973
        disable no_transaction ;
1974
        disable main ;
1975
    end
1976
 
1977
    // write address mask register
1978
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1979
    if ( ok !== 1 )
1980
    begin
1981
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1982
        test_fail("WB Address Mask register couldn't be written") ;
1983
        disable no_transaction ;
1984
        disable main ;
1985
    end
1986
 
1987
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1988
 
1989
    skip = 0 ;
1990
 
1991
    // memory mapped image - access is erroneous when address is not alligned
1992
    write_data`WRITE_ADDRESS = target_address + 1 ;
1993
    write_data`WRITE_DATA    = wmem_data[0] ;
1994
    write_data`WRITE_SEL     = 4'hF ;
1995
 
1996
    // handle retries from now on
1997
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1998
 
1999
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
2000
 
2001
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2002
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2003
    begin
2004
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2005
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2006
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2007
        disable no_transaction ;
2008
        disable main ;
2009
    end
2010
 
2011
    write_data`WRITE_ADDRESS = target_address + 2 ;
2012
 
2013
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2014
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2015
    begin
2016
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2017
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2018
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2019
        disable no_transaction ;
2020
        disable main ;
2021
 
2022
    end
2023
 
2024
    write_data`WRITE_ADDRESS = target_address + 3 ;
2025
 
2026
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2027
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2028
    begin
2029
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2030
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2031
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
2032
        disable no_transaction ;
2033
        disable main ;
2034
    end
2035
 
2036
    test_ok ;
2037
 
2038
    // perform same tests for read accesses
2039
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
2040
 
2041
    read_data`READ_ADDRESS  = target_address + 2 ;
2042
    read_data`READ_SEL      = 4'hF ;
2043
    read_data`READ_TAG_STIM = 0 ;
2044
 
2045
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2046
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2047
    begin
2048
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2049
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2050
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2051
        disable no_transaction ;
2052
        disable main ;
2053
    end
2054
 
2055
    test_ok ;
2056
 
2057
    // prepare write data
2058
    for ( i = 0 ; i < 6 ; i = i + 1 )
2059
    begin
2060
        write_data`WRITE_DATA    = wmem_data[i] ;
2061
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2062
        write_data`WRITE_SEL     = 4'hF ;
2063
        wishbone_master.blk_write_data[i] = write_data ;
2064
    end
2065
 
2066
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2067
    write_flags`WB_TRANSFER_CAB    = 1 ;
2068
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2069
 
2070
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2071
    wishbone_master.wb_block_write(write_flags, write_status) ;
2072
 
2073
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2074
    begin
2075
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2076
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2077
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2078
        disable no_transaction ;
2079
        disable main ;
2080
    end
2081
 
2082
    // prepare read data
2083
    for ( i = 0 ; i < 6 ; i = i + 1 )
2084
    begin
2085
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2086
        read_data`READ_SEL     = 4'hF ;
2087
        wishbone_master.blk_read_data_in[i] = read_data ;
2088
    end
2089
 
2090
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2091
    wishbone_master.wb_block_read(write_flags, read_status) ;
2092
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2093
    begin
2094
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2095
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2096
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2097
        disable no_transaction ;
2098
        disable main ;
2099
    end
2100
 
2101
    test_ok ;
2102
 
2103
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2104
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2105
 
2106
    // map image to IO space
2107
    `ifdef GUEST
2108
        skip = 1 ;
2109
    `endif
2110
 
2111
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2112
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2113
    if ( ok !== 1 )
2114
    begin
2115
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2116
        test_fail("WB Image Base Address register couldn't be written") ;
2117
        disable no_transaction ;
2118
        disable main ;
2119
    end
2120
 
2121
    skip = 0 ;
2122
 
2123
    write_data`WRITE_ADDRESS = target_address ;
2124
    write_data`WRITE_DATA    = wmem_data[0] ;
2125
    write_data`WRITE_SEL     = 4'b1010 ;
2126
 
2127
    // don't handle retries
2128
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2129
 
2130
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2131
 
2132
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2133
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2134
    begin
2135
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2136
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2137
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2138
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2139
        disable no_transaction ;
2140
        disable main ;
2141
    end
2142
 
2143
    write_data`WRITE_ADDRESS = target_address + 1 ;
2144
    write_data`WRITE_SEL     = 4'b0011 ;
2145
 
2146
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2147
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2148
    begin
2149
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2150
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2151
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2152
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2153
        disable no_transaction ;
2154
        disable main ;
2155
    end
2156
 
2157
    write_data`WRITE_SEL     = 4'b1100 ;
2158
 
2159
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2160
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2161
    begin
2162
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2163
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2164
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2165
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2166
        disable no_transaction ;
2167
        disable main ;
2168
    end
2169
 
2170
    write_data`WRITE_ADDRESS = target_address + 2 ;
2171
    write_data`WRITE_SEL     = 4'b0101 ;
2172
 
2173
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2174
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2175
    begin
2176
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2177
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2178
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2179
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2180
        disable no_transaction ;
2181
        disable main ;
2182
    end
2183
 
2184
    write_data`WRITE_SEL     = 4'b1000 ;
2185
 
2186
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2187
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2188
    begin
2189
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2190
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2191
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2192
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2193
        disable no_transaction ;
2194
        disable main ;
2195
    end
2196
 
2197
    write_data`WRITE_ADDRESS = target_address + 3 ;
2198
    write_data`WRITE_SEL     = 4'b1010 ;
2199
 
2200
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2201
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2202
    begin
2203
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2204
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2205
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2206
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2207
        disable no_transaction ;
2208
        disable main ;
2209
    end
2210
 
2211
    write_data`WRITE_SEL     = 4'b0110 ;
2212
 
2213
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2214
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2215
    begin
2216
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2217
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2218
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2219
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2220
        disable no_transaction ;
2221
        disable main ;
2222
    end
2223
 
2224
    test_ok ;
2225
 
2226
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2227
 
2228
    read_data`READ_ADDRESS  = target_address + 3 ;
2229
    read_data`READ_SEL      = 4'hF ;
2230
    read_data`READ_TAG_STIM = 0 ;
2231
 
2232
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2233
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2234
    begin
2235
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2236
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2237
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2238
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2239
        disable no_transaction ;
2240
        disable main ;
2241
    end
2242
 
2243
    test_ok ;
2244
 
2245
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2246
    // prepare write data
2247
    for ( i = 0 ; i < 6 ; i = i + 1 )
2248
    begin
2249
        write_data`WRITE_DATA    = wmem_data[i] ;
2250
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2251
        write_data`WRITE_SEL     = 4'hF ;
2252
        wishbone_master.blk_write_data[i] = write_data ;
2253
    end
2254
 
2255
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2256
    write_flags`WB_TRANSFER_CAB    = 1 ;
2257
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2258
 
2259
    wishbone_master.wb_block_write(write_flags, write_status) ;
2260
 
2261
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2262
    begin
2263
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2264
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2265
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2266
        disable no_transaction ;
2267
        disable main ;
2268
    end
2269
 
2270
    test_ok ;
2271
 
2272
    test_name = "CAB I/O READ TO WB SLAVE" ;
2273
    // prepare read data
2274
    for ( i = 0 ; i < 6 ; i = i + 1 )
2275
    begin
2276
        read_data`READ_ADDRESS = target_address + 4*i ;
2277
        read_data`READ_SEL     = 4'hF ;
2278
        wishbone_master.blk_read_data_in[i] = read_data ;
2279
    end
2280
 
2281
    wishbone_master.wb_block_read(write_flags, read_status) ;
2282
 
2283
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2284
    begin
2285
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2286
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2287
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2288
        disable no_transaction ;
2289
        disable main ;
2290
    end
2291
 
2292
    test_ok ;
2293
 
2294
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2295
 
2296
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2297
 
2298
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2299
    write_data`WRITE_ADDRESS = target_address + 1 ;
2300
    write_data`WRITE_DATA    = wmem_data[0] ;
2301
    write_data`WRITE_SEL     = 4'hF ;
2302
 
2303
    // don't handle retries
2304
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2305
 
2306
    `ifdef HOST
2307
        `define DO_W_CONF_TEST
2308
        `define DO_R_CONF_TEST
2309
    `else
2310
        `ifdef WB_CNF_IMAGE
2311
             `define DO_R_CONF_TEST
2312
        `endif
2313
    `endif
2314
 
2315
    `ifdef DO_W_CONF_TEST
2316
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2317
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2318
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2319
    begin
2320
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2321
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2322
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2323
        disable no_transaction ;
2324
        disable main ;
2325
    end
2326
 
2327
    write_data`WRITE_ADDRESS = target_address + 2 ;
2328
 
2329
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2330
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2331
    begin
2332
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2333
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2334
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2335
        disable no_transaction ;
2336
        disable main ;
2337
    end
2338
 
2339
    write_data`WRITE_ADDRESS = target_address + 3 ;
2340
 
2341
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2342
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2343
    begin
2344
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2345
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2346
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2347
        disable no_transaction ;
2348
        disable main ;
2349
    end
2350
 
2351
    test_ok ;
2352
    `endif
2353
 
2354
    `ifdef DO_R_CONF_TEST
2355
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2356
    read_data`READ_ADDRESS  = target_address + 3 ;
2357
    read_data`READ_SEL      = 4'hF ;
2358
    read_data`READ_TAG_STIM = 0 ;
2359
 
2360
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2361
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2362
    begin
2363
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2364
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2365
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2366
        disable no_transaction ;
2367
        disable main ;
2368
    end
2369
 
2370
    test_ok ;
2371
    `endif
2372
 
2373
    `ifdef DO_W_CONF_TEST
2374
    // prepare write data
2375
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2376
    for ( i = 0 ; i < 6 ; i = i + 1 )
2377
    begin
2378
        write_data`WRITE_DATA    = wmem_data[i] ;
2379
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2380
        write_data`WRITE_SEL     = 4'hF ;
2381
        wishbone_master.blk_write_data[i] = write_data ;
2382
    end
2383
 
2384
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2385
    write_flags`WB_TRANSFER_CAB    = 1 ;
2386
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2387
 
2388
    wishbone_master.wb_block_write(write_flags, write_status) ;
2389
 
2390
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2391
    begin
2392
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2393
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2394
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2395
        disable no_transaction ;
2396
        disable main ;
2397
    end
2398
    test_ok ;
2399
    `endif
2400
 
2401
    `ifdef DO_R_CONF_TEST
2402
    // prepare read data
2403
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2404
    for ( i = 0 ; i < 6 ; i = i + 1 )
2405
    begin
2406
        read_data`READ_ADDRESS = target_address + 4*i ;
2407
        read_data`READ_SEL     = 4'hF ;
2408
        wishbone_master.blk_read_data_in[i] = read_data ;
2409
    end
2410
 
2411
    wishbone_master.wb_block_read(write_flags, read_status) ;
2412
 
2413
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2414
    begin
2415
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2416
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2417
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2418
        disable no_transaction ;
2419
        disable main ;
2420
    end
2421
    test_ok ;
2422
    `endif
2423
 
2424
    `ifdef GUEST
2425
        skip = 1 ;
2426
    `endif
2427
 
2428
    // disable image
2429
    test_name = "DISABLE IMAGE" ;
2430
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2431
    if ( ok !== 1 )
2432
    begin
2433
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2434
        test_fail("WB Address Mask register couldn't be written") ;
2435
        disable no_transaction ;
2436
        disable main ;
2437
    end
2438
 
2439
    skip = 0 ;
2440
 
2441
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2442
 
2443
    disable no_transaction ;
2444
end
2445
begin:no_transaction
2446
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2447
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2448
    forever
2449
    begin
2450
        @(posedge pci_clock) ;
2451
        if ( skip !== 1 )
2452
        begin
2453
            if ( FRAME !== 1 )
2454
            begin
2455
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2456
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2457
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2458
            end
2459
        end
2460
    end
2461
end
2462
join
2463
endtask //wb_slave_errors
2464
 
2465
task wb_to_pci_error_handling ;
2466
    reg   [11:0] ctrl_offset ;
2467
    reg   [11:0] ba_offset ;
2468
    reg   [11:0] am_offset ;
2469
    reg   [11:0] ta_offset ;
2470
    reg   [11:0] err_cs_offset ;
2471
    reg `WRITE_STIM_TYPE write_data ;
2472
    reg `READ_STIM_TYPE  read_data ;
2473
    reg `READ_RETURN_TYPE read_status ;
2474
 
2475
    reg `WRITE_RETURN_TYPE write_status ;
2476
    reg `WB_TRANSFER_FLAGS write_flags ;
2477
    reg [31:0] temp_val1 ;
2478
    reg [31:0] temp_val2 ;
2479
    reg        ok   ;
2480
    reg [11:0] pci_ctrl_offset ;
2481
    reg [31:0] image_base ;
2482
    reg [31:0] target_address ;
2483
    integer    num_of_trans ;
2484
    integer    current ;
2485
    integer    i ;
2486
begin:main
2487
 
2488
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2489
 
2490
    pci_ctrl_offset = 12'h4 ;
2491
 
2492
    // disable error interrupts and disable error reporting
2493
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2494
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2495
    if ( ok !== 1 )
2496
    begin
2497
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2498
        test_fail("PCI Device Control register couldn't be written") ;
2499
        disable main ;
2500
    end
2501
 
2502
    // image 1 is used for error testing, since it is always implemented
2503
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2504
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2505
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2506
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2507
 
2508
    // set master abort testing address to address that goes out of target's range
2509
    target_address  = `BEH_TAR1_MEM_START ;
2510
    image_base      = 0 ;
2511
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2512
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2513
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2514
 
2515
    write_flags                    = 0 ;
2516
    write_flags`INIT_WAITS         = tb_init_waits ;
2517
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2518
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2519
 
2520
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2521
 
2522
    // enable master & target operation
2523
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2524
    if ( ok !== 1 )
2525
    begin
2526
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2527
        test_fail("PCI Device Control register couldn't be written") ;
2528
        disable main ;
2529
    end
2530
 
2531
    // prepare image control register
2532
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2533
    if ( ok !== 1 )
2534
    begin
2535
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2536
        test_fail("WB Image Control register couldn't be written") ;
2537
        disable main ;
2538
    end
2539
 
2540
    // prepare base address register
2541
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2542
    if ( ok !== 1 )
2543
    begin
2544
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2545
        test_fail("WB Image Base Address register couldn't be written") ;
2546
        disable main ;
2547
    end
2548
 
2549
    // write address mask register
2550
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2551
    if ( ok !== 1 )
2552
    begin
2553
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2554
        test_fail("WB Image Address Mask register couldn't be written") ;
2555
        disable main ;
2556
    end
2557
 
2558
    // disable error reporting
2559
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2560
    if ( ~ok )
2561
    begin
2562
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2563
        test_fail("WB Error Control and Status register couldn't be written") ;
2564
        disable main ;
2565
    end
2566
 
2567
    // perform two writes - one to error address and one to OK address
2568
    // prepare write buffer
2569
 
2570
    write_data`WRITE_ADDRESS = target_address ;
2571
    write_data`WRITE_DATA    = wmem_data[100] ;
2572
    write_data`WRITE_SEL     = 4'hF ;
2573
 
2574
    wishbone_master.blk_write_data[0] = write_data ;
2575
 
2576
    write_flags`WB_TRANSFER_SIZE = 2 ;
2577
 
2578
    // don't handle retries
2579
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2580
    write_flags`WB_TRANSFER_CAB    = 0 ;
2581
 
2582
    $display("Introducing master abort error on single WB to PCI write!") ;
2583
 
2584
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2585
    // first disable target 1
2586
 
2587 45 mihad
    configuration_cycle_write(0,                        // bus number
2588
                              `TAR1_IDSEL_INDEX - 11,   // device number
2589
                              0,                        // function number
2590
                              1,                        // register number
2591
                              0,                        // type of configuration cycle
2592
                              4'b0001,                  // byte enables
2593
                              32'h0000_0000             // data
2594 15 mihad
                             ) ;
2595
 
2596
    fork
2597
    begin
2598
        // start no response monitor in parallel with writes
2599
        musnt_respond(ok) ;
2600
        if ( ok !== 1 )
2601
        begin
2602
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2603
            $display("Testbench is configured wrong!") ;
2604
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2605
        end
2606
        else
2607
            test_ok ;
2608
    end
2609
    begin
2610
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2611
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2612
       begin
2613
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2614
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2615
           test_fail("WB Slave state machine failed to post single memory write");
2616
           disable main ;
2617
       end
2618
    end
2619
    join
2620
 
2621
    /*// read data from second write
2622
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2623
    read_data`READ_ADDRESS = target_address ;
2624
    read_data`READ_SEL     = 4'hF ;
2625
    read_data`READ_TAG_STIM = 0 ;
2626
 
2627
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2628
 
2629
    if ( read_status`READ_DATA !== wmem_data[101] )
2630
    begin
2631
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2632
    end
2633
    */
2634
 
2635
    // read error status register - no errors should be reported since reporting was disabled
2636
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2637
 
2638
    @(posedge pci_clock) ;
2639
    // wait for two WB clocks for synchronization to be finished
2640
    repeat (2)
2641
        @(posedge wb_clock) ;
2642
 
2643
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2644
    if ( temp_val1[8] !== 0 )
2645
    begin
2646
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2647
        $display("Error reporting was disabled, but error was reported anyway!") ;
2648
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2649
        disable main ;
2650
    end
2651
    test_ok ;
2652
 
2653
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2654
    // check for interrupts - there should be no interrupt requests active
2655
    `ifdef HOST
2656
        repeat(4)
2657
            @(posedge wb_clock) ;
2658
 
2659
        if ( INT_O !== 0 )
2660
        begin
2661
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2662
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2663
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2664
        end
2665
        else
2666
            test_ok ;
2667
    `else
2668
    `ifdef GUEST
2669
        repeat( 4 )
2670
            @(posedge pci_clock) ;
2671
 
2672
        if ( INTA !== 1 )
2673
        begin
2674
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2675
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2676
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2677
        end
2678
        else
2679
            test_ok ;
2680
    `endif
2681
    `endif
2682
 
2683
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2684
    // check PCI status register
2685
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2686
    if ( temp_val1[29] !== 1 )
2687
    begin
2688
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2689
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2690
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2691
    end
2692
    else
2693
        test_ok ;
2694
 
2695
    // clear
2696
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2697
 
2698
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2699
 
2700
    $display("Introducing master abort error to CAB write!") ;
2701
    // now enable error reporting mechanism
2702
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2703
    // enable error interrupts
2704
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2705
 
2706
    // configure flags for CAB transfer
2707
    write_flags`WB_TRANSFER_CAB = 1 ;
2708
    write_flags`WB_TRANSFER_SIZE = 3 ;
2709
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2710
 
2711
    // prepare data for erroneous write
2712
    for ( i = 0 ; i < 3 ; i = i + 1 )
2713
    begin
2714
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2715
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2716
        write_data`WRITE_SEL     = 4'hF ;
2717
        wishbone_master.blk_write_data[i] = write_data ;
2718
    end
2719
 
2720
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2721
    fork
2722
    begin
2723
        wishbone_master.wb_block_write(write_flags, write_status) ;
2724
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2725
        begin
2726
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2727
            $display("Complete burst write through WB slave didn't succeed!") ;
2728
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2729
            disable main ;
2730
        end
2731
    end
2732
    begin
2733
        musnt_respond(ok) ;
2734
        if ( ok !== 1 )
2735
        begin
2736
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2737
            $display("Testbench is configured wrong!") ;
2738
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2739
        end
2740
        else
2741
            test_ok ;
2742
    end
2743
    join
2744
 
2745
    // check error status address, data, byte enables and bus command
2746
    // error status bit is signalled on PCI clock and synchronized to WB clock
2747
    // wait one PCI clock cycle
2748
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2749
    ok = 1 ;
2750
    @(posedge pci_clock) ;
2751
 
2752
    // wait for two WB clocks for synchronization to be finished
2753
    repeat (2)
2754
        @(posedge wb_clock) ;
2755
 
2756
    // read registers
2757
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2758
    if ( temp_val1[8] !== 1 )
2759
    begin
2760
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2761
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2762
        ok = 0 ;
2763
    end
2764
 
2765
    if ( temp_val1[9] !== 1 )
2766
    begin
2767
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2768
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2769
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2770
        ok = 0 ;
2771
    end
2772
 
2773
    if ( temp_val1[31:28] !== 0 )
2774
    begin
2775
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2776
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2777
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2778
        ok = 0 ;
2779
    end
2780
 
2781
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2782
    begin
2783
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2784
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2785
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2786
        ok = 0 ;
2787
    end
2788
 
2789
    // read error address register
2790
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2791
    if ( temp_val1 !== target_address )
2792
    begin
2793
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2794
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2795
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2796
        ok = 0 ;
2797
    end
2798
 
2799
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2800
    if ( temp_val1 !== wmem_data[110] )
2801
    begin
2802
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2803
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2804
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2805
        ok = 0 ;
2806
    end
2807
 
2808
    // check PCI status register
2809
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2810
    if ( temp_val1[29] !== 1 )
2811
    begin
2812
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2813
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2814
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2815
        ok = 0 ;
2816
    end
2817
 
2818
    if ( temp_val1[28] !== 0 )
2819
    begin
2820
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2821
        $display("Received Target Abort bit was set for no reason!") ;
2822
        test_fail("Received Target Abort bit was set for no reason") ;
2823
        ok = 0 ;
2824
    end
2825
 
2826
    if ( ok )
2827
        test_ok ;
2828
 
2829
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2830
 
2831
    // clear error status bit
2832
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2833
 
2834
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2835
 
2836
    ok = 1 ;
2837
 
2838
    `ifdef HOST
2839
        repeat(4)
2840
        @(posedge wb_clock) ;
2841
        if ( INT_O !== 1 )
2842
        begin
2843
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2844
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2845
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2846
            ok = 0 ;
2847
        end
2848
    `else
2849
    `ifdef GUEST
2850
        repeat(4)
2851
        @(posedge pci_clock) ;
2852
        if ( INTA !== 0 )
2853
        begin
2854
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2855
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2856
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2857
            ok = 0 ;
2858
        end
2859
    `endif
2860
    `endif
2861
 
2862
    // read interrupt status register
2863
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2864
    if ( temp_val1 !== 32'h0000_0002 )
2865
    begin
2866
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2867
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2868
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2869
        test_fail("Interrupt Status register returned wrong value") ;
2870
        ok = 0 ;
2871
    end
2872
 
2873
    if ( ok )
2874
        test_ok ;
2875
    // clear interrupt status bits
2876
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2877
 
2878
    ok = 1 ;
2879
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2880
    // wait for two clock cycles before checking interrupt request deassertion
2881
    `ifdef HOST
2882
        repeat (4)
2883
            @(posedge wb_clock) ;
2884
 
2885
        if ( INT_O !== 0 )
2886
        begin
2887
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2888
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2889
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2890
            ok = 0 ;
2891
        end
2892
    `else
2893
    `ifdef GUEST
2894
        repeat (4)
2895
            @(posedge pci_clock) ;
2896
 
2897
        if ( INTA !== 1 )
2898
        begin
2899
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2900
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2901
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2902
            ok = 0 ;
2903
        end
2904
    `endif
2905
    `endif
2906
 
2907
    if ( ok )
2908
        test_ok ;
2909
 
2910
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2911
    ok = 1 ;
2912
    // enable target
2913 45 mihad
    configuration_cycle_write(0,                        // bus number
2914
                              `TAR1_IDSEL_INDEX - 11,   // device number
2915
                              0,                        // function number
2916
                              1,                        // register number
2917
                              0,                        // type of configuration cycle
2918
                              4'b0001,                  // byte enables
2919
                              32'h0000_0007             // data
2920 15 mihad
                             ) ;
2921
    // prepare data for ok write
2922
    for ( i = 0 ; i < 3 ; i = i + 1 )
2923
    begin
2924
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2925
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2926
        write_data`WRITE_SEL     = 4'hF ;
2927
        wishbone_master.blk_write_data[i] = write_data ;
2928
    end
2929
 
2930
    wishbone_master.wb_block_write(write_flags, write_status) ;
2931
 
2932
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2933
    begin
2934
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2935
        $display("Complete burst write through WB slave didn't succeed!") ;
2936
        test_fail("WB Slave state machine failed to post CAB write") ;
2937
        disable main ;
2938
    end
2939
 
2940
    // do a read
2941
    for ( i = 0 ; i < 3 ; i = i + 1 )
2942
    begin
2943
        read_data`READ_ADDRESS = target_address + 4*i ;
2944
        read_data`READ_SEL     = 4'hF ;
2945
        wishbone_master.blk_read_data_in[i] = read_data ;
2946
    end
2947
 
2948
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2949
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2950
    write_flags`WB_TRANSFER_CAB    = 1 ;
2951
 
2952
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2953
 
2954
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2955
    begin
2956
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2957
        $display("Complete burst read through WB slave didn't succeed!") ;
2958
        test_fail("Delayed CAB write was not processed as expected") ;
2959
        disable main ;
2960
    end
2961
 
2962
    for ( i = 0 ; i < 3 ; i = i + 1 )
2963
    begin
2964
        read_status = wishbone_master.blk_read_data_out[i] ;
2965
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2966
        begin
2967
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2968
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2969
        end
2970
    end
2971
 
2972
    $display("Introducing master abort error to single read!") ;
2973
    // disable target
2974 45 mihad
    configuration_cycle_write(0,                        // bus number
2975
                              `TAR1_IDSEL_INDEX - 11,   // device number
2976
                              0,                        // function number
2977
                              1,                        // register number
2978
                              0,                        // type of configuration cycle
2979
                              4'b0001,                  // byte enables
2980
                              32'h0000_0000             // data
2981 15 mihad
                             ) ;
2982
    // set read data
2983
    read_data`READ_ADDRESS = target_address ;
2984
    read_data`READ_SEL     = 4'hF ;
2985
 
2986
    // enable automatic retry handling
2987
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2988
    write_flags`WB_TRANSFER_CAB    = 0 ;
2989
 
2990
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2991
    fork
2992
    begin
2993
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2994
    end
2995
    begin
2996
        musnt_respond(ok) ;
2997
        if ( ok !== 1 )
2998
        begin
2999
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3000
            $display("Testbench is configured wrong!") ;
3001
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3002
        end
3003
    end
3004
    join
3005
 
3006
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3007
    begin
3008
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3009
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3010
        $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) ;
3011
        test_fail("read didn't finish on WB bus as expected") ;
3012
        disable main ;
3013
    end
3014
 
3015
    test_ok ;
3016
 
3017
 
3018
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
3019
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
3020
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3021
    if ( temp_val1[8] !== 0 )
3022
    begin
3023
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3024
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
3025
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
3026
    end
3027
    else
3028
        test_ok ;
3029
 
3030
    // now check normal read operation
3031 45 mihad
    configuration_cycle_write(0,                        // bus number
3032
                              `TAR1_IDSEL_INDEX - 11,   // device number
3033
                              0,                        // function number
3034
                              1,                        // register number
3035
                              0,                        // type of configuration cycle
3036
                              4'b0001,                  // byte enables
3037
                              32'h0000_0007             // data
3038 15 mihad
                             ) ;
3039
 
3040 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
3041 15 mihad
    read_data`READ_ADDRESS = target_address ;
3042
    read_data`READ_SEL     = 4'hF ;
3043
 
3044
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3045
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3046
    begin
3047
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3048
        $display("WB slave failed to process single read!") ;
3049
        $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) ;
3050
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3051
        disable main ;
3052
    end
3053
 
3054
    if ( read_status`READ_DATA !== wmem_data[113] )
3055
    begin
3056
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3057
        test_fail("when read finished on WB bus, wrong data was provided") ;
3058
    end
3059
    else
3060
        test_ok ;
3061
 
3062
    // check PCI status register
3063 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3064 15 mihad
    ok = 1 ;
3065
 
3066
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3067
    if ( temp_val1[29] !== 1 )
3068
    begin
3069
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3070
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3071
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3072
        ok = 0 ;
3073
    end
3074
 
3075
    if ( temp_val1[28] !== 0 )
3076
    begin
3077
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3078
        $display("Received Target Abort bit was set for no reason!") ;
3079
        test_fail("Received Target Abort bit was set for no reason") ;
3080
        ok = 0 ;
3081
    end
3082
    if ( ok )
3083
        test_ok ;
3084
 
3085
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3086
 
3087
    $display("Introducing master abort error to CAB read!") ;
3088
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3089
 
3090 45 mihad
    configuration_cycle_write(0,                        // bus number
3091
                              `TAR1_IDSEL_INDEX - 11,   // device number
3092
                              0,                        // function number
3093
                              1,                        // register number
3094
                              0,                        // type of configuration cycle
3095
                              4'b0001,                  // byte enables
3096
                              32'h0000_0000             // data
3097 15 mihad
                             ) ;
3098
 
3099
    for ( i = 0 ; i < 3 ; i = i + 1 )
3100
    begin
3101
        read_data`READ_ADDRESS = target_address + 4*i ;
3102
        read_data`READ_SEL     = 4'hF ;
3103
        wishbone_master.blk_read_data_in[i] = read_data ;
3104
    end
3105
 
3106
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3107
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3108
    write_flags`WB_TRANSFER_CAB    = 1 ;
3109
 
3110
    fork
3111
    begin
3112
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3113
    end
3114
    begin
3115
        musnt_respond(ok) ;
3116
        if ( ok !== 1 )
3117
        begin
3118
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3119
            $display("Testbench is configured wrong!") ;
3120
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3121
        end
3122
    end
3123
    join
3124
 
3125
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3126
    begin
3127
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3128
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3129
        $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) ;
3130
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3131
        disable main ;
3132
    end
3133
    else
3134
        test_ok ;
3135
 
3136
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3137
    ok = 1 ;
3138
    // check PCI status register
3139
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3140
    if ( temp_val1[29] !== 1 )
3141
    begin
3142
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3143
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3144
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3145
        ok = 0 ;
3146
    end
3147
 
3148
    if ( temp_val1[28] !== 0 )
3149
    begin
3150
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3151
        $display("Received Target Abort bit was set for no reason!") ;
3152
        test_fail("Received Target Abort bit was set for no reason") ;
3153
        ok = 0 ;
3154
    end
3155
 
3156
    if ( ok )
3157
        test_ok ;
3158
 
3159
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3160
 
3161
    $display("Introducing target abort termination to single write!") ;
3162
 
3163
    // disable error reporting and interrupts
3164
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3165
 
3166 45 mihad
    configuration_cycle_write(0,                        // bus number
3167
                              `TAR1_IDSEL_INDEX - 11,   // device number
3168
                              0,                        // function number
3169
                              1,                        // register number
3170
                              0,                        // type of configuration cycle
3171
                              4'b0001,                  // byte enables
3172
                              32'h0000_0007             // data
3173 15 mihad
                             ) ;
3174
 
3175
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3176
    if ( ok !== 1 )
3177
    begin
3178
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3179
        test_fail("WB Error Control and Status register couldn't be written to") ;
3180
        disable main ;
3181
    end
3182
 
3183
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3184
    if ( ok !== 1 )
3185
    begin
3186
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3187
        test_fail("Interrupt Control register couldn't be written to") ;
3188
        disable main ;
3189
    end
3190
 
3191
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3192
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3193
 
3194
    write_data`WRITE_ADDRESS = target_address ;
3195
    write_data`WRITE_DATA    = wmem_data[0] ;
3196
    write_data`WRITE_SEL     = 4'hF ;
3197
 
3198
    wishbone_master.blk_write_data[0] = write_data ;
3199
 
3200
    write_data`WRITE_ADDRESS = target_address + 4;
3201
    write_data`WRITE_DATA    = wmem_data[1] ;
3202
    write_data`WRITE_SEL     = 4'hF ;
3203
 
3204
    wishbone_master.blk_write_data[1] = write_data ;
3205
 
3206
    write_flags`WB_TRANSFER_SIZE = 2 ;
3207
 
3208
    // don't handle retries
3209
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3210
    write_flags`WB_TRANSFER_CAB    = 0 ;
3211
 
3212
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3213
    fork
3214
    begin
3215
        wishbone_master.wb_block_write(write_flags, write_status) ;
3216
 
3217
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3218
        begin
3219
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3220
            $display("Image writes were not accepted as expected!") ;
3221
            $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) ;
3222
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3223
            disable main ;
3224
        end
3225
 
3226
        // read data back to see, if it was written OK
3227
        read_data`READ_ADDRESS         = target_address + 4;
3228
        read_data`READ_SEL             = 4'hF ;
3229
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3230
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3231
    end
3232
    begin
3233
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3234
        if ( ok !== 1 )
3235
        begin
3236
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3237
        end
3238
        else
3239
            test_ok ;
3240
 
3241
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3242
 
3243
        // when first transaction finishes - enable normal target response!
3244
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3245
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3246
 
3247
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3248
        if ( ok !== 1 )
3249
        begin
3250
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3251
        end
3252
        else
3253
            test_ok ;
3254
 
3255
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3256
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3257
        if ( ok !== 1 )
3258
        begin
3259
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3260
        end
3261
    end
3262
    join
3263
 
3264
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3265
    begin
3266
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3267
        $display("Bridge failed to process single read after target abort terminated write!") ;
3268
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3269
        disable main ;
3270
    end
3271
 
3272
    if ( read_status`READ_DATA !== wmem_data[1] )
3273
    begin
3274
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3275
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3276
    end
3277
    else
3278
        test_ok ;
3279
 
3280
    // check interrupt and error statuses!
3281
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3282
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3283
    if ( temp_val1[8] !== 0 )
3284
    begin
3285
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3286
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3287
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3288
    end
3289
    else
3290
        test_ok ;
3291
 
3292
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3293
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3294
    if ( temp_val1[1] !== 0 )
3295
    begin
3296
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3297
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3298
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3299
    end
3300
    else
3301
        test_ok ;
3302
 
3303
    // check PCI status register
3304
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3305
    ok = 1 ;
3306
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3307
    if ( temp_val1[29] !== 0 )
3308
    begin
3309
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3310
        $display("Received Master Abort bit was set with no reason!") ;
3311
        test_fail("Received Master Abort bit was set with no reason") ;
3312
        ok = 0 ;
3313
    end
3314
 
3315
    if ( temp_val1[28] !== 1 )
3316
    begin
3317
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3318
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3319
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3320
        ok = 0 ;
3321
    end
3322
 
3323
    if ( ok )
3324
        test_ok ;
3325
 
3326
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3327
 
3328
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3329
 
3330
    $display("Introducing target abort termination to CAB write!") ;
3331
    // enable error reporting mechanism
3332
 
3333
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3334
    if ( ok !== 1 )
3335
    begin
3336
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3337
        test_fail("WB Error Control and Status register could not be written to") ;
3338
        disable main ;
3339
    end
3340
 
3341
    for ( i = 0 ; i < 3 ; i = i + 1 )
3342
    begin
3343
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3344
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3345
        write_data`WRITE_SEL     = 4'b1010 ;
3346
        wishbone_master.blk_write_data[i] = write_data ;
3347
    end
3348
 
3349
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3350
    write_flags`WB_TRANSFER_CAB    = 1 ;
3351
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3352
 
3353
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3354
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3355
 
3356
    fork
3357
    begin
3358
        wishbone_master.wb_block_write(write_flags, write_status) ;
3359
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3360
        begin
3361
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3362
            $display("Bridge failed to process complete CAB write!") ;
3363
            test_fail("bridge failed to post CAB Memory Write") ;
3364
            disable main ;
3365
        end
3366
    end
3367
    begin
3368
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3369
        if ( ok !== 1 )
3370
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3371
        else
3372
            test_ok ;
3373
    end
3374
    join
3375
 
3376
    // check statuses and data from error
3377
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3378
    ok = 1 ;
3379
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3380
    if ( temp_val1[8] !== 1 )
3381
    begin
3382
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3383
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3384
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3385
        ok = 0 ;
3386
    end
3387
 
3388
    if ( temp_val1[9] !== 0 )
3389
    begin
3390
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3391
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3392
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3393
        ok = 0 ;
3394
    end
3395
 
3396
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3397
    begin
3398
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3399
        $display("Value in W_ERR_CS register was wrong!") ;
3400
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3401
        test_fail("BE Field didn't provided expected value") ;
3402
        ok = 0 ;
3403
    end
3404
 
3405
    if ( ok )
3406
        test_ok ;
3407
 
3408
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3409
    ok = 1 ;
3410
    // check erroneous address and data
3411
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3412
    if ( temp_val1 !== (target_address + 8) )
3413
    begin
3414
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3415
        $display("Value in W_ERR_ADDR register was wrong!") ;
3416
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3417
        test_fail("Value in WB Erroneous Address register was wrong") ;
3418
        ok = 0 ;
3419
    end
3420
 
3421
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3422
    if ( temp_val1 !== wmem_data[120] )
3423
    begin
3424
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3425
        $display("Value in W_ERR_DATA register was wrong!") ;
3426
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3427
        test_fail("Value in WB Erroneous Data register was wrong") ;
3428
        ok = 0 ;
3429
    end
3430
 
3431
    if ( ok )
3432
        test_ok ;
3433
 
3434
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3435
    ok = 1 ;
3436
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3437
    if ( temp_val1[29] !== 0 )
3438
    begin
3439
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3440
        $display("Received Master Abort bit was set with no reason!") ;
3441
        test_fail("Received Master Abort bit was set for no reason") ;
3442
        ok = 0 ;
3443
    end
3444
 
3445
    if ( temp_val1[28] !== 1 )
3446
    begin
3447
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3448
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3449
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3450
        ok = 0 ;
3451
    end
3452
 
3453
    if ( ok )
3454
        test_ok ;
3455
 
3456
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3457
 
3458
    // clear error status bit and enable error interrupts
3459
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3460
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3461
 
3462
    // check if error bit was cleared
3463
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3464
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3465
    if ( temp_val1[8] !== 0 )
3466
    begin
3467
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3468
        $display("Error bit was not cleared even though one was written to its location!") ;
3469
        test_fail("Error bit was not cleared even though one was written to its location") ;
3470
    end
3471
 
3472
    // repeat same write with different target configuration
3473
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3474
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3475
 
3476
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3477
    fork
3478
    begin
3479
        write_flags`WB_TRANSFER_SIZE = 2 ;
3480
        wishbone_master.wb_block_write(write_flags, write_status) ;
3481
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3482
        begin
3483
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3484
            $display("Bridge failed to process complete CAB write!") ;
3485
            test_fail("bridge failed to post CAB Memory Write") ;
3486
            disable main ;
3487
        end
3488
 
3489
        write_flags`WB_TRANSFER_SIZE = 3 ;
3490
        wishbone_master.wb_block_write(write_flags, write_status) ;
3491
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3492
        begin
3493
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3494
            $display("Bridge failed to process complete CAB write!") ;
3495
            test_fail("bridge failed to post CAB Memory Write") ;
3496
            disable main ;
3497
        end
3498
    end
3499
    begin
3500
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3501
        if ( ok !== 1 )
3502
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3503
        else
3504
        begin
3505
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3506
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3507
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3508
            if ( ok !== 1 )
3509
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3510
            else
3511
                test_ok ;
3512
        end
3513
    end
3514
    join
3515
 
3516
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3517
    ok = 1 ;
3518
    // check statuses and data from error
3519
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3520
    if ( temp_val1[8] !== 1 )
3521
    begin
3522
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3523
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3524
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3525
        ok = 0 ;
3526
    end
3527
 
3528
    if ( temp_val1[9] !== 0 )
3529
    begin
3530
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3531
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3532
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3533
        ok = 0 ;
3534
    end
3535
 
3536
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3537
    begin
3538
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3539
        $display("Value in W_ERR_CS register was wrong!") ;
3540
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3541
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3542
        ok = 0 ;
3543
    end
3544
 
3545
    if ( ok )
3546
        test_ok ;
3547
 
3548
    // check erroneous address and data
3549
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3550
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3551
    ok = 1 ;
3552
    if ( temp_val1 !== (target_address + 8 + 4) )
3553
    begin
3554
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3555
        $display("Value in W_ERR_ADDR register was wrong!") ;
3556
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3557
        test_fail("Value in WB Erroneous Address register was wrong") ;
3558
        ok = 0 ;
3559
 
3560
    end
3561
 
3562
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3563
    if ( temp_val1 !== wmem_data[121] )
3564
    begin
3565
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3566
        $display("Value in W_ERR_DATA register was wrong!") ;
3567
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3568
        test_fail("Value in WB Erroneous Data register was wrong") ;
3569
        ok = 0 ;
3570
    end
3571
 
3572
    if ( ok )
3573
        test_ok ;
3574
 
3575
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3576
    `ifdef HOST
3577
        repeat(4)
3578
            @(posedge wb_clock) ;
3579
        if ( INT_O !== 1 )
3580
        begin
3581
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3582
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3583
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3584
        end
3585
        else
3586
            test_ok ;
3587
    `else
3588
    `ifdef GUEST
3589
        repeat(4)
3590
            @(posedge pci_clock) ;
3591
        if ( INTA !== 0 )
3592
        begin
3593
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3594
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3595
            test_fail("interrupt request was not presented on PCI bus") ;
3596
        end
3597
        else
3598
            test_ok ;
3599
    `endif
3600
    `endif
3601
 
3602
    // read interrupt status register
3603
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3604
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3605
    if ( temp_val1[1] !== 1 )
3606
    begin
3607
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3608
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3609
        test_fail("Expected Interrupt status bit wasn't set") ;
3610
    end
3611
 
3612
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3613
 
3614
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3615
    ok = 1 ;
3616
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3617
    if ( temp_val1[29] !== 0 )
3618
    begin
3619
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3620
        $display("Received Master Abort bit was set with no reason!") ;
3621
        test_fail("Received Master Abort bit was set with no reason") ;
3622
        ok = 0 ;
3623
    end
3624
 
3625
    if ( temp_val1[28] !== 1 )
3626
    begin
3627
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3628
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3629
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3630
        ok = 0 ;
3631
    end
3632
 
3633
    if ( ok )
3634
        test_ok ;
3635
 
3636
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3637
 
3638
    // clear interrupts and errors
3639
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3640
    repeat( 3 )
3641
        @(posedge pci_clock) ;
3642
 
3643
    repeat( 2 )
3644
        @(posedge wb_clock) ;
3645
 
3646
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3647
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3648
    if ( temp_val1[1] !== 0 )
3649
    begin
3650
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3651
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3652
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3653
    end
3654
    else
3655
        test_ok ;
3656
 
3657
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3658
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3659
    if ( temp_val1[8] !== 0 )
3660
    begin
3661
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3662
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3663
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3664
    end
3665
 
3666
 
3667
    $display("Introducing Target Abort error to single read!") ;
3668
    // set read data
3669
    read_data`READ_ADDRESS = target_address + 8 ;
3670
    read_data`READ_SEL     = 4'hF ;
3671
 
3672
    // enable automatic retry handling
3673
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3674
    write_flags`WB_TRANSFER_CAB    = 0 ;
3675
 
3676
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3677
 
3678
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3679
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3680
 
3681
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3682
 
3683
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3684
    begin
3685
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3686
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3687
        $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) ;
3688
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3689
        disable main ;
3690
    end
3691
    else
3692
        test_ok ;
3693
 
3694
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3695
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3696
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3697
    if ( temp_val1[8] !== 0 )
3698
    begin
3699
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3700
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3701
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3702
    end
3703
    else
3704
        test_ok ;
3705
 
3706
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3707
    ok = 1 ;
3708
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3709
    if ( temp_val1[29] !== 0 )
3710
    begin
3711
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3712
        $display("Received Master Abort bit was set with no reason!") ;
3713
        test_fail("Received Master Abort bit was set with no reason") ;
3714
        ok = 0 ;
3715
    end
3716
 
3717
    if ( temp_val1[28] !== 1 )
3718
    begin
3719
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3720
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3721
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3722
        ok = 0 ;
3723
    end
3724
 
3725
    if ( ok )
3726
        test_ok ;
3727
 
3728
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3729
 
3730
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3731
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3732
    if ( temp_val1[1] !== 0 )
3733
    begin
3734
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3735
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3736
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3737
    end
3738
    else
3739
        test_ok ;
3740
 
3741
    $display("Introducing Target Abort error to CAB read!") ;
3742
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3743
 
3744
    for ( i = 0 ; i < 4 ; i = i + 1 )
3745
    begin
3746
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3747
        read_data`READ_SEL     = 4'b1010 ;
3748
        wishbone_master.blk_read_data_in[i] = read_data ;
3749
    end
3750
 
3751
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3752
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3753
    write_flags`WB_TRANSFER_CAB    = 1 ;
3754
 
3755
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3756
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3757
 
3758
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3759
 
3760
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3761
    begin
3762
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3763
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3764
        $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) ;
3765
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3766
        disable main ;
3767
    end
3768
 
3769
    read_status = wishbone_master.blk_read_data_out[0] ;
3770
    temp_val1 = read_status`READ_DATA ;
3771
    temp_val2 = wmem_data[120] ;
3772
 
3773
    // last write to this address was with only two byte enables - check only those
3774
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3775
    begin
3776
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3777
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3778
    end
3779
    else
3780
        test_ok ;
3781
 
3782
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3783
    ok = 1 ;
3784
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3785
    if ( temp_val1[29] !== 0 )
3786
    begin
3787
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3788
        $display("Received Master Abort bit was set with no reason!") ;
3789
        test_fail("Received Master Abort bit was set with no reason") ;
3790
        ok = 0 ;
3791
    end
3792
 
3793
    if ( temp_val1[28] !== 1 )
3794
    begin
3795
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3796
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3797
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3798
        ok = 0 ;
3799
    end
3800
 
3801
    if ( ok )
3802
       test_ok ;
3803
 
3804
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3805
 
3806
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3807
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3808
 
3809
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3810
    for ( i = 0 ; i < 3 ; i = i + 1 )
3811
    begin
3812
        read_data`READ_ADDRESS = target_address + 4*i ;
3813
        read_data`READ_SEL     = 4'b1111 ;
3814
        wishbone_master.blk_read_data_in[i] = read_data ;
3815
    end
3816
 
3817
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3818
 
3819
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3820
 
3821
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3822
    begin
3823
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3824
        $display("Complete burst read through WB slave didn't succeed!") ;
3825
        test_fail("bridge didn't process Burst Read in an expected way") ;
3826
        disable main ;
3827
    end
3828
    else
3829
        test_ok ;
3830
 
3831
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3832
 
3833
    for ( i = 0 ; i < 3 ; i = i + 1 )
3834
    begin
3835
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3836
        read_data`READ_SEL     = 4'b1111 ;
3837
        wishbone_master.blk_read_data_in[i] = read_data ;
3838
    end
3839
 
3840
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3841
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3842
    write_flags`WB_TRANSFER_CAB    = 1 ;
3843
 
3844
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3845
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3846
 
3847
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3848
 
3849
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3850
    begin
3851
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3852
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3853
        $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) ;
3854
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3855
        disable main ;
3856
    end
3857
 
3858
    for ( i = 0 ; i < 3 ; i = i + 1 )
3859
    begin
3860
        ok = 1 ;
3861
        read_status = wishbone_master.blk_read_data_out[i] ;
3862
        temp_val1 = read_status`READ_DATA ;
3863
        temp_val2 = wmem_data[120 + i] ;
3864
 
3865
        // last write to this address was with only two byte enables - check only those
3866
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3867
        begin
3868
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3869
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3870
            ok = 0 ;
3871
        end
3872
    end
3873
 
3874
    if ( ok )
3875
        test_ok ;
3876
 
3877
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3878
    ok = 1 ;
3879
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3880
    if ( temp_val1[29] !== 0 )
3881
    begin
3882
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3883
        $display("Received Master Abort bit was set with no reason!") ;
3884
        test_fail("Received Master Abort bit was set with no reason") ;
3885
        ok = 0 ;
3886
    end
3887
 
3888
    if ( temp_val1[28] !== 1 )
3889
    begin
3890
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3891
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3892
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3893
        ok = 0 ;
3894
    end
3895
 
3896
    if ( ok )
3897
       test_ok ;
3898
 
3899
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3900
 
3901
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3902
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3903
 
3904
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3905
    for ( i = 0 ; i < 3 ; i = i + 1 )
3906
    begin
3907
        read_data`READ_ADDRESS = target_address + 4*i ;
3908
        read_data`READ_SEL     = 4'b1111 ;
3909
        wishbone_master.blk_read_data_in[i] = read_data ;
3910
    end
3911
 
3912
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3913
 
3914
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3915
 
3916
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3917
    begin
3918
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3919
        $display("Complete burst read through WB slave didn't succeed!") ;
3920
        test_fail("bridge didn't process Burst Read in an expected way") ;
3921
        disable main ;
3922
    end
3923
    else
3924
        test_ok ;
3925
 
3926
    // test error on IO write
3927
    // change base address
3928
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3929
    write_data`WRITE_SEL     = 4'b0101 ;
3930
    write_data`WRITE_ADDRESS = target_address ;
3931
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3932
 
3933
    write_flags`WB_TRANSFER_CAB    = 0 ;
3934
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3935
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3936
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3937
    fork
3938
    begin
3939
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3940
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3941
        begin
3942
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3943
            $display("WB slave failed to accept IO write!") ;
3944
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3945
            disable main ;
3946
        end
3947
    end
3948
    begin
3949
        musnt_respond(ok) ;
3950
        if ( ok !== 1 )
3951
        begin
3952
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3953
            $display("Testbench is configured wrong!") ;
3954
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3955
        end
3956
        else
3957
            test_ok ;
3958
    end
3959
    join
3960
 
3961
    // check statuses and everything else
3962
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3963
    ok = 1 ;
3964
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3965
    if ( temp_val1[8] !== 1 )
3966
    begin
3967
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3968
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3969
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3970
        ok = 0 ;
3971
    end
3972
 
3973
    if ( temp_val1[9] !== 1 )
3974
    begin
3975
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3976
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3977
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3978
        ok = 0 ;
3979
    end
3980
 
3981
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3982
    begin
3983
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3984
        $display("Value in W_ERR_CS register was wrong!") ;
3985
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3986
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3987
        ok = 0 ;
3988
    end
3989
 
3990
    if ( ok )
3991
        test_ok ;
3992
 
3993
    // check erroneous address and data
3994
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3995
    ok = 1 ;
3996
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3997
    if ( temp_val1 !== target_address )
3998
    begin
3999
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4000
        $display("Value in W_ERR_ADDR register was wrong!") ;
4001
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
4002
        test_fail("WB Erroneous Address register didn't provide right value") ;
4003
        ok = 0 ;
4004
    end
4005
 
4006
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
4007
    if ( temp_val1 !== 32'hAAAA_AAAA )
4008
    begin
4009
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4010
        $display("Value in W_ERR_DATA register was wrong!") ;
4011
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
4012
        test_fail("WB Erroneous Data register didn't provide right value") ;
4013
        ok = 0 ;
4014
    end
4015
 
4016
    if ( ok )
4017
        test_ok ;
4018
 
4019
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4020
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
4021
    if ( temp_val1[1] !== 1 )
4022
    begin
4023
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4024
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
4025
        test_fail("expected interrupt status bit was not set") ;
4026
    end
4027
    else
4028
        test_ok ;
4029
 
4030
    // clear interrupts and errors
4031
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
4032
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
4033
 
4034
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
4035
    ok = 1 ;
4036
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4037
    if ( temp_val1[29] !== 1 )
4038
    begin
4039
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4040
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
4041
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
4042
        ok = 0 ;
4043
    end
4044
 
4045
    if ( temp_val1[28] !== 0 )
4046
    begin
4047
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
4048
        $display("Received Target Abort bit was set for no reason!") ;
4049
        test_fail("Received Target Abort bit was set for no reason") ;
4050
        ok = 0 ;
4051
    end
4052
 
4053
    if ( ok )
4054
        test_ok ;
4055
 
4056
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4057
 
4058
    // disable image
4059
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4060
    if ( ok !== 1 )
4061
    begin
4062
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4063
        test_fail("WB Image Address Mask register couldn't be written") ;
4064
        disable main ;
4065
    end
4066
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4067
 
4068
end
4069
endtask
4070
 
4071
task parity_checking ;
4072
    reg   [11:0] ctrl_offset ;
4073
    reg   [11:0] ba_offset ;
4074
    reg   [11:0] am_offset ;
4075
    reg   [11:0] ta_offset ;
4076
    reg `WRITE_STIM_TYPE write_data ;
4077
    reg `READ_STIM_TYPE  read_data ;
4078
    reg `READ_RETURN_TYPE read_status ;
4079
 
4080
    reg `WRITE_RETURN_TYPE write_status ;
4081
    reg `WB_TRANSFER_FLAGS write_flags ;
4082
    reg [31:0] temp_val1 ;
4083
    reg [31:0] temp_val2 ;
4084
    reg        ok   ;
4085
    reg [11:0] pci_ctrl_offset ;
4086
    reg [31:0] image_base ;
4087
    reg [31:0] target_address ;
4088
    reg [11:0] icr_offset ;
4089
    reg [11:0] isr_offset ;
4090
    reg [11:0] p_ba_offset ;
4091
    reg [11:0] p_am_offset ;
4092
    reg [11:0] p_ctrl_offset ;
4093
    integer    i ;
4094
    reg        perr_asserted ;
4095
begin:main
4096
    $display("******************************* Testing Parity Checker functions ********************************") ;
4097
    $display("Testing Parity Errors during Master Transactions!") ;
4098
    $display("Introducing Parity Erros to Master Writes!") ;
4099
    $fdisplay(pci_mon_log_file_desc,
4100
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4101
 
4102
    // image 1 is used for error testing, since it is always implemented
4103
    pci_ctrl_offset = 12'h004 ;
4104
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4105
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4106
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4107
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4108
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4109
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4110
 
4111
    // image 1 for PCI target
4112
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4113
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4114
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4115
 
4116
    target_address  = `BEH_TAR1_MEM_START ;
4117
    image_base      = 0 ;
4118
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4119
 
4120
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4121
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4122
    write_flags                    = 0 ;
4123
    write_flags`INIT_WAITS         = tb_init_waits ;
4124
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4125
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4126
 
4127
    // enable master & target operation and disable parity functions
4128
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4129
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4130
    if ( ok !== 1 )
4131
    begin
4132
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4133
        test_fail("PCI Device Control register could not be written to") ;
4134
        disable main ;
4135
    end
4136
 
4137
    // prepare image control register
4138
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4139
    if ( ok !== 1 )
4140
    begin
4141
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4142
        test_fail("WB Image Control register could not be written to") ;
4143
        disable main ;
4144
    end
4145
 
4146
    // prepare base address register
4147
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4148
    if ( ok !== 1 )
4149
    begin
4150
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4151
        test_fail("WB Image Base Address register could not be written to") ;
4152
        disable main ;
4153
    end
4154
 
4155
    // write address mask register
4156
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4157
    if ( ok !== 1 )
4158
    begin
4159
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4160
        test_fail("WB Image Address Mask register could not be written to") ;
4161
        disable main ;
4162
    end
4163
 
4164
    // disable parity interrupts
4165
    config_write( icr_offset, 0, 4'hF, ok ) ;
4166
    if ( ok !== 1 )
4167
    begin
4168
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4169
        test_fail("Interrupt Control register could not be written to") ;
4170
        disable main ;
4171
    end
4172
 
4173
    write_data`WRITE_ADDRESS = target_address ;
4174
    write_data`WRITE_DATA    = wmem_data[0] ;
4175
    write_data`WRITE_SEL     = 4'b1111 ;
4176
 
4177
    // enable target's 1 response to parity errors
4178 45 mihad
    configuration_cycle_write(0,                        // bus number
4179
                              `TAR1_IDSEL_INDEX - 11,   // device number
4180
                              0,                        // function number
4181
                              1,                        // register number
4182
                              0,                        // type of configuration cycle
4183
                              4'b0001,                  // byte enables
4184
                              32'h0000_0047             // data
4185 15 mihad
                             ) ;
4186
 
4187
    // disable target's 2 response to parity errors
4188 45 mihad
    configuration_cycle_write(0,                        // bus number
4189
                              `TAR2_IDSEL_INDEX - 11,   // device number
4190
                              0,                        // function number
4191
                              1,                        // register number
4192
                              0,                        // type of configuration cycle
4193
                              4'b0001,                  // byte enables
4194
                              32'h0000_0007             // data
4195 15 mihad
                             ) ;
4196
 
4197
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4198
 
4199
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4200
    fork
4201
    begin
4202
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4203
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4204
        begin
4205
            $display("Parity checker testing failed! Time %t ", $time) ;
4206
            $display("Bridge failed to process single memory write!") ;
4207
            test_fail("bridge failed to post single WB memory write") ;
4208
            disable main ;
4209
        end
4210
    end
4211
    begin:wait_perr1
4212
        perr_asserted = 0 ;
4213
        @(posedge pci_clock) ;
4214
 
4215 35 mihad
        while ( PERR !== 0 )
4216 15 mihad
            @(posedge pci_clock) ;
4217
 
4218 35 mihad
        perr_asserted = 1 ;
4219 15 mihad
 
4220
    end
4221
    begin
4222
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4223
 
4224
        if ( ok !== 1 )
4225
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4226
 
4227 35 mihad
        repeat(2)
4228 15 mihad
            @(posedge pci_clock) ;
4229
 
4230 35 mihad
        #1 ;
4231
        if ( !perr_asserted )
4232
            disable wait_perr1 ;
4233 15 mihad
    end
4234
    join
4235
 
4236
    if ( perr_asserted && ok )
4237
    begin
4238
        test_ok ;
4239
    end
4240
    else
4241
    if ( ~perr_asserted )
4242
    begin
4243
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4244
        disable main ;
4245
    end
4246
 
4247
    // check all the statuses - if HOST is defined, wait for them to be synced
4248
    `ifdef HOST
4249
    repeat(4)
4250
        @(posedge wb_clock) ;
4251
    `endif
4252
 
4253
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4254
    ok = 1 ;
4255
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4256 45 mihad
    if ( temp_val1[31] !== 0 )
4257 15 mihad
    begin
4258
        $display("Parity checker testing failed! Time %t ", $time) ;
4259 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4260
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4261 15 mihad
        ok = 0 ;
4262
    end
4263
 
4264
    if ( temp_val1[30] !== 0 )
4265
    begin
4266
        $display("Parity checker testing failed! Time %t ", $time) ;
4267
        $display("Signalled System Error bit was set for no reason!") ;
4268
        test_fail("Signalled System Error bit was set for no reason") ;
4269
        ok = 0 ;
4270
    end
4271
 
4272
    if ( temp_val1[24] !== 0 )
4273
    begin
4274
        $display("Parity checker testing failed! Time %t ", $time) ;
4275
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4276
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4277
        ok = 0 ;
4278
    end
4279
 
4280
    if ( ok )
4281
        test_ok ;
4282
 
4283
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4284
    // clear parity bits and enable parity response
4285
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4286
    if ( ok !== 1 )
4287
    begin
4288
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4289
        test_fail("write to PCI Status Register failed") ;
4290
        disable main ;
4291
    end
4292
 
4293
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4294
    fork
4295
    begin
4296
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4297
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4298
        begin
4299
            $display("Parity checker testing failed! Time %t ", $time) ;
4300
            $display("Bridge failed to process single memory write!") ;
4301
            test_fail("bridge failed to post single memory write") ;
4302
            disable main ;
4303
        end
4304
    end
4305
    begin:wait_perr2
4306
        perr_asserted = 0 ;
4307
        @(posedge pci_clock) ;
4308
 
4309 35 mihad
        while ( PERR !== 0 )
4310 15 mihad
            @(posedge pci_clock) ;
4311
 
4312 35 mihad
        perr_asserted = 1 ;
4313 15 mihad
 
4314
    end
4315
    begin
4316
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4317
 
4318
        if ( ok !== 1 )
4319
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4320
 
4321 35 mihad
        repeat(2)
4322 15 mihad
            @(posedge pci_clock) ;
4323
 
4324 35 mihad
        #1 ;
4325
        if (!perr_asserted)
4326
            disable wait_perr2 ;
4327 15 mihad
    end
4328
    join
4329
 
4330
    if ( perr_asserted && ok )
4331
    begin
4332
        test_ok ;
4333
    end
4334
    else
4335
    if ( ~perr_asserted )
4336
    begin
4337
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4338
        disable main ;
4339
    end
4340
 
4341
    // check all the statuses - if HOST is defined, wait for them to be synced
4342
    `ifdef HOST
4343
    repeat(4)
4344
        @(posedge wb_clock) ;
4345
    `endif
4346
 
4347
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4348
    ok = 1 ;
4349
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4350 45 mihad
    if ( temp_val1[31] !== 0 )
4351 15 mihad
    begin
4352
        $display("Parity checker testing failed! Time %t ", $time) ;
4353 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4354
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4355 15 mihad
        ok = 0 ;
4356
    end
4357
 
4358
    if ( temp_val1[30] !== 0 )
4359
    begin
4360
        $display("Parity checker testing failed! Time %t ", $time) ;
4361
        $display("Signalled System Error bit was set for no reason!") ;
4362
        test_fail("Signalled System Error bit was set for no reason") ;
4363
        ok = 0 ;
4364
    end
4365
 
4366
    if ( temp_val1[24] !== 1 )
4367
    begin
4368
        $display("Parity checker testing failed! Time %t ", $time) ;
4369 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!") ;
4370
        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") ;
4371 15 mihad
        ok = 0 ;
4372
    end
4373
 
4374
    if ( ok )
4375
        test_ok ;
4376
 
4377
    // clear status bits and disable parity error response
4378
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4379
 
4380
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4381
 
4382
    // disable perr generation and perform a write - no bits should be set
4383
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4384
    fork
4385
    begin
4386
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4387
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4388
        begin
4389
            $display("Parity checker testing failed! Time %t ", $time) ;
4390
            $display("Bridge failed to process single memory write!") ;
4391
            test_fail("bridge failed to post single memory write") ;
4392
            disable main ;
4393
        end
4394
    end
4395
    begin
4396
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4397
 
4398
        if ( ok !== 1 )
4399
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4400
        else
4401
            test_ok ;
4402
 
4403
        repeat(3)
4404
            @(posedge pci_clock) ;
4405
    end
4406
    join
4407
 
4408
    `ifdef HOST
4409
    repeat(4)
4410
        @(posedge wb_clock) ;
4411
    `endif
4412
 
4413
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4414
    ok = 1 ;
4415
 
4416
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4417
    if ( temp_val1[31] !== 0 )
4418
    begin
4419
        $display("Parity checker testing failed! Time %t ", $time) ;
4420
        $display("Detected Parity Error bit was set for no reason!") ;
4421
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4422
        ok = 0 ;
4423
    end
4424
 
4425
    if ( temp_val1[30] !== 0 )
4426
    begin
4427
        $display("Parity checker testing failed! Time %t ", $time) ;
4428
        $display("Signalled System Error bit was set for no reason!") ;
4429
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4430
        ok = 0 ;
4431
    end
4432
 
4433
    if ( temp_val1[24] !== 0 )
4434
    begin
4435
        $display("Parity checker testing failed! Time %t ", $time) ;
4436
        $display("Master Data Parity Error bit was set for no reason!") ;
4437
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4438
        ok = 0 ;
4439
    end
4440
 
4441
    if ( ok )
4442
        test_ok ;
4443
 
4444
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4445
 
4446
    read_data = 0 ;
4447
    read_data`READ_ADDRESS  = target_address ;
4448
    read_data`READ_SEL      = 4'hF ;
4449
    read_data`READ_TAG_STIM = 0 ;
4450
 
4451
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4452
 
4453
    // enable parity and system error interrupts
4454
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4455
 
4456
    // enable parity error response
4457
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4458
 
4459
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4460
 
4461
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4462
    fork
4463
    begin
4464
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4465
    end
4466
    begin:wait_perr4
4467
        perr_asserted = 0 ;
4468
        @(posedge pci_clock) ;
4469 35 mihad
        while ( PERR !== 0 )
4470 15 mihad
            @(posedge pci_clock) ;
4471
 
4472 35 mihad
        perr_asserted = 1 ;
4473 15 mihad
 
4474
    end
4475
    begin
4476
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4477
 
4478
        if ( ok !== 1 )
4479
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4480
 
4481
        repeat(2)
4482
            @(posedge pci_clock) ;
4483
 
4484 35 mihad
        #1 ;
4485
        if ( !perr_asserted )
4486
            disable wait_perr4 ;
4487 15 mihad
    end
4488
    join
4489
 
4490
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4491
    begin
4492
        $display("Parity checker testing failed! Time %t ", $time) ;
4493
        $display("Bridge failed to process single memory read!") ;
4494
        test_fail("bridge didn't process single memory read correctly") ;
4495
        ok = 0 ;
4496
    end
4497
 
4498
    if ( perr_asserted && ok )
4499
    begin
4500
        test_ok ;
4501
    end
4502
    else
4503
    if ( ~perr_asserted )
4504
    begin
4505
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4506
        disable main ;
4507
    end
4508
 
4509
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4510
    // interrupt should also be present
4511
    `ifdef HOST
4512
        repeat(4)
4513 26 mihad
            @(posedge pci_clock) ;
4514
        repeat(4)
4515 15 mihad
            @(posedge wb_clock) ;
4516
 
4517
        if ( INT_O !== 1 )
4518
        begin
4519
            $display("Parity checker testing failed! Time %t ", $time) ;
4520
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4521
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4522
        end
4523
        else
4524
            test_ok ;
4525
    `else
4526
    `ifdef GUEST
4527 26 mihad
        repeat(4)
4528
            @(posedge wb_clock) ;
4529
        repeat(4)
4530 15 mihad
            @(posedge pci_clock) ;
4531
 
4532
        if ( INTA !== 1 )
4533
        begin
4534
            $display("Parity checker testing failed! Time %t ", $time) ;
4535
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4536
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4537
        end
4538
        else
4539
            test_ok ;
4540
    `endif
4541
    `endif
4542
 
4543
    // check statuses!
4544
 
4545
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4546
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4547
    ok = 1 ;
4548
 
4549
    if ( temp_val1[31] !== 1 )
4550
    begin
4551
        $display("Parity checker testing failed! Time %t ", $time) ;
4552 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4553
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4554 15 mihad
        ok = 0 ;
4555
    end
4556
 
4557
    if ( temp_val1[30] !== 0 )
4558
    begin
4559
        $display("Parity checker testing failed! Time %t ", $time) ;
4560
        $display("Signalled System Error bit was set for no reason!") ;
4561
        test_fail("Signalled System Error bit was set for no reason") ;
4562
        ok = 0 ;
4563
    end
4564
 
4565
    if ( temp_val1[24] !== 1 )
4566
    begin
4567
        $display("Parity checker testing failed! Time %t ", $time) ;
4568 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4569
        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") ;
4570 15 mihad
        ok = 0 ;
4571
    end
4572
 
4573
    if ( ok )
4574
        test_ok ;
4575
 
4576
    // clear statuses and disable parity error response
4577
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4578
 
4579
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4580
    ok = 1 ;
4581
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4582
 
4583
    if ( temp_val1[4] !== 0 )
4584
    begin
4585
        $display("Parity checker testing failed! Time %t ", $time) ;
4586
        $display("System error interrupt status bit set for no reason!") ;
4587
        test_fail("System error interrupt status bit set for no reason") ;
4588
        ok = 0 ;
4589
    end
4590
 
4591
    `ifdef HOST
4592
    if ( temp_val1[3] !== 1 )
4593
    begin
4594
        $display("Parity checker testing failed! Time %t ", $time) ;
4595
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4596
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4597
        ok = 0 ;
4598
    end
4599
    `else
4600
    if ( temp_val1[3] !== 0 )
4601
    begin
4602
        $display("Parity checker testing failed! Time %t ", $time) ;
4603
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4604
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4605
        ok = 0 ;
4606
    end
4607
    `endif
4608
 
4609
    if ( ok )
4610
        test_ok ;
4611
 
4612
    // clear int statuses
4613
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4614
 
4615
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4616
 
4617
    `ifdef HOST
4618
        repeat(4)
4619 26 mihad
            @(posedge pci_clock) ;
4620
        repeat(4)
4621 15 mihad
            @(posedge wb_clock) ;
4622
 
4623
        if ( INT_O !== 0 )
4624
        begin
4625
            $display("Parity checker testing failed! Time %t ", $time) ;
4626
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4627
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4628
        end
4629
        else
4630
            test_ok ;
4631
    `else
4632
    `ifdef GUEST
4633 26 mihad
        repeat(4)
4634
            @(posedge wb_clock) ;
4635
        repeat(4)
4636 15 mihad
            @(posedge pci_clock) ;
4637
 
4638
        if ( INTA !== 1 )
4639
        begin
4640
            $display("Parity checker testing failed! Time %t ", $time) ;
4641
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4642
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4643
        end
4644
        else
4645
            test_ok ;
4646
    `endif
4647
    `endif
4648
 
4649
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4650
 
4651
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4652
    fork
4653
    begin
4654
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4655
    end
4656
    begin:wait_perr5
4657
        perr_asserted = 0 ;
4658
        @(posedge pci_clock) ;
4659
        while ( PERR === 1 )
4660
            @(posedge pci_clock) ;
4661
 
4662
        perr_asserted = 1 ;
4663
        $display("Parity checker testing failed! Time %t ", $time) ;
4664 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4665
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4666 15 mihad
    end
4667
    begin
4668
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4669
        if ( ok !== 1 )
4670
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4671
 
4672
        // perr can be asserted on idle or next PCI address phase
4673
        repeat(2)
4674
            @(posedge pci_clock) ;
4675
 
4676 35 mihad
        #1 ;
4677
        if ( !perr_asserted )
4678
            disable wait_perr5 ;
4679 15 mihad
    end
4680
    join
4681
 
4682
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4683
    begin
4684
        $display("Parity checker testing failed! Time %t ", $time) ;
4685
        $display("Bridge failed to process single memory read!") ;
4686
        test_fail("bridge failed to process single memory read correctly") ;
4687
        ok = 0 ;
4688
    end
4689
 
4690
    if ( ok && !perr_asserted)
4691
        test_ok ;
4692
 
4693
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4694
 
4695
    // interrupts should not be present
4696
    `ifdef HOST
4697
        repeat( 4 )
4698 26 mihad
            @(posedge pci_clock) ;
4699
        repeat( 4 )
4700 15 mihad
            @(posedge wb_clock) ;
4701
        if ( INT_O !== 0 )
4702
        begin
4703
            $display("Parity checker testing failed! Time %t ", $time) ;
4704
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4705
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4706
        end
4707
        else
4708
            test_ok ;
4709
    `else
4710
    `ifdef GUEST
4711
        repeat( 4 )
4712 26 mihad
            @(posedge wb_clock) ;
4713
        repeat( 4 )
4714 15 mihad
            @(posedge pci_clock) ;
4715
        if ( INTA !== 1 )
4716
        begin
4717
            $display("Parity checker testing failed! Time %t ", $time) ;
4718
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4719
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4720
        end
4721
        else
4722
            test_ok ;
4723
    `endif
4724
    `endif
4725
 
4726
    // check statuses!
4727
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4728
    ok = 1 ;
4729
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4730
    if ( temp_val1[31] !== 1 )
4731
    begin
4732
        $display("Parity checker testing failed! Time %t ", $time) ;
4733 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4734 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4735
        ok = 0 ;
4736
    end
4737
 
4738
    if ( temp_val1[30] !== 0 )
4739
    begin
4740
        $display("Parity checker testing failed! Time %t ", $time) ;
4741
        $display("Signalled System Error bit was set for no reason!") ;
4742
        test_fail("Signalled System Error bit was set for no reason") ;
4743
        ok = 0 ;
4744
    end
4745
 
4746
    if ( temp_val1[24] !== 0 )
4747
    begin
4748
        $display("Parity checker testing failed! Time %t ", $time) ;
4749 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4750 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4751
        ok = 0 ;
4752
    end
4753
 
4754
    if ( ok )
4755
        test_ok ;
4756
 
4757
    // clear statuses
4758
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4759
 
4760
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4761
    ok = 1 ;
4762
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4763
 
4764
    if ( temp_val1[4] !== 0 )
4765
    begin
4766
        $display("Parity checker testing failed! Time %t ", $time) ;
4767
        $display("System error interrupt status bit set for no reason!") ;
4768
        test_fail("System error interrupt status bit set for no reason") ;
4769
        ok = 0 ;
4770
    end
4771
 
4772
    if ( temp_val1[3] !== 0 )
4773
    begin
4774
        $display("Parity checker testing failed! Time %t ", $time) ;
4775
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4776
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4777
        ok = 0 ;
4778
    end
4779
 
4780
    if ( ok )
4781
        test_ok ;
4782
 
4783
    // enable all responses to parity errors!
4784
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4785
 
4786
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4787
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4788
 
4789
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4790
 
4791
    // repeat a read
4792
    fork
4793
    begin
4794
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4795
    end
4796
    begin:wait_perr6
4797
        perr_asserted = 0 ;
4798
        @(posedge pci_clock) ;
4799
        while ( PERR === 1 )
4800
            @(posedge pci_clock) ;
4801
 
4802
        perr_asserted = 1 ;
4803
        $display("Parity checker testing failed! Time %t ", $time) ;
4804
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4805
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4806
    end
4807
    begin
4808
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4809
        if ( ok !== 1 )
4810
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4811
 
4812
        repeat(2)
4813
            @(posedge pci_clock) ;
4814
 
4815 35 mihad
        #1 ;
4816
        if ( !perr_asserted )
4817
            disable wait_perr6 ;
4818 15 mihad
    end
4819
    join
4820
 
4821
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4822
    begin
4823
        $display("Parity checker testing failed! Time %t ", $time) ;
4824
        $display("Bridge failed to process single memory read!") ;
4825
        test_fail("bridge didn't process single memory read as expected") ;
4826
        ok = 0 ;
4827
    end
4828
 
4829
    if ( ok && !perr_asserted)
4830
        test_ok ;
4831
 
4832
    // check statuses!
4833
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4834
    ok = 1 ;
4835
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4836
    if ( temp_val1[31] !== 0 )
4837
    begin
4838
        $display("Parity checker testing failed! Time %t ", $time) ;
4839
        $display("Detected Parity Error bit was set for no reason!") ;
4840
        test_fail("Detected Parity Error bit was set for no reason") ;
4841
        ok = 0 ;
4842
    end
4843
 
4844
    if ( temp_val1[30] !== 0 )
4845
    begin
4846
        $display("Parity checker testing failed! Time %t ", $time) ;
4847
        $display("Signalled System Error bit was set for no reason!") ;
4848
        test_fail("Signalled System Error bit was set for no reason") ;
4849
        ok = 0 ;
4850
    end
4851
 
4852
    if ( temp_val1[24] !== 0 )
4853
    begin
4854
        $display("Parity checker testing failed! Time %t ", $time) ;
4855
        $display("Master Data Parity Error bit was set for no reason!") ;
4856
        test_fail("Master Data Parity Error bit was set for no reason") ;
4857
        ok = 0 ;
4858
    end
4859
 
4860
    if ( ok )
4861
        test_ok ;
4862
 
4863
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4864
    ok = 1 ;
4865
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4866
 
4867
    if ( temp_val1[4] !== 0 )
4868
    begin
4869
        $display("Parity checker testing failed! Time %t ", $time) ;
4870
        $display("System error interrupt status bit set for no reason!") ;
4871
        test_fail("System error interrupt status bit set for no reason") ;
4872
        ok = 0 ;
4873
    end
4874
 
4875
    if ( temp_val1[3] !== 0 )
4876
    begin
4877
        $display("Parity checker testing failed! Time %t ", $time) ;
4878
        $display("Parity error interrupt status bit set for no reason!") ;
4879
        test_fail("Parity error interrupt status bit set for no reason") ;
4880
        ok = 0 ;
4881
    end
4882
 
4883
    if ( ok )
4884
        test_ok ;
4885
 
4886
    $display("Presenting address parity error on PCI bus!") ;
4887
    // enable parity errors - this should not affect system errors
4888
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4889
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4890
 
4891
    // perform PCI write
4892
    // check transaction progress
4893
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4894
    fork
4895
    begin
4896
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4897
               target_address, 32'h1234_5678,
4898
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4899
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4900
        do_pause( 1 ) ;
4901
    end
4902
    begin:wait_serr7
4903
        perr_asserted = 0 ;
4904
        @(posedge pci_clock) ;
4905
        while( SERR === 1 )
4906
            @(posedge pci_clock) ;
4907
 
4908
        perr_asserted = 1 ;
4909
        $display("Parity checker testing failed! Time %t ", $time) ;
4910
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4911
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4912
    end
4913
    begin
4914
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4915
        if ( ok !== 1 )
4916
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4917
 
4918 35 mihad
        if ( !perr_asserted )
4919
            disable wait_serr7 ;
4920 15 mihad
    end
4921
    join
4922
 
4923
    if ( ok && !perr_asserted)
4924
        test_ok ;
4925
 
4926
    // check statuses!
4927
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4928
    ok = 1 ;
4929
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4930
    if ( temp_val1[31] !== 1 )
4931
    begin
4932
        $display("Parity checker testing failed! Time %t ", $time) ;
4933
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4934
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4935
        ok = 0 ;
4936
    end
4937
 
4938
    if ( temp_val1[30] !== 0 )
4939
    begin
4940
        $display("Parity checker testing failed! Time %t ", $time) ;
4941
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4942
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4943
        ok = 0 ;
4944
    end
4945
 
4946
    if ( temp_val1[24] !== 0 )
4947
    begin
4948
        $display("Parity checker testing failed! Time %t ", $time) ;
4949
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4950
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4951
        ok = 0 ;
4952
    end
4953
 
4954
    if ( ok )
4955
        test_ok ;
4956
 
4957
    // clear statuses
4958
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4959
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4960
    fork
4961
    begin
4962
        ipci_unsupported_commands_master.master_reference
4963
        (
4964
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4965
            32'h5555_5555,      // second part of address in dual address cycle
4966
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4967
            `BC_MEM_WRITE,      // normal command
4968
            4'h0,               // byte enables
4969
            32'h1234_5678,      // data
4970
            1'b1,               // make address parity error on first phase of dual address
4971
            1'b0,               // make address parity error on second phase of dual address
4972
            ok                  // result of operation
4973
        ) ;
4974 35 mihad
        if ( !perr_asserted )
4975
            disable wait_serr8 ;
4976 15 mihad
    end
4977
    begin:wait_serr8
4978
        perr_asserted = 0 ;
4979
        @(posedge pci_clock) ;
4980
        while( SERR === 1 )
4981
            @(posedge pci_clock) ;
4982
 
4983
        perr_asserted = 1 ;
4984
        $display("Parity checker testing failed! Time %t ", $time) ;
4985
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4986
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4987
    end
4988
    join
4989
 
4990
    if ( ok && !perr_asserted)
4991
        test_ok ;
4992
 
4993
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4994
    fork
4995
    begin
4996
        ipci_unsupported_commands_master.master_reference
4997
        (
4998
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4999
            32'h5555_5555,      // second part of address in dual address cycle
5000
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5001
            `BC_MEM_WRITE,      // normal command
5002
            4'h0,               // byte enables
5003
            32'h1234_5678,      // data
5004
            1'b0,               // make address parity error on first phase of dual address
5005
            1'b1,               // make address parity error on second phase of dual address
5006
            ok                  // result of operation
5007
        ) ;
5008 35 mihad
        if ( !perr_asserted )
5009
            disable wait_serr9 ;
5010 15 mihad
    end
5011
    begin:wait_serr9
5012
        perr_asserted = 0 ;
5013
        @(posedge pci_clock) ;
5014
        while( SERR === 1 )
5015
            @(posedge pci_clock) ;
5016
 
5017
        perr_asserted = 1 ;
5018
        $display("Parity checker testing failed! Time %t ", $time) ;
5019
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5020
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5021
    end
5022
    join
5023
 
5024
    if ( ok && !perr_asserted)
5025
        test_ok ;
5026
 
5027
    // check statuses!
5028
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5029
    ok = 1 ;
5030
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5031
    if ( temp_val1[31] !== 1 )
5032
    begin
5033
        $display("Parity checker testing failed! Time %t ", $time) ;
5034
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5035
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5036
        ok = 0 ;
5037
    end
5038
 
5039
    if ( temp_val1[30] !== 0 )
5040
    begin
5041
        $display("Parity checker testing failed! Time %t ", $time) ;
5042
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5043
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5044
        ok = 0 ;
5045
    end
5046
 
5047
    if ( temp_val1[24] !== 0 )
5048
    begin
5049
        $display("Parity checker testing failed! Time %t ", $time) ;
5050
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5051
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5052
        ok = 0 ;
5053
    end
5054
 
5055
    if ( ok )
5056
        test_ok ;
5057
 
5058
    // clear statuses
5059
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5060
 
5061
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5062
    fork
5063
    begin
5064
        ipci_unsupported_commands_master.master_reference
5065
        (
5066
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5067
            32'h5555_5555,      // second part of address in dual address cycle
5068
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5069
            `BC_MEM_WRITE,      // normal command
5070
            4'h0,               // byte enables
5071
            32'h1234_5678,      // data
5072
            1'b1,               // make address parity error on first phase of dual address
5073
            1'b1,               // make address parity error on second phase of dual address
5074
            ok                  // result of operation
5075
        ) ;
5076 35 mihad
        if ( !perr_asserted )
5077
            disable wait_serr10 ;
5078 15 mihad
    end
5079
    begin:wait_serr10
5080
        perr_asserted = 0 ;
5081
        @(posedge pci_clock) ;
5082
        while( SERR === 1 )
5083
            @(posedge pci_clock) ;
5084
 
5085
        perr_asserted = 1 ;
5086
        $display("Parity checker testing failed! Time %t ", $time) ;
5087
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5088
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5089
    end
5090
    join
5091
 
5092
    if ( ok && !perr_asserted)
5093
        test_ok ;
5094
 
5095
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5096
 
5097
    `ifdef HOST
5098
        repeat(4)
5099 26 mihad
            @(posedge pci_clock) ;
5100
        repeat(4)
5101 15 mihad
            @(posedge wb_clock) ;
5102
        if ( INT_O !== 0 )
5103
        begin
5104
            $display("Parity checker testing failed! Time %t ", $time) ;
5105
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5106
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5107
        end
5108
        else
5109
            test_ok ;
5110
    `else
5111
    `ifdef GUEST
5112 26 mihad
        repeat(4)
5113
            @(posedge wb_clock) ;
5114
        repeat(4)
5115 15 mihad
            @(posedge pci_clock) ;
5116
 
5117
        if ( INTA !== 1 )
5118
        begin
5119
            $display("Parity checker testing failed! Time %t ", $time) ;
5120
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5121
            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") ;
5122
        end
5123
        else
5124
            test_ok ;
5125
    `endif
5126
    `endif
5127
 
5128
    // check statuses!
5129
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5130
    ok = 1 ;
5131
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5132
    if ( temp_val1[31] !== 1 )
5133
    begin
5134
        $display("Parity checker testing failed! Time %t ", $time) ;
5135
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5136
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5137
        ok = 0 ;
5138
    end
5139
 
5140
    if ( temp_val1[30] !== 0 )
5141
    begin
5142
        $display("Parity checker testing failed! Time %t ", $time) ;
5143
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5144
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5145
        ok = 0 ;
5146
    end
5147
 
5148
    if ( temp_val1[24] !== 0 )
5149
    begin
5150
        $display("Parity checker testing failed! Time %t ", $time) ;
5151
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5152
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5153
        ok = 0 ;
5154
    end
5155
 
5156
    if ( ok )
5157
        test_ok ;
5158
 
5159
    // clear statuses
5160
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5161
 
5162
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5163
    ok = 1 ;
5164
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5165
 
5166
    if ( temp_val1[4] !== 0 )
5167
    begin
5168
        $display("Parity checker testing failed! Time %t ", $time) ;
5169
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5170
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5171
        ok = 0 ;
5172
    end
5173
 
5174
    if ( temp_val1[3] !== 0 )
5175
    begin
5176
        $display("Parity checker testing failed! Time %t ", $time) ;
5177
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5178
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5179
        ok = 0 ;
5180
    end
5181
 
5182
    if ( ok )
5183
        test_ok ;
5184
 
5185
    // now enable system error signaling and test response
5186
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5187
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5188
 
5189
    fork
5190
    begin
5191
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5192
               target_address, 32'h1234_5678,
5193
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5194
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5195
        do_pause( 1 ) ;
5196
    end
5197
    begin:wait_serr11
5198
        perr_asserted = 0 ;
5199
        @(posedge pci_clock) ;
5200 35 mihad
        while( SERR !== 0 )
5201 15 mihad
            @(posedge pci_clock) ;
5202
 
5203 35 mihad
        perr_asserted = 1 ;
5204 15 mihad
    end
5205
    begin
5206
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5207
        if ( ok !== 1 )
5208
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5209
 
5210
        @(posedge pci_clock) ;
5211 35 mihad
        #1 ;
5212
        if ( !perr_asserted )
5213
            disable wait_serr11 ;
5214 15 mihad
    end
5215
    join
5216
 
5217
    if ( ok && perr_asserted)
5218
        test_ok ;
5219
    else
5220
    if ( !perr_asserted )
5221
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5222
 
5223
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5224
 
5225
    `ifdef HOST
5226
        repeat(4)
5227 26 mihad
            @(posedge pci_clock) ;
5228
        repeat(4)
5229 15 mihad
            @(posedge wb_clock) ;
5230
        if ( INT_O !== 1 )
5231
        begin
5232
            $display("Parity checker testing failed! Time %t ", $time) ;
5233
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5234
            test_fail("Interrupt Request was not triggered as expected") ;
5235
        end
5236
        else
5237
            test_ok ;
5238
    `else
5239
    `ifdef GUEST
5240 26 mihad
        repeat(4)
5241
            @(posedge wb_clock) ;
5242
        repeat(4)
5243 15 mihad
            @(posedge pci_clock) ;
5244
 
5245
        if ( INTA !== 1 )
5246
        begin
5247
            $display("Parity checker testing failed! Time %t ", $time) ;
5248
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5249
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5250
        end
5251
        else
5252
            test_ok ;
5253
    `endif
5254
    `endif
5255
 
5256
    // check statuses!
5257
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5258
    ok = 1 ;
5259
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5260
    if ( temp_val1[31] !== 1 )
5261
    begin
5262
        $display("Parity checker testing failed! Time %t ", $time) ;
5263
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5264
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5265
        ok = 0 ;
5266
    end
5267
 
5268
    if ( temp_val1[30] !== 1 )
5269
    begin
5270
        $display("Parity checker testing failed! Time %t ", $time) ;
5271
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5272
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5273
        ok = 0 ;
5274
    end
5275
 
5276
    if ( temp_val1[24] !== 0 )
5277
    begin
5278
        $display("Parity checker testing failed! Time %t ", $time) ;
5279
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5280
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5281
        ok = 0 ;
5282
    end
5283
 
5284
    if ( ok )
5285
        test_ok ;
5286
 
5287
    // clear statuses
5288
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5289
 
5290
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5291
 
5292
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5293
    ok = 1 ;
5294
 
5295
    `ifdef HOST
5296
    if ( temp_val1[4] !== 1 )
5297
    begin
5298
        $display("Parity checker testing failed! Time %t ", $time) ;
5299
        $display("System error interrupt status bit not set when expected!") ;
5300
        test_fail("System error interrupt status bit not set when expected") ;
5301
        ok = 0 ;
5302
    end
5303
    `else
5304
    if ( temp_val1[4] !== 0 )
5305
    begin
5306
        $display("Parity checker testing failed! Time %t ", $time) ;
5307
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5308
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5309
        ok = 0 ;
5310
    end
5311
    `endif
5312
 
5313
    if ( temp_val1[3] !== 0 )
5314
    begin
5315
        $display("Parity checker testing failed! Time %t ", $time) ;
5316
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5317
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5318
        ok = 0 ;
5319
    end
5320
 
5321
    if ( ok )
5322
        test_ok ;
5323
 
5324
    // clear statuses
5325
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5326
 
5327
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5328
    fork
5329
    begin
5330
        ipci_unsupported_commands_master.master_reference
5331
        (
5332
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5333
            32'h5555_5555,      // second part of address in dual address cycle
5334
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5335
            `BC_MEM_WRITE,      // normal command
5336
            4'h0,               // byte enables
5337
            32'h1234_5678,      // data
5338
            1'b1,               // make address parity error on first phase of dual address
5339
            1'b0,               // make address parity error on second phase of dual address
5340
            ok                  // result of operation
5341
        ) ;
5342 35 mihad
        if ( !perr_asserted )
5343
            disable wait_serr14 ;
5344 15 mihad
    end
5345
    begin:wait_serr14
5346
        perr_asserted = 0 ;
5347
        @(posedge pci_clock) ;
5348 35 mihad
        while( SERR !== 0 )
5349 15 mihad
            @(posedge pci_clock) ;
5350
 
5351 35 mihad
        perr_asserted = 1 ;
5352 15 mihad
    end
5353
    join
5354
 
5355
    if ( ok && perr_asserted)
5356
        test_ok ;
5357
    else
5358
    if ( !perr_asserted )
5359
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5360
 
5361
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5362
 
5363
    `ifdef HOST
5364
        repeat(4)
5365 26 mihad
            @(posedge pci_clock) ;
5366
        repeat(4)
5367 15 mihad
            @(posedge wb_clock) ;
5368
        if ( INT_O !== 1 )
5369
        begin
5370
            $display("Parity checker testing failed! Time %t ", $time) ;
5371
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5372
            test_fail("Interrupt Request was not triggered as expected") ;
5373
        end
5374
        else
5375
            test_ok ;
5376
    `else
5377
    `ifdef GUEST
5378 26 mihad
        repeat(4)
5379
            @(posedge wb_clock) ;
5380
        repeat(4)
5381 15 mihad
            @(posedge pci_clock) ;
5382
 
5383
        if ( INTA !== 1 )
5384
        begin
5385
            $display("Parity checker testing failed! Time %t ", $time) ;
5386
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5387
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5388
        end
5389
        else
5390
            test_ok ;
5391
    `endif
5392
    `endif
5393
 
5394
    // check statuses!
5395
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5396
    ok = 1 ;
5397
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5398
    if ( temp_val1[31] !== 1 )
5399
    begin
5400
        $display("Parity checker testing failed! Time %t ", $time) ;
5401
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5402
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5403
        ok = 0 ;
5404
    end
5405
 
5406
    if ( temp_val1[30] !== 1 )
5407
    begin
5408
        $display("Parity checker testing failed! Time %t ", $time) ;
5409
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5410
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5411
        ok = 0 ;
5412
    end
5413
 
5414
    if ( temp_val1[24] !== 0 )
5415
    begin
5416
        $display("Parity checker testing failed! Time %t ", $time) ;
5417
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5418
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5419
        ok = 0 ;
5420
    end
5421
 
5422
    if ( ok )
5423
        test_ok ;
5424
 
5425
    // clear statuses
5426
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5427
 
5428
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5429
 
5430
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5431
    ok = 1 ;
5432
 
5433
    `ifdef HOST
5434
    if ( temp_val1[4] !== 1 )
5435
    begin
5436
        $display("Parity checker testing failed! Time %t ", $time) ;
5437
        $display("System error interrupt status bit not set when expected!") ;
5438
        test_fail("System error interrupt status bit not set when expected") ;
5439
        ok = 0 ;
5440
    end
5441
    `else
5442
    if ( temp_val1[4] !== 0 )
5443
    begin
5444
        $display("Parity checker testing failed! Time %t ", $time) ;
5445
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5446
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5447
        ok = 0 ;
5448
    end
5449
    `endif
5450
 
5451
    if ( temp_val1[3] !== 0 )
5452
    begin
5453
        $display("Parity checker testing failed! Time %t ", $time) ;
5454
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5455
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5456
        ok = 0 ;
5457
    end
5458
 
5459
    if ( ok )
5460
        test_ok ;
5461
 
5462
    // clear statuses
5463
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5464
 
5465
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5466
    fork
5467
    begin
5468
        ipci_unsupported_commands_master.master_reference
5469
        (
5470
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5471
            32'h5555_5555,      // second part of address in dual address cycle
5472
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5473
            `BC_MEM_WRITE,      // normal command
5474
            4'h0,               // byte enables
5475
            32'h1234_5678,      // data
5476
            1'b0,               // make address parity error on first phase of dual address
5477
            1'b1,               // make address parity error on second phase of dual address
5478
            ok                  // result of operation
5479
        ) ;
5480 35 mihad
        if ( !perr_asserted )
5481
            disable wait_serr15 ;
5482 15 mihad
    end
5483
    begin:wait_serr15
5484
        perr_asserted = 0 ;
5485
        @(posedge pci_clock) ;
5486 35 mihad
        while( SERR !== 0 )
5487 15 mihad
            @(posedge pci_clock) ;
5488
 
5489 35 mihad
        perr_asserted = 1 ;
5490 15 mihad
    end
5491
    join
5492
 
5493
    if ( ok && perr_asserted)
5494
        test_ok ;
5495
    else
5496
    if ( !perr_asserted )
5497
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5498
 
5499
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5500
 
5501
    `ifdef HOST
5502
        repeat(4)
5503 26 mihad
            @(posedge pci_clock) ;
5504
        repeat(4)
5505 15 mihad
            @(posedge wb_clock) ;
5506
        if ( INT_O !== 1 )
5507
        begin
5508
            $display("Parity checker testing failed! Time %t ", $time) ;
5509
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5510
            test_fail("Interrupt Request was not triggered as expected") ;
5511
        end
5512
        else
5513
            test_ok ;
5514
    `else
5515
    `ifdef GUEST
5516 26 mihad
        repeat(4)
5517
            @(posedge wb_clock) ;
5518
        repeat(4)
5519 15 mihad
            @(posedge pci_clock) ;
5520
 
5521
        if ( INTA !== 1 )
5522
        begin
5523
            $display("Parity checker testing failed! Time %t ", $time) ;
5524
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5525
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5526
        end
5527
        else
5528
            test_ok ;
5529
    `endif
5530
    `endif
5531
 
5532
    // check statuses!
5533
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5534
    ok = 1 ;
5535
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5536
    if ( temp_val1[31] !== 1 )
5537
    begin
5538
        $display("Parity checker testing failed! Time %t ", $time) ;
5539
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5540
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5541
        ok = 0 ;
5542
    end
5543
 
5544
    if ( temp_val1[30] !== 1 )
5545
    begin
5546
        $display("Parity checker testing failed! Time %t ", $time) ;
5547
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5548
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5549
        ok = 0 ;
5550
    end
5551
 
5552
    if ( temp_val1[24] !== 0 )
5553
    begin
5554
        $display("Parity checker testing failed! Time %t ", $time) ;
5555
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5556
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5557
        ok = 0 ;
5558
    end
5559
 
5560
    if ( ok )
5561
        test_ok ;
5562
 
5563
    // clear statuses
5564
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5565
 
5566
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5567
 
5568
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5569
    ok = 1 ;
5570
 
5571
    `ifdef HOST
5572
    if ( temp_val1[4] !== 1 )
5573
    begin
5574
        $display("Parity checker testing failed! Time %t ", $time) ;
5575
        $display("System error interrupt status bit not set when expected!") ;
5576
        test_fail("System error interrupt status bit not set when expected") ;
5577
        ok = 0 ;
5578
    end
5579
    `else
5580
    if ( temp_val1[4] !== 0 )
5581
    begin
5582
        $display("Parity checker testing failed! Time %t ", $time) ;
5583
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5584
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5585
        ok = 0 ;
5586
    end
5587
    `endif
5588
 
5589
    if ( temp_val1[3] !== 0 )
5590
    begin
5591
        $display("Parity checker testing failed! Time %t ", $time) ;
5592
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5593
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5594
        ok = 0 ;
5595
    end
5596
 
5597
    if ( ok )
5598
        test_ok ;
5599
 
5600
    // clear statuses
5601
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5602
 
5603
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5604
    fork
5605
    begin
5606
        ipci_unsupported_commands_master.master_reference
5607
        (
5608
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5609
            32'h5555_5555,      // second part of address in dual address cycle
5610
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5611
            `BC_MEM_WRITE,      // normal command
5612
            4'h0,               // byte enables
5613
            32'h1234_5678,      // data
5614
            1'b1,               // make address parity error on first phase of dual address
5615
            1'b1,               // make address parity error on second phase of dual address
5616
            ok                  // result of operation
5617
        ) ;
5618 35 mihad
        if ( !perr_asserted )
5619
            disable wait_serr16 ;
5620 15 mihad
    end
5621
    begin:wait_serr16
5622
        perr_asserted = 0 ;
5623
        @(posedge pci_clock) ;
5624 35 mihad
        while( SERR !== 0 )
5625 15 mihad
            @(posedge pci_clock) ;
5626
 
5627 35 mihad
        perr_asserted = 1 ;
5628 15 mihad
    end
5629
    join
5630
 
5631
    if ( ok && perr_asserted)
5632
        test_ok ;
5633
    else
5634
    if ( !perr_asserted )
5635
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5636
 
5637
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5638
 
5639
    `ifdef HOST
5640
        repeat(4)
5641 26 mihad
            @(posedge pci_clock) ;
5642
        repeat(4)
5643 15 mihad
            @(posedge wb_clock) ;
5644
        if ( INT_O !== 1 )
5645
        begin
5646
            $display("Parity checker testing failed! Time %t ", $time) ;
5647
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5648
            test_fail("Interrupt Request was not triggered as expected") ;
5649
        end
5650
        else
5651
            test_ok ;
5652
    `else
5653
    `ifdef GUEST
5654 26 mihad
        repeat(4)
5655
            @(posedge wb_clock) ;
5656
        repeat(4)
5657 15 mihad
            @(posedge pci_clock) ;
5658
 
5659
        if ( INTA !== 1 )
5660
        begin
5661
            $display("Parity checker testing failed! Time %t ", $time) ;
5662
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5663
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5664
        end
5665
        else
5666
            test_ok ;
5667
    `endif
5668
    `endif
5669
 
5670
    // check statuses!
5671
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5672
    ok = 1 ;
5673
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5674
    if ( temp_val1[31] !== 1 )
5675
    begin
5676
        $display("Parity checker testing failed! Time %t ", $time) ;
5677
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5678
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5679
        ok = 0 ;
5680
    end
5681
 
5682
    if ( temp_val1[30] !== 1 )
5683
    begin
5684
        $display("Parity checker testing failed! Time %t ", $time) ;
5685
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5686
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5687
        ok = 0 ;
5688
    end
5689
 
5690
    if ( temp_val1[24] !== 0 )
5691
    begin
5692
        $display("Parity checker testing failed! Time %t ", $time) ;
5693
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5694
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5695
        ok = 0 ;
5696
    end
5697
 
5698
    if ( ok )
5699
        test_ok ;
5700
 
5701
    // clear statuses
5702
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5703
 
5704
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5705
 
5706
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5707
    ok = 1 ;
5708
 
5709
    `ifdef HOST
5710
    if ( temp_val1[4] !== 1 )
5711
    begin
5712
        $display("Parity checker testing failed! Time %t ", $time) ;
5713
        $display("System error interrupt status bit not set when expected!") ;
5714
        test_fail("System error interrupt status bit not set when expected") ;
5715
        ok = 0 ;
5716
    end
5717
    `else
5718
    if ( temp_val1[4] !== 0 )
5719
    begin
5720
        $display("Parity checker testing failed! Time %t ", $time) ;
5721
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5722
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5723
        ok = 0 ;
5724
    end
5725
    `endif
5726
 
5727
    if ( temp_val1[3] !== 0 )
5728
    begin
5729
        $display("Parity checker testing failed! Time %t ", $time) ;
5730
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5731
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5732
        ok = 0 ;
5733
    end
5734
 
5735
    if ( ok )
5736
        test_ok ;
5737
 
5738
    // clear statuses
5739
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5740
 
5741
    // now just disable Parity Error response - on Address par errors nothing should happen
5742
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5743
 
5744
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5745
    fork
5746
    begin
5747
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5748
               target_address, 32'h1234_5678,
5749
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5750
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5751
        do_pause( 1 ) ;
5752
    end
5753
    begin:wait_serr12
5754
        perr_asserted = 0 ;
5755
        @(posedge pci_clock) ;
5756
        while( SERR === 1 )
5757
            @(posedge pci_clock) ;
5758
 
5759
        perr_asserted = 1 ;
5760
        $display("Parity checker testing failed! Time %t ", $time) ;
5761
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5762
        test_fail("SERR asserted when parity error response was disabled") ;
5763
    end
5764
    begin
5765
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5766
        if ( ok !== 1 )
5767
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5768
 
5769 35 mihad
        @(posedge pci_clock) ;
5770
        #1 ;
5771
        if ( !perr_asserted )
5772
            disable wait_serr12 ;
5773 15 mihad
    end
5774
    join
5775
 
5776
    if ( ok && !perr_asserted )
5777
        test_ok ;
5778
 
5779
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5780
    `ifdef HOST
5781 26 mihad
        repeat (4)
5782
            @(posedge pci_clock) ;
5783 15 mihad
        repeat(4)
5784
            @(posedge wb_clock) ;
5785
        if ( INT_O !== 0 )
5786
        begin
5787
            $display("Parity checker testing failed! Time %t ", $time) ;
5788
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5789
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5790
        end
5791
        else
5792
            test_ok ;
5793
    `else
5794
    `ifdef GUEST
5795 26 mihad
        repeat(4)
5796
            @(posedge wb_clock) ;
5797
        repeat (4)
5798 15 mihad
            @(posedge pci_clock) ;
5799
 
5800
        if ( INTA !== 1 )
5801
        begin
5802
            $display("Parity checker testing failed! Time %t ", $time) ;
5803
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5804
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5805
        end
5806
        else
5807
            test_ok ;
5808
    `endif
5809
    `endif
5810
 
5811
    // check statuses!
5812
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5813
    ok = 1 ;
5814
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5815
    if ( temp_val1[31] !== 1 )
5816
    begin
5817
        $display("Parity checker testing failed! Time %t ", $time) ;
5818
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5819
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5820
        ok = 0 ;
5821
    end
5822
 
5823
    if ( temp_val1[30] !== 0 )
5824
    begin
5825
        $display("Parity checker testing failed! Time %t ", $time) ;
5826
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5827
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5828
        ok = 0 ;
5829
    end
5830
 
5831
    if ( temp_val1[24] !== 0 )
5832
    begin
5833
        $display("Parity checker testing failed! Time %t ", $time) ;
5834
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5835
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5836
        ok = 0 ;
5837
    end
5838
 
5839
    if ( ok )
5840
        test_ok ;
5841
 
5842
    // clear statuses
5843
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5844
 
5845
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5846
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5847
    ok = 1 ;
5848
    if ( temp_val1[4] !== 0 )
5849
    begin
5850
        $display("Parity checker testing failed! Time %t ", $time) ;
5851
        $display("System error interrupt status bit set when not expected!") ;
5852
        test_fail("System error interrupt status bit set when not expected") ;
5853
        ok = 0 ;
5854
    end
5855
 
5856
    if ( temp_val1[3] !== 0 )
5857
    begin
5858
        $display("Parity checker testing failed! Time %t ", $time) ;
5859
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5860
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5861
        ok = 0 ;
5862
    end
5863
 
5864
    if ( ok )
5865
        test_ok ;
5866
 
5867
    // clear statuses
5868
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5869
 
5870
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5871
    fork
5872
    begin
5873
        ipci_unsupported_commands_master.master_reference
5874
        (
5875
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5876
            32'h5555_5555,      // second part of address in dual address cycle
5877
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5878
            `BC_MEM_WRITE,      // normal command
5879
            4'h0,               // byte enables
5880
            32'h1234_5678,      // data
5881
            1'b1,               // make address parity error on first phase of dual address
5882
            1'b0,               // make address parity error on second phase of dual address
5883
            ok                  // result of operation
5884
        ) ;
5885 35 mihad
        if ( !perr_asserted )
5886
            disable wait_serr17 ;
5887 15 mihad
    end
5888
    begin:wait_serr17
5889
        perr_asserted = 0 ;
5890
        @(posedge pci_clock) ;
5891
        while( SERR === 1 )
5892
            @(posedge pci_clock) ;
5893
 
5894
        perr_asserted = 1 ;
5895
        $display("Parity checker testing failed! Time %t ", $time) ;
5896
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5897
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5898
    end
5899
    join
5900
 
5901
    if ( ok && !perr_asserted)
5902
        test_ok ;
5903
 
5904
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5905
    fork
5906
    begin
5907
        ipci_unsupported_commands_master.master_reference
5908
        (
5909
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5910
            32'h5555_5555,      // second part of address in dual address cycle
5911
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5912
            `BC_MEM_WRITE,      // normal command
5913
            4'h0,               // byte enables
5914
            32'h1234_5678,      // data
5915
            1'b0,               // make address parity error on first phase of dual address
5916
            1'b1,               // make address parity error on second phase of dual address
5917
            ok                  // result of operation
5918
        ) ;
5919 35 mihad
        if ( !perr_asserted )
5920
            disable wait_serr18 ;
5921 15 mihad
    end
5922
    begin:wait_serr18
5923
        perr_asserted = 0 ;
5924
        @(posedge pci_clock) ;
5925
        while( SERR === 1 )
5926
            @(posedge pci_clock) ;
5927
 
5928
        perr_asserted = 1 ;
5929
        $display("Parity checker testing failed! Time %t ", $time) ;
5930
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5931
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5932
    end
5933
    join
5934
 
5935
    if ( ok && !perr_asserted)
5936
        test_ok ;
5937
 
5938
    // check statuses!
5939
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5940
    ok = 1 ;
5941
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5942
    if ( temp_val1[31] !== 1 )
5943
    begin
5944
        $display("Parity checker testing failed! Time %t ", $time) ;
5945
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5946
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5947
        ok = 0 ;
5948
    end
5949
 
5950
    if ( temp_val1[30] !== 0 )
5951
    begin
5952
        $display("Parity checker testing failed! Time %t ", $time) ;
5953
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5954
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5955
        ok = 0 ;
5956
    end
5957
 
5958
    if ( temp_val1[24] !== 0 )
5959
    begin
5960
        $display("Parity checker testing failed! Time %t ", $time) ;
5961
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5962
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5963
        ok = 0 ;
5964
    end
5965
 
5966
    if ( ok )
5967
        test_ok ;
5968
 
5969
    // clear statuses
5970
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5971
 
5972
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5973
    fork
5974
    begin
5975
        ipci_unsupported_commands_master.master_reference
5976
        (
5977
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5978
            32'h5555_5555,      // second part of address in dual address cycle
5979
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5980
            `BC_MEM_WRITE,      // normal command
5981
            4'h0,               // byte enables
5982
            32'h1234_5678,      // data
5983
            1'b1,               // make address parity error on first phase of dual address
5984
            1'b1,               // make address parity error on second phase of dual address
5985
            ok                  // result of operation
5986
        ) ;
5987 35 mihad
        if ( !perr_asserted )
5988
            disable wait_serr19 ;
5989 15 mihad
    end
5990
    begin:wait_serr19
5991
        perr_asserted = 0 ;
5992
        @(posedge pci_clock) ;
5993
        while( SERR === 1 )
5994
            @(posedge pci_clock) ;
5995
 
5996
        perr_asserted = 1 ;
5997
        $display("Parity checker testing failed! Time %t ", $time) ;
5998
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5999
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
6000
    end
6001
    join
6002
 
6003
    if ( ok && !perr_asserted)
6004
        test_ok ;
6005
 
6006
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
6007
 
6008
    `ifdef HOST
6009
        repeat(4)
6010 26 mihad
            @(posedge pci_clock) ;
6011
        repeat(4)
6012 15 mihad
            @(posedge wb_clock) ;
6013
        if ( INT_O !== 0 )
6014
        begin
6015
            $display("Parity checker testing failed! Time %t ", $time) ;
6016
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
6017
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
6018
        end
6019
        else
6020
            test_ok ;
6021
    `else
6022
    `ifdef GUEST
6023 26 mihad
        repeat(4)
6024
            @(posedge wb_clock) ;
6025
        repeat(4)
6026 15 mihad
            @(posedge pci_clock) ;
6027
 
6028
        if ( INTA !== 1 )
6029
        begin
6030
            $display("Parity checker testing failed! Time %t ", $time) ;
6031
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
6032
            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") ;
6033
        end
6034
        else
6035
            test_ok ;
6036
    `endif
6037
    `endif
6038
 
6039
    // check statuses!
6040
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
6041
    ok = 1 ;
6042
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6043
    if ( temp_val1[31] !== 1 )
6044
    begin
6045
        $display("Parity checker testing failed! Time %t ", $time) ;
6046
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
6047
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
6048
        ok = 0 ;
6049
    end
6050
 
6051
    if ( temp_val1[30] !== 0 )
6052
    begin
6053
        $display("Parity checker testing failed! Time %t ", $time) ;
6054
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6055
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6056
        ok = 0 ;
6057
    end
6058
 
6059
    if ( temp_val1[24] !== 0 )
6060
    begin
6061
        $display("Parity checker testing failed! Time %t ", $time) ;
6062
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6063
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6064
        ok = 0 ;
6065
    end
6066
 
6067
    if ( ok )
6068
        test_ok ;
6069
 
6070
    // clear statuses
6071
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6072
 
6073
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6074
 
6075
    // do normal write
6076
    fork
6077
    begin
6078
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6079
               target_address, 32'h1234_5678, `Test_All_Bytes,
6080
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6081
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6082
        do_pause( 1 ) ;
6083
    end
6084
    begin:wait_serr13
6085
        perr_asserted = 0 ;
6086
        @(posedge pci_clock) ;
6087
        while( SERR === 1 )
6088
            @(posedge pci_clock) ;
6089
 
6090
        perr_asserted = 1 ;
6091
        $display("Parity checker testing failed! Time %t ", $time) ;
6092
        $display("SERR asserted for no reason!") ;
6093
        test_fail("SERR was asserted for no reason") ;
6094
    end
6095
    begin
6096
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6097
        if ( ok !== 1 )
6098
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6099
 
6100 35 mihad
        @(posedge pci_clock) ;
6101
        #1 ;
6102
        if ( !perr_asserted )
6103
            disable wait_serr13 ;
6104 15 mihad
    end
6105
    join
6106
 
6107
    if ( ok && !perr_asserted )
6108
        test_ok ;
6109
 
6110
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6111
    `ifdef HOST
6112 26 mihad
        repeat( 4 )
6113
            @(posedge pci_clock) ;
6114 15 mihad
        repeat(4)
6115
            @(posedge wb_clock) ;
6116
        if ( INT_O !== 0 )
6117
        begin
6118
            $display("Parity checker testing failed! Time %t ", $time) ;
6119
            $display("Interrupt request asserted for no reason!") ;
6120
            test_fail("Interrupt request was asserted for no reason") ;
6121
        end
6122
        else
6123
            test_ok ;
6124
    `else
6125
    `ifdef GUEST
6126 26 mihad
        repeat(4)
6127
            @(posedge wb_clock) ;
6128
        repeat(4)
6129 15 mihad
            @(posedge pci_clock) ;
6130
 
6131
        if ( INTA !== 1 )
6132
        begin
6133
            $display("Parity checker testing failed! Time %t ", $time) ;
6134
            $display("Interrupt request asserted for no reason!") ;
6135
            test_fail("Interrupt request was asserted for no reason") ;
6136
        end
6137
        else
6138
            test_ok ;
6139
    `endif
6140
    `endif
6141
 
6142
    // check statuses!
6143
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6144
    ok = 1 ;
6145
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6146
    if ( temp_val1[31] !== 0 )
6147
    begin
6148
        $display("Parity checker testing failed! Time %t ", $time) ;
6149
        $display("Detected Parity Error bit was set for no reason!") ;
6150
        test_fail("Detected Parity Error bit was set for no reason") ;
6151
        ok = 0 ;
6152
    end
6153
 
6154
    if ( temp_val1[30] !== 0 )
6155
    begin
6156
        $display("Parity checker testing failed! Time %t ", $time) ;
6157
        $display("Signalled System Error bit was set for no reason!") ;
6158
        test_fail("Signalled System Error bit was set for no reason") ;
6159
        ok = 0 ;
6160
    end
6161
 
6162
    if ( temp_val1[24] !== 0 )
6163
    begin
6164
        $display("Parity checker testing failed! Time %t ", $time) ;
6165
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6166
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6167
        ok = 0 ;
6168
    end
6169
 
6170
    if ( ok )
6171
        test_ok ;
6172
 
6173
    // clear statuses
6174
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6175
 
6176
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6177
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6178
    ok = 1 ;
6179
 
6180
    if ( temp_val1[4] !== 0 )
6181
    begin
6182
        $display("Parity checker testing failed! Time %t ", $time) ;
6183
        $display("System error interrupt status bit set when not expected!") ;
6184
        test_fail("System error interrupt status bit set when not expected") ;
6185
        ok = 0 ;
6186
    end
6187
 
6188
    if ( temp_val1[3] !== 0 )
6189
    begin
6190
        $display("Parity checker testing failed! Time %t ", $time) ;
6191
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6192
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6193
        ok = 0 ;
6194
    end
6195
 
6196
    if ( ok )
6197
        test_ok ;
6198
 
6199
    // clear statuses
6200
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6201
 
6202
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6203
 
6204
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6205
 
6206
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6207
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6208
 
6209
    // setup target's image!
6210
    target_address  = Target_Base_Addr_R[1] ;
6211
 
6212
    // base address
6213
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6214
 
6215
    // address mask
6216
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6217
 
6218
    // image control
6219
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6220
 
6221
    // enable everything possible for parity checking
6222
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6223
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6224
 
6225
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6226
 
6227
    fork
6228
    begin
6229
        if ( target_mem_image === 1 )
6230
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6231
                   target_address, 32'h1234_5678,
6232
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6233
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6234
        else
6235
            PCIU_IO_WRITE_MAKE_PERR (
6236
                                    `Test_Master_1,
6237
                                    target_address,
6238
                                    32'h1234_5678,
6239
                                    4'h0,
6240
                                    1,
6241
                                    `Test_Target_Normal_Completion
6242
                                    );
6243
 
6244
        do_pause( 1 ) ;
6245
    end
6246
    begin:wait_perr11
6247
        perr_asserted = 0 ;
6248
        @(posedge pci_clock) ;
6249 35 mihad
        while ( PERR !== 0 )
6250 15 mihad
            @(posedge pci_clock) ;
6251
 
6252 35 mihad
        perr_asserted = 1 ;
6253 15 mihad
 
6254
    end
6255
    begin
6256
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6257
 
6258
        if ( ok !== 1 )
6259
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6260
 
6261
        repeat(2)
6262
            @(posedge pci_clock) ;
6263
 
6264 35 mihad
        #1 ;
6265
        if ( !perr_asserted )
6266
            disable wait_perr11 ;
6267 15 mihad
    end
6268
    join
6269
 
6270
    if ( ok && perr_asserted )
6271
        test_ok ;
6272
    else
6273
    if ( !perr_asserted )
6274
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6275
 
6276
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6277
    `ifdef HOST
6278 26 mihad
        repeat (4)
6279
            @(posedge pci_clock) ;
6280 15 mihad
        repeat(4)
6281
            @(posedge wb_clock) ;
6282
        if ( INT_O !== 0 )
6283
        begin
6284
            $display("Parity checker testing failed! Time %t ", $time) ;
6285
            $display("Interrupt request asserted for no reason!") ;
6286
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6287
        end
6288
        else
6289
            test_ok ;
6290
    `else
6291
    `ifdef GUEST
6292 26 mihad
        repeat(4)
6293
            @(posedge wb_clock) ;
6294
        repeat (4)
6295 15 mihad
            @(posedge pci_clock) ;
6296
 
6297
        if ( INTA !== 1 )
6298
        begin
6299
            $display("Parity checker testing failed! Time %t ", $time) ;
6300
            $display("Interrupt request asserted for no reason!") ;
6301
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6302
        end
6303
        else
6304
            test_ok ;
6305
 
6306
    `endif
6307
    `endif
6308
 
6309
    // check statuses!
6310
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6311
    ok = 1 ;
6312
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6313
    if ( temp_val1[31] !== 1 )
6314
    begin
6315
        $display("Parity checker testing failed! Time %t ", $time) ;
6316 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6317
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6318 15 mihad
        ok = 0 ;
6319
    end
6320
 
6321
    if ( temp_val1[30] !== 0 )
6322
    begin
6323
        $display("Parity checker testing failed! Time %t ", $time) ;
6324
        $display("Signalled System Error bit was set for no reason!") ;
6325
        test_fail("Signalled System Error bit was set for no reason") ;
6326
        ok = 0 ;
6327
    end
6328
 
6329
    if ( temp_val1[24] !== 0 )
6330
    begin
6331
        $display("Parity checker testing failed! Time %t ", $time) ;
6332
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6333
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6334
        ok = 0 ;
6335
    end
6336
 
6337
    if ( ok )
6338
        test_ok ;
6339
 
6340
    // clear statuses
6341
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6342
 
6343
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6344
 
6345
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6346
    ok = 1 ;
6347
    if ( temp_val1[4] !== 0 )
6348
    begin
6349
        $display("Parity checker testing failed! Time %t ", $time) ;
6350
        $display("System error interrupt status bit set when not expected!") ;
6351
        test_fail("System error interrupt status bit set when not expected") ;
6352
        ok = 0 ;
6353
    end
6354
 
6355
    if ( temp_val1[3] !== 0 )
6356
    begin
6357
        $display("Parity checker testing failed! Time %t ", $time) ;
6358
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6359
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6360
        ok = 0 ;
6361
    end
6362
 
6363
    if ( ok )
6364
        test_ok ;
6365
 
6366
    // clear statuses
6367
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6368
 
6369
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6370
 
6371
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6372
    fork
6373
    begin
6374
        if ( target_mem_image === 1 )
6375
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6376
                          target_address, 32'h1234_5678,
6377
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6378
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6379
        else
6380
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6381
 
6382
        do_pause( 1 ) ;
6383
    end
6384
    begin:wait_perr12
6385
        perr_asserted = 0 ;
6386
        @(posedge pci_clock) ;
6387 35 mihad
        while ( PERR !== 0 )
6388 15 mihad
            @(posedge pci_clock) ;
6389
 
6390 35 mihad
        perr_asserted = 1 ;
6391 15 mihad
    end
6392
    begin
6393
 
6394
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6395
        if ( ok !== 1 )
6396
        begin
6397
            test_fail("Bridge failed to process Target Memory read correctly") ;
6398
            disable main ;
6399
        end
6400
 
6401
        repeat(3)
6402
            @(posedge pci_clock) ;
6403
 
6404
        if ( target_mem_image === 1 )
6405
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6406
                    target_address, 32'h1234_5678,
6407
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6408
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6409
        else
6410
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6411
 
6412
        do_pause( 1 ) ;
6413
 
6414
    end
6415
    begin
6416
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6417
        if ( ok !== 1 )
6418
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6419
        else
6420
        begin
6421
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6422
            if ( ok !== 1 )
6423
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6424
        end
6425
 
6426 35 mihad
        repeat(2)
6427 15 mihad
            @(posedge pci_clock) ;
6428
 
6429 35 mihad
        #1 ;
6430
        if ( !perr_asserted )
6431
            disable wait_perr12 ;
6432 15 mihad
    end
6433
    join
6434
 
6435
    if ( ok && perr_asserted )
6436
        test_ok ;
6437
    else
6438
    if ( !perr_asserted )
6439
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6440
 
6441
 
6442
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6443
    `ifdef HOST
6444
        repeat(4)
6445 26 mihad
            @(posedge pci_clock) ;
6446
        repeat(4)
6447 15 mihad
            @(posedge wb_clock) ;
6448
        if ( INT_O !== 0 )
6449
        begin
6450
            $display("Parity checker testing failed! Time %t ", $time) ;
6451
            $display("Interrupt request asserted for no reason!") ;
6452
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6453
        end
6454
        else
6455
            test_ok ;
6456
    `else
6457
    `ifdef GUEST
6458 26 mihad
        repeat(4)
6459
            @(posedge wb_clock) ;
6460
        repeat(4)
6461 15 mihad
            @(posedge pci_clock) ;
6462
 
6463
        if ( INTA !== 1 )
6464
        begin
6465
            $display("Parity checker testing failed! Time %t ", $time) ;
6466
            $display("Interrupt request asserted for no reason!") ;
6467
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6468
        end
6469
        else
6470
            test_ok ;
6471
    `endif
6472
    `endif
6473
 
6474
    // check statuses!
6475
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6476
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6477
    ok = 1 ;
6478 45 mihad
    if ( temp_val1[31] !== 0 )
6479 15 mihad
    begin
6480
        $display("Parity checker testing failed! Time %t ", $time) ;
6481 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6482
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6483 15 mihad
        ok = 0 ;
6484
    end
6485
 
6486
    if ( temp_val1[30] !== 0 )
6487
    begin
6488
        $display("Parity checker testing failed! Time %t ", $time) ;
6489
        $display("Signalled System Error bit was set for no reason!") ;
6490
        test_fail("Signalled System Error bit was set for no reason") ;
6491
        ok = 0 ;
6492
    end
6493
 
6494
    if ( temp_val1[24] !== 0 )
6495
    begin
6496
        $display("Parity checker testing failed! Time %t ", $time) ;
6497
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6498
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6499
        ok = 0 ;
6500
    end
6501
 
6502
    if ( ok )
6503
        test_ok ;
6504
 
6505
    // clear statuses
6506
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6507
 
6508
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6509
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6510
    ok = 1 ;
6511
    if ( temp_val1[4] !== 0 )
6512
    begin
6513
        $display("Parity checker testing failed! Time %t ", $time) ;
6514
        $display("System error interrupt status bit set when not expected!") ;
6515
        test_fail("System error interrupt status bit set when not expected") ;
6516
        ok = 0 ;
6517
    end
6518
 
6519
    if ( temp_val1[3] !== 0 )
6520
    begin
6521
        $display("Parity checker testing failed! Time %t ", $time) ;
6522
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6523
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6524
        ok = 0 ;
6525
    end
6526
 
6527
    if ( ok )
6528
        test_ok ;
6529
    // clear statuses
6530
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6531
 
6532
    $fdisplay(pci_mon_log_file_desc,
6533
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6534
    test_name = "DISABLE USED IMAGES" ;
6535
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6536
    if ( ok !== 1 )
6537
    begin
6538
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6539
        test_fail("WB Image Address Mask register could not be written to") ;
6540
        disable main ;
6541
    end
6542
 
6543 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6544 15 mihad
    if ( ok !== 1 )
6545
    begin
6546
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6547
        test_fail("PCI Image Address Mask register could not be written to") ;
6548
        disable main ;
6549
    end
6550
 
6551
    // disable target's 1 response to parity errors
6552 45 mihad
    configuration_cycle_write(0,                        // bus number
6553
                              `TAR1_IDSEL_INDEX - 11,   // device number
6554
                              0,                        // function number
6555
                              1,                        // register number
6556
                              0,                        // type of configuration cycle
6557
                              4'b0001,                  // byte enables
6558
                              32'h0000_0007             // data
6559 15 mihad
                             ) ;
6560
 
6561
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6562
end
6563
endtask // parity_checking
6564
 
6565
task wb_to_pci_transactions ;
6566
    reg   [11:0] ctrl_offset ;
6567
    reg   [11:0] ba_offset ;
6568
    reg   [11:0] am_offset ;
6569
    reg   [11:0] pci_ctrl_offset ;
6570
    reg   [11:0] err_cs_offset ;
6571
    reg   [11:0] icr_offset ;
6572
    reg   [11:0] isr_offset ;
6573
    reg   [11:0] lat_tim_cls_offset ;
6574
 
6575
    reg `WRITE_STIM_TYPE  write_data ;
6576
    reg `READ_STIM_TYPE   read_data ;
6577
    reg `READ_RETURN_TYPE read_status ;
6578
 
6579
    reg `WRITE_RETURN_TYPE write_status ;
6580
    reg `WB_TRANSFER_FLAGS write_flags ;
6581
    reg [31:0] temp_val1 ;
6582
    reg [31:0] temp_val2 ;
6583
    reg        ok   ;
6584
 
6585
    reg [31:0] image_base ;
6586
    reg [31:0] target_address ;
6587
    integer i ;
6588
    integer required_reads ;
6589
    integer writes_left ;
6590
 
6591
begin:main
6592
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6593
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6594
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6595
    pci_ctrl_offset    = 12'h4 ;
6596
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6597
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6598
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6599
    lat_tim_cls_offset = 12'hC ;
6600
 
6601
    $display("Checking WB to PCI transaction lengths!") ;
6602
    target_address  = `BEH_TAR1_MEM_START ;
6603
    image_base      = 0 ;
6604
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6605
 
6606
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6607
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6608
    write_flags                    = 0 ;
6609
    write_flags`INIT_WAITS         = tb_init_waits ;
6610
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6611
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6612
 
6613
    // enable master & target operation
6614
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6615
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6616
    if ( ok !== 1 )
6617
    begin
6618
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6619
        test_fail("write to PCI Device Control register failed") ;
6620
        disable main ;
6621
    end
6622
 
6623
    // prepare image control register
6624
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6625
    if ( ok !== 1 )
6626
    begin
6627
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6628
        test_fail("write to WB Image Control register failed") ;
6629
        disable main ;
6630
    end
6631
 
6632
    // prepare base address register
6633
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6634
    if ( ok !== 1 )
6635
    begin
6636
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6637
        test_fail("write to WB Base Address register failed") ;
6638
        disable main ;
6639
    end
6640
 
6641
    // write address mask register
6642
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6643
    if ( ok !== 1 )
6644
    begin
6645
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6646
        test_fail("write to WB Address Mask register failed") ;
6647
        disable main ;
6648
    end
6649
 
6650
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6651
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6652
    if ( ok !== 1 )
6653
    begin
6654
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6655
        test_fail("write to WB Error Control and Status register failed") ;
6656
        disable main ;
6657
    end
6658
 
6659
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6660
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6661
    if ( ok !== 1 )
6662
    begin
6663
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6664
        test_fail("write to Interrupt Control register failed") ;
6665
        disable main ;
6666
    end
6667
 
6668
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6669
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6670
    if ( ok !== 1 )
6671
    begin
6672
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6673
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6674
        disable main ;
6675
    end
6676
 
6677
    $display("Testing single write transaction progress from WB to PCI!") ;
6678
    write_data`WRITE_ADDRESS = target_address ;
6679
    write_data`WRITE_DATA    = wmem_data[0] ;
6680
    write_data`WRITE_SEL     = 4'hF ;
6681
 
6682
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6683
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6684
 
6685
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6686
    fork
6687
    begin
6688
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6689
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6690
        begin
6691
            $display("Transaction progress testing failed! Time %t ", $time) ;
6692
            $display("Bridge failed to process single memory write!") ;
6693
            test_fail("bridge failed to post single memory write") ;
6694
            disable main ;
6695
        end
6696
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6697
    end
6698
    begin
6699
        // wait two retries, then enable target response
6700
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6701
        if ( ok !== 1 )
6702
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6703
        else
6704
            test_ok ;
6705
 
6706
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6707
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6708
        if ( ok !== 1 )
6709
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6710
        else
6711
            test_ok ;
6712
 
6713
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6714
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6715
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6716
 
6717
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6718
        if ( ok !== 1 )
6719
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6720
        else
6721
            test_ok ;
6722
    end
6723
    join
6724
 
6725
    $display("Testing burst write transaction progress from WB to PCI!") ;
6726
    write_data`WRITE_ADDRESS = target_address ;
6727
    write_data`WRITE_DATA    = wmem_data[0] ;
6728
    write_data`WRITE_SEL     = 4'hF ;
6729
 
6730
    wishbone_master.blk_write_data[0] = write_data ;
6731
 
6732
    write_data`WRITE_ADDRESS = target_address + 4 ;
6733
    write_data`WRITE_DATA    = wmem_data[1] ;
6734
    write_data`WRITE_SEL     = 4'hF ;
6735
 
6736
    wishbone_master.blk_write_data[1] = write_data ;
6737
 
6738
    write_flags`WB_TRANSFER_SIZE = 2 ;
6739
    write_flags`WB_TRANSFER_CAB  = 1 ;
6740
 
6741
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6742
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6743
 
6744
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6745
 
6746
    fork
6747
    begin
6748
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6749
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6750
        begin
6751
            $display("Transaction progress testing failed! Time %t ", $time) ;
6752
            $display("Bridge failed to process whole CAB memory write!") ;
6753
            test_fail("bridge failed to post whole CAB memory write") ;
6754
            disable main ;
6755
        end
6756
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6757
    end
6758
    begin
6759
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6760
        if ( ok !== 1 )
6761
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6762
        else
6763
            test_ok ;
6764
 
6765
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6766
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6767
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6768
 
6769
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6770
        if ( ok !== 1 )
6771
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6772
        else
6773
            test_ok ;
6774
 
6775
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6776
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6777
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6778
 
6779
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6780
        if ( ok !== 1 )
6781
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6782
        else
6783
            test_ok ;
6784
    end
6785
    join
6786
 
6787
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6788
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6789
 
6790
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6791
    // try same write with other terminations
6792
    fork
6793
    begin
6794
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6795
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6796
        begin
6797
            $display("Transaction progress testing failed! Time %t ", $time) ;
6798
            $display("Bridge failed to process whole CAB memory write!") ;
6799
            test_fail("bridge failed to post whole CAB memory write") ;
6800
            disable main ;
6801
        end
6802
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6803
    end
6804
    begin
6805
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6806
        if ( ok !== 1 )
6807
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6808
        else
6809
            test_ok ;
6810
 
6811
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6812
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6813
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6814
 
6815
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6816
        if ( ok !== 1 )
6817
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6818
        else
6819
            test_ok ;
6820
    end
6821
    join
6822
 
6823
    // repeat the write with normal completion
6824
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6825
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6826
 
6827
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6828
    fork
6829
    begin
6830
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6831
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6832
        begin
6833
            $display("Transaction progress testing failed! Time %t ", $time) ;
6834
            $display("Bridge failed to process whole CAB memory write!") ;
6835
            test_fail("bridge failed to post whole CAB memory write") ;
6836
            disable main ;
6837
        end
6838
    end
6839
    begin
6840
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6841
        if ( ok !== 1 )
6842
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6843
        else
6844
            test_ok ;
6845
    end
6846
    join
6847
 
6848
    // do the same thing with burst length of 3
6849
    write_data`WRITE_ADDRESS = target_address + 8 ;
6850
    write_data`WRITE_DATA    = wmem_data[2] ;
6851
    write_data`WRITE_SEL     = 4'hF ;
6852
 
6853
    wishbone_master.blk_write_data[2] = write_data ;
6854
 
6855
    write_flags`WB_TRANSFER_SIZE = 3 ;
6856
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6857
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6858
 
6859
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6860
 
6861
    fork
6862
    begin
6863
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6864
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6865
        begin
6866
            $display("Transaction progress testing failed! Time %t ", $time) ;
6867
            $display("Bridge failed to process whole CAB memory write!") ;
6868
            test_fail("bridge failed to post whole CAB memory write") ;
6869
            disable main ;
6870
        end
6871
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6872
    end
6873
    begin
6874
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6875
        if ( ok !== 1 )
6876
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6877
        else
6878
            test_ok ;
6879
 
6880
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6881
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6882
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6883
 
6884
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6885
        if ( ok !== 1 )
6886
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6887
        else
6888
            test_ok ;
6889
    end
6890
    join
6891
 
6892
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6893
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6894
 
6895
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6896
    fork
6897
    begin
6898
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6899
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6900
        begin
6901
            $display("Transaction progress testing failed! Time %t ", $time) ;
6902
            $display("Bridge failed to process whole CAB memory write!") ;
6903
            test_fail("bridge failed to post whole CAB memory write") ;
6904
            disable main ;
6905
        end
6906
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6907
    end
6908
    begin
6909
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6910
        if ( ok !== 1 )
6911
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6912
        else
6913
            test_ok ;
6914
 
6915
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6916
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6917
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6918
 
6919
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6920
        if ( ok !== 1 )
6921
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6922
        else
6923
            test_ok ;
6924
 
6925
    end
6926
    join
6927
 
6928
    // repeat with normal completion
6929
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6930
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6931
 
6932
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6933
    fork
6934
    begin
6935
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6936
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6937
        begin
6938
            $display("Transaction progress testing failed! Time %t ", $time) ;
6939
            $display("Bridge failed to process whole CAB memory write!") ;
6940
            test_fail("bridge failed to post whole CAB memory write") ;
6941
            disable main ;
6942
        end
6943
    end
6944
    begin
6945
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6946
        if ( ok !== 1 )
6947
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6948
        else
6949
            test_ok ;
6950
 
6951
    end
6952
    join
6953
 
6954
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6955
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6956
    begin
6957
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6958
        write_data`WRITE_DATA    = wmem_data[i] ;
6959
        write_data`WRITE_SEL     = 4'hF ;
6960
 
6961
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6962
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6963
 
6964
        wishbone_master.blk_write_data[i]   = write_data ;
6965
        wishbone_master.blk_read_data_in[i] = read_data ;
6966
    end
6967
 
6968
    write_flags`WB_TRANSFER_CAB      = 1 ;
6969
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6970
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6971
 
6972
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6973
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6974
 
6975
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6976
    fork
6977
    begin
6978
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6979
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6980
        begin
6981
            $display("Transaction progress testing failed! Time %t ", $time) ;
6982
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6983
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6984
            test_fail("bridge failed to post whole CAB memory write") ;
6985
            disable main ;
6986
        end
6987
 
6988
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6989
 
6990
        // read here just checks if data was transfered OK
6991
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6992
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6993
 
6994
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6995
 
6996
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6997
        begin
6998
            $display("Transaction progress testing failed! Time %t ", $time) ;
6999
            $display("Bridge processed CAB read wrong!") ;
7000
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
7001
        end
7002
 
7003
    end
7004
    begin
7005
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7006
        if ( ok !== 1 )
7007
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7008
        else
7009
            test_ok ;
7010
 
7011
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
7012
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7013
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7014
 
7015
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7016
        if ( ok !== 1 )
7017
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7018
        else
7019
            test_ok ;
7020
 
7021
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
7022
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
7023
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7024
 
7025
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7026
        if ( ok !== 1 )
7027
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7028
        else
7029
            test_ok ;
7030
 
7031
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
7032
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7033
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7034
 
7035
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7036
        if ( ok !== 1 )
7037
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7038
        else
7039
            test_ok ;
7040
 
7041
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
7042
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7043
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7044
 
7045
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
7046
        if ( ok !== 1 )
7047
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7048
        else
7049
            test_ok ;
7050
 
7051
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7052
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7053
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7054
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7055
        begin
7056
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7057
            if ( ok !== 1 )
7058
                test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
7059
        end
7060
    end
7061
    join
7062
 
7063
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7064
    begin
7065
        read_status = wishbone_master.blk_read_data_out[i] ;
7066
        if (read_status`READ_DATA !== wmem_data[i])
7067
        begin
7068
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7069
            test_fail("data read from target wasn't the same as data written to it") ;
7070
            ok = 0 ;
7071
        end
7072
    end
7073
 
7074
    if ( ok )
7075
        test_ok ;
7076
 
7077
    $display("Testing single read transaction progress from WB to PCI!") ;
7078
    read_data`READ_ADDRESS = target_address + 8 ;
7079
    read_data`READ_SEL     = 4'hF ;
7080
 
7081
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7082
 
7083
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7084
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7085
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7086
 
7087
    fork
7088
    begin
7089
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7090
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7091
        begin
7092
            $display("Transaction progress testing failed! Time %t ", $time) ;
7093
            $display("Bridge processed single read wrong!") ;
7094
            test_fail("bridge processed single read wrong") ;
7095
            disable main ;
7096
        end
7097
 
7098
        if (read_status`READ_DATA !== wmem_data[2])
7099
        begin
7100
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7101
            test_fail("data returned from single read was not as expected") ;
7102
        end
7103
        else
7104
        if ( ok )
7105
            test_ok ;
7106
    end
7107
    begin
7108
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7109
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7110
 
7111
        if ( ok !== 1 )
7112
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7113
 
7114
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7115
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7116
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7117
 
7118
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7119
        if ( ok !== 1 )
7120
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7121
    end
7122
    join
7123
 
7124
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7125
 
7126
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7127
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7128
 
7129
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7130
    // first fill target's memory with enough data to fill WBR_FIFO
7131
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7132
    begin
7133
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7134
        write_data`WRITE_DATA    = wmem_data[i] ;
7135
        write_data`WRITE_SEL     = 4'hF ;
7136
 
7137
        wishbone_master.blk_write_data[i] = write_data ;
7138
    end
7139
 
7140
    write_flags`WB_TRANSFER_CAB = 1 ;
7141
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7142
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7143
 
7144
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7145
 
7146
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7147
    begin
7148
        $display("Transaction progress testing failed! Time %t ", $time) ;
7149
        $display("Bridge processed CAB write wrong!") ;
7150
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7151
        disable main ;
7152
    end
7153
 
7154
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7155
    // perform single read to force write data to pci
7156
    read_data`READ_ADDRESS = target_address + 8;
7157
    read_data`READ_SEL     = 4'hF ;
7158
 
7159
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7160
 
7161
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7162
    begin
7163
        $display("Transaction progress testing failed! Time %t ", $time) ;
7164
        $display("Bridge processed single read wrong!") ;
7165
        test_fail("bridge didn't process single memory read as expected") ;
7166
        disable main ;
7167
    end
7168
 
7169
    wishbone_master.blk_read_data_in[0] = read_data ;
7170
 
7171
    read_data`READ_ADDRESS = target_address + 12 ;
7172
    read_data`READ_SEL     = 4'hF ;
7173
 
7174
    wishbone_master.blk_read_data_in[1] = read_data ;
7175
 
7176
    read_data`READ_ADDRESS = target_address + 16 ;
7177
    read_data`READ_SEL     = 4'hF ;
7178
 
7179
    wishbone_master.blk_read_data_in[2] = read_data ;
7180
 
7181
    write_flags`WB_TRANSFER_CAB  = 1 ;
7182
    write_flags`WB_TRANSFER_SIZE = 2 ;
7183
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7184
    read_status = 0 ;
7185
 
7186
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7187
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7188
 
7189
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7190
 
7191
    ok = 1 ;
7192
    fork
7193
    begin
7194
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7195
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7196
 
7197
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7198
        begin
7199
            $display("Transaction progress testing failed! Time %t ", $time) ;
7200
            $display("Bridge processed CAB read wrong!") ;
7201
            test_fail("bridge didn't process disconnected burst read as expected") ;
7202
        end
7203
        else
7204
        begin
7205
 
7206
            read_status = wishbone_master.blk_read_data_out[0] ;
7207
 
7208
            if (read_status`READ_DATA !== wmem_data[2])
7209
            begin
7210
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7211
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7212
            end
7213
            else
7214
                test_ok ;
7215
        end
7216
 
7217
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7218
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7219
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7220
 
7221
        read_status = 0 ;
7222
 
7223
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7224
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7225
 
7226
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7227
        begin
7228
            $display("Transaction progress testing failed! Time %t ", $time) ;
7229
            $display("Bridge processed CAB read wrong!") ;
7230
            test_fail("bridge didn't process disconnected burst read as expected") ;
7231
        end
7232
        else
7233
        begin
7234
 
7235
            read_status = wishbone_master.blk_read_data_out[0] ;
7236
 
7237
            if (read_status`READ_DATA !== wmem_data[3])
7238
            begin
7239
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7240
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7241
            end
7242
            else
7243
                test_ok ;
7244
        end
7245
 
7246
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7247
        // complete delayed read which was requested
7248
        read_data = wishbone_master.blk_read_data_in[2] ;
7249
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7250
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7251
 
7252
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7253
        begin
7254
            $display("Transaction progress testing failed! Time %t ", $time) ;
7255
            $display("Bridge processed single out of burst read wrong!") ;
7256
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7257
        end
7258
        else
7259
        begin
7260
 
7261
            if (read_status`READ_DATA !== wmem_data[4])
7262
            begin
7263
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7264
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7265
            end
7266
            else
7267
                test_ok ;
7268
        end
7269
 
7270
    end
7271
    begin
7272
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7273
 
7274
        if ( ok !== 1 )
7275
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7276
 
7277
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7278
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7279
 
7280
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7281
        if ( ok !== 1 )
7282
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7283
 
7284
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7285
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7286
 
7287
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7288
        if ( ok !== 1 )
7289
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7290
    end
7291
    join
7292
 
7293
    // now try burst read with normal termination
7294
    read_data`READ_ADDRESS = target_address + 12 ;
7295
    read_data`READ_SEL     = 4'hF ;
7296
 
7297
    wishbone_master.blk_read_data_in[0] = read_data ;
7298
 
7299
    read_data`READ_ADDRESS = target_address + 16 ;
7300
    read_data`READ_SEL     = 4'hF ;
7301
 
7302
    wishbone_master.blk_read_data_in[1] = read_data ;
7303
 
7304
    write_flags`WB_TRANSFER_SIZE = 2 ;
7305
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7306
    write_flags`WB_TRANSFER_CAB = 1 ;
7307
 
7308
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7309
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7310
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7311
 
7312
    fork
7313
    begin
7314
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7315
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7316
        begin
7317
            $display("Transaction progress testing failed! Time %t ", $time) ;
7318
            $display("Bridge processed CAB read wrong!") ;
7319
            test_fail("bridge didn't process burst read as expected") ;
7320
            ok = 0 ;
7321
        end
7322
    end
7323
    begin
7324
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7325
        if ( ok !== 1 )
7326
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7327
    end
7328
    join
7329
 
7330
    if ( ok )
7331
    begin
7332
        read_status = wishbone_master.blk_read_data_out[0] ;
7333
        if ( read_status`READ_DATA !== wmem_data[3] )
7334
        begin
7335
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7336
            test_fail("data provided from normaly terminated read was wrong") ;
7337
            ok = 0 ;
7338
        end
7339
 
7340
        read_status = wishbone_master.blk_read_data_out[1] ;
7341
        if ( read_status`READ_DATA !== wmem_data[4] )
7342
        begin
7343
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7344
            test_fail("data provided from normaly terminated read was wrong") ;
7345
            ok = 0 ;
7346
        end
7347
    end
7348
 
7349
    if ( ok )
7350
        test_ok ;
7351
 
7352
    // disable memory read line command and enable prefetch
7353
    // prepare image control register
7354
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7355
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7356
    if ( ok !== 1 )
7357
    begin
7358
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7359
        test_fail("WB Image Control register couldn't be written to") ;
7360
        disable main ;
7361
    end
7362
 
7363
    write_flags`WB_TRANSFER_SIZE = 4 ;
7364
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7365
    write_flags`WB_TRANSFER_CAB = 1 ;
7366
 
7367
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7368
 
7369
    for ( i = 0 ; i < 4 ; i = i + 1 )
7370
    begin
7371
        read_data`READ_ADDRESS = target_address + i*4 ;
7372
        read_data`READ_SEL     = 4'b1010 ;
7373
 
7374
        wishbone_master.blk_read_data_in[i] = read_data ;
7375
    end
7376
 
7377
    fork
7378
    begin
7379
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7380
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7381
        begin
7382
            $display("Transaction progress testing failed! Time %t ", $time) ;
7383
            $display("Bridge processed CAB read wrong!") ;
7384
            test_fail("bridge didn't process prefetched burst read as expected") ;
7385
            ok = 0 ;
7386
        end
7387
    end
7388
    begin
7389
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7390
        if ( ok !== 1 )
7391
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7392
    end
7393
    join
7394
 
7395
    if ( ok )
7396
    begin
7397
        for ( i = 0 ; i < 4 ; i = i + 1 )
7398
        begin
7399
            read_status = wishbone_master.blk_read_data_out[i] ;
7400
            if ( read_status`READ_DATA !== wmem_data[i] )
7401
            begin
7402
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7403
                test_fail("burst read returned unexpected data") ;
7404
                ok = 0 ;
7405
            end
7406
        end
7407
    end
7408
 
7409
    if ( ok )
7410
        test_ok ;
7411
 
7412
    // do one single read with different byte enables
7413
    read_data`READ_ADDRESS = target_address + 4 ;
7414
    read_data`READ_SEL     = 4'b1010 ;
7415
 
7416
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7417
    fork
7418
    begin
7419
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7420
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7421
        begin
7422
            $display("Transaction progress testing failed! Time %t ", $time) ;
7423
            $display("Bridge processed single read wrong!") ;
7424
            test_fail("bridge didn't process single memory read as expected") ;
7425
            ok = 0 ;
7426
        end
7427
    end
7428
    begin
7429
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7430
        if ( ok !== 1 )
7431
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7432
    end
7433
    join
7434
 
7435
    // check read data
7436
    if ( ok )
7437
    begin
7438
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7439
        begin
7440
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7441
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7442
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7443
            ok = 0 ;
7444
            test_fail("unexpected data received from single read") ;
7445
        end
7446
    end
7447
 
7448
    if ( ok )
7449
         test_ok ;
7450
 
7451
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7452
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7453
 
7454
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7455
    if ( ok !== 1 )
7456
    begin
7457
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7458
        test_fail("WB Image Control register could not be written") ;
7459
        disable main ;
7460
    end
7461
 
7462
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7463
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7464
    begin
7465
        read_data`READ_ADDRESS = target_address + i*4 ;
7466
        read_data`READ_SEL     = 4'b1111 ;
7467
 
7468
        wishbone_master.blk_read_data_in[i] = read_data ;
7469
    end
7470
 
7471
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7472
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7473
    write_flags`WB_TRANSFER_CAB = 1 ;
7474
 
7475
    fork
7476
    begin
7477
        read_status         = 0 ;
7478
        read_status`CYC_RTY = 1 ;
7479
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7480
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7481
 
7482
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7483
        begin
7484
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7485
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7486
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7487
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7488
            ok = 0 ;
7489
        end
7490
    end
7491
    begin
7492
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7493
        if ( ok !== 1 )
7494
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7495
    end
7496
    join
7497
 
7498
    // now repeat single read to flush redundant read initiated
7499
    write_flags`WB_TRANSFER_SIZE = 1 ;
7500
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7501
    write_flags`WB_TRANSFER_CAB = 1 ;
7502
 
7503
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7504
    read_data`READ_SEL     = 4'hF ;
7505
 
7506
    wishbone_master.blk_read_data_in[0] = read_data ;
7507
 
7508
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7509
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7510
 
7511
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7512
    begin
7513
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7514
        $display(" PCI bridge failed to process single CAB read!") ;
7515
        test_fail("single CAB write was not processed as expected") ;
7516
    end
7517
 
7518
    // because last read could be very long on PCI - delete target abort status
7519
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7520
 
7521
    // write unsupported value to cache line size register
7522
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7523
 
7524
    read_data`READ_ADDRESS = target_address ;
7525
    read_data`READ_SEL     = 4'hF ;
7526
    wishbone_master.blk_read_data_in[0] = read_data ;
7527
 
7528
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7529
    // perform a read
7530
    fork
7531
    begin
7532
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7533
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7534
        begin
7535
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7536
            $display(" PCI bridge failed to process single CAB read!") ;
7537
            test_fail("burst read was not processed as expected") ;
7538
            ok = 0 ;
7539
        end
7540
    end
7541
    begin
7542
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7543
        if ( ok !== 1 )
7544
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7545
    end
7546
    join
7547
 
7548
    if ( ok )
7549
        test_ok ;
7550
 
7551
    // write 2 to cache line size register
7552
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7553
 
7554
    // perform a read
7555
    fork
7556
    begin
7557
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7558
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7559
        begin
7560
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7561
            $display(" PCI bridge failed to process single CAB read!") ;
7562
            test_fail("burst read was not processed as expected") ;
7563
            ok = 0 ;
7564
        end
7565
    end
7566
    begin
7567
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7568
        if ( ok !== 1 )
7569
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7570
    end
7571
    join
7572
 
7573
    if ( ok )
7574
        test_ok ;
7575
 
7576
    // write 0 to cache line size
7577
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7578
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7579
 
7580
    // perform a read
7581
    fork
7582
    begin
7583
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7584
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7585
        begin
7586
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7587
            $display(" PCI bridge failed to process single CAB read!") ;
7588
            test_fail("burst read was not processed as expected") ;
7589
            ok = 0 ;
7590
        end
7591
    end
7592
    begin
7593
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7594
        if ( ok !== 1 )
7595
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7596
    end
7597
    join
7598
 
7599
    if ( ok )
7600
        test_ok ;
7601
 
7602
    // write normal value to cls register
7603
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7604
 
7605
    $display("Testing Master's latency timer operation!") ;
7606
    $display("Testing Latency timer during Master Writes!") ;
7607
 
7608
    for ( i = 0 ; i < 6 ; i = i + 1 )
7609
    begin
7610
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7611
        write_data`WRITE_SEL     = 4'b1111 ;
7612
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7613
 
7614
        wishbone_master.blk_write_data[i] = write_data ;
7615
    end
7616
 
7617
    write_flags`WB_TRANSFER_SIZE = 6 ;
7618
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7619
    write_flags`WB_TRANSFER_CAB = 1 ;
7620
 
7621
    // start wb write, pci write and monitor in parallel
7622
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7623
    fork
7624
    begin
7625
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7626
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7627
        begin
7628
            $display("Transaction progress testing failed! Time %t ", $time) ;
7629
            $display("Bridge failed to process CAB write!") ;
7630
            test_fail("bridge didn't post whole burst memory write") ;
7631
            disable main ;
7632
        end
7633
    end
7634
    begin
7635
        // wait for bridge's master to start transaction
7636
        @(posedge pci_clock) ;
7637
        while ( FRAME === 1 )
7638
            @(posedge pci_clock) ;
7639
 
7640
        // start behavioral master request
7641
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7642
               target_address, wmem_data[1023], `Test_All_Bytes,
7643
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7644
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7645
 
7646
        do_pause ( 1 ) ;
7647
    end
7648
    begin
7649
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7650
        if ( ok !== 1 )
7651
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7652
        else
7653
            test_ok ;
7654
    end
7655
    join
7656
 
7657
    // perform a read to check data
7658
    for ( i = 0 ; i < 6 ; i = i + 1 )
7659
    begin
7660
        read_data`READ_ADDRESS = target_address + i*4 ;
7661
        read_data`READ_SEL     = 4'b1111 ;
7662
 
7663
        wishbone_master.blk_read_data_in[i] = read_data ;
7664
    end
7665
 
7666
    write_flags`WB_TRANSFER_SIZE = 6 ;
7667
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7668
    write_flags`WB_TRANSFER_CAB = 1 ;
7669
 
7670
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7671
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7672
 
7673
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7674
    begin
7675
        $display("Transaction progress testing failed! Time %t ", $time) ;
7676
        $display("Bridge failed to process CAB read!") ;
7677
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7678
        disable main ;
7679
    end
7680
 
7681
    ok = 1 ;
7682
    for ( i = 0 ; i < 6 ; i = i + 1 )
7683
    begin
7684
        read_status = wishbone_master.blk_read_data_out[i] ;
7685
 
7686
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7687
        begin
7688
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7689
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7690
            test_fail("unexpected data read back from PCI") ;
7691
            ok = 0 ;
7692
        end
7693
    end
7694
 
7695
    if ( ok )
7696
        test_ok ;
7697
 
7698
    $display("Testing Latency timer during Master Reads!") ;
7699
 
7700
    // at least 2 words are transfered during Master Reads terminated with timeout
7701
    write_flags`WB_TRANSFER_SIZE = 2 ;
7702
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7703
    fork
7704
    begin
7705
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7706
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7707
        begin
7708
            $display("Transaction progress testing failed! Time %t ", $time) ;
7709
            $display("Bridge failed to process CAB read!") ;
7710
            test_fail("bridge didn't process burst read as expected") ;
7711
            ok = 0 ;
7712
        end
7713
    end
7714
    begin
7715
        // wait for bridge's master to start transaction
7716
        @(posedge pci_clock) ;
7717
        while ( FRAME === 1 )
7718
            @(posedge pci_clock) ;
7719
 
7720
        // start behavioral master request
7721
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7722
               target_address, wmem_data[0], `Test_All_Bytes,
7723
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7724
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7725
 
7726
        do_pause ( 1 ) ;
7727
    end
7728
    begin
7729
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7730
        if ( ok !== 1 )
7731
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7732
    end
7733
    join
7734
 
7735
    // check data provided by target
7736
    if ( ok )
7737
    begin
7738
        for ( i = 0 ; i < 2 ; i = i + 1 )
7739
        begin
7740
            read_status = wishbone_master.blk_read_data_out[i] ;
7741
 
7742
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7743
            begin
7744
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7745
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7746
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7747
                ok = 0 ;
7748
            end
7749
        end
7750
    end
7751
    if ( ok )
7752
        test_ok ;
7753
 
7754
    test_name = "DISABLE_IMAGE" ;
7755
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7756
    if ( ok !== 1 )
7757
    begin
7758
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7759
        test_fail("write to WB Address Mask register failed") ;
7760
        disable main ;
7761
    end
7762
 
7763
end
7764
endtask //wb_to_pci_transactions
7765
 
7766
task iack_cycle ;
7767
    reg `READ_STIM_TYPE   read_data ;
7768
    reg `READ_RETURN_TYPE read_status ;
7769
    reg `WB_TRANSFER_FLAGS flags ;
7770
 
7771
    reg [31:0] temp_var ;
7772
    reg ok ;
7773 45 mihad
    reg ok_wb ;
7774
    reg ok_pci ;
7775
 
7776
    reg [31:0] irq_vector ;
7777 15 mihad
begin
7778
 
7779 45 mihad
    ok     = 1 ;
7780
    ok_wb  = 1 ;
7781
    ok_pci = 1 ;
7782
 
7783 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7784
 
7785
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7786
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7787
 
7788
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7789
    read_data`READ_SEL     = 4'hF ;
7790
 
7791
    flags = 0 ;
7792
 
7793
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7794
 
7795
    irq_vector  = 32'hAAAA_AAAA ;
7796
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7797
 
7798 45 mihad
    // disable both pci blue behavioral targets
7799
    configuration_cycle_write
7800
    (
7801
        0,                          // bus number [7:0]
7802
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7803
        0,                          // function number [2:0]
7804
        1,                          // register number [5:0]
7805
        0,                          // type [1:0]
7806
        4'h1,                       // byte enables [3:0]
7807
        32'h0000_0044               // data to write [31:0]
7808
    ) ;
7809
 
7810
    configuration_cycle_write
7811
    (
7812
        0,                          // bus number [7:0]
7813
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7814
        0,                          // function number [2:0]
7815
        1,                          // register number [5:0]
7816
        0,                          // type [1:0]
7817
        4'h1,                       // byte enables [3:0]
7818
        32'h0000_0044               // data to write [31:0]
7819
    ) ;
7820
 
7821 15 mihad
    fork
7822
    begin
7823
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7824
    end
7825
    begin
7826 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7827
        if ( ok_pci !== 1 )
7828 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7829
    end
7830
    join
7831
 
7832
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7833
    begin
7834 45 mihad
        ok_wb = 0 ;
7835 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7836
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7837
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7838
    end
7839 45 mihad
 
7840
    if ( ok_pci && ok_wb )
7841 15 mihad
        test_ok ;
7842 45 mihad
 
7843
    ok_wb = 1 ;
7844
    ok_pci = 1 ;
7845
    ok = 1 ;
7846 15 mihad
 
7847 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7848
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7849 15 mihad
 
7850
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7851 45 mihad
    // enable pci blue behavioral target 1
7852
    configuration_cycle_write
7853
    (
7854
        0,                          // bus number [7:0]
7855
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7856
        0,                          // function number [2:0]
7857
        1,                          // register number [5:0]
7858
        0,                          // type [1:0]
7859
        4'h1,                       // byte enables [3:0]
7860
        32'h0000_0047               // data to write [31:0]
7861
    ) ;
7862 15 mihad
    fork
7863
    begin
7864
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7865
    end
7866
    begin
7867 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7868
        if ( ok_pci !== 1 )
7869 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7870
    end
7871
    join
7872
 
7873
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7874
    begin
7875 45 mihad
        ok_wb = 0 ;
7876 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7877
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7878
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7879
    end
7880
 
7881
    if ( read_status`READ_DATA !== irq_vector )
7882
    begin
7883
        $display(" Time %t ", $time ) ;
7884
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7885
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7886 45 mihad
        ok_wb = 0 ;
7887 15 mihad
    end
7888
 
7889 45 mihad
    if ( ok_pci && ok_wb )
7890 15 mihad
        test_ok ;
7891
 
7892 45 mihad
    ok_pci = 1 ;
7893
    ok_wb  = 1 ;
7894
    ok     = 1 ;
7895
 
7896 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7897 45 mihad
    irq_vector  = 32'h5555_5555 ;
7898
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7899
 
7900 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7901
    fork
7902
    begin
7903
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7904
    end
7905
    begin
7906 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7907
        if ( ok_pci !== 1 )
7908 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7909
    end
7910
    join
7911
 
7912
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7913
    begin
7914
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7915
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7916
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7917 45 mihad
        ok_wb = 0 ;
7918 15 mihad
    end
7919
 
7920 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7921 15 mihad
    begin
7922
        $display(" Time %t ", $time ) ;
7923 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7924 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7925 45 mihad
        ok_wb = 0 ;
7926 15 mihad
    end
7927
 
7928 45 mihad
    if (ok_pci && ok_wb)
7929 15 mihad
        test_ok ;
7930
 
7931 45 mihad
    ok_pci = 1 ;
7932
    ok_wb  = 1 ;
7933
    ok     = 1 ;
7934 15 mihad
 
7935 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7936
 
7937
    // set target to terminate with target abort
7938
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7939
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7940
 
7941
    fork
7942
    begin
7943
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7944
    end
7945
    begin
7946
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7947
        if ( ok_pci !== 1 )
7948
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7949
    end
7950
    join
7951
 
7952
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7953
    begin
7954
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7955
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7956
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7957
        ok_wb = 0 ;
7958
    end
7959
 
7960
    // set target to terminate with target abort
7961
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7962
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7963
 
7964
    // enable pci blue behavioral target 2
7965
    configuration_cycle_write
7966
    (
7967
        0,                          // bus number [7:0]
7968
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7969
        0,                          // function number [2:0]
7970
        1,                          // register number [5:0]
7971
        0,                          // type [1:0]
7972
        4'h1,                       // byte enables [3:0]
7973
        32'h0000_0047               // data to write [31:0]
7974
    ) ;
7975
 
7976
    // read PCI Device status
7977
    config_read(12'h4, 4'hC, temp_var) ;
7978
    if (temp_var[29] !== 1)
7979
    begin
7980
        $display("Time %t", $time) ;
7981
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7982
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7983
        ok_wb = 0 ;
7984
    end
7985
 
7986
    if (temp_var[28] !== 1)
7987
    begin
7988
        $display("Time %t", $time) ;
7989
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7990
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7991
        ok_wb = 0 ;
7992
    end
7993
 
7994
    // clearing the status bits
7995
        config_write(12'h4, temp_var, 4'hC, ok);
7996
 
7997
    if ( ok && ok_pci && ok_wb )
7998
        test_ok ;
7999
 
8000 15 mihad
end
8001
endtask //iack_cycle
8002
 
8003
task transaction_ordering ;
8004
    reg   [11:0] wb_ctrl_offset ;
8005
    reg   [11:0] wb_ba_offset ;
8006
    reg   [11:0] wb_am_offset ;
8007
    reg   [11:0] pci_ctrl_offset ;
8008
    reg   [11:0] pci_ba_offset ;
8009
    reg   [11:0] pci_am_offset ;
8010
    reg   [11:0] pci_device_ctrl_offset ;
8011
    reg   [11:0] wb_err_cs_offset ;
8012
    reg   [11:0] pci_err_cs_offset ;
8013
    reg   [11:0] icr_offset ;
8014
    reg   [11:0] isr_offset ;
8015
    reg   [11:0] lat_tim_cls_offset ;
8016
 
8017
    reg `WRITE_STIM_TYPE  write_data ;
8018
    reg `READ_STIM_TYPE   read_data ;
8019
    reg `READ_RETURN_TYPE read_status ;
8020
 
8021
    reg `WRITE_RETURN_TYPE write_status ;
8022
    reg `WB_TRANSFER_FLAGS write_flags ;
8023
    reg [31:0] temp_val1 ;
8024
    reg [31:0] temp_val2 ;
8025
    reg        ok   ;
8026
 
8027
    reg [31:0] wb_image_base ;
8028
    reg [31:0] wb_target_address ;
8029
    reg [31:0] pci_image_base ;
8030
    integer i ;
8031
 
8032
    reg     error_monitor_done ;
8033
begin:main
8034
    write_flags`INIT_WAITS = tb_init_waits ;
8035
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
8036
 
8037
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
8038
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
8039
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
8040
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
8041
 
8042
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
8043
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
8044
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
8045
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
8046
 
8047
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
8048
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
8049
    lat_tim_cls_offset = 12'hC ;
8050
    pci_device_ctrl_offset    = 12'h4 ;
8051
 
8052
    wb_target_address  = `BEH_TAR1_MEM_START ;
8053
    wb_image_base      = 0 ;
8054
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8055
 
8056
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8057
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8058
    write_flags                    = 0 ;
8059
    write_flags`INIT_WAITS         = 0 ;
8060
    write_flags`SUBSEQ_WAITS       = 0 ;
8061
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8062
 
8063
    pci_image_base = Target_Base_Addr_R[1] ;
8064
 
8065
    // enable master & target operation
8066
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8067
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8068
    if ( ok !== 1 )
8069
    begin
8070
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8071
        test_fail("write to PCI Device Control register failed") ;
8072
        disable main ;
8073
    end
8074
 
8075
    // prepare image control register
8076
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8077
    if ( ok !== 1 )
8078
    begin
8079
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8080
        test_fail("write to WB Image Control register failed") ;
8081
        disable main ;
8082
    end
8083
 
8084
    // prepare base address register
8085
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8086
    if ( ok !== 1 )
8087
    begin
8088
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8089
        test_fail("write to WB Base Address register failed") ;
8090
        disable main ;
8091
    end
8092
 
8093
    // write address mask register
8094
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8095
    if ( ok !== 1 )
8096
    begin
8097
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8098
        test_fail("write to WB Address Mask register failed") ;
8099
        disable main ;
8100
    end
8101
 
8102
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8103
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8104
    if ( ok !== 1 )
8105
    begin
8106
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8107
        test_fail("write to WB Error Control and Status register failed") ;
8108
        disable main ;
8109
    end
8110
 
8111
    // prepare image control register
8112
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8113
    if ( ok !== 1 )
8114
    begin
8115
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8116
        test_fail("write to PCI Image Control register failed") ;
8117
        disable main ;
8118
    end
8119
 
8120
    // prepare base address register
8121
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8122
    if ( ok !== 1 )
8123
    begin
8124
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8125
        test_fail("write to PCI Base Address register failed") ;
8126
        disable main ;
8127
    end
8128
 
8129
    // write address mask register
8130
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8131
    if ( ok !== 1 )
8132
    begin
8133
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8134
        test_fail("write to PCI Address Mask register failed") ;
8135
        disable main ;
8136
    end
8137
 
8138
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8139
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8140
    if ( ok !== 1 )
8141
    begin
8142
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8143
        test_fail("write to PCI Error Control and Status register failed") ;
8144
        disable main ;
8145
    end
8146
 
8147
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8148
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8149
    if ( ok !== 1 )
8150
    begin
8151
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8152
        test_fail("write to Interrupt Control register failed") ;
8153
        disable main ;
8154
    end
8155
 
8156
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8157
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8158
    if ( ok !== 1 )
8159
    begin
8160
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8161
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8162
        disable main ;
8163
    end
8164
 
8165
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8166
 
8167
    // prepare wb_master write and read data
8168
    for ( i = 0 ; i < 4 ; i = i + 1 )
8169
    begin
8170
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8171
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8172
        write_data`WRITE_SEL     = 4'hF ;
8173
 
8174
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8175
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8176
 
8177
        wishbone_master.blk_write_data[i]   = write_data ;
8178
        wishbone_master.blk_read_data_in[i] = read_data ;
8179
    end
8180
 
8181
    // put wishbone slave in acknowledge and pci target in retry mode
8182
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8183
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8184
 
8185
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8186
 
8187
    fork
8188
    begin
8189
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8190
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8191
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8192
        begin
8193
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8194
            test_fail("Bridge didn't post single memory write as expected") ;
8195
        end
8196
 
8197
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8198
        if ( ok !== 1 )
8199
        begin
8200
            $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) ;
8201
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8202
            ok = 0 ;
8203
        end
8204
 
8205
        // now post single write to target - normal progress
8206
        if ( target_mem_image == 1 )
8207
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8208
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8209
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8210
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8211
        else
8212
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8213
 
8214
        do_pause( 1 ) ;
8215
 
8216
    end
8217
    begin:error_monitor_1
8218 35 mihad
        error_monitor_done = 0 ;
8219 15 mihad
        @(error_event_int) ;
8220
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8221
        ok = 0 ;
8222 35 mihad
        error_monitor_done = 1 ;
8223 15 mihad
    end
8224
    begin
8225
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8226
        if ( ok !== 1 )
8227
        begin
8228
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8229
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8230
        end
8231
        else
8232
        begin
8233 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8234
//            while ( FRAME === 0 || IRDY === 0 )
8235
//                @(posedge pci_clock) ;
8236 15 mihad
 
8237
            // enable response in PCI target
8238
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8239
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8240
 
8241
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8242
            if ( ok !== 1 )
8243
            begin
8244
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8245
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8246
            end
8247
        end
8248
 
8249 35 mihad
        #1 ;
8250
        if ( !error_monitor_done )
8251
            disable error_monitor_1 ;
8252 15 mihad
    end
8253
    join
8254
 
8255
    if ( ok )
8256
        test_ok ;
8257
 
8258
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8259
 
8260
    // put WISHBONE slave in retry mode
8261
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8262
 
8263
    fork
8264
    begin
8265
        // now post single write to target - normal progress
8266
        if ( target_mem_image == 1 )
8267
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8268
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8269
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8270
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8271
        else
8272
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8273
 
8274
        do_pause( 1 ) ;
8275
 
8276
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8277
        if ( ok !== 1 )
8278
        begin
8279
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8280
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8281
        end
8282
 
8283
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8284
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8285
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8286
        begin
8287
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8288
            test_fail("Bridge didn't post single memory write as expected") ;
8289
        end
8290
 
8291
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8292
        if ( ok !== 1 )
8293
        begin
8294
            $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) ;
8295
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8296
            ok = 0 ;
8297
        end
8298
 
8299
        wait ( CYC_O === 0 ) ;
8300
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8301
 
8302
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8303
        if ( ok !== 1 )
8304
        begin
8305
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8306
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8307
        end
8308
 
8309 35 mihad
        #1 ;
8310
        if ( !error_monitor_done )
8311
            disable error_monitor_2 ;
8312 15 mihad
    end
8313
    begin:error_monitor_2
8314 35 mihad
        error_monitor_done = 0 ;
8315 15 mihad
        @(error_event_int) ;
8316
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8317
        ok = 0 ;
8318 35 mihad
        error_monitor_done = 1 ;
8319 15 mihad
    end
8320
    join
8321
 
8322
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8323
 
8324
    // put wishbone slave in acknowledge and pci target in retry mode
8325
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8326
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8327
 
8328
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8329
 
8330
    fork
8331
    begin
8332
        write_flags`WB_TRANSFER_SIZE = 3 ;
8333
        write_flags`WB_TRANSFER_CAB  = 1 ;
8334
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8335
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8336
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8337
        begin
8338
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8339
            test_fail("Bridge didn't post burst memory write as expected") ;
8340
        end
8341
 
8342
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8343
        if ( ok !== 1 )
8344
        begin
8345
            $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) ;
8346
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8347
            ok = 0 ;
8348
        end
8349
 
8350
        // now post single write to target - normal progress
8351
        if ( target_mem_image == 1 )
8352
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8353
                        pci_image_base, 32'h5555_5555, 4'h0,
8354
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8355
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8356
        else
8357
        begin
8358
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8359
            do_pause( 1 ) ;
8360
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8361
        end
8362
 
8363
        do_pause( 1 ) ;
8364
 
8365
    end
8366
    begin:error_monitor_3
8367 35 mihad
        error_monitor_done = 0 ;
8368 15 mihad
        @(error_event_int) ;
8369
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8370
        ok = 0 ;
8371 35 mihad
        error_monitor_done = 1 ;
8372 15 mihad
    end
8373
    begin
8374
        if ( target_mem_image == 1 )
8375
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8376
        else
8377
        begin
8378
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8379
            if ( ok )
8380
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8381
        end
8382
 
8383
        if ( ok !== 1 )
8384
        begin
8385
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8386
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8387
        end
8388
        else
8389
        begin
8390 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8391
//            while ( FRAME === 0 || IRDY === 0 )
8392
//                @(posedge pci_clock) ;
8393 15 mihad
 
8394
            // enable response in PCI target
8395
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8396
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8397
 
8398
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8399
            if ( ok !== 1 )
8400
            begin
8401
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8402
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8403
            end
8404
        end
8405
 
8406 35 mihad
        #1 ;
8407
        if ( !error_monitor_done )
8408
            disable error_monitor_3 ;
8409 15 mihad
    end
8410
    join
8411
 
8412
    if ( ok )
8413
        test_ok ;
8414
 
8415
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8416
 
8417
    // put WISHBONE slave in retry mode
8418
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8419
 
8420
    fork
8421
    begin
8422
        // now post single write to target - normal progress
8423
        if ( target_mem_image == 1 )
8424
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8425
                        pci_image_base, 32'h5555_5555, 4'h0,
8426
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8427
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8428
        else
8429
        begin
8430
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8431
            do_pause( 1 ) ;
8432
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8433
        end
8434
 
8435
        do_pause( 1 ) ;
8436
 
8437
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8438
 
8439
        if ( ok !== 1 )
8440
        begin
8441
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8442
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8443
        end
8444
 
8445
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8446
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8447
        write_flags`WB_TRANSFER_CAB      = 1 ;
8448
 
8449
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8450
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8451
        begin
8452
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8453
            test_fail("Bridge didn't post burst memory write as expected") ;
8454
        end
8455
 
8456
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8457
        if ( ok !== 1 )
8458
        begin
8459
            $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) ;
8460
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8461
            ok = 0 ;
8462
        end
8463
 
8464
        @(posedge wb_clock) ;
8465
        while ( CYC_O === 1 )
8466
            @(posedge wb_clock) ;
8467
 
8468
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8469
 
8470
        if ( target_mem_image == 1 )
8471
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8472
        else
8473
        begin
8474
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8475
            if ( ok )
8476
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8477
        end
8478
 
8479 35 mihad
        #1 ;
8480
        if ( !error_monitor_done )
8481
            disable error_monitor_4 ;
8482 15 mihad
    end
8483
    begin:error_monitor_4
8484 35 mihad
        error_monitor_done = 0 ;
8485 15 mihad
        @(error_event_int) ;
8486
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8487
        ok = 0 ;
8488 35 mihad
        error_monitor_done = 1 ;
8489 15 mihad
    end
8490
    join
8491
 
8492
    if ( ok )
8493
        test_ok ;
8494
 
8495
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8496
 
8497
    // put wishbone slave in acknowledge and pci target in retry mode
8498
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8499
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8500
 
8501
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8502
 
8503
    master1_check_received_data = 1 ;
8504
 
8505
    error_monitor_done = 0 ;
8506
    fork
8507
    begin:error_monitor_5
8508
        @(error_event_int or error_monitor_done) ;
8509
        if ( !error_monitor_done )
8510
        begin
8511
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8512
            ok = 0 ;
8513
        end
8514
    end
8515
    begin
8516
 
8517
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8518
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8519
        begin
8520
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8521
            test_fail("Bridge didn't post single memory write as expected") ;
8522
        end
8523
 
8524
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8525
        if ( ok !== 1 )
8526
        begin
8527
            $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) ;
8528
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8529
            ok = 0 ;
8530
        end
8531
 
8532
        // start Read Through pci target
8533
        if ( target_mem_image == 1 )
8534
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8535
                          pci_image_base, 32'h5555_5555,
8536
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8537
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8538
        else
8539
            PCIU_IO_READ
8540
             (
8541
                `Test_Master_1,
8542
                pci_image_base,
8543
                32'h5555_5555,
8544
                4'h0,
8545
                1,
8546
                `Test_Target_Retry_On
8547
             );
8548
 
8549
         do_pause( 1 ) ;
8550
 
8551
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8552
         if ( ok !== 1 )
8553
         begin
8554
            $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) ;
8555
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8556
         end
8557
 
8558
         // repeat the read 4 times - it should be retried all the time by pci target
8559
        for ( i = 0 ; i < 4 ; i = i + 1 )
8560
        begin
8561
            if ( target_mem_image == 1 )
8562
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8563
                            pci_image_base, 32'h5555_5555,
8564
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8565
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8566
            else
8567
                PCIU_IO_READ
8568
                (
8569
                    `Test_Master_1,
8570
                    pci_image_base,
8571
                    32'h5555_5555,
8572
                    4'h0,
8573
                    1,
8574
                    `Test_Target_Retry_On
8575
                );
8576
 
8577
            do_pause( 1 ) ;
8578
        end
8579
 
8580
        // now do posted write through target - it must go through OK
8581
        if ( target_mem_image == 1 )
8582
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8583
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8584
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8585
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8586
        else
8587
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8588
 
8589
        do_pause( 1 ) ;
8590
 
8591
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8592
        if ( ok !== 1 )
8593
        begin
8594
           $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) ;
8595
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8596
        end
8597
 
8598
        // start a read through wb_slave
8599
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8600
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8601
        begin
8602
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8603
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8604
            ok = 0 ;
8605
        end
8606
 
8607 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8608
//        while ( FRAME === 0 || IRDY === 0 )
8609
//            @(posedge pci_clock) ;
8610 15 mihad
 
8611
        // set the target to normal completion
8612
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8613
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8614
 
8615
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8616
        if ( ok !== 1 )
8617
        begin
8618
            $display("Transaction ordering test failed! PCI Master started invalid transaction or none at all on PCI bus after single memory write was posted! Time %t ", $time) ;
8619
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8620
            ok = 0 ;
8621
        end
8622
 
8623
        // now wait for delayed read to finish
8624
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8625
        if ( ok !== 1 )
8626
        begin
8627
            $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) ;
8628
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8629
            ok = 0 ;
8630
        end
8631
 
8632
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8633
        fork
8634
        begin
8635
                if ( target_mem_image == 1 )
8636
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8637
                                pci_image_base, 32'h5555_5555, 4'h0,
8638
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8639
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8640
                else
8641
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8642
 
8643
                do_pause( 1 ) ;
8644
                end
8645
                begin
8646
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8647
                end
8648
                join
8649
 
8650
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8651
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8652
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8653
        begin
8654
            $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) ;
8655
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8656
            ok = 0 ;
8657
        end
8658
 
8659
        fork
8660
        begin
8661
        // now complete a read from PCI Target
8662
            if ( target_mem_image == 1 )
8663
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8664
                            pci_image_base, 32'h5555_5555,
8665
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8666
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8667
            else
8668
                PCIU_IO_READ
8669
                (
8670
                    `Test_Master_1,
8671
                    pci_image_base,
8672
                    32'h5555_5555,
8673
                    4'h0,
8674
                    1,
8675
                    `Test_Target_Normal_Completion
8676
                );
8677
 
8678
            do_pause( 1 ) ;
8679
        end
8680
        begin
8681
            if ( target_mem_image == 1 )
8682
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8683
            else
8684
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8685
        end
8686
        join
8687
 
8688
        @(posedge pci_clock) ;
8689
        repeat( 4 )
8690
            @(posedge wb_clock) ;
8691
 
8692
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8693
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8694
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8695
        begin
8696
            $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) ;
8697
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8698
            ok = 0 ;
8699
        end
8700
 
8701
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8702
        if ( ok !== 1 )
8703
        begin
8704
            $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) ;
8705
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8706
            ok = 0 ;
8707
        end
8708
 
8709
        // finish a read on WISHBONE also
8710
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8711
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8712
        begin
8713
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8714
            test_fail("WB Slave didn't process single delayed read as expected") ;
8715
        end
8716
 
8717
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8718
        begin
8719
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8720
            ok = 0 ;
8721
        end
8722
 
8723
 
8724
        error_monitor_done = 1 ;
8725
    end
8726
    join
8727
 
8728
    if ( ok )
8729
        test_ok ;
8730
 
8731
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8732
 
8733
    // put wishbone slave in retry and pci target in completion mode
8734
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8735
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8736
 
8737
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8738
 
8739
    master1_check_received_data = 1 ;
8740
 
8741
    error_monitor_done = 0 ;
8742
    fork
8743
    begin:error_monitor_6
8744
        @(error_event_int or error_monitor_done) ;
8745
        if ( !error_monitor_done )
8746
        begin
8747
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8748
            ok = 0 ;
8749
        end
8750
    end
8751
    begin
8752
 
8753
        // do a write through Target
8754
        fork
8755
        begin
8756
            if ( target_mem_image == 1 )
8757
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8758
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8759
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8760
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8761
            else
8762
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8763
 
8764
            do_pause( 1 ) ;
8765
        end
8766
        begin
8767
            if ( target_mem_image == 1 )
8768
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8769
            else
8770
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8771
        end
8772
        join
8773
 
8774
        // start a read through WB slave
8775
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8776
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8777
        begin
8778
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8779
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8780
            ok = 0 ;
8781
        end
8782
 
8783
        // now wait for this read to finish on pci
8784
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8785
        if ( ok !== 1 )
8786
        begin
8787
            $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) ;
8788
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8789
            ok = 0 ;
8790
        end
8791
 
8792
        // repeat the read four times - it should be retried
8793
        for ( i = 0 ; i < 4 ; i = i + 1 )
8794
        begin
8795
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8796
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8797
            begin
8798
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8799
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8800
                ok = 0 ;
8801
            end
8802
        end
8803
 
8804
        // posted write through WB Slave - must go through
8805
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8806
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8807
        begin
8808
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8809
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8810
            ok = 0 ;
8811
        end
8812
 
8813
        // write must come through
8814
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8815
        if ( ok !== 1 )
8816
        begin
8817
            $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) ;
8818
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8819
            ok = 0 ;
8820
        end
8821
 
8822
        // do a read through pci target
8823
        if ( target_mem_image == 1 )
8824
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8825
                          pci_image_base + 12, 32'hDEAD_BEAF,
8826
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8827
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8828
        else
8829
            PCIU_IO_READ
8830
             (
8831
                `Test_Master_1,
8832
                pci_image_base + 12,
8833
                32'hDEAD_BEAF,
8834
                4'h0,
8835
                1,
8836
                `Test_Target_Retry_On
8837
             );
8838
 
8839
         do_pause( 1 ) ;
8840
 
8841
        // wait for current cycle to finish on WB
8842 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8843
//        @(posedge wb_clock) ;
8844
//        while( CYC_O === 1 )
8845
//            @(posedge wb_clock) ;
8846 15 mihad
 
8847
        // set slave response to acknowledge
8848
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8849
 
8850
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8851
        if ( ok !== 1 )
8852
        begin
8853
            $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) ;
8854
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8855
        end
8856
 
8857
        // check the read to finish on wb
8858
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8859
        if ( ok !== 1 )
8860
        begin
8861
            $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) ;
8862
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8863
        end
8864
 
8865
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8866
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8867
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8868
        begin
8869
            $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) ;
8870
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8871
            ok = 0 ;
8872
        end
8873
 
8874
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8875
        fork
8876
        begin
8877
            if ( target_mem_image == 1 )
8878
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8879
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8880
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8881
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8882
            else
8883
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8884
        end
8885
        begin
8886
            if ( target_mem_image == 1 )
8887
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8888
            else
8889
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8890
        end
8891
        join
8892
 
8893
        do_pause( 1 ) ;
8894
 
8895
        // complete a read in WB Slave Unit
8896
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8897
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8898
        begin
8899
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8900
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8901
            ok = 0 ;
8902
        end
8903
 
8904
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8905
        begin
8906
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8907
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8908
            ok = 0 ;
8909
        end
8910
 
8911
        // wait for statuses to be propagated from one side of bridge to another
8912
        repeat( 4 )
8913
            @(posedge pci_clock) ;
8914
 
8915
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8916
        fork
8917
        begin
8918
            if ( target_mem_image == 1 )
8919
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8920
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8921
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8922
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8923
            else
8924
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8925
 
8926
            do_pause( 1 ) ;
8927
        end
8928
        begin
8929
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8930
            if ( ok !== 1 )
8931
            begin
8932
                $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) ;
8933
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8934
            end
8935
        end
8936
        join
8937
 
8938
        // finish the last read in PCI Target Unit
8939
        if ( target_mem_image == 1 )
8940
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8941
                          pci_image_base + 12, 32'hDEAD_BEAF,
8942
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8943
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8944
        else
8945
            PCIU_IO_READ
8946
             (
8947
                `Test_Master_1,
8948
                pci_image_base + 12,
8949
                32'hDEAD_BEAF,
8950
                4'h0,
8951
                1,
8952
                `Test_Target_Normal_Completion
8953
             );
8954
 
8955
         do_pause( 1 ) ;
8956
 
8957
         error_monitor_done = 1 ;
8958
    end
8959
    join
8960
 
8961
    if ( ok )
8962
        test_ok ;
8963
 
8964
end
8965
endtask // transaction_ordering
8966
 
8967
task pci_transaction_progress_monitor ;
8968
    input [31:0] address ;
8969
    input [3:0]  bus_command ;
8970
    input [31:0] num_of_transfers ;
8971
    input [31:0] num_of_cycles ;
8972
    input check_transfers ;
8973
    input check_cycles ;
8974
    input doing_fast_back_to_back ;
8975
    output ok ;
8976
    reg in_use ;
8977
    integer deadlock_counter ;
8978
    integer transfer_counter ;
8979
    integer cycle_counter ;
8980
    integer deadlock_max_val ;
8981
begin:main
8982
 
8983
    if ( in_use === 1 )
8984
    begin
8985
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8986
        ok = 0 ;
8987
        disable main ;
8988
    end
8989
 
8990
    // approximate number of cycles on WB bus for maximum transaction length
8991
    deadlock_max_val = tb_init_waits + 100 +
8992
                       `WBW_DEPTH *
8993
                       (tb_subseq_waits + 1 +
8994
                       `ifdef REGISTER_WBS_OUTPUTS
8995
                       1) ;
8996
                       `else
8997
                       0) ;
8998
                       `endif
8999
 
9000
    // time used for maximum transaction length on WB
9001
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
9002
 
9003
    // maximum pci clock cycles
9004
    `ifdef PCI33
9005
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
9006
    `else
9007
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
9008
    `endif
9009
 
9010
    in_use = 1 ;
9011
    ok     = 1 ;
9012
 
9013
    fork
9014
    begin:wait_start
9015
 
9016
        deadlock_counter = 0 ;
9017
 
9018
        @(posedge pci_clock) ;
9019
 
9020
        if ( doing_fast_back_to_back !== 1 )
9021
        begin
9022
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
9023
            begin
9024 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
9025
                    deadlock_counter = 0 ;
9026
                else
9027
                    deadlock_counter = deadlock_counter + 1 ;
9028 15 mihad
                @(posedge pci_clock) ;
9029
            end
9030
            if ( FRAME !== 1 )
9031
            begin
9032
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9033
                in_use = 0 ;
9034
                ok     = 0 ;
9035
                disable main ;
9036
            end
9037
        end
9038
 
9039
        deadlock_counter = 0 ;
9040
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
9041
        begin
9042
            deadlock_counter = deadlock_counter + 1 ;
9043
            @(posedge pci_clock) ;
9044
        end
9045
 
9046
        if ( FRAME !== 0 )
9047
        begin
9048
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9049
            in_use = 0 ;
9050
            ok     = 0 ;
9051
            disable main ;
9052
        end
9053
    end //wait_start
9054
 
9055
    begin:addr_bc_monitor
9056
 
9057
        @(posedge pci_clock) ;
9058
 
9059
        if ( doing_fast_back_to_back !== 1 )
9060
        begin
9061
            while ( FRAME !== 1 )
9062
                @(posedge pci_clock) ;
9063
        end
9064
 
9065
        while( FRAME !== 0 )
9066
            @(posedge pci_clock) ;
9067
 
9068
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9069
        if ( bus_command !== `BC_IACK )
9070
        begin
9071
            if ( AD !== address )
9072
            begin
9073
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9074
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9075
                ok = 0 ;
9076
            end
9077
        end
9078
 
9079
        if ( CBE !== bus_command )
9080
        begin
9081
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9082
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9083
            ok = 0 ;
9084
        end
9085
    end //addr_bc_monitor
9086
 
9087
    begin:transfer_checker
9088
        transfer_counter = 0 ;
9089
 
9090
        @(posedge pci_clock) ;
9091
 
9092
        if ( doing_fast_back_to_back !== 1 )
9093
        begin
9094
            while ( FRAME !== 1 )
9095
                @(posedge pci_clock) ;
9096
        end
9097
 
9098
        while( FRAME !== 0 )
9099
            @(posedge pci_clock) ;
9100
 
9101
        while( FRAME === 0 )
9102
        begin
9103
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9104
                transfer_counter = transfer_counter + 1 ;
9105
            @(posedge pci_clock) ;
9106
        end
9107
 
9108
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9109
        begin
9110
            @(posedge pci_clock) ;
9111
        end
9112
 
9113
        if ( (TRDY === 0) && (DEVSEL === 0) )
9114
                transfer_counter = transfer_counter + 1 ;
9115
 
9116
        if ( check_transfers === 1 )
9117
        begin
9118
            if ( transfer_counter !== num_of_transfers )
9119
            begin
9120
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9121
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9122
                ok = 0 ;
9123
            end
9124
        end
9125
    end //transfer_checker
9126
    begin:cycle_checker
9127
        if ( check_cycles )
9128
        begin
9129
            cycle_counter = 0 ;
9130
            @(posedge pci_clock) ;
9131
 
9132
            if ( doing_fast_back_to_back !== 1)
9133
            begin
9134
                while ( FRAME !== 1 )
9135
                    @(posedge pci_clock) ;
9136
            end
9137
 
9138
            while( FRAME !== 0 )
9139
                @(posedge pci_clock) ;
9140
 
9141
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9142
            begin
9143
                cycle_counter = cycle_counter + 1 ;
9144
                @(posedge pci_clock) ;
9145
            end
9146
 
9147
            if ( FRAME !== 1 )
9148
            begin
9149
                while ((FRAME === 0) && (MAS0_GNT === 0))
9150
                    @(posedge pci_clock) ;
9151
 
9152
                if ( FRAME !== 1 )
9153
                begin
9154
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9155
                        @(posedge pci_clock) ;
9156
 
9157
                    @(posedge pci_clock) ;
9158
 
9159
                    if ( FRAME !== 1 )
9160
                    begin
9161
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9162
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9163
                        ok = 0 ;
9164
                    end
9165
                end
9166
            end
9167
        end
9168
    end // cycle_checker
9169
    join
9170
 
9171
    in_use = 0 ;
9172
end
9173
endtask //pci_transaction_progress_monitor
9174
 
9175
reg CYC_O_previous ;
9176
always@(posedge wb_clock or posedge reset)
9177
begin
9178
    if ( reset )
9179
        CYC_O_previous <= #1 1'b0 ;
9180
    else
9181
        CYC_O_previous <= #1 CYC_O ;
9182
end
9183
 
9184
task wb_transaction_progress_monitor ;
9185
    input [31:0] address ;
9186
    input        write ;
9187
    input [31:0] num_of_transfers ;
9188
    input check_transfers ;
9189
    output ok ;
9190
    reg in_use ;
9191
    integer deadlock_counter ;
9192
    integer transfer_counter ;
9193
    integer deadlock_max_val ;
9194
begin:main
9195
    if ( in_use === 1 )
9196
    begin
9197
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9198
        ok = 0 ;
9199
        disable main ;
9200
    end
9201
 
9202
    // number of cycles on WB bus for maximum transaction length
9203
    deadlock_max_val = 4 - tb_init_waits + 100 +
9204
                       `PCIW_DEPTH *
9205
                       (4 - tb_subseq_waits + 1) ;
9206
 
9207
    // time used for maximum transaction length on PCI
9208
    `ifdef PCI33
9209
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9210
    `else
9211
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9212
    `endif
9213
 
9214
    // maximum wb clock cycles
9215
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9216
 
9217
    in_use = 1 ;
9218
    ok     = 1 ;
9219
 
9220
    fork
9221
    begin:wait_start
9222
        deadlock_counter = 0 ;
9223
        @(posedge wb_clock) ;
9224
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9225
        begin
9226 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9227
                deadlock_counter = deadlock_counter + 1 ;
9228
            else
9229
                deadlock_counter = 0;
9230 15 mihad
            @(posedge wb_clock) ;
9231
        end
9232
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9233
        begin
9234
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9235
            in_use = 0 ;
9236
            ok     = 0 ;
9237
            disable main ;
9238
        end
9239
 
9240
        deadlock_counter = 0 ;
9241
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9242
        begin
9243
            deadlock_counter = deadlock_counter + 1 ;
9244
            @(posedge wb_clock) ;
9245
        end
9246
 
9247
        if ( CYC_O !== 1 )
9248
        begin
9249
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9250
            in_use = 0 ;
9251
            ok     = 0 ;
9252
            disable main ;
9253
        end
9254
    end //wait_start
9255
    begin:addr_monitor
9256
        @(posedge wb_clock) ;
9257
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9258
            @(posedge wb_clock) ;
9259
 
9260
        while( CYC_O !== 1 )
9261
            @(posedge wb_clock) ;
9262
 
9263
        while (STB_O !== 1 )
9264
            @(posedge wb_clock) ;
9265
 
9266
        if ( WE_O !== write )
9267
        begin
9268
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9269
            if ( write !== 1 )
9270
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9271
            else
9272
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9273
        end
9274
 
9275
        if ( ADR_O !== address )
9276
        begin
9277
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9278
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9279
            ok = 0 ;
9280
        end
9281
    end
9282
    begin:transfer_checker
9283
        transfer_counter = 0 ;
9284
        @(posedge wb_clock) ;
9285
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9286
            @(posedge wb_clock) ;
9287
 
9288
        while( CYC_O !== 1 )
9289
            @(posedge wb_clock) ;
9290
 
9291 63 mihad
        while( (CYC_O === 1) && ((transfer_counter <= `PCIW_DEPTH) || (transfer_counter <= `PCIR_DEPTH)) )
9292 15 mihad
        begin
9293
            if ( (STB_O === 1) && (ACK_I === 1) )
9294
                transfer_counter = transfer_counter + 1 ;
9295
            @(posedge wb_clock) ;
9296
        end
9297
 
9298
        if ( check_transfers === 1 )
9299
        begin
9300
            if ( transfer_counter !== num_of_transfers )
9301
            begin
9302
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9303
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9304
                ok = 0 ;
9305
            end
9306
        end
9307
    end //transfer_checker
9308
    join
9309
 
9310
    in_use = 0 ;
9311
end
9312
endtask // wb_transaction_progress_monitor
9313
 
9314
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9315
// so they are not re-entered
9316
task wb_transaction_progress_monitor_backup ;
9317
    input [31:0] address ;
9318
    input        write ;
9319
    input [31:0] num_of_transfers ;
9320
    input check_transfers ;
9321
    output ok ;
9322
    reg in_use ;
9323
    integer deadlock_counter ;
9324
    integer transfer_counter ;
9325
    integer deadlock_max_val ;
9326
begin:main
9327
    if ( in_use === 1 )
9328
    begin
9329
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9330
        ok = 0 ;
9331
        disable main ;
9332
    end
9333
 
9334
    // number of cycles on WB bus for maximum transaction length
9335
    deadlock_max_val = 4 - tb_init_waits + 100 +
9336
                       `PCIW_DEPTH *
9337
                       (4 - tb_subseq_waits + 1) ;
9338
 
9339
    // time used for maximum transaction length on PCI
9340
    `ifdef PCI33
9341
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9342
    `else
9343
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9344
    `endif
9345
 
9346
    // maximum wb clock cycles
9347
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9348
 
9349
    in_use = 1 ;
9350
    ok     = 1 ;
9351
 
9352
    fork
9353
    begin:wait_start
9354
        deadlock_counter = 0 ;
9355
        @(posedge wb_clock) ;
9356
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9357
        begin
9358 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9359
                deadlock_counter = deadlock_counter + 1 ;
9360
            else
9361
                deadlock_counter = 0;
9362 15 mihad
            @(posedge wb_clock) ;
9363
        end
9364
        if ( CYC_O !== 0 )
9365
        begin
9366
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9367
            in_use = 0 ;
9368
            ok     = 0 ;
9369
            disable main ;
9370
        end
9371
 
9372
        deadlock_counter = 0 ;
9373
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9374
        begin
9375
            deadlock_counter = deadlock_counter + 1 ;
9376
            @(posedge wb_clock) ;
9377
        end
9378
 
9379
        if ( CYC_O !== 1 )
9380
        begin
9381
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9382
            in_use = 0 ;
9383
            ok     = 0 ;
9384
            disable main ;
9385
        end
9386
    end //wait_start
9387
    begin:addr_monitor
9388
        @(posedge wb_clock) ;
9389
        while ( CYC_O !== 0 )
9390
            @(posedge wb_clock) ;
9391
 
9392
        while( CYC_O !== 1 )
9393
            @(posedge wb_clock) ;
9394
 
9395
        while (STB_O !== 1 )
9396
            @(posedge wb_clock) ;
9397
 
9398
        if ( WE_O !== write )
9399
        begin
9400
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9401
            if ( write !== 1 )
9402
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9403
            else
9404
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9405
        end
9406
 
9407
        if ( ADR_O !== address )
9408
        begin
9409
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9410
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9411
            ok = 0 ;
9412
        end
9413
    end
9414
    begin:transfer_checker
9415
        transfer_counter = 0 ;
9416
        @(posedge wb_clock) ;
9417
        while ( CYC_O !== 0 )
9418
            @(posedge wb_clock) ;
9419
 
9420
        while( CYC_O !== 1 )
9421
            @(posedge wb_clock) ;
9422
 
9423
        while( CYC_O === 1 )
9424
        begin
9425
            if ( (STB_O === 1) && (ACK_I === 1) )
9426
                transfer_counter = transfer_counter + 1 ;
9427
            @(posedge wb_clock) ;
9428
        end
9429
 
9430
        if ( check_transfers === 1 )
9431
        begin
9432
            if ( transfer_counter !== num_of_transfers )
9433
            begin
9434
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9435
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9436
                ok = 0 ;
9437
            end
9438
        end
9439
    end //transfer_checker
9440
    join
9441
 
9442
    in_use = 0 ;
9443
end
9444
endtask // wb_transaction_progress_monitor_backup
9445
 
9446
task wb_transaction_stop ;
9447
    input [31:0] num_of_transfers ;
9448
    integer transfer_counter ;
9449
begin:main
9450
    begin:transfer_checker
9451
        transfer_counter = 0 ;
9452
        @(posedge wb_clock) ;
9453
        while ( CYC_O !== 0 )
9454
            @(posedge wb_clock) ;
9455
 
9456
        while( CYC_O !== 1 )
9457
            @(posedge wb_clock) ;
9458
 
9459
        if ( (STB_O === 1) && (ACK_I === 1) )
9460
            transfer_counter = transfer_counter + 1 ;
9461
 
9462
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9463
        begin
9464
            @(posedge wb_clock) ;
9465
            if ( (STB_O === 1) && (ACK_I === 1) )
9466
                transfer_counter = transfer_counter + 1 ;
9467
        end
9468
    end //transfer_checker
9469
end
9470
endtask // wb_transaction_stop
9471
 
9472
task musnt_respond ;
9473
    output ok ;
9474
    reg in_use ;
9475
    integer i ;
9476
begin:main
9477
    if ( in_use === 1 )
9478
    begin
9479
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9480
        #20 $stop ;
9481
        ok = 0 ;
9482
        disable main ;
9483
    end
9484
 
9485
    in_use = 1 ;
9486
    ok = 1 ;
9487
 
9488
    fork
9489
    begin:wait_start
9490
        @(negedge FRAME) ;
9491
        disable count ;
9492
    end
9493
    begin:count
9494
        i = 0 ;
9495
        while ( i < 1000 )
9496
        begin
9497
            @(posedge pci_clock) ;
9498
            i = i + 1 ;
9499
        end
9500
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9501
        ok = 0 ;
9502
        disable wait_start ;
9503
    end
9504
    join
9505
 
9506
    @(posedge pci_clock) ;
9507
    while ( FRAME === 0 && ok )
9508
    begin
9509
        if ( DEVSEL !== 1 )
9510
        begin
9511
            ok = 0 ;
9512
        end
9513
        @(posedge pci_clock) ;
9514
    end
9515
 
9516
    while ( IRDY === 0 && ok )
9517
    begin
9518
        if ( DEVSEL !== 1 )
9519
        begin
9520
            ok = 0 ;
9521
        end
9522
        @(posedge pci_clock) ;
9523
    end
9524
    in_use = 0 ;
9525
end
9526
endtask
9527
 
9528
function [31:0] wb_to_pci_addr_convert ;
9529
    input [31:0] wb_address ;
9530
    input [31:0] translation_address ;
9531
    input [31:0] translate ;
9532
 
9533
    reg   [31:0] temp_address ;
9534
begin
9535
    if ( translate !== 1 )
9536
    begin
9537
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9538
    end
9539
    else
9540
    begin
9541
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9542
    end
9543
 
9544
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9545
    wb_to_pci_addr_convert = temp_address ;
9546
end
9547
endfunction //wb_to_pci_addr_convert
9548
 
9549 45 mihad
`ifdef HOST
9550 15 mihad
task find_pci_devices ;
9551
    integer device_num ;
9552
    reg     found ;
9553
    reg [11:0] pci_ctrl_offset ;
9554
    reg ok ;
9555
    reg [31:0] data ;
9556 45 mihad
    reg [31:0] expected_data ;
9557
 
9558
    reg [5:0]  reg_num ;
9559 15 mihad
begin:main
9560 45 mihad
 
9561
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9562 15 mihad
    pci_ctrl_offset = 12'h004 ;
9563
 
9564
    // enable master & target operation
9565
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9566
 
9567
    if ( ok !== 1 )
9568
    begin
9569
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9570 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9571 15 mihad
        disable main ;
9572
    end
9573
    // find all possible devices on pci bus by performing configuration cycles
9574 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9575 15 mihad
    begin
9576
        find_device ( device_num, found ) ;
9577
 
9578
        // check pci status register - if device is not present, Received Master Abort bit must be set
9579
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9580
 
9581
        if ( (data[29] !== 0) && (found !== 0) )
9582 45 mihad
        begin
9583 15 mihad
            $display( "Time %t ", $time ) ;
9584
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9585
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9586 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9587
            ok = 0 ;
9588 15 mihad
        end
9589
 
9590
        if ( (data[29] !== 1) && (found !== 1) )
9591
        begin
9592
            $display( "Time %t ", $time ) ;
9593
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9594
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9595 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9596
            ok = 0 ;
9597 15 mihad
        end
9598
 
9599
        // clear Master Abort status if set
9600
        if ( data[29] !== 0 )
9601
        begin
9602
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9603
        end
9604 45 mihad
 
9605
        if (found === 1)
9606
        begin
9607
            // first check if found target is supposed to exist
9608
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9609
            begin
9610
                $display("Time %t", $time) ;
9611
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9612
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9613
                ok = 0 ;
9614
            end
9615
            else
9616
            begin
9617
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9618
                begin
9619
 
9620
                    data = 32'hFFFF_FFFF ;
9621
 
9622
                    expected_data = 0 ;
9623
 
9624
                    if (reg_num == 4)
9625
                    begin
9626
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9627
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9628
                    end
9629
                    else if (reg_num == 5)
9630
                    begin
9631
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9632
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9633
                    end
9634
 
9635
                    // write base address 0
9636
                    generate_configuration_cycle
9637
                    (
9638
                        'h0,            //bus_num
9639
                        device_num,     //device_num
9640
                        'h0,            //func_num
9641
                        reg_num,        //reg_num
9642
                        'h0,            //type
9643
                        4'hF,           // byte_enables
9644
                        data,           //data
9645
                        1'b1            //read0_write1
9646
                    );
9647
 
9648
                    // read data back
9649
                    generate_configuration_cycle
9650
                    (
9651
                        'h0,            //bus_num
9652
                        device_num,     //device_num
9653
                        'h0,            //func_num
9654
                        reg_num,        //reg_num
9655
                        'h0,            //type
9656
                        4'hF,           // byte_enables
9657
                        data,           //data
9658
                        1'b0            //read0_write1
9659
                    );
9660
 
9661
                    if (data !== expected_data)
9662
                    begin
9663
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9664
                        $display("Data read back not as expected!");
9665
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9666
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9667
                        ok = 0 ;
9668
                    end
9669
                end
9670
            end
9671
        end
9672 15 mihad
    end
9673 45 mihad
 
9674
    if (ok)
9675
        test_ok ;
9676 15 mihad
end //main
9677
endtask //find_pci_devices
9678
 
9679
task find_device ;
9680
    input [31:0] device_num ;
9681
    output  found ;
9682
 
9683
    reg [31:0] read_data ;
9684
begin
9685
    found = 1'b0 ;
9686
 
9687
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9688 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9689 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9690
    else
9691
    begin
9692
        $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]) ;
9693
        found = 1'b1 ;
9694
    end
9695
end
9696
endtask //find_device
9697 45 mihad
`endif
9698 15 mihad
 
9699
/*task set_bridge_parameters ;
9700
    reg [11:0] current_offset ;
9701
    reg [2:0] result ;
9702
    reg [31:0] write_data ;
9703
begin
9704
    // set burst size
9705
    // set latency timer
9706
    current_offset = 12'h00C ;
9707
    // set burst size to 16 and latency timer to 8
9708
    write_data     = {24'h0000_08, system_burst_size} ;
9709
    config_write(current_offset, write_data, 4'b1111) ;
9710
 
9711
    // set io image
9712
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9713
    write_data = 32'h0000_000_3 ;
9714
    config_write(current_offset, write_data, 4'b1111) ;
9715
 
9716
 
9717
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9718
    write_data = 32'h0001_000_1 ;
9719
    config_write(current_offset, write_data, 4'b1111) ;
9720
 
9721
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9722
    write_data = 32'hFFFF_0000 ;
9723
    config_write(current_offset, write_data, 4'b1111) ;
9724
 
9725
    // set memory image
9726
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9727
    write_data = 32'h0000_000_7 ;
9728
    config_write(current_offset, write_data, 4'b1111) ;
9729
 
9730
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9731
    write_data = 32'h0002_000_0 ;
9732
    config_write(current_offset, write_data, 4'b1111) ;
9733
 
9734
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9735
    write_data = 32'h0001_0000 ;
9736
    config_write(current_offset, write_data, 4'b1111) ;
9737
 
9738
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9739
    write_data = 32'hFFFF_0000 ;
9740
    config_write(current_offset, write_data, 4'b1111) ;
9741
 
9742
    // set parameters for bridge's target unit
9743
    // image control 0
9744
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9745
    write_data     = 32'h0000_0002 ;
9746
    config_write(current_offset, write_data, 4'b0001) ;
9747
 
9748
    // base_address 0
9749
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9750
    write_data      = 32'h2000_0000 ;
9751
    config_write(current_offset, write_data, 4'b1111) ;
9752
 
9753
    // address mask 0
9754
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9755
    write_data     = 32'hFFFF_F000 ;
9756
    config_write(current_offset, write_data, 4'b1111) ;
9757
 
9758
    // command register - enable response to io and mem space and PCI master
9759
    current_offset = 12'h004 ;
9760
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9761
    config_write(current_offset, write_data, 4'b1111) ;
9762
end
9763
endtask // set_bridge_parameters
9764
*/
9765
 
9766
task configuration_cycle_write ;
9767
    input [7:0]  bus_num ;
9768
    input [4:0]  device_num ;
9769
    input [2:0]  func_num ;
9770
    input [5:0]  reg_num ;
9771
    input [1:0]  type ;
9772
    input [3:0]  byte_enables ;
9773
    input [31:0] data ;
9774
 
9775
    reg [31:0] write_address ;
9776
    reg in_use ;
9777
    reg ok ;
9778
begin:main
9779
 
9780
    if ( in_use === 1 )
9781
    begin
9782 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9783 15 mihad
        disable main ;
9784
    end
9785
 
9786 45 mihad
    if ( (device_num > 20) && (type === 0) )
9787 15 mihad
    begin
9788
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9789
        disable main ;
9790
    end
9791
 
9792
    in_use = 1 ;
9793
 
9794 45 mihad
 
9795
`ifdef HOST
9796
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9797
`else
9798
`ifdef GUEST
9799
 
9800 15 mihad
    if ( type )
9801
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9802
    else
9803
    begin
9804
        write_address = 0 ;
9805
        write_address[10:0] = { func_num, reg_num, type } ;
9806
        write_address[11 + device_num] = 1'b1 ;
9807
    end
9808 45 mihad
 
9809
    fork
9810 15 mihad
    begin
9811 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9812
                            write_address,
9813
                            data, ~byte_enables,
9814
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9815
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9816
        do_pause(1) ;
9817 15 mihad
    end
9818 45 mihad
    begin
9819
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9820
    end
9821
    join
9822
`endif
9823
`endif
9824
 
9825
    in_use = 0 ;
9826
end
9827
endtask // configuration_cycle_write
9828 15 mihad
 
9829 45 mihad
task configuration_cycle_read ;
9830
    input [7:0]  bus_num ;
9831
    input [4:0]  device_num ;
9832
    input [2:0]  func_num ;
9833
    input [5:0]  reg_num ;
9834
    input [1:0]  type ;
9835
    input [3:0]  byte_enables ;
9836
    output [31:0] data ;
9837 15 mihad
 
9838 45 mihad
    reg [31:0] read_address ;
9839
    reg in_use ;
9840 15 mihad
 
9841 45 mihad
    reg master_check_data_prev ;
9842
begin:main
9843 15 mihad
 
9844 45 mihad
    if ( in_use === 1 )
9845 15 mihad
    begin
9846 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9847
        data = 32'hxxxx_xxxx ;
9848
        disable main ;
9849 15 mihad
    end
9850
 
9851 45 mihad
    in_use = 1 ;
9852 15 mihad
 
9853 45 mihad
`ifdef HOST
9854
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9855
`else
9856
`ifdef GUEST
9857
     master_check_data_prev = master1_check_received_data ;
9858 15 mihad
     if ( type )
9859 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9860 15 mihad
     else
9861
     begin
9862 45 mihad
         read_address = 0 ;
9863
         read_address[10:0] = { func_num, reg_num, type } ;
9864
         read_address[11 + device_num] = 1'b1 ;
9865 15 mihad
     end
9866 45 mihad
 
9867
     fork
9868
     begin
9869
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9870
                 read_address,
9871 15 mihad
                 data, ~byte_enables,
9872
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9873
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9874 45 mihad
         do_pause(1) ;
9875
     end
9876
     begin
9877
         @(master1_received_data_valid) ;
9878
         data = master1_received_data ;
9879
     end
9880
     join
9881 15 mihad
 
9882 45 mihad
    master1_check_received_data = master_check_data_prev ;
9883
`endif
9884
`endif
9885
 
9886 15 mihad
    in_use = 0 ;
9887
 
9888 45 mihad
end //main
9889
endtask // configuration_cycle_read
9890
 
9891 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9892
task test_conf_cycle_type1_reference ;
9893
    reg [31:0] address ;
9894
    reg in_use ;
9895
 
9896
    reg master_check_data_prev ;
9897
    reg [31:0] data ;
9898
    reg monitor_ok ;
9899
    reg master_ok ;
9900
begin:main
9901
 
9902
    if ( in_use === 1 )
9903
    begin
9904
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9905
        disable main ;
9906
    end
9907
 
9908
    in_use = 1 ;
9909
 
9910
    master_check_data_prev = master1_check_received_data ;
9911
 
9912
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9913
    address = `TAR0_IDSEL_ADDR ;
9914
 
9915
    address[1:0] = 2'b01 ;
9916
 
9917
    `ifdef HOST
9918
        conf_cyc_type1_target_bus_num = 255 ;
9919
    `endif
9920
    master_ok = 1 ;
9921
    fork
9922
    begin
9923
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9924
        do_pause(1) ;
9925
    end
9926
    begin:error_monitor1
9927
        @(error_event_int) ;
9928
        master_ok = 0 ;
9929
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9930
    end
9931
    begin
9932
        pci_transaction_progress_monitor
9933
        (
9934
            address,                                                // expected address on PCI bus
9935
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9936
            0,                                                      // expected number of succesfull data phases
9937
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9938
            1'b1,                                                   // monitor checking/not checking number of transfers
9939
            1'b0,                                                   // monitor checking/not checking number of cycles
9940
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9941
            monitor_ok                                              // status - 1 success, 0 failure
9942
        ) ;
9943
 
9944
        @(posedge pci_clock);
9945
        #1 ;
9946
 
9947
        if (master_ok)
9948
            disable error_monitor1 ;
9949
 
9950
        if (!monitor_ok)
9951
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9952
    end
9953
    join
9954
 
9955
    if (monitor_ok && master_ok)
9956
        test_ok ;
9957
 
9958
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9959
    master_ok = 1 ;
9960
    fork
9961
    begin
9962
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9963
        do_pause(1) ;
9964
    end
9965
    begin:error_monitor2
9966
        @(error_event_int) ;
9967
        master_ok = 0 ;
9968
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9969
    end
9970
    begin
9971
        pci_transaction_progress_monitor
9972
        (
9973
            address,                                                // expected address on PCI bus
9974
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9975
            0,                                                      // expected number of succesfull data phases
9976
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9977
            1'b1,                                                   // monitor checking/not checking number of transfers
9978
            1'b0,                                                   // monitor checking/not checking number of cycles
9979
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9980
            monitor_ok                                              // status - 1 success, 0 failure
9981
        ) ;
9982
 
9983
        @(posedge pci_clock);
9984
        #1 ;
9985
 
9986
        if (master_ok)
9987
            disable error_monitor2 ;
9988
 
9989
        if (!monitor_ok)
9990
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9991
    end
9992
    join
9993
 
9994
    master1_check_received_data = master_check_data_prev ;
9995
 
9996
    if (monitor_ok && master_ok)
9997
        test_ok ;
9998
 
9999
    in_use = 0 ;
10000
 
10001
end //main
10002
endtask // test_conf_cycle_type1_reference
10003
`endif
10004
 
10005 45 mihad
`ifdef HOST
10006
task generate_configuration_cycle ;
10007 15 mihad
    input [7:0]  bus_num ;
10008
    input [4:0]  device_num ;
10009
    input [2:0]  func_num ;
10010
    input [5:0]  reg_num ;
10011
    input [1:0]  type ;
10012
    input [3:0]  byte_enables ;
10013 45 mihad
    inout [31:0] data ;
10014
    input        read0_write1 ;
10015 15 mihad
 
10016
    reg `READ_STIM_TYPE read_data ;
10017
    reg `WB_TRANSFER_FLAGS  flags ;
10018
    reg `READ_RETURN_TYPE   read_status ;
10019
 
10020
    reg `WRITE_STIM_TYPE   write_data ;
10021
    reg `WRITE_RETURN_TYPE write_status ;
10022
 
10023 45 mihad
    reg [31:0] pci_address ;
10024 15 mihad
    reg in_use ;
10025 45 mihad
    reg ok ;
10026 15 mihad
 
10027
    reg [31:0] temp_var ;
10028
begin:main
10029
 
10030
    if ( in_use === 1 )
10031
    begin
10032 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
10033 15 mihad
        data = 32'hxxxx_xxxx ;
10034
        disable main ;
10035
    end
10036
 
10037 45 mihad
    in_use = 1 ;
10038
 
10039
    if ( type )
10040
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10041
    else
10042 15 mihad
    begin
10043 45 mihad
        pci_address = 0 ;
10044
        pci_address[10:0] = { func_num, reg_num, type } ;
10045
        if (device_num <= 20)
10046
            pci_address[11 + device_num] = 1'b1 ;
10047
    end
10048
 
10049
    // setup flags
10050
    flags = 0 ;
10051
    flags`INIT_WAITS   = tb_init_waits ;
10052
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10053
 
10054
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10055
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10056
 
10057
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10058
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10059
    write_data`WRITE_SEL      = 4'hF ;
10060
    write_data`WRITE_TAG_STIM = 0 ;
10061
 
10062
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10063
 
10064
    // check if write succeeded
10065
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10066
    begin
10067
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10068 15 mihad
        data = 32'hxxxx_xxxx ;
10069 45 mihad
        in_use = 0 ;
10070 15 mihad
        disable main ;
10071
    end
10072
 
10073 45 mihad
    // setup flags for wb master to handle retries and read and write data
10074
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10075
 
10076
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10077
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10078
    read_data`READ_SEL          = byte_enables ;
10079
    write_data`WRITE_SEL        = byte_enables ;
10080
    read_data`READ_TAG_STIM     = 0 ;
10081
    write_data`WRITE_TAG_STIM   = 0 ;
10082
    write_data`WRITE_DATA       = data ;
10083
 
10084
    ok = 0 ;
10085
 
10086
    fork
10087
    begin
10088
        if (read0_write1 === 0)
10089
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10090
        else
10091
        if (read0_write1 === 1)
10092
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10093
    end
10094
    begin
10095
        pci_transaction_progress_monitor
10096
        (
10097
            pci_address,                                            // expected address on PCI bus
10098
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10099
            1,                                                      // expected number of succesfull data phases
10100
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10101
            1'b0,                                                   // monitor checking/not checking number of transfers
10102
            1'b0,                                                   // monitor checking/not checking number of cycles
10103
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10104
            ok                                                      // status - 1 success, 0 failure
10105
        ) ;
10106
    end
10107
    join
10108
 
10109
    // check if transfer succeeded
10110
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10111
    begin
10112
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10113
        data = 32'hxxxx_xxxx ;
10114
        in_use = 0 ;
10115
        disable main ;
10116
    end
10117
 
10118
    if (!ok)
10119
    begin
10120
        data = 32'hxxxx_xxxx ;
10121
        in_use = 0 ;
10122
        disable main ;
10123
    end
10124
 
10125
    if (read0_write1 === 0)
10126
        data = read_status`READ_DATA ;
10127
 
10128
    in_use = 0 ;
10129
end
10130
endtask // generate_configuration_cycle
10131
 
10132
task test_configuration_cycle_target_abort ;
10133
    reg `READ_STIM_TYPE read_data ;
10134
    reg `WB_TRANSFER_FLAGS  flags ;
10135
    reg `READ_RETURN_TYPE   read_status ;
10136
 
10137
    reg `WRITE_STIM_TYPE   write_data ;
10138
    reg `WRITE_RETURN_TYPE write_status ;
10139
 
10140
    reg [31:0] pci_address ;
10141
    reg in_use ;
10142
    reg ok_pci ;
10143
    reg ok_wb  ;
10144
    reg ok     ;
10145
 
10146
    reg [31:0] temp_var ;
10147
 
10148
begin:main
10149
 
10150
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10151
 
10152
    if ( in_use === 1 )
10153
    begin
10154
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10155
        disable main ;
10156
    end
10157
 
10158 15 mihad
    in_use = 1 ;
10159
 
10160 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10161
 
10162 15 mihad
    // setup flags
10163
    flags = 0 ;
10164 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10165
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10166 15 mihad
 
10167
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10168
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10169
 
10170
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10171 45 mihad
    temp_var                  = 0 ;
10172
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10173
    write_data`WRITE_DATA     = temp_var ;
10174 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10175
    write_data`WRITE_TAG_STIM = 0 ;
10176
 
10177
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10178
 
10179
    // check if write succeeded
10180
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10181
    begin
10182
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10183 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10184
        in_use = 0 ;
10185 15 mihad
        disable main ;
10186
    end
10187
 
10188 45 mihad
    // setup flags for wb master to handle retries and read and write data
10189 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10190
 
10191 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10192
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10193 15 mihad
 
10194 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10195
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10196
    read_data`READ_SEL          = 4'hF ;
10197
    write_data`WRITE_SEL        = 4'hF ;
10198
    read_data`READ_TAG_STIM     = 0 ;
10199
    write_data`WRITE_TAG_STIM   = 0 ;
10200
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10201
 
10202
    ok_pci = 0 ;
10203
    ok_wb  = 1 ;
10204
 
10205
    // set target to terminate with target abort
10206
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10207
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10208
    fork
10209
    begin
10210
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10211
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10212
        begin
10213
            $display("Time %t", $time) ;
10214
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10215
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10216
            ok_wb = 0 ;
10217
        end
10218
 
10219
        config_read( 12'h4, 4'hF, temp_var ) ;
10220
        if ( temp_var[29] !== 0 )
10221
        begin
10222
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10223
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10224
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10225
            ok_wb = 0 ;
10226
        end
10227
 
10228
        if ( temp_var[28] !== 1 )
10229
        begin
10230
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10231
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10232
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10233
            ok_wb = 0 ;
10234
        end
10235
 
10236
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10237
 
10238
        if (ok !== 1)
10239
        begin
10240
            ok_wb = 0 ;
10241
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10242
            $display("Write to PCI Device Status Register failed") ;
10243
            test_fail("Write to PCI Device Status Register failed") ;
10244
        end
10245
 
10246
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10247
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10248
        begin
10249
            $display("Time %t", $time) ;
10250
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10251
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10252
            ok_wb = 0 ;
10253
        end
10254
 
10255
        config_read( 12'h4, 4'hF, temp_var ) ;
10256
        if ( temp_var[29] !== 0 )
10257
        begin
10258
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10259
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10260
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10261
            ok_wb = 0 ;
10262
        end
10263
 
10264
        if ( temp_var[28] !== 1 )
10265
        begin
10266
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10267
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10268
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10269
            ok_wb = 0 ;
10270
        end
10271
 
10272
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10273
 
10274
        if (ok !== 1)
10275
        begin
10276
            ok_wb = 0 ;
10277
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10278
            $display("Write to PCI Device Status Register failed") ;
10279
            test_fail("Write to PCI Device Status Register failed") ;
10280
        end
10281
    end
10282
    begin
10283
        pci_transaction_progress_monitor
10284
        (
10285
            pci_address,                                            // expected address on PCI bus
10286
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10287
            0,                                                      // expected number of succesfull data phases
10288
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10289
            1'b1,                                                   // monitor checking/not checking number of transfers
10290
            1'b0,                                                   // monitor checking/not checking number of cycles
10291
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10292
            ok_pci                                                  // status - 1 success, 0 failure
10293
        ) ;
10294
 
10295
        if (ok_pci)
10296
        begin
10297
            pci_transaction_progress_monitor
10298
            (
10299
                pci_address,                                            // expected address on PCI bus
10300
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10301
                0,                                                      // expected number of succesfull data phases
10302
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10303
                1'b1,                                                   // monitor checking/not checking number of transfers
10304
                1'b0,                                                   // monitor checking/not checking number of cycles
10305
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10306
                ok_pci                                                  // status - 1 success, 0 failure
10307
            ) ;
10308
        end
10309
 
10310
        if (!ok_pci)
10311
        begin
10312
            $display("Time %t", $time) ;
10313
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10314
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10315
        end
10316
    end
10317
    join
10318
 
10319
    if (ok_pci && ok_wb)
10320
    begin
10321
        test_ok ;
10322
    end
10323
 
10324
    in_use = 0 ;
10325
 
10326
    // set target to terminate normally
10327
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10328
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10329
end
10330
endtask // test_configuration_cycle_target_abort
10331
 
10332
task test_configuration_cycle_type1_generation ;
10333
    reg `READ_STIM_TYPE read_data ;
10334
    reg `WB_TRANSFER_FLAGS  flags ;
10335
    reg `READ_RETURN_TYPE   read_status ;
10336
 
10337
    reg `WRITE_STIM_TYPE   write_data ;
10338
    reg `WRITE_RETURN_TYPE write_status ;
10339
 
10340
    reg [31:0] pci_address ;
10341
    reg in_use ;
10342
    reg ok_pci ;
10343
    reg ok_wb  ;
10344
    reg ok     ;
10345
 
10346
    reg [31:0] temp_var ;
10347
 
10348
begin:main
10349
 
10350
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10351
    conf_cyc_type1_target_data = 0 ;
10352
    conf_cyc_type1_target_bus_num = 0;
10353
 
10354
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10355
 
10356
    if ( in_use === 1 )
10357
    begin
10358
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10359
        disable main ;
10360
    end
10361
 
10362
    in_use = 1 ;
10363
 
10364
    pci_address        = 32'hAAAA_AAAA ;
10365
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10366
 
10367
    // setup flags
10368
    flags = 0 ;
10369
    flags`INIT_WAITS   = tb_init_waits ;
10370
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10371
 
10372
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10373
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10374
 
10375
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10376
    write_data`WRITE_DATA     = pci_address ;
10377
    write_data`WRITE_SEL      = 4'hF ;
10378
    write_data`WRITE_TAG_STIM = 0 ;
10379
 
10380
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10381
 
10382
    // check if write succeeded
10383
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10384
    begin
10385
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10386
        test_fail("write to configuration cycle address register was not possible") ;
10387
        in_use = 0 ;
10388
        disable main ;
10389
    end
10390
 
10391
    // setup flags for wb master to handle retries and read and write data
10392
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10393
 
10394
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10395
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10396
 
10397
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10398
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10399
    read_data`READ_SEL          = 4'hF ;
10400
    write_data`WRITE_SEL        = 4'hF ;
10401
    read_data`READ_TAG_STIM     = 0 ;
10402
    write_data`WRITE_TAG_STIM   = 0 ;
10403
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10404
 
10405
    ok_pci = 0 ;
10406
    ok_wb  = 1 ;
10407
 
10408
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10409
    pci_address[31:24] = 0 ;
10410
    fork
10411
    begin
10412
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10413
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10414
        begin
10415
            $display("Time %t", $time) ;
10416
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10417
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10418
            ok_wb = 0 ;
10419
        end
10420
 
10421
        config_read( 12'h4, 4'hF, temp_var ) ;
10422
        if ( temp_var[29] !== 1 )
10423
        begin
10424
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10425
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10426
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10427
            ok_wb = 0 ;
10428
        end
10429
 
10430
        if ( temp_var[28] !== 0 )
10431
        begin
10432
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10433
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10434
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10435
            ok_wb = 0 ;
10436
        end
10437
 
10438
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10439
 
10440
        if (ok !== 1)
10441
        begin
10442
            ok_wb = 0 ;
10443
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10444
            $display("Write to PCI Device Status Register failed") ;
10445
            test_fail("Write to PCI Device Status Register failed") ;
10446
        end
10447
 
10448
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10449
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10450
        begin
10451
            $display("Time %t", $time) ;
10452
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10453
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10454
            ok_wb = 0 ;
10455
        end
10456
 
10457
        config_read( 12'h4, 4'hF, temp_var ) ;
10458
        if ( temp_var[29] !== 1 )
10459
        begin
10460
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10461
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10462
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10463
            ok_wb = 0 ;
10464
        end
10465
 
10466
        if ( temp_var[28] !== 0 )
10467
        begin
10468
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10469
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10470
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10471
            ok_wb = 0 ;
10472
        end
10473
 
10474
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10475
 
10476
        if (ok !== 1)
10477
        begin
10478
            ok_wb = 0 ;
10479
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10480
            $display("Write to PCI Device Status Register failed") ;
10481
            test_fail("Write to PCI Device Status Register failed") ;
10482
        end
10483
    end
10484
    begin
10485
        pci_transaction_progress_monitor
10486
        (
10487
            pci_address,                                            // expected address on PCI bus
10488
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10489
            0,                                                      // expected number of succesfull data phases
10490
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10491
            1'b1,                                                   // monitor checking/not checking number of transfers
10492
            1'b0,                                                   // monitor checking/not checking number of cycles
10493
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10494
            ok_pci                                                  // status - 1 success, 0 failure
10495
        ) ;
10496
 
10497
        if (ok_pci)
10498
        begin
10499
            pci_transaction_progress_monitor
10500
            (
10501
                pci_address,                                            // expected address on PCI bus
10502
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10503
                0,                                                      // expected number of succesfull data phases
10504
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10505
                1'b1,                                                   // monitor checking/not checking number of transfers
10506
                1'b0,                                                   // monitor checking/not checking number of cycles
10507
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10508
                ok_pci                                                  // status - 1 success, 0 failure
10509
            ) ;
10510
        end
10511
 
10512
        if (!ok_pci)
10513
        begin
10514
            $display("Time %t", $time) ;
10515
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10516
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10517
        end
10518
    end
10519
    join
10520
 
10521
    if (ok_pci && ok_wb)
10522
    begin
10523
        test_ok ;
10524
    end
10525
 
10526
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10527
    conf_cyc_type1_target_data = 0 ;
10528
    conf_cyc_type1_target_bus_num = 8'h55;
10529
 
10530
    pci_address      = 32'h5555_5555 ;
10531
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10532
 
10533
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10534
 
10535
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10536
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10537
 
10538
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10539
    write_data`WRITE_DATA     = pci_address ;
10540
    write_data`WRITE_SEL      = 4'hF ;
10541
    write_data`WRITE_TAG_STIM = 0 ;
10542
 
10543
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10544
 
10545
    // check if write succeeded
10546
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10547
    begin
10548
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10549
        test_fail("write to configuration cycle address register was not possible") ;
10550
        in_use = 0 ;
10551
        disable main ;
10552
    end
10553
 
10554
    // setup flags for wb master to handle retries and read and write data
10555
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10556
 
10557
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10558
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10559
 
10560
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10561
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10562
    read_data`READ_SEL          = 4'hF ;
10563
    write_data`WRITE_SEL        = 4'hF ;
10564
    read_data`READ_TAG_STIM     = 0 ;
10565
    write_data`WRITE_TAG_STIM   = 0 ;
10566
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10567
 
10568
    ok_pci = 0 ;
10569
    ok_wb  = 1 ;
10570
 
10571
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10572
    pci_address[31:24] = 0 ;
10573
    fork
10574
    begin
10575
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10576
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10577
        begin
10578
            $display("Time %t", $time) ;
10579
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10580
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10581
            ok_wb = 0 ;
10582
        end
10583
 
10584
        config_read( 12'h4, 4'hF, temp_var ) ;
10585
        if ( temp_var[29] !== 0 )
10586
        begin
10587
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10588
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10589
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10590
            ok_wb = 0 ;
10591
        end
10592
 
10593
        if ( temp_var[28] !== 1 )
10594
        begin
10595
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10596
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10597
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10598
            ok_wb = 0 ;
10599
        end
10600
 
10601
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10602
 
10603
        if (ok !== 1)
10604
        begin
10605
            ok_wb = 0 ;
10606
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10607
            $display("Write to PCI Device Status Register failed") ;
10608
            test_fail("Write to PCI Device Status Register failed") ;
10609
        end
10610
 
10611
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10612
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10613
        begin
10614
            $display("Time %t", $time) ;
10615
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10616
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10617
            ok_wb = 0 ;
10618
        end
10619
 
10620
        config_read( 12'h4, 4'hF, temp_var ) ;
10621
        if ( temp_var[29] !== 0 )
10622
        begin
10623
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10624
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10625
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10626
            ok_wb = 0 ;
10627
        end
10628
 
10629
        if ( temp_var[28] !== 1 )
10630
        begin
10631
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10632
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10633
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10634
            ok_wb = 0 ;
10635
        end
10636
 
10637
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10638
 
10639
        if (ok !== 1)
10640
        begin
10641
            ok_wb = 0 ;
10642
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10643
            $display("Write to PCI Device Status Register failed") ;
10644
            test_fail("Write to PCI Device Status Register failed") ;
10645
        end
10646
    end
10647
    begin
10648
        pci_transaction_progress_monitor
10649
        (
10650
            pci_address,                                            // expected address on PCI bus
10651
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10652
            0,                                                      // expected number of succesfull data phases
10653
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10654
            1'b1,                                                   // monitor checking/not checking number of transfers
10655
            1'b0,                                                   // monitor checking/not checking number of cycles
10656
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10657
            ok_pci                                                  // status - 1 success, 0 failure
10658
        ) ;
10659
 
10660
        if (ok_pci)
10661
        begin
10662
            pci_transaction_progress_monitor
10663
            (
10664
                pci_address,                                            // expected address on PCI bus
10665
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10666
                0,                                                      // expected number of succesfull data phases
10667
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10668
                1'b1,                                                   // monitor checking/not checking number of transfers
10669
                1'b0,                                                   // monitor checking/not checking number of cycles
10670
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10671
                ok_pci                                                  // status - 1 success, 0 failure
10672
            ) ;
10673
        end
10674
 
10675
        if (!ok_pci)
10676
        begin
10677
            $display("Time %t", $time) ;
10678
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10679
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10680
        end
10681
    end
10682
    join
10683
 
10684
    if (ok_pci && ok_wb)
10685
    begin
10686
        test_ok ;
10687
    end
10688
 
10689
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10690
 
10691
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10692
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10693
    conf_cyc_type1_target_bus_num = 8'hAA;
10694
 
10695
    pci_address      = 32'hAAAA_AAAA ;
10696
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10697
 
10698
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10699
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10700
 
10701
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10702
    write_data`WRITE_DATA     = pci_address ;
10703
    write_data`WRITE_SEL      = 4'hF ;
10704
    write_data`WRITE_TAG_STIM = 0 ;
10705
 
10706
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10707
 
10708
    // check if write succeeded
10709
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10710
    begin
10711
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10712
        test_fail("write to configuration cycle address register was not possible") ;
10713
        in_use = 0 ;
10714
        disable main ;
10715
    end
10716
 
10717
    // setup flags for wb master to handle retries and read and write data
10718
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10719
 
10720
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10721
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10722
 
10723
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10724
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10725
    read_data`READ_SEL          = 4'b0101 ;
10726
    write_data`WRITE_SEL        = 4'b1010 ;
10727
    read_data`READ_TAG_STIM     = 0 ;
10728
    write_data`WRITE_TAG_STIM   = 0 ;
10729
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10730
 
10731
    ok_pci = 0 ;
10732
    ok_wb  = 1 ;
10733
 
10734
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10735
    pci_address[31:24] = 0 ;
10736
 
10737
    fork
10738
    begin
10739
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10740
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10741
        begin
10742
            $display("Time %t", $time) ;
10743
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10744
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10745
            ok_wb = 0 ;
10746
        end
10747
 
10748
        config_read( 12'h4, 4'hF, temp_var ) ;
10749
        if ( temp_var[29] !== 0 )
10750
        begin
10751
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10752
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10753
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10754
            ok_wb = 0 ;
10755
        end
10756
 
10757
        if ( temp_var[28] !== 0 )
10758
        begin
10759
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10760
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10761
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10762
            ok_wb = 0 ;
10763
        end
10764
 
10765
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10766
 
10767
        if (ok !== 1)
10768
        begin
10769
            ok_wb = 0 ;
10770
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10771
            $display("Write to PCI Device Status Register failed") ;
10772
            test_fail("Write to PCI Device Status Register failed") ;
10773
        end
10774
 
10775
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10776
        begin
10777
            ok_wb = 0 ;
10778
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10779
            $display("Read Data provided by the bridge was not as expected!") ;
10780
            test_fail("Read Data provided by the bridge was not as expected") ;
10781
        end
10782
 
10783
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10784
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10785
        begin
10786
            $display("Time %t", $time) ;
10787
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10788
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10789
            ok_wb = 0 ;
10790
        end
10791
 
10792
        config_read( 12'h4, 4'hF, temp_var ) ;
10793
        if ( temp_var[29] !== 0 )
10794
        begin
10795
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10796
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10797
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10798
            ok_wb = 0 ;
10799
        end
10800
 
10801
        if ( temp_var[28] !== 0 )
10802
        begin
10803
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10804
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10805
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10806
            ok_wb = 0 ;
10807
        end
10808
 
10809
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10810
 
10811
        if (ok !== 1)
10812
        begin
10813
            ok_wb = 0 ;
10814
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10815
            $display("Write to PCI Device Status Register failed") ;
10816
            test_fail("Write to PCI Device Status Register failed") ;
10817
        end
10818
 
10819
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10820
        begin
10821
            ok_wb = 0 ;
10822
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10823
            $display("Data written by the bridge was not as expected!") ;
10824
            test_fail("Data written by the bridge was not as expected") ;
10825
        end
10826
 
10827
    end
10828
    begin
10829
        ok = 1 ;
10830
        repeat(8)
10831
        begin
10832
            pci_transaction_progress_monitor
10833
            (
10834
                pci_address,                                            // expected address on PCI bus
10835
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10836
                0,                                                      // expected number of succesfull data phases
10837
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10838
                1'b1,                                                   // monitor checking/not checking number of transfers
10839
                1'b0,                                                   // monitor checking/not checking number of cycles
10840
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10841
                ok_pci                                                  // status - 1 success, 0 failure
10842
            ) ;
10843
 
10844
            if (!ok_pci)
10845
            begin
10846
                ok = 0 ;
10847
                $display("Time %t", $time) ;
10848
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10849
            end
10850
        end
10851
 
10852
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10853
 
10854
        pci_transaction_progress_monitor
10855
        (
10856
            pci_address,                                            // expected address on PCI bus
10857
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10858
            1,                                                      // expected number of succesfull data phases
10859
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10860
            1'b1,                                                   // monitor checking/not checking number of transfers
10861
            1'b0,                                                   // monitor checking/not checking number of cycles
10862
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10863
            ok_pci                                                  // status - 1 success, 0 failure
10864
        ) ;
10865
 
10866
        if (!ok_pci)
10867
        begin
10868
            ok = 0 ;
10869
            $display("Time %t", $time) ;
10870
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10871
        end
10872
 
10873
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10874
        repeat(8)
10875
        begin
10876
            pci_transaction_progress_monitor
10877
            (
10878
                pci_address,                                            // expected address on PCI bus
10879
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10880
                0,                                                      // expected number of succesfull data phases
10881
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10882
                1'b1,                                                   // monitor checking/not checking number of transfers
10883
                1'b0,                                                   // monitor checking/not checking number of cycles
10884
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10885
                ok_pci                                                  // status - 1 success, 0 failure
10886
            ) ;
10887
 
10888
            if (!ok_pci)
10889
            begin
10890
                ok = 0 ;
10891
                $display("Time %t", $time) ;
10892
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10893
            end
10894
        end
10895
 
10896
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10897
        pci_transaction_progress_monitor
10898
        (
10899
            pci_address,                                            // expected address on PCI bus
10900
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10901
            1,                                                      // expected number of succesfull data phases
10902
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10903
            1'b1,                                                   // monitor checking/not checking number of transfers
10904
            1'b0,                                                   // monitor checking/not checking number of cycles
10905
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10906
            ok_pci                                                  // status - 1 success, 0 failure
10907
        ) ;
10908
 
10909
        if (!ok_pci)
10910
        begin
10911
            ok = 0 ;
10912
            $display("Time %t", $time) ;
10913
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10914
        end
10915
 
10916
        if (!ok)
10917
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10918
    end
10919
    join
10920
 
10921
    if (ok_pci && ok_wb)
10922
    begin
10923
        test_ok ;
10924
    end
10925
 
10926
    in_use = 0 ;
10927
end
10928
endtask // test_configuration_cycle_type1_generation
10929
`endif
10930
 
10931
task test_initial_conf_values ;
10932
    reg [11:0] register_offset ;
10933
    reg [31:0] expected_value ;
10934
    reg        failed ;
10935
`ifdef HOST
10936
    reg `READ_STIM_TYPE    read_data ;
10937
    reg `WB_TRANSFER_FLAGS flags ;
10938
    reg `READ_RETURN_TYPE  read_status ;
10939
 
10940
    reg `WRITE_STIM_TYPE   write_data ;
10941
    reg `WRITE_RETURN_TYPE write_status ;
10942
begin
10943
    failed     = 0 ;
10944
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10945
    flags      = 0 ;
10946
    read_data  = 0 ;
10947
    write_data = 0 ;
10948
 
10949
    read_data`READ_SEL = 4'hF ;
10950
 
10951
    flags`INIT_WAITS           = tb_init_waits ;
10952
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10953
 
10954
    // test MEM/IO map bit initial value in each PCI BAR
10955
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10956
 
10957
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10958
 
10959 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10960
 
10961 45 mihad
    `ifdef NO_CNF_IMAGE
10962
        `ifdef PCI_IMAGE0
10963
            if (`PCI_AM0)
10964
                expected_value = `PCI_BA0_MEM_IO ;
10965
            else
10966
                expected_value = 32'h0000_0000 ;
10967
        `else
10968
            expected_value = 32'h0000_0000 ;
10969
        `endif
10970
    `else
10971
        expected_value = 32'h0000_0000 ;
10972
    `endif
10973
 
10974 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10975
    begin
10976 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10977
        failed = 1 ;
10978 15 mihad
    end
10979 45 mihad
    else
10980
    begin
10981
        if (read_status`READ_DATA !== expected_value)
10982
        begin
10983
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10984
            failed = 1 ;
10985
        end
10986
    end
10987 15 mihad
 
10988 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10989 15 mihad
 
10990 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10991
 
10992
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10993
 
10994
    if (`PCI_AM1)
10995
        expected_value = `PCI_BA1_MEM_IO ;
10996
    else
10997
        expected_value = 32'h0000_0000 ;
10998
 
10999
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11000
    begin
11001
        test_fail("read from P_BA1 register didn't succeede") ;
11002
        failed = 1 ;
11003
    end
11004
    else
11005
    begin
11006
        if (read_status`READ_DATA !== expected_value)
11007
        begin
11008
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
11009
            failed = 1 ;
11010
        end
11011
    end
11012
 
11013
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
11014
 
11015
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11016
 
11017
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11018
 
11019
    `ifdef PCI_IMAGE2
11020
        if (`PCI_AM2)
11021
            expected_value = `PCI_BA2_MEM_IO ;
11022
        else
11023
            expected_value = 32'h0000_0000 ;
11024 15 mihad
    `else
11025 45 mihad
        expected_value = 32'h0000_0000 ;
11026
    `endif
11027 15 mihad
 
11028 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11029
    begin
11030
        test_fail("read from P_BA2 register didn't succeede") ;
11031
        failed = 1 ;
11032
    end
11033
    else
11034
    begin
11035
        if (read_status`READ_DATA !== expected_value)
11036
        begin
11037
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
11038
            failed = 1 ;
11039
        end
11040
    end
11041 15 mihad
 
11042 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
11043
 
11044
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11045
 
11046
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11047
 
11048
    `ifdef PCI_IMAGE3
11049
        if (`PCI_AM3)
11050
            expected_value = `PCI_BA3_MEM_IO ;
11051
        else
11052
            expected_value = 32'h0000_0000 ;
11053
    `else
11054
        expected_value = 32'h0000_0000 ;
11055 15 mihad
    `endif
11056 45 mihad
 
11057
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11058
    begin
11059
        test_fail("read from P_BA3 register didn't succeede") ;
11060
        failed = 1 ;
11061
    end
11062
    else
11063
    begin
11064
        if (read_status`READ_DATA !== expected_value)
11065
        begin
11066
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11067
            failed = 1 ;
11068
        end
11069
    end
11070
 
11071
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11072
 
11073
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11074
 
11075
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11076
 
11077
    `ifdef PCI_IMAGE4
11078
        if (`PCI_AM4)
11079
            expected_value = `PCI_BA4_MEM_IO ;
11080
        else
11081
            expected_value = 32'h0000_0000 ;
11082
    `else
11083
        expected_value = 32'h0000_0000 ;
11084 15 mihad
    `endif
11085
 
11086 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11087
    begin
11088
        test_fail("read from P_BA4 register didn't succeede") ;
11089
        failed = 1 ;
11090
    end
11091
    else
11092
    begin
11093
        if (read_status`READ_DATA !== expected_value)
11094
        begin
11095
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11096
            failed = 1 ;
11097
        end
11098
    end
11099 15 mihad
 
11100 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11101 15 mihad
 
11102 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11103
 
11104
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11105
 
11106
    `ifdef PCI_IMAGE5
11107
        if(`PCI_AM5)
11108
            expected_value = `PCI_BA5_MEM_IO ;
11109
        else
11110
            expected_value = 32'h0000_0000 ;
11111
    `else
11112
        expected_value = 32'h0000_0000 ;
11113
    `endif
11114
 
11115
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11116
    begin
11117
        test_fail("read from P_BA5 register didn't succeede") ;
11118
        failed = 1 ;
11119
    end
11120
    else
11121
    begin
11122
        if (read_status`READ_DATA !== expected_value)
11123
        begin
11124
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11125
            failed = 1 ;
11126
        end
11127
    end
11128
 
11129
    // test Address Mask initial values
11130
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11131
 
11132
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11133
 
11134
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11135
 
11136
    `ifdef NO_CNF_IMAGE
11137
        `ifdef PCI_IMAGE0
11138
            expected_value = {`PCI_AM0, 12'h000};
11139
 
11140
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11141
        `else
11142
            expected_value = 32'h0000_0000 ;
11143
        `endif
11144
    `else
11145
        expected_value = 32'hFFFF_FFFF ;
11146
 
11147
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11148
    `endif
11149
 
11150
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11151
    begin
11152
        test_fail("read from P_AM0 register didn't succeede") ;
11153
        failed = 1 ;
11154
    end
11155
    else
11156
    begin
11157
        if (read_status`READ_DATA !== expected_value)
11158
        begin
11159
            test_fail("AM0 initial value was not set as defined");
11160
            failed = 1 ;
11161
        end
11162
    end
11163
 
11164
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11165
 
11166
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11167
 
11168
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11169
 
11170
    expected_value = {`PCI_AM1, 12'h000};
11171
 
11172
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11173
 
11174
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11175
    begin
11176
        test_fail("read from P_AM1 register didn't succeede") ;
11177
        failed = 1 ;
11178
    end
11179
    else
11180
    begin
11181
        if (read_status`READ_DATA !== expected_value)
11182
        begin
11183
            test_fail("AM1 initial value was not set as defined");
11184
            failed = 1 ;
11185
        end
11186
    end
11187
 
11188
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11189
 
11190
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11191
 
11192
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11193
 
11194
    `ifdef PCI_IMAGE2
11195
        expected_value = {`PCI_AM2, 12'h000};
11196
 
11197
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11198
    `else
11199
        expected_value = 32'h0000_0000 ;
11200
    `endif
11201
 
11202
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11203
    begin
11204
        test_fail("read from P_AM2 register didn't succeede") ;
11205
        failed = 1 ;
11206
    end
11207
    else
11208
    begin
11209
        if (read_status`READ_DATA !== expected_value)
11210
        begin
11211
            test_fail("AM2 initial value was not set as defined");
11212
            failed = 1 ;
11213
        end
11214
    end
11215
 
11216
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11217
 
11218
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11219
 
11220
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11221
 
11222
    `ifdef PCI_IMAGE3
11223
        expected_value = {`PCI_AM3, 12'h000};
11224
 
11225
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11226
    `else
11227
        expected_value = 32'h0000_0000 ;
11228
    `endif
11229
 
11230
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11231
    begin
11232
        test_fail("read from P_AM3 register didn't succeede") ;
11233
        failed = 1 ;
11234
    end
11235
    else
11236
    begin
11237
        if (read_status`READ_DATA !== expected_value)
11238
        begin
11239
            test_fail("AM3 initial value was not set as defined");
11240
            failed = 1 ;
11241
        end
11242
    end
11243
 
11244
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11245
 
11246
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11247
 
11248
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11249
 
11250
    `ifdef PCI_IMAGE4
11251
        expected_value = {`PCI_AM4, 12'h000};
11252
 
11253
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11254
    `else
11255
        expected_value = 32'h0000_0000 ;
11256
    `endif
11257
 
11258
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11259
    begin
11260
        test_fail("read from P_AM4 register didn't succeede") ;
11261
        failed = 1 ;
11262
    end
11263
    else
11264
    begin
11265
        if (read_status`READ_DATA !== expected_value)
11266
        begin
11267
            test_fail("AM4 initial value was not set as defined");
11268
            failed = 1 ;
11269
        end
11270
    end
11271
 
11272
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11273
 
11274
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11275
 
11276
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11277
 
11278
    `ifdef PCI_IMAGE5
11279
        expected_value = {`PCI_AM5, 12'h000};
11280
 
11281
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11282
    `else
11283
        expected_value = 32'h0000_0000 ;
11284
    `endif
11285
 
11286
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11287
    begin
11288
        test_fail("read from P_AM5 register didn't succeede") ;
11289
        failed = 1 ;
11290
    end
11291
    else
11292
    begin
11293
        if (read_status`READ_DATA !== expected_value)
11294
        begin
11295
            test_fail("AM5 initial value was not set as defined");
11296
            failed = 1 ;
11297
        end
11298
    end
11299
 
11300
`endif
11301
 
11302
`ifdef GUEST
11303
    reg [31:0] read_data ;
11304
begin
11305
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11306
    failed    = 0 ;
11307
 
11308
    // check all images' BARs
11309
 
11310
    // BAR0
11311
    configuration_cycle_read
11312
    (
11313
        8'h00,                          // bus number [7:0]
11314
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11315
        3'h0,                           // function number [2:0]
11316
        6'h4,                           // register number [5:0]
11317
        2'h0,                           // type [1:0]
11318
        4'hF,                           // byte enables [3:0]
11319
        read_data                       // data returned from configuration read [31:0]
11320
    ) ;
11321
 
11322
    expected_value = 32'h0000_0000 ;
11323
 
11324
    if( read_data !== expected_value)
11325
    begin
11326
        test_fail("initial value of BAR0 register not as expected") ;
11327
        failed = 1 ;
11328
    end
11329
 
11330
    // BAR1
11331
    configuration_cycle_read
11332
    (
11333
        8'h00,                          // bus number [7:0]
11334
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11335
        3'h0,                           // function number [2:0]
11336
        6'h5,                           // register number [5:0]
11337
        2'h0,                           // type [1:0]
11338
        4'hF,                           // byte enables [3:0]
11339
        read_data                       // data returned from configuration read [31:0]
11340
    ) ;
11341
 
11342
    if (`PCI_AM1)
11343
        expected_value = `PCI_BA1_MEM_IO ;
11344
    else
11345
        expected_value = 32'h0000_0000 ;
11346
 
11347
    if( read_data !== expected_value)
11348
    begin
11349
        test_fail("initial value of BAR1 register not as expected") ;
11350
        failed = 1 ;
11351
    end
11352
 
11353
    // BAR2
11354
    configuration_cycle_read
11355
    (
11356
        8'h00,                          // bus number [7:0]
11357
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11358
        3'h0,                           // function number [2:0]
11359
        6'h6,                           // register number [5:0]
11360
        2'h0,                           // type [1:0]
11361
        4'hF,                           // byte enables [3:0]
11362
        read_data                       // data returned from configuration read [31:0]
11363
    ) ;
11364
 
11365
    `ifdef PCI_IMAGE2
11366
    if (`PCI_AM2)
11367
        expected_value = `PCI_BA2_MEM_IO ;
11368
    else
11369
        expected_value = 32'h0000_0000 ;
11370
    `else
11371
    expected_value = 32'h0 ;
11372
    `endif
11373
 
11374
    if( read_data !== expected_value)
11375
    begin
11376
        test_fail("initial value of BAR2 register not as expected") ;
11377
        failed = 1 ;
11378
    end
11379
 
11380
    // BAR3
11381
    configuration_cycle_read
11382
    (
11383
        8'h00,                          // bus number [7:0]
11384
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11385
        3'h0,                           // function number [2:0]
11386
        6'h7,                           // register number [5:0]
11387
        2'h0,                           // type [1:0]
11388
        4'hF,                           // byte enables [3:0]
11389
        read_data                       // data returned from configuration read [31:0]
11390
    ) ;
11391
 
11392
    `ifdef PCI_IMAGE3
11393
    if(`PCI_AM3)
11394
        expected_value = `PCI_BA3_MEM_IO ;
11395
    else
11396
        expected_value = 32'h0000_0000 ;
11397
    `else
11398
    expected_value = 32'h0 ;
11399
    `endif
11400
 
11401
    if( read_data !== expected_value)
11402
    begin
11403
        test_fail("initial value of BAR3 register not as expected") ;
11404
        failed = 1 ;
11405
    end
11406
 
11407
    // BAR4
11408
    configuration_cycle_read
11409
    (
11410
        8'h00,                          // bus number [7:0]
11411
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11412
        3'h0,                           // function number [2:0]
11413
        6'h8,                           // register number [5:0]
11414
        2'h0,                           // type [1:0]
11415
        4'hF,                           // byte enables [3:0]
11416
        read_data                       // data returned from configuration read [31:0]
11417
    ) ;
11418
 
11419
    `ifdef PCI_IMAGE4
11420
    if (`PCI_AM4)
11421
        expected_value = `PCI_BA4_MEM_IO ;
11422
    else
11423
        expected_value = 32'h0000_0000 ;
11424
    `else
11425
    expected_value = 32'h0 ;
11426
    `endif
11427
 
11428
    if( read_data !== expected_value)
11429
    begin
11430
        test_fail("initial value of BAR4 register not as expected") ;
11431
        failed = 1 ;
11432
    end
11433
 
11434
    // BAR5
11435
    configuration_cycle_read
11436
    (
11437
        8'h00,                          // bus number [7:0]
11438
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11439
        3'h0,                           // function number [2:0]
11440
        6'h9,                           // register number [5:0]
11441
        2'h0,                           // type [1:0]
11442
        4'hF,                           // byte enables [3:0]
11443
        read_data                       // data returned from configuration read [31:0]
11444
    ) ;
11445
 
11446
    `ifdef PCI_IMAGE5
11447
    if(`PCI_AM5)
11448
        expected_value = `PCI_BA5_MEM_IO ;
11449
    else
11450
        expected_value = 32'h0000_0000 ;
11451
    `else
11452
    expected_value = 32'h0 ;
11453
    `endif
11454
 
11455
    if( read_data !== expected_value)
11456
    begin
11457
        test_fail("initial value of BAR5 register not as expected") ;
11458
        failed = 1 ;
11459
    end
11460
 
11461
    // write all 1s to BAR0
11462
    read_data = 32'hFFFF_FFFF ;
11463
 
11464
    // BAR0
11465
    configuration_cycle_write
11466
    (
11467
        8'h00,                          // bus number [7:0]
11468
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11469
        3'h0,                           // function number [2:0]
11470
        6'h4,                           // register number [5:0]
11471
        2'h0,                           // type [1:0]
11472
        4'hF,                           // byte enables [3:0]
11473
        read_data                       // data to write [31:0]
11474
    ) ;
11475
 
11476
    expected_value = 32'hFFFF_FFFF ;
11477
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11478
 
11479
    configuration_cycle_read
11480
    (
11481
        8'h00,                          // bus number [7:0]
11482
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11483
        3'h0,                           // function number [2:0]
11484
        6'h4,                           // register number [5:0]
11485
        2'h0,                           // type [1:0]
11486
        4'hF,                           // byte enables [3:0]
11487
        read_data                       // data to write [31:0]
11488
    ) ;
11489
 
11490
    if ( read_data !== expected_value )
11491
    begin
11492
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11493
        failed = 1 ;
11494
    end
11495
 
11496
    // write all 1s to BAR1
11497
    read_data = 32'hFFFF_FFFF ;
11498
 
11499
    // BAR1
11500
    configuration_cycle_write
11501
    (
11502
        8'h00,                          // bus number [7:0]
11503
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11504
        3'h0,                           // function number [2:0]
11505
        6'h5,                           // register number [5:0]
11506
        2'h0,                           // type [1:0]
11507
        4'hF,                           // byte enables [3:0]
11508
        read_data                       // data to write [31:0]
11509
    ) ;
11510
 
11511
    expected_value = {`PCI_AM1, 12'h000} ;
11512
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11513
    if (`PCI_AM1)
11514
        expected_value[0] = `PCI_BA1_MEM_IO ;
11515
 
11516
    configuration_cycle_read
11517
    (
11518
        8'h00,                          // bus number [7:0]
11519
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11520
        3'h0,                           // function number [2:0]
11521
        6'h5,                           // register number [5:0]
11522
        2'h0,                           // type [1:0]
11523
        4'hF,                           // byte enables [3:0]
11524
        read_data                       // data to write [31:0]
11525
    ) ;
11526
 
11527
    if ( read_data !== expected_value )
11528
    begin
11529
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11530
        failed = 1 ;
11531
    end
11532
 
11533
    // write all 1s to BAR2
11534
    read_data = 32'hFFFF_FFFF ;
11535
 
11536
    // BAR2
11537
    configuration_cycle_write
11538
    (
11539
        8'h00,                          // bus number [7:0]
11540
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11541
        3'h0,                           // function number [2:0]
11542
        6'h6,                           // register number [5:0]
11543
        2'h0,                           // type [1:0]
11544
        4'hF,                           // byte enables [3:0]
11545
        read_data                       // data to write [31:0]
11546
    ) ;
11547
 
11548
`ifdef PCI_IMAGE2
11549
    expected_value = {`PCI_AM2, 12'h000} ;
11550
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11551
    if (`PCI_AM2)
11552
        expected_value[0] = `PCI_BA2_MEM_IO ;
11553
`else
11554
    expected_value = 0 ;
11555
`endif
11556
 
11557
    configuration_cycle_read
11558
    (
11559
        8'h00,                          // bus number [7:0]
11560
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11561
        3'h0,                           // function number [2:0]
11562
        6'h6,                           // register number [5:0]
11563
        2'h0,                           // type [1:0]
11564
        4'hF,                           // byte enables [3:0]
11565
        read_data                       // data to write [31:0]
11566
    ) ;
11567
 
11568
    if ( read_data !== expected_value )
11569
    begin
11570
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11571
        failed = 1 ;
11572
    end
11573
 
11574
    // write all 1s to BAR3
11575
    read_data = 32'hFFFF_FFFF ;
11576
 
11577
    // BAR3
11578
    configuration_cycle_write
11579
    (
11580
        8'h00,                          // bus number [7:0]
11581
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11582
        3'h0,                           // function number [2:0]
11583
        6'h7,                           // register number [5:0]
11584
        2'h0,                           // type [1:0]
11585
        4'hF,                           // byte enables [3:0]
11586
        read_data                       // data to write [31:0]
11587
    ) ;
11588
 
11589
`ifdef PCI_IMAGE3
11590
    expected_value = {`PCI_AM3, 12'h000} ;
11591
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11592
    if(`PCI_AM3)
11593
        expected_value[0] = `PCI_BA3_MEM_IO ;
11594
`else
11595
    expected_value = 0 ;
11596
`endif
11597
 
11598
    configuration_cycle_read
11599
    (
11600
        8'h00,                          // bus number [7:0]
11601
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11602
        3'h0,                           // function number [2:0]
11603
        6'h7,                           // register number [5:0]
11604
        2'h0,                           // type [1:0]
11605
        4'hF,                           // byte enables [3:0]
11606
        read_data                       // data to write [31:0]
11607
    ) ;
11608
 
11609
    if ( read_data !== expected_value )
11610
    begin
11611
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11612
        failed = 1 ;
11613
    end
11614
 
11615
    // write all 1s to BAR4
11616
    read_data = 32'hFFFF_FFFF ;
11617
 
11618
    // BAR4
11619
    configuration_cycle_write
11620
    (
11621
        8'h00,                          // bus number [7:0]
11622
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11623
        3'h0,                           // function number [2:0]
11624
        6'h8,                           // register number [5:0]
11625
        2'h0,                           // type [1:0]
11626
        4'hF,                           // byte enables [3:0]
11627
        read_data                       // data to write [31:0]
11628
    ) ;
11629
 
11630
`ifdef PCI_IMAGE4
11631
    expected_value = {`PCI_AM4, 12'h000} ;
11632
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11633
    if(`PCI_AM4)
11634
        expected_value[0] = `PCI_BA4_MEM_IO ;
11635
`else
11636
    expected_value = 0 ;
11637
`endif
11638
 
11639
    configuration_cycle_read
11640
    (
11641
        8'h00,                          // bus number [7:0]
11642
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11643
        3'h0,                           // function number [2:0]
11644
        6'h8,                           // register number [5:0]
11645
        2'h0,                           // type [1:0]
11646
        4'hF,                           // byte enables [3:0]
11647
        read_data                       // data to write [31:0]
11648
    ) ;
11649
 
11650
    if ( read_data !== expected_value )
11651
    begin
11652
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11653
        failed = 1 ;
11654
    end
11655
 
11656
    // write all 1s to BAR5
11657
    read_data = 32'hFFFF_FFFF ;
11658
 
11659
    // BAR5
11660
    configuration_cycle_write
11661
    (
11662
        8'h00,                          // bus number [7:0]
11663
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11664
        3'h0,                           // function number [2:0]
11665
        6'h9,                           // register number [5:0]
11666
        2'h0,                           // type [1:0]
11667
        4'hF,                           // byte enables [3:0]
11668
        read_data                       // data to write [31:0]
11669
    ) ;
11670
 
11671
`ifdef PCI_IMAGE5
11672
    expected_value = {`PCI_AM5, 12'h000} ;
11673
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11674
    if(`PCI_AM5)
11675
        expected_value[0] = `PCI_BA5_MEM_IO ;
11676
`else
11677
    expected_value = 0 ;
11678
`endif
11679
 
11680
    configuration_cycle_read
11681
    (
11682
        8'h00,                          // bus number [7:0]
11683
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11684
        3'h0,                           // function number [2:0]
11685
        6'h9,                           // register number [5:0]
11686
        2'h0,                           // type [1:0]
11687
        4'hF,                           // byte enables [3:0]
11688
        read_data                       // data to write [31:0]
11689
    ) ;
11690
 
11691
    if ( read_data !== expected_value )
11692
    begin
11693
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11694
        failed = 1 ;
11695
    end
11696
`endif
11697
 
11698
    if (!failed)
11699
        test_ok ;
11700
end
11701
endtask
11702
 
11703 15 mihad
task display_warning;
11704
    input [31:0] error_address ;
11705
    input [31:0] expected_data ;
11706
    input [31:0] actual ;
11707
begin
11708
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11709
end
11710
endtask // display warning
11711
 
11712
/*############################################################################
11713
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11714
=====================
11715
############################################################################*/
11716
 
11717
// Task reslease the PCI bus for 'delay' clocks
11718
task do_pause;
11719
  input  [15:0] delay;
11720
  reg    [15:0] cnt;
11721
  begin
11722
    test_start <= 1'b0;  // no device is allowed to take this
11723
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11724
    begin
11725
      if (~pci_reset_comb)
11726
      begin
11727
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11728
      end
11729
      `NO_ELSE;
11730
    end
11731
  end
11732
endtask // do_pause
11733
 
11734
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11735
task DO_REF;
11736
  input  [79:0] name;
11737
  input  [2:0] master_number;
11738
  input  [PCI_BUS_DATA_RANGE:0] address;
11739
  input  [3:0] command;
11740
  input  [PCI_BUS_DATA_RANGE:0] data;
11741
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11742
  input  [9:0] size;
11743
  input   make_addr_par_error, make_data_par_error;
11744
  input  [7:0] master_wait_states;
11745
  input  [7:0] target_wait_states;
11746
  input  [1:0] target_devsel_speed;
11747
  input   fast_back_to_back;
11748
  input  [2:0] target_termination;
11749
  input   expect_master_abort;
11750
  reg     waiting;
11751
  begin
11752
// Cautiously wait for previous command to be done
11753
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11754
    begin
11755
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11756
      begin
11757
        if (~pci_reset_comb)
11758
        begin
11759
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11760
        end
11761
        `NO_ELSE;
11762
      end
11763
      else
11764
      begin
11765
        waiting = 1'b0;  // ready to do next command
11766
      end
11767
    end
11768
    next_test_name[79:0] <= name[79:0];
11769
    test_master_number <= master_number[2:0];
11770
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11771
    test_command[3:0] <= command[3:0] ;
11772
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11773
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11774
    test_size <= size;
11775
    test_make_addr_par_error <= make_addr_par_error;
11776
    test_make_data_par_error <= make_data_par_error;
11777
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11778
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11779
    test_target_initial_wait_states <= target_wait_states[7:4];
11780
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11781
    test_target_devsel_speed <= target_devsel_speed[1:0];
11782
    test_fast_back_to_back <= fast_back_to_back;
11783
    test_target_termination <= target_termination[2:0];
11784
    test_expect_master_abort <= expect_master_abort;
11785
    test_start <= 1'b1;
11786
    if (~pci_reset_comb)
11787
    begin
11788
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11789
    end
11790
    `NO_ELSE;
11791
// wait for new command to start
11792
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11793
    begin
11794
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11795
      begin
11796
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11797
      end
11798
      else
11799
      begin
11800
        waiting = 1'b0;  // ready to do next command
11801
      end
11802
    end
11803
  end
11804
endtask // DO_REF
11805
 
11806
// Use Macros defined in pci_defines.vh as paramaters
11807
 
11808
// DO_REF (name[79:0], master_number[2:0],
11809
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11810
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11811
//          make_addr_par_error, make_data_par_error,
11812
//          master_wait_states[8:0], target_wait_states[8:0],
11813
//          target_devsel_speed[1:0], fast_back_to_back,
11814
//          target_termination[2:0],
11815
//          expect_master_abort);
11816
//
11817
// Example:
11818
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11819
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11820
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11821
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11822
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11823
 
11824
// Access a location with no high-order bits set, assuring that no device responds
11825
task PCIU_CONFIG_READ_MASTER_ABORT;
11826
  input  [79:0] name;
11827
  input  [2:0] master_number;
11828 51 mihad
  input  [31:0] address ;
11829
  input  [3:0] be ;
11830 15 mihad
  begin
11831 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11832
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11833
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11834 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11835
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11836
  end
11837
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11838
 
11839
// Access a location with no high-order bits set, assuring that no device responds
11840
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11841
  input  [79:0] name;
11842
  input  [2:0] master_number;
11843 51 mihad
  input  [31:0] address ;
11844
  input  [3:0] be ;
11845 15 mihad
  begin
11846 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11847
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11848
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11849 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11850
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11851
  end
11852
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11853
 
11854
// Access a location with no high-order bits set, assuring that no device responds
11855
task PCIU_MEM_READ_MASTER_ABORT;
11856
  input  [79:0] name;
11857
  input  [2:0] master_number;
11858
  input  [9:0] size;
11859
  begin
11860
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11861
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11862
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11863
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11864
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11865
  end
11866
endtask // PCIU_MEM_READ_MASTER_ABORT
11867
 
11868
// Access a location with no high-order bits set, assuring that no device responds
11869
task PCIU_MEM_WRITE_MASTER_ABORT;
11870
  input  [79:0] name;
11871
  input  [2:0] master_number;
11872
  input  [9:0] size;
11873
  begin
11874
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11875
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11876
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11877
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11878
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11879
  end
11880
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11881
 
11882
// Do variable length transfers with various paramaters
11883
task PCIU_CONFIG_READ;
11884
  input  [79:0] name;
11885
  input  [2:0] master_number;
11886
  input  [PCI_BUS_DATA_RANGE:0] address;
11887
  input  [PCI_BUS_DATA_RANGE:0] data;
11888
  input  [3:0] be ;
11889
  input  [9:0] size;
11890
  input  [7:0] master_wait_states;
11891
  input  [7:0] target_wait_states;
11892
  input  [1:0] target_devsel_speed;
11893
  input  [2:0] target_termination;
11894
  begin
11895
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11896
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11897
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11898
              8'h0_0, target_wait_states[7:0],
11899
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11900
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11901
  end
11902
endtask // PCIU_CONFIG_READ
11903
 
11904
task PCIU_CONFIG_WRITE;
11905
  input  [79:0] name;
11906
  input  [2:0] master_number;
11907
  input  [PCI_BUS_DATA_RANGE:0] address;
11908
  input  [PCI_BUS_DATA_RANGE:0] data;
11909
  input  [3:0] be ;
11910
  input  [9:0] size;
11911
  input  [7:0] master_wait_states;
11912
  input  [7:0] target_wait_states;
11913
  input  [1:0] target_devsel_speed;
11914
  input  [2:0] target_termination;
11915
  begin
11916
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11917
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11918
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11919
              8'h0_0, target_wait_states[7:0],
11920
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11921
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11922
  end
11923
endtask // PCIU_CONFIG_WRITE
11924
 
11925
task PCIU_READ;
11926
  input  [2:0] master_number;
11927
  input  [PCI_BUS_DATA_RANGE:0] address;
11928
  input  [3:0] command;
11929
  input  [PCI_BUS_DATA_RANGE:0] data;
11930
  input  [3:0] byte_en;
11931
  input  [9:0] size;
11932
  input  [7:0] master_wait_states;
11933
  input  [7:0] target_wait_states;
11934
  input  [1:0] target_devsel_speed;
11935
  input  [2:0] target_termination;
11936
  reg    [79:0] name;
11937
  begin
11938
    if (command == `BC_MEM_READ)
11939
        name = "MEM_READ  " ;
11940
    else if (command == `BC_MEM_READ_LN)
11941
        name = "MEM_RD_LN " ;
11942
    else if (command == `BC_MEM_READ_MUL )
11943
        name = "MEM_RD_MUL" ;
11944
    else
11945
        name = "WRONG_READ" ;
11946
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11947
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
11948
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11949
              8'h0_0, target_wait_states[7:0],
11950
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11951
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11952
  end
11953
endtask // PCIU_READ
11954
 
11955
task PCIU_MEM_READ;
11956
  input  [79:0] name;
11957
  input  [2:0] master_number;
11958
  input  [PCI_BUS_DATA_RANGE:0] address;
11959
  input  [PCI_BUS_DATA_RANGE:0] data;
11960
  input  [9:0] size;
11961
  input  [7:0] master_wait_states;
11962
  input  [7:0] target_wait_states;
11963
  input  [1:0] target_devsel_speed;
11964
  input  [2:0] target_termination;
11965
  begin
11966
 
11967
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11968
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11969
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11970
              8'h0_0, target_wait_states[7:0],
11971
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11972
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11973
  end
11974
endtask // PCIU_MEM_READ
11975
 
11976
task PCIU_IO_READ;
11977
  input  [2:0] master_number;
11978
  input  [PCI_BUS_DATA_RANGE:0] address;
11979
  input  [PCI_BUS_DATA_RANGE:0] data;
11980
  input  [3:0] byte_en ;
11981
  input  [9:0] size;
11982
  input  [2:0] target_termination ;
11983
  begin
11984
 
11985
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11986
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11987
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11988
              8'h0_0, `Test_One_Zero_Target_WS,
11989
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11990
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11991
  end
11992
endtask // PCIU_IO_READ
11993
 
11994
task PCIU_IO_READ_MAKE_PERR;
11995
  input  [2:0] master_number;
11996
  input  [PCI_BUS_DATA_RANGE:0] address;
11997
  input  [PCI_BUS_DATA_RANGE:0] data;
11998
  input  [3:0] byte_en ;
11999
  input  [9:0] size;
12000
  input  [2:0] target_termination ;
12001
  begin
12002
 
12003
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12004
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
12005
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12006
              8'h0_0, `Test_One_Zero_Target_WS,
12007
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12008
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12009
  end
12010
endtask // PCIU_IO_READ_MAKE_PERR
12011
 
12012
task PCIU_MEM_READ_LN;
12013
  input  [79:0] name;
12014
  input  [2:0] master_number;
12015
  input  [PCI_BUS_DATA_RANGE:0] address;
12016
  input  [PCI_BUS_DATA_RANGE:0] data;
12017
  input  [9:0] size;
12018
  input  [7:0] master_wait_states;
12019
  input  [7:0] target_wait_states;
12020
  input  [1:0] target_devsel_speed;
12021
  input  [2:0] target_termination;
12022
  begin
12023
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12024
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12025
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12026
              8'h0_0, target_wait_states[7:0],
12027
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12028
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12029
  end
12030
endtask // PCIU_MEM_READ_LN
12031
 
12032
task PCIU_MEM_READ_MUL;
12033
  input  [79:0] name;
12034
  input  [2:0] master_number;
12035
  input  [PCI_BUS_DATA_RANGE:0] address;
12036
  input  [PCI_BUS_DATA_RANGE:0] data;
12037
  input  [9:0] size;
12038
  input  [7:0] master_wait_states;
12039
  input  [7:0] target_wait_states;
12040
  input  [1:0] target_devsel_speed;
12041
  input  [2:0] target_termination;
12042
  begin
12043
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12044
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12045
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12046
              8'h0_0, target_wait_states[7:0],
12047
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12048
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12049
  end
12050
endtask // PCIU_MEM_READ_MUL
12051
 
12052
task PCIU_MEM_READ_MAKE_PERR;
12053
  input  [79:0] name;
12054
  input  [2:0] master_number;
12055
  input  [PCI_BUS_DATA_RANGE:0] address;
12056
  input  [PCI_BUS_DATA_RANGE:0] data;
12057
  input  [9:0] size;
12058
  input  [7:0] master_wait_states;
12059
  input  [7:0] target_wait_states;
12060
  input  [1:0] target_devsel_speed;
12061
  input  [2:0] target_termination;
12062
  begin
12063
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12064
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12065
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12066
              8'h0_0, target_wait_states[7:0],
12067
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12068
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12069
  end
12070
endtask // PCIU_MEM_READ_MAKE_PERR
12071
 
12072
task PCIU_MEM_WRITE;
12073
  input  [79:0] name;
12074
  input  [2:0] master_number;
12075
  input  [PCI_BUS_DATA_RANGE:0] address;
12076
  input  [PCI_BUS_DATA_RANGE:0] data;
12077
  input  [3:0] byte_en;
12078
  input  [9:0] size;
12079
  input  [7:0] master_wait_states;
12080
  input  [7:0] target_wait_states;
12081
  input  [1:0] target_devsel_speed;
12082
  input  [2:0] target_termination;
12083
  begin
12084
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12085
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12086
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12087
              8'h0_0, target_wait_states[7:0],
12088
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12089
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12090
  end
12091
endtask // PCIU_MEM_WRITE
12092
 
12093
task PCIU_IO_WRITE;
12094
  input  [2:0] master_number;
12095
  input  [PCI_BUS_DATA_RANGE:0] address;
12096
  input  [PCI_BUS_DATA_RANGE:0] data;
12097
  input  [3:0] byte_en;
12098
  input  [9:0] size;
12099
  input  [2:0] target_termination ;
12100
  begin
12101
 
12102
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12103
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12104
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12105
              8'h0_0, `Test_One_Zero_Target_WS,
12106
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12107
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12108
  end
12109
endtask // PCIU_IO_WRITE
12110
 
12111
task PCIU_IO_WRITE_MAKE_PERR ;
12112
  input  [2:0] master_number;
12113
  input  [PCI_BUS_DATA_RANGE:0] address;
12114
  input  [PCI_BUS_DATA_RANGE:0] data;
12115
  input  [3:0] byte_en;
12116
  input  [9:0] size;
12117
  input  [2:0] target_termination ;
12118
  begin
12119
 
12120
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12121
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12122
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12123
              8'h0_0, `Test_One_Zero_Target_WS,
12124
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12125
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12126
  end
12127
endtask // PCIU_IO_WRITE
12128
 
12129
task PCIU_MEM_WRITE_MAKE_SERR;
12130
  input  [79:0] name;
12131
  input  [2:0] master_number;
12132
  input  [PCI_BUS_DATA_RANGE:0] address;
12133
  input  [PCI_BUS_DATA_RANGE:0] data;
12134
  input  [9:0] size;
12135
  input  [7:0] master_wait_states;
12136
  input  [7:0] target_wait_states;
12137
  input  [1:0] target_devsel_speed;
12138
  input  [2:0] target_termination;
12139
  begin
12140
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12141
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12142
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12143
              8'h0_0, target_wait_states[7:0],
12144
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12145
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12146
  end
12147
endtask // PCIU_MEM_WRITE_MAKE_SERR
12148
 
12149
task PCIU_MEM_WRITE_MAKE_PERR;
12150
  input  [79:0] name;
12151
  input  [2:0] master_number;
12152
  input  [PCI_BUS_DATA_RANGE:0] address;
12153
  input  [PCI_BUS_DATA_RANGE:0] data;
12154
  input  [9:0] size;
12155
  input  [7:0] master_wait_states;
12156
  input  [7:0] target_wait_states;
12157
  input  [1:0] target_devsel_speed;
12158
  input  [2:0] target_termination;
12159
  begin
12160
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12161
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12162
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12163
              8'h0_0, target_wait_states[7:0],
12164
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12165
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12166
  end
12167
endtask // PCIU_MEM_WRITE
12168
 
12169
/*--------------------------------------------------------------------------
12170
Initialization CASES
12171
--------------------------------------------------------------------------*/
12172
 
12173
// Initialize the basic Config Registers of the PCI bridge target device
12174
task configure_bridge_target;
12175
    reg [11:0] offset ;
12176
    reg [31:0] data ;
12177
    `ifdef HOST
12178
    reg `WRITE_STIM_TYPE   write_data ;
12179
    reg `WB_TRANSFER_FLAGS write_flags ;
12180
    reg `WRITE_RETURN_TYPE write_status ;
12181
    `else
12182
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12183
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12184
    `endif
12185
 
12186
    reg [31:0] temp_var ;
12187
begin
12188
`ifdef HOST //  set Header
12189
    offset  = 12'h4 ; // PCI Header Command register
12190
    data    = 32'h0000_0007 ; // enable master & target operation
12191
 
12192
    write_flags                      = 0 ;
12193
    write_flags`INIT_WAITS           = tb_init_waits ;
12194
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12195
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12196
 
12197
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12198
    write_data`WRITE_SEL      = 4'h1 ;
12199
    write_data`WRITE_TAG_STIM = 0 ;
12200
    write_data`WRITE_DATA     = data ;
12201
 
12202
    next_test_name[79:0] <= "Init_Tar_R";
12203
 
12204
    $display(" bridge target - Enabling master and target operation!");
12205
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12206
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12207
    begin
12208
        $display("Write to configuration space failed! Time %t ", $time) ;
12209
    end
12210
 
12211
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12212
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12213
 
12214
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12215
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12216
 
12217
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12218
    write_data`WRITE_SEL      = 4'hf ;
12219
    write_data`WRITE_TAG_STIM = 0 ;
12220
    write_data`WRITE_DATA     = data ;
12221
 
12222
 `ifdef  NO_CNF_IMAGE
12223
  `ifdef PCI_IMAGE0 //      set P_BA0
12224
 
12225
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12226
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12227
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12228
    begin
12229
        $display("Write to configuration space failed! Time %t ", $time) ;
12230
    end
12231
  `endif
12232
 `else //      set P_BA0
12233
 
12234
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12235
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12236
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12237
    begin
12238
        $display("Write to configuration space failed! Time %t ", $time) ;
12239
    end
12240
 `endif
12241
 
12242
`else // GUEST, set Header, set P_BA0
12243
    data            = 32'h0000_0007 ; // enable master & target operation
12244
    byte_enables    = 4'hF ;
12245
    $display(" bridge target - Enabling master and target operation!");
12246 45 mihad
    configuration_cycle_write(0,                        // bus number
12247
                              `TAR0_IDSEL_INDEX - 11,   // device number
12248
                              0,                        // function number
12249
                              1,                        // register number
12250
                              0,                        // type of configuration cycle
12251
                              byte_enables,             // byte enables
12252
                              data                      // data
12253 15 mihad
                             ) ;
12254
 
12255
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12256
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12257
    byte_enables = 4'hf ;
12258 45 mihad
    configuration_cycle_write(0,                        // bus number
12259
                              `TAR0_IDSEL_INDEX - 11,   // device number
12260
                              0,                        // function number
12261
                              4,                        // register number
12262
                              0,                        // type of configuration cycle
12263
                              byte_enables,             // byte enables
12264
                              data                      // data
12265 15 mihad
                             ) ;
12266
 
12267
`endif
12268
end
12269
endtask // configure_bridge_target
12270
 
12271
// Initialize the basic Config Registers of the PCI bridge target device
12272
task configure_bridge_target_base_addresses;
12273
    reg [11:0] offset ;
12274
    reg [31:0] data ;
12275
    `ifdef HOST
12276
    reg `WRITE_STIM_TYPE   write_data ;
12277
    reg `WB_TRANSFER_FLAGS write_flags ;
12278
    reg `WRITE_RETURN_TYPE write_status ;
12279
    `else
12280
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12281
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12282
    `endif
12283
 
12284
    reg [31:0] temp_var ;
12285
begin
12286
`ifdef HOST //  set Header
12287
    offset  = 12'h4 ; // PCI Header Command register
12288
    data    = 32'h0000_0007 ; // enable master & target operation
12289
 
12290
    write_flags                    = 0 ;
12291
    write_flags`INIT_WAITS         = tb_init_waits ;
12292
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12293
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12294
 
12295
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12296
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12297
 
12298
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12299
    write_data`WRITE_SEL      = 4'h1 ;
12300
    write_data`WRITE_TAG_STIM = 0 ;
12301
    write_data`WRITE_DATA     = data ;
12302
 
12303
    next_test_name[79:0] <= "Init_Tar_R";
12304
 
12305
    $display(" bridge target - Enabling master and target operation!");
12306
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12307
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12308
    begin
12309
        $display("Write to configuration space failed! Time %t ", $time) ;
12310
    end
12311
 
12312
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12313
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12314
 
12315
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12316
    write_data`WRITE_SEL      = 4'hf ;
12317
    write_data`WRITE_TAG_STIM = 0 ;
12318
    write_data`WRITE_DATA     = data ;
12319
 
12320
 `ifdef  NO_CNF_IMAGE
12321
  `ifdef PCI_IMAGE0 //      set P_BA0
12322
 
12323
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12324
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12325
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12326
    begin
12327
        $display("Write to configuration space failed! Time %t ", $time) ;
12328
    end
12329
  `endif
12330
 `else //      set P_BA0
12331
 
12332
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12333
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12334
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12335
    begin
12336
        $display("Write to configuration space failed! Time %t ", $time) ;
12337
    end
12338
 `endif
12339
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12340
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12341
 
12342
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12343
    write_data`WRITE_SEL      = 4'hf ;
12344
    write_data`WRITE_TAG_STIM = 0 ;
12345
    write_data`WRITE_DATA     = data ;
12346
 
12347
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12348
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12349
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12350
    begin
12351
        $display("Write to configuration space failed! Time %t ", $time) ;
12352
    end
12353
 `ifdef PCI_IMAGE2
12354
 
12355
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12356
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12357
 
12358
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12359
    write_data`WRITE_SEL      = 4'hf ;
12360
    write_data`WRITE_TAG_STIM = 0 ;
12361
    write_data`WRITE_DATA     = data ;
12362
 
12363
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12364
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12365
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12366
    begin
12367
        $display("Write to configuration space failed! Time %t ", $time) ;
12368
    end
12369
 `endif
12370
 `ifdef PCI_IMAGE3
12371
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12372
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12373
 
12374
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12375
    write_data`WRITE_SEL      = 4'hf ;
12376
    write_data`WRITE_TAG_STIM = 0 ;
12377
    write_data`WRITE_DATA     = data ;
12378
 
12379
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12380
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12381
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12382
    begin
12383
        $display("Write to configuration space failed! Time %t ", $time) ;
12384
    end
12385
 `endif
12386
 `ifdef PCI_IMAGE4
12387
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12388
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12389
 
12390
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12391
    write_data`WRITE_SEL      = 4'hf ;
12392
    write_data`WRITE_TAG_STIM = 0 ;
12393
    write_data`WRITE_DATA     = data ;
12394
 
12395
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12396
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12397
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12398
    begin
12399
        $display("Write to configuration space failed! Time %t ", $time) ;
12400
    end
12401
 `endif
12402
 `ifdef PCI_IMAGE5
12403
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12404
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12405
 
12406
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12407
    write_data`WRITE_SEL      = 4'hf ;
12408
    write_data`WRITE_TAG_STIM = 0 ;
12409
    write_data`WRITE_DATA     = data ;
12410
 
12411
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12412
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12413
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12414
    begin
12415
        $display("Write to configuration space failed! Time %t ", $time) ;
12416
    end
12417
 `endif
12418
 
12419
`else // GUEST, set Header, set P_BA0
12420
    data            = 32'h0000_0007 ; // enable master & target operation
12421
    byte_enables    = 4'hF ;
12422
    $display(" bridge target - Enabling master and target operation!");
12423 45 mihad
    configuration_cycle_write(0,                        // bus number
12424
                              `TAR0_IDSEL_INDEX - 11,   // device number
12425
                              0,                        // function number
12426
                              1,                        // register number
12427
                              0,                        // type of configuration cycle
12428
                              byte_enables,             // byte enables
12429
                              data                      // data
12430 15 mihad
                             ) ;
12431
 
12432
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12433
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12434
    byte_enables = 4'hf ;
12435 45 mihad
    configuration_cycle_write(0,                        // bus number
12436
                              `TAR0_IDSEL_INDEX - 11,   // device number
12437
                              0,                        // function number
12438
                              4,                        // register number
12439
                              0,                        // type of configuration cycle
12440
                              byte_enables,             // byte enables
12441
                              data                      // data
12442 15 mihad
                             ) ;
12443
 
12444
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12445
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12446
    byte_enables = 4'hf ;
12447 45 mihad
    configuration_cycle_write(0,                        // bus number
12448
                              `TAR0_IDSEL_INDEX - 11,   // device number
12449
                              0,                        // function number
12450
                              5,                        // register number
12451
                              0,                        // type of configuration cycle
12452
                              byte_enables,             // byte enables
12453
                              data                      // data
12454 15 mihad
                             ) ;
12455
 `ifdef PCI_IMAGE2
12456
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12457
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12458
    byte_enables = 4'hf ;
12459 45 mihad
    configuration_cycle_write(0,                        // bus number
12460
                              `TAR0_IDSEL_INDEX - 11,   // device number
12461
                              0,                        // function number
12462
                              6,                        // register number
12463
                              0,                        // type of configuration cycle
12464
                              byte_enables,             // byte enables
12465
                              data                      // data
12466 15 mihad
                             ) ;
12467
 `endif
12468
 `ifdef PCI_IMAGE3
12469
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12470
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12471
    byte_enables = 4'hf ;
12472 45 mihad
    configuration_cycle_write(0,                        // bus number
12473
                              `TAR0_IDSEL_INDEX - 11,   // device number
12474
                              0,                        // function number
12475
                              7,                        // register number
12476
                              0,                        // type of configuration cycle
12477
                              byte_enables,             // byte enables
12478
                              data                      // data
12479 15 mihad
                             ) ;
12480
 `endif
12481
 `ifdef PCI_IMAGE4
12482
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12483
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12484
    byte_enables = 4'hf ;
12485 45 mihad
    configuration_cycle_write(0,                        // bus number
12486
                              `TAR0_IDSEL_INDEX - 11,   // device number
12487
                              0,                        // function number
12488
                              8,                        // register number
12489
                              0,                        // type of configuration cycle
12490
                              byte_enables,             // byte enables
12491
                              data                      // data
12492 15 mihad
                             ) ;
12493
 `endif
12494
 `ifdef PCI_IMAGE5
12495
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12496
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12497
    byte_enables = 4'hf ;
12498 45 mihad
    configuration_cycle_write(0,                        // bus number
12499
                              `TAR0_IDSEL_INDEX - 11,   // device number
12500
                              0,                        // function number
12501
                              9,                        // register number
12502
                              0,                        // type of configuration cycle
12503
                              byte_enables,             // byte enables
12504
                              data                      // data
12505 15 mihad
                             ) ;
12506
 `endif
12507
`endif
12508
end
12509
endtask // configure_bridge_target_base_addresses
12510
 
12511
/*--------------------------------------------------------------------------
12512
Test CASES
12513
--------------------------------------------------------------------------*/
12514
 
12515
// function converts PCI address to WB with the same data as the pci_decoder does
12516
function [31:0] pci_to_wb_addr_convert ;
12517
 
12518
    input [31:0] pci_address ;
12519
    input [31:0] translation_address ;
12520
    input [31:0] translate ;
12521
 
12522
    reg   [31:0] temp_address ;
12523
begin
12524
    if ( translate !== 1 )
12525
    begin
12526
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12527
    end
12528
    else
12529
    begin
12530
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12531
    end
12532
 
12533
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12534
    pci_to_wb_addr_convert = temp_address ;
12535
end
12536
endfunction // pci_to_wb_addr_convert
12537
 
12538
// Test normal write and read to WB slave
12539
task test_normal_wr_rd;
12540
  input  [2:0]  Master_ID;
12541
  input  [PCI_BUS_DATA_RANGE:0] Address;
12542
  input  [PCI_BUS_DATA_RANGE:0] Data;
12543
  input  [3:0]  Be;
12544
  input  [2:0]  Image_num;
12545
  input  [9:0]  Set_size;
12546
  input         Set_addr_translation;
12547
  input         Set_prefetch_enable;
12548
  input  [7:0]  Cache_lsize;
12549
  input         Set_wb_wait_states;
12550
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12551
 
12552
  reg    [31:0] rd_address;
12553
  reg    [31:0] rd_data;
12554
  reg    [3:0]  rd_be;
12555
  reg    [11:0] addr_offset;
12556
  reg    [31:0] read_data;
12557
  reg           continue ;
12558
  reg           ok   ;
12559
  reg    [31:0] expect_address ;
12560
  reg    [31:0] expect_rd_address ;
12561
  reg           expect_we ;
12562
  reg    [9:0]  expect_length_wr ;
12563
  reg    [9:0]  expect_length_rd ;
12564
  reg    [9:0]  expect_length_rd1 ;
12565
  reg    [9:0]  expect_length_rd2 ;
12566
  reg    [3:0]  use_rd_cmd ;
12567
  integer       i ;
12568 35 mihad
  reg           error_monitor_done ;
12569 15 mihad
begin:main
12570
 
12571
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12572
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12573
    $display(" - errors will be reported, but they should not occur!");
12574
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12575
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12576
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12577
    if ( ok !== 1 )
12578
    begin
12579
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12580
        test_fail("write to P_ERR_CS register didn't succeede") ;
12581
        disable main;
12582
    end
12583
 
12584
    `ifdef  ADDR_TRAN_IMPL
12585
 
12586
    // set or clear address translation
12587
    if (Set_addr_translation)
12588
    begin
12589
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12590
        $display(" - address translation will be performed!");
12591
    end
12592
    else
12593
    begin
12594
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12595
        $display(" - address translation will not be performed!");
12596
    end
12597
    // set or clear pre-fetch enable
12598
    if (Set_prefetch_enable)
12599
    begin
12600
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12601
        $display(" - bursts can be performed!");
12602
    end
12603
    else
12604
    begin
12605
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12606
        $display(" - bursts can not be performed!");
12607
    end
12608
 
12609
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12610
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12611
    if ( ok !== 1 )
12612
    begin
12613
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12614
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12615
        disable main;
12616
    end
12617
 
12618
    // predict the address and control signals on WB bus
12619
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12620
    expect_we      = 1'b1 ; // WRITE
12621
 
12622
    `else
12623
 
12624
    // address translation is not implemented
12625
    $display("Address translation is NOT implemented for PCI images!");
12626
    // set or clear pre-fetch enable
12627
    if (Set_prefetch_enable)
12628
    begin
12629
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12630
        $display(" - bursts can be performed!");
12631
    end
12632
    else
12633
    begin
12634
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12635
        $display(" - bursts can not be performed!");
12636
    end
12637
 
12638
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12639
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12640
    if ( ok !== 1 )
12641
    begin
12642
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12643
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12644
        disable main;
12645
    end
12646
 
12647
    // predict the address and control signals on WB bus
12648
    expect_address = Address ;
12649
    expect_we      = 1'b1 ; // WRITE
12650
 
12651
    `endif
12652
 
12653
    // set WB SLAVE parameters
12654
    if (Set_wb_wait_states)
12655
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12656
    else
12657
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12658
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12659
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12660
 
12661
    if ( Set_size > (`PCIW_DEPTH - 2) )
12662
    begin
12663
        expect_length_wr = `PCIW_DEPTH - 2 ;
12664
    end
12665
    else
12666
    begin
12667
        expect_length_wr = Set_size ;
12668
    end
12669
    // write through the PCI bridge to WB slave
12670
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12671
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12672
 
12673
    fork
12674
    begin
12675
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12676
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12677
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12678
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12679
        do_pause( 1 ) ;
12680
    end
12681
    begin
12682
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12683
       if ( ok !== 1 )
12684
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12685
       else
12686
           test_ok ;
12687
    end
12688
    join
12689
 
12690
    // predict the address and control signals on WB bus
12691
    expect_we      = 1'b0 ; // READ
12692
 
12693
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12694
    $display("Memory read through PCI bridge to WB slave!");
12695
 
12696
    if ( expect_length_wr == 1 )
12697
    begin
12698
        if (Set_prefetch_enable)
12699
        begin
12700
            expect_length_rd1 = Cache_lsize ;
12701
            expect_length_rd2 = 0 ;
12702
                // If PCI behavioral master must check received DATA
12703
                master2_check_received_data = 0 ;
12704
                    master1_check_received_data = 0 ;
12705
        end
12706
        else
12707
        begin
12708
            expect_length_rd1 = 1 ;
12709
            expect_length_rd2 = 0 ;
12710
                // If PCI behavioral master must check received DATA
12711
                master2_check_received_data = 1 ;
12712
                    master1_check_received_data = 1 ;
12713
        end
12714
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12715
        expect_length_rd  = expect_length_rd1 ;
12716
    end
12717
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12718
    begin
12719
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12720
        expect_length_rd2 = 0 ;
12721
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12722
        expect_length_rd  = expect_length_rd1 ;
12723
                // If PCI behavioral master must check received DATA
12724
        master2_check_received_data = 1 ;
12725
            master1_check_received_data = 1 ;
12726
    end
12727
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12728
    begin
12729
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12730
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12731
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12732
        expect_length_rd  = expect_length_rd1 ;
12733
                // If PCI behavioral master must check received DATA
12734
                master2_check_received_data = 1 ;
12735
            master1_check_received_data = 1 ;
12736
    end
12737
    else
12738
    begin
12739
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12740
        begin
12741
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12742
            expect_length_rd2 = 0 ;
12743
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12744
            expect_length_rd  = expect_length_rd1 ;
12745
                // If PCI behavioral master must check received DATA
12746
                master2_check_received_data = 0 ;
12747
                    master1_check_received_data = 0 ;
12748
        end
12749
        else
12750
        begin
12751
            if ( expect_length_wr > Cache_lsize )
12752
            begin
12753
                expect_length_rd1 = Cache_lsize ;
12754
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12755
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12756
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12757
                else
12758
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12759
                expect_length_rd  = expect_length_rd1 ;
12760
                        // If PCI behavioral master must check received DATA
12761
                        master2_check_received_data = 1 ;
12762
                            master1_check_received_data = 1 ;
12763
            end
12764
            else
12765
            begin
12766
                expect_length_rd1 = Cache_lsize ;
12767
                expect_length_rd2 = 0 ;
12768
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12769
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12770
                else
12771
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12772
                expect_length_rd  = expect_length_wr ;
12773
                                if ( expect_length_wr == Cache_lsize )
12774
                        begin
12775
                                // If PCI behavioral master must check received DATA
12776
                                master2_check_received_data = 1 ;
12777
                                    master1_check_received_data = 1 ;
12778
                                end
12779
                                else
12780
                                begin
12781
                                // If PCI behavioral master must check received DATA
12782
                                master2_check_received_data = 0 ;
12783
                                    master1_check_received_data = 0 ;
12784
                end
12785
            end
12786
        end
12787
    end
12788
 
12789
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12790
    expect_rd_address = expect_address ;
12791
    rd_data[31:0] = Data[31:0];
12792
    rd_be[3:0] = Be[3:0];
12793
 
12794
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12795
    while (expect_length_rd2 > 0)
12796
    begin
12797
        // do read
12798
        $display("Read %d words!", expect_length_rd);
12799
 
12800
        fork
12801
        begin
12802
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12803
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12804
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12805
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12806
 
12807
            wb_transaction_stop( expect_length_rd - 1) ;
12808
 
12809
            do_pause( 1 ) ;
12810
        end
12811
        begin
12812
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12813
            if ( ok !== 1 )
12814
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12815
 
12816
            repeat( 3 )
12817
                @(posedge pci_clock) ;
12818
 
12819
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12820
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12821
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12822
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12823
 
12824
            do_pause( 1 ) ;
12825
            while ( FRAME === 0 )
12826
                @(posedge pci_clock) ;
12827
 
12828
            while ( IRDY === 0 )
12829
                @(posedge pci_clock) ;
12830
 
12831 35 mihad
            #1 ;
12832
            if ( !error_monitor_done )
12833
                disable monitor_error_event1 ;
12834 15 mihad
        end
12835
        begin:monitor_error_event1
12836 35 mihad
            error_monitor_done = 0 ;
12837 15 mihad
            @(error_event_int) ;
12838
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12839
            ok = 0 ;
12840 35 mihad
            error_monitor_done = 1 ;
12841 15 mihad
        end
12842
        join
12843
 
12844
        // increasing the starting address for PCI master and for WB transaction monitor
12845
        rd_address = rd_address + (4 * expect_length_rd) ;
12846
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12847
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12848
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12849
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12850
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12851
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12852
        for (i=0; i<expect_length_rd; i=i+1)
12853
            rd_be[3:0] = {Be[2:0], Be[3]};
12854
 
12855
        // set parameters for next read
12856
        if ( expect_length_rd2 == 1 )
12857
        begin
12858
                if (Set_prefetch_enable)
12859
                begin
12860
                    expect_length_rd1 = Cache_lsize ;
12861
                    expect_length_rd2 = 0 ;
12862
                        // If PCI behavioral master must check received DATA
12863
                        master2_check_received_data = 0 ;
12864
                            master1_check_received_data = 0 ;
12865
                end
12866
                else
12867
                begin
12868
                    expect_length_rd1 = 1 ;
12869
                    expect_length_rd2 = 0 ;
12870
                        // If PCI behavioral master must check received DATA
12871
                        master2_check_received_data = 1 ;
12872
                            master1_check_received_data = 1 ;
12873
                end
12874
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12875
            expect_length_rd  = expect_length_rd1 ;
12876
        end
12877
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12878
        begin
12879
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12880
            expect_length_rd2 = 0 ;
12881
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12882
            expect_length_rd  = expect_length_rd1 ;
12883
                        // If PCI behavioral master must check received DATA
12884
                        master2_check_received_data = 1 ;
12885
                    master1_check_received_data = 1 ;
12886
        end
12887
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12888
        begin
12889
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12890
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12891
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12892
            expect_length_rd  = expect_length_rd1 ;
12893
                        // If PCI behavioral master must check received DATA
12894
                        master2_check_received_data = 1 ;
12895
                    master1_check_received_data = 1 ;
12896
        end
12897
        else
12898
        begin
12899
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12900
            begin
12901
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12902
                expect_length_rd2 = 0 ;
12903
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12904
                expect_length_rd  = expect_length_rd1 ;
12905
                        // If PCI behavioral master must check received DATA
12906
                        master2_check_received_data = 0 ;
12907
                            master1_check_received_data = 0 ;
12908
            end
12909
            else
12910
            begin
12911
                if ( expect_length_rd2 > Cache_lsize )
12912
                begin
12913
                    expect_length_rd1 = Cache_lsize ;
12914
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12915
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12916
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12917
                    else
12918
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12919
                    expect_length_rd  = expect_length_rd1 ;
12920
                                // If PCI behavioral master must check received DATA
12921
                                master2_check_received_data = 1 ;
12922
                                    master1_check_received_data = 1 ;
12923
                end
12924
                else
12925
                begin
12926
                    expect_length_rd  = expect_length_rd2 ;
12927
                    expect_length_rd1 = Cache_lsize ;
12928
                    expect_length_rd2 = 0 ;
12929
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12930
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12931
                    else
12932
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12933
                                        if ( expect_length_rd2 == Cache_lsize )
12934
                                begin
12935
                                        // If PCI behavioral master must check received DATA
12936
                                        master2_check_received_data = 1 ;
12937
                                            master1_check_received_data = 1 ;
12938
                                        end
12939
                                        else
12940
                                        begin
12941
                                        // If PCI behavioral master must check received DATA
12942
                                        master2_check_received_data = 0 ;
12943
                                            master1_check_received_data = 0 ;
12944
                        end
12945
                end
12946
            end
12947
        end
12948
    end
12949
    // do last read
12950
    $display("Read %d words!", expect_length_rd);
12951
 
12952
    fork
12953
    begin
12954
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12955
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12956
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12957
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12958
 
12959
        wb_transaction_stop(expect_length_rd - 1) ;
12960
        do_pause( 1 ) ;
12961
    end
12962
    begin
12963
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12964
 
12965
        do_pause(3) ;
12966
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12967
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12968
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12969
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12970
        do_pause(1) ;
12971
 
12972
        while ( FRAME === 0 )
12973
            @(posedge pci_clock) ;
12974
 
12975
        while ( IRDY === 0 )
12976
            @(posedge pci_clock) ;
12977
 
12978 35 mihad
        #1 ;
12979
        if ( !error_monitor_done )
12980
            disable monitor_error_event2 ;
12981 15 mihad
    end
12982
    begin:monitor_error_event2
12983 35 mihad
        error_monitor_done = 0 ;
12984 15 mihad
        @(error_event_int) ;
12985
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12986
        ok = 0 ;
12987 35 mihad
        error_monitor_done = 1 ;
12988 15 mihad
    end
12989
    join
12990
 
12991
    if ( ok )
12992
        test_ok ;
12993
 
12994
    // Check that no ERRORs were reported
12995
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12996
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
12997
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12998
    config_read( addr_offset, 4'hF, read_data ) ;
12999
    if ( read_data[8] !== 0 )
13000
    begin
13001
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
13002
        test_fail("error status was set even though no errors occured on WB bus") ;
13003
    end
13004
    else
13005
    begin
13006
        $display("No error was signaled, as expected!");
13007
        test_ok ;
13008
    end
13009
 
13010
end // main
13011
endtask // test_normal_wr_rd
13012
 
13013
// Test erroneous write to WB slave
13014
task test_wb_error_wr;
13015
  input  [2:0]  Master_ID;
13016
  input  [PCI_BUS_DATA_RANGE:0] Address;
13017
  input  [PCI_BUS_DATA_RANGE:0] Data;
13018
  input  [3:0]  Be;
13019
  input  [2:0]  Image_num;
13020
  input  [9:0]  Set_size;
13021
  input         Set_err_and_int_report;
13022
  input         Set_wb_wait_states;
13023
  input  [1:0]  Imm_BefLast_Last_error;
13024
 
13025
  reg    [11:0] addr_offset;
13026
  reg    [31:0] read_data;
13027
  reg           continue ;
13028
  reg           ok   ;
13029
  reg    [9:0]  expect_length ;
13030
  reg    [31:0] expect_address ;
13031
  reg    [0:0]  expect_we ;
13032
  reg    [31:0] rd_address;
13033
  reg    [31:0] rd_data;
13034
  reg    [3:0]  rd_be;
13035
  integer       i ;
13036
begin:main
13037
    if (Set_err_and_int_report)
13038
    begin
13039
        // enable ERROR reporting, because error must be reported and interrupt if required!
13040
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13041
        $display(" - errors will be reported when they will occur!");
13042
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
13043
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13044
        $display(" - interrupt will be reported when error will occur!");
13045
    end
13046
    else
13047
    begin
13048
        // disable ERROR reporting, because error and interrupt must not be reported!
13049
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
13050
        $display(" - errors will NOT be reported when they will occur!");
13051
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13052
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13053
        $display(" - interrupt will NOT be reported when error will occur!");
13054
    end
13055
    // enable/disable ERROR reporting
13056
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13057
 
13058
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13059
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13060
    if ( ok !== 1 )
13061
    begin
13062
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13063
        test_fail("PCI Error Control and Status register could not be written") ;
13064
        disable main;
13065
    end
13066
    // enable/disable INTERRUPT reporting
13067
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13068
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13069
    if ( ok !== 1 )
13070
    begin
13071
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13072
        test_fail("Interrupt Control register could not be written") ;
13073
        disable main;
13074
    end
13075
 
13076
    `ifdef  ADDR_TRAN_IMPL
13077
 
13078
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13079
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13080
    config_read( addr_offset, 4'hF, read_data ) ;
13081
    if ( read_data[2] !== 0 )
13082
    begin
13083
        $display("Address translation is set for PCI image%d!", Image_num);
13084
        // predict the address and control signals on WB bus
13085
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13086
        expect_we      = 1'b1 ; // WRITE
13087
    end
13088
    else
13089
    begin
13090
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13091
        // predict the address and control signals on WB bus
13092
        expect_address = Address ;
13093
        expect_we      = 1'b1 ; // WRITE
13094
    end
13095
 
13096
    `else
13097
 
13098
    // address translation is not implemented
13099
    $display("Address translation is NOT implemented for PCI images!");
13100
    // predict the address and control signals on WB bus
13101
    expect_address = Address ;
13102
    expect_we      = 1'b1 ; // WRITE
13103
 
13104
    `endif
13105
 
13106
    if ( Set_size > (`PCIW_DEPTH - 2) )
13107
    begin
13108
        expect_length = `PCIW_DEPTH - 2 ;
13109
    end
13110
    else
13111
    begin
13112
        expect_length = Set_size ;
13113
    end
13114
 
13115
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13116
    begin
13117
        $display("ERR termination with first data!");
13118
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13119
    end
13120
    else if (Imm_BefLast_Last_error == 1)
13121
    begin
13122
        $display("ERR termination before last data!");
13123
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13124
    end
13125
    else
13126
    begin
13127
        $display("ERR termination with last data!");
13128
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13129
    end
13130
 
13131
    // write through the PCI bridge to WB slave
13132
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13133
    fork
13134
    begin
13135
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13136
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13137
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13138
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13139
        do_pause( 1 ) ;
13140
    end
13141
    begin
13142
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13143
        begin
13144
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13145
            if ( ok !== 1 )
13146
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13147
        end
13148
        else if (Imm_BefLast_Last_error == 1)
13149
        begin
13150
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13151
            if ( ok !== 1 )
13152
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13153
        end
13154
        else
13155
        begin
13156
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13157
            if ( ok !== 1 )
13158
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13159
        end
13160
    end
13161
    begin
13162
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13163
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13164
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13165
        else if (Imm_BefLast_Last_error == 1)
13166
        begin
13167
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13168
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13169
            wb_transaction_stop(expect_length-2) ;
13170
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13171
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13172
        end
13173
        else
13174
        begin
13175
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13176
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13177
            wb_transaction_stop(expect_length-1) ;
13178
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13179
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13180
        end
13181
    end
13182
    join
13183
 
13184
    if ( ok )
13185
        test_ok ;
13186
 
13187
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13188
    begin
13189
        rd_data[31:0] = Data[31:0];
13190
        rd_address[31:0] = expect_address;
13191
        rd_be[3:0] = Be[3:0];
13192
    end
13193
    else if (Imm_BefLast_Last_error == 1)
13194
    begin
13195
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13196
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13197
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13198
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13199
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13200
        rd_be[3:0] = Be[3:0];
13201
        for (i=0; i<(expect_length-2); i=i+1)
13202
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13203
    end
13204
    else
13205
    begin
13206
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13207
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13208
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13209
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13210
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13211
        rd_be[3:0] = Be[3:0];
13212
        for (i=0; i<(expect_length-1); i=i+1)
13213
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13214
    end
13215
 
13216
    master2_check_received_data = 0 ;
13217
    master1_check_received_data = 0 ;
13218
 
13219
    // Check if ERRORs were reported
13220
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13221
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13222
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13223
 
13224
    ok = 1 ;
13225
    config_read( addr_offset, 4'hF, read_data ) ;
13226
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13227
    begin
13228
        $display("Error was signaled and reported, as expected!");
13229
        if (read_data[31:28] === rd_be)
13230
            $display("Byte enables written into P_ERR_CS register are as expected!");
13231
        else
13232
        begin
13233
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13234
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13235
            ok = 0 ;
13236
        end
13237
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13238
            $display("Bus command written into P_ERR_CS register is as expected!");
13239
        else
13240
        begin
13241
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13242
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13243
            ok = 0 ;
13244
        end
13245
 
13246
        if ( ok )
13247
            test_ok ;
13248
 
13249
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13250
 
13251
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13252
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13253
        config_read( addr_offset, 4'hF, read_data ) ;
13254
        if (read_data === rd_data)
13255
        begin
13256
            $display("Data written into P_ERR_DATA register is as expected!");
13257
            test_ok ;
13258
        end
13259
        else
13260
        begin
13261
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13262
            test_fail("PCI Erroneous Data register value was wrong") ;
13263
        end
13264
 
13265
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13266
 
13267
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13268
 
13269
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13270
        config_read( addr_offset, 4'hF, read_data ) ;
13271
        if (read_data === rd_address)
13272
        begin
13273
            $display("Address written into P_ERR_ADDR register is as expected!");
13274
            test_ok ;
13275
        end
13276
        else
13277
        begin
13278
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13279
            test_fail("PCI Erroneous Address register value was wrong") ;
13280
        end
13281
    end
13282
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13283
    begin
13284
        $display("Error was signaled and not reported, as expected!");
13285
        test_ok ;
13286
    end
13287
    else
13288
    begin
13289
        $display("Error was signaled and reported, as NOT expected!");
13290
        test_fail("Error status bit was set event though error reporting was disabled") ;
13291
    end
13292
 
13293
    // Check if Interrupts were reported
13294
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13295
 
13296
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13297
    ok = 1 ;
13298
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13299
    config_read( addr_offset, 4'hF, read_data ) ;
13300
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13301
    begin
13302
        $display("Interrupts was signaled and reported, as expected!");
13303
    end
13304
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13305
    begin
13306
        $display("Interrupts was signaled and not reported, as expected!");
13307
    end
13308
    else
13309
    begin
13310
        $display("Interrupt was signaled and reported, as NOT expected!");
13311
        test_fail("PCI Error Interrupt status was set when not expected") ;
13312
        ok = 0 ;
13313
    end
13314
 
13315
    `ifdef HOST
13316
    repeat( 4 )
13317
        @(posedge wb_clock) ;
13318
 
13319
    if ( INT_O === Set_err_and_int_report )
13320
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13321
    else
13322
    begin
13323
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13324
        test_fail("Interrupt request didn't have expected value") ;
13325
        ok = 0 ;
13326
    end
13327
 
13328
    `else // GUEST
13329
    repeat( 4 )
13330
        @(posedge pci_clock) ;
13331
 
13332
    if ( INTA === !Set_err_and_int_report )
13333
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13334
    else
13335
    begin
13336
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13337
        test_fail("Interrupt request didn't have expected value") ;
13338
        ok = 0 ;
13339
    end
13340
 
13341
    `endif
13342
 
13343
    if ( ok )
13344
        test_ok ;
13345
 
13346
    if (Set_err_and_int_report)
13347
    begin
13348
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13349
        $display("Error and Interrupt must be cleared!");
13350
        // clear  ERROR reporting bit
13351
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13352
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13353
        if ( ok !== 1 )
13354
        begin
13355
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13356
            test_fail("PCI Error Control and Status register could not be written to") ;
13357
            disable main;
13358
        end
13359
 
13360
        // clear INTERRUPT reporting bit
13361
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13362
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13363
        if ( ok !== 1 )
13364
        begin
13365
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13366
            test_fail("Interrupt Status register could not be written to") ;
13367
            disable main;
13368
        end
13369
 
13370
        test_ok ;
13371
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13372
        `ifdef HOST
13373
 
13374
        repeat(4)
13375
            @(posedge wb_clock) ;
13376
        if ( INT_O === 1'b0 )
13377
        begin
13378
            $display("Interrupt pin INT_O was correctly cleared!");
13379
            test_ok ;
13380
        end
13381
        else
13382
        begin
13383
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13384
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13385
            disable main;
13386
        end
13387
 
13388
        `else // GUEST
13389
 
13390
        repeat(4)
13391
            @(posedge pci_clock) ;
13392
        if ( INTA === 1'b1 )
13393
        begin
13394
            $display("Interrupt pin INTA was correctly cleared!");
13395
            test_ok ;
13396
        end
13397
        else
13398
        begin
13399
            $display("Interrupt pin INTA was NOT correctly cleared!");
13400
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13401
            disable main;
13402
        end
13403
 
13404
        `endif
13405
 
13406
    end
13407
    else
13408
    begin
13409
        $display("Error and Interrupt don't need to be cleared!");
13410
    end
13411
end // main
13412
endtask // test_wb_error_wr
13413
 
13414
task test_wb_error_rd;
13415
    reg    [11:0] addr_offset ;
13416
    reg    [11:0] ctrl_offset ;
13417
    reg    [11:0] ba_offset ;
13418
    reg    [11:0] am_offset ;
13419
    reg    [11:0] ta_offset ;
13420
    reg    [31:0] read_data;
13421
    reg           ok   ;
13422
    reg    [9:0]  expect_length ;
13423
    reg    [31:0] expect_address ;
13424
    reg    [0:0]  expect_we ;
13425
    reg    [31:0] rd_address;
13426
    reg    [31:0] rd_data;
13427
    reg    [3:0]  rd_be;
13428
    integer       i ;
13429
    reg           do_mem_aborts ;
13430
    reg           do_io_aborts ;
13431 35 mihad
    reg           error_monitor_done ;
13432 15 mihad
begin:main
13433
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13434
 
13435
    if ( target_mem_image !== -1 )
13436
    begin
13437
        do_mem_aborts = 1 ;
13438
 
13439
        if (target_mem_image === 1)
13440
        begin
13441
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13442
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13443
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13444
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13445
        end
13446
        else if (target_mem_image === 2)
13447
        begin
13448
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13449
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13450
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13451
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13452
        end
13453
        else if (target_mem_image === 3)
13454
        begin
13455
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13456
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13457
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13458
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13459
        end
13460
        else if (target_mem_image === 4)
13461
        begin
13462
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13463
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13464
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13465
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13466
        end
13467
        else if (target_mem_image === 5)
13468
        begin
13469
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13470
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13471
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13472
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13473
        end
13474
    end
13475
    else
13476
        do_mem_aborts = 0 ;
13477
 
13478
    if ( do_mem_aborts )
13479
    begin
13480
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13481
 
13482
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13483
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13484
        if ( ok !== 1 )
13485
        begin
13486
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13487
            test_fail("PCI Error Control and Status register could not be written") ;
13488
            disable main;
13489
        end
13490
 
13491
        // enable INTERRUPT reporting
13492
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13493
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13494
        if ( ok !== 1 )
13495
        begin
13496
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13497
            test_fail("Interrupt Control register could not be written") ;
13498
            disable main;
13499
        end
13500
 
13501
        addr_offset = 12'h010 + (4*target_mem_image) ;
13502
 
13503
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13504
        if ( ok !== 1 )
13505
        begin
13506
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13507
            test_fail("PCI Base Address register could not be written") ;
13508
            disable main;
13509
        end
13510
 
13511
        // disable address translation and enable prefetch so read bursts can be performed
13512
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13513
        if ( ok !== 1 )
13514
        begin
13515
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13516
            test_fail("PCI Image Control register could not be written") ;
13517
            disable main;
13518
        end
13519
 
13520
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13521
        if ( ok !== 1 )
13522
        begin
13523
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13524
            test_fail("PCI Address Mask register could not be written") ;
13525
            disable main;
13526
        end
13527
 
13528
        addr_offset = 12'h00C ;
13529
 
13530
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13531
        if ( ok !== 1 )
13532
        begin
13533
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13534
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13535
            disable main;
13536
        end
13537
 
13538
        // disable PCI master data checking
13539
        master1_check_received_data = 0 ;
13540
 
13541
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13542
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13543
 
13544
 
13545
        // do a single read error terminated on WB bus
13546
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13547
 
13548
        fork
13549
        begin
13550
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13551
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13552
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13553
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13554
 
13555
            do_pause( 1 ) ;
13556
        end
13557
        begin
13558
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13559
 
13560
            if ( ok !== 1 )
13561
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13562
 
13563
            do_pause(3) ;
13564
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13565
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13566
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13567
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13568
            do_pause(1) ;
13569
 
13570
            while ( FRAME === 0 )
13571
                @(posedge pci_clock) ;
13572
 
13573
            while ( IRDY === 0 )
13574
                @(posedge pci_clock) ;
13575
 
13576 35 mihad
            #1 ;
13577
            if ( !error_monitor_done )
13578
                disable monitor_error_event1 ;
13579 15 mihad
        end
13580
        begin:monitor_error_event1
13581 35 mihad
            error_monitor_done = 0 ;
13582 15 mihad
            @(error_event_int) ;
13583
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13584
            ok = 0 ;
13585 35 mihad
            error_monitor_done = 1 ;
13586 15 mihad
        end
13587
        join
13588
 
13589
        if ( ok )
13590
            test_ok ;
13591 26 mihad
 
13592
        @(posedge pci_clock) ;
13593
        @(posedge pci_clock) ;
13594
        @(posedge wb_clock) ;
13595
        @(posedge wb_clock) ;
13596 15 mihad
 
13597
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13598
        addr_offset = 12'h004 ;
13599
        config_read(addr_offset, 4'hF, read_data) ;
13600
        ok = 1 ;
13601
        if ( read_data[27] !== 1 )
13602
        begin
13603
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13604
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13605
            ok = 0 ;
13606
        end
13607
        if ( read_data[28] !== 0 )
13608
        begin
13609
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13610
            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") ;
13611
            ok = 0 ;
13612
        end
13613
        if ( read_data[29] !== 0 )
13614
        begin
13615
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13616
            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") ;
13617
            ok = 0 ;
13618
        end
13619
 
13620
        // clear statuses
13621
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13622
        if ( !ok )
13623
        begin
13624
            test_fail("write to PCI Device Status register failed") ;
13625
            $display("Couldn't write PCI Device Status register") ;
13626
            disable main ;
13627
        end
13628
 
13629
        if ( ok )
13630
            test_ok ;
13631
 
13632
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13633
 
13634
        ok = 1 ;
13635
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13636
 
13637
        config_read(addr_offset, 4'hF, read_data) ;
13638
        if (read_data[8] !== 0)
13639
        begin
13640
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13641
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13642
            ok = 0 ;
13643
        end
13644
        else
13645
            test_ok ;
13646
 
13647
        if ( ok !== 1 )
13648
        begin
13649
            config_write(addr_offset, read_data, 4'hF, ok) ;
13650
            if ( !ok )
13651
            begin
13652
                test_fail("PCI Error Control and Status register could not be written") ;
13653
                disable main ;
13654
            end
13655
        end
13656
 
13657
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13658
        fork
13659
        begin
13660
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13661
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13662
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13663
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13664
 
13665
            do_pause( 1 ) ;
13666
        end
13667
        begin
13668
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13669
 
13670
            if ( ok !== 1 )
13671
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13672
 
13673
            do_pause(3) ;
13674
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13675
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13676
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13677
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13678
            do_pause(1) ;
13679
 
13680
            while ( FRAME === 0 )
13681
                @(posedge pci_clock) ;
13682
 
13683
            while ( IRDY === 0 )
13684
                @(posedge pci_clock) ;
13685
 
13686 35 mihad
            #1 ;
13687
            if ( !error_monitor_done )
13688
                disable monitor_error_event2 ;
13689 15 mihad
        end
13690
        begin:monitor_error_event2
13691 35 mihad
            error_monitor_done = 0 ;
13692 15 mihad
            @(error_event_int) ;
13693
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13694
            ok = 0 ;
13695 35 mihad
            error_monitor_done = 1 ;
13696 15 mihad
        end
13697
        join
13698
 
13699
        if ( ok )
13700
            test_ok ;
13701
 
13702 26 mihad
        @(posedge pci_clock) ;
13703
        @(posedge pci_clock) ;
13704
        @(posedge wb_clock) ;
13705
        @(posedge wb_clock) ;
13706
 
13707 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13708
        addr_offset = 12'h004 ;
13709
        config_read(addr_offset, 4'hF, read_data) ;
13710
        ok = 1 ;
13711
        if ( read_data[27] !== 1 )
13712
        begin
13713
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13714
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13715
            ok = 0 ;
13716
        end
13717
        if ( read_data[28] !== 0 )
13718
        begin
13719
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13720
            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") ;
13721
            ok = 0 ;
13722
        end
13723
        if ( read_data[29] !== 0 )
13724
        begin
13725
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13726
            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") ;
13727
            ok = 0 ;
13728
        end
13729
 
13730
        // clear statuses
13731
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13732
        if ( !ok )
13733
        begin
13734
            test_fail("write to PCI Device Status register failed") ;
13735
            $display("Couldn't write PCI Device Status register") ;
13736
            disable main ;
13737
        end
13738
 
13739
        if ( ok )
13740
            test_ok ;
13741
 
13742
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13743
 
13744
        ok = 1 ;
13745
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13746
 
13747
        config_read(addr_offset, 4'hF, read_data) ;
13748
        if (read_data[8] !== 0)
13749
        begin
13750
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13751
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13752
            ok = 0 ;
13753
        end
13754
        else
13755
            test_ok ;
13756
 
13757
        if ( ok !== 1 )
13758
        begin
13759
            config_write(addr_offset, read_data, 4'hF, ok) ;
13760
            if ( !ok )
13761
            begin
13762
                test_fail("PCI Error Control and Status register could not be written") ;
13763
                disable main ;
13764
            end
13765
        end
13766
 
13767
        // do a single read error terminated on WB bus
13768
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13769
 
13770
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13771
 
13772
        fork
13773
        begin
13774
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13775
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13776
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13777
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13778
 
13779
            do_pause( 1 ) ;
13780
        end
13781
        begin
13782
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13783
 
13784
            if ( ok !== 1 )
13785
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13786
 
13787
            do_pause(3) ;
13788
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13789
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13790
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13791
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13792
            do_pause(1) ;
13793
 
13794
            while ( FRAME === 0 )
13795
                @(posedge pci_clock) ;
13796
 
13797
            while ( IRDY === 0 )
13798
                @(posedge pci_clock) ;
13799
 
13800 35 mihad
            if ( !error_monitor_done )
13801
                disable monitor_error_event3 ;
13802 15 mihad
        end
13803
        begin:monitor_error_event3
13804 35 mihad
            error_monitor_done = 0 ;
13805 15 mihad
            @(error_event_int) ;
13806
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13807
            ok = 0 ;
13808 35 mihad
            error_monitor_done = 1 ;
13809 15 mihad
        end
13810
        join
13811
 
13812
        if ( ok )
13813
            test_ok ;
13814
 
13815 26 mihad
        @(posedge pci_clock) ;
13816
        @(posedge pci_clock) ;
13817
        @(posedge wb_clock) ;
13818
        @(posedge wb_clock) ;
13819
 
13820 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13821
        addr_offset = 12'h004 ;
13822
        config_read(addr_offset, 4'hF, read_data) ;
13823
        ok = 1 ;
13824
        if ( read_data[27] !== 1 )
13825
        begin
13826
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13827
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13828
            ok = 0 ;
13829
        end
13830
        if ( read_data[28] !== 0 )
13831
        begin
13832
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13833
            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") ;
13834
            ok = 0 ;
13835
        end
13836
        if ( read_data[29] !== 0 )
13837
        begin
13838
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13839
            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") ;
13840
            ok = 0 ;
13841
        end
13842
 
13843
        // clear statuses
13844
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13845
        if ( !ok )
13846
        begin
13847
            test_fail("write to PCI Device Status register failed") ;
13848
            $display("Couldn't write PCI Device Status register") ;
13849
            disable main ;
13850
        end
13851
 
13852
        if ( ok )
13853
            test_ok ;
13854
 
13855
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13856
 
13857
        ok = 1 ;
13858
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13859
 
13860
        config_read(addr_offset, 4'hF, read_data) ;
13861
        if (read_data[8] !== 0)
13862
        begin
13863
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13864
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13865
            ok = 0 ;
13866
        end
13867
        else
13868
            test_ok ;
13869
 
13870
        if ( ok !== 1 )
13871
        begin
13872
            config_write(addr_offset, read_data, 4'hF, ok) ;
13873
            if ( !ok )
13874
            begin
13875
                test_fail("PCI Error Control and Status register could not be written") ;
13876
                disable main ;
13877
            end
13878
        end
13879
 
13880
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13881
 
13882
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13883
 
13884
        fork
13885
        begin
13886
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13887
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13888
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13889
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13890
 
13891
            do_pause( 1 ) ;
13892
        end
13893
        begin
13894
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13895
 
13896
            if ( ok !== 1 )
13897
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13898
 
13899
            do_pause(3) ;
13900
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13901
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13902
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13903
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13904
            do_pause(1) ;
13905
 
13906
            while ( FRAME === 0 )
13907
                @(posedge pci_clock) ;
13908
 
13909
            while ( IRDY === 0 )
13910
                @(posedge pci_clock) ;
13911
 
13912 35 mihad
            #1 ;
13913
            if ( !error_monitor_done )
13914
                disable monitor_error_event4 ;
13915 15 mihad
        end
13916
        begin:monitor_error_event4
13917 35 mihad
            error_monitor_done = 0 ;
13918 15 mihad
            @(error_event_int) ;
13919
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13920
            ok = 0 ;
13921 35 mihad
            error_monitor_done = 1 ;
13922 15 mihad
        end
13923
        begin
13924
            wb_transaction_stop( 1 ) ;
13925
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13926
        end
13927
        join
13928
 
13929
        if ( ok )
13930
            test_ok ;
13931
 
13932 26 mihad
        @(posedge pci_clock) ;
13933
        @(posedge pci_clock) ;
13934
        @(posedge wb_clock) ;
13935
        @(posedge wb_clock) ;
13936
 
13937 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13938
        addr_offset = 12'h004 ;
13939
        config_read(addr_offset, 4'hF, read_data) ;
13940
        ok = 1 ;
13941
        if ( read_data[27] !== 1 )
13942
        begin
13943
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13944
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13945
            ok = 0 ;
13946
        end
13947
        if ( read_data[28] !== 0 )
13948
        begin
13949
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13950
            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") ;
13951
            ok = 0 ;
13952
        end
13953
        if ( read_data[29] !== 0 )
13954
        begin
13955
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13956
            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") ;
13957
            ok = 0 ;
13958
        end
13959
 
13960
        // clear statuses
13961
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13962
        if ( !ok )
13963
        begin
13964
            test_fail("write to PCI Device Status register failed") ;
13965
            $display("Couldn't write PCI Device Status register") ;
13966
            disable main ;
13967
        end
13968
 
13969
        if ( ok )
13970
            test_ok ;
13971
 
13972
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13973
 
13974
        ok = 1 ;
13975
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13976
 
13977
        config_read(addr_offset, 4'hF, read_data) ;
13978
        if (read_data[8] !== 0)
13979
        begin
13980
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13981
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13982
            ok = 0 ;
13983
        end
13984
        else
13985
            test_ok ;
13986
 
13987
        if ( ok !== 1 )
13988
        begin
13989
            config_write(addr_offset, read_data, 4'hF, ok) ;
13990
            if ( !ok )
13991
            begin
13992
                test_fail("PCI Error Control and Status register could not be written") ;
13993
                disable main ;
13994
            end
13995
        end
13996
 
13997
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13998
 
13999
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14000
 
14001
        fork
14002
        begin
14003
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14004
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14005
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14006
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14007
 
14008
            do_pause( 1 ) ;
14009
        end
14010
        begin
14011
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14012
 
14013
            if ( ok !== 1 )
14014
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14015
 
14016
            do_pause(3) ;
14017
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14018
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14019
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14020
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14021
            do_pause(1) ;
14022
 
14023
            while ( FRAME === 0 )
14024
                @(posedge pci_clock) ;
14025
 
14026
            while ( IRDY === 0 )
14027
                @(posedge pci_clock) ;
14028
 
14029 35 mihad
            #1 ;
14030
            if ( !error_monitor_done )
14031
                disable monitor_error_event5 ;
14032 15 mihad
        end
14033
        begin:monitor_error_event5
14034 35 mihad
            error_monitor_done = 0 ;
14035 15 mihad
            @(error_event_int) ;
14036
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14037
            ok = 0 ;
14038 35 mihad
            error_monitor_done = 1 ;
14039 15 mihad
        end
14040
        begin
14041
            wb_transaction_stop( 3 ) ;
14042
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14043
        end
14044
        join
14045
 
14046
        if ( ok )
14047
            test_ok ;
14048
 
14049 26 mihad
        @(posedge pci_clock) ;
14050
        @(posedge pci_clock) ;
14051
        @(posedge wb_clock) ;
14052
        @(posedge wb_clock) ;
14053
 
14054 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14055
        addr_offset = 12'h004 ;
14056
        config_read(addr_offset, 4'hF, read_data) ;
14057
        ok = 1 ;
14058
        if ( read_data[27] !== 1 )
14059
        begin
14060
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14061
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14062
            ok = 0 ;
14063
        end
14064
        if ( read_data[28] !== 0 )
14065
        begin
14066
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14067
            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") ;
14068
            ok = 0 ;
14069
        end
14070
        if ( read_data[29] !== 0 )
14071
        begin
14072
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14073
            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") ;
14074
            ok = 0 ;
14075
        end
14076
 
14077
        // clear statuses
14078
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14079
        if ( !ok )
14080
        begin
14081
            test_fail("write to PCI Device Status register failed") ;
14082
            $display("Couldn't write PCI Device Status register") ;
14083
            disable main ;
14084
        end
14085
 
14086
        if ( ok )
14087
            test_ok ;
14088
 
14089
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14090
 
14091
        ok = 1 ;
14092
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14093
 
14094
        config_read(addr_offset, 4'hF, read_data) ;
14095
        if (read_data[8] !== 0)
14096
        begin
14097
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14098
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14099
            ok = 0 ;
14100
        end
14101
        else
14102
            test_ok ;
14103
 
14104
        if ( ok !== 1 )
14105
        begin
14106
            config_write(addr_offset, read_data, 4'hF, ok) ;
14107
            if ( !ok )
14108
            begin
14109
                test_fail("PCI Error Control and Status register could not be written") ;
14110
                disable main ;
14111
            end
14112
        end
14113
 
14114
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14115
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14116
        fork
14117
        begin
14118
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14119
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14120
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14121
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14122
 
14123
            do_pause( 1 ) ;
14124
        end
14125
        begin
14126
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14127
 
14128
            if ( ok !== 1 )
14129
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14130
 
14131
            do_pause(3) ;
14132
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14133
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14134
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14135
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14136
            do_pause(1) ;
14137
 
14138
            while ( FRAME === 0 )
14139
                @(posedge pci_clock) ;
14140
 
14141
            while ( IRDY === 0 )
14142
                @(posedge pci_clock) ;
14143
 
14144 35 mihad
            #1 ;
14145
            if ( !error_monitor_done )
14146
                disable monitor_error_event6 ;
14147 15 mihad
        end
14148
        begin:monitor_error_event6
14149 35 mihad
            error_monitor_done = 0 ;
14150 15 mihad
            @(error_event_int) ;
14151
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14152
            ok = 0 ;
14153 35 mihad
            error_monitor_done = 1 ;
14154 15 mihad
        end
14155
        begin
14156
            wb_transaction_stop( 3 ) ;
14157
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14158
        end
14159
        join
14160
 
14161
        if ( ok )
14162
            test_ok ;
14163
 
14164 26 mihad
        @(posedge pci_clock) ;
14165
        @(posedge pci_clock) ;
14166
        @(posedge wb_clock) ;
14167
        @(posedge wb_clock) ;
14168
 
14169 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14170
        addr_offset = 12'h004 ;
14171
        config_read(addr_offset, 4'hF, read_data) ;
14172
        ok = 1 ;
14173
        if ( read_data[27] !== 1 )
14174
        begin
14175
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14176
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14177
            ok = 0 ;
14178
        end
14179
        if ( read_data[28] !== 0 )
14180
        begin
14181
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14182
            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") ;
14183
            ok = 0 ;
14184
        end
14185
        if ( read_data[29] !== 0 )
14186
        begin
14187
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14188
            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") ;
14189
            ok = 0 ;
14190
        end
14191
 
14192
        // clear statuses
14193
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14194
        if ( !ok )
14195
        begin
14196
            test_fail("write to PCI Device Status register failed") ;
14197
            $display("Couldn't write PCI Device Status register") ;
14198
            disable main ;
14199
        end
14200
 
14201
        if ( ok )
14202
            test_ok ;
14203
 
14204
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14205
 
14206
        ok = 1 ;
14207
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14208
 
14209
        config_read(addr_offset, 4'hF, read_data) ;
14210
        if (read_data[8] !== 0)
14211
        begin
14212
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14213
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14214
            ok = 0 ;
14215
        end
14216
        else
14217
            test_ok ;
14218
 
14219
        if ( ok !== 1 )
14220
        begin
14221
            config_write(addr_offset, read_data, 4'hF, ok) ;
14222
            if ( !ok )
14223
            begin
14224
                test_fail("PCI Error Control and Status register could not be written") ;
14225
                disable main ;
14226
            end
14227
        end
14228
 
14229
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14230
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14231
        fork
14232
        begin
14233
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14234
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14235
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14236
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14237
 
14238
            do_pause( 1 ) ;
14239
        end
14240
        begin
14241
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14242
 
14243
            if ( ok !== 1 )
14244
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14245
 
14246
            do_pause(3) ;
14247
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14248
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14249
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14250
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14251
            do_pause(1) ;
14252
 
14253
            while ( FRAME === 0 )
14254
                @(posedge pci_clock) ;
14255
 
14256
            while ( IRDY === 0 )
14257
                @(posedge pci_clock) ;
14258
 
14259 35 mihad
            #1 ;
14260
            if ( !error_monitor_done )
14261
                disable monitor_error_event7 ;
14262 15 mihad
        end
14263
        begin:monitor_error_event7
14264 35 mihad
            error_monitor_done = 0 ;
14265 15 mihad
            @(error_event_int) ;
14266
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14267
            ok = 0 ;
14268 35 mihad
            error_monitor_done = 1 ;
14269 15 mihad
        end
14270
        begin
14271
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14272
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14273
        end
14274
        join
14275
 
14276
        if ( ok )
14277
            test_ok ;
14278
 
14279 26 mihad
        @(posedge pci_clock) ;
14280
        @(posedge pci_clock) ;
14281
        @(posedge wb_clock) ;
14282
        @(posedge wb_clock) ;
14283
 
14284 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14285
        addr_offset = 12'h004 ;
14286
        config_read(addr_offset, 4'hF, read_data) ;
14287
        ok = 1 ;
14288
        if ( read_data[27] !== 1 )
14289
        begin
14290
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14291
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14292
            ok = 0 ;
14293
        end
14294
        if ( read_data[28] !== 0 )
14295
        begin
14296
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14297
            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") ;
14298
            ok = 0 ;
14299
        end
14300
        if ( read_data[29] !== 0 )
14301
        begin
14302
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14303
            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") ;
14304
            ok = 0 ;
14305
        end
14306
 
14307
        // clear statuses
14308
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14309
        if ( !ok )
14310
        begin
14311
            test_fail("write to PCI Device Status register failed") ;
14312
            $display("Couldn't write PCI Device Status register") ;
14313
            disable main ;
14314
        end
14315
 
14316
        if ( ok )
14317
            test_ok ;
14318
 
14319
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14320
 
14321
        ok = 1 ;
14322
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14323
 
14324
        config_read(addr_offset, 4'hF, read_data) ;
14325
        if (read_data[8] !== 0)
14326
        begin
14327
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14328
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14329
            ok = 0 ;
14330
        end
14331
        else
14332
            test_ok ;
14333
 
14334
        if ( ok !== 1 )
14335
        begin
14336
            config_write(addr_offset, read_data, 4'hF, ok) ;
14337
            if ( !ok )
14338
            begin
14339
                test_fail("PCI Error Control and Status register could not be written") ;
14340
                disable main ;
14341
            end
14342
        end
14343
 
14344
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14345
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14346
        fork
14347
        begin
14348
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14349
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14350
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14351
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14352
 
14353
            do_pause( 1 ) ;
14354
        end
14355
        begin
14356
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14357
 
14358
            if ( ok !== 1 )
14359
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14360
 
14361
            do_pause(3) ;
14362
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14363
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14364
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14365
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14366
            do_pause(1) ;
14367
 
14368
            while ( FRAME === 0 )
14369
                @(posedge pci_clock) ;
14370
 
14371
            while ( IRDY === 0 )
14372
                @(posedge pci_clock) ;
14373
 
14374 35 mihad
            #1 ;
14375
            if ( !error_monitor_done )
14376
                disable monitor_error_event8 ;
14377 15 mihad
        end
14378
        begin:monitor_error_event8
14379 35 mihad
            error_monitor_done = 0 ;
14380 15 mihad
            @(error_event_int) ;
14381
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14382
            ok = 0 ;
14383 35 mihad
            error_monitor_done = 1 ;
14384 15 mihad
        end
14385
        begin
14386
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14387
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14388
        end
14389
        join
14390
 
14391
        if ( ok )
14392
            test_ok ;
14393
 
14394 26 mihad
        @(posedge pci_clock) ;
14395
        @(posedge pci_clock) ;
14396
        @(posedge wb_clock) ;
14397
        @(posedge wb_clock) ;
14398
 
14399 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14400
 
14401
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14402
        addr_offset = 12'h004 ;
14403
        config_read(addr_offset, 4'hF, read_data) ;
14404
        ok = 1 ;
14405
        if ( read_data[27] !== 1 )
14406
        begin
14407
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14408
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14409
            ok = 0 ;
14410
        end
14411
        if ( read_data[28] !== 0 )
14412
        begin
14413
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14414
            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") ;
14415
            ok = 0 ;
14416
        end
14417
        if ( read_data[29] !== 0 )
14418
        begin
14419
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14420
            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") ;
14421
            ok = 0 ;
14422
        end
14423
 
14424
        // clear statuses
14425
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14426
        if ( !ok )
14427
        begin
14428
            test_fail("write to PCI Device Status register failed") ;
14429
            $display("Couldn't write PCI Device Status register") ;
14430
            disable main ;
14431
        end
14432
 
14433
        if ( ok )
14434
            test_ok ;
14435
 
14436
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14437
 
14438
        ok = 1 ;
14439
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14440
 
14441
        config_read(addr_offset, 4'hF, read_data) ;
14442
        if (read_data[8] !== 0)
14443
        begin
14444
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14445
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14446
            ok = 0 ;
14447
        end
14448
        else
14449
            test_ok ;
14450
 
14451
        if ( ok !== 1 )
14452
        begin
14453
            config_write(addr_offset, read_data, 4'hF, ok) ;
14454
            if ( !ok )
14455
            begin
14456
                test_fail("PCI Error Control and Status register could not be written") ;
14457
                disable main ;
14458
            end
14459
        end
14460
 
14461
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14462
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14463
        fork
14464
        begin
14465
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14466
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14467
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14468
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14469
 
14470
            do_pause( 1 ) ;
14471
        end
14472
        begin
14473
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14474
 
14475
            if ( ok !== 1 )
14476
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14477
 
14478
            do_pause(3) ;
14479
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14480
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14481
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14482
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14483
            do_pause(1) ;
14484
 
14485
            while ( FRAME === 0 )
14486
                @(posedge pci_clock) ;
14487
 
14488
            while ( IRDY === 0 )
14489
                @(posedge pci_clock) ;
14490
 
14491 35 mihad
            #1 ;
14492
            if ( !error_monitor_done )
14493
                disable monitor_error_event9 ;
14494 15 mihad
        end
14495
        begin:monitor_error_event9
14496 35 mihad
            error_monitor_done = 0 ;
14497 15 mihad
            @(error_event_int) ;
14498
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14499
            ok = 0 ;
14500 35 mihad
            error_monitor_done = 1 ;
14501 15 mihad
        end
14502
        begin
14503
            wb_transaction_stop( 3 ) ;
14504
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14505
        end
14506
        join
14507
 
14508
        if ( ok )
14509
            test_ok ;
14510
 
14511
        // now check all other statuses too
14512
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14513
        ok = 1 ;
14514
 
14515
        addr_offset = 12'h004 ;
14516
        config_read(addr_offset, 4'hF, read_data) ;
14517
        if (read_data[31] !== 0)
14518
        begin
14519
            $display("Detected Parity Error bit set for no reason") ;
14520
            test_fail("Detected Parity Error bit was set for no reason") ;
14521
            ok = 0 ;
14522
        end
14523
 
14524
        if (read_data[30] !== 0)
14525
        begin
14526
            $display("Signaled System Error bit set for no reason") ;
14527
            test_fail("Signaled System Error bit was set for no reason") ;
14528
            ok = 0 ;
14529
        end
14530
 
14531
        if (read_data[29] !== 0)
14532
        begin
14533
            $display("Received Master Abort bit set for no reason") ;
14534
            test_fail("Received Master Abort bit was set for no reason") ;
14535
            ok = 0 ;
14536
        end
14537
 
14538
        if (read_data[28] !== 0)
14539
        begin
14540
            $display("Received Target Abort bit set for no reason");
14541
            test_fail("Received Target Abort bit was set for no reason") ;
14542
            ok = 0 ;
14543
        end
14544
 
14545
        if (read_data[27] !== 0)
14546
        begin
14547
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14548
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14549
            ok = 0 ;
14550
        end
14551
 
14552
        if (read_data[24] !== 0)
14553
        begin
14554
            $display("Master Data Parity Error bit set for no reason") ;
14555
            test_fail("Master Data Parity Error bit was set for no reason") ;
14556
            ok = 0 ;
14557
        end
14558
 
14559
        if ( ok )
14560
            test_ok ;
14561
 
14562
        test_name = "DISABLE IMAGE" ;
14563 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14564 15 mihad
        if ( ok !== 1 )
14565
        begin
14566
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14567
            test_fail("PCI Address Mask register could not be written") ;
14568
            disable main;
14569
        end
14570
    end
14571
 
14572
    if ( target_io_image !== -1 )
14573
    begin
14574
        do_io_aborts = 1 ;
14575
 
14576
        if (target_io_image === 1)
14577
        begin
14578
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14579
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14580
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14581
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14582
        end
14583
        else if (target_io_image === 2)
14584
        begin
14585
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14586
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14587
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14588
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14589
        end
14590
        else if (target_io_image === 3)
14591
        begin
14592
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14593
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14594
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14595
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14596
        end
14597
        else if (target_io_image === 4)
14598
        begin
14599
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14600
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14601
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14602
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14603
        end
14604
        else if (target_io_image === 5)
14605
        begin
14606
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14607
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14608
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14609
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14610
        end
14611
    end
14612
    else
14613
        do_io_aborts = 0 ;
14614
 
14615
    if ( do_io_aborts )
14616
    begin
14617
 
14618
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14619
 
14620
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14621
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14622
        if ( ok !== 1 )
14623
        begin
14624
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14625
            test_fail("PCI Error Control and Status register could not be written") ;
14626
            disable main;
14627
        end
14628
 
14629
        // enable INTERRUPT reporting
14630
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14631
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14632
        if ( ok !== 1 )
14633
        begin
14634
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14635
            test_fail("Interrupt Control register could not be written") ;
14636
            disable main;
14637
        end
14638
 
14639
        addr_offset = 12'h010 + (4*target_io_image) ;
14640
 
14641
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14642
        if ( ok !== 1 )
14643
        begin
14644
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14645
            test_fail("PCI Base Address register could not be written") ;
14646
            disable main;
14647
        end
14648
 
14649
        // disable address translation and enable prefetch so read bursts can be performed
14650
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14651
        if ( ok !== 1 )
14652
        begin
14653
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14654
            test_fail("PCI Image Control register could not be written") ;
14655
            disable main;
14656
        end
14657
 
14658
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14659
        if ( ok !== 1 )
14660
        begin
14661
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14662
            test_fail("PCI Address Mask register could not be written") ;
14663
            disable main;
14664
        end
14665
 
14666
        addr_offset = 12'h00C ;
14667
 
14668
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14669
        if ( ok !== 1 )
14670
        begin
14671
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14672
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14673
            disable main;
14674
        end
14675
 
14676
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14677
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14678
 
14679
        // do a single read error terminated on WB bus
14680
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14681
 
14682
        fork
14683
        begin
14684
            PCIU_IO_READ
14685
             (
14686
                `Test_Master_1,
14687
                Target_Base_Addr_R[target_io_image],
14688
                32'hAAAA_5555,
14689
                4'h0,
14690
                1,
14691
                `Test_Target_Retry_On
14692
             );
14693
 
14694
            do_pause( 1 ) ;
14695
        end
14696
        begin
14697
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14698
 
14699
            if ( ok !== 1 )
14700
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14701
 
14702
            do_pause(3) ;
14703
 
14704
            PCIU_IO_READ
14705
             (
14706
                `Test_Master_1,
14707
                Target_Base_Addr_R[target_io_image],
14708
                32'hAAAA_5555,
14709
                4'h0,
14710
                1,
14711
                `Test_Target_Abort_On
14712
             );
14713
 
14714
            do_pause( 1 ) ;
14715
 
14716
            while ( FRAME === 0 )
14717
                @(posedge pci_clock) ;
14718
 
14719
            while ( IRDY === 0 )
14720
                @(posedge pci_clock) ;
14721
 
14722 35 mihad
            #1 ;
14723
            if ( !error_monitor_done )
14724
                disable monitor_error_event10 ;
14725 15 mihad
        end
14726
        begin:monitor_error_event10
14727 35 mihad
            error_monitor_done = 0 ;
14728 15 mihad
            @(error_event_int) ;
14729
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14730
            ok = 0 ;
14731 35 mihad
            error_monitor_done = 1 ;
14732 15 mihad
        end
14733
        join
14734
 
14735
        if ( ok )
14736
            test_ok ;
14737
 
14738 26 mihad
        @(posedge pci_clock) ;
14739
        @(posedge pci_clock) ;
14740
        @(posedge wb_clock) ;
14741
        @(posedge wb_clock) ;
14742
 
14743 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14744
        addr_offset = 12'h004 ;
14745
        config_read(addr_offset, 4'hF, read_data) ;
14746
        ok = 1 ;
14747
        if ( read_data[27] !== 1 )
14748
        begin
14749
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14750
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14751
            ok = 0 ;
14752
        end
14753
        if ( read_data[28] !== 0 )
14754
        begin
14755
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14756
            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") ;
14757
            ok = 0 ;
14758
        end
14759
        if ( read_data[29] !== 0 )
14760
        begin
14761
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14762
            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") ;
14763
            ok = 0 ;
14764
        end
14765
 
14766
        // clear statuses
14767
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14768
        if ( !ok )
14769
        begin
14770
            test_fail("write to PCI Device Status register failed") ;
14771
            $display("Couldn't write PCI Device Status register") ;
14772
            disable main ;
14773
        end
14774
 
14775
        if ( ok )
14776
            test_ok ;
14777
 
14778
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14779
 
14780
        ok = 1 ;
14781
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14782
 
14783
        config_read(addr_offset, 4'hF, read_data) ;
14784
        if (read_data[8] !== 0)
14785
        begin
14786
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14787
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14788
            ok = 0 ;
14789
        end
14790
        else
14791
            test_ok ;
14792
 
14793
        if ( ok !== 1 )
14794
        begin
14795
            config_write(addr_offset, read_data, 4'hF, ok) ;
14796
            if ( !ok )
14797
            begin
14798
                test_fail("PCI Error Control and Status register could not be written") ;
14799
                disable main ;
14800
            end
14801
        end
14802
 
14803
        test_name = "DISABLE IMAGE" ;
14804 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14805 15 mihad
        if ( ok !== 1 )
14806
        begin
14807
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14808
            test_fail("PCI Address Mask register could not be written") ;
14809
            disable main;
14810
        end
14811
 
14812
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14813
 
14814
    end
14815
end // main
14816
endtask // test_wb_error_rd
14817
 
14818
task test_target_abort ;
14819
    input [2:0]  image_num ;
14820
    reg   [11:0] pci_ctrl_offset ;
14821
    reg   [11:0] ctrl_offset ;
14822
    reg   [11:0] ba_offset ;
14823
    reg   [11:0] am_offset ;
14824
    reg   [11:0] ta_offset ;
14825
    reg   [31:0] pci_address ;
14826
    reg   [3:0]  byte_enables ;
14827
    reg          ok ;
14828 35 mihad
    reg          error_monitor_done ;
14829 15 mihad
begin:main
14830
    pci_ctrl_offset = 12'h4 ;
14831
    if (image_num === 0)
14832
    begin
14833
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14834
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14835
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14836
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14837
    end
14838
    else if (image_num === 1)
14839
    begin
14840
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14841
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14842
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14843
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14844
    end
14845
    else if (image_num === 2)
14846
    begin
14847
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14848
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14849
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14850
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14851
    end
14852
    else if (image_num === 3)
14853
    begin
14854
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14855
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14856
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14857
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14858
    end
14859
    else if (image_num === 4)
14860
    begin
14861
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14862
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14863
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14864
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14865
    end
14866
    else if (image_num === 5)
14867
    begin
14868
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14869
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14870
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14871
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14872
    end
14873
 
14874
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14875
 
14876
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14877
    if ( ok !== 1 )
14878
    begin
14879
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14880
        test_fail("PCI Base Address register could not be written") ;
14881
        disable main ;
14882
    end
14883
 
14884
    // Set Address Mask of IMAGE
14885
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14886
    if ( ok !== 1 )
14887
    begin
14888
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14889
        test_fail("PCI Address Mask register could not be written") ;
14890
        disable main ;
14891
    end
14892
 
14893
    // Set Translation Address of IMAGE
14894
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14895
    if ( ok !== 1 )
14896
    begin
14897
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14898
        test_fail("PCI Translation Address Register could not be written") ;
14899
        disable main ;
14900
    end
14901
 
14902
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14903
    if ( ok !== 1 )
14904
    begin
14905
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14906
        test_fail("PCI Image Control register could not be written") ;
14907
        disable main ;
14908
    end
14909
 
14910
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14911
 
14912
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14913
 
14914
    pci_address  = Target_Base_Addr_R[image_num] ;
14915
    byte_enables = 4'b0001 ;
14916
 
14917
    fork
14918
    begin
14919
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14920
        do_pause ( 1 ) ;
14921
    end
14922
    begin:monitor_error_event1
14923 35 mihad
        error_monitor_done = 0 ;
14924 15 mihad
        @(error_event_int) ;
14925
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14926
        ok = 0 ;
14927 35 mihad
        error_monitor_done = 1 ;
14928 15 mihad
    end
14929
    begin
14930
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14931
        @(posedge pci_clock) ;
14932 35 mihad
        #1 ;
14933
        if ( !error_monitor_done )
14934
            disable monitor_error_event1 ;
14935 15 mihad
    end
14936
    join
14937
 
14938
    if ( ok )
14939
        test_ok ;
14940
 
14941
    ok = 1 ;
14942
 
14943
    fork
14944
    begin
14945
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14946
        do_pause ( 1 ) ;
14947
    end
14948
    begin:monitor_error_event2
14949 35 mihad
        error_monitor_done = 0 ;
14950 15 mihad
        @(error_event_int) ;
14951
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14952
        ok = 0 ;
14953 35 mihad
        error_monitor_done = 1 ;
14954 15 mihad
    end
14955
    begin
14956
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14957
        @(posedge pci_clock) ;
14958 35 mihad
        #1 ;
14959
        if ( !error_monitor_done )
14960
            disable monitor_error_event2 ;
14961 15 mihad
    end
14962
    join
14963
 
14964
    if ( ok )
14965
        test_ok ;
14966
 
14967
    ok = 1 ;
14968
 
14969
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14970
    byte_enables = 4'b0011 ;
14971
 
14972
    fork
14973
    begin
14974
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14975
        do_pause ( 1 ) ;
14976
    end
14977
    begin:monitor_error_event3
14978 35 mihad
        error_monitor_done = 0 ;
14979 15 mihad
        @(error_event_int) ;
14980
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14981
        ok = 0 ;
14982 35 mihad
        error_monitor_done = 1 ;
14983 15 mihad
    end
14984
    begin
14985
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14986
        @(posedge pci_clock) ;
14987 35 mihad
        if ( !error_monitor_done )
14988
            disable monitor_error_event3 ;
14989 15 mihad
    end
14990
    join
14991
 
14992
    if ( ok )
14993
        test_ok ;
14994
 
14995
    ok = 1 ;
14996
 
14997
    byte_enables = 4'b0000 ;
14998
 
14999
    fork
15000
    begin
15001
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15002
        do_pause ( 1 ) ;
15003
    end
15004
    begin:monitor_error_event4
15005 35 mihad
        error_monitor_done = 0 ;
15006 15 mihad
        @(error_event_int) ;
15007
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15008
        ok = 0 ;
15009 35 mihad
        error_monitor_done = 1 ;
15010 15 mihad
    end
15011
    begin
15012
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15013
        @(posedge pci_clock) ;
15014 35 mihad
        #1 ;
15015
        if ( !error_monitor_done )
15016
            disable monitor_error_event4 ;
15017 15 mihad
    end
15018
    join
15019
 
15020
    if ( ok )
15021
        test_ok ;
15022
 
15023
    ok = 1 ;
15024
 
15025
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
15026
    byte_enables = 4'b0111 ;
15027
 
15028
    fork
15029
    begin
15030
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15031
        do_pause ( 1 ) ;
15032
    end
15033
    begin:monitor_error_event5
15034 35 mihad
        error_monitor_done = 0 ;
15035 15 mihad
        @(error_event_int) ;
15036
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15037
        ok = 0 ;
15038 35 mihad
        error_monitor_done = 1 ;
15039 15 mihad
    end
15040
    begin
15041
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15042
        @(posedge pci_clock) ;
15043 35 mihad
        #1 ;
15044
        if ( !error_monitor_done )
15045
            disable monitor_error_event5 ;
15046 15 mihad
    end
15047
    join
15048
 
15049
    if ( ok )
15050
        test_ok ;
15051
 
15052
    ok = 1 ;
15053
 
15054
    byte_enables = 4'b0010 ;
15055
 
15056
    fork
15057
    begin
15058
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15059
        do_pause ( 1 ) ;
15060
    end
15061
    begin:monitor_error_event6
15062 35 mihad
        error_monitor_done = 0 ;
15063 15 mihad
        @(error_event_int) ;
15064
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15065
        ok = 0 ;
15066 35 mihad
        error_monitor_done = 1 ;
15067 15 mihad
    end
15068
    begin
15069
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15070
        @(posedge pci_clock) ;
15071 35 mihad
        #1 ;
15072
        if ( !error_monitor_done )
15073
            disable monitor_error_event6 ;
15074 15 mihad
    end
15075
    join
15076
 
15077
    if ( ok )
15078
        test_ok ;
15079
 
15080
    ok = 1 ;
15081
    byte_enables = 4'b0001 ;
15082
 
15083
    fork
15084
    begin
15085
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15086
        do_pause ( 1 ) ;
15087
    end
15088
    begin:monitor_error_event7
15089 35 mihad
        error_monitor_done = 0 ;
15090 15 mihad
        @(error_event_int) ;
15091
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15092
        ok = 0 ;
15093 35 mihad
        error_monitor_done = 1 ;
15094 15 mihad
    end
15095
    begin
15096
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15097
        @(posedge pci_clock) ;
15098 35 mihad
        #1 ;
15099
        if ( !error_monitor_done )
15100
            disable monitor_error_event7 ;
15101 15 mihad
    end
15102
    join
15103
 
15104
    if ( ok )
15105
        test_ok ;
15106
 
15107
    ok = 1 ;
15108
    byte_enables = 4'b0000 ;
15109
 
15110
    fork
15111
    begin
15112
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15113
        do_pause ( 1 ) ;
15114
    end
15115
    begin:monitor_error_event8
15116 35 mihad
        error_monitor_done = 0 ;
15117 15 mihad
        @(error_event_int) ;
15118
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15119
        ok = 0 ;
15120 35 mihad
        error_monitor_done = 1 ;
15121 15 mihad
    end
15122
    begin
15123
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15124
        @(posedge pci_clock) ;
15125 35 mihad
        #1 ;
15126
        if ( !error_monitor_done )
15127
            disable monitor_error_event8 ;
15128 15 mihad
    end
15129
    join
15130
 
15131
    if ( ok )
15132
        test_ok ;
15133
 
15134
    ok = 1 ;
15135
 
15136
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15137
    byte_enables = 4'b0110 ;
15138
 
15139
    fork
15140
    begin
15141
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15142
        do_pause ( 1 ) ;
15143
    end
15144
    begin:monitor_error_event9
15145 35 mihad
        error_monitor_done = 0 ;
15146 15 mihad
        @(error_event_int) ;
15147
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15148
        ok = 0 ;
15149 35 mihad
        error_monitor_done = 1 ;
15150 15 mihad
    end
15151
    begin
15152
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15153
        @(posedge pci_clock) ;
15154 35 mihad
        #1 ;
15155
        if ( !error_monitor_done )
15156
            disable monitor_error_event9 ;
15157 15 mihad
    end
15158
    join
15159
 
15160
    if ( ok )
15161
        test_ok ;
15162
 
15163
    ok = 1 ;
15164
    fork
15165
    begin
15166
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15167
        do_pause ( 1 ) ;
15168
    end
15169
    begin:monitor_error_event10
15170 35 mihad
        error_monitor_done = 0 ;
15171 15 mihad
        @(error_event_int) ;
15172
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15173
        ok = 0 ;
15174 35 mihad
        error_monitor_done = 1 ;
15175 15 mihad
    end
15176
    begin
15177
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15178
        @(posedge pci_clock) ;
15179 35 mihad
 
15180
        #1 ;
15181
        if ( !error_monitor_done )
15182
            disable monitor_error_event10 ;
15183 15 mihad
    end
15184
    join
15185
 
15186
    if ( ok )
15187
        test_ok ;
15188
 
15189
    ok = 1 ;
15190
 
15191
    byte_enables = 4'b0001 ;
15192
 
15193
    fork
15194
    begin
15195
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15196
        do_pause ( 1 ) ;
15197
    end
15198
    begin:monitor_error_event11
15199 35 mihad
        error_monitor_done = 0 ;
15200 15 mihad
        @(error_event_int) ;
15201
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15202
        ok = 0 ;
15203 35 mihad
        error_monitor_done = 1 ;
15204 15 mihad
    end
15205
    begin
15206
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15207
        @(posedge pci_clock) ;
15208 35 mihad
        #1 ;
15209
        if ( !error_monitor_done )
15210
            disable monitor_error_event11 ;
15211 15 mihad
    end
15212
    join
15213
 
15214
    if ( ok )
15215
        test_ok ;
15216
 
15217
    ok = 1 ;
15218
 
15219
    byte_enables = 4'b0101 ;
15220
 
15221
    fork
15222
    begin
15223
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15224
        do_pause ( 1 ) ;
15225
    end
15226
    begin:monitor_error_event12
15227 35 mihad
        error_monitor_done = 0 ;
15228 15 mihad
        @(error_event_int) ;
15229
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15230
        ok = 0 ;
15231 35 mihad
        error_monitor_done = 1 ;
15232 15 mihad
    end
15233
    begin
15234
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15235
        @(posedge pci_clock) ;
15236 35 mihad
        #1 ;
15237
        if ( !error_monitor_done )
15238
            disable monitor_error_event12 ;
15239 15 mihad
    end
15240
    join
15241
 
15242
    if ( ok )
15243
        test_ok ;
15244
 
15245
    ok = 1 ;
15246
 
15247
    byte_enables = 4'b0011 ;
15248
 
15249
    fork
15250
    begin
15251
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15252
        do_pause ( 1 ) ;
15253
    end
15254
    begin:monitor_error_event13
15255 35 mihad
        error_monitor_done = 0 ;
15256 15 mihad
        @(error_event_int) ;
15257
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15258
        ok = 0 ;
15259 35 mihad
        error_monitor_done = 1 ;
15260 15 mihad
    end
15261
    begin
15262
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15263
        @(posedge pci_clock) ;
15264 35 mihad
        #1 ;
15265
        if ( !error_monitor_done )
15266
            disable monitor_error_event13 ;
15267 15 mihad
    end
15268
    join
15269
 
15270
    if ( ok )
15271
        test_ok ;
15272
 
15273
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15274
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15275
    ok = 1 ;
15276
    if ( pci_address[27] !== 1 )
15277
    begin
15278
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15279
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15280
        ok = 0 ;
15281
    end
15282
    if ( pci_address[28] !== 0 )
15283
    begin
15284
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15285
        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") ;
15286
        ok = 0 ;
15287
    end
15288
    if ( pci_address[29] !== 0 )
15289
    begin
15290
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15291
        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") ;
15292
        ok = 0 ;
15293
    end
15294
 
15295
    // clear statuses
15296
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15297
    if ( !ok )
15298
    begin
15299
        test_fail("write to PCI Device Status register failed") ;
15300
        $display("Couldn't write PCI Device Status register") ;
15301
        disable main ;
15302
    end
15303
 
15304
    if ( ok )
15305
        test_ok ;
15306
 
15307
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15308
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15309
    if ( pci_address[8] !== 0 )
15310
    begin
15311
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15312
    end
15313
    else
15314
        test_ok ;
15315
 
15316
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15317
 
15318
    test_name = "DISABLE IMAGE" ;
15319
 
15320 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15321 15 mihad
    if ( ok !== 1 )
15322
    begin
15323
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15324
        test_fail("PCI Address Mask register could not be written") ;
15325
        disable main ;
15326
    end
15327
end
15328
endtask // test_target_abort
15329
 
15330
task test_target_io_wr_rd ;
15331
    input [2:0]  image_num ;
15332
    input        translate_address ;
15333
    input [11:0] img_ctrl_offset ;
15334
    reg   [31:0] expect_address ;
15335
    reg   [31:0] pci_address ;
15336
    reg          translation ;
15337
    reg   [31:0] read_data ;
15338
    reg   [3:0]  byte_enables ;
15339
    reg          ok ;
15340
    reg          pci_ok ;
15341
    reg          wb_ok ;
15342
    integer      i ;
15343 35 mihad
    reg          error_monitor_done ;
15344 15 mihad
begin:main
15345
    `ifdef ADDR_TRAN_IMPL
15346
        translation = translate_address ;
15347
    `else
15348
        translation = 0 ;
15349
    `endif
15350
 
15351
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15352
 
15353
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15354
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15355
    if ( translation )
15356
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15357
    else
15358
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15359
 
15360
    if ( !ok )
15361
    begin
15362
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15363
        test_fail("PCI Image Control register could not be written") ;
15364
    end
15365
 
15366
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15367
    pci_address  = Target_Base_Addr_R[image_num] ;
15368
    byte_enables = 4'b0000 ;
15369
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15370
 
15371
    fork
15372
    begin
15373
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15374
        do_pause ( 1 ) ;
15375
    end
15376
    begin
15377
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15378
        if ( wb_ok !== 1 )
15379
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15380
 
15381 35 mihad
        #1 ;
15382
        if ( !error_monitor_done )
15383
            disable monitor_pci_error_1 ;
15384 15 mihad
    end
15385
    begin:monitor_pci_error_1
15386 35 mihad
        error_monitor_done = 0 ;
15387 15 mihad
        pci_ok = 1 ;
15388
        @(error_event_int) ;
15389
        pci_ok = 0 ;
15390
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15391 35 mihad
        error_monitor_done = 1 ;
15392 15 mihad
    end
15393
    join
15394
 
15395
    byte_enables = 4'b1111 ;
15396
    for ( i = 0 ; i < 4 ; i = i + 1 )
15397
    begin:loop_1
15398
        byte_enables[i] = 0 ;
15399
        if ( i > 0 )
15400
            byte_enables[i - 1] = 1 ;
15401
        fork
15402
        begin
15403
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15404
            do_pause ( 1 ) ;
15405
        end
15406
        begin
15407
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15408
            if ( wb_ok !== 1 )
15409
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15410
 
15411 35 mihad
            #1 ;
15412
            if ( !error_monitor_done )
15413
                disable monitor_pci_error_2 ;
15414 15 mihad
        end
15415
        begin:monitor_pci_error_2
15416 35 mihad
            error_monitor_done = 0 ;
15417 15 mihad
            pci_ok = 1 ;
15418
            @(error_event_int) ;
15419
            pci_ok = 0 ;
15420
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15421 35 mihad
            error_monitor_done = 1 ;
15422 15 mihad
        end
15423
        join
15424
 
15425
        if ( !pci_ok || !wb_ok )
15426
            disable loop_1 ;
15427
 
15428
        pci_address = pci_address + 1 ;
15429
        expect_address = expect_address + 1 ;
15430
    end
15431
 
15432
    if ( pci_ok && wb_ok )
15433
        test_ok ;
15434
 
15435
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15436
    pci_address  = Target_Base_Addr_R[image_num] ;
15437
    byte_enables = 4'b1100 ;
15438
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15439
 
15440
    master1_check_received_data = 1 ;
15441
    fork
15442
    begin
15443
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15444
        do_pause( 1 ) ;
15445
    end
15446
    begin
15447
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15448
        if ( wb_ok !== 1 )
15449
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15450
 
15451
        do_pause ( 2 ) ;
15452
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15453
        do_pause ( 16 ) ;
15454
 
15455 35 mihad
        #1 ;
15456
        if ( !error_monitor_done )
15457
            disable monitor_pci_error_3 ;
15458 15 mihad
    end
15459
    begin:monitor_pci_error_3
15460 35 mihad
        error_monitor_done = 0 ;
15461 15 mihad
        pci_ok = 1 ;
15462
        @(error_event_int) ;
15463
        pci_ok = 0 ;
15464
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15465 35 mihad
        error_monitor_done = 1 ;
15466 15 mihad
    end
15467
    join
15468
 
15469
    if ( !pci_ok || !wb_ok )
15470
    begin
15471
        disable main ;
15472
    end
15473
 
15474
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15475
    byte_enables = 4'b0011 ;
15476
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15477
 
15478
    master1_check_received_data = 1 ;
15479
    fork
15480
    begin
15481
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15482
        do_pause( 1 ) ;
15483
    end
15484
    begin
15485
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15486
        if ( wb_ok !== 1 )
15487
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15488
 
15489
        do_pause ( 2 ) ;
15490
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15491
        do_pause ( 16 ) ;
15492
 
15493 35 mihad
        #1 ;
15494
        if ( !error_monitor_done )
15495
            disable monitor_pci_error_4 ;
15496 15 mihad
    end
15497
    begin:monitor_pci_error_4
15498 35 mihad
        error_monitor_done = 0 ;
15499 15 mihad
        pci_ok = 1 ;
15500
        @(error_event_int) ;
15501
        pci_ok = 0 ;
15502
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15503 35 mihad
        error_monitor_done = 1 ;
15504 15 mihad
    end
15505
    join
15506
 
15507
    if ( !pci_ok || !wb_ok )
15508
    begin
15509
        disable main ;
15510
    end
15511
 
15512
    pci_address  = Target_Base_Addr_R[image_num] ;
15513
    byte_enables = 4'b0000 ;
15514
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15515
 
15516
    master1_check_received_data = 1 ;
15517
    fork
15518
    begin
15519
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15520
        do_pause( 1 ) ;
15521
    end
15522
    begin
15523
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15524
        if ( wb_ok !== 1 )
15525
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15526
 
15527
        do_pause ( 2 ) ;
15528
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15529
        do_pause ( 16 ) ;
15530
 
15531 35 mihad
        #1 ;
15532
        if ( !error_monitor_done )
15533
            disable monitor_pci_error_5 ;
15534 15 mihad
    end
15535
    begin:monitor_pci_error_5
15536 35 mihad
        error_monitor_done = 0 ;
15537 15 mihad
        pci_ok = 1 ;
15538
        @(error_event_int) ;
15539
        pci_ok = 0 ;
15540
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15541 35 mihad
        error_monitor_done = 1 ;
15542 15 mihad
    end
15543
    join
15544
 
15545
    if ( pci_ok && wb_ok )
15546
        test_ok ;
15547
end
15548
endtask // test_target_io_wr_rd
15549
 
15550
task test_target_io_err_wr ;
15551
    input [2:0]  image_num ;
15552
    input        translate_address ;
15553
    input [11:0] img_ctrl_offset ;
15554
    input        enable_error_report ;
15555
    input        enable_error_interrupt ;
15556
 
15557
    reg   [31:0] expect_address ;
15558
    reg   [31:0] pci_address ;
15559
    reg          translation ;
15560
    reg   [31:0] read_data ;
15561
    reg   [3:0]  byte_enables ;
15562
    reg          ok ;
15563
    reg          pci_ok ;
15564
    reg          wb_ok ;
15565
    integer      i ;
15566
    reg   [11:0] offset ;
15567 35 mihad
    reg          error_monitor_done ;
15568 15 mihad
begin:main
15569
    `ifdef ADDR_TRAN_IMPL
15570
        translation = translate_address ;
15571
    `else
15572
        translation = 0 ;
15573
    `endif
15574
 
15575
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15576
 
15577
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15578
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15579
    if ( translation )
15580
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15581
    else
15582
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15583
 
15584
    if ( !ok )
15585
    begin
15586
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15587
        test_fail("PCI Image Control register could not be written") ;
15588
    end
15589
 
15590
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15591
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15592
    if ( enable_error_report )
15593
    begin
15594
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15595
        if ( !ok )
15596
        begin
15597
            test_fail("PCI Error Control and Status register could not be written") ;
15598
            disable main ;
15599
        end
15600
    end
15601
    else
15602
    begin
15603
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15604
        if ( !ok )
15605
        begin
15606
            test_fail("PCI Error Control and Status register could not be written") ;
15607
            disable main ;
15608
        end
15609
    end
15610
 
15611
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15612
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15613
    if ( enable_error_interrupt )
15614
    begin
15615
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15616
        if ( !ok )
15617
        begin
15618
            test_fail("Interrupt Control register could not be written") ;
15619
            disable main ;
15620
        end
15621
    end
15622
    else
15623
    begin
15624
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15625
        if ( !ok )
15626
        begin
15627
            test_fail("Interrupt Control register could not be written") ;
15628
            disable main ;
15629
        end
15630
    end
15631
 
15632
    pci_address  = Target_Base_Addr_R[image_num] ;
15633
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15634
 
15635
    byte_enables = 4'b1111 ;
15636
 
15637
    for ( i = 0 ; i < 4 ; i = i + 1 )
15638
    begin:loop_1
15639
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15640
        byte_enables[i] = 0 ;
15641
        if ( i > 0 )
15642
            byte_enables[i - 1] = 1 ;
15643
 
15644
        fork
15645
        begin
15646
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15647
            do_pause ( 1 ) ;
15648
        end
15649
        begin
15650
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15651
            if ( wb_ok !== 1 )
15652
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15653
 
15654 35 mihad
            #1 ;
15655
            if ( !error_monitor_done )
15656
                disable monitor_pci_error_2 ;
15657 15 mihad
        end
15658
        begin:monitor_pci_error_2
15659 35 mihad
            error_monitor_done = 0 ;
15660 15 mihad
            pci_ok = 1 ;
15661
            @(error_event_int) ;
15662
            pci_ok = 0 ;
15663
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15664 35 mihad
            error_monitor_done = 1 ;
15665 15 mihad
        end
15666
        join
15667
 
15668
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15669
        `ifdef HOST
15670
 
15671
            repeat ( 4 )
15672
                @( posedge wb_clock ) ;
15673
 
15674
            if ( enable_error_interrupt && enable_error_report )
15675
            begin
15676
                if ( INT_O !== 1 )
15677
                begin
15678
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15679
                end
15680
            end
15681
            else
15682
            begin
15683
                if ( INT_O !== 0 )
15684
                begin
15685
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15686
                end
15687
            end
15688
        `else
15689
            repeat ( 4 )
15690
                @( posedge pci_clock ) ;
15691
 
15692
            if ( enable_error_interrupt && enable_error_report )
15693
            begin
15694
                if ( INTA !== 0 )
15695
                begin
15696
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15697
                end
15698
            end
15699
            else
15700
            begin
15701
                if ( INTA !== 1 )
15702
                begin
15703
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15704
                end
15705
            end
15706
        `endif
15707
 
15708
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15709
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15710
        config_read( offset, 4'hF, read_data ) ;
15711
        ok = 1 ;
15712
        if ( enable_error_report )
15713
        begin
15714
            if ( read_data[8] !== 1 )
15715
            begin
15716
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15717
                ok = 0 ;
15718
            end
15719
 
15720
            if ( read_data[9] !== 0 )
15721
            begin
15722
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15723
                ok = 0 ;
15724
            end
15725
 
15726
            if ( read_data[31:28] !== byte_enables )
15727
            begin
15728
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15729
                ok = 0 ;
15730
            end
15731
 
15732
            if ( read_data[27:24] !== `BC_IO_WRITE )
15733
            begin
15734
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15735
                ok = 0 ;
15736
            end
15737
 
15738
            if ( ok )
15739
                test_ok ;
15740
 
15741
            test_name = "CLEAR ERROR STATUS" ;
15742
            config_write( offset, read_data, 4'hF, ok ) ;
15743
            if ( !ok )
15744
                test_fail("PCI Error Control and Status register could not be written") ;
15745
 
15746
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15747
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15748
            config_read ( offset, 4'hf, read_data ) ;
15749
 
15750
            if ( read_data !== expect_address )
15751
            begin
15752
                test_fail("value in Erroneous Address register was incorrect") ;
15753
                ok = 0 ;
15754
            end
15755
 
15756
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15757
            config_read ( offset, 4'hf, read_data ) ;
15758
 
15759
            if ( read_data !== 32'hAAAA_AAAA )
15760
            begin
15761
                test_fail("value in Erroneous Data register was incorrect") ;
15762
                ok = 0 ;
15763
            end
15764
 
15765
            if ( ok )
15766
                test_ok ;
15767
 
15768
        end
15769
        else
15770
        begin
15771
            if ( read_data[8] !== 0 )
15772
            begin
15773
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15774
                ok = 0 ;
15775
            end
15776
            else
15777
                test_ok ;
15778
        end
15779
 
15780
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15781
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15782
        ok = 1 ;
15783
 
15784
        config_read ( offset, 4'hF, read_data ) ;
15785
        if ( enable_error_report && enable_error_interrupt )
15786
        begin
15787
            if ( read_data[2] !== 1 )
15788
            begin
15789
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15790
                ok = 0 ;
15791
            end
15792
 
15793
            test_name = "CLEARING INTERRUPT STATUS" ;
15794
            config_write( offset, read_data, 4'hF, ok ) ;
15795
            if ( !ok )
15796
                test_fail("Interrupt Status register could not be written") ;
15797
        end
15798
        else
15799
        begin
15800
            if ( read_data[2] !== 0 )
15801
            begin
15802
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15803
                ok = 0 ;
15804
            end
15805
        end
15806
 
15807
        if ( ok )
15808
            test_ok ;
15809
 
15810
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15811
        `ifdef HOST
15812
 
15813
            repeat ( 4 )
15814
                @( posedge wb_clock ) ;
15815
 
15816
            if ( INT_O !== 0 )
15817
            begin
15818
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15819
            end
15820
            else
15821
                test_ok ;
15822
 
15823
        `else
15824
            repeat ( 4 )
15825
                @( posedge pci_clock ) ;
15826
 
15827
            if ( INTA !== 1 )
15828
            begin
15829
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15830
            end
15831
            else
15832
                test_ok ;
15833
 
15834
        `endif
15835
 
15836
        pci_address = pci_address + 1 ;
15837
        expect_address = expect_address + 1 ;
15838
    end
15839
 
15840
end
15841
endtask // test_target_io_err_wr
15842
 
15843
task test_pci_image ;
15844
    input [2:0]  image_num ;
15845
    reg   [11:0] pci_ctrl_offset ;
15846
    reg   [11:0] ctrl_offset ;
15847
    reg   [11:0] ba_offset ;
15848
    reg   [11:0] am_offset ;
15849
    reg   [11:0] ta_offset ;
15850
    reg   [7:0]  cache_lsize ;
15851
    reg          ok ;
15852
    reg          test_io ;
15853
    reg          test_mem ;
15854
begin
15855
    pci_ctrl_offset = 12'h4 ;
15856
    if (image_num === 0)
15857
    begin
15858
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15859
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15860
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15861
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15862
    end
15863
    else if (image_num === 1)
15864
    begin
15865
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15866
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15867
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15868
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15869
    end
15870
    else if (image_num === 2)
15871
    begin
15872
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15873
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15874
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15875
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15876
    end
15877
    else if (image_num === 3)
15878
    begin
15879
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15880
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15881
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15882
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15883
    end
15884
    else if (image_num === 4)
15885
    begin
15886
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15887
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15888
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15889
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15890
    end
15891
    else if (image_num === 5)
15892
    begin
15893
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15894
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15895
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15896
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15897
    end
15898
 
15899
    `ifdef HOST
15900
        test_io  = 1 ;
15901
        test_mem = 1 ;
15902
    `else
15903
        if (image_num == 1)
15904
            test_io = `PCI_BA1_MEM_IO ;
15905
        else if ( image_num == 2 )
15906
            test_io = `PCI_BA2_MEM_IO ;
15907
        else if ( image_num == 3 )
15908
            test_io = `PCI_BA3_MEM_IO ;
15909
        else if ( image_num == 4 )
15910
            test_io = `PCI_BA4_MEM_IO ;
15911
        else if ( image_num == 5 )
15912
            test_io = `PCI_BA5_MEM_IO ;
15913
 
15914
        test_mem = !test_io ;
15915
    `endif
15916
 
15917
    $display(" ");
15918
    $display("########################################################################") ;
15919
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15920
    test_name = "PCI IMAGE SETTINGS" ;
15921
 
15922
    // Set Base Address of IMAGE
15923
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15924
    if ( ok !== 1 )
15925
    begin
15926
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15927
        test_fail("PCI Base Address register could not be written") ;
15928
    end
15929
 
15930
    // Set Address Mask of IMAGE
15931
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15932
    if ( ok !== 1 )
15933
    begin
15934
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15935
        test_fail("PCI Address Mask register could not be written") ;
15936
    end
15937
 
15938
    // Set Translation Address of IMAGE
15939
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15940
    if ( ok !== 1 )
15941
    begin
15942
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15943
        test_fail("PCI Translation Address register could not be written") ;
15944
    end
15945
 
15946
// Following are defines for byte enable signals !
15947
//      Byte Masks
15948
//      `Test_Byte_0                            (4'b1110)
15949
//      `Test_Byte_1                            (4'b1101)
15950
//      `Test_Byte_2                            (4'b1011)
15951
//      `Test_Byte_3                            (4'b0111)
15952
//      `Test_Half_0                            (4'b1100)
15953
//      `Test_Half_1                            (4'b0011)
15954
//      `Test_All_Bytes                         (4'b0000)
15955
 
15956
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15957
    // Set Cache Line Size
15958
    cache_lsize = 8'h4 ;
15959
 
15960
    $display(" ");
15961
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15962
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15963
    if ( ok !== 1 )
15964
    begin
15965
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15966
        test_fail("PCI Device Control and Status register could not be written") ;
15967
    end
15968
 
15969
    if (test_mem)
15970
    begin
15971
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15972
        // Task test_normal_wr_rd has the following parameters:
15973
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15974
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15975
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15976
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15977
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15978
 
15979
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15980
        // Set Cache Line Size
15981
        cache_lsize = 8'h4 ;
15982
 
15983
        $display(" ");
15984
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15985
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15986
        if ( ok !== 1 )
15987
        begin
15988
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15989
            test_fail("Cache Line Size register could not be written" ) ;
15990
        end
15991
 
15992
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15993
        // Task test_normal_wr_rd has the following parameters:
15994
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15995
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15996
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15997
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
15998
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
15999
 
16000
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16001
        // Set Cache Line Size
16002
        cache_lsize = 8'h8 ;
16003
 
16004
        $display(" ");
16005
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16006
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16007
        if ( ok !== 1 )
16008
        begin
16009
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16010
            test_fail("Cache Line Size register could not be written" ) ;
16011
        end
16012
 
16013
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
16014
        // Task test_normal_wr_rd has the following parameters:
16015
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16016
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16017
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16018
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
16019
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16020
 
16021
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
16022
        // Set Cache Line Size
16023
        cache_lsize = 8'h4 ;
16024
 
16025
        $display(" ");
16026
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16027
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16028
        if ( ok !== 1 )
16029
        begin
16030
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16031
            test_fail("Cache Line Size register could not be written" ) ;
16032
        end
16033
 
16034
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
16035
        // Task test_normal_wr_rd has the following parameters:
16036
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
16037
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
16038
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
16039
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
16040
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
16041
 
16042
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16043
        $display(" ");
16044
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
16045
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16046
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16047
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
16048
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
16049
 
16050
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16051
        $display(" ");
16052
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16053
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16054
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16055
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16056
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16057
 
16058
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16059
        $display(" ");
16060
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16061
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16062
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16063
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16064
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16065
 
16066
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16067
        $display(" ");
16068
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16069
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16070
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16071
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16072
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16073
    end
16074
 
16075
    if ( test_io )
16076
    begin
16077
        test_name = "PCI IMAGE SETTINGS" ;
16078
 
16079
        // Set Base Address of IMAGE
16080
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16081
        if ( ok !== 1 )
16082
        begin
16083
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16084
            test_fail("PCI Base Address register could not be written") ;
16085
        end
16086
 
16087
        // Set Address Mask of IMAGE
16088
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16089
        if ( ok !== 1 )
16090
        begin
16091
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16092
            test_fail("PCI Address Mask register could not be written") ;
16093
        end
16094
 
16095
        // Set Translation Address of IMAGE
16096
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16097
        if ( ok !== 1 )
16098
        begin
16099
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16100
            test_fail("PCI Translation Address register could not be written") ;
16101
        end
16102
 
16103
        // Set Cache Line Size
16104
        cache_lsize = 8'h4 ;
16105
 
16106
        $display(" ");
16107
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16108
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16109
        if ( ok !== 1 )
16110
        begin
16111
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16112
            test_fail("Cache Line Size register could not be written" ) ;
16113
        end
16114
 
16115
        test_target_io_wr_rd
16116
        (
16117
            image_num,    // image number
16118
            0,            // test with address translation
16119
            ctrl_offset   // image control register offset
16120
        ) ;
16121
 
16122
        test_target_io_wr_rd
16123
        (
16124
            image_num,    // image number
16125
            1,            // test with address translation
16126
            ctrl_offset   // image control register offset
16127
        ) ;
16128
 
16129
        test_target_io_err_wr
16130
        (
16131
            image_num,      // image number
16132
            0,              // address translation on/off
16133
            ctrl_offset,    // image control register offset
16134
            0,              // enable error reporting
16135
 
16136
        ) ;
16137
 
16138
        test_target_io_err_wr
16139
        (
16140
            image_num,      // image number
16141
            1,              // address translation on/off
16142
            ctrl_offset,    // image control register offset
16143
            0,              // enable error reporting
16144
            1               // enable error interrupts
16145
        ) ;
16146
 
16147
        test_target_io_err_wr
16148
        (
16149
            image_num,      // image number
16150
            0,              // address translation on/off
16151
            ctrl_offset,    // image control register offset
16152
            1,              // enable error reporting
16153
 
16154
        ) ;
16155
 
16156
        test_target_io_err_wr
16157
        (
16158
            image_num,      // image number
16159
            1,              // address translation on/off
16160
            ctrl_offset,    // image control register offset
16161
            1,              // enable error reporting
16162
            1               // enable error interrupts
16163
        ) ;
16164
    end
16165
 
16166
    // Test master abort with NON supported commands
16167
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16168
 
16169
    // disable the image
16170 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16171 15 mihad
end
16172
endtask //test_pci_image
16173
 
16174
task target_fast_back_to_back ;
16175
    reg   [11:0] pci_ctrl_offset ;
16176
    reg   [11:0] ctrl_offset ;
16177
    reg   [11:0] ba_offset ;
16178
    reg   [11:0] am_offset ;
16179
    reg   [11:0] ta_offset ;
16180
    reg   [11:0] cls_offset ;
16181
    reg          do_mem_fb2b ;
16182
    reg          do_io_fb2b ;
16183
    reg          ok ;
16184
begin:main
16185
 
16186
    if ( target_mem_image !== -1 )
16187
    begin
16188
        do_mem_fb2b = 1 ;
16189
 
16190
        if (target_mem_image === 1)
16191
        begin
16192
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16193
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16194
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16195
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16196
        end
16197
        else if (target_mem_image === 2)
16198
        begin
16199
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16200
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16201
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16202
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16203
        end
16204
        else if (target_mem_image === 3)
16205
        begin
16206
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16207
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16208
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16209
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16210
        end
16211
        else if (target_mem_image === 4)
16212
        begin
16213
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16214
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16215
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16216
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16217
        end
16218
        else if (target_mem_image === 5)
16219
        begin
16220
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16221
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16222
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16223
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16224
        end
16225
    end
16226
    else
16227
        do_mem_fb2b = 0 ;
16228
 
16229
    pci_ctrl_offset = 12'h4 ;
16230
    cls_offset      = 12'h00C ;
16231
 
16232
    if ( do_mem_fb2b )
16233
    begin
16234
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16235
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16236
        if ( ok !== 1 )
16237
        begin
16238
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16239
            test_fail("PCI Base Address register could not be written") ;
16240
            disable main ;
16241
        end
16242
 
16243
        // Set Address Mask of IMAGE
16244
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16245
        if ( ok !== 1 )
16246
        begin
16247
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16248
            test_fail("PCI Address Mask register could not be written") ;
16249
            disable main ;
16250
        end
16251
 
16252
        // Set Translation Address of IMAGE
16253
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16254
        if ( ok !== 1 )
16255
        begin
16256
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16257
            test_fail("PCI Translation Address Register could not be written") ;
16258
            disable main ;
16259
        end
16260
 
16261
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16262
        if ( ok !== 1 )
16263
        begin
16264
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16265
            test_fail("PCI Image Control register could not be written") ;
16266
            disable main ;
16267
        end
16268
 
16269
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16270
        if ( ok !== 1 )
16271
        begin
16272
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16273
            test_fail("Cache Line Size register could not be written") ;
16274
            disable main ;
16275
        end
16276
 
16277
        // enable master 1 fast_b2b
16278 45 mihad
        configuration_cycle_write(0,                        // bus number
16279
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16280
                                  0,                        // function number
16281
                                  1,                        // register number
16282
                                  0,                        // type of configuration cycle
16283
                                  4'b1111,                  // byte enables
16284
                                  32'hFFFF_FFFF             // data
16285 15 mihad
                                 ) ;
16286
 
16287
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16288
 
16289
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16290
        fork
16291
        begin
16292
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16293
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16294
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16295
                  0, `Test_One_Zero_Target_WS,
16296
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16297
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16298
 
16299
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16300
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16301
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16302
                  0, `Test_One_Zero_Target_WS,
16303
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16304
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16305
            do_pause(5) ;
16306
 
16307
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16308
        end
16309
        begin:wb_monitor1
16310
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16311
            if ( ok !== 1 )
16312
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16313
 
16314
            disable monitor_error_event1 ;
16315
        end
16316
        begin:monitor_error_event1
16317
            @(error_event_int) ;
16318
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16319
            ok = 0 ;
16320
            disable wb_monitor1 ;
16321
        end
16322
        join
16323
 
16324
        if ( ok )
16325
            test_ok ;
16326
 
16327
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16328
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16329
        fork
16330
        begin
16331
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16332
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16333
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16334
                  0, `Test_One_Zero_Target_WS,
16335
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16336
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16337
 
16338
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16339
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16340
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16341
                  0, `Test_One_Zero_Target_WS,
16342
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16343
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16344
            do_pause(5) ;
16345
 
16346
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16347
 
16348
        end
16349
        begin:wb_monitor2
16350
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16351
            if ( ok !== 1 )
16352
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16353
            else
16354
            begin
16355
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16356
                if ( ok !== 1 )
16357
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16358
            end
16359
 
16360
            disable monitor_error_event2 ;
16361
        end
16362
        begin:monitor_error_event2
16363
            @(error_event_int) ;
16364
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16365
            ok = 0 ;
16366
            disable wb_monitor2 ;
16367
        end
16368
        join
16369
 
16370
        if ( ok )
16371
            test_ok ;
16372
 
16373
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16374
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16375
        fork
16376
        begin
16377
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16378
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16379
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16380
                  0, `Test_One_Zero_Target_WS,
16381
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16382
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16383
 
16384
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16385
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16386
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16387
                  0, `Test_One_Zero_Target_WS,
16388
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16389
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16390
            do_pause(5) ;
16391
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16392
 
16393
        end
16394
        begin:wb_monitor3
16395
            fork
16396
            begin
16397
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16398
                if ( ok !== 1 )
16399
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16400
            end
16401
            begin
16402
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16403
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16404
                if ( ok !== 1 )
16405
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16406
            end
16407
            join
16408
 
16409
            if ( ok )
16410
            begin
16411
                fork
16412
                begin
16413
                    do_pause(3) ;
16414
 
16415
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16416
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16417
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16418
                        0, `Test_One_Zero_Target_WS,
16419
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16420
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16421
 
16422
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16423
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16424
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16425
                            0, `Test_One_Zero_Target_WS,
16426
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16427
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16428
 
16429
                    do_pause(1) ;
16430
                end
16431
                begin
16432
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16433
                    if ( ok !== 1 )
16434
                    begin
16435
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16436
                        disable monitor_error_event3 ;
16437
                    end
16438
                    else
16439
                    begin
16440
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16441
                        if ( ok !== 1 )
16442
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16443
                    end
16444
                end
16445 26 mihad
                begin
16446
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16447
                        if ( ok !== 1 )
16448
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16449
                end
16450 15 mihad
                join
16451
            end
16452
            disable monitor_error_event3 ;
16453
        end
16454
        begin:monitor_error_event3
16455
            @(error_event_int) ;
16456
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16457
            ok = 0 ;
16458
            disable wb_monitor3 ;
16459
        end
16460
        join
16461
 
16462
        if ( ok )
16463
            test_ok ;
16464
 
16465
        test_name = "DISABLING MEM IMAGE" ;
16466 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16467 15 mihad
        if ( ok !== 1 )
16468
        begin
16469
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16470
            test_fail("PCI Address Mask register could not be written") ;
16471
            disable main ;
16472
        end
16473
    end
16474
 
16475
    if ( target_io_image !== -1 )
16476
    begin
16477
        do_io_fb2b = 1 ;
16478
 
16479
        if (target_io_image === 1)
16480
        begin
16481
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16482
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16483
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16484
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16485
        end
16486
        else if (target_io_image === 2)
16487
        begin
16488
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16489
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16490
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16491
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16492
        end
16493
        else if (target_io_image === 3)
16494
        begin
16495
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16496
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16497
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16498
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16499
        end
16500
        else if (target_io_image === 4)
16501
        begin
16502
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16503
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16504
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16505
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16506
        end
16507
        else if (target_io_image === 5)
16508
        begin
16509
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16510
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16511
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16512
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16513
        end
16514
    end
16515
    else
16516
        do_io_fb2b = 0 ;
16517
 
16518
    if ( do_io_fb2b )
16519
    begin
16520
 
16521
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16522
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16523
        if ( ok !== 1 )
16524
        begin
16525
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16526
            test_fail("PCI Base Address register could not be written") ;
16527
            disable main ;
16528
        end
16529
 
16530
        // Set Address Mask of IMAGE
16531
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16532
        if ( ok !== 1 )
16533
        begin
16534
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16535
            test_fail("PCI Address Mask register could not be written") ;
16536
            disable main ;
16537
        end
16538
 
16539
        // Set Translation Address of IMAGE
16540
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16541
        if ( ok !== 1 )
16542
        begin
16543
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16544
            test_fail("PCI Translation Address Register could not be written") ;
16545
            disable main ;
16546
        end
16547
 
16548
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16549
        if ( ok !== 1 )
16550
        begin
16551
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16552
            test_fail("PCI Image Control register could not be written") ;
16553
            disable main ;
16554
        end
16555
 
16556
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16557
        if ( ok !== 1 )
16558
        begin
16559
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16560
            test_fail("Cache Line Size register could not be written") ;
16561
            disable main ;
16562
        end
16563
 
16564
        // enable master 1 fast_b2b
16565 45 mihad
        configuration_cycle_write(0,                        // bus number
16566
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16567
                                  0,                        // function number
16568
                                  1,                        // register number
16569
                                  0,                        // type of configuration cycle
16570
                                  4'b1111,                  // byte enables
16571
                                  32'hFFFF_FFFF             // data
16572 15 mihad
                                 ) ;
16573
 
16574
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16575
 
16576
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16577
        fork
16578
        begin
16579
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16580
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16581
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16582
                  0, `Test_One_Zero_Target_WS,
16583
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16584
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16585
 
16586
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16587
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16588
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16589
                  0, `Test_One_Zero_Target_WS,
16590
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16591
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16592
            do_pause(5) ;
16593
 
16594
        end
16595
        begin:wb_monitor4
16596
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16597
            if ( ok !== 1 )
16598
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16599
 
16600
            if ( ok )
16601
            begin
16602
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16603
                if ( ok !== 1 )
16604
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16605
            end
16606
 
16607
            disable monitor_error_event4 ;
16608
        end
16609
        begin:monitor_error_event4
16610
            @(error_event_int) ;
16611
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16612
            ok = 0 ;
16613
            disable wb_monitor4 ;
16614
        end
16615
        join
16616
 
16617
        if ( ok )
16618
            test_ok ;
16619
 
16620
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16621
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16622
        fork
16623
        begin
16624
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16625
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16626
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16627
                  0, `Test_One_Zero_Target_WS,
16628
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16629
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16630
 
16631
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16632
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16633
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16634
                  0, `Test_One_Zero_Target_WS,
16635
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16636
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16637
            do_pause(5) ;
16638
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16639
        end
16640
        begin:wb_monitor5
16641
            fork
16642
            begin
16643
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16644
                if ( ok !== 1 )
16645
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16646
            end
16647
            begin
16648
                wb_transaction_stop( 1 ) ;
16649
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16650
                if ( ok !== 1 )
16651
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16652
            end
16653
            join
16654
 
16655
            if ( ok )
16656
            begin
16657
                fork
16658
                begin
16659
                    do_pause(3) ;
16660
 
16661
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16662
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16663
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16664
                            0, `Test_One_Zero_Target_WS,
16665
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16666
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16667
 
16668
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16669
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16670
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16671
                            0, `Test_One_Zero_Target_WS,
16672
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16673
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16674
 
16675
                    do_pause(1) ;
16676
                end
16677
                begin
16678
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16679
                    if ( ok !== 1 )
16680
                    begin
16681
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16682
                        disable monitor_error_event5 ;
16683
                    end
16684
                    else
16685
                    begin
16686
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16687
                        if ( ok !== 1 )
16688
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16689
                    end
16690
                end
16691
                join
16692
            end
16693
            disable monitor_error_event5 ;
16694
        end
16695
        begin:monitor_error_event5
16696
            @(error_event_int) ;
16697
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16698
            ok = 0 ;
16699
            disable wb_monitor5 ;
16700
        end
16701
        join
16702
 
16703
        if ( ok )
16704
            test_ok ;
16705
 
16706
        test_name = "DISABLING IO IMAGE" ;
16707 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16708 15 mihad
        if ( ok !== 1 )
16709
        begin
16710
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16711
            test_fail("PCI Address Mask register could not be written") ;
16712
            disable main ;
16713
        end
16714
    end
16715
 
16716
end
16717
endtask //target_fast_back_to_back
16718
 
16719
task target_disconnects ;
16720
    reg   [11:0] pci_ctrl_offset ;
16721
    reg   [11:0] ctrl_offset ;
16722
    reg   [11:0] ba_offset ;
16723
    reg   [11:0] am_offset ;
16724
    reg   [11:0] ta_offset ;
16725
    reg   [11:0] cls_offset ;
16726
    reg          pci_ok ;
16727
    reg          wb_ok ;
16728
    reg          ok ;
16729
    reg   [31:0] pci_address ;
16730
    reg   [31:0] data ;
16731
    reg   [3:0]  byte_enables ;
16732
    reg   [9:0]  expect_length ;
16733
 
16734
    reg          do_mem_disconnects ;
16735
    reg          do_io_disconnects ;
16736 35 mihad
    reg          error_monitor_done ;
16737 15 mihad
begin:main
16738
    if ( target_mem_image !== -1 )
16739
    begin
16740
        do_mem_disconnects = 1 ;
16741
 
16742
        if (target_mem_image === 1)
16743
        begin
16744
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16745
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16746
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16747
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16748
        end
16749
        else if (target_mem_image === 2)
16750
        begin
16751
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16752
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16753
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16754
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16755
        end
16756
        else if (target_mem_image === 3)
16757
        begin
16758
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16759
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16760
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16761
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16762
        end
16763
        else if (target_mem_image === 4)
16764
        begin
16765
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16766
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16767
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16768
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16769
        end
16770
        else if (target_mem_image === 5)
16771
        begin
16772
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16773
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16774
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16775
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16776
        end
16777
    end
16778
    else
16779
        do_mem_disconnects = 0 ;
16780
 
16781
    pci_ctrl_offset = 12'h4 ;
16782
    cls_offset = 12'h00C ;
16783
 
16784
    master1_check_received_data = 0 ;
16785
    master2_check_received_data = 0 ;
16786
 
16787
    `ifdef HOST
16788
        `ifdef NO_CNF_IMAGE
16789
        `else
16790
            `define TEST_BURST_CONFIG_READ
16791
        `endif
16792
    `else
16793
        `define TEST_BURST_CONFIG_READ
16794
        `define TEST_BURST_CONFIG_WRITE
16795
    `endif
16796
 
16797
    `ifdef TEST_BURST_CONFIG_WRITE
16798
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16799
 
16800
        data = 32'h0000_08_08 ;
16801
 
16802 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16803 15 mihad
        byte_enables = 4'b0000 ;
16804
 
16805
        fork
16806
        begin
16807
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16808
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16809
                    byte_enables,
16810
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16811
                    8'h0_0, `Test_One_Zero_Target_WS,
16812
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16813
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16814
 
16815
            data = 32'h0000_04_04 ;
16816
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16817
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16818
                    byte_enables,
16819
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16820
                    8'h0_0, `Test_One_Zero_Target_WS,
16821
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16822
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16823
            do_pause( 1 ) ;
16824
            while ( FRAME !== 1 || IRDY !== 1 )
16825
                @(posedge pci_clock) ;
16826
 
16827 35 mihad
            #1 ;
16828
            if ( !error_monitor_done )
16829
                disable monitor_error_event1 ;
16830 15 mihad
        end
16831
        begin:monitor_error_event1
16832 35 mihad
            error_monitor_done = 0 ;
16833 15 mihad
            ok = 1 ;
16834
            @(error_event_int) ;
16835
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16836
            ok = 0 ;
16837 35 mihad
            error_monitor_done = 1 ;
16838 15 mihad
        end
16839
        join
16840
 
16841
        config_read(pci_address, 4'hF, data) ;
16842
        if ( data [15:0] !== 16'h04_04 )
16843
        begin
16844
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16845
        end
16846
        else if ( ok )
16847
            test_ok ;
16848
 
16849 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16850
 
16851
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16852 15 mihad
        data         = 32'h0000_0808 ;
16853
        byte_enables = 4'h0 ;
16854
        fork
16855
        begin
16856
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16857
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16858
                    byte_enables,
16859
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16860
                    8'h0_0, `Test_One_Zero_Target_WS,
16861
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16862
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16863
 
16864
            data = 32'h0000_04_04 ;
16865
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16866
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16867
                    byte_enables,
16868
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16869
                    8'h0_0, `Test_One_Zero_Target_WS,
16870
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16871
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16872
 
16873
            do_pause( 1 ) ;
16874
            while ( FRAME !== 1 || IRDY !== 1 )
16875
                @(posedge pci_clock) ;
16876
 
16877 35 mihad
            #1 ;
16878
            if ( !error_monitor_done )
16879
                disable monitor_error_event2 ;
16880 15 mihad
        end
16881
        begin:monitor_error_event2
16882 35 mihad
            error_monitor_done = 0 ;
16883 15 mihad
            ok = 1 ;
16884
            @(error_event_int) ;
16885
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16886
            ok = 0 ;
16887 35 mihad
            error_monitor_done = 1 ;
16888 15 mihad
        end
16889
        join
16890
 
16891
        config_read(pci_address, 4'hF, data) ;
16892
        if ( data [15:0] !== 16'h04_04 )
16893
        begin
16894
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16895
        end
16896
        else if ( ok )
16897
            test_ok ;
16898
    `endif
16899
 
16900
    `ifdef TEST_BURST_CONFIG_READ
16901
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16902
 
16903
        data = 32'h0000_04_04 ;
16904
 
16905 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16906 15 mihad
        byte_enables = 4'b0000 ;
16907
 
16908
        fork
16909
        begin
16910
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16911
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16912
                    byte_enables,
16913
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16914
                    8'h0_0, `Test_One_Zero_Target_WS,
16915
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16916
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16917
            do_pause( 1 ) ;
16918
 
16919
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16920
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16921
                    byte_enables,
16922
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16923
                    8'h0_0, `Test_One_Zero_Target_WS,
16924
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16925
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16926
            do_pause( 1 ) ;
16927
 
16928
            while ( FRAME !== 1 || IRDY !== 1 )
16929
                @(posedge pci_clock) ;
16930
 
16931 35 mihad
            if ( !error_monitor_done )
16932
                disable monitor_error_event3 ;
16933 15 mihad
        end
16934
        begin:monitor_error_event3
16935 35 mihad
            error_monitor_done = 0 ;
16936 15 mihad
            ok = 1 ;
16937
            @(error_event_int) ;
16938
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16939
            ok = 0 ;
16940 35 mihad
            error_monitor_done = 1 ;
16941 15 mihad
        end
16942
        join
16943
 
16944
        if ( ok )
16945
            test_ok ;
16946
 
16947 45 mihad
 
16948
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16949
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16950 15 mihad
        fork
16951
        begin
16952
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16953
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16954
                    byte_enables,
16955
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16956
                    8'h0_0, `Test_One_Zero_Target_WS,
16957
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16958
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16959
            do_pause( 1 ) ;
16960
 
16961
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16962
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16963
                    byte_enables,
16964
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16965
                    8'h0_0, `Test_One_Zero_Target_WS,
16966
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16967
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16968
            do_pause( 1 ) ;
16969
 
16970
            while ( FRAME !== 1 || IRDY !== 1 )
16971
                @(posedge pci_clock) ;
16972
 
16973 35 mihad
            #1 ;
16974
            if ( !error_monitor_done )
16975
                disable monitor_error_event4 ;
16976 15 mihad
        end
16977
        begin:monitor_error_event4
16978 35 mihad
            error_monitor_done = 0 ;
16979 15 mihad
            ok = 1 ;
16980
            @(error_event_int) ;
16981
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16982
            ok = 0 ;
16983 35 mihad
            error_monitor_done = 1 ;
16984 15 mihad
        end
16985
        join
16986
 
16987
        if ( ok )
16988
            test_ok ;
16989
    `endif
16990
 
16991
    `ifdef TEST_BURST_CONFIG_READ
16992
        `undef TEST_BURST_CONFIG_READ
16993
    `endif
16994
 
16995
    `ifdef TEST_BURST_CONFIG_WRITE
16996
        `undef TEST_BURST_CONFIG_WRITE
16997
    `endif
16998
 
16999
    master1_check_received_data = 1 ;
17000
    master2_check_received_data = 1 ;
17001
 
17002
    if ( do_mem_disconnects )
17003
    begin
17004
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17005
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
17006
        if ( ok !== 1 )
17007
        begin
17008
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17009
            test_fail("PCI Base Address register could not be written") ;
17010
            disable main ;
17011
        end
17012
 
17013
        // Set Address Mask of IMAGE
17014
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
17015
        if ( ok !== 1 )
17016
        begin
17017
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17018
            test_fail("PCI Address Mask register could not be written") ;
17019
            disable main ;
17020
        end
17021
 
17022
        // Set Translation Address of IMAGE
17023
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
17024
        if ( ok !== 1 )
17025
        begin
17026
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17027
            test_fail("PCI Translation Address Register could not be written") ;
17028
            disable main ;
17029
        end
17030
 
17031
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17032
        if ( ok !== 1 )
17033
        begin
17034
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17035
            test_fail("PCI Image Control register could not be written") ;
17036
            disable main ;
17037
        end
17038
 
17039
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17040
        if ( ok !== 1 )
17041
        begin
17042
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17043
            test_fail("Cache Line Size register could not be written") ;
17044
            disable main ;
17045
        end
17046
 
17047
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17048
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17049
        data = 32'hAAAA_AAAA ;
17050
        byte_enables = 4'h0 ;
17051
        expect_length = `PCIW_DEPTH - 2 ;
17052
 
17053
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17054
        fork
17055
        begin
17056
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17057
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17058
                        byte_enables,
17059
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
17060
                        8'h0_0, `Test_One_Zero_Target_WS,
17061
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17062
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17063
            do_pause( 3 ) ;
17064
 
17065
            while ( FRAME !== 1 || IRDY !== 1 )
17066
                @(posedge pci_clock) ;
17067
 
17068 35 mihad
            #1 ;
17069
            if ( !error_monitor_done )
17070
                disable monitor_error_event5 ;
17071 15 mihad
        end
17072
        begin:monitor_error_event5
17073 35 mihad
            error_monitor_done = 0 ;
17074 15 mihad
            pci_ok = 1 ;
17075
            @(error_event_int) ;
17076
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17077
            pci_ok = 0 ;
17078 35 mihad
            error_monitor_done = 1 ;
17079 15 mihad
        end
17080
        begin
17081
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17082
            if ( wb_ok !== 1 )
17083
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17084
        end
17085
        join
17086
 
17087
        if ( wb_ok && pci_ok )
17088
            test_ok ;
17089
 
17090
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17091
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17092
        data = 32'hAAAA_AAAA ;
17093
        byte_enables = 4'h0 ;
17094
        expect_length = `PCIW_DEPTH - 2 ;
17095
 
17096
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17097
        fork
17098
        begin
17099
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17100
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17101
                        byte_enables,
17102
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
17103
                        8'h0_0, `Test_One_Zero_Target_WS,
17104
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17105
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17106
            do_pause( 3 ) ;
17107
 
17108
            while ( FRAME !== 1 || IRDY !== 1 )
17109
                @(posedge pci_clock) ;
17110
 
17111 35 mihad
            #1 ;
17112
            if ( !error_monitor_done )
17113
                disable monitor_error_event6 ;
17114 15 mihad
        end
17115
        begin:monitor_error_event6
17116 35 mihad
            error_monitor_done = 0 ;
17117 15 mihad
            pci_ok = 1 ;
17118
            @(error_event_int) ;
17119
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17120
            pci_ok = 0 ;
17121 35 mihad
            error_monitor_done = 1 ;
17122 15 mihad
        end
17123
        begin
17124
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17125
            if ( wb_ok !== 1 )
17126
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17127
        end
17128
        join
17129
 
17130
        if ( wb_ok && pci_ok )
17131
            test_ok ;
17132
 
17133
        master1_check_received_data = 1 ;
17134
//        master2_check_received_data = 0 ;
17135
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17136
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17137
        data = 32'hAAAA_AAAA ;
17138
        byte_enables = 4'h0 ;
17139
        expect_length = 4 ;
17140
 
17141
        fork
17142
        begin
17143
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17144
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17145
                        byte_enables,
17146
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17147
                        8'h0_0, `Test_One_Zero_Target_WS,
17148
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17149
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17150
            do_pause( 1 ) ;
17151
 
17152
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17153
            if ( wb_ok !== 1 )
17154
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17155
 
17156
            do_pause(2) ;
17157
 
17158
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17159
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17160
                        byte_enables,
17161
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17162
                        8'h0_0, `Test_One_Zero_Target_WS,
17163
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17164
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17165
            do_pause( 3 ) ;
17166
 
17167
            while ( FRAME !== 1 || IRDY !== 1 )
17168
                @(posedge pci_clock) ;
17169
 
17170 35 mihad
            #1 ;
17171
            if ( !error_monitor_done )
17172
                disable monitor_error_event7 ;
17173 15 mihad
        end
17174
        begin:monitor_error_event7
17175 35 mihad
            error_monitor_done = 0 ;
17176 15 mihad
            pci_ok = 1 ;
17177
            @(error_event_int) ;
17178
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17179
            pci_ok = 0 ;
17180 35 mihad
            error_monitor_done = 1 ;
17181 15 mihad
        end
17182
        join
17183
 
17184
        if ( wb_ok && pci_ok )
17185
            test_ok ;
17186
 
17187
        master1_check_received_data = 1 ;
17188
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17189
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17190
        data = 32'hAAAA_AAAA ;
17191
        byte_enables = 4'h0 ;
17192
        expect_length = 4 ;
17193
 
17194
        fork
17195
        begin
17196
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17197
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17198
                        byte_enables,
17199
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17200
                        8'h0_0, `Test_One_Zero_Target_WS,
17201
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17202
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17203
            do_pause( 1 ) ;
17204
 
17205
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17206
            if ( wb_ok !== 1 )
17207
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17208
 
17209
            do_pause(2) ;
17210
 
17211
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17212
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17213
                        byte_enables,
17214
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17215
                        8'h0_0, `Test_One_Zero_Target_WS,
17216
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17217
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17218
            do_pause( 3 ) ;
17219
 
17220
            while ( FRAME !== 1 || IRDY !== 1 )
17221
                @(posedge pci_clock) ;
17222
 
17223 35 mihad
            #1 ;
17224
            if ( !error_monitor_done )
17225
                disable monitor_error_event8 ;
17226 15 mihad
        end
17227
        begin:monitor_error_event8
17228 35 mihad
            error_monitor_done = 0 ;
17229 15 mihad
            pci_ok = 1 ;
17230
            @(error_event_int) ;
17231
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17232
            pci_ok = 0 ;
17233 35 mihad
            error_monitor_done = 1 ;
17234 15 mihad
        end
17235
        join
17236
 
17237
        if ( wb_ok && pci_ok )
17238
            test_ok ;
17239
 
17240
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17241
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17242
        data = 32'hDEAF_BEAF ;
17243
        byte_enables = 4'h0 ;
17244
        expect_length = 1 ;
17245
 
17246
        fork
17247
        begin
17248
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17249
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17250
                        byte_enables,
17251
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17252
                        8'h0_0, `Test_One_Zero_Target_WS,
17253
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17254
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17255
            do_pause( 3 ) ;
17256
 
17257
            while ( FRAME !== 1 || IRDY !== 1 )
17258
                @(posedge pci_clock) ;
17259
 
17260 35 mihad
            #1 ;
17261
            if ( !error_monitor_done )
17262
                disable monitor_error_event9 ;
17263 15 mihad
        end
17264
        begin:monitor_error_event9
17265 35 mihad
            error_monitor_done = 0 ;
17266 15 mihad
            pci_ok = 1 ;
17267
            @(error_event_int) ;
17268
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17269
            pci_ok = 0 ;
17270 35 mihad
            error_monitor_done = 1 ;
17271 15 mihad
        end
17272
        begin
17273
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17274
            if ( wb_ok !== 1 )
17275
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17276
        end
17277
        join
17278
 
17279
        if ( wb_ok && pci_ok )
17280
            test_ok ;
17281
 
17282
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17283
        data = 32'hDEAD_BEAF ;
17284
        byte_enables = 4'h0 ;
17285
        expect_length = 1 ;
17286
 
17287
        fork
17288
        begin
17289
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17290
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17291
                        byte_enables,
17292
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17293
                        8'h0_0, `Test_One_Zero_Target_WS,
17294
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17295
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17296
            do_pause( 3 ) ;
17297
 
17298
            while ( FRAME !== 1 || IRDY !== 1 )
17299
                @(posedge pci_clock) ;
17300
 
17301 35 mihad
            #1 ;
17302
            if ( !error_monitor_done )
17303
                disable monitor_error_event10 ;
17304 15 mihad
        end
17305
        begin:monitor_error_event10
17306 35 mihad
            error_monitor_done = 0 ;
17307 15 mihad
            pci_ok = 1 ;
17308
            @(error_event_int) ;
17309
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17310
            pci_ok = 0 ;
17311 35 mihad
            error_monitor_done = 1 ;
17312 15 mihad
        end
17313
        begin
17314
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17315
            if ( wb_ok !== 1 )
17316
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17317
        end
17318
        join
17319
 
17320
        if ( wb_ok && pci_ok )
17321
            test_ok ;
17322
 
17323
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17324
        data = 32'hAAAA_AAAA ;
17325
        byte_enables = 4'h0 ;
17326
        expect_length = 1 ;
17327
 
17328
        fork
17329
        begin
17330
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17331
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17332
                        byte_enables,
17333
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17334
                        8'h0_0, `Test_One_Zero_Target_WS,
17335
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17336
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17337
            do_pause( 3 ) ;
17338
 
17339
            while ( FRAME !== 1 || IRDY !== 1 )
17340
                @(posedge pci_clock) ;
17341
 
17342 35 mihad
            #1 ;
17343
            if ( !error_monitor_done )
17344
                disable monitor_error_event11 ;
17345 15 mihad
        end
17346
        begin:monitor_error_event11
17347 35 mihad
            error_monitor_done = 0 ;
17348 15 mihad
            pci_ok = 1 ;
17349
            @(error_event_int) ;
17350
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17351
            pci_ok = 0 ;
17352 35 mihad
            error_monitor_done = 1 ;
17353 15 mihad
        end
17354
        begin
17355
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17356
            if ( wb_ok !== 1 )
17357
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17358
        end
17359
        join
17360
 
17361
        if ( wb_ok && pci_ok )
17362
            test_ok ;
17363
 
17364
        master1_check_received_data = 1 ;
17365
 
17366
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17367
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17368
        data = 32'hDEAF_BEAF ;
17369
        byte_enables = 4'h0 ;
17370
        expect_length = 1 ;
17371
 
17372
        fork
17373
        begin
17374
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17375
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17376
                        byte_enables,
17377
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17378
                        8'h0_0, `Test_One_Zero_Target_WS,
17379
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17380
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17381
            do_pause( 1 ) ;
17382
 
17383
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17384
            if ( wb_ok !== 1 )
17385
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17386
 
17387
            do_pause(3) ;
17388
 
17389
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17390
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17391
                        byte_enables,
17392
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17393
                        8'h0_0, `Test_One_Zero_Target_WS,
17394
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17395
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17396
            do_pause( 3 ) ;
17397
 
17398
            while ( FRAME !== 1 || IRDY !== 1 )
17399
                @(posedge pci_clock) ;
17400
 
17401 35 mihad
            #1 ;
17402
            if ( !error_monitor_done )
17403
                disable monitor_error_event12 ;
17404 15 mihad
        end
17405
        begin:monitor_error_event12
17406 35 mihad
            error_monitor_done = 0 ;
17407 15 mihad
            pci_ok = 1 ;
17408
            @(error_event_int) ;
17409
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17410
            pci_ok = 0 ;
17411 35 mihad
            error_monitor_done = 1 ;
17412 15 mihad
        end
17413
        join
17414
 
17415
        if ( wb_ok && pci_ok )
17416
            test_ok ;
17417
 
17418
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17419
        data = 32'hDEAD_BEAF ;
17420
        byte_enables = 4'h0 ;
17421
        expect_length = 1 ;
17422
 
17423
        fork
17424
        begin
17425
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17426
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17427
                        byte_enables,
17428
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17429
                        8'h0_0, `Test_One_Zero_Target_WS,
17430
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17431
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17432
            do_pause( 1 ) ;
17433
 
17434
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17435
            if ( wb_ok !== 1 )
17436
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17437
 
17438
            do_pause(3) ;
17439
 
17440
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17441
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17442
                        byte_enables,
17443
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17444
                        8'h0_0, `Test_One_Zero_Target_WS,
17445
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17446
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17447
            do_pause( 3 ) ;
17448
 
17449
            while ( FRAME !== 1 || IRDY !== 1 )
17450
                @(posedge pci_clock) ;
17451
 
17452 35 mihad
            #1 ;
17453
            if ( !error_monitor_done )
17454
                disable monitor_error_event13 ;
17455 15 mihad
        end
17456
        begin:monitor_error_event13
17457 35 mihad
            error_monitor_done = 0 ;
17458 15 mihad
            pci_ok = 1 ;
17459
            @(error_event_int) ;
17460
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17461
            pci_ok = 0 ;
17462 35 mihad
            error_monitor_done = 1 ;
17463 15 mihad
        end
17464
        join
17465
 
17466
        if ( wb_ok && pci_ok )
17467
            test_ok ;
17468
 
17469
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17470
        data = 32'hAAAA_AAAA ;
17471
        byte_enables = 4'h0 ;
17472
        expect_length = 1 ;
17473
 
17474
        fork
17475
        begin
17476
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17477
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17478
                        byte_enables,
17479
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17480
                        8'h0_0, `Test_One_Zero_Target_WS,
17481
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17482
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17483
            do_pause( 1 ) ;
17484
 
17485
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17486
            if ( wb_ok !== 1 )
17487
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17488
 
17489
            do_pause(3) ;
17490
 
17491
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17492
                        `BC_MEM_READ_MUL, data[PCI_BUS_DATA_RANGE:0],
17493
                        byte_enables,
17494
                        3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17495
                        8'h0_0, `Test_One_Zero_Target_WS,
17496
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17497
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17498
            do_pause( 3 ) ;
17499
 
17500
            while ( FRAME !== 1 || IRDY !== 1 )
17501
                @(posedge pci_clock) ;
17502
 
17503 35 mihad
            #1 ;
17504
            if ( !error_monitor_done )
17505
                disable monitor_error_event14 ;
17506 15 mihad
        end
17507
        begin:monitor_error_event14
17508 35 mihad
            error_monitor_done = 0 ;
17509 15 mihad
            pci_ok = 1 ;
17510
            @(error_event_int) ;
17511
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17512
            pci_ok = 0 ;
17513 35 mihad
            error_monitor_done = 1 ;
17514 15 mihad
        end
17515
        join
17516
 
17517
        if ( wb_ok && pci_ok )
17518
            test_ok ;
17519
 
17520
        // disable the image
17521
        test_name = "DISABLING MEMORY IMAGE" ;
17522 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17523 15 mihad
        if ( ok !== 1 )
17524
        begin
17525
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17526
            test_fail("PCI Address Mask register could not be written") ;
17527
            disable main ;
17528
        end
17529
    end
17530
//*
17531
    if ( target_io_image !== -1 )
17532
    begin
17533
        do_io_disconnects = 1 ;
17534
 
17535
        if (target_io_image === 1)
17536
        begin
17537
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17538
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17539
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17540
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17541
        end
17542
        else if (target_io_image === 2)
17543
        begin
17544
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17545
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17546
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17547
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17548
        end
17549
        else if (target_io_image === 3)
17550
        begin
17551
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17552
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17553
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17554
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17555
        end
17556
        else if (target_io_image === 4)
17557
        begin
17558
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17559
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17560
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17561
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17562
        end
17563
        else if (target_io_image === 5)
17564
        begin
17565
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17566
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17567
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17568
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17569
        end
17570
    end
17571
    else
17572
        do_io_disconnects = 0 ;
17573
 
17574
    if ( do_io_disconnects )
17575
    begin
17576
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17577
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17578
        if ( ok !== 1 )
17579
        begin
17580
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17581
            test_fail("PCI Base Address register could not be written") ;
17582
            disable main ;
17583
        end
17584
 
17585
        // Set Address Mask of IMAGE
17586
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17587
        if ( ok !== 1 )
17588
        begin
17589
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17590
            test_fail("PCI Address Mask register could not be written") ;
17591
            disable main ;
17592
        end
17593
 
17594
        // Set Translation Address of IMAGE
17595
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17596
        if ( ok !== 1 )
17597
        begin
17598
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17599
            test_fail("PCI Translation Address Register could not be written") ;
17600
            disable main ;
17601
        end
17602
 
17603
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17604
        if ( ok !== 1 )
17605
        begin
17606
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17607
            test_fail("PCI Image Control register could not be written") ;
17608
            disable main ;
17609
        end
17610
 
17611
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17612
        if ( ok !== 1 )
17613
        begin
17614
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17615
            test_fail("Cache Line Size register could not be written") ;
17616
            disable main ;
17617
        end
17618
 
17619
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17620
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17621
        data = 32'h5555_5555 ;
17622
        byte_enables = 4'h0 ;
17623
        expect_length = 1 ;
17624
 
17625
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17626
 
17627
        fork
17628
        begin
17629
            PCIU_IO_WRITE
17630
            (
17631
                `Test_Master_1,             // which master
17632
                pci_address,                // to what address
17633
                data,                       // data
17634
                byte_enables,               // byte enable
17635
                expect_length + 1,          // length to request
17636
                `Test_Target_Retry_On       // expected target termination
17637
            ) ;
17638
 
17639
            do_pause( 3 ) ;
17640
 
17641
            while ( FRAME !== 1 || IRDY !== 1 )
17642
                @(posedge pci_clock) ;
17643
 
17644 35 mihad
            #1 ;
17645
            if ( !error_monitor_done )
17646
                disable monitor_error_event15 ;
17647 15 mihad
        end
17648
        begin:monitor_error_event15
17649 35 mihad
            error_monitor_done = 0 ;
17650 15 mihad
            pci_ok = 1 ;
17651
            @(error_event_int) ;
17652
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17653
            pci_ok = 0 ;
17654 35 mihad
            error_monitor_done = 1 ;
17655 15 mihad
        end
17656
        begin
17657
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17658
            if ( wb_ok !== 1 )
17659
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17660
        end
17661
        join
17662
 
17663
        if ( wb_ok && pci_ok )
17664
            test_ok ;
17665
 
17666
        data = 32'hAAAA_AAAA ;
17667
        fork
17668
        begin
17669
            PCIU_IO_WRITE
17670
            (
17671
                `Test_Master_1,             // which master
17672
                pci_address,                // to what address
17673
                data,                       // data
17674
                byte_enables,               // byte enable
17675
                expect_length + 2,          // length to request
17676
                `Test_Target_Retry_Before   // expected target termination
17677
            ) ;
17678
 
17679
            do_pause( 3 ) ;
17680
 
17681
            while ( FRAME !== 1 || IRDY !== 1 )
17682
                @(posedge pci_clock) ;
17683
 
17684 35 mihad
            #1 ;
17685
            if ( !error_monitor_done )
17686
                disable monitor_error_event16 ;
17687 15 mihad
        end
17688
        begin:monitor_error_event16
17689 35 mihad
            error_monitor_done = 0 ;
17690 15 mihad
            pci_ok = 1 ;
17691
            @(error_event_int) ;
17692
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17693
            pci_ok = 0 ;
17694 35 mihad
            error_monitor_done = 1 ;
17695 15 mihad
        end
17696
        begin
17697
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17698
            if ( wb_ok !== 1 )
17699
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17700
        end
17701
        join
17702
 
17703
        if ( wb_ok && pci_ok )
17704
            test_ok ;
17705
 
17706
        master2_check_received_data = 1 ;
17707
 
17708
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17709
 
17710
        fork
17711
        begin
17712
 
17713
             PCIU_IO_READ
17714
             (
17715
                `Test_Master_2,
17716
                pci_address[PCI_BUS_DATA_RANGE:0],
17717
                data,
17718
                byte_enables,
17719
                2,
17720
                `Test_Target_Retry_Before
17721
             );
17722
 
17723
            do_pause( 1 ) ;
17724
 
17725
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17726
            if ( wb_ok !== 1 )
17727
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17728
 
17729
            do_pause(3) ;
17730
 
17731
            PCIU_IO_READ
17732
             (
17733
                `Test_Master_2,
17734
                pci_address[PCI_BUS_DATA_RANGE:0],
17735
                data,
17736
                byte_enables,
17737
                expect_length + 1,
17738
                `Test_Target_Retry_On
17739
             );
17740
 
17741
            do_pause( 3 ) ;
17742
 
17743
            while ( FRAME !== 1 || IRDY !== 1 )
17744
                @(posedge pci_clock) ;
17745
 
17746 35 mihad
            #1 ;
17747
            if ( !error_monitor_done )
17748
                disable monitor_error_event17 ;
17749 15 mihad
        end
17750
        begin:monitor_error_event17
17751 35 mihad
            error_monitor_done = 0 ;
17752 15 mihad
            pci_ok = 1 ;
17753
            @(error_event_int) ;
17754
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17755
            pci_ok = 0 ;
17756 35 mihad
            error_monitor_done = 1 ;
17757 15 mihad
        end
17758
        join
17759
 
17760
        if ( wb_ok && pci_ok )
17761
            test_ok ;
17762
 
17763
        fork
17764
        begin
17765
 
17766
             PCIU_IO_READ
17767
             (
17768
                `Test_Master_2,
17769
                pci_address[PCI_BUS_DATA_RANGE:0],
17770
                data,
17771
                byte_enables,
17772
                2,
17773
                `Test_Target_Retry_Before
17774
             );
17775
 
17776
            do_pause( 1 ) ;
17777
 
17778
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17779
            if ( wb_ok !== 1 )
17780
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17781
 
17782
            do_pause(3) ;
17783
 
17784
            PCIU_IO_READ
17785
             (
17786
                `Test_Master_2,
17787
                pci_address[PCI_BUS_DATA_RANGE:0],
17788
                data,
17789
                byte_enables,
17790
                expect_length + 2,
17791
                `Test_Target_Retry_Before
17792
             );
17793
 
17794
            do_pause( 3 ) ;
17795
 
17796
            while ( FRAME !== 1 || IRDY !== 1 )
17797
                @(posedge pci_clock) ;
17798
 
17799 35 mihad
            #1 ;
17800
            if ( !error_monitor_done )
17801
                disable monitor_error_event18 ;
17802 15 mihad
        end
17803
        begin:monitor_error_event18
17804 35 mihad
            error_monitor_done = 0 ;
17805 15 mihad
            pci_ok = 1 ;
17806
            @(error_event_int) ;
17807
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17808
            pci_ok = 0 ;
17809 35 mihad
            error_monitor_done = 1 ;
17810 15 mihad
        end
17811
        join
17812
 
17813
        if ( wb_ok && pci_ok )
17814
            test_ok ;
17815
 
17816
        test_name = "DISABLING IO IMAGE" ;
17817 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17818 15 mihad
        if ( ok !== 1 )
17819
        begin
17820
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17821
            test_fail("PCI Address Mask register could not be written") ;
17822
            disable main ;
17823
        end
17824
    end
17825
//*/
17826
end
17827
endtask // target_disconnects
17828
 
17829
task target_unsupported_cmds ;
17830
        input [31:0] Address;
17831
        input [2:0]  image_num ;
17832
    reg          ok ;
17833
begin:main
17834
 
17835
    $display("  ") ;
17836
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17837
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17838 45 mihad
 
17839
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17840
    configuration_cycle_write
17841
    (
17842
        0,                        // bus number
17843
        `TAR1_IDSEL_INDEX - 11,   // device number
17844
        0,                        // function number
17845
        1,                        // register number
17846
        0,                        // type of configuration cycle
17847
        4'b0001,                  // byte enables
17848
        32'h0000_0044             // data
17849
    ) ;
17850
 
17851
    configuration_cycle_write
17852
    (
17853
        0,                        // bus number
17854
        `TAR2_IDSEL_INDEX - 11,   // device number
17855
        0,                        // function number
17856
        1,                        // register number
17857
        0,                        // type of configuration cycle
17858
        4'b0001,                  // byte enables
17859
        32'h0000_0044             // data
17860
    ) ;
17861
 
17862 15 mihad
    ipci_unsupported_commands_master.master_reference
17863
    (
17864
        Address,                // first part of address in dual address cycle
17865
        Address,                // second part of address in dual address cycle
17866
        `BC_IACK,                       // dual address cycle command
17867
        `BC_IACK,               // normal command
17868
        4'h0,               // byte enables
17869
        32'h1234_5678,      // data
17870
        1'b0,               // make address parity error on first phase of dual address
17871
        1'b0,               // make address parity error on second phase of dual address
17872
        ok                  // result of operation
17873
    ) ;
17874
    if ( ok )
17875
        test_ok ;
17876
    else
17877
    begin
17878
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17879
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17880
    end
17881
 
17882
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17883
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17884
    ipci_unsupported_commands_master.master_reference
17885
    (
17886
        Address,                // first part of address in dual address cycle
17887
        Address,                // second part of address in dual address cycle
17888
        `BC_SPECIAL,            // dual address cycle command
17889
        `BC_SPECIAL,            // normal command
17890
        4'h0,               // byte enables
17891
        32'h1234_5678,      // data
17892
        1'b0,               // make address parity error on first phase of dual address
17893
        1'b0,               // make address parity error on second phase of dual address
17894
        ok                  // result of operation
17895
    ) ;
17896
    if ( ok )
17897
        test_ok ;
17898
    else
17899
    begin
17900
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17901
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17902
    end
17903
 
17904
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17905
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17906
    ipci_unsupported_commands_master.master_reference
17907
    (
17908
        Address,                // first part of address in dual address cycle
17909
        Address,                // second part of address in dual address cycle
17910
        `BC_RESERVED0,          // dual address cycle command
17911
        `BC_RESERVED0,      // normal command
17912
        4'h0,               // byte enables
17913
        32'h1234_5678,      // data
17914
        1'b0,               // make address parity error on first phase of dual address
17915
        1'b0,               // make address parity error on second phase of dual address
17916
        ok                  // result of operation
17917
    ) ;
17918
    if ( ok )
17919
        test_ok ;
17920
    else
17921
    begin
17922
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17923
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17924
    end
17925
 
17926
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17927
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17928
    ipci_unsupported_commands_master.master_reference
17929
    (
17930
        Address,                // first part of address in dual address cycle
17931
        Address,                // second part of address in dual address cycle
17932
        `BC_RESERVED1,          // dual address cycle command
17933
        `BC_RESERVED1,      // normal command
17934
        4'h0,               // byte enables
17935
        32'h1234_5678,      // data
17936
        1'b0,               // make address parity error on first phase of dual address
17937
        1'b0,               // make address parity error on second phase of dual address
17938
        ok                  // result of operation
17939
    ) ;
17940
    if ( ok )
17941
        test_ok ;
17942
    else
17943
    begin
17944
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17945
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17946
    end
17947
 
17948
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17949
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17950
    ipci_unsupported_commands_master.master_reference
17951
    (
17952
        Address,                // first part of address in dual address cycle
17953
        Address,                // second part of address in dual address cycle
17954
        `BC_RESERVED2,          // dual address cycle command
17955
        `BC_RESERVED2,      // normal command
17956
        4'h0,               // byte enables
17957
        32'h1234_5678,      // data
17958
        1'b0,               // make address parity error on first phase of dual address
17959
        1'b0,               // make address parity error on second phase of dual address
17960
        ok                  // result of operation
17961
    ) ;
17962
    if ( ok )
17963
        test_ok ;
17964
    else
17965
    begin
17966
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17967
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17968
    end
17969
 
17970
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17971
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17972
    ipci_unsupported_commands_master.master_reference
17973
    (
17974
        Address,                // first part of address in dual address cycle
17975
        Address,                // second part of address in dual address cycle
17976
        `BC_RESERVED3,          // dual address cycle command
17977
        `BC_RESERVED3,      // normal command
17978
        4'h0,               // byte enables
17979
        32'h1234_5678,      // data
17980
        1'b0,               // make address parity error on first phase of dual address
17981
        1'b0,               // make address parity error on second phase of dual address
17982
        ok                  // result of operation
17983
    ) ;
17984
    if ( ok )
17985
        test_ok ;
17986
    else
17987
    begin
17988
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17989
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17990
    end
17991
 
17992
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17993
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17994
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17995
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17996
    ipci_unsupported_commands_master.master_reference
17997
    (
17998
        Address,                // first part of address in dual address cycle
17999
        Address,                // second part of address in dual address cycle
18000
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
18001
        `BC_MEM_WRITE,      // normal command
18002
        4'h0,               // byte enables;
18003
        32'h1234_5678,      // data
18004
        1'b0,               // make address parity error on first phase of dual address
18005
        1'b0,               // make address parity error on second phase of dual address
18006
        ok                  // result of operation
18007
    ) ;
18008
    if ( ok )
18009
        test_ok ;
18010
    else
18011
    begin
18012
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
18013
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
18014
    end
18015
 
18016 45 mihad
    // enable pci blue behavioral targets 1 and 2
18017
    configuration_cycle_write
18018
    (
18019
        0,                        // bus number
18020
        `TAR1_IDSEL_INDEX - 11,   // device number
18021
        0,                        // function number
18022
        1,                        // register number
18023
        0,                        // type of configuration cycle
18024
        4'b0001,                  // byte enables
18025
        32'h0000_0047             // data
18026
    ) ;
18027
 
18028
    configuration_cycle_write
18029
    (
18030
        0,                        // bus number
18031
        `TAR2_IDSEL_INDEX - 11,   // device number
18032
        0,                        // function number
18033
        1,                        // register number
18034
        0,                        // type of configuration cycle
18035
        4'b0001,                  // byte enables
18036
        32'h0000_0047             // data
18037
    ) ;
18038 15 mihad
end
18039
endtask // target_unsupported_cmds
18040
 
18041 63 mihad
`ifdef DISABLE_COMPLETION_EXPIRED_TESTS
18042
`else
18043 15 mihad
task target_completion_expiration ;
18044
    reg   [11:0] pci_ctrl_offset ;
18045
    reg   [11:0] pci_ba_offset ;
18046
    reg   [11:0] pci_am_offset ;
18047
    reg   [11:0] pci_device_ctrl_offset ;
18048
    reg   [11:0] pci_err_cs_offset ;
18049
    reg   [11:0] icr_offset ;
18050
    reg   [11:0] isr_offset ;
18051
    reg   [11:0] lat_tim_cls_offset ;
18052
 
18053
    reg [31:0] temp_val1 ;
18054
    reg [31:0] temp_val2 ;
18055
    reg        ok   ;
18056 33 mihad
    reg        ok_wb ;
18057
    reg        ok_pci ;
18058 15 mihad
 
18059
    reg [31:0] pci_image_base ;
18060
    integer i ;
18061 33 mihad
    integer clocks_after_completion ;
18062
    reg     error_monitor_done ;
18063
    reg     test_mem ;
18064 15 mihad
 
18065
begin:main
18066
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18067
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18068
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18069
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18070
 
18071
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18072
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18073
    lat_tim_cls_offset = 12'hC ;
18074
    pci_device_ctrl_offset    = 12'h4 ;
18075
 
18076 33 mihad
    `ifdef HOST
18077
        test_mem = 1'b1 ;
18078
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18079
    `else
18080
        test_mem = !`PCI_BA1_MEM_IO ;
18081
        pci_image_base = Target_Base_Addr_R[1] ;
18082
    `endif
18083 15 mihad
 
18084
    // enable master & target operation
18085
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18086
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18087
    if ( ok !== 1 )
18088
    begin
18089
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18090
        test_fail("write to PCI Device Control register failed") ;
18091
        disable main ;
18092
    end
18093
 
18094
    // prepare image control register
18095 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18096 15 mihad
    if ( ok !== 1 )
18097
    begin
18098
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18099
        test_fail("write to PCI Image Control register failed") ;
18100
        disable main ;
18101
    end
18102
 
18103
    // prepare base address register
18104
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18105
    if ( ok !== 1 )
18106
    begin
18107
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18108
        test_fail("write to PCI Base Address register failed") ;
18109
        disable main ;
18110
    end
18111
 
18112
    // write address mask register
18113
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18114
    if ( ok !== 1 )
18115
    begin
18116
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18117
        test_fail("write to PCI Address Mask register failed") ;
18118
        disable main ;
18119
    end
18120
 
18121
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18122
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18123
    if ( ok !== 1 )
18124
    begin
18125
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18126
        test_fail("write to PCI Error Control and Status register failed") ;
18127
        disable main ;
18128
    end
18129
 
18130 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18131 15 mihad
    if ( ok !== 1 )
18132
    begin
18133
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18134
        test_fail("write to Interrupt Control register failed") ;
18135
        disable main ;
18136
    end
18137
 
18138
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18139
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18140
    if ( ok !== 1 )
18141
    begin
18142
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18143
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18144
        disable main ;
18145
    end
18146
 
18147
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18148
 
18149
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18150 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18151
    master1_check_received_data = 0 ;
18152 15 mihad
 
18153 33 mihad
    ok_pci = 1 ;
18154
    // start a delayed read request
18155
    fork
18156
    begin
18157
        if ( test_mem )
18158
 
18159
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18160
                          pci_image_base, 32'h1234_5678,
18161
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18162
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18163
        else
18164
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18165
 
18166
        do_pause( 1 ) ;
18167
    end
18168
    begin:error_monitor1
18169 35 mihad
        error_monitor_done = 0 ;
18170 33 mihad
        @(error_event_int) ;
18171
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18172
        ok_pci = 0 ;
18173 35 mihad
        error_monitor_done = 1 ;
18174 33 mihad
    end
18175
    begin
18176
        if ( test_mem )
18177
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18178
        else
18179
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18180 15 mihad
 
18181 33 mihad
        if ( ok_wb !== 1 )
18182
        begin
18183
            test_fail("Bridge failed to process Target Memory read correctly") ;
18184
            disable main ;
18185
        end
18186
 
18187 35 mihad
        #1 ;
18188
        if ( !error_monitor_done )
18189 33 mihad
            disable error_monitor1 ;
18190
    end
18191
    join
18192
 
18193
    clocks_after_completion = 0 ;
18194
    // now do another - different transaction
18195
    fork
18196
    begin
18197
        if ( test_mem )
18198
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18199
                          pci_image_base + 4, 32'h1234_5678,
18200
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18201
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18202
        else
18203
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18204
 
18205
        while ( clocks_after_completion < 32'h0000_FFF0 )
18206
        begin
18207
            @(posedge pci_clock) ;
18208
            clocks_after_completion = clocks_after_completion + 1 ;
18209
        end
18210
 
18211
        do_pause('hFF) ;
18212
 
18213
        if ( test_mem )
18214
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18215
                          pci_image_base + 4, 32'h1234_5678,
18216
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18217
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18218
        else
18219
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18220
 
18221
        do_pause( 1 ) ;
18222
    end
18223
    begin:error_monitor2
18224 35 mihad
        error_monitor_done = 0 ;
18225 33 mihad
        @(error_event_int) ;
18226
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18227
        ok_pci = 0 ;
18228 35 mihad
        error_monitor_done = 1 ;
18229 33 mihad
    end
18230
    begin
18231
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18232
        repeat( 'hFF )
18233
            @(posedge pci_clock) ;
18234
 
18235
        if ( test_mem )
18236
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18237
        else
18238
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18239
 
18240
        if ( ok_wb !== 1 )
18241
        begin
18242
            test_fail("Bridge failed to process Target Memory read correctly") ;
18243
            disable main ;
18244
        end
18245
 
18246
        repeat(4)
18247
            @(posedge pci_clock) ;
18248
 
18249
        fork
18250
        begin
18251
            if ( test_mem )
18252
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18253
                              pci_image_base + 4, 32'h1234_5678,
18254
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18255
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18256
            else
18257
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18258
 
18259
            do_pause(1) ;
18260
        end
18261
        begin
18262
           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 ) ;
18263 35 mihad
           #1 ;
18264
           if ( !error_monitor_done )
18265 33 mihad
               disable error_monitor2 ;
18266
        end
18267
        join
18268
    end
18269
    join
18270
 
18271
    if ( ok && ok_pci && ok_wb )
18272
        test_ok ;
18273
 
18274
    if ( ok !== 1 )
18275
    begin
18276
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18277
        test_fail("write to PCI Address Mask register failed") ;
18278
        disable main ;
18279
    end
18280
 
18281
    // check statuses after this situation - none should be set
18282
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18283
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18284
    if ( ok !== 1 )
18285
    begin
18286
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18287
        test_fail("read from pci device status register failed") ;
18288
        disable main ;
18289
    end
18290
 
18291
    if ( temp_val1[31] )
18292
    begin
18293
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18294
        test_fail("detected parity error bit was set for no reason") ;
18295
    end
18296
 
18297
    if ( temp_val1[30] )
18298
    begin
18299
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18300
        test_fail("signaled system error bit was set for no reason") ;
18301
    end
18302
 
18303
    if ( temp_val1[29] )
18304
    begin
18305
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18306
        test_fail("received master abort bit was set for no reason") ;
18307
    end
18308
 
18309
    if ( temp_val1[28] )
18310
    begin
18311
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18312
        test_fail("received target abort bit was set for no reason") ;
18313
    end
18314
 
18315
    if ( temp_val1[27] )
18316
    begin
18317
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18318
        test_fail("signaled target abort bit was set for no reason") ;
18319
    end
18320
 
18321
    if ( temp_val1[24] )
18322
    begin
18323
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18324
        test_fail("Master Data parity error bit was set for no reason") ;
18325
    end
18326
 
18327
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18328
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18329
    if ( temp_val1[8] !== 0 )
18330
    begin
18331
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18332
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18333
    end
18334
    // test target retry counter expiration
18335
    // set wb slave to retry response
18336
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18337
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18338
    ok_pci = 1 ;
18339
 
18340
    fork
18341
    begin
18342
        if ( test_mem == 1 )
18343
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18344
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18345
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18346
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18347
        else
18348
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18349
 
18350
        do_pause(1) ;
18351
 
18352
        // do another write with same address and different data
18353
        if ( test_mem == 1 )
18354
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18355
                        pci_image_base, 32'h8765_4321, 4'h0,
18356
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18357
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18358
        else
18359
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18360
 
18361
        do_pause(1) ;
18362
    end
18363
    begin
18364
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18365
        begin
18366
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18367
            if ( ok_wb !== 1 )
18368
            begin
18369
                $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) ;
18370
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18371
                disable main ;
18372
            end
18373
        end
18374
 
18375
        // set WB slave to normal completion
18376
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18377
 
18378
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18379
        if ( ok_wb !== 1 )
18380
        begin
18381
            $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) ;
18382
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18383
            disable main ;
18384
        end
18385
 
18386 35 mihad
        #1 ;
18387
        if ( !error_monitor_done )
18388 33 mihad
            disable error_monitor3 ;
18389
    end
18390
    begin:error_monitor3
18391 35 mihad
        error_monitor_done = 0 ;
18392 33 mihad
        @(error_event_int) ;
18393
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18394
        ok_pci = 0 ;
18395 35 mihad
        error_monitor_done = 1 ;
18396 33 mihad
    end
18397
    join
18398
 
18399
    if ( ok_wb && ok_pci )
18400
    begin
18401
        test_ok ;
18402
    end
18403
 
18404
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18405
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18406
    if ( temp_val1[8] !== 1'b1 )
18407
    begin
18408
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18409
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18410
    end
18411
 
18412
    if ( temp_val1[9] !== 1 )
18413
    begin
18414
        $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) ;
18415
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18416
    end
18417
 
18418
    if ( temp_val1[10] !== 1 )
18419
    begin
18420
        $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) ;
18421
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18422
    end
18423
 
18424
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18425
    begin
18426
        $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) ;
18427
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18428
    end
18429
 
18430
    if ( temp_val1[31:28] !== 4'hA )
18431
    begin
18432
        $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) ;
18433
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18434
    end
18435
 
18436
    // clear error status register
18437
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18438
 
18439
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18440
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18441
    if ( temp_val1 !== pci_image_base )
18442
    begin
18443
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18444
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18445
    end
18446
 
18447
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18448
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18449
    if ( temp_val1 !== 32'hDEAD_BEAF )
18450
    begin
18451
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18452
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18453
    end
18454
 
18455
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18456
    ok_pci = 1 ;
18457
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18458
 
18459
    i = 0 ;
18460
    fork
18461
    begin
18462
        if ( test_mem )
18463
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18464
                          pci_image_base + 4, 32'h1234_5678,
18465
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18466
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18467
        else
18468
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18469
 
18470
        do_pause( 1 ) ;
18471
 
18472
    end
18473
    begin
18474
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18475
        begin
18476
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18477
            if ( ok_wb !== 1 )
18478
            begin
18479
                $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) ;
18480
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18481
                disable main ;
18482
            end
18483
        end
18484
 
18485
        // set WB slave to normal completion
18486
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18487
 
18488
        fork
18489
        begin
18490
            repeat(4)
18491
                @(posedge pci_clock) ;
18492
 
18493
            if ( test_mem )
18494
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18495
                              pci_image_base, 32'h8765_4321,
18496
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18497
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18498
            else
18499
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18500
 
18501
            do_pause(1) ;
18502
        end
18503
        begin
18504
 
18505
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18506
            if ( ok_wb !== 1 )
18507
            begin
18508
                $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) ;
18509
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18510
                disable main ;
18511
            end
18512
        end
18513
        join
18514
 
18515
        repeat( 4 )
18516
            @(posedge pci_clock) ;
18517
 
18518
        if ( test_mem )
18519
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18520
                          pci_image_base, 32'h8765_4321,
18521
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18522
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18523
        else
18524
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18525
 
18526
        do_pause(1) ;
18527
 
18528 35 mihad
        #1 ;
18529
        if ( !error_monitor_done )
18530 33 mihad
            disable error_monitor4 ;
18531
    end
18532
    begin:error_monitor4
18533 35 mihad
        error_monitor_done = 0 ;
18534 33 mihad
        @(error_event_int) ;
18535
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18536
        ok_pci = 0 ;
18537 35 mihad
        error_monitor_done = 1 ;
18538 33 mihad
    end
18539
    join
18540
 
18541
    if ( ok_wb && ok_pci )
18542
        test_ok ;
18543
 
18544
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18545
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18546
    if ( temp_val1[8] !== 1'b0 )
18547
    begin
18548
        $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) ;
18549
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18550
    end
18551
 
18552
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18553 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18554
    $fdisplay(pciu_mon_log_file_desc,
18555
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18556 33 mihad
    ok_pci = 1 ;
18557
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18558
 
18559
    fork
18560
    begin
18561
        if ( test_mem )
18562
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18563
                          pci_image_base + 4, 32'h1234_5678,
18564
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18565
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18566
        else
18567
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18568
 
18569
        do_pause( 1 ) ;
18570
 
18571
    end
18572
    begin
18573
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18574
        if ( ok_wb !== 1 )
18575
        begin
18576
            $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) ;
18577
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18578
            disable main ;
18579
        end
18580
 
18581
        repeat(4)
18582
            @(posedge pci_clock) ;
18583
 
18584
        fork
18585
        begin
18586
 
18587
            if ( test_mem )
18588
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18589
                              pci_image_base + 4, 32'h8765_4321,
18590
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18591
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18592
            else
18593
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18594
 
18595
            do_pause(1) ;
18596
 
18597
        end
18598
        begin
18599
 
18600
            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 ) ;
18601
            if ( ok !== 1 )
18602
            begin
18603
                $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) ;
18604
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18605
                disable main ;
18606
            end
18607
        end
18608
        join
18609
 
18610 35 mihad
        #1 ;
18611
        if ( !error_monitor_done )
18612 33 mihad
            disable error_monitor5 ;
18613
    end
18614
    begin:error_monitor5
18615 35 mihad
        error_monitor_done = 0 ;
18616 33 mihad
        @(error_event_int) ;
18617
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18618
        ok_pci = 0 ;
18619 35 mihad
        error_monitor_done = 1 ;
18620 33 mihad
    end
18621
    join
18622
 
18623
    if ( ok_wb && ok_pci )
18624
        test_ok ;
18625
 
18626
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18627
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18628
    if ( temp_val1[8] !== 1'b0 )
18629
    begin
18630
        $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) ;
18631
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18632
    end
18633
 
18634
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18635
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18636
    if ( temp_val1[25] !== 1'b1 )
18637
    begin
18638
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18639
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18640
    end
18641
 
18642
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18643
 
18644
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18645
    ok_pci = 1 ;
18646
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18647
 
18648
    fork
18649
    begin
18650
        if ( test_mem == 1 )
18651
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18652
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18653
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18654
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18655
        else
18656
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18657
 
18658
        do_pause(1) ;
18659
 
18660
        // do another write with same address and different data
18661
        if ( test_mem == 1 )
18662
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18663
                        pci_image_base, 32'h8765_6789, 4'h0,
18664
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18665
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18666
        else
18667
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18668
 
18669
        do_pause(1) ;
18670
    end
18671
    begin
18672
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18673
        if ( ok_wb !== 1 )
18674
        begin
18675
            $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) ;
18676
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18677
            disable main ;
18678
        end
18679
 
18680
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18681
 
18682
        if ( test_mem )
18683
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18684
        else
18685
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18686
 
18687
        if ( ok_wb !== 1 )
18688
        begin
18689
            $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) ;
18690
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18691
            disable main ;
18692
        end
18693
 
18694 35 mihad
        #1 ;
18695
        if ( !error_monitor_done )
18696 33 mihad
            disable error_monitor6 ;
18697
    end
18698
    begin:error_monitor6
18699 35 mihad
        error_monitor_done = 0 ;
18700 33 mihad
        @(error_event_int) ;
18701
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18702
        ok_pci = 0 ;
18703 35 mihad
        error_monitor_done = 1 ;
18704 33 mihad
    end
18705
    join
18706
 
18707
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18708
    $fdisplay(pciu_mon_log_file_desc,
18709
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18710
 
18711
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18712
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18713
    if ( temp_val1[8] !== 1'b1 )
18714
    begin
18715
        $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) ;
18716
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18717
    end
18718
 
18719
    if ( temp_val1[9] !== 0 )
18720
    begin
18721
        $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) ;
18722
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18723
    end
18724
 
18725
    if ( temp_val1[10] !== 1 )
18726
    begin
18727
        $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) ;
18728
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18729
    end
18730
 
18731
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18732
    begin
18733
        $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) ;
18734
        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") ;
18735
    end
18736
 
18737
    if ( temp_val1[31:28] !== 4'h0 )
18738
    begin
18739
        $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) ;
18740
        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") ;
18741
    end
18742
 
18743
    // clear error status register
18744
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18745
 
18746
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18747
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18748
    if ( temp_val1 !== pci_image_base )
18749
    begin
18750
        $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) ;
18751
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18752
    end
18753
 
18754
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18755
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18756
    if ( temp_val1 !== 32'hBEAF_DEAD )
18757
    begin
18758
        $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) ;
18759
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18760
    end
18761
 
18762
    // disable current image - write address mask register
18763 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18764 15 mihad
end
18765 57 mihad
endtask // target_completion_expiration
18766 15 mihad
 
18767 57 mihad
task master_completion_expiration ;
18768
    reg   [11:0] ctrl_offset ;
18769
    reg   [11:0] ba_offset ;
18770
    reg   [11:0] am_offset ;
18771
    reg `WRITE_STIM_TYPE write_data ;
18772
    reg `READ_STIM_TYPE  read_data ;
18773
    reg `READ_RETURN_TYPE read_status ;
18774
 
18775
    reg `WRITE_RETURN_TYPE write_status ;
18776
    reg `WB_TRANSFER_FLAGS write_flags ;
18777
    reg        ok   ;
18778
    reg [11:0] pci_ctrl_offset ;
18779
    reg [31:0] image_base ;
18780
    reg [31:0] target_address ;
18781
begin:main
18782
    pci_ctrl_offset = 12'h4 ;
18783
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18784
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18785
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18786
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18787
 
18788
    target_address  = `BEH_TAR1_MEM_START ;
18789
    image_base      = 0 ;
18790
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18791
 
18792
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18793
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18794
    write_flags                      = 0 ;
18795
    write_flags`INIT_WAITS           = tb_init_waits ;
18796
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18797
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18798
 
18799
    // enable master & target operation
18800
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18801
    if ( ok !== 1 )
18802
    begin
18803
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18804
        test_fail("write to PCI Device Control register didn't succeede");
18805
        disable main ;
18806
    end
18807
 
18808
    // prepare image control register
18809
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18810
    if ( ok !== 1 )
18811
    begin
18812
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18813
        test_fail("write to WB Image Control register didn't succeede");
18814
        disable main ;
18815
    end
18816
 
18817
    // prepare base address register
18818
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18819
    if ( ok !== 1 )
18820
    begin
18821
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18822
        test_fail("write to WB Base Address register didn't succeede");
18823
        disable main ;
18824
    end
18825
 
18826
    // write address mask register
18827
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18828
    if ( ok !== 1 )
18829
    begin
18830
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18831
        test_fail("write to WB Address Mask register didn't succeede");
18832
        disable main ;
18833
    end
18834
 
18835
    fork
18836
    begin
18837
        // do not handle retries
18838
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18839
 
18840
        // initiate a read request
18841
        read_data`READ_ADDRESS  = target_address ;
18842
        read_data`READ_SEL      = 4'hF ;
18843
        read_data`READ_TAG_STIM = 0 ;
18844
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18845
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18846
        begin
18847
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18848
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18849
            disable main ;
18850
        end
18851
 
18852
        // handle retries from now on
18853
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18854
 
18855
        write_data`WRITE_ADDRESS = target_address + 4 ;
18856
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18857
        write_data`WRITE_SEL     = 4'hF ;
18858
 
18859
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18860
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18861
        begin
18862
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18863
            test_fail("WB Slave state machine failed to post single memory write");
18864
            disable main ;
18865
        end
18866
 
18867
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 100
18868
        repeat('h1_0000 - 100)
18869
            @(posedge wb_clock) ;
18870
 
18871
        // now perform a read
18872
        read_data`READ_ADDRESS  = target_address + 4 ;
18873
        read_data`READ_SEL      = 4'hF ;
18874
        read_data`READ_TAG_STIM = 0 ;
18875
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18876
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18877
        begin
18878
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18879
            test_fail("PCI bridge didn't process the read as expected");
18880
            disable main ;
18881
        end
18882
 
18883
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18884
        begin
18885
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18886
            test_fail("PCI bridge returned unexpected Read Data");
18887
        end
18888
        else if (ok === 1'b1)
18889
            test_ok ;
18890
    end
18891
    begin:monitors
18892
        // monitor first read, which will expire
18893
        pci_transaction_progress_monitor
18894
        (
18895
            target_address, // expected address
18896
            `BC_MEM_READ,   // expected bus command
18897
            1,              // expected number of transfers
18898
            0,              // expected number of cycles
18899
            1,              // check number of transfers true/false
18900
            0,              // check number of cycles true/false
18901
            0,              // is this fast B2B true/false
18902
            ok              // return 1 if as expected, anything else on error
18903
        ) ;
18904
 
18905
        if ( ok !== 1 )
18906
        begin
18907
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18908
            #1 disable monitors ;
18909
        end
18910
 
18911
        // monitor normal single write
18912
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18913
        if ( ok !== 1 )
18914
        begin
18915
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18916
            #1 disable monitors ;
18917
        end
18918
 
18919
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18920
        repeat('h1_0000 - 50)
18921
            @(posedge wb_clock) ;
18922
 
18923
        // monitor normal single memory read
18924
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18925
        if ( ok !== 1 )
18926
        begin
18927
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18928
        end
18929
    end
18930
    join
18931
 
18932
    // disable the image
18933
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18934
    if ( ok !== 1 )
18935
    begin
18936
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18937
        test_fail("write to WB Address Mask register didn't succeede");
18938
    end
18939
end
18940
endtask // master_completion_expiration
18941 63 mihad
`endif
18942 57 mihad
 
18943 15 mihad
task config_write ;
18944
    input [11:0] offset ;
18945
    input [31:0] data ;
18946
    input [3:0]  byte_enable ;
18947
    output       ok ;
18948
    `ifdef HOST
18949
    reg   `WRITE_STIM_TYPE   write_data ;
18950
    reg   `WB_TRANSFER_FLAGS write_flags ;
18951
    reg   `WRITE_RETURN_TYPE write_status ;
18952
    `else
18953
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18954
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18955
    `endif
18956
    reg in_use ;
18957
    reg [31:0] temp_var ;
18958
begin
18959
    if ( in_use === 1 )
18960
    begin
18961
        $display("config_read task re-entered! Time %t ", $time) ;
18962
        ok = 0 ;
18963
        #20 $stop ;
18964
    end
18965
    else
18966
    begin
18967
        ok = 1 ;
18968
        in_use = 1 ;
18969
    end
18970
    `ifdef HOST
18971
    write_flags                    = 0 ;
18972
    write_flags`INIT_WAITS         = tb_init_waits ;
18973
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18974
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18975
 
18976
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18977
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18978
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18979
    write_data`WRITE_SEL                         = byte_enable ;
18980
    write_data`WRITE_TAG_STIM                    = 0 ;
18981
    write_data`WRITE_DATA                        = data ;
18982
 
18983
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18984
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18985
    begin
18986
        $display("Write to configuration space failed! Time %t ", $time) ;
18987
        ok = 0 ;
18988
    end
18989
 
18990
    @(posedge wb_clock) ;
18991
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18992
    // here we just wait for two guest cycles for conf space bits to synchronize
18993
    repeat( 2 )
18994
        @(posedge pci_clock) ;
18995
 
18996
    `else // GUEST
18997
    byte_enables_l = ~byte_enable ;
18998
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18999
 
19000
    fork
19001
    begin
19002
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19003
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
19004
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
19005
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19006
              8'h0_0, `Test_One_Zero_Target_WS,
19007
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
19008
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19009
    do_pause( 1 ) ;
19010
    end
19011
    begin
19012
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
19013
        @(posedge pci_clock) ;
19014
    end
19015
    join
19016
 
19017
     repeat( 2 )
19018
         @(posedge wb_clock) ;
19019
 
19020
    `endif
19021
    in_use = 0 ;
19022
end
19023
endtask // config_write
19024
 
19025
task config_read ;
19026
    input [11:0] offset ;
19027
    input [3:0]  byte_enable ;
19028
    output [31:0] data ;
19029
 
19030
    reg `READ_STIM_TYPE    read_data ;
19031
    reg `WB_TRANSFER_FLAGS read_flags ;
19032
    reg `READ_RETURN_TYPE  read_status ;
19033
 
19034
    reg [31:0] pci_address ;
19035
    reg [3:0] byte_enables_l ;
19036
 
19037
    reg master_check_data_prev ;
19038
    reg in_use ;
19039
    reg [31:0] temp_var ;
19040
begin:main
19041
    if ( in_use === 1 )
19042
    begin
19043
        $display("config_read task re-entered! Time %t ", $time) ;
19044
        data = 32'hxxxx_xxxx ;
19045
        disable main ;
19046
    end
19047
 
19048
    in_use = 1 ;
19049
 
19050
`ifdef HOST
19051 26 mihad
    repeat(4)
19052
        @(posedge pci_clock) ;
19053
    repeat(4)
19054
        @(posedge wb_clock) ;
19055 15 mihad
    read_flags                    = 0 ;
19056
    read_flags`INIT_WAITS         = tb_init_waits ;
19057
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19058
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19059
 
19060
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19061
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19062
 
19063
    read_data`READ_ADDRESS  = temp_var + offset ;
19064
    read_data`READ_SEL      = byte_enable ;
19065
    read_data`READ_TAG_STIM = 0 ;
19066
 
19067
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19068
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19069
    begin
19070
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19071
        #20 $stop ;
19072
    end
19073
    data = read_status`READ_DATA ;
19074
`else
19075
  `ifdef GUEST
19076 26 mihad
    repeat(4)
19077
        @(posedge wb_clock) ;
19078
    repeat(4)
19079
        @(posedge pci_clock) ;
19080 15 mihad
    master_check_data_prev = master2_check_received_data ;
19081
    master2_check_received_data = 0 ;
19082
 
19083
    byte_enables_l = ~byte_enable ;
19084
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19085
 
19086
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19087
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19088
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19089
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19090
             8'h4_0, `Test_One_Zero_Target_WS,
19091
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19092
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19093
    do_pause( 1 ) ;
19094
 
19095
    @(master2_received_data_valid) ;
19096
    data = master2_received_data ;
19097
 
19098
    master2_check_received_data = master_check_data_prev ;
19099
  `endif
19100
`endif
19101
    in_use = 0 ;
19102
end
19103
endtask //config_read
19104
 
19105 62 mihad
`ifdef PCI_BIST
19106
`ifdef WB_RAM_DONT_SHARE
19107
    `ifdef PCI_RAM_DONT_SHARE
19108
        parameter bist_chain_length = 8 ;
19109
    `else
19110
        parameter bist_chain_length = 6 ;
19111
    `endif
19112
`else
19113
    `ifdef PCI_RAM_DONT_SHARE
19114
        bist_chain_length = 6 ;
19115
    `else
19116
        bist_chain_length = 4 ;
19117
    `endif
19118
`endif
19119
 
19120
task run_bist_test ;
19121
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19122
    integer count ;
19123
    integer deadlock_count ;
19124
begin
19125
 
19126
    test_name = "BIST FOR RAMS RUN" ;
19127
 
19128
    SI          = 0 ;
19129
    shift_DR    = 0 ;
19130
    capture_DR  = 0 ;
19131
    extest      = 0 ;
19132
    tck         = 0 ;
19133
 
19134
    fork
19135
    begin
19136
        repeat(2)
19137
            @(posedge wb_clock) ;
19138
    end
19139
    begin
19140
        repeat(2)
19141
            @(posedge pci_clock) ;
19142
    end
19143
    join
19144
 
19145
    // test is run with forcing extest high
19146
    extest <= 1'b1 ;
19147
 
19148
    bist_result_vector = 0 ;
19149
 
19150
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19151
    fork
19152
    begin:scan
19153
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19154
        begin
19155
            @(negedge tck) ;
19156
            capture_DR <= #1 1'b1 ;
19157
            @(negedge tck) ;
19158
            capture_DR <= #1 1'b0 ;
19159
            shift_DR   <= #1 1'b1 ;
19160
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19161
            begin
19162
                @(negedge tck) ;
19163
                bist_result_vector[count] = SO ;
19164
            end
19165
 
19166
            shift_DR <= #1 1'b0 ;
19167
        end
19168
        #1 disable deadlock ;
19169
        @(negedge tck) ;
19170
        extest <= #1 1'b0 ;
19171
        #1 ;
19172
        disable tck_gen ;
19173
        test_ok ;
19174
    end
19175
    begin:deadlock
19176
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19177
        begin
19178
            @(posedge pci_clock) ;
19179
            @(posedge wb_clock) ;
19180
        end
19181
 
19182
        test_fail("BIST Test didn't finish as expected") ;
19183
        extest <= #1 1'b0 ;
19184
        disable scan ;
19185
        @(negedge tck) ;
19186
        #1 ;
19187
        disable tck_gen ;
19188
    end
19189
    begin:tck_gen
19190
        forever
19191
            #50 tck = !tck ;
19192
    end
19193
    join
19194
end
19195
endtask // run_bist_test
19196
`endif
19197
 
19198 63 mihad
`ifdef WB_CLOCK_FOLLOWS_PCI_CLOCK
19199
task target_special_corner_case_test ;
19200
    reg   [11:0]    pci_ctrl_offset ;
19201
    reg   [11:0]    ctrl_offset ;
19202
    reg   [11:0]    ba_offset ;
19203
    reg   [11:0]    am_offset ;
19204
    reg             ok_wb ;
19205
    reg             ok_pci ;
19206
    reg             test_mem ;
19207
    reg             master_check_data_previous ;
19208
begin:main
19209
    master_check_data_previous  = master1_check_received_data ;
19210
    master1_check_received_data = 1'b1 ;
19211
    pci_ctrl_offset = 12'h4 ;
19212
    // use image 1 for this test
19213
    ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
19214
    ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
19215
    am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
19216
 
19217
    // set behavioral slave cycle response
19218
    `ifdef REGISTER_WBM_OUTPUTS
19219
    wishbone_slave.cycle_response
19220
    (
19221
        3'b100,         // {ACK, ERR, RTY}
19222
        0,              // wait cycles
19223
        8'h0            // num of retries before termination
19224
    );
19225
    `else
19226
    wishbone_slave.cycle_response
19227
    (
19228
        3'b100,         // {ACK, ERR, RTY}
19229
        1,              // wait cycles
19230
        8'h0            // num of retries before termination
19231
    );
19232
    `endif
19233
 
19234
    `ifdef HOST
19235
        test_mem = 1 ;
19236
    `else
19237
        test_mem = `PCI_BA1_MEM_IO ;
19238
        test_mem = !test_mem ;
19239
    `endif
19240
 
19241
    test_name = "PCI TARGET UNIT SPECIAL CORNER CASE" ;
19242
 
19243
    // Set Base Address of IMAGE
19244
    config_write( ba_offset, Target_Base_Addr_R[1], 4'hF, ok_wb ) ;
19245
    if ( ok_wb !== 1 )
19246
    begin
19247
        $display("Image testing failed! Failed to write P_BA1 register! Time %t ", $time);
19248
        test_fail("PCI Base Address register 1 could not be written") ;
19249
        #1 ;
19250
        disable main ;
19251
    end
19252
 
19253
    // Set Address Mask of IMAGE
19254
    config_write( am_offset, Target_Addr_Mask_R[1], 4'hF, ok_wb ) ;
19255
    if ( ok_wb !== 1 )
19256
    begin
19257
        $display("Image testing failed! Failed to write P_AM1 register! Time %t ", $time);
19258
        test_fail("PCI Address Mask register 1 could not be written") ;
19259
        #1 ;
19260
        disable main ;
19261
    end
19262
 
19263
    // Disable all the features of the PCI Image 1
19264
    config_write( ctrl_offset, 0, 4'hF, ok_wb ) ;
19265
    if ( ok_wb !== 1 )
19266
    begin
19267
        $display("Image testing failed! Failed to write P_CTRL1 register! Time %t ", $time);
19268
        test_fail("PCI Image Control register 1 could not be written") ;
19269
        #1 ;
19270
        disable main ;
19271
    end
19272
 
19273
    // set waits to max, which means 0 on PCI
19274
    tb_init_waits   = 4 ;
19275
    tb_subseq_waits = 4 ;
19276
 
19277
    // do one dummy write, to receive a GNT park
19278
    if (test_mem)
19279
    begin
19280
        PCIU_MEM_WRITE
19281
        (
19282
            "MEM_WRITE ",                       // just the name
19283
            `Test_Master_1,                     // Behavioral Master to use for reference
19284
            Target_Base_Addr_R[1],              // Address of this transaction
19285
            32'hAAAA_AAAA,                      // Data For the transaction
19286
            4'h0,                               // Byte enables
19287
            1,                                  // length of transfer
19288
            `Test_One_Zero_Master_WS,           // Master Waits - don't care
19289
            `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19290
            `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19291
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19292
        );
19293
    end
19294
    else
19295
    begin
19296
        PCIU_IO_WRITE
19297
        (
19298
            `Test_Master_1,                     // Behavioral Master to use for reference
19299
            Target_Base_Addr_R[1],              // Address of this transaction
19300
            32'hAAAA_AAAA,                      // Data For the transaction
19301
            4'h0,                               // Byte enables
19302
            1,                                  // Size of transfer
19303
            `Test_Target_Normal_Completion      // Expected Target Termination Response
19304
        ) ;
19305
    end
19306
 
19307
    do_pause( 1 ) ;
19308
    wb_transaction_progress_monitor
19309
    (
19310
        Target_Base_Addr_R[1],          // expected address
19311
        1'b1,                           // expected operation R/W
19312
        1,                              // 1
19313
        1'b1,                           // turn checking of transfers ON/OFF
19314
        ok_wb                           // succeeded/failed
19315
    ) ;
19316
 
19317
    if (ok_wb !== 1'b1)
19318
    begin
19319
        test_fail("WB Transaction Monitor detected invalid transaction on WB bus after posted memory write through target") ;
19320
        #1 ;
19321
        disable main ;
19322
    end
19323
 
19324
    fork
19325
    begin
19326
        if (test_mem)
19327
        begin
19328
            PCIU_MEM_WRITE
19329
            (
19330
                "MEM_WRITE ",                       // just the name
19331
                `Test_Master_1,                     // Behavioral Master to use for reference
19332
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19333
                32'hF0F0_F0F0,                      // Data For the transaction
19334
                4'h0,                               // Byte enables       
19335
                1,                                  // length of transfer
19336
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19337
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19338
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19339
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19340
            );
19341
        end
19342
        else
19343
        begin
19344
            PCIU_IO_WRITE
19345
            (
19346
                `Test_Master_1,                     // Behavioral Master to use for reference
19347
                Target_Base_Addr_R[1] + 64,         // Address of this transaction
19348
                32'hF0F0_F0F0,                      // Data For the transaction
19349
                4'h0,                               // Byte enables
19350
                1,                                  // Size of transfer
19351
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19352
            ) ;
19353
        end
19354
 
19355
        do_pause( 1 ) ;
19356
 
19357
        if (test_mem)
19358
        begin
19359
            PCIU_MEM_WRITE
19360
            (
19361
                "MEM_WRITE ",                       // just the name
19362
                `Test_Master_1,                     // Behavioral Master to use for reference
19363
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19364
                32'h0F0F_0F0F,                      // Data For the transaction
19365
                4'h0,                               // Byte enables
19366
                1,                                  // length of transfer
19367
                `Test_One_Zero_Master_WS,           // Master Waits - don't care
19368
                `Test_One_Zero_Target_WS,           // Expected Target Wait State Response
19369
                `Test_Devsel_Medium,                // Expected Target DEVSEL Speed Response
19370
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19371
            );
19372
        end
19373
        else
19374
        begin
19375
            PCIU_IO_WRITE
19376
            (
19377
                `Test_Master_1,                     // Behavioral Master to use for reference
19378
                Target_Base_Addr_R[1] + 128,        // Address of this transaction
19379
                32'h0F0F_0F0F,                      // Data For the transaction
19380
                4'h0,                               // Byte enables
19381
                1,                                  // Size of transfer
19382
                `Test_Target_Normal_Completion      // Expected Target Termination Response
19383
            ) ;
19384
        end
19385
 
19386
        do_pause( 1 ) ;
19387
    end
19388
    begin
19389
        wb_transaction_progress_monitor
19390
        (
19391
            Target_Base_Addr_R[1] + 64,     // expected address
19392
            1'b1,                           // expected operation R/W
19393
            1,                              // expected number of transfers
19394
            1'b1,                           // turn checking of transfers ON/OFF
19395
            ok_wb                           // succeeded/failed
19396
        ) ;
19397
 
19398
        if ( ok_wb === 1 )
19399
        begin
19400
 
19401
            wb_transaction_progress_monitor
19402
            (
19403
                Target_Base_Addr_R[1] + 128,    // expected address
19404
                1'b1,                           // expected operation R/W
19405
                1,                              // expected number of transfers
19406
                1'b1,                           // turn checking of transfers ON/OFF
19407
                ok_wb                           // succeeded/failed
19408
            ) ;
19409
        end
19410
 
19411
        @(posedge pci_clock) ;
19412
        #1 ;
19413
        disable pci_error_mon1 ;
19414
    end
19415
    begin:pci_error_mon1
19416
        ok_pci = 1 ;
19417
        @(error_event_int) ;
19418
        ok_pci = 0 ;
19419
    end
19420
    join
19421
 
19422
    if ( ok_wb !== 1'b1 )
19423
    begin
19424
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19425
    end
19426
 
19427
    if ( ok_pci !== 1'b1)
19428
    begin
19429
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19430
    end
19431
 
19432
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19433
    begin
19434
        #1 ;
19435
        disable main ;
19436
    end
19437
 
19438
    if ( test_mem )
19439
    begin
19440
        PCIU_MEM_READ
19441
        (
19442
            "MEM_READ  ",                   // description
19443
            `Test_Master_1,                 // behavioral master selection
19444
            Target_Base_Addr_R[1] + 64,     // address of access
19445
            32'hF0F0_F0F0,                  // expected read data
19446
            1,                              // number of transfers
19447
            8'h7_0,                         // don't care (wait cycles)
19448
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19449
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19450
            `Test_Target_Retry_On           // expected Target termination
19451
        );
19452
    end
19453
    else
19454
    begin
19455
        PCIU_IO_READ
19456
        (
19457
            `Test_Master_1,                 // behavioral master selection
19458
            Target_Base_Addr_R[1] + 64,     // address of access
19459
            32'hF0F0_F0F0,                  // expected read data
19460
            4'h0,                           // byte enables
19461
            1,                              // number of transfers
19462
            `Test_Target_Retry_On           // expected target termination
19463
        ) ;
19464
    end
19465
 
19466
    wb_transaction_progress_monitor
19467
    (
19468
            Target_Base_Addr_R[1] + 64,     // expected address
19469
            1'b0,                           // expected operation R/W
19470
            1,                              // expected number transfers
19471
            1'b1,                           // turn checking of transfers ON/OFF
19472
            ok_wb                           // succeeded/failed
19473
    ) ;
19474
 
19475
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19476
    repeat(3)
19477
        @(posedge pci_clock) ;
19478
 
19479
    // now read data
19480
    fork
19481
    begin
19482
        if ( test_mem )
19483
        begin
19484
            PCIU_MEM_READ
19485
            (
19486
                "MEM_READ  ",                   // description
19487
                `Test_Master_1,                 // behavioral master selection
19488
                Target_Base_Addr_R[1] + 64,     // address of access
19489
                32'hF0F0_F0F0,                  // expected read data
19490
                1,                              // number of transfers
19491
                8'h7_0,                         // don't care (wait cycles)
19492
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19493
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19494
                `Test_Target_Normal_Completion  // expected Target termination
19495
            );
19496
        end
19497
        else
19498
        begin
19499
            PCIU_IO_READ
19500
            (
19501
                `Test_Master_1,                 // behavioral master selection
19502
                Target_Base_Addr_R[1] + 64,     // address of access
19503
                32'hF0F0_F0F0,                  // expected read data
19504
                4'h0,                           // byte enables
19505
                1,                              // number of transfers
19506
                `Test_Target_Normal_Completion  // expected target termination
19507
            ) ;
19508
        end
19509
 
19510
        @(posedge pci_clock) ;
19511
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19512
            @(posedge pci_clock) ;
19513
 
19514
        @(posedge pci_clock) ;
19515
        #1 ;
19516
        disable pci_error_mon2 ;
19517
    end
19518
    begin:pci_error_mon2
19519
        ok_pci = 1 ;
19520
        @(error_event_int) ;
19521
        ok_pci = 0 ;
19522
    end
19523
    join
19524
 
19525
    if ( ok_wb !== 1'b1 )
19526
    begin
19527
        test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
19528
    end
19529
 
19530
    if ( ok_pci !== 1'b1)
19531
    begin
19532
        test_fail("PCI Behavioral Master or Monitor signaled an error during write to PCI Bridge Target") ;
19533
    end
19534
 
19535
    if ((ok_pci !== 1'b1) || (ok_wb !== 1'b1))
19536
    begin
19537
        #1 ;
19538
        disable main ;
19539
    end
19540
 
19541
    if ( test_mem )
19542
    begin
19543
        PCIU_MEM_READ
19544
        (
19545
            "MEM_READ  ",                   // description
19546
            `Test_Master_1,                 // behavioral master selection
19547
            Target_Base_Addr_R[1] + 128,    // address of access
19548
            32'h0F0F_0F0F,                  // expected read data
19549
            1,                              // number of transfers
19550
            8'h7_0,                         // don't care (wait cycles)
19551
            `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19552
            `Test_Devsel_Medium,            // expected Target DEVSEL speed
19553
            `Test_Target_Retry_On           // expected Target termination
19554
        );
19555
    end
19556
    else
19557
    begin
19558
        PCIU_IO_READ
19559
        (
19560
            `Test_Master_1,                 // behavioral master selection
19561
            Target_Base_Addr_R[1] + 128,    // address of access
19562
            32'h0F0F_0F0F,                  // expected read data
19563
            4'h0,                           // byte enables
19564
            1,                              // number of transfers
19565
            `Test_Target_Retry_On           // expected target termination
19566
        ) ;
19567
    end
19568
 
19569
    wb_transaction_progress_monitor
19570
    (
19571
            Target_Base_Addr_R[1] + 128,    // expected address
19572
            1'b0,                           // expected operation R/W
19573
            1,                              // expected number transfers
19574
            1'b1,                           // turn checking of transfers ON/OFF
19575
            ok_wb                           // succeeded/failed
19576
    ) ;
19577
 
19578
    // wait for 3 pci cycles for delayed read to become available in pci clock domain
19579
    repeat(3)
19580
        @(posedge pci_clock) ;
19581
 
19582
    // now read data
19583
    fork
19584
    begin
19585
        if ( test_mem )
19586
        begin
19587
            PCIU_MEM_READ
19588
            (
19589
                "MEM_READ  ",                   // description
19590
                `Test_Master_1,                 // behavioral master selection
19591
                Target_Base_Addr_R[1] + 128,    // address of access
19592
                32'h0F0F_0F0F,                  // expected read data
19593
                1,                              // number of transfers
19594
                8'h7_0,                         // don't care (wait cycles)
19595
                `Test_One_Zero_Target_WS,       // expected Target Wait Cycles
19596
                `Test_Devsel_Medium,            // expected Target DEVSEL speed
19597
                `Test_Target_Normal_Completion  // expected Target termination
19598
            );
19599
        end
19600
        else
19601
        begin
19602
            PCIU_IO_READ
19603
            (
19604
                `Test_Master_1,                 // behavioral master selection
19605
                Target_Base_Addr_R[1] + 128,    // address of access
19606
                32'h0F0F_0F0F,                  // expected read data
19607
                4'h0,                           // byte enables
19608
                1,                              // number of transfers
19609
                `Test_Target_Normal_Completion  // expected target termination
19610
            ) ;
19611
        end
19612
 
19613
        @(posedge pci_clock) ;
19614
        while (FRAME !== 1'b1 || IRDY !== 1'b1)
19615
            @(posedge pci_clock) ;
19616
 
19617
        @(posedge pci_clock) ;
19618
        #1 ;
19619
        disable pci_error_mon3 ;
19620
    end
19621
    begin:pci_error_mon3
19622
        ok_pci = 1 ;
19623
        @(error_event_int) ;
19624
        ok_pci = 0 ;
19625
    end
19626
    join
19627
 
19628
    if ((ok_wb === 1'b1) && (ok_pci === 1'b1))
19629
        test_ok ;
19630
 
19631
    if ( ok_wb !== 1'b1 )
19632
    begin
19633
        test_fail("WB Master started invalid transaction or none at all after Target read was requested") ;
19634
    end
19635
 
19636
    if ( ok_pci !== 1'b1)
19637
    begin
19638
        test_fail("PCI Behavioral Master or Monitor signaled an error during read from PCI Bridge Target") ;
19639
    end
19640
 
19641
    master1_check_received_data = master_check_data_previous ;
19642
end
19643
endtask // target_special_corner_case_test
19644
`endif
19645
 
19646 15 mihad
task test_fail ;
19647
    input [7999:0] failure_reason ;
19648
    reg   [8007:0] display_failure ;
19649
    reg   [799:0] display_test ;
19650
begin
19651
    tests_failed = tests_failed + 1 ;
19652
 
19653
    display_failure = {failure_reason, "!"} ;
19654
    while ( display_failure[7999:7992] == 0 )
19655
        display_failure = display_failure << 8 ;
19656
 
19657
    display_test = test_name ;
19658
    while ( display_test[799:792] == 0 )
19659
       display_test = display_test << 8 ;
19660
 
19661 63 mihad
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19662 15 mihad
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
19663
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
19664
    $fdisplay( tb_log_file, " *FAILED* because") ;
19665
    $fdisplay( tb_log_file, " %s", display_failure ) ;
19666 63 mihad
    current_test_parameters ;
19667
    $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19668 15 mihad
    $fdisplay( tb_log_file, " " ) ;
19669
 
19670
    `ifdef STOP_ON_FAILURE
19671
    #20 $stop ;
19672
    `endif
19673
end
19674
endtask // test_fail
19675
 
19676
task test_ok ;
19677
    reg [799:0] display_test ;
19678
begin
19679
   tests_successfull = tests_successfull + 1 ;
19680
 
19681
   display_test = test_name ;
19682
   while ( display_test[799:792] == 0 )
19683
       display_test = display_test << 8 ;
19684
 
19685 63 mihad
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19686 15 mihad
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
19687
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
19688
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
19689 63 mihad
   current_test_parameters ;
19690
   $fdisplay( tb_log_file, "************************************************************************************************************************************************************" ) ;
19691 15 mihad
   $fdisplay( tb_log_file, " " ) ;
19692
end
19693
endtask // test_ok
19694
 
19695
task test_summary;
19696
begin
19697 63 mihad
    $fdisplay(tb_log_file, "\n \n");
19698 15 mihad
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19699
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
19700
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
19701
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
19702
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19703
    $fclose(tb_log_file) ;
19704
end
19705
endtask
19706
 
19707 63 mihad
task current_test_parameters ;
19708
    reg [87:0] decode_speed_text ;
19709
begin
19710
    case (tb_target_decode_speed)
19711
        3'b000: decode_speed_text = "FAST       " ;
19712
        3'b001: decode_speed_text = "MEDIUM     " ;
19713
        3'b010: decode_speed_text = "SLOW       " ;
19714
        3'b011: decode_speed_text = "SUBTRACTIVE" ;
19715
    endcase
19716
 
19717
    $fdisplay( tb_log_file, "TEST PARAMETERS:") ;
19718
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Initial Wait States         = %d", (3'd4 - tb_init_waits)) ;
19719
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' Subsequent Wait States      = %d", (3'd4 - tb_subseq_waits)) ;
19720
    $fdisplay( tb_log_file, "  - PCI Behavioral Devices' DEVSEL speed                = %s", decode_speed_text) ;
19721
 
19722
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Initial Wait States    = %d", tb_init_waits) ;
19723
    $fdisplay( tb_log_file, "  - WISHBONE Behavioral Devices' Subsequent Wait States = %d", tb_subseq_waits) ;
19724
end
19725
endtask
19726
 
19727 15 mihad
endmodule

powered by: WebSVN 2.1.0

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