summaryrefslogtreecommitdiffstats
path: root/private/ntos/miniport/always/33c93.c
blob: f44dc9fab48c9e1d27d7faef256a113a65f2c6b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
/* Copyright (C) 1991, 1992 by Always Technology Corporation.
   This module contains information proprietary to
   Always Technology Corporation, and is be treated as confidential.
*/

#include "environ.h"
#include "rqm.h"
#include "api.h"
#include "apiscsi.h"
#include "debug.h"

#include "33c93.h"

#define ReadWDReg(HA,WDReg) (outb(HA->Ext->SBIC.WD33C93.WDSelPort, (WDReg)), inb(HA->Ext->SBIC.WD33C93.WDDataPort))

#ifndef ReadWDReg
unsigned const
ReadWDReg (const ADAPTER_PTR HA, const unsigned reg)
{

  outb(HA->Ext->SBIC.WD33C93.WDSelPort, (WDReg));
  return inb(HA->IOBase + INWDDataOff);

}
#endif




U8 REGPARMS
ReadTilStable (ADAPTER_PTR HA, unsigned Reg)
{
  U8 Stat1, Stat2;

  Stat2 = ReadWDReg(HA, Reg);
  do {

    Stat1 = Stat2;
    Stat2 &= ReadWDReg(HA, Reg);
    Stat2 &= ReadWDReg(HA, Reg);

  } while (Stat1 != Stat2);

  return Stat1;

}



// Wait for WD command in progress to complete, then issue a new command:
#define SendWDCmd(WDSelPort, WDDataPort, WDCmd)  {while (inb(WDSelPort) & (WD_Busy | WD_CIP)) ; \
                outb(WDSelPort, WDCMDReg);  outb(WDDataPort, WDCmd); }

#if !defined(SendWDCmd)
void const REGPARMS
SendWDCmd (IOHandle WDSelPort, IOHandle WDDataPort, unsigned WDCmd)
{

  while (inb(WDSelPort) & (WD_Busy | WD_CIP)) ;         // Spin on WD busy

  outb(WDSelPort, WDCMDReg);                            // Select command register
  outb(WDDataPort, WDCmd);                              // Issue command

}
#endif


int REGPARMS
WaitForDataReady (ADAPTER_PTR HA)
{
  unsigned stat;
  unsigned long Spin=100000l;

  while ( ((((stat = inb(HA->Ext->SBIC.WD33C93.WDSelPort)) & WD_DBR) == 0)
           || (stat & WD_CIP) ) && Spin--) {

    if (stat & (IntPending | CommandIGN))
      return -1;

  }

  if ((stat & WD_DBR) == 0)  {			// Fell out of loop because of spin loop exhaustion

    TRACE(0, ("WaitForDataReady(): Spun out waiting for data ready\n"));
    return -1;

  }

  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDDataReg);
  return 0;

}



int REGPARMS
WaitForWrite (const ADAPTER_PTR HA, const U8 Data)
{

  if (WaitForDataReady(HA))
    return -1;
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, Data);
  return 0;

}



int REGPARMS
WaitForRead (const ADAPTER_PTR HA,
             U8 FAR *const Data)
{

  if (WaitForDataReady(HA))
    return -1;
  *Data = inb(HA->Ext->SBIC.WD33C93.WDDataPort);
  return 0;

}



//#define XferInByte(HA,Data) (SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDXferInfo | WDSingleByte),  WaitForRead(HA, Data))
#if !defined(XferInByte)

int REGPARMS
XferInByte (const ADAPTER_PTR HA, U8 FAR *Data)
{

  SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDXferInfo | WDSingleByte);
  return WaitForRead(HA, Data);

}
#endif


//#define XferOutByte(HA,Data) (SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDXferInfo | WDSingleByte),  WaitForWrite(HA, Data))
#if !defined(XferOutByte)

int REGPARMS
XferOutByte (const ADAPTER_PTR HA, const U8 Data)
{

  SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDXferInfo | WDSingleByte);
  return WaitForWrite(HA, Data);

}
#endif



