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

Subversion Repositories pci

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

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 62 mihad
// Revision 1.8  2002/09/25 09:54:47  mihad
43
// Added completion expiration test for WB Slave unit. Changed expiration signalling
44
//
45 57 mihad
// Revision 1.7  2002/08/22 09:20:16  mihad
46
// Oops, never before noticed that OC header is missing
47 52 mihad
//
48 57 mihad
//
49 52 mihad
 
50 15 mihad
`include "pci_constants.v"
51
`include "bus_commands.v"
52
`include "pci_testbench_defines.v"
53
`include "timescale.v"
54
 
55 51 mihad
`ifdef HOST
56
    `ifdef NO_CNF_IMAGE
57
    `else
58
        `define TEST_CONF_CYCLE_TYPE1_REFERENCE
59
    `endif
60
`else
61
    `define TEST_CONF_CYCLE_TYPE1_REFERENCE
62
`endif
63
 
64 15 mihad
module SYSTEM ;
65
 
66
`include "pci_blue_constants.vh"
67
`include "pci_blue_options.vh"
68
 
69
integer tests_successfull ;
70
integer tests_failed ;
71
integer tb_log_file ;
72
reg [799:0] test_name ;
73
 
74
reg pci_clock ;
75
reg wb_clock ;
76
reg reset ;
77
 
78
wire [4:0] arb_grant_out ;
79
 
80
wire [31:0] AD ;
81
wire [3:0]  CBE ;
82
pullup(INTA) ;
83
pullup(MAS0_REQ) ;
84
pullup(MAS1_REQ) ;
85
pullup(MAS2_REQ) ;
86
pullup(MAS3_REQ) ;
87
 
88
wire MAS0_GNT = ~arb_grant_out[0];
89
wire MAS1_GNT = ~arb_grant_out[1] ;
90
wire MAS2_GNT = ~arb_grant_out[2] ;
91
wire MAS3_GNT = ~arb_grant_out[3] ;
92
 
93
pullup(FRAME) ;
94
pullup(IRDY) ;
95 45 mihad
 
96
wire        TAR0_IDSEL = AD[`TAR0_IDSEL_INDEX] ;
97
 
98 15 mihad
pullup(DEVSEL) ;
99
pullup(TRDY) ;
100
pullup(STOP) ;
101
wire   PAR ;
102
pullup(PERR) ;
103
pullup(SERR) ;
104
wire [3:0] MAS1_IDSEL ;
105
 
106
pullup lockpu ( LOCK ) ;
107
 
108
wire        RST_O ;
109
wire        INT_O ;
110
reg         INT_I ;
111
wire [31:0] ADR_I ;
112
wire [31:0] SDAT_I ;
113
wire [31:0] SDAT_O ;
114
wire [3:0]  SEL_I ;
115
wire        CYC_I ;
116
wire        STB_I ;
117
wire        WE_I ;
118
wire        CAB_I ;
119
wire        ACK_O ;
120
wire        RTY_O ;
121
wire        ERR_O ;
122
 
123
wire [31:0] ADR_O ;
124
wire [31:0] MDAT_I ;
125
wire [31:0] MDAT_O ;
126
wire [3:0]  SEL_O ;
127
wire        CYC_O ;
128
wire        STB_O ;
129
wire        WE_O ;
130
wire        CAB_O ;
131
wire        ACK_I ;
132
wire        RTY_I ;
133
wire        ERR_I ;
134
 
135 45 mihad
wire        TAR1_IDSEL = AD[`TAR1_IDSEL_INDEX] ;
136
 
137
wire        TAR2_IDSEL = AD[`TAR2_IDSEL_INDEX] ;
138
 
139 15 mihad
wire        reset_wb ; // reset to Wb devices
140
 
141 62 mihad
`ifdef PCI_BIST
142
wire SO ;
143
reg  SI ;
144
reg  shift_DR ;
145
reg  capture_DR ;
146
reg  extest ;
147
reg  tck ;
148
`endif
149
 
150 15 mihad
`ifdef GUEST
151
    wire    RST = ~reset ;
152
    assign  reset_wb = RST_O ;
153
`else
154
    pullup(RST) ;
155
    assign  reset_wb = reset ;
156
`endif
157
 
158
`define PCI_BRIDGE_INSTANCE bridge32_top
159
 
160
TOP `PCI_BRIDGE_INSTANCE
161
(
162
    .CLK    ( pci_clock),
163
    .AD     ( AD ),
164
    .CBE    ( CBE ),
165
    .RST    ( RST ),
166
    .INTA   ( INTA ),
167
    .REQ    ( MAS0_REQ ),
168
    .GNT    ( MAS0_GNT ),
169
    .FRAME  ( FRAME ),
170
    .IRDY   ( IRDY ),
171
    .IDSEL  ( TAR0_IDSEL),
172
    .DEVSEL ( DEVSEL ),
173
    .TRDY   ( TRDY ),
174
    .STOP   ( STOP ),
175
    .PAR    ( PAR ),
176
    .PERR   ( PERR ),
177
    .SERR   ( SERR ),
178
 
179
    .CLK_I  ( wb_clock ),
180
    .RST_I  ( reset ),
181
    .RST_O  ( RST_O ),
182
    .INT_I  ( INT_I ),
183
    .INT_O  ( INT_O ),
184
 
185
    // WISHBONE slave interface
186
    .ADR_I  ( ADR_I ),
187
    .SDAT_I ( SDAT_I ),
188
    .SDAT_O ( SDAT_O ),
189
    .SEL_I  ( SEL_I ),
190
    .CYC_I  ( CYC_I ),
191
    .STB_I  ( STB_I ),
192
    .WE_I   ( WE_I ),
193
    .CAB_I  ( CAB_I),
194
    .ACK_O  ( ACK_O ),
195
    .RTY_O  ( RTY_O ),
196
    .ERR_O  ( ERR_O ),
197
 
198
    // WISHBONE master interface
199
    .ADR_O  ( ADR_O ),
200
    .MDAT_I ( MDAT_I ),
201
    .MDAT_O ( MDAT_O ),
202
    .SEL_O  ( SEL_O ),
203
    .CYC_O  ( CYC_O ),
204
    .STB_O  ( STB_O ),
205
    .WE_O   ( WE_O ),
206
    .CAB_O  ( CAB_O ),
207
    .ACK_I  ( ACK_I ),
208
    .RTY_I  ( RTY_I ),
209
    .ERR_I  ( ERR_I )
210 62 mihad
 
211
`ifdef PCI_BIST
212
    ,
213
    .SO         (SO),
214
    .SI         (SI),
215
    .shift_DR   (shift_DR),
216
    .capture_DR (capture_DR),
217
    .extest     (extest),
218
    .tck        (tck)
219
`endif
220 15 mihad
) ;
221
 
222
WB_MASTER_BEHAVIORAL wishbone_master
223
(
224
    .CLK_I(wb_clock),
225
    .RST_I(reset_wb),
226
    .TAG_I(4'b0000),
227
    .TAG_O(),
228
    .ACK_I(ACK_O),
229
    .ADR_O(ADR_I),
230
    .CYC_O(CYC_I),
231
    .DAT_I(SDAT_O),
232
    .DAT_O(SDAT_I),
233
    .ERR_I(ERR_O),
234
    .RTY_I(RTY_O),
235
    .SEL_O(SEL_I),
236
    .STB_O(STB_I),
237
    .WE_O (WE_I),
238
    .CAB_O(CAB_I)
239
);
240
 
241
WB_SLAVE_BEHAVIORAL wishbone_slave
242
(
243
    .CLK_I              (wb_clock),
244
    .RST_I              (reset_wb),
245
    .ACK_O              (ACK_I),
246
    .ADR_I              (ADR_O),
247
    .CYC_I              (CYC_O),
248
    .DAT_O              (MDAT_I),
249
    .DAT_I              (MDAT_O),
250
    .ERR_O              (ERR_I),
251
    .RTY_O              (RTY_I),
252
    .SEL_I              (SEL_O),
253
    .STB_I              (STB_O),
254
    .WE_I               (WE_O),
255
    .CAB_I              (CAB_O)
256
);
257
 
258
integer wbu_mon_log_file_desc ;
259
integer pciu_mon_log_file_desc ;
260
WB_BUS_MON wbu_wb_mon(
261
                    .CLK_I(wb_clock),
262
                    .RST_I(reset_wb),
263
                    .ACK_I(ACK_O),
264
                    .ADDR_O(ADR_I),
265
                    .CYC_O(CYC_I),
266
                    .DAT_I(SDAT_O),
267
                    .DAT_O(SDAT_I),
268
                    .ERR_I(ERR_O),
269
                    .RTY_I(RTY_O),
270
                    .SEL_O(SEL_I),
271
                    .STB_O(STB_I),
272
                    .WE_O (WE_I),
273
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
274
                    .TAG_O(),
275
                    .CAB_O(CAB_I),
276
                    .log_file_desc ( wbu_mon_log_file_desc )
277
                  ) ;
278
 
279
WB_BUS_MON pciu_wb_mon(
280
                    .CLK_I(wb_clock),
281
                    .RST_I(reset_wb),
282
                    .ACK_I(ACK_I),
283
                    .ADDR_O(ADR_O),
284
                    .CYC_O(CYC_O),
285
                    .DAT_I(MDAT_I),
286
                    .DAT_O(MDAT_O),
287
                    .ERR_I(ERR_I),
288
                    .RTY_I(RTY_I),
289
                    .SEL_O(SEL_O),
290
                    .STB_O(STB_O),
291
                    .WE_O (WE_O),
292
                    .TAG_I({`WB_TAG_WIDTH{1'b0}}),
293
                    .TAG_O(),
294
                    .CAB_O(CAB_O),
295
                    .log_file_desc( pciu_mon_log_file_desc )
296
                  ) ;
297
 
298
// some aditional signals are needed here because of the arbiter
299
reg [3:0] pci_ext_req_prev ;
300
always@(posedge pci_clock)
301
begin
302
    pci_ext_req_prev <= {~MAS3_REQ, ~MAS2_REQ, ~MAS1_REQ, ~MAS0_REQ} ;
303
end
304
reg pci_frame_prev ;
305
always@(posedge pci_clock)
306
begin
307
    pci_frame_prev <= FRAME ;
308
end
309
reg pci_irdy_prev ;
310
always@(posedge pci_clock)
311
begin
312
    pci_irdy_prev <= IRDY ;
313
end
314
 
315
pci_blue_arbiter pci_arbiter
316
(
317
  .pci_int_req_direct(1'b0),
318
  .pci_ext_req_prev(pci_ext_req_prev),
319
  .pci_int_gnt_direct_out(arb_grant_out[4]),
320
  .pci_ext_gnt_direct_out(arb_grant_out[3:0]),
321
  .pci_frame_prev(~pci_frame_prev),
322
  .pci_irdy_prev(~pci_irdy_prev),
323
  .pci_irdy_now(~IRDY),
324
  .arbitration_enable(1'b1),
325
  .pci_clk(pci_clock),
326
  .pci_reset_comb(~RST)
327
);
328
 
329
reg [31:0] target_message ;
330
 
331
// define output enable signals for monitor inputs
332
// real output enable signals
333
//{frame_oe, irdy_oe, devsel_t_s_oe, ad_oe, cbe_oe, perr_oe}
334
`ifdef ACTIVE_LOW_OE
335
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en && `PCI_BRIDGE_INSTANCE.TRDY_en && `PCI_BRIDGE_INSTANCE.STOP_en ;
336
wire ad_oe         = &(`PCI_BRIDGE_INSTANCE.AD_en) ;
337
wire cbe_oe        = &(`PCI_BRIDGE_INSTANCE.CBE_en) ;
338
wire [5:0] r_oe_sigs = {!`PCI_BRIDGE_INSTANCE.FRAME_en,
339
                        !`PCI_BRIDGE_INSTANCE.IRDY_en,
340
                        !devsel_t_s_oe,
341
                        !ad_oe,
342
                        !cbe_oe,
343
                        !`PCI_BRIDGE_INSTANCE.PERR_en}
344
                        ;
345
`else
346
`ifdef ACTIVE_HIGH_OE
347
wire devsel_t_s_oe = `PCI_BRIDGE_INSTANCE.DEVSEL_en || `PCI_BRIDGE_INSTANCE.TRDY_en || `PCI_BRIDGE_INSTANCE.STOP_en ;
348
wire ad_oe         = |(`PCI_BRIDGE_INSTANCE.AD_en) ;
349
wire cbe_oe        = |(`PCI_BRIDGE_INSTANCE.CBE_en) ;
350
wire [5:0] r_oe_sigs = {`PCI_BRIDGE_INSTANCE.FRAME_en,
351
                        `PCI_BRIDGE_INSTANCE.IRDY_en,
352
                        devsel_t_s_oe,
353
                        ad_oe,
354
                        cbe_oe,
355
                        `PCI_BRIDGE_INSTANCE.PERR_en}
356
                        ;
357
`endif
358
`endif
359
/*wire [5:0] oe_sigs_0 = {1'b0,
360
                        1'b0,
361
                        pci_target32.ctl_enable | pci_target32.r_ctl_enable,
362
                        pci_target32.ad_enable,
363
                        1'b0,
364
                        pci_target32.err_enable | pci_target32.r_err_enable
365
                       } ;
366
*/
367
 
368
wire [5:0] oe_sigs_2 ;
369
wire [5:0] oe_sigs_1 ;
370
 
371
// signals which are used by test modules to know what to do
372
triand  test_accepted_l_int, error_event_int;
373
pullup  (test_accepted_l_int), (error_event_int);
374
 
375
wire    pci_reset_comb  = ~RST;
376
wire    pci_ext_clk     = pci_clock;
377
 
378
integer pci_mon_log_file_desc ;
379
pci_bus_monitor monitor32
380
(
381
    .pci_ext_ad                 (AD),
382
    .pci_ext_cbe_l              (CBE),
383
    .pci_ext_par                (PAR),
384
    .pci_ext_frame_l            (FRAME),
385
    .pci_ext_irdy_l             (IRDY),
386
    .pci_ext_devsel_l           (DEVSEL),
387
    .pci_ext_trdy_l             (TRDY),
388
    .pci_ext_stop_l             (STOP),
389
    .pci_ext_perr_l             (PERR),
390
    .pci_ext_serr_l             (SERR),
391
    .pci_real_req_l             (MAS0_REQ),
392
    .pci_real_gnt_l             (MAS0_GNT),
393
    .pci_ext_req_l              ({1'b1, MAS3_REQ, MAS2_REQ, MAS1_REQ}),
394
    .pci_ext_gnt_l              (~arb_grant_out[4:1]),
395
    .test_error_event           (error_event_int),
396
    .test_observe_r_oe_sigs     (r_oe_sigs),
397
    .test_observe_0_oe_sigs     (6'h00),
398
    .test_observe_1_oe_sigs     (oe_sigs_1),
399
    .test_observe_2_oe_sigs     (oe_sigs_2),
400
    .test_observe_3_oe_sigs     (6'h00),
401
    .pci_ext_reset_l            (RST),
402
    .pci_ext_clk                (pci_clock),
403
    .log_file_desc              (pci_mon_log_file_desc)
404
) ;
405
 
406
reg [2:0]  test_master_number ;
407
reg [31:0] test_address ;
408
reg [3:0]  test_command ;
409
reg [31:0] test_data ;
410
reg [3:0]  test_byte_enables_l ;
411
reg [9:0]  test_size ;
412
reg        test_make_addr_par_error ;
413
reg        test_make_data_par_error ;
414
reg [3:0]  test_master_initial_wait_states ;
415
reg [3:0]  test_master_subsequent_wait_states ;
416
reg [3:0]  test_target_initial_wait_states ;
417
reg [3:0]  test_target_subsequent_wait_states ;
418
reg [1:0]  test_target_devsel_speed ;
419
reg        test_fast_back_to_back ;
420
reg [2:0]  test_target_termination ;
421
reg        test_expect_master_abort ;
422
reg        test_start ;
423
reg [25:0] test_target_response ;
424
 
425
wire [31:0] master2_received_data ;
426
wire        master2_received_data_valid ;
427
reg         master2_check_received_data ;
428
pci_behaviorial_device pci_behaviorial_device2
429
(
430
    .pci_ext_ad(AD),
431
    .pci_ext_cbe_l(CBE),
432
    .pci_ext_par(PAR),
433
    .pci_ext_frame_l(FRAME),
434
    .pci_ext_irdy_l(IRDY),
435
    .pci_ext_devsel_l(DEVSEL),
436
    .pci_ext_trdy_l(TRDY),
437
    .pci_ext_stop_l(STOP),
438
    .pci_ext_perr_l(PERR),
439
    .pci_ext_serr_l(SERR),
440
    .pci_ext_idsel(TAR2_IDSEL),
441
    .pci_ext_inta_l(INTA),
442
    .pci_ext_req_l(MAS2_REQ),
443
    .pci_ext_gnt_l(MAS2_GNT),
444
    .pci_ext_reset_l(RST),
445
    .pci_ext_clk(pci_clock),
446
 
447
// Signals used by the test bench instead of using "." notation
448
    .test_observe_oe_sigs               (oe_sigs_2[5:0]),               //
449
    .test_master_number                 (test_master_number[2:0]),
450
    .test_address                       (test_address[PCI_BUS_DATA_RANGE:0]),
451
    .test_command                       (test_command[3:0]),
452
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
453
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
454
    .test_size                          (test_size),
455
    .test_make_addr_par_error           (test_make_addr_par_error),
456
    .test_make_data_par_error           (test_make_data_par_error),
457
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
458
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
459
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
460
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
461
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
462
    .test_fast_back_to_back             (test_fast_back_to_back),
463
    .test_target_termination            (test_target_termination[2:0]),
464
    .test_expect_master_abort           (test_expect_master_abort),
465
    .test_start                         (test_start),
466
    .test_accepted_l                    (test_accepted_l_int),
467
    .test_error_event                   (error_event_int),
468
    .test_device_id                     (`Test_Master_2),
469
    .test_target_response               (test_target_response),
470
 
471
    .master_received_data               (master2_received_data),
472
    .master_received_data_valid         (master2_received_data_valid),
473
    .master_check_received_data         (master2_check_received_data)
474
);
475
 
476
wire [31:0] master1_received_data ;
477
wire        master1_received_data_valid ;
478
reg         master1_check_received_data ;
479
pci_behaviorial_device pci_behaviorial_device1
480
(
481
    .pci_ext_ad(AD),
482
    .pci_ext_cbe_l(CBE),
483
    .pci_ext_par(PAR),
484
    .pci_ext_frame_l(FRAME),
485
    .pci_ext_irdy_l(IRDY),
486
    .pci_ext_devsel_l(DEVSEL),
487
    .pci_ext_trdy_l(TRDY),
488
    .pci_ext_stop_l(STOP),
489
    .pci_ext_perr_l(PERR),
490
    .pci_ext_serr_l(SERR),
491
    .pci_ext_idsel(TAR1_IDSEL),
492
    .pci_ext_inta_l(INTA),
493
    .pci_ext_req_l(MAS1_REQ),
494
    .pci_ext_gnt_l(MAS1_GNT),
495
    .pci_ext_reset_l(RST),
496
    .pci_ext_clk(pci_clock),
497
 
498
// Signals used by the test bench instead of using "." notation
499
    .test_observe_oe_sigs           (oe_sigs_1[5:0]),               //
500
    .test_master_number                 (test_master_number[2:0]),
501
    .test_address                               (test_address[PCI_BUS_DATA_RANGE:0]),
502
    .test_command                       (test_command[3:0]),
503
    .test_data                          (test_data[PCI_BUS_DATA_RANGE:0]),
504
    .test_byte_enables_l                (test_byte_enables_l[PCI_BUS_CBE_RANGE:0]),
505
    .test_size                          (test_size),
506
    .test_make_addr_par_error           (test_make_addr_par_error),
507
    .test_make_data_par_error           (test_make_data_par_error),
508
    .test_master_initial_wait_states    (test_master_initial_wait_states[3:0]),
509
    .test_master_subsequent_wait_states (test_master_subsequent_wait_states[3:0]),
510
    .test_target_initial_wait_states    (test_target_initial_wait_states[3:0]),
511
    .test_target_subsequent_wait_states (test_target_subsequent_wait_states[3:0]),
512
    .test_target_devsel_speed           (test_target_devsel_speed[1:0]),
513
    .test_fast_back_to_back             (test_fast_back_to_back),
514
    .test_target_termination            (test_target_termination[2:0]),
515
    .test_expect_master_abort           (test_expect_master_abort),
516
    .test_start                         (test_start),
517
    .test_accepted_l                    (test_accepted_l_int),
518
    .test_error_event                   (error_event_int),
519
    .test_device_id                     (`Test_Master_1),
520
    .test_target_response               (test_target_response),
521
 
522
    .master_received_data               (master1_received_data),
523
    .master_received_data_valid         (master1_received_data_valid),
524
    .master_check_received_data         (master1_check_received_data)
525
);
526
 
527
pci_unsupported_commands_master ipci_unsupported_commands_master
528
(
529
    .CLK    ( pci_clock),
530
    .AD     ( AD ),
531
    .CBE    ( CBE ),
532
    .RST    ( RST ),
533
    .REQ    ( MAS3_REQ ),
534
    .GNT    ( MAS3_GNT ),
535
    .FRAME  ( FRAME ),
536
    .IRDY   ( IRDY ),
537
    .DEVSEL ( DEVSEL ),
538
    .TRDY   ( TRDY ),
539
    .STOP   ( STOP ),
540
    .PAR    ( PAR )
541
) ;
542
 
543 45 mihad
`ifdef HOST
544
 
545
reg     [1:0]   conf_cyc_type1_target_response ;
546
reg     [31:0]  conf_cyc_type1_target_data ;
547
reg     [7:0]   conf_cyc_type1_target_bus_num ;
548
wire    [31:0]  conf_cyc_type1_target_data_from_PCI ;
549
 
550
pci_behavioral_pci2pci_bridge i_pci_behavioral_pci2pci_bridge
551
(
552
    .CLK              ( pci_clock),
553
    .AD               ( AD ),
554
    .CBE              ( CBE ),
555
    .RST              ( RST ),
556
    .FRAME            ( FRAME ),
557
    .IRDY             ( IRDY ),
558
    .DEVSEL           ( DEVSEL ),
559
    .TRDY             ( TRDY ),
560
    .STOP             ( STOP ),
561
    .PAR              ( PAR ),
562
 
563
    .response         ( conf_cyc_type1_target_response ),
564
    .data_out         ( conf_cyc_type1_target_data ),
565
    .data_in          ( conf_cyc_type1_target_data_from_PCI ),
566
    .devsel_speed     ( test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] ),
567
    .wait_states      ( test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] ),
568
    .bus_number       ( conf_cyc_type1_target_bus_num )
569
);
570
`endif
571
 
572 15 mihad
// pci clock generator
573
always
574
`ifdef PCI33
575
    #15 pci_clock = ~pci_clock ;
576
`else
577
`ifdef PCI66
578
    #7.5 pci_clock = ~pci_clock ;
579
`endif
580
`endif
581
 
582
// WISHBONE clock generation
583
always
584
    #(((1/`WB_FREQ)/2)) wb_clock = ~wb_clock ;
585
 
586
// Make test name visible when the Master starts working on it
587
reg     [79:0] present_test_name;
588
reg     [79:0] next_test_name;
589
wire    test_accepted = ~test_accepted_l_int;
590
always @(posedge test_accepted)
591
begin
592
    present_test_name <= next_test_name;
593
end
594
 
595
reg [31:0] wmem_data [0:1023] ; // data for memory mapped image writes
596
reg [31:0] wio_data  [0:1023] ; // data for IO mapped image writes
597
 
598
// basic configuration parameters for both behavioral devices
599
parameter [2:0] Master_ID_A                           = `Test_Master_1;
600
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_A = `TAR2_IDSEL_ADDR;
601
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A0  = `BEH_TAR2_MEM_START;
602
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_A1  = `BEH_TAR2_IO_START;
603
 
604
parameter [2:0] Master_ID_B                           = `Test_Master_2;
605
parameter [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_B = `TAR1_IDSEL_ADDR;
606
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B0  = `BEH_TAR1_MEM_START;
607
parameter [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_B1  = `BEH_TAR1_IO_START;
608
 
609
// basic configuration parameters for REAL device
610
reg [PCI_BUS_DATA_RANGE:0] Target_Config_Addr_R ;
611
reg [PCI_BUS_DATA_RANGE:0] Target_Base_Addr_R [0:5];
612
reg [PCI_BUS_DATA_RANGE:0] Target_Addr_Mask_R [0:5];
613
reg [PCI_BUS_DATA_RANGE:0] Target_Tran_Addr_R [0:5];
614
 
615
// reg  [2:0]   ack_err_rty_termination ;
616
// reg          wait_cycles ;
617
// reg  [7:0]   num_of_retries ;
618
 
619
//reg [19:0] pci_config_base ;
620
reg [7:0] system_burst_size ;
621
reg [7:0] bridge_latency ;
622
integer   target_mem_image ;
623
integer   target_io_image ;
624
 
625
initial
626
begin
627 62 mihad
 
628
`ifdef PCI_BIST
629
    SI          = 0 ;
630
    shift_DR    = 0 ;
631
    capture_DR  = 0 ;
632
    extest      = 0 ;
633
    tck         = 0 ;
634
`endif
635 15 mihad
    next_test_name[79:0] <= "Nowhere___";
636
    reset = 1'b1 ;
637
    pci_clock = 1'b0 ;
638
    wb_clock  = 1'b1 ;
639
    target_message = 32'h0000_0000 ;
640
//  num_of_retries = 8'h01 ;
641
//  ack_err_rty_termination = 3'b100 ;
642
//  wait_cycles = 1'b0 ;
643
 
644
    // system paameters
645
    system_burst_size = 16 ;
646
    bridge_latency    = 8 ;
647
 
648
    // set initial values for controling the behavioral PCI master
649
    Target_Config_Addr_R  = `TAR0_IDSEL_ADDR ;
650
    Target_Base_Addr_R[0] = `TAR0_BASE_ADDR_0;
651
    Target_Base_Addr_R[1] = `TAR0_BASE_ADDR_1;
652
    Target_Base_Addr_R[2] = `TAR0_BASE_ADDR_2;
653
    Target_Base_Addr_R[3] = `TAR0_BASE_ADDR_3;
654
    Target_Base_Addr_R[4] = `TAR0_BASE_ADDR_4;
655
    Target_Base_Addr_R[5] = `TAR0_BASE_ADDR_5;
656
 
657
    Target_Addr_Mask_R[0] = `TAR0_ADDR_MASK_0;
658
    Target_Addr_Mask_R[1] = `TAR0_ADDR_MASK_1;
659
    Target_Addr_Mask_R[2] = `TAR0_ADDR_MASK_2;
660
    Target_Addr_Mask_R[3] = `TAR0_ADDR_MASK_3;
661
    Target_Addr_Mask_R[4] = `TAR0_ADDR_MASK_4;
662
    Target_Addr_Mask_R[5] = `TAR0_ADDR_MASK_5;
663
 
664
    Target_Tran_Addr_R[0] = `TAR0_TRAN_ADDR_0;
665
    Target_Tran_Addr_R[1] = `TAR0_TRAN_ADDR_1;
666
    Target_Tran_Addr_R[2] = `TAR0_TRAN_ADDR_2;
667
    Target_Tran_Addr_R[3] = `TAR0_TRAN_ADDR_3;
668
    Target_Tran_Addr_R[4] = `TAR0_TRAN_ADDR_4;
669
    Target_Tran_Addr_R[5] = `TAR0_TRAN_ADDR_5;
670
 
671
    test_master_number = `Test_Master_2 ;
672
    test_address = 32'h0000_0000 ;
673
    test_command = `BC_RESERVED0 ;
674
    test_data = 32'h0000_0000 ;
675
    test_byte_enables_l   = 4'hF ;
676
    test_size = 0 ;
677
    test_make_addr_par_error = 0 ;
678
    test_make_data_par_error = 0;
679
    test_master_initial_wait_states = 0 ;
680
    test_master_subsequent_wait_states = 0 ;
681
    test_target_initial_wait_states = 0 ;
682
    test_target_subsequent_wait_states = 0;
683
    test_target_devsel_speed = `Test_Devsel_Fast ;
684
    test_fast_back_to_back = 0 ;
685
    test_target_termination = `Test_Target_Normal_Completion ;
686
    test_expect_master_abort = 0 ;
687
    test_start = 0 ;
688
    test_target_response = 0 ;
689
 
690
    master1_check_received_data = 0 ;
691
    master2_check_received_data = 0 ;
692
 
693 45 mihad
    `ifdef HOST
694
        conf_cyc_type1_target_response = 0 ;
695
        conf_cyc_type1_target_data = 0 ;
696
        conf_cyc_type1_target_bus_num = 255 ;
697
    `endif
698 15 mihad
 
699
    // fill memory and IO data with random values
700
    fill_memory ;
701
 
702
    INT_I = 0 ;
703
 
704
    // extract from constants which target image can be used as IO and which as memory
705
    `ifdef HOST
706
        target_mem_image = 1 ;
707
        target_io_image  = 1 ;
708
    `else
709
        target_mem_image = -1 ;
710
        target_io_image     = -1 ;
711
        if ( `PCI_BA1_MEM_IO === 0 )
712
            target_mem_image = 1 ;
713
        else
714
            target_io_image = 1 ;
715
 
716
        if ( target_mem_image === -1 )
717
        begin
718
            `ifdef PCI_IMAGE2
719
                if ( `PCI_BA2_MEM_IO === 0 )
720
                    target_mem_image = 2 ;
721
                else if ( target_io_image === -1 )
722
                    target_io_image = 2 ;
723
            `endif
724
        end
725
 
726
        if ( target_mem_image === -1 )
727
        begin
728
            `ifdef PCI_IMAGE3
729
                if ( `PCI_BA3_MEM_IO === 0 )
730
                    target_mem_image = 3 ;
731
                else if ( target_io_image === -1 )
732
                    target_io_image = 3 ;
733
            `endif
734
        end
735
 
736
        if ( target_mem_image === -1 )
737
        begin
738
            `ifdef PCI_IMAGE4
739
                if ( `PCI_BA4_MEM_IO === 0 )
740
                    target_mem_image = 4 ;
741
                else if ( target_io_image === -1 )
742
                    target_io_image = 4 ;
743
            `endif
744
        end
745
 
746
        if ( target_mem_image === -1 )
747
        begin
748
            `ifdef PCI_IMAGE5
749
                if ( `PCI_BA5_MEM_IO === 0 )
750
                    target_mem_image = 5 ;
751
                else if ( target_io_image === -1 )
752
                    target_io_image = 5 ;
753
            `endif
754
        end
755
    `endif
756
 
757
    tests_successfull = 0 ;
758
    tests_failed = 0 ;
759
 
760
    tb_log_file = $fopen("../log/pci_tb.log") ;
761
 
762
    if ( tb_log_file < 2 )
763
    begin
764
        $display(" Could not open/create testbench log file in ../log/ directory! " ) ;
765
        $finish ;
766
    end
767
 
768
    $fdisplay( tb_log_file, "************************ PCI IP Core Testbench Test results ************************") ;
769
    $fdisplay( tb_log_file,"" ) ;
770
 
771
    wbu_mon_log_file_desc  = $fopen("../log/wbu_mon.log") ;
772
    pciu_mon_log_file_desc = $fopen("../log/pciu_mon.log") ;
773
 
774
    if ( (wbu_mon_log_file_desc < 2) || (pciu_mon_log_file_desc < 2 ) )
775
    begin
776
        $fdisplay(tb_log_file, "Could not open WISHBONE monitors' log files!") ;
777
        $finish ;
778
    end
779
 
780
    $fdisplay(wbu_mon_log_file_desc, "*********************************** Start WISHBONE Slave Bus Monitor log file *******************************************") ;
781
    $fdisplay(pciu_mon_log_file_desc, "*********************************** Start WISHBONE Master Bus Monitor log file ******************************************") ;
782
 
783
    pci_mon_log_file_desc = $fopen("../log/pci_mon.log") ;
784
    if ( pci_mon_log_file_desc < 2 )
785
    begin
786
        $fdisplay(tb_log_file, "Could not open PCI monitor's log file!") ;
787
        $finish ;
788
    end
789
 
790
    $fdisplay(pci_mon_log_file_desc, "*********************************** Start PCI Bus Monitor log file ******************************************") ;
791
 
792
    run_tests ;
793
end
794
 
795
task fill_memory ;
796
    integer temp_index ;
797
begin
798
    // fill write memories with random data
799
    for( temp_index = 0; temp_index <=1023; temp_index = temp_index + 1 )
800
    begin
801
        wmem_data[temp_index[9:0]] = $random ;
802 26 mihad
        # 1;
803 15 mihad
        wio_data[temp_index[9:0]]  = $random ;
804 26 mihad
        # 1;
805 15 mihad
    end
806
    // fill WB slave behavioral MEMORY
807
    for( temp_index = 0; temp_index <=65535; temp_index = temp_index + 1 )
808
    begin
809
        wishbone_slave.wb_memory[temp_index[15:0]] = $random ;
810
        # 1;
811
    end
812
end
813
endtask // fill_memory
814
 
815
reg [2:0] tb_init_waits ;
816
reg [2:0] tb_subseq_waits ;
817
reg [2:0] tb_target_decode_speed ;
818
 
819
task run_tests ;
820
begin
821
    // first - reset logic
822
    do_reset ;
823 62 mihad
 
824
    // if BIST is implemented, give it a go
825
`ifdef PCI_BIST
826
    run_bist_test ;
827
`endif
828 45 mihad
    test_initial_conf_values ;
829
 
830 15 mihad
    next_test_name[79:0] <= "Initing...";
831
    test_target_response[`TARGET_ENCODED_PARAMATERS_ENABLE] = 1 ;
832
 
833
    for ( tb_init_waits = 0 ; tb_init_waits <= 4 ; tb_init_waits = tb_init_waits + 1 )
834
    begin
835
        for ( tb_subseq_waits = 0 ; tb_subseq_waits <= 4 ; tb_subseq_waits = tb_subseq_waits + 1 )
836
        begin
837
 
838
            test_target_response[`TARGET_ENCODED_INIT_WAITSTATES] = 4 - tb_init_waits ;
839
            test_target_response[`TARGET_ENCODED_SUBS_WAITSTATES] = 4 - tb_subseq_waits ;
840
 
841
            for ( tb_target_decode_speed = 0 ; tb_target_decode_speed <= 3 ; tb_target_decode_speed = tb_target_decode_speed + 1 )
842
            begin
843
                test_target_response[`TARGET_ENCODED_DEVSEL_SPEED] = tb_target_decode_speed ;
844
 
845
                `ifdef HOST
846
                    configure_bridge_target ;
847
                    find_pci_devices ;
848 45 mihad
                    test_configuration_cycle_target_abort ;
849
                    test_configuration_cycle_type1_generation ;
850 15 mihad
                `endif
851
 
852
                @(posedge pci_clock) ;
853
                configure_target(1) ;
854
                @(posedge pci_clock) ;
855
                configure_target(2) ;
856
 
857
                `ifdef GUEST
858
                    configure_bridge_target ;
859
                `endif
860
 
861
               next_test_name[79:0] <= "WB_SLAVE..";
862
 
863
                $display("Testing WISHBONE slave images' features!") ;
864
                test_wb_image(1) ;
865
 
866
                `ifdef WB_IMAGE2
867
                    test_wb_image(2) ;
868
                `else
869
                    $display(" WB IMAGE 2 not implemented! ") ;
870
                `endif
871
 
872
                `ifdef WB_IMAGE3
873
                    test_wb_image(3) ;
874
                `else
875
                    $display(" WB IMAGE 3 not implemented! ") ;
876
                `endif
877
 
878
                `ifdef WB_IMAGE4
879
                    test_wb_image(4) ;
880
                `else
881
                    $display(" WB IMAGE 4 not implemented! ") ;
882
                `endif
883
 
884
                `ifdef WB_IMAGE5
885
                    test_wb_image(5) ;
886
                `else
887
                    $display(" WB IMAGE 5 not implemented! ") ;
888
                `endif
889
 
890
                wb_slave_errors ;
891
                wb_to_pci_error_handling ;
892
 
893
                parity_checking ;
894
 
895
                wb_to_pci_transactions ;
896
 
897
                `ifdef HOST
898
                iack_cycle ;
899
                `endif
900
 
901
            end
902 57 mihad
 
903
            master_completion_expiration ;
904
 
905 15 mihad
            $display(" ") ;
906
            $display("WB slave images' tests finished!") ;
907
 
908
            $display("########################################################################") ;
909
            $display("########################################################################") ;
910
            $display("||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||") ;
911
            $display("########################################################################") ;
912
            $display("########################################################################") ;
913
 
914
            $display("Testing PCI target images' features!") ;
915
            configure_bridge_target_base_addresses ;
916
 
917 51 mihad
            `ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
918
                test_conf_cycle_type1_reference ;
919
            `endif
920
 
921 15 mihad
            `ifdef HOST
922
             `ifdef NO_CNF_IMAGE
923
              `ifdef PCI_IMAGE0
924
            $display("PCI bridge implemented as HOST device, PCI image 0 implemented to access WB bus!") ;
925
            test_pci_image(0) ;
926
              `else
927
            $display("PCI bridge implemented as HOST device, P_BA0 NOT used (no access to Configuration space)!") ;
928
              `endif
929
             `else
930
            $display("PCI bridge implemented as HOST device, P_BA0 used for Read-only access to Configuration space!") ;
931
             `endif
932
            `endif
933
 
934
            $display("PCI image 1 is ALWAYS implemented!") ;
935
            test_pci_image(1) ;
936
 
937
            `ifdef PCI_IMAGE2
938
            $display("PCI image 2 is implemented!") ;
939
            test_pci_image(2) ;
940
            `else
941
            $display("PCI image 2 is NOT implemented!") ;
942
            `endif
943
 
944
            `ifdef PCI_IMAGE3
945
            $display("PCI image 3 is implemented!") ;
946
            test_pci_image(3) ;
947
            `else
948
            $display("PCI image 3 is NOT implemented!") ;
949
            `endif
950
 
951
            `ifdef PCI_IMAGE4
952
            $display("PCI image 4 is implemented!") ;
953
            test_pci_image(4) ;
954
            `else
955
            $display("PCI image 4 is NOT implemented!") ;
956
            `endif
957
 
958
            `ifdef PCI_IMAGE5
959
            $display("PCI image 5 is implemented!") ;
960
            test_pci_image(5) ;
961
            `else
962
            $display("PCI image 5 is NOT implemented!") ;
963
            `endif
964
 
965
            test_wb_error_rd ;
966
 
967
            target_fast_back_to_back ;
968
            target_disconnects ;
969
 
970
            if ( target_io_image !== -1 )
971
                test_target_abort( target_io_image ) ;
972
            $display(" ") ;
973
            $display("PCI target images' tests finished!") ;
974
 
975
            transaction_ordering ;
976 33 mihad
 
977
            target_completion_expiration ;
978 15 mihad
            $display(" ") ;
979
            $display("PCI transaction ordering tests finished!") ;
980
        end
981
    end
982
 
983
    test_summary ;
984
 
985
    $fclose(wbu_mon_log_file_desc | pciu_mon_log_file_desc | pci_mon_log_file_desc) ;
986
    $stop ;
987
end
988
endtask // run_tests
989
 
990
task do_reset;
991
begin
992
    next_test_name[79:0] <= "Reset.....";
993
 
994
    reset = 1'b1 ;
995
    #100 ;
996
    `ifdef HOST
997
        @(posedge wb_clock) ;
998
    `else
999
    `ifdef GUEST
1000
        @(posedge pci_clock) ;
1001
    `endif
1002
    `endif
1003
 
1004
    reset <= 1'b0 ;
1005
 
1006 45 mihad
    `ifdef HOST
1007
        @(posedge wb_clock) ;
1008
    `else
1009
    `ifdef GUEST
1010
        @(posedge pci_clock) ;
1011
    `endif
1012
    `endif
1013
 
1014 15 mihad
end
1015
endtask
1016
 
1017
/*############################################################################
1018
WB SLAVE UNIT tasks
1019
===================
1020
############################################################################*/
1021
 
1022
task configure_target ;
1023 45 mihad
    input [1:0]  beh_dev_num ;
1024 15 mihad
    reg   [31:0] base_address1 ;
1025
    reg   [31:0] base_address2 ;
1026
    reg   [2:0]  Master_ID;
1027
    reg   [31:0] Target_Config_Addr;
1028 45 mihad
    reg   [4:0]  device_num ;
1029 15 mihad
begin
1030 45 mihad
    if (beh_dev_num === 1)
1031 15 mihad
    begin
1032
        base_address1       = `BEH_TAR1_MEM_START ;
1033
        base_address2       = `BEH_TAR1_IO_START  ;
1034
        Master_ID           = `Test_Master_2 ;
1035
        Target_Config_Addr  = `TAR1_IDSEL_ADDR ;
1036 45 mihad
        device_num          = `TAR1_IDSEL_INDEX - 'd11 ;
1037 15 mihad
    end
1038
    else
1039 45 mihad
    if (beh_dev_num === 2)
1040 15 mihad
    begin
1041
        base_address1       = `BEH_TAR2_MEM_START ;
1042
        base_address2       = `BEH_TAR2_IO_START  ;
1043
        Master_ID           = `Test_Master_1 ;
1044
        Target_Config_Addr  = `TAR2_IDSEL_ADDR ;
1045 45 mihad
        device_num          = `TAR2_IDSEL_INDEX - 'd11 ;
1046 15 mihad
    end
1047
 
1048
    // write target's base addresses
1049
    // bus number 0, device number, function number 0, register number = 4 = base address register 0,
1050
    // type 0 cycle, byte enables, base address
1051
    configuration_cycle_write(0, device_num, 0, 4, 0, 4'hF, base_address1) ;
1052
    configuration_cycle_write(0, device_num, 0, 5, 0, 4'hF, base_address2) ;
1053
 
1054
    // enable target's response and master
1055
    // enable parity errors, disable system error
1056
 
1057
    configuration_cycle_write(0, device_num, 0, 1, 0, 4'h3, 32'h0000_0047) ;
1058
 
1059
end
1060
endtask //configure_target
1061
 
1062
task test_wb_image ;
1063
    input [2:0]  image_num ;
1064
    reg   [11:0] ctrl_offset ;
1065
    reg   [11:0] ba_offset ;
1066
    reg   [11:0] am_offset ;
1067
    reg   [11:0] ta_offset ;
1068
    reg   [11:0] err_cs_offset ;
1069
    reg `WRITE_STIM_TYPE write_data ;
1070
    reg `READ_STIM_TYPE  read_data ;
1071
    reg `READ_RETURN_TYPE read_status ;
1072
 
1073
    reg `WRITE_RETURN_TYPE write_status ;
1074
    reg `WB_TRANSFER_FLAGS write_flags ;
1075
    reg [31:0] temp_val ;
1076
    reg        ok   ;
1077
    reg [11:0] pci_ctrl_offset ;
1078
    reg [31:0] image_base ;
1079
    reg [31:0] target_address ;
1080
    reg [31:0] translation_address ;
1081
    integer    i ;
1082
    integer    j ;
1083
begin:main
1084
    pci_ctrl_offset = 12'h4 ;
1085
    err_cs_offset   = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
1086
    // image 0 can only be configuration image - start with 1
1087
    if (image_num === 1)
1088
    begin
1089
        ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1090
        ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1091
        am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1092
        ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1093
        test_name   = "WB IMAGE 1 FEATURES TEST" ;
1094
    end
1095
    else if (image_num === 2)
1096
    begin
1097
        ctrl_offset = {4'h1, `W_IMG_CTRL2_ADDR, 2'b00} ;
1098
        ba_offset   = {4'h1, `W_BA2_ADDR, 2'b00} ;
1099
        am_offset   = {4'h1, `W_AM2_ADDR, 2'b00} ;
1100
        ta_offset   = {4'h1, `W_TA2_ADDR, 2'b00} ;
1101
        test_name   = "WB IMAGE 2 FEATURES TEST" ;
1102
    end
1103
    else if (image_num === 3)
1104
    begin
1105
        ctrl_offset = {4'h1, `W_IMG_CTRL3_ADDR, 2'b00} ;
1106
        ba_offset   = {4'h1, `W_BA3_ADDR, 2'b00} ;
1107
        am_offset   = {4'h1, `W_AM3_ADDR, 2'b00} ;
1108
        ta_offset   = {4'h1, `W_TA3_ADDR, 2'b00} ;
1109
        test_name   = "WB IMAGE 3 FEATURES TEST" ;
1110
    end
1111
    else if (image_num === 4)
1112
    begin
1113
        ctrl_offset = {4'h1, `W_IMG_CTRL4_ADDR, 2'b00} ;
1114
        ba_offset   = {4'h1, `W_BA4_ADDR, 2'b00} ;
1115
        am_offset   = {4'h1, `W_AM4_ADDR, 2'b00} ;
1116
        ta_offset   = {4'h1, `W_TA4_ADDR, 2'b00} ;
1117
        test_name   = "WB IMAGE 4 FEATURES TEST" ;
1118
    end
1119
    else if (image_num === 5)
1120
    begin
1121
        ctrl_offset = {4'h1, `W_IMG_CTRL5_ADDR, 2'b00} ;
1122
        ba_offset   = {4'h1, `W_BA5_ADDR, 2'b00} ;
1123
        am_offset   = {4'h1, `W_AM5_ADDR, 2'b00} ;
1124
        ta_offset   = {4'h1, `W_TA5_ADDR, 2'b00} ;
1125
        test_name   = "WB IMAGE 5 FEATURES TEST" ;
1126
    end
1127
    else
1128
    begin
1129
        test_name   = "WB IMAGES' FEATURES TEST" ;
1130
        test_fail("invalid image number was provided for call to task test_wb_image") ;
1131
        disable main ;
1132
    end
1133
 
1134
    target_address  = `BEH_TAR1_MEM_START ;
1135
    image_base      = 0 ;
1136
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1137
 
1138
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1139
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1140
    write_flags                      = 0 ;
1141
    write_flags`INIT_WAITS           = tb_init_waits ;
1142
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
1143
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1144
 
1145
    test_name = "WB IMAGE CONFIGURATION" ;
1146
    // enable master & target operation
1147
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1148
    if ( ok !== 1 )
1149
    begin
1150
        $display("Image testing failed! Failed to write PCI Device Control register! Time %t ", image_num, $time) ;
1151
        test_fail("write to PCI Device Control register didn't succeede");
1152
        disable main ;
1153
    end
1154
 
1155
    config_write( err_cs_offset, 32'h0000_0000, 4'h1, ok) ;
1156
    if ( ok !== 1 )
1157
    begin
1158
        $display("Image testing failed! Failed to write WB Error Control and Status register! Time %t ", image_num, $time) ;
1159
        test_fail("write to WB Error Control and Status register didn't succeede");
1160
        disable main ;
1161
    end
1162
 
1163
    // prepare image control register
1164
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1165
    if ( ok !== 1 )
1166
    begin
1167
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1168
        test_fail("write to WB Image Control register didn't succeede");
1169
        disable main ;
1170
    end
1171
 
1172
    // prepare base address register
1173
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1174
    if ( ok !== 1 )
1175
    begin
1176
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1177
        test_fail("write to WB Base Address register didn't succeede");
1178
        disable main ;
1179
    end
1180
 
1181
    // write address mask register
1182
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1183
    if ( ok !== 1 )
1184
    begin
1185
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1186
        test_fail("write to WB Address Mask register didn't succeede");
1187
        disable main ;
1188
    end
1189
 
1190
    fork
1191
    begin
1192
        write_data`WRITE_ADDRESS = target_address ;
1193
        write_data`WRITE_DATA    = wmem_data[0] ;
1194
        write_data`WRITE_SEL     = 4'hF ;
1195
 
1196
        // handle retries from now on
1197
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1198
 
1199
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1200
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1201
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1202
        begin
1203
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1204
            test_fail("WB Slave state machine failed to post single memory write");
1205
            disable main ;
1206
        end
1207
 
1208
        // read written data back
1209
        read_data`READ_ADDRESS  = target_address ;
1210
        read_data`READ_SEL      = 4'hF ;
1211
        read_data`READ_TAG_STIM = 0 ;
1212
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1213
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1214
        begin
1215
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1216
            test_fail("PCI bridge didn't process the read as expected");
1217
            disable main ;
1218
        end
1219
 
1220
        if (read_status`READ_DATA !== wmem_data[0])
1221
        begin
1222
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1223
            test_fail("PCI bridge returned unexpected Read Data");
1224
        end
1225
        else
1226
            test_ok ;
1227
    end
1228
    begin
1229
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
1230
        if ( ok !== 1 )
1231
        begin
1232
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
1233
        end
1234
        else
1235
            test_ok ;
1236
 
1237
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1238
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
1239
        if ( ok !== 1 )
1240
        begin
1241
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
1242
        end
1243
    end
1244
    join
1245
 
1246
    // if address translation is implemented - try it out
1247
    translation_address = image_base ;
1248
    `ifdef ADDR_TRAN_IMPL
1249
    test_name = "CONFIGURE ADDRESS TRANSLATION FOR WISHBONE IMAGE" ;
1250
    config_write( ta_offset, translation_address, 4'hF, ok ) ;
1251
    if ( ok !== 1 )
1252
    begin
1253
        $display("Image testing failed! Failed to write W_TA%d register! Time %t ", image_num, $time) ;
1254
        test_fail("write to WB Image Translation Address Register failed") ;
1255
        disable main ;
1256
    end
1257
 
1258
    target_address  = `BEH_TAR2_MEM_START ;
1259
    image_base      = 0 ;
1260
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1261
 
1262
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1263
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = translation_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1264
 
1265
    write_flags                      = 0 ;
1266
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1267
 
1268
    test_name = "CHANGE WB IMAGE BASE ADDRESS" ;
1269
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1270
    if ( ok !== 1 )
1271
    begin
1272
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1273
        test_fail("write to WB Image Base Address Register failed") ;
1274
        disable main ;
1275
    end
1276
 
1277
    test_name = "ENABLE WB IMAGE ADDRESS TRANSLATION" ;
1278
    // enable address translation
1279
    config_write( ctrl_offset, 4, 4'h1, ok ) ;
1280
    if ( ok !== 1 )
1281
    begin
1282
        $display("Image testing failed! Failed to write W_IMG_CTRL%d register! Time %t ", image_num, $time) ;
1283
        test_fail("write to WB Image Control Register failed") ;
1284
        disable main ;
1285
    end
1286
 
1287
    `endif
1288
 
1289
    fork
1290
    begin
1291
        write_data`WRITE_ADDRESS = target_address + 4 ;
1292
        write_data`WRITE_DATA    = wmem_data[1] ;
1293
        write_data`WRITE_SEL     = 4'hF ;
1294
 
1295
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1296
 
1297
        `ifdef ADDR_TRAN_IMPL
1298
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI WITH ADDRESS TRANSLATION" ;
1299
        `else
1300
        test_name = "NORMAL SINGLE MEMORY WRITE THROUGH WB IMAGE TO PCI" ;
1301
        `endif
1302
 
1303
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1304
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1305
        begin
1306
            $display("Image testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
1307
            test_fail("WB Slave state machine failed to post single memory write") ;
1308
            disable main ;
1309
        end
1310
 
1311
        // read written data back
1312
        read_data`READ_ADDRESS  = target_address + 4 ;
1313
        read_data`READ_SEL      = 4'hF ;
1314
        read_data`READ_TAG_STIM = 0 ;
1315
 
1316
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1317
 
1318
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1319
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
1320
        begin
1321
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1322
            test_fail("PCI bridge failed to process single delayed memory read") ;
1323
            disable main ;
1324
        end
1325
 
1326
        if (read_status`READ_DATA !== wmem_data[1])
1327
        begin
1328
            display_warning(target_address + 4, wmem_data[1], read_status`READ_DATA) ;
1329
            test_fail("PCI bridge returned unexpected Read Data");
1330
        end
1331
        else
1332
            test_ok ;
1333
    end
1334
    begin
1335
        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 ) ;
1336
        if ( ok !== 1 )
1337
        begin
1338
            test_fail("single memory write didn't engage expected transaction on PCI bus") ;
1339
        end
1340
        else
1341
            test_ok ;
1342
 
1343
        test_name = "NORMAL SINGLE MEMORY READ THROUGH WB IMAGE FROM PCI" ;
1344
        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 ) ;
1345
        if ( ok !== 1 )
1346
        begin
1347
            test_fail("single memory read didn't engage expected transaction on PCI bus") ;
1348
        end
1349
    end
1350
    join
1351
 
1352
    // 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
1353
    // prepare write data
1354
    for ( i = 0 ; i < 6 ; i = i + 1 )
1355
    begin
1356
        write_data`WRITE_DATA    = wmem_data[2 + i] ;
1357
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
1358
        write_data`WRITE_SEL     = 4'hF ;
1359
        wishbone_master.blk_write_data[i] = write_data ;
1360
    end
1361
 
1362
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1363
    write_flags`WB_TRANSFER_CAB    = 1 ;
1364
    write_flags`WB_TRANSFER_SIZE   = 6 ;
1365
 
1366
    fork
1367
    begin
1368
        test_name = "CAB MEMORY WRITE THROUGH WB SLAVE TO PCI" ;
1369
        wishbone_master.wb_block_write(write_flags, write_status) ;
1370
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
1371
        begin
1372
            $display("Image testing failed! Bridge failed to process CAB memory write! Time %t ", $time) ;
1373
            test_fail("WB Slave state machine failed to post CAB memory write") ;
1374
            disable main ;
1375
        end
1376
    end
1377
    begin
1378
        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 ) ;
1379
        if ( ok !== 1 )
1380
        begin
1381
            test_fail("CAB memory write didn't engage expected transaction on PCI bus") ;
1382
        end
1383
        else
1384
            test_ok ;
1385
    end
1386
    join
1387
 
1388
    // set burst size and latency timer
1389
    config_write( 12'h00C, {bridge_latency, 8'd4}, 4'b1111, ok ) ;
1390
 
1391
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1392
    write_flags`WB_TRANSFER_CAB    = 1 ;
1393
    write_flags`WB_TRANSFER_SIZE   = 4 ;
1394
 
1395
    // prepare read data
1396
    for ( i = 0 ; i < 4 ; i = i + 1 )
1397
    begin
1398
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
1399
        read_data`READ_SEL     = 4'hF ;
1400
        wishbone_master.blk_read_data_in[i] = read_data ;
1401
    end
1402
 
1403
    fork
1404
    begin
1405
        test_name = "CAB MEMORY READ THROUGH WB SLAVE FROM PCI" ;
1406
        wishbone_master.wb_block_read(write_flags, read_status) ;
1407
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1408
        begin
1409
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1410
            test_fail("PCI Bridge Failed to process delayed CAB read") ;
1411
            disable main ;
1412
        end
1413
 
1414
        // check data read from target
1415
        for ( i = 0 ; i < 4 ; i = i + 1 )
1416
        begin
1417
            read_status = wishbone_master.blk_read_data_out[i] ;
1418
            if (read_status`READ_DATA !== wmem_data[2 + i])
1419
            begin
1420
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1421
                test_fail("data returned by PCI bridge during completion of Delayed Read didn't have expected value") ;
1422
            end
1423
        end
1424
    end
1425
    begin
1426
        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 ) ;
1427
        if ( ok !== 1 )
1428
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1429
        else
1430
            test_ok ;
1431
 
1432
        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 ) ;
1433
        if ( ok !== 1 )
1434
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1435
        else
1436
            test_ok ;
1437
 
1438
        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 ) ;
1439
        if ( ok !== 1 )
1440
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1441
        else
1442
            test_ok ;
1443
 
1444
        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 ) ;
1445
        if ( ok !== 1 )
1446
            test_fail("CAB memory read divided into single transactions didn't engage expected transaction on PCI bus") ;
1447
        else
1448
            test_ok ;
1449
 
1450
    end
1451
    join
1452
 
1453
    // now repeat this same burst read with various image features enabled or disabled
1454
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1455
    config_write( ctrl_offset, 5, 4'b1, ok ) ;
1456
    if (ok !== 1)
1457
    begin
1458
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1459
        test_fail("write to WB Image control register failed") ;
1460
        disable main ;
1461
    end
1462
 
1463
    fork
1464
    begin
1465
        test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1466
        wishbone_master.wb_block_read(write_flags, read_status) ;
1467
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1468
        begin
1469
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1470
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1471
            disable main ;
1472
        end
1473
 
1474
        // check data read from target
1475
        for ( i = 0 ; i < 4 ; i = i + 1 )
1476
        begin
1477
            read_status = wishbone_master.blk_read_data_out[i] ;
1478
            if (read_status`READ_DATA !== wmem_data[2 + i])
1479
            begin
1480
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1481
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1482
            end
1483
            else
1484
                test_ok ;
1485
        end
1486
    end
1487
    begin
1488
        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 ) ;
1489
        if ( ok !== 1 )
1490
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1491
    end
1492
    join
1493
 
1494
    read_data`READ_ADDRESS  = target_address ;
1495
    read_data`READ_SEL      = 4'hF ;
1496
    read_data`READ_TAG_STIM = 0 ;
1497
 
1498
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1499
    fork
1500
    begin
1501
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1502
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1503
        begin
1504
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1505
            test_fail("delayed single memory read wasn't processed as expected") ;
1506
            disable main ;
1507
        end
1508
 
1509
        if (read_status`READ_DATA !== wmem_data[0])
1510
        begin
1511
            display_warning(target_address, wmem_data[0], read_status`READ_DATA) ;
1512
            test_fail("delayed single memory read data value returned was not as expected") ;
1513
        end
1514
        else
1515
            test_ok ;
1516
    end
1517
    begin
1518
        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 ) ;
1519
        if ( ok !== 1 )
1520
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1521
    end
1522
    join
1523
 
1524
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1525
    config_write( ctrl_offset, 6, 4'b1, ok ) ;
1526
    if (ok !== 1)
1527
    begin
1528
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1529
        test_fail("write to WB Image control register failed") ;
1530
        disable main ;
1531
    end
1532
 
1533
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1534
    fork
1535
    begin
1536
        wishbone_master.wb_block_read(write_flags, read_status) ;
1537
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1538
        begin
1539
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1540
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1541
            disable main ;
1542
        end
1543
 
1544
        // check data read from target
1545
        for ( i = 0 ; i < 4 ; i = i + 1 )
1546
        begin
1547
            read_status = wishbone_master.blk_read_data_out[i] ;
1548
            if (read_status`READ_DATA !== wmem_data[2 + i])
1549
            begin
1550
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1551
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1552
            end
1553
            else
1554
                test_ok ;
1555
        end
1556
    end
1557
    begin
1558
        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 ) ;
1559
        if ( ok !== 1 )
1560
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1561
    end
1562
    join
1563
 
1564
    read_data`READ_ADDRESS  = target_address + 4 ;
1565
    read_data`READ_SEL      = 4'hF ;
1566
    read_data`READ_TAG_STIM = 0 ;
1567
 
1568
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1569
    fork
1570
    begin
1571
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1572
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1573
        begin
1574
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1575
            test_fail("delayed single memory read wasn't processed as expected") ;
1576
            disable main ;
1577
        end
1578
 
1579
        if (read_status`READ_DATA !== wmem_data[1])
1580
        begin
1581
            display_warning(target_address, wmem_data[1], read_status`READ_DATA) ;
1582
            test_fail("delayed single memory read data value returned was not as expected") ;
1583
        end
1584
        else
1585
            test_ok ;
1586
    end
1587
    begin
1588
        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 ) ;
1589
        if ( ok !== 1 )
1590
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1591
    end
1592
    join
1593
 
1594
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1595
    config_write( ctrl_offset, 7, 4'b1, ok ) ;
1596
    if (ok !== 1)
1597
    begin
1598
        $display("WISHBONE image %d test failed! Couldn't write image's control register! Time %t ", image_num, $time) ;
1599
        test_fail("write to WB Image control register failed") ;
1600
        disable main ;
1601
    end
1602
 
1603
    test_name = "CAB MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1604
    fork
1605
    begin
1606
        wishbone_master.wb_block_read(write_flags, read_status) ;
1607
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
1608
        begin
1609
            $display("Image testing failed! Bridge failed to process CAB memory read! Time %t ", $time) ;
1610
            test_fail("delayed CAB memory read wasn't processed as expected") ;
1611
            disable main ;
1612
        end
1613
 
1614
        // check data read from target
1615
        for ( i = 0 ; i < 4 ; i = i + 1 )
1616
        begin
1617
            read_status = wishbone_master.blk_read_data_out[i] ;
1618
            if (read_status`READ_DATA !== wmem_data[2 + i])
1619
            begin
1620
                display_warning(target_address + 8 + 4 * i, wmem_data[2 + i], read_status`READ_DATA) ;
1621
                test_fail("delayed CAB memory read data value returned was not as expected") ;
1622
            end
1623
            else
1624
                test_ok ;
1625
        end
1626
    end
1627
    begin
1628
        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 ) ;
1629
        if ( ok !== 1 )
1630
            test_fail( "burst Delayed Read didn't engage expected transaction on PCI bus" ) ;
1631
    end
1632
    join
1633
 
1634
    read_data`READ_ADDRESS  = target_address + 8 ;
1635
    read_data`READ_SEL      = 4'hF ;
1636
    read_data`READ_TAG_STIM = 0 ;
1637
 
1638
    test_name = "SINGLE MEMORY READ THROUGH WB IMAGE WITH READ BURSTING ENABLED" ;
1639
    fork
1640
    begin
1641
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
1642
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
1643
        begin
1644
            $display("Image testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
1645
            test_fail("delayed single memory read wasn't processed as expected") ;
1646
            disable main ;
1647
        end
1648
 
1649
        if (read_status`READ_DATA !== wmem_data[2])
1650
        begin
1651
            display_warning(target_address, wmem_data[2], read_status`READ_DATA) ;
1652
            test_fail("delayed single memory read data value returned was not as expected") ;
1653
        end
1654
        else
1655
            test_ok ;
1656
    end
1657
    begin
1658
        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 ) ;
1659
        if ( ok !== 1 )
1660
            test_fail( "single Delayed Read didn't engage expected transaction on PCI bus" ) ;
1661
    end
1662
    join
1663
 
1664
    // map image to IO space
1665
    test_name   = "ENABLING/DISABLING IMAGE'S FEATURES" ;
1666
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
1667
    if ( ok !== 1 )
1668
    begin
1669
        $display("Image testing failed! Failed to write W_BA%d register! Time %t ", image_num, $time) ;
1670
        test_fail("write to WB Image Base Address register failed") ;
1671
        disable main ;
1672
    end
1673
 
1674
    write_data`WRITE_ADDRESS = target_address ;
1675
    write_data`WRITE_DATA    = wmem_data[11] ;
1676
    write_data`WRITE_SEL     = 4'hF ;
1677
 
1678
    // handle retries from now on
1679
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1680
 
1681
    test_name   = "I/O WRITE TRANSACTION FROM WB TO PCI TEST" ;
1682
    fork
1683
    begin
1684
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1685
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1686
        begin
1687
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1688
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1689
            disable main ;
1690
        end
1691
    end
1692
    begin
1693
        // currently IO commands not supported in behavioral models - master abort
1694
        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 ) ;
1695
        if ( ok !== 1 )
1696
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1697
        else
1698
            test_ok ;
1699
    end
1700
    join
1701
 
1702
    read_data`READ_ADDRESS  = target_address ;
1703
    read_data`READ_SEL      = 4'hF ;
1704
    read_data`READ_TAG_STIM = 0 ;
1705
 
1706
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1707
 
1708
    // currently io commands are not supported by behavioral target - transfer should not be completed
1709
    test_name   = "I/O READ TRANSACTION FROM WB TO PCI TEST" ;
1710
    fork
1711
    begin
1712
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1713
        if (read_status`CYC_ERR !== 1)
1714
        begin
1715
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1716
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1717
            disable main ;
1718
        end
1719
        else
1720
            test_ok ;
1721
    end
1722
    begin
1723
        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 ) ;
1724
        if ( ok !== 1 )
1725
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1726
    end
1727
    join
1728
 
1729
    // test byte addressing
1730
    read_data`READ_ADDRESS = target_address + 2 ;
1731
    read_data`READ_SEL     = 4'b1100 ;
1732
 
1733
    fork
1734
    begin
1735
        // currently io commands are not supported by behavioral target - transfer should not be completed
1736
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1737
        if (read_status`CYC_ERR !== 1)
1738
        begin
1739
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1740
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1741
            disable main ;
1742
        end
1743
        else test_ok ;
1744
    end
1745
    begin
1746
        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 ) ;
1747
        if ( ok !== 1 )
1748
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1749
    end
1750
    join
1751
 
1752
    test_name = "CHECK MAXIMUM IMAGE SIZE" ;
1753
    target_address = ~({`WB_CONFIGURATION_BASE, 12'hFFF}) ;
1754
    config_write(ba_offset, target_address + 1, 4'hF, ok) ;
1755
    if ( ok !== 1 )
1756
    begin
1757
        test_fail("WB Base address register could not be written") ;
1758
        disable main ;
1759
    end
1760
 
1761
    config_write(am_offset, 32'h8000_0000, 4'hF, ok) ;
1762
    if ( ok !== 1 )
1763
    begin
1764
        test_fail("WB Address Mask register could not be written") ;
1765
        disable main ;
1766
    end
1767
 
1768
    config_write(ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1769
    if ( ok !== 1 )
1770
    begin
1771
        test_fail("WB Image Control register could not be written") ;
1772
        disable main ;
1773
    end
1774
 
1775
    write_data`WRITE_ADDRESS = {target_address[31], 31'h7FFF_FFFF} ;
1776
    write_data`WRITE_DATA    = wmem_data[11] ;
1777
    write_data`WRITE_SEL     = 4'b1000 ;
1778
 
1779
    // handle retries from now on
1780
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1781
 
1782
    fork
1783
    begin
1784
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1785
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
1786
        begin
1787
            $display("Image testing failed! Bridge failed to process single IO write! Time %t ", $time) ;
1788
            test_fail("single I/O write was not posted by WB Slave state machine as expected");
1789
            disable main ;
1790
        end
1791
    end
1792
    begin
1793
        // currently IO commands not supported in behavioral models - master abort
1794
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_IO_WRITE, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1795
        if ( ok !== 1 )
1796
            test_fail( "single I/O write didn't engage expected transaction on PCI bus" ) ;
1797
        else
1798
            test_ok ;
1799
    end
1800
    join
1801
 
1802
    read_data`READ_ADDRESS = write_data`WRITE_ADDRESS ;
1803
    read_data`READ_SEL     = write_data`WRITE_SEL ;
1804
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
1805
 
1806
    fork
1807
    begin
1808
        // currently io commands are not supported by behavioral target - transfer should not be completed
1809
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1810
        if (read_status`CYC_ERR !== 1)
1811
        begin
1812
            $display("Image testing failed! Bridge failed to process single IO read! Time %t ", $time) ;
1813
            test_fail("single I/O read was not finished by WB Slave state machine as expected");
1814
            disable main ;
1815
        end
1816
        else test_ok ;
1817
    end
1818
    begin
1819
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_IO_READ, 0, 0, 1'b0, 1'b0, 0, ok ) ;
1820
        if ( ok !== 1 )
1821
            test_fail( "single I/O read didn't engage expected transaction on PCI bus" ) ;
1822
    end
1823
    join
1824
 
1825
    test_name = "DISABLING WB IMAGE" ;
1826
 
1827
    // disable current image
1828
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
1829
    if ( ok !== 1 )
1830
    begin
1831
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1832
        test_fail("write to WB Image Address Mask register not accepted as expected") ;
1833
        disable main ;
1834
    end
1835
 
1836
    // clear master abort status bit
1837
    config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'hC, ok ) ;
1838
    if ( ok !== 1 )
1839
    begin
1840
        $display("Image testing failed! Failed to write W_AM%d register! Time %t ", image_num, $time) ;
1841
        test_fail("write to PCI Device Status register not accepted as expected") ;
1842
        disable main ;
1843
    end
1844
 
1845
end //main
1846
endtask //test_wb_image
1847
 
1848
task wb_slave_errors ;
1849
    reg   [11:0] ctrl_offset ;
1850
    reg   [11:0] ba_offset ;
1851
    reg   [11:0] am_offset ;
1852
    reg   [11:0] ta_offset ;
1853
    reg `WRITE_STIM_TYPE write_data ;
1854
    reg `READ_STIM_TYPE  read_data ;
1855
    reg `READ_RETURN_TYPE read_status ;
1856
 
1857
    reg `WRITE_RETURN_TYPE write_status ;
1858
    reg `WB_TRANSFER_FLAGS write_flags ;
1859
    reg [31:0] temp_val1 ;
1860
    reg [31:0] temp_val2 ;
1861
    reg        ok   ;
1862
    reg [11:0] pci_ctrl_offset ;
1863
    reg [31:0] image_base ;
1864
    reg [31:0] target_address ;
1865
    integer    i ;
1866
    reg skip ;
1867
fork
1868
begin:main
1869
 
1870
    `ifdef GUEST
1871
        skip = 1 ;
1872
    `else
1873
        skip = 0 ;
1874
    `endif
1875
 
1876
    pci_ctrl_offset = 12'h4 ;
1877
 
1878
    // image 1 is used for error testing, since it is always implemented
1879
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
1880
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
1881
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
1882
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
1883
 
1884
    target_address  = `BEH_TAR1_MEM_START ;
1885
    image_base      = 0 ;
1886
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
1887
 
1888
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
1889
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
1890
    write_flags                    = 0 ;
1891
    write_flags`INIT_WAITS         = tb_init_waits ;
1892
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
1893
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1894
 
1895
    // enable master & target operation
1896
    test_name = "CONFIGURING IMAGE FOR WB SLAVE ERROR TERMINATION TESTING" ;
1897
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
1898
    if ( ok !== 1 )
1899
    begin
1900
        $display("WISHBONE slave error termination testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
1901
        test_fail("PCI Device Control register couldn't be written") ;
1902
        disable no_transaction ;
1903
        disable main ;
1904
    end
1905
 
1906
    // prepare image control register
1907
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
1908
    if ( ok !== 1 )
1909
    begin
1910
        $display("WISHBONE slave error termination testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
1911
        test_fail("WB Image Control register couldn't be written") ;
1912
        disable no_transaction ;
1913
        disable main ;
1914
    end
1915
 
1916
    // prepare base address register
1917
    config_write( ba_offset, image_base, 4'hF, ok ) ;
1918
    if ( ok !== 1 )
1919
    begin
1920
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
1921
        test_fail("WB Base Address register couldn't be written") ;
1922
        disable no_transaction ;
1923
        disable main ;
1924
    end
1925
 
1926
    // write address mask register
1927
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
1928
    if ( ok !== 1 )
1929
    begin
1930
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
1931
        test_fail("WB Address Mask register couldn't be written") ;
1932
        disable no_transaction ;
1933
        disable main ;
1934
    end
1935
 
1936
    $display("************************* Testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
1937
 
1938
    skip = 0 ;
1939
 
1940
    // memory mapped image - access is erroneous when address is not alligned
1941
    write_data`WRITE_ADDRESS = target_address + 1 ;
1942
    write_data`WRITE_DATA    = wmem_data[0] ;
1943
    write_data`WRITE_SEL     = 4'hF ;
1944
 
1945
    // handle retries from now on
1946
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
1947
 
1948
    test_name = "SINGLE ERRONEOUS MEMORY WRITE TO WB SLAVE" ;
1949
 
1950
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1951
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1952
    begin
1953
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1954
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1955
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1956
        disable no_transaction ;
1957
        disable main ;
1958
    end
1959
 
1960
    write_data`WRITE_ADDRESS = target_address + 2 ;
1961
 
1962
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1963
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1964
    begin
1965
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1966
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1967
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1968
        disable no_transaction ;
1969
        disable main ;
1970
 
1971
    end
1972
 
1973
    write_data`WRITE_ADDRESS = target_address + 3 ;
1974
 
1975
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
1976
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
1977
    begin
1978
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1979
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1980
        test_fail("WB Slave state machine didn't reject erroneous memory write as expected") ;
1981
        disable no_transaction ;
1982
        disable main ;
1983
    end
1984
 
1985
    test_ok ;
1986
 
1987
    // perform same tests for read accesses
1988
    test_name = "SINGLE ERRONEOUS MEMORY READ TO WB SLAVE" ;
1989
 
1990
    read_data`READ_ADDRESS  = target_address + 2 ;
1991
    read_data`READ_SEL      = 4'hF ;
1992
    read_data`READ_TAG_STIM = 0 ;
1993
 
1994
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
1995
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
1996
    begin
1997
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
1998
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
1999
        test_fail("WB Slave state machine didn't reject erroneous memory read as expected") ;
2000
        disable no_transaction ;
2001
        disable main ;
2002
    end
2003
 
2004
    test_ok ;
2005
 
2006
    // prepare write data
2007
    for ( i = 0 ; i < 6 ; i = i + 1 )
2008
    begin
2009
        write_data`WRITE_DATA    = wmem_data[i] ;
2010
        write_data`WRITE_ADDRESS = target_address +  4*i + 2 ;
2011
        write_data`WRITE_SEL     = 4'hF ;
2012
        wishbone_master.blk_write_data[i] = write_data ;
2013
    end
2014
 
2015
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2016
    write_flags`WB_TRANSFER_CAB    = 1 ;
2017
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2018
 
2019
    test_name = "ERRONEOUS CAB MEMORY WRITE TO WB SLAVE" ;
2020
    wishbone_master.wb_block_write(write_flags, write_status) ;
2021
 
2022
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2023
    begin
2024
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2025
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2026
        test_fail("WB Slave state machine didn't reject erroneous CAB memory write as expected") ;
2027
        disable no_transaction ;
2028
        disable main ;
2029
    end
2030
 
2031
    // prepare read data
2032
    for ( i = 0 ; i < 6 ; i = i + 1 )
2033
    begin
2034
        read_data`READ_ADDRESS = target_address + 4*i + 3 ;
2035
        read_data`READ_SEL     = 4'hF ;
2036
        wishbone_master.blk_read_data_in[i] = read_data ;
2037
    end
2038
 
2039
    test_name = "ERRONEOUS CAB MEMORY READ TO WB SLAVE" ;
2040
    wishbone_master.wb_block_read(write_flags, read_status) ;
2041
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2042
    begin
2043
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned memory address! Time %t ", $time) ;
2044
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2045
        test_fail("WB Slave state machine didn't reject erroneous CAB memory read as expected") ;
2046
        disable no_transaction ;
2047
        disable main ;
2048
    end
2049
 
2050
    test_ok ;
2051
 
2052
    $display("************************* DONE testing WISHBONE Slave's response to erroneous memory accesses **************************") ;
2053
    $display("***************************** Testing WISHBONE Slave's response to erroneous IO accesses ******************************") ;
2054
 
2055
    // map image to IO space
2056
    `ifdef GUEST
2057
        skip = 1 ;
2058
    `endif
2059
 
2060
    test_name = "RECONFIGURING IMAGE TO I/O MAPPED ADDRESS SPACE" ;
2061
    config_write( ba_offset, image_base | 1, 4'hF, ok ) ;
2062
    if ( ok !== 1 )
2063
    begin
2064
        $display("WISHBONE slave error termination testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2065
        test_fail("WB Image Base Address register couldn't be written") ;
2066
        disable no_transaction ;
2067
        disable main ;
2068
    end
2069
 
2070
    skip = 0 ;
2071
 
2072
    write_data`WRITE_ADDRESS = target_address ;
2073
    write_data`WRITE_DATA    = wmem_data[0] ;
2074
    write_data`WRITE_SEL     = 4'b1010 ;
2075
 
2076
    // don't handle retries
2077
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2078
 
2079
    test_name = "ERRONEOUS I/O WRITE TO WB SLAVE" ;
2080
 
2081
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2082
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2083
    begin
2084
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2085
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2086
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2087
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2088
        disable no_transaction ;
2089
        disable main ;
2090
    end
2091
 
2092
    write_data`WRITE_ADDRESS = target_address + 1 ;
2093
    write_data`WRITE_SEL     = 4'b0011 ;
2094
 
2095
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2096
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2097
    begin
2098
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2099
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2100
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2101
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2102
        disable no_transaction ;
2103
        disable main ;
2104
    end
2105
 
2106
    write_data`WRITE_SEL     = 4'b1100 ;
2107
 
2108
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2109
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2110
    begin
2111
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2112
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2113
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2114
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2115
        disable no_transaction ;
2116
        disable main ;
2117
    end
2118
 
2119
    write_data`WRITE_ADDRESS = target_address + 2 ;
2120
    write_data`WRITE_SEL     = 4'b0101 ;
2121
 
2122
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2123
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2124
    begin
2125
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2126
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2127
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2128
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2129
        disable no_transaction ;
2130
        disable main ;
2131
    end
2132
 
2133
    write_data`WRITE_SEL     = 4'b1000 ;
2134
 
2135
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2136
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2137
    begin
2138
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2139
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2140
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2141
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2142
        disable no_transaction ;
2143
        disable main ;
2144
    end
2145
 
2146
    write_data`WRITE_ADDRESS = target_address + 3 ;
2147
    write_data`WRITE_SEL     = 4'b1010 ;
2148
 
2149
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2150
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2151
    begin
2152
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2153
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2154
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2155
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2156
        disable no_transaction ;
2157
        disable main ;
2158
    end
2159
 
2160
    write_data`WRITE_SEL     = 4'b0110 ;
2161
 
2162
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2163
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2164
    begin
2165
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2166
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2167
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2168
        test_fail("WB Slave state machine didn't reject erroneous I/O write as expected") ;
2169
        disable no_transaction ;
2170
        disable main ;
2171
    end
2172
 
2173
    test_ok ;
2174
 
2175
    test_name = "ERRONEOUS I/O READ TO WB SLAVE" ;
2176
 
2177
    read_data`READ_ADDRESS  = target_address + 3 ;
2178
    read_data`READ_SEL      = 4'hF ;
2179
    read_data`READ_TAG_STIM = 0 ;
2180
 
2181
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2182
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2183
    begin
2184
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on erroneous access to IO mapped address! Time %t ", $time) ;
2185
        $display("ADDRESS : %h, SEL : %b ", write_data`WRITE_ADDRESS, write_data`WRITE_SEL) ;
2186
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2187
        test_fail("WB Slave state machine didn't reject erroneous I/O read as expected") ;
2188
        disable no_transaction ;
2189
        disable main ;
2190
    end
2191
 
2192
    test_ok ;
2193
 
2194
    test_name = "CAB I/O WRITE TO WB SLAVE" ;
2195
    // prepare write data
2196
    for ( i = 0 ; i < 6 ; i = i + 1 )
2197
    begin
2198
        write_data`WRITE_DATA    = wmem_data[i] ;
2199
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2200
        write_data`WRITE_SEL     = 4'hF ;
2201
        wishbone_master.blk_write_data[i] = write_data ;
2202
    end
2203
 
2204
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2205
    write_flags`WB_TRANSFER_CAB    = 1 ;
2206
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2207
 
2208
    wishbone_master.wb_block_write(write_flags, write_status) ;
2209
 
2210
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2211
    begin
2212
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2213
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2214
        test_fail("WB Slave state machine didn't reject CAB I/O write as expected") ;
2215
        disable no_transaction ;
2216
        disable main ;
2217
    end
2218
 
2219
    test_ok ;
2220
 
2221
    test_name = "CAB I/O READ TO WB SLAVE" ;
2222
    // prepare read data
2223
    for ( i = 0 ; i < 6 ; i = i + 1 )
2224
    begin
2225
        read_data`READ_ADDRESS = target_address + 4*i ;
2226
        read_data`READ_SEL     = 4'hF ;
2227
        wishbone_master.blk_read_data_in[i] = read_data ;
2228
    end
2229
 
2230
    wishbone_master.wb_block_read(write_flags, read_status) ;
2231
 
2232
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2233
    begin
2234
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to IO mapped address! Time %t ", $time) ;
2235
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2236
        test_fail("WB Slave state machine didn't reject CAB I/O read as expected") ;
2237
        disable no_transaction ;
2238
        disable main ;
2239
    end
2240
 
2241
    test_ok ;
2242
 
2243
    $display("**************************** DONE testing WISHBONE Slave's response to erroneous IO accesses ***************************") ;
2244
 
2245
    $display("************************* Testing WISHBONE Slave's response to erroneous configuration accesses **************************") ;
2246
 
2247
    target_address = {`WB_CONFIGURATION_BASE, 12'h0} ;
2248
    write_data`WRITE_ADDRESS = target_address + 1 ;
2249
    write_data`WRITE_DATA    = wmem_data[0] ;
2250
    write_data`WRITE_SEL     = 4'hF ;
2251
 
2252
    // don't handle retries
2253
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2254
 
2255
    `ifdef HOST
2256
        `define DO_W_CONF_TEST
2257
        `define DO_R_CONF_TEST
2258
    `else
2259
        `ifdef WB_CNF_IMAGE
2260
             `define DO_R_CONF_TEST
2261
        `endif
2262
    `endif
2263
 
2264
    `ifdef DO_W_CONF_TEST
2265
    test_name = "ERRONEOUS WB CONFIGURATION WRITE ACCESS" ;
2266
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2267
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2268
    begin
2269
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2270
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2271
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2272
        disable no_transaction ;
2273
        disable main ;
2274
    end
2275
 
2276
    write_data`WRITE_ADDRESS = target_address + 2 ;
2277
 
2278
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2279
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2280
    begin
2281
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2282
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2283
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2284
        disable no_transaction ;
2285
        disable main ;
2286
    end
2287
 
2288
    write_data`WRITE_ADDRESS = target_address + 3 ;
2289
 
2290
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
2291
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2292
    begin
2293
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2294
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2295
        test_fail("WB Slave state machine didn't reject erroneous Configuration write as expected") ;
2296
        disable no_transaction ;
2297
        disable main ;
2298
    end
2299
 
2300
    test_ok ;
2301
    `endif
2302
 
2303
    `ifdef DO_R_CONF_TEST
2304
    test_name = "ERRONEOUS WB CONFIGURATION READ ACCESS" ;
2305
    read_data`READ_ADDRESS  = target_address + 3 ;
2306
    read_data`READ_SEL      = 4'hF ;
2307
    read_data`READ_TAG_STIM = 0 ;
2308
 
2309
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2310
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2311
    begin
2312
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on access to non-alligned configuration address! Time %t ", $time) ;
2313
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2314
        test_fail("WB Slave state machine didn't reject erroneous Configuration read as expected") ;
2315
        disable no_transaction ;
2316
        disable main ;
2317
    end
2318
 
2319
    test_ok ;
2320
    `endif
2321
 
2322
    `ifdef DO_W_CONF_TEST
2323
    // prepare write data
2324
    test_name = "WB CAB CONFIGURATION WRITE ACCESS" ;
2325
    for ( i = 0 ; i < 6 ; i = i + 1 )
2326
    begin
2327
        write_data`WRITE_DATA    = wmem_data[i] ;
2328
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2329
        write_data`WRITE_SEL     = 4'hF ;
2330
        wishbone_master.blk_write_data[i] = write_data ;
2331
    end
2332
 
2333
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2334
    write_flags`WB_TRANSFER_CAB    = 1 ;
2335
    write_flags`WB_TRANSFER_SIZE   = 6 ;
2336
 
2337
    wishbone_master.wb_block_write(write_flags, write_status) ;
2338
 
2339
    if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
2340
    begin
2341
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2342
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2343
        test_fail("WB Slave state machine didn't reject CAB Configuration write as expected") ;
2344
        disable no_transaction ;
2345
        disable main ;
2346
    end
2347
    test_ok ;
2348
    `endif
2349
 
2350
    `ifdef DO_R_CONF_TEST
2351
    // prepare read data
2352
    test_name = "WB CAB CONFIGURATION READ ACCESS" ;
2353
    for ( i = 0 ; i < 6 ; i = i + 1 )
2354
    begin
2355
        read_data`READ_ADDRESS = target_address + 4*i ;
2356
        read_data`READ_SEL     = 4'hF ;
2357
        wishbone_master.blk_read_data_in[i] = read_data ;
2358
    end
2359
 
2360
    wishbone_master.wb_block_read(write_flags, read_status) ;
2361
 
2362
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2363
    begin
2364
        $display("WISHBONE slave error termination testing failed! WB Slave didn't signal error on CAB access to configuration address! Time %t ", $time) ;
2365
        $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2366
        test_fail("WB Slave state machine didn't reject CAB Configuration read as expected") ;
2367
        disable no_transaction ;
2368
        disable main ;
2369
    end
2370
    test_ok ;
2371
    `endif
2372
 
2373
    `ifdef GUEST
2374
        skip = 1 ;
2375
    `endif
2376
 
2377
    // disable image
2378
    test_name = "DISABLE IMAGE" ;
2379
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
2380
    if ( ok !== 1 )
2381
    begin
2382
        $display("WISHBONE slave error termination testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2383
        test_fail("WB Address Mask register couldn't be written") ;
2384
        disable no_transaction ;
2385
        disable main ;
2386
    end
2387
 
2388
    skip = 0 ;
2389
 
2390
    $display("*********************** DONE testing WISHBONE Slave's response to erroneous configuration accesses ***********************") ;
2391
 
2392
    disable no_transaction ;
2393
end
2394
begin:no_transaction
2395
    // this block of statements monitors PCI bus for initiated transaction - no transaction can be initiated on PCI bus by PCI bridge,
2396
    // since all WISHBONE transactions in this test should be terminated with error on WISHBONE and should not proceede to PCI bus
2397
    forever
2398
    begin
2399
        @(posedge pci_clock) ;
2400
        if ( skip !== 1 )
2401
        begin
2402
            if ( FRAME !== 1 )
2403
            begin
2404
                $display("WISHBONE slave error termination testing failed! Transaction terminated with error on WISHBONE should not proceede to PCI bus! Time %t ", $time) ;
2405
                $display("Address = %h, Bus command = %b ", AD, CBE) ;
2406
                test_fail("access that should be terminated with error by WB Slave state machine proceeded to PCI bus") ;
2407
            end
2408
        end
2409
    end
2410
end
2411
join
2412
endtask //wb_slave_errors
2413
 
2414
task wb_to_pci_error_handling ;
2415
    reg   [11:0] ctrl_offset ;
2416
    reg   [11:0] ba_offset ;
2417
    reg   [11:0] am_offset ;
2418
    reg   [11:0] ta_offset ;
2419
    reg   [11:0] err_cs_offset ;
2420
    reg `WRITE_STIM_TYPE write_data ;
2421
    reg `READ_STIM_TYPE  read_data ;
2422
    reg `READ_RETURN_TYPE read_status ;
2423
 
2424
    reg `WRITE_RETURN_TYPE write_status ;
2425
    reg `WB_TRANSFER_FLAGS write_flags ;
2426
    reg [31:0] temp_val1 ;
2427
    reg [31:0] temp_val2 ;
2428
    reg        ok   ;
2429
    reg [11:0] pci_ctrl_offset ;
2430
    reg [31:0] image_base ;
2431
    reg [31:0] target_address ;
2432
    integer    num_of_trans ;
2433
    integer    current ;
2434
    integer    i ;
2435
begin:main
2436
 
2437
    $display("************************** Testing handling of PCI bus errors *******************************************") ;
2438
 
2439
    pci_ctrl_offset = 12'h4 ;
2440
 
2441
    // disable error interrupts and disable error reporting
2442
    test_name = "CONFIGURING BRIDGE FOR PCI ERROR TERMINATION RESPONSE BY WB SLAVE TESTING" ;
2443
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
2444
    if ( ok !== 1 )
2445
    begin
2446
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
2447
        test_fail("PCI Device Control register couldn't be written") ;
2448
        disable main ;
2449
    end
2450
 
2451
    // image 1 is used for error testing, since it is always implemented
2452
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
2453
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
2454
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
2455
    ta_offset   = {4'h1, `W_TA1_ADDR, 2'b00} ;
2456
 
2457
    // set master abort testing address to address that goes out of target's range
2458
    target_address  = `BEH_TAR1_MEM_START ;
2459
    image_base      = 0 ;
2460
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
2461
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
2462
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
2463
 
2464
    write_flags                    = 0 ;
2465
    write_flags`INIT_WAITS         = tb_init_waits ;
2466
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
2467
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2468
 
2469
    err_cs_offset = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
2470
 
2471
    // enable master & target operation
2472
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
2473
    if ( ok !== 1 )
2474
    begin
2475
        $display("PCI bus error handling testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
2476
        test_fail("PCI Device Control register couldn't be written") ;
2477
        disable main ;
2478
    end
2479
 
2480
    // prepare image control register
2481
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
2482
    if ( ok !== 1 )
2483
    begin
2484
        $display("PCI bus error handling testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
2485
        test_fail("WB Image Control register couldn't be written") ;
2486
        disable main ;
2487
    end
2488
 
2489
    // prepare base address register
2490
    config_write( ba_offset, image_base, 4'hF, ok ) ;
2491
    if ( ok !== 1 )
2492
    begin
2493
        $display("PCI bus error handling testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
2494
        test_fail("WB Image Base Address register couldn't be written") ;
2495
        disable main ;
2496
    end
2497
 
2498
    // write address mask register
2499
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
2500
    if ( ok !== 1 )
2501
    begin
2502
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
2503
        test_fail("WB Image Address Mask register couldn't be written") ;
2504
        disable main ;
2505
    end
2506
 
2507
    // disable error reporting
2508
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok ) ;
2509
    if ( ~ok )
2510
    begin
2511
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
2512
        test_fail("WB Error Control and Status register couldn't be written") ;
2513
        disable main ;
2514
    end
2515
 
2516
    // perform two writes - one to error address and one to OK address
2517
    // prepare write buffer
2518
 
2519
    write_data`WRITE_ADDRESS = target_address ;
2520
    write_data`WRITE_DATA    = wmem_data[100] ;
2521
    write_data`WRITE_SEL     = 4'hF ;
2522
 
2523
    wishbone_master.blk_write_data[0] = write_data ;
2524
 
2525
    write_flags`WB_TRANSFER_SIZE = 2 ;
2526
 
2527
    // don't handle retries
2528
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2529
    write_flags`WB_TRANSFER_CAB    = 0 ;
2530
 
2531
    $display("Introducing master abort error on single WB to PCI write!") ;
2532
 
2533
    test_name = "MASTER ABORT ERROR HANDLING DURING WB TO PCI WRITES" ;
2534
    // first disable target 1
2535
 
2536 45 mihad
    configuration_cycle_write(0,                        // bus number
2537
                              `TAR1_IDSEL_INDEX - 11,   // device number
2538
                              0,                        // function number
2539
                              1,                        // register number
2540
                              0,                        // type of configuration cycle
2541
                              4'b0001,                  // byte enables
2542
                              32'h0000_0000             // data
2543 15 mihad
                             ) ;
2544
 
2545
    fork
2546
    begin
2547
        // start no response monitor in parallel with writes
2548
        musnt_respond(ok) ;
2549
        if ( ok !== 1 )
2550
        begin
2551
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2552
            $display("Testbench is configured wrong!") ;
2553
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2554
        end
2555
        else
2556
            test_ok ;
2557
    end
2558
    begin
2559
       wishbone_master.wb_single_write(write_data, write_flags, write_status) ;
2560
       if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
2561
       begin
2562
           $display("PCI bus error handling testing failed! WB slave didn't acknowledge single write cycle! Time %t ", $time) ;
2563
           $display("WISHBONE slave response: ACK = %b, RTY = %b, ERR = %b ", write_status`CYC_ACK, write_status`CYC_RTY, write_status`CYC_ERR) ;
2564
           test_fail("WB Slave state machine failed to post single memory write");
2565
           disable main ;
2566
       end
2567
    end
2568
    join
2569
 
2570
    /*// read data from second write
2571
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2572
    read_data`READ_ADDRESS = target_address ;
2573
    read_data`READ_SEL     = 4'hF ;
2574
    read_data`READ_TAG_STIM = 0 ;
2575
 
2576
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
2577
 
2578
    if ( read_status`READ_DATA !== wmem_data[101] )
2579
    begin
2580
        display_warning( target_address, wmem_data[101], read_status`READ_DATA ) ;
2581
    end
2582
    */
2583
 
2584
    // read error status register - no errors should be reported since reporting was disabled
2585
    test_name = "CHECKING ERROR REPORTING FUNCTIONS AFTER MASTER ABORT ERROR" ;
2586
 
2587
    @(posedge pci_clock) ;
2588
    // wait for two WB clocks for synchronization to be finished
2589
    repeat (2)
2590
        @(posedge wb_clock) ;
2591
 
2592
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2593
    if ( temp_val1[8] !== 0 )
2594
    begin
2595
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2596
        $display("Error reporting was disabled, but error was reported anyway!") ;
2597
        test_fail("Error reporting was disabled, but error was reported anyway") ;
2598
        disable main ;
2599
    end
2600
    test_ok ;
2601
 
2602
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2603
    // check for interrupts - there should be no interrupt requests active
2604
    `ifdef HOST
2605
        repeat(4)
2606
            @(posedge wb_clock) ;
2607
 
2608
        if ( INT_O !== 0 )
2609
        begin
2610
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2611
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on WISHBONE bus!") ;
2612
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on WISHBONE bus") ;
2613
        end
2614
        else
2615
            test_ok ;
2616
    `else
2617
    `ifdef GUEST
2618
        repeat( 4 )
2619
            @(posedge pci_clock) ;
2620
 
2621
        if ( INTA !== 1 )
2622
        begin
2623
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2624
            $display("WISHBONE error interrupt enable is cleared, error signal bit is cleared, but interrupt was signalled on PCI bus!") ;
2625
            test_fail("WISHBONE error interrupts were disabled, error signal bit is clear, but interrupt was signalled on PCI bus") ;
2626
        end
2627
        else
2628
            test_ok ;
2629
    `endif
2630
    `endif
2631
 
2632
    test_name = "CHECKING PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT" ;
2633
    // check PCI status register
2634
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2635
    if ( temp_val1[29] !== 1 )
2636
    begin
2637
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2638
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2639
        test_fail("Received Master Abort bit was not set when write was terminated with Master Abort") ;
2640
    end
2641
    else
2642
        test_ok ;
2643
 
2644
    // clear
2645
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
2646
 
2647
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2648
 
2649
    $display("Introducing master abort error to CAB write!") ;
2650
    // now enable error reporting mechanism
2651
    config_write( err_cs_offset, 1, 4'h1, ok ) ;
2652
    // enable error interrupts
2653
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
2654
 
2655
    // configure flags for CAB transfer
2656
    write_flags`WB_TRANSFER_CAB = 1 ;
2657
    write_flags`WB_TRANSFER_SIZE = 3 ;
2658
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
2659
 
2660
    // prepare data for erroneous write
2661
    for ( i = 0 ; i < 3 ; i = i + 1 )
2662
    begin
2663
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2664
        write_data`WRITE_DATA    = wmem_data[110 + i] ;
2665
        write_data`WRITE_SEL     = 4'hF ;
2666
        wishbone_master.blk_write_data[i] = write_data ;
2667
    end
2668
 
2669
    test_name = "CHECKING MASTER ABORT ERROR HANDLING ON CAB MEMORY WRITE" ;
2670
    fork
2671
    begin
2672
        wishbone_master.wb_block_write(write_flags, write_status) ;
2673
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2674
        begin
2675
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2676
            $display("Complete burst write through WB slave didn't succeed!") ;
2677
            test_fail("WB Slave state machine failed to post CAB Memory write") ;
2678
            disable main ;
2679
        end
2680
    end
2681
    begin
2682
        musnt_respond(ok) ;
2683
        if ( ok !== 1 )
2684
        begin
2685
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2686
            $display("Testbench is configured wrong!") ;
2687
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2688
        end
2689
        else
2690
            test_ok ;
2691
    end
2692
    join
2693
 
2694
    // check error status address, data, byte enables and bus command
2695
    // error status bit is signalled on PCI clock and synchronized to WB clock
2696
    // wait one PCI clock cycle
2697
    test_name = "CHECKING ERROR REPORTING REGISTERS' VALUES AFTER MASTER ABORT ERROR" ;
2698
    ok = 1 ;
2699
    @(posedge pci_clock) ;
2700
 
2701
    // wait for two WB clocks for synchronization to be finished
2702
    repeat (2)
2703
        @(posedge wb_clock) ;
2704
 
2705
    // read registers
2706
    config_read( err_cs_offset, 4'h2, temp_val1 ) ;
2707
    if ( temp_val1[8] !== 1 )
2708
    begin
2709
        $display("PCI bus error handling testing failed! Error reporting was enabled, but error was not reported! Time %t ", $time) ;
2710
        test_fail("Error reporting was enabled, but error wasn't reported") ;
2711
        ok = 0 ;
2712
    end
2713
 
2714
    if ( temp_val1[9] !== 1 )
2715
    begin
2716
        $display("PCI bus error handling testing failed! Error source bit value incorrect! Time %t ", $time) ;
2717
        $display("Error source bit should be 1 to indicate master is reporting error!") ;
2718
        test_fail("Error source bit should be 1 to indicate master is reporting error after Master Abort") ;
2719
        ok = 0 ;
2720
    end
2721
 
2722
    if ( temp_val1[31:28] !== 0 )
2723
    begin
2724
        $display("PCI bus error handling testing failed! Byte enable field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2725
        $display("Expected value %b, actualy read value %b !", 4'h0, temp_val1[31:28]) ;
2726
        test_fail("BE field in WB Error Control and Status register was wrong after Master Abort") ;
2727
        ok = 0 ;
2728
    end
2729
 
2730
    if ( temp_val1[27:24] !== `BC_MEM_WRITE )
2731
    begin
2732
        $display("PCI bus error handling testing failed! Bus command field in W_ERR_CS bit has incorrect value! Time %t ", $time) ;
2733
        $display("Expected value %b, actualy read value %b !", `BC_MEM_WRITE, temp_val1[27:24]) ;
2734
        test_fail("BC field in WB Error Control and Status register was wrong after Master Abort") ;
2735
        ok = 0 ;
2736
    end
2737
 
2738
    // read error address register
2739
    config_read( {4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2740
    if ( temp_val1 !== target_address )
2741
    begin
2742
        $display("PCI bus error handling testing failed! Erroneous address register has incorrect value! Time %t ", $time) ;
2743
        $display("Expected value %h, actualy read value %h !", target_address, temp_val1) ;
2744
        test_fail("address provided in WB Erroneous Address register was wrong after Master Abort") ;
2745
        ok = 0 ;
2746
    end
2747
 
2748
    config_read( {4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2749
    if ( temp_val1 !== wmem_data[110] )
2750
    begin
2751
        $display("PCI bus error handling testing failed! Erroneous data register has incorrect value! Time %t ", $time) ;
2752
        $display("Expected value %h, actualy read value %h !", wmem_data[110], temp_val1) ;
2753
        test_fail("data provided in WB Erroneous Data register was wrong after Master Abort") ;
2754
        ok = 0 ;
2755
    end
2756
 
2757
    // check PCI status register
2758
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
2759
    if ( temp_val1[29] !== 1 )
2760
    begin
2761
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2762
        $display("Received Master Abort bit was not set when write was terminated with Master Abort!") ;
2763
        test_fail("Received Master Abort bit in PCI Device Status register was not set when write was terminated with Master Abort") ;
2764
        ok = 0 ;
2765
    end
2766
 
2767
    if ( temp_val1[28] !== 0 )
2768
    begin
2769
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2770
        $display("Received Target Abort bit was set for no reason!") ;
2771
        test_fail("Received Target Abort bit was set for no reason") ;
2772
        ok = 0 ;
2773
    end
2774
 
2775
    if ( ok )
2776
        test_ok ;
2777
 
2778
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
2779
 
2780
    // clear error status bit
2781
    config_write( err_cs_offset, 32'h0000_0100, 4'h2, ok ) ;
2782
 
2783
    test_name = "CHECKING INTERRUPT REQUESTS AFTER MASTER ABORT ERROR" ;
2784
 
2785
    ok = 1 ;
2786
 
2787
    `ifdef HOST
2788
        repeat(4)
2789
        @(posedge wb_clock) ;
2790
        if ( INT_O !== 1 )
2791
        begin
2792
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2793
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
2794
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on WISHBONE bus") ;
2795
            ok = 0 ;
2796
        end
2797
    `else
2798
    `ifdef GUEST
2799
        repeat(4)
2800
        @(posedge pci_clock) ;
2801
        if ( INTA !== 0 )
2802
        begin
2803
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2804
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
2805
            test_fail("WISHBONE error interrupt enable was set, error was signalled, but interrupt request was not presented on PCI bus") ;
2806
            ok = 0 ;
2807
        end
2808
    `endif
2809
    `endif
2810
 
2811
    // read interrupt status register
2812
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
2813
    if ( temp_val1 !== 32'h0000_0002 )
2814
    begin
2815
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2816
        $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt status register has wrong value!") ;
2817
        $display("Expected ISR = %h, actual ISR = %h ", 32'h0000_0002, temp_val1) ;
2818
        test_fail("Interrupt Status register returned wrong value") ;
2819
        ok = 0 ;
2820
    end
2821
 
2822
    if ( ok )
2823
        test_ok ;
2824
    // clear interrupt status bits
2825
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
2826
 
2827
    ok = 1 ;
2828
    test_name = "CHECKING INTERRUPT REQUESTS AFTER CLEARING THEM" ;
2829
    // wait for two clock cycles before checking interrupt request deassertion
2830
    `ifdef HOST
2831
        repeat (4)
2832
            @(posedge wb_clock) ;
2833
 
2834
        if ( INT_O !== 0 )
2835
        begin
2836
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2837
            $display("WISHBONE interrupt request still presented, even when interrupt statuses were cleared!") ;
2838
            test_fail("WISHBONE interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2839
            ok = 0 ;
2840
        end
2841
    `else
2842
    `ifdef GUEST
2843
        repeat (4)
2844
            @(posedge pci_clock) ;
2845
 
2846
        if ( INTA !== 1 )
2847
        begin
2848
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
2849
            $display("PCI interrupt request still presented, even when interrupt statuses were cleared!") ;
2850
            test_fail("PCI interrupt request was still asserted, even when interrupt statuses were cleared!") ;
2851
            ok = 0 ;
2852
        end
2853
    `endif
2854
    `endif
2855
 
2856
    if ( ok )
2857
        test_ok ;
2858
 
2859
    test_name = "CHECK NORMAL WRITING/READING FROM WISHBONE TO PCI AFTER ERRORS WERE PRESENTED" ;
2860
    ok = 1 ;
2861
    // enable target
2862 45 mihad
    configuration_cycle_write(0,                        // bus number
2863
                              `TAR1_IDSEL_INDEX - 11,   // device number
2864
                              0,                        // function number
2865
                              1,                        // register number
2866
                              0,                        // type of configuration cycle
2867
                              4'b0001,                  // byte enables
2868
                              32'h0000_0007             // data
2869 15 mihad
                             ) ;
2870
    // prepare data for ok write
2871
    for ( i = 0 ; i < 3 ; i = i + 1 )
2872
    begin
2873
        write_data`WRITE_ADDRESS = target_address + 4*i ;
2874
        write_data`WRITE_DATA    = wmem_data[113 + i] ;
2875
        write_data`WRITE_SEL     = 4'hF ;
2876
        wishbone_master.blk_write_data[i] = write_data ;
2877
    end
2878
 
2879
    wishbone_master.wb_block_write(write_flags, write_status) ;
2880
 
2881
    if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
2882
    begin
2883
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2884
        $display("Complete burst write through WB slave didn't succeed!") ;
2885
        test_fail("WB Slave state machine failed to post CAB write") ;
2886
        disable main ;
2887
    end
2888
 
2889
    // do a read
2890
    for ( i = 0 ; i < 3 ; i = i + 1 )
2891
    begin
2892
        read_data`READ_ADDRESS = target_address + 4*i ;
2893
        read_data`READ_SEL     = 4'hF ;
2894
        wishbone_master.blk_read_data_in[i] = read_data ;
2895
    end
2896
 
2897
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2898
    write_flags`WB_TRANSFER_SIZE   = 3 ;
2899
    write_flags`WB_TRANSFER_CAB    = 1 ;
2900
 
2901
    wishbone_master.wb_block_read( write_flags, read_status ) ;
2902
 
2903
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
2904
    begin
2905
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2906
        $display("Complete burst read through WB slave didn't succeed!") ;
2907
        test_fail("Delayed CAB write was not processed as expected") ;
2908
        disable main ;
2909
    end
2910
 
2911
    for ( i = 0 ; i < 3 ; i = i + 1 )
2912
    begin
2913
        read_status = wishbone_master.blk_read_data_out[i] ;
2914
        if ( read_status`READ_DATA !== wmem_data[113 + i] )
2915
        begin
2916
            display_warning( target_address + 4*i, wmem_data[113 + i], read_status`READ_DATA ) ;
2917
            test_fail ( "data value provided by PCI bridge for normal read was not as expected") ;
2918
        end
2919
    end
2920
 
2921
    $display("Introducing master abort error to single read!") ;
2922
    // disable target
2923 45 mihad
    configuration_cycle_write(0,                        // bus number
2924
                              `TAR1_IDSEL_INDEX - 11,   // device number
2925
                              0,                        // function number
2926
                              1,                        // register number
2927
                              0,                        // type of configuration cycle
2928
                              4'b0001,                  // byte enables
2929
                              32'h0000_0000             // data
2930 15 mihad
                             ) ;
2931
    // set read data
2932
    read_data`READ_ADDRESS = target_address ;
2933
    read_data`READ_SEL     = 4'hF ;
2934
 
2935
    // enable automatic retry handling
2936
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
2937
    write_flags`WB_TRANSFER_CAB    = 0 ;
2938
 
2939
    test_name = "MASTER ABORT ERROR HANDLING FOR WB TO PCI READS" ;
2940
    fork
2941
    begin
2942
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2943
    end
2944
    begin
2945
        musnt_respond(ok) ;
2946
        if ( ok !== 1 )
2947
        begin
2948
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
2949
            $display("Testbench is configured wrong!") ;
2950
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
2951
        end
2952
    end
2953
    join
2954
 
2955
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
2956
    begin
2957
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2958
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
2959
        $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) ;
2960
        test_fail("read didn't finish on WB bus as expected") ;
2961
        disable main ;
2962
    end
2963
 
2964
    test_ok ;
2965
 
2966
 
2967
    // now check for error statuses - because reads are delayed, nothing of a kind should happen on error
2968
    test_name = "CHECKING ERROR STATUS AFTER MASTER ABORT ON READ" ;
2969
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
2970
    if ( temp_val1[8] !== 0 )
2971
    begin
2972
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2973
        $display("Error reporting mechanism reports errors on read terminated with master abort! This shouldn't happen!") ;
2974
        test_fail("error status bit should not be set after error occures on Delayed Read Transaction") ;
2975
    end
2976
    else
2977
        test_ok ;
2978
 
2979
    // now check normal read operation
2980 45 mihad
    configuration_cycle_write(0,                        // bus number
2981
                              `TAR1_IDSEL_INDEX - 11,   // device number
2982
                              0,                        // function number
2983
                              1,                        // register number
2984
                              0,                        // type of configuration cycle
2985
                              4'b0001,                  // byte enables
2986
                              32'h0000_0007             // data
2987 15 mihad
                             ) ;
2988
 
2989 45 mihad
    test_name = "CHECK NORMAL READ AFTER MASTER ABORT TERMINATED READ" ;
2990 15 mihad
    read_data`READ_ADDRESS = target_address ;
2991
    read_data`READ_SEL     = 4'hF ;
2992
 
2993
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
2994
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
2995
    begin
2996
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
2997
        $display("WB slave failed to process single read!") ;
2998
        $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) ;
2999
        test_fail("PCI Bridge didn't process single Delayed Read as expected") ;
3000
        disable main ;
3001
    end
3002
 
3003
    if ( read_status`READ_DATA !== wmem_data[113] )
3004
    begin
3005
        display_warning( target_address, wmem_data[113 + i], read_status`READ_DATA ) ;
3006
        test_fail("when read finished on WB bus, wrong data was provided") ;
3007
    end
3008
    else
3009
        test_ok ;
3010
 
3011
    // check PCI status register
3012 45 mihad
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORT ON DELAYED READ" ;
3013 15 mihad
    ok = 1 ;
3014
 
3015
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3016
    if ( temp_val1[29] !== 1 )
3017
    begin
3018
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3019
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3020
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3021
        ok = 0 ;
3022
    end
3023
 
3024
    if ( temp_val1[28] !== 0 )
3025
    begin
3026
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3027
        $display("Received Target Abort bit was set for no reason!") ;
3028
        test_fail("Received Target Abort bit was set for no reason") ;
3029
        ok = 0 ;
3030
    end
3031
    if ( ok )
3032
        test_ok ;
3033
 
3034
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3035
 
3036
    $display("Introducing master abort error to CAB read!") ;
3037
    test_name = "MASTER ABORT ERROR DURING CAB READ FROM WB TO PCI" ;
3038
 
3039 45 mihad
    configuration_cycle_write(0,                        // bus number
3040
                              `TAR1_IDSEL_INDEX - 11,   // device number
3041
                              0,                        // function number
3042
                              1,                        // register number
3043
                              0,                        // type of configuration cycle
3044
                              4'b0001,                  // byte enables
3045
                              32'h0000_0000             // data
3046 15 mihad
                             ) ;
3047
 
3048
    for ( i = 0 ; i < 3 ; i = i + 1 )
3049
    begin
3050
        read_data`READ_ADDRESS = target_address + 4*i ;
3051
        read_data`READ_SEL     = 4'hF ;
3052
        wishbone_master.blk_read_data_in[i] = read_data ;
3053
    end
3054
 
3055
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3056
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3057
    write_flags`WB_TRANSFER_CAB    = 1 ;
3058
 
3059
    fork
3060
    begin
3061
        wishbone_master.wb_block_read( write_flags, read_status ) ;
3062
    end
3063
    begin
3064
        musnt_respond(ok) ;
3065
        if ( ok !== 1 )
3066
        begin
3067
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3068
            $display("Testbench is configured wrong!") ;
3069
            test_fail("transaction wasn't initiated by PCI Master state machine or Target responded and Master Abort didn't occur");
3070
        end
3071
    end
3072
    join
3073
 
3074
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3075
    begin
3076
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3077
        $display("Read terminated with master abort should return zero data and terminate WISHBONE cycle with error!") ;
3078
        $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) ;
3079
        test_fail("Read terminated with Master Abort didn't return zero data or terminate WISHBONE cycle with error") ;
3080
        disable main ;
3081
    end
3082
    else
3083
        test_ok ;
3084
 
3085
    test_name = "CHECK PCI DEVICE STATUS REGISTER AFTER READ TERMINATED WITH MASTER ABORT" ;
3086
    ok = 1 ;
3087
    // check PCI status register
3088
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3089
    if ( temp_val1[29] !== 1 )
3090
    begin
3091
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3092
        $display("Received Master Abort bit was not set when read was terminated with Master Abort!") ;
3093
        test_fail("Received Master Abort bit was not set when read was terminated with Master Abort") ;
3094
        ok = 0 ;
3095
    end
3096
 
3097
    if ( temp_val1[28] !== 0 )
3098
    begin
3099
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3100
        $display("Received Target Abort bit was set for no reason!") ;
3101
        test_fail("Received Target Abort bit was set for no reason") ;
3102
        ok = 0 ;
3103
    end
3104
 
3105
    if ( ok )
3106
        test_ok ;
3107
 
3108
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3109
 
3110
    $display("Introducing target abort termination to single write!") ;
3111
 
3112
    // disable error reporting and interrupts
3113
    test_name = "SETUP BRIDGE FOR TARGET ABORT HANDLING TESTS" ;
3114
 
3115 45 mihad
    configuration_cycle_write(0,                        // bus number
3116
                              `TAR1_IDSEL_INDEX - 11,   // device number
3117
                              0,                        // function number
3118
                              1,                        // register number
3119
                              0,                        // type of configuration cycle
3120
                              4'b0001,                  // byte enables
3121
                              32'h0000_0007             // data
3122 15 mihad
                             ) ;
3123
 
3124
    config_write( err_cs_offset, 32'h0000_0000, 4'hF, ok) ;
3125
    if ( ok !== 1 )
3126
    begin
3127
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3128
        test_fail("WB Error Control and Status register couldn't be written to") ;
3129
        disable main ;
3130
    end
3131
 
3132
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0000, 4'h1, ok) ;
3133
    if ( ok !== 1 )
3134
    begin
3135
        $display("PCI bus error handling testing failed! Failed to write ICR register! Time %t ", $time) ;
3136
        test_fail("Interrupt Control register couldn't be written to") ;
3137
        disable main ;
3138
    end
3139
 
3140
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3141
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3142
 
3143
    write_data`WRITE_ADDRESS = target_address ;
3144
    write_data`WRITE_DATA    = wmem_data[0] ;
3145
    write_data`WRITE_SEL     = 4'hF ;
3146
 
3147
    wishbone_master.blk_write_data[0] = write_data ;
3148
 
3149
    write_data`WRITE_ADDRESS = target_address + 4;
3150
    write_data`WRITE_DATA    = wmem_data[1] ;
3151
    write_data`WRITE_SEL     = 4'hF ;
3152
 
3153
    wishbone_master.blk_write_data[1] = write_data ;
3154
 
3155
    write_flags`WB_TRANSFER_SIZE = 2 ;
3156
 
3157
    // don't handle retries
3158
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3159
    write_flags`WB_TRANSFER_CAB    = 0 ;
3160
 
3161
    test_name = "TARGET ABORT ERROR ON SINGLE WRITE" ;
3162
    fork
3163
    begin
3164
        wishbone_master.wb_block_write(write_flags, write_status) ;
3165
 
3166
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3167
        begin
3168
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3169
            $display("Image writes were not accepted as expected!") ;
3170
            $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) ;
3171
            test_fail("WB Slave state machine failed to post two single memory writes")  ;
3172
            disable main ;
3173
        end
3174
 
3175
        // read data back to see, if it was written OK
3176
        read_data`READ_ADDRESS         = target_address + 4;
3177
        read_data`READ_SEL             = 4'hF ;
3178
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3179
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
3180
    end
3181
    begin
3182
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
3183
        if ( ok !== 1 )
3184
        begin
3185
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Abort during Memory Write was expected") ;
3186
        end
3187
        else
3188
            test_ok ;
3189
 
3190
        test_name = "NORMAL SINGLE MEMORY WRITE IMMEDIATELY AFTER ONE TERMINATED WITH TARGET ABORT" ;
3191
 
3192
        // when first transaction finishes - enable normal target response!
3193
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Normal_Completion ;
3194
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3195
 
3196
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3197
        if ( ok !== 1 )
3198
        begin
3199
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Write was expected") ;
3200
        end
3201
        else
3202
            test_ok ;
3203
 
3204
        test_name = "NORMAL SINGLE MEMORY READ AFTER WRITE TERMINATED WITH TARGET ABORT" ;
3205
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
3206
        if ( ok !== 1 )
3207
        begin
3208
            test_fail("unexpected transaction or no response detected on PCI bus, when single Memory Read was expected") ;
3209
        end
3210
    end
3211
    join
3212
 
3213
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
3214
    begin
3215
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3216
        $display("Bridge failed to process single read after target abort terminated write!") ;
3217
        test_fail("bridge failed to process single delayed read after target abort terminated write") ;
3218
        disable main ;
3219
    end
3220
 
3221
    if ( read_status`READ_DATA !== wmem_data[1] )
3222
    begin
3223
        display_warning( target_address + 4, wmem_data[1], read_status`READ_DATA ) ;
3224
        test_fail("bridge returned unexpected data on read following Target Abort Terminated write") ;
3225
    end
3226
    else
3227
        test_ok ;
3228
 
3229
    // check interrupt and error statuses!
3230
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3231
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3232
    if ( temp_val1[8] !== 0 )
3233
    begin
3234
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3235
        $display("Error bit in error status register was set even though error reporting was disabled!") ;
3236
        test_fail("Error bit in error status register was set even though error reporting was disabled") ;
3237
    end
3238
    else
3239
        test_ok ;
3240
 
3241
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3242
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3243
    if ( temp_val1[1] !== 0 )
3244
    begin
3245
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3246
        $display("Error interrupt request bit was set after PCI error termination, even though interrupts were disabled!") ;
3247
        test_fail("Error interrupt request bit was set after PCI Target Abort termination, even though interrupts were disabled") ;
3248
    end
3249
    else
3250
        test_ok ;
3251
 
3252
    // check PCI status register
3253
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3254
    ok = 1 ;
3255
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3256
    if ( temp_val1[29] !== 0 )
3257
    begin
3258
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3259
        $display("Received Master Abort bit was set with no reason!") ;
3260
        test_fail("Received Master Abort bit was set with no reason") ;
3261
        ok = 0 ;
3262
    end
3263
 
3264
    if ( temp_val1[28] !== 1 )
3265
    begin
3266
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3267
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3268
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3269
        ok = 0 ;
3270
    end
3271
 
3272
    if ( ok )
3273
        test_ok ;
3274
 
3275
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3276
 
3277
    test_name = "TARGET ABORT ERROR ON CAB MEMORY WRITE" ;
3278
 
3279
    $display("Introducing target abort termination to CAB write!") ;
3280
    // enable error reporting mechanism
3281
 
3282
    config_write( err_cs_offset, 32'h0000_0001, 4'hF, ok) ;
3283
    if ( ok !== 1 )
3284
    begin
3285
        $display("PCI bus error handling testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
3286
        test_fail("WB Error Control and Status register could not be written to") ;
3287
        disable main ;
3288
    end
3289
 
3290
    for ( i = 0 ; i < 3 ; i = i + 1 )
3291
    begin
3292
        write_data`WRITE_ADDRESS = target_address + 8 + 4*i ;
3293
        write_data`WRITE_DATA    = wmem_data[120 + i] ;
3294
        write_data`WRITE_SEL     = 4'b1010 ;
3295
        wishbone_master.blk_write_data[i] = write_data ;
3296
    end
3297
 
3298
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3299
    write_flags`WB_TRANSFER_CAB    = 1 ;
3300
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3301
 
3302
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3303
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3304
 
3305
    fork
3306
    begin
3307
        wishbone_master.wb_block_write(write_flags, write_status) ;
3308
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3309
        begin
3310
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3311
            $display("Bridge failed to process complete CAB write!") ;
3312
            test_fail("bridge failed to post CAB Memory Write") ;
3313
            disable main ;
3314
        end
3315
    end
3316
    begin
3317
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok) ;
3318
        if ( ok !== 1 )
3319
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3320
        else
3321
            test_ok ;
3322
    end
3323
    join
3324
 
3325
    // check statuses and data from error
3326
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3327
    ok = 1 ;
3328
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3329
    if ( temp_val1[8] !== 1 )
3330
    begin
3331
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3332
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3333
        test_fail("Error Signaled bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3334
        ok = 0 ;
3335
    end
3336
 
3337
    if ( temp_val1[9] !== 0 )
3338
    begin
3339
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3340
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3341
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3342
        ok = 0 ;
3343
    end
3344
 
3345
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3346
    begin
3347
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3348
        $display("Value in W_ERR_CS register was wrong!") ;
3349
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b0101, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3350
        test_fail("BE Field didn't provided expected value") ;
3351
        ok = 0 ;
3352
    end
3353
 
3354
    if ( ok )
3355
        test_ok ;
3356
 
3357
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3358
    ok = 1 ;
3359
    // check erroneous address and data
3360
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3361
    if ( temp_val1 !== (target_address + 8) )
3362
    begin
3363
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3364
        $display("Value in W_ERR_ADDR register was wrong!") ;
3365
        $display("Expected value = %h, actual value = %h " , target_address + 8, temp_val1 ) ;
3366
        test_fail("Value in WB Erroneous Address register was wrong") ;
3367
        ok = 0 ;
3368
    end
3369
 
3370
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3371
    if ( temp_val1 !== wmem_data[120] )
3372
    begin
3373
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3374
        $display("Value in W_ERR_DATA register was wrong!") ;
3375
        $display("Expected value = %h, actual value = %h " , wmem_data[120], temp_val1 ) ;
3376
        test_fail("Value in WB Erroneous Data register was wrong") ;
3377
        ok = 0 ;
3378
    end
3379
 
3380
    if ( ok )
3381
        test_ok ;
3382
 
3383
    test_name = "PCI DEVICE STATUS VALUE CHECK AFTER WRITE TARGET ABORT" ;
3384
    ok = 1 ;
3385
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3386
    if ( temp_val1[29] !== 0 )
3387
    begin
3388
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3389
        $display("Received Master Abort bit was set with no reason!") ;
3390
        test_fail("Received Master Abort bit was set for no reason") ;
3391
        ok = 0 ;
3392
    end
3393
 
3394
    if ( temp_val1[28] !== 1 )
3395
    begin
3396
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3397
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3398
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3399
        ok = 0 ;
3400
    end
3401
 
3402
    if ( ok )
3403
        test_ok ;
3404
 
3405
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3406
 
3407
    // clear error status bit and enable error interrupts
3408
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3409
    config_write( {4'h1, `ICR_ADDR, 2'b00}, 32'h0000_0002, 4'h1, ok) ;
3410
 
3411
    // check if error bit was cleared
3412
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER CLEARING ERROR STATUS" ;
3413
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3414
    if ( temp_val1[8] !== 0 )
3415
    begin
3416
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3417
        $display("Error bit was not cleared even though one was written to its location!") ;
3418
        test_fail("Error bit was not cleared even though one was written to its location") ;
3419
    end
3420
 
3421
    // repeat same write with different target configuration
3422
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Abort ;
3423
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
3424
 
3425
    test_name = "TARGET ABORT TERMINATION ON SECOND DATA PHASE OF BURST WRITE" ;
3426
    fork
3427
    begin
3428
        write_flags`WB_TRANSFER_SIZE = 2 ;
3429
        wishbone_master.wb_block_write(write_flags, write_status) ;
3430
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
3431
        begin
3432
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3433
            $display("Bridge failed to process complete CAB write!") ;
3434
            test_fail("bridge failed to post CAB Memory Write") ;
3435
            disable main ;
3436
        end
3437
 
3438
        write_flags`WB_TRANSFER_SIZE = 3 ;
3439
        wishbone_master.wb_block_write(write_flags, write_status) ;
3440
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
3441
        begin
3442
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3443
            $display("Bridge failed to process complete CAB write!") ;
3444
            test_fail("bridge failed to post CAB Memory Write") ;
3445
            disable main ;
3446
        end
3447
    end
3448
    begin
3449
        pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
3450
        if ( ok !== 1 )
3451
            test_fail("unexpected transaction or no response detected on PCI bus, when Target Aborted Memory Write was expected") ;
3452
        else
3453
        begin
3454
            test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
3455
            test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
3456
            pci_transaction_progress_monitor(target_address + 8, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok) ;
3457
            if ( ok !== 1 )
3458
                test_fail("unexpected transaction or no response detected on PCI bus, when Normal Memory Write was posted immediately after Target Aborted Memory write") ;
3459
            else
3460
                test_ok ;
3461
        end
3462
    end
3463
    join
3464
 
3465
    test_name = "WB ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER WRITE TARGET ABORT" ;
3466
    ok = 1 ;
3467
    // check statuses and data from error
3468
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3469
    if ( temp_val1[8] !== 1 )
3470
    begin
3471
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3472
        $display("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled!") ;
3473
        test_fail("Error bit was not set even though write was terminated with Target Abort and error reporting was enabled") ;
3474
        ok = 0 ;
3475
    end
3476
 
3477
    if ( temp_val1[9] !== 0 )
3478
    begin
3479
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3480
        $display("Error source bit was not 0 to indicate target signalled the error!") ;
3481
        test_fail("Error source bit was not 0 to indicate target signalled the error") ;
3482
        ok = 0 ;
3483
    end
3484
 
3485
    if ( temp_val1[31:24] !== {4'b0101, `BC_MEM_WRITE} )
3486
    begin
3487
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3488
        $display("Value in W_ERR_CS register was wrong!") ;
3489
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_MEM_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3490
        test_fail("BE or bus command field(s) didn't provide expected value") ;
3491
        ok = 0 ;
3492
    end
3493
 
3494
    if ( ok )
3495
        test_ok ;
3496
 
3497
    // check erroneous address and data
3498
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3499
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TARGET ABORT" ;
3500
    ok = 1 ;
3501
    if ( temp_val1 !== (target_address + 8 + 4) )
3502
    begin
3503
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3504
        $display("Value in W_ERR_ADDR register was wrong!") ;
3505
        $display("Expected value = %h, actual value = %h " , target_address + 8 + 4, temp_val1 ) ;
3506
        test_fail("Value in WB Erroneous Address register was wrong") ;
3507
        ok = 0 ;
3508
 
3509
    end
3510
 
3511
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3512
    if ( temp_val1 !== wmem_data[121] )
3513
    begin
3514
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3515
        $display("Value in W_ERR_DATA register was wrong!") ;
3516
        $display("Expected value = %h, actual value = %h " , wmem_data[121], temp_val1 ) ;
3517
        test_fail("Value in WB Erroneous Data register was wrong") ;
3518
        ok = 0 ;
3519
    end
3520
 
3521
    if ( ok )
3522
        test_ok ;
3523
 
3524
    test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR REPORTING TRIGGER" ;
3525
    `ifdef HOST
3526
        repeat(4)
3527
            @(posedge wb_clock) ;
3528
        if ( INT_O !== 1 )
3529
        begin
3530
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3531
            $display("WISHBONE error interrupt enable is set, error was signalled, but interrupt request was not presented on WISHBONE bus!") ;
3532
            test_fail("interrupt request was not presented on WISHBONE bus") ;
3533
        end
3534
        else
3535
            test_ok ;
3536
    `else
3537
    `ifdef GUEST
3538
        repeat(4)
3539
            @(posedge pci_clock) ;
3540
        if ( INTA !== 0 )
3541
        begin
3542
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3543
            $display("WISHBONE error interrupt enable is set, error was signaled, but interrupt request was not presented on PCI bus!") ;
3544
            test_fail("interrupt request was not presented on PCI bus") ;
3545
        end
3546
        else
3547
            test_ok ;
3548
    `endif
3549
    `endif
3550
 
3551
    // read interrupt status register
3552
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3553
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3554
    if ( temp_val1[1] !== 1 )
3555
    begin
3556
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3557
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3558
        test_fail("Expected Interrupt status bit wasn't set") ;
3559
    end
3560
 
3561
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3562
 
3563
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER TARGET ABORTED MEMORY WRITE" ;
3564
    ok = 1 ;
3565
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3566
    if ( temp_val1[29] !== 0 )
3567
    begin
3568
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3569
        $display("Received Master Abort bit was set with no reason!") ;
3570
        test_fail("Received Master Abort bit was set with no reason") ;
3571
        ok = 0 ;
3572
    end
3573
 
3574
    if ( temp_val1[28] !== 1 )
3575
    begin
3576
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3577
        $display("Received Target Abort bit was not set when write transaction was terminated with target abort!") ;
3578
        test_fail("Received Target Abort bit was not set when write transaction was terminated with target abort") ;
3579
        ok = 0 ;
3580
    end
3581
 
3582
    if ( ok )
3583
        test_ok ;
3584
 
3585
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3586
 
3587
    // clear interrupts and errors
3588
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3589
    repeat( 3 )
3590
        @(posedge pci_clock) ;
3591
 
3592
    repeat( 2 )
3593
        @(posedge wb_clock) ;
3594
 
3595
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BITS" ;
3596
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3597
    if ( temp_val1[1] !== 0 )
3598
    begin
3599
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3600
        $display("WISHBONE error interrupt status remains set in ISR after writing one to its location!") ;
3601
        test_fail("WISHBONE error interrupt status remains set in Interrupt Status register after writing one to its location") ;
3602
    end
3603
    else
3604
        test_ok ;
3605
 
3606
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER CLEARING STATUS BIT" ;
3607
    config_read( err_cs_offset, 4'b0011, temp_val1 ) ;
3608
    if ( temp_val1[8] !== 0 )
3609
    begin
3610
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3611
        $display("WISHBONE error status remains set in W_ERR_CS after writing one to its location!") ;
3612
        test_fail("WISHBONE error status remains set in WB Error Status register after writing one to its location") ;
3613
    end
3614
 
3615
 
3616
    $display("Introducing Target Abort error to single read!") ;
3617
    // set read data
3618
    read_data`READ_ADDRESS = target_address + 8 ;
3619
    read_data`READ_SEL     = 4'hF ;
3620
 
3621
    // enable automatic retry handling
3622
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3623
    write_flags`WB_TRANSFER_CAB    = 0 ;
3624
 
3625
    test_name = "TARGET ABORT DURING SINGLE MEMORY READ" ;
3626
 
3627
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3628
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
3629
 
3630
    wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
3631
 
3632
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
3633
    begin
3634
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3635
        $display("Read terminated with Target Abort should return zero data and terminate WISHBONE cycle with error!") ;
3636
        $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) ;
3637
        test_fail("single read terminated with Target Abort shouldn't return any data and should terminate WISHBONE cycle with error") ;
3638
        disable main ;
3639
    end
3640
    else
3641
        test_ok ;
3642
 
3643
    // now check for interrupts or error statuses - because reads are delayed, nothing of a kind should happen on error
3644
    test_name = "WB ERROR STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3645
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3646
    if ( temp_val1[8] !== 0 )
3647
    begin
3648
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3649
        $display("Error reporting mechanism reports errors on read terminated with Target Abort! This shouldn't happen!") ;
3650
        test_fail("Error reporting mechanism shouldn't report errors on reads terminated with Target Abort") ;
3651
    end
3652
    else
3653
        test_ok ;
3654
 
3655
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3656
    ok = 1 ;
3657
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3658
    if ( temp_val1[29] !== 0 )
3659
    begin
3660
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3661
        $display("Received Master Abort bit was set with no reason!") ;
3662
        test_fail("Received Master Abort bit was set with no reason") ;
3663
        ok = 0 ;
3664
    end
3665
 
3666
    if ( temp_val1[28] !== 1 )
3667
    begin
3668
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3669
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3670
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3671
        ok = 0 ;
3672
    end
3673
 
3674
    if ( ok )
3675
        test_ok ;
3676
 
3677
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3678
 
3679
    test_name = "INTERRUPT STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3680
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3681
    if ( temp_val1[1] !== 0 )
3682
    begin
3683
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3684
        $display("WISHBONE error interrupt status set after read was terminated with an error - this shouldn't happen!") ;
3685
        test_fail("WISHBONE Error Interrupt status shouldn't be set after read terminated with Target Abort") ;
3686
    end
3687
    else
3688
        test_ok ;
3689
 
3690
    $display("Introducing Target Abort error to CAB read!") ;
3691
    test_name = "TARGET ABORT ERROR DURING SECOND DATAPHASE OF BURST READ" ;
3692
 
3693
    for ( i = 0 ; i < 4 ; i = i + 1 )
3694
    begin
3695
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3696
        read_data`READ_SEL     = 4'b1010 ;
3697
        wishbone_master.blk_read_data_in[i] = read_data ;
3698
    end
3699
 
3700
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3701
    write_flags`WB_TRANSFER_SIZE   = 2 ;
3702
    write_flags`WB_TRANSFER_CAB    = 1 ;
3703
 
3704
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3705
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 2 ;
3706
 
3707
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3708
 
3709
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 1) || (read_status`CYC_ERR !== 1) )
3710
    begin
3711
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3712
        $display("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer!") ;
3713
        $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) ;
3714
        test_fail("Read terminated with Target Abort on second phase should return one data and terminate WISHBONE cycle with error on second transfer") ;
3715
        disable main ;
3716
    end
3717
 
3718
    read_status = wishbone_master.blk_read_data_out[0] ;
3719
    temp_val1 = read_status`READ_DATA ;
3720
    temp_val2 = wmem_data[120] ;
3721
 
3722
    // last write to this address was with only two byte enables - check only those
3723
    if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3724
    begin
3725
        display_warning( target_address + 8, wmem_data[120], read_status`READ_DATA ) ;
3726
        test_fail("data provided during normaly completed first dataphase didn't have expected value");
3727
    end
3728
    else
3729
        test_ok ;
3730
 
3731
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3732
    ok = 1 ;
3733
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3734
    if ( temp_val1[29] !== 0 )
3735
    begin
3736
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3737
        $display("Received Master Abort bit was set with no reason!") ;
3738
        test_fail("Received Master Abort bit was set with no reason") ;
3739
        ok = 0 ;
3740
    end
3741
 
3742
    if ( temp_val1[28] !== 1 )
3743
    begin
3744
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3745
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3746
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3747
        ok = 0 ;
3748
    end
3749
 
3750
    if ( ok )
3751
       test_ok ;
3752
 
3753
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3754
 
3755
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3756
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3757
 
3758
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3759
    for ( i = 0 ; i < 3 ; i = i + 1 )
3760
    begin
3761
        read_data`READ_ADDRESS = target_address + 4*i ;
3762
        read_data`READ_SEL     = 4'b1111 ;
3763
        wishbone_master.blk_read_data_in[i] = read_data ;
3764
    end
3765
 
3766
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3767
 
3768
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3769
 
3770
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3771
    begin
3772
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3773
        $display("Complete burst read through WB slave didn't succeed!") ;
3774
        test_fail("bridge didn't process Burst Read in an expected way") ;
3775
        disable main ;
3776
    end
3777
    else
3778
        test_ok ;
3779
 
3780
    test_name = "TARGET ABORT ERROR DURING LAST DATAPHASE OF BURST READ" ;
3781
 
3782
    for ( i = 0 ; i < 3 ; i = i + 1 )
3783
    begin
3784
        read_data`READ_ADDRESS = target_address + 8 + 4*i ;
3785
        read_data`READ_SEL     = 4'b1111 ;
3786
        wishbone_master.blk_read_data_in[i] = read_data ;
3787
    end
3788
 
3789
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
3790
    write_flags`WB_TRANSFER_SIZE   = 4 ;
3791
    write_flags`WB_TRANSFER_CAB    = 1 ;
3792
 
3793
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
3794
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 4 ;
3795
 
3796
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3797
 
3798
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 3) || (read_status`CYC_ERR !== 1) )
3799
    begin
3800
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3801
        $display("Read terminated with Target Abort on last dataphase should return 3 words and terminate WISHBONE cycle with error on fourth transfer!") ;
3802
        $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) ;
3803
        test_fail("Read terminated with Target Abort on last dataphase should return three words and terminate WISHBONE cycle with error on fourth transfer") ;
3804
        disable main ;
3805
    end
3806
 
3807
    for ( i = 0 ; i < 3 ; i = i + 1 )
3808
    begin
3809
        ok = 1 ;
3810
        read_status = wishbone_master.blk_read_data_out[i] ;
3811
        temp_val1 = read_status`READ_DATA ;
3812
        temp_val2 = wmem_data[120 + i] ;
3813
 
3814
        // last write to this address was with only two byte enables - check only those
3815
        if ( (temp_val1[31:24] !== temp_val2[31:24]) || (temp_val1[15:8] !== temp_val2[15:8]) )
3816
        begin
3817
            display_warning( target_address + 8 + 4*i, wmem_data[120 + i], read_status`READ_DATA ) ;
3818
            test_fail("data provided during normaly completed first dataphase didn't have expected value");
3819
            ok = 0 ;
3820
        end
3821
    end
3822
 
3823
    if ( ok )
3824
        test_ok ;
3825
 
3826
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER READ TERMINATED WITH TARGET ABORT" ;
3827
    ok = 1 ;
3828
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3829
    if ( temp_val1[29] !== 0 )
3830
    begin
3831
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3832
        $display("Received Master Abort bit was set with no reason!") ;
3833
        test_fail("Received Master Abort bit was set with no reason") ;
3834
        ok = 0 ;
3835
    end
3836
 
3837
    if ( temp_val1[28] !== 1 )
3838
    begin
3839
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3840
        $display("Received Target Abort bit was not set when read transaction was terminated with target abort!") ;
3841
        test_fail("Received Target Abort bit was not set when read transaction was terminated with target abort") ;
3842
        ok = 0 ;
3843
    end
3844
 
3845
    if ( ok )
3846
       test_ok ;
3847
 
3848
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
3849
 
3850
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
3851
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
3852
 
3853
    test_name = "CHECK NORMAL BURST READ AFTER TARGET ABORT TERMINATED BURST READ" ;
3854
    for ( i = 0 ; i < 3 ; i = i + 1 )
3855
    begin
3856
        read_data`READ_ADDRESS = target_address + 4*i ;
3857
        read_data`READ_SEL     = 4'b1111 ;
3858
        wishbone_master.blk_read_data_in[i] = read_data ;
3859
    end
3860
 
3861
    write_flags`WB_TRANSFER_SIZE   = 3 ;
3862
 
3863
    wishbone_master.wb_block_read( write_flags, read_status ) ;
3864
 
3865
    if ( read_status`CYC_ACTUAL_TRANSFER !== 3 )
3866
    begin
3867
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3868
        $display("Complete burst read through WB slave didn't succeed!") ;
3869
        test_fail("bridge didn't process Burst Read in an expected way") ;
3870
        disable main ;
3871
    end
3872
    else
3873
        test_ok ;
3874
 
3875
    // test error on IO write
3876
    // change base address
3877
    config_write( ba_offset, image_base + 1, 4'hF, ok ) ;
3878
    write_data`WRITE_SEL     = 4'b0101 ;
3879
    write_data`WRITE_ADDRESS = target_address ;
3880
    write_data`WRITE_DATA    = 32'hAAAA_AAAA ;
3881
 
3882
    write_flags`WB_TRANSFER_CAB    = 0 ;
3883
    write_flags`WB_TRANSFER_SIZE   = 1 ;
3884
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
3885
    test_name = "ERROR REPORTING FUNCTIONALITY FOR I/O WRITE" ;
3886
    fork
3887
    begin
3888
        wishbone_master.wb_single_write ( write_data, write_flags, write_status ) ;
3889
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
3890
        begin
3891
            $display("PCI bus error handling testing failed! Time %t ", $time) ;
3892
            $display("WB slave failed to accept IO write!") ;
3893
            test_fail("WB Slave state machine didn't post I/O write as expected") ;
3894
            disable main ;
3895
        end
3896
    end
3897
    begin
3898
        musnt_respond(ok) ;
3899
        if ( ok !== 1 )
3900
        begin
3901
            $display("PCI bus error handling testing failed! Test of master abort handling got one target to respond! Time %t ", $time) ;
3902
            $display("Testbench is configured wrong!") ;
3903
            test_fail("I/O write didn't start a transaction on PCI or target responded when not expected") ;
3904
        end
3905
        else
3906
            test_ok ;
3907
    end
3908
    join
3909
 
3910
    // check statuses and everything else
3911
    test_name = "WB ERROR STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3912
    ok = 1 ;
3913
    config_read( err_cs_offset, 4'hF, temp_val1 ) ;
3914
    if ( temp_val1[8] !== 1 )
3915
    begin
3916
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3917
        $display("Error bit was not set even though write was terminated with Master Abort and error reporting was enabled!") ;
3918
        test_fail("WB Error bit was not set even though write was terminated with Master Abort and error reporting was enabled") ;
3919
        ok = 0 ;
3920
    end
3921
 
3922
    if ( temp_val1[9] !== 1 )
3923
    begin
3924
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3925
        $display("Error source bit was not 1 to indicate Master signalled the error!") ;
3926
        test_fail("Error source bit was not 1 to indicate Master signalled the error") ;
3927
        ok = 0 ;
3928
    end
3929
 
3930
    if ( temp_val1[31:24] !== {4'b1010, `BC_IO_WRITE} )
3931
    begin
3932
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3933
        $display("Value in W_ERR_CS register was wrong!") ;
3934
        $display("Expected BE = %b, BC = %b ; actuals: BE = %b, BC = %b ", 4'b1010, `BC_IO_WRITE, temp_val1[31:28], temp_val1[27:24]) ;
3935
        test_fail("values in BE or BC field in WB Error Status register was/were wrong") ;
3936
        ok = 0 ;
3937
    end
3938
 
3939
    if ( ok )
3940
        test_ok ;
3941
 
3942
    // check erroneous address and data
3943
    test_name = "WB ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES AFTER MASTER ABORTED I/O WRITE" ;
3944
    ok = 1 ;
3945
    config_read( { 4'h1, `W_ERR_ADDR_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3946
    if ( temp_val1 !== target_address )
3947
    begin
3948
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3949
        $display("Value in W_ERR_ADDR register was wrong!") ;
3950
        $display("Expected value = %h, actual value = %h " , target_address, temp_val1 ) ;
3951
        test_fail("WB Erroneous Address register didn't provide right value") ;
3952
        ok = 0 ;
3953
    end
3954
 
3955
    config_read( { 4'h1, `W_ERR_DATA_ADDR, 2'b00}, 4'hF, temp_val1 ) ;
3956
    if ( temp_val1 !== 32'hAAAA_AAAA )
3957
    begin
3958
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3959
        $display("Value in W_ERR_DATA register was wrong!") ;
3960
        $display("Expected value = %h, actual value = %h " , 32'hAAAA_AAAA, temp_val1 ) ;
3961
        test_fail("WB Erroneous Data register didn't provide right value") ;
3962
        ok = 0 ;
3963
    end
3964
 
3965
    if ( ok )
3966
        test_ok ;
3967
 
3968
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3969
    config_read( {4'h1, `ISR_ADDR, 2'b00}, 4'hF, temp_val1) ;
3970
    if ( temp_val1[1] !== 1 )
3971
    begin
3972
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3973
        $display("WISHBONE error interrupt enable is set, error was signalled, but corresponding interrupt status bit was not set in ISR!") ;
3974
        test_fail("expected interrupt status bit was not set") ;
3975
    end
3976
    else
3977
        test_ok ;
3978
 
3979
    // clear interrupts and errors
3980
    config_write( {4'h1, `ISR_ADDR, 2'b00}, temp_val1, 4'hF, ok ) ;
3981
    config_write( err_cs_offset, 32'h0000_0101, 4'b0011, ok ) ;
3982
 
3983
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER ABORTED I/O WRITE" ;
3984
    ok = 1 ;
3985
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
3986
    if ( temp_val1[29] !== 1 )
3987
    begin
3988
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3989
        $display("Received Master Abort bit was not set when IO write transaction finished with Master Abort!") ;
3990
        test_fail("Received Master Abort bit was not set when IO write transaction finished with Master Abort") ;
3991
        ok = 0 ;
3992
    end
3993
 
3994
    if ( temp_val1[28] !== 0 )
3995
    begin
3996
        $display("PCI bus error handling testing failed! Time %t ", $time) ;
3997
        $display("Received Target Abort bit was set for no reason!") ;
3998
        test_fail("Received Target Abort bit was set for no reason") ;
3999
        ok = 0 ;
4000
    end
4001
 
4002
    if ( ok )
4003
        test_ok ;
4004
 
4005
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4006
 
4007
    // disable image
4008
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4009
    if ( ok !== 1 )
4010
    begin
4011
        $display("PCI bus error handling testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4012
        test_fail("WB Image Address Mask register couldn't be written") ;
4013
        disable main ;
4014
    end
4015
    $display("************************ DONE testing handling of PCI bus errors ****************************************") ;
4016
 
4017
end
4018
endtask
4019
 
4020
task parity_checking ;
4021
    reg   [11:0] ctrl_offset ;
4022
    reg   [11:0] ba_offset ;
4023
    reg   [11:0] am_offset ;
4024
    reg   [11:0] ta_offset ;
4025
    reg `WRITE_STIM_TYPE write_data ;
4026
    reg `READ_STIM_TYPE  read_data ;
4027
    reg `READ_RETURN_TYPE read_status ;
4028
 
4029
    reg `WRITE_RETURN_TYPE write_status ;
4030
    reg `WB_TRANSFER_FLAGS write_flags ;
4031
    reg [31:0] temp_val1 ;
4032
    reg [31:0] temp_val2 ;
4033
    reg        ok   ;
4034
    reg [11:0] pci_ctrl_offset ;
4035
    reg [31:0] image_base ;
4036
    reg [31:0] target_address ;
4037
    reg [11:0] icr_offset ;
4038
    reg [11:0] isr_offset ;
4039
    reg [11:0] p_ba_offset ;
4040
    reg [11:0] p_am_offset ;
4041
    reg [11:0] p_ctrl_offset ;
4042
    integer    i ;
4043
    reg        perr_asserted ;
4044
begin:main
4045
    $display("******************************* Testing Parity Checker functions ********************************") ;
4046
    $display("Testing Parity Errors during Master Transactions!") ;
4047
    $display("Introducing Parity Erros to Master Writes!") ;
4048
    $fdisplay(pci_mon_log_file_desc,
4049
    "******************************************** Monitor will complain in following section for a few times - testbench is intentionally causing parity errors *********************************************") ;
4050
 
4051
    // image 1 is used for error testing, since it is always implemented
4052
    pci_ctrl_offset = 12'h004 ;
4053
    ctrl_offset     = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
4054
    ba_offset       = {4'h1, `W_BA1_ADDR, 2'b00} ;
4055
    am_offset       = {4'h1, `W_AM1_ADDR, 2'b00} ;
4056
    ta_offset       = {4'h1, `W_TA1_ADDR, 2'b00} ;
4057
    isr_offset      = {4'h1, `ISR_ADDR, 2'b00} ;
4058
    icr_offset      = {4'h1, `ICR_ADDR, 2'b00} ;
4059
 
4060
    // image 1 for PCI target
4061
    p_ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
4062
    p_am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
4063
    p_ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
4064
 
4065
    target_address  = `BEH_TAR1_MEM_START ;
4066
    image_base      = 0 ;
4067
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
4068
 
4069
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
4070
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
4071
    write_flags                    = 0 ;
4072
    write_flags`INIT_WAITS         = tb_init_waits ;
4073
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
4074
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
4075
 
4076
    // enable master & target operation and disable parity functions
4077
    test_name = "CONFIGURE BRIDGE FOR PARITY CHECKER FUNCTIONS TESTING" ;
4078
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h3, ok) ;
4079
    if ( ok !== 1 )
4080
    begin
4081
        $display("Parity checker testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
4082
        test_fail("PCI Device Control register could not be written to") ;
4083
        disable main ;
4084
    end
4085
 
4086
    // prepare image control register
4087
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
4088
    if ( ok !== 1 )
4089
    begin
4090
        $display("Parity checker testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
4091
        test_fail("WB Image Control register could not be written to") ;
4092
        disable main ;
4093
    end
4094
 
4095
    // prepare base address register
4096
    config_write( ba_offset, image_base, 4'hF, ok ) ;
4097
    if ( ok !== 1 )
4098
    begin
4099
        $display("Parity checker testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
4100
        test_fail("WB Image Base Address register could not be written to") ;
4101
        disable main ;
4102
    end
4103
 
4104
    // write address mask register
4105
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
4106
    if ( ok !== 1 )
4107
    begin
4108
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
4109
        test_fail("WB Image Address Mask register could not be written to") ;
4110
        disable main ;
4111
    end
4112
 
4113
    // disable parity interrupts
4114
    config_write( icr_offset, 0, 4'hF, ok ) ;
4115
    if ( ok !== 1 )
4116
    begin
4117
        $display("Parity checker testing failed! Failed to write ICR! Time %t ", $time) ;
4118
        test_fail("Interrupt Control register could not be written to") ;
4119
        disable main ;
4120
    end
4121
 
4122
    write_data`WRITE_ADDRESS = target_address ;
4123
    write_data`WRITE_DATA    = wmem_data[0] ;
4124
    write_data`WRITE_SEL     = 4'b1111 ;
4125
 
4126
    // enable target's 1 response to parity errors
4127 45 mihad
    configuration_cycle_write(0,                        // bus number
4128
                              `TAR1_IDSEL_INDEX - 11,   // device number
4129
                              0,                        // function number
4130
                              1,                        // register number
4131
                              0,                        // type of configuration cycle
4132
                              4'b0001,                  // byte enables
4133
                              32'h0000_0047             // data
4134 15 mihad
                             ) ;
4135
 
4136
    // disable target's 2 response to parity errors
4137 45 mihad
    configuration_cycle_write(0,                        // bus number
4138
                              `TAR2_IDSEL_INDEX - 11,   // device number
4139
                              0,                        // function number
4140
                              1,                        // register number
4141
                              0,                        // type of configuration cycle
4142
                              4'b0001,                  // byte enables
4143
                              32'h0000_0007             // data
4144 15 mihad
                             ) ;
4145
 
4146
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4147
 
4148
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE" ;
4149
    fork
4150
    begin
4151
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4152
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4153
        begin
4154
            $display("Parity checker testing failed! Time %t ", $time) ;
4155
            $display("Bridge failed to process single memory write!") ;
4156
            test_fail("bridge failed to post single WB memory write") ;
4157
            disable main ;
4158
        end
4159
    end
4160
    begin:wait_perr1
4161
        perr_asserted = 0 ;
4162
        @(posedge pci_clock) ;
4163
 
4164 35 mihad
        while ( PERR !== 0 )
4165 15 mihad
            @(posedge pci_clock) ;
4166
 
4167 35 mihad
        perr_asserted = 1 ;
4168 15 mihad
 
4169
    end
4170
    begin
4171
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4172
 
4173
        if ( ok !== 1 )
4174
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4175
 
4176 35 mihad
        repeat(2)
4177 15 mihad
            @(posedge pci_clock) ;
4178
 
4179 35 mihad
        #1 ;
4180
        if ( !perr_asserted )
4181
            disable wait_perr1 ;
4182 15 mihad
    end
4183
    join
4184
 
4185
    if ( perr_asserted && ok )
4186
    begin
4187
        test_ok ;
4188
    end
4189
    else
4190
    if ( ~perr_asserted )
4191
    begin
4192
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4193
        disable main ;
4194
    end
4195
 
4196
    // check all the statuses - if HOST is defined, wait for them to be synced
4197
    `ifdef HOST
4198
    repeat(4)
4199
        @(posedge wb_clock) ;
4200
    `endif
4201
 
4202
    test_name = "CHECK PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE" ;
4203
    ok = 1 ;
4204
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4205 45 mihad
    if ( temp_val1[31] !== 0 )
4206 15 mihad
    begin
4207
        $display("Parity checker testing failed! Time %t ", $time) ;
4208 45 mihad
        $display("Detected Parity Error bit was set when the PCI Bridge was the Master of PCI Write!") ;
4209
        test_fail("Detected Parity Error bit was set when Data Parity Error was signaled during Master Write") ;
4210 15 mihad
        ok = 0 ;
4211
    end
4212
 
4213
    if ( temp_val1[30] !== 0 )
4214
    begin
4215
        $display("Parity checker testing failed! Time %t ", $time) ;
4216
        $display("Signalled System Error bit was set for no reason!") ;
4217
        test_fail("Signalled System Error bit was set for no reason") ;
4218
        ok = 0 ;
4219
    end
4220
 
4221
    if ( temp_val1[24] !== 0 )
4222
    begin
4223
        $display("Parity checker testing failed! Time %t ", $time) ;
4224
        $display("Master Data Parity Error bit set even though Parity Error Response bit was not set!") ;
4225
        test_fail("Master Data Parity Error bit was set even though Parity Error Response was not enabled") ;
4226
        ok = 0 ;
4227
    end
4228
 
4229
    if ( ok )
4230
        test_ok ;
4231
 
4232
    test_name = "CLEARING PARITY ERROR STATUSES" ;
4233
    // clear parity bits and enable parity response
4234
    config_write( pci_ctrl_offset, temp_val1 | CONFIG_CMD_PAR_ERR_EN, 4'hF, ok ) ;
4235
    if ( ok !== 1 )
4236
    begin
4237
        $display("Parity checker testing failed! Failed to write PCI control and status reg! Time %t ", $time) ;
4238
        test_fail("write to PCI Status Register failed") ;
4239
        disable main ;
4240
    end
4241
 
4242
    test_name = "RESPONSE TO TARGET ASSERTING PERR DURING MASTER WRITE WITH PARITY ERROR RESPONSE ENABLED" ;
4243
    fork
4244
    begin
4245
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4246
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4247
        begin
4248
            $display("Parity checker testing failed! Time %t ", $time) ;
4249
            $display("Bridge failed to process single memory write!") ;
4250
            test_fail("bridge failed to post single memory write") ;
4251
            disable main ;
4252
        end
4253
    end
4254
    begin:wait_perr2
4255
        perr_asserted = 0 ;
4256
        @(posedge pci_clock) ;
4257
 
4258 35 mihad
        while ( PERR !== 0 )
4259 15 mihad
            @(posedge pci_clock) ;
4260
 
4261 35 mihad
        perr_asserted = 1 ;
4262 15 mihad
 
4263
    end
4264
    begin
4265
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4266
 
4267
        if ( ok !== 1 )
4268
            test_fail("bridge failed to process single memory write correctly, or target didn't respond to it") ;
4269
 
4270 35 mihad
        repeat(2)
4271 15 mihad
            @(posedge pci_clock) ;
4272
 
4273 35 mihad
        #1 ;
4274
        if (!perr_asserted)
4275
            disable wait_perr2 ;
4276 15 mihad
    end
4277
    join
4278
 
4279
    if ( perr_asserted && ok )
4280
    begin
4281
        test_ok ;
4282
    end
4283
    else
4284
    if ( ~perr_asserted )
4285
    begin
4286
        test_fail("PCI behavioral target failed to assert invalid PERR for testing") ;
4287
        disable main ;
4288
    end
4289
 
4290
    // check all the statuses - if HOST is defined, wait for them to be synced
4291
    `ifdef HOST
4292
    repeat(4)
4293
        @(posedge wb_clock) ;
4294
    `endif
4295
 
4296
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR DURING MASTER WRITE - PAR. ERR. RESPONSE ENABLED" ;
4297
    ok = 1 ;
4298
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4299 45 mihad
    if ( temp_val1[31] !== 0 )
4300 15 mihad
    begin
4301
        $display("Parity checker testing failed! Time %t ", $time) ;
4302 45 mihad
        $display("Detected Parity Error bit was set after data parity error on PCI bus during Master Write!") ;
4303
        test_fail("Detected Parity Error bit was set after data parity error on PCI bus during Master Write") ;
4304 15 mihad
        ok = 0 ;
4305
    end
4306
 
4307
    if ( temp_val1[30] !== 0 )
4308
    begin
4309
        $display("Parity checker testing failed! Time %t ", $time) ;
4310
        $display("Signalled System Error bit was set for no reason!") ;
4311
        test_fail("Signalled System Error bit was set for no reason") ;
4312
        ok = 0 ;
4313
    end
4314
 
4315
    if ( temp_val1[24] !== 1 )
4316
    begin
4317
        $display("Parity checker testing failed! Time %t ", $time) ;
4318 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!") ;
4319
        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") ;
4320 15 mihad
        ok = 0 ;
4321
    end
4322
 
4323
    if ( ok )
4324
        test_ok ;
4325
 
4326
    // clear status bits and disable parity error response
4327
    config_write( pci_ctrl_offset, temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4328
 
4329
    test_name = "MASTER WRITE WITH NO PARITY ERRORS" ;
4330
 
4331
    // disable perr generation and perform a write - no bits should be set
4332
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4333
    fork
4334
    begin
4335
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
4336
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
4337
        begin
4338
            $display("Parity checker testing failed! Time %t ", $time) ;
4339
            $display("Bridge failed to process single memory write!") ;
4340
            test_fail("bridge failed to post single memory write") ;
4341
            disable main ;
4342
        end
4343
    end
4344
    begin
4345
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4346
 
4347
        if ( ok !== 1 )
4348
            test_fail("bridge failed to start posted memory write transaction on PCI bus correctly") ;
4349
        else
4350
            test_ok ;
4351
 
4352
        repeat(3)
4353
            @(posedge pci_clock) ;
4354
    end
4355
    join
4356
 
4357
    `ifdef HOST
4358
    repeat(4)
4359
        @(posedge wb_clock) ;
4360
    `endif
4361
 
4362
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL MEMORY WRITE" ;
4363
    ok = 1 ;
4364
 
4365
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4366
    if ( temp_val1[31] !== 0 )
4367
    begin
4368
        $display("Parity checker testing failed! Time %t ", $time) ;
4369
        $display("Detected Parity Error bit was set for no reason!") ;
4370
        test_fail("Detected Parity Error bit was set even though no parity errors happened on PCI") ;
4371
        ok = 0 ;
4372
    end
4373
 
4374
    if ( temp_val1[30] !== 0 )
4375
    begin
4376
        $display("Parity checker testing failed! Time %t ", $time) ;
4377
        $display("Signalled System Error bit was set for no reason!") ;
4378
        test_fail("Signalled System Error bit was set even though no parity errors happened on PCI") ;
4379
        ok = 0 ;
4380
    end
4381
 
4382
    if ( temp_val1[24] !== 0 )
4383
    begin
4384
        $display("Parity checker testing failed! Time %t ", $time) ;
4385
        $display("Master Data Parity Error bit was set for no reason!") ;
4386
        test_fail("Master Data Parity Error bit was set even though no parity errors happened on PCI") ;
4387
        ok = 0 ;
4388
    end
4389
 
4390
    if ( ok )
4391
        test_ok ;
4392
 
4393
    $display(" Introducing Parity Errors to Master reads ! " ) ;
4394
 
4395
    read_data = 0 ;
4396
    read_data`READ_ADDRESS  = target_address ;
4397
    read_data`READ_SEL      = 4'hF ;
4398
    read_data`READ_TAG_STIM = 0 ;
4399
 
4400
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
4401
 
4402
    // enable parity and system error interrupts
4403
    config_write ( icr_offset, 32'h0000_0018, 4'h1, ok ) ;
4404
 
4405
    // enable parity error response
4406
    config_write ( pci_ctrl_offset, (temp_val1 | CONFIG_CMD_PAR_ERR_EN), 4'hF, ok ) ;
4407
 
4408
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 1 ;
4409
 
4410
    test_name = "BRIDGE'S RESPONSE TO PARITY ERRORS DURING MASTER READS" ;
4411
    fork
4412
    begin
4413
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4414
    end
4415
    begin:wait_perr4
4416
        perr_asserted = 0 ;
4417
        @(posedge pci_clock) ;
4418 35 mihad
        while ( PERR !== 0 )
4419 15 mihad
            @(posedge pci_clock) ;
4420
 
4421 35 mihad
        perr_asserted = 1 ;
4422 15 mihad
 
4423
    end
4424
    begin
4425
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
4426
 
4427
        if ( ok !== 1 )
4428
            test_fail("bridge failed to process single memory read correctly, or target didn't respond to it") ;
4429
 
4430
        repeat(2)
4431
            @(posedge pci_clock) ;
4432
 
4433 35 mihad
        #1 ;
4434
        if ( !perr_asserted )
4435
            disable wait_perr4 ;
4436 15 mihad
    end
4437
    join
4438
 
4439
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4440
    begin
4441
        $display("Parity checker testing failed! Time %t ", $time) ;
4442
        $display("Bridge failed to process single memory read!") ;
4443
        test_fail("bridge didn't process single memory read correctly") ;
4444
        ok = 0 ;
4445
    end
4446
 
4447
    if ( perr_asserted && ok )
4448
    begin
4449
        test_ok ;
4450
    end
4451
    else
4452
    if ( ~perr_asserted )
4453
    begin
4454
        test_fail("PCI bridge failed to assert invalid PERR on Master Read reference") ;
4455
        disable main ;
4456
    end
4457
 
4458
    test_name = "INTERRUPT REQUEST ASSERTION AFTER PARITY ERROR" ;
4459
    // interrupt should also be present
4460
    `ifdef HOST
4461
        repeat(4)
4462 26 mihad
            @(posedge pci_clock) ;
4463
        repeat(4)
4464 15 mihad
            @(posedge wb_clock) ;
4465
 
4466
        if ( INT_O !== 1 )
4467
        begin
4468
            $display("Parity checker testing failed! Time %t ", $time) ;
4469
            $display("Parity Error was presented on Master reference, parity error int. en. was set, but INT REQ was not signalled on WB bus!") ;
4470
            test_fail("HOST bridge didn't assert INT_O line, after Parity Error was presented during read reference and Par. Err. interrupts were enabled") ;
4471
        end
4472
        else
4473
            test_ok ;
4474
    `else
4475
    `ifdef GUEST
4476 26 mihad
        repeat(4)
4477
            @(posedge wb_clock) ;
4478
        repeat(4)
4479 15 mihad
            @(posedge pci_clock) ;
4480
 
4481
        if ( INTA !== 1 )
4482
        begin
4483
            $display("Parity checker testing failed! Time %t ", $time) ;
4484
            $display("Parity Error caused interrupt request on PCI bus! PCI bus has other means for signaling parity errors!") ;
4485
            test_fail("GUEST bridge shouldn't assert interrupt requests on Parity Errors. Other means are provided for signaling Parity errors") ;
4486
        end
4487
        else
4488
            test_ok ;
4489
    `endif
4490
    `endif
4491
 
4492
    // check statuses!
4493
 
4494
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4495
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4496
    ok = 1 ;
4497
 
4498
    if ( temp_val1[31] !== 1 )
4499
    begin
4500
        $display("Parity checker testing failed! Time %t ", $time) ;
4501 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4502
        test_fail("Detected Parity Error bit was not set when parity error was presented on Master Read transaction") ;
4503 15 mihad
        ok = 0 ;
4504
    end
4505
 
4506
    if ( temp_val1[30] !== 0 )
4507
    begin
4508
        $display("Parity checker testing failed! Time %t ", $time) ;
4509
        $display("Signalled System Error bit was set for no reason!") ;
4510
        test_fail("Signalled System Error bit was set for no reason") ;
4511
        ok = 0 ;
4512
    end
4513
 
4514
    if ( temp_val1[24] !== 1 )
4515
    begin
4516
        $display("Parity checker testing failed! Time %t ", $time) ;
4517 45 mihad
        $display("Master Data Parity Error bit was not set when parity error was presented during Master Read transaction!") ;
4518
        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") ;
4519 15 mihad
        ok = 0 ;
4520
    end
4521
 
4522
    if ( ok )
4523
        test_ok ;
4524
 
4525
    // clear statuses and disable parity error response
4526
    config_write( pci_ctrl_offset, (temp_val1 & ~(CONFIG_CMD_PAR_ERR_EN)), 4'b1111, ok ) ;
4527
 
4528
    test_name = "INTERRUPT STATUS REGISTER AFTER MASTER READ PARITY ERROR" ;
4529
    ok = 1 ;
4530
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4531
 
4532
    if ( temp_val1[4] !== 0 )
4533
    begin
4534
        $display("Parity checker testing failed! Time %t ", $time) ;
4535
        $display("System error interrupt status bit set for no reason!") ;
4536
        test_fail("System error interrupt status bit set for no reason") ;
4537
        ok = 0 ;
4538
    end
4539
 
4540
    `ifdef HOST
4541
    if ( temp_val1[3] !== 1 )
4542
    begin
4543
        $display("Parity checker testing failed! Time %t ", $time) ;
4544
        $display("Parity Error interrupt status bit was not set when Parity Error occured and PERR INT was enabled!") ;
4545
        test_fail("Parity Error interrupt status bit in HOST bridge was not set when Parity Error occured and PERR INT was enabled") ;
4546
        ok = 0 ;
4547
    end
4548
    `else
4549
    if ( temp_val1[3] !== 0 )
4550
    begin
4551
        $display("Parity checker testing failed! Time %t ", $time) ;
4552
        $display("Parity Error interrupt status bit was set in guest implementation of the bridge!") ;
4553
        test_fail("Parity Error interrupt status bit was set in GUEST implementation of the bridge") ;
4554
        ok = 0 ;
4555
    end
4556
    `endif
4557
 
4558
    if ( ok )
4559
        test_ok ;
4560
 
4561
    // clear int statuses
4562
    test_name = "CLEARANCE OF PARITY INTERRUPT STATUSES" ;
4563
 
4564
    config_write( isr_offset, temp_val1, 4'hF, ok ) ;
4565
 
4566
    `ifdef HOST
4567
        repeat(4)
4568 26 mihad
            @(posedge pci_clock) ;
4569
        repeat(4)
4570 15 mihad
            @(posedge wb_clock) ;
4571
 
4572
        if ( INT_O !== 0 )
4573
        begin
4574
            $display("Parity checker testing failed! Time %t ", $time) ;
4575
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4576
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4577
        end
4578
        else
4579
            test_ok ;
4580
    `else
4581
    `ifdef GUEST
4582 26 mihad
        repeat(4)
4583
            @(posedge wb_clock) ;
4584
        repeat(4)
4585 15 mihad
            @(posedge pci_clock) ;
4586
 
4587
        if ( INTA !== 1 )
4588
        begin
4589
            $display("Parity checker testing failed! Time %t ", $time) ;
4590
            $display("Interrupt request was not cleared when status bits were cleared!") ;
4591
            test_fail("Interrupt request was not cleared when interrupt status bits were cleared") ;
4592
        end
4593
        else
4594
            test_ok ;
4595
    `endif
4596
    `endif
4597
 
4598
    test_name = "NO PERR ASSERTION ON MASTER READ WITH PAR. ERR. RESPONSE DISABLED" ;
4599
 
4600
    // repeat the read - because Parity error response is not enabled, PERR should not be asserted
4601
    fork
4602
    begin
4603
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4604
    end
4605
    begin:wait_perr5
4606
        perr_asserted = 0 ;
4607
        @(posedge pci_clock) ;
4608
        while ( PERR === 1 )
4609
            @(posedge pci_clock) ;
4610
 
4611
        perr_asserted = 1 ;
4612
        $display("Parity checker testing failed! Time %t ", $time) ;
4613 45 mihad
        $display("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled!") ;
4614
        test_fail("Bridge asserted PERR during Master Read transaction when Parity Error response was disabled") ;
4615 15 mihad
    end
4616
    begin
4617
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4618
        if ( ok !== 1 )
4619
            test_fail("bridge failed to engage expected read transaction on PCI bus") ;
4620
 
4621
        // perr can be asserted on idle or next PCI address phase
4622
        repeat(2)
4623
            @(posedge pci_clock) ;
4624
 
4625 35 mihad
        #1 ;
4626
        if ( !perr_asserted )
4627
            disable wait_perr5 ;
4628 15 mihad
    end
4629
    join
4630
 
4631
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4632
    begin
4633
        $display("Parity checker testing failed! Time %t ", $time) ;
4634
        $display("Bridge failed to process single memory read!") ;
4635
        test_fail("bridge failed to process single memory read correctly") ;
4636
        ok = 0 ;
4637
    end
4638
 
4639
    if ( ok && !perr_asserted)
4640
        test_ok ;
4641
 
4642
    test_name = "INTERRUPT REQUEST CHECK AFTER READ PARITY ERROR WITH PARITY ERROR RESPONSE DISABLED" ;
4643
 
4644
    // interrupts should not be present
4645
    `ifdef HOST
4646
        repeat( 4 )
4647 26 mihad
            @(posedge pci_clock) ;
4648
        repeat( 4 )
4649 15 mihad
            @(posedge wb_clock) ;
4650
        if ( INT_O !== 0 )
4651
        begin
4652
            $display("Parity checker testing failed! Time %t ", $time) ;
4653
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4654
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4655
        end
4656
        else
4657
            test_ok ;
4658
    `else
4659
    `ifdef GUEST
4660
        repeat( 4 )
4661 26 mihad
            @(posedge wb_clock) ;
4662
        repeat( 4 )
4663 15 mihad
            @(posedge pci_clock) ;
4664
        if ( INTA !== 1 )
4665
        begin
4666
            $display("Parity checker testing failed! Time %t ", $time) ;
4667
            $display("Parity Error response was disabled, but bridge asserted interrupt because of parity error!") ;
4668
            test_fail("Parity Error response was disabled, but bridge asserted interrupt") ;
4669
        end
4670
        else
4671
            test_ok ;
4672
    `endif
4673
    `endif
4674
 
4675
    // check statuses!
4676
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR" ;
4677
    ok = 1 ;
4678
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4679
    if ( temp_val1[31] !== 1 )
4680
    begin
4681
        $display("Parity checker testing failed! Time %t ", $time) ;
4682 45 mihad
        $display("Detected Parity Error bit was not set when parity error was presented on Master Read transaction!") ;
4683 15 mihad
        test_fail("Detected Parity Error bit was not set when parity error was presented on PCI Master Read transaction") ;
4684
        ok = 0 ;
4685
    end
4686
 
4687
    if ( temp_val1[30] !== 0 )
4688
    begin
4689
        $display("Parity checker testing failed! Time %t ", $time) ;
4690
        $display("Signalled System Error bit was set for no reason!") ;
4691
        test_fail("Signalled System Error bit was set for no reason") ;
4692
        ok = 0 ;
4693
    end
4694
 
4695
    if ( temp_val1[24] !== 0 )
4696
    begin
4697
        $display("Parity checker testing failed! Time %t ", $time) ;
4698 45 mihad
        $display("Master Data Parity Error bit was set when parity error was presented during Master Read transaction, but Parity Response was disabled!") ;
4699 15 mihad
        test_fail("Master Data Parity Error bit was set, but Parity Response was disabled");
4700
        ok = 0 ;
4701
    end
4702
 
4703
    if ( ok )
4704
        test_ok ;
4705
 
4706
    // clear statuses
4707
    config_write( pci_ctrl_offset, temp_val1, 4'b1100, ok ) ;
4708
 
4709
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER MASTER READ PARITY ERROR WITH PAR. ERR. RESPONSE DISABLED" ;
4710
    ok = 1 ;
4711
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4712
 
4713
    if ( temp_val1[4] !== 0 )
4714
    begin
4715
        $display("Parity checker testing failed! Time %t ", $time) ;
4716
        $display("System error interrupt status bit set for no reason!") ;
4717
        test_fail("System error interrupt status bit set for no reason") ;
4718
        ok = 0 ;
4719
    end
4720
 
4721
    if ( temp_val1[3] !== 0 )
4722
    begin
4723
        $display("Parity checker testing failed! Time %t ", $time) ;
4724
        $display("Parity Error interrupt status bit was set when Parity Error occured and Parity Error response was disabled!") ;
4725
        test_fail("Parity Error interrupt status bit was set when Parity Error response was disabled!") ;
4726
        ok = 0 ;
4727
    end
4728
 
4729
    if ( ok )
4730
        test_ok ;
4731
 
4732
    // enable all responses to parity errors!
4733
    test_name = "MASTER READ TRANSACTION WITH NO PARITY ERRORS" ;
4734
 
4735
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
4736
    config_write ( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
4737
 
4738
    test_target_response[`TARGET_ENCODED_DATA_PAR_ERR] = 0 ;
4739
 
4740
    // repeat a read
4741
    fork
4742
    begin
4743
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
4744
    end
4745
    begin:wait_perr6
4746
        perr_asserted = 0 ;
4747
        @(posedge pci_clock) ;
4748
        while ( PERR === 1 )
4749
            @(posedge pci_clock) ;
4750
 
4751
        perr_asserted = 1 ;
4752
        $display("Parity checker testing failed! Time %t ", $time) ;
4753
        $display("Bridge asserted PERR during read transaction when Parity Error response was disabled!") ;
4754
        test_fail("Bridge asserted PERR during read transaction when no parity error occurred") ;
4755
    end
4756
    begin
4757
        pci_transaction_progress_monitor(target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok) ;
4758
        if ( ok !== 1 )
4759
            test_fail("bridge failed to start expected read transaction on PCI bus") ;
4760
 
4761
        repeat(2)
4762
            @(posedge pci_clock) ;
4763
 
4764 35 mihad
        #1 ;
4765
        if ( !perr_asserted )
4766
            disable wait_perr6 ;
4767 15 mihad
    end
4768
    join
4769
 
4770
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
4771
    begin
4772
        $display("Parity checker testing failed! Time %t ", $time) ;
4773
        $display("Bridge failed to process single memory read!") ;
4774
        test_fail("bridge didn't process single memory read as expected") ;
4775
        ok = 0 ;
4776
    end
4777
 
4778
    if ( ok && !perr_asserted)
4779
        test_ok ;
4780
 
4781
    // check statuses!
4782
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL READ" ;
4783
    ok = 1 ;
4784
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4785
    if ( temp_val1[31] !== 0 )
4786
    begin
4787
        $display("Parity checker testing failed! Time %t ", $time) ;
4788
        $display("Detected Parity Error bit was set for no reason!") ;
4789
        test_fail("Detected Parity Error bit was set for no reason") ;
4790
        ok = 0 ;
4791
    end
4792
 
4793
    if ( temp_val1[30] !== 0 )
4794
    begin
4795
        $display("Parity checker testing failed! Time %t ", $time) ;
4796
        $display("Signalled System Error bit was set for no reason!") ;
4797
        test_fail("Signalled System Error bit was set for no reason") ;
4798
        ok = 0 ;
4799
    end
4800
 
4801
    if ( temp_val1[24] !== 0 )
4802
    begin
4803
        $display("Parity checker testing failed! Time %t ", $time) ;
4804
        $display("Master Data Parity Error bit was set for no reason!") ;
4805
        test_fail("Master Data Parity Error bit was set for no reason") ;
4806
        ok = 0 ;
4807
    end
4808
 
4809
    if ( ok )
4810
        test_ok ;
4811
 
4812
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL READ" ;
4813
    ok = 1 ;
4814
    config_read( isr_offset, 4'hF, temp_val1 ) ;
4815
 
4816
    if ( temp_val1[4] !== 0 )
4817
    begin
4818
        $display("Parity checker testing failed! Time %t ", $time) ;
4819
        $display("System error interrupt status bit set for no reason!") ;
4820
        test_fail("System error interrupt status bit set for no reason") ;
4821
        ok = 0 ;
4822
    end
4823
 
4824
    if ( temp_val1[3] !== 0 )
4825
    begin
4826
        $display("Parity checker testing failed! Time %t ", $time) ;
4827
        $display("Parity error interrupt status bit set for no reason!") ;
4828
        test_fail("Parity error interrupt status bit set for no reason") ;
4829
        ok = 0 ;
4830
    end
4831
 
4832
    if ( ok )
4833
        test_ok ;
4834
 
4835
    $display("Presenting address parity error on PCI bus!") ;
4836
    // enable parity errors - this should not affect system errors
4837
    config_write( pci_ctrl_offset, 32'h0000_0047, 4'hF, ok ) ;
4838
    config_write ( icr_offset, 32'h0000_0018, 4'hF, ok ) ;
4839
 
4840
    // perform PCI write
4841
    // check transaction progress
4842
    test_name = "NO SERR ASSERTION AFTER ADDRESS PARITY ERROR, SERR DISABLED AND PAR. ERR. RESPONSE ENABLED" ;
4843
    fork
4844
    begin
4845
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
4846
               target_address, 32'h1234_5678,
4847
               1, 8'h0_0, `Test_One_Zero_Target_WS,
4848
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
4849
        do_pause( 1 ) ;
4850
    end
4851
    begin:wait_serr7
4852
        perr_asserted = 0 ;
4853
        @(posedge pci_clock) ;
4854
        while( SERR === 1 )
4855
            @(posedge pci_clock) ;
4856
 
4857
        perr_asserted = 1 ;
4858
        $display("Parity checker testing failed! Time %t ", $time) ;
4859
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4860
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4861
    end
4862
    begin
4863
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
4864
        if ( ok !== 1 )
4865
            test_fail("behavioral master failed to start expected transaction or behavioral target didn't respond") ;
4866
 
4867 35 mihad
        if ( !perr_asserted )
4868
            disable wait_serr7 ;
4869 15 mihad
    end
4870
    join
4871
 
4872
    if ( ok && !perr_asserted)
4873
        test_ok ;
4874
 
4875
    // check statuses!
4876
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4877
    ok = 1 ;
4878
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4879
    if ( temp_val1[31] !== 1 )
4880
    begin
4881
        $display("Parity checker testing failed! Time %t ", $time) ;
4882
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4883
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4884
        ok = 0 ;
4885
    end
4886
 
4887
    if ( temp_val1[30] !== 0 )
4888
    begin
4889
        $display("Parity checker testing failed! Time %t ", $time) ;
4890
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4891
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4892
        ok = 0 ;
4893
    end
4894
 
4895
    if ( temp_val1[24] !== 0 )
4896
    begin
4897
        $display("Parity checker testing failed! Time %t ", $time) ;
4898
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
4899
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
4900
        ok = 0 ;
4901
    end
4902
 
4903
    if ( ok )
4904
        test_ok ;
4905
 
4906
    // clear statuses
4907
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
4908
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4909
    fork
4910
    begin
4911
        ipci_unsupported_commands_master.master_reference
4912
        (
4913
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4914
            32'h5555_5555,      // second part of address in dual address cycle
4915
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4916
            `BC_MEM_WRITE,      // normal command
4917
            4'h0,               // byte enables
4918
            32'h1234_5678,      // data
4919
            1'b1,               // make address parity error on first phase of dual address
4920
            1'b0,               // make address parity error on second phase of dual address
4921
            ok                  // result of operation
4922
        ) ;
4923 35 mihad
        if ( !perr_asserted )
4924
            disable wait_serr8 ;
4925 15 mihad
    end
4926
    begin:wait_serr8
4927
        perr_asserted = 0 ;
4928
        @(posedge pci_clock) ;
4929
        while( SERR === 1 )
4930
            @(posedge pci_clock) ;
4931
 
4932
        perr_asserted = 1 ;
4933
        $display("Parity checker testing failed! Time %t ", $time) ;
4934
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4935
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4936
    end
4937
    join
4938
 
4939
    if ( ok && !perr_asserted)
4940
        test_ok ;
4941
 
4942
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
4943
    fork
4944
    begin
4945
        ipci_unsupported_commands_master.master_reference
4946
        (
4947
            32'hAAAA_AAAA,      // first part of address in dual address cycle
4948
            32'h5555_5555,      // second part of address in dual address cycle
4949
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
4950
            `BC_MEM_WRITE,      // normal command
4951
            4'h0,               // byte enables
4952
            32'h1234_5678,      // data
4953
            1'b0,               // make address parity error on first phase of dual address
4954
            1'b1,               // make address parity error on second phase of dual address
4955
            ok                  // result of operation
4956
        ) ;
4957 35 mihad
        if ( !perr_asserted )
4958
            disable wait_serr9 ;
4959 15 mihad
    end
4960
    begin:wait_serr9
4961
        perr_asserted = 0 ;
4962
        @(posedge pci_clock) ;
4963
        while( SERR === 1 )
4964
            @(posedge pci_clock) ;
4965
 
4966
        perr_asserted = 1 ;
4967
        $display("Parity checker testing failed! Time %t ", $time) ;
4968
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
4969
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
4970
    end
4971
    join
4972
 
4973
    if ( ok && !perr_asserted)
4974
        test_ok ;
4975
 
4976
    // check statuses!
4977
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
4978
    ok = 1 ;
4979
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
4980
    if ( temp_val1[31] !== 1 )
4981
    begin
4982
        $display("Parity checker testing failed! Time %t ", $time) ;
4983
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
4984
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
4985
        ok = 0 ;
4986
    end
4987
 
4988
    if ( temp_val1[30] !== 0 )
4989
    begin
4990
        $display("Parity checker testing failed! Time %t ", $time) ;
4991
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
4992
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
4993
        ok = 0 ;
4994
    end
4995
 
4996
    if ( temp_val1[24] !== 0 )
4997
    begin
4998
        $display("Parity checker testing failed! Time %t ", $time) ;
4999
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5000
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5001
        ok = 0 ;
5002
    end
5003
 
5004
    if ( ok )
5005
        test_ok ;
5006
 
5007
    // clear statuses
5008
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5009
 
5010
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR DISABLED, PAR. RESP. ENABLED" ;
5011
    fork
5012
    begin
5013
        ipci_unsupported_commands_master.master_reference
5014
        (
5015
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5016
            32'h5555_5555,      // second part of address in dual address cycle
5017
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5018
            `BC_MEM_WRITE,      // normal command
5019
            4'h0,               // byte enables
5020
            32'h1234_5678,      // data
5021
            1'b1,               // make address parity error on first phase of dual address
5022
            1'b1,               // make address parity error on second phase of dual address
5023
            ok                  // result of operation
5024
        ) ;
5025 35 mihad
        if ( !perr_asserted )
5026
            disable wait_serr10 ;
5027 15 mihad
    end
5028
    begin:wait_serr10
5029
        perr_asserted = 0 ;
5030
        @(posedge pci_clock) ;
5031
        while( SERR === 1 )
5032
            @(posedge pci_clock) ;
5033
 
5034
        perr_asserted = 1 ;
5035
        $display("Parity checker testing failed! Time %t ", $time) ;
5036
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5037
        test_fail("bridge shouldn't assert SERR when SERR is disabled") ;
5038
    end
5039
    join
5040
 
5041
    if ( ok && !perr_asserted)
5042
        test_ok ;
5043
 
5044
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5045
 
5046
    `ifdef HOST
5047
        repeat(4)
5048 26 mihad
            @(posedge pci_clock) ;
5049
        repeat(4)
5050 15 mihad
            @(posedge wb_clock) ;
5051
        if ( INT_O !== 0 )
5052
        begin
5053
            $display("Parity checker testing failed! Time %t ", $time) ;
5054
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5055
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5056
        end
5057
        else
5058
            test_ok ;
5059
    `else
5060
    `ifdef GUEST
5061 26 mihad
        repeat(4)
5062
            @(posedge wb_clock) ;
5063
        repeat(4)
5064 15 mihad
            @(posedge pci_clock) ;
5065
 
5066
        if ( INTA !== 1 )
5067
        begin
5068
            $display("Parity checker testing failed! Time %t ", $time) ;
5069
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5070
            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") ;
5071
        end
5072
        else
5073
            test_ok ;
5074
    `endif
5075
    `endif
5076
 
5077
    // check statuses!
5078
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5079
    ok = 1 ;
5080
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5081
    if ( temp_val1[31] !== 1 )
5082
    begin
5083
        $display("Parity checker testing failed! Time %t ", $time) ;
5084
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5085
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5086
        ok = 0 ;
5087
    end
5088
 
5089
    if ( temp_val1[30] !== 0 )
5090
    begin
5091
        $display("Parity checker testing failed! Time %t ", $time) ;
5092
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5093
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5094
        ok = 0 ;
5095
    end
5096
 
5097
    if ( temp_val1[24] !== 0 )
5098
    begin
5099
        $display("Parity checker testing failed! Time %t ", $time) ;
5100
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5101
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5102
        ok = 0 ;
5103
    end
5104
 
5105
    if ( ok )
5106
        test_ok ;
5107
 
5108
    // clear statuses
5109
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5110
 
5111
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND SERR DISABLED" ;
5112
    ok = 1 ;
5113
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5114
 
5115
    if ( temp_val1[4] !== 0 )
5116
    begin
5117
        $display("Parity checker testing failed! Time %t ", $time) ;
5118
        $display("System error interrupt status bit set when SERR signaling was disabled!") ;
5119
        test_fail("System error interrupt status bit set when SERR signaling was disabled") ;
5120
        ok = 0 ;
5121
    end
5122
 
5123
    if ( temp_val1[3] !== 0 )
5124
    begin
5125
        $display("Parity checker testing failed! Time %t ", $time) ;
5126
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5127
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform reference") ;
5128
        ok = 0 ;
5129
    end
5130
 
5131
    if ( ok )
5132
        test_ok ;
5133
 
5134
    // now enable system error signaling and test response
5135
    test_name = "ADDRESS PARITY ERROR RESPONSE WITH SERR AND PARITY ERROR RESPONSE ENABLED" ;
5136
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'hF, ok ) ;
5137
 
5138
    fork
5139
    begin
5140
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5141
               target_address, 32'h1234_5678,
5142
               1, 8'h7_0, `Test_One_Zero_Target_WS,
5143
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5144
        do_pause( 1 ) ;
5145
    end
5146
    begin:wait_serr11
5147
        perr_asserted = 0 ;
5148
        @(posedge pci_clock) ;
5149 35 mihad
        while( SERR !== 0 )
5150 15 mihad
            @(posedge pci_clock) ;
5151
 
5152 35 mihad
        perr_asserted = 1 ;
5153 15 mihad
    end
5154
    begin
5155
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5156
        if ( ok !== 1 )
5157
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5158
 
5159
        @(posedge pci_clock) ;
5160 35 mihad
        #1 ;
5161
        if ( !perr_asserted )
5162
            disable wait_serr11 ;
5163 15 mihad
    end
5164
    join
5165
 
5166
    if ( ok && perr_asserted)
5167
        test_ok ;
5168
    else
5169
    if ( !perr_asserted )
5170
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5171
 
5172
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5173
 
5174
    `ifdef HOST
5175
        repeat(4)
5176 26 mihad
            @(posedge pci_clock) ;
5177
        repeat(4)
5178 15 mihad
            @(posedge wb_clock) ;
5179
        if ( INT_O !== 1 )
5180
        begin
5181
            $display("Parity checker testing failed! Time %t ", $time) ;
5182
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5183
            test_fail("Interrupt Request was not triggered as expected") ;
5184
        end
5185
        else
5186
            test_ok ;
5187
    `else
5188
    `ifdef GUEST
5189 26 mihad
        repeat(4)
5190
            @(posedge wb_clock) ;
5191
        repeat(4)
5192 15 mihad
            @(posedge pci_clock) ;
5193
 
5194
        if ( INTA !== 1 )
5195
        begin
5196
            $display("Parity checker testing failed! Time %t ", $time) ;
5197
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5198
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5199
        end
5200
        else
5201
            test_ok ;
5202
    `endif
5203
    `endif
5204
 
5205
    // check statuses!
5206
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5207
    ok = 1 ;
5208
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5209
    if ( temp_val1[31] !== 1 )
5210
    begin
5211
        $display("Parity checker testing failed! Time %t ", $time) ;
5212
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5213
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5214
        ok = 0 ;
5215
    end
5216
 
5217
    if ( temp_val1[30] !== 1 )
5218
    begin
5219
        $display("Parity checker testing failed! Time %t ", $time) ;
5220
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5221
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5222
        ok = 0 ;
5223
    end
5224
 
5225
    if ( temp_val1[24] !== 0 )
5226
    begin
5227
        $display("Parity checker testing failed! Time %t ", $time) ;
5228
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5229
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5230
        ok = 0 ;
5231
    end
5232
 
5233
    if ( ok )
5234
        test_ok ;
5235
 
5236
    // clear statuses
5237
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5238
 
5239
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5240
 
5241
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5242
    ok = 1 ;
5243
 
5244
    `ifdef HOST
5245
    if ( temp_val1[4] !== 1 )
5246
    begin
5247
        $display("Parity checker testing failed! Time %t ", $time) ;
5248
        $display("System error interrupt status bit not set when expected!") ;
5249
        test_fail("System error interrupt status bit not set when expected") ;
5250
        ok = 0 ;
5251
    end
5252
    `else
5253
    if ( temp_val1[4] !== 0 )
5254
    begin
5255
        $display("Parity checker testing failed! Time %t ", $time) ;
5256
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5257
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5258
        ok = 0 ;
5259
    end
5260
    `endif
5261
 
5262
    if ( temp_val1[3] !== 0 )
5263
    begin
5264
        $display("Parity checker testing failed! Time %t ", $time) ;
5265
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5266
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5267
        ok = 0 ;
5268
    end
5269
 
5270
    if ( ok )
5271
        test_ok ;
5272
 
5273
    // clear statuses
5274
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5275
 
5276
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5277
    fork
5278
    begin
5279
        ipci_unsupported_commands_master.master_reference
5280
        (
5281
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5282
            32'h5555_5555,      // second part of address in dual address cycle
5283
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5284
            `BC_MEM_WRITE,      // normal command
5285
            4'h0,               // byte enables
5286
            32'h1234_5678,      // data
5287
            1'b1,               // make address parity error on first phase of dual address
5288
            1'b0,               // make address parity error on second phase of dual address
5289
            ok                  // result of operation
5290
        ) ;
5291 35 mihad
        if ( !perr_asserted )
5292
            disable wait_serr14 ;
5293 15 mihad
    end
5294
    begin:wait_serr14
5295
        perr_asserted = 0 ;
5296
        @(posedge pci_clock) ;
5297 35 mihad
        while( SERR !== 0 )
5298 15 mihad
            @(posedge pci_clock) ;
5299
 
5300 35 mihad
        perr_asserted = 1 ;
5301 15 mihad
    end
5302
    join
5303
 
5304
    if ( ok && perr_asserted)
5305
        test_ok ;
5306
    else
5307
    if ( !perr_asserted )
5308
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5309
 
5310
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5311
 
5312
    `ifdef HOST
5313
        repeat(4)
5314 26 mihad
            @(posedge pci_clock) ;
5315
        repeat(4)
5316 15 mihad
            @(posedge wb_clock) ;
5317
        if ( INT_O !== 1 )
5318
        begin
5319
            $display("Parity checker testing failed! Time %t ", $time) ;
5320
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5321
            test_fail("Interrupt Request was not triggered as expected") ;
5322
        end
5323
        else
5324
            test_ok ;
5325
    `else
5326
    `ifdef GUEST
5327 26 mihad
        repeat(4)
5328
            @(posedge wb_clock) ;
5329
        repeat(4)
5330 15 mihad
            @(posedge pci_clock) ;
5331
 
5332
        if ( INTA !== 1 )
5333
        begin
5334
            $display("Parity checker testing failed! Time %t ", $time) ;
5335
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5336
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5337
        end
5338
        else
5339
            test_ok ;
5340
    `endif
5341
    `endif
5342
 
5343
    // check statuses!
5344
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5345
    ok = 1 ;
5346
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5347
    if ( temp_val1[31] !== 1 )
5348
    begin
5349
        $display("Parity checker testing failed! Time %t ", $time) ;
5350
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5351
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5352
        ok = 0 ;
5353
    end
5354
 
5355
    if ( temp_val1[30] !== 1 )
5356
    begin
5357
        $display("Parity checker testing failed! Time %t ", $time) ;
5358
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5359
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5360
        ok = 0 ;
5361
    end
5362
 
5363
    if ( temp_val1[24] !== 0 )
5364
    begin
5365
        $display("Parity checker testing failed! Time %t ", $time) ;
5366
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5367
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5368
        ok = 0 ;
5369
    end
5370
 
5371
    if ( ok )
5372
        test_ok ;
5373
 
5374
    // clear statuses
5375
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5376
 
5377
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5378
 
5379
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5380
    ok = 1 ;
5381
 
5382
    `ifdef HOST
5383
    if ( temp_val1[4] !== 1 )
5384
    begin
5385
        $display("Parity checker testing failed! Time %t ", $time) ;
5386
        $display("System error interrupt status bit not set when expected!") ;
5387
        test_fail("System error interrupt status bit not set when expected") ;
5388
        ok = 0 ;
5389
    end
5390
    `else
5391
    if ( temp_val1[4] !== 0 )
5392
    begin
5393
        $display("Parity checker testing failed! Time %t ", $time) ;
5394
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5395
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5396
        ok = 0 ;
5397
    end
5398
    `endif
5399
 
5400
    if ( temp_val1[3] !== 0 )
5401
    begin
5402
        $display("Parity checker testing failed! Time %t ", $time) ;
5403
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5404
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5405
        ok = 0 ;
5406
    end
5407
 
5408
    if ( ok )
5409
        test_ok ;
5410
 
5411
    // clear statuses
5412
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5413
 
5414
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5415
    fork
5416
    begin
5417
        ipci_unsupported_commands_master.master_reference
5418
        (
5419
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5420
            32'h5555_5555,      // second part of address in dual address cycle
5421
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5422
            `BC_MEM_WRITE,      // normal command
5423
            4'h0,               // byte enables
5424
            32'h1234_5678,      // data
5425
            1'b0,               // make address parity error on first phase of dual address
5426
            1'b1,               // make address parity error on second phase of dual address
5427
            ok                  // result of operation
5428
        ) ;
5429 35 mihad
        if ( !perr_asserted )
5430
            disable wait_serr15 ;
5431 15 mihad
    end
5432
    begin:wait_serr15
5433
        perr_asserted = 0 ;
5434
        @(posedge pci_clock) ;
5435 35 mihad
        while( SERR !== 0 )
5436 15 mihad
            @(posedge pci_clock) ;
5437
 
5438 35 mihad
        perr_asserted = 1 ;
5439 15 mihad
    end
5440
    join
5441
 
5442
    if ( ok && perr_asserted)
5443
        test_ok ;
5444
    else
5445
    if ( !perr_asserted )
5446
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5447
 
5448
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5449
 
5450
    `ifdef HOST
5451
        repeat(4)
5452 26 mihad
            @(posedge pci_clock) ;
5453
        repeat(4)
5454 15 mihad
            @(posedge wb_clock) ;
5455
        if ( INT_O !== 1 )
5456
        begin
5457
            $display("Parity checker testing failed! Time %t ", $time) ;
5458
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5459
            test_fail("Interrupt Request was not triggered as expected") ;
5460
        end
5461
        else
5462
            test_ok ;
5463
    `else
5464
    `ifdef GUEST
5465 26 mihad
        repeat(4)
5466
            @(posedge wb_clock) ;
5467
        repeat(4)
5468 15 mihad
            @(posedge pci_clock) ;
5469
 
5470
        if ( INTA !== 1 )
5471
        begin
5472
            $display("Parity checker testing failed! Time %t ", $time) ;
5473
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5474
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5475
        end
5476
        else
5477
            test_ok ;
5478
    `endif
5479
    `endif
5480
 
5481
    // check statuses!
5482
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5483
    ok = 1 ;
5484
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5485
    if ( temp_val1[31] !== 1 )
5486
    begin
5487
        $display("Parity checker testing failed! Time %t ", $time) ;
5488
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5489
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5490
        ok = 0 ;
5491
    end
5492
 
5493
    if ( temp_val1[30] !== 1 )
5494
    begin
5495
        $display("Parity checker testing failed! Time %t ", $time) ;
5496
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5497
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5498
        ok = 0 ;
5499
    end
5500
 
5501
    if ( temp_val1[24] !== 0 )
5502
    begin
5503
        $display("Parity checker testing failed! Time %t ", $time) ;
5504
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5505
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5506
        ok = 0 ;
5507
    end
5508
 
5509
    if ( ok )
5510
        test_ok ;
5511
 
5512
    // clear statuses
5513
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5514
 
5515
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5516
 
5517
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5518
    ok = 1 ;
5519
 
5520
    `ifdef HOST
5521
    if ( temp_val1[4] !== 1 )
5522
    begin
5523
        $display("Parity checker testing failed! Time %t ", $time) ;
5524
        $display("System error interrupt status bit not set when expected!") ;
5525
        test_fail("System error interrupt status bit not set when expected") ;
5526
        ok = 0 ;
5527
    end
5528
    `else
5529
    if ( temp_val1[4] !== 0 )
5530
    begin
5531
        $display("Parity checker testing failed! Time %t ", $time) ;
5532
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5533
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5534
        ok = 0 ;
5535
    end
5536
    `endif
5537
 
5538
    if ( temp_val1[3] !== 0 )
5539
    begin
5540
        $display("Parity checker testing failed! Time %t ", $time) ;
5541
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5542
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5543
        ok = 0 ;
5544
    end
5545
 
5546
    if ( ok )
5547
        test_ok ;
5548
 
5549
    // clear statuses
5550
    config_write( pci_ctrl_offset, (32'h0000_0147 | temp_val1), 4'b1111, ok ) ;
5551
 
5552
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. ENABLED" ;
5553
    fork
5554
    begin
5555
        ipci_unsupported_commands_master.master_reference
5556
        (
5557
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5558
            32'h5555_5555,      // second part of address in dual address cycle
5559
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5560
            `BC_MEM_WRITE,      // normal command
5561
            4'h0,               // byte enables
5562
            32'h1234_5678,      // data
5563
            1'b1,               // make address parity error on first phase of dual address
5564
            1'b1,               // make address parity error on second phase of dual address
5565
            ok                  // result of operation
5566
        ) ;
5567 35 mihad
        if ( !perr_asserted )
5568
            disable wait_serr16 ;
5569 15 mihad
    end
5570
    begin:wait_serr16
5571
        perr_asserted = 0 ;
5572
        @(posedge pci_clock) ;
5573 35 mihad
        while( SERR !== 0 )
5574 15 mihad
            @(posedge pci_clock) ;
5575
 
5576 35 mihad
        perr_asserted = 1 ;
5577 15 mihad
    end
5578
    join
5579
 
5580
    if ( ok && perr_asserted)
5581
        test_ok ;
5582
    else
5583
    if ( !perr_asserted )
5584
        test_fail("PCI bridge failed to assert SERR when Address Parity Error was presented on PCI bus") ;
5585
 
5586
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR WAS PRESENTED ON PCI" ;
5587
 
5588
    `ifdef HOST
5589
        repeat(4)
5590 26 mihad
            @(posedge pci_clock) ;
5591
        repeat(4)
5592 15 mihad
            @(posedge wb_clock) ;
5593
        if ( INT_O !== 1 )
5594
        begin
5595
            $display("Parity checker testing failed! Time %t ", $time) ;
5596
            $display("Address Parity error just presented on PCI should trigger an interrupt request, but no request detected!") ;
5597
            test_fail("Interrupt Request was not triggered as expected") ;
5598
        end
5599
        else
5600
            test_ok ;
5601
    `else
5602
    `ifdef GUEST
5603 26 mihad
        repeat(4)
5604
            @(posedge wb_clock) ;
5605
        repeat(4)
5606 15 mihad
            @(posedge pci_clock) ;
5607
 
5608
        if ( INTA !== 1 )
5609
        begin
5610
            $display("Parity checker testing failed! Time %t ", $time) ;
5611
            $display("Address Parity error just presented on PCI triggered an interrupt request on PCI!") ;
5612
            test_fail("GUEST bridge isn't supposed to trigger interrupts because of parity errors") ;
5613
        end
5614
        else
5615
            test_ok ;
5616
    `endif
5617
    `endif
5618
 
5619
    // check statuses!
5620
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5621
    ok = 1 ;
5622
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5623
    if ( temp_val1[31] !== 1 )
5624
    begin
5625
        $display("Parity checker testing failed! Time %t ", $time) ;
5626
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5627
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI");
5628
        ok = 0 ;
5629
    end
5630
 
5631
    if ( temp_val1[30] !== 1 )
5632
    begin
5633
        $display("Parity checker testing failed! Time %t ", $time) ;
5634
        $display("Signalled System Error bit was not set on address parity error when expected!") ;
5635
        test_fail("Signalled System Error bit was not set on address parity error as expected") ;
5636
        ok = 0 ;
5637
    end
5638
 
5639
    if ( temp_val1[24] !== 0 )
5640
    begin
5641
        $display("Parity checker testing failed! Time %t ", $time) ;
5642
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5643
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5644
        ok = 0 ;
5645
    end
5646
 
5647
    if ( ok )
5648
        test_ok ;
5649
 
5650
    // clear statuses
5651
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5652
 
5653
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5654
 
5655
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR ON PCI" ;
5656
    ok = 1 ;
5657
 
5658
    `ifdef HOST
5659
    if ( temp_val1[4] !== 1 )
5660
    begin
5661
        $display("Parity checker testing failed! Time %t ", $time) ;
5662
        $display("System error interrupt status bit not set when expected!") ;
5663
        test_fail("System error interrupt status bit not set when expected") ;
5664
        ok = 0 ;
5665
    end
5666
    `else
5667
    if ( temp_val1[4] !== 0 )
5668
    begin
5669
        $display("Parity checker testing failed! Time %t ", $time) ;
5670
        $display("System error interrupt status bit set in GUEST implementation of the bridge!") ;
5671
        test_fail("System error interrupt status bit set in GUEST implementation of the bridge") ;
5672
        ok = 0 ;
5673
    end
5674
    `endif
5675
 
5676
    if ( temp_val1[3] !== 0 )
5677
    begin
5678
        $display("Parity checker testing failed! Time %t ", $time) ;
5679
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5680
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5681
        ok = 0 ;
5682
    end
5683
 
5684
    if ( ok )
5685
        test_ok ;
5686
 
5687
    // clear statuses
5688
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5689
 
5690
    // now just disable Parity Error response - on Address par errors nothing should happen
5691
    config_write( pci_ctrl_offset, 32'h0000_0107, 4'b0011, ok ) ;
5692
 
5693
    test_name = "NO SERR ASSERTION ON ADDRESS PARITY ERROR WITH SERR ENABLED AND PAR. ERR. RESPONSE DISABLED" ;
5694
    fork
5695
    begin
5696
        PCIU_MEM_WRITE_MAKE_SERR ("MEM_WRITE ", `Test_Master_2,
5697
               target_address, 32'h1234_5678,
5698
               1, 8'h2_0, `Test_One_Zero_Target_WS,
5699
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
5700
        do_pause( 1 ) ;
5701
    end
5702
    begin:wait_serr12
5703
        perr_asserted = 0 ;
5704
        @(posedge pci_clock) ;
5705
        while( SERR === 1 )
5706
            @(posedge pci_clock) ;
5707
 
5708
        perr_asserted = 1 ;
5709
        $display("Parity checker testing failed! Time %t ", $time) ;
5710
        $display("SERR asserted on address parity error when System Error response was disabled!") ;
5711
        test_fail("SERR asserted when parity error response was disabled") ;
5712
    end
5713
    begin
5714
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
5715
        if ( ok !== 1 )
5716
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
5717
 
5718 35 mihad
        @(posedge pci_clock) ;
5719
        #1 ;
5720
        if ( !perr_asserted )
5721
            disable wait_serr12 ;
5722 15 mihad
    end
5723
    join
5724
 
5725
    if ( ok && !perr_asserted )
5726
        test_ok ;
5727
 
5728
    test_name = "INTERRUPT REQUEST AFTER ADDR. PARITY ERROR WITH PERR RESPONSE DISABLED" ;
5729
    `ifdef HOST
5730 26 mihad
        repeat (4)
5731
            @(posedge pci_clock) ;
5732 15 mihad
        repeat(4)
5733
            @(posedge wb_clock) ;
5734
        if ( INT_O !== 0 )
5735
        begin
5736
            $display("Parity checker testing failed! Time %t ", $time) ;
5737
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5738
            test_fail("Interrupt Request should not be asserted when parity error response is disabled") ;
5739
        end
5740
        else
5741
            test_ok ;
5742
    `else
5743
    `ifdef GUEST
5744 26 mihad
        repeat(4)
5745
            @(posedge wb_clock) ;
5746
        repeat (4)
5747 15 mihad
            @(posedge pci_clock) ;
5748
 
5749
        if ( INTA !== 1 )
5750
        begin
5751
            $display("Parity checker testing failed! Time %t ", $time) ;
5752
            $display("Address Parity error just presented on PCI shouldn't trigger an interrupt request!") ;
5753
            test_fail("Parity Errors shouldn't trigger interrupts on PCI bus") ;
5754
        end
5755
        else
5756
            test_ok ;
5757
    `endif
5758
    `endif
5759
 
5760
    // check statuses!
5761
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5762
    ok = 1 ;
5763
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5764
    if ( temp_val1[31] !== 1 )
5765
    begin
5766
        $display("Parity checker testing failed! Time %t ", $time) ;
5767
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5768
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5769
        ok = 0 ;
5770
    end
5771
 
5772
    if ( temp_val1[30] !== 0 )
5773
    begin
5774
        $display("Parity checker testing failed! Time %t ", $time) ;
5775
        $display("Signalled System Error bit was set on address parity error when not expected!") ;
5776
        test_fail("Signalled System Error bit was set on address parity error when not expected") ;
5777
        ok = 0 ;
5778
    end
5779
 
5780
    if ( temp_val1[24] !== 0 )
5781
    begin
5782
        $display("Parity checker testing failed! Time %t ", $time) ;
5783
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5784
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5785
        ok = 0 ;
5786
    end
5787
 
5788
    if ( ok )
5789
        test_ok ;
5790
 
5791
    // clear statuses
5792
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5793
 
5794
    config_read( isr_offset, 4'hF, temp_val1 ) ;
5795
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ADDR PERR WITH PERR RESPONSE DISABLED" ;
5796
    ok = 1 ;
5797
    if ( temp_val1[4] !== 0 )
5798
    begin
5799
        $display("Parity checker testing failed! Time %t ", $time) ;
5800
        $display("System error interrupt status bit set when not expected!") ;
5801
        test_fail("System error interrupt status bit set when not expected") ;
5802
        ok = 0 ;
5803
    end
5804
 
5805
    if ( temp_val1[3] !== 0 )
5806
    begin
5807
        $display("Parity checker testing failed! Time %t ", $time) ;
5808
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
5809
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
5810
        ok = 0 ;
5811
    end
5812
 
5813
    if ( ok )
5814
        test_ok ;
5815
 
5816
    // clear statuses
5817
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
5818
 
5819
    test_name = "ADDRESS PARITY ERROR ON FIRST DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5820
    fork
5821
    begin
5822
        ipci_unsupported_commands_master.master_reference
5823
        (
5824
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5825
            32'h5555_5555,      // second part of address in dual address cycle
5826
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5827
            `BC_MEM_WRITE,      // normal command
5828
            4'h0,               // byte enables
5829
            32'h1234_5678,      // data
5830
            1'b1,               // make address parity error on first phase of dual address
5831
            1'b0,               // make address parity error on second phase of dual address
5832
            ok                  // result of operation
5833
        ) ;
5834 35 mihad
        if ( !perr_asserted )
5835
            disable wait_serr17 ;
5836 15 mihad
    end
5837
    begin:wait_serr17
5838
        perr_asserted = 0 ;
5839
        @(posedge pci_clock) ;
5840
        while( SERR === 1 )
5841
            @(posedge pci_clock) ;
5842
 
5843
        perr_asserted = 1 ;
5844
        $display("Parity checker testing failed! Time %t ", $time) ;
5845
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5846
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5847
    end
5848
    join
5849
 
5850
    if ( ok && !perr_asserted)
5851
        test_ok ;
5852
 
5853
    test_name = "ADDRESS PARITY ERROR ON SECOND DATA PHASE OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5854
    fork
5855
    begin
5856
        ipci_unsupported_commands_master.master_reference
5857
        (
5858
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5859
            32'h5555_5555,      // second part of address in dual address cycle
5860
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5861
            `BC_MEM_WRITE,      // normal command
5862
            4'h0,               // byte enables
5863
            32'h1234_5678,      // data
5864
            1'b0,               // make address parity error on first phase of dual address
5865
            1'b1,               // make address parity error on second phase of dual address
5866
            ok                  // result of operation
5867
        ) ;
5868 35 mihad
        if ( !perr_asserted )
5869
            disable wait_serr18 ;
5870 15 mihad
    end
5871
    begin:wait_serr18
5872
        perr_asserted = 0 ;
5873
        @(posedge pci_clock) ;
5874
        while( SERR === 1 )
5875
            @(posedge pci_clock) ;
5876
 
5877
        perr_asserted = 1 ;
5878
        $display("Parity checker testing failed! Time %t ", $time) ;
5879
        $display("SERR asserted on address parity error when Parity Error response was disabled!") ;
5880
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5881
    end
5882
    join
5883
 
5884
    if ( ok && !perr_asserted)
5885
        test_ok ;
5886
 
5887
    // check statuses!
5888
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5889
    ok = 1 ;
5890
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5891
    if ( temp_val1[31] !== 1 )
5892
    begin
5893
        $display("Parity checker testing failed! Time %t ", $time) ;
5894
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5895
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5896
        ok = 0 ;
5897
    end
5898
 
5899
    if ( temp_val1[30] !== 0 )
5900
    begin
5901
        $display("Parity checker testing failed! Time %t ", $time) ;
5902
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
5903
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
5904
        ok = 0 ;
5905
    end
5906
 
5907
    if ( temp_val1[24] !== 0 )
5908
    begin
5909
        $display("Parity checker testing failed! Time %t ", $time) ;
5910
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
5911
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
5912
        ok = 0 ;
5913
    end
5914
 
5915
    if ( ok )
5916
        test_ok ;
5917
 
5918
    // clear statuses
5919
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
5920
 
5921
    test_name = "ADDRESS PARITY ERROR ON BOTH DATA PHASES OF DUAL ADDRESS CYCLE - SERR ENABLED, PAR. RESP. DISABLED" ;
5922
    fork
5923
    begin
5924
        ipci_unsupported_commands_master.master_reference
5925
        (
5926
            32'hAAAA_AAAA,      // first part of address in dual address cycle
5927
            32'h5555_5555,      // second part of address in dual address cycle
5928
            `BC_DUAL_ADDR_CYC,  // dual address cycle command
5929
            `BC_MEM_WRITE,      // normal command
5930
            4'h0,               // byte enables
5931
            32'h1234_5678,      // data
5932
            1'b1,               // make address parity error on first phase of dual address
5933
            1'b1,               // make address parity error on second phase of dual address
5934
            ok                  // result of operation
5935
        ) ;
5936 35 mihad
        if ( !perr_asserted )
5937
            disable wait_serr19 ;
5938 15 mihad
    end
5939
    begin:wait_serr19
5940
        perr_asserted = 0 ;
5941
        @(posedge pci_clock) ;
5942
        while( SERR === 1 )
5943
            @(posedge pci_clock) ;
5944
 
5945
        perr_asserted = 1 ;
5946
        $display("Parity checker testing failed! Time %t ", $time) ;
5947
        $display("SERR asserted on address parity error when Patity Error response was disabled!") ;
5948
        test_fail("bridge shouldn't assert SERR when PERR is disabled") ;
5949
    end
5950
    join
5951
 
5952
    if ( ok && !perr_asserted)
5953
        test_ok ;
5954
 
5955
    test_name = "INTERRUPT REQUEST AFTER ADDRESS PARITY ERROR" ;
5956
 
5957
    `ifdef HOST
5958
        repeat(4)
5959 26 mihad
            @(posedge pci_clock) ;
5960
        repeat(4)
5961 15 mihad
            @(posedge wb_clock) ;
5962
        if ( INT_O !== 0 )
5963
        begin
5964
            $display("Parity checker testing failed! Time %t ", $time) ;
5965
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on WB bus!") ;
5966
            test_fail("Address Parity Error was presented on PCI, SERR was not enabled, but INT REQ was signalled on WB bus") ;
5967
        end
5968
        else
5969
            test_ok ;
5970
    `else
5971
    `ifdef GUEST
5972 26 mihad
        repeat(4)
5973
            @(posedge wb_clock) ;
5974
        repeat(4)
5975 15 mihad
            @(posedge pci_clock) ;
5976
 
5977
        if ( INTA !== 1 )
5978
        begin
5979
            $display("Parity checker testing failed! Time %t ", $time) ;
5980
            $display("Address Parity Error was presented on PCI, SERR int. en. was not set, but INT REQ was signalled on PCI bus!") ;
5981
            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") ;
5982
        end
5983
        else
5984
            test_ok ;
5985
    `endif
5986
    `endif
5987
 
5988
    // check statuses!
5989
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER ADDRESS PARITY ERROR AND PERR DISABLED" ;
5990
    ok = 1 ;
5991
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
5992
    if ( temp_val1[31] !== 1 )
5993
    begin
5994
        $display("Parity checker testing failed! Time %t ", $time) ;
5995
        $display("Detected Parity Error bit was not set when address parity error was presented on PCI!") ;
5996
        test_fail("Detected Parity Error bit was not set when address parity error was presented on PCI") ;
5997
        ok = 0 ;
5998
    end
5999
 
6000
    if ( temp_val1[30] !== 0 )
6001
    begin
6002
        $display("Parity checker testing failed! Time %t ", $time) ;
6003
        $display("Signalled System Error bit was set on address parity error, when SERR enable bit was disabled!") ;
6004
        test_fail("Signalled System Error bit was set on address parity error, when SERR enable bit was not set") ;
6005
        ok = 0 ;
6006
    end
6007
 
6008
    if ( temp_val1[24] !== 0 )
6009
    begin
6010
        $display("Parity checker testing failed! Time %t ", $time) ;
6011
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6012
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6013
        ok = 0 ;
6014
    end
6015
 
6016
    if ( ok )
6017
        test_ok ;
6018
 
6019
    // clear statuses
6020
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6021
 
6022
    test_name = "EXTERNAL WRITE WITH NO PARITY ERRORS" ;
6023
 
6024
    // do normal write
6025
    fork
6026
    begin
6027
        PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_2,
6028
               target_address, 32'h1234_5678, `Test_All_Bytes,
6029
               1, 8'h3_0, `Test_One_Zero_Target_WS,
6030
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6031
        do_pause( 1 ) ;
6032
    end
6033
    begin:wait_serr13
6034
        perr_asserted = 0 ;
6035
        @(posedge pci_clock) ;
6036
        while( SERR === 1 )
6037
            @(posedge pci_clock) ;
6038
 
6039
        perr_asserted = 1 ;
6040
        $display("Parity checker testing failed! Time %t ", $time) ;
6041
        $display("SERR asserted for no reason!") ;
6042
        test_fail("SERR was asserted for no reason") ;
6043
    end
6044
    begin
6045
        pci_transaction_progress_monitor(target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
6046
        if ( ok !== 1 )
6047
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6048
 
6049 35 mihad
        @(posedge pci_clock) ;
6050
        #1 ;
6051
        if ( !perr_asserted )
6052
            disable wait_serr13 ;
6053 15 mihad
    end
6054
    join
6055
 
6056
    if ( ok && !perr_asserted )
6057
        test_ok ;
6058
 
6059
    test_name = "INTERRUPT REQUESTS AFTER NORMAL EXTERNAL MASTER WRITE" ;
6060
    `ifdef HOST
6061 26 mihad
        repeat( 4 )
6062
            @(posedge pci_clock) ;
6063 15 mihad
        repeat(4)
6064
            @(posedge wb_clock) ;
6065
        if ( INT_O !== 0 )
6066
        begin
6067
            $display("Parity checker testing failed! Time %t ", $time) ;
6068
            $display("Interrupt request asserted for no reason!") ;
6069
            test_fail("Interrupt request was asserted for no reason") ;
6070
        end
6071
        else
6072
            test_ok ;
6073
    `else
6074
    `ifdef GUEST
6075 26 mihad
        repeat(4)
6076
            @(posedge wb_clock) ;
6077
        repeat(4)
6078 15 mihad
            @(posedge pci_clock) ;
6079
 
6080
        if ( INTA !== 1 )
6081
        begin
6082
            $display("Parity checker testing failed! Time %t ", $time) ;
6083
            $display("Interrupt request asserted for no reason!") ;
6084
            test_fail("Interrupt request was asserted for no reason") ;
6085
        end
6086
        else
6087
            test_ok ;
6088
    `endif
6089
    `endif
6090
 
6091
    // check statuses!
6092
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6093
    ok = 1 ;
6094
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6095
    if ( temp_val1[31] !== 0 )
6096
    begin
6097
        $display("Parity checker testing failed! Time %t ", $time) ;
6098
        $display("Detected Parity Error bit was set for no reason!") ;
6099
        test_fail("Detected Parity Error bit was set for no reason") ;
6100
        ok = 0 ;
6101
    end
6102
 
6103
    if ( temp_val1[30] !== 0 )
6104
    begin
6105
        $display("Parity checker testing failed! Time %t ", $time) ;
6106
        $display("Signalled System Error bit was set for no reason!") ;
6107
        test_fail("Signalled System Error bit was set for no reason") ;
6108
        ok = 0 ;
6109
    end
6110
 
6111
    if ( temp_val1[24] !== 0 )
6112
    begin
6113
        $display("Parity checker testing failed! Time %t ", $time) ;
6114
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6115
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6116
        ok = 0 ;
6117
    end
6118
 
6119
    if ( ok )
6120
        test_ok ;
6121
 
6122
    // clear statuses
6123
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6124
 
6125
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6126
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER NORMAL EXTERNAL MASTER WRITE" ;
6127
    ok = 1 ;
6128
 
6129
    if ( temp_val1[4] !== 0 )
6130
    begin
6131
        $display("Parity checker testing failed! Time %t ", $time) ;
6132
        $display("System error interrupt status bit set when not expected!") ;
6133
        test_fail("System error interrupt status bit set when not expected") ;
6134
        ok = 0 ;
6135
    end
6136
 
6137
    if ( temp_val1[3] !== 0 )
6138
    begin
6139
        $display("Parity checker testing failed! Time %t ", $time) ;
6140
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6141
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6142
        ok = 0 ;
6143
    end
6144
 
6145
    if ( ok )
6146
        test_ok ;
6147
 
6148
    // clear statuses
6149
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6150
 
6151
    $display("Introducing Data Parity Errors on Bridge's Target references!") ;
6152
 
6153
    $display("Introducing Data Parity Error on Write reference to Bridge's Target!") ;
6154
 
6155
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
6156
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
6157
 
6158
    // setup target's image!
6159
    target_address  = Target_Base_Addr_R[1] ;
6160
 
6161
    // base address
6162
    config_write( p_ba_offset, target_address, 4'b1111, ok ) ;
6163
 
6164
    // address mask
6165
    config_write( p_am_offset, 32'hFFFF_FFFF, 4'b1111, ok ) ;
6166
 
6167
    // image control
6168
    config_write( p_ctrl_offset, 32'h0000_0000, 4'hF, ok ) ;
6169
 
6170
    // enable everything possible for parity checking
6171
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'b1111, ok ) ;
6172
    config_write( icr_offset, 32'h0000_0018, 4'b0001, ok ) ;
6173
 
6174
    test_name = "INVALID PAR ON WRITE REFERENCE THROUGH BRIDGE'S TARGET - PERR RESPONSE ENABLED" ;
6175
 
6176
    fork
6177
    begin
6178
        if ( target_mem_image === 1 )
6179
            PCIU_MEM_WRITE_MAKE_PERR ("MEM_WRITE ", `Test_Master_1,
6180
                   target_address, 32'h1234_5678,
6181
                   1, 8'h1_0, `Test_One_Zero_Target_WS,
6182
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6183
        else
6184
            PCIU_IO_WRITE_MAKE_PERR (
6185
                                    `Test_Master_1,
6186
                                    target_address,
6187
                                    32'h1234_5678,
6188
                                    4'h0,
6189
                                    1,
6190
                                    `Test_Target_Normal_Completion
6191
                                    );
6192
 
6193
        do_pause( 1 ) ;
6194
    end
6195
    begin:wait_perr11
6196
        perr_asserted = 0 ;
6197
        @(posedge pci_clock) ;
6198 35 mihad
        while ( PERR !== 0 )
6199 15 mihad
            @(posedge pci_clock) ;
6200
 
6201 35 mihad
        perr_asserted = 1 ;
6202 15 mihad
 
6203
    end
6204
    begin
6205
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_WRITE : `BC_IO_WRITE) , 1, 0, 1'b1, 1'b0, 0, ok) ;
6206
 
6207
        if ( ok !== 1 )
6208
            test_fail("behavioral PCI Master failed to start expected transaction or behavioral PCI target failed to respond to it") ;
6209
 
6210
        repeat(2)
6211
            @(posedge pci_clock) ;
6212
 
6213 35 mihad
        #1 ;
6214
        if ( !perr_asserted )
6215
            disable wait_perr11 ;
6216 15 mihad
    end
6217
    join
6218
 
6219
    if ( ok && perr_asserted )
6220
        test_ok ;
6221
    else
6222
    if ( !perr_asserted )
6223
        test_fail("Bridge failed to assert PERR on write reference to bridge's target") ;
6224
 
6225
    test_name = "INTERRUPT REQUESTS AFTER TARGET WRITE REFERENCE PARITY ERROR" ;
6226
    `ifdef HOST
6227 26 mihad
        repeat (4)
6228
            @(posedge pci_clock) ;
6229 15 mihad
        repeat(4)
6230
            @(posedge wb_clock) ;
6231
        if ( INT_O !== 0 )
6232
        begin
6233
            $display("Parity checker testing failed! Time %t ", $time) ;
6234
            $display("Interrupt request asserted for no reason!") ;
6235
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6236
        end
6237
        else
6238
            test_ok ;
6239
    `else
6240
    `ifdef GUEST
6241 26 mihad
        repeat(4)
6242
            @(posedge wb_clock) ;
6243
        repeat (4)
6244 15 mihad
            @(posedge pci_clock) ;
6245
 
6246
        if ( INTA !== 1 )
6247
        begin
6248
            $display("Parity checker testing failed! Time %t ", $time) ;
6249
            $display("Interrupt request asserted for no reason!") ;
6250
            test_fail("Parity Errors musn't cause interrupt requests on Target references") ;
6251
        end
6252
        else
6253
            test_ok ;
6254
 
6255
    `endif
6256
    `endif
6257
 
6258
    // check statuses!
6259
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6260
    ok = 1 ;
6261
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6262
    if ( temp_val1[31] !== 1 )
6263
    begin
6264
        $display("Parity checker testing failed! Time %t ", $time) ;
6265 45 mihad
        $display("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction!") ;
6266
        test_fail("Detected Parity Error bit was not set after data parity error was presented during Target Write Transaction") ;
6267 15 mihad
        ok = 0 ;
6268
    end
6269
 
6270
    if ( temp_val1[30] !== 0 )
6271
    begin
6272
        $display("Parity checker testing failed! Time %t ", $time) ;
6273
        $display("Signalled System Error bit was set for no reason!") ;
6274
        test_fail("Signalled System Error bit was set for no reason") ;
6275
        ok = 0 ;
6276
    end
6277
 
6278
    if ( temp_val1[24] !== 0 )
6279
    begin
6280
        $display("Parity checker testing failed! Time %t ", $time) ;
6281
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6282
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6283
        ok = 0 ;
6284
    end
6285
 
6286
    if ( ok )
6287
        test_ok ;
6288
 
6289
    // clear statuses
6290
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6291
 
6292
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6293
 
6294
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET REFERENCE" ;
6295
    ok = 1 ;
6296
    if ( temp_val1[4] !== 0 )
6297
    begin
6298
        $display("Parity checker testing failed! Time %t ", $time) ;
6299
        $display("System error interrupt status bit set when not expected!") ;
6300
        test_fail("System error interrupt status bit set when not expected") ;
6301
        ok = 0 ;
6302
    end
6303
 
6304
    if ( temp_val1[3] !== 0 )
6305
    begin
6306
        $display("Parity checker testing failed! Time %t ", $time) ;
6307
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6308
        test_fail("Parity Error interrupt status bit was set when  Bridge's master didn't perform references") ;
6309
        ok = 0 ;
6310
    end
6311
 
6312
    if ( ok )
6313
        test_ok ;
6314
 
6315
    // clear statuses
6316
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6317
 
6318
    $display("Introducing Data Parity Error on Read reference to Bridge's Target!") ;
6319
 
6320
    test_name = "PARITY ERROR HANDLING ON TARGET READ REFERENCE" ;
6321
    fork
6322
    begin
6323
        if ( target_mem_image === 1 )
6324
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
6325
                          target_address, 32'h1234_5678,
6326
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
6327
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
6328
        else
6329
            PCIU_IO_READ( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
6330
 
6331
        do_pause( 1 ) ;
6332
    end
6333
    begin:wait_perr12
6334
        perr_asserted = 0 ;
6335
        @(posedge pci_clock) ;
6336 35 mihad
        while ( PERR !== 0 )
6337 15 mihad
            @(posedge pci_clock) ;
6338
 
6339 35 mihad
        perr_asserted = 1 ;
6340 15 mihad
    end
6341
    begin
6342
 
6343
        wb_transaction_progress_monitor(target_address, 0, 1, 1'b1, ok) ;
6344
        if ( ok !== 1 )
6345
        begin
6346
            test_fail("Bridge failed to process Target Memory read correctly") ;
6347
            disable main ;
6348
        end
6349
 
6350
        repeat(3)
6351
            @(posedge pci_clock) ;
6352
 
6353
        if ( target_mem_image === 1 )
6354
            PCIU_MEM_READ_MAKE_PERR("MEM_READ  ", `Test_Master_1,
6355
                    target_address, 32'h1234_5678,
6356
                    1, 8'h3_0, `Test_One_Zero_Target_WS,
6357
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
6358
        else
6359
            PCIU_IO_READ_MAKE_PERR( `Test_Master_1, target_address, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
6360
 
6361
        do_pause( 1 ) ;
6362
 
6363
    end
6364
    begin
6365
        pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 0, 0, 1'b1, 1'b0, 0, ok) ;
6366
        if ( ok !== 1 )
6367
            test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6368
        else
6369
        begin
6370
            pci_transaction_progress_monitor(target_address, ((target_mem_image === 1) ? `BC_MEM_READ : `BC_IO_READ), 1, 0, 1'b1, 1'b0, 0, ok) ;
6371
            if ( ok !== 1 )
6372
                test_fail("behavioral PCI master failed to start expected transaction or Bridge's Target failed to respond on it") ;
6373
        end
6374
 
6375 35 mihad
        repeat(2)
6376 15 mihad
            @(posedge pci_clock) ;
6377
 
6378 35 mihad
        #1 ;
6379
        if ( !perr_asserted )
6380
            disable wait_perr12 ;
6381 15 mihad
    end
6382
    join
6383
 
6384
    if ( ok && perr_asserted )
6385
        test_ok ;
6386
    else
6387
    if ( !perr_asserted )
6388
        test_fail("behavioral master failed to assert invalid read PERR for testing") ;
6389
 
6390
 
6391
    test_name = "INTERRUPT REQUESTS AFTER PERR ON READ REFERENCE THROUGH BRIDGE'S TARGET" ;
6392
    `ifdef HOST
6393
        repeat(4)
6394 26 mihad
            @(posedge pci_clock) ;
6395
        repeat(4)
6396 15 mihad
            @(posedge wb_clock) ;
6397
        if ( INT_O !== 0 )
6398
        begin
6399
            $display("Parity checker testing failed! Time %t ", $time) ;
6400
            $display("Interrupt request asserted for no reason!") ;
6401
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6402
        end
6403
        else
6404
            test_ok ;
6405
    `else
6406
    `ifdef GUEST
6407 26 mihad
        repeat(4)
6408
            @(posedge wb_clock) ;
6409
        repeat(4)
6410 15 mihad
            @(posedge pci_clock) ;
6411
 
6412
        if ( INTA !== 1 )
6413
        begin
6414
            $display("Parity checker testing failed! Time %t ", $time) ;
6415
            $display("Interrupt request asserted for no reason!") ;
6416
            test_fail("Parity Interrupt request should not be asserted because parity errors on Target references") ;
6417
        end
6418
        else
6419
            test_ok ;
6420
    `endif
6421
    `endif
6422
 
6423
    // check statuses!
6424
    config_read( pci_ctrl_offset, 4'hF, temp_val1 ) ;
6425
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6426
    ok = 1 ;
6427 45 mihad
    if ( temp_val1[31] !== 0 )
6428 15 mihad
    begin
6429
        $display("Parity checker testing failed! Time %t ", $time) ;
6430 45 mihad
        $display("Detected Parity Error bit was set after data parity error during Target Read Transaction!") ;
6431
        test_fail("Detected Parity Error bit was set after Target received PERR asserted during Read Transaction") ;
6432 15 mihad
        ok = 0 ;
6433
    end
6434
 
6435
    if ( temp_val1[30] !== 0 )
6436
    begin
6437
        $display("Parity checker testing failed! Time %t ", $time) ;
6438
        $display("Signalled System Error bit was set for no reason!") ;
6439
        test_fail("Signalled System Error bit was set for no reason") ;
6440
        ok = 0 ;
6441
    end
6442
 
6443
    if ( temp_val1[24] !== 0 )
6444
    begin
6445
        $display("Parity checker testing failed! Time %t ", $time) ;
6446
        $display("Master Data Parity Error bit was set when Bridge's master was not even making a reference!") ;
6447
        test_fail("Master Data Parity Error bit was set when Bridge's master was not even making a reference") ;
6448
        ok = 0 ;
6449
    end
6450
 
6451
    if ( ok )
6452
        test_ok ;
6453
 
6454
    // clear statuses
6455
    config_write( pci_ctrl_offset, temp_val1, 4'b1111, ok ) ;
6456
 
6457
    config_read( isr_offset, 4'hF, temp_val1 ) ;
6458
    test_name = "INTERRUPT STATUS REGISTER VALUE AFTER PARITY ERROR ON TARGET READ REFERENCE" ;
6459
    ok = 1 ;
6460
    if ( temp_val1[4] !== 0 )
6461
    begin
6462
        $display("Parity checker testing failed! Time %t ", $time) ;
6463
        $display("System error interrupt status bit set when not expected!") ;
6464
        test_fail("System error interrupt status bit set when not expected") ;
6465
        ok = 0 ;
6466
    end
6467
 
6468
    if ( temp_val1[3] !== 0 )
6469
    begin
6470
        $display("Parity checker testing failed! Time %t ", $time) ;
6471
        $display("Parity Error interrupt status bit was set when  Bridge's master didn't perform references!") ;
6472
        test_fail("Parity Errors on Target references should not cause interrupt statuses to be set") ;
6473
        ok = 0 ;
6474
    end
6475
 
6476
    if ( ok )
6477
        test_ok ;
6478
    // clear statuses
6479
    config_write( isr_offset, temp_val1, 4'b1111, ok ) ;
6480
 
6481
    $fdisplay(pci_mon_log_file_desc,
6482
    "********************************************************************************** End of Monitor complaining section **********************************************************************************") ;
6483
    test_name = "DISABLE USED IMAGES" ;
6484
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6485
    if ( ok !== 1 )
6486
    begin
6487
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6488
        test_fail("WB Image Address Mask register could not be written to") ;
6489
        disable main ;
6490
    end
6491
 
6492 45 mihad
    config_write( p_am_offset, 32'h0000_0000, 4'hF, ok ) ;
6493 15 mihad
    if ( ok !== 1 )
6494
    begin
6495
        $display("Parity checker testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6496
        test_fail("PCI Image Address Mask register could not be written to") ;
6497
        disable main ;
6498
    end
6499
 
6500
    // disable target's 1 response to parity errors
6501 45 mihad
    configuration_cycle_write(0,                        // bus number
6502
                              `TAR1_IDSEL_INDEX - 11,   // device number
6503
                              0,                        // function number
6504
                              1,                        // register number
6505
                              0,                        // type of configuration cycle
6506
                              4'b0001,                  // byte enables
6507
                              32'h0000_0007             // data
6508 15 mihad
                             ) ;
6509
 
6510
    $display("**************************** DONE testing Parity Checker functions ******************************") ;
6511
end
6512
endtask // parity_checking
6513
 
6514
task wb_to_pci_transactions ;
6515
    reg   [11:0] ctrl_offset ;
6516
    reg   [11:0] ba_offset ;
6517
    reg   [11:0] am_offset ;
6518
    reg   [11:0] pci_ctrl_offset ;
6519
    reg   [11:0] err_cs_offset ;
6520
    reg   [11:0] icr_offset ;
6521
    reg   [11:0] isr_offset ;
6522
    reg   [11:0] lat_tim_cls_offset ;
6523
 
6524
    reg `WRITE_STIM_TYPE  write_data ;
6525
    reg `READ_STIM_TYPE   read_data ;
6526
    reg `READ_RETURN_TYPE read_status ;
6527
 
6528
    reg `WRITE_RETURN_TYPE write_status ;
6529
    reg `WB_TRANSFER_FLAGS write_flags ;
6530
    reg [31:0] temp_val1 ;
6531
    reg [31:0] temp_val2 ;
6532
    reg        ok   ;
6533
 
6534
    reg [31:0] image_base ;
6535
    reg [31:0] target_address ;
6536
    integer i ;
6537
    integer required_reads ;
6538
    integer writes_left ;
6539
 
6540
begin:main
6541
    ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
6542
    ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
6543
    am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
6544
    pci_ctrl_offset    = 12'h4 ;
6545
    err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
6546
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
6547
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
6548
    lat_tim_cls_offset = 12'hC ;
6549
 
6550
    $display("Checking WB to PCI transaction lengths!") ;
6551
    target_address  = `BEH_TAR1_MEM_START ;
6552
    image_base      = 0 ;
6553
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
6554
 
6555
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
6556
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
6557
    write_flags                    = 0 ;
6558
    write_flags`INIT_WAITS         = tb_init_waits ;
6559
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
6560
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6561
 
6562
    // enable master & target operation
6563
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION TESTING" ;
6564
    config_write( pci_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
6565
    if ( ok !== 1 )
6566
    begin
6567
        $display("WB to PCI transacton progress testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
6568
        test_fail("write to PCI Device Control register failed") ;
6569
        disable main ;
6570
    end
6571
 
6572
    // prepare image control register
6573
    config_write( ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
6574
    if ( ok !== 1 )
6575
    begin
6576
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
6577
        test_fail("write to WB Image Control register failed") ;
6578
        disable main ;
6579
    end
6580
 
6581
    // prepare base address register
6582
    config_write( ba_offset, image_base, 4'hF, ok ) ;
6583
    if ( ok !== 1 )
6584
    begin
6585
        $display("WB to PCI transacton progress testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
6586
        test_fail("write to WB Base Address register failed") ;
6587
        disable main ;
6588
    end
6589
 
6590
    // write address mask register
6591
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6592
    if ( ok !== 1 )
6593
    begin
6594
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
6595
        test_fail("write to WB Address Mask register failed") ;
6596
        disable main ;
6597
    end
6598
 
6599
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
6600
    config_write( err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
6601
    if ( ok !== 1 )
6602
    begin
6603
        $display("WB to PCI transacton progress testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
6604
        test_fail("write to WB Error Control and Status register failed") ;
6605
        disable main ;
6606
    end
6607
 
6608
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
6609
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
6610
    if ( ok !== 1 )
6611
    begin
6612
        $display("WB to PCI transacton progress testing failed! Failed to write IC register! Time %t ", $time) ;
6613
        test_fail("write to Interrupt Control register failed") ;
6614
        disable main ;
6615
    end
6616
 
6617
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
6618
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
6619
    if ( ok !== 1 )
6620
    begin
6621
        $display("WB to PCI transacton progress testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
6622
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
6623
        disable main ;
6624
    end
6625
 
6626
    $display("Testing single write transaction progress from WB to PCI!") ;
6627
    write_data`WRITE_ADDRESS = target_address ;
6628
    write_data`WRITE_DATA    = wmem_data[0] ;
6629
    write_data`WRITE_SEL     = 4'hF ;
6630
 
6631
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6632
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6633
 
6634
    test_name = "SINGLE POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6635
    fork
6636
    begin
6637
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
6638
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
6639
        begin
6640
            $display("Transaction progress testing failed! Time %t ", $time) ;
6641
            $display("Bridge failed to process single memory write!") ;
6642
            test_fail("bridge failed to post single memory write") ;
6643
            disable main ;
6644
        end
6645
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED FIRST TIME" ;
6646
    end
6647
    begin
6648
        // wait two retries, then enable target response
6649
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6650
        if ( ok !== 1 )
6651
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6652
        else
6653
            test_ok ;
6654
 
6655
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI RETRIED SECOND TIME" ;
6656
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6657
        if ( ok !== 1 )
6658
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6659
        else
6660
            test_ok ;
6661
 
6662
        test_name = "SINGLE POSTED WRITE FROM WISHBONE TO PCI DISCONNECTED" ;
6663
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6664
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6665
 
6666
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6667
        if ( ok !== 1 )
6668
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6669
        else
6670
            test_ok ;
6671
    end
6672
    join
6673
 
6674
    $display("Testing burst write transaction progress from WB to PCI!") ;
6675
    write_data`WRITE_ADDRESS = target_address ;
6676
    write_data`WRITE_DATA    = wmem_data[0] ;
6677
    write_data`WRITE_SEL     = 4'hF ;
6678
 
6679
    wishbone_master.blk_write_data[0] = write_data ;
6680
 
6681
    write_data`WRITE_ADDRESS = target_address + 4 ;
6682
    write_data`WRITE_DATA    = wmem_data[1] ;
6683
    write_data`WRITE_SEL     = 4'hF ;
6684
 
6685
    wishbone_master.blk_write_data[1] = write_data ;
6686
 
6687
    write_flags`WB_TRANSFER_SIZE = 2 ;
6688
    write_flags`WB_TRANSFER_CAB  = 1 ;
6689
 
6690
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6691
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6692
 
6693
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6694
 
6695
    fork
6696
    begin
6697
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6698
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6699
        begin
6700
            $display("Transaction progress testing failed! Time %t ", $time) ;
6701
            $display("Bridge failed to process whole CAB memory write!") ;
6702
            test_fail("bridge failed to post whole CAB memory write") ;
6703
            disable main ;
6704
        end
6705
        test_name = "BURST LENGTH 2 POSTED WRITE STARTS WITH RETRY" ;
6706
    end
6707
    begin
6708
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6709
        if ( ok !== 1 )
6710
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6711
        else
6712
            test_ok ;
6713
 
6714
        test_name = "BURST LENGTH 2 POSTED WRITE RETRIED SECOND TIME DISCONNECTED ON FIRST DATAPHASE" ;
6715
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6716
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6717
 
6718
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6719
        if ( ok !== 1 )
6720
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6721
        else
6722
            test_ok ;
6723
 
6724
        test_name = "BURST LENGTH 2 POSTED WRITE NORMAL COMPLETION AFTER DISCONNECT " ;
6725
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6726
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6727
 
6728
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6729
        if ( ok !== 1 )
6730
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6731
        else
6732
            test_ok ;
6733
    end
6734
    join
6735
 
6736
    test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6737
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6738
 
6739
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6740
    // try same write with other terminations
6741
    fork
6742
    begin
6743
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6744
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6745
        begin
6746
            $display("Transaction progress testing failed! Time %t ", $time) ;
6747
            $display("Bridge failed to process whole CAB memory write!") ;
6748
            test_fail("bridge failed to post whole CAB memory write") ;
6749
            disable main ;
6750
        end
6751
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED AFTER FIRST DATAPHASE FIRST TIME" ;
6752
    end
6753
    begin
6754
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6755
        if ( ok !== 1 )
6756
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6757
        else
6758
            test_ok ;
6759
 
6760
        test_name = "BURST LENGTH 2 POSTED WRITE DISCONNECTED WITH SECOND DATAPHASE SECOND TIME" ;
6761
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6762
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6763
 
6764
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6765
        if ( ok !== 1 )
6766
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6767
        else
6768
            test_ok ;
6769
    end
6770
    join
6771
 
6772
    // repeat the write with normal completion
6773
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6774
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6775
 
6776
    test_name = "BURST LENGTH 2 POSTED WRITE TRANSACTION PROCESSING ON PCI WITH NORMAL COMPLETION" ;
6777
    fork
6778
    begin
6779
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6780
        if ( write_status`CYC_ACTUAL_TRANSFER !== 2 )
6781
        begin
6782
            $display("Transaction progress testing failed! Time %t ", $time) ;
6783
            $display("Bridge failed to process whole CAB memory write!") ;
6784
            test_fail("bridge failed to post whole CAB memory write") ;
6785
            disable main ;
6786
        end
6787
    end
6788
    begin
6789
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6790
        if ( ok !== 1 )
6791
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6792
        else
6793
            test_ok ;
6794
    end
6795
    join
6796
 
6797
    // do the same thing with burst length of 3
6798
    write_data`WRITE_ADDRESS = target_address + 8 ;
6799
    write_data`WRITE_DATA    = wmem_data[2] ;
6800
    write_data`WRITE_SEL     = 4'hF ;
6801
 
6802
    wishbone_master.blk_write_data[2] = write_data ;
6803
 
6804
    write_flags`WB_TRANSFER_SIZE = 3 ;
6805
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6806
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6807
 
6808
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6809
 
6810
    fork
6811
    begin
6812
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6813
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6814
        begin
6815
            $display("Transaction progress testing failed! Time %t ", $time) ;
6816
            $display("Bridge failed to process whole CAB memory write!") ;
6817
            test_fail("bridge failed to post whole CAB memory write") ;
6818
            disable main ;
6819
        end
6820
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON FIRST DATAPHASE FIRST TIME" ;
6821
    end
6822
    begin
6823
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6824
        if ( ok !== 1 )
6825
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6826
        else
6827
            test_ok ;
6828
 
6829
        test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION DISCONNECT ON SECOND DATAPHASE SECOND TIME" ;
6830
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6831
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6832
 
6833
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6834
        if ( ok !== 1 )
6835
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6836
        else
6837
            test_ok ;
6838
    end
6839
    join
6840
 
6841
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6842
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6843
 
6844
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION PROCESSING ON PCI" ;
6845
    fork
6846
    begin
6847
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6848
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6849
        begin
6850
            $display("Transaction progress testing failed! Time %t ", $time) ;
6851
            $display("Bridge failed to process whole CAB memory write!") ;
6852
            test_fail("bridge failed to post whole CAB memory write") ;
6853
            disable main ;
6854
        end
6855
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON SECOND FIRST TIME" ;
6856
    end
6857
    begin
6858
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6859
        if ( ok !== 1 )
6860
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6861
        else
6862
            test_ok ;
6863
 
6864
        test_name = "BURST LENGTH 3 POSTED WRITE DISCONNECTED ON FIRST SECOND TIME" ;
6865
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6866
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6867
 
6868
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6869
        if ( ok !== 1 )
6870
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6871
        else
6872
            test_ok ;
6873
 
6874
    end
6875
    join
6876
 
6877
    // repeat with normal completion
6878
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6879
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6880
 
6881
    test_name = "BURST LENGTH 3 POSTED WRITE TRANSACTION WITH NORMAL COMPLETION" ;
6882
    fork
6883
    begin
6884
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6885
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
6886
        begin
6887
            $display("Transaction progress testing failed! Time %t ", $time) ;
6888
            $display("Bridge failed to process whole CAB memory write!") ;
6889
            test_fail("bridge failed to post whole CAB memory write") ;
6890
            disable main ;
6891
        end
6892
    end
6893
    begin
6894
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 0, ok ) ;
6895
        if ( ok !== 1 )
6896
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6897
        else
6898
            test_ok ;
6899
 
6900
    end
6901
    join
6902
 
6903
    // prepare data to fill whole write FIFO + 1 - in parallel prepare read data!
6904
    for ( i = 0 ; i < `WBW_DEPTH - 1 ; i = i + 1 )
6905
    begin
6906
        write_data`WRITE_ADDRESS = target_address + i*4 ;
6907
        write_data`WRITE_DATA    = wmem_data[i] ;
6908
        write_data`WRITE_SEL     = 4'hF ;
6909
 
6910
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
6911
        read_data`READ_SEL       = write_data`WRITE_SEL ;
6912
 
6913
        wishbone_master.blk_write_data[i]   = write_data ;
6914
        wishbone_master.blk_read_data_in[i] = read_data ;
6915
    end
6916
 
6917
    write_flags`WB_TRANSFER_CAB      = 1 ;
6918
    write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 1 ;
6919
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
6920
 
6921
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
6922
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6923
 
6924
    test_name = "BURST LENGTH OF WISHBONE FIFO DEPTH POSTED MEMORY WRITE" ;
6925
    fork
6926
    begin
6927
        wishbone_master.wb_block_write( write_flags, write_status ) ;
6928
        if ( write_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6929
        begin
6930
            $display("Transaction progress testing failed! Time %t ", $time) ;
6931
            $display("Bridge failed to process right number of databeats in CAB write!") ;
6932
            $display("WBW_FIFO can accomodate %d entries, WB_SLAVE accepted %d writes!", `WBW_DEPTH - 2, write_status`CYC_ACTUAL_TRANSFER) ;
6933
            test_fail("bridge failed to post whole CAB memory write") ;
6934
            disable main ;
6935
        end
6936
 
6937
        test_name = "FULL WRITE FIFO BURST RETRIED FIRST TIME" ;
6938
 
6939
        // read here just checks if data was transfered OK
6940
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
6941
        write_flags`WB_TRANSFER_SIZE     = `WBW_DEPTH - 2 ;
6942
 
6943
        wishbone_master.wb_block_read( write_flags, read_status ) ;
6944
 
6945
        if ( read_status`CYC_ACTUAL_TRANSFER !== `WBW_DEPTH - 2 )
6946
        begin
6947
            $display("Transaction progress testing failed! Time %t ", $time) ;
6948
            $display("Bridge processed CAB read wrong!") ;
6949
            test_fail("bridge didn't process read OK, to check data written by a burst") ;
6950
        end
6951
 
6952
    end
6953
    begin
6954
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
6955
        if ( ok !== 1 )
6956
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6957
        else
6958
            test_ok ;
6959
 
6960
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH FIRST SECOND TIME" ;
6961
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6962
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
6963
 
6964
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6965
        if ( ok !== 1 )
6966
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6967
        else
6968
            test_ok ;
6969
 
6970
        test_name = "FULL WRITE FIFO BURST DISCONNECT AFTER FIRST THIRD TIME" ;
6971
        test_target_response[`TARGET_ENCODED_TERMINATION] = `Test_Target_Retry_Before ;
6972
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6973
 
6974
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
6975
        if ( ok !== 1 )
6976
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6977
        else
6978
            test_ok ;
6979
 
6980
        test_name = "FULL WRITE FIFO BURST DISCONNECT WITH SECOND FOURTH TIME" ;
6981
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
6982
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
6983
 
6984
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_WRITE, 2, 0, 1'b1, 1'b0, 0, ok ) ;
6985
        if ( ok !== 1 )
6986
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6987
        else
6988
            test_ok ;
6989
 
6990
        test_name = "REMAINDER OF FULL WRITE FIFO BURST NORMAL COMPLETION FIFTH TIME" ;
6991
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
6992
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
6993
 
6994
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_WRITE, `WBW_DEPTH - 2 - 4, 0, 1'b1, 1'b0, 0, ok ) ;
6995
        if ( ok !== 1 )
6996
            test_fail("bridge started invalid memory write transaction or none at all or behavioral target didn't respond as expected") ;
6997
        else
6998
            test_ok ;
6999
 
7000
        // calculate how many read transactions must be done to read all written data back from target - bursts were set to length of 4
7001
        required_reads = (((`WBW_DEPTH - 2) % 4) > 0) ? ((`WBW_DEPTH - 2) / 4) + 1 : ((`WBW_DEPTH - 2) / 4) ;
7002
        test_name = "READ DATA BURSTED TO TARGET BACK AND CHECK VALUES" ;
7003
        for ( i = 0 ; i < required_reads ; i = i + 1 )
7004
        begin
7005
            pci_transaction_progress_monitor( target_address + 16*i, `BC_MEM_READ_LN, 4, 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
        end
7009
    end
7010
    join
7011
 
7012
    for ( i = 0 ; i < (`WBW_DEPTH - 2) ; i = i + 1 )
7013
    begin
7014
        read_status = wishbone_master.blk_read_data_out[i] ;
7015
        if (read_status`READ_DATA !== wmem_data[i])
7016
        begin
7017
            display_warning(target_address + 4 * i, wmem_data[i], read_status`READ_DATA) ;
7018
            test_fail("data read from target wasn't the same as data written to it") ;
7019
            ok = 0 ;
7020
        end
7021
    end
7022
 
7023
    if ( ok )
7024
        test_ok ;
7025
 
7026
    $display("Testing single read transaction progress from WB to PCI!") ;
7027
    read_data`READ_ADDRESS = target_address + 8 ;
7028
    read_data`READ_SEL     = 4'hF ;
7029
 
7030
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7031
 
7032
    test_name = "SINGLE READ TRANSACTION PROCESSING ON PCI" ;
7033
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7034
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7035
 
7036
    fork
7037
    begin
7038
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7039
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7040
        begin
7041
            $display("Transaction progress testing failed! Time %t ", $time) ;
7042
            $display("Bridge processed single read wrong!") ;
7043
            test_fail("bridge processed single read wrong") ;
7044
            disable main ;
7045
        end
7046
 
7047
        if (read_status`READ_DATA !== wmem_data[2])
7048
        begin
7049
            display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7050
            test_fail("data returned from single read was not as expected") ;
7051
        end
7052
        else
7053
        if ( ok )
7054
            test_ok ;
7055
    end
7056
    begin
7057
        test_name = "SINGLE MEMORY READ RETRIED FIRST TIME" ;
7058
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
7059
 
7060
        if ( ok !== 1 )
7061
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7062
 
7063
        test_name = "SINGLE MEMORY READ DISCONNECTED WITH FIRST SECOND TIME" ;
7064
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7065
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7066
 
7067
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7068
        if ( ok !== 1 )
7069
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7070
    end
7071
    join
7072
 
7073
    $display("Testing CAB read transaction progress from WB to PCI!") ;
7074
 
7075
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7076
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7077
 
7078
    test_name = "FILL TARGET MEMORY WITH DATA" ;
7079
    // first fill target's memory with enough data to fill WBR_FIFO
7080
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7081
    begin
7082
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7083
        write_data`WRITE_DATA    = wmem_data[i] ;
7084
        write_data`WRITE_SEL     = 4'hF ;
7085
 
7086
        wishbone_master.blk_write_data[i] = write_data ;
7087
    end
7088
 
7089
    write_flags`WB_TRANSFER_CAB = 1 ;
7090
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7091
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7092
 
7093
    wishbone_master.wb_block_write( write_flags, write_status ) ;
7094
 
7095
    if ( write_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH) )
7096
    begin
7097
        $display("Transaction progress testing failed! Time %t ", $time) ;
7098
        $display("Bridge processed CAB write wrong!") ;
7099
        test_fail("bridge didn't process all the writes as it was supposed too") ;
7100
        disable main ;
7101
    end
7102
 
7103
    test_name = "SINGLE READ TO PUSH WRITE DATA FROM FIFO" ;
7104
    // perform single read to force write data to pci
7105
    read_data`READ_ADDRESS = target_address + 8;
7106
    read_data`READ_SEL     = 4'hF ;
7107
 
7108
    wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7109
 
7110
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7111
    begin
7112
        $display("Transaction progress testing failed! Time %t ", $time) ;
7113
        $display("Bridge processed single read wrong!") ;
7114
        test_fail("bridge didn't process single memory read as expected") ;
7115
        disable main ;
7116
    end
7117
 
7118
    wishbone_master.blk_read_data_in[0] = read_data ;
7119
 
7120
    read_data`READ_ADDRESS = target_address + 12 ;
7121
    read_data`READ_SEL     = 4'hF ;
7122
 
7123
    wishbone_master.blk_read_data_in[1] = read_data ;
7124
 
7125
    read_data`READ_ADDRESS = target_address + 16 ;
7126
    read_data`READ_SEL     = 4'hF ;
7127
 
7128
    wishbone_master.blk_read_data_in[2] = read_data ;
7129
 
7130
    write_flags`WB_TRANSFER_CAB  = 1 ;
7131
    write_flags`WB_TRANSFER_SIZE = 2 ;
7132
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7133
    read_status = 0 ;
7134
 
7135
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7136
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 1 ;
7137
 
7138
    test_name = "BURST READ WITH DISCONNECT ON FIRST" ;
7139
 
7140
    ok = 1 ;
7141
    fork
7142
    begin
7143
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7144
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7145
 
7146
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7147
        begin
7148
            $display("Transaction progress testing failed! Time %t ", $time) ;
7149
            $display("Bridge processed CAB read wrong!") ;
7150
            test_fail("bridge didn't process disconnected burst read as expected") ;
7151
        end
7152
        else
7153
        begin
7154
 
7155
            read_status = wishbone_master.blk_read_data_out[0] ;
7156
 
7157
            if (read_status`READ_DATA !== wmem_data[2])
7158
            begin
7159
                display_warning(target_address + 8, wmem_data[2], read_status`READ_DATA) ;
7160
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7161
            end
7162
            else
7163
                test_ok ;
7164
        end
7165
 
7166
        test_name = "BURST READ WITH DISCONNECT AFTER FIRST" ;
7167
        wishbone_master.blk_read_data_in[0] = wishbone_master.blk_read_data_in[1] ;
7168
        wishbone_master.blk_read_data_in[1] = wishbone_master.blk_read_data_in[2] ;
7169
 
7170
        read_status = 0 ;
7171
 
7172
        while ( read_status`CYC_ACTUAL_TRANSFER === 0 )
7173
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7174
 
7175
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7176
        begin
7177
            $display("Transaction progress testing failed! Time %t ", $time) ;
7178
            $display("Bridge processed CAB read wrong!") ;
7179
            test_fail("bridge didn't process disconnected burst read as expected") ;
7180
        end
7181
        else
7182
        begin
7183
 
7184
            read_status = wishbone_master.blk_read_data_out[0] ;
7185
 
7186
            if (read_status`READ_DATA !== wmem_data[3])
7187
            begin
7188
                display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7189
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7190
            end
7191
            else
7192
                test_ok ;
7193
        end
7194
 
7195
        test_name = "BURST READ WITH DISCONNECT ON SECOND - TAKE OUT ONLY ONE" ;
7196
        // complete delayed read which was requested
7197
        read_data = wishbone_master.blk_read_data_in[2] ;
7198
        write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7199
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7200
 
7201
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7202
        begin
7203
            $display("Transaction progress testing failed! Time %t ", $time) ;
7204
            $display("Bridge processed single out of burst read wrong!") ;
7205
            test_fail("bridge didn't process disconnected burst converted to single read as expected") ;
7206
        end
7207
        else
7208
        begin
7209
 
7210
            if (read_status`READ_DATA !== wmem_data[4])
7211
            begin
7212
                display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7213
                test_fail("bridge provided wrong read data on disconnected burst read") ;
7214
            end
7215
            else
7216
                test_ok ;
7217
        end
7218
 
7219
    end
7220
    begin
7221
        pci_transaction_progress_monitor( target_address + 8, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7222
 
7223
        if ( ok !== 1 )
7224
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7225
 
7226
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Retry_Before ;
7227
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7228
 
7229
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7230
        if ( ok !== 1 )
7231
            test_fail("bridge started invalid memory read transaction or none at all behavioral target didn't respond as expected") ;
7232
 
7233
        test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Disc_With ;
7234
        test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 2 ;
7235
 
7236
        pci_transaction_progress_monitor( target_address + 16, `BC_MEM_READ_LN, 2, 0, 1'b1, 1'b0, 0, ok ) ;
7237
        if ( ok !== 1 )
7238
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7239
    end
7240
    join
7241
 
7242
    // now try burst read with normal termination
7243
    read_data`READ_ADDRESS = target_address + 12 ;
7244
    read_data`READ_SEL     = 4'hF ;
7245
 
7246
    wishbone_master.blk_read_data_in[0] = read_data ;
7247
 
7248
    read_data`READ_ADDRESS = target_address + 16 ;
7249
    read_data`READ_SEL     = 4'hF ;
7250
 
7251
    wishbone_master.blk_read_data_in[1] = read_data ;
7252
 
7253
    write_flags`WB_TRANSFER_SIZE = 2 ;
7254
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7255
    write_flags`WB_TRANSFER_CAB = 1 ;
7256
 
7257
    test_name = "BURST READ WITH NORMAL TERMINATION" ;
7258
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7259
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7260
 
7261
    fork
7262
    begin
7263
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7264
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7265
        begin
7266
            $display("Transaction progress testing failed! Time %t ", $time) ;
7267
            $display("Bridge processed CAB read wrong!") ;
7268
            test_fail("bridge didn't process burst read as expected") ;
7269
            ok = 0 ;
7270
        end
7271
    end
7272
    begin
7273
        pci_transaction_progress_monitor( target_address + 12, `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 0, ok ) ;
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
    end
7277
    join
7278
 
7279
    if ( ok )
7280
    begin
7281
        read_status = wishbone_master.blk_read_data_out[0] ;
7282
        if ( read_status`READ_DATA !== wmem_data[3] )
7283
        begin
7284
            display_warning(target_address + 12, wmem_data[3], read_status`READ_DATA) ;
7285
            test_fail("data provided from normaly terminated read was wrong") ;
7286
            ok = 0 ;
7287
        end
7288
 
7289
        read_status = wishbone_master.blk_read_data_out[1] ;
7290
        if ( read_status`READ_DATA !== wmem_data[4] )
7291
        begin
7292
            display_warning(target_address + 16, wmem_data[4], read_status`READ_DATA) ;
7293
            test_fail("data provided from normaly terminated read was wrong") ;
7294
            ok = 0 ;
7295
        end
7296
    end
7297
 
7298
    if ( ok )
7299
        test_ok ;
7300
 
7301
    // disable memory read line command and enable prefetch
7302
    // prepare image control register
7303
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7304
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
7305
    if ( ok !== 1 )
7306
    begin
7307
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7308
        test_fail("WB Image Control register couldn't be written to") ;
7309
        disable main ;
7310
    end
7311
 
7312
    write_flags`WB_TRANSFER_SIZE = 4 ;
7313
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7314
    write_flags`WB_TRANSFER_CAB = 1 ;
7315
 
7316
    test_name = "NORMAL BURST READ WITH NORMAL COMPLETION, MEMORY READ LINE DISABLED, PREFETCH ENABLED, BURST SIZE 4" ;
7317
 
7318
    for ( i = 0 ; i < 4 ; i = i + 1 )
7319
    begin
7320
        read_data`READ_ADDRESS = target_address + i*4 ;
7321
        read_data`READ_SEL     = 4'b1010 ;
7322
 
7323
        wishbone_master.blk_read_data_in[i] = read_data ;
7324
    end
7325
 
7326
    fork
7327
    begin
7328
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7329
        if ( read_status`CYC_ACTUAL_TRANSFER !== 4 )
7330
        begin
7331
            $display("Transaction progress testing failed! Time %t ", $time) ;
7332
            $display("Bridge processed CAB read wrong!") ;
7333
            test_fail("bridge didn't process prefetched burst read as expected") ;
7334
            ok = 0 ;
7335
        end
7336
    end
7337
    begin
7338
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 4, 0, 1'b1, 1'b0, 0, ok ) ;
7339
        if ( ok !== 1 )
7340
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7341
    end
7342
    join
7343
 
7344
    if ( ok )
7345
    begin
7346
        for ( i = 0 ; i < 4 ; i = i + 1 )
7347
        begin
7348
            read_status = wishbone_master.blk_read_data_out[i] ;
7349
            if ( read_status`READ_DATA !== wmem_data[i] )
7350
            begin
7351
                display_warning(target_address + i*4, wmem_data[i], read_status`READ_DATA) ;
7352
                test_fail("burst read returned unexpected data") ;
7353
                ok = 0 ;
7354
            end
7355
        end
7356
    end
7357
 
7358
    if ( ok )
7359
        test_ok ;
7360
 
7361
    // do one single read with different byte enables
7362
    read_data`READ_ADDRESS = target_address + 4 ;
7363
    read_data`READ_SEL     = 4'b1010 ;
7364
 
7365
    test_name = "SINGLE READ WITH FUNNY BYTE ENABLE COMBINATION" ;
7366
    fork
7367
    begin
7368
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
7369
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7370
        begin
7371
            $display("Transaction progress testing failed! Time %t ", $time) ;
7372
            $display("Bridge processed single read wrong!") ;
7373
            test_fail("bridge didn't process single memory read as expected") ;
7374
            ok = 0 ;
7375
        end
7376
    end
7377
    begin
7378
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7379
        if ( ok !== 1 )
7380
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7381
    end
7382
    join
7383
 
7384
    // check read data
7385
    if ( ok )
7386
    begin
7387
        if ( read_status`READ_DATA !== (wmem_data[1] & 32'hFF_00_FF_00) )
7388
        begin
7389
            display_warning(target_address + 4, (wmem_data[1] & 32'hFF_00_FF_00), read_status`READ_DATA) ;
7390
            $display("WB to PCI Transaction progress testing failed! Time %t ", $time) ;
7391
            $display("Possibility of wrong read byte enable passing to PCI is possible!") ;
7392
            ok = 0 ;
7393
            test_fail("unexpected data received from single read") ;
7394
        end
7395
    end
7396
 
7397
    if ( ok )
7398
         test_ok ;
7399
 
7400
    // enable prefetch and mrl - now memory read multiple should be used for reads and whole WBR_FIFO should be filled
7401
    test_name = "RECONFIGURE PCI MASTER/WISHBONE SLAVE" ;
7402
 
7403
    config_write( ctrl_offset, 32'h0000_0003, 4'hF, ok) ;
7404
    if ( ok !== 1 )
7405
    begin
7406
        $display("WB to PCI transacton progress testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
7407
        test_fail("WB Image Control register could not be written") ;
7408
        disable main ;
7409
    end
7410
 
7411
    test_name = "BURST READ WITH NORMAL COMPLETION FILLING FULL FIFO - MRL AND PREFETCH BOTH ENABLED" ;
7412
    for ( i = 0 ; i < `WBR_DEPTH ; i = i + 1 )
7413
    begin
7414
        read_data`READ_ADDRESS = target_address + i*4 ;
7415
        read_data`READ_SEL     = 4'b1111 ;
7416
 
7417
        wishbone_master.blk_read_data_in[i] = read_data ;
7418
    end
7419
 
7420
    write_flags`WB_TRANSFER_SIZE = `WBR_DEPTH ;
7421
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7422
    write_flags`WB_TRANSFER_CAB = 1 ;
7423
 
7424
    fork
7425
    begin
7426
        read_status         = 0 ;
7427
        read_status`CYC_RTY = 1 ;
7428
        while ( (read_status`CYC_ACTUAL_TRANSFER === 0) && (read_status`CYC_RTY === 1) )
7429
            wishbone_master.wb_block_read( write_flags, read_status ) ;
7430
 
7431
        if ( read_status`CYC_ACTUAL_TRANSFER !== (`WBR_DEPTH - 1) )
7432
        begin
7433
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7434
            $display(" WBR_FIFO can accomodate reads of max size %d.", `WBR_DEPTH - 1 ) ;
7435
            $display(" Max size read test failed. Size of read was %d.", read_status`CYC_ACTUAL_TRANSFER) ;
7436
            test_fail("read performed was not as long as it was expected - full WB Read Fifo - 1") ;
7437
            ok = 0 ;
7438
        end
7439
    end
7440
    begin
7441
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, `WBR_DEPTH - 1, 0, 1'b1, 1'b0, 0, ok ) ;
7442
        if ( ok !== 1 )
7443
            test_fail("bridge started invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7444
    end
7445
    join
7446
 
7447
    // now repeat single read to flush redundant read initiated
7448
    write_flags`WB_TRANSFER_SIZE = 1 ;
7449
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7450
    write_flags`WB_TRANSFER_CAB = 1 ;
7451
 
7452
    read_data`READ_ADDRESS = target_address + (`WBR_DEPTH - 1) * 4 ;
7453
    read_data`READ_SEL     = 4'hF ;
7454
 
7455
    wishbone_master.blk_read_data_in[0] = read_data ;
7456
 
7457
    test_name = "SINGLE CAB READ FOR FLUSHING STALE READ DATA FROM FIFO" ;
7458
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7459
 
7460
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7461
    begin
7462
        $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7463
        $display(" PCI bridge failed to process single CAB read!") ;
7464
        test_fail("single CAB write was not processed as expected") ;
7465
    end
7466
 
7467
    // because last read could be very long on PCI - delete target abort status
7468
    config_write( pci_ctrl_offset, 32'h1000_0000, 4'b1000, ok ) ;
7469
 
7470
    // write unsupported value to cache line size register
7471
    config_write( lat_tim_cls_offset, 32'h0000_04_05, 4'b0011, ok ) ;
7472
 
7473
    read_data`READ_ADDRESS = target_address ;
7474
    read_data`READ_SEL     = 4'hF ;
7475
    wishbone_master.blk_read_data_in[0] = read_data ;
7476
 
7477
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS INVALID" ;
7478
    // perform a read
7479
    fork
7480
    begin
7481
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7482
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7483
        begin
7484
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7485
            $display(" PCI bridge failed to process single CAB read!") ;
7486
            test_fail("burst read was not processed as expected") ;
7487
            ok = 0 ;
7488
        end
7489
    end
7490
    begin
7491
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7492
        if ( ok !== 1 )
7493
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7494
    end
7495
    join
7496
 
7497
    if ( ok )
7498
        test_ok ;
7499
 
7500
    // write 2 to cache line size register
7501
    config_write( lat_tim_cls_offset, 32'h0000_04_02, 4'b0011, ok ) ;
7502
 
7503
    // perform a read
7504
    fork
7505
    begin
7506
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7507
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7508
        begin
7509
            $display(" WB to PCI transacton progress testing failed! Time %t ", $time) ;
7510
            $display(" PCI bridge failed to process single CAB read!") ;
7511
            test_fail("burst read was not processed as expected") ;
7512
            ok = 0 ;
7513
        end
7514
    end
7515
    begin
7516
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 0, ok ) ;
7517
        if ( ok !== 1 )
7518
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7519
    end
7520
    join
7521
 
7522
    if ( ok )
7523
        test_ok ;
7524
 
7525
    // write 0 to cache line size
7526
    config_write( lat_tim_cls_offset, 32'h0000_04_00, 4'b0011, ok ) ;
7527
    test_name = "WB BURST READ WHEN CACHE LINE SIZE VALUE IS ZERO" ;
7528
 
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 normal value to cls register
7552
    config_write( lat_tim_cls_offset, 32'h0000_02_04, 4'b0011, ok ) ;
7553
 
7554
    $display("Testing Master's latency timer operation!") ;
7555
    $display("Testing Latency timer during Master Writes!") ;
7556
 
7557
    for ( i = 0 ; i < 6 ; i = i + 1 )
7558
    begin
7559
        write_data`WRITE_ADDRESS = target_address + i*4 ;
7560
        write_data`WRITE_SEL     = 4'b1111 ;
7561
        write_data`WRITE_DATA    = wmem_data[1023 - i] ;
7562
 
7563
        wishbone_master.blk_write_data[i] = write_data ;
7564
    end
7565
 
7566
    write_flags`WB_TRANSFER_SIZE = 6 ;
7567
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
7568
    write_flags`WB_TRANSFER_CAB = 1 ;
7569
 
7570
    // start wb write, pci write and monitor in parallel
7571
    test_name = "LATENCY TIMER OPERATION ON PCI MASTER WRITE" ;
7572
    fork
7573
    begin
7574
        wishbone_master.wb_block_write( write_flags, write_status ) ;
7575
        if ( write_status`CYC_ACTUAL_TRANSFER !== 6 )
7576
        begin
7577
            $display("Transaction progress testing failed! Time %t ", $time) ;
7578
            $display("Bridge failed to process CAB write!") ;
7579
            test_fail("bridge didn't post whole burst memory write") ;
7580
            disable main ;
7581
        end
7582
    end
7583
    begin
7584
        // wait for bridge's master to start transaction
7585
        @(posedge pci_clock) ;
7586
        while ( FRAME === 1 )
7587
            @(posedge pci_clock) ;
7588
 
7589
        // start behavioral master request
7590
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7591
               target_address, wmem_data[1023], `Test_All_Bytes,
7592
               1, 8'h2_0, `Test_One_Zero_Target_WS,
7593
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7594
 
7595
        do_pause ( 1 ) ;
7596
    end
7597
    begin
7598
        pci_transaction_progress_monitor( target_address, `BC_MEM_WRITE, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7599
        if ( ok !== 1 )
7600
            test_fail("bridge didn't finish the burst write transaction after latency timer has expired") ;
7601
        else
7602
            test_ok ;
7603
    end
7604
    join
7605
 
7606
    // perform a read to check data
7607
    for ( i = 0 ; i < 6 ; i = i + 1 )
7608
    begin
7609
        read_data`READ_ADDRESS = target_address + i*4 ;
7610
        read_data`READ_SEL     = 4'b1111 ;
7611
 
7612
        wishbone_master.blk_read_data_in[i] = read_data ;
7613
    end
7614
 
7615
    write_flags`WB_TRANSFER_SIZE = 6 ;
7616
    write_flags`WB_TRANSFER_AUTO_RTY = 1 ;
7617
    write_flags`WB_TRANSFER_CAB = 1 ;
7618
 
7619
    test_name = "BURST WRITE DATA DISCONNECTED BY LATENCY TIMEOUT" ;
7620
    wishbone_master.wb_block_read( write_flags, read_status ) ;
7621
 
7622
    if ( read_status`CYC_ACTUAL_TRANSFER !== 6 )
7623
    begin
7624
        $display("Transaction progress testing failed! Time %t ", $time) ;
7625
        $display("Bridge failed to process CAB read!") ;
7626
        test_fail("whole burst data not read by bridge - CAB read processed wrong") ;
7627
        disable main ;
7628
    end
7629
 
7630
    ok = 1 ;
7631
    for ( i = 0 ; i < 6 ; i = i + 1 )
7632
    begin
7633
        read_status = wishbone_master.blk_read_data_out[i] ;
7634
 
7635
        if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7636
        begin
7637
            $display("Latency timer operation testing failed! Time %t ", $time) ;
7638
            display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7639
            test_fail("unexpected data read back from PCI") ;
7640
            ok = 0 ;
7641
        end
7642
    end
7643
 
7644
    if ( ok )
7645
        test_ok ;
7646
 
7647
    $display("Testing Latency timer during Master Reads!") ;
7648
 
7649
    // at least 2 words are transfered during Master Reads terminated with timeout
7650
    write_flags`WB_TRANSFER_SIZE = 2 ;
7651
    test_name = "LATENCY TIMER OPERATION DURING MASTER READ" ;
7652
    fork
7653
    begin
7654
        wishbone_master.wb_block_read( write_flags, read_status ) ;
7655
        if ( read_status`CYC_ACTUAL_TRANSFER !== 2 )
7656
        begin
7657
            $display("Transaction progress testing failed! Time %t ", $time) ;
7658
            $display("Bridge failed to process CAB read!") ;
7659
            test_fail("bridge didn't process burst read as expected") ;
7660
            ok = 0 ;
7661
        end
7662
    end
7663
    begin
7664
        // wait for bridge's master to start transaction
7665
        @(posedge pci_clock) ;
7666
        while ( FRAME === 1 )
7667
            @(posedge pci_clock) ;
7668
 
7669
        // start behavioral master request
7670
        PCIU_MEM_WRITE("MEM_WRITE  ", `Test_Master_1,
7671
               target_address, wmem_data[0], `Test_All_Bytes,
7672
               1, 8'h3_0, `Test_One_Zero_Target_WS,
7673
               `Test_Devsel_Medium, `Test_Target_Normal_Completion);
7674
 
7675
        do_pause ( 1 ) ;
7676
    end
7677
    begin
7678
        pci_transaction_progress_monitor( target_address, `BC_MEM_READ_MUL, 0, 2, 1'b0, 1'b1, 0, ok ) ;
7679
        if ( ok !== 1 )
7680
            test_fail("bridge did invalid memory read transaction or none at all or behavioral target didn't respond as expected") ;
7681
    end
7682
    join
7683
 
7684
    // check data provided by target
7685
    if ( ok )
7686
    begin
7687
        for ( i = 0 ; i < 2 ; i = i + 1 )
7688
        begin
7689
            read_status = wishbone_master.blk_read_data_out[i] ;
7690
 
7691
            if ( read_status`READ_DATA !== wmem_data[1023 - i] )
7692
            begin
7693
                $display("Latency timer operation testing failed! Time %t ", $time) ;
7694
                display_warning(target_address + i*4, wmem_data[1023 - i], read_status`READ_DATA) ;
7695
                test_fail("burst read interrupted by Latency Timeout didn't return expected data") ;
7696
                ok = 0 ;
7697
            end
7698
        end
7699
    end
7700
    if ( ok )
7701
        test_ok ;
7702
 
7703
    test_name = "DISABLE_IMAGE" ;
7704
    config_write( am_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
7705
    if ( ok !== 1 )
7706
    begin
7707
        $display("WB to PCI transacton progress testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
7708
        test_fail("write to WB Address Mask register failed") ;
7709
        disable main ;
7710
    end
7711
 
7712
end
7713
endtask //wb_to_pci_transactions
7714
 
7715
task iack_cycle ;
7716
    reg `READ_STIM_TYPE   read_data ;
7717
    reg `READ_RETURN_TYPE read_status ;
7718
    reg `WB_TRANSFER_FLAGS flags ;
7719
 
7720
    reg [31:0] temp_var ;
7721
    reg ok ;
7722 45 mihad
    reg ok_wb ;
7723
    reg ok_pci ;
7724
 
7725
    reg [31:0] irq_vector ;
7726 15 mihad
begin
7727
 
7728 45 mihad
    ok     = 1 ;
7729
    ok_wb  = 1 ;
7730
    ok_pci = 1 ;
7731
 
7732 15 mihad
    $display(" Testing Interrupt Acknowledge cycle generation!") ;
7733
 
7734
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
7735
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
7736
 
7737
    read_data`READ_ADDRESS = temp_var + { 4'h1, `INT_ACK_ADDR, 2'b00 } ;
7738
    read_data`READ_SEL     = 4'hF ;
7739
 
7740
    flags = 0 ;
7741
 
7742
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
7743
 
7744
    irq_vector  = 32'hAAAA_AAAA ;
7745
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH MASTER ABORT" ;
7746
 
7747 45 mihad
    // disable both pci blue behavioral targets
7748
    configuration_cycle_write
7749
    (
7750
        0,                          // bus number [7:0]
7751
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7752
        0,                          // function number [2:0]
7753
        1,                          // register number [5:0]
7754
        0,                          // type [1:0]
7755
        4'h1,                       // byte enables [3:0]
7756
        32'h0000_0044               // data to write [31:0]
7757
    ) ;
7758
 
7759
    configuration_cycle_write
7760
    (
7761
        0,                          // bus number [7:0]
7762
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7763
        0,                          // function number [2:0]
7764
        1,                          // register number [5:0]
7765
        0,                          // type [1:0]
7766
        4'h1,                       // byte enables [3:0]
7767
        32'h0000_0044               // data to write [31:0]
7768
    ) ;
7769
 
7770 15 mihad
    fork
7771
    begin
7772
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7773
    end
7774
    begin
7775 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7776
        if ( ok_pci !== 1 )
7777 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7778
    end
7779
    join
7780
 
7781
    if ( read_status`CYC_ACTUAL_TRANSFER !== 0 || read_status`CYC_ERR !== 1 )
7782
    begin
7783 45 mihad
        ok_wb = 0 ;
7784 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7785
        $display(" It should be terminated by master abort on PCI and therefore by error on WISHBONE bus!") ;
7786
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7787
    end
7788 45 mihad
 
7789
    if ( ok_pci && ok_wb )
7790 15 mihad
        test_ok ;
7791 45 mihad
 
7792
    ok_wb = 1 ;
7793
    ok_pci = 1 ;
7794
    ok = 1 ;
7795 15 mihad
 
7796 45 mihad
    irq_vector  = 32'hAAAA_AAAA ;
7797
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7798 15 mihad
 
7799
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION" ;
7800 45 mihad
    // enable pci blue behavioral target 1
7801
    configuration_cycle_write
7802
    (
7803
        0,                          // bus number [7:0]
7804
        `TAR1_IDSEL_INDEX - 11,     // device number [4:0]
7805
        0,                          // function number [2:0]
7806
        1,                          // register number [5:0]
7807
        0,                          // type [1:0]
7808
        4'h1,                       // byte enables [3:0]
7809
        32'h0000_0047               // data to write [31:0]
7810
    ) ;
7811 15 mihad
    fork
7812
    begin
7813
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7814
    end
7815
    begin
7816 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7817
        if ( ok_pci !== 1 )
7818 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7819
    end
7820
    join
7821
 
7822
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7823
    begin
7824 45 mihad
        ok_wb = 0 ;
7825 15 mihad
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7826
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7827
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7828
    end
7829
 
7830
    if ( read_status`READ_DATA !== irq_vector )
7831
    begin
7832
        $display(" Time %t ", $time ) ;
7833
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", irq_vector, read_status`READ_DATA ) ;
7834
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7835 45 mihad
        ok_wb = 0 ;
7836 15 mihad
    end
7837
 
7838 45 mihad
    if ( ok_pci && ok_wb )
7839 15 mihad
        test_ok ;
7840
 
7841 45 mihad
    ok_pci = 1 ;
7842
    ok_wb  = 1 ;
7843
    ok     = 1 ;
7844
 
7845 15 mihad
    read_data`READ_SEL = 4'b0101 ;
7846 45 mihad
    irq_vector  = 32'h5555_5555 ;
7847
    pci_behaviorial_device1.pci_behaviorial_target.Test_Device_Mem[0] = irq_vector ;
7848
 
7849 15 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH NORMAL COMPLETION AND FUNNY BYTE ENABLES" ;
7850
    fork
7851
    begin
7852
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7853
    end
7854
    begin
7855 45 mihad
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 1, 0, 1'b1, 1'b0, 0, ok_pci) ;
7856
        if ( ok_pci !== 1 )
7857 15 mihad
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7858
    end
7859
    join
7860
 
7861
    if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
7862
    begin
7863
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7864
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7865
        test_fail("bridge didn't handle Interrupt Acknowledge cycle as expected") ;
7866 45 mihad
        ok_wb = 0 ;
7867 15 mihad
    end
7868
 
7869 45 mihad
    if ( read_status`READ_DATA !== 32'h0055_0055 )
7870 15 mihad
    begin
7871
        $display(" Time %t ", $time ) ;
7872 45 mihad
        $display(" Expected interrupt acknowledge vector was %h, actualy read value was %h ! ", 32'h0055_0055, read_status`READ_DATA ) ;
7873 15 mihad
        test_fail("Interrupt Acknowledge returned unexpected data") ;
7874 45 mihad
        ok_wb = 0 ;
7875 15 mihad
    end
7876
 
7877 45 mihad
    if (ok_pci && ok_wb)
7878 15 mihad
        test_ok ;
7879
 
7880 45 mihad
    ok_pci = 1 ;
7881
    ok_wb  = 1 ;
7882
    ok     = 1 ;
7883 15 mihad
 
7884 45 mihad
    test_name = "INTERRUPT ACKNOWLEDGE CYCLE GENERATION WITH TARGET ABORT" ;
7885
 
7886
    // set target to terminate with target abort
7887
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
7888
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
7889
 
7890
    fork
7891
    begin
7892
        wishbone_master.wb_single_read( read_data, flags, read_status ) ;
7893
    end
7894
    begin
7895
        pci_transaction_progress_monitor( 32'h0000_0000, `BC_IACK, 0, 0, 1'b1, 1'b0, 0, ok_pci) ;
7896
        if ( ok_pci !== 1 )
7897
           test_fail("bridge did invalid Interrupt Acknowledge read transaction or none at all or behavioral target didn't respond as expected") ;
7898
    end
7899
    join
7900
 
7901
    if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
7902
    begin
7903
        $display(" Interrupt acknowledge cycle generation failed! Time %t ", $time ) ;
7904
        $display(" Bridge failed to process Interrupt Acknowledge cycle!") ;
7905
        test_fail("Interrupt Acknowledge Cycle terminated with Target Abort on PCI was not terminated with ERR on WISHBONE") ;
7906
        ok_wb = 0 ;
7907
    end
7908
 
7909
    // set target to terminate with target abort
7910
    test_target_response[`TARGET_ENCODED_TERMINATION]  = `Test_Target_Normal_Completion ;
7911
    test_target_response[`TARGET_ENCODED_TERMINATE_ON] = 0 ;
7912
 
7913
    // enable pci blue behavioral target 2
7914
    configuration_cycle_write
7915
    (
7916
        0,                          // bus number [7:0]
7917
        `TAR2_IDSEL_INDEX - 11,     // device number [4:0]
7918
        0,                          // function number [2:0]
7919
        1,                          // register number [5:0]
7920
        0,                          // type [1:0]
7921
        4'h1,                       // byte enables [3:0]
7922
        32'h0000_0047               // data to write [31:0]
7923
    ) ;
7924
 
7925
    // read PCI Device status
7926
    config_read(12'h4, 4'hC, temp_var) ;
7927
    if (temp_var[29] !== 1)
7928
    begin
7929
        $display("Time %t", $time) ;
7930
        $display("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort!") ;
7931
        test_fail("Received Master Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Master Abort") ;
7932
        ok_wb = 0 ;
7933
    end
7934
 
7935
    if (temp_var[28] !== 1)
7936
    begin
7937
        $display("Time %t", $time) ;
7938
        $display("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort!") ;
7939
        test_fail("Received Target Abort bit in PCI Device Status register was not set after Interrupt Acknowledge Cycle was terminated with Target Abort") ;
7940
        ok_wb = 0 ;
7941
    end
7942
 
7943
    // clearing the status bits
7944
        config_write(12'h4, temp_var, 4'hC, ok);
7945
 
7946
    if ( ok && ok_pci && ok_wb )
7947
        test_ok ;
7948
 
7949 15 mihad
end
7950
endtask //iack_cycle
7951
 
7952
task transaction_ordering ;
7953
    reg   [11:0] wb_ctrl_offset ;
7954
    reg   [11:0] wb_ba_offset ;
7955
    reg   [11:0] wb_am_offset ;
7956
    reg   [11:0] pci_ctrl_offset ;
7957
    reg   [11:0] pci_ba_offset ;
7958
    reg   [11:0] pci_am_offset ;
7959
    reg   [11:0] pci_device_ctrl_offset ;
7960
    reg   [11:0] wb_err_cs_offset ;
7961
    reg   [11:0] pci_err_cs_offset ;
7962
    reg   [11:0] icr_offset ;
7963
    reg   [11:0] isr_offset ;
7964
    reg   [11:0] lat_tim_cls_offset ;
7965
 
7966
    reg `WRITE_STIM_TYPE  write_data ;
7967
    reg `READ_STIM_TYPE   read_data ;
7968
    reg `READ_RETURN_TYPE read_status ;
7969
 
7970
    reg `WRITE_RETURN_TYPE write_status ;
7971
    reg `WB_TRANSFER_FLAGS write_flags ;
7972
    reg [31:0] temp_val1 ;
7973
    reg [31:0] temp_val2 ;
7974
    reg        ok   ;
7975
 
7976
    reg [31:0] wb_image_base ;
7977
    reg [31:0] wb_target_address ;
7978
    reg [31:0] pci_image_base ;
7979
    integer i ;
7980
 
7981
    reg     error_monitor_done ;
7982
begin:main
7983
    write_flags`INIT_WAITS = tb_init_waits ;
7984
    write_flags`SUBSEQ_WAITS = tb_subseq_waits ;
7985
 
7986
    wb_ctrl_offset        = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
7987
    wb_ba_offset          = {4'h1, `W_BA1_ADDR, 2'b00} ;
7988
    wb_am_offset          = {4'h1, `W_AM1_ADDR, 2'b00} ;
7989
    wb_err_cs_offset      = {4'h1, `W_ERR_CS_ADDR, 2'b00} ;
7990
 
7991
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
7992
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
7993
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
7994
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
7995
 
7996
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
7997
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
7998
    lat_tim_cls_offset = 12'hC ;
7999
    pci_device_ctrl_offset    = 12'h4 ;
8000
 
8001
    wb_target_address  = `BEH_TAR1_MEM_START ;
8002
    wb_image_base      = 0 ;
8003
    wb_image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = wb_target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
8004
 
8005
    wb_target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = wb_image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
8006
    wb_target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = wb_image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
8007
    write_flags                    = 0 ;
8008
    write_flags`INIT_WAITS         = 0 ;
8009
    write_flags`SUBSEQ_WAITS       = 0 ;
8010
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8011
 
8012
    pci_image_base = Target_Base_Addr_R[1] ;
8013
 
8014
    // enable master & target operation
8015
    test_name = "BRIDGE CONFIGURATION FOR TRANSACTION ORDERING TESTS" ;
8016
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
8017
    if ( ok !== 1 )
8018
    begin
8019
        $display("Transacton ordering testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
8020
        test_fail("write to PCI Device Control register failed") ;
8021
        disable main ;
8022
    end
8023
 
8024
    // prepare image control register
8025
    config_write( wb_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8026
    if ( ok !== 1 )
8027
    begin
8028
        $display("Transacton ordering testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
8029
        test_fail("write to WB Image Control register failed") ;
8030
        disable main ;
8031
    end
8032
 
8033
    // prepare base address register
8034
    config_write( wb_ba_offset, wb_image_base, 4'hF, ok ) ;
8035
    if ( ok !== 1 )
8036
    begin
8037
        $display("Transacton ordering testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
8038
        test_fail("write to WB Base Address register failed") ;
8039
        disable main ;
8040
    end
8041
 
8042
    // write address mask register
8043
    config_write( wb_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8044
    if ( ok !== 1 )
8045
    begin
8046
        $display("Transacton ordering testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
8047
        test_fail("write to WB Address Mask register failed") ;
8048
        disable main ;
8049
    end
8050
 
8051
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8052
    config_write( wb_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8053
    if ( ok !== 1 )
8054
    begin
8055
        $display("Transacton ordering testing failed! Failed to write W_ERR_CS register! Time %t ", $time) ;
8056
        test_fail("write to WB Error Control and Status register failed") ;
8057
        disable main ;
8058
    end
8059
 
8060
    // prepare image control register
8061
    config_write( pci_ctrl_offset, 32'h0000_0001, 4'hF, ok) ;
8062
    if ( ok !== 1 )
8063
    begin
8064
        $display("Transacton ordering testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
8065
        test_fail("write to PCI Image Control register failed") ;
8066
        disable main ;
8067
    end
8068
 
8069
    // prepare base address register
8070
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
8071
    if ( ok !== 1 )
8072
    begin
8073
        $display("Transacton ordering testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
8074
        test_fail("write to PCI Base Address register failed") ;
8075
        disable main ;
8076
    end
8077
 
8078
    // write address mask register
8079
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8080
    if ( ok !== 1 )
8081
    begin
8082
        $display("Transacton ordering testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
8083
        test_fail("write to PCI Address Mask register failed") ;
8084
        disable main ;
8085
    end
8086
 
8087
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
8088
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
8089
    if ( ok !== 1 )
8090
    begin
8091
        $display("Transacton ordering testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
8092
        test_fail("write to PCI Error Control and Status register failed") ;
8093
        disable main ;
8094
    end
8095
 
8096
    // carefull - first value here is 7, because bit 31 of ICR is software reset!
8097
    config_write( icr_offset, 32'h7FFF_FFFF, 4'hF, ok ) ;
8098
    if ( ok !== 1 )
8099
    begin
8100
        $display("Transacton ordering testing failed! Failed to write IC register! Time %t ", $time) ;
8101
        test_fail("write to Interrupt Control register failed") ;
8102
        disable main ;
8103
    end
8104
 
8105
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
8106
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
8107
    if ( ok !== 1 )
8108
    begin
8109
        $display("Transacton ordering testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
8110
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
8111
        disable main ;
8112
    end
8113
 
8114
    test_name = "SIMULTANEOUS WRITE REFERENCE TO WB SLAVE AND PCI TARGET" ;
8115
 
8116
    // prepare wb_master write and read data
8117
    for ( i = 0 ; i < 4 ; i = i + 1 )
8118
    begin
8119
        write_data`WRITE_ADDRESS = wb_target_address + i*4 ;
8120
        write_data`WRITE_DATA    = wmem_data[500 + i] ;
8121
        write_data`WRITE_SEL     = 4'hF ;
8122
 
8123
        read_data`READ_ADDRESS   = write_data`WRITE_ADDRESS ;
8124
        read_data`READ_SEL       = write_data`WRITE_SEL ;
8125
 
8126
        wishbone_master.blk_write_data[i]   = write_data ;
8127
        wishbone_master.blk_read_data_in[i] = read_data ;
8128
    end
8129
 
8130
    // put wishbone slave in acknowledge and pci target in retry mode
8131
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8132
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8133
 
8134
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8135
 
8136
    fork
8137
    begin
8138
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8139
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8140
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8141
        begin
8142
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8143
            test_fail("Bridge didn't post single memory write as expected") ;
8144
        end
8145
 
8146
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8147
        if ( ok !== 1 )
8148
        begin
8149
            $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) ;
8150
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8151
            ok = 0 ;
8152
        end
8153
 
8154
        // now post single write to target - normal progress
8155
        if ( target_mem_image == 1 )
8156
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8157
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8158
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8159
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8160
        else
8161
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8162
 
8163
        do_pause( 1 ) ;
8164
 
8165
    end
8166
    begin:error_monitor_1
8167 35 mihad
        error_monitor_done = 0 ;
8168 15 mihad
        @(error_event_int) ;
8169
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8170
        ok = 0 ;
8171 35 mihad
        error_monitor_done = 1 ;
8172 15 mihad
    end
8173
    begin
8174
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8175
        if ( ok !== 1 )
8176
        begin
8177
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8178
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8179
        end
8180
        else
8181
        begin
8182 26 mihad
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8183
//            while ( FRAME === 0 || IRDY === 0 )
8184
//                @(posedge pci_clock) ;
8185 15 mihad
 
8186
            // enable response in PCI target
8187
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8188
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8189
 
8190
            pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8191
            if ( ok !== 1 )
8192
            begin
8193
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8194
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8195
            end
8196
        end
8197
 
8198 35 mihad
        #1 ;
8199
        if ( !error_monitor_done )
8200
            disable error_monitor_1 ;
8201 15 mihad
    end
8202
    join
8203
 
8204
    if ( ok )
8205
        test_ok ;
8206
 
8207
    test_name = "SIMULTANEOUS WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8208
 
8209
    // put WISHBONE slave in retry mode
8210
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8211
 
8212
    fork
8213
    begin
8214
        // now post single write to target - normal progress
8215
        if ( target_mem_image == 1 )
8216
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8217
                        pci_image_base + 12, 32'h5555_5555, 4'h0,
8218
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8219
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8220
        else
8221
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8222
 
8223
        do_pause( 1 ) ;
8224
 
8225
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8226
        if ( ok !== 1 )
8227
        begin
8228
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8229
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8230
        end
8231
 
8232
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8233
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8234
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8235
        begin
8236
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8237
            test_fail("Bridge didn't post single memory write as expected") ;
8238
        end
8239
 
8240
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8241
        if ( ok !== 1 )
8242
        begin
8243
            $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) ;
8244
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8245
            ok = 0 ;
8246
        end
8247
 
8248
        wait ( CYC_O === 0 ) ;
8249
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8250
 
8251
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8252
        if ( ok !== 1 )
8253
        begin
8254
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8255
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8256
        end
8257
 
8258 35 mihad
        #1 ;
8259
        if ( !error_monitor_done )
8260
            disable error_monitor_2 ;
8261 15 mihad
    end
8262
    begin:error_monitor_2
8263 35 mihad
        error_monitor_done = 0 ;
8264 15 mihad
        @(error_event_int) ;
8265
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8266
        ok = 0 ;
8267 35 mihad
        error_monitor_done = 1 ;
8268 15 mihad
    end
8269
    join
8270
 
8271
    test_name = "SIMULTANEOUS MULTI BEAT WRITES THROUGH WB SLAVE AND PCI TARGET" ;
8272
 
8273
    // put wishbone slave in acknowledge and pci target in retry mode
8274
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8275
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8276
 
8277
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8278
 
8279
    fork
8280
    begin
8281
        write_flags`WB_TRANSFER_SIZE = 3 ;
8282
        write_flags`WB_TRANSFER_CAB  = 1 ;
8283
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8284
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8285
        if ( write_status`CYC_ACTUAL_TRANSFER !== 3 )
8286
        begin
8287
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8288
            test_fail("Bridge didn't post burst memory write as expected") ;
8289
        end
8290
 
8291
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 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
        // now post single write to target - normal progress
8300
        if ( target_mem_image == 1 )
8301
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8302
                        pci_image_base, 32'h5555_5555, 4'h0,
8303
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8304
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8305
        else
8306
        begin
8307
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8308
            do_pause( 1 ) ;
8309
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8310
        end
8311
 
8312
        do_pause( 1 ) ;
8313
 
8314
    end
8315
    begin:error_monitor_3
8316 35 mihad
        error_monitor_done = 0 ;
8317 15 mihad
        @(error_event_int) ;
8318
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8319
        ok = 0 ;
8320 35 mihad
        error_monitor_done = 1 ;
8321 15 mihad
    end
8322
    begin
8323
        if ( target_mem_image == 1 )
8324
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8325
        else
8326
        begin
8327
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8328
            if ( ok )
8329
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8330
        end
8331
 
8332
        if ( ok !== 1 )
8333
        begin
8334
            $display("Transaction ordering test failed! WB Master didn't start expected transaction on WB bus! Time %t ", $time) ;
8335
            test_fail("WB Master didn't start expected transaction on WB bus") ;
8336
        end
8337
        else
8338
        begin
8339 26 mihad
                pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8340
//            while ( FRAME === 0 || IRDY === 0 )
8341
//                @(posedge pci_clock) ;
8342 15 mihad
 
8343
            // enable response in PCI target
8344
            test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8345
            test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8346
 
8347
            pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 3, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8348
            if ( ok !== 1 )
8349
            begin
8350
                $display("Transaction ordering test failed! PCI Master didn't start expected transaction on PCI bus! Time %t ", $time) ;
8351
                test_fail("PCI Master didn't perform expected transaction on PCI bus") ;
8352
            end
8353
        end
8354
 
8355 35 mihad
        #1 ;
8356
        if ( !error_monitor_done )
8357
            disable error_monitor_3 ;
8358 15 mihad
    end
8359
    join
8360
 
8361
    if ( ok )
8362
        test_ok ;
8363
 
8364
    test_name = "SIMULTANEOUS MULTI BEAT WRITE REFERENCE TO PCI TARGET AND WB SLAVE" ;
8365
 
8366
    // put WISHBONE slave in retry mode
8367
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8368
 
8369
    fork
8370
    begin
8371
        // now post single write to target - normal progress
8372
        if ( target_mem_image == 1 )
8373
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8374
                        pci_image_base, 32'h5555_5555, 4'h0,
8375
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8376
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8377
        else
8378
        begin
8379
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Normal_Completion) ;
8380
            do_pause( 1 ) ;
8381
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 4, 32'h6666_6666, 4'h0, 1, `Test_Target_Normal_Completion) ;
8382
        end
8383
 
8384
        do_pause( 1 ) ;
8385
 
8386
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok ) ;
8387
 
8388
        if ( ok !== 1 )
8389
        begin
8390
            $display("Transaction ordering test failed! WB Master didn't perform expected transaction on WB bus! Time %t ", $time) ;
8391
            test_fail("WB Master didn't perform expected transaction on WB bus") ;
8392
        end
8393
 
8394
        write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
8395
        write_flags`WB_TRANSFER_SIZE     = 4 ;
8396
        write_flags`WB_TRANSFER_CAB      = 1 ;
8397
 
8398
        wishbone_master.wb_block_write( write_flags, write_status ) ;
8399
        if ( write_status`CYC_ACTUAL_TRANSFER !== 4 )
8400
        begin
8401
            $display("Transaction ordering test failed! Bridge failed to post burst memory write! Time %t ", $time) ;
8402
            test_fail("Bridge didn't post burst memory write as expected") ;
8403
        end
8404
 
8405
        pci_transaction_progress_monitor( wb_target_address, `BC_MEM_WRITE, 4, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8406
        if ( ok !== 1 )
8407
        begin
8408
            $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) ;
8409
            test_fail("PCI Master failed to start valid transaction on PCI bus after burst memory write was posted") ;
8410
            ok = 0 ;
8411
        end
8412
 
8413
        @(posedge wb_clock) ;
8414
        while ( CYC_O === 1 )
8415
            @(posedge wb_clock) ;
8416
 
8417
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8418
 
8419
        if ( target_mem_image == 1 )
8420
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok ) ;
8421
        else
8422
        begin
8423
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8424
            if ( ok )
8425
                wb_transaction_progress_monitor( pci_image_base + 4, 1'b1, 1, 1'b1, ok ) ;
8426
        end
8427
 
8428 35 mihad
        #1 ;
8429
        if ( !error_monitor_done )
8430
            disable error_monitor_4 ;
8431 15 mihad
    end
8432
    begin:error_monitor_4
8433 35 mihad
        error_monitor_done = 0 ;
8434 15 mihad
        @(error_event_int) ;
8435
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8436
        ok = 0 ;
8437 35 mihad
        error_monitor_done = 1 ;
8438 15 mihad
    end
8439
    join
8440
 
8441
    if ( ok )
8442
        test_ok ;
8443
 
8444
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH WB SLAVE, READ THROUGH PCI TARGET" ;
8445
 
8446
    // put wishbone slave in acknowledge and pci target in retry mode
8447
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Retry_Before ;
8448
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8449
 
8450
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8451
 
8452
    master1_check_received_data = 1 ;
8453
 
8454
    error_monitor_done = 0 ;
8455
    fork
8456
    begin:error_monitor_5
8457
        @(error_event_int or error_monitor_done) ;
8458
        if ( !error_monitor_done )
8459
        begin
8460
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8461
            ok = 0 ;
8462
        end
8463
    end
8464
    begin
8465
 
8466
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8467
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8468
        begin
8469
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8470
            test_fail("Bridge didn't post single memory write as expected") ;
8471
        end
8472
 
8473
        pci_transaction_progress_monitor( wb_target_address + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8474
        if ( ok !== 1 )
8475
        begin
8476
            $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) ;
8477
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8478
            ok = 0 ;
8479
        end
8480
 
8481
        // start Read Through pci target
8482
        if ( target_mem_image == 1 )
8483
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8484
                          pci_image_base, 32'h5555_5555,
8485
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8486
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8487
        else
8488
            PCIU_IO_READ
8489
             (
8490
                `Test_Master_1,
8491
                pci_image_base,
8492
                32'h5555_5555,
8493
                4'h0,
8494
                1,
8495
                `Test_Target_Retry_On
8496
             );
8497
 
8498
         do_pause( 1 ) ;
8499
 
8500
         wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok ) ;
8501
         if ( ok !== 1 )
8502
         begin
8503
            $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) ;
8504
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8505
         end
8506
 
8507
         // repeat the read 4 times - it should be retried all the time by pci target
8508
        for ( i = 0 ; i < 4 ; i = i + 1 )
8509
        begin
8510
            if ( target_mem_image == 1 )
8511
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8512
                            pci_image_base, 32'h5555_5555,
8513
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8514
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8515
            else
8516
                PCIU_IO_READ
8517
                (
8518
                    `Test_Master_1,
8519
                    pci_image_base,
8520
                    32'h5555_5555,
8521
                    4'h0,
8522
                    1,
8523
                    `Test_Target_Retry_On
8524
                );
8525
 
8526
            do_pause( 1 ) ;
8527
        end
8528
 
8529
        // now do posted write through target - it must go through OK
8530
        if ( target_mem_image == 1 )
8531
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8532
                        pci_image_base, 32'hAAAA_AAAA, 4'h0,
8533
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8534
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8535
        else
8536
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8537
 
8538
        do_pause( 1 ) ;
8539
 
8540
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok ) ;
8541
        if ( ok !== 1 )
8542
        begin
8543
           $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) ;
8544
           test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8545
        end
8546
 
8547
        // start a read through wb_slave
8548
        wishbone_master.wb_single_read(read_data, write_flags, read_status) ;
8549
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0 ) || (read_status`CYC_RTY !== 1))
8550
        begin
8551
            $display("Transaction ordering test failed! WB Slave didn't respond with retry on delayed read request! Time %t ", $time) ;
8552
            test_fail("WB Slave didn't respond as expected to delayed read request") ;
8553
            ok = 0 ;
8554
        end
8555
 
8556 26 mihad
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8557
//        while ( FRAME === 0 || IRDY === 0 )
8558
//            @(posedge pci_clock) ;
8559 15 mihad
 
8560
        // set the target to normal completion
8561
        test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8562
        test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8563
 
8564
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b1, ok ) ;
8565
        if ( ok !== 1 )
8566
        begin
8567
            $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) ;
8568
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8569
            ok = 0 ;
8570
        end
8571
 
8572
        // now wait for delayed read to finish
8573
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8574
        if ( ok !== 1 )
8575
        begin
8576
            $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) ;
8577
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory read was requested") ;
8578
            ok = 0 ;
8579
        end
8580
 
8581
        // start a write through target - it shouldn't go through since delayed read completion for WB is already present in a bridge
8582
        fork
8583
        begin
8584
                if ( target_mem_image == 1 )
8585
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8586
                                pci_image_base, 32'h5555_5555, 4'h0,
8587
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8588
                                `Test_Devsel_Medium, `Test_Target_Retry_On);
8589
                else
8590
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h5555_5555, 4'h0, 1, `Test_Target_Retry_On) ;
8591
 
8592
                do_pause( 1 ) ;
8593
                end
8594
                begin
8595
            pci_transaction_progress_monitor( pci_image_base, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8596
                end
8597
                join
8598
 
8599
        // try posting a write through wb_slave - it musn't go through since delayed read completion is present in PCI target unit
8600
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8601
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8602
        begin
8603
            $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) ;
8604
            test_fail("WB Slave didn't reject posted memory write when delayed read completion was present in PCI Target Unit") ;
8605
            ok = 0 ;
8606
        end
8607
 
8608
        fork
8609
        begin
8610
        // now complete a read from PCI Target
8611
            if ( target_mem_image == 1 )
8612
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8613
                            pci_image_base, 32'h5555_5555,
8614
                            1, 8'h7_0, `Test_One_Zero_Target_WS,
8615
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8616
            else
8617
                PCIU_IO_READ
8618
                (
8619
                    `Test_Master_1,
8620
                    pci_image_base,
8621
                    32'h5555_5555,
8622
                    4'h0,
8623
                    1,
8624
                    `Test_Target_Normal_Completion
8625
                );
8626
 
8627
            do_pause( 1 ) ;
8628
        end
8629
        begin
8630
            if ( target_mem_image == 1 )
8631
                pci_transaction_progress_monitor( pci_image_base, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8632
            else
8633
                pci_transaction_progress_monitor( pci_image_base, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8634
        end
8635
        join
8636
 
8637
        @(posedge pci_clock) ;
8638
        repeat( 4 )
8639
            @(posedge wb_clock) ;
8640
 
8641
        // except read completion in WB slave unit, everything is done - post anoher write - it must be accepted
8642
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8643
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8644
        begin
8645
            $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) ;
8646
            test_fail("WB Slave didn't accept posted memory write when delayed read completion was present in WB Slave Unit") ;
8647
            ok = 0 ;
8648
        end
8649
 
8650
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8651
        if ( ok !== 1 )
8652
        begin
8653
            $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) ;
8654
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8655
            ok = 0 ;
8656
        end
8657
 
8658
        // finish a read on WISHBONE also
8659
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8660
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8661
        begin
8662
            $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8663
            test_fail("WB Slave didn't process single delayed read as expected") ;
8664
        end
8665
 
8666
        if ( read_status`READ_DATA !== wmem_data[500 + 3] )
8667
        begin
8668
            test_fail("delayed read data provided by WB Slave was not as expected") ;
8669
            ok = 0 ;
8670
        end
8671
 
8672
 
8673
        error_monitor_done = 1 ;
8674
    end
8675
    join
8676
 
8677
    if ( ok )
8678
        test_ok ;
8679
 
8680
    test_name = "ORDERING OF TRANSACTIONS MOVING IN SAME DIRECTION - WRITE THROUGH PCI TARGET, READ THROUGH WB SLAVE" ;
8681
 
8682
    // put wishbone slave in retry and pci target in completion mode
8683
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
8684
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
8685
 
8686
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'hFF);
8687
 
8688
    master1_check_received_data = 1 ;
8689
 
8690
    error_monitor_done = 0 ;
8691
    fork
8692
    begin:error_monitor_6
8693
        @(error_event_int or error_monitor_done) ;
8694
        if ( !error_monitor_done )
8695
        begin
8696
            test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
8697
            ok = 0 ;
8698
        end
8699
    end
8700
    begin
8701
 
8702
        // do a write through Target
8703
        fork
8704
        begin
8705
            if ( target_mem_image == 1 )
8706
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8707
                            pci_image_base + 12, 32'hDEAD_BEAF, 4'h0,
8708
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8709
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8710
            else
8711
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hDEAD_BEAF, 4'h0, 1, `Test_Target_Normal_Completion) ;
8712
 
8713
            do_pause( 1 ) ;
8714
        end
8715
        begin
8716
            if ( target_mem_image == 1 )
8717
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8718
            else
8719
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8720
        end
8721
        join
8722
 
8723
        // start a read through WB slave
8724
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8725
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8726
        begin
8727
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8728
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8729
            ok = 0 ;
8730
        end
8731
 
8732
        // now wait for this read to finish on pci
8733
        pci_transaction_progress_monitor( read_data`READ_ADDRESS, `BC_MEM_READ, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8734
        if ( ok !== 1 )
8735
        begin
8736
            $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) ;
8737
            test_fail("PCI Master failed to start valid transaction on PCI bus after single delayed read was requested") ;
8738
            ok = 0 ;
8739
        end
8740
 
8741
        // repeat the read four times - it should be retried
8742
        for ( i = 0 ; i < 4 ; i = i + 1 )
8743
        begin
8744
           wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8745
            if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1) )
8746
            begin
8747
                $display("Transaction ordering test failed! Single delayed read was not processed as expected by WB Slave unit! Time %t ", $time) ;
8748
                test_fail("Single delayed read was not processed as expected by WB Slave unit") ;
8749
                ok = 0 ;
8750
            end
8751
        end
8752
 
8753
        // posted write through WB Slave - must go through
8754
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8755
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
8756
        begin
8757
            $display("Transaction ordering test failed! Bridge failed to post single memory write! Time %t ", $time) ;
8758
            test_fail("Bridge didn't post single memory write as expected on WB bus") ;
8759
            ok = 0 ;
8760
        end
8761
 
8762
        // write must come through
8763
        pci_transaction_progress_monitor( write_data`WRITE_ADDRESS, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8764
        if ( ok !== 1 )
8765
        begin
8766
            $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) ;
8767
            test_fail("PCI Master failed to start valid transaction on PCI bus after single memory write was posted") ;
8768
            ok = 0 ;
8769
        end
8770
 
8771
        // do a read through pci target
8772
        if ( target_mem_image == 1 )
8773
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8774
                          pci_image_base + 12, 32'hDEAD_BEAF,
8775
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8776
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
8777
        else
8778
            PCIU_IO_READ
8779
             (
8780
                `Test_Master_1,
8781
                pci_image_base + 12,
8782
                32'hDEAD_BEAF,
8783
                4'h0,
8784
                1,
8785
                `Test_Target_Retry_On
8786
             );
8787
 
8788
         do_pause( 1 ) ;
8789
 
8790
        // wait for current cycle to finish on WB
8791 26 mihad
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 0, 1'b1, ok ) ;
8792
//        @(posedge wb_clock) ;
8793
//        while( CYC_O === 1 )
8794
//            @(posedge wb_clock) ;
8795 15 mihad
 
8796
        // set slave response to acknowledge
8797
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
8798
 
8799
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8800
        if ( ok !== 1 )
8801
        begin
8802
            $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) ;
8803
            test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8804
        end
8805
 
8806
        // check the read to finish on wb
8807
        wb_transaction_progress_monitor( pci_image_base + 12, 1'b0, 1, 1'b1, ok ) ;
8808
        if ( ok !== 1 )
8809
        begin
8810
            $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) ;
8811
            test_fail("WB Master failed to start valid transaction on WB bus after single delayed read was requested") ;
8812
        end
8813
 
8814
        // do a write to wb_slave - musn't go through, since delayed read completion is present in PCI Target unit
8815
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
8816
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_RTY !== 1) )
8817
        begin
8818
            $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) ;
8819
            test_fail("WB Slave didn't reject single posted write when delayed read completion was present in PCI Target unit") ;
8820
            ok = 0 ;
8821
        end
8822
 
8823
        // try a write through PCI Target Unit - musn't go through since delayed read completion is present in WB Slave Unit
8824
        fork
8825
        begin
8826
            if ( target_mem_image == 1 )
8827
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8828
                            pci_image_base + 12, 32'h1234_5678, 4'h0,
8829
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8830
                            `Test_Devsel_Medium, `Test_Target_Retry_On);
8831
            else
8832
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On) ;
8833
        end
8834
        begin
8835
            if ( target_mem_image == 1 )
8836
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_MEM_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8837
            else
8838
                pci_transaction_progress_monitor( pci_image_base + 12, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 1'b0, ok ) ;
8839
        end
8840
        join
8841
 
8842
        do_pause( 1 ) ;
8843
 
8844
        // complete a read in WB Slave Unit
8845
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
8846
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
8847
        begin
8848
            $display("Transaction ordering test failed! Single delayed read request was not processed as expected by WB Slave unit! Time %t ", $time) ;
8849
            test_fail("Single delayed read request was not processed as expected by WB Slave unit") ;
8850
            ok = 0 ;
8851
        end
8852
 
8853
        if ( read_status`READ_DATA !== write_data`WRITE_DATA )
8854
        begin
8855
            $display("Transaction ordering test failed! Single delayed read through WB Slave didn't return expected data! Time %t ", $time) ;
8856
            test_fail("Single delayed read through WB Slave didn't return expected data") ;
8857
            ok = 0 ;
8858
        end
8859
 
8860
        // wait for statuses to be propagated from one side of bridge to another
8861
        repeat( 4 )
8862
            @(posedge pci_clock) ;
8863
 
8864
        // post a write through pci_target_unit - must go through since only delayed read completion in pci target unit is present
8865
        fork
8866
        begin
8867
            if ( target_mem_image == 1 )
8868
                PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
8869
                            pci_image_base + 12, 32'hAAAA_AAAA, 4'h0,
8870
                            1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
8871
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8872
            else
8873
                PCIU_IO_WRITE( `Test_Master_1, pci_image_base + 12, 32'hAAAA_AAAA, 4'h0, 1, `Test_Target_Normal_Completion) ;
8874
 
8875
            do_pause( 1 ) ;
8876
        end
8877
        begin
8878
            wb_transaction_progress_monitor( pci_image_base + 12, 1'b1, 1, 1'b1, ok ) ;
8879
            if ( ok !== 1 )
8880
            begin
8881
                $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) ;
8882
                test_fail("WB Master failed to start valid transaction on WB bus after single write was posted") ;
8883
            end
8884
        end
8885
        join
8886
 
8887
        // finish the last read in PCI Target Unit
8888
        if ( target_mem_image == 1 )
8889
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
8890
                          pci_image_base + 12, 32'hDEAD_BEAF,
8891
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
8892
                          `Test_Devsel_Medium, `Test_Target_Normal_Completion);
8893
        else
8894
            PCIU_IO_READ
8895
             (
8896
                `Test_Master_1,
8897
                pci_image_base + 12,
8898
                32'hDEAD_BEAF,
8899
                4'h0,
8900
                1,
8901
                `Test_Target_Normal_Completion
8902
             );
8903
 
8904
         do_pause( 1 ) ;
8905
 
8906
         error_monitor_done = 1 ;
8907
    end
8908
    join
8909
 
8910
    if ( ok )
8911
        test_ok ;
8912
 
8913
end
8914
endtask // transaction_ordering
8915
 
8916
task pci_transaction_progress_monitor ;
8917
    input [31:0] address ;
8918
    input [3:0]  bus_command ;
8919
    input [31:0] num_of_transfers ;
8920
    input [31:0] num_of_cycles ;
8921
    input check_transfers ;
8922
    input check_cycles ;
8923
    input doing_fast_back_to_back ;
8924
    output ok ;
8925
    reg in_use ;
8926
    integer deadlock_counter ;
8927
    integer transfer_counter ;
8928
    integer cycle_counter ;
8929
    integer deadlock_max_val ;
8930
begin:main
8931
 
8932
    if ( in_use === 1 )
8933
    begin
8934
        $display("pci_transaction_progress_monitor task re-entered! Time %t ", $time) ;
8935
        ok = 0 ;
8936
        disable main ;
8937
    end
8938
 
8939
    // approximate number of cycles on WB bus for maximum transaction length
8940
    deadlock_max_val = tb_init_waits + 100 +
8941
                       `WBW_DEPTH *
8942
                       (tb_subseq_waits + 1 +
8943
                       `ifdef REGISTER_WBS_OUTPUTS
8944
                       1) ;
8945
                       `else
8946
                       0) ;
8947
                       `endif
8948
 
8949
    // time used for maximum transaction length on WB
8950
    deadlock_max_val = deadlock_max_val * ( 1/`WB_FREQ ) ;
8951
 
8952
    // maximum pci clock cycles
8953
    `ifdef PCI33
8954
        deadlock_max_val = deadlock_max_val / 30 + 100 ;
8955
    `else
8956
        deadlock_max_val = deadlock_max_val / 15 + 100 ;
8957
    `endif
8958
 
8959
    in_use = 1 ;
8960
    ok     = 1 ;
8961
 
8962
    fork
8963
    begin:wait_start
8964
 
8965
        deadlock_counter = 0 ;
8966
 
8967
        @(posedge pci_clock) ;
8968
 
8969
        if ( doing_fast_back_to_back !== 1 )
8970
        begin
8971
            while ( (FRAME !== 1) && (deadlock_counter < deadlock_max_val) )
8972
            begin
8973 26 mihad
                if ( (IRDY == 0) && ((TRDY == 0) || (STOP == 0)) )
8974
                    deadlock_counter = 0 ;
8975
                else
8976
                    deadlock_counter = deadlock_counter + 1 ;
8977 15 mihad
                @(posedge pci_clock) ;
8978
            end
8979
            if ( FRAME !== 1 )
8980
            begin
8981
                $display("pci_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
8982
                in_use = 0 ;
8983
                ok     = 0 ;
8984
                disable main ;
8985
            end
8986
        end
8987
 
8988
        deadlock_counter = 0 ;
8989
        while ( (FRAME !== 0) && (deadlock_counter < deadlock_max_val) )
8990
        begin
8991
            deadlock_counter = deadlock_counter + 1 ;
8992
            @(posedge pci_clock) ;
8993
        end
8994
 
8995
        if ( FRAME !== 0 )
8996
        begin
8997
            $display("pci_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
8998
            in_use = 0 ;
8999
            ok     = 0 ;
9000
            disable main ;
9001
        end
9002
    end //wait_start
9003
 
9004
    begin:addr_bc_monitor
9005
 
9006
        @(posedge pci_clock) ;
9007
 
9008
        if ( doing_fast_back_to_back !== 1 )
9009
        begin
9010
            while ( FRAME !== 1 )
9011
                @(posedge pci_clock) ;
9012
        end
9013
 
9014
        while( FRAME !== 0 )
9015
            @(posedge pci_clock) ;
9016
 
9017
        // Address during Interrupt Acknowledge cycle has don't care value - don't check it
9018
        if ( bus_command !== `BC_IACK )
9019
        begin
9020
            if ( AD !== address )
9021
            begin
9022
                $display("pci_transaction_progress_monitor detected unexpected address on PCI! Time %t ", $time) ;
9023
                $display("Expected address = %h, detected address = %h ", address, AD) ;
9024
                ok = 0 ;
9025
            end
9026
        end
9027
 
9028
        if ( CBE !== bus_command )
9029
        begin
9030
            $display("pci_transaction_progress_monitor detected unexpected bus command on PCI! Time %t ", $time) ;
9031
            $display("Expected bus command = %b, detected bus command = %b", bus_command, CBE) ;
9032
            ok = 0 ;
9033
        end
9034
    end //addr_bc_monitor
9035
 
9036
    begin:transfer_checker
9037
        transfer_counter = 0 ;
9038
 
9039
        @(posedge pci_clock) ;
9040
 
9041
        if ( doing_fast_back_to_back !== 1 )
9042
        begin
9043
            while ( FRAME !== 1 )
9044
                @(posedge pci_clock) ;
9045
        end
9046
 
9047
        while( FRAME !== 0 )
9048
            @(posedge pci_clock) ;
9049
 
9050
        while( FRAME === 0 )
9051
        begin
9052
            if ( (IRDY === 0) && (TRDY === 0) && (DEVSEL === 0) )
9053
                transfer_counter = transfer_counter + 1 ;
9054
            @(posedge pci_clock) ;
9055
        end
9056
 
9057
        while( (IRDY === 0) && (TRDY === 1) && (STOP === 1) )
9058
        begin
9059
            @(posedge pci_clock) ;
9060
        end
9061
 
9062
        if ( (TRDY === 0) && (DEVSEL === 0) )
9063
                transfer_counter = transfer_counter + 1 ;
9064
 
9065
        if ( check_transfers === 1 )
9066
        begin
9067
            if ( transfer_counter !== num_of_transfers )
9068
            begin
9069
                $display("pci_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9070
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9071
                ok = 0 ;
9072
            end
9073
        end
9074
    end //transfer_checker
9075
    begin:cycle_checker
9076
        if ( check_cycles )
9077
        begin
9078
            cycle_counter = 0 ;
9079
            @(posedge pci_clock) ;
9080
 
9081
            if ( doing_fast_back_to_back !== 1)
9082
            begin
9083
                while ( FRAME !== 1 )
9084
                    @(posedge pci_clock) ;
9085
            end
9086
 
9087
            while( FRAME !== 0 )
9088
                @(posedge pci_clock) ;
9089
 
9090
            while ( (FRAME !== 1) && (cycle_counter < num_of_cycles) )
9091
            begin
9092
                cycle_counter = cycle_counter + 1 ;
9093
                @(posedge pci_clock) ;
9094
            end
9095
 
9096
            if ( FRAME !== 1 )
9097
            begin
9098
                while ((FRAME === 0) && (MAS0_GNT === 0))
9099
                    @(posedge pci_clock) ;
9100
 
9101
                if ( FRAME !== 1 )
9102
                begin
9103
                    while( (IRDY === 1) || ((TRDY === 1) && (STOP === 1)) )
9104
                        @(posedge pci_clock) ;
9105
 
9106
                    @(posedge pci_clock) ;
9107
 
9108
                    if ( FRAME !== 1 )
9109
                    begin
9110
                        $display("pci_transaction_progress_monitor detected invalid transaction length! Time %t ", $time) ;
9111
                        $display("Possibility of wrong operation in latency timer logic exists!") ;
9112
                        ok = 0 ;
9113
                    end
9114
                end
9115
            end
9116
        end
9117
    end // cycle_checker
9118
    join
9119
 
9120
    in_use = 0 ;
9121
end
9122
endtask //pci_transaction_progress_monitor
9123
 
9124
reg CYC_O_previous ;
9125
always@(posedge wb_clock or posedge reset)
9126
begin
9127
    if ( reset )
9128
        CYC_O_previous <= #1 1'b0 ;
9129
    else
9130
        CYC_O_previous <= #1 CYC_O ;
9131
end
9132
 
9133
task wb_transaction_progress_monitor ;
9134
    input [31:0] address ;
9135
    input        write ;
9136
    input [31:0] num_of_transfers ;
9137
    input check_transfers ;
9138
    output ok ;
9139
    reg in_use ;
9140
    integer deadlock_counter ;
9141
    integer transfer_counter ;
9142
    integer deadlock_max_val ;
9143
begin:main
9144
    if ( in_use === 1 )
9145
    begin
9146
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9147
        ok = 0 ;
9148
        disable main ;
9149
    end
9150
 
9151
    // number of cycles on WB bus for maximum transaction length
9152
    deadlock_max_val = 4 - tb_init_waits + 100 +
9153
                       `PCIW_DEPTH *
9154
                       (4 - tb_subseq_waits + 1) ;
9155
 
9156
    // time used for maximum transaction length on PCI
9157
    `ifdef PCI33
9158
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9159
    `else
9160
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9161
    `endif
9162
 
9163
    // maximum wb clock cycles
9164
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9165
 
9166
    in_use = 1 ;
9167
    ok     = 1 ;
9168
 
9169
    fork
9170
    begin:wait_start
9171
        deadlock_counter = 0 ;
9172
        @(posedge wb_clock) ;
9173
        while ( (CYC_O !== 0 && CYC_O_previous !== 0) && (deadlock_counter < deadlock_max_val) )
9174
        begin
9175 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9176
                deadlock_counter = deadlock_counter + 1 ;
9177
            else
9178
                deadlock_counter = 0;
9179 15 mihad
            @(posedge wb_clock) ;
9180
        end
9181
        if ( CYC_O !== 0 && CYC_O_previous !== 0)
9182
        begin
9183
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9184
            in_use = 0 ;
9185
            ok     = 0 ;
9186
            disable main ;
9187
        end
9188
 
9189
        deadlock_counter = 0 ;
9190
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9191
        begin
9192
            deadlock_counter = deadlock_counter + 1 ;
9193
            @(posedge wb_clock) ;
9194
        end
9195
 
9196
        if ( CYC_O !== 1 )
9197
        begin
9198
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9199
            in_use = 0 ;
9200
            ok     = 0 ;
9201
            disable main ;
9202
        end
9203
    end //wait_start
9204
    begin:addr_monitor
9205
        @(posedge wb_clock) ;
9206
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9207
            @(posedge wb_clock) ;
9208
 
9209
        while( CYC_O !== 1 )
9210
            @(posedge wb_clock) ;
9211
 
9212
        while (STB_O !== 1 )
9213
            @(posedge wb_clock) ;
9214
 
9215
        if ( WE_O !== write )
9216
        begin
9217
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9218
            if ( write !== 1 )
9219
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9220
            else
9221
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9222
        end
9223
 
9224
        if ( ADR_O !== address )
9225
        begin
9226
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9227
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9228
            ok = 0 ;
9229
        end
9230
    end
9231
    begin:transfer_checker
9232
        transfer_counter = 0 ;
9233
        @(posedge wb_clock) ;
9234
        while ( CYC_O !== 0 && CYC_O_previous !== 0)
9235
            @(posedge wb_clock) ;
9236
 
9237
        while( CYC_O !== 1 )
9238
            @(posedge wb_clock) ;
9239
 
9240
        while( CYC_O === 1 )
9241
        begin
9242
            if ( (STB_O === 1) && (ACK_I === 1) )
9243
                transfer_counter = transfer_counter + 1 ;
9244
            @(posedge wb_clock) ;
9245
        end
9246
 
9247
        if ( check_transfers === 1 )
9248
        begin
9249
            if ( transfer_counter !== num_of_transfers )
9250
            begin
9251
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9252
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9253
                ok = 0 ;
9254
            end
9255
        end
9256
    end //transfer_checker
9257
    join
9258
 
9259
    in_use = 0 ;
9260
end
9261
endtask // wb_transaction_progress_monitor
9262
 
9263
// this task is the same as wb_transaction_progress_monitor. It is used, when two tasks must run in parallel,
9264
// so they are not re-entered
9265
task wb_transaction_progress_monitor_backup ;
9266
    input [31:0] address ;
9267
    input        write ;
9268
    input [31:0] num_of_transfers ;
9269
    input check_transfers ;
9270
    output ok ;
9271
    reg in_use ;
9272
    integer deadlock_counter ;
9273
    integer transfer_counter ;
9274
    integer deadlock_max_val ;
9275
begin:main
9276
    if ( in_use === 1 )
9277
    begin
9278
        $display("wb_transaction_progress_monitor task re-entered! Time %t ", $time) ;
9279
        ok = 0 ;
9280
        disable main ;
9281
    end
9282
 
9283
    // number of cycles on WB bus for maximum transaction length
9284
    deadlock_max_val = 4 - tb_init_waits + 100 +
9285
                       `PCIW_DEPTH *
9286
                       (4 - tb_subseq_waits + 1) ;
9287
 
9288
    // time used for maximum transaction length on PCI
9289
    `ifdef PCI33
9290
    deadlock_max_val = deadlock_max_val * ( 30 ) + 100 ;
9291
    `else
9292
    deadlock_max_val = deadlock_max_val * ( 15 ) + 100 ;
9293
    `endif
9294
 
9295
    // maximum wb clock cycles
9296
    deadlock_max_val = deadlock_max_val / (1/`WB_FREQ) ;
9297
 
9298
    in_use = 1 ;
9299
    ok     = 1 ;
9300
 
9301
    fork
9302
    begin:wait_start
9303
        deadlock_counter = 0 ;
9304
        @(posedge wb_clock) ;
9305
        while ( (CYC_O !== 0) && (deadlock_counter < deadlock_max_val) )
9306
        begin
9307 26 mihad
                if ((!STB_O) || (!ACK_I && !RTY_I && !ERR_I))
9308
                deadlock_counter = deadlock_counter + 1 ;
9309
            else
9310
                deadlock_counter = 0;
9311 15 mihad
            @(posedge wb_clock) ;
9312
        end
9313
        if ( CYC_O !== 0 )
9314
        begin
9315
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for previous transaction to complete! Time %t ", $time) ;
9316
            in_use = 0 ;
9317
            ok     = 0 ;
9318
            disable main ;
9319
        end
9320
 
9321
        deadlock_counter = 0 ;
9322
        while ( (CYC_O !== 1) && (deadlock_counter < deadlock_max_val) )
9323
        begin
9324
            deadlock_counter = deadlock_counter + 1 ;
9325
            @(posedge wb_clock) ;
9326
        end
9327
 
9328
        if ( CYC_O !== 1 )
9329
        begin
9330
            $display("wb_transaction_progress_monitor task waited for 1000 cycles for transaction to start! Time %t ", $time) ;
9331
            in_use = 0 ;
9332
            ok     = 0 ;
9333
            disable main ;
9334
        end
9335
    end //wait_start
9336
    begin:addr_monitor
9337
        @(posedge wb_clock) ;
9338
        while ( CYC_O !== 0 )
9339
            @(posedge wb_clock) ;
9340
 
9341
        while( CYC_O !== 1 )
9342
            @(posedge wb_clock) ;
9343
 
9344
        while (STB_O !== 1 )
9345
            @(posedge wb_clock) ;
9346
 
9347
        if ( WE_O !== write )
9348
        begin
9349
            $display("wb_transaction_progress_monitor detected unexpected transaction on WB bus! Time %t ", $time) ;
9350
            if ( write !== 1 )
9351
                $display("Expected read transaction, WE_O signal value %b ", WE_O) ;
9352
            else
9353
                $display("Expected write transaction, WE_O signal value %b ", WE_O) ;
9354
        end
9355
 
9356
        if ( ADR_O !== address )
9357
        begin
9358
            $display("wb_transaction_progress_monitor detected unexpected address on WB bus! Time %t ", $time) ;
9359
            $display("Expected address = %h, detected address = %h ", address, ADR_O) ;
9360
            ok = 0 ;
9361
        end
9362
    end
9363
    begin:transfer_checker
9364
        transfer_counter = 0 ;
9365
        @(posedge wb_clock) ;
9366
        while ( CYC_O !== 0 )
9367
            @(posedge wb_clock) ;
9368
 
9369
        while( CYC_O !== 1 )
9370
            @(posedge wb_clock) ;
9371
 
9372
        while( CYC_O === 1 )
9373
        begin
9374
            if ( (STB_O === 1) && (ACK_I === 1) )
9375
                transfer_counter = transfer_counter + 1 ;
9376
            @(posedge wb_clock) ;
9377
        end
9378
 
9379
        if ( check_transfers === 1 )
9380
        begin
9381
            if ( transfer_counter !== num_of_transfers )
9382
            begin
9383
                $display("wb_transaction_progress_monitor detected unexpected transaction! Time %t ", $time) ;
9384
                $display("Expected transfers in transaction = %d, actual transfers = %d ", num_of_transfers, transfer_counter) ;
9385
                ok = 0 ;
9386
            end
9387
        end
9388
    end //transfer_checker
9389
    join
9390
 
9391
    in_use = 0 ;
9392
end
9393
endtask // wb_transaction_progress_monitor_backup
9394
 
9395
task wb_transaction_stop ;
9396
    input [31:0] num_of_transfers ;
9397
    integer transfer_counter ;
9398
begin:main
9399
    begin:transfer_checker
9400
        transfer_counter = 0 ;
9401
        @(posedge wb_clock) ;
9402
        while ( CYC_O !== 0 )
9403
            @(posedge wb_clock) ;
9404
 
9405
        while( CYC_O !== 1 )
9406
            @(posedge wb_clock) ;
9407
 
9408
        if ( (STB_O === 1) && (ACK_I === 1) )
9409
            transfer_counter = transfer_counter + 1 ;
9410
 
9411
        while( (transfer_counter < num_of_transfers) && (CYC_O === 1) )
9412
        begin
9413
            @(posedge wb_clock) ;
9414
            if ( (STB_O === 1) && (ACK_I === 1) )
9415
                transfer_counter = transfer_counter + 1 ;
9416
        end
9417
    end //transfer_checker
9418
end
9419
endtask // wb_transaction_stop
9420
 
9421
task musnt_respond ;
9422
    output ok ;
9423
    reg in_use ;
9424
    integer i ;
9425
begin:main
9426
    if ( in_use === 1 )
9427
    begin
9428
        $display("Testbench error! Task musnt_repond re-entered! Time %t ", $time) ;
9429
        #20 $stop ;
9430
        ok = 0 ;
9431
        disable main ;
9432
    end
9433
 
9434
    in_use = 1 ;
9435
    ok = 1 ;
9436
 
9437
    fork
9438
    begin:wait_start
9439
        @(negedge FRAME) ;
9440
        disable count ;
9441
    end
9442
    begin:count
9443
        i = 0 ;
9444
        while ( i < 1000 )
9445
        begin
9446
            @(posedge pci_clock) ;
9447
            i = i + 1 ;
9448
        end
9449
        $display("Error! Something is wrong! Task musnt_respond waited for 1000 cycles for transaction to start!") ;
9450
        ok = 0 ;
9451
        disable wait_start ;
9452
    end
9453
    join
9454
 
9455
    @(posedge pci_clock) ;
9456
    while ( FRAME === 0 && ok )
9457
    begin
9458
        if ( DEVSEL !== 1 )
9459
        begin
9460
            ok = 0 ;
9461
        end
9462
        @(posedge pci_clock) ;
9463
    end
9464
 
9465
    while ( IRDY === 0 && ok )
9466
    begin
9467
        if ( DEVSEL !== 1 )
9468
        begin
9469
            ok = 0 ;
9470
        end
9471
        @(posedge pci_clock) ;
9472
    end
9473
    in_use = 0 ;
9474
end
9475
endtask
9476
 
9477
function [31:0] wb_to_pci_addr_convert ;
9478
    input [31:0] wb_address ;
9479
    input [31:0] translation_address ;
9480
    input [31:0] translate ;
9481
 
9482
    reg   [31:0] temp_address ;
9483
begin
9484
    if ( translate !== 1 )
9485
    begin
9486
        temp_address = wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9487
    end
9488
    else
9489
    begin
9490
        temp_address = {translation_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)], {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
9491
    end
9492
 
9493
    temp_address = temp_address | (wb_address & {{(`WB_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `WB_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
9494
    wb_to_pci_addr_convert = temp_address ;
9495
end
9496
endfunction //wb_to_pci_addr_convert
9497
 
9498 45 mihad
`ifdef HOST
9499 15 mihad
task find_pci_devices ;
9500
    integer device_num ;
9501
    reg     found ;
9502
    reg [11:0] pci_ctrl_offset ;
9503
    reg ok ;
9504
    reg [31:0] data ;
9505 45 mihad
    reg [31:0] expected_data ;
9506
 
9507
    reg [5:0]  reg_num ;
9508 15 mihad
begin:main
9509 45 mihad
 
9510
    test_name = "HOST BRIDGE CONFIGURATION CYCLE TYPE 0 GENERATION" ;
9511 15 mihad
    pci_ctrl_offset = 12'h004 ;
9512
 
9513
    // enable master & target operation
9514
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
9515
 
9516
    if ( ok !== 1 )
9517
    begin
9518
        $display("Couldn't enable master! PCI device search cannot proceede! Time %t ", $time) ;
9519 45 mihad
        test_fail("PCI Bridge Master could not be enabled with configuration space access via WISHBONE bus") ;
9520 15 mihad
        disable main ;
9521
    end
9522
    // find all possible devices on pci bus by performing configuration cycles
9523 45 mihad
    for ( device_num = 0 ; device_num <= 31 ; device_num = device_num + 1 )
9524 15 mihad
    begin
9525
        find_device ( device_num, found ) ;
9526
 
9527
        // check pci status register - if device is not present, Received Master Abort bit must be set
9528
        config_read( pci_ctrl_offset, 4'hF, data ) ;
9529
 
9530
        if ( (data[29] !== 0) && (found !== 0) )
9531 45 mihad
        begin
9532 15 mihad
            $display( "Time %t ", $time ) ;
9533
            $display( "Target responded to Configuration cycle, but Received Master Abort bit was set!") ;
9534
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9535 45 mihad
            test_fail("PCI Target responded to configuration cycle and Received Master Abort bit was set") ;
9536
            ok = 0 ;
9537 15 mihad
        end
9538
 
9539
        if ( (data[29] !== 1) && (found !== 1) )
9540
        begin
9541
            $display( "Time %t ", $time ) ;
9542
            $display( "Target didn't respond to Configuration cycle, but Received Master Abort bit was not set!") ;
9543
            $display( "Value read from device status register: %h ", data[31:16] ) ;
9544 45 mihad
            test_fail("PCI Target didn't respond to Configuration cycle, but Received Master Abort bit was not set") ;
9545
            ok = 0 ;
9546 15 mihad
        end
9547
 
9548
        // clear Master Abort status if set
9549
        if ( data[29] !== 0 )
9550
        begin
9551
            config_write( pci_ctrl_offset, 32'hFFFF_0000, 4'b1000, ok) ;
9552
        end
9553 45 mihad
 
9554
        if (found === 1)
9555
        begin
9556
            // first check if found target is supposed to exist
9557
            if (((32'h0000_0800 << device_num) !== `TAR1_IDSEL_ADDR) && ((32'h0000_0800 << device_num) !== `TAR2_IDSEL_ADDR))
9558
            begin
9559
                $display("Time %t", $time) ;
9560
                $display("Unknown Target responded to Type 0 Configuration Cycle generated with HOST Bridge") ;
9561
                test_fail("unknown PCI Target responded to Type 0 Configuration Cycle generated with HOST Bridge");
9562
                ok = 0 ;
9563
            end
9564
            else
9565
            begin
9566
                for (reg_num = 4 ; reg_num <= 9 ; reg_num = reg_num + 1)
9567
                begin
9568
 
9569
                    data = 32'hFFFF_FFFF ;
9570
 
9571
                    expected_data = 0 ;
9572
 
9573
                    if (reg_num == 4)
9574
                    begin
9575
                        expected_data[`PCI_BASE_ADDR0_MATCH_RANGE] = data ;
9576
                        expected_data[3:0]                         = `PCI_BASE_ADDR0_MAP_QUAL ;
9577
                    end
9578
                    else if (reg_num == 5)
9579
                    begin
9580
                        expected_data[`PCI_BASE_ADDR1_MATCH_RANGE] = data ;
9581
                        expected_data[3:0]                         = `PCI_BASE_ADDR1_MAP_QUAL ;
9582
                    end
9583
 
9584
                    // write base address 0
9585
                    generate_configuration_cycle
9586
                    (
9587
                        'h0,            //bus_num
9588
                        device_num,     //device_num
9589
                        'h0,            //func_num
9590
                        reg_num,        //reg_num
9591
                        'h0,            //type
9592
                        4'hF,           // byte_enables
9593
                        data,           //data
9594
                        1'b1            //read0_write1
9595
                    );
9596
 
9597
                    // read data back
9598
                    generate_configuration_cycle
9599
                    (
9600
                        'h0,            //bus_num
9601
                        device_num,     //device_num
9602
                        'h0,            //func_num
9603
                        reg_num,        //reg_num
9604
                        'h0,            //type
9605
                        4'hF,           // byte_enables
9606
                        data,           //data
9607
                        1'b0            //read0_write1
9608
                    );
9609
 
9610
                    if (data !== expected_data)
9611
                    begin
9612
                        $display("All 1s written to BAR0 of behavioral PCI Target!") ;
9613
                        $display("Data read back not as expected!");
9614
                        $display("Expected Data: %h, Actual Data %h", expected_data, data) ;
9615
                        test_fail("data read from BAR of behavioral PCI Target was not as expected") ;
9616
                        ok = 0 ;
9617
                    end
9618
                end
9619
            end
9620
        end
9621 15 mihad
    end
9622 45 mihad
 
9623
    if (ok)
9624
        test_ok ;
9625 15 mihad
end //main
9626
endtask //find_pci_devices
9627
 
9628
task find_device ;
9629
    input [31:0] device_num ;
9630
    output  found ;
9631
 
9632
    reg [31:0] read_data ;
9633
begin
9634
    found = 1'b0 ;
9635
 
9636
    configuration_cycle_read ( 8'h00, device_num[4:0], 3'h0, 6'h00, 2'h0, 4'hF, read_data) ;
9637 45 mihad
    if ( read_data === 32'hFFFF_FFFF)
9638 15 mihad
        $display("Device %d not present on PCI bus!", device_num) ;
9639
    else
9640
    begin
9641
        $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]) ;
9642
        found = 1'b1 ;
9643
    end
9644
end
9645
endtask //find_device
9646 45 mihad
`endif
9647 15 mihad
 
9648
/*task set_bridge_parameters ;
9649
    reg [11:0] current_offset ;
9650
    reg [2:0] result ;
9651
    reg [31:0] write_data ;
9652
begin
9653
    // set burst size
9654
    // set latency timer
9655
    current_offset = 12'h00C ;
9656
    // set burst size to 16 and latency timer to 8
9657
    write_data     = {24'h0000_08, system_burst_size} ;
9658
    config_write(current_offset, write_data, 4'b1111) ;
9659
 
9660
    // set io image
9661
    current_offset = {4'b0001, `W_IMG_CTRL1_ADDR, 2'b00};
9662
    write_data = 32'h0000_000_3 ;
9663
    config_write(current_offset, write_data, 4'b1111) ;
9664
 
9665
 
9666
    current_offset = { 4'b0001, `W_BA1_ADDR, 2'b00 } ;
9667
    write_data = 32'h0001_000_1 ;
9668
    config_write(current_offset, write_data, 4'b1111) ;
9669
 
9670
    current_offset = { 4'b0001, `W_AM1_ADDR, 2'b00 } ;
9671
    write_data = 32'hFFFF_0000 ;
9672
    config_write(current_offset, write_data, 4'b1111) ;
9673
 
9674
    // set memory image
9675
    current_offset = { 4'b0001, `W_IMG_CTRL2_ADDR, 2'b00 } ;
9676
    write_data = 32'h0000_000_7 ;
9677
    config_write(current_offset, write_data, 4'b1111) ;
9678
 
9679
    current_offset = { 4'b0001, `W_BA2_ADDR, 2'b00 } ;
9680
    write_data = 32'h0002_000_0 ;
9681
    config_write(current_offset, write_data, 4'b1111) ;
9682
 
9683
    current_offset = { 4'b0001, `W_TA2_ADDR, 2'b00 } ;
9684
    write_data = 32'h0001_0000 ;
9685
    config_write(current_offset, write_data, 4'b1111) ;
9686
 
9687
    current_offset = { 4'b0001, `W_AM2_ADDR, 2'b00 } ;
9688
    write_data = 32'hFFFF_0000 ;
9689
    config_write(current_offset, write_data, 4'b1111) ;
9690
 
9691
    // set parameters for bridge's target unit
9692
    // image control 0
9693
    current_offset = { 4'b0001, `P_IMG_CTRL0_ADDR, 2'b00 } ;
9694
    write_data     = 32'h0000_0002 ;
9695
    config_write(current_offset, write_data, 4'b0001) ;
9696
 
9697
    // base_address 0
9698
    current_offset = { 4'b0001, `P_BA0_ADDR, 2'b00 } ;
9699
    write_data      = 32'h2000_0000 ;
9700
    config_write(current_offset, write_data, 4'b1111) ;
9701
 
9702
    // address mask 0
9703
    current_offset = { 4'b0001, `P_AM0_ADDR, 2'b00 } ;
9704
    write_data     = 32'hFFFF_F000 ;
9705
    config_write(current_offset, write_data, 4'b1111) ;
9706
 
9707
    // command register - enable response to io and mem space and PCI master
9708
    current_offset = 12'h004 ;
9709
    write_data     = 32'h0000_0007 ; // enable device's memory and io access response !
9710
    config_write(current_offset, write_data, 4'b1111) ;
9711
end
9712
endtask // set_bridge_parameters
9713
*/
9714
 
9715
task configuration_cycle_write ;
9716
    input [7:0]  bus_num ;
9717
    input [4:0]  device_num ;
9718
    input [2:0]  func_num ;
9719
    input [5:0]  reg_num ;
9720
    input [1:0]  type ;
9721
    input [3:0]  byte_enables ;
9722
    input [31:0] data ;
9723
 
9724
    reg [31:0] write_address ;
9725
    reg in_use ;
9726
    reg ok ;
9727
begin:main
9728
 
9729
    if ( in_use === 1 )
9730
    begin
9731 45 mihad
        $display(" Task configuration_cycle_write re-entered! Time %t ", $time ) ;
9732 15 mihad
        disable main ;
9733
    end
9734
 
9735 45 mihad
    if ( (device_num > 20) && (type === 0) )
9736 15 mihad
    begin
9737
        $display("Configuration cycle generation only supports access to 21 devices!") ;
9738
        disable main ;
9739
    end
9740
 
9741
    in_use = 1 ;
9742
 
9743 45 mihad
 
9744
`ifdef HOST
9745
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b1) ;
9746
`else
9747
`ifdef GUEST
9748
 
9749 15 mihad
    if ( type )
9750
        write_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9751
    else
9752
    begin
9753
        write_address = 0 ;
9754
        write_address[10:0] = { func_num, reg_num, type } ;
9755
        write_address[11 + device_num] = 1'b1 ;
9756
    end
9757 45 mihad
 
9758
    fork
9759 15 mihad
    begin
9760 45 mihad
        PCIU_CONFIG_WRITE ("CFG_WRITE ", `Test_Master_2,
9761
                            write_address,
9762
                            data, ~byte_enables,
9763
                            1, `Test_No_Master_WS, `Test_No_Target_WS,
9764
                            `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9765
        do_pause(1) ;
9766 15 mihad
    end
9767 45 mihad
    begin
9768
        pci_transaction_progress_monitor( write_address, `BC_CONF_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
9769
    end
9770
    join
9771
`endif
9772
`endif
9773
 
9774
    in_use = 0 ;
9775
end
9776
endtask // configuration_cycle_write
9777 15 mihad
 
9778 45 mihad
task configuration_cycle_read ;
9779
    input [7:0]  bus_num ;
9780
    input [4:0]  device_num ;
9781
    input [2:0]  func_num ;
9782
    input [5:0]  reg_num ;
9783
    input [1:0]  type ;
9784
    input [3:0]  byte_enables ;
9785
    output [31:0] data ;
9786 15 mihad
 
9787 45 mihad
    reg [31:0] read_address ;
9788
    reg in_use ;
9789 15 mihad
 
9790 45 mihad
    reg master_check_data_prev ;
9791
begin:main
9792 15 mihad
 
9793 45 mihad
    if ( in_use === 1 )
9794 15 mihad
    begin
9795 45 mihad
        $display("configuration_cycle_read task re-entered! Time %t ", $time) ;
9796
        data = 32'hxxxx_xxxx ;
9797
        disable main ;
9798 15 mihad
    end
9799
 
9800 45 mihad
    in_use = 1 ;
9801 15 mihad
 
9802 45 mihad
`ifdef HOST
9803
    generate_configuration_cycle(bus_num, device_num, func_num, reg_num, type, byte_enables, data, 1'b0) ;
9804
`else
9805
`ifdef GUEST
9806
     master_check_data_prev = master1_check_received_data ;
9807 15 mihad
     if ( type )
9808 45 mihad
         read_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9809 15 mihad
     else
9810
     begin
9811 45 mihad
         read_address = 0 ;
9812
         read_address[10:0] = { func_num, reg_num, type } ;
9813
         read_address[11 + device_num] = 1'b1 ;
9814 15 mihad
     end
9815 45 mihad
 
9816
     fork
9817
     begin
9818
         PCIU_CONFIG_READ ("CFG_READ  ", `Test_Master_1,
9819
                 read_address,
9820 15 mihad
                 data, ~byte_enables,
9821
                 1, `Test_No_Master_WS, `Test_No_Target_WS,
9822
                 `Test_Devsel_Medium, `Test_Target_Normal_Completion);
9823 45 mihad
         do_pause(1) ;
9824
     end
9825
     begin
9826
         @(master1_received_data_valid) ;
9827
         data = master1_received_data ;
9828
     end
9829
     join
9830 15 mihad
 
9831 45 mihad
    master1_check_received_data = master_check_data_prev ;
9832
`endif
9833
`endif
9834
 
9835 15 mihad
    in_use = 0 ;
9836
 
9837 45 mihad
end //main
9838
endtask // configuration_cycle_read
9839
 
9840 51 mihad
`ifdef TEST_CONF_CYCLE_TYPE1_REFERENCE
9841
task test_conf_cycle_type1_reference ;
9842
    reg [31:0] address ;
9843
    reg in_use ;
9844
 
9845
    reg master_check_data_prev ;
9846
    reg [31:0] data ;
9847
    reg monitor_ok ;
9848
    reg master_ok ;
9849
begin:main
9850
 
9851
    if ( in_use === 1 )
9852
    begin
9853
        $display("test_conf_cycle_type1_reference task re-entered! Time %t ", $time) ;
9854
        disable main ;
9855
    end
9856
 
9857
    in_use = 1 ;
9858
 
9859
    master_check_data_prev = master1_check_received_data ;
9860
 
9861
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 READ TARGET REFERENCE" ;
9862
    address = `TAR0_IDSEL_ADDR ;
9863
 
9864
    address[1:0] = 2'b01 ;
9865
 
9866
    `ifdef HOST
9867
        conf_cyc_type1_target_bus_num = 255 ;
9868
    `endif
9869
    master_ok = 1 ;
9870
    fork
9871
    begin
9872
        PCIU_CONFIG_READ_MASTER_ABORT ("CFG_READ  ", `Test_Master_1, address, 4'hE) ;
9873
        do_pause(1) ;
9874
    end
9875
    begin:error_monitor1
9876
        @(error_event_int) ;
9877
        master_ok = 0 ;
9878
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9879
    end
9880
    begin
9881
        pci_transaction_progress_monitor
9882
        (
9883
            address,                                                // expected address on PCI bus
9884
            `BC_CONF_READ,                                          // expected bus command on PCI bus
9885
            0,                                                      // expected number of succesfull data phases
9886
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9887
            1'b1,                                                   // monitor checking/not checking number of transfers
9888
            1'b0,                                                   // monitor checking/not checking number of cycles
9889
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9890
            monitor_ok                                              // status - 1 success, 0 failure
9891
        ) ;
9892
 
9893
        @(posedge pci_clock);
9894
        #1 ;
9895
 
9896
        if (master_ok)
9897
            disable error_monitor1 ;
9898
 
9899
        if (!monitor_ok)
9900
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9901
    end
9902
    join
9903
 
9904
    if (monitor_ok && master_ok)
9905
        test_ok ;
9906
 
9907
    test_name = "NO RESPONSE TO CONFIGURATION CYCLE TYPE 1 WRITE TARGET REFERENCE" ;
9908
    master_ok = 1 ;
9909
    fork
9910
    begin
9911
        PCIU_CONFIG_WRITE_MASTER_ABORT ("CFG_WRITE ", `Test_Master_1, address, 4'hF) ;
9912
        do_pause(1) ;
9913
    end
9914
    begin:error_monitor2
9915
        @(error_event_int) ;
9916
        master_ok = 0 ;
9917
        test_fail("PCI Behavioral master signaled an error during the target reference") ;
9918
    end
9919
    begin
9920
        pci_transaction_progress_monitor
9921
        (
9922
            address,                                                // expected address on PCI bus
9923
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
9924
            0,                                                      // expected number of succesfull data phases
9925
            0,                                                      // expected number of cycles the transaction will take on PCI bus
9926
            1'b1,                                                   // monitor checking/not checking number of transfers
9927
            1'b0,                                                   // monitor checking/not checking number of cycles
9928
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
9929
            monitor_ok                                              // status - 1 success, 0 failure
9930
        ) ;
9931
 
9932
        @(posedge pci_clock);
9933
        #1 ;
9934
 
9935
        if (master_ok)
9936
            disable error_monitor2 ;
9937
 
9938
        if (!monitor_ok)
9939
            test_fail("PCI Transaction Monitor detected unexpected transaction on PCI bus") ;
9940
    end
9941
    join
9942
 
9943
    master1_check_received_data = master_check_data_prev ;
9944
 
9945
    if (monitor_ok && master_ok)
9946
        test_ok ;
9947
 
9948
    in_use = 0 ;
9949
 
9950
end //main
9951
endtask // test_conf_cycle_type1_reference
9952
`endif
9953
 
9954 45 mihad
`ifdef HOST
9955
task generate_configuration_cycle ;
9956 15 mihad
    input [7:0]  bus_num ;
9957
    input [4:0]  device_num ;
9958
    input [2:0]  func_num ;
9959
    input [5:0]  reg_num ;
9960
    input [1:0]  type ;
9961
    input [3:0]  byte_enables ;
9962 45 mihad
    inout [31:0] data ;
9963
    input        read0_write1 ;
9964 15 mihad
 
9965
    reg `READ_STIM_TYPE read_data ;
9966
    reg `WB_TRANSFER_FLAGS  flags ;
9967
    reg `READ_RETURN_TYPE   read_status ;
9968
 
9969
    reg `WRITE_STIM_TYPE   write_data ;
9970
    reg `WRITE_RETURN_TYPE write_status ;
9971
 
9972 45 mihad
    reg [31:0] pci_address ;
9973 15 mihad
    reg in_use ;
9974 45 mihad
    reg ok ;
9975 15 mihad
 
9976
    reg [31:0] temp_var ;
9977
begin:main
9978
 
9979
    if ( in_use === 1 )
9980
    begin
9981 45 mihad
        $display("generate_configuration_cycle task re-entered! Time %t ", $time) ;
9982 15 mihad
        data = 32'hxxxx_xxxx ;
9983
        disable main ;
9984
    end
9985
 
9986 45 mihad
    in_use = 1 ;
9987
 
9988
    if ( type )
9989
        pci_address = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
9990
    else
9991 15 mihad
    begin
9992 45 mihad
        pci_address = 0 ;
9993
        pci_address[10:0] = { func_num, reg_num, type } ;
9994
        if (device_num <= 20)
9995
            pci_address[11 + device_num] = 1'b1 ;
9996
    end
9997
 
9998
    // setup flags
9999
    flags = 0 ;
10000
    flags`INIT_WAITS   = tb_init_waits ;
10001
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10002
 
10003
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10004
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10005
 
10006
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10007
    write_data`WRITE_DATA     = { 8'h00, bus_num, device_num, func_num, reg_num, type } ;
10008
    write_data`WRITE_SEL      = 4'hF ;
10009
    write_data`WRITE_TAG_STIM = 0 ;
10010
 
10011
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10012
 
10013
    // check if write succeeded
10014
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10015
    begin
10016
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10017 15 mihad
        data = 32'hxxxx_xxxx ;
10018 45 mihad
        in_use = 0 ;
10019 15 mihad
        disable main ;
10020
    end
10021
 
10022 45 mihad
    // setup flags for wb master to handle retries and read and write data
10023
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10024
 
10025
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10026
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10027
    read_data`READ_SEL          = byte_enables ;
10028
    write_data`WRITE_SEL        = byte_enables ;
10029
    read_data`READ_TAG_STIM     = 0 ;
10030
    write_data`WRITE_TAG_STIM   = 0 ;
10031
    write_data`WRITE_DATA       = data ;
10032
 
10033
    ok = 0 ;
10034
 
10035
    fork
10036
    begin
10037
        if (read0_write1 === 0)
10038
            wishbone_master.wb_single_read(read_data, flags, read_status) ;
10039
        else
10040
        if (read0_write1 === 1)
10041
            wishbone_master.wb_single_write(write_data, flags, write_status) ;
10042
    end
10043
    begin
10044
        pci_transaction_progress_monitor
10045
        (
10046
            pci_address,                                            // expected address on PCI bus
10047
            read0_write1 ? `BC_CONF_WRITE : `BC_CONF_READ,          // expected bus command on PCI bus
10048
            1,                                                      // expected number of succesfull data phases
10049
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10050
            1'b0,                                                   // monitor checking/not checking number of transfers
10051
            1'b0,                                                   // monitor checking/not checking number of cycles
10052
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10053
            ok                                                      // status - 1 success, 0 failure
10054
        ) ;
10055
    end
10056
    join
10057
 
10058
    // check if transfer succeeded
10059
    if ((read0_write1 ? write_status`CYC_ACTUAL_TRANSFER : read_status`CYC_ACTUAL_TRANSFER) !== 1)
10060
    begin
10061
        $display("Configuration cycle generation failed! Configuration cycle not processed correctly by the bridge! Time %t ", $time) ;
10062
        data = 32'hxxxx_xxxx ;
10063
        in_use = 0 ;
10064
        disable main ;
10065
    end
10066
 
10067
    if (!ok)
10068
    begin
10069
        data = 32'hxxxx_xxxx ;
10070
        in_use = 0 ;
10071
        disable main ;
10072
    end
10073
 
10074
    if (read0_write1 === 0)
10075
        data = read_status`READ_DATA ;
10076
 
10077
    in_use = 0 ;
10078
end
10079
endtask // generate_configuration_cycle
10080
 
10081
task test_configuration_cycle_target_abort ;
10082
    reg `READ_STIM_TYPE read_data ;
10083
    reg `WB_TRANSFER_FLAGS  flags ;
10084
    reg `READ_RETURN_TYPE   read_status ;
10085
 
10086
    reg `WRITE_STIM_TYPE   write_data ;
10087
    reg `WRITE_RETURN_TYPE write_status ;
10088
 
10089
    reg [31:0] pci_address ;
10090
    reg in_use ;
10091
    reg ok_pci ;
10092
    reg ok_wb  ;
10093
    reg ok     ;
10094
 
10095
    reg [31:0] temp_var ;
10096
 
10097
begin:main
10098
 
10099
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE GENERATION" ;
10100
 
10101
    if ( in_use === 1 )
10102
    begin
10103
        $display("test_configuration_cycle_target_abort task re-entered! Time %t ", $time) ;
10104
        disable main ;
10105
    end
10106
 
10107 15 mihad
    in_use = 1 ;
10108
 
10109 45 mihad
    pci_address = `TAR1_IDSEL_ADDR ;
10110
 
10111 15 mihad
    // setup flags
10112
    flags = 0 ;
10113 45 mihad
    flags`INIT_WAITS   = tb_init_waits ;
10114
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10115 15 mihad
 
10116
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10117
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10118
 
10119
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10120 45 mihad
    temp_var                  = 0 ;
10121
    temp_var[15:11]           = `TAR1_IDSEL_INDEX - 11 ; // device number field
10122
    write_data`WRITE_DATA     = temp_var ;
10123 15 mihad
    write_data`WRITE_SEL      = 4'hF ;
10124
    write_data`WRITE_TAG_STIM = 0 ;
10125
 
10126
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10127
 
10128
    // check if write succeeded
10129
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10130
    begin
10131
        $display("Configuration cycle generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10132 45 mihad
        test_fail("write to configuration cycle address register was not possible") ;
10133
        in_use = 0 ;
10134 15 mihad
        disable main ;
10135
    end
10136
 
10137 45 mihad
    // setup flags for wb master to handle retries and read and write data
10138 15 mihad
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10139
 
10140 45 mihad
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10141
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10142 15 mihad
 
10143 45 mihad
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10144
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10145
    read_data`READ_SEL          = 4'hF ;
10146
    write_data`WRITE_SEL        = 4'hF ;
10147
    read_data`READ_TAG_STIM     = 0 ;
10148
    write_data`WRITE_TAG_STIM   = 0 ;
10149
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10150
 
10151
    ok_pci = 0 ;
10152
    ok_wb  = 1 ;
10153
 
10154
    // set target to terminate with target abort
10155
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Abort ;
10156
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 1 ;
10157
    fork
10158
    begin
10159
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10160
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1))
10161
        begin
10162
            $display("Time %t", $time) ;
10163
            $display("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10164
            test_fail("Configuration Cycle Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10165
            ok_wb = 0 ;
10166
        end
10167
 
10168
        config_read( 12'h4, 4'hF, temp_var ) ;
10169
        if ( temp_var[29] !== 0 )
10170
        begin
10171
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10172
            $display("Received Master Abort bit was set when Configuration Read was terminated with Target Abort!") ;
10173
            test_fail("Received Master Abort bit was set when Configuration Read was terminated with Target Abort") ;
10174
            ok_wb = 0 ;
10175
        end
10176
 
10177
        if ( temp_var[28] !== 1 )
10178
        begin
10179
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10180
            $display("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort!") ;
10181
            test_fail("Received Target Abort bit was not set when Configuration Read was terminated with Target Abort") ;
10182
            ok_wb = 0 ;
10183
        end
10184
 
10185
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10186
 
10187
        if (ok !== 1)
10188
        begin
10189
            ok_wb = 0 ;
10190
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10191
            $display("Write to PCI Device Status Register failed") ;
10192
            test_fail("Write to PCI Device Status Register failed") ;
10193
        end
10194
 
10195
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10196
        if ((write_status`CYC_ACTUAL_TRANSFER !== 0 || write_status`CYC_ERR !== 1))
10197
        begin
10198
            $display("Time %t", $time) ;
10199
            $display("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10200
            test_fail("Configuration Cycle Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10201
            ok_wb = 0 ;
10202
        end
10203
 
10204
        config_read( 12'h4, 4'hF, temp_var ) ;
10205
        if ( temp_var[29] !== 0 )
10206
        begin
10207
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10208
            $display("Received Master Abort bit was set when Configuration Write was terminated with Target Abort!") ;
10209
            test_fail("Received Master Abort bit was set when Configuration Write was terminated with Target Abort") ;
10210
            ok_wb = 0 ;
10211
        end
10212
 
10213
        if ( temp_var[28] !== 1 )
10214
        begin
10215
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10216
            $display("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort!") ;
10217
            test_fail("Received Target Abort bit was not set when Configuration Write was terminated with Target Abort") ;
10218
            ok_wb = 0 ;
10219
        end
10220
 
10221
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10222
 
10223
        if (ok !== 1)
10224
        begin
10225
            ok_wb = 0 ;
10226
            $display("Target Abort termination of Configuration Cycle testing failed! Time %t ", $time) ;
10227
            $display("Write to PCI Device Status Register failed") ;
10228
            test_fail("Write to PCI Device Status Register failed") ;
10229
        end
10230
    end
10231
    begin
10232
        pci_transaction_progress_monitor
10233
        (
10234
            pci_address,                                            // expected address on PCI bus
10235
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10236
            0,                                                      // expected number of succesfull data phases
10237
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10238
            1'b1,                                                   // monitor checking/not checking number of transfers
10239
            1'b0,                                                   // monitor checking/not checking number of cycles
10240
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10241
            ok_pci                                                  // status - 1 success, 0 failure
10242
        ) ;
10243
 
10244
        if (ok_pci)
10245
        begin
10246
            pci_transaction_progress_monitor
10247
            (
10248
                pci_address,                                            // expected address on PCI bus
10249
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10250
                0,                                                      // expected number of succesfull data phases
10251
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10252
                1'b1,                                                   // monitor checking/not checking number of transfers
10253
                1'b0,                                                   // monitor checking/not checking number of cycles
10254
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10255
                ok_pci                                                  // status - 1 success, 0 failure
10256
            ) ;
10257
        end
10258
 
10259
        if (!ok_pci)
10260
        begin
10261
            $display("Time %t", $time) ;
10262
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10263
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10264
        end
10265
    end
10266
    join
10267
 
10268
    if (ok_pci && ok_wb)
10269
    begin
10270
        test_ok ;
10271
    end
10272
 
10273
    in_use = 0 ;
10274
 
10275
    // set target to terminate normally
10276
    test_target_response[`TARGET_ENCODED_TERMINATION]       = `Test_Target_Normal_Completion ;
10277
    test_target_response[`TARGET_ENCODED_TERMINATE_ON]      = 0 ;
10278
end
10279
endtask // test_configuration_cycle_target_abort
10280
 
10281
task test_configuration_cycle_type1_generation ;
10282
    reg `READ_STIM_TYPE read_data ;
10283
    reg `WB_TRANSFER_FLAGS  flags ;
10284
    reg `READ_RETURN_TYPE   read_status ;
10285
 
10286
    reg `WRITE_STIM_TYPE   write_data ;
10287
    reg `WRITE_RETURN_TYPE write_status ;
10288
 
10289
    reg [31:0] pci_address ;
10290
    reg in_use ;
10291
    reg ok_pci ;
10292
    reg ok_wb  ;
10293
    reg ok     ;
10294
 
10295
    reg [31:0] temp_var ;
10296
 
10297
begin:main
10298
 
10299
    conf_cyc_type1_target_response = 0 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10300
    conf_cyc_type1_target_data = 0 ;
10301
    conf_cyc_type1_target_bus_num = 0;
10302
 
10303
    test_name = "MASTER ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10304
 
10305
    if ( in_use === 1 )
10306
    begin
10307
        $display("test_configuration_cycle_type1_generation task re-entered! Time %t ", $time) ;
10308
        disable main ;
10309
    end
10310
 
10311
    in_use = 1 ;
10312
 
10313
    pci_address        = 32'hAAAA_AAAA ;
10314
    pci_address[1:0]   = 2'b01 ; // indicate Type 1 configuration cycle
10315
 
10316
    // setup flags
10317
    flags = 0 ;
10318
    flags`INIT_WAITS   = tb_init_waits ;
10319
    flags`SUBSEQ_WAITS = tb_subseq_waits ;
10320
 
10321
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10322
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10323
 
10324
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10325
    write_data`WRITE_DATA     = pci_address ;
10326
    write_data`WRITE_SEL      = 4'hF ;
10327
    write_data`WRITE_TAG_STIM = 0 ;
10328
 
10329
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10330
 
10331
    // check if write succeeded
10332
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10333
    begin
10334
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10335
        test_fail("write to configuration cycle address register was not possible") ;
10336
        in_use = 0 ;
10337
        disable main ;
10338
    end
10339
 
10340
    // setup flags for wb master to handle retries and read and write data
10341
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10342
 
10343
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10344
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10345
 
10346
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10347
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10348
    read_data`READ_SEL          = 4'hF ;
10349
    write_data`WRITE_SEL        = 4'hF ;
10350
    read_data`READ_TAG_STIM     = 0 ;
10351
    write_data`WRITE_TAG_STIM   = 0 ;
10352
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10353
 
10354
    ok_pci = 0 ;
10355
    ok_wb  = 1 ;
10356
 
10357
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10358
    pci_address[31:24] = 0 ;
10359
    fork
10360
    begin
10361
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10362
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10363
        begin
10364
            $display("Time %t", $time) ;
10365
            $display("Configuration Cycle Type1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10366
            test_fail("Configuration Cycle Type 1 Read was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10367
            ok_wb = 0 ;
10368
        end
10369
 
10370
        config_read( 12'h4, 4'hF, temp_var ) ;
10371
        if ( temp_var[29] !== 1 )
10372
        begin
10373
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10374
            $display("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort!") ;
10375
            test_fail("Received Master Abort bit was not set when Configuration Type1 Read was terminated with Master Abort") ;
10376
            ok_wb = 0 ;
10377
        end
10378
 
10379
        if ( temp_var[28] !== 0 )
10380
        begin
10381
            $display("Master Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10382
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort!") ;
10383
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated with Master Abort") ;
10384
            ok_wb = 0 ;
10385
        end
10386
 
10387
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10388
 
10389
        if (ok !== 1)
10390
        begin
10391
            ok_wb = 0 ;
10392
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10393
            $display("Write to PCI Device Status Register failed") ;
10394
            test_fail("Write to PCI Device Status Register failed") ;
10395
        end
10396
 
10397
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10398
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10399
        begin
10400
            $display("Time %t", $time) ;
10401
            $display("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10402
            test_fail("Configuration Cycle Type1 Write was terminated with Master Abort on PCI Bus but didn't terminate with ACK on WB Bus") ;
10403
            ok_wb = 0 ;
10404
        end
10405
 
10406
        config_read( 12'h4, 4'hF, temp_var ) ;
10407
        if ( temp_var[29] !== 1 )
10408
        begin
10409
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10410
            $display("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort!") ;
10411
            test_fail("Received Master Abort bit was not set when Configuration Type1 Write was terminated with Master Abort") ;
10412
            ok_wb = 0 ;
10413
        end
10414
 
10415
        if ( temp_var[28] !== 0 )
10416
        begin
10417
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10418
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort!") ;
10419
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated with Master Abort") ;
10420
            ok_wb = 0 ;
10421
        end
10422
 
10423
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10424
 
10425
        if (ok !== 1)
10426
        begin
10427
            ok_wb = 0 ;
10428
            $display("Master Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10429
            $display("Write to PCI Device Status Register failed") ;
10430
            test_fail("Write to PCI Device Status Register failed") ;
10431
        end
10432
    end
10433
    begin
10434
        pci_transaction_progress_monitor
10435
        (
10436
            pci_address,                                            // expected address on PCI bus
10437
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10438
            0,                                                      // expected number of succesfull data phases
10439
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10440
            1'b1,                                                   // monitor checking/not checking number of transfers
10441
            1'b0,                                                   // monitor checking/not checking number of cycles
10442
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10443
            ok_pci                                                  // status - 1 success, 0 failure
10444
        ) ;
10445
 
10446
        if (ok_pci)
10447
        begin
10448
            pci_transaction_progress_monitor
10449
            (
10450
                pci_address,                                            // expected address on PCI bus
10451
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10452
                0,                                                      // expected number of succesfull data phases
10453
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10454
                1'b1,                                                   // monitor checking/not checking number of transfers
10455
                1'b0,                                                   // monitor checking/not checking number of cycles
10456
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10457
                ok_pci                                                  // status - 1 success, 0 failure
10458
            ) ;
10459
        end
10460
 
10461
        if (!ok_pci)
10462
        begin
10463
            $display("Time %t", $time) ;
10464
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10465
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10466
        end
10467
    end
10468
    join
10469
 
10470
    if (ok_pci && ok_wb)
10471
    begin
10472
        test_ok ;
10473
    end
10474
 
10475
    conf_cyc_type1_target_response = 2'b11 ; // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10476
    conf_cyc_type1_target_data = 0 ;
10477
    conf_cyc_type1_target_bus_num = 8'h55;
10478
 
10479
    pci_address      = 32'h5555_5555 ;
10480
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10481
 
10482
    test_name = "TARGET ABORT HANDLING DURING CONFIGURATION CYCLE TYPE1 GENERATION" ;
10483
 
10484
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10485
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10486
 
10487
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10488
    write_data`WRITE_DATA     = pci_address ;
10489
    write_data`WRITE_SEL      = 4'hF ;
10490
    write_data`WRITE_TAG_STIM = 0 ;
10491
 
10492
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10493
 
10494
    // check if write succeeded
10495
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10496
    begin
10497
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10498
        test_fail("write to configuration cycle address register was not possible") ;
10499
        in_use = 0 ;
10500
        disable main ;
10501
    end
10502
 
10503
    // setup flags for wb master to handle retries and read and write data
10504
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10505
 
10506
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10507
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10508
 
10509
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10510
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10511
    read_data`READ_SEL          = 4'hF ;
10512
    write_data`WRITE_SEL        = 4'hF ;
10513
    read_data`READ_TAG_STIM     = 0 ;
10514
    write_data`WRITE_TAG_STIM   = 0 ;
10515
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10516
 
10517
    ok_pci = 0 ;
10518
    ok_wb  = 1 ;
10519
 
10520
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10521
    pci_address[31:24] = 0 ;
10522
    fork
10523
    begin
10524
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10525
        if ( (read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_ERR !== 1) )
10526
        begin
10527
            $display("Time %t", $time) ;
10528
            $display("Configuration Cycle Type1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10529
            test_fail("Configuration Cycle Type 1 Read was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10530
            ok_wb = 0 ;
10531
        end
10532
 
10533
        config_read( 12'h4, 4'hF, temp_var ) ;
10534
        if ( temp_var[29] !== 0 )
10535
        begin
10536
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10537
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort!") ;
10538
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated with Target Abort") ;
10539
            ok_wb = 0 ;
10540
        end
10541
 
10542
        if ( temp_var[28] !== 1 )
10543
        begin
10544
            $display("Target Abort termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10545
            $display("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort!") ;
10546
            test_fail("Received Target Abort bit was not set when Configuration Type1 Read was terminated with Target Abort") ;
10547
            ok_wb = 0 ;
10548
        end
10549
 
10550
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10551
 
10552
        if (ok !== 1)
10553
        begin
10554
            ok_wb = 0 ;
10555
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10556
            $display("Write to PCI Device Status Register failed") ;
10557
            test_fail("Write to PCI Device Status Register failed") ;
10558
        end
10559
 
10560
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10561
        if ( (write_status`CYC_ACTUAL_TRANSFER !== 0) || (write_status`CYC_ERR !== 1) )
10562
        begin
10563
            $display("Time %t", $time) ;
10564
            $display("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus!") ;
10565
            test_fail("Configuration Cycle Type1 Write was terminated with Target Abort on PCI Bus but didn't terminate with ERR on WB Bus") ;
10566
            ok_wb = 0 ;
10567
        end
10568
 
10569
        config_read( 12'h4, 4'hF, temp_var ) ;
10570
        if ( temp_var[29] !== 0 )
10571
        begin
10572
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10573
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort!") ;
10574
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated with Target Abort") ;
10575
            ok_wb = 0 ;
10576
        end
10577
 
10578
        if ( temp_var[28] !== 1 )
10579
        begin
10580
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10581
            $display("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort!") ;
10582
            test_fail("Received Target Abort bit was not set when Configuration Type1 Write was terminated with Target Abort") ;
10583
            ok_wb = 0 ;
10584
        end
10585
 
10586
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10587
 
10588
        if (ok !== 1)
10589
        begin
10590
            ok_wb = 0 ;
10591
            $display("Target Abort termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10592
            $display("Write to PCI Device Status Register failed") ;
10593
            test_fail("Write to PCI Device Status Register failed") ;
10594
        end
10595
    end
10596
    begin
10597
        pci_transaction_progress_monitor
10598
        (
10599
            pci_address,                                            // expected address on PCI bus
10600
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10601
            0,                                                      // expected number of succesfull data phases
10602
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10603
            1'b1,                                                   // monitor checking/not checking number of transfers
10604
            1'b0,                                                   // monitor checking/not checking number of cycles
10605
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10606
            ok_pci                                                  // status - 1 success, 0 failure
10607
        ) ;
10608
 
10609
        if (ok_pci)
10610
        begin
10611
            pci_transaction_progress_monitor
10612
            (
10613
                pci_address,                                            // expected address on PCI bus
10614
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10615
                0,                                                      // expected number of succesfull data phases
10616
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10617
                1'b1,                                                   // monitor checking/not checking number of transfers
10618
                1'b0,                                                   // monitor checking/not checking number of cycles
10619
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10620
                ok_pci                                                  // status - 1 success, 0 failure
10621
            ) ;
10622
        end
10623
 
10624
        if (!ok_pci)
10625
        begin
10626
            $display("Time %t", $time) ;
10627
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10628
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10629
        end
10630
    end
10631
    join
10632
 
10633
    if (ok_pci && ok_wb)
10634
    begin
10635
        test_ok ;
10636
    end
10637
 
10638
    test_name = "NORMAL CONFIGURATION CYCLE TYPE1 GENERATION" ;
10639
 
10640
    conf_cyc_type1_target_response = 2'b10 ;  // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10641
    conf_cyc_type1_target_data = 32'h5555_5555 ;
10642
    conf_cyc_type1_target_bus_num = 8'hAA;
10643
 
10644
    pci_address      = 32'hAAAA_AAAA ;
10645
    pci_address[1:0] = 2'b01 ; // indicate Type1 Configuration Cycle
10646
 
10647
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10648
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10649
 
10650
    write_data`WRITE_ADDRESS  = temp_var + { 4'h1, `CNF_ADDR_ADDR, 2'b00 } ;
10651
    write_data`WRITE_DATA     = pci_address ;
10652
    write_data`WRITE_SEL      = 4'hF ;
10653
    write_data`WRITE_TAG_STIM = 0 ;
10654
 
10655
    wishbone_master.wb_single_write(write_data, flags, write_status) ;
10656
 
10657
    // check if write succeeded
10658
    if (write_status`CYC_ACTUAL_TRANSFER !== 1)
10659
    begin
10660
        $display("Configuration cycle Type1 generation failed! Couldn't write to configuration address register! Time %t ", $time) ;
10661
        test_fail("write to configuration cycle address register was not possible") ;
10662
        in_use = 0 ;
10663
        disable main ;
10664
    end
10665
 
10666
    // setup flags for wb master to handle retries and read and write data
10667
    flags`WB_TRANSFER_AUTO_RTY = 1 ;
10668
 
10669
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
10670
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
10671
 
10672
    read_data`READ_ADDRESS      = temp_var + {4'b0001, `CNF_DATA_ADDR, 2'b00} ;
10673
    write_data`WRITE_ADDRESS    = read_data`READ_ADDRESS ;
10674
    read_data`READ_SEL          = 4'b0101 ;
10675
    write_data`WRITE_SEL        = 4'b1010 ;
10676
    read_data`READ_TAG_STIM     = 0 ;
10677
    write_data`WRITE_TAG_STIM   = 0 ;
10678
    write_data`WRITE_DATA       = 32'hAAAA_AAAA ;
10679
 
10680
    ok_pci = 0 ;
10681
    ok_wb  = 1 ;
10682
 
10683
    // bridge sets reserved bits of configuration address to 0 - set pci_address for comparison
10684
    pci_address[31:24] = 0 ;
10685
 
10686
    fork
10687
    begin
10688
        wishbone_master.wb_single_read(read_data, flags, read_status) ;
10689
        if ( read_status`CYC_ACTUAL_TRANSFER !== 1 )
10690
        begin
10691
            $display("Time %t", $time) ;
10692
            $display("Configuration Cycle Type1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10693
            test_fail("Configuration Cycle Type 1 Read was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10694
            ok_wb = 0 ;
10695
        end
10696
 
10697
        config_read( 12'h4, 4'hF, temp_var ) ;
10698
        if ( temp_var[29] !== 0 )
10699
        begin
10700
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10701
            $display("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10702
            test_fail("Received Master Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10703
            ok_wb = 0 ;
10704
        end
10705
 
10706
        if ( temp_var[28] !== 0 )
10707
        begin
10708
            $display("Normal termination of Configuration Cycle Type 1 testing failed! Time %t ", $time) ;
10709
            $display("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly!") ;
10710
            test_fail("Received Target Abort bit was set when Configuration Type1 Read was terminated normaly") ;
10711
            ok_wb = 0 ;
10712
        end
10713
 
10714
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10715
 
10716
        if (ok !== 1)
10717
        begin
10718
            ok_wb = 0 ;
10719
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10720
            $display("Write to PCI Device Status Register failed") ;
10721
            test_fail("Write to PCI Device Status Register failed") ;
10722
        end
10723
 
10724
        if (read_status`READ_DATA !== 32'hDE55_BE55)
10725
        begin
10726
            ok_wb = 0 ;
10727
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10728
            $display("Read Data provided by the bridge was not as expected!") ;
10729
            test_fail("Read Data provided by the bridge was not as expected") ;
10730
        end
10731
 
10732
        wishbone_master.wb_single_write(write_data, flags, write_status) ;
10733
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
10734
        begin
10735
            $display("Time %t", $time) ;
10736
            $display("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus!") ;
10737
            test_fail("Configuration Cycle Type1 Write was terminated normaly on PCI Bus but didn't terminate with ACK on WB Bus") ;
10738
            ok_wb = 0 ;
10739
        end
10740
 
10741
        config_read( 12'h4, 4'hF, temp_var ) ;
10742
        if ( temp_var[29] !== 0 )
10743
        begin
10744
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10745
            $display("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10746
            test_fail("Received Master Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10747
            ok_wb = 0 ;
10748
        end
10749
 
10750
        if ( temp_var[28] !== 0 )
10751
        begin
10752
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10753
            $display("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly!") ;
10754
            test_fail("Received Target Abort bit was set when Configuration Type1 Write was terminated normaly") ;
10755
            ok_wb = 0 ;
10756
        end
10757
 
10758
        config_write( 12'h4, temp_var, 4'b1100, ok ) ;
10759
 
10760
        if (ok !== 1)
10761
        begin
10762
            ok_wb = 0 ;
10763
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10764
            $display("Write to PCI Device Status Register failed") ;
10765
            test_fail("Write to PCI Device Status Register failed") ;
10766
        end
10767
 
10768
        if (conf_cyc_type1_target_data_from_PCI !== 32'hAAAD_AAAF)
10769
        begin
10770
            ok_wb = 0 ;
10771
            $display("Normal termination of Configuration Cycle Type1 testing failed! Time %t ", $time) ;
10772
            $display("Data written by the bridge was not as expected!") ;
10773
            test_fail("Data written by the bridge was not as expected") ;
10774
        end
10775
 
10776
    end
10777
    begin
10778
        ok = 1 ;
10779
        repeat(8)
10780
        begin
10781
            pci_transaction_progress_monitor
10782
            (
10783
                pci_address,                                            // expected address on PCI bus
10784
                `BC_CONF_READ,                                          // expected bus command on PCI bus
10785
                0,                                                      // expected number of succesfull data phases
10786
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10787
                1'b1,                                                   // monitor checking/not checking number of transfers
10788
                1'b0,                                                   // monitor checking/not checking number of cycles
10789
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10790
                ok_pci                                                  // status - 1 success, 0 failure
10791
            ) ;
10792
 
10793
            if (!ok_pci)
10794
            begin
10795
                ok = 0 ;
10796
                $display("Time %t", $time) ;
10797
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10798
            end
10799
        end
10800
 
10801
        conf_cyc_type1_target_response = 2'b01 ;    // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10802
 
10803
        pci_transaction_progress_monitor
10804
        (
10805
            pci_address,                                            // expected address on PCI bus
10806
            `BC_CONF_READ,                                          // expected bus command on PCI bus
10807
            1,                                                      // expected number of succesfull data phases
10808
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10809
            1'b1,                                                   // monitor checking/not checking number of transfers
10810
            1'b0,                                                   // monitor checking/not checking number of cycles
10811
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10812
            ok_pci                                                  // status - 1 success, 0 failure
10813
        ) ;
10814
 
10815
        if (!ok_pci)
10816
        begin
10817
            ok = 0 ;
10818
            $display("Time %t", $time) ;
10819
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10820
        end
10821
 
10822
        conf_cyc_type1_target_response = 2'b10 ;              // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10823
        repeat(8)
10824
        begin
10825
            pci_transaction_progress_monitor
10826
            (
10827
                pci_address,                                            // expected address on PCI bus
10828
                `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10829
                0,                                                      // expected number of succesfull data phases
10830
                0,                                                      // expected number of cycles the transaction will take on PCI bus
10831
                1'b1,                                                   // monitor checking/not checking number of transfers
10832
                1'b0,                                                   // monitor checking/not checking number of cycles
10833
                0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10834
                ok_pci                                                  // status - 1 success, 0 failure
10835
            ) ;
10836
 
10837
            if (!ok_pci)
10838
            begin
10839
                ok = 0 ;
10840
                $display("Time %t", $time) ;
10841
                $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10842
            end
10843
        end
10844
 
10845
        conf_cyc_type1_target_response = 2'b00 ;            // 0 = normal completion, 1 = disconnect with data, 2 = retry, 3 = Target Abort
10846
        pci_transaction_progress_monitor
10847
        (
10848
            pci_address,                                            // expected address on PCI bus
10849
            `BC_CONF_WRITE,                                         // expected bus command on PCI bus
10850
            1,                                                      // expected number of succesfull data phases
10851
            0,                                                      // expected number of cycles the transaction will take on PCI bus
10852
            1'b1,                                                   // monitor checking/not checking number of transfers
10853
            1'b0,                                                   // monitor checking/not checking number of cycles
10854
            0,                                                      // tell to monitor if it has to expect a fast back to back transaction
10855
            ok_pci                                                  // status - 1 success, 0 failure
10856
        ) ;
10857
 
10858
        if (!ok_pci)
10859
        begin
10860
            ok = 0 ;
10861
            $display("Time %t", $time) ;
10862
            $display("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10863
        end
10864
 
10865
        if (!ok)
10866
            test_fail("PCI Transaction Progress Monitor detected invalid transaction during testing") ;
10867
    end
10868
    join
10869
 
10870
    if (ok_pci && ok_wb)
10871
    begin
10872
        test_ok ;
10873
    end
10874
 
10875
    in_use = 0 ;
10876
end
10877
endtask // test_configuration_cycle_type1_generation
10878
`endif
10879
 
10880
task test_initial_conf_values ;
10881
    reg [11:0] register_offset ;
10882
    reg [31:0] expected_value ;
10883
    reg        failed ;
10884
`ifdef HOST
10885
    reg `READ_STIM_TYPE    read_data ;
10886
    reg `WB_TRANSFER_FLAGS flags ;
10887
    reg `READ_RETURN_TYPE  read_status ;
10888
 
10889
    reg `WRITE_STIM_TYPE   write_data ;
10890
    reg `WRITE_RETURN_TYPE write_status ;
10891
begin
10892
    failed     = 0 ;
10893
    test_name  = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
10894
    flags      = 0 ;
10895
    read_data  = 0 ;
10896
    write_data = 0 ;
10897
 
10898
    read_data`READ_SEL = 4'hF ;
10899
 
10900
    flags`INIT_WAITS           = tb_init_waits ;
10901
    flags`SUBSEQ_WAITS         = tb_subseq_waits ;
10902
 
10903
    // test MEM/IO map bit initial value in each PCI BAR
10904
    register_offset = {1'b1, `P_BA0_ADDR, 2'b00} ;
10905
 
10906
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10907
 
10908 15 mihad
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10909
 
10910 45 mihad
    `ifdef NO_CNF_IMAGE
10911
        `ifdef PCI_IMAGE0
10912
            if (`PCI_AM0)
10913
                expected_value = `PCI_BA0_MEM_IO ;
10914
            else
10915
                expected_value = 32'h0000_0000 ;
10916
        `else
10917
            expected_value = 32'h0000_0000 ;
10918
        `endif
10919
    `else
10920
        expected_value = 32'h0000_0000 ;
10921
    `endif
10922
 
10923 15 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10924
    begin
10925 45 mihad
        test_fail("read from P_BA0 register didn't succeede") ;
10926
        failed = 1 ;
10927 15 mihad
    end
10928 45 mihad
    else
10929
    begin
10930
        if (read_status`READ_DATA !== expected_value)
10931
        begin
10932
            test_fail("BA0 MEM/IO initial bit value was not set as defined");
10933
            failed = 1 ;
10934
        end
10935
    end
10936 15 mihad
 
10937 45 mihad
    register_offset = {1'b1, `P_BA1_ADDR, 2'b00} ;
10938 15 mihad
 
10939 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10940
 
10941
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10942
 
10943
    if (`PCI_AM1)
10944
        expected_value = `PCI_BA1_MEM_IO ;
10945
    else
10946
        expected_value = 32'h0000_0000 ;
10947
 
10948
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10949
    begin
10950
        test_fail("read from P_BA1 register didn't succeede") ;
10951
        failed = 1 ;
10952
    end
10953
    else
10954
    begin
10955
        if (read_status`READ_DATA !== expected_value)
10956
        begin
10957
            test_fail("BA1 MEM/IO initial bit value was not set as defined");
10958
            failed = 1 ;
10959
        end
10960
    end
10961
 
10962
    register_offset = {1'b1, `P_BA2_ADDR, 2'b00} ;
10963
 
10964
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10965
 
10966
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10967
 
10968
    `ifdef PCI_IMAGE2
10969
        if (`PCI_AM2)
10970
            expected_value = `PCI_BA2_MEM_IO ;
10971
        else
10972
            expected_value = 32'h0000_0000 ;
10973 15 mihad
    `else
10974 45 mihad
        expected_value = 32'h0000_0000 ;
10975
    `endif
10976 15 mihad
 
10977 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
10978
    begin
10979
        test_fail("read from P_BA2 register didn't succeede") ;
10980
        failed = 1 ;
10981
    end
10982
    else
10983
    begin
10984
        if (read_status`READ_DATA !== expected_value)
10985
        begin
10986
            test_fail("BA2 MEM/IO initial bit value was not set as defined");
10987
            failed = 1 ;
10988
        end
10989
    end
10990 15 mihad
 
10991 45 mihad
    register_offset = {1'b1, `P_BA3_ADDR, 2'b00} ;
10992
 
10993
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
10994
 
10995
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
10996
 
10997
    `ifdef PCI_IMAGE3
10998
        if (`PCI_AM3)
10999
            expected_value = `PCI_BA3_MEM_IO ;
11000
        else
11001
            expected_value = 32'h0000_0000 ;
11002
    `else
11003
        expected_value = 32'h0000_0000 ;
11004 15 mihad
    `endif
11005 45 mihad
 
11006
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11007
    begin
11008
        test_fail("read from P_BA3 register didn't succeede") ;
11009
        failed = 1 ;
11010
    end
11011
    else
11012
    begin
11013
        if (read_status`READ_DATA !== expected_value)
11014
        begin
11015
            test_fail("BA3 MEM/IO initial bit value was not set as defined");
11016
            failed = 1 ;
11017
        end
11018
    end
11019
 
11020
    register_offset = {1'b1, `P_BA4_ADDR, 2'b00} ;
11021
 
11022
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11023
 
11024
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11025
 
11026
    `ifdef PCI_IMAGE4
11027
        if (`PCI_AM4)
11028
            expected_value = `PCI_BA4_MEM_IO ;
11029
        else
11030
            expected_value = 32'h0000_0000 ;
11031
    `else
11032
        expected_value = 32'h0000_0000 ;
11033 15 mihad
    `endif
11034
 
11035 45 mihad
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11036
    begin
11037
        test_fail("read from P_BA4 register didn't succeede") ;
11038
        failed = 1 ;
11039
    end
11040
    else
11041
    begin
11042
        if (read_status`READ_DATA !== expected_value)
11043
        begin
11044
            test_fail("BA4 MEM/IO initial bit value was not set as defined");
11045
            failed = 1 ;
11046
        end
11047
    end
11048 15 mihad
 
11049 45 mihad
    register_offset = {1'b1, `P_BA5_ADDR, 2'b00} ;
11050 15 mihad
 
11051 45 mihad
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11052
 
11053
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11054
 
11055
    `ifdef PCI_IMAGE5
11056
        if(`PCI_AM5)
11057
            expected_value = `PCI_BA5_MEM_IO ;
11058
        else
11059
            expected_value = 32'h0000_0000 ;
11060
    `else
11061
        expected_value = 32'h0000_0000 ;
11062
    `endif
11063
 
11064
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11065
    begin
11066
        test_fail("read from P_BA5 register didn't succeede") ;
11067
        failed = 1 ;
11068
    end
11069
    else
11070
    begin
11071
        if (read_status`READ_DATA !== expected_value)
11072
        begin
11073
            test_fail("BA5 MEM/IO initial bit value was not set as defined");
11074
            failed = 1 ;
11075
        end
11076
    end
11077
 
11078
    // test Address Mask initial values
11079
    register_offset = {1'b1, `P_AM0_ADDR, 2'b00} ;
11080
 
11081
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11082
 
11083
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11084
 
11085
    `ifdef NO_CNF_IMAGE
11086
        `ifdef PCI_IMAGE0
11087
            expected_value = {`PCI_AM0, 12'h000};
11088
 
11089
            expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11090
        `else
11091
            expected_value = 32'h0000_0000 ;
11092
        `endif
11093
    `else
11094
        expected_value = 32'hFFFF_FFFF ;
11095
 
11096
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11097
    `endif
11098
 
11099
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11100
    begin
11101
        test_fail("read from P_AM0 register didn't succeede") ;
11102
        failed = 1 ;
11103
    end
11104
    else
11105
    begin
11106
        if (read_status`READ_DATA !== expected_value)
11107
        begin
11108
            test_fail("AM0 initial value was not set as defined");
11109
            failed = 1 ;
11110
        end
11111
    end
11112
 
11113
    register_offset = {1'b1, `P_AM1_ADDR, 2'b00} ;
11114
 
11115
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11116
 
11117
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11118
 
11119
    expected_value = {`PCI_AM1, 12'h000};
11120
 
11121
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11122
 
11123
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11124
    begin
11125
        test_fail("read from P_AM1 register didn't succeede") ;
11126
        failed = 1 ;
11127
    end
11128
    else
11129
    begin
11130
        if (read_status`READ_DATA !== expected_value)
11131
        begin
11132
            test_fail("AM1 initial value was not set as defined");
11133
            failed = 1 ;
11134
        end
11135
    end
11136
 
11137
    register_offset = {1'b1, `P_AM2_ADDR, 2'b00} ;
11138
 
11139
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11140
 
11141
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11142
 
11143
    `ifdef PCI_IMAGE2
11144
        expected_value = {`PCI_AM2, 12'h000};
11145
 
11146
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11147
    `else
11148
        expected_value = 32'h0000_0000 ;
11149
    `endif
11150
 
11151
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11152
    begin
11153
        test_fail("read from P_AM2 register didn't succeede") ;
11154
        failed = 1 ;
11155
    end
11156
    else
11157
    begin
11158
        if (read_status`READ_DATA !== expected_value)
11159
        begin
11160
            test_fail("AM2 initial value was not set as defined");
11161
            failed = 1 ;
11162
        end
11163
    end
11164
 
11165
    register_offset = {1'b1, `P_AM3_ADDR, 2'b00} ;
11166
 
11167
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11168
 
11169
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11170
 
11171
    `ifdef PCI_IMAGE3
11172
        expected_value = {`PCI_AM3, 12'h000};
11173
 
11174
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11175
    `else
11176
        expected_value = 32'h0000_0000 ;
11177
    `endif
11178
 
11179
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11180
    begin
11181
        test_fail("read from P_AM3 register didn't succeede") ;
11182
        failed = 1 ;
11183
    end
11184
    else
11185
    begin
11186
        if (read_status`READ_DATA !== expected_value)
11187
        begin
11188
            test_fail("AM3 initial value was not set as defined");
11189
            failed = 1 ;
11190
        end
11191
    end
11192
 
11193
    register_offset = {1'b1, `P_AM4_ADDR, 2'b00} ;
11194
 
11195
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11196
 
11197
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11198
 
11199
    `ifdef PCI_IMAGE4
11200
        expected_value = {`PCI_AM4, 12'h000};
11201
 
11202
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11203
    `else
11204
        expected_value = 32'h0000_0000 ;
11205
    `endif
11206
 
11207
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11208
    begin
11209
        test_fail("read from P_AM4 register didn't succeede") ;
11210
        failed = 1 ;
11211
    end
11212
    else
11213
    begin
11214
        if (read_status`READ_DATA !== expected_value)
11215
        begin
11216
            test_fail("AM4 initial value was not set as defined");
11217
            failed = 1 ;
11218
        end
11219
    end
11220
 
11221
    register_offset = {1'b1, `P_AM5_ADDR, 2'b00} ;
11222
 
11223
    read_data`READ_ADDRESS = {`WB_CONFIGURATION_BASE, register_offset} ;
11224
 
11225
    wishbone_master.wb_single_read(read_data, flags, read_status) ;
11226
 
11227
    `ifdef PCI_IMAGE5
11228
        expected_value = {`PCI_AM5, 12'h000};
11229
 
11230
        expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11231
    `else
11232
        expected_value = 32'h0000_0000 ;
11233
    `endif
11234
 
11235
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
11236
    begin
11237
        test_fail("read from P_AM5 register didn't succeede") ;
11238
        failed = 1 ;
11239
    end
11240
    else
11241
    begin
11242
        if (read_status`READ_DATA !== expected_value)
11243
        begin
11244
            test_fail("AM5 initial value was not set as defined");
11245
            failed = 1 ;
11246
        end
11247
    end
11248
 
11249
`endif
11250
 
11251
`ifdef GUEST
11252
    reg [31:0] read_data ;
11253
begin
11254
    test_name = "DEFINED INITIAL VALUES OF CONFIGURATION REGISTERS" ;
11255
    failed    = 0 ;
11256
 
11257
    // check all images' BARs
11258
 
11259
    // BAR0
11260
    configuration_cycle_read
11261
    (
11262
        8'h00,                          // bus number [7:0]
11263
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11264
        3'h0,                           // function number [2:0]
11265
        6'h4,                           // register number [5:0]
11266
        2'h0,                           // type [1:0]
11267
        4'hF,                           // byte enables [3:0]
11268
        read_data                       // data returned from configuration read [31:0]
11269
    ) ;
11270
 
11271
    expected_value = 32'h0000_0000 ;
11272
 
11273
    if( read_data !== expected_value)
11274
    begin
11275
        test_fail("initial value of BAR0 register not as expected") ;
11276
        failed = 1 ;
11277
    end
11278
 
11279
    // BAR1
11280
    configuration_cycle_read
11281
    (
11282
        8'h00,                          // bus number [7:0]
11283
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11284
        3'h0,                           // function number [2:0]
11285
        6'h5,                           // register number [5:0]
11286
        2'h0,                           // type [1:0]
11287
        4'hF,                           // byte enables [3:0]
11288
        read_data                       // data returned from configuration read [31:0]
11289
    ) ;
11290
 
11291
    if (`PCI_AM1)
11292
        expected_value = `PCI_BA1_MEM_IO ;
11293
    else
11294
        expected_value = 32'h0000_0000 ;
11295
 
11296
    if( read_data !== expected_value)
11297
    begin
11298
        test_fail("initial value of BAR1 register not as expected") ;
11299
        failed = 1 ;
11300
    end
11301
 
11302
    // BAR2
11303
    configuration_cycle_read
11304
    (
11305
        8'h00,                          // bus number [7:0]
11306
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11307
        3'h0,                           // function number [2:0]
11308
        6'h6,                           // register number [5:0]
11309
        2'h0,                           // type [1:0]
11310
        4'hF,                           // byte enables [3:0]
11311
        read_data                       // data returned from configuration read [31:0]
11312
    ) ;
11313
 
11314
    `ifdef PCI_IMAGE2
11315
    if (`PCI_AM2)
11316
        expected_value = `PCI_BA2_MEM_IO ;
11317
    else
11318
        expected_value = 32'h0000_0000 ;
11319
    `else
11320
    expected_value = 32'h0 ;
11321
    `endif
11322
 
11323
    if( read_data !== expected_value)
11324
    begin
11325
        test_fail("initial value of BAR2 register not as expected") ;
11326
        failed = 1 ;
11327
    end
11328
 
11329
    // BAR3
11330
    configuration_cycle_read
11331
    (
11332
        8'h00,                          // bus number [7:0]
11333
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11334
        3'h0,                           // function number [2:0]
11335
        6'h7,                           // register number [5:0]
11336
        2'h0,                           // type [1:0]
11337
        4'hF,                           // byte enables [3:0]
11338
        read_data                       // data returned from configuration read [31:0]
11339
    ) ;
11340
 
11341
    `ifdef PCI_IMAGE3
11342
    if(`PCI_AM3)
11343
        expected_value = `PCI_BA3_MEM_IO ;
11344
    else
11345
        expected_value = 32'h0000_0000 ;
11346
    `else
11347
    expected_value = 32'h0 ;
11348
    `endif
11349
 
11350
    if( read_data !== expected_value)
11351
    begin
11352
        test_fail("initial value of BAR3 register not as expected") ;
11353
        failed = 1 ;
11354
    end
11355
 
11356
    // BAR4
11357
    configuration_cycle_read
11358
    (
11359
        8'h00,                          // bus number [7:0]
11360
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11361
        3'h0,                           // function number [2:0]
11362
        6'h8,                           // register number [5:0]
11363
        2'h0,                           // type [1:0]
11364
        4'hF,                           // byte enables [3:0]
11365
        read_data                       // data returned from configuration read [31:0]
11366
    ) ;
11367
 
11368
    `ifdef PCI_IMAGE4
11369
    if (`PCI_AM4)
11370
        expected_value = `PCI_BA4_MEM_IO ;
11371
    else
11372
        expected_value = 32'h0000_0000 ;
11373
    `else
11374
    expected_value = 32'h0 ;
11375
    `endif
11376
 
11377
    if( read_data !== expected_value)
11378
    begin
11379
        test_fail("initial value of BAR4 register not as expected") ;
11380
        failed = 1 ;
11381
    end
11382
 
11383
    // BAR5
11384
    configuration_cycle_read
11385
    (
11386
        8'h00,                          // bus number [7:0]
11387
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11388
        3'h0,                           // function number [2:0]
11389
        6'h9,                           // register number [5:0]
11390
        2'h0,                           // type [1:0]
11391
        4'hF,                           // byte enables [3:0]
11392
        read_data                       // data returned from configuration read [31:0]
11393
    ) ;
11394
 
11395
    `ifdef PCI_IMAGE5
11396
    if(`PCI_AM5)
11397
        expected_value = `PCI_BA5_MEM_IO ;
11398
    else
11399
        expected_value = 32'h0000_0000 ;
11400
    `else
11401
    expected_value = 32'h0 ;
11402
    `endif
11403
 
11404
    if( read_data !== expected_value)
11405
    begin
11406
        test_fail("initial value of BAR5 register not as expected") ;
11407
        failed = 1 ;
11408
    end
11409
 
11410
    // write all 1s to BAR0
11411
    read_data = 32'hFFFF_FFFF ;
11412
 
11413
    // BAR0
11414
    configuration_cycle_write
11415
    (
11416
        8'h00,                          // bus number [7:0]
11417
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11418
        3'h0,                           // function number [2:0]
11419
        6'h4,                           // register number [5:0]
11420
        2'h0,                           // type [1:0]
11421
        4'hF,                           // byte enables [3:0]
11422
        read_data                       // data to write [31:0]
11423
    ) ;
11424
 
11425
    expected_value = 32'hFFFF_FFFF ;
11426
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11427
 
11428
    configuration_cycle_read
11429
    (
11430
        8'h00,                          // bus number [7:0]
11431
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11432
        3'h0,                           // function number [2:0]
11433
        6'h4,                           // register number [5:0]
11434
        2'h0,                           // type [1:0]
11435
        4'hF,                           // byte enables [3:0]
11436
        read_data                       // data to write [31:0]
11437
    ) ;
11438
 
11439
    if ( read_data !== expected_value )
11440
    begin
11441
        test_fail("BAR0 value was not masked correctly during configuration read") ;
11442
        failed = 1 ;
11443
    end
11444
 
11445
    // write all 1s to BAR1
11446
    read_data = 32'hFFFF_FFFF ;
11447
 
11448
    // BAR1
11449
    configuration_cycle_write
11450
    (
11451
        8'h00,                          // bus number [7:0]
11452
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11453
        3'h0,                           // function number [2:0]
11454
        6'h5,                           // register number [5:0]
11455
        2'h0,                           // type [1:0]
11456
        4'hF,                           // byte enables [3:0]
11457
        read_data                       // data to write [31:0]
11458
    ) ;
11459
 
11460
    expected_value = {`PCI_AM1, 12'h000} ;
11461
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11462
    if (`PCI_AM1)
11463
        expected_value[0] = `PCI_BA1_MEM_IO ;
11464
 
11465
    configuration_cycle_read
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'h5,                           // 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
    if ( read_data !== expected_value )
11477
    begin
11478
        test_fail("BAR1 value was not masked correctly during configuration read") ;
11479
        failed = 1 ;
11480
    end
11481
 
11482
    // write all 1s to BAR2
11483
    read_data = 32'hFFFF_FFFF ;
11484
 
11485
    // BAR2
11486
    configuration_cycle_write
11487
    (
11488
        8'h00,                          // bus number [7:0]
11489
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11490
        3'h0,                           // function number [2:0]
11491
        6'h6,                           // register number [5:0]
11492
        2'h0,                           // type [1:0]
11493
        4'hF,                           // byte enables [3:0]
11494
        read_data                       // data to write [31:0]
11495
    ) ;
11496
 
11497
`ifdef PCI_IMAGE2
11498
    expected_value = {`PCI_AM2, 12'h000} ;
11499
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11500
    if (`PCI_AM2)
11501
        expected_value[0] = `PCI_BA2_MEM_IO ;
11502
`else
11503
    expected_value = 0 ;
11504
`endif
11505
 
11506
    configuration_cycle_read
11507
    (
11508
        8'h00,                          // bus number [7:0]
11509
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11510
        3'h0,                           // function number [2:0]
11511
        6'h6,                           // register number [5:0]
11512
        2'h0,                           // type [1:0]
11513
        4'hF,                           // byte enables [3:0]
11514
        read_data                       // data to write [31:0]
11515
    ) ;
11516
 
11517
    if ( read_data !== expected_value )
11518
    begin
11519
        test_fail("BAR2 value was not masked correctly during configuration read") ;
11520
        failed = 1 ;
11521
    end
11522
 
11523
    // write all 1s to BAR3
11524
    read_data = 32'hFFFF_FFFF ;
11525
 
11526
    // BAR3
11527
    configuration_cycle_write
11528
    (
11529
        8'h00,                          // bus number [7:0]
11530
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11531
        3'h0,                           // function number [2:0]
11532
        6'h7,                           // register number [5:0]
11533
        2'h0,                           // type [1:0]
11534
        4'hF,                           // byte enables [3:0]
11535
        read_data                       // data to write [31:0]
11536
    ) ;
11537
 
11538
`ifdef PCI_IMAGE3
11539
    expected_value = {`PCI_AM3, 12'h000} ;
11540
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11541
    if(`PCI_AM3)
11542
        expected_value[0] = `PCI_BA3_MEM_IO ;
11543
`else
11544
    expected_value = 0 ;
11545
`endif
11546
 
11547
    configuration_cycle_read
11548
    (
11549
        8'h00,                          // bus number [7:0]
11550
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11551
        3'h0,                           // function number [2:0]
11552
        6'h7,                           // register number [5:0]
11553
        2'h0,                           // type [1:0]
11554
        4'hF,                           // byte enables [3:0]
11555
        read_data                       // data to write [31:0]
11556
    ) ;
11557
 
11558
    if ( read_data !== expected_value )
11559
    begin
11560
        test_fail("BAR3 value was not masked correctly during configuration read") ;
11561
        failed = 1 ;
11562
    end
11563
 
11564
    // write all 1s to BAR4
11565
    read_data = 32'hFFFF_FFFF ;
11566
 
11567
    // BAR4
11568
    configuration_cycle_write
11569
    (
11570
        8'h00,                          // bus number [7:0]
11571
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11572
        3'h0,                           // function number [2:0]
11573
        6'h8,                           // register number [5:0]
11574
        2'h0,                           // type [1:0]
11575
        4'hF,                           // byte enables [3:0]
11576
        read_data                       // data to write [31:0]
11577
    ) ;
11578
 
11579
`ifdef PCI_IMAGE4
11580
    expected_value = {`PCI_AM4, 12'h000} ;
11581
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11582
    if(`PCI_AM4)
11583
        expected_value[0] = `PCI_BA4_MEM_IO ;
11584
`else
11585
    expected_value = 0 ;
11586
`endif
11587
 
11588
    configuration_cycle_read
11589
    (
11590
        8'h00,                          // bus number [7:0]
11591
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11592
        3'h0,                           // function number [2:0]
11593
        6'h8,                           // register number [5:0]
11594
        2'h0,                           // type [1:0]
11595
        4'hF,                           // byte enables [3:0]
11596
        read_data                       // data to write [31:0]
11597
    ) ;
11598
 
11599
    if ( read_data !== expected_value )
11600
    begin
11601
        test_fail("BAR4 value was not masked correctly during configuration read") ;
11602
        failed = 1 ;
11603
    end
11604
 
11605
    // write all 1s to BAR5
11606
    read_data = 32'hFFFF_FFFF ;
11607
 
11608
    // BAR5
11609
    configuration_cycle_write
11610
    (
11611
        8'h00,                          // bus number [7:0]
11612
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11613
        3'h0,                           // function number [2:0]
11614
        6'h9,                           // register number [5:0]
11615
        2'h0,                           // type [1:0]
11616
        4'hF,                           // byte enables [3:0]
11617
        read_data                       // data to write [31:0]
11618
    ) ;
11619
 
11620
`ifdef PCI_IMAGE5
11621
    expected_value = {`PCI_AM5, 12'h000} ;
11622
    expected_value[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
11623
    if(`PCI_AM5)
11624
        expected_value[0] = `PCI_BA5_MEM_IO ;
11625
`else
11626
    expected_value = 0 ;
11627
`endif
11628
 
11629
    configuration_cycle_read
11630
    (
11631
        8'h00,                          // bus number [7:0]
11632
        `TAR0_IDSEL_INDEX - 11,         // device number [4:0]
11633
        3'h0,                           // function number [2:0]
11634
        6'h9,                           // register number [5:0]
11635
        2'h0,                           // type [1:0]
11636
        4'hF,                           // byte enables [3:0]
11637
        read_data                       // data to write [31:0]
11638
    ) ;
11639
 
11640
    if ( read_data !== expected_value )
11641
    begin
11642
        test_fail("BAR5 value was not masked correctly during configuration read") ;
11643
        failed = 1 ;
11644
    end
11645
`endif
11646
 
11647
    if (!failed)
11648
        test_ok ;
11649
end
11650
endtask
11651
 
11652 15 mihad
task display_warning;
11653
    input [31:0] error_address ;
11654
    input [31:0] expected_data ;
11655
    input [31:0] actual ;
11656
begin
11657
    $display("Read from address %h produced wrong result! \nExpected value was %h\tread value was %h!", error_address, expected_data, actual) ;
11658
end
11659
endtask // display warning
11660
 
11661
/*############################################################################
11662
PCI TARGET UNIT tasks (some general tasks from WB SLAVE UNIT also used)
11663
=====================
11664
############################################################################*/
11665
 
11666
// Task reslease the PCI bus for 'delay' clocks
11667
task do_pause;
11668
  input  [15:0] delay;
11669
  reg    [15:0] cnt;
11670
  begin
11671
    test_start <= 1'b0;  // no device is allowed to take this
11672
    for (cnt = 16'h0000; cnt[15:0] < delay[15:0]; cnt[15:0] = cnt[15:0] + 16'h0001)
11673
    begin
11674
      if (~pci_reset_comb)
11675
      begin
11676
           @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11677
      end
11678
      `NO_ELSE;
11679
    end
11680
  end
11681
endtask // do_pause
11682
 
11683
// Reference task for using pci_behavioral_master! (from Blue Beaver)
11684
task DO_REF;
11685
  input  [79:0] name;
11686
  input  [2:0] master_number;
11687
  input  [PCI_BUS_DATA_RANGE:0] address;
11688
  input  [3:0] command;
11689
  input  [PCI_BUS_DATA_RANGE:0] data;
11690
  input  [PCI_BUS_CBE_RANGE:0] byte_enables_l;
11691
  input  [9:0] size;
11692
  input   make_addr_par_error, make_data_par_error;
11693
  input  [7:0] master_wait_states;
11694
  input  [7:0] target_wait_states;
11695
  input  [1:0] target_devsel_speed;
11696
  input   fast_back_to_back;
11697
  input  [2:0] target_termination;
11698
  input   expect_master_abort;
11699
  reg     waiting;
11700
  begin
11701
// Cautiously wait for previous command to be done
11702
    for (waiting = test_accepted_l_int; waiting != 1'b0; waiting = waiting)
11703
    begin
11704
      if (~pci_reset_comb && (test_accepted_l_int == 1'b0))
11705
      begin
11706
        if (~pci_reset_comb)
11707
        begin
11708
             @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11709
        end
11710
        `NO_ELSE;
11711
      end
11712
      else
11713
      begin
11714
        waiting = 1'b0;  // ready to do next command
11715
      end
11716
    end
11717
    next_test_name[79:0] <= name[79:0];
11718
    test_master_number <= master_number[2:0];
11719
    test_address[PCI_BUS_DATA_RANGE:0] <= address[PCI_BUS_DATA_RANGE:0];
11720
    test_command[3:0] <= command[3:0] ;
11721
    test_data[PCI_BUS_DATA_RANGE:0] <= data[PCI_BUS_DATA_RANGE:0];
11722
    test_byte_enables_l[PCI_BUS_CBE_RANGE:0] <= byte_enables_l[PCI_BUS_CBE_RANGE:0];
11723
    test_size <= size;
11724
    test_make_addr_par_error <= make_addr_par_error;
11725
    test_make_data_par_error <= make_data_par_error;
11726
    test_master_initial_wait_states <= 4 - tb_init_waits ;
11727
    test_master_subsequent_wait_states <= 4 - tb_subseq_waits ;
11728
    test_target_initial_wait_states <= target_wait_states[7:4];
11729
    test_target_subsequent_wait_states <= target_wait_states[3:0];
11730
    test_target_devsel_speed <= target_devsel_speed[1:0];
11731
    test_fast_back_to_back <= fast_back_to_back;
11732
    test_target_termination <= target_termination[2:0];
11733
    test_expect_master_abort <= expect_master_abort;
11734
    test_start <= 1'b1;
11735
    if (~pci_reset_comb)
11736
    begin
11737
      @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11738
    end
11739
    `NO_ELSE;
11740
// wait for new command to start
11741
    for (waiting = 1'b1; waiting != 1'b0; waiting = waiting)
11742
    begin
11743
      if (~pci_reset_comb && (test_accepted_l_int == 1'b1))
11744
      begin
11745
        if (~pci_reset_comb) @ (negedge pci_ext_clk or posedge pci_reset_comb) ;
11746
      end
11747
      else
11748
      begin
11749
        waiting = 1'b0;  // ready to do next command
11750
      end
11751
    end
11752
  end
11753
endtask // DO_REF
11754
 
11755
// Use Macros defined in pci_defines.vh as paramaters
11756
 
11757
// DO_REF (name[79:0], master_number[2:0],
11758
//          address[PCI_FIFO_DATA_RANGE:0], command[3:0],
11759
//          data[PCI_FIFO_DATA_RANGE:0], byte_enables_l[PCI_FIFO_CBE_RANGE:0], size[3:0],
11760
//          make_addr_par_error, make_data_par_error,
11761
//          master_wait_states[8:0], target_wait_states[8:0],
11762
//          target_devsel_speed[1:0], fast_back_to_back,
11763
//          target_termination[2:0],
11764
//          expect_master_abort);
11765
//
11766
// Example:
11767
//      DO_REF ("CFG_R_MA_0", `Test_Master_1, 32'h12345678, `Config_Read,
11768
//                32'h76543210, `Test_All_Bytes, `Test_No_Data,
11769
//                `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11770
//                `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_Fast_B2B,
11771
//                `Test_Target_Normal_Completion, `Test_Master_Abort);
11772
 
11773
// Access a location with no high-order bits set, assuring that no device responds
11774
task PCIU_CONFIG_READ_MASTER_ABORT;
11775
  input  [79:0] name;
11776
  input  [2:0] master_number;
11777 51 mihad
  input  [31:0] address ;
11778
  input  [3:0] be ;
11779 15 mihad
  begin
11780 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11781
               PCI_COMMAND_CONFIG_READ, 32'h76543210, ~be, 1,
11782
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11783 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11784
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11785
  end
11786
endtask // PCIU_CONFIG_READ_MASTER_ABORT
11787
 
11788
// Access a location with no high-order bits set, assuring that no device responds
11789
task PCIU_CONFIG_WRITE_MASTER_ABORT;
11790
  input  [79:0] name;
11791
  input  [2:0] master_number;
11792 51 mihad
  input  [31:0] address ;
11793
  input  [3:0] be ;
11794 15 mihad
  begin
11795 51 mihad
    DO_REF (name[79:0], master_number[2:0], address,
11796
               PCI_COMMAND_CONFIG_WRITE, 32'h76543210, ~be, 1,
11797
              `Test_No_Addr_Perr, `Test_No_Data_Perr, `Test_One_Zero_Master_WS,
11798 15 mihad
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11799
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11800
  end
11801
endtask // PCIU_CONFIG_WRITE_MASTER_ABORT
11802
 
11803
// Access a location with no high-order bits set, assuring that no device responds
11804
task PCIU_MEM_READ_MASTER_ABORT;
11805
  input  [79:0] name;
11806
  input  [2:0] master_number;
11807
  input  [9:0] size;
11808
  begin
11809
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11810
               PCI_COMMAND_MEMORY_READ, 32'h76543210, `Test_All_Bytes, size[9:0],
11811
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11812
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11813
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11814
  end
11815
endtask // PCIU_MEM_READ_MASTER_ABORT
11816
 
11817
// Access a location with no high-order bits set, assuring that no device responds
11818
task PCIU_MEM_WRITE_MASTER_ABORT;
11819
  input  [79:0] name;
11820
  input  [2:0] master_number;
11821
  input  [9:0] size;
11822
  begin
11823
    DO_REF (name[79:0], master_number[2:0], `NO_DEVICE_IDSEL_ADDR,
11824
               PCI_COMMAND_MEMORY_WRITE, 32'h76543210, `Test_All_Bytes, size[9:0],
11825
              `Test_Addr_Perr, `Test_Data_Perr, 8'h0_0,
11826
              `Test_One_Zero_Target_WS, `Test_Devsel_Medium, `Test_No_Fast_B2B,
11827
              `Test_Target_Normal_Completion, `Test_Expect_Master_Abort);
11828
  end
11829
endtask // PCIU_MEM_WRITE_MASTER_ABORT
11830
 
11831
// Do variable length transfers with various paramaters
11832
task PCIU_CONFIG_READ;
11833
  input  [79:0] name;
11834
  input  [2:0] master_number;
11835
  input  [PCI_BUS_DATA_RANGE:0] address;
11836
  input  [PCI_BUS_DATA_RANGE:0] data;
11837
  input  [3:0] be ;
11838
  input  [9:0] size;
11839
  input  [7:0] master_wait_states;
11840
  input  [7:0] target_wait_states;
11841
  input  [1:0] target_devsel_speed;
11842
  input  [2:0] target_termination;
11843
  begin
11844
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11845
              PCI_COMMAND_CONFIG_READ, data[PCI_BUS_DATA_RANGE:0], ~be,
11846
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11847
              8'h0_0, target_wait_states[7:0],
11848
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11849
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11850
  end
11851
endtask // PCIU_CONFIG_READ
11852
 
11853
task PCIU_CONFIG_WRITE;
11854
  input  [79:0] name;
11855
  input  [2:0] master_number;
11856
  input  [PCI_BUS_DATA_RANGE:0] address;
11857
  input  [PCI_BUS_DATA_RANGE:0] data;
11858
  input  [3:0] be ;
11859
  input  [9:0] size;
11860
  input  [7:0] master_wait_states;
11861
  input  [7:0] target_wait_states;
11862
  input  [1:0] target_devsel_speed;
11863
  input  [2:0] target_termination;
11864
  begin
11865
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11866
              PCI_COMMAND_CONFIG_WRITE, data[PCI_BUS_DATA_RANGE:0], be,
11867
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11868
              8'h0_0, target_wait_states[7:0],
11869
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11870
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11871
  end
11872
endtask // PCIU_CONFIG_WRITE
11873
 
11874
task PCIU_READ;
11875
  input  [2:0] master_number;
11876
  input  [PCI_BUS_DATA_RANGE:0] address;
11877
  input  [3:0] command;
11878
  input  [PCI_BUS_DATA_RANGE:0] data;
11879
  input  [3:0] byte_en;
11880
  input  [9:0] size;
11881
  input  [7:0] master_wait_states;
11882
  input  [7:0] target_wait_states;
11883
  input  [1:0] target_devsel_speed;
11884
  input  [2:0] target_termination;
11885
  reg    [79:0] name;
11886
  begin
11887
    if (command == `BC_MEM_READ)
11888
        name = "MEM_READ  " ;
11889
    else if (command == `BC_MEM_READ_LN)
11890
        name = "MEM_RD_LN " ;
11891
    else if (command == `BC_MEM_READ_MUL )
11892
        name = "MEM_RD_MUL" ;
11893
    else
11894
        name = "WRONG_READ" ;
11895
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11896
              command[3:0], data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
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_READ
11903
 
11904
task PCIU_MEM_READ;
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  [9:0] size;
11910
  input  [7:0] master_wait_states;
11911
  input  [7:0] target_wait_states;
11912
  input  [1:0] target_devsel_speed;
11913
  input  [2:0] target_termination;
11914
  begin
11915
 
11916
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11917
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
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_MEM_READ
11924
 
11925
task PCIU_IO_READ;
11926
  input  [2:0] master_number;
11927
  input  [PCI_BUS_DATA_RANGE:0] address;
11928
  input  [PCI_BUS_DATA_RANGE:0] data;
11929
  input  [3:0] byte_en ;
11930
  input  [9:0] size;
11931
  input  [2:0] target_termination ;
11932
  begin
11933
 
11934
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11935
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11936
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11937
              8'h0_0, `Test_One_Zero_Target_WS,
11938
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11939
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11940
  end
11941
endtask // PCIU_IO_READ
11942
 
11943
task PCIU_IO_READ_MAKE_PERR;
11944
  input  [2:0] master_number;
11945
  input  [PCI_BUS_DATA_RANGE:0] address;
11946
  input  [PCI_BUS_DATA_RANGE:0] data;
11947
  input  [3:0] byte_en ;
11948
  input  [9:0] size;
11949
  input  [2:0] target_termination ;
11950
  begin
11951
 
11952
    DO_REF ("IO_READ   ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11953
              PCI_COMMAND_IO_READ, data[PCI_BUS_DATA_RANGE:0], byte_en,
11954
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
11955
              8'h0_0, `Test_One_Zero_Target_WS,
11956
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
11957
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11958
  end
11959
endtask // PCIU_IO_READ_MAKE_PERR
11960
 
11961
task PCIU_MEM_READ_LN;
11962
  input  [79:0] name;
11963
  input  [2:0] master_number;
11964
  input  [PCI_BUS_DATA_RANGE:0] address;
11965
  input  [PCI_BUS_DATA_RANGE:0] data;
11966
  input  [9:0] size;
11967
  input  [7:0] master_wait_states;
11968
  input  [7:0] target_wait_states;
11969
  input  [1:0] target_devsel_speed;
11970
  input  [2:0] target_termination;
11971
  begin
11972
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11973
              PCI_COMMAND_MEMORY_READ_LINE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11974
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11975
              8'h0_0, target_wait_states[7:0],
11976
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11977
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11978
  end
11979
endtask // PCIU_MEM_READ_LN
11980
 
11981
task PCIU_MEM_READ_MUL;
11982
  input  [79:0] name;
11983
  input  [2:0] master_number;
11984
  input  [PCI_BUS_DATA_RANGE:0] address;
11985
  input  [PCI_BUS_DATA_RANGE:0] data;
11986
  input  [9:0] size;
11987
  input  [7:0] master_wait_states;
11988
  input  [7:0] target_wait_states;
11989
  input  [1:0] target_devsel_speed;
11990
  input  [2:0] target_termination;
11991
  begin
11992
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
11993
              PCI_COMMAND_MEMORY_READ_MULTIPLE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
11994
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
11995
              8'h0_0, target_wait_states[7:0],
11996
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
11997
              target_termination[2:0], `Test_Expect_No_Master_Abort);
11998
  end
11999
endtask // PCIU_MEM_READ_MUL
12000
 
12001
task PCIU_MEM_READ_MAKE_PERR;
12002
  input  [79:0] name;
12003
  input  [2:0] master_number;
12004
  input  [PCI_BUS_DATA_RANGE:0] address;
12005
  input  [PCI_BUS_DATA_RANGE:0] data;
12006
  input  [9:0] size;
12007
  input  [7:0] master_wait_states;
12008
  input  [7:0] target_wait_states;
12009
  input  [1:0] target_devsel_speed;
12010
  input  [2:0] target_termination;
12011
  begin
12012
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12013
              PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12014
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12015
              8'h0_0, target_wait_states[7:0],
12016
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12017
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12018
  end
12019
endtask // PCIU_MEM_READ_MAKE_PERR
12020
 
12021
task PCIU_MEM_WRITE;
12022
  input  [79:0] name;
12023
  input  [2:0] master_number;
12024
  input  [PCI_BUS_DATA_RANGE:0] address;
12025
  input  [PCI_BUS_DATA_RANGE:0] data;
12026
  input  [3:0] byte_en;
12027
  input  [9:0] size;
12028
  input  [7:0] master_wait_states;
12029
  input  [7:0] target_wait_states;
12030
  input  [1:0] target_devsel_speed;
12031
  input  [2:0] target_termination;
12032
  begin
12033
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12034
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12035
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12036
              8'h0_0, target_wait_states[7:0],
12037
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12038
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12039
  end
12040
endtask // PCIU_MEM_WRITE
12041
 
12042
task PCIU_IO_WRITE;
12043
  input  [2:0] master_number;
12044
  input  [PCI_BUS_DATA_RANGE:0] address;
12045
  input  [PCI_BUS_DATA_RANGE:0] data;
12046
  input  [3:0] byte_en;
12047
  input  [9:0] size;
12048
  input  [2:0] target_termination ;
12049
  begin
12050
 
12051
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12052
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12053
              size[9:0], `Test_No_Addr_Perr, `Test_No_Data_Perr,
12054
              8'h0_0, `Test_One_Zero_Target_WS,
12055
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12056
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12057
  end
12058
endtask // PCIU_IO_WRITE
12059
 
12060
task PCIU_IO_WRITE_MAKE_PERR ;
12061
  input  [2:0] master_number;
12062
  input  [PCI_BUS_DATA_RANGE:0] address;
12063
  input  [PCI_BUS_DATA_RANGE:0] data;
12064
  input  [3:0] byte_en;
12065
  input  [9:0] size;
12066
  input  [2:0] target_termination ;
12067
  begin
12068
 
12069
    DO_REF ("IO_WRITE  ", master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12070
              PCI_COMMAND_IO_WRITE, data[PCI_BUS_DATA_RANGE:0], byte_en[3:0],
12071
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12072
              8'h0_0, `Test_One_Zero_Target_WS,
12073
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
12074
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12075
  end
12076
endtask // PCIU_IO_WRITE
12077
 
12078
task PCIU_MEM_WRITE_MAKE_SERR;
12079
  input  [79:0] name;
12080
  input  [2:0] master_number;
12081
  input  [PCI_BUS_DATA_RANGE:0] address;
12082
  input  [PCI_BUS_DATA_RANGE:0] data;
12083
  input  [9:0] size;
12084
  input  [7:0] master_wait_states;
12085
  input  [7:0] target_wait_states;
12086
  input  [1:0] target_devsel_speed;
12087
  input  [2:0] target_termination;
12088
  begin
12089
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12090
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12091
              size[9:0], `Test_Addr_Perr, `Test_No_Data_Perr,
12092
              8'h0_0, target_wait_states[7:0],
12093
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12094
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12095
  end
12096
endtask // PCIU_MEM_WRITE_MAKE_SERR
12097
 
12098
task PCIU_MEM_WRITE_MAKE_PERR;
12099
  input  [79:0] name;
12100
  input  [2:0] master_number;
12101
  input  [PCI_BUS_DATA_RANGE:0] address;
12102
  input  [PCI_BUS_DATA_RANGE:0] data;
12103
  input  [9:0] size;
12104
  input  [7:0] master_wait_states;
12105
  input  [7:0] target_wait_states;
12106
  input  [1:0] target_devsel_speed;
12107
  input  [2:0] target_termination;
12108
  begin
12109
    DO_REF (name[79:0], master_number[2:0], address[PCI_BUS_DATA_RANGE:0],
12110
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0], `Test_All_Bytes,
12111
              size[9:0], `Test_No_Addr_Perr, `Test_Data_Perr,
12112
              8'h0_0, target_wait_states[7:0],
12113
              target_devsel_speed[1:0], `Test_No_Fast_B2B,
12114
              target_termination[2:0], `Test_Expect_No_Master_Abort);
12115
  end
12116
endtask // PCIU_MEM_WRITE
12117
 
12118
/*--------------------------------------------------------------------------
12119
Initialization CASES
12120
--------------------------------------------------------------------------*/
12121
 
12122
// Initialize the basic Config Registers of the PCI bridge target device
12123
task configure_bridge_target;
12124
    reg [11:0] offset ;
12125
    reg [31:0] data ;
12126
    `ifdef HOST
12127
    reg `WRITE_STIM_TYPE   write_data ;
12128
    reg `WB_TRANSFER_FLAGS write_flags ;
12129
    reg `WRITE_RETURN_TYPE write_status ;
12130
    `else
12131
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12132
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12133
    `endif
12134
 
12135
    reg [31:0] temp_var ;
12136
begin
12137
`ifdef HOST //  set Header
12138
    offset  = 12'h4 ; // PCI Header Command register
12139
    data    = 32'h0000_0007 ; // enable master & target operation
12140
 
12141
    write_flags                      = 0 ;
12142
    write_flags`INIT_WAITS           = tb_init_waits ;
12143
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
12144
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12145
 
12146
    write_data`WRITE_ADDRESS  = { `WB_CONFIGURATION_BASE, offset } ;
12147
    write_data`WRITE_SEL      = 4'h1 ;
12148
    write_data`WRITE_TAG_STIM = 0 ;
12149
    write_data`WRITE_DATA     = data ;
12150
 
12151
    next_test_name[79:0] <= "Init_Tar_R";
12152
 
12153
    $display(" bridge target - Enabling master and target operation!");
12154
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12155
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12156
    begin
12157
        $display("Write to configuration space failed! Time %t ", $time) ;
12158
    end
12159
 
12160
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12161
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12162
 
12163
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12164
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12165
 
12166
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12167
    write_data`WRITE_SEL      = 4'hf ;
12168
    write_data`WRITE_TAG_STIM = 0 ;
12169
    write_data`WRITE_DATA     = data ;
12170
 
12171
 `ifdef  NO_CNF_IMAGE
12172
  `ifdef PCI_IMAGE0 //      set P_BA0
12173
 
12174
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12175
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12176
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12177
    begin
12178
        $display("Write to configuration space failed! Time %t ", $time) ;
12179
    end
12180
  `endif
12181
 `else //      set P_BA0
12182
 
12183
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12184
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12185
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12186
    begin
12187
        $display("Write to configuration space failed! Time %t ", $time) ;
12188
    end
12189
 `endif
12190
 
12191
`else // GUEST, set Header, set P_BA0
12192
    data            = 32'h0000_0007 ; // enable master & target operation
12193
    byte_enables    = 4'hF ;
12194
    $display(" bridge target - Enabling master and target operation!");
12195 45 mihad
    configuration_cycle_write(0,                        // bus number
12196
                              `TAR0_IDSEL_INDEX - 11,   // device number
12197
                              0,                        // function number
12198
                              1,                        // register number
12199
                              0,                        // type of configuration cycle
12200
                              byte_enables,             // byte enables
12201
                              data                      // data
12202 15 mihad
                             ) ;
12203
 
12204
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12205
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12206
    byte_enables = 4'hf ;
12207 45 mihad
    configuration_cycle_write(0,                        // bus number
12208
                              `TAR0_IDSEL_INDEX - 11,   // device number
12209
                              0,                        // function number
12210
                              4,                        // register number
12211
                              0,                        // type of configuration cycle
12212
                              byte_enables,             // byte enables
12213
                              data                      // data
12214 15 mihad
                             ) ;
12215
 
12216
`endif
12217
end
12218
endtask // configure_bridge_target
12219
 
12220
// Initialize the basic Config Registers of the PCI bridge target device
12221
task configure_bridge_target_base_addresses;
12222
    reg [11:0] offset ;
12223
    reg [31:0] data ;
12224
    `ifdef HOST
12225
    reg `WRITE_STIM_TYPE   write_data ;
12226
    reg `WB_TRANSFER_FLAGS write_flags ;
12227
    reg `WRITE_RETURN_TYPE write_status ;
12228
    `else
12229
    reg [PCI_BUS_DATA_RANGE:0] pci_conf_addr;
12230
    reg [PCI_BUS_CBE_RANGE:0]  byte_enables;
12231
    `endif
12232
 
12233
    reg [31:0] temp_var ;
12234
begin
12235
`ifdef HOST //  set Header
12236
    offset  = 12'h4 ; // PCI Header Command register
12237
    data    = 32'h0000_0007 ; // enable master & target operation
12238
 
12239
    write_flags                    = 0 ;
12240
    write_flags`INIT_WAITS         = tb_init_waits ;
12241
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
12242
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
12243
 
12244
    temp_var                                   = { `WB_CONFIGURATION_BASE, 12'h000 } ;
12245
    temp_var[(31-`WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
12246
 
12247
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12248
    write_data`WRITE_SEL      = 4'h1 ;
12249
    write_data`WRITE_TAG_STIM = 0 ;
12250
    write_data`WRITE_DATA     = data ;
12251
 
12252
    next_test_name[79:0] <= "Init_Tar_R";
12253
 
12254
    $display(" bridge target - Enabling master and target operation!");
12255
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12256
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12257
    begin
12258
        $display("Write to configuration space failed! Time %t ", $time) ;
12259
    end
12260
 
12261
    offset  = {4'h1, `P_BA0_ADDR, 2'b00} ; // PCI Base Address 0
12262
    data    = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12263
 
12264
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12265
    write_data`WRITE_SEL      = 4'hf ;
12266
    write_data`WRITE_TAG_STIM = 0 ;
12267
    write_data`WRITE_DATA     = data ;
12268
 
12269
 `ifdef  NO_CNF_IMAGE
12270
  `ifdef PCI_IMAGE0 //      set P_BA0
12271
 
12272
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12273
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12274
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12275
    begin
12276
        $display("Write to configuration space failed! Time %t ", $time) ;
12277
    end
12278
  `endif
12279
 `else //      set P_BA0
12280
 
12281
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12282
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12283
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12284
    begin
12285
        $display("Write to configuration space failed! Time %t ", $time) ;
12286
    end
12287
 `endif
12288
    offset  = {4'h1, `P_BA1_ADDR, 2'b00} ; // PCI Base Address 1
12289
    data    = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12290
 
12291
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12292
    write_data`WRITE_SEL      = 4'hf ;
12293
    write_data`WRITE_TAG_STIM = 0 ;
12294
    write_data`WRITE_DATA     = data ;
12295
 
12296
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12297
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12298
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12299
    begin
12300
        $display("Write to configuration space failed! Time %t ", $time) ;
12301
    end
12302
 `ifdef PCI_IMAGE2
12303
 
12304
    offset  = {4'h1, `P_BA2_ADDR, 2'b00} ; // PCI Base Address 2
12305
    data    = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12306
 
12307
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12308
    write_data`WRITE_SEL      = 4'hf ;
12309
    write_data`WRITE_TAG_STIM = 0 ;
12310
    write_data`WRITE_DATA     = data ;
12311
 
12312
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12313
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12314
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12315
    begin
12316
        $display("Write to configuration space failed! Time %t ", $time) ;
12317
    end
12318
 `endif
12319
 `ifdef PCI_IMAGE3
12320
    offset  = {4'h1, `P_BA3_ADDR, 2'b00} ; // PCI Base Address 3
12321
    data    = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12322
 
12323
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12324
    write_data`WRITE_SEL      = 4'hf ;
12325
    write_data`WRITE_TAG_STIM = 0 ;
12326
    write_data`WRITE_DATA     = data ;
12327
 
12328
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12329
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12330
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12331
    begin
12332
        $display("Write to configuration space failed! Time %t ", $time) ;
12333
    end
12334
 `endif
12335
 `ifdef PCI_IMAGE4
12336
    offset  = {4'h1, `P_BA4_ADDR, 2'b00} ; // PCI Base Address 4
12337
    data    = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12338
 
12339
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12340
    write_data`WRITE_SEL      = 4'hf ;
12341
    write_data`WRITE_TAG_STIM = 0 ;
12342
    write_data`WRITE_DATA     = data ;
12343
 
12344
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12345
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12346
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12347
    begin
12348
        $display("Write to configuration space failed! Time %t ", $time) ;
12349
    end
12350
 `endif
12351
 `ifdef PCI_IMAGE5
12352
    offset  = {4'h1, `P_BA5_ADDR, 2'b00} ; // PCI Base Address 5
12353
    data    = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12354
 
12355
    write_data`WRITE_ADDRESS  = temp_var + offset ;
12356
    write_data`WRITE_SEL      = 4'hf ;
12357
    write_data`WRITE_TAG_STIM = 0 ;
12358
    write_data`WRITE_DATA     = data ;
12359
 
12360
    $display(" bridge target - Setting base address P_BA5 to    32'h %h !", data);
12361
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
12362
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
12363
    begin
12364
        $display("Write to configuration space failed! Time %t ", $time) ;
12365
    end
12366
 `endif
12367
 
12368
`else // GUEST, set Header, set P_BA0
12369
    data            = 32'h0000_0007 ; // enable master & target operation
12370
    byte_enables    = 4'hF ;
12371
    $display(" bridge target - Enabling master and target operation!");
12372 45 mihad
    configuration_cycle_write(0,                        // bus number
12373
                              `TAR0_IDSEL_INDEX - 11,   // device number
12374
                              0,                        // function number
12375
                              1,                        // register number
12376
                              0,                        // type of configuration cycle
12377
                              byte_enables,             // byte enables
12378
                              data                      // data
12379 15 mihad
                             ) ;
12380
 
12381
    data = Target_Base_Addr_R[0] ; // `TAR0_BASE_ADDR_0 = 32'h1000_0000
12382
    $display(" bridge target - Setting base address P_BA0 to    32'h %h !", data);
12383
    byte_enables = 4'hf ;
12384 45 mihad
    configuration_cycle_write(0,                        // bus number
12385
                              `TAR0_IDSEL_INDEX - 11,   // device number
12386
                              0,                        // function number
12387
                              4,                        // register number
12388
                              0,                        // type of configuration cycle
12389
                              byte_enables,             // byte enables
12390
                              data                      // data
12391 15 mihad
                             ) ;
12392
 
12393
    data = Target_Base_Addr_R[1] ; // `TAR0_BASE_ADDR_1 = 32'h2000_0000
12394
    $display(" bridge target - Setting base address P_BA1 to    32'h %h !", data);
12395
    byte_enables = 4'hf ;
12396 45 mihad
    configuration_cycle_write(0,                        // bus number
12397
                              `TAR0_IDSEL_INDEX - 11,   // device number
12398
                              0,                        // function number
12399
                              5,                        // register number
12400
                              0,                        // type of configuration cycle
12401
                              byte_enables,             // byte enables
12402
                              data                      // data
12403 15 mihad
                             ) ;
12404
 `ifdef PCI_IMAGE2
12405
    data = Target_Base_Addr_R[2] ; // `TAR0_BASE_ADDR_2 = 32'h3000_0000
12406
    $display(" bridge target - Setting base address P_BA2 to    32'h %h !", data);
12407
    byte_enables = 4'hf ;
12408 45 mihad
    configuration_cycle_write(0,                        // bus number
12409
                              `TAR0_IDSEL_INDEX - 11,   // device number
12410
                              0,                        // function number
12411
                              6,                        // register number
12412
                              0,                        // type of configuration cycle
12413
                              byte_enables,             // byte enables
12414
                              data                      // data
12415 15 mihad
                             ) ;
12416
 `endif
12417
 `ifdef PCI_IMAGE3
12418
    data = Target_Base_Addr_R[3] ; // `TAR0_BASE_ADDR_3 = 32'h4000_0000
12419
    $display(" bridge target - Setting base address P_BA3 to    32'h %h !", data);
12420
    byte_enables = 4'hf ;
12421 45 mihad
    configuration_cycle_write(0,                        // bus number
12422
                              `TAR0_IDSEL_INDEX - 11,   // device number
12423
                              0,                        // function number
12424
                              7,                        // register number
12425
                              0,                        // type of configuration cycle
12426
                              byte_enables,             // byte enables
12427
                              data                      // data
12428 15 mihad
                             ) ;
12429
 `endif
12430
 `ifdef PCI_IMAGE4
12431
    data = Target_Base_Addr_R[4] ; // `TAR0_BASE_ADDR_4 = 32'h5000_0000
12432
    $display(" bridge target - Setting base address P_BA4 to    32'h %h !", data);
12433
    byte_enables = 4'hf ;
12434 45 mihad
    configuration_cycle_write(0,                        // bus number
12435
                              `TAR0_IDSEL_INDEX - 11,   // device number
12436
                              0,                        // function number
12437
                              8,                        // register number
12438
                              0,                        // type of configuration cycle
12439
                              byte_enables,             // byte enables
12440
                              data                      // data
12441 15 mihad
                             ) ;
12442
 `endif
12443
 `ifdef PCI_IMAGE5
12444
    data = Target_Base_Addr_R[5] ; // `TAR0_BASE_ADDR_5 = 32'h6000_0000
12445
    $display(" bridge target - Setting base address P_BA5 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
                              9,                        // register number
12451
                              0,                        // type of configuration cycle
12452
                              byte_enables,             // byte enables
12453
                              data                      // data
12454 15 mihad
                             ) ;
12455
 `endif
12456
`endif
12457
end
12458
endtask // configure_bridge_target_base_addresses
12459
 
12460
/*--------------------------------------------------------------------------
12461
Test CASES
12462
--------------------------------------------------------------------------*/
12463
 
12464
// function converts PCI address to WB with the same data as the pci_decoder does
12465
function [31:0] pci_to_wb_addr_convert ;
12466
 
12467
    input [31:0] pci_address ;
12468
    input [31:0] translation_address ;
12469
    input [31:0] translate ;
12470
 
12471
    reg   [31:0] temp_address ;
12472
begin
12473
    if ( translate !== 1 )
12474
    begin
12475
        temp_address = pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12476
    end
12477
    else
12478
    begin
12479
        temp_address = {translation_address[31:(32 - `PCI_NUM_OF_DEC_ADDR_LINES)], {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}} ;
12480
    end
12481
 
12482
    temp_address = temp_address | (pci_address & {{(`PCI_NUM_OF_DEC_ADDR_LINES){1'b0}}, {(32 - `PCI_NUM_OF_DEC_ADDR_LINES){1'b1}}}) ;
12483
    pci_to_wb_addr_convert = temp_address ;
12484
end
12485
endfunction // pci_to_wb_addr_convert
12486
 
12487
// Test normal write and read to WB slave
12488
task test_normal_wr_rd;
12489
  input  [2:0]  Master_ID;
12490
  input  [PCI_BUS_DATA_RANGE:0] Address;
12491
  input  [PCI_BUS_DATA_RANGE:0] Data;
12492
  input  [3:0]  Be;
12493
  input  [2:0]  Image_num;
12494
  input  [9:0]  Set_size;
12495
  input         Set_addr_translation;
12496
  input         Set_prefetch_enable;
12497
  input  [7:0]  Cache_lsize;
12498
  input         Set_wb_wait_states;
12499
  input         MemRdLn_or_MemRd_when_cache_lsize_read;
12500
 
12501
  reg    [31:0] rd_address;
12502
  reg    [31:0] rd_data;
12503
  reg    [3:0]  rd_be;
12504
  reg    [11:0] addr_offset;
12505
  reg    [31:0] read_data;
12506
  reg           continue ;
12507
  reg           ok   ;
12508
  reg    [31:0] expect_address ;
12509
  reg    [31:0] expect_rd_address ;
12510
  reg           expect_we ;
12511
  reg    [9:0]  expect_length_wr ;
12512
  reg    [9:0]  expect_length_rd ;
12513
  reg    [9:0]  expect_length_rd1 ;
12514
  reg    [9:0]  expect_length_rd2 ;
12515
  reg    [3:0]  use_rd_cmd ;
12516
  integer       i ;
12517 35 mihad
  reg           error_monitor_done ;
12518 15 mihad
begin:main
12519
 
12520
    // enable ERROR reporting, because error must NOT be reported and address translation if required!
12521
    $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12522
    $display(" - errors will be reported, but they should not occur!");
12523
    test_name = "CONFIGURE BRIDGE FOR NORMAL TARGET READ/WRITE" ;
12524
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12525
    config_write( addr_offset, 32'h0000_0001, 4'hF, ok) ;
12526
    if ( ok !== 1 )
12527
    begin
12528
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
12529
        test_fail("write to P_ERR_CS register didn't succeede") ;
12530
        disable main;
12531
    end
12532
 
12533
    `ifdef  ADDR_TRAN_IMPL
12534
 
12535
    // set or clear address translation
12536
    if (Set_addr_translation)
12537
    begin
12538
        $display("Setting the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12539
        $display(" - address translation will be performed!");
12540
    end
12541
    else
12542
    begin
12543
        $display("Clearing the AT_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12544
        $display(" - address translation will not be performed!");
12545
    end
12546
    // set or clear pre-fetch enable
12547
    if (Set_prefetch_enable)
12548
    begin
12549
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12550
        $display(" - bursts can be performed!");
12551
    end
12552
    else
12553
    begin
12554
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12555
        $display(" - bursts can not be performed!");
12556
    end
12557
 
12558
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12559
    config_write( addr_offset, {29'h0, Set_addr_translation, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12560
    if ( ok !== 1 )
12561
    begin
12562
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12563
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12564
        disable main;
12565
    end
12566
 
12567
    // predict the address and control signals on WB bus
12568
    expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], Set_addr_translation ) ;
12569
    expect_we      = 1'b1 ; // WRITE
12570
 
12571
    `else
12572
 
12573
    // address translation is not implemented
12574
    $display("Address translation is NOT implemented for PCI images!");
12575
    // set or clear pre-fetch enable
12576
    if (Set_prefetch_enable)
12577
    begin
12578
        $display("Setting the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12579
        $display(" - bursts can be performed!");
12580
    end
12581
    else
12582
    begin
12583
        $display("Clearing the PRF_EN bit of PCI Image Control register P_IMG_CTRL%d.", Image_num);
12584
        $display(" - bursts can not be performed!");
12585
    end
12586
 
12587
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
12588
    config_write( addr_offset, {29'h0, 1'b0, Set_prefetch_enable, 1'b0}, 4'hF, ok) ;
12589
    if ( ok !== 1 )
12590
    begin
12591
        $display("Image testing failed! Failed to write P_IMG_CTRL%d register! Time %t ", Image_num, $time);
12592
        test_fail("write to P_IMG_CTRL didn't succeede") ;
12593
        disable main;
12594
    end
12595
 
12596
    // predict the address and control signals on WB bus
12597
    expect_address = Address ;
12598
    expect_we      = 1'b1 ; // WRITE
12599
 
12600
    `endif
12601
 
12602
    // set WB SLAVE parameters
12603
    if (Set_wb_wait_states)
12604
        $display("Setting behavioral WB slave parameters: ACK termination and 3 WAIT states!");
12605
    else
12606
        $display("Setting behavioral WB slave parameters: ACK termination and 0 WAIT states!");
12607
    // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
12608
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
12609
 
12610
    if ( Set_size > (`PCIW_DEPTH - 2) )
12611
    begin
12612
        expect_length_wr = `PCIW_DEPTH - 2 ;
12613
    end
12614
    else
12615
    begin
12616
        expect_length_wr = Set_size ;
12617
    end
12618
    // write through the PCI bridge to WB slave
12619
    test_name = "NORMAL POSTED WRITE THROUGH PCI TARGET UNIT" ;
12620
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length_wr);
12621
 
12622
    fork
12623
    begin
12624
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
12625
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
12626
                   expect_length_wr, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12627
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12628
        do_pause( 1 ) ;
12629
    end
12630
    begin
12631
       wb_transaction_progress_monitor( expect_address, expect_we, expect_length_wr, 1'b1, ok ) ;
12632
       if ( ok !== 1 )
12633
           test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
12634
       else
12635
           test_ok ;
12636
    end
12637
    join
12638
 
12639
    // predict the address and control signals on WB bus
12640
    expect_we      = 1'b0 ; // READ
12641
 
12642
    // read from the PCI bridge (from WB slave) - PCI master behavioral checks if the same data was written
12643
    $display("Memory read through PCI bridge to WB slave!");
12644
 
12645
    if ( expect_length_wr == 1 )
12646
    begin
12647
        if (Set_prefetch_enable)
12648
        begin
12649
            expect_length_rd1 = Cache_lsize ;
12650
            expect_length_rd2 = 0 ;
12651
                // If PCI behavioral master must check received DATA
12652
                master2_check_received_data = 0 ;
12653
                    master1_check_received_data = 0 ;
12654
        end
12655
        else
12656
        begin
12657
            expect_length_rd1 = 1 ;
12658
            expect_length_rd2 = 0 ;
12659
                // If PCI behavioral master must check received DATA
12660
                master2_check_received_data = 1 ;
12661
                    master1_check_received_data = 1 ;
12662
        end
12663
        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12664
        expect_length_rd  = expect_length_rd1 ;
12665
    end
12666
    else if ( expect_length_wr == (`PCIR_DEPTH - 1) )
12667
    begin
12668
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12669
        expect_length_rd2 = 0 ;
12670
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12671
        expect_length_rd  = expect_length_rd1 ;
12672
                // If PCI behavioral master must check received DATA
12673
        master2_check_received_data = 1 ;
12674
            master1_check_received_data = 1 ;
12675
    end
12676
    else if ( expect_length_wr > (`PCIR_DEPTH - 1) )
12677
    begin
12678
        expect_length_rd1 = `PCIR_DEPTH - 1 ;
12679
        expect_length_rd2 = expect_length_wr - expect_length_rd1 ;
12680
        use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12681
        expect_length_rd  = expect_length_rd1 ;
12682
                // If PCI behavioral master must check received DATA
12683
                master2_check_received_data = 1 ;
12684
            master1_check_received_data = 1 ;
12685
    end
12686
    else
12687
    begin
12688
        if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12689
        begin
12690
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12691
            expect_length_rd2 = 0 ;
12692
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12693
            expect_length_rd  = expect_length_rd1 ;
12694
                // If PCI behavioral master must check received DATA
12695
                master2_check_received_data = 0 ;
12696
                    master1_check_received_data = 0 ;
12697
        end
12698
        else
12699
        begin
12700
            if ( expect_length_wr > Cache_lsize )
12701
            begin
12702
                expect_length_rd1 = Cache_lsize ;
12703
                expect_length_rd2 = expect_length_wr - Cache_lsize ;
12704
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12705
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12706
                else
12707
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12708
                expect_length_rd  = expect_length_rd1 ;
12709
                        // If PCI behavioral master must check received DATA
12710
                        master2_check_received_data = 1 ;
12711
                            master1_check_received_data = 1 ;
12712
            end
12713
            else
12714
            begin
12715
                expect_length_rd1 = Cache_lsize ;
12716
                expect_length_rd2 = 0 ;
12717
                if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12718
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12719
                else
12720
                    use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12721
                expect_length_rd  = expect_length_wr ;
12722
                                if ( expect_length_wr == Cache_lsize )
12723
                        begin
12724
                                // If PCI behavioral master must check received DATA
12725
                                master2_check_received_data = 1 ;
12726
                                    master1_check_received_data = 1 ;
12727
                                end
12728
                                else
12729
                                begin
12730
                                // If PCI behavioral master must check received DATA
12731
                                master2_check_received_data = 0 ;
12732
                                    master1_check_received_data = 0 ;
12733
                end
12734
            end
12735
        end
12736
    end
12737
 
12738
    rd_address = Address[PCI_BUS_DATA_RANGE:0];
12739
    expect_rd_address = expect_address ;
12740
    rd_data[31:0] = Data[31:0];
12741
    rd_be[3:0] = Be[3:0];
12742
 
12743
    test_name = "NORMAL MEMORY READ THROUGH PCI TARGET UNIT" ;
12744
    while (expect_length_rd2 > 0)
12745
    begin
12746
        // do read
12747
        $display("Read %d words!", expect_length_rd);
12748
 
12749
        fork
12750
        begin
12751
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12752
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12753
                        expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12754
                        `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12755
 
12756
            wb_transaction_stop( expect_length_rd - 1) ;
12757
 
12758
            do_pause( 1 ) ;
12759
        end
12760
        begin
12761
            wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12762
            if ( ok !== 1 )
12763
                test_fail("WB Master started invalid transaction or none at all after Target delayed read was requested") ;
12764
 
12765
            repeat( 3 )
12766
                @(posedge pci_clock) ;
12767
 
12768
            PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12769
                        use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12770
                        expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12771
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12772
 
12773
            do_pause( 1 ) ;
12774
            while ( FRAME === 0 )
12775
                @(posedge pci_clock) ;
12776
 
12777
            while ( IRDY === 0 )
12778
                @(posedge pci_clock) ;
12779
 
12780 35 mihad
            #1 ;
12781
            if ( !error_monitor_done )
12782
                disable monitor_error_event1 ;
12783 15 mihad
        end
12784
        begin:monitor_error_event1
12785 35 mihad
            error_monitor_done = 0 ;
12786 15 mihad
            @(error_event_int) ;
12787
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12788
            ok = 0 ;
12789 35 mihad
            error_monitor_done = 1 ;
12790 15 mihad
        end
12791
        join
12792
 
12793
        // increasing the starting address for PCI master and for WB transaction monitor
12794
        rd_address = rd_address + (4 * expect_length_rd) ;
12795
        expect_rd_address = expect_rd_address + (4 * expect_length_rd) ;
12796
        // change the expected read data and byte enables as they are changed in the PCI behavioral master
12797
        rd_data[31:24] = Data[31:24] + expect_length_rd;
12798
        rd_data[23:16] = Data[23:16] + expect_length_rd;
12799
        rd_data[15: 8] = Data[15: 8] + expect_length_rd;
12800
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length_rd;
12801
        for (i=0; i<expect_length_rd; i=i+1)
12802
            rd_be[3:0] = {Be[2:0], Be[3]};
12803
 
12804
        // set parameters for next read
12805
        if ( expect_length_rd2 == 1 )
12806
        begin
12807
                if (Set_prefetch_enable)
12808
                begin
12809
                    expect_length_rd1 = Cache_lsize ;
12810
                    expect_length_rd2 = 0 ;
12811
                        // If PCI behavioral master must check received DATA
12812
                        master2_check_received_data = 0 ;
12813
                            master1_check_received_data = 0 ;
12814
                end
12815
                else
12816
                begin
12817
                    expect_length_rd1 = 1 ;
12818
                    expect_length_rd2 = 0 ;
12819
                        // If PCI behavioral master must check received DATA
12820
                        master2_check_received_data = 1 ;
12821
                            master1_check_received_data = 1 ;
12822
                end
12823
            use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12824
            expect_length_rd  = expect_length_rd1 ;
12825
        end
12826
        else if ( expect_length_rd2 == (`PCIR_DEPTH - 1) )
12827
        begin
12828
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12829
            expect_length_rd2 = 0 ;
12830
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12831
            expect_length_rd  = expect_length_rd1 ;
12832
                        // If PCI behavioral master must check received DATA
12833
                        master2_check_received_data = 1 ;
12834
                    master1_check_received_data = 1 ;
12835
        end
12836
        else if ( expect_length_rd2 > (`PCIR_DEPTH - 1) )
12837
        begin
12838
            expect_length_rd1 = `PCIR_DEPTH - 1 ;
12839
            expect_length_rd2 = expect_length_rd2 - expect_length_rd1 ;
12840
            use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12841
            expect_length_rd  = expect_length_rd1 ;
12842
                        // If PCI behavioral master must check received DATA
12843
                        master2_check_received_data = 1 ;
12844
                    master1_check_received_data = 1 ;
12845
        end
12846
        else
12847
        begin
12848
            if ( Cache_lsize >= (`PCIR_DEPTH - 1) )
12849
            begin
12850
                expect_length_rd1 = `PCIR_DEPTH - 1 ;
12851
                expect_length_rd2 = 0 ;
12852
                use_rd_cmd = PCI_COMMAND_MEMORY_READ_MULTIPLE ;
12853
                expect_length_rd  = expect_length_rd1 ;
12854
                        // If PCI behavioral master must check received DATA
12855
                        master2_check_received_data = 0 ;
12856
                            master1_check_received_data = 0 ;
12857
            end
12858
            else
12859
            begin
12860
                if ( expect_length_rd2 > Cache_lsize )
12861
                begin
12862
                    expect_length_rd1 = Cache_lsize ;
12863
                    expect_length_rd2 = expect_length_rd2 - Cache_lsize ;
12864
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12865
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12866
                    else
12867
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12868
                    expect_length_rd  = expect_length_rd1 ;
12869
                                // If PCI behavioral master must check received DATA
12870
                                master2_check_received_data = 1 ;
12871
                                    master1_check_received_data = 1 ;
12872
                end
12873
                else
12874
                begin
12875
                    expect_length_rd  = expect_length_rd2 ;
12876
                    expect_length_rd1 = Cache_lsize ;
12877
                    expect_length_rd2 = 0 ;
12878
                    if ( MemRdLn_or_MemRd_when_cache_lsize_read )
12879
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ_LINE ;
12880
                    else
12881
                        use_rd_cmd = PCI_COMMAND_MEMORY_READ ;
12882
                                        if ( expect_length_rd2 == Cache_lsize )
12883
                                begin
12884
                                        // If PCI behavioral master must check received DATA
12885
                                        master2_check_received_data = 1 ;
12886
                                            master1_check_received_data = 1 ;
12887
                                        end
12888
                                        else
12889
                                        begin
12890
                                        // If PCI behavioral master must check received DATA
12891
                                        master2_check_received_data = 0 ;
12892
                                            master1_check_received_data = 0 ;
12893
                        end
12894
                end
12895
            end
12896
        end
12897
    end
12898
    // do last read
12899
    $display("Read %d words!", expect_length_rd);
12900
 
12901
    fork
12902
    begin
12903
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12904
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12905
                    expect_length_rd1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12906
                    `Test_Devsel_Medium, `Test_Target_Start_Delayed_Read);
12907
 
12908
        wb_transaction_stop(expect_length_rd - 1) ;
12909
        do_pause( 1 ) ;
12910
    end
12911
    begin
12912
        wb_transaction_progress_monitor( expect_rd_address, expect_we, expect_length_rd1, 1'b1, ok ) ;
12913
 
12914
        do_pause(3) ;
12915
        PCIU_READ (Master_ID[2:0], rd_address[PCI_BUS_DATA_RANGE:0],
12916
                    use_rd_cmd, rd_data[PCI_BUS_DATA_RANGE:0], rd_be[3:0],
12917
                    expect_length_rd, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
12918
                    `Test_Devsel_Medium, `Test_Target_Normal_Completion);
12919
        do_pause(1) ;
12920
 
12921
        while ( FRAME === 0 )
12922
            @(posedge pci_clock) ;
12923
 
12924
        while ( IRDY === 0 )
12925
            @(posedge pci_clock) ;
12926
 
12927 35 mihad
        #1 ;
12928
        if ( !error_monitor_done )
12929
            disable monitor_error_event2 ;
12930 15 mihad
    end
12931
    begin:monitor_error_event2
12932 35 mihad
        error_monitor_done = 0 ;
12933 15 mihad
        @(error_event_int) ;
12934
        test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
12935
        ok = 0 ;
12936 35 mihad
        error_monitor_done = 1 ;
12937 15 mihad
    end
12938
    join
12939
 
12940
    if ( ok )
12941
        test_ok ;
12942
 
12943
    // Check that no ERRORs were reported
12944
    test_name = "PCI ERROR STATUS AFTER NORMAL WRITE/READ" ;
12945
    $display("Reading the ERR_SIG bit of PCI Error Control and Status register P_ERR_CS.");
12946
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
12947
    config_read( addr_offset, 4'hF, read_data ) ;
12948
    if ( read_data[8] !== 0 )
12949
    begin
12950
        $display("Image testing failed! Failed because ERROR was signaled, Time %t ", $time);
12951
        test_fail("error status was set even though no errors occured on WB bus") ;
12952
    end
12953
    else
12954
    begin
12955
        $display("No error was signaled, as expected!");
12956
        test_ok ;
12957
    end
12958
 
12959
end // main
12960
endtask // test_normal_wr_rd
12961
 
12962
// Test erroneous write to WB slave
12963
task test_wb_error_wr;
12964
  input  [2:0]  Master_ID;
12965
  input  [PCI_BUS_DATA_RANGE:0] Address;
12966
  input  [PCI_BUS_DATA_RANGE:0] Data;
12967
  input  [3:0]  Be;
12968
  input  [2:0]  Image_num;
12969
  input  [9:0]  Set_size;
12970
  input         Set_err_and_int_report;
12971
  input         Set_wb_wait_states;
12972
  input  [1:0]  Imm_BefLast_Last_error;
12973
 
12974
  reg    [11:0] addr_offset;
12975
  reg    [31:0] read_data;
12976
  reg           continue ;
12977
  reg           ok   ;
12978
  reg    [9:0]  expect_length ;
12979
  reg    [31:0] expect_address ;
12980
  reg    [0:0]  expect_we ;
12981
  reg    [31:0] rd_address;
12982
  reg    [31:0] rd_data;
12983
  reg    [3:0]  rd_be;
12984
  integer       i ;
12985
begin:main
12986
    if (Set_err_and_int_report)
12987
    begin
12988
        // enable ERROR reporting, because error must be reported and interrupt if required!
12989
        $display("Setting the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12990
        $display(" - errors will be reported when they will occur!");
12991
        // enable INTERRUPT reporting, because error must be reported and interrupt if required!
12992
        $display("Setting the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
12993
        $display(" - interrupt will be reported when error will occur!");
12994
    end
12995
    else
12996
    begin
12997
        // disable ERROR reporting, because error and interrupt must not be reported!
12998
        $display("Clearing the ERR_EN bit of PCI Error Control and Status register P_ERR_CS.");
12999
        $display(" - errors will NOT be reported when they will occur!");
13000
        // disable INTERRUPT reporting, because error and interrupt must not be reported!
13001
        $display("Clearing the PCI_EINT_EN and WB_EINT_EN bit of Interrupt Control register ICR.");
13002
        $display(" - interrupt will NOT be reported when error will occur!");
13003
    end
13004
    // enable/disable ERROR reporting
13005
    test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED WRITES THROUGH PCI TARGET UNIT" ;
13006
 
13007
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13008
    config_write( addr_offset, {31'h0, Set_err_and_int_report}, 4'hF, ok) ;
13009
    if ( ok !== 1 )
13010
    begin
13011
        $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13012
        test_fail("PCI Error Control and Status register could not be written") ;
13013
        disable main;
13014
    end
13015
    // enable/disable INTERRUPT reporting
13016
    addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13017
    config_write( addr_offset, {29'h0, Set_err_and_int_report, Set_err_and_int_report, 1'b0}, 4'hF, ok) ;
13018
    if ( ok !== 1 )
13019
    begin
13020
        $display("Image testing failed! Failed to write ICR register! Time %t ", $time);
13021
        test_fail("Interrupt Control register could not be written") ;
13022
        disable main;
13023
    end
13024
 
13025
    `ifdef  ADDR_TRAN_IMPL
13026
 
13027
    $display("Reading the AT_EN bit of Image Control register P_IMG_CTRL%d, for WB address prediction", Image_num);
13028
    addr_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} + (12'h10 * Image_num);
13029
    config_read( addr_offset, 4'hF, read_data ) ;
13030
    if ( read_data[2] !== 0 )
13031
    begin
13032
        $display("Address translation is set for PCI image%d!", Image_num);
13033
        // predict the address and control signals on WB bus
13034
        expect_address = pci_to_wb_addr_convert( Address, Target_Tran_Addr_R[Image_num], 1'b1 ) ;
13035
        expect_we      = 1'b1 ; // WRITE
13036
    end
13037
    else
13038
    begin
13039
        $display("Address translation is NOT set for PCI image%d!", Image_num);
13040
        // predict the address and control signals on WB bus
13041
        expect_address = Address ;
13042
        expect_we      = 1'b1 ; // WRITE
13043
    end
13044
 
13045
    `else
13046
 
13047
    // address translation is not implemented
13048
    $display("Address translation is NOT implemented for PCI images!");
13049
    // predict the address and control signals on WB bus
13050
    expect_address = Address ;
13051
    expect_we      = 1'b1 ; // WRITE
13052
 
13053
    `endif
13054
 
13055
    if ( Set_size > (`PCIW_DEPTH - 2) )
13056
    begin
13057
        expect_length = `PCIW_DEPTH - 2 ;
13058
    end
13059
    else
13060
    begin
13061
        expect_length = Set_size ;
13062
    end
13063
 
13064
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13065
    begin
13066
        $display("ERR termination with first data!");
13067
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON FIRST TRANSFER" ;
13068
    end
13069
    else if (Imm_BefLast_Last_error == 1)
13070
    begin
13071
        $display("ERR termination before last data!");
13072
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ONE BEFORE LAST TRANSFER" ;
13073
    end
13074
    else
13075
    begin
13076
        $display("ERR termination with last data!");
13077
        test_name = "POSTED WRITE THROUGH PCI TARGET ERROR TERMINATION ON WB ON LAST TRANSFER" ;
13078
    end
13079
 
13080
    // write through the PCI bridge to WB slave
13081
    $display("Memory write (%d words) through PCI bridge to WB slave!", expect_length);
13082
    fork
13083
    begin
13084
        PCIU_MEM_WRITE ("MEM_WRITE ", Master_ID[2:0],
13085
                   Address[PCI_BUS_DATA_RANGE:0], Data[PCI_BUS_DATA_RANGE:0], Be[3:0],
13086
                   expect_length, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13087
                   `Test_Devsel_Medium, `Test_Target_Normal_Completion);
13088
        do_pause( 1 ) ;
13089
    end
13090
    begin
13091
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13092
        begin
13093
            wb_transaction_progress_monitor( expect_address, expect_we, 4'h0, 1'b1, ok ) ;
13094
            if ( ok !== 1 )
13095
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13096
        end
13097
        else if (Imm_BefLast_Last_error == 1)
13098
        begin
13099
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-2), 1'b1, ok ) ;
13100
            if ( ok !== 1 )
13101
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13102
        end
13103
        else
13104
        begin
13105
            wb_transaction_progress_monitor( expect_address, expect_we, (expect_length-1), 1'b1, ok ) ;
13106
            if ( ok !== 1 )
13107
                test_fail("WB Master started invalid transaction or none at all after Target write was posted") ;
13108
        end
13109
    end
13110
    begin
13111
        if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13112
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13113
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13114
        else if (Imm_BefLast_Last_error == 1)
13115
        begin
13116
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13117
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13118
            wb_transaction_stop(expect_length-2) ;
13119
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13120
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13121
        end
13122
        else
13123
        begin
13124
            // set response of WB SLAVE - ACK,    WAIT cycles,        RETRY cycles
13125
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13126
            wb_transaction_stop(expect_length-1) ;
13127
            // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13128
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13129
        end
13130
    end
13131
    join
13132
 
13133
    if ( ok )
13134
        test_ok ;
13135
 
13136
    if ((Imm_BefLast_Last_error == 0) || (expect_length <= 2))
13137
    begin
13138
        rd_data[31:0] = Data[31:0];
13139
        rd_address[31:0] = expect_address;
13140
        rd_be[3:0] = Be[3:0];
13141
    end
13142
    else if (Imm_BefLast_Last_error == 1)
13143
    begin
13144
        rd_data[31:24] = Data[31:24] + expect_length - 2;
13145
        rd_data[23:16] = Data[23:16] + expect_length - 2;
13146
        rd_data[15: 8] = Data[15: 8] + expect_length - 2;
13147
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 2;
13148
        rd_address[31:0] = expect_address + ((expect_length - 2) * 4);
13149
        rd_be[3:0] = Be[3:0];
13150
        for (i=0; i<(expect_length-2); i=i+1)
13151
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13152
    end
13153
    else
13154
    begin
13155
        rd_data[31:24] = Data[31:24] + expect_length - 1;
13156
        rd_data[23:16] = Data[23:16] + expect_length - 1;
13157
        rd_data[15: 8] = Data[15: 8] + expect_length - 1;
13158
        rd_data[ 7: 0] = Data[ 7: 0] + expect_length - 1;
13159
        rd_address[31:0] = expect_address + ((expect_length - 1) * 4);
13160
        rd_be[3:0] = Be[3:0];
13161
        for (i=0; i<(expect_length-1); i=i+1)
13162
            rd_be[3:0] = {rd_be[2:0], rd_be[3]};
13163
    end
13164
 
13165
    master2_check_received_data = 0 ;
13166
    master1_check_received_data = 0 ;
13167
 
13168
    // Check if ERRORs were reported
13169
    $display("Reading the PCI Error Control and Status register P_ERR_CS.");
13170
    addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13171
    test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR" ;
13172
 
13173
    ok = 1 ;
13174
    config_read( addr_offset, 4'hF, read_data ) ;
13175
    if (( read_data[10:8] === 3'b001 ) && ( Set_err_and_int_report === 1'b1 ))
13176
    begin
13177
        $display("Error was signaled and reported, as expected!");
13178
        if (read_data[31:28] === rd_be)
13179
            $display("Byte enables written into P_ERR_CS register are as expected!");
13180
        else
13181
        begin
13182
            $display("Byte enables written into P_ERR_CS register are NOT as expected!");
13183
            test_fail("Byte enable information in PCI Error Control and Status register was wrong") ;
13184
            ok = 0 ;
13185
        end
13186
        if (read_data[27:24] === PCI_COMMAND_MEMORY_WRITE)
13187
            $display("Bus command written into P_ERR_CS register is as expected!");
13188
        else
13189
        begin
13190
            $display("Bus command written into P_ERR_CS register is NOT as expected!");
13191
            test_fail("Bus command information in PCI Error Control and Status register was wrong") ;
13192
            ok = 0 ;
13193
        end
13194
 
13195
        if ( ok )
13196
            test_ok ;
13197
 
13198
        $display("Reading the PCI Error Data register P_ERR_DATA.");
13199
 
13200
        test_name = "PCI ERRONEOUS DATA REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13201
        addr_offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
13202
        config_read( addr_offset, 4'hF, read_data ) ;
13203
        if (read_data === rd_data)
13204
        begin
13205
            $display("Data written into P_ERR_DATA register is as expected!");
13206
            test_ok ;
13207
        end
13208
        else
13209
        begin
13210
            $display("Data written into P_ERR_DATA register is NOT as expected!");
13211
            test_fail("PCI Erroneous Data register value was wrong") ;
13212
        end
13213
 
13214
        $display("Reading the PCI Error Address register P_ERR_ADDR.");
13215
 
13216
        test_name = "PCI ERRONEOUS ADDRESS REGISTER VALUE AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13217
 
13218
        addr_offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
13219
        config_read( addr_offset, 4'hF, read_data ) ;
13220
        if (read_data === rd_address)
13221
        begin
13222
            $display("Address written into P_ERR_ADDR register is as expected!");
13223
            test_ok ;
13224
        end
13225
        else
13226
        begin
13227
            $display("Address written into P_ERR_ADDR register is NOT as expected!");
13228
            test_fail("PCI Erroneous Address register value was wrong") ;
13229
        end
13230
    end
13231
    else if (( read_data[8] === 1'b0 ) && ( Set_err_and_int_report === 1'b0 ))
13232
    begin
13233
        $display("Error was signaled and not reported, as expected!");
13234
        test_ok ;
13235
    end
13236
    else
13237
    begin
13238
        $display("Error was signaled and reported, as NOT expected!");
13239
        test_fail("Error status bit was set event though error reporting was disabled") ;
13240
    end
13241
 
13242
    // Check if Interrupts were reported
13243
    $display("Reading the PCI_EINT and WB_EINT bit of Interrupt Status register ISR.");
13244
 
13245
    test_name = "INTERRUPT ASSERTION AND STATUS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13246
    ok = 1 ;
13247
    addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13248
    config_read( addr_offset, 4'hF, read_data ) ;
13249
    if (( read_data[2:1] === 2'b10 ) && ( Set_err_and_int_report === 1'b1 ))
13250
    begin
13251
        $display("Interrupts was signaled and reported, as expected!");
13252
    end
13253
    else if (( read_data[2:1] === 2'b00 ) && ( Set_err_and_int_report === 1'b0 ))
13254
    begin
13255
        $display("Interrupts was signaled and not reported, as expected!");
13256
    end
13257
    else
13258
    begin
13259
        $display("Interrupt was signaled and reported, as NOT expected!");
13260
        test_fail("PCI Error Interrupt status was set when not expected") ;
13261
        ok = 0 ;
13262
    end
13263
 
13264
    `ifdef HOST
13265
    repeat( 4 )
13266
        @(posedge wb_clock) ;
13267
 
13268
    if ( INT_O === Set_err_and_int_report )
13269
        $display("Interrupt pin INT_O was correctly set to logic '%d'!", Set_err_and_int_report);
13270
    else
13271
    begin
13272
        $display("Interrupt pin INT_O was NOT correctly set to logic '%d'!", Set_err_and_int_report);
13273
        test_fail("Interrupt request didn't have expected value") ;
13274
        ok = 0 ;
13275
    end
13276
 
13277
    `else // GUEST
13278
    repeat( 4 )
13279
        @(posedge pci_clock) ;
13280
 
13281
    if ( INTA === !Set_err_and_int_report )
13282
        $display("Interrupt pin INTA was correctly set to logic '%d'!", !Set_err_and_int_report);
13283
    else
13284
    begin
13285
        $display("Interrupt pin INTA was NOT correctly set to logic '%d'!", !Set_err_and_int_report);
13286
        test_fail("Interrupt request didn't have expected value") ;
13287
        ok = 0 ;
13288
    end
13289
 
13290
    `endif
13291
 
13292
    if ( ok )
13293
        test_ok ;
13294
 
13295
    if (Set_err_and_int_report)
13296
    begin
13297
        test_name = "CLEARING STATUS BITS AFTER WRITE TERMINATED WITH ERROR ON WB" ;
13298
        $display("Error and Interrupt must be cleared!");
13299
        // clear  ERROR reporting bit
13300
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13301
        config_write( addr_offset, 32'h0000_0100, 4'hF, ok) ;
13302
        if ( ok !== 1 )
13303
        begin
13304
            $display("Image testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13305
            test_fail("PCI Error Control and Status register could not be written to") ;
13306
            disable main;
13307
        end
13308
 
13309
        // clear INTERRUPT reporting bit
13310
        addr_offset = {4'h1, `ISR_ADDR, 2'b00} ;
13311
        config_write( addr_offset, 32'h0000_0004, 4'hF, ok) ;
13312
        if ( ok !== 1 )
13313
        begin
13314
            $display("Image testing failed! Failed to write ISR register! Time %t ", $time);
13315
            test_fail("Interrupt Status register could not be written to") ;
13316
            disable main;
13317
        end
13318
 
13319
        test_ok ;
13320
        test_name = "INTERRUPT REQUEST FINISHED AFTER PCI ERROR INTERRUPT STATUS IS CLEARED" ;
13321
        `ifdef HOST
13322
 
13323
        repeat(4)
13324
            @(posedge wb_clock) ;
13325
        if ( INT_O === 1'b0 )
13326
        begin
13327
            $display("Interrupt pin INT_O was correctly cleared!");
13328
            test_ok ;
13329
        end
13330
        else
13331
        begin
13332
            $display("Interrupt pin INT_O was NOT correctly cleared!");
13333
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13334
            disable main;
13335
        end
13336
 
13337
        `else // GUEST
13338
 
13339
        repeat(4)
13340
            @(posedge pci_clock) ;
13341
        if ( INTA === 1'b1 )
13342
        begin
13343
            $display("Interrupt pin INTA was correctly cleared!");
13344
            test_ok ;
13345
        end
13346
        else
13347
        begin
13348
            $display("Interrupt pin INTA was NOT correctly cleared!");
13349
            test_fail("Interrupt pin was still asserted after Interrupt status was cleared") ;
13350
            disable main;
13351
        end
13352
 
13353
        `endif
13354
 
13355
    end
13356
    else
13357
    begin
13358
        $display("Error and Interrupt don't need to be cleared!");
13359
    end
13360
end // main
13361
endtask // test_wb_error_wr
13362
 
13363
task test_wb_error_rd;
13364
    reg    [11:0] addr_offset ;
13365
    reg    [11:0] ctrl_offset ;
13366
    reg    [11:0] ba_offset ;
13367
    reg    [11:0] am_offset ;
13368
    reg    [11:0] ta_offset ;
13369
    reg    [31:0] read_data;
13370
    reg           ok   ;
13371
    reg    [9:0]  expect_length ;
13372
    reg    [31:0] expect_address ;
13373
    reg    [0:0]  expect_we ;
13374
    reg    [31:0] rd_address;
13375
    reg    [31:0] rd_data;
13376
    reg    [3:0]  rd_be;
13377
    integer       i ;
13378
    reg           do_mem_aborts ;
13379
    reg           do_io_aborts ;
13380 35 mihad
    reg           error_monitor_done ;
13381 15 mihad
begin:main
13382
    // enable all error reporting mechanisms - during erroneous reads, errors should not be reported
13383
 
13384
    if ( target_mem_image !== -1 )
13385
    begin
13386
        do_mem_aborts = 1 ;
13387
 
13388
        if (target_mem_image === 1)
13389
        begin
13390
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
13391
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
13392
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
13393
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
13394
        end
13395
        else if (target_mem_image === 2)
13396
        begin
13397
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
13398
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
13399
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
13400
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
13401
        end
13402
        else if (target_mem_image === 3)
13403
        begin
13404
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
13405
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
13406
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
13407
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
13408
        end
13409
        else if (target_mem_image === 4)
13410
        begin
13411
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
13412
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
13413
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
13414
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
13415
        end
13416
        else if (target_mem_image === 5)
13417
        begin
13418
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
13419
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
13420
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
13421
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
13422
        end
13423
    end
13424
    else
13425
        do_mem_aborts = 0 ;
13426
 
13427
    if ( do_mem_aborts )
13428
    begin
13429
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
13430
 
13431
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13432
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
13433
        if ( ok !== 1 )
13434
        begin
13435
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
13436
            test_fail("PCI Error Control and Status register could not be written") ;
13437
            disable main;
13438
        end
13439
 
13440
        // enable INTERRUPT reporting
13441
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
13442
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
13443
        if ( ok !== 1 )
13444
        begin
13445
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
13446
            test_fail("Interrupt Control register could not be written") ;
13447
            disable main;
13448
        end
13449
 
13450
        addr_offset = 12'h010 + (4*target_mem_image) ;
13451
 
13452
        config_write( addr_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
13453
        if ( ok !== 1 )
13454
        begin
13455
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
13456
            test_fail("PCI Base Address register could not be written") ;
13457
            disable main;
13458
        end
13459
 
13460
        // disable address translation and enable prefetch so read bursts can be performed
13461
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
13462
        if ( ok !== 1 )
13463
        begin
13464
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
13465
            test_fail("PCI Image Control register could not be written") ;
13466
            disable main;
13467
        end
13468
 
13469
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
13470
        if ( ok !== 1 )
13471
        begin
13472
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
13473
            test_fail("PCI Address Mask register could not be written") ;
13474
            disable main;
13475
        end
13476
 
13477
        addr_offset = 12'h00C ;
13478
 
13479
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
13480
        if ( ok !== 1 )
13481
        begin
13482
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
13483
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
13484
            disable main;
13485
        end
13486
 
13487
        // disable PCI master data checking
13488
        master1_check_received_data = 0 ;
13489
 
13490
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
13491
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13492
 
13493
 
13494
        // do a single read error terminated on WB bus
13495
        test_name = "SINGLE READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
13496
 
13497
        fork
13498
        begin
13499
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13500
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13501
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13502
                        `Test_Devsel_Medium, `Test_Target_Retry_On);
13503
 
13504
            do_pause( 1 ) ;
13505
        end
13506
        begin
13507
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13508
 
13509
            if ( ok !== 1 )
13510
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13511
 
13512
            do_pause(3) ;
13513
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13514
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13515
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13516
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13517
            do_pause(1) ;
13518
 
13519
            while ( FRAME === 0 )
13520
                @(posedge pci_clock) ;
13521
 
13522
            while ( IRDY === 0 )
13523
                @(posedge pci_clock) ;
13524
 
13525 35 mihad
            #1 ;
13526
            if ( !error_monitor_done )
13527
                disable monitor_error_event1 ;
13528 15 mihad
        end
13529
        begin:monitor_error_event1
13530 35 mihad
            error_monitor_done = 0 ;
13531 15 mihad
            @(error_event_int) ;
13532
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13533
            ok = 0 ;
13534 35 mihad
            error_monitor_done = 1 ;
13535 15 mihad
        end
13536
        join
13537
 
13538
        if ( ok )
13539
            test_ok ;
13540 26 mihad
 
13541
        @(posedge pci_clock) ;
13542
        @(posedge pci_clock) ;
13543
        @(posedge wb_clock) ;
13544
        @(posedge wb_clock) ;
13545 15 mihad
 
13546
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13547
        addr_offset = 12'h004 ;
13548
        config_read(addr_offset, 4'hF, read_data) ;
13549
        ok = 1 ;
13550
        if ( read_data[27] !== 1 )
13551
        begin
13552
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13553
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13554
            ok = 0 ;
13555
        end
13556
        if ( read_data[28] !== 0 )
13557
        begin
13558
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13559
            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") ;
13560
            ok = 0 ;
13561
        end
13562
        if ( read_data[29] !== 0 )
13563
        begin
13564
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13565
            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") ;
13566
            ok = 0 ;
13567
        end
13568
 
13569
        // clear statuses
13570
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13571
        if ( !ok )
13572
        begin
13573
            test_fail("write to PCI Device Status register failed") ;
13574
            $display("Couldn't write PCI Device Status register") ;
13575
            disable main ;
13576
        end
13577
 
13578
        if ( ok )
13579
            test_ok ;
13580
 
13581
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13582
 
13583
        ok = 1 ;
13584
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13585
 
13586
        config_read(addr_offset, 4'hF, read_data) ;
13587
        if (read_data[8] !== 0)
13588
        begin
13589
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13590
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13591
            ok = 0 ;
13592
        end
13593
        else
13594
            test_ok ;
13595
 
13596
        if ( ok !== 1 )
13597
        begin
13598
            config_write(addr_offset, read_data, 4'hF, ok) ;
13599
            if ( !ok )
13600
            begin
13601
                test_fail("PCI Error Control and Status register could not be written") ;
13602
                disable main ;
13603
            end
13604
        end
13605
 
13606
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13607
        fork
13608
        begin
13609
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13610
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13611
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13612
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13613
 
13614
            do_pause( 1 ) ;
13615
        end
13616
        begin
13617
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13618
 
13619
            if ( ok !== 1 )
13620
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13621
 
13622
            do_pause(3) ;
13623
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13624
                        `BC_MEM_READ, 32'h1234_5678, 4'hF,
13625
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13626
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13627
            do_pause(1) ;
13628
 
13629
            while ( FRAME === 0 )
13630
                @(posedge pci_clock) ;
13631
 
13632
            while ( IRDY === 0 )
13633
                @(posedge pci_clock) ;
13634
 
13635 35 mihad
            #1 ;
13636
            if ( !error_monitor_done )
13637
                disable monitor_error_event2 ;
13638 15 mihad
        end
13639
        begin:monitor_error_event2
13640 35 mihad
            error_monitor_done = 0 ;
13641 15 mihad
            @(error_event_int) ;
13642
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13643
            ok = 0 ;
13644 35 mihad
            error_monitor_done = 1 ;
13645 15 mihad
        end
13646
        join
13647
 
13648
        if ( ok )
13649
            test_ok ;
13650
 
13651 26 mihad
        @(posedge pci_clock) ;
13652
        @(posedge pci_clock) ;
13653
        @(posedge wb_clock) ;
13654
        @(posedge wb_clock) ;
13655
 
13656 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13657
        addr_offset = 12'h004 ;
13658
        config_read(addr_offset, 4'hF, read_data) ;
13659
        ok = 1 ;
13660
        if ( read_data[27] !== 1 )
13661
        begin
13662
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13663
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13664
            ok = 0 ;
13665
        end
13666
        if ( read_data[28] !== 0 )
13667
        begin
13668
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13669
            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") ;
13670
            ok = 0 ;
13671
        end
13672
        if ( read_data[29] !== 0 )
13673
        begin
13674
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13675
            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") ;
13676
            ok = 0 ;
13677
        end
13678
 
13679
        // clear statuses
13680
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13681
        if ( !ok )
13682
        begin
13683
            test_fail("write to PCI Device Status register failed") ;
13684
            $display("Couldn't write PCI Device Status register") ;
13685
            disable main ;
13686
        end
13687
 
13688
        if ( ok )
13689
            test_ok ;
13690
 
13691
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13692
 
13693
        ok = 1 ;
13694
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13695
 
13696
        config_read(addr_offset, 4'hF, read_data) ;
13697
        if (read_data[8] !== 0)
13698
        begin
13699
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13700
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13701
            ok = 0 ;
13702
        end
13703
        else
13704
            test_ok ;
13705
 
13706
        if ( ok !== 1 )
13707
        begin
13708
            config_write(addr_offset, read_data, 4'hF, ok) ;
13709
            if ( !ok )
13710
            begin
13711
                test_fail("PCI Error Control and Status register could not be written") ;
13712
                disable main ;
13713
            end
13714
        end
13715
 
13716
        // do a single read error terminated on WB bus
13717
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON FIRST DATAPHASE" ;
13718
 
13719
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13720
 
13721
        fork
13722
        begin
13723
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13724
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13725
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13726
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13727
 
13728
            do_pause( 1 ) ;
13729
        end
13730
        begin
13731
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 0, 1'b1, ok ) ;
13732
 
13733
            if ( ok !== 1 )
13734
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13735
 
13736
            do_pause(3) ;
13737
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13738
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13739
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13740
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13741
            do_pause(1) ;
13742
 
13743
            while ( FRAME === 0 )
13744
                @(posedge pci_clock) ;
13745
 
13746
            while ( IRDY === 0 )
13747
                @(posedge pci_clock) ;
13748
 
13749 35 mihad
            if ( !error_monitor_done )
13750
                disable monitor_error_event3 ;
13751 15 mihad
        end
13752
        begin:monitor_error_event3
13753 35 mihad
            error_monitor_done = 0 ;
13754 15 mihad
            @(error_event_int) ;
13755
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13756
            ok = 0 ;
13757 35 mihad
            error_monitor_done = 1 ;
13758 15 mihad
        end
13759
        join
13760
 
13761
        if ( ok )
13762
            test_ok ;
13763
 
13764 26 mihad
        @(posedge pci_clock) ;
13765
        @(posedge pci_clock) ;
13766
        @(posedge wb_clock) ;
13767
        @(posedge wb_clock) ;
13768
 
13769 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13770
        addr_offset = 12'h004 ;
13771
        config_read(addr_offset, 4'hF, read_data) ;
13772
        ok = 1 ;
13773
        if ( read_data[27] !== 1 )
13774
        begin
13775
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13776
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13777
            ok = 0 ;
13778
        end
13779
        if ( read_data[28] !== 0 )
13780
        begin
13781
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13782
            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") ;
13783
            ok = 0 ;
13784
        end
13785
        if ( read_data[29] !== 0 )
13786
        begin
13787
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13788
            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") ;
13789
            ok = 0 ;
13790
        end
13791
 
13792
        // clear statuses
13793
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13794
        if ( !ok )
13795
        begin
13796
            test_fail("write to PCI Device Status register failed") ;
13797
            $display("Couldn't write PCI Device Status register") ;
13798
            disable main ;
13799
        end
13800
 
13801
        if ( ok )
13802
            test_ok ;
13803
 
13804
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13805
 
13806
        ok = 1 ;
13807
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13808
 
13809
        config_read(addr_offset, 4'hF, read_data) ;
13810
        if (read_data[8] !== 0)
13811
        begin
13812
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13813
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13814
            ok = 0 ;
13815
        end
13816
        else
13817
            test_ok ;
13818
 
13819
        if ( ok !== 1 )
13820
        begin
13821
            config_write(addr_offset, read_data, 4'hF, ok) ;
13822
            if ( !ok )
13823
            begin
13824
                test_fail("PCI Error Control and Status register could not be written") ;
13825
                disable main ;
13826
            end
13827
        end
13828
 
13829
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON SECOND DATAPHASE" ;
13830
 
13831
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13832
 
13833
        fork
13834
        begin
13835
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13836
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13837
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13838
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13839
 
13840
            do_pause( 1 ) ;
13841
        end
13842
        begin
13843
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 1, 1'b1, ok ) ;
13844
 
13845
            if ( ok !== 1 )
13846
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13847
 
13848
            do_pause(3) ;
13849
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13850
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13851
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13852
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
13853
            do_pause(1) ;
13854
 
13855
            while ( FRAME === 0 )
13856
                @(posedge pci_clock) ;
13857
 
13858
            while ( IRDY === 0 )
13859
                @(posedge pci_clock) ;
13860
 
13861 35 mihad
            #1 ;
13862
            if ( !error_monitor_done )
13863
                disable monitor_error_event4 ;
13864 15 mihad
        end
13865
        begin:monitor_error_event4
13866 35 mihad
            error_monitor_done = 0 ;
13867 15 mihad
            @(error_event_int) ;
13868
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13869
            ok = 0 ;
13870 35 mihad
            error_monitor_done = 1 ;
13871 15 mihad
        end
13872
        begin
13873
            wb_transaction_stop( 1 ) ;
13874
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13875
        end
13876
        join
13877
 
13878
        if ( ok )
13879
            test_ok ;
13880
 
13881 26 mihad
        @(posedge pci_clock) ;
13882
        @(posedge pci_clock) ;
13883
        @(posedge wb_clock) ;
13884
        @(posedge wb_clock) ;
13885
 
13886 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
13887
        addr_offset = 12'h004 ;
13888
        config_read(addr_offset, 4'hF, read_data) ;
13889
        ok = 1 ;
13890
        if ( read_data[27] !== 1 )
13891
        begin
13892
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
13893
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
13894
            ok = 0 ;
13895
        end
13896
        if ( read_data[28] !== 0 )
13897
        begin
13898
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13899
            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") ;
13900
            ok = 0 ;
13901
        end
13902
        if ( read_data[29] !== 0 )
13903
        begin
13904
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
13905
            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") ;
13906
            ok = 0 ;
13907
        end
13908
 
13909
        // clear statuses
13910
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
13911
        if ( !ok )
13912
        begin
13913
            test_fail("write to PCI Device Status register failed") ;
13914
            $display("Couldn't write PCI Device Status register") ;
13915
            disable main ;
13916
        end
13917
 
13918
        if ( ok )
13919
            test_ok ;
13920
 
13921
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
13922
 
13923
        ok = 1 ;
13924
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
13925
 
13926
        config_read(addr_offset, 4'hF, read_data) ;
13927
        if (read_data[8] !== 0)
13928
        begin
13929
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
13930
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
13931
            ok = 0 ;
13932
        end
13933
        else
13934
            test_ok ;
13935
 
13936
        if ( ok !== 1 )
13937
        begin
13938
            config_write(addr_offset, read_data, 4'hF, ok) ;
13939
            if ( !ok )
13940
            begin
13941
                test_fail("PCI Error Control and Status register could not be written") ;
13942
                disable main ;
13943
            end
13944
        end
13945
 
13946
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
13947
 
13948
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
13949
 
13950
        fork
13951
        begin
13952
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13953
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13954
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13955
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
13956
 
13957
            do_pause( 1 ) ;
13958
        end
13959
        begin
13960
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
13961
 
13962
            if ( ok !== 1 )
13963
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
13964
 
13965
            do_pause(3) ;
13966
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
13967
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
13968
                        4, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
13969
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
13970
            do_pause(1) ;
13971
 
13972
            while ( FRAME === 0 )
13973
                @(posedge pci_clock) ;
13974
 
13975
            while ( IRDY === 0 )
13976
                @(posedge pci_clock) ;
13977
 
13978 35 mihad
            #1 ;
13979
            if ( !error_monitor_done )
13980
                disable monitor_error_event5 ;
13981 15 mihad
        end
13982
        begin:monitor_error_event5
13983 35 mihad
            error_monitor_done = 0 ;
13984 15 mihad
            @(error_event_int) ;
13985
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
13986
            ok = 0 ;
13987 35 mihad
            error_monitor_done = 1 ;
13988 15 mihad
        end
13989
        begin
13990
            wb_transaction_stop( 3 ) ;
13991
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
13992
        end
13993
        join
13994
 
13995
        if ( ok )
13996
            test_ok ;
13997
 
13998 26 mihad
        @(posedge pci_clock) ;
13999
        @(posedge pci_clock) ;
14000
        @(posedge wb_clock) ;
14001
        @(posedge wb_clock) ;
14002
 
14003 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14004
        addr_offset = 12'h004 ;
14005
        config_read(addr_offset, 4'hF, read_data) ;
14006
        ok = 1 ;
14007
        if ( read_data[27] !== 1 )
14008
        begin
14009
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14010
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14011
            ok = 0 ;
14012
        end
14013
        if ( read_data[28] !== 0 )
14014
        begin
14015
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14016
            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") ;
14017
            ok = 0 ;
14018
        end
14019
        if ( read_data[29] !== 0 )
14020
        begin
14021
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14022
            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") ;
14023
            ok = 0 ;
14024
        end
14025
 
14026
        // clear statuses
14027
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14028
        if ( !ok )
14029
        begin
14030
            test_fail("write to PCI Device Status register failed") ;
14031
            $display("Couldn't write PCI Device Status register") ;
14032
            disable main ;
14033
        end
14034
 
14035
        if ( ok )
14036
            test_ok ;
14037
 
14038
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14039
 
14040
        ok = 1 ;
14041
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14042
 
14043
        config_read(addr_offset, 4'hF, read_data) ;
14044
        if (read_data[8] !== 0)
14045
        begin
14046
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14047
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14048
            ok = 0 ;
14049
        end
14050
        else
14051
            test_ok ;
14052
 
14053
        if ( ok !== 1 )
14054
        begin
14055
            config_write(addr_offset, read_data, 4'hF, ok) ;
14056
            if ( !ok )
14057
            begin
14058
                test_fail("PCI Error Control and Status register could not be written") ;
14059
                disable main ;
14060
            end
14061
        end
14062
 
14063
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON ONE BEFORE LAST DATAPHASE" ;
14064
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14065
        fork
14066
        begin
14067
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14068
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14069
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14070
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14071
 
14072
            do_pause( 1 ) ;
14073
        end
14074
        begin
14075
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14076
 
14077
            if ( ok !== 1 )
14078
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14079
 
14080
            do_pause(3) ;
14081
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14082
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14083
                        5, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14084
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14085
            do_pause(1) ;
14086
 
14087
            while ( FRAME === 0 )
14088
                @(posedge pci_clock) ;
14089
 
14090
            while ( IRDY === 0 )
14091
                @(posedge pci_clock) ;
14092
 
14093 35 mihad
            #1 ;
14094
            if ( !error_monitor_done )
14095
                disable monitor_error_event6 ;
14096 15 mihad
        end
14097
        begin:monitor_error_event6
14098 35 mihad
            error_monitor_done = 0 ;
14099 15 mihad
            @(error_event_int) ;
14100
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14101
            ok = 0 ;
14102 35 mihad
            error_monitor_done = 1 ;
14103 15 mihad
        end
14104
        begin
14105
            wb_transaction_stop( 3 ) ;
14106
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14107
        end
14108
        join
14109
 
14110
        if ( ok )
14111
            test_ok ;
14112
 
14113 26 mihad
        @(posedge pci_clock) ;
14114
        @(posedge pci_clock) ;
14115
        @(posedge wb_clock) ;
14116
        @(posedge wb_clock) ;
14117
 
14118 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14119
        addr_offset = 12'h004 ;
14120
        config_read(addr_offset, 4'hF, read_data) ;
14121
        ok = 1 ;
14122
        if ( read_data[27] !== 1 )
14123
        begin
14124
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14125
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14126
            ok = 0 ;
14127
        end
14128
        if ( read_data[28] !== 0 )
14129
        begin
14130
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14131
            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") ;
14132
            ok = 0 ;
14133
        end
14134
        if ( read_data[29] !== 0 )
14135
        begin
14136
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14137
            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") ;
14138
            ok = 0 ;
14139
        end
14140
 
14141
        // clear statuses
14142
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14143
        if ( !ok )
14144
        begin
14145
            test_fail("write to PCI Device Status register failed") ;
14146
            $display("Couldn't write PCI Device Status register") ;
14147
            disable main ;
14148
        end
14149
 
14150
        if ( ok )
14151
            test_ok ;
14152
 
14153
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14154
 
14155
        ok = 1 ;
14156
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14157
 
14158
        config_read(addr_offset, 4'hF, read_data) ;
14159
        if (read_data[8] !== 0)
14160
        begin
14161
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14162
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14163
            ok = 0 ;
14164
        end
14165
        else
14166
            test_ok ;
14167
 
14168
        if ( ok !== 1 )
14169
        begin
14170
            config_write(addr_offset, read_data, 4'hF, ok) ;
14171
            if ( !ok )
14172
            begin
14173
                test_fail("PCI Error Control and Status register could not be written") ;
14174
                disable main ;
14175
            end
14176
        end
14177
 
14178
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE ON LAST DATAPHASE" ;
14179
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14180
        fork
14181
        begin
14182
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14183
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14184
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14185
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14186
 
14187
            do_pause( 1 ) ;
14188
        end
14189
        begin
14190
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14191
 
14192
            if ( ok !== 1 )
14193
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14194
 
14195
            do_pause(3) ;
14196
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14197
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14198
                        `PCIR_DEPTH - 1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14199
                        `Test_Devsel_Medium, `Test_Target_Abort_On);
14200
            do_pause(1) ;
14201
 
14202
            while ( FRAME === 0 )
14203
                @(posedge pci_clock) ;
14204
 
14205
            while ( IRDY === 0 )
14206
                @(posedge pci_clock) ;
14207
 
14208 35 mihad
            #1 ;
14209
            if ( !error_monitor_done )
14210
                disable monitor_error_event7 ;
14211 15 mihad
        end
14212
        begin:monitor_error_event7
14213 35 mihad
            error_monitor_done = 0 ;
14214 15 mihad
            @(error_event_int) ;
14215
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14216
            ok = 0 ;
14217 35 mihad
            error_monitor_done = 1 ;
14218 15 mihad
        end
14219
        begin
14220
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14221
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14222
        end
14223
        join
14224
 
14225
        if ( ok )
14226
            test_ok ;
14227
 
14228 26 mihad
        @(posedge pci_clock) ;
14229
        @(posedge pci_clock) ;
14230
        @(posedge wb_clock) ;
14231
        @(posedge wb_clock) ;
14232
 
14233 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14234
        addr_offset = 12'h004 ;
14235
        config_read(addr_offset, 4'hF, read_data) ;
14236
        ok = 1 ;
14237
        if ( read_data[27] !== 1 )
14238
        begin
14239
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14240
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14241
            ok = 0 ;
14242
        end
14243
        if ( read_data[28] !== 0 )
14244
        begin
14245
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14246
            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") ;
14247
            ok = 0 ;
14248
        end
14249
        if ( read_data[29] !== 0 )
14250
        begin
14251
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14252
            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") ;
14253
            ok = 0 ;
14254
        end
14255
 
14256
        // clear statuses
14257
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14258
        if ( !ok )
14259
        begin
14260
            test_fail("write to PCI Device Status register failed") ;
14261
            $display("Couldn't write PCI Device Status register") ;
14262
            disable main ;
14263
        end
14264
 
14265
        if ( ok )
14266
            test_ok ;
14267
 
14268
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14269
 
14270
        ok = 1 ;
14271
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14272
 
14273
        config_read(addr_offset, 4'hF, read_data) ;
14274
        if (read_data[8] !== 0)
14275
        begin
14276
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14277
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14278
            ok = 0 ;
14279
        end
14280
        else
14281
            test_ok ;
14282
 
14283
        if ( ok !== 1 )
14284
        begin
14285
            config_write(addr_offset, read_data, 4'hF, ok) ;
14286
            if ( !ok )
14287
            begin
14288
                test_fail("PCI Error Control and Status register could not be written") ;
14289
                disable main ;
14290
            end
14291
        end
14292
 
14293
        test_name = "FULL FIFO BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE BEFORE LAST DATAPHASE" ;
14294
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14295
        fork
14296
        begin
14297
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14298
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14299
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14300
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14301
 
14302
            do_pause( 1 ) ;
14303
        end
14304
        begin
14305
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, `PCIR_DEPTH - 2, 1'b1, ok ) ;
14306
 
14307
            if ( ok !== 1 )
14308
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14309
 
14310
            do_pause(3) ;
14311
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14312
                        `BC_MEM_READ_MUL, 32'h1234_5678, 4'hF,
14313
                        `PCIR_DEPTH, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14314
                        `Test_Devsel_Medium, `Test_Target_Abort_Before);
14315
            do_pause(1) ;
14316
 
14317
            while ( FRAME === 0 )
14318
                @(posedge pci_clock) ;
14319
 
14320
            while ( IRDY === 0 )
14321
                @(posedge pci_clock) ;
14322
 
14323 35 mihad
            #1 ;
14324
            if ( !error_monitor_done )
14325
                disable monitor_error_event8 ;
14326 15 mihad
        end
14327
        begin:monitor_error_event8
14328 35 mihad
            error_monitor_done = 0 ;
14329 15 mihad
            @(error_event_int) ;
14330
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14331
            ok = 0 ;
14332 35 mihad
            error_monitor_done = 1 ;
14333 15 mihad
        end
14334
        begin
14335
            wb_transaction_stop( `PCIR_DEPTH - 2 ) ;
14336
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14337
        end
14338
        join
14339
 
14340
        if ( ok )
14341
            test_ok ;
14342
 
14343 26 mihad
        @(posedge pci_clock) ;
14344
        @(posedge pci_clock) ;
14345
        @(posedge wb_clock) ;
14346
        @(posedge wb_clock) ;
14347
 
14348 15 mihad
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14349
 
14350
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14351
        addr_offset = 12'h004 ;
14352
        config_read(addr_offset, 4'hF, read_data) ;
14353
        ok = 1 ;
14354
        if ( read_data[27] !== 1 )
14355
        begin
14356
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14357
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14358
            ok = 0 ;
14359
        end
14360
        if ( read_data[28] !== 0 )
14361
        begin
14362
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14363
            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") ;
14364
            ok = 0 ;
14365
        end
14366
        if ( read_data[29] !== 0 )
14367
        begin
14368
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14369
            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") ;
14370
            ok = 0 ;
14371
        end
14372
 
14373
        // clear statuses
14374
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14375
        if ( !ok )
14376
        begin
14377
            test_fail("write to PCI Device Status register failed") ;
14378
            $display("Couldn't write PCI Device Status register") ;
14379
            disable main ;
14380
        end
14381
 
14382
        if ( ok )
14383
            test_ok ;
14384
 
14385
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14386
 
14387
        ok = 1 ;
14388
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14389
 
14390
        config_read(addr_offset, 4'hF, read_data) ;
14391
        if (read_data[8] !== 0)
14392
        begin
14393
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14394
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14395
            ok = 0 ;
14396
        end
14397
        else
14398
            test_ok ;
14399
 
14400
        if ( ok !== 1 )
14401
        begin
14402
            config_write(addr_offset, read_data, 4'hF, ok) ;
14403
            if ( !ok )
14404
            begin
14405
                test_fail("PCI Error Control and Status register could not be written") ;
14406
                disable main ;
14407
            end
14408
        end
14409
 
14410
        test_name = "BURST READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE, ERROR NOT PULLED OUT ON PCI" ;
14411
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14412
        fork
14413
        begin
14414
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14415
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14416
                        2, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14417
                        `Test_Devsel_Medium, `Test_Target_Retry_Before);
14418
 
14419
            do_pause( 1 ) ;
14420
        end
14421
        begin
14422
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_mem_image], 1'b0, 3, 1'b1, ok ) ;
14423
 
14424
            if ( ok !== 1 )
14425
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14426
 
14427
            do_pause(3) ;
14428
            PCIU_READ (1, Target_Base_Addr_R[target_mem_image],
14429
                        `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
14430
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
14431
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
14432
            do_pause(1) ;
14433
 
14434
            while ( FRAME === 0 )
14435
                @(posedge pci_clock) ;
14436
 
14437
            while ( IRDY === 0 )
14438
                @(posedge pci_clock) ;
14439
 
14440 35 mihad
            #1 ;
14441
            if ( !error_monitor_done )
14442
                disable monitor_error_event9 ;
14443 15 mihad
        end
14444
        begin:monitor_error_event9
14445 35 mihad
            error_monitor_done = 0 ;
14446 15 mihad
            @(error_event_int) ;
14447
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14448
            ok = 0 ;
14449 35 mihad
            error_monitor_done = 1 ;
14450 15 mihad
        end
14451
        begin
14452
            wb_transaction_stop( 3 ) ;
14453
            wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14454
        end
14455
        join
14456
 
14457
        if ( ok )
14458
            test_ok ;
14459
 
14460
        // now check all other statuses too
14461
        test_name = "ALL PCI DEVICE STATUSES AFTER ERRONEOUS TARGET READS" ;
14462
        ok = 1 ;
14463
 
14464
        addr_offset = 12'h004 ;
14465
        config_read(addr_offset, 4'hF, read_data) ;
14466
        if (read_data[31] !== 0)
14467
        begin
14468
            $display("Detected Parity Error bit set for no reason") ;
14469
            test_fail("Detected Parity Error bit was set for no reason") ;
14470
            ok = 0 ;
14471
        end
14472
 
14473
        if (read_data[30] !== 0)
14474
        begin
14475
            $display("Signaled System Error bit set for no reason") ;
14476
            test_fail("Signaled System Error bit was set for no reason") ;
14477
            ok = 0 ;
14478
        end
14479
 
14480
        if (read_data[29] !== 0)
14481
        begin
14482
            $display("Received Master Abort bit set for no reason") ;
14483
            test_fail("Received Master Abort bit was set for no reason") ;
14484
            ok = 0 ;
14485
        end
14486
 
14487
        if (read_data[28] !== 0)
14488
        begin
14489
            $display("Received Target Abort bit set for no reason");
14490
            test_fail("Received Target Abort bit was set for no reason") ;
14491
            ok = 0 ;
14492
        end
14493
 
14494
        if (read_data[27] !== 0)
14495
        begin
14496
            $display("Signaled Target Abort bit set after it was cleared by writing one to its location") ;
14497
            test_fail("Signaled Target Abort bit was set after it was cleared by writing one to its location") ;
14498
            ok = 0 ;
14499
        end
14500
 
14501
        if (read_data[24] !== 0)
14502
        begin
14503
            $display("Master Data Parity Error bit set for no reason") ;
14504
            test_fail("Master Data Parity Error bit was set for no reason") ;
14505
            ok = 0 ;
14506
        end
14507
 
14508
        if ( ok )
14509
            test_ok ;
14510
 
14511
        test_name = "DISABLE IMAGE" ;
14512 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14513 15 mihad
        if ( ok !== 1 )
14514
        begin
14515
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14516
            test_fail("PCI Address Mask register could not be written") ;
14517
            disable main;
14518
        end
14519
    end
14520
 
14521
    if ( target_io_image !== -1 )
14522
    begin
14523
        do_io_aborts = 1 ;
14524
 
14525
        if (target_io_image === 1)
14526
        begin
14527
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14528
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14529
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14530
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14531
        end
14532
        else if (target_io_image === 2)
14533
        begin
14534
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14535
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14536
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14537
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14538
        end
14539
        else if (target_io_image === 3)
14540
        begin
14541
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14542
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14543
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14544
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14545
        end
14546
        else if (target_io_image === 4)
14547
        begin
14548
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14549
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14550
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14551
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14552
        end
14553
        else if (target_io_image === 5)
14554
        begin
14555
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14556
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14557
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14558
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14559
        end
14560
    end
14561
    else
14562
        do_io_aborts = 0 ;
14563
 
14564
    if ( do_io_aborts )
14565
    begin
14566
 
14567
        test_name = "CONFIGURE BRIDGE FOR ERROR TERMINATED READS THROUGH PCI TARGET UNIT" ;
14568
 
14569
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14570
        config_write( addr_offset, 32'hFFFF_FFFF, 4'hF, ok) ;
14571
        if ( ok !== 1 )
14572
        begin
14573
            $display("Erroneous PCI Target read testing failed! Failed to write P_ERR_CS register! Time %t ", $time);
14574
            test_fail("PCI Error Control and Status register could not be written") ;
14575
            disable main;
14576
        end
14577
 
14578
        // enable INTERRUPT reporting
14579
        addr_offset = {4'h1, `ICR_ADDR, 2'b00} ;
14580
        config_write( addr_offset, 32'h7FFF_FFFF, 4'hF, ok) ;
14581
        if ( ok !== 1 )
14582
        begin
14583
            $display("Erroneous PCI Target read testing failed! Failed to write ICR register! Time %t ", $time);
14584
            test_fail("Interrupt Control register could not be written") ;
14585
            disable main;
14586
        end
14587
 
14588
        addr_offset = 12'h010 + (4*target_io_image) ;
14589
 
14590
        config_write( addr_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
14591
        if ( ok !== 1 )
14592
        begin
14593
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Base Address register! Time %t ", $time);
14594
            test_fail("PCI Base Address register could not be written") ;
14595
            disable main;
14596
        end
14597
 
14598
        // disable address translation and enable prefetch so read bursts can be performed
14599
        config_write( ctrl_offset, 32'h0000_0002, 4'h1, ok ) ;
14600
        if ( ok !== 1 )
14601
        begin
14602
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Image Control register! Time %t ", $time);
14603
            test_fail("PCI Image Control register could not be written") ;
14604
            disable main;
14605
        end
14606
 
14607
        config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
14608
        if ( ok !== 1 )
14609
        begin
14610
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14611
            test_fail("PCI Address Mask register could not be written") ;
14612
            disable main;
14613
        end
14614
 
14615
        addr_offset = 12'h00C ;
14616
 
14617
        config_write( addr_offset, 32'h0000_04_04, 4'hF, ok ) ;
14618
        if ( ok !== 1 )
14619
        begin
14620
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Latency Timer/Cache line size register! Time %t ", $time);
14621
            test_fail("PCI Latency Timer/Cache line size register could not be written") ;
14622
            disable main;
14623
        end
14624
 
14625
        // set response of WB SLAVE - ERR,    WAIT cycles,        RETRY cycles
14626
        wishbone_slave.cycle_response(3'b010, tb_subseq_waits, 8'h0);
14627
 
14628
        // do a single read error terminated on WB bus
14629
        test_name = "SINGLE I/O READ THROUGH PCI TARGET TERMINATED WITH ERROR ON WISHBONE" ;
14630
 
14631
        fork
14632
        begin
14633
            PCIU_IO_READ
14634
             (
14635
                `Test_Master_1,
14636
                Target_Base_Addr_R[target_io_image],
14637
                32'hAAAA_5555,
14638
                4'h0,
14639
                1,
14640
                `Test_Target_Retry_On
14641
             );
14642
 
14643
            do_pause( 1 ) ;
14644
        end
14645
        begin
14646
            wb_transaction_progress_monitor( Target_Base_Addr_R[target_io_image], 1'b0, 0, 1'b1, ok ) ;
14647
 
14648
            if ( ok !== 1 )
14649
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus") ;
14650
 
14651
            do_pause(3) ;
14652
 
14653
            PCIU_IO_READ
14654
             (
14655
                `Test_Master_1,
14656
                Target_Base_Addr_R[target_io_image],
14657
                32'hAAAA_5555,
14658
                4'h0,
14659
                1,
14660
                `Test_Target_Abort_On
14661
             );
14662
 
14663
            do_pause( 1 ) ;
14664
 
14665
            while ( FRAME === 0 )
14666
                @(posedge pci_clock) ;
14667
 
14668
            while ( IRDY === 0 )
14669
                @(posedge pci_clock) ;
14670
 
14671 35 mihad
            #1 ;
14672
            if ( !error_monitor_done )
14673
                disable monitor_error_event10 ;
14674 15 mihad
        end
14675
        begin:monitor_error_event10
14676 35 mihad
            error_monitor_done = 0 ;
14677 15 mihad
            @(error_event_int) ;
14678
            test_fail("either PCI Monitor or PCI Master detected an error while reading through PCI Target Unit") ;
14679
            ok = 0 ;
14680 35 mihad
            error_monitor_done = 1 ;
14681 15 mihad
        end
14682
        join
14683
 
14684
        if ( ok )
14685
            test_ok ;
14686
 
14687 26 mihad
        @(posedge pci_clock) ;
14688
        @(posedge pci_clock) ;
14689
        @(posedge wb_clock) ;
14690
        @(posedge wb_clock) ;
14691
 
14692 15 mihad
        test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
14693
        addr_offset = 12'h004 ;
14694
        config_read(addr_offset, 4'hF, read_data) ;
14695
        ok = 1 ;
14696
        if ( read_data[27] !== 1 )
14697
        begin
14698
            $display("Signaled Target Abort bit not set in PCI Device Status register after read terminated with Target Abort") ;
14699
            test_fail("Signaled Target Abort bit was not set in PCI Device Status register after read terminated with Target Abort") ;
14700
            ok = 0 ;
14701
        end
14702
        if ( read_data[28] !== 0 )
14703
        begin
14704
            $display("Received Target Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14705
            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") ;
14706
            ok = 0 ;
14707
        end
14708
        if ( read_data[29] !== 0 )
14709
        begin
14710
            $display("Received Master Abort bit set in PCI Device Status register after Target read terminated with Target Abort. Master was not working") ;
14711
            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") ;
14712
            ok = 0 ;
14713
        end
14714
 
14715
        // clear statuses
14716
        config_write(addr_offset, {2'b00, read_data[29:27], 27'h0}, 4'b11_00, ok) ;
14717
        if ( !ok )
14718
        begin
14719
            test_fail("write to PCI Device Status register failed") ;
14720
            $display("Couldn't write PCI Device Status register") ;
14721
            disable main ;
14722
        end
14723
 
14724
        if ( ok )
14725
            test_ok ;
14726
 
14727
        addr_offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
14728
 
14729
        ok = 1 ;
14730
        test_name = "PCI ERROR CONTROL AND STATUS REGISTER VALUE AFTER READ THROUGH TARGET TERMINATED WITH TARGET ABORT" ;
14731
 
14732
        config_read(addr_offset, 4'hF, read_data) ;
14733
        if (read_data[8] !== 0)
14734
        begin
14735
            $display("Error signaled bit set after Target Read Terminated with Error on WISHBONE. Error reporting should be done only for posted writes") ;
14736
            test_fail("Error signaled bit set after Target Read Terminated with Error on WISHBONE") ;
14737
            ok = 0 ;
14738
        end
14739
        else
14740
            test_ok ;
14741
 
14742
        if ( ok !== 1 )
14743
        begin
14744
            config_write(addr_offset, read_data, 4'hF, ok) ;
14745
            if ( !ok )
14746
            begin
14747
                test_fail("PCI Error Control and Status register could not be written") ;
14748
                disable main ;
14749
            end
14750
        end
14751
 
14752
        test_name = "DISABLE IMAGE" ;
14753 45 mihad
        config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
14754 15 mihad
        if ( ok !== 1 )
14755
        begin
14756
            $display("Erroneous PCI Target read testing failed! Failed to write PCI Address Mask register! Time %t ", $time);
14757
            test_fail("PCI Address Mask register could not be written") ;
14758
            disable main;
14759
        end
14760
 
14761
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
14762
 
14763
    end
14764
end // main
14765
endtask // test_wb_error_rd
14766
 
14767
task test_target_abort ;
14768
    input [2:0]  image_num ;
14769
    reg   [11:0] pci_ctrl_offset ;
14770
    reg   [11:0] ctrl_offset ;
14771
    reg   [11:0] ba_offset ;
14772
    reg   [11:0] am_offset ;
14773
    reg   [11:0] ta_offset ;
14774
    reg   [31:0] pci_address ;
14775
    reg   [3:0]  byte_enables ;
14776
    reg          ok ;
14777 35 mihad
    reg          error_monitor_done ;
14778 15 mihad
begin:main
14779
    pci_ctrl_offset = 12'h4 ;
14780
    if (image_num === 0)
14781
    begin
14782
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
14783
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
14784
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
14785
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
14786
    end
14787
    else if (image_num === 1)
14788
    begin
14789
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
14790
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
14791
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
14792
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
14793
    end
14794
    else if (image_num === 2)
14795
    begin
14796
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
14797
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
14798
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
14799
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
14800
    end
14801
    else if (image_num === 3)
14802
    begin
14803
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
14804
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
14805
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
14806
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
14807
    end
14808
    else if (image_num === 4)
14809
    begin
14810
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
14811
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
14812
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
14813
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
14814
    end
14815
    else if (image_num === 5)
14816
    begin
14817
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
14818
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
14819
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
14820
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
14821
    end
14822
 
14823
    test_name = "CONFIGURE TARGET FOR TARGET ABORT TESTING" ;
14824
 
14825
    config_write( ba_offset, Target_Base_Addr_R[image_num] | 32'h0000_0001, 4'hF, ok ) ;
14826
    if ( ok !== 1 )
14827
    begin
14828
        $display("Target Abort testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
14829
        test_fail("PCI Base Address register could not be written") ;
14830
        disable main ;
14831
    end
14832
 
14833
    // Set Address Mask of IMAGE
14834
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
14835
    if ( ok !== 1 )
14836
    begin
14837
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
14838
        test_fail("PCI Address Mask register could not be written") ;
14839
        disable main ;
14840
    end
14841
 
14842
    // Set Translation Address of IMAGE
14843
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
14844
    if ( ok !== 1 )
14845
    begin
14846
        $display("Target Abort testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
14847
        test_fail("PCI Translation Address Register could not be written") ;
14848
        disable main ;
14849
    end
14850
 
14851
    config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
14852
    if ( ok !== 1 )
14853
    begin
14854
        $display("Target Abort testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
14855
        test_fail("PCI Image Control register could not be written") ;
14856
        disable main ;
14857
    end
14858
 
14859
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
14860
 
14861
    test_name = "TARGET ABORT SIGNALING ON I/O ACCESSES WITH INVALID ADDRESS/BYTE ENABLE COMBINATION" ;
14862
 
14863
    pci_address  = Target_Base_Addr_R[image_num] ;
14864
    byte_enables = 4'b0001 ;
14865
 
14866
    fork
14867
    begin
14868
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14869
        do_pause ( 1 ) ;
14870
    end
14871
    begin:monitor_error_event1
14872 35 mihad
        error_monitor_done = 0 ;
14873 15 mihad
        @(error_event_int) ;
14874
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14875
        ok = 0 ;
14876 35 mihad
        error_monitor_done = 1 ;
14877 15 mihad
    end
14878
    begin
14879
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14880
        @(posedge pci_clock) ;
14881 35 mihad
        #1 ;
14882
        if ( !error_monitor_done )
14883
            disable monitor_error_event1 ;
14884 15 mihad
    end
14885
    join
14886
 
14887
    if ( ok )
14888
        test_ok ;
14889
 
14890
    ok = 1 ;
14891
 
14892
    fork
14893
    begin
14894
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14895
        do_pause ( 1 ) ;
14896
    end
14897
    begin:monitor_error_event2
14898 35 mihad
        error_monitor_done = 0 ;
14899 15 mihad
        @(error_event_int) ;
14900
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14901
        ok = 0 ;
14902 35 mihad
        error_monitor_done = 1 ;
14903 15 mihad
    end
14904
    begin
14905
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14906
        @(posedge pci_clock) ;
14907 35 mihad
        #1 ;
14908
        if ( !error_monitor_done )
14909
            disable monitor_error_event2 ;
14910 15 mihad
    end
14911
    join
14912
 
14913
    if ( ok )
14914
        test_ok ;
14915
 
14916
    ok = 1 ;
14917
 
14918
    pci_address  = Target_Base_Addr_R[image_num] + 1 ;
14919
    byte_enables = 4'b0011 ;
14920
 
14921
    fork
14922
    begin
14923
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14924
        do_pause ( 1 ) ;
14925
    end
14926
    begin:monitor_error_event3
14927 35 mihad
        error_monitor_done = 0 ;
14928 15 mihad
        @(error_event_int) ;
14929
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14930
        ok = 0 ;
14931 35 mihad
        error_monitor_done = 1 ;
14932 15 mihad
    end
14933
    begin
14934
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14935
        @(posedge pci_clock) ;
14936 35 mihad
        if ( !error_monitor_done )
14937
            disable monitor_error_event3 ;
14938 15 mihad
    end
14939
    join
14940
 
14941
    if ( ok )
14942
        test_ok ;
14943
 
14944
    ok = 1 ;
14945
 
14946
    byte_enables = 4'b0000 ;
14947
 
14948
    fork
14949
    begin
14950
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
14951
        do_pause ( 1 ) ;
14952
    end
14953
    begin:monitor_error_event4
14954 35 mihad
        error_monitor_done = 0 ;
14955 15 mihad
        @(error_event_int) ;
14956
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14957
        ok = 0 ;
14958 35 mihad
        error_monitor_done = 1 ;
14959 15 mihad
    end
14960
    begin
14961
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14962
        @(posedge pci_clock) ;
14963 35 mihad
        #1 ;
14964
        if ( !error_monitor_done )
14965
            disable monitor_error_event4 ;
14966 15 mihad
    end
14967
    join
14968
 
14969
    if ( ok )
14970
        test_ok ;
14971
 
14972
    ok = 1 ;
14973
 
14974
    pci_address  = Target_Base_Addr_R[image_num] + 2 ;
14975
    byte_enables = 4'b0111 ;
14976
 
14977
    fork
14978
    begin
14979
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
14980
        do_pause ( 1 ) ;
14981
    end
14982
    begin:monitor_error_event5
14983 35 mihad
        error_monitor_done = 0 ;
14984 15 mihad
        @(error_event_int) ;
14985
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
14986
        ok = 0 ;
14987 35 mihad
        error_monitor_done = 1 ;
14988 15 mihad
    end
14989
    begin
14990
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
14991
        @(posedge pci_clock) ;
14992 35 mihad
        #1 ;
14993
        if ( !error_monitor_done )
14994
            disable monitor_error_event5 ;
14995 15 mihad
    end
14996
    join
14997
 
14998
    if ( ok )
14999
        test_ok ;
15000
 
15001
    ok = 1 ;
15002
 
15003
    byte_enables = 4'b0010 ;
15004
 
15005
    fork
15006
    begin
15007
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15008
        do_pause ( 1 ) ;
15009
    end
15010
    begin:monitor_error_event6
15011 35 mihad
        error_monitor_done = 0 ;
15012 15 mihad
        @(error_event_int) ;
15013
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15014
        ok = 0 ;
15015 35 mihad
        error_monitor_done = 1 ;
15016 15 mihad
    end
15017
    begin
15018
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15019
        @(posedge pci_clock) ;
15020 35 mihad
        #1 ;
15021
        if ( !error_monitor_done )
15022
            disable monitor_error_event6 ;
15023 15 mihad
    end
15024
    join
15025
 
15026
    if ( ok )
15027
        test_ok ;
15028
 
15029
    ok = 1 ;
15030
    byte_enables = 4'b0001 ;
15031
 
15032
    fork
15033
    begin
15034
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15035
        do_pause ( 1 ) ;
15036
    end
15037
    begin:monitor_error_event7
15038 35 mihad
        error_monitor_done = 0 ;
15039 15 mihad
        @(error_event_int) ;
15040
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15041
        ok = 0 ;
15042 35 mihad
        error_monitor_done = 1 ;
15043 15 mihad
    end
15044
    begin
15045
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15046
        @(posedge pci_clock) ;
15047 35 mihad
        #1 ;
15048
        if ( !error_monitor_done )
15049
            disable monitor_error_event7 ;
15050 15 mihad
    end
15051
    join
15052
 
15053
    if ( ok )
15054
        test_ok ;
15055
 
15056
    ok = 1 ;
15057
    byte_enables = 4'b0000 ;
15058
 
15059
    fork
15060
    begin
15061
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Abort_On) ;
15062
        do_pause ( 1 ) ;
15063
    end
15064
    begin:monitor_error_event8
15065 35 mihad
        error_monitor_done = 0 ;
15066 15 mihad
        @(error_event_int) ;
15067
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15068
        ok = 0 ;
15069 35 mihad
        error_monitor_done = 1 ;
15070 15 mihad
    end
15071
    begin
15072
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15073
        @(posedge pci_clock) ;
15074 35 mihad
        #1 ;
15075
        if ( !error_monitor_done )
15076
            disable monitor_error_event8 ;
15077 15 mihad
    end
15078
    join
15079
 
15080
    if ( ok )
15081
        test_ok ;
15082
 
15083
    ok = 1 ;
15084
 
15085
    pci_address  = Target_Base_Addr_R[image_num] + 3 ;
15086
    byte_enables = 4'b0110 ;
15087
 
15088
    fork
15089
    begin
15090
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15091
        do_pause ( 1 ) ;
15092
    end
15093
    begin:monitor_error_event9
15094 35 mihad
        error_monitor_done = 0 ;
15095 15 mihad
        @(error_event_int) ;
15096
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15097
        ok = 0 ;
15098 35 mihad
        error_monitor_done = 1 ;
15099 15 mihad
    end
15100
    begin
15101
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15102
        @(posedge pci_clock) ;
15103 35 mihad
        #1 ;
15104
        if ( !error_monitor_done )
15105
            disable monitor_error_event9 ;
15106 15 mihad
    end
15107
    join
15108
 
15109
    if ( ok )
15110
        test_ok ;
15111
 
15112
    ok = 1 ;
15113
    fork
15114
    begin
15115
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hA1A2_A3A4, byte_enables, 1, `Test_Target_Abort_On) ;
15116
        do_pause ( 1 ) ;
15117
    end
15118
    begin:monitor_error_event10
15119 35 mihad
        error_monitor_done = 0 ;
15120 15 mihad
        @(error_event_int) ;
15121
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15122
        ok = 0 ;
15123 35 mihad
        error_monitor_done = 1 ;
15124 15 mihad
    end
15125
    begin
15126
        pci_transaction_progress_monitor( pci_address, `BC_IO_READ, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15127
        @(posedge pci_clock) ;
15128 35 mihad
 
15129
        #1 ;
15130
        if ( !error_monitor_done )
15131
            disable monitor_error_event10 ;
15132 15 mihad
    end
15133
    join
15134
 
15135
    if ( ok )
15136
        test_ok ;
15137
 
15138
    ok = 1 ;
15139
 
15140
    byte_enables = 4'b0001 ;
15141
 
15142
    fork
15143
    begin
15144
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15145
        do_pause ( 1 ) ;
15146
    end
15147
    begin:monitor_error_event11
15148 35 mihad
        error_monitor_done = 0 ;
15149 15 mihad
        @(error_event_int) ;
15150
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15151
        ok = 0 ;
15152 35 mihad
        error_monitor_done = 1 ;
15153 15 mihad
    end
15154
    begin
15155
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15156
        @(posedge pci_clock) ;
15157 35 mihad
        #1 ;
15158
        if ( !error_monitor_done )
15159
            disable monitor_error_event11 ;
15160 15 mihad
    end
15161
    join
15162
 
15163
    if ( ok )
15164
        test_ok ;
15165
 
15166
    ok = 1 ;
15167
 
15168
    byte_enables = 4'b0101 ;
15169
 
15170
    fork
15171
    begin
15172
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15173
        do_pause ( 1 ) ;
15174
    end
15175
    begin:monitor_error_event12
15176 35 mihad
        error_monitor_done = 0 ;
15177 15 mihad
        @(error_event_int) ;
15178
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15179
        ok = 0 ;
15180 35 mihad
        error_monitor_done = 1 ;
15181 15 mihad
    end
15182
    begin
15183
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15184
        @(posedge pci_clock) ;
15185 35 mihad
        #1 ;
15186
        if ( !error_monitor_done )
15187
            disable monitor_error_event12 ;
15188 15 mihad
    end
15189
    join
15190
 
15191
    if ( ok )
15192
        test_ok ;
15193
 
15194
    ok = 1 ;
15195
 
15196
    byte_enables = 4'b0011 ;
15197
 
15198
    fork
15199
    begin
15200
        PCIU_IO_WRITE( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 2, `Test_Target_Abort_Before) ;
15201
        do_pause ( 1 ) ;
15202
    end
15203
    begin:monitor_error_event13
15204 35 mihad
        error_monitor_done = 0 ;
15205 15 mihad
        @(error_event_int) ;
15206
        test_fail("PCI Master or Monitor detected invalid operation on PCI bus") ;
15207
        ok = 0 ;
15208 35 mihad
        error_monitor_done = 1 ;
15209 15 mihad
    end
15210
    begin
15211
        pci_transaction_progress_monitor( pci_address, `BC_IO_WRITE, 0, 0, 1'b1, 1'b0, 0, ok ) ;
15212
        @(posedge pci_clock) ;
15213 35 mihad
        #1 ;
15214
        if ( !error_monitor_done )
15215
            disable monitor_error_event13 ;
15216 15 mihad
    end
15217
    join
15218
 
15219
    if ( ok )
15220
        test_ok ;
15221
 
15222
    test_name = "PCI DEVICE STATUS REGISTER VALUE AFTER TARGET ABORT" ;
15223
    config_read(pci_ctrl_offset, 4'hF, pci_address) ;
15224
    ok = 1 ;
15225
    if ( pci_address[27] !== 1 )
15226
    begin
15227
        $display("Signaled Target Abort bit not set in PCI Device Status register after a few Target Aborts were signaled") ;
15228
        test_fail("Signaled Target Abort bit was not set in PCI Device Status register after target terminated with Target Abort") ;
15229
        ok = 0 ;
15230
    end
15231
    if ( pci_address[28] !== 0 )
15232
    begin
15233
        $display("Received Target Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15234
        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") ;
15235
        ok = 0 ;
15236
    end
15237
    if ( pci_address[29] !== 0 )
15238
    begin
15239
        $display("Received Master Abort bit set in PCI Device Status register after Target terminated with Target Abort. Master was not working") ;
15240
        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") ;
15241
        ok = 0 ;
15242
    end
15243
 
15244
    // clear statuses
15245
    config_write(pci_ctrl_offset, {2'b00, pci_address[29:27], 27'h0}, 4'b11_00, ok) ;
15246
    if ( !ok )
15247
    begin
15248
        test_fail("write to PCI Device Status register failed") ;
15249
        $display("Couldn't write PCI Device Status register") ;
15250
        disable main ;
15251
    end
15252
 
15253
    if ( ok )
15254
        test_ok ;
15255
 
15256
    test_name = "ERROR CONTROL AND STATUS REGISTER VALUE CHECK AFTER TARGET ABORTS" ;
15257
    config_read({4'h1, `P_ERR_CS_ADDR, 2'b00}, 4'hF, pci_address) ;
15258
    if ( pci_address[8] !== 0 )
15259
    begin
15260
        test_fail("writes and reads terminated with Target Aborts on PCI side should not proceede to WISHBONE bus") ;
15261
    end
15262
    else
15263
        test_ok ;
15264
 
15265
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15266
 
15267
    test_name = "DISABLE IMAGE" ;
15268
 
15269 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
15270 15 mihad
    if ( ok !== 1 )
15271
    begin
15272
        $display("Target Abort testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
15273
        test_fail("PCI Address Mask register could not be written") ;
15274
        disable main ;
15275
    end
15276
end
15277
endtask // test_target_abort
15278
 
15279
task test_target_io_wr_rd ;
15280
    input [2:0]  image_num ;
15281
    input        translate_address ;
15282
    input [11:0] img_ctrl_offset ;
15283
    reg   [31:0] expect_address ;
15284
    reg   [31:0] pci_address ;
15285
    reg          translation ;
15286
    reg   [31:0] read_data ;
15287
    reg   [3:0]  byte_enables ;
15288
    reg          ok ;
15289
    reg          pci_ok ;
15290
    reg          wb_ok ;
15291
    integer      i ;
15292 35 mihad
    reg          error_monitor_done ;
15293 15 mihad
begin:main
15294
    `ifdef ADDR_TRAN_IMPL
15295
        translation = translate_address ;
15296
    `else
15297
        translation = 0 ;
15298
    `endif
15299
 
15300
    wishbone_slave.cycle_response( 3'b100, tb_subseq_waits, 0 ) ;
15301
 
15302
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15303
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15304
    if ( translation )
15305
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15306
    else
15307
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15308
 
15309
    if ( !ok )
15310
    begin
15311
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15312
        test_fail("PCI Image Control register could not be written") ;
15313
    end
15314
 
15315
    test_name = "BYTE ADDRESSABLE WRITES THROUGH TARGET IO IMAGE" ;
15316
    pci_address  = Target_Base_Addr_R[image_num] ;
15317
    byte_enables = 4'b0000 ;
15318
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15319
 
15320
    fork
15321
    begin
15322
        PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'h5555_5555, byte_enables, 1, `Test_Target_Normal_Completion) ;
15323
        do_pause ( 1 ) ;
15324
    end
15325
    begin
15326
        wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15327
        if ( wb_ok !== 1 )
15328
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15329
 
15330 35 mihad
        #1 ;
15331
        if ( !error_monitor_done )
15332
            disable monitor_pci_error_1 ;
15333 15 mihad
    end
15334
    begin:monitor_pci_error_1
15335 35 mihad
        error_monitor_done = 0 ;
15336 15 mihad
        pci_ok = 1 ;
15337
        @(error_event_int) ;
15338
        pci_ok = 0 ;
15339
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO refernce to Target" ) ;
15340 35 mihad
        error_monitor_done = 1 ;
15341 15 mihad
    end
15342
    join
15343
 
15344
    byte_enables = 4'b1111 ;
15345
    for ( i = 0 ; i < 4 ; i = i + 1 )
15346
    begin:loop_1
15347
        byte_enables[i] = 0 ;
15348
        if ( i > 0 )
15349
            byte_enables[i - 1] = 1 ;
15350
        fork
15351
        begin
15352
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15353
            do_pause ( 1 ) ;
15354
        end
15355
        begin
15356
            wb_transaction_progress_monitor( expect_address, 1'b1, 1, 1'b1, wb_ok ) ;
15357
            if ( wb_ok !== 1 )
15358
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15359
 
15360 35 mihad
            #1 ;
15361
            if ( !error_monitor_done )
15362
                disable monitor_pci_error_2 ;
15363 15 mihad
        end
15364
        begin:monitor_pci_error_2
15365 35 mihad
            error_monitor_done = 0 ;
15366 15 mihad
            pci_ok = 1 ;
15367
            @(error_event_int) ;
15368
            pci_ok = 0 ;
15369
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15370 35 mihad
            error_monitor_done = 1 ;
15371 15 mihad
        end
15372
        join
15373
 
15374
        if ( !pci_ok || !wb_ok )
15375
            disable loop_1 ;
15376
 
15377
        pci_address = pci_address + 1 ;
15378
        expect_address = expect_address + 1 ;
15379
    end
15380
 
15381
    if ( pci_ok && wb_ok )
15382
        test_ok ;
15383
 
15384
    test_name = "READ BY WORDS IO DATA PREVIOUSLY WRITTEN BY BYTES" ;
15385
    pci_address  = Target_Base_Addr_R[image_num] ;
15386
    byte_enables = 4'b1100 ;
15387
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15388
 
15389
    master1_check_received_data = 1 ;
15390
    fork
15391
    begin
15392
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15393
        do_pause( 1 ) ;
15394
    end
15395
    begin
15396
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15397
        if ( wb_ok !== 1 )
15398
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15399
 
15400
        do_pause ( 2 ) ;
15401
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15402
        do_pause ( 16 ) ;
15403
 
15404 35 mihad
        #1 ;
15405
        if ( !error_monitor_done )
15406
            disable monitor_pci_error_3 ;
15407 15 mihad
    end
15408
    begin:monitor_pci_error_3
15409 35 mihad
        error_monitor_done = 0 ;
15410 15 mihad
        pci_ok = 1 ;
15411
        @(error_event_int) ;
15412
        pci_ok = 0 ;
15413
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15414 35 mihad
        error_monitor_done = 1 ;
15415 15 mihad
    end
15416
    join
15417
 
15418
    if ( !pci_ok || !wb_ok )
15419
    begin
15420
        disable main ;
15421
    end
15422
 
15423
    pci_address  = Target_Base_Addr_R[image_num] + 2;
15424
    byte_enables = 4'b0011 ;
15425
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15426
 
15427
    master1_check_received_data = 1 ;
15428
    fork
15429
    begin
15430
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15431
        do_pause( 1 ) ;
15432
    end
15433
    begin
15434
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15435
        if ( wb_ok !== 1 )
15436
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15437
 
15438
        do_pause ( 2 ) ;
15439
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15440
        do_pause ( 16 ) ;
15441
 
15442 35 mihad
        #1 ;
15443
        if ( !error_monitor_done )
15444
            disable monitor_pci_error_4 ;
15445 15 mihad
    end
15446
    begin:monitor_pci_error_4
15447 35 mihad
        error_monitor_done = 0 ;
15448 15 mihad
        pci_ok = 1 ;
15449
        @(error_event_int) ;
15450
        pci_ok = 0 ;
15451
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15452 35 mihad
        error_monitor_done = 1 ;
15453 15 mihad
    end
15454
    join
15455
 
15456
    if ( !pci_ok || !wb_ok )
15457
    begin
15458
        disable main ;
15459
    end
15460
 
15461
    pci_address  = Target_Base_Addr_R[image_num] ;
15462
    byte_enables = 4'b0000 ;
15463
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15464
 
15465
    master1_check_received_data = 1 ;
15466
    fork
15467
    begin
15468
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Retry_On) ;
15469
        do_pause( 1 ) ;
15470
    end
15471
    begin
15472
        wb_transaction_progress_monitor( expect_address, 1'b0, 1, 1'b1, wb_ok ) ;
15473
        if ( wb_ok !== 1 )
15474
            test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O read requested on PCI") ;
15475
 
15476
        do_pause ( 2 ) ;
15477
        PCIU_IO_READ( `Test_Master_1, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15478
        do_pause ( 16 ) ;
15479
 
15480 35 mihad
        #1 ;
15481
        if ( !error_monitor_done )
15482
            disable monitor_pci_error_5 ;
15483 15 mihad
    end
15484
    begin:monitor_pci_error_5
15485 35 mihad
        error_monitor_done = 0 ;
15486 15 mihad
        pci_ok = 1 ;
15487
        @(error_event_int) ;
15488
        pci_ok = 0 ;
15489
        test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO read reference to Target" ) ;
15490 35 mihad
        error_monitor_done = 1 ;
15491 15 mihad
    end
15492
    join
15493
 
15494
    if ( pci_ok && wb_ok )
15495
        test_ok ;
15496
end
15497
endtask // test_target_io_wr_rd
15498
 
15499
task test_target_io_err_wr ;
15500
    input [2:0]  image_num ;
15501
    input        translate_address ;
15502
    input [11:0] img_ctrl_offset ;
15503
    input        enable_error_report ;
15504
    input        enable_error_interrupt ;
15505
 
15506
    reg   [31:0] expect_address ;
15507
    reg   [31:0] pci_address ;
15508
    reg          translation ;
15509
    reg   [31:0] read_data ;
15510
    reg   [3:0]  byte_enables ;
15511
    reg          ok ;
15512
    reg          pci_ok ;
15513
    reg          wb_ok ;
15514
    integer      i ;
15515
    reg   [11:0] offset ;
15516 35 mihad
    reg          error_monitor_done ;
15517 15 mihad
begin:main
15518
    `ifdef ADDR_TRAN_IMPL
15519
        translation = translate_address ;
15520
    `else
15521
        translation = 0 ;
15522
    `endif
15523
 
15524
    wishbone_slave.cycle_response( 3'b010, tb_subseq_waits, 0 ) ;
15525
 
15526
    test_name = "ENABLE/DISABLE ADDRESS TRANSLATION" ;
15527
    config_read( img_ctrl_offset, 4'hF, read_data ) ;
15528
    if ( translation )
15529
        config_write( img_ctrl_offset, read_data | 32'h0000_0004, 4'hF, ok ) ;
15530
    else
15531
        config_write( img_ctrl_offset, read_data & 32'hFFFF_FFFB, 4'hF, ok ) ;
15532
 
15533
    if ( !ok )
15534
    begin
15535
        $display("Failed to write PCI Image Control register, time %t ", $time ) ;
15536
        test_fail("PCI Image Control register could not be written") ;
15537
    end
15538
 
15539
    test_name = "ENABLE/DISABLE ERROR REPORTING" ;
15540
    offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15541
    if ( enable_error_report )
15542
    begin
15543
        config_write(offset, 32'h0000_0001, 4'b0001, ok) ;
15544
        if ( !ok )
15545
        begin
15546
            test_fail("PCI Error Control and Status register could not be written") ;
15547
            disable main ;
15548
        end
15549
    end
15550
    else
15551
    begin
15552
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15553
        if ( !ok )
15554
        begin
15555
            test_fail("PCI Error Control and Status register could not be written") ;
15556
            disable main ;
15557
        end
15558
    end
15559
 
15560
    test_name = "ENABLE/DISABLE PCI ERROR INTERRUPTS" ;
15561
    offset    = {4'h1, `ICR_ADDR, 2'b00} ;
15562
    if ( enable_error_interrupt )
15563
    begin
15564
        config_write(offset, 32'h0000_0004, 4'b0001, ok) ;
15565
        if ( !ok )
15566
        begin
15567
            test_fail("Interrupt Control register could not be written") ;
15568
            disable main ;
15569
        end
15570
    end
15571
    else
15572
    begin
15573
        config_write(offset, 32'h0000_0000, 4'b0001, ok) ;
15574
        if ( !ok )
15575
        begin
15576
            test_fail("Interrupt Control register could not be written") ;
15577
            disable main ;
15578
        end
15579
    end
15580
 
15581
    pci_address  = Target_Base_Addr_R[image_num] ;
15582
    expect_address = pci_to_wb_addr_convert( pci_address, Target_Tran_Addr_R[image_num], translation ) ;
15583
 
15584
    byte_enables = 4'b1111 ;
15585
 
15586
    for ( i = 0 ; i < 4 ; i = i + 1 )
15587
    begin:loop_1
15588
        test_name = "POST IO WRITE THAT WILL BE TERMINATED WITH ERROR ON WISHBONE" ;
15589
        byte_enables[i] = 0 ;
15590
        if ( i > 0 )
15591
            byte_enables[i - 1] = 1 ;
15592
 
15593
        fork
15594
        begin
15595
            PCIU_IO_WRITE( `Test_Master_2, pci_address, 32'hAAAA_AAAA, byte_enables, 1, `Test_Target_Normal_Completion) ;
15596
            do_pause ( 1 ) ;
15597
        end
15598
        begin
15599
            wb_transaction_progress_monitor( expect_address, 1'b1, 0, 1'b1, wb_ok ) ;
15600
            if ( wb_ok !== 1 )
15601
                test_fail("WISHBONE Master started invalid transaction or none at all on WB bus after single I/O write was posted on PCI") ;
15602
 
15603 35 mihad
            #1 ;
15604
            if ( !error_monitor_done )
15605
                disable monitor_pci_error_2 ;
15606 15 mihad
        end
15607
        begin:monitor_pci_error_2
15608 35 mihad
            error_monitor_done = 0 ;
15609 15 mihad
            pci_ok = 1 ;
15610
            @(error_event_int) ;
15611
            pci_ok = 0 ;
15612
            test_fail ( "PCI Monitor or PCI Master detected an error on PCI bus while doing IO reference to Target" ) ;
15613 35 mihad
            error_monitor_done = 1 ;
15614 15 mihad
        end
15615
        join
15616
 
15617
         test_name = "INTERRUPT REQUEST ASSERTION AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15618
        `ifdef HOST
15619
 
15620
            repeat ( 4 )
15621
                @( posedge wb_clock ) ;
15622
 
15623
            if ( enable_error_interrupt && enable_error_report )
15624
            begin
15625
                if ( INT_O !== 1 )
15626
                begin
15627
                    test_fail("bridge didn't assert interrupt request on WISHBONE after error terminated posted write with error reporting and interrupts enabled") ;
15628
                end
15629
            end
15630
            else
15631
            begin
15632
                if ( INT_O !== 0 )
15633
                begin
15634
                    test_fail("bridge asserted interrupt request on WISHBONE after error terminated posted write with error reporting or interrupts disabled") ;
15635
                end
15636
            end
15637
        `else
15638
            repeat ( 4 )
15639
                @( posedge pci_clock ) ;
15640
 
15641
            if ( enable_error_interrupt && enable_error_report )
15642
            begin
15643
                if ( INTA !== 0 )
15644
                begin
15645
                    test_fail("bridge didn't assert interrupt request on PCI after error terminated posted write with error reporting and interrupts enabled") ;
15646
                end
15647
            end
15648
            else
15649
            begin
15650
                if ( INTA !== 1 )
15651
                begin
15652
                    test_fail("bridge asserted interrupt request on PCI after error terminated posted write with error reporting or interrupts disabled") ;
15653
                end
15654
            end
15655
        `endif
15656
 
15657
        test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER ERROR TERMINATED POSTED IO WRITE ON WISHBONE" ;
15658
        offset = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
15659
        config_read( offset, 4'hF, read_data ) ;
15660
        ok = 1 ;
15661
        if ( enable_error_report )
15662
        begin
15663
            if ( read_data[8] !== 1 )
15664
            begin
15665
                test_fail("error terminated write on WISHBONE didn't set Error bit when error reporting was enabled" ) ;
15666
                ok = 0 ;
15667
            end
15668
 
15669
            if ( read_data[9] !== 0 )
15670
            begin
15671
                test_fail("WISHBONE slave was a cause of error, but error source bit was not 0" ) ;
15672
                ok = 0 ;
15673
            end
15674
 
15675
            if ( read_data[31:28] !== byte_enables )
15676
            begin
15677
                test_fail("byte enable field in PCI Error Control and Status register was wrong" ) ;
15678
                ok = 0 ;
15679
            end
15680
 
15681
            if ( read_data[27:24] !== `BC_IO_WRITE )
15682
            begin
15683
                test_fail("bus command field in PCI Error Control and Status register was wrong" ) ;
15684
                ok = 0 ;
15685
            end
15686
 
15687
            if ( ok )
15688
                test_ok ;
15689
 
15690
            test_name = "CLEAR ERROR STATUS" ;
15691
            config_write( offset, read_data, 4'hF, ok ) ;
15692
            if ( !ok )
15693
                test_fail("PCI Error Control and Status register could not be written") ;
15694
 
15695
            test_name = "ERRONEOUS ADDRESS AND DATA REGISTERS' VALUES CHECK AFTER WRITE TERMINATED WITH ERROR ON WISHBONE" ;
15696
            offset = {4'h1, `P_ERR_ADDR_ADDR, 2'b00} ;
15697
            config_read ( offset, 4'hf, read_data ) ;
15698
 
15699
            if ( read_data !== expect_address )
15700
            begin
15701
                test_fail("value in Erroneous Address register was incorrect") ;
15702
                ok = 0 ;
15703
            end
15704
 
15705
            offset = {4'h1, `P_ERR_DATA_ADDR, 2'b00} ;
15706
            config_read ( offset, 4'hf, read_data ) ;
15707
 
15708
            if ( read_data !== 32'hAAAA_AAAA )
15709
            begin
15710
                test_fail("value in Erroneous Data register was incorrect") ;
15711
                ok = 0 ;
15712
            end
15713
 
15714
            if ( ok )
15715
                test_ok ;
15716
 
15717
        end
15718
        else
15719
        begin
15720
            if ( read_data[8] !== 0 )
15721
            begin
15722
                test_fail("error terminated write on WISHBONE set Error bit when error reporting was disabled" ) ;
15723
                ok = 0 ;
15724
            end
15725
            else
15726
                test_ok ;
15727
        end
15728
 
15729
        test_name = "INTERRUPT STATUS REGISTER VALUE AFTER ERROR TERMINATED WRITE ON WISHBONE" ;
15730
        offset = {4'h1, `ISR_ADDR, 2'b00} ;
15731
        ok = 1 ;
15732
 
15733
        config_read ( offset, 4'hF, read_data ) ;
15734
        if ( enable_error_report && enable_error_interrupt )
15735
        begin
15736
            if ( read_data[2] !== 1 )
15737
            begin
15738
                test_fail("PCI Error Interrupt Status bit was not set when expected") ;
15739
                ok = 0 ;
15740
            end
15741
 
15742
            test_name = "CLEARING INTERRUPT STATUS" ;
15743
            config_write( offset, read_data, 4'hF, ok ) ;
15744
            if ( !ok )
15745
                test_fail("Interrupt Status register could not be written") ;
15746
        end
15747
        else
15748
        begin
15749
            if ( read_data[2] !== 0 )
15750
            begin
15751
                test_fail("PCI Error Interrupt Status bit was set when Error Interrupts were disabled") ;
15752
                ok = 0 ;
15753
            end
15754
        end
15755
 
15756
        if ( ok )
15757
            test_ok ;
15758
 
15759
        test_name = "INTERRUPT REQUEST DEASSERTION AFTER CLEARING INTERRUPT STATUS" ;
15760
        `ifdef HOST
15761
 
15762
            repeat ( 4 )
15763
                @( posedge wb_clock ) ;
15764
 
15765
            if ( INT_O !== 0 )
15766
            begin
15767
                test_fail("bridge asserted interrupt request on WISHBONE for no apparent reason") ;
15768
            end
15769
            else
15770
                test_ok ;
15771
 
15772
        `else
15773
            repeat ( 4 )
15774
                @( posedge pci_clock ) ;
15775
 
15776
            if ( INTA !== 1 )
15777
            begin
15778
                test_fail("bridge asserted interrupt request on PCI for no apparent reason") ;
15779
            end
15780
            else
15781
                test_ok ;
15782
 
15783
        `endif
15784
 
15785
        pci_address = pci_address + 1 ;
15786
        expect_address = expect_address + 1 ;
15787
    end
15788
 
15789
end
15790
endtask // test_target_io_err_wr
15791
 
15792
task test_pci_image ;
15793
    input [2:0]  image_num ;
15794
    reg   [11:0] pci_ctrl_offset ;
15795
    reg   [11:0] ctrl_offset ;
15796
    reg   [11:0] ba_offset ;
15797
    reg   [11:0] am_offset ;
15798
    reg   [11:0] ta_offset ;
15799
    reg   [7:0]  cache_lsize ;
15800
    reg          ok ;
15801
    reg          test_io ;
15802
    reg          test_mem ;
15803
begin
15804
    pci_ctrl_offset = 12'h4 ;
15805
    if (image_num === 0)
15806
    begin
15807
        ctrl_offset = {4'h1, `P_IMG_CTRL0_ADDR, 2'b00} ;
15808
        ba_offset   = {4'h1, `P_BA0_ADDR, 2'b00} ;
15809
        am_offset   = {4'h1, `P_AM0_ADDR, 2'b00} ;
15810
        ta_offset   = {4'h1, `P_TA0_ADDR, 2'b00} ;
15811
    end
15812
    else if (image_num === 1)
15813
    begin
15814
        ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
15815
        ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
15816
        am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
15817
        ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
15818
    end
15819
    else if (image_num === 2)
15820
    begin
15821
        ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
15822
        ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
15823
        am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
15824
        ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
15825
    end
15826
    else if (image_num === 3)
15827
    begin
15828
        ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
15829
        ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
15830
        am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
15831
        ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
15832
    end
15833
    else if (image_num === 4)
15834
    begin
15835
        ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
15836
        ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
15837
        am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
15838
        ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
15839
    end
15840
    else if (image_num === 5)
15841
    begin
15842
        ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
15843
        ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
15844
        am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
15845
        ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
15846
    end
15847
 
15848
    `ifdef HOST
15849
        test_io  = 1 ;
15850
        test_mem = 1 ;
15851
    `else
15852
        if (image_num == 1)
15853
            test_io = `PCI_BA1_MEM_IO ;
15854
        else if ( image_num == 2 )
15855
            test_io = `PCI_BA2_MEM_IO ;
15856
        else if ( image_num == 3 )
15857
            test_io = `PCI_BA3_MEM_IO ;
15858
        else if ( image_num == 4 )
15859
            test_io = `PCI_BA4_MEM_IO ;
15860
        else if ( image_num == 5 )
15861
            test_io = `PCI_BA5_MEM_IO ;
15862
 
15863
        test_mem = !test_io ;
15864
    `endif
15865
 
15866
    $display(" ");
15867
    $display("########################################################################") ;
15868
    $display("Setting the IMAGE %d configuration registers (P_BA, P_AM, P_TA)",image_num);
15869
    test_name = "PCI IMAGE SETTINGS" ;
15870
 
15871
    // Set Base Address of IMAGE
15872
    config_write( ba_offset, Target_Base_Addr_R[image_num], 4'hF, ok ) ;
15873
    if ( ok !== 1 )
15874
    begin
15875
        $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
15876
        test_fail("PCI Base Address register could not be written") ;
15877
    end
15878
 
15879
    // Set Address Mask of IMAGE
15880
    config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
15881
    if ( ok !== 1 )
15882
    begin
15883
        $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
15884
        test_fail("PCI Address Mask register could not be written") ;
15885
    end
15886
 
15887
    // Set Translation Address of IMAGE
15888
    config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
15889
    if ( ok !== 1 )
15890
    begin
15891
        $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
15892
        test_fail("PCI Translation Address register could not be written") ;
15893
    end
15894
 
15895
// Following are defines for byte enable signals !
15896
//      Byte Masks
15897
//      `Test_Byte_0                            (4'b1110)
15898
//      `Test_Byte_1                            (4'b1101)
15899
//      `Test_Byte_2                            (4'b1011)
15900
//      `Test_Byte_3                            (4'b0111)
15901
//      `Test_Half_0                            (4'b1100)
15902
//      `Test_Half_1                            (4'b0011)
15903
//      `Test_All_Bytes                         (4'b0000)
15904
 
15905
// "TEST NORMAL SINGLE WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITHOUT PREFETCABLE IMAGES"
15906
    // Set Cache Line Size
15907
    cache_lsize = 8'h4 ;
15908
 
15909
    $display(" ");
15910
    $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15911
    config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15912
    if ( ok !== 1 )
15913
    begin
15914
        $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15915
        test_fail("PCI Device Control and Status register could not be written") ;
15916
    end
15917
 
15918
    if (test_mem)
15919
    begin
15920
        $display("Do single WR / RD test through the IMAGE %d !",image_num);
15921
        // Task test_normal_wr_rd has the following parameters:
15922
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15923
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15924
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15925
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes, image_num,
15926
                            `Test_One_Word, 1'b0, 1'b1, cache_lsize, 1'b0, 1'b0 );
15927
 
15928
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITHOUT ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15929
        // Set Cache Line Size
15930
        cache_lsize = 8'h4 ;
15931
 
15932
        $display(" ");
15933
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15934
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15935
        if ( ok !== 1 )
15936
        begin
15937
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15938
            test_fail("Cache Line Size register could not be written" ) ;
15939
        end
15940
 
15941
        $display("Do burst (2 words) WR / RD test through the IMAGE %d !",image_num);
15942
        // Task test_normal_wr_rd has the following parameters:
15943
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15944
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15945
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15946
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h4, 32'h5a5a_5a5a, `Test_Half_0, image_num,
15947
                            `Test_Two_Words, 1'b0, 1'b1, cache_lsize, 1'b1, 1'b0 );
15948
 
15949
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15950
        // Set Cache Line Size
15951
        cache_lsize = 8'h8 ;
15952
 
15953
        $display(" ");
15954
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15955
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15956
        if ( ok !== 1 )
15957
        begin
15958
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15959
            test_fail("Cache Line Size register could not be written" ) ;
15960
        end
15961
 
15962
        $display("Do burst (3 words) WR / RD test through the IMAGE %d !",image_num);
15963
        // Task test_normal_wr_rd has the following parameters:
15964
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15965
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15966
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15967
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h10, 32'h3c3c_3c3c, `Test_Half_1, image_num,
15968
                            `Test_Three_Words, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15969
 
15970
    // TEST NORMAL BURST WRITE READ THROUGH IMAGE WITH ADDRESS TRANSLATION AND WITH PREFETCABLE IMAGES
15971
        // Set Cache Line Size
15972
        cache_lsize = 8'h4 ;
15973
 
15974
        $display(" ");
15975
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
15976
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
15977
        if ( ok !== 1 )
15978
        begin
15979
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
15980
            test_fail("Cache Line Size register could not be written" ) ;
15981
        end
15982
 
15983
        $display("Do burst (full fifo depth words) WR / RD test through the IMAGE %d !",image_num);
15984
        // Task test_normal_wr_rd has the following parameters:
15985
        //  [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be, [2:0]Image_num,
15986
        //  [3:0]Set_size, Set_addr_translation, Set_prefetch_enable, [7:0]Cache_lsize, Set_wb_wait_states,
15987
        //  MemRdLn_or_MemRd_when_cache_lsize_read.
15988
        test_normal_wr_rd( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h20, 32'h7147_a5c3, `Test_Byte_2, image_num,
15989
                            `PCIW_DEPTH - 2, 1'b1, 1'b1, cache_lsize, 1'b1, 1'b1 );
15990
 
15991
    // TEST ERRONEOUS SINGLE WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
15992
        $display(" ");
15993
        $display("Do single erroneous WR test through the IMAGE %d !",image_num);
15994
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
15995
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
15996
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num], 32'h1234_5678, `Test_All_Bytes,
15997
                            image_num, `Test_One_Word, 1'b0, 1'b0, 2'h0 );
15998
 
15999
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16000
        $display(" ");
16001
        $display("Do burst (2 words) erroneous WR test through the IMAGE %d !",image_num);
16002
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16003
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16004
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h30, 32'h1234_5678, `Test_Half_0,
16005
                            image_num, `Test_Two_Words, 1'b1, 1'b0, 2'h0 );
16006
 
16007
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITHOUT ERROR AND INTERRUPT REPORTING
16008
        $display(" ");
16009
        $display("Do burst (3 words) erroneous WR test through the IMAGE %d !",image_num);
16010
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16011
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16012
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h40, 32'h1234_5678, `Test_Half_1,
16013
                            image_num, `Test_Three_Words, 1'b0, 1'b1, 2'h2 );
16014
 
16015
    // TEST ERRONEOUS BURST WRITE THROUGH IMAGE WITH ERROR AND INTERRUPT REPORTING
16016
        $display(" ");
16017
        $display("Do burst (8 words) erroneous WR test through the IMAGE %d !",image_num);
16018
        // Task test_wb_error_wr has the following parameters: [2:0]Master_ID, [31:0]Address, [31:0]Data, [3:0]Be,
16019
        //  [2:0]Image_num, [3:0]Set_size, Set_err_and_int_report, Set_wb_wait_states, [1:0]Imm_BefLast_Last_error.
16020
        test_wb_error_wr( `Test_Master_2, Target_Base_Addr_R[image_num] + 32'h50, 32'h1234_5678, `Test_Byte_1,
16021
                            image_num, `Test_Eight_Words, 1'b1, 1'b1, 2'h1 );
16022
    end
16023
 
16024
    if ( test_io )
16025
    begin
16026
        test_name = "PCI IMAGE SETTINGS" ;
16027
 
16028
        // Set Base Address of IMAGE
16029
        config_write( ba_offset, Target_Base_Addr_R[image_num] | 1, 4'hF, ok ) ;
16030
        if ( ok !== 1 )
16031
        begin
16032
            $display("Image testing failed! Failed to write P_BA%d register! Time %t ",image_num ,$time);
16033
            test_fail("PCI Base Address register could not be written") ;
16034
        end
16035
 
16036
        // Set Address Mask of IMAGE
16037
        config_write( am_offset, Target_Addr_Mask_R[image_num], 4'hF, ok ) ;
16038
        if ( ok !== 1 )
16039
        begin
16040
            $display("Image testing failed! Failed to write P_AM%d register! Time %t ",image_num ,$time);
16041
            test_fail("PCI Address Mask register could not be written") ;
16042
        end
16043
 
16044
        // Set Translation Address of IMAGE
16045
        config_write( ta_offset, Target_Tran_Addr_R[image_num], 4'hF, ok ) ;
16046
        if ( ok !== 1 )
16047
        begin
16048
            $display("Image testing failed! Failed to write P_TA%d register! Time %t ",image_num ,$time);
16049
            test_fail("PCI Translation Address register could not be written") ;
16050
        end
16051
 
16052
        // Set Cache Line Size
16053
        cache_lsize = 8'h4 ;
16054
 
16055
        $display(" ");
16056
        $display("Setting the Cache Line Size register to %d word(s)", cache_lsize);
16057
        config_write( pci_ctrl_offset + 12'h8, {24'h0000_00, cache_lsize}, 4'h1, ok) ;
16058
        if ( ok !== 1 )
16059
        begin
16060
            $display("Image testing failed! Failed to write Cache Line Size register! Time %t ",$time);
16061
            test_fail("Cache Line Size register could not be written" ) ;
16062
        end
16063
 
16064
        test_target_io_wr_rd
16065
        (
16066
            image_num,    // image number
16067
            0,            // test with address translation
16068
            ctrl_offset   // image control register offset
16069
        ) ;
16070
 
16071
        test_target_io_wr_rd
16072
        (
16073
            image_num,    // image number
16074
            1,            // test with address translation
16075
            ctrl_offset   // image control register offset
16076
        ) ;
16077
 
16078
        test_target_io_err_wr
16079
        (
16080
            image_num,      // image number
16081
            0,              // address translation on/off
16082
            ctrl_offset,    // image control register offset
16083
            0,              // enable error reporting
16084
 
16085
        ) ;
16086
 
16087
        test_target_io_err_wr
16088
        (
16089
            image_num,      // image number
16090
            1,              // address translation on/off
16091
            ctrl_offset,    // image control register offset
16092
            0,              // enable error reporting
16093
            1               // enable error interrupts
16094
        ) ;
16095
 
16096
        test_target_io_err_wr
16097
        (
16098
            image_num,      // image number
16099
            0,              // address translation on/off
16100
            ctrl_offset,    // image control register offset
16101
            1,              // enable error reporting
16102
 
16103
        ) ;
16104
 
16105
        test_target_io_err_wr
16106
        (
16107
            image_num,      // image number
16108
            1,              // address translation on/off
16109
            ctrl_offset,    // image control register offset
16110
            1,              // enable error reporting
16111
            1               // enable error interrupts
16112
        ) ;
16113
    end
16114
 
16115
    // Test master abort with NON supported commands
16116
    target_unsupported_cmds( Target_Base_Addr_R[image_num], image_num ) ;
16117
 
16118
    // disable the image
16119 45 mihad
    config_write( am_offset, Target_Addr_Mask_R[image_num] & 32'h0000_0000, 4'hF, ok ) ;
16120 15 mihad
end
16121
endtask //test_pci_image
16122
 
16123
task target_fast_back_to_back ;
16124
    reg   [11:0] pci_ctrl_offset ;
16125
    reg   [11:0] ctrl_offset ;
16126
    reg   [11:0] ba_offset ;
16127
    reg   [11:0] am_offset ;
16128
    reg   [11:0] ta_offset ;
16129
    reg   [11:0] cls_offset ;
16130
    reg          do_mem_fb2b ;
16131
    reg          do_io_fb2b ;
16132
    reg          ok ;
16133
begin:main
16134
 
16135
    if ( target_mem_image !== -1 )
16136
    begin
16137
        do_mem_fb2b = 1 ;
16138
 
16139
        if (target_mem_image === 1)
16140
        begin
16141
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16142
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16143
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16144
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16145
        end
16146
        else if (target_mem_image === 2)
16147
        begin
16148
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16149
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16150
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16151
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16152
        end
16153
        else if (target_mem_image === 3)
16154
        begin
16155
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16156
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16157
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16158
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16159
        end
16160
        else if (target_mem_image === 4)
16161
        begin
16162
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16163
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16164
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16165
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16166
        end
16167
        else if (target_mem_image === 5)
16168
        begin
16169
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16170
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16171
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16172
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16173
        end
16174
    end
16175
    else
16176
        do_mem_fb2b = 0 ;
16177
 
16178
    pci_ctrl_offset = 12'h4 ;
16179
    cls_offset      = 12'h00C ;
16180
 
16181
    if ( do_mem_fb2b )
16182
    begin
16183
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16184
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16185
        if ( ok !== 1 )
16186
        begin
16187
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16188
            test_fail("PCI Base Address register could not be written") ;
16189
            disable main ;
16190
        end
16191
 
16192
        // Set Address Mask of IMAGE
16193
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16194
        if ( ok !== 1 )
16195
        begin
16196
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16197
            test_fail("PCI Address Mask register could not be written") ;
16198
            disable main ;
16199
        end
16200
 
16201
        // Set Translation Address of IMAGE
16202
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16203
        if ( ok !== 1 )
16204
        begin
16205
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16206
            test_fail("PCI Translation Address Register could not be written") ;
16207
            disable main ;
16208
        end
16209
 
16210
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16211
        if ( ok !== 1 )
16212
        begin
16213
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16214
            test_fail("PCI Image Control register could not be written") ;
16215
            disable main ;
16216
        end
16217
 
16218
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16219
        if ( ok !== 1 )
16220
        begin
16221
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16222
            test_fail("Cache Line Size register could not be written") ;
16223
            disable main ;
16224
        end
16225
 
16226
        // enable master 1 fast_b2b
16227 45 mihad
        configuration_cycle_write(0,                        // bus number
16228
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16229
                                  0,                        // function number
16230
                                  1,                        // register number
16231
                                  0,                        // type of configuration cycle
16232
                                  4'b1111,                  // byte enables
16233
                                  32'hFFFF_FFFF             // data
16234 15 mihad
                                 ) ;
16235
 
16236
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16237
 
16238
        test_name = "FAST BACK TO BACK THROUGH TARGET - FILL WRITE FIFO, CHECK RETRY ON FAST B2B WRITE" ;
16239
        fork
16240
        begin
16241
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16242
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16243
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16244
                  0, `Test_One_Zero_Target_WS,
16245
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16246
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16247
 
16248
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16249
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16250
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16251
                  0, `Test_One_Zero_Target_WS,
16252
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16253
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16254
            do_pause(5) ;
16255
 
16256
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16257
        end
16258
        begin:wb_monitor1
16259
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16260
            if ( ok !== 1 )
16261
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16262
 
16263
            disable monitor_error_event1 ;
16264
        end
16265
        begin:monitor_error_event1
16266
            @(error_event_int) ;
16267
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16268
            ok = 0 ;
16269
            disable wb_monitor1 ;
16270
        end
16271
        join
16272
 
16273
        if ( ok )
16274
            test_ok ;
16275
 
16276
        test_name = "FAST BACK TO BACK THROUGH TARGET - BOTH WRITES SMALL ENOUGH TO PROCEEDE THROUGH FIFO" ;
16277
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16278
        fork
16279
        begin
16280
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16281
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16282
                  `PCIW_DEPTH - 6, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16283
                  0, `Test_One_Zero_Target_WS,
16284
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16285
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16286
 
16287
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4),
16288
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16289
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16290
                  0, `Test_One_Zero_Target_WS,
16291
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16292
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16293
            do_pause(5) ;
16294
 
16295
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16296
 
16297
        end
16298
        begin:wb_monitor2
16299
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 6, 1'b1, ok) ;
16300
            if ( ok !== 1 )
16301
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16302
            else
16303
            begin
16304
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image] + ((`PCIW_DEPTH - 6) * 4), 1'b1, 2, 1'b1, ok) ;
16305
                if ( ok !== 1 )
16306
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16307
            end
16308
 
16309
            disable monitor_error_event2 ;
16310
        end
16311
        begin:monitor_error_event2
16312
            @(error_event_int) ;
16313
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16314
            ok = 0 ;
16315
            disable wb_monitor2 ;
16316
        end
16317
        join
16318
 
16319
        if ( ok )
16320
            test_ok ;
16321
 
16322
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST WRITE FULL FIFO, THEN READ BACK" ;
16323
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16324
        fork
16325
        begin
16326
            DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16327
                  PCI_COMMAND_MEMORY_WRITE, 32'h1234_5678, 4'hF,
16328
                  `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16329
                  0, `Test_One_Zero_Target_WS,
16330
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16331
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16332
 
16333
            DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16334
                  `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16335
                  2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16336
                  0, `Test_One_Zero_Target_WS,
16337
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16338
                  `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16339
            do_pause(5) ;
16340
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16341
 
16342
        end
16343
        begin:wb_monitor3
16344
            fork
16345
            begin
16346
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16347
                if ( ok !== 1 )
16348
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16349
            end
16350
            begin
16351
                wb_transaction_stop(`PCIW_DEPTH - 2) ;
16352
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_mem_image], 1'b0, 4, 1'b1, ok) ;
16353
                if ( ok !== 1 )
16354
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16355
            end
16356
            join
16357
 
16358
            if ( ok )
16359
            begin
16360
                fork
16361
                begin
16362
                    do_pause(3) ;
16363
 
16364
                    DO_REF ("MEM_WRITE ", 1, Target_Base_Addr_R[target_mem_image],
16365
                        PCI_COMMAND_MEMORY_WRITE, 32'h8765_4321, 4'hF,
16366
                        `PCIW_DEPTH - 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16367
                        0, `Test_One_Zero_Target_WS,
16368
                        `Test_Devsel_Medium, `Test_Fast_B2B,
16369
                        `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16370
 
16371
                    DO_REF ("MEM_READ  ", 1, Target_Base_Addr_R[target_mem_image],
16372
                            `BC_MEM_READ_LN, 32'h1234_5678, 4'hF,
16373
                            4, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16374
                            0, `Test_One_Zero_Target_WS,
16375
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16376
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16377
 
16378
                    do_pause(1) ;
16379
                end
16380
                begin
16381
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_WRITE, `PCIW_DEPTH - 2, 0, 1'b1, 1'b0, 0, ok) ;
16382
                    if ( ok !== 1 )
16383
                    begin
16384
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16385
                        disable monitor_error_event3 ;
16386
                    end
16387
                    else
16388
                    begin
16389
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], `BC_MEM_READ_LN, 4, 0, 1'b1, 1'b0, 1, ok) ;
16390
                        if ( ok !== 1 )
16391
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16392
                    end
16393
                end
16394 26 mihad
                begin
16395
                            wb_transaction_progress_monitor(Target_Base_Addr_R[target_mem_image], 1'b1, `PCIW_DEPTH - 2, 1'b1, ok) ;
16396
                        if ( ok !== 1 )
16397
                                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16398
                end
16399 15 mihad
                join
16400
            end
16401
            disable monitor_error_event3 ;
16402
        end
16403
        begin:monitor_error_event3
16404
            @(error_event_int) ;
16405
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16406
            ok = 0 ;
16407
            disable wb_monitor3 ;
16408
        end
16409
        join
16410
 
16411
        if ( ok )
16412
            test_ok ;
16413
 
16414
        test_name = "DISABLING MEM IMAGE" ;
16415 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
16416 15 mihad
        if ( ok !== 1 )
16417
        begin
16418
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16419
            test_fail("PCI Address Mask register could not be written") ;
16420
            disable main ;
16421
        end
16422
    end
16423
 
16424
    if ( target_io_image !== -1 )
16425
    begin
16426
        do_io_fb2b = 1 ;
16427
 
16428
        if (target_io_image === 1)
16429
        begin
16430
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16431
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16432
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16433
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16434
        end
16435
        else if (target_io_image === 2)
16436
        begin
16437
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16438
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16439
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16440
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16441
        end
16442
        else if (target_io_image === 3)
16443
        begin
16444
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16445
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16446
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16447
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16448
        end
16449
        else if (target_io_image === 4)
16450
        begin
16451
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16452
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16453
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16454
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16455
        end
16456
        else if (target_io_image === 5)
16457
        begin
16458
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16459
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16460
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16461
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16462
        end
16463
    end
16464
    else
16465
        do_io_fb2b = 0 ;
16466
 
16467
    if ( do_io_fb2b )
16468
    begin
16469
 
16470
        test_name = "CONFIGURE TARGET FOR FAST B2B TESTING" ;
16471
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
16472
        if ( ok !== 1 )
16473
        begin
16474
            $display("Fast B2B testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16475
            test_fail("PCI Base Address register could not be written") ;
16476
            disable main ;
16477
        end
16478
 
16479
        // Set Address Mask of IMAGE
16480
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
16481
        if ( ok !== 1 )
16482
        begin
16483
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16484
            test_fail("PCI Address Mask register could not be written") ;
16485
            disable main ;
16486
        end
16487
 
16488
        // Set Translation Address of IMAGE
16489
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
16490
        if ( ok !== 1 )
16491
        begin
16492
            $display("Fast B2B testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16493
            test_fail("PCI Translation Address Register could not be written") ;
16494
            disable main ;
16495
        end
16496
 
16497
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16498
        if ( ok !== 1 )
16499
        begin
16500
            $display("Fast B2B testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16501
            test_fail("PCI Image Control register could not be written") ;
16502
            disable main ;
16503
        end
16504
 
16505
        config_write( cls_offset, 32'h0000_00_04, 4'b0001, ok ) ;
16506
        if ( ok !== 1 )
16507
        begin
16508
            $display("Fast B2B testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16509
            test_fail("Cache Line Size register could not be written") ;
16510
            disable main ;
16511
        end
16512
 
16513
        // enable master 1 fast_b2b
16514 45 mihad
        configuration_cycle_write(0,                        // bus number
16515
                                  `TAR1_IDSEL_INDEX - 11,   // device number
16516
                                  0,                        // function number
16517
                                  1,                        // register number
16518
                                  0,                        // type of configuration cycle
16519
                                  4'b1111,                  // byte enables
16520
                                  32'hFFFF_FFFF             // data
16521 15 mihad
                                 ) ;
16522
 
16523
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16524
 
16525
        test_name = "FAST BACK TO BACK THROUGH TARGET - TWO SINGLE IO WRITES" ;
16526
        fork
16527
        begin
16528
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 100,
16529
                  `BC_IO_WRITE, 32'hA5A5_A5A5, 4'hF,
16530
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16531
                  0, `Test_One_Zero_Target_WS,
16532
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16533
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16534
 
16535
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 104,
16536
                  `BC_IO_WRITE, 32'h5A5A_5A5A, 4'hF,
16537
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16538
                  0, `Test_One_Zero_Target_WS,
16539
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16540
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16541
            do_pause(5) ;
16542
 
16543
        end
16544
        begin:wb_monitor4
16545
            wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 100, 1'b1, 1, 1'b1, ok) ;
16546
            if ( ok !== 1 )
16547
                test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16548
 
16549
            if ( ok )
16550
            begin
16551
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 104, 1'b1, 1, 1'b1, ok) ;
16552
                if ( ok !== 1 )
16553
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16554
            end
16555
 
16556
            disable monitor_error_event4 ;
16557
        end
16558
        begin:monitor_error_event4
16559
            @(error_event_int) ;
16560
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16561
            ok = 0 ;
16562
            disable wb_monitor4 ;
16563
        end
16564
        join
16565
 
16566
        if ( ok )
16567
            test_ok ;
16568
 
16569
        test_name = "FAST BACK TO BACK THROUGH TARGET - FIRST I/O WRITE, THEN READ BACK" ;
16570
        wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 0) ;
16571
        fork
16572
        begin
16573
            DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16574
                  `BC_IO_WRITE, 32'hAAAA_AAAA, 4'hF,
16575
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16576
                  0, `Test_One_Zero_Target_WS,
16577
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16578
                  `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16579
 
16580
            DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16581
                  `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16582
                  1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16583
                  0, `Test_One_Zero_Target_WS,
16584
                  `Test_Devsel_Medium, `Test_Fast_B2B,
16585
                  `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16586
            do_pause(5) ;
16587
            wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 0) ;
16588
        end
16589
        begin:wb_monitor5
16590
            fork
16591
            begin
16592
                wb_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, 1'b1, 1, 1'b1, ok) ;
16593
                if ( ok !== 1 )
16594
                    test_fail("WISHBONE master did invalid transaction or none at all on WISHBONE bus") ;
16595
            end
16596
            begin
16597
                wb_transaction_stop( 1 ) ;
16598
                wb_transaction_progress_monitor_backup(Target_Base_Addr_R[target_io_image] + 40, 1'b0, 1, 1'b1, ok) ;
16599
                if ( ok !== 1 )
16600
                    test_fail("WISHBONE master did invalid second transaction or none at all on WISHBONE bus when it was requested as fast back to back") ;
16601
            end
16602
            join
16603
 
16604
            if ( ok )
16605
            begin
16606
                fork
16607
                begin
16608
                    do_pause(3) ;
16609
 
16610
                    DO_REF ("IO_WRITE  ", 1, Target_Base_Addr_R[target_io_image] + 40,
16611
                            `BC_IO_WRITE, 32'h5555_5555, 4'hF,
16612
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16613
                            0, `Test_One_Zero_Target_WS,
16614
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16615
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16616
 
16617
                    DO_REF ("IO_READ   ", 1, Target_Base_Addr_R[target_io_image] + 40,
16618
                            `BC_IO_READ, 32'hAAAA_AAAA, 4'hF,
16619
                            1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16620
                            0, `Test_One_Zero_Target_WS,
16621
                            `Test_Devsel_Medium, `Test_Fast_B2B,
16622
                            `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
16623
 
16624
                    do_pause(1) ;
16625
                end
16626
                begin
16627
                    pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_WRITE, 1, 0, 1'b1, 1'b0, 0, ok) ;
16628
                    if ( ok !== 1 )
16629
                    begin
16630
                        test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16631
                        disable monitor_error_event5 ;
16632
                    end
16633
                    else
16634
                    begin
16635
                        pci_transaction_progress_monitor(Target_Base_Addr_R[target_io_image] + 40, `BC_IO_READ, 1, 0, 1'b1, 1'b0, 1, ok) ;
16636
                        if ( ok !== 1 )
16637
                            test_fail("unexpected transaction was detected on PCI when FastB2B read was repeated") ;
16638
                    end
16639
                end
16640
                join
16641
            end
16642
            disable monitor_error_event5 ;
16643
        end
16644
        begin:monitor_error_event5
16645
            @(error_event_int) ;
16646
            test_fail("either PCI Monitor or PCI Master detected an error while testing Fast Back to Back through PCI Target Unit") ;
16647
            ok = 0 ;
16648
            disable wb_monitor5 ;
16649
        end
16650
        join
16651
 
16652
        if ( ok )
16653
            test_ok ;
16654
 
16655
        test_name = "DISABLING IO IMAGE" ;
16656 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
16657 15 mihad
        if ( ok !== 1 )
16658
        begin
16659
            $display("Fast B2B testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16660
            test_fail("PCI Address Mask register could not be written") ;
16661
            disable main ;
16662
        end
16663
    end
16664
 
16665
end
16666
endtask //target_fast_back_to_back
16667
 
16668
task target_disconnects ;
16669
    reg   [11:0] pci_ctrl_offset ;
16670
    reg   [11:0] ctrl_offset ;
16671
    reg   [11:0] ba_offset ;
16672
    reg   [11:0] am_offset ;
16673
    reg   [11:0] ta_offset ;
16674
    reg   [11:0] cls_offset ;
16675
    reg          pci_ok ;
16676
    reg          wb_ok ;
16677
    reg          ok ;
16678
    reg   [31:0] pci_address ;
16679
    reg   [31:0] data ;
16680
    reg   [3:0]  byte_enables ;
16681
    reg   [9:0]  expect_length ;
16682
 
16683
    reg          do_mem_disconnects ;
16684
    reg          do_io_disconnects ;
16685 35 mihad
    reg          error_monitor_done ;
16686 15 mihad
begin:main
16687
    if ( target_mem_image !== -1 )
16688
    begin
16689
        do_mem_disconnects = 1 ;
16690
 
16691
        if (target_mem_image === 1)
16692
        begin
16693
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
16694
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
16695
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
16696
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
16697
        end
16698
        else if (target_mem_image === 2)
16699
        begin
16700
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
16701
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
16702
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
16703
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
16704
        end
16705
        else if (target_mem_image === 3)
16706
        begin
16707
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
16708
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
16709
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
16710
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
16711
        end
16712
        else if (target_mem_image === 4)
16713
        begin
16714
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
16715
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
16716
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
16717
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
16718
        end
16719
        else if (target_mem_image === 5)
16720
        begin
16721
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
16722
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
16723
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
16724
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
16725
        end
16726
    end
16727
    else
16728
        do_mem_disconnects = 0 ;
16729
 
16730
    pci_ctrl_offset = 12'h4 ;
16731
    cls_offset = 12'h00C ;
16732
 
16733
    master1_check_received_data = 0 ;
16734
    master2_check_received_data = 0 ;
16735
 
16736
    `ifdef HOST
16737
        `ifdef NO_CNF_IMAGE
16738
        `else
16739
            `define TEST_BURST_CONFIG_READ
16740
        `endif
16741
    `else
16742
        `define TEST_BURST_CONFIG_READ
16743
        `define TEST_BURST_CONFIG_WRITE
16744
    `endif
16745
 
16746
    `ifdef TEST_BURST_CONFIG_WRITE
16747
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16748
 
16749
        data = 32'h0000_08_08 ;
16750
 
16751 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY WRITE TO CONFIGURATION SPACE" ;
16752 15 mihad
        byte_enables = 4'b0000 ;
16753
 
16754
        fork
16755
        begin
16756
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16757
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16758
                    byte_enables,
16759
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16760
                    8'h0_0, `Test_One_Zero_Target_WS,
16761
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16762
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16763
 
16764
            data = 32'h0000_04_04 ;
16765
            DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16766
                    PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
16767
                    byte_enables,
16768
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16769
                    8'h0_0, `Test_One_Zero_Target_WS,
16770
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16771
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16772
            do_pause( 1 ) ;
16773
            while ( FRAME !== 1 || IRDY !== 1 )
16774
                @(posedge pci_clock) ;
16775
 
16776 35 mihad
            #1 ;
16777
            if ( !error_monitor_done )
16778
                disable monitor_error_event1 ;
16779 15 mihad
        end
16780
        begin:monitor_error_event1
16781 35 mihad
            error_monitor_done = 0 ;
16782 15 mihad
            ok = 1 ;
16783
            @(error_event_int) ;
16784
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16785
            ok = 0 ;
16786 35 mihad
            error_monitor_done = 1 ;
16787 15 mihad
        end
16788
        join
16789
 
16790
        config_read(pci_address, 4'hF, data) ;
16791
        if ( data [15:0] !== 16'h04_04 )
16792
        begin
16793
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16794
        end
16795
        else if ( ok )
16796
            test_ok ;
16797
 
16798 45 mihad
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION WRITE" ;
16799
 
16800
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16801 15 mihad
        data         = 32'h0000_0808 ;
16802
        byte_enables = 4'h0 ;
16803
        fork
16804
        begin
16805
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16806
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16807
                    byte_enables,
16808
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16809
                    8'h0_0, `Test_One_Zero_Target_WS,
16810
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16811
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16812
 
16813
            data = 32'h0000_04_04 ;
16814
            DO_REF ("CFG_WRITE ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16815
                    `BC_CONF_WRITE, data[PCI_BUS_DATA_RANGE:0],
16816
                    byte_enables,
16817
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16818
                    8'h0_0, `Test_One_Zero_Target_WS,
16819
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16820
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16821
 
16822
            do_pause( 1 ) ;
16823
            while ( FRAME !== 1 || IRDY !== 1 )
16824
                @(posedge pci_clock) ;
16825
 
16826 35 mihad
            #1 ;
16827
            if ( !error_monitor_done )
16828
                disable monitor_error_event2 ;
16829 15 mihad
        end
16830
        begin:monitor_error_event2
16831 35 mihad
            error_monitor_done = 0 ;
16832 15 mihad
            ok = 1 ;
16833
            @(error_event_int) ;
16834
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16835
            ok = 0 ;
16836 35 mihad
            error_monitor_done = 1 ;
16837 15 mihad
        end
16838
        join
16839
 
16840
        config_read(pci_address, 4'hF, data) ;
16841
        if ( data [15:0] !== 16'h04_04 )
16842
        begin
16843
            test_fail("only the first data in a burst to configuration space should actually be written to it") ;
16844
        end
16845
        else if ( ok )
16846
            test_ok ;
16847
    `endif
16848
 
16849
    `ifdef TEST_BURST_CONFIG_READ
16850
        pci_address = Target_Base_Addr_R[0] + 12'h00C ;
16851
 
16852
        data = 32'h0000_04_04 ;
16853
 
16854 45 mihad
        test_name = "TARGET DISCONNECT ON BURST MEMORY READ FROM CONFIGURATION SPACE" ;
16855 15 mihad
        byte_enables = 4'b0000 ;
16856
 
16857
        fork
16858
        begin
16859
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16860
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16861
                    byte_enables,
16862
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16863
                    8'h0_0, `Test_One_Zero_Target_WS,
16864
                    `Test_Devsel_Medium, `Test_Fast_B2B,
16865
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16866
            do_pause( 1 ) ;
16867
 
16868
            DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16869
                    PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
16870
                    byte_enables,
16871
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16872
                    8'h0_0, `Test_One_Zero_Target_WS,
16873
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16874
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16875
            do_pause( 1 ) ;
16876
 
16877
            while ( FRAME !== 1 || IRDY !== 1 )
16878
                @(posedge pci_clock) ;
16879
 
16880 35 mihad
            if ( !error_monitor_done )
16881
                disable monitor_error_event3 ;
16882 15 mihad
        end
16883
        begin:monitor_error_event3
16884 35 mihad
            error_monitor_done = 0 ;
16885 15 mihad
            ok = 1 ;
16886
            @(error_event_int) ;
16887
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16888
            ok = 0 ;
16889 35 mihad
            error_monitor_done = 1 ;
16890 15 mihad
        end
16891
        join
16892
 
16893
        if ( ok )
16894
            test_ok ;
16895
 
16896 45 mihad
 
16897
        test_name = "TARGET DISCONNECT ON BURST CONFIGURATION READ" ;
16898
        pci_address  = `TAR0_IDSEL_ADDR + 'hC ;
16899 15 mihad
        fork
16900
        begin
16901
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16902
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16903
                    byte_enables,
16904
                    2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16905
                    8'h0_0, `Test_One_Zero_Target_WS,
16906
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16907
                    `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
16908
            do_pause( 1 ) ;
16909
 
16910
            DO_REF ("CFG_READ  ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
16911
                    `BC_CONF_READ, data[PCI_BUS_DATA_RANGE:0],
16912
                    byte_enables,
16913
                    3, `Test_No_Addr_Perr, `Test_No_Data_Perr,
16914
                    8'h0_0, `Test_One_Zero_Target_WS,
16915
                    `Test_Devsel_Medium, `Test_No_Fast_B2B,
16916
                    `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
16917
            do_pause( 1 ) ;
16918
 
16919
            while ( FRAME !== 1 || IRDY !== 1 )
16920
                @(posedge pci_clock) ;
16921
 
16922 35 mihad
            #1 ;
16923
            if ( !error_monitor_done )
16924
                disable monitor_error_event4 ;
16925 15 mihad
        end
16926
        begin:monitor_error_event4
16927 35 mihad
            error_monitor_done = 0 ;
16928 15 mihad
            ok = 1 ;
16929
            @(error_event_int) ;
16930
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on bursts to configuration space") ;
16931
            ok = 0 ;
16932 35 mihad
            error_monitor_done = 1 ;
16933 15 mihad
        end
16934
        join
16935
 
16936
        if ( ok )
16937
            test_ok ;
16938
    `endif
16939
 
16940
    `ifdef TEST_BURST_CONFIG_READ
16941
        `undef TEST_BURST_CONFIG_READ
16942
    `endif
16943
 
16944
    `ifdef TEST_BURST_CONFIG_WRITE
16945
        `undef TEST_BURST_CONFIG_WRITE
16946
    `endif
16947
 
16948
    master1_check_received_data = 1 ;
16949
    master2_check_received_data = 1 ;
16950
 
16951
    if ( do_mem_disconnects )
16952
    begin
16953
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
16954
        config_write( ba_offset, Target_Base_Addr_R[target_mem_image], 4'hF, ok ) ;
16955
        if ( ok !== 1 )
16956
        begin
16957
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
16958
            test_fail("PCI Base Address register could not be written") ;
16959
            disable main ;
16960
        end
16961
 
16962
        // Set Address Mask of IMAGE
16963
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image], 4'hF, ok ) ;
16964
        if ( ok !== 1 )
16965
        begin
16966
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
16967
            test_fail("PCI Address Mask register could not be written") ;
16968
            disable main ;
16969
        end
16970
 
16971
        // Set Translation Address of IMAGE
16972
        config_write( ta_offset, Target_Tran_Addr_R[target_mem_image], 4'hF, ok ) ;
16973
        if ( ok !== 1 )
16974
        begin
16975
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
16976
            test_fail("PCI Translation Address Register could not be written") ;
16977
            disable main ;
16978
        end
16979
 
16980
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
16981
        if ( ok !== 1 )
16982
        begin
16983
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
16984
            test_fail("PCI Image Control register could not be written") ;
16985
            disable main ;
16986
        end
16987
 
16988
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
16989
        if ( ok !== 1 )
16990
        begin
16991
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
16992
            test_fail("Cache Line Size register could not be written") ;
16993
            disable main ;
16994
        end
16995
 
16996
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
16997
        pci_address = Target_Base_Addr_R[target_mem_image] ;
16998
        data = 32'hAAAA_AAAA ;
16999
        byte_enables = 4'h0 ;
17000
        expect_length = `PCIW_DEPTH - 2 ;
17001
 
17002
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17003
        fork
17004
        begin
17005
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17006
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17007
                        byte_enables,
17008
                        (tb_subseq_waits != 4) ? expect_length : (expect_length + 1), `Test_No_Addr_Perr, `Test_No_Data_Perr,
17009
                        8'h0_0, `Test_One_Zero_Target_WS,
17010
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17011
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_On : `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17012
            do_pause( 3 ) ;
17013
 
17014
            while ( FRAME !== 1 || IRDY !== 1 )
17015
                @(posedge pci_clock) ;
17016
 
17017 35 mihad
            #1 ;
17018
            if ( !error_monitor_done )
17019
                disable monitor_error_event5 ;
17020 15 mihad
        end
17021
        begin:monitor_error_event5
17022 35 mihad
            error_monitor_done = 0 ;
17023 15 mihad
            pci_ok = 1 ;
17024
            @(error_event_int) ;
17025
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17026
            pci_ok = 0 ;
17027 35 mihad
            error_monitor_done = 1 ;
17028 15 mihad
        end
17029
        begin
17030
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17031
            if ( wb_ok !== 1 )
17032
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17033
        end
17034
        join
17035
 
17036
        if ( wb_ok && pci_ok )
17037
            test_ok ;
17038
 
17039
        test_name = "TARGET DISCONNECT WHEN WRITE FIFO FILLED DURING BURST WRITE" ;
17040
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17041
        data = 32'hAAAA_AAAA ;
17042
        byte_enables = 4'h0 ;
17043
        expect_length = `PCIW_DEPTH - 2 ;
17044
 
17045
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17046
        fork
17047
        begin
17048
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0],
17049
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17050
                        byte_enables,
17051
                        (tb_subseq_waits != 4) ? (expect_length + 1) : (expect_length + 2) , `Test_No_Addr_Perr, `Test_No_Data_Perr,
17052
                        8'h0_0, `Test_One_Zero_Target_WS,
17053
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17054
                        (tb_subseq_waits != 4) ? `Test_Target_Disc_Before : `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17055
            do_pause( 3 ) ;
17056
 
17057
            while ( FRAME !== 1 || IRDY !== 1 )
17058
                @(posedge pci_clock) ;
17059
 
17060 35 mihad
            #1 ;
17061
            if ( !error_monitor_done )
17062
                disable monitor_error_event6 ;
17063 15 mihad
        end
17064
        begin:monitor_error_event6
17065 35 mihad
            error_monitor_done = 0 ;
17066 15 mihad
            pci_ok = 1 ;
17067
            @(error_event_int) ;
17068
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17069
            pci_ok = 0 ;
17070 35 mihad
            error_monitor_done = 1 ;
17071 15 mihad
        end
17072
        begin
17073
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17074
            if ( wb_ok !== 1 )
17075
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17076
        end
17077
        join
17078
 
17079
        if ( wb_ok && pci_ok )
17080
            test_ok ;
17081
 
17082
        master1_check_received_data = 1 ;
17083
//        master2_check_received_data = 0 ;
17084
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17085
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17086
        data = 32'hAAAA_AAAA ;
17087
        byte_enables = 4'h0 ;
17088
        expect_length = 4 ;
17089
 
17090
        fork
17091
        begin
17092
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17093
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17094
                        byte_enables,
17095
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17096
                        8'h0_0, `Test_One_Zero_Target_WS,
17097
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17098
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17099
            do_pause( 1 ) ;
17100
 
17101
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17102
            if ( wb_ok !== 1 )
17103
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17104
 
17105
            do_pause(2) ;
17106
 
17107
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17108
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17109
                        byte_enables,
17110
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17111
                        8'h0_0, `Test_One_Zero_Target_WS,
17112
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17113
                        (tb_subseq_waits == 4) ? `Test_Target_Retry_On : `Test_Target_Disc_Before, `Test_Expect_No_Master_Abort);
17114
            do_pause( 3 ) ;
17115
 
17116
            while ( FRAME !== 1 || IRDY !== 1 )
17117
                @(posedge pci_clock) ;
17118
 
17119 35 mihad
            #1 ;
17120
            if ( !error_monitor_done )
17121
                disable monitor_error_event7 ;
17122 15 mihad
        end
17123
        begin:monitor_error_event7
17124 35 mihad
            error_monitor_done = 0 ;
17125 15 mihad
            pci_ok = 1 ;
17126
            @(error_event_int) ;
17127
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17128
            pci_ok = 0 ;
17129 35 mihad
            error_monitor_done = 1 ;
17130 15 mihad
        end
17131
        join
17132
 
17133
        if ( wb_ok && pci_ok )
17134
            test_ok ;
17135
 
17136
        master1_check_received_data = 1 ;
17137
        test_name = "TARGET DISCONNECT WHEN READ FIFO IS EMPTIED DURING BURST READ" ;
17138
        pci_address = Target_Base_Addr_R[target_mem_image] ;
17139
        data = 32'hAAAA_AAAA ;
17140
        byte_enables = 4'h0 ;
17141
        expect_length = 4 ;
17142
 
17143
        fork
17144
        begin
17145
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17146
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17147
                        byte_enables,
17148
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17149
                        8'h0_0, `Test_One_Zero_Target_WS,
17150
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17151
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17152
            do_pause( 1 ) ;
17153
 
17154
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17155
            if ( wb_ok !== 1 )
17156
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17157
 
17158
            do_pause(2) ;
17159
 
17160
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
17161
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17162
                        byte_enables,
17163
                        expect_length, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17164
                        8'h0_0, `Test_One_Zero_Target_WS,
17165
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17166
                        `Test_Target_Normal_Completion/*Test_Target_Disc_On*/, `Test_Expect_No_Master_Abort);
17167
            do_pause( 3 ) ;
17168
 
17169
            while ( FRAME !== 1 || IRDY !== 1 )
17170
                @(posedge pci_clock) ;
17171
 
17172 35 mihad
            #1 ;
17173
            if ( !error_monitor_done )
17174
                disable monitor_error_event8 ;
17175 15 mihad
        end
17176
        begin:monitor_error_event8
17177 35 mihad
            error_monitor_done = 0 ;
17178 15 mihad
            pci_ok = 1 ;
17179
            @(error_event_int) ;
17180
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17181
            pci_ok = 0 ;
17182 35 mihad
            error_monitor_done = 1 ;
17183 15 mihad
        end
17184
        join
17185
 
17186
        if ( wb_ok && pci_ok )
17187
            test_ok ;
17188
 
17189
        test_name = "TARGET DISCONNECT ON WRITES WITH UNSUPPORTED WRAPING MODES" ;
17190
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17191
        data = 32'hDEAF_BEAF ;
17192
        byte_enables = 4'h0 ;
17193
        expect_length = 1 ;
17194
 
17195
        fork
17196
        begin
17197
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17198
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17199
                        byte_enables,
17200
                        expect_length + 1, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17201
                        8'h0_0, `Test_One_Zero_Target_WS,
17202
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17203
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17204
            do_pause( 3 ) ;
17205
 
17206
            while ( FRAME !== 1 || IRDY !== 1 )
17207
                @(posedge pci_clock) ;
17208
 
17209 35 mihad
            #1 ;
17210
            if ( !error_monitor_done )
17211
                disable monitor_error_event9 ;
17212 15 mihad
        end
17213
        begin:monitor_error_event9
17214 35 mihad
            error_monitor_done = 0 ;
17215 15 mihad
            pci_ok = 1 ;
17216
            @(error_event_int) ;
17217
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17218
            pci_ok = 0 ;
17219 35 mihad
            error_monitor_done = 1 ;
17220 15 mihad
        end
17221
        begin
17222
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17223
            if ( wb_ok !== 1 )
17224
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17225
        end
17226
        join
17227
 
17228
        if ( wb_ok && pci_ok )
17229
            test_ok ;
17230
 
17231
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17232
        data = 32'hDEAD_BEAF ;
17233
        byte_enables = 4'h0 ;
17234
        expect_length = 1 ;
17235
 
17236
        fork
17237
        begin
17238
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 2,
17239
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17240
                        byte_enables,
17241
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17242
                        8'h0_0, `Test_One_Zero_Target_WS,
17243
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17244
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17245
            do_pause( 3 ) ;
17246
 
17247
            while ( FRAME !== 1 || IRDY !== 1 )
17248
                @(posedge pci_clock) ;
17249
 
17250 35 mihad
            #1 ;
17251
            if ( !error_monitor_done )
17252
                disable monitor_error_event10 ;
17253 15 mihad
        end
17254
        begin:monitor_error_event10
17255 35 mihad
            error_monitor_done = 0 ;
17256 15 mihad
            pci_ok = 1 ;
17257
            @(error_event_int) ;
17258
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17259
            pci_ok = 0 ;
17260 35 mihad
            error_monitor_done = 1 ;
17261 15 mihad
        end
17262
        begin
17263
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17264
            if ( wb_ok !== 1 )
17265
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17266
        end
17267
        join
17268
 
17269
        if ( wb_ok && pci_ok )
17270
            test_ok ;
17271
 
17272
        pci_address = Target_Base_Addr_R[target_mem_image] + 108 ;
17273
        data = 32'hAAAA_AAAA ;
17274
        byte_enables = 4'h0 ;
17275
        expect_length = 1 ;
17276
 
17277
        fork
17278
        begin
17279
            DO_REF ("MEM_WRITE ", `Test_Master_1, pci_address[PCI_BUS_DATA_RANGE:0] + 3,
17280
                        PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
17281
                        byte_enables,
17282
                        expect_length + 2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17283
                        8'h0_0, `Test_One_Zero_Target_WS,
17284
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17285
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17286
            do_pause( 3 ) ;
17287
 
17288
            while ( FRAME !== 1 || IRDY !== 1 )
17289
                @(posedge pci_clock) ;
17290
 
17291 35 mihad
            #1 ;
17292
            if ( !error_monitor_done )
17293
                disable monitor_error_event11 ;
17294 15 mihad
        end
17295
        begin:monitor_error_event11
17296 35 mihad
            error_monitor_done = 0 ;
17297 15 mihad
            pci_ok = 1 ;
17298
            @(error_event_int) ;
17299
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target write burst to WISHBONE") ;
17300
            pci_ok = 0 ;
17301 35 mihad
            error_monitor_done = 1 ;
17302 15 mihad
        end
17303
        begin
17304
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17305
            if ( wb_ok !== 1 )
17306
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17307
        end
17308
        join
17309
 
17310
        if ( wb_ok && pci_ok )
17311
            test_ok ;
17312
 
17313
        master1_check_received_data = 1 ;
17314
 
17315
        test_name = "TARGET DISCONNECT ON READS WITH UNSUPPORTED WRAPING MODES" ;
17316
        pci_address = Target_Base_Addr_R[target_mem_image] + 100 ;
17317
        data = 32'hDEAF_BEAF ;
17318
        byte_enables = 4'h0 ;
17319
        expect_length = 1 ;
17320
 
17321
        fork
17322
        begin
17323
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17324
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17325
                        byte_enables,
17326
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17327
                        8'h0_0, `Test_One_Zero_Target_WS,
17328
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17329
                        `Test_Target_Retry_Before, `Test_Expect_No_Master_Abort);
17330
            do_pause( 1 ) ;
17331
 
17332
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17333
            if ( wb_ok !== 1 )
17334
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17335
 
17336
            do_pause(3) ;
17337
 
17338
            DO_REF ("MEM_READ ", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0] + 1,
17339
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17340
                        byte_enables,
17341
                        2, `Test_No_Addr_Perr, `Test_No_Data_Perr,
17342
                        8'h0_0, `Test_One_Zero_Target_WS,
17343
                        `Test_Devsel_Medium, `Test_No_Fast_B2B,
17344
                        `Test_Target_Retry_On, `Test_Expect_No_Master_Abort);
17345
            do_pause( 3 ) ;
17346
 
17347
            while ( FRAME !== 1 || IRDY !== 1 )
17348
                @(posedge pci_clock) ;
17349
 
17350 35 mihad
            #1 ;
17351
            if ( !error_monitor_done )
17352
                disable monitor_error_event12 ;
17353 15 mihad
        end
17354
        begin:monitor_error_event12
17355 35 mihad
            error_monitor_done = 0 ;
17356 15 mihad
            pci_ok = 1 ;
17357
            @(error_event_int) ;
17358
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17359
            pci_ok = 0 ;
17360 35 mihad
            error_monitor_done = 1 ;
17361 15 mihad
        end
17362
        join
17363
 
17364
        if ( wb_ok && pci_ok )
17365
            test_ok ;
17366
 
17367
        pci_address = Target_Base_Addr_R[target_mem_image] + 104 ;
17368
        data = 32'hDEAD_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] + 2,
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] + 2,
17390
                        `BC_MEM_READ_LN, data[PCI_BUS_DATA_RANGE:0],
17391
                        byte_enables,
17392
                        3, `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_Before, `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_event13 ;
17404 15 mihad
        end
17405
        begin:monitor_error_event13
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] + 108 ;
17419
        data = 32'hAAAA_AAAA ;
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] + 3,
17426
                        `BC_MEM_READ_MUL, 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] + 3,
17441
                        `BC_MEM_READ_MUL, 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_event14 ;
17455 15 mihad
        end
17456
        begin:monitor_error_event14
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
        // disable the image
17470
        test_name = "DISABLING MEMORY IMAGE" ;
17471 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_mem_image] & 32'h0000_0000, 4'hF, ok ) ;
17472 15 mihad
        if ( ok !== 1 )
17473
        begin
17474
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17475
            test_fail("PCI Address Mask register could not be written") ;
17476
            disable main ;
17477
        end
17478
    end
17479
//*
17480
    if ( target_io_image !== -1 )
17481
    begin
17482
        do_io_disconnects = 1 ;
17483
 
17484
        if (target_io_image === 1)
17485
        begin
17486
            ctrl_offset = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
17487
            ba_offset   = {4'h1, `P_BA1_ADDR, 2'b00} ;
17488
            am_offset   = {4'h1, `P_AM1_ADDR, 2'b00} ;
17489
            ta_offset   = {4'h1, `P_TA1_ADDR, 2'b00} ;
17490
        end
17491
        else if (target_io_image === 2)
17492
        begin
17493
            ctrl_offset = {4'h1, `P_IMG_CTRL2_ADDR, 2'b00} ;
17494
            ba_offset   = {4'h1, `P_BA2_ADDR, 2'b00} ;
17495
            am_offset   = {4'h1, `P_AM2_ADDR, 2'b00} ;
17496
            ta_offset   = {4'h1, `P_TA2_ADDR, 2'b00} ;
17497
        end
17498
        else if (target_io_image === 3)
17499
        begin
17500
            ctrl_offset = {4'h1, `P_IMG_CTRL3_ADDR, 2'b00} ;
17501
            ba_offset   = {4'h1, `P_BA3_ADDR, 2'b00} ;
17502
            am_offset   = {4'h1, `P_AM3_ADDR, 2'b00} ;
17503
            ta_offset   = {4'h1, `P_TA3_ADDR, 2'b00} ;
17504
        end
17505
        else if (target_io_image === 4)
17506
        begin
17507
            ctrl_offset = {4'h1, `P_IMG_CTRL4_ADDR, 2'b00} ;
17508
            ba_offset   = {4'h1, `P_BA4_ADDR, 2'b00} ;
17509
            am_offset   = {4'h1, `P_AM4_ADDR, 2'b00} ;
17510
            ta_offset   = {4'h1, `P_TA4_ADDR, 2'b00} ;
17511
        end
17512
        else if (target_io_image === 5)
17513
        begin
17514
            ctrl_offset = {4'h1, `P_IMG_CTRL5_ADDR, 2'b00} ;
17515
            ba_offset   = {4'h1, `P_BA5_ADDR, 2'b00} ;
17516
            am_offset   = {4'h1, `P_AM5_ADDR, 2'b00} ;
17517
            ta_offset   = {4'h1, `P_TA5_ADDR, 2'b00} ;
17518
        end
17519
    end
17520
    else
17521
        do_io_disconnects = 0 ;
17522
 
17523
    if ( do_io_disconnects )
17524
    begin
17525
        test_name = "CONFIGURE TARGET FOR DISCONNECT TESTING" ;
17526
        config_write( ba_offset, Target_Base_Addr_R[target_io_image] | 32'h0000_0001, 4'hF, ok ) ;
17527
        if ( ok !== 1 )
17528
        begin
17529
            $display("Target Disconnect testing failed! Failed to write P_BA%d register! Time %t ", 1 ,$time);
17530
            test_fail("PCI Base Address register could not be written") ;
17531
            disable main ;
17532
        end
17533
 
17534
        // Set Address Mask of IMAGE
17535
        config_write( am_offset, Target_Addr_Mask_R[target_io_image], 4'hF, ok ) ;
17536
        if ( ok !== 1 )
17537
        begin
17538
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17539
            test_fail("PCI Address Mask register could not be written") ;
17540
            disable main ;
17541
        end
17542
 
17543
        // Set Translation Address of IMAGE
17544
        config_write( ta_offset, Target_Tran_Addr_R[target_io_image], 4'hF, ok ) ;
17545
        if ( ok !== 1 )
17546
        begin
17547
            $display("Target Disconnect testing failed! Failed to write P_TA%d register! Time %t ",1 ,$time);
17548
            test_fail("PCI Translation Address Register could not be written") ;
17549
            disable main ;
17550
        end
17551
 
17552
        config_write( ctrl_offset, 32'h0000_0002, 4'hF, ok ) ;
17553
        if ( ok !== 1 )
17554
        begin
17555
            $display("Target Disconnect testing failed! Failed to write P_IMG_CTRL%d register! Time %t ",1 ,$time);
17556
            test_fail("PCI Image Control register could not be written") ;
17557
            disable main ;
17558
        end
17559
 
17560
        config_write( cls_offset, 32'h0000_04_04, 4'b0011, ok ) ;
17561
        if ( ok !== 1 )
17562
        begin
17563
            $display("Target Disconnect testing failed! Failed to write Cache Line Size register! Time %t ", $time);
17564
            test_fail("Cache Line Size register could not be written") ;
17565
            disable main ;
17566
        end
17567
 
17568
        test_name = "TARGET DISCONNECT ON BURST WRITE TO IO SPACE" ;
17569
        pci_address = Target_Base_Addr_R[target_io_image] + 200 ;
17570
        data = 32'h5555_5555 ;
17571
        byte_enables = 4'h0 ;
17572
        expect_length = 1 ;
17573
 
17574
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
17575
 
17576
        fork
17577
        begin
17578
            PCIU_IO_WRITE
17579
            (
17580
                `Test_Master_1,             // which master
17581
                pci_address,                // to what address
17582
                data,                       // data
17583
                byte_enables,               // byte enable
17584
                expect_length + 1,          // length to request
17585
                `Test_Target_Retry_On       // expected target termination
17586
            ) ;
17587
 
17588
            do_pause( 3 ) ;
17589
 
17590
            while ( FRAME !== 1 || IRDY !== 1 )
17591
                @(posedge pci_clock) ;
17592
 
17593 35 mihad
            #1 ;
17594
            if ( !error_monitor_done )
17595
                disable monitor_error_event15 ;
17596 15 mihad
        end
17597
        begin:monitor_error_event15
17598 35 mihad
            error_monitor_done = 0 ;
17599 15 mihad
            pci_ok = 1 ;
17600
            @(error_event_int) ;
17601
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17602
            pci_ok = 0 ;
17603 35 mihad
            error_monitor_done = 1 ;
17604 15 mihad
        end
17605
        begin
17606
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17607
            if ( wb_ok !== 1 )
17608
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17609
        end
17610
        join
17611
 
17612
        if ( wb_ok && pci_ok )
17613
            test_ok ;
17614
 
17615
        data = 32'hAAAA_AAAA ;
17616
        fork
17617
        begin
17618
            PCIU_IO_WRITE
17619
            (
17620
                `Test_Master_1,             // which master
17621
                pci_address,                // to what address
17622
                data,                       // data
17623
                byte_enables,               // byte enable
17624
                expect_length + 2,          // length to request
17625
                `Test_Target_Retry_Before   // expected target termination
17626
            ) ;
17627
 
17628
            do_pause( 3 ) ;
17629
 
17630
            while ( FRAME !== 1 || IRDY !== 1 )
17631
                @(posedge pci_clock) ;
17632
 
17633 35 mihad
            #1 ;
17634
            if ( !error_monitor_done )
17635
                disable monitor_error_event16 ;
17636 15 mihad
        end
17637
        begin:monitor_error_event16
17638 35 mihad
            error_monitor_done = 0 ;
17639 15 mihad
            pci_ok = 1 ;
17640
            @(error_event_int) ;
17641
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target IO burst write") ;
17642
            pci_ok = 0 ;
17643 35 mihad
            error_monitor_done = 1 ;
17644 15 mihad
        end
17645
        begin
17646
            wb_transaction_progress_monitor(pci_address, 1'b1, expect_length, 1'b1, wb_ok) ;
17647
            if ( wb_ok !== 1 )
17648
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17649
        end
17650
        join
17651
 
17652
        if ( wb_ok && pci_ok )
17653
            test_ok ;
17654
 
17655
        master2_check_received_data = 1 ;
17656
 
17657
        test_name = "TARGET DISCONNECT ON BURST READ TO IO SPACE" ;
17658
 
17659
        fork
17660
        begin
17661
 
17662
             PCIU_IO_READ
17663
             (
17664
                `Test_Master_2,
17665
                pci_address[PCI_BUS_DATA_RANGE:0],
17666
                data,
17667
                byte_enables,
17668
                2,
17669
                `Test_Target_Retry_Before
17670
             );
17671
 
17672
            do_pause( 1 ) ;
17673
 
17674
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17675
            if ( wb_ok !== 1 )
17676
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17677
 
17678
            do_pause(3) ;
17679
 
17680
            PCIU_IO_READ
17681
             (
17682
                `Test_Master_2,
17683
                pci_address[PCI_BUS_DATA_RANGE:0],
17684
                data,
17685
                byte_enables,
17686
                expect_length + 1,
17687
                `Test_Target_Retry_On
17688
             );
17689
 
17690
            do_pause( 3 ) ;
17691
 
17692
            while ( FRAME !== 1 || IRDY !== 1 )
17693
                @(posedge pci_clock) ;
17694
 
17695 35 mihad
            #1 ;
17696
            if ( !error_monitor_done )
17697
                disable monitor_error_event17 ;
17698 15 mihad
        end
17699
        begin:monitor_error_event17
17700 35 mihad
            error_monitor_done = 0 ;
17701 15 mihad
            pci_ok = 1 ;
17702
            @(error_event_int) ;
17703
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17704
            pci_ok = 0 ;
17705 35 mihad
            error_monitor_done = 1 ;
17706 15 mihad
        end
17707
        join
17708
 
17709
        if ( wb_ok && pci_ok )
17710
            test_ok ;
17711
 
17712
        fork
17713
        begin
17714
 
17715
             PCIU_IO_READ
17716
             (
17717
                `Test_Master_2,
17718
                pci_address[PCI_BUS_DATA_RANGE:0],
17719
                data,
17720
                byte_enables,
17721
                2,
17722
                `Test_Target_Retry_Before
17723
             );
17724
 
17725
            do_pause( 1 ) ;
17726
 
17727
            wb_transaction_progress_monitor(pci_address, 1'b0, expect_length, 1'b1, wb_ok) ;
17728
            if ( wb_ok !== 1 )
17729
                test_fail("WISHBONE Master started invalid transaction or none at all on WISHBONE bus") ;
17730
 
17731
            do_pause(3) ;
17732
 
17733
            PCIU_IO_READ
17734
             (
17735
                `Test_Master_2,
17736
                pci_address[PCI_BUS_DATA_RANGE:0],
17737
                data,
17738
                byte_enables,
17739
                expect_length + 2,
17740
                `Test_Target_Retry_Before
17741
             );
17742
 
17743
            do_pause( 3 ) ;
17744
 
17745
            while ( FRAME !== 1 || IRDY !== 1 )
17746
                @(posedge pci_clock) ;
17747
 
17748 35 mihad
            #1 ;
17749
            if ( !error_monitor_done )
17750
                disable monitor_error_event18 ;
17751 15 mihad
        end
17752
        begin:monitor_error_event18
17753 35 mihad
            error_monitor_done = 0 ;
17754 15 mihad
            pci_ok = 1 ;
17755
            @(error_event_int) ;
17756
            test_fail("PCI Master or Monitor signaled an error while testing disconnect on Target read burst from WISHBONE") ;
17757
            pci_ok = 0 ;
17758 35 mihad
            error_monitor_done = 1 ;
17759 15 mihad
        end
17760
        join
17761
 
17762
        if ( wb_ok && pci_ok )
17763
            test_ok ;
17764
 
17765
        test_name = "DISABLING IO IMAGE" ;
17766 45 mihad
        config_write( am_offset, Target_Addr_Mask_R[target_io_image] & 32'h0000_0000, 4'hF, ok ) ;
17767 15 mihad
        if ( ok !== 1 )
17768
        begin
17769
            $display("Target Disconnect testing failed! Failed to write P_AM%d register! Time %t ",1 ,$time);
17770
            test_fail("PCI Address Mask register could not be written") ;
17771
            disable main ;
17772
        end
17773
    end
17774
//*/
17775
end
17776
endtask // target_disconnects
17777
 
17778
task target_unsupported_cmds ;
17779
        input [31:0] Address;
17780
        input [2:0]  image_num ;
17781
    reg          ok ;
17782
begin:main
17783
 
17784
    $display("  ") ;
17785
    $display("  Master abort testing with unsuported bus command to image %d (BC is IACK)!", image_num) ;
17786
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - IACK" ;
17787 45 mihad
 
17788
    // disable pci blue behavioral targets 1 and 2, so no device except the bridge can respond to this
17789
    configuration_cycle_write
17790
    (
17791
        0,                        // bus number
17792
        `TAR1_IDSEL_INDEX - 11,   // device number
17793
        0,                        // function number
17794
        1,                        // register number
17795
        0,                        // type of configuration cycle
17796
        4'b0001,                  // byte enables
17797
        32'h0000_0044             // data
17798
    ) ;
17799
 
17800
    configuration_cycle_write
17801
    (
17802
        0,                        // bus number
17803
        `TAR2_IDSEL_INDEX - 11,   // device number
17804
        0,                        // function number
17805
        1,                        // register number
17806
        0,                        // type of configuration cycle
17807
        4'b0001,                  // byte enables
17808
        32'h0000_0044             // data
17809
    ) ;
17810
 
17811 15 mihad
    ipci_unsupported_commands_master.master_reference
17812
    (
17813
        Address,                // first part of address in dual address cycle
17814
        Address,                // second part of address in dual address cycle
17815
        `BC_IACK,                       // dual address cycle command
17816
        `BC_IACK,               // normal command
17817
        4'h0,               // byte enables
17818
        32'h1234_5678,      // data
17819
        1'b0,               // make address parity error on first phase of dual address
17820
        1'b0,               // make address parity error on second phase of dual address
17821
        ok                  // result of operation
17822
    ) ;
17823
    if ( ok )
17824
        test_ok ;
17825
    else
17826
    begin
17827
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17828
        test_fail("PCI Target shouldn't responded on unsuported bus command IACK") ;
17829
    end
17830
 
17831
    $display("  Master abort testing with unsuported bus command to image %d (BC is SPECIAL)!", image_num) ;
17832
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - SPECIAL" ;
17833
    ipci_unsupported_commands_master.master_reference
17834
    (
17835
        Address,                // first part of address in dual address cycle
17836
        Address,                // second part of address in dual address cycle
17837
        `BC_SPECIAL,            // dual address cycle command
17838
        `BC_SPECIAL,            // normal command
17839
        4'h0,               // byte enables
17840
        32'h1234_5678,      // data
17841
        1'b0,               // make address parity error on first phase of dual address
17842
        1'b0,               // make address parity error on second phase of dual address
17843
        ok                  // result of operation
17844
    ) ;
17845
    if ( ok )
17846
        test_ok ;
17847
    else
17848
    begin
17849
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17850
        test_fail("PCI Target shouldn't responded on unsuported bus command SPECIAL") ;
17851
    end
17852
 
17853
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED0)!", image_num) ;
17854
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED0" ;
17855
    ipci_unsupported_commands_master.master_reference
17856
    (
17857
        Address,                // first part of address in dual address cycle
17858
        Address,                // second part of address in dual address cycle
17859
        `BC_RESERVED0,          // dual address cycle command
17860
        `BC_RESERVED0,      // normal command
17861
        4'h0,               // byte enables
17862
        32'h1234_5678,      // data
17863
        1'b0,               // make address parity error on first phase of dual address
17864
        1'b0,               // make address parity error on second phase of dual address
17865
        ok                  // result of operation
17866
    ) ;
17867
    if ( ok )
17868
        test_ok ;
17869
    else
17870
    begin
17871
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17872
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED0") ;
17873
    end
17874
 
17875
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED1)", image_num) ;
17876
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED1" ;
17877
    ipci_unsupported_commands_master.master_reference
17878
    (
17879
        Address,                // first part of address in dual address cycle
17880
        Address,                // second part of address in dual address cycle
17881
        `BC_RESERVED1,          // dual address cycle command
17882
        `BC_RESERVED1,      // normal command
17883
        4'h0,               // byte enables
17884
        32'h1234_5678,      // data
17885
        1'b0,               // make address parity error on first phase of dual address
17886
        1'b0,               // make address parity error on second phase of dual address
17887
        ok                  // result of operation
17888
    ) ;
17889
    if ( ok )
17890
        test_ok ;
17891
    else
17892
    begin
17893
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17894
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED1") ;
17895
    end
17896
 
17897
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED2)!", image_num) ;
17898
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED2" ;
17899
    ipci_unsupported_commands_master.master_reference
17900
    (
17901
        Address,                // first part of address in dual address cycle
17902
        Address,                // second part of address in dual address cycle
17903
        `BC_RESERVED2,          // dual address cycle command
17904
        `BC_RESERVED2,      // normal command
17905
        4'h0,               // byte enables
17906
        32'h1234_5678,      // data
17907
        1'b0,               // make address parity error on first phase of dual address
17908
        1'b0,               // make address parity error on second phase of dual address
17909
        ok                  // result of operation
17910
    ) ;
17911
    if ( ok )
17912
        test_ok ;
17913
    else
17914
    begin
17915
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17916
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED2") ;
17917
    end
17918
 
17919
    $display("  Master abort testing with unsuported bus command to image %d (BC is RESERVED3)!", image_num) ;
17920
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - RESERVED3" ;
17921
    ipci_unsupported_commands_master.master_reference
17922
    (
17923
        Address,                // first part of address in dual address cycle
17924
        Address,                // second part of address in dual address cycle
17925
        `BC_RESERVED3,          // dual address cycle command
17926
        `BC_RESERVED3,      // normal command
17927
        4'h0,               // byte enables
17928
        32'h1234_5678,      // data
17929
        1'b0,               // make address parity error on first phase of dual address
17930
        1'b0,               // make address parity error on second phase of dual address
17931
        ok                  // result of operation
17932
    ) ;
17933
    if ( ok )
17934
        test_ok ;
17935
    else
17936
    begin
17937
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17938
        test_fail("PCI Target shouldn't responded on unsuported bus command RESERVED3") ;
17939
    end
17940
 
17941
    $display("PCI monitor will complain twice with 'CBE Bus Changed'; second bus command (MEM_WRITE) and ") ;
17942
    $display("    byte enables are different than first bus command (DUAL_ADDR_CYC)!") ;
17943
    $display("  Master abort testing with unsuported bus command to image %d (BC is DUAL_ADDR_CYC)!", image_num) ;
17944
    test_name = "MASTER ABORT WHEN ACCESSING TARGET WITH UNSUPPORTED BUS COMMAND - DUAL_ADDR_CYC" ;
17945
    ipci_unsupported_commands_master.master_reference
17946
    (
17947
        Address,                // first part of address in dual address cycle
17948
        Address,                // second part of address in dual address cycle
17949
        `BC_DUAL_ADDR_CYC,  // dual address cycle command
17950
        `BC_MEM_WRITE,      // normal command
17951
        4'h0,               // byte enables;
17952
        32'h1234_5678,      // data
17953
        1'b0,               // make address parity error on first phase of dual address
17954
        1'b0,               // make address parity error on second phase of dual address
17955
        ok                  // result of operation
17956
    ) ;
17957
    if ( ok )
17958
        test_ok ;
17959
    else
17960
    begin
17961
        $display("* Master abort testing failed, PCI Target responded on unsuported bus command!        Time %t ", $time) ;
17962
        test_fail("PCI Target shouldn't responded on unsuported bus command DUAL_ADDR_CYC") ;
17963
    end
17964
 
17965 45 mihad
    // enable pci blue behavioral targets 1 and 2
17966
    configuration_cycle_write
17967
    (
17968
        0,                        // bus number
17969
        `TAR1_IDSEL_INDEX - 11,   // device number
17970
        0,                        // function number
17971
        1,                        // register number
17972
        0,                        // type of configuration cycle
17973
        4'b0001,                  // byte enables
17974
        32'h0000_0047             // data
17975
    ) ;
17976
 
17977
    configuration_cycle_write
17978
    (
17979
        0,                        // bus number
17980
        `TAR2_IDSEL_INDEX - 11,   // device number
17981
        0,                        // function number
17982
        1,                        // register number
17983
        0,                        // type of configuration cycle
17984
        4'b0001,                  // byte enables
17985
        32'h0000_0047             // data
17986
    ) ;
17987 15 mihad
end
17988
endtask // target_unsupported_cmds
17989
 
17990
task target_completion_expiration ;
17991
    reg   [11:0] pci_ctrl_offset ;
17992
    reg   [11:0] pci_ba_offset ;
17993
    reg   [11:0] pci_am_offset ;
17994
    reg   [11:0] pci_device_ctrl_offset ;
17995
    reg   [11:0] pci_err_cs_offset ;
17996
    reg   [11:0] icr_offset ;
17997
    reg   [11:0] isr_offset ;
17998
    reg   [11:0] lat_tim_cls_offset ;
17999
 
18000
    reg [31:0] temp_val1 ;
18001
    reg [31:0] temp_val2 ;
18002
    reg        ok   ;
18003 33 mihad
    reg        ok_wb ;
18004
    reg        ok_pci ;
18005 15 mihad
 
18006
    reg [31:0] pci_image_base ;
18007
    integer i ;
18008 33 mihad
    integer clocks_after_completion ;
18009
    reg     error_monitor_done ;
18010
    reg     test_mem ;
18011 15 mihad
 
18012
begin:main
18013
    pci_ctrl_offset        = {4'h1, `P_IMG_CTRL1_ADDR, 2'b00} ;
18014
    pci_ba_offset          = {4'h1, `P_BA1_ADDR, 2'b00} ;
18015
    pci_am_offset          = {4'h1, `P_AM1_ADDR, 2'b00} ;
18016
    pci_err_cs_offset      = {4'h1, `P_ERR_CS_ADDR, 2'b00} ;
18017
 
18018
    icr_offset         = {4'h1, `ICR_ADDR, 2'b00} ;
18019
    isr_offset         = {4'h1, `ISR_ADDR, 2'b00} ;
18020
    lat_tim_cls_offset = 12'hC ;
18021
    pci_device_ctrl_offset    = 12'h4 ;
18022
 
18023 33 mihad
    `ifdef HOST
18024
        test_mem = 1'b1 ;
18025
        pci_image_base = Target_Base_Addr_R[1] & 32'hFFFF_FFFE ;
18026
    `else
18027
        test_mem = !`PCI_BA1_MEM_IO ;
18028
        pci_image_base = Target_Base_Addr_R[1] ;
18029
    `endif
18030 15 mihad
 
18031
    // enable master & target operation
18032
    test_name = "BRIDGE CONFIGURATION FOR DELAYED COMPLETION EXPIRATION TEST" ;
18033
    config_write( pci_device_ctrl_offset, 32'h0000_0147, 4'h3, ok) ;
18034
    if ( ok !== 1 )
18035
    begin
18036
        $display("Target completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18037
        test_fail("write to PCI Device Control register failed") ;
18038
        disable main ;
18039
    end
18040
 
18041
    // prepare image control register
18042 33 mihad
    config_write( pci_ctrl_offset, 32'h0000_0002, 4'hF, ok) ;
18043 15 mihad
    if ( ok !== 1 )
18044
    begin
18045
        $display("Target completion expiration testing failed! Failed to write P_IMG_CTRL1 register! Time %t ", $time) ;
18046
        test_fail("write to PCI Image Control register failed") ;
18047
        disable main ;
18048
    end
18049
 
18050
    // prepare base address register
18051
    config_write( pci_ba_offset, pci_image_base, 4'hF, ok ) ;
18052
    if ( ok !== 1 )
18053
    begin
18054
        $display("Target completion expiration testing failed! Failed to write P_BA1 register! Time %t ", $time) ;
18055
        test_fail("write to PCI Base Address register failed") ;
18056
        disable main ;
18057
    end
18058
 
18059
    // write address mask register
18060
    config_write( pci_am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18061
    if ( ok !== 1 )
18062
    begin
18063
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18064
        test_fail("write to PCI Address Mask register failed") ;
18065
        disable main ;
18066
    end
18067
 
18068
    // enable all status and error reporting features - this tests should proceede normaly and cause no statuses to be set
18069
    config_write( pci_err_cs_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18070
    if ( ok !== 1 )
18071
    begin
18072
        $display("Target completion expiration testing failed! Failed to write P_ERR_CS register! Time %t ", $time) ;
18073
        test_fail("write to PCI Error Control and Status register failed") ;
18074
        disable main ;
18075
    end
18076
 
18077 33 mihad
    config_write( icr_offset, 32'h0000_0000, 4'hF, ok ) ;
18078 15 mihad
    if ( ok !== 1 )
18079
    begin
18080
        $display("Target completion expiration testing failed! Failed to write IC register! Time %t ", $time) ;
18081
        test_fail("write to Interrupt Control register failed") ;
18082
        disable main ;
18083
    end
18084
 
18085
    // set latency timer and cache line size to 4 - this way even the smallest fifo sizes can be tested
18086
    config_write( lat_tim_cls_offset, 32'hFFFF_0404, 4'h3, ok ) ;
18087
    if ( ok !== 1 )
18088
    begin
18089
        $display("Target completion expiration testing failed! Failed to write latency timer and cache line size values! Time %t ", $time) ;
18090
        test_fail("write to Latency Timer and Cache Line Size registers failed") ;
18091
        disable main ;
18092
    end
18093
 
18094
    pci_image_base[(31-`PCI_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18095
 
18096
    wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18097 33 mihad
    test_name = "FLUSH OF DELAYED READ UNCOMPLETED IN 2^^16 CYCLES FROM PCI TARGET UNIT" ;
18098
    master1_check_received_data = 0 ;
18099 15 mihad
 
18100 33 mihad
    ok_pci = 1 ;
18101
    // start a delayed read request
18102
    fork
18103
    begin
18104
        if ( test_mem )
18105
 
18106
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18107
                          pci_image_base, 32'h1234_5678,
18108
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18109
                          `Test_Devsel_Medium, `Test_Target_Retry_On);
18110
        else
18111
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18112
 
18113
        do_pause( 1 ) ;
18114
    end
18115
    begin:error_monitor1
18116 35 mihad
        error_monitor_done = 0 ;
18117 33 mihad
        @(error_event_int) ;
18118
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18119
        ok_pci = 0 ;
18120 35 mihad
        error_monitor_done = 1 ;
18121 33 mihad
    end
18122
    begin
18123
        if ( test_mem )
18124
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 4, 1'b1, ok_wb ) ;
18125
        else
18126
            wb_transaction_progress_monitor( pci_image_base, 1'b0, 1, 1'b1, ok_wb ) ;
18127 15 mihad
 
18128 33 mihad
        if ( ok_wb !== 1 )
18129
        begin
18130
            test_fail("Bridge failed to process Target Memory read correctly") ;
18131
            disable main ;
18132
        end
18133
 
18134 35 mihad
        #1 ;
18135
        if ( !error_monitor_done )
18136 33 mihad
            disable error_monitor1 ;
18137
    end
18138
    join
18139
 
18140
    clocks_after_completion = 0 ;
18141
    // now do another - different transaction
18142
    fork
18143
    begin
18144
        if ( test_mem )
18145
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18146
                          pci_image_base + 4, 32'h1234_5678,
18147
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18148
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18149
        else
18150
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18151
 
18152
        while ( clocks_after_completion < 32'h0000_FFF0 )
18153
        begin
18154
            @(posedge pci_clock) ;
18155
            clocks_after_completion = clocks_after_completion + 1 ;
18156
        end
18157
 
18158
        do_pause('hFF) ;
18159
 
18160
        if ( test_mem )
18161
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18162
                          pci_image_base + 4, 32'h1234_5678,
18163
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18164
                         `Test_Devsel_Medium, `Test_Target_Retry_On);
18165
        else
18166
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Retry_On ) ;
18167
 
18168
        do_pause( 1 ) ;
18169
    end
18170
    begin:error_monitor2
18171 35 mihad
        error_monitor_done = 0 ;
18172 33 mihad
        @(error_event_int) ;
18173
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18174
        ok_pci = 0 ;
18175 35 mihad
        error_monitor_done = 1 ;
18176 33 mihad
    end
18177
    begin
18178
        wait ( clocks_after_completion === 32'h0000_FFF0 ) ;
18179
        repeat( 'hFF )
18180
            @(posedge pci_clock) ;
18181
 
18182
        if ( test_mem )
18183
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 4, 1'b1, ok_wb ) ;
18184
        else
18185
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 1, 1'b1, ok_wb ) ;
18186
 
18187
        if ( ok_wb !== 1 )
18188
        begin
18189
            test_fail("Bridge failed to process Target Memory read correctly") ;
18190
            disable main ;
18191
        end
18192
 
18193
        repeat(4)
18194
            @(posedge pci_clock) ;
18195
 
18196
        fork
18197
        begin
18198
            if ( test_mem )
18199
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18200
                              pci_image_base + 4, 32'h1234_5678,
18201
                              4, 8'h7_0, `Test_One_Zero_Target_WS,
18202
                             `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18203
            else
18204
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18205
 
18206
            do_pause(1) ;
18207
        end
18208
        begin
18209
           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 ) ;
18210 35 mihad
           #1 ;
18211
           if ( !error_monitor_done )
18212 33 mihad
               disable error_monitor2 ;
18213
        end
18214
        join
18215
    end
18216
    join
18217
 
18218
    if ( ok && ok_pci && ok_wb )
18219
        test_ok ;
18220
 
18221
    if ( ok !== 1 )
18222
    begin
18223
        $display("Target completion expiration testing failed! Failed to write P_AM1 register! Time %t ", $time) ;
18224
        test_fail("write to PCI Address Mask register failed") ;
18225
        disable main ;
18226
    end
18227
 
18228
    // check statuses after this situation - none should be set
18229
    test_name = "PCI DEVICE ERROR STATUS BITS' STATES AFTER COMPLETION EXPIRED IN PCI TARGET UNIT" ;
18230
    config_read( pci_device_ctrl_offset, 4'hC, temp_val1 ) ;
18231
    if ( ok !== 1 )
18232
    begin
18233
        $display("Target completion expiration testing failed! Failed to read pci device status register! Time %t ", $time) ;
18234
        test_fail("read from pci device status register failed") ;
18235
        disable main ;
18236
    end
18237
 
18238
    if ( temp_val1[31] )
18239
    begin
18240
        $display("Target completion expiration testing failed! Detected parity error bit set for no reason! Time %t ", $time) ;
18241
        test_fail("detected parity error bit was set for no reason") ;
18242
    end
18243
 
18244
    if ( temp_val1[30] )
18245
    begin
18246
        $display("Target completion expiration testing failed! Signaled system error bit set for no reason! Time %t ", $time) ;
18247
        test_fail("signaled system error bit was set for no reason") ;
18248
    end
18249
 
18250
    if ( temp_val1[29] )
18251
    begin
18252
        $display("Target completion expiration testing failed! Received master abort bit set for no reason! Time %t ", $time) ;
18253
        test_fail("received master abort bit was set for no reason") ;
18254
    end
18255
 
18256
    if ( temp_val1[28] )
18257
    begin
18258
        $display("Target completion expiration testing failed! Received Target abort bit set for no reason! Time %t ", $time) ;
18259
        test_fail("received target abort bit was set for no reason") ;
18260
    end
18261
 
18262
    if ( temp_val1[27] )
18263
    begin
18264
        $display("Target completion expiration testing failed! Signaled Target abort bit set for no reason! Time %t ", $time) ;
18265
        test_fail("signaled target abort bit was set for no reason") ;
18266
    end
18267
 
18268
    if ( temp_val1[24] )
18269
    begin
18270
        $display("Target completion expiration testing failed! Master Data parity error bit set for no reason! Time %t ", $time) ;
18271
        test_fail("Master Data parity error bit was set for no reason") ;
18272
    end
18273
 
18274
    test_name = "PCI TARGET UNIT ERROR REPORTING REGISTER VALUE AFTER COMPLETION EXPIRED" ;
18275
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18276
    if ( temp_val1[8] !== 0 )
18277
    begin
18278
        $display("Target completion expiration testing failed! Error status bit in PCI error reporting register set for no reason! Time %t ", $time) ;
18279
        test_fail("Error status bit in PCI error reporting register was set for no reason") ;
18280
    end
18281
    // test target retry counter expiration
18282
    // set wb slave to retry response
18283
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18284
    test_name = "RETRY COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18285
    ok_pci = 1 ;
18286
 
18287
    fork
18288
    begin
18289
        if ( test_mem == 1 )
18290
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18291
                        pci_image_base, 32'hDEAD_BEAF, 4'hA,
18292
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18293
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18294
        else
18295
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hDEAD_BEAF, 4'hA, 1, `Test_Target_Normal_Completion) ;
18296
 
18297
        do_pause(1) ;
18298
 
18299
        // do another write with same address and different data
18300
        if ( test_mem == 1 )
18301
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18302
                        pci_image_base, 32'h8765_4321, 4'h0,
18303
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18304
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18305
        else
18306
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion) ;
18307
 
18308
        do_pause(1) ;
18309
    end
18310
    begin
18311
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18312
        begin
18313
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18314
            if ( ok_wb !== 1 )
18315
            begin
18316
                $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) ;
18317
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18318
                disable main ;
18319
            end
18320
        end
18321
 
18322
        // set WB slave to normal completion
18323
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18324
 
18325
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18326
        if ( ok_wb !== 1 )
18327
        begin
18328
            $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) ;
18329
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18330
            disable main ;
18331
        end
18332
 
18333 35 mihad
        #1 ;
18334
        if ( !error_monitor_done )
18335 33 mihad
            disable error_monitor3 ;
18336
    end
18337
    begin:error_monitor3
18338 35 mihad
        error_monitor_done = 0 ;
18339 33 mihad
        @(error_event_int) ;
18340
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18341
        ok_pci = 0 ;
18342 35 mihad
        error_monitor_done = 1 ;
18343 33 mihad
    end
18344
    join
18345
 
18346
    if ( ok_wb && ok_pci )
18347
    begin
18348
        test_ok ;
18349
    end
18350
 
18351
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18352
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18353
    if ( temp_val1[8] !== 1'b1 )
18354
    begin
18355
        $display("WISHBONE Master Retry Counter expiration test failed! WB Master should signal an error when retry counter expires during a write! Time %t", $time) ;
18356
        test_fail("error wasn't reported, when retry counter expired during posted write through PCI Target unit") ;
18357
    end
18358
 
18359
    if ( temp_val1[9] !== 1 )
18360
    begin
18361
        $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) ;
18362
        test_fail("error source bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18363
    end
18364
 
18365
    if ( temp_val1[10] !== 1 )
18366
    begin
18367
        $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) ;
18368
        test_fail("retry expired bit wasn't set, when retry counter expired during posted write through PCI Target unit") ;
18369
    end
18370
 
18371
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18372
    begin
18373
        $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) ;
18374
        test_fail("bus command field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18375
    end
18376
 
18377
    if ( temp_val1[31:28] !== 4'hA )
18378
    begin
18379
        $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) ;
18380
        test_fail("byte enable field in error control and status register was wrong when retry counter expired during posted write through PCI Target unit") ;
18381
    end
18382
 
18383
    // clear error status register
18384
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18385
 
18386
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18387
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18388
    if ( temp_val1 !== pci_image_base )
18389
    begin
18390
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error address register when retry counter expired during a write! Time %t", $time) ;
18391
        test_fail("value in error address register was wrong when retry counter expired during posted write through PCI Target unit") ;
18392
    end
18393
 
18394
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED" ;
18395
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18396
    if ( temp_val1 !== 32'hDEAD_BEAF )
18397
    begin
18398
        $display("WISHBONE Master Retry Counter expiration test failed! Invalid value in error data register when retry counter expired during a write! Time %t", $time) ;
18399
        test_fail("value in error data register was wrong when retry counter expired during posted write through PCI Target unit") ;
18400
    end
18401
 
18402
    test_name = "RETRY COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18403
    ok_pci = 1 ;
18404
    wishbone_slave.cycle_response(3'b001, tb_subseq_waits, 8'd255);
18405
 
18406
    i = 0 ;
18407
    fork
18408
    begin
18409
        if ( test_mem )
18410
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18411
                          pci_image_base + 4, 32'h1234_5678,
18412
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18413
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18414
        else
18415
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18416
 
18417
        do_pause( 1 ) ;
18418
 
18419
    end
18420
    begin
18421
        for ( i = 0 ; i < `WB_RTY_CNT_MAX ; i = i + 1 )
18422
        begin
18423
            wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18424
            if ( ok_wb !== 1 )
18425
            begin
18426
                $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) ;
18427
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18428
                disable main ;
18429
            end
18430
        end
18431
 
18432
        // set WB slave to normal completion
18433
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'h0);
18434
 
18435
        fork
18436
        begin
18437
            repeat(4)
18438
                @(posedge pci_clock) ;
18439
 
18440
            if ( test_mem )
18441
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18442
                              pci_image_base, 32'h8765_4321,
18443
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18444
                             `Test_Devsel_Medium, `Test_Target_Retry_On);
18445
            else
18446
                PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Retry_On ) ;
18447
 
18448
            do_pause(1) ;
18449
        end
18450
        begin
18451
 
18452
            wb_transaction_progress_monitor( pci_image_base, 1'b0, test_mem ? 4 : 1, 1'b1, ok_wb ) ;
18453
            if ( ok_wb !== 1 )
18454
            begin
18455
                $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) ;
18456
                test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18457
                disable main ;
18458
            end
18459
        end
18460
        join
18461
 
18462
        repeat( 4 )
18463
            @(posedge pci_clock) ;
18464
 
18465
        if ( test_mem )
18466
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18467
                          pci_image_base, 32'h8765_4321,
18468
                          1, 8'h7_0, `Test_One_Zero_Target_WS,
18469
                         `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18470
        else
18471
            PCIU_IO_READ( `Test_Master_1, pci_image_base, 32'h8765_4321, 4'h0, 1, `Test_Target_Normal_Completion ) ;
18472
 
18473
        do_pause(1) ;
18474
 
18475 35 mihad
        #1 ;
18476
        if ( !error_monitor_done )
18477 33 mihad
            disable error_monitor4 ;
18478
    end
18479
    begin:error_monitor4
18480 35 mihad
        error_monitor_done = 0 ;
18481 33 mihad
        @(error_event_int) ;
18482
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18483
        ok_pci = 0 ;
18484 35 mihad
        error_monitor_done = 1 ;
18485 33 mihad
    end
18486
    join
18487
 
18488
    if ( ok_wb && ok_pci )
18489
        test_ok ;
18490
 
18491
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER RETRY COUNTER EXPIRED DURING READ" ;
18492
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18493
    if ( temp_val1[8] !== 1'b0 )
18494
    begin
18495
        $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) ;
18496
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18497
    end
18498
 
18499
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING READ THROUGH PCI TARGET UNIT" ;
18500 45 mihad
    $display("PCIU monitor (WB bus) will complain in following section for a few times - no WB response test!") ;
18501
    $fdisplay(pciu_mon_log_file_desc,
18502
    "********************************************  Monitor should complain in following section for two times about STB de-asserted without slave response  ************************************************") ;
18503 33 mihad
    ok_pci = 1 ;
18504
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18505
 
18506
    fork
18507
    begin
18508
        if ( test_mem )
18509
            PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18510
                          pci_image_base + 4, 32'h1234_5678,
18511
                          2, 8'h7_0, `Test_One_Zero_Target_WS,
18512
                         `Test_Devsel_Medium, `Test_Target_Retry_Before);
18513
        else
18514
            PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h1234_5678, 4'h0, 2, `Test_Target_Retry_Before ) ;
18515
 
18516
        do_pause( 1 ) ;
18517
 
18518
    end
18519
    begin
18520
        wb_transaction_progress_monitor( pci_image_base + 4, 1'b0, 0, 1'b1, ok_wb ) ;
18521
        if ( ok_wb !== 1 )
18522
        begin
18523
            $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) ;
18524
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18525
            disable main ;
18526
        end
18527
 
18528
        repeat(4)
18529
            @(posedge pci_clock) ;
18530
 
18531
        fork
18532
        begin
18533
 
18534
            if ( test_mem )
18535
                PCIU_MEM_READ("MEM_READ  ", `Test_Master_1,
18536
                              pci_image_base + 4, 32'h8765_4321,
18537
                              1, 8'h7_0, `Test_One_Zero_Target_WS,
18538
                             `Test_Devsel_Medium, `Test_Target_Abort_On);
18539
            else
18540
                PCIU_IO_READ( `Test_Master_1, pci_image_base + 4, 32'h8765_4321, 4'h0, 1, `Test_Target_Abort_On ) ;
18541
 
18542
            do_pause(1) ;
18543
 
18544
        end
18545
        begin
18546
 
18547
            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 ) ;
18548
            if ( ok !== 1 )
18549
            begin
18550
                $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) ;
18551
                test_fail("PCI transaction progress monitor detected invalid transaction or none at all on PCI bus") ;
18552
                disable main ;
18553
            end
18554
        end
18555
        join
18556
 
18557 35 mihad
        #1 ;
18558
        if ( !error_monitor_done )
18559 33 mihad
            disable error_monitor5 ;
18560
    end
18561
    begin:error_monitor5
18562 35 mihad
        error_monitor_done = 0 ;
18563 33 mihad
        @(error_event_int) ;
18564
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18565
        ok_pci = 0 ;
18566 35 mihad
        error_monitor_done = 1 ;
18567 33 mihad
    end
18568
    join
18569
 
18570
    if ( ok_wb && ok_pci )
18571
        test_ok ;
18572
 
18573
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18574
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18575
    if ( temp_val1[8] !== 1'b0 )
18576
    begin
18577
        $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) ;
18578
        test_fail("error shouldn't be reported, when retry counter expires during read through PCI Target unit") ;
18579
    end
18580
 
18581
    test_name = "PCI DEVICE STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING READ" ;
18582
    config_read( pci_device_ctrl_offset, 4'hF, temp_val1 ) ;
18583
    if ( temp_val1[25] !== 1'b1 )
18584
    begin
18585
        $display("WISHBONE Master Retry Counter expiration test failed! Signaled Target Abort bit not set when PCI Target terminated with target abort! Time %t", $time) ;
18586
        test_fail("Signaled Target Abort bit was not set when PCI Target terminated with target abort") ;
18587
    end
18588
 
18589
    config_write( pci_device_ctrl_offset, temp_val1, 4'hF, ok ) ;
18590
 
18591
    test_name = "NO RESPONSE COUNTER EXPIRATION DURING WRITE THROUGH PCI TARGET UNIT" ;
18592
    ok_pci = 1 ;
18593
    wishbone_slave.cycle_response(3'b000, tb_subseq_waits, 8'd255);
18594
 
18595
    fork
18596
    begin
18597
        if ( test_mem == 1 )
18598
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18599
                        pci_image_base, 32'hBEAF_DEAD, 4'h0,
18600
                        1, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18601
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18602
        else
18603
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'hBEAF_DEAD, 4'h0, 1, `Test_Target_Normal_Completion) ;
18604
 
18605
        do_pause(1) ;
18606
 
18607
        // do another write with same address and different data
18608
        if ( test_mem == 1 )
18609
            PCIU_MEM_WRITE ("MEM_WRITE ", `Test_Master_1,
18610
                        pci_image_base, 32'h8765_6789, 4'h0,
18611
                        3, `Test_One_Zero_Master_WS, `Test_One_Zero_Target_WS,
18612
                        `Test_Devsel_Medium, `Test_Target_Normal_Completion);
18613
        else
18614
            PCIU_IO_WRITE( `Test_Master_1, pci_image_base, 32'h8765_6789, 4'h0, 1, `Test_Target_Normal_Completion) ;
18615
 
18616
        do_pause(1) ;
18617
    end
18618
    begin
18619
        wb_transaction_progress_monitor( pci_image_base, 1'b1, 0, 1'b1, ok_wb ) ;
18620
        if ( ok_wb !== 1 )
18621
        begin
18622
            $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) ;
18623
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18624
            disable main ;
18625
        end
18626
 
18627
        wishbone_slave.cycle_response(3'b100, tb_subseq_waits, 8'd255);
18628
 
18629
        if ( test_mem )
18630
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 3, 1'b1, ok_wb ) ;
18631
        else
18632
            wb_transaction_progress_monitor( pci_image_base, 1'b1, 1, 1'b1, ok_wb ) ;
18633
 
18634
        if ( ok_wb !== 1 )
18635
        begin
18636
            $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) ;
18637
            test_fail("WB transaction progress monitor detected invalid transaction or none at all on WB bus") ;
18638
            disable main ;
18639
        end
18640
 
18641 35 mihad
        #1 ;
18642
        if ( !error_monitor_done )
18643 33 mihad
            disable error_monitor6 ;
18644
    end
18645
    begin:error_monitor6
18646 35 mihad
        error_monitor_done = 0 ;
18647 33 mihad
        @(error_event_int) ;
18648
        test_fail("PCI behavioral master or PCI monitor detected error on PCI bus") ;
18649
        ok_pci = 0 ;
18650 35 mihad
        error_monitor_done = 1 ;
18651 33 mihad
    end
18652
    join
18653
 
18654
    $display("PCIU monitor (WB bus) should NOT complain any more!") ;
18655
    $fdisplay(pciu_mon_log_file_desc,
18656
    "********************************************  Monitor should NOT complain any more  ********************************************************************************************************************") ;
18657
 
18658
    test_name = "ERROR STATUS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED DURING TARGET WRITE" ;
18659
    config_read( pci_err_cs_offset, 4'hF, temp_val1 ) ;
18660
    if ( temp_val1[8] !== 1'b1 )
18661
    begin
18662
        $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) ;
18663
        test_fail("error wasn't reported, when no response counter expired during posted write through PCI Target unit") ;
18664
    end
18665
 
18666
    if ( temp_val1[9] !== 0 )
18667
    begin
18668
        $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) ;
18669
        test_fail("error source bit was set, when no response counter expired during posted write through PCI Target unit") ;
18670
    end
18671
 
18672
    if ( temp_val1[10] !== 1 )
18673
    begin
18674
        $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) ;
18675
        test_fail("retry expired bit wasn't set, when no response counter expired during posted write through PCI Target unit") ;
18676
    end
18677
 
18678
    if ( temp_val1[27:24] !== (test_mem ? `BC_MEM_WRITE : `BC_IO_WRITE) )
18679
    begin
18680
        $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) ;
18681
        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") ;
18682
    end
18683
 
18684
    if ( temp_val1[31:28] !== 4'h0 )
18685
    begin
18686
        $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) ;
18687
        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") ;
18688
    end
18689
 
18690
    // clear error status register
18691
    config_write( pci_err_cs_offset, temp_val1, 4'h2, ok ) ;
18692
 
18693
    test_name = "ERROR ADDRESS REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18694
    config_read( pci_err_cs_offset + 4, 4'hF, temp_val1 ) ;
18695
    if ( temp_val1 !== pci_image_base )
18696
    begin
18697
        $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) ;
18698
        test_fail("value in error address register was wrong when no response counter expired during posted write through PCI Target unit") ;
18699
    end
18700
 
18701
    test_name = "ERROR DATA REGISTER VALUE CHECK AFTER NO RESPONSE COUNTER EXPIRED" ;
18702
    config_read( pci_err_cs_offset + 8, 4'hF, temp_val1 ) ;
18703
    if ( temp_val1 !== 32'hBEAF_DEAD )
18704
    begin
18705
        $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) ;
18706
        test_fail("value in error data register was wrong when no response counter expired during posted write through PCI Target unit") ;
18707
    end
18708
 
18709
    // disable current image - write address mask register
18710 45 mihad
    config_write( pci_am_offset, 32'h0000_0000, 4'hF, ok ) ;
18711 15 mihad
end
18712 57 mihad
endtask // target_completion_expiration
18713 15 mihad
 
18714 57 mihad
task master_completion_expiration ;
18715
    reg   [11:0] ctrl_offset ;
18716
    reg   [11:0] ba_offset ;
18717
    reg   [11:0] am_offset ;
18718
    reg `WRITE_STIM_TYPE write_data ;
18719
    reg `READ_STIM_TYPE  read_data ;
18720
    reg `READ_RETURN_TYPE read_status ;
18721
 
18722
    reg `WRITE_RETURN_TYPE write_status ;
18723
    reg `WB_TRANSFER_FLAGS write_flags ;
18724
    reg        ok   ;
18725
    reg [11:0] pci_ctrl_offset ;
18726
    reg [31:0] image_base ;
18727
    reg [31:0] target_address ;
18728
begin:main
18729
    pci_ctrl_offset = 12'h4 ;
18730
    ctrl_offset = {4'h1, `W_IMG_CTRL1_ADDR, 2'b00} ;
18731
    ba_offset   = {4'h1, `W_BA1_ADDR, 2'b00} ;
18732
    am_offset   = {4'h1, `W_AM1_ADDR, 2'b00} ;
18733
    test_name   = "MASTER DELAYED COMPLETION EXPIRATION" ;
18734
 
18735
    target_address  = `BEH_TAR1_MEM_START ;
18736
    image_base      = 0 ;
18737
    image_base[`PCI_BASE_ADDR0_MATCH_RANGE] = target_address[`PCI_BASE_ADDR0_MATCH_RANGE] ;
18738
 
18739
    target_address[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] = image_base[31:(32 - `WB_NUM_OF_DEC_ADDR_LINES)] ;
18740
    target_address[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0]  = image_base[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] ;
18741
    write_flags                      = 0 ;
18742
    write_flags`INIT_WAITS           = tb_init_waits ;
18743
    write_flags`SUBSEQ_WAITS         = tb_subseq_waits ;
18744
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18745
 
18746
    // enable master & target operation
18747
    config_write( pci_ctrl_offset, 32'h0000_0007, 4'h1, ok) ;
18748
    if ( ok !== 1 )
18749
    begin
18750
        $display("Completion expiration testing failed! Failed to write PCI Device Control register! Time %t ", $time) ;
18751
        test_fail("write to PCI Device Control register didn't succeede");
18752
        disable main ;
18753
    end
18754
 
18755
    // prepare image control register
18756
    config_write( ctrl_offset, 32'h0000_0000, 4'hF, ok) ;
18757
    if ( ok !== 1 )
18758
    begin
18759
        $display("Completion expiration testing failed! Failed to write W_IMG_CTRL1 register! Time %t ", $time) ;
18760
        test_fail("write to WB Image Control register didn't succeede");
18761
        disable main ;
18762
    end
18763
 
18764
    // prepare base address register
18765
    config_write( ba_offset, image_base, 4'hF, ok ) ;
18766
    if ( ok !== 1 )
18767
    begin
18768
        $display("Completion expiration testing failed! Failed to write W_BA1 register! Time %t ", $time) ;
18769
        test_fail("write to WB Base Address register didn't succeede");
18770
        disable main ;
18771
    end
18772
 
18773
    // write address mask register
18774
    config_write( am_offset, 32'hFFFF_FFFF, 4'hF, ok ) ;
18775
    if ( ok !== 1 )
18776
    begin
18777
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18778
        test_fail("write to WB Address Mask register didn't succeede");
18779
        disable main ;
18780
    end
18781
 
18782
    fork
18783
    begin
18784
        // do not handle retries
18785
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b0 ;
18786
 
18787
        // initiate a read request
18788
        read_data`READ_ADDRESS  = target_address ;
18789
        read_data`READ_SEL      = 4'hF ;
18790
        read_data`READ_TAG_STIM = 0 ;
18791
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18792
        if ((read_status`CYC_ACTUAL_TRANSFER !== 0) || (read_status`CYC_RTY !== 1'b1))
18793
        begin
18794
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18795
            test_fail("PCI bridge didn't process the read as expected - didn't respond with retry");
18796
            disable main ;
18797
        end
18798
 
18799
        // handle retries from now on
18800
        write_flags`WB_TRANSFER_AUTO_RTY = 1'b1 ;
18801
 
18802
        write_data`WRITE_ADDRESS = target_address + 4 ;
18803
        write_data`WRITE_DATA    = 32'hF0F0_0F0F ;
18804
        write_data`WRITE_SEL     = 4'hF ;
18805
 
18806
        wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18807
        if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18808
        begin
18809
            $display("Completion expiration testing failed! Bridge failed to process single memory write! Time %t ", $time) ;
18810
            test_fail("WB Slave state machine failed to post single memory write");
18811
            disable main ;
18812
        end
18813
 
18814
        // completion is present if wbr fifo for sure, since write proceeded ok, wait for completion to almost expire - 2^^16 cycles - 100
18815
        repeat('h1_0000 - 100)
18816
            @(posedge wb_clock) ;
18817
 
18818
        // now perform a read
18819
        read_data`READ_ADDRESS  = target_address + 4 ;
18820
        read_data`READ_SEL      = 4'hF ;
18821
        read_data`READ_TAG_STIM = 0 ;
18822
        wishbone_master.wb_single_read( read_data, write_flags, read_status ) ;
18823
        if (read_status`CYC_ACTUAL_TRANSFER !== 1)
18824
        begin
18825
            $display("Completion expiration testing failed! Bridge failed to process single memory read! Time %t ", $time) ;
18826
            test_fail("PCI bridge didn't process the read as expected");
18827
            disable main ;
18828
        end
18829
 
18830
        if (read_status`READ_DATA !== write_data`WRITE_DATA)
18831
        begin
18832
            display_warning(target_address + 4, write_data`WRITE_DATA, read_status`READ_DATA) ;
18833
            test_fail("PCI bridge returned unexpected Read Data");
18834
        end
18835
        else if (ok === 1'b1)
18836
            test_ok ;
18837
    end
18838
    begin:monitors
18839
        // monitor first read, which will expire
18840
        pci_transaction_progress_monitor
18841
        (
18842
            target_address, // expected address
18843
            `BC_MEM_READ,   // expected bus command
18844
            1,              // expected number of transfers
18845
            0,              // expected number of cycles
18846
            1,              // check number of transfers true/false
18847
            0,              // check number of cycles true/false
18848
            0,              // is this fast B2B true/false
18849
            ok              // return 1 if as expected, anything else on error
18850
        ) ;
18851
 
18852
        if ( ok !== 1 )
18853
        begin
18854
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18855
            #1 disable monitors ;
18856
        end
18857
 
18858
        // monitor normal single write
18859
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_WRITE, 1, 0, 1, 0, 0, ok ) ;
18860
        if ( ok !== 1 )
18861
        begin
18862
            test_fail("because single memory write from WB to PCI didn't engage expected transaction on PCI bus") ;
18863
            #1 disable monitors ;
18864
        end
18865
 
18866
        // wait for 2^^16 cycles, so monitor won't complain about waiting too long
18867
        repeat('h1_0000 - 50)
18868
            @(posedge wb_clock) ;
18869
 
18870
        // monitor normal single memory read
18871
        pci_transaction_progress_monitor( target_address + 4, `BC_MEM_READ, 1, 0, 1, 0, 0, ok ) ;
18872
        if ( ok !== 1 )
18873
        begin
18874
            test_fail("because single memory read from WB to PCI didn't engage expected transaction on PCI bus") ;
18875
        end
18876
    end
18877
    join
18878
 
18879
    // disable the image
18880
    config_write( am_offset, 32'h0000_0000, 4'hF, ok ) ;
18881
    if ( ok !== 1 )
18882
    begin
18883
        $display("Completion expiration testing failed! Failed to write W_AM1 register! Time %t ", $time) ;
18884
        test_fail("write to WB Address Mask register didn't succeede");
18885
    end
18886
end
18887
endtask // master_completion_expiration
18888
 
18889 15 mihad
task config_write ;
18890
    input [11:0] offset ;
18891
    input [31:0] data ;
18892
    input [3:0]  byte_enable ;
18893
    output       ok ;
18894
    `ifdef HOST
18895
    reg   `WRITE_STIM_TYPE   write_data ;
18896
    reg   `WB_TRANSFER_FLAGS write_flags ;
18897
    reg   `WRITE_RETURN_TYPE write_status ;
18898
    `else
18899
    reg   [PCI_BUS_DATA_RANGE:0] pci_address;
18900
    reg   [PCI_BUS_CBE_RANGE:0]  byte_enables_l; // active LOW
18901
    `endif
18902
    reg in_use ;
18903
    reg [31:0] temp_var ;
18904
begin
18905
    if ( in_use === 1 )
18906
    begin
18907
        $display("config_read task re-entered! Time %t ", $time) ;
18908
        ok = 0 ;
18909
        #20 $stop ;
18910
    end
18911
    else
18912
    begin
18913
        ok = 1 ;
18914
        in_use = 1 ;
18915
    end
18916
    `ifdef HOST
18917
    write_flags                    = 0 ;
18918
    write_flags`INIT_WAITS         = tb_init_waits ;
18919
    write_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
18920
    write_flags`WB_TRANSFER_AUTO_RTY = 0 ;
18921
 
18922
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
18923
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
18924
    write_data`WRITE_ADDRESS                     = temp_var + offset ;
18925
    write_data`WRITE_SEL                         = byte_enable ;
18926
    write_data`WRITE_TAG_STIM                    = 0 ;
18927
    write_data`WRITE_DATA                        = data ;
18928
 
18929
    wishbone_master.wb_single_write( write_data, write_flags, write_status ) ;
18930
    if ( write_status`CYC_ACTUAL_TRANSFER !== 1 )
18931
    begin
18932
        $display("Write to configuration space failed! Time %t ", $time) ;
18933
        ok = 0 ;
18934
    end
18935
 
18936
    @(posedge wb_clock) ;
18937
    // normal thing to do for software would be to disable master and target operation before doing a configuration write
18938
    // here we just wait for two guest cycles for conf space bits to synchronize
18939
    repeat( 2 )
18940
        @(posedge pci_clock) ;
18941
 
18942
    `else // GUEST
18943
    byte_enables_l = ~byte_enable ;
18944
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
18945
 
18946
    fork
18947
    begin
18948
        DO_REF ("MEM_W_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
18949
              PCI_COMMAND_MEMORY_WRITE, data[PCI_BUS_DATA_RANGE:0],
18950
              byte_enables_l[PCI_BUS_CBE_RANGE:0],
18951
              `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
18952
              8'h0_0, `Test_One_Zero_Target_WS,
18953
              `Test_Devsel_Medium, `Test_No_Fast_B2B,
18954
              `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
18955
    do_pause( 1 ) ;
18956
    end
18957
    begin
18958
        pci_transaction_progress_monitor( pci_address, `BC_MEM_WRITE, 1, 0, 1'b1, 1'b0, 0, ok ) ;
18959
        @(posedge pci_clock) ;
18960
    end
18961
    join
18962
 
18963
     repeat( 2 )
18964
         @(posedge wb_clock) ;
18965
 
18966
    `endif
18967
    in_use = 0 ;
18968
end
18969
endtask // config_write
18970
 
18971
task config_read ;
18972
    input [11:0] offset ;
18973
    input [3:0]  byte_enable ;
18974
    output [31:0] data ;
18975
 
18976
    reg `READ_STIM_TYPE    read_data ;
18977
    reg `WB_TRANSFER_FLAGS read_flags ;
18978
    reg `READ_RETURN_TYPE  read_status ;
18979
 
18980
    reg [31:0] pci_address ;
18981
    reg [3:0] byte_enables_l ;
18982
 
18983
    reg master_check_data_prev ;
18984
    reg in_use ;
18985
    reg [31:0] temp_var ;
18986
begin:main
18987
    if ( in_use === 1 )
18988
    begin
18989
        $display("config_read task re-entered! Time %t ", $time) ;
18990
        data = 32'hxxxx_xxxx ;
18991
        disable main ;
18992
    end
18993
 
18994
    in_use = 1 ;
18995
 
18996
`ifdef HOST
18997 26 mihad
    repeat(4)
18998
        @(posedge pci_clock) ;
18999
    repeat(4)
19000
        @(posedge wb_clock) ;
19001 15 mihad
    read_flags                    = 0 ;
19002
    read_flags`INIT_WAITS         = tb_init_waits ;
19003
    read_flags`SUBSEQ_WAITS       = tb_subseq_waits ;
19004
    read_flags`WB_TRANSFER_AUTO_RTY = 0 ;
19005
 
19006
    temp_var                                     = { `WB_CONFIGURATION_BASE, 12'h000 } ;
19007
    temp_var[(31 - `WB_NUM_OF_DEC_ADDR_LINES):0] = 0 ;
19008
 
19009
    read_data`READ_ADDRESS  = temp_var + offset ;
19010
    read_data`READ_SEL      = byte_enable ;
19011
    read_data`READ_TAG_STIM = 0 ;
19012
 
19013
    wishbone_master.wb_single_read( read_data, read_flags, read_status ) ;
19014
    if (read_status`CYC_ACTUAL_TRANSFER !== 1)
19015
    begin
19016
        $display("Configuration read failed! Bridge failed to process single memory read! Time %t ", $time) ;
19017
        #20 $stop ;
19018
    end
19019
    data = read_status`READ_DATA ;
19020
`else
19021
  `ifdef GUEST
19022 26 mihad
    repeat(4)
19023
        @(posedge wb_clock) ;
19024
    repeat(4)
19025
        @(posedge pci_clock) ;
19026 15 mihad
    master_check_data_prev = master2_check_received_data ;
19027
    master2_check_received_data = 0 ;
19028
 
19029
    byte_enables_l = ~byte_enable ;
19030
    pci_address    = Target_Base_Addr_R[0] | { 20'h0, offset } ;
19031
 
19032
    DO_REF ("MEM_R_CONF", `Test_Master_2, pci_address[PCI_BUS_DATA_RANGE:0],
19033
             PCI_COMMAND_MEMORY_READ, data[PCI_BUS_DATA_RANGE:0],
19034
             byte_enables_l[PCI_BUS_CBE_RANGE:0],
19035
             `Test_One_Word, `Test_No_Addr_Perr, `Test_No_Data_Perr,
19036
             8'h4_0, `Test_One_Zero_Target_WS,
19037
             `Test_Devsel_Medium, `Test_No_Fast_B2B,
19038
             `Test_Target_Normal_Completion, `Test_Expect_No_Master_Abort);
19039
    do_pause( 1 ) ;
19040
 
19041
    @(master2_received_data_valid) ;
19042
    data = master2_received_data ;
19043
 
19044
    master2_check_received_data = master_check_data_prev ;
19045
  `endif
19046
`endif
19047
    in_use = 0 ;
19048
end
19049
endtask //config_read
19050
 
19051 62 mihad
`ifdef PCI_BIST
19052
`ifdef WB_RAM_DONT_SHARE
19053
    `ifdef PCI_RAM_DONT_SHARE
19054
        parameter bist_chain_length = 8 ;
19055
    `else
19056
        parameter bist_chain_length = 6 ;
19057
    `endif
19058
`else
19059
    `ifdef PCI_RAM_DONT_SHARE
19060
        bist_chain_length = 6 ;
19061
    `else
19062
        bist_chain_length = 4 ;
19063
    `endif
19064
`endif
19065
 
19066
task run_bist_test ;
19067
    reg [(bist_chain_length - 1):0] bist_result_vector ;
19068
    integer count ;
19069
    integer deadlock_count ;
19070
begin
19071
 
19072
    test_name = "BIST FOR RAMS RUN" ;
19073
 
19074
    SI          = 0 ;
19075
    shift_DR    = 0 ;
19076
    capture_DR  = 0 ;
19077
    extest      = 0 ;
19078
    tck         = 0 ;
19079
 
19080
    fork
19081
    begin
19082
        repeat(2)
19083
            @(posedge wb_clock) ;
19084
    end
19085
    begin
19086
        repeat(2)
19087
            @(posedge pci_clock) ;
19088
    end
19089
    join
19090
 
19091
    // test is run with forcing extest high
19092
    extest <= 1'b1 ;
19093
 
19094
    bist_result_vector = 0 ;
19095
 
19096
    // result vector must be all 1s, because in RTL there cannot be a reason for BIST to fail
19097
    fork
19098
    begin:scan
19099
        while (bist_result_vector !== {bist_chain_length{1'b1}})
19100
        begin
19101
            @(negedge tck) ;
19102
            capture_DR <= #1 1'b1 ;
19103
            @(negedge tck) ;
19104
            capture_DR <= #1 1'b0 ;
19105
            shift_DR   <= #1 1'b1 ;
19106
            for (count = 0 ; count < bist_chain_length ; count = count + 1'b1)
19107
            begin
19108
                @(negedge tck) ;
19109
                bist_result_vector[count] = SO ;
19110
            end
19111
 
19112
            shift_DR <= #1 1'b0 ;
19113
        end
19114
        #1 disable deadlock ;
19115
        @(negedge tck) ;
19116
        extest <= #1 1'b0 ;
19117
        #1 ;
19118
        disable tck_gen ;
19119
        test_ok ;
19120
    end
19121
    begin:deadlock
19122
        for (deadlock_count = 0; deadlock_count <= 100000; deadlock_count = deadlock_count + 1'b1)
19123
        begin
19124
            @(posedge pci_clock) ;
19125
            @(posedge wb_clock) ;
19126
        end
19127
 
19128
        test_fail("BIST Test didn't finish as expected") ;
19129
        extest <= #1 1'b0 ;
19130
        disable scan ;
19131
        @(negedge tck) ;
19132
        #1 ;
19133
        disable tck_gen ;
19134
    end
19135
    begin:tck_gen
19136
        forever
19137
            #50 tck = !tck ;
19138
    end
19139
    join
19140
end
19141
endtask // run_bist_test
19142
`endif
19143
 
19144 15 mihad
task test_fail ;
19145
    input [7999:0] failure_reason ;
19146
    reg   [8007:0] display_failure ;
19147
    reg   [799:0] display_test ;
19148
begin
19149
    tests_failed = tests_failed + 1 ;
19150
 
19151
    display_failure = {failure_reason, "!"} ;
19152
    while ( display_failure[7999:7992] == 0 )
19153
        display_failure = display_failure << 8 ;
19154
 
19155
    display_test = test_name ;
19156
    while ( display_test[799:792] == 0 )
19157
       display_test = display_test << 8 ;
19158
 
19159
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19160
    $fdisplay( tb_log_file, " At time %t ", $time ) ;
19161
    $fdisplay( tb_log_file, " Test %s", display_test ) ;
19162
    $fdisplay( tb_log_file, " *FAILED* because") ;
19163
    $fdisplay( tb_log_file, " %s", display_failure ) ;
19164
    $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19165
    $fdisplay( tb_log_file, " " ) ;
19166
 
19167
    `ifdef STOP_ON_FAILURE
19168
    #20 $stop ;
19169
    `endif
19170
end
19171
endtask // test_fail
19172
 
19173
task test_ok ;
19174
    reg [799:0] display_test ;
19175
begin
19176
   tests_successfull = tests_successfull + 1 ;
19177
 
19178
   display_test = test_name ;
19179
   while ( display_test[799:792] == 0 )
19180
       display_test = display_test << 8 ;
19181
 
19182
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19183
   $fdisplay( tb_log_file, " At time %t ", $time ) ;
19184
   $fdisplay( tb_log_file, " Test %s", display_test ) ;
19185
   $fdisplay( tb_log_file, " reported *SUCCESSFULL*! ") ;
19186
   $fdisplay( tb_log_file, "*****************************************************************************************" ) ;
19187
   $fdisplay( tb_log_file, " " ) ;
19188
end
19189
endtask // test_ok
19190
 
19191
task test_summary;
19192
begin
19193
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19194
    $fdisplay(tb_log_file, "Tests performed:   %d", tests_successfull + tests_failed) ;
19195
    $fdisplay(tb_log_file, "Failed tests   :   %d", tests_failed) ;
19196
    $fdisplay(tb_log_file, "Successfull tests: %d", tests_successfull) ;
19197
    $fdisplay(tb_log_file, "******************************* PCI Testcase summary *******************************") ;
19198
    $fclose(tb_log_file) ;
19199
end
19200
endtask
19201
 
19202
endmodule

powered by: WebSVN 2.1.0

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