unsigned
PIORead (ADAPTER_PTR const HA,
         U8 FAR *Block,
         unsigned Count)
{
  unsigned i;

  TRACE(5,("in2000: PIORead(): "));

  for (i = 0; i < Count; i++) {
    if (WaitForRead(HA, Block++))
      break;
  }
  TRACE(5, ("%d read bytes\n", i));
  return i;

}



unsigned
PIOWrite (ADAPTER_PTR HA,
          U8 FAR *Block,
          unsigned Count)
{
  unsigned i;

  for (i = 0; i < Count; i++) {
    if (WaitForWrite(HA, *Block++))
      break;
  }
  return i;

}



static
PIOWriteBlk (ADAPTER_PTR HA,
             U8 FAR *Block,
             unsigned Count)
{
  unsigned i;

  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDCountReg);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, 0);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, Count >> 8);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, Count);

  SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDXferInfo); /* Start data xfer */

  for (i = 0; i < Count; i++) {
    if (WaitForWrite(HA, *Block++))
      break;
  }
  return i;
}


void REGPARMS
Abort (ADAPTER_PTR HA)
{

  SCSISendAbort(HA);
  SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDSetAtnCmd); /* Set attention */

}


void
WD33C93_Reset (ADAPTER_PTR HA)
{
  int Divisor;

  /* Set freq devisor & default SCSI ID; must be set before reset */
  if (HA->Ext->SBIC.WD33C93.MHz >= 16)
    Divisor = 4;
  else if (HA->Ext->SBIC.WD33C93.MHz >= 12)
    Divisor = 3;
  else Divisor = 2;

  //IFreq = Internal freq and max xfer rate
  HA->Ext->SBIC.WD33C93.IFreq = HA->Ext->SBIC.WD33C93.MHz / Divisor;
  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDOwnIDReg);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, (((Divisor - 2) & 3) << 6) | HA->SCSI_ID);

  critical(HA);

  /* Reset chip, then wait for reset complete interrupt */
  SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDResetCmd);

  while ((ReadTilStable(HA, WDAuxStatReg) & IntPending) == 0)
    ;
  ReadWDReg(HA, WDStatusReg);                           /* Clear the interrupt */

  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDControlReg);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, HaltPE);          // Enable parity checking

  /* Set default selection timeout to 250 ms (x = ms * MHz / 80) */
  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDTimeoutReg);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, ((25*HA->Ext->SBIC.WD33C93.MHz)+7) / 8);

  /* Allow reselections: */
  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDSourceReg);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, EnableRSel);

  uncritical(HA);

}

int
WD33C93_Init (ADAPTER_PTR HA)
{

  WD33C93_Reset(HA);

  /* Sync period in SCSI terms (nS/4) */
  // Rate(Hz) = IFreq.
  // Period(ns) = 1,000,000,000 / Rate(Hz) == 1000/Rate(MHz)
  // SCSI period (Period(ns)/2) == (1000/4)/Rate(MHz)
  HA->Sync_Period = (((HA->Ext->SBIC.WD33C93.MHz >= 16) ? 500 : 1000)/4) / HA->Ext->SBIC.WD33C93.IFreq;
  HA->Sync_Offset = 12;
  TRACE(5, ("WD33C93_Init(): HA Sync. period set to: %d, offset set to %d\n", HA->Sync_Period, HA->Sync_Offset));

  /* This is an 8-bit SCSI bus: */
  HA->Max_TID = 7;
  return 0;

}


// Set a devices adapter specific sync. value
LOCAL void REGPARMS
WD33C93UpdateSync (ADAPTER_PTR HA)
{

  unsigned Cycles;
  unsigned FastSCSI=0;                                  // In case we're FAST SCSI on 33C93B

  /* Magic math: */
  if (HA->Ext->SBIC.WD33C93.MHz >= 16) {                     // Assume > 16MHz is "B" part

    // First calc. the period in nS for the 33C93 SCSI clock:
    if ((unsigned)HA->CurrDev->Sync_Period < (200/4)) {

      TRACE(3, ("WD33C93UpdateSync(): Device is asking for fast SCSI: %d\n", (unsigned)HA->CurrDev->Sync_Period));
      FastSCSI = 0x80;                                  // "B" part, < 200nS xfer period
      Cycles = 2000/(2*HA->Ext->SBIC.WD33C93.MHz);

    } else {

      Cycles = 2000/(HA->Ext->SBIC.WD33C93.MHz);

    }

    TRACE(3, ("WD33C93UpdateSync(): Period/Cycle =%dnS\n", Cycles));

    // Then calc. the SCSI xfer period by the 33C93 internal period for number of cycles:
    Cycles = ((unsigned)HA->CurrDev->Sync_Period * 4) / Cycles;
    TRACE(3, ("WD33C93UpdateSync(): Cycles/Xfer =%d\n", Cycles));

  } else Cycles = ((unsigned)HA->CurrDev->Sync_Period * (4 * 2) * HA->Ext->SBIC.WD33C93.IFreq + 999) / 1000;

  if (Cycles >= 8)
    Cycles = 0;

  HA->DevInfo[HA->CurrDev->SCSI_ID].HASync1 = ((Cycles & 7)<< 4) | HA->CurrDev->Sync_Offset | FastSCSI;
  outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDSyncReg);
  outb(HA->Ext->SBIC.WD33C93.WDDataPort, HA->DevInfo[HA->CurrDev->SCSI_ID].HASync1);
  TRACE(2, ("WD33C93UpdateSync(): HA Sync period set to: %02x\n", HA->DevInfo[HA->CurrDev->SCSI_ID].HASync1));

}



void REGPARMS
Resel (ADAPTER_PTR HA, U8 MSG)
{

  HA->ReqStarting = 0;                                  // Don't accept starting command

  HA->Ext->SBIC.WD33C93.TID = ReadTilStable(HA, WDSourceReg);

  if ((HA->Ext->SBIC.WD33C93.TID & IDValid)
  && (Reselect(HA, (U8)(HA->Ext->SBIC.WD33C93.TID & 0x7), (U8)(MSG & 0x7), 0) == 0)) {

    if (HA->DevInfo[HA->CurrDev->SCSI_ID].Flags.UseSync) {

      outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDSyncReg);
      outb(HA->Ext->SBIC.WD33C93.WDDataPort, HA->DevInfo[HA->CurrDev->SCSI_ID].HASync1);

    } else {

      outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDSyncReg);
      outb(HA->Ext->SBIC.WD33C93.WDDataPort, HA->Ext->SBIC.WD33C93.AsyncValue);

    }

  } else {

    TRACE(1,("Reselection rejected, TID == %02x, MSG == %02x\n", HA->Ext->SBIC.WD33C93.TID, MSG));
    LogMessage(HA, NILL, HA->Ext->SBIC.WD33C93.TID, MSG, MSG_BAD_RESEL, __LINE__);

    SCSISendReject(HA);
    SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDSetAtnCmd); /* Set attention */

  }
}



static void REGPARMS
HandleMessageByte (ADAPTER_PTR HA)
{
  switch (Receive_Msg(HA, HA->Ext->SBIC.WD33C93.MI_Temp)) {

    case MI_SYNC_RESP:					/* Response from sync req; update values */

      WD33C93UpdateSync(HA);
      break;						/* All done */


    case MI_SYNC_REQ:					/* got sync req; update values, and respond */

      WD33C93UpdateSync(HA);
      // Fall Through !!

    case MI_SEND_MSG:					/* Msg in resulted in message out request: */

      TRACE(4,("WD33C93_ISR(): Send message requested\n"));
      SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort,
		WDSetAtnCmd);				// Have a response msg, set attention
      break;


    case MSG_IDENTIFY:					/* Identify? */

      Resel(HA, HA->Ext->SBIC.WD33C93.MI_Temp);
      break;


    default:

      break;

  }

  SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDNegAckCmd); // Message received, negate ACK to signal acceptance


}



void
WD33c93_ISR (ADAPTER_PTR HA)
{
  /* Remember, when defining automatics that SS may not equal DS, so
     don't use pointers to automatics in ISRs. -- This is only a problem
     in brain dead "real" mode environments.  This is not a problem in
     flat model systems.

     Q: Why is a processor which is limited to 1MB and uses segments in
     "real" mode?  Such a mode should be called "Bogus mode."  A "real"
     processor has none of these characteristics.
  */

  U32 S;
  U8 Stat;

#if defined(KEEP_STATS)
  HA->Ext->SBICInterrupts++;
#endif

  ReadTilStable(HA, WDAuxStatReg);
  Stat = ReadWDReg(HA, WDStatusReg);

  TRACE(4,("WD33c93_ISR(): WD status = %02x\n", Stat));
  if (Stat == 0xff)
    return;

  if (HA->Ext->SBIC.WD33C93.State & WD_BLOCK_XFER) {

    HA->Service(HA_DATA_CMPLT, HA, (U32)0);
    HA->Ext->SBIC.WD33C93.State &= ~WD_BLOCK_XFER;

  }



  /* See if this is a new bus phase interrupt (bit 0x08 set).  If so,
     mask off the most sig. nibble, and case on the new phase: */
  if (Stat & 0x08)
    Stat &= WD_PHASE_MASK;

  switch (Stat) {

  case WD_STAT_RESET:                                   /* Chip has reset; Who did that??? */
  case WD_STAT_RESETA:

    TRACE(1, ("33c93_ISR(): Bus reset detected\n"));
    HA->ReqStarting = 0;
    WD33C93_Reset(HA);
    SCSIBusHasReset(HA);
    break;


  /*
    The following are the bus phase changes;  The most significant
    nibble is masked off, since we are only interested in the new
    bus phase.
  */

  case WD_MDATA_OUT:                                    // Data out phase
  case WD_MDATA_IN:                                     // Data in phase

    if (HA->ReqCurrentCount == 0) {

      GetXferSegment(HA, HA->CurrReq, &HA->SGDescr, HA->ReqCurrentIndex, FALSE);
      HA->ReqCurrentCount = HA->SGDescr.SegmentLength;

    }


#if defined(COMPOUND_CMD)
    // If we are using compound commands, the only way we can leave compound mode is by a message interrupt, or a data interrupt
    HA->Ext->SBIC.WD33C93.State &= ~WD_COMPOUND_CMD;
#endif

    if ( (((Stat & 1) != 0) && !ReqDataIn(HA->CurrReq))	// Phase is in, no req data
    ||   (((Stat & 1) == 0) && !ReqDataOut(HA->CurrReq)) // Phase is out, no req data
#if defined(ReqNoData)
    ||   ReqNoData(HA->CurrReq)				// Req. wants no data
#endif
    ||   HA->ReqCurrentCount == 0) {		// No data left

      TRACE(0,("WD33C93_ISR(): Data xfer pad: flags = %x, CurrCount = %d, direction = %s\n", ReqFlags(HA->CurrReq), HA->ReqCurrentCount, ((Stat & 1) ? "In" : "Out") ));
//      BreakPoint(HA);

      ReqAPIStatus(HA->CurrReq) = S_REQ_OVERRUN;
      /* Do a single byte xfer pad: */
      if (Stat & 1)
        XferInByte(HA,  (U8 FAR *)&Stat);
      else
        XferOutByte(HA, (U8)Stat);
      break;

    }

    TRACE(3,("WD33C93_ISR(): Data xfer of %ld bytes started\n", HA->ReqCurrentCount));

#if defined(NATIVE32)

    /* Set the XFER count register: */
    outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDCountReg);
    outb(HA->Ext->SBIC.WD33C93.WDDataPort, (U8)(HA->ReqCurrentCount / (long)0x10000));
    outb(HA->Ext->SBIC.WD33C93.WDDataPort, (U8)(HA->ReqCurrentCount / (long)0x100));
    outb(HA->Ext->SBIC.WD33C93.WDDataPort, (U8)HA->ReqCurrentCount);

#else

    /* Set the XFER count register: */
    outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDCountReg);
    outb(HA->Ext->SBIC.WD33C93.WDDataPort, (((U8 FAR *)&HA->ReqCurrentCount)[2]));
    outb(HA->Ext->SBIC.WD33C93.WDDataPort, (((U8 FAR *)&HA->ReqCurrentCount)[1]));
    outb(HA->Ext->SBIC.WD33C93.WDDataPort, (((U8 FAR *)&HA->ReqCurrentCount)[0]));

#endif

    HA->State.DataIn = (Stat & 1);                      /* Data in or out */
    S = HA->Service(HA_DATA_SETUP, HA, (U32)(Stat & 1));

    /* Start the data transfer */
    SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDXferInfo);

    if (S == HAServiceResponse_UseByteIO) {

      S = (Stat & 1) ?
        PIORead(HA,
		(U8 FAR *)&(((U8 FAR *)(ReqDataPtr(HA->CurrReq)))[(unsigned)HA->ReqCurrentIndex]),
		(unsigned)HA->ReqCurrentCount)
      : PIOWrite(HA,
		 (U8 FAR *)&(((U8 FAR *)(ReqDataPtr(HA->CurrReq)))[(unsigned)HA->ReqCurrentIndex]),
		 (unsigned)HA->ReqCurrentCount);
      HA->ReqCurrentIndex += S;
      HA->ReqCurrentCount -= S;
      TRACE(4,("WD33C93_ISR(): Xfer of %d bytes complete\n", S));

    } else {

      HA->State.DataXfer = 1;
      HA->Ext->SBIC.WD33C93.State |= WD_BLOCK_XFER;

    }
    break;


  case WD_MCOMMAND:                                     /* Command phase */

    TRACE(3,("WD33C93_ISR(): command phase\n"));

    if (HA->DevInfo[HA->CurrDev->SCSI_ID].Flags.UseSync) { // Sync. xfer been established?

      outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDSyncReg);
      outb(HA->Ext->SBIC.WD33C93.WDDataPort, HA->DevInfo[HA->CurrDev->SCSI_ID].HASync1);

    } else {

      outb(HA->Ext->SBIC.WD33C93.WDSelPort, WDSyncReg);
      outb(HA->Ext->SBIC.WD33C93.WDDataPort, HA->Ext->SBIC.WD33C93.AsyncValue);

    }

    PIOWriteBlk(HA, ReqCDB(HA->CurrReq), ReqCDBLen(HA->CurrReq));
    break;



  case WD_STAT_BAD_STATUS:                              /* Status phase w/ parity */

    TRACE(2, ("WD33C93_ISR(): Parity error detected\n"));
    SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDSetAtnCmd);
    HA->Ext->MO_Buff[HA->Ext->MO_Count++] = MSG_INIT_ERROR;
    SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDNegAckCmd);
    LogMessage(HA, HA->CurrReq, HA->CurrDev->SCSI_ID, 0, MSG_PARITY, __LINE__);
    // Fall through

  case WD_MSTATUS:                                      /* status phase */

    XferInByte(HA, (U8 FAR *)&Stat);
    if (ReqAPIStatus(HA->CurrReq) == S_REQ_STARTED || ReqAPIStatus(HA->CurrReq) == S_REQ_ACCEPTED)
      ReqAPIStatus(HA->CurrReq) = TargetStatus(Stat);

    // Update the saved index to reflect the number of bytes actually
    // transfered:
    ReqSavedIndex(HA->CurrReq) = HA->ReqCurrentIndex;

    TRACE(3, ("WD33C93_ISR(): status phase %02x\n", Stat));
    break;


  /*
    A disconnect will occur either as an intermediate disconnect,
    followed by a later reselect, or it happens after command
    completion.  If there is a request in progress, then a later
    reselect is expected.

    After cleaning up as necessary, the first request for the next
    pending target is initiated.
  */
  case WD_MMSG_OUT:                                     // Message out phase

    TRACE(4,("MsgOutP: sending message %02x\n", HA->Ext->MO_Buff[HA->Ext->MO_Index]));

    if (HA->Ext->MO_Count)  {                                // Any messages waiting?

      PIOWriteBlk(HA, HA->Ext->MO_Buff, HA->Ext->MO_Count);       // Then send them

    } else
      XferOutByte(HA, MSG_NOP);                         // Otherwise, send a no-op

    HA->Ext->MO_Index = HA->Ext->MO_Count = 0;                    // Reset the Message Out counters

#if defined(COMPOUND_CMD)
    // If we are using compound commands, the only way we can leave compound mode is by a message interrupt, or a data interrupt
    HA->Ext->SBIC.WD33C93.State &= ~WD_COMPOUND_CMD;
#endif

    break;



  case WD_MMSG_IN:                                      /* Message in phase */

    if (XferInByte(HA, &HA->Ext->SBIC.WD33C93.MI_Temp))      // Read the message byte
      TRACE(3,("WD33C93_ISR(): WD_MSG_IN failed: %02x\n", inb(HA->Ext->SBIC.WD33C93.WDSelPort)));
    if (HA->ReqStarting)				// Don't know yet if this message is for the staring request
      HA->ReqStarting++;
    TRACE(3, ("WD33C93_ISR(): Message in phase: %02x\n", HA->Ext->SBIC.WD33C93.MI_Temp));
    /* We should next get a WD_STAT_XFER_PAUSED (0x20) state, process the message there */

#if defined(COMPOUND_CMD)
    // If we are using compound commands, the only way we can leave compound mode is by a message interrupt, or a data interrupt
    HA->Ext->SBIC.WD33C93.State &= ~WD_COMPOUND_CMD;
#endif

    break;



  case WD_STAT_SELECT_CMPLT:                            /* Select complete */

    break;



  /*

    On reselection, get the reselecting target ID.  From there, get
    the first request structure for that ID, and verify that a
    reselection is pending.  If a proper disconnect occured, then
    the disconnected request is the first on the list for that
    target ID.  If reselection is not pending, send an abort to the
    reselecting target If a request was started, but reselection
    occurred out from under it, clear the ReqStarting flag.  If at
    the end of the interrupt, the flag is non-zero, it is
    decremented.  If the flag decrements to zero, the request will
    be flagged as accepted (by incrementing the command pointer).
    If the decrement does not set the flag to zero, then the command
    was just started by the interrupt being processed, so we wait
    for the next interrupt to occur (with the flag set to 1).

  */
  /*

    The select and transfer command has completed, and therefore,
    the request is complete.  Retreive the command status into the
    request structure, de-queue the request, and notify the
    requestor.

  */

  case WD_STAT_SandT_CMPLT:                             // Select and transfer complete

    HA->Ext->SBIC.WD33C93.State |= WD_COMPOUND_CMPLT;
    ReqAPIStatus(HA->CurrReq) = TargetStatus(ReadTilStable(HA, WDTarLUNReg));
    ReqDone(HA, HA->CurrReq);
    break;


  case WD_STAT_SAVE_PTR:				/* Save data pointer */

    TRACE(4, ("WD33C93_ISR(): Saved data pointer status received\n"));
    HA->Ext->SBIC.WD33C93.MI_Temp = MSG_SAVE_PTR;

  /* Fall through */
  case WD_STAT_XFER_PAUSED:				/* Paused w/ ACK (message in) */

    HandleMessageByte(HA);
    break;


  case WD_STAT_BAD_DISC:                                // Unexpected bus free

    ReqAPIStatus(HA->CurrReq) = S_AD_FREE;
    ReqDone(HA, HA->CurrReq);
    BusFree(HA, 2);
    break;


  case WD_STAT_SEL_TO:					/* Select timeout */

    ReqAPIStatus(HA->CurrReq) = S_REQ_NOTAR;		// Target not responding
    ReqDone(HA, HA->CurrReq);
    BusFree(HA, 2);
    break;


  case WD_STAT_RESELECTED:				/* Reselection */

    HA->ReqStarting = 0;				/* Don't accept starting command */
    HA->State.Busy = 1;

    // The actual attachment to a request will be done when we get the
    // identify message
    TRACE(3,("WD33c93_ISR(): Reselect phase\n"));

    do {

      HA->Ext->SBIC.WD33C93.TID = ReadTilStable(HA, WDSourceReg);

    } while ((HA->Ext->SBIC.WD33C93.TID & IDValid) == 0);



    TRACE(3,("WD33c93_ISR(): Reselect, TID = 0x%02x\n", HA->Ext->SBIC.WD33C93.TID));
    break;


  case WD_STAT_RESELECTED_A:				// Advanced mode reselection; unexpected, but has been seen

    HA->ReqStarting = 0;				/* Don't accept starting command */
    HA->State.Busy = 1;

    // The actual attachment to a request will be done when we get the
    // identify message
    TRACE(3,("WD33c93_ISR(): Reselect phase\n"));

    do {

      HA->Ext->SBIC.WD33C93.TID = ReadTilStable(HA, WDSourceReg);

    } while ((HA->Ext->SBIC.WD33C93.TID & IDValid) == 0);

    TRACE(0, ("WD33C93_ISR(): Unusual advanced mode reselect; TID = 0x%02x, LUN = 0x%02x\n", HA->Ext->SBIC.WD33C93.TID, HA->Ext->MI_Buff[0]));
    TRACE(3, ("WD33c93_ISR(): Reselect, TID = 0x%02x\n", HA->Ext->SBIC.WD33C93.TID));

    HA->Ext->SBIC.WD33C93.MI_Temp = ReadWDReg(HA, WDDataReg);
    HandleMessageByte(HA);
    break;


   case WD_STAT_SELECTED:                               /* Selected */
   case WD_STAT_SELECTED_ATN:                           /* Selected w/ATN */

     SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort,
	       HA->Ext->SBIC.WD33C93.WDDataPort,
	       WDDisconnectCmd);			/* disconnect */
     break;


  case WD_STAT_DISCONNECT:                              /* Normal disconnect */

    /*
      If there is no "CurrReq", then the request has been completed through
      normal Status and message phases (Status for completion, message for
      disconnect).

      If the WD "compound" (level II) commands are being used, then the
      disconnect interrupt will ccur with "CurrReq" still set.  In this
      case, it is a normal disconnect, and the status and message bytes
      should be examined here.
    */

    if ((HA->CurrReq == NILL) || ((HA->Ext->SBIC.WD33C93.State & WD_COMPOUND_CMD) && (HA->Ext->SBIC.WD33C93.State & WD_COMPOUND_CMPLT))) {

      TRACE(3,("WD33C93_ISR(): Expected disconnect\n"));

    } else {

      if (ErrorClass(ReqAPIStatus(HA->CurrReq)) !=TargetClass) {

                                                        // The request status is not of target class, so we have not seen a status phase
        TRACE(3, ("WD33C93_ISR(): Unexpected disconnect\n"));
        ReqAPIStatus(HA->CurrReq) = S_AD_FREE;                  // Unexpected bus free

      } else {

                                                        // We have seen a status phase, so this is an expected bus free
        TRACE(3,("WD33C93_ISR(): Expected disconnect\n"));

      }

      ReqDone(HA, HA->CurrReq);

    }
    HA->State.Busy = 0;                                 // Mark the adapter as free, to allow new requests to start
    BusFree(HA, 2);
    break;


  case WD_STAT_PARITY:

    SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDSetAtnCmd); /* Set attention */
                                                        // Fall Through

  case WD_STAT_PARITY_ATN:

    TRACE(2, ("WD33C93_ISR(): Parity error detected\n"));
    LogMessage(HA, HA->CurrReq, HA->CurrDev->SCSI_ID, 0, MSG_PARITY, __LINE__);
    HA->Ext->MO_Buff[HA->Ext->MO_Count++] = MSG_INIT_ERROR;
    SendWDCmd(HA->Ext->SBIC.WD33C93.WDSelPort, HA->Ext->SBIC.WD33C93.WDDataPort, WDNegAckCmd);
    break;


  default:

//    LogMessage(HA, HA->CurrReq, 0, 0, MSG_INTERNAL_ERROR, Stat);
    TRACE(0, ("WD33C93_ISR(): Unknown status 0x%02x\n", Stat));
//    BreakPoint(HA);
    HA->Service(HA_RESET_BUS, HA, (U32)0);
    break;

  }
  AcceptReq(HA);
}