- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / scsi / pci2220i.c
blob6b767a1c8db4149d6d0b7c8afcd9f5d009c86adf
1 /****************************************************************************
2 * Perceptive Solutions, Inc. PCI-2220I device driver for Linux.
4 * pci2220i.c - Linux Host Driver for PCI-2220I EIDE RAID Adapters
6 * Copyright (c) 1997-1999 Perceptive Solutions, Inc.
7 * All Rights Reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that redistributions of source
11 * code retain the above copyright notice and this comment without
12 * modification.
14 * Technical updates and product information at:
15 * http://www.psidisk.com
17 * Please send questions, comments, bug reports to:
18 * tech@psidisk.com Technical Support
21 * Revisions 1.10 Mar-26-1999
22 * - Updated driver for RAID and hot reconstruct support.
24 * Revisions 1.11 Mar-26-1999
25 * - Fixed spinlock and PCI configuration.
27 * Revision 2.00 December-1-1999
28 * - Added code for the PCI-2240I controller
29 * - Added code for ATAPI devices.
30 * - Double buffer for scatter/gather support
32 * Revision 2.10 March-27-2000
33 * - Added support for dynamic DMA
35 ****************************************************************************/
37 //#define DEBUG 1
39 #include <linux/module.h>
40 #include <linux/kernel.h>
41 #include <linux/types.h>
42 #include <linux/string.h>
43 #include <linux/malloc.h>
44 #include <linux/pci.h>
45 #include <linux/ioport.h>
46 #include <linux/delay.h>
47 #include <linux/sched.h>
48 #include <linux/proc_fs.h>
49 #include <linux/stat.h>
50 #include <linux/kdev_t.h>
51 #include <linux/blk.h>
52 #include <linux/timer.h>
53 #include <linux/spinlock.h>
54 #include <asm/dma.h>
55 #include <asm/system.h>
56 #include <asm/io.h>
57 #include "scsi.h"
58 #include "hosts.h"
59 #include "pci2220i.h"
60 #include "psi_dale.h"
63 #define PCI2220I_VERSION "2.10"
64 #define READ_CMD IDE_CMD_READ_MULTIPLE
65 #define WRITE_CMD IDE_CMD_WRITE_MULTIPLE
66 #define MAX_BUS_MASTER_BLOCKS SECTORSXFER // This is the maximum we can bus master
68 #ifdef DEBUG
69 #define DEB(x) x
70 #define STOP_HERE() {int st;for(st=0;st<100;st++){st=1;}}
71 #else
72 #define DEB(x)
73 #define STOP_HERE()
74 #endif
76 #define MAXADAPTER 4 // Increase this and the sizes of the arrays below, if you need more.
79 typedef struct
81 UCHAR byte6; // device select register image
82 UCHAR spigot; // spigot number
83 UCHAR spigots[2]; // RAID spigots
84 UCHAR deviceID[2]; // device ID codes
85 USHORT sectors; // number of sectors per track
86 USHORT heads; // number of heads
87 USHORT cylinders; // number of cylinders for this device
88 USHORT spareword; // placeholder
89 ULONG blocks; // number of blocks on device
90 DISK_MIRROR DiskMirror[2]; // RAID status and control
91 ULONG lastsectorlba[2]; // last addressable sector on the drive
92 USHORT raid; // RAID active flag
93 USHORT mirrorRecon;
94 UCHAR reconOn;
95 USHORT reconCount;
96 USHORT reconIsStarting; // indicate hot reconstruct is starting
97 UCHAR cmdDrqInt; // flag for command interrupt
98 UCHAR packet; // command packet size in bytes
99 } OUR_DEVICE, *POUR_DEVICE;
101 typedef struct
103 USHORT bigD; // identity is a PCI-2240I if true, otherwise a PCI-2220I
104 USHORT atapi; // this interface is for ATAPI devices only
105 ULONG regDmaDesc; // address of the DMA discriptor register for direction of transfer
106 ULONG regDmaCmdStat; // Byte #1 of DMA command status register
107 ULONG regDmaAddrPci; // 32 bit register for PCI address of DMA
108 ULONG regDmaAddrLoc; // 32 bit register for local bus address of DMA
109 ULONG regDmaCount; // 32 bit register for DMA transfer count
110 ULONG regDmaMode; // 32 bit register for DMA mode control
111 ULONG regRemap; // 32 bit local space remap
112 ULONG regDesc; // 32 bit local region descriptor
113 ULONG regRange; // 32 bit local range
114 ULONG regIrqControl; // 16 bit Interrupt enable/disable and status
115 ULONG regScratchPad; // scratch pad I/O base address
116 ULONG regBase; // Base I/O register for data space
117 ULONG regData; // data register I/O address
118 ULONG regError; // error register I/O address
119 ULONG regSectCount; // sector count register I/O address
120 ULONG regLba0; // least significant byte of LBA
121 ULONG regLba8; // next least significant byte of LBA
122 ULONG regLba16; // next most significan byte of LBA
123 ULONG regLba24; // head and most 4 significant bits of LBA
124 ULONG regStatCmd; // status on read and command on write register
125 ULONG regStatSel; // board status on read and spigot select on write register
126 ULONG regFail; // fail bits control register
127 ULONG regAltStat; // alternate status and drive control register
128 ULONG basePort; // PLX base I/O port
129 USHORT timingMode; // timing mode currently set for adapter
130 USHORT timingPIO; // TRUE if PIO timing is active
131 struct pci_dev *pcidev;
132 ULONG timingAddress; // address to use on adapter for current timing mode
133 ULONG irqOwned; // owned IRQ or zero if shared
134 UCHAR numberOfDrives; // saved number of drives on this controller
135 UCHAR failRegister; // current inverted data in fail register
136 OUR_DEVICE device[BIGD_MAXDRIVES];
137 DISK_MIRROR *raidData[BIGD_MAXDRIVES];
138 ULONG startSector;
139 USHORT sectorCount;
140 ULONG readCount;
141 UCHAR *currentSgBuffer;
142 ULONG currentSgCount;
143 USHORT nextSg;
144 UCHAR cmd;
145 Scsi_Cmnd *SCpnt;
146 POUR_DEVICE pdev; // current device opearating on
147 USHORT devInReconIndex;
148 USHORT expectingIRQ;
149 USHORT reconOn; // Hot reconstruct is to be done.
150 USHORT reconPhase; // Hot reconstruct operation is in progress.
151 ULONG reconSize;
152 USHORT demoFail; // flag for RAID failure demonstration
153 USHORT survivor;
154 USHORT failinprog;
155 struct timer_list reconTimer;
156 struct timer_list timer;
157 UCHAR *kBuffer;
158 dma_addr_t kBufferDma;
159 UCHAR reqSense;
160 UCHAR atapiCdb[16];
161 UCHAR atapiSpecial;
162 } ADAPTER2220I, *PADAPTER2220I;
164 #define HOSTDATA(host) ((PADAPTER2220I)&host->hostdata)
166 #define RECON_PHASE_READY 0x01
167 #define RECON_PHASE_COPY 0x02
168 #define RECON_PHASE_UPDATE 0x03
169 #define RECON_PHASE_LAST 0x04
170 #define RECON_PHASE_END 0x07
171 #define RECON_PHASE_MARKING 0x80
172 #define RECON_PHASE_FAILOVER 0xFF
174 static struct Scsi_Host *PsiHost[MAXADAPTER] = {NULL,}; // One for each adapter
175 static int NumAdapters = 0;
176 static int Installed = 0;
177 static SETUP DaleSetup;
178 static DISK_MIRROR DiskMirror[BIGD_MAXDRIVES];
179 static ULONG ModeArray[] = {DALE_DATA_MODE2, DALE_DATA_MODE3, DALE_DATA_MODE4, DALE_DATA_MODE5};
180 static ULONG ModeArray2[] = {BIGD_DATA_MODE2, BIGD_DATA_MODE3, BIGD_DATA_MODE4, BIGD_DATA_MODE5};
182 static void ReconTimerExpiry (unsigned long data);
184 /*******************************************************************************************************
185 * Name: Alarm
187 * Description: Sound the for the given device
189 * Parameters: padapter - Pointer adapter data structure.
190 * device - Device number.
192 * Returns: Nothing.
194 ******************************************************************************************************/
195 static void Alarm (PADAPTER2220I padapter, UCHAR device)
197 UCHAR zc;
199 if ( padapter->bigD )
201 zc = device | (FAIL_ANY | FAIL_AUDIBLE);
202 if ( padapter->failRegister & FAIL_ANY )
203 zc |= FAIL_MULTIPLE;
205 padapter->failRegister = zc;
206 outb_p (~zc, padapter->regFail);
208 else
209 outb_p (0x3C | (1 << device), padapter->regFail); // sound alarm and set fail light
211 /****************************************************************
212 * Name: MuteAlarm :LOCAL
214 * Description: Mute the audible alarm.
216 * Parameters: padapter - Pointer adapter data structure.
218 * Returns: TRUE if drive does not assert DRQ in time.
220 ****************************************************************/
221 static void MuteAlarm (PADAPTER2220I padapter)
223 UCHAR old;
225 if ( padapter->bigD )
227 padapter->failRegister &= ~FAIL_AUDIBLE;
228 outb_p (~padapter->failRegister, padapter->regFail);
230 else
232 old = (inb_p (padapter->regStatSel) >> 3) | (inb_p (padapter->regStatSel) & 0x83);
233 outb_p (old | 0x40, padapter->regFail);
236 /****************************************************************
237 * Name: WaitReady :LOCAL
239 * Description: Wait for device ready.
241 * Parameters: padapter - Pointer adapter data structure.
243 * Returns: TRUE if drive does not assert DRQ in time.
245 ****************************************************************/
246 static int WaitReady (PADAPTER2220I padapter)
248 ULONG z;
249 UCHAR status;
251 for ( z = 0; z < (TIMEOUT_READY * 4); z++ )
253 status = inb_p (padapter->regStatCmd);
254 if ( (status & (IDE_STATUS_DRDY | IDE_STATUS_BUSY)) == IDE_STATUS_DRDY )
255 return 0;
256 udelay (250);
258 return status;
260 /****************************************************************
261 * Name: WaitReadyReset :LOCAL
263 * Description: Wait for device ready.
265 * Parameters: padapter - Pointer adapter data structure.
267 * Returns: TRUE if drive does not assert DRQ in time.
269 ****************************************************************/
270 static int WaitReadyReset (PADAPTER2220I padapter)
272 ULONG z;
273 UCHAR status;
275 for ( z = 0; z < (125 * 16); z++ ) // wait up to 1/4 second
277 status = inb_p (padapter->regStatCmd);
278 if ( (status & (IDE_STATUS_DRDY | IDE_STATUS_BUSY)) == IDE_STATUS_DRDY )
280 DEB (printk ("\nPCI2220I: Reset took %ld mSec to be ready", z / 8));
281 return 0;
283 udelay (125);
285 DEB (printk ("\nPCI2220I: Reset took more than 2 Seconds to come ready, Disk Failure"));
286 return status;
288 /****************************************************************
289 * Name: WaitDrq :LOCAL
291 * Description: Wait for device ready for data transfer.
293 * Parameters: padapter - Pointer adapter data structure.
295 * Returns: TRUE if drive does not assert DRQ in time.
297 ****************************************************************/
298 static int WaitDrq (PADAPTER2220I padapter)
300 ULONG z;
301 UCHAR status;
303 for ( z = 0; z < (TIMEOUT_DRQ * 4); z++ )
305 status = inb_p (padapter->regStatCmd);
306 if ( status & IDE_STATUS_DRQ )
307 return 0;
308 udelay (250);
310 return status;
312 /****************************************************************
313 * Name: AtapiWaitReady :LOCAL
315 * Description: Wait for device busy and DRQ to be cleared.
317 * Parameters: padapter - Pointer adapter data structure.
318 * msec - Number of milliseconds to wait.
320 * Returns: TRUE if drive does not clear busy in time.
322 ****************************************************************/
323 static int AtapiWaitReady (PADAPTER2220I padapter, int msec)
325 int z;
327 for ( z = 0; z < (msec * 16); z++ )
329 if ( !(inb_p (padapter->regStatCmd) & (IDE_STATUS_BUSY | IDE_STATUS_DRQ)) )
330 return FALSE;
331 udelay (125);
333 return TRUE;
335 /****************************************************************
336 * Name: AtapiWaitDrq :LOCAL
338 * Description: Wait for device ready for data transfer.
340 * Parameters: padapter - Pointer adapter data structure.
341 * msec - Number of milliseconds to wait.
343 * Returns: TRUE if drive does not assert DRQ in time.
345 ****************************************************************/
346 static int AtapiWaitDrq (PADAPTER2220I padapter, int msec)
348 ULONG z;
350 for ( z = 0; z < (msec * 16); z++ )
352 if ( inb_p (padapter->regStatCmd) & IDE_STATUS_DRQ )
353 return 0;
354 udelay (128);
356 return TRUE;
358 /****************************************************************
359 * Name: HardReset :LOCAL
361 * Description: Wait for device ready for data transfer.
363 * Parameters: padapter - Pointer adapter data structure.
364 * pdev - Pointer to device.
365 * spigot - Spigot number.
367 * Returns: TRUE if drive does not assert DRQ in time.
369 ****************************************************************/
370 static int HardReset (PADAPTER2220I padapter, POUR_DEVICE pdev, UCHAR spigot)
372 DEB (printk ("\npci2220i:RESET spigot = %X devices = %d, %d", spigot, pdev->deviceID[0], pdev->deviceID[1]));
373 udelay (100000); // just wait 100 mSec to let drives flush
374 SelectSpigot (padapter, spigot | SEL_IRQ_OFF);
376 outb_p (0x0E, padapter->regAltStat); // reset the suvivor
377 udelay (100); // wait a little
378 outb_p (0x08, padapter->regAltStat); // clear the reset
379 udelay (100);
381 outb_p (0xA0, padapter->regLba24); // select the master drive
382 if ( WaitReadyReset (padapter) )
384 DEB (printk ("\npci2220i: master not ready after reset"));
385 return TRUE;
387 outb_p (0xB0, padapter->regLba24); // try the slave drive
388 if ( (inb_p (padapter->regStatCmd) & (IDE_STATUS_DRDY | IDE_STATUS_BUSY)) == IDE_STATUS_DRDY )
390 DEB (printk ("\nPCI2220I: initializing slave drive on spigot %X", spigot));
391 outb_p (SECTORSXFER, padapter->regSectCount);
392 WriteCommand (padapter, IDE_CMD_SET_MULTIPLE);
393 if ( WaitReady (padapter) )
395 DEB (printk ("\npci2220i: slave not ready after set multiple"));
396 return TRUE;
400 outb_p (0xA0, padapter->regLba24); // select the drive
401 outb_p (SECTORSXFER, padapter->regSectCount);
402 WriteCommand (padapter, IDE_CMD_SET_MULTIPLE);
403 if ( WaitReady (padapter) )
405 DEB (printk ("\npci2220i: master not ready after set multiple"));
406 return TRUE;
408 return FALSE;
410 /****************************************************************
411 * Name: AtapiReset :LOCAL
413 * Description: Wait for device ready for data transfer.
415 * Parameters: padapter - Pointer adapter data structure.
416 * pdev - Pointer to device.
418 * Returns: TRUE if drive does not come ready.
420 ****************************************************************/
421 static int AtapiReset (PADAPTER2220I padapter, POUR_DEVICE pdev)
423 SelectSpigot (padapter, pdev->spigot);
424 AtapiDevice (padapter, pdev->byte6);
425 AtapiCountLo (padapter, 0);
426 AtapiCountHi (padapter, 0);
427 WriteCommand (padapter, IDE_COMMAND_ATAPI_RESET);
428 udelay (125);
429 if ( AtapiWaitReady (padapter, 1000) )
430 return TRUE;
431 if ( inb_p (padapter->regStatCmd) || (inb_p (padapter->regLba8) != 0x14) || (inb_p (padapter->regLba16) != 0xEB) )
432 return TRUE;
433 return FALSE;
435 /****************************************************************
436 * Name: WalkScatGath :LOCAL
438 * Description: Transfer data to/from scatter/gather buffers.
440 * Parameters: padapter - Pointer adapter data structure.
441 * datain - TRUE if data read.
442 * length - Number of bytes to transfer.
444 * Returns: Nothing.
446 ****************************************************************/
447 static void WalkScatGath (PADAPTER2220I padapter, UCHAR datain, ULONG length)
449 ULONG count;
450 UCHAR *buffer = padapter->kBuffer;
452 while ( length )
454 count = ( length > padapter->currentSgCount ) ? padapter->currentSgCount : length;
456 if ( datain )
457 memcpy (padapter->currentSgBuffer, buffer, count);
458 else
459 memcpy (buffer, padapter->currentSgBuffer, count);
461 padapter->currentSgCount -= count;
462 if ( !padapter->currentSgCount )
464 if ( padapter->nextSg < padapter->SCpnt->use_sg )
466 padapter->currentSgBuffer = ((struct scatterlist *)padapter->SCpnt->request_buffer)[padapter->nextSg].address;
467 padapter->currentSgCount = ((struct scatterlist *)padapter->SCpnt->request_buffer)[padapter->nextSg].length;
468 padapter->nextSg++;
471 else
472 padapter->currentSgBuffer += count;
474 length -= count;
475 buffer += count;
478 /****************************************************************
479 * Name: BusMaster :LOCAL
481 * Description: Do a bus master I/O.
483 * Parameters: padapter - Pointer adapter data structure.
484 * datain - TRUE if data read.
485 * irq - TRUE if bus master interrupt expected.
487 * Returns: Nothing.
489 ****************************************************************/
490 static void BusMaster (PADAPTER2220I padapter, UCHAR datain, UCHAR irq)
492 ULONG zl;
494 zl = ( padapter->sectorCount > MAX_BUS_MASTER_BLOCKS ) ? MAX_BUS_MASTER_BLOCKS : padapter->sectorCount;
495 padapter->sectorCount -= zl;
496 zl *= (ULONG)BYTES_PER_SECTOR;
498 if ( datain )
500 padapter->readCount = zl;
501 outb_p (8, padapter->regDmaDesc); // read operation
502 if ( padapter->bigD )
504 if ( irq && !padapter->sectorCount )
505 outb_p (0x0C, padapter->regDmaMode); // interrupt on
506 else
507 outb_p (0x08, padapter->regDmaMode); // no interrupt
509 else
511 if ( irq && !padapter->sectorCount )
512 outb_p (0x05, padapter->regDmaMode); // interrupt on
513 else
514 outb_p (0x01, padapter->regDmaMode); // no interrupt
517 else
519 outb_p (0x00, padapter->regDmaDesc); // write operation
520 if ( padapter->bigD )
521 outb_p (0x08, padapter->regDmaMode); // no interrupt
522 else
523 outb_p (0x01, padapter->regDmaMode); // no interrupt
524 WalkScatGath (padapter, FALSE, zl);
527 outl (padapter->timingAddress, padapter->regDmaAddrLoc);
528 outl (padapter->kBufferDma, padapter->regDmaAddrPci);
529 outl (zl, padapter->regDmaCount);
530 outb_p (0x03, padapter->regDmaCmdStat); // kick the DMA engine in gear
532 /****************************************************************
533 * Name: AtapiBusMaster :LOCAL
535 * Description: Do a bus master I/O.
537 * Parameters: padapter - Pointer adapter data structure.
538 * datain - TRUE if data read.
539 * length - Number of bytes to transfer.
541 * Returns: Nothing.
543 ****************************************************************/
544 static void AtapiBusMaster (PADAPTER2220I padapter, UCHAR datain, ULONG length)
546 outl (padapter->timingAddress, padapter->regDmaAddrLoc);
547 outl (padapter->kBufferDma, padapter->regDmaAddrPci);
548 outl (length, padapter->regDmaCount);
549 if ( datain )
551 if ( padapter->readCount )
552 WalkScatGath (padapter, TRUE, padapter->readCount);
553 outb_p (0x08, padapter->regDmaDesc); // read operation
554 outb_p (0x08, padapter->regDmaMode); // no interrupt
555 padapter->readCount = length;
557 else
559 outb_p (0x00, padapter->regDmaDesc); // write operation
560 outb_p (0x08, padapter->regDmaMode); // no interrupt
561 if ( !padapter->atapiSpecial )
562 WalkScatGath (padapter, FALSE, length);
564 outb_p (0x03, padapter->regDmaCmdStat); // kick the DMA engine in gear
566 /****************************************************************
567 * Name: WriteData :LOCAL
569 * Description: Write data to device.
571 * Parameters: padapter - Pointer adapter data structure.
573 * Returns: TRUE if drive does not assert DRQ in time.
575 ****************************************************************/
576 static int WriteData (PADAPTER2220I padapter)
578 ULONG zl;
580 if ( !WaitDrq (padapter) )
582 if ( padapter->timingPIO )
584 zl = (padapter->sectorCount > MAX_BUS_MASTER_BLOCKS) ? MAX_BUS_MASTER_BLOCKS : padapter->sectorCount;
585 WalkScatGath (padapter, FALSE, zl * BYTES_PER_SECTOR);
586 outsw (padapter->regData, padapter->kBuffer, zl * (BYTES_PER_SECTOR / 2));
587 padapter->sectorCount -= zl;
589 else
590 BusMaster (padapter, 0, 0);
591 return 0;
593 padapter->cmd = 0; // null out the command byte
594 return 1;
596 /****************************************************************
597 * Name: WriteDataBoth :LOCAL
599 * Description: Write data to device.
601 * Parameters: padapter - Pointer to adapter structure.
602 * pdev - Pointer to device structure
604 * Returns: Index + 1 of drive not failed or zero for OK.
606 ****************************************************************/
607 static int WriteDataBoth (PADAPTER2220I padapter, POUR_DEVICE pdev)
609 ULONG zl;
610 UCHAR status0, status1;
612 SelectSpigot (padapter, pdev->spigots[0]);
613 status0 = WaitDrq (padapter);
614 if ( !status0 )
616 SelectSpigot (padapter, pdev->spigots[1]);
617 status1 = WaitDrq (padapter);
618 if ( !status1 )
620 SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1] | padapter->bigD);
621 if ( padapter->timingPIO )
623 zl = (padapter->sectorCount > MAX_BUS_MASTER_BLOCKS) ? MAX_BUS_MASTER_BLOCKS : padapter->sectorCount;
624 WalkScatGath (padapter, FALSE, zl * BYTES_PER_SECTOR);
625 outsw (padapter->regData, padapter->kBuffer, zl * (BYTES_PER_SECTOR / 2));
626 padapter->sectorCount -= zl;
628 else
629 BusMaster (padapter, 0, 0);
630 return 0;
633 padapter->cmd = 0; // null out the command byte
634 if ( status0 )
635 return 2;
636 return 1;
638 /****************************************************************
639 * Name: IdeCmd :LOCAL
641 * Description: Process an IDE command.
643 * Parameters: padapter - Pointer adapter data structure.
644 * pdev - Pointer to device.
646 * Returns: Zero if no error or status register contents on error.
648 ****************************************************************/
649 static UCHAR IdeCmd (PADAPTER2220I padapter, POUR_DEVICE pdev)
651 UCHAR status;
653 SelectSpigot (padapter, pdev->spigot | padapter->bigD); // select the spigot
654 outb_p (pdev->byte6 | ((UCHAR *)(&padapter->startSector))[3], padapter->regLba24); // select the drive
655 status = WaitReady (padapter);
656 if ( !status )
658 outb_p (padapter->sectorCount, padapter->regSectCount);
659 outb_p (((UCHAR *)(&padapter->startSector))[0], padapter->regLba0);
660 outb_p (((UCHAR *)(&padapter->startSector))[1], padapter->regLba8);
661 outb_p (((UCHAR *)(&padapter->startSector))[2], padapter->regLba16);
662 padapter->expectingIRQ = TRUE;
663 WriteCommand (padapter, padapter->cmd);
664 return 0;
667 padapter->cmd = 0; // null out the command byte
668 return status;
670 /****************************************************************
671 * Name: IdeCmdBoth :LOCAL
673 * Description: Process an IDE command to both drivers.
675 * Parameters: padapter - Pointer adapter data structure.
676 * pdev - Pointer to device structure
678 * Returns: Index + 1 of drive not failed or zero for OK.
680 ****************************************************************/
681 static UCHAR IdeCmdBoth (PADAPTER2220I padapter, POUR_DEVICE pdev)
683 UCHAR status0;
684 UCHAR status1;
686 SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1]); // select the spigots
687 outb_p (padapter->pdev->byte6 | ((UCHAR *)(&padapter->startSector))[3], padapter->regLba24);// select the drive
688 SelectSpigot (padapter, pdev->spigots[0]);
689 status0 = WaitReady (padapter);
690 if ( !status0 )
692 SelectSpigot (padapter, pdev->spigots[1]);
693 status1 = WaitReady (padapter);
694 if ( !status1 )
696 SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1] | padapter->bigD);
697 outb_p (padapter->sectorCount, padapter->regSectCount);
698 outb_p (((UCHAR *)(&padapter->startSector))[0], padapter->regLba0);
699 outb_p (((UCHAR *)(&padapter->startSector))[1], padapter->regLba8);
700 outb_p (((UCHAR *)(&padapter->startSector))[2], padapter->regLba16);
701 padapter->expectingIRQ = TRUE;
702 WriteCommand (padapter, padapter->cmd);
703 return 0;
706 padapter->cmd = 0; // null out the command byte
707 if ( status0 )
708 return 2;
709 return 1;
711 /****************************************************************
712 * Name: OpDone :LOCAL
714 * Description: Complete an operatoin done sequence.
716 * Parameters: padapter - Pointer to host data block.
717 * spigot - Spigot select code.
718 * device - Device byte code.
720 * Returns: Nothing.
722 ****************************************************************/
723 static void OpDone (PADAPTER2220I padapter, ULONG result)
725 Scsi_Cmnd *SCpnt = padapter->SCpnt;
727 if ( padapter->reconPhase )
729 padapter->reconPhase = 0;
730 if ( padapter->SCpnt )
732 Pci2220i_QueueCommand (SCpnt, SCpnt->scsi_done);
734 else
736 if ( padapter->reconOn )
738 ReconTimerExpiry ((unsigned long)padapter);
742 else
744 padapter->cmd = 0;
745 padapter->SCpnt = NULL;
746 padapter->pdev = NULL;
747 SCpnt->result = result;
748 SCpnt->scsi_done (SCpnt);
749 if ( padapter->reconOn && !padapter->reconTimer.data )
751 padapter->reconTimer.expires = jiffies + (HZ / 4); // start in 1/4 second
752 padapter->reconTimer.data = (unsigned long)padapter;
753 add_timer (&padapter->reconTimer);
757 /****************************************************************
758 * Name: InlineIdentify :LOCAL
760 * Description: Do an intline inquiry on a drive.
762 * Parameters: padapter - Pointer to host data block.
763 * spigot - Spigot select code.
764 * device - Device byte code.
766 * Returns: Last addressable sector or zero if none.
768 ****************************************************************/
769 static ULONG InlineIdentify (PADAPTER2220I padapter, UCHAR spigot, UCHAR device)
771 PIDENTIFY_DATA pid = (PIDENTIFY_DATA)padapter->kBuffer;
773 SelectSpigot (padapter, spigot | SEL_IRQ_OFF); // select the spigot
774 outb_p ((device << 4) | 0xA0, padapter->regLba24); // select the drive
775 if ( WaitReady (padapter) )
776 return 0;
777 WriteCommand (padapter, IDE_COMMAND_IDENTIFY);
778 if ( WaitDrq (padapter) )
779 return 0;
780 insw (padapter->regData, padapter->kBuffer, sizeof (IDENTIFY_DATA) >> 1);
781 return (pid->LBATotalSectors - 1);
783 /****************************************************************
784 * Name: AtapiIdentify :LOCAL
786 * Description: Do an intline inquiry on a drive.
788 * Parameters: padapter - Pointer to host data block.
789 * pdev - Pointer to device table.
791 * Returns: TRUE on error.
793 ****************************************************************/
794 static ULONG AtapiIdentify (PADAPTER2220I padapter, POUR_DEVICE pdev)
796 ATAPI_GENERAL_0 ag0;
797 USHORT zs;
798 int z;
800 AtapiDevice (padapter, pdev->byte6);
801 WriteCommand (padapter, IDE_COMMAND_ATAPI_IDENTIFY);
802 if ( AtapiWaitDrq (padapter, 3000) )
803 return TRUE;
805 *(USHORT *)&ag0 = inw_p (padapter->regData);
806 for ( z = 0; z < 255; z++ )
807 zs = inw_p (padapter->regData);
809 if ( ag0.ProtocolType == 2 )
811 if ( ag0.CmdDrqType == 1 )
812 pdev->cmdDrqInt = TRUE;
813 switch ( ag0.CmdPacketSize )
815 case 0:
816 pdev->packet = 6;
817 break;
818 case 1:
819 pdev->packet = 8;
820 break;
821 default:
822 pdev->packet = 6;
823 break;
825 return FALSE;
827 return TRUE;
829 /****************************************************************
830 * Name: Atapi2Scsi
832 * Description: Convert ATAPI data to SCSI data.
834 * Parameters: padapter - Pointer adapter data structure.
835 * SCpnt - Pointer to SCSI command structure.
837 * Returns: Nothing.
839 ****************************************************************/
840 void Atapi2Scsi (PADAPTER2220I padapter, Scsi_Cmnd *SCpnt)
842 UCHAR *buff = padapter->currentSgBuffer;
844 switch ( SCpnt->cmnd[0] )
846 case SCSIOP_MODE_SENSE:
847 buff[0] = padapter->kBuffer[1];
848 buff[1] = padapter->kBuffer[2];
849 buff[2] = padapter->kBuffer[3];
850 buff[3] = padapter->kBuffer[7];
851 memcpy (&buff[4], &padapter->kBuffer[8], padapter->atapiCdb[8] - 8);
852 break;
853 case SCSIOP_INQUIRY:
854 padapter->kBuffer[2] = 2;
855 memcpy (buff, padapter->kBuffer, padapter->currentSgCount);
856 break;
857 default:
858 if ( padapter->readCount )
859 WalkScatGath (padapter, TRUE, padapter->readCount);
860 break;
863 /****************************************************************
864 * Name: Scsi2Atapi
866 * Description: Convert SCSI packet command to Atapi packet command.
868 * Parameters: padapter - Pointer adapter data structure.
869 * SCpnt - Pointer to SCSI command structure.
871 * Returns: Nothing.
873 ****************************************************************/
874 static void Scsi2Atapi (PADAPTER2220I padapter, Scsi_Cmnd *SCpnt)
876 UCHAR *cdb = SCpnt->cmnd;
877 UCHAR *buff = padapter->currentSgBuffer;
879 switch (cdb[0])
881 case SCSIOP_READ6:
882 padapter->atapiCdb[0] = SCSIOP_READ;
883 padapter->atapiCdb[1] = cdb[1] & 0xE0;
884 padapter->atapiCdb[3] = cdb[1] & 0x1F;
885 padapter->atapiCdb[4] = cdb[2];
886 padapter->atapiCdb[5] = cdb[3];
887 padapter->atapiCdb[8] = cdb[4];
888 padapter->atapiCdb[9] = cdb[5];
889 break;
890 case SCSIOP_WRITE6:
891 padapter->atapiCdb[0] = SCSIOP_WRITE;
892 padapter->atapiCdb[1] = cdb[1] & 0xE0;
893 padapter->atapiCdb[3] = cdb[1] & 0x1F;
894 padapter->atapiCdb[4] = cdb[2];
895 padapter->atapiCdb[5] = cdb[3];
896 padapter->atapiCdb[8] = cdb[4];
897 padapter->atapiCdb[9] = cdb[5];
898 break;
899 case SCSIOP_MODE_SENSE:
900 padapter->atapiCdb[0] = SCSIOP_MODE_SENSE10;
901 padapter->atapiCdb[2] = cdb[2];
902 padapter->atapiCdb[8] = cdb[4] + 4;
903 break;
905 case SCSIOP_MODE_SELECT:
906 padapter->atapiSpecial = TRUE;
907 padapter->atapiCdb[0] = SCSIOP_MODE_SELECT10;
908 padapter->atapiCdb[1] = cdb[1] | 0x10;
909 memcpy (padapter->kBuffer, buff, 4);
910 padapter->kBuffer[4] = padapter->kBuffer[5] = 0;
911 padapter->kBuffer[6] = padapter->kBuffer[7] = 0;
912 memcpy (&padapter->kBuffer[8], &buff[4], cdb[4] - 4);
913 padapter->atapiCdb[8] = cdb[4] + 4;
914 break;
917 /****************************************************************
918 * Name: AtapiSendCdb
920 * Description: Send the CDB packet to the device.
922 * Parameters: padapter - Pointer adapter data structure.
923 * pdev - Pointer to device.
924 * cdb - Pointer to 16 byte SCSI cdb.
926 * Returns: Nothing.
928 ****************************************************************/
929 static void AtapiSendCdb (PADAPTER2220I padapter, POUR_DEVICE pdev, CHAR *cdb)
931 DEB (printk ("\nPCI2242I: CDB: %X %X %X %X %X %X %X %X %X %X %X %X", cdb[0], cdb[1], cdb[2], cdb[3], cdb[4], cdb[5], cdb[6], cdb[7], cdb[8], cdb[9], cdb[10], cdb[11]));
932 outsw (padapter->regData, cdb, pdev->packet);
934 /****************************************************************
935 * Name: AtapiRequestSense
937 * Description: Send the CDB packet to the device.
939 * Parameters: padapter - Pointer adapter data structure.
940 * pdev - Pointer to device.
941 * SCpnt - Pointer to SCSI command structure.
942 * pass - If true then this is the second pass to send cdb.
944 * Returns: TRUE on error.
946 ****************************************************************/
947 static int AtapiRequestSense (PADAPTER2220I padapter, POUR_DEVICE pdev, Scsi_Cmnd *SCpnt, UCHAR pass)
949 UCHAR cdb[16] = {SCSIOP_REQUEST_SENSE,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0};
951 DEB (printk ("\nPCI2242I: AUTO REQUEST SENSE"));
952 cdb[4] = (UCHAR)(sizeof (SCpnt->sense_buffer));
953 if ( !pass )
955 padapter->reqSense = TRUE;
956 AtapiCountLo (padapter, cdb[4]);
957 AtapiCountHi (padapter, 0);
958 outb_p (0, padapter->regError);
959 WriteCommand (padapter, IDE_COMMAND_ATAPI_PACKET);
960 if ( pdev->cmdDrqInt )
961 return FALSE;
963 if ( AtapiWaitDrq (padapter, 500) )
964 return TRUE;
966 AtapiSendCdb (padapter, pdev, cdb);
967 return FALSE;
969 /****************************************************************
970 * Name: InlineReadSignature :LOCAL
972 * Description: Do an inline read RAID sigature.
974 * Parameters: padapter - Pointer adapter data structure.
975 * pdev - Pointer to device.
976 * index - index of data to read.
978 * Returns: Zero if no error or status register contents on error.
980 ****************************************************************/
981 static UCHAR InlineReadSignature (PADAPTER2220I padapter, POUR_DEVICE pdev, int index)
983 UCHAR status;
984 ULONG zl = pdev->lastsectorlba[index];
986 SelectSpigot (padapter, pdev->spigots[index] | SEL_IRQ_OFF); // select the spigot without interrupts
987 outb_p (pdev->byte6 | ((UCHAR *)&zl)[3], padapter->regLba24);
988 status = WaitReady (padapter);
989 if ( !status )
991 outb_p (((UCHAR *)&zl)[2], padapter->regLba16);
992 outb_p (((UCHAR *)&zl)[1], padapter->regLba8);
993 outb_p (((UCHAR *)&zl)[0], padapter->regLba0);
994 outb_p (1, padapter->regSectCount);
995 WriteCommand (padapter, IDE_COMMAND_READ);
996 status = WaitDrq (padapter);
997 if ( !status )
999 insw (padapter->regData, padapter->kBuffer, BYTES_PER_SECTOR / 2);
1000 ((ULONG *)(&pdev->DiskMirror[index]))[0] = ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[0];
1001 ((ULONG *)(&pdev->DiskMirror[index]))[1] = ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[1];
1002 // some drives assert DRQ before IRQ so let's make sure we clear the IRQ
1003 WaitReady (padapter);
1004 return 0;
1007 return status;
1009 /****************************************************************
1010 * Name: DecodeError :LOCAL
1012 * Description: Decode and process device errors.
1014 * Parameters: padapter - Pointer to adapter data.
1015 * status - Status register code.
1017 * Returns: The driver status code.
1019 ****************************************************************/
1020 static ULONG DecodeError (PADAPTER2220I padapter, UCHAR status)
1022 UCHAR error;
1024 padapter->expectingIRQ = 0;
1025 if ( status & IDE_STATUS_WRITE_FAULT )
1027 return DID_PARITY << 16;
1029 if ( status & IDE_STATUS_BUSY )
1030 return DID_BUS_BUSY << 16;
1032 error = inb_p (padapter->regError);
1033 DEB(printk ("\npci2220i error register: %x", error));
1034 switch ( error )
1036 case IDE_ERROR_AMNF:
1037 case IDE_ERROR_TKONF:
1038 case IDE_ERROR_ABRT:
1039 case IDE_ERROR_IDFN:
1040 case IDE_ERROR_UNC:
1041 case IDE_ERROR_BBK:
1042 default:
1043 return DID_ERROR << 16;
1045 return DID_ERROR << 16;
1047 /****************************************************************
1048 * Name: StartTimer :LOCAL
1050 * Description: Start the timer.
1052 * Parameters: ipadapter - Pointer adapter data structure.
1054 * Returns: Nothing.
1056 ****************************************************************/
1057 static void StartTimer (PADAPTER2220I padapter)
1059 padapter->timer.expires = jiffies + TIMEOUT_DATA;
1060 add_timer (&padapter->timer);
1062 /****************************************************************
1063 * Name: WriteSignature :LOCAL
1065 * Description: Start the timer.
1067 * Parameters: padapter - Pointer adapter data structure.
1068 * pdev - Pointer to our device.
1069 * spigot - Selected spigot.
1070 * index - index of mirror signature on device.
1072 * Returns: TRUE on any error.
1074 ****************************************************************/
1075 static int WriteSignature (PADAPTER2220I padapter, POUR_DEVICE pdev, UCHAR spigot, int index)
1077 ULONG zl;
1079 SelectSpigot (padapter, spigot);
1080 zl = pdev->lastsectorlba[index];
1081 outb_p (pdev->byte6 | ((UCHAR *)&zl)[3], padapter->regLba24);
1082 outb_p (((UCHAR *)&zl)[2], padapter->regLba16);
1083 outb_p (((UCHAR *)&zl)[1], padapter->regLba8);
1084 outb_p (((UCHAR *)&zl)[0], padapter->regLba0);
1085 outb_p (1, padapter->regSectCount);
1087 WriteCommand (padapter, IDE_COMMAND_WRITE);
1088 if ( WaitDrq (padapter) )
1089 return TRUE;
1090 StartTimer (padapter);
1091 padapter->expectingIRQ = TRUE;
1093 ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[0] = ((ULONG *)(&pdev->DiskMirror[index]))[0];
1094 ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[1] = ((ULONG *)(&pdev->DiskMirror[index]))[1];
1095 outsw (padapter->regData, padapter->kBuffer, BYTES_PER_SECTOR / 2);
1096 return FALSE;
1098 /*******************************************************************************************************
1099 * Name: InitFailover
1101 * Description: This is the beginning of the failover routine
1103 * Parameters: SCpnt - Pointer to SCSI command structure.
1104 * padapter - Pointer adapter data structure.
1105 * pdev - Pointer to our device.
1107 * Returns: TRUE on error.
1109 ******************************************************************************************************/
1110 static int InitFailover (PADAPTER2220I padapter, POUR_DEVICE pdev)
1112 UCHAR spigot;
1114 DEB (printk ("\npci2220i: Initialize failover process - survivor = %d", pdev->deviceID[padapter->survivor]));
1115 pdev->raid = FALSE; //initializes system for non raid mode
1116 pdev->reconOn = FALSE;
1117 spigot = pdev->spigots[padapter->survivor];
1119 if ( pdev->DiskMirror[padapter->survivor].status & UCBF_REBUILD )
1121 DEB (printk ("\n failed, is survivor"));
1122 return (TRUE);
1125 if ( HardReset (padapter, pdev, spigot) )
1127 DEB (printk ("\n failed, reset"));
1128 return TRUE;
1131 Alarm (padapter, pdev->deviceID[padapter->survivor ^ 1]);
1132 pdev->DiskMirror[padapter->survivor].status = UCBF_MIRRORED | UCBF_SURVIVOR; //clear present status
1134 if ( WriteSignature (padapter, pdev, spigot, padapter->survivor) )
1136 DEB (printk ("\n failed, write signature"));
1137 return TRUE;
1139 padapter->failinprog = TRUE;
1140 return FALSE;
1142 /****************************************************************
1143 * Name: TimerExpiry :LOCAL
1145 * Description: Timer expiry routine.
1147 * Parameters: data - Pointer adapter data structure.
1149 * Returns: Nothing.
1151 ****************************************************************/
1152 static void TimerExpiry (unsigned long data)
1154 PADAPTER2220I padapter = (PADAPTER2220I)data;
1155 POUR_DEVICE pdev = padapter->pdev;
1156 UCHAR status = IDE_STATUS_BUSY;
1157 UCHAR temp, temp1;
1158 unsigned long flags;
1161 * Disable interrupts, if they aren't already disabled and acquire
1162 * the I/O spinlock.
1164 spin_lock_irqsave (&io_request_lock, flags);
1165 DEB (printk ("\nPCI2220I: Timeout expired "));
1167 if ( padapter->failinprog )
1169 DEB (printk ("in failover process"));
1170 OpDone (padapter, DecodeError (padapter, inb_p (padapter->regStatCmd)));
1171 goto timerExpiryDone;
1174 while ( padapter->reconPhase )
1176 DEB (printk ("in recon phase %X", padapter->reconPhase));
1177 switch ( padapter->reconPhase )
1179 case RECON_PHASE_MARKING:
1180 case RECON_PHASE_LAST:
1181 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 1 : 0;
1182 DEB (printk ("\npci2220i: FAILURE 1"));
1183 if ( InitFailover (padapter, pdev) )
1184 OpDone (padapter, DID_ERROR << 16);
1185 goto timerExpiryDone;
1187 case RECON_PHASE_READY:
1188 OpDone (padapter, DID_ERROR << 16);
1189 goto timerExpiryDone;
1191 case RECON_PHASE_COPY:
1192 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1193 DEB (printk ("\npci2220i: FAILURE 2"));
1194 DEB (printk ("\n spig/stat = %X", inb_p (padapter->regStatSel));
1195 if ( InitFailover (padapter, pdev) )
1196 OpDone (padapter, DID_ERROR << 16);
1197 goto timerExpiryDone;
1199 case RECON_PHASE_UPDATE:
1200 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1201 DEB (printk ("\npci2220i: FAILURE 3")));
1202 if ( InitFailover (padapter, pdev) )
1203 OpDone (padapter, DID_ERROR << 16);
1204 goto timerExpiryDone;
1206 case RECON_PHASE_END:
1207 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1208 DEB (printk ("\npci2220i: FAILURE 4"));
1209 if ( InitFailover (padapter, pdev) )
1210 OpDone (padapter, DID_ERROR << 16);
1211 goto timerExpiryDone;
1213 default:
1214 goto timerExpiryDone;
1218 while ( padapter->cmd )
1220 outb_p (0x08, padapter->regDmaCmdStat); // cancel interrupt from DMA engine
1221 if ( pdev->raid )
1223 if ( padapter->cmd == WRITE_CMD )
1225 DEB (printk ("in RAID write operation"));
1226 temp = ( pdev->spigot & (SEL_1 | SEL_2) ) ? SEL_1 : SEL_3;
1227 if ( inb_p (padapter->regStatSel) & temp )
1229 DEB (printk ("\npci2220i: Determined A OK"));
1230 SelectSpigot (padapter, temp | SEL_IRQ_OFF); // Masking the interrupt during spigot select
1231 temp = inb_p (padapter->regStatCmd);
1233 else
1234 temp = IDE_STATUS_BUSY;
1236 temp1 = ( pdev->spigot & (SEL_1 | SEL_2) ) ? SEL_2 : SEL_4;
1237 if ( inb (padapter->regStatSel) & temp1 )
1239 DEB (printk ("\npci2220i: Determined B OK"));
1240 SelectSpigot (padapter, temp1 | SEL_IRQ_OFF); // Masking the interrupt during spigot select
1241 temp1 = inb_p (padapter->regStatCmd);
1243 else
1244 temp1 = IDE_STATUS_BUSY;
1246 if ( (temp & IDE_STATUS_BUSY) || (temp1 & IDE_STATUS_BUSY) )
1248 DEB (printk ("\npci2220i: Status A: %X B: %X", temp & 0xFF, temp1 & 0xFF));
1249 if ( (temp & IDE_STATUS_BUSY) && (temp1 & IDE_STATUS_BUSY) )
1251 status = temp;
1252 break;
1254 else
1256 if ( temp & IDE_STATUS_BUSY )
1257 padapter->survivor = 1;
1258 else
1259 padapter->survivor = 0;
1260 if ( InitFailover (padapter, pdev) )
1262 status = inb_p (padapter->regStatCmd);
1263 break;
1265 goto timerExpiryDone;
1269 else
1271 DEB (printk ("in RAID read operation"));
1272 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1273 DEB (printk ("\npci2220i: FAILURE 6"));
1274 if ( InitFailover (padapter, pdev) )
1276 status = inb_p (padapter->regStatCmd);
1277 break;
1279 goto timerExpiryDone;
1282 else
1284 DEB (printk ("in I/O operation"));
1285 status = inb_p (padapter->regStatCmd);
1287 break;
1290 OpDone (padapter, DecodeError (padapter, status));
1292 timerExpiryDone:;
1294 * Release the I/O spinlock and restore the original flags
1295 * which will enable interrupts if and only if they were
1296 * enabled on entry.
1298 spin_unlock_irqrestore (&io_request_lock, flags);
1300 /****************************************************************
1301 * Name: SetReconstruct :LOCAL
1303 * Description: Set the reconstruct up.
1305 * Parameters: pdev - Pointer to device structure.
1306 * index - Mirror index number.
1308 * Returns: Number of sectors on new disk required.
1310 ****************************************************************/
1311 static LONG SetReconstruct (POUR_DEVICE pdev, int index)
1313 pdev->DiskMirror[index].status = UCBF_MIRRORED; // setup the flags
1314 pdev->DiskMirror[index ^ 1].status = UCBF_MIRRORED | UCBF_REBUILD;
1315 pdev->DiskMirror[index ^ 1].reconstructPoint = 0; // start the reconstruct
1316 pdev->reconCount = 1990; // mark target drive early
1317 return pdev->DiskMirror[index].reconstructPoint;
1319 /****************************************************************
1320 * Name: ReconTimerExpiry :LOCAL
1322 * Description: Reconstruct timer expiry routine.
1324 * Parameters: data - Pointer adapter data structure.
1326 * Returns: Nothing.
1328 ****************************************************************/
1329 static void ReconTimerExpiry (unsigned long data)
1331 PADAPTER2220I padapter;
1332 POUR_DEVICE pdev;
1333 ULONG testsize = 0;
1334 PIDENTIFY_DATA pid;
1335 USHORT minmode;
1336 ULONG zl;
1337 UCHAR zc;
1338 USHORT z;
1339 unsigned long flags;
1342 * Disable interrupts, if they aren't already disabled and acquire
1343 * the I/O spinlock.
1345 spin_lock_irqsave (&io_request_lock, flags);
1347 padapter = (PADAPTER2220I)data;
1348 if ( padapter->SCpnt )
1349 goto reconTimerExpiry;
1351 padapter->reconTimer.data = 0;
1352 for ( z = padapter->devInReconIndex + 1; z < BIGD_MAXDRIVES; z++ )
1354 if ( padapter->device[z].reconOn )
1355 break;
1357 if ( z < BIGD_MAXDRIVES )
1358 pdev = &padapter->device[z];
1359 else
1361 for ( z = 0; z < BIGD_MAXDRIVES; z++ )
1363 if ( padapter->device[z].reconOn )
1364 break;
1366 if ( z < BIGD_MAXDRIVES )
1367 pdev = &padapter->device[z];
1368 else
1370 padapter->reconOn = FALSE;
1371 goto reconTimerExpiry;
1375 padapter->devInReconIndex = z;
1376 pid = (PIDENTIFY_DATA)padapter->kBuffer;
1377 padapter->pdev = pdev;
1378 if ( pdev->reconIsStarting )
1380 pdev->reconIsStarting = FALSE;
1381 pdev->reconOn = FALSE;
1383 while ( (pdev->DiskMirror[0].signature == SIGNATURE) && (pdev->DiskMirror[1].signature == SIGNATURE) &&
1384 (pdev->DiskMirror[0].pairIdentifier == (pdev->DiskMirror[1].pairIdentifier ^ 1)) )
1386 if ( (pdev->DiskMirror[0].status & UCBF_MATCHED) && (pdev->DiskMirror[1].status & UCBF_MATCHED) )
1387 break;;
1389 if ( pdev->DiskMirror[0].status & UCBF_SURVIVOR ) // is first drive survivor?
1390 testsize = SetReconstruct (pdev, 0);
1391 else
1392 if ( pdev->DiskMirror[1].status & UCBF_SURVIVOR ) // is second drive survivor?
1393 testsize = SetReconstruct (pdev, 1);
1395 if ( (pdev->DiskMirror[0].status & UCBF_REBUILD) || (pdev->DiskMirror[1].status & UCBF_REBUILD) )
1397 if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
1398 pdev->mirrorRecon = 0;
1399 else
1400 pdev->mirrorRecon = 1;
1401 pdev->reconOn = TRUE;
1403 break;
1406 if ( !pdev->reconOn )
1407 goto reconTimerExpiry;
1409 if ( padapter->bigD )
1411 padapter->failRegister = 0;
1412 outb_p (~padapter->failRegister, padapter->regFail);
1414 else
1416 zc = ((inb_p (padapter->regStatSel) >> 3) | inb_p (padapter->regStatSel)) & 0x83; // mute the alarm
1417 outb_p (0xFF, padapter->regFail);
1420 while ( 1 )
1422 DEB (printk ("\npci2220i: hard reset issue"));
1423 if ( HardReset (padapter, pdev, pdev->spigots[pdev->mirrorRecon]) )
1425 DEB (printk ("\npci2220i: sub 1"));
1426 break;
1429 pdev->lastsectorlba[pdev->mirrorRecon] = InlineIdentify (padapter, pdev->spigots[pdev->mirrorRecon], pdev->deviceID[pdev->mirrorRecon] & 1);
1431 if ( pdev->lastsectorlba[pdev->mirrorRecon] < testsize )
1433 DEB (printk ("\npci2220i: sub 2 %ld %ld", pdev->lastsectorlba[pdev->mirrorRecon], testsize));
1434 break;
1437 // test LBA and multiper sector transfer compatability
1438 if (!pid->SupportLBA || (pid->NumSectorsPerInt < SECTORSXFER) || !pid->Valid_64_70 )
1440 DEB (printk ("\npci2220i: sub 3"));
1441 break;
1444 // test PIO/bus matering mode compatability
1445 if ( (pid->MinPIOCycleWithoutFlow > 240) && !pid->SupportIORDYDisable && !padapter->timingPIO )
1447 DEB (printk ("\npci2220i: sub 4"));
1448 break;
1451 if ( pid->MinPIOCycleWithoutFlow <= 120 ) // setup timing mode of drive
1452 minmode = 5;
1453 else
1455 if ( pid->MinPIOCylceWithFlow <= 150 )
1456 minmode = 4;
1457 else
1459 if ( pid->MinPIOCylceWithFlow <= 180 )
1460 minmode = 3;
1461 else
1463 if ( pid->MinPIOCylceWithFlow <= 240 )
1464 minmode = 2;
1465 else
1467 DEB (printk ("\npci2220i: sub 5"));
1468 break;
1474 if ( padapter->timingMode > minmode ) // set minimum timing mode
1475 padapter->timingMode = minmode;
1476 if ( padapter->timingMode >= 2 )
1477 padapter->timingAddress = ModeArray[padapter->timingMode - 2];
1478 else
1479 padapter->timingPIO = TRUE;
1481 padapter->reconOn = TRUE;
1482 break;
1485 if ( !pdev->reconOn )
1487 padapter->survivor = pdev->mirrorRecon ^ 1;
1488 padapter->reconPhase = RECON_PHASE_FAILOVER;
1489 DEB (printk ("\npci2220i: FAILURE 7"));
1490 InitFailover (padapter, pdev);
1491 goto reconTimerExpiry;
1494 pdev->raid = TRUE;
1496 if ( WriteSignature (padapter, pdev, pdev->spigot, pdev->mirrorRecon ^ 1) )
1497 goto reconTimerExpiry;
1498 padapter->reconPhase = RECON_PHASE_MARKING;
1499 goto reconTimerExpiry;
1502 //**********************************
1503 // reconstruct copy starts here
1504 //**********************************
1505 if ( pdev->reconCount++ > 2000 )
1507 pdev->reconCount = 0;
1508 if ( WriteSignature (padapter, pdev, pdev->spigots[pdev->mirrorRecon], pdev->mirrorRecon) )
1510 padapter->survivor = pdev->mirrorRecon ^ 1;
1511 padapter->reconPhase = RECON_PHASE_FAILOVER;
1512 DEB (printk ("\npci2220i: FAILURE 8"));
1513 InitFailover (padapter, pdev);
1514 goto reconTimerExpiry;
1516 padapter->reconPhase = RECON_PHASE_UPDATE;
1517 goto reconTimerExpiry;
1520 zl = pdev->DiskMirror[pdev->mirrorRecon].reconstructPoint;
1521 padapter->reconSize = pdev->DiskMirror[pdev->mirrorRecon ^ 1].reconstructPoint - zl;
1522 if ( padapter->reconSize > MAX_BUS_MASTER_BLOCKS )
1523 padapter->reconSize = MAX_BUS_MASTER_BLOCKS;
1525 if ( padapter->reconSize )
1527 SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1]); // select the spigots
1528 outb_p (pdev->byte6 | ((UCHAR *)(&zl))[3], padapter->regLba24); // select the drive
1529 SelectSpigot (padapter, pdev->spigot);
1530 if ( WaitReady (padapter) )
1531 goto reconTimerExpiry;
1533 SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon]);
1534 if ( WaitReady (padapter) )
1536 padapter->survivor = pdev->mirrorRecon ^ 1;
1537 padapter->reconPhase = RECON_PHASE_FAILOVER;
1538 DEB (printk ("\npci2220i: FAILURE 9"));
1539 InitFailover (padapter, pdev);
1540 goto reconTimerExpiry;
1543 SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1]);
1544 outb_p (padapter->reconSize & 0xFF, padapter->regSectCount);
1545 outb_p (((UCHAR *)(&zl))[0], padapter->regLba0);
1546 outb_p (((UCHAR *)(&zl))[1], padapter->regLba8);
1547 outb_p (((UCHAR *)(&zl))[2], padapter->regLba16);
1548 padapter->expectingIRQ = TRUE;
1549 padapter->reconPhase = RECON_PHASE_READY;
1550 SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon]);
1551 WriteCommand (padapter, WRITE_CMD);
1552 StartTimer (padapter);
1553 SelectSpigot (padapter, pdev->spigot);
1554 WriteCommand (padapter, READ_CMD);
1555 goto reconTimerExpiry;
1558 pdev->DiskMirror[pdev->mirrorRecon].status = UCBF_MIRRORED | UCBF_MATCHED;
1559 pdev->DiskMirror[pdev->mirrorRecon ^ 1].status = UCBF_MIRRORED | UCBF_MATCHED;
1560 if ( WriteSignature (padapter, pdev, pdev->spigot, pdev->mirrorRecon ^ 1) )
1561 goto reconTimerExpiry;
1562 padapter->reconPhase = RECON_PHASE_LAST;
1564 reconTimerExpiry:;
1566 * Release the I/O spinlock and restore the original flags
1567 * which will enable interrupts if and only if they were
1568 * enabled on entry.
1570 spin_unlock_irqrestore (&io_request_lock, flags);
1572 /****************************************************************
1573 * Name: Irq_Handler :LOCAL
1575 * Description: Interrupt handler.
1577 * Parameters: irq - Hardware IRQ number.
1578 * dev_id -
1579 * regs -
1581 * Returns: TRUE if drive is not ready in time.
1583 ****************************************************************/
1584 static void Irq_Handler (int irq, void *dev_id, struct pt_regs *regs)
1586 struct Scsi_Host *shost = NULL; // Pointer to host data block
1587 PADAPTER2220I padapter; // Pointer to adapter control structure
1588 POUR_DEVICE pdev;
1589 Scsi_Cmnd *SCpnt;
1590 UCHAR status;
1591 UCHAR status1;
1592 ATAPI_STATUS statusa;
1593 ATAPI_REASON reasona;
1594 ATAPI_ERROR errora;
1595 int z;
1596 ULONG zl;
1597 unsigned long flags;
1600 * Disable interrupts, if they aren't already disabled and acquire
1601 * the I/O spinlock.
1603 spin_lock_irqsave (&io_request_lock, flags);
1605 // DEB (printk ("\npci2220i recieved interrupt\n"));
1607 for ( z = 0; z < NumAdapters; z++ ) // scan for interrupt to process
1609 if ( PsiHost[z]->irq == (UCHAR)(irq & 0xFF) )
1611 if ( inw_p (HOSTDATA(PsiHost[z])->regIrqControl) & 0x8000 )
1613 shost = PsiHost[z];
1614 break;
1619 if ( !shost )
1621 DEB (printk ("\npci2220i: not my interrupt"));
1622 goto irq_return;
1625 padapter = HOSTDATA(shost);
1626 pdev = padapter->pdev;
1627 SCpnt = padapter->SCpnt;
1628 outb_p (0x08, padapter->regDmaCmdStat); // cancel interrupt from DMA engine
1630 if ( padapter->atapi && SCpnt )
1632 *(char *)&statusa = inb_p (padapter->regStatCmd); // read the device status
1633 *(char *)&reasona = inb_p (padapter->regSectCount); // read the device interrupt reason
1635 if ( !statusa.bsy )
1637 if ( statusa.drq ) // test for transfer phase
1639 if ( !reasona.cod ) // test for data phase
1641 z = (ULONG)inb_p (padapter->regLba8) | (ULONG)(inb_p (padapter->regLba16) << 8);
1642 if ( padapter->reqSense )
1643 insw (padapter->regData, SCpnt->sense_buffer, z / 2);
1644 else
1645 AtapiBusMaster (padapter, reasona.io, z);
1646 goto irq_return;
1648 if ( reasona.cod && !reasona.io ) // test for command packet phase
1650 if ( padapter->reqSense )
1651 AtapiRequestSense (padapter, pdev, SCpnt, TRUE);
1652 else
1653 AtapiSendCdb (padapter, pdev, padapter->atapiCdb);
1654 goto irq_return;
1657 else
1659 if ( reasona.io && statusa.drdy ) // test for status phase
1661 Atapi2Scsi (padapter, SCpnt);
1662 if ( statusa.check )
1664 *(UCHAR *)&errora = inb_p (padapter->regError); // read the device error
1665 if ( errora.senseKey )
1667 if ( padapter->reqSense || AtapiRequestSense (padapter, pdev, SCpnt, FALSE) )
1668 OpDone (padapter, DID_ERROR << 16);
1670 else
1672 if ( errora.ili || errora.abort )
1673 OpDone (padapter, DID_ERROR << 16);
1674 else
1675 OpDone (padapter, DID_OK << 16);
1678 else
1679 if ( padapter->reqSense )
1681 DEB (printk ("PCI2242I: Sense codes - %X %X %X ", ((UCHAR *)SCpnt->sense_buffer)[0], ((UCHAR *)SCpnt->sense_buffer)[12], ((UCHAR *)SCpnt->sense_buffer)[13]));
1682 OpDone (padapter, (DRIVER_SENSE << 24) | (DID_OK << 16) | 2);
1684 else
1685 OpDone (padapter, DID_OK << 16);
1689 goto irq_return;
1692 if ( !padapter->expectingIRQ || !(SCpnt || padapter->reconPhase) )
1694 DEB(printk ("\npci2220i Unsolicited interrupt\n"));
1695 STOP_HERE ();
1696 goto irq_return;
1698 padapter->expectingIRQ = 0;
1700 if ( padapter->failinprog )
1702 DEB (printk ("\npci2220i interrupt failover complete"));
1703 padapter->failinprog = FALSE;
1704 status = inb_p (padapter->regStatCmd); // read the device status
1705 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1707 DEB (printk ("\npci2220i: interrupt failover error from drive %X", status));
1708 padapter->cmd = 0;
1710 else
1712 DEB (printk ("\npci2220i: restarting failed opertation."));
1713 pdev->spigot = (padapter->survivor) ? pdev->spigots[1] : pdev->spigots[0];
1714 del_timer (&padapter->timer);
1715 if ( padapter->reconPhase )
1716 OpDone (padapter, DID_OK << 16);
1717 else
1718 Pci2220i_QueueCommand (SCpnt, SCpnt->scsi_done);
1719 goto irq_return;
1723 if ( padapter->reconPhase )
1725 switch ( padapter->reconPhase )
1727 case RECON_PHASE_MARKING:
1728 case RECON_PHASE_LAST:
1729 status = inb_p (padapter->regStatCmd); // read the device status
1730 del_timer (&padapter->timer);
1731 if ( padapter->reconPhase == RECON_PHASE_LAST )
1733 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1735 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 1 : 0;
1736 DEB (printk ("\npci2220i: FAILURE 10"));
1737 if ( InitFailover (padapter, pdev) )
1738 OpDone (padapter, DecodeError (padapter, status));
1739 goto irq_return;
1741 if ( WriteSignature (padapter, pdev, pdev->spigots[pdev->mirrorRecon], pdev->mirrorRecon) )
1743 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1744 DEB (printk ("\npci2220i: FAILURE 11"));
1745 if ( InitFailover (padapter, pdev) )
1746 OpDone (padapter, DecodeError (padapter, status));
1747 goto irq_return;
1749 padapter->reconPhase = RECON_PHASE_END;
1750 goto irq_return;
1752 OpDone (padapter, DID_OK << 16);
1753 goto irq_return;
1755 case RECON_PHASE_READY:
1756 status = inb_p (padapter->regStatCmd); // read the device status
1757 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1759 del_timer (&padapter->timer);
1760 OpDone (padapter, DecodeError (padapter, status));
1761 goto irq_return;
1763 SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon]);
1764 if ( WaitDrq (padapter) )
1766 del_timer (&padapter->timer);
1767 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1768 DEB (printk ("\npci2220i: FAILURE 12"));
1769 if ( InitFailover (padapter, pdev) )
1770 OpDone (padapter, DecodeError (padapter, status));
1771 goto irq_return;
1773 SelectSpigot (padapter, pdev->spigot | SEL_COPY | padapter->bigD);
1774 padapter->reconPhase = RECON_PHASE_COPY;
1775 padapter->expectingIRQ = TRUE;
1776 if ( padapter->timingPIO )
1778 insw (padapter->regData, padapter->kBuffer, padapter->reconSize * (BYTES_PER_SECTOR / 2));
1780 else
1782 if ( (padapter->timingMode > 3) )
1784 if ( padapter->bigD )
1785 outl (BIGD_DATA_MODE3, padapter->regDmaAddrLoc);
1786 else
1787 outl (DALE_DATA_MODE3, padapter->regDmaAddrLoc);
1789 else
1790 outl (padapter->timingAddress, padapter->regDmaAddrLoc);
1791 outl (padapter->kBufferDma, padapter->regDmaAddrPci);
1792 outl (padapter->reconSize * BYTES_PER_SECTOR, padapter->regDmaCount);
1793 outb_p (8, padapter->regDmaDesc); // read operation
1794 if ( padapter->bigD )
1795 outb_p (8, padapter->regDmaMode); // no interrupt
1796 else
1797 outb_p (1, padapter->regDmaMode); // no interrupt
1798 outb_p (0x03, padapter->regDmaCmdStat); // kick the DMA engine in gear
1800 goto irq_return;
1802 case RECON_PHASE_COPY:
1803 pdev->DiskMirror[pdev->mirrorRecon].reconstructPoint += padapter->reconSize;
1805 case RECON_PHASE_UPDATE:
1806 SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon] | SEL_IRQ_OFF);
1807 status = inb_p (padapter->regStatCmd); // read the device status
1808 del_timer (&padapter->timer);
1809 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1811 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1812 DEB (printk ("\npci2220i: FAILURE 13"));
1813 DEB (printk ("\n status register = %X error = %X", status, inb_p (padapter->regError)));
1814 if ( InitFailover (padapter, pdev) )
1815 OpDone (padapter, DecodeError (padapter, status));
1816 goto irq_return;
1818 OpDone (padapter, DID_OK << 16);
1819 goto irq_return;
1821 case RECON_PHASE_END:
1822 status = inb_p (padapter->regStatCmd); // read the device status
1823 del_timer (&padapter->timer);
1824 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1826 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
1827 DEB (printk ("\npci2220i: FAILURE 14"));
1828 if ( InitFailover (padapter, pdev) )
1829 OpDone (padapter, DecodeError (padapter, status));
1830 goto irq_return;
1832 pdev->reconOn = 0;
1833 if ( padapter->bigD )
1835 for ( z = 0; z < padapter->numberOfDrives; z++ )
1837 if ( padapter->device[z].DiskMirror[0].status & UCBF_SURVIVOR )
1839 Alarm (padapter, padapter->device[z].deviceID[0] ^ 2);
1840 MuteAlarm (padapter);
1842 if ( padapter->device[z].DiskMirror[1].status & UCBF_SURVIVOR )
1844 Alarm (padapter, padapter->device[z].deviceID[1] ^ 2);
1845 MuteAlarm (padapter);
1849 OpDone (padapter, DID_OK << 16);
1850 goto irq_return;
1852 default:
1853 goto irq_return;
1857 switch ( padapter->cmd ) // decide how to handle the interrupt
1859 case READ_CMD:
1860 if ( padapter->sectorCount )
1862 status = inb_p (padapter->regStatCmd); // read the device status
1863 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1865 if ( pdev->raid )
1867 padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 1 : 0;
1868 del_timer (&padapter->timer);
1869 DEB (printk ("\npci2220i: FAILURE 15"));
1870 if ( !InitFailover (padapter, pdev) )
1871 goto irq_return;
1873 break;
1875 if ( padapter->timingPIO )
1877 insw (padapter->regData, padapter->kBuffer, padapter->readCount / 2);
1878 padapter->sectorCount -= padapter->readCount / BYTES_PER_SECTOR;
1879 WalkScatGath (padapter, TRUE, padapter->readCount);
1880 if ( !padapter->sectorCount )
1882 status = 0;
1883 break;
1886 else
1888 if ( padapter->readCount )
1889 WalkScatGath (padapter, TRUE, padapter->readCount);
1890 BusMaster (padapter, 1, 1);
1892 padapter->expectingIRQ = TRUE;
1893 goto irq_return;
1895 if ( padapter->readCount && !padapter->timingPIO )
1896 WalkScatGath (padapter, TRUE, padapter->readCount);
1897 status = 0;
1898 break;
1900 case WRITE_CMD:
1901 if ( pdev->raid )
1903 SelectSpigot (padapter, pdev->spigots[0] | SEL_IRQ_OFF);
1904 status = inb_p (padapter->regStatCmd); // read the device status
1905 SelectSpigot (padapter, pdev->spigots[1] | SEL_IRQ_OFF);
1906 status1 = inb_p (padapter->regStatCmd); // read the device status
1908 else
1909 SelectSpigot (padapter, pdev->spigot | SEL_IRQ_OFF);
1910 status = inb_p (padapter->regStatCmd); // read the device status
1911 status1 = 0;
1913 if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1915 if ( pdev->raid && !(status1 & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT)) )
1917 padapter->survivor = 1;
1918 del_timer (&padapter->timer);
1919 SelectSpigot (padapter, pdev->spigot | SEL_IRQ_OFF);
1920 DEB (printk ("\npci2220i: FAILURE 16 status = %X error = %X", status, inb_p (padapter->regError)));
1921 if ( !InitFailover (padapter, pdev) )
1922 goto irq_return;
1924 break;
1926 if ( pdev->raid )
1928 if ( status1 & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
1930 padapter->survivor = 0;
1931 del_timer (&padapter->timer);
1932 DEB (printk ("\npci2220i: FAILURE 17 status = %X error = %X", status1, inb_p (padapter->regError)));
1933 if ( !InitFailover (padapter, pdev) )
1934 goto irq_return;
1935 status = status1;
1936 break;
1938 if ( padapter->sectorCount )
1940 status = WriteDataBoth (padapter, pdev);
1941 if ( status )
1943 padapter->survivor = status >> 1;
1944 del_timer (&padapter->timer);
1945 DEB (printk ("\npci2220i: FAILURE 18"));
1946 if ( !InitFailover (padapter, pdev) )
1947 goto irq_return;
1948 SelectSpigot (padapter, pdev->spigots[status] | SEL_IRQ_OFF);
1949 status = inb_p (padapter->regStatCmd); // read the device status
1950 break;
1952 padapter->expectingIRQ = TRUE;
1953 goto irq_return;
1955 status = 0;
1956 break;
1958 if ( padapter->sectorCount )
1960 SelectSpigot (padapter, pdev->spigot | padapter->bigD);
1961 status = WriteData (padapter);
1962 if ( status )
1963 break;
1964 padapter->expectingIRQ = TRUE;
1965 goto irq_return;
1967 status = 0;
1968 break;
1970 case IDE_COMMAND_IDENTIFY:
1972 PINQUIRYDATA pinquiryData = SCpnt->request_buffer;
1973 PIDENTIFY_DATA pid = (PIDENTIFY_DATA)padapter->kBuffer;
1975 status = inb_p (padapter->regStatCmd);
1976 if ( status & IDE_STATUS_DRQ )
1978 insw (padapter->regData, pid, sizeof (IDENTIFY_DATA) >> 1);
1980 memset (pinquiryData, 0, SCpnt->request_bufflen); // Zero INQUIRY data structure.
1981 pinquiryData->DeviceType = 0;
1982 pinquiryData->Versions = 2;
1983 pinquiryData->AdditionalLength = 35 - 4;
1985 // Fill in vendor identification fields.
1986 for ( z = 0; z < 20; z += 2 )
1988 pinquiryData->VendorId[z] = ((UCHAR *)pid->ModelNumber)[z + 1];
1989 pinquiryData->VendorId[z + 1] = ((UCHAR *)pid->ModelNumber)[z];
1992 // Initialize unused portion of product id.
1993 for ( z = 0; z < 4; z++ )
1994 pinquiryData->ProductId[12 + z] = ' ';
1996 // Move firmware revision from IDENTIFY data to
1997 // product revision in INQUIRY data.
1998 for ( z = 0; z < 4; z += 2 )
2000 pinquiryData->ProductRevisionLevel[z] = ((UCHAR *)pid->FirmwareRevision)[z + 1];
2001 pinquiryData->ProductRevisionLevel[z + 1] = ((UCHAR *)pid->FirmwareRevision)[z];
2003 if ( pdev == padapter->device )
2004 *((USHORT *)(&pinquiryData->VendorSpecific)) = DEVICE_DALE_1;
2006 status = 0;
2008 break;
2011 default:
2012 status = 0;
2013 break;
2016 del_timer (&padapter->timer);
2017 if ( status )
2019 DEB (printk ("\npci2220i Interupt hanlder return error"));
2020 zl = DecodeError (padapter, status);
2022 else
2023 zl = DID_OK << 16;
2025 OpDone (padapter, zl);
2026 irq_return:;
2028 * Release the I/O spinlock and restore the original flags
2029 * which will enable interrupts if and only if they were
2030 * enabled on entry.
2032 spin_unlock_irqrestore (&io_request_lock, flags);
2034 /****************************************************************
2035 * Name: Pci2220i_QueueCommand
2037 * Description: Process a queued command from the SCSI manager.
2039 * Parameters: SCpnt - Pointer to SCSI command structure.
2040 * done - Pointer to done function to call.
2042 * Returns: Status code.
2044 ****************************************************************/
2045 int Pci2220i_QueueCommand (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
2047 UCHAR *cdb = (UCHAR *)SCpnt->cmnd; // Pointer to SCSI CDB
2048 PADAPTER2220I padapter = HOSTDATA(SCpnt->host); // Pointer to adapter control structure
2049 POUR_DEVICE pdev = &padapter->device[SCpnt->target];// Pointer to device information
2050 UCHAR rc; // command return code
2051 int z;
2052 PDEVICE_RAID1 pdr;
2054 SCpnt->scsi_done = done;
2055 padapter->SCpnt = SCpnt; // Save this command data
2056 padapter->readCount = 0;
2058 if ( SCpnt->use_sg )
2060 padapter->currentSgBuffer = ((struct scatterlist *)SCpnt->request_buffer)[0].address;
2061 padapter->currentSgCount = ((struct scatterlist *)SCpnt->request_buffer)[0].length;
2063 else
2065 padapter->currentSgBuffer = SCpnt->request_buffer;
2066 padapter->currentSgCount = SCpnt->request_bufflen;
2068 padapter->nextSg = 1;
2070 if ( !done )
2072 printk("pci2220i_queuecommand: %02X: done can't be NULL\n", *cdb);
2073 return 0;
2076 if ( padapter->atapi )
2078 UCHAR zlo, zhi;
2080 DEB (printk ("\nPCI2242I: ID %d, LUN %d opcode %X ", SCpnt->target, SCpnt->lun, *cdb));
2081 padapter->pdev = pdev;
2082 if ( !pdev->byte6 || SCpnt->lun )
2084 OpDone (padapter, DID_BAD_TARGET << 16);
2085 return 0;
2088 padapter->atapiSpecial = FALSE;
2089 padapter->reqSense = FALSE;
2090 memset (padapter->atapiCdb, 0, 16);
2091 SelectSpigot (padapter, pdev->spigot); // select the spigot
2092 AtapiDevice (padapter, pdev->byte6); // select the drive
2093 if ( AtapiWaitReady (padapter, 100) )
2095 OpDone (padapter, DID_NO_CONNECT << 16);
2096 return 0;
2099 switch ( cdb[0] )
2101 case SCSIOP_MODE_SENSE:
2102 case SCSIOP_MODE_SELECT:
2103 Scsi2Atapi (padapter, SCpnt);
2104 z = SCpnt->request_bufflen + 4;
2105 break;
2106 case SCSIOP_READ6:
2107 case SCSIOP_WRITE6:
2108 Scsi2Atapi (padapter, SCpnt);
2109 z = SCpnt->request_bufflen;
2110 break;
2111 default:
2112 memcpy (padapter->atapiCdb, cdb, SCpnt->cmd_len);
2113 z = SCpnt->request_bufflen;
2114 break;
2116 if ( z > ATAPI_TRANSFER )
2117 z = ATAPI_TRANSFER;
2118 zlo = (UCHAR)(z & 0xFF);
2119 zhi = (UCHAR)(z >> 8);
2121 AtapiCountLo (padapter, zlo);
2122 AtapiCountHi (padapter, zhi);
2123 outb_p (0, padapter->regError);
2124 WriteCommand (padapter, IDE_COMMAND_ATAPI_PACKET);
2125 if ( pdev->cmdDrqInt )
2126 return 0;
2128 if ( AtapiWaitDrq (padapter, 500) )
2130 OpDone (padapter, DID_ERROR << 16);
2131 return 0;
2133 AtapiSendCdb (padapter, pdev, padapter->atapiCdb);
2134 return 0;
2137 if ( padapter->reconPhase )
2138 return 0;
2139 if ( padapter->reconTimer.data )
2141 del_timer (&padapter->reconTimer);
2142 padapter->reconTimer.data = 0;
2145 if ( (SCpnt->target >= padapter->numberOfDrives) || SCpnt->lun )
2147 OpDone (padapter, DID_BAD_TARGET << 16);
2148 return 0;
2151 switch ( *cdb )
2153 case SCSIOP_INQUIRY: // inquiry CDB
2155 if ( cdb[2] == SC_MY_RAID )
2157 switch ( cdb[3] )
2159 case MY_SCSI_REBUILD:
2160 for ( z = 0; z < padapter->numberOfDrives; z++ )
2162 pdev = &padapter->device[z];
2163 if ( ((pdev->DiskMirror[0].status & UCBF_SURVIVOR) && (pdev->DiskMirror[1].status & UCBF_MIRRORED)) ||
2164 ((pdev->DiskMirror[1].status & UCBF_SURVIVOR) && (pdev->DiskMirror[0].status & UCBF_MIRRORED)) )
2166 padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
2169 OpDone (padapter, DID_OK << 16);
2170 break;
2171 case MY_SCSI_ALARMMUTE:
2172 MuteAlarm (padapter);
2173 OpDone (padapter, DID_OK << 16);
2174 break;
2175 case MY_SCSI_DEMOFAIL:
2176 padapter->demoFail = TRUE;
2177 OpDone (padapter, DID_OK << 16);
2178 break;
2179 default:
2180 z = cdb[5]; // get index
2181 pdr = (PDEVICE_RAID1)SCpnt->request_buffer;
2182 if ( padapter->raidData[z] )
2184 memcpy (&pdr->DiskRaid1, padapter->raidData[z], sizeof (DISK_MIRROR));
2185 if ( padapter->raidData[z]->reconstructPoint > padapter->raidData[z ^ 2]->reconstructPoint )
2186 pdr->TotalSectors = padapter->raidData[z]->reconstructPoint;
2187 else
2188 pdr->TotalSectors = padapter->raidData[z ^ 2]->reconstructPoint;
2190 else
2191 memset (pdr, 0, sizeof (DEVICE_RAID1));
2192 OpDone (padapter, DID_OK << 16);
2193 break;
2195 return 0;
2197 padapter->cmd = IDE_COMMAND_IDENTIFY;
2198 break;
2201 case SCSIOP_TEST_UNIT_READY: // test unit ready CDB
2202 OpDone (padapter, DID_OK << 16);
2203 return 0;
2204 case SCSIOP_READ_CAPACITY: // read capctiy CDB
2206 PREAD_CAPACITY_DATA pdata = (PREAD_CAPACITY_DATA)SCpnt->request_buffer;
2208 pdata->blksiz = 0x20000;
2209 XANY2SCSI ((UCHAR *)&pdata->blks, pdev->blocks);
2210 OpDone (padapter, DID_OK << 16);
2211 return 0;
2213 case SCSIOP_VERIFY: // verify CDB
2214 padapter->startSector = XSCSI2LONG (&cdb[2]);
2215 padapter->sectorCount = (UCHAR)((USHORT)cdb[8] | ((USHORT)cdb[7] << 8));
2216 padapter->cmd = IDE_COMMAND_VERIFY;
2217 break;
2218 case SCSIOP_READ: // read10 CDB
2219 padapter->startSector = XSCSI2LONG (&cdb[2]);
2220 padapter->sectorCount = (USHORT)cdb[8] | ((USHORT)cdb[7] << 8);
2221 padapter->cmd = READ_CMD;
2222 break;
2223 case SCSIOP_READ6: // read6 CDB
2224 padapter->startSector = SCSI2LONG (&cdb[1]);
2225 padapter->sectorCount = cdb[4];
2226 padapter->cmd = READ_CMD;
2227 break;
2228 case SCSIOP_WRITE: // write10 CDB
2229 padapter->startSector = XSCSI2LONG (&cdb[2]);
2230 padapter->sectorCount = (USHORT)cdb[8] | ((USHORT)cdb[7] << 8);
2231 padapter->cmd = WRITE_CMD;
2232 break;
2233 case SCSIOP_WRITE6: // write6 CDB
2234 padapter->startSector = SCSI2LONG (&cdb[1]);
2235 padapter->sectorCount = cdb[4];
2236 padapter->cmd = WRITE_CMD;
2237 break;
2238 default:
2239 DEB (printk ("pci2220i_queuecommand: Unsupported command %02X\n", *cdb));
2240 OpDone (padapter, DID_ERROR << 16);
2241 return 0;
2244 if ( padapter->reconPhase )
2245 return 0;
2247 padapter->pdev = pdev;
2249 while ( padapter->demoFail )
2251 pdev = padapter->pdev = &padapter->device[0];
2252 padapter->demoFail = FALSE;
2253 if ( !pdev->raid ||
2254 (pdev->DiskMirror[0].status & UCBF_SURVIVOR) ||
2255 (pdev->DiskMirror[1].status & UCBF_SURVIVOR) )
2257 break;
2259 if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
2260 padapter->survivor = 1;
2261 else
2262 padapter->survivor = 0;
2263 DEB (printk ("\npci2220i: FAILURE 19"));
2264 if ( InitFailover (padapter, pdev) )
2265 break;
2266 return 0;
2269 StartTimer (padapter);
2270 if ( pdev->raid && (padapter->cmd == WRITE_CMD) )
2272 rc = IdeCmdBoth (padapter, pdev);
2273 if ( !rc )
2274 rc = WriteDataBoth (padapter, pdev);
2275 if ( rc )
2277 del_timer (&padapter->timer);
2278 padapter->expectingIRQ = 0;
2279 padapter->survivor = rc >> 1;
2280 DEB (printk ("\npci2220i: FAILURE 20"));
2281 if ( InitFailover (padapter, pdev) )
2283 OpDone (padapter, DID_ERROR << 16);
2284 return 0;
2288 else
2290 rc = IdeCmd (padapter, pdev);
2291 if ( (padapter->cmd == WRITE_CMD) && !rc )
2292 rc = WriteData (padapter);
2293 if ( rc )
2295 del_timer (&padapter->timer);
2296 padapter->expectingIRQ = 0;
2297 if ( pdev->raid )
2299 padapter->survivor = (pdev->spigot ^ 3) >> 1;
2300 DEB (printk ("\npci2220i: FAILURE 21"));
2301 if ( !InitFailover (padapter, pdev) )
2302 return 0;
2304 OpDone (padapter, DID_ERROR << 16);
2305 return 0;
2308 return 0;
2310 static void internal_done(Scsi_Cmnd *SCpnt)
2312 SCpnt->SCp.Status++;
2314 /****************************************************************
2315 * Name: Pci2220i_Command
2317 * Description: Process a command from the SCSI manager.
2319 * Parameters: SCpnt - Pointer to SCSI command structure.
2321 * Returns: Status code.
2323 ****************************************************************/
2324 int Pci2220i_Command (Scsi_Cmnd *SCpnt)
2326 Pci2220i_QueueCommand (SCpnt, internal_done);
2327 SCpnt->SCp.Status = 0;
2328 while (!SCpnt->SCp.Status)
2329 barrier ();
2330 return SCpnt->result;
2332 /****************************************************************
2333 * Name: ReadFlash
2335 * Description: Read information from controller Flash memory.
2337 * Parameters: padapter - Pointer to host interface data structure.
2338 * pdata - Pointer to data structures.
2339 * base - base address in Flash.
2340 * length - lenght of data space in bytes.
2342 * Returns: Nothing.
2344 ****************************************************************/
2345 static VOID ReadFlash (PADAPTER2220I padapter, VOID *pdata, ULONG base, ULONG length)
2347 ULONG oldremap;
2348 UCHAR olddesc;
2349 ULONG z;
2350 UCHAR *pd = (UCHAR *)pdata;
2352 oldremap = inl (padapter->regRemap); // save values to restore later
2353 olddesc = inb_p (padapter->regDesc);
2355 outl (base | 1, padapter->regRemap); // remap to Flash space as specified
2356 outb_p (0x40, padapter->regDesc); // describe remap region as 8 bit
2357 for ( z = 0; z < length; z++) // get "length" data count
2358 *pd++ = inb_p (padapter->regBase + z); // read in the data
2360 outl (oldremap, padapter->regRemap); // restore remap register values
2361 outb_p (olddesc, padapter->regDesc);
2363 /****************************************************************
2364 * Name: GetRegs
2366 * Description: Initialize the regester information.
2368 * Parameters: pshost - Pointer to SCSI host data structure.
2369 * bigd - PCI-2240I identifier
2370 * pcidev - Pointer to device data structure.
2372 * Returns: TRUE if failure to install.
2374 ****************************************************************/
2375 static USHORT GetRegs (struct Scsi_Host *pshost, BOOL bigd, struct pci_dev *pcidev)
2377 PADAPTER2220I padapter;
2378 int setirq;
2379 int z;
2380 USHORT zr, zl;
2381 UCHAR *consistent;
2382 dma_addr_t consistentDma;
2384 padapter = HOSTDATA(pshost);
2385 memset (padapter, 0, sizeof (ADAPTER2220I));
2386 memset (&DaleSetup, 0, sizeof (DaleSetup));
2387 memset (DiskMirror, 0, sizeof (DiskMirror));
2389 zr = pci_resource_start (pcidev, 1);
2390 zl = pci_resource_start (pcidev, 2);
2392 padapter->basePort = zr;
2393 padapter->regRemap = zr + RTR_LOCAL_REMAP; // 32 bit local space remap
2394 padapter->regDesc = zr + RTR_REGIONS; // 32 bit local region descriptor
2395 padapter->regRange = zr + RTR_LOCAL_RANGE; // 32 bit local range
2396 padapter->regIrqControl = zr + RTR_INT_CONTROL_STATUS; // 16 bit interupt control and status
2397 padapter->regScratchPad = zr + RTR_MAILBOX; // 16 byte scratchpad I/O base address
2399 padapter->regBase = zl;
2400 padapter->regData = zl + REG_DATA; // data register I/O address
2401 padapter->regError = zl + REG_ERROR; // error register I/O address
2402 padapter->regSectCount = zl + REG_SECTOR_COUNT; // sector count register I/O address
2403 padapter->regLba0 = zl + REG_LBA_0; // least significant byte of LBA
2404 padapter->regLba8 = zl + REG_LBA_8; // next least significant byte of LBA
2405 padapter->regLba16 = zl + REG_LBA_16; // next most significan byte of LBA
2406 padapter->regLba24 = zl + REG_LBA_24; // head and most 4 significant bits of LBA
2407 padapter->regStatCmd = zl + REG_STAT_CMD; // status on read and command on write register
2408 padapter->regStatSel = zl + REG_STAT_SEL; // board status on read and spigot select on write register
2409 padapter->regFail = zl + REG_FAIL;
2410 padapter->regAltStat = zl + REG_ALT_STAT;
2411 padapter->pcidev = pcidev;
2413 if ( bigd )
2415 padapter->regDmaDesc = zr + RTR_DMA0_DESC_PTR; // address of the DMA discriptor register for direction of transfer
2416 padapter->regDmaCmdStat = zr + RTR_DMA_COMMAND_STATUS; // Byte #0 of DMA command status register
2417 padapter->regDmaAddrPci = zr + RTR_DMA0_PCI_ADDR; // 32 bit register for PCI address of DMA
2418 padapter->regDmaAddrLoc = zr + RTR_DMA0_LOCAL_ADDR; // 32 bit register for local bus address of DMA
2419 padapter->regDmaCount = zr + RTR_DMA0_COUNT; // 32 bit register for DMA transfer count
2420 padapter->regDmaMode = zr + RTR_DMA0_MODE + 1; // 32 bit register for DMA mode control
2421 padapter->bigD = SEL_NEW_SPEED_1; // set spigot speed control bit
2423 else
2425 padapter->regDmaDesc = zl + RTL_DMA1_DESC_PTR; // address of the DMA discriptor register for direction of transfer
2426 padapter->regDmaCmdStat = zl + RTL_DMA_COMMAND_STATUS + 1; // Byte #1 of DMA command status register
2427 padapter->regDmaAddrPci = zl + RTL_DMA1_PCI_ADDR; // 32 bit register for PCI address of DMA
2428 padapter->regDmaAddrLoc = zl + RTL_DMA1_LOCAL_ADDR; // 32 bit register for local bus address of DMA
2429 padapter->regDmaCount = zl + RTL_DMA1_COUNT; // 32 bit register for DMA transfer count
2430 padapter->regDmaMode = zl + RTL_DMA1_MODE + 1; // 32 bit register for DMA mode control
2433 padapter->numberOfDrives = inb_p (padapter->regScratchPad + BIGD_NUM_DRIVES);
2434 if ( !bigd && !padapter->numberOfDrives ) // if no devices on this board
2435 return TRUE;
2437 pshost->irq = pcidev->irq;
2438 setirq = 1;
2439 for ( z = 0; z < Installed; z++ ) // scan for shared interrupts
2441 if ( PsiHost[z]->irq == pshost->irq ) // if shared then, don't posses
2442 setirq = 0;
2444 if ( setirq ) // if not shared, posses
2446 if ( request_irq (pshost->irq, Irq_Handler, SA_SHIRQ, "pci2220i", padapter) < 0 )
2448 if ( request_irq (pshost->irq, Irq_Handler, SA_INTERRUPT | SA_SHIRQ, "pci2220i", padapter) < 0 )
2450 printk ("Unable to allocate IRQ for PCI-2220I controller.\n");
2451 return TRUE;
2454 padapter->irqOwned = pshost->irq; // set IRQ as owned
2457 if ( padapter->numberOfDrives )
2458 consistent = pci_alloc_consistent (pcidev, SECTORSXFER * BYTES_PER_SECTOR, &consistentDma);
2459 else
2460 consistent = pci_alloc_consistent (pcidev, ATAPI_TRANSFER, &consistentDma);
2461 if ( !consistent )
2463 printk ("Unable to allocate DMA buffer for PCI-2220I controller.\n");
2464 free_irq (pshost->irq, padapter);
2465 return TRUE;
2467 padapter->kBuffer = consistent;
2468 padapter->kBufferDma = consistentDma;
2470 PsiHost[Installed] = pshost; // save SCSI_HOST pointer
2471 pshost->io_port = padapter->basePort;
2472 pshost->n_io_port = 0xFF;
2473 pshost->unique_id = padapter->regBase;
2475 outb_p (0x01, padapter->regRange); // fix our range register because other drivers want to tromp on it
2477 padapter->timingMode = inb_p (padapter->regScratchPad + DALE_TIMING_MODE);
2478 if ( padapter->timingMode >= 2 )
2480 if ( bigd )
2481 padapter->timingAddress = ModeArray2[padapter->timingMode - 2];
2482 else
2483 padapter->timingAddress = ModeArray[padapter->timingMode - 2];
2485 else
2486 padapter->timingPIO = TRUE;
2488 ReadFlash (padapter, &DaleSetup, DALE_FLASH_SETUP, sizeof (SETUP));
2489 ReadFlash (padapter, &DiskMirror, DALE_FLASH_RAID, sizeof (DiskMirror));
2491 return FALSE;
2493 /****************************************************************
2494 * Name: SetupFinish
2496 * Description: Complete the driver initialization process for a card
2498 * Parameters: padapter - Pointer to SCSI host data structure.
2499 * str - Pointer to board type string.
2501 * Returns: Nothing.
2503 ****************************************************************/
2504 VOID SetupFinish (PADAPTER2220I padapter, char *str, int irq)
2506 init_timer (&padapter->timer);
2507 padapter->timer.function = TimerExpiry;
2508 padapter->timer.data = (unsigned long)padapter;
2509 init_timer (&padapter->reconTimer);
2510 padapter->reconTimer.function = ReconTimerExpiry;
2511 padapter->reconTimer.data = (unsigned long)padapter;
2512 printk("\nPCI-%sI EIDE CONTROLLER: at I/O = %lX/%lX IRQ = %d\n", str, padapter->basePort, padapter->regBase, irq);
2513 printk("Version %s, Compiled %s %s\n\n", PCI2220I_VERSION, __DATE__, __TIME__);
2515 /****************************************************************
2516 * Name: Pci2220i_Detect
2518 * Description: Detect and initialize our boards.
2520 * Parameters: tpnt - Pointer to SCSI host template structure.
2522 * Returns: Number of adapters installed.
2524 ****************************************************************/
2525 int Pci2220i_Detect (Scsi_Host_Template *tpnt)
2527 struct Scsi_Host *pshost;
2528 PADAPTER2220I padapter;
2529 POUR_DEVICE pdev;
2530 int unit;
2531 int z;
2532 USHORT raidon;
2533 UCHAR spigot1, spigot2;
2534 UCHAR device;
2535 struct pci_dev *pcidev = NULL;
2537 if ( !pci_present () )
2539 printk ("pci2220i: PCI BIOS not present\n");
2540 return 0;
2543 while ( (pcidev = pci_find_device (VENDOR_PSI, DEVICE_DALE_1, pcidev)) != NULL )
2545 if (pci_enable_device(pcidev))
2546 continue;
2547 pshost = scsi_register (tpnt, sizeof(ADAPTER2220I));
2548 if(pshost==NULL)
2549 continue;
2551 padapter = HOSTDATA(pshost);
2553 if ( GetRegs (pshost, FALSE, pcidev) )
2554 goto unregister;
2556 pshost->max_id = padapter->numberOfDrives;
2557 for ( z = 0; z < padapter->numberOfDrives; z++ )
2559 unit = inb_p (padapter->regScratchPad + DALE_CHANNEL_DEVICE_0 + z) & 0x0F;
2560 pdev = &padapter->device[z];
2561 pdev->byte6 = (UCHAR)(((unit & 1) << 4) | 0xE0);
2562 pdev->spigot = (UCHAR)(1 << (unit >> 1));
2563 pdev->sectors = DaleSetup.setupDevice[unit].sectors;
2564 pdev->heads = DaleSetup.setupDevice[unit].heads;
2565 pdev->cylinders = DaleSetup.setupDevice[unit].cylinders;
2566 pdev->blocks = DaleSetup.setupDevice[unit].blocks;
2568 if ( !z )
2570 DiskMirror[0].status = inb_p (padapter->regScratchPad + DALE_RAID_0_STATUS);
2571 DiskMirror[1].status = inb_p (padapter->regScratchPad + DALE_RAID_1_STATUS);
2572 if ( (DiskMirror[0].signature == SIGNATURE) && (DiskMirror[1].signature == SIGNATURE) &&
2573 (DiskMirror[0].pairIdentifier == (DiskMirror[1].pairIdentifier ^ 1)) )
2575 raidon = TRUE;
2576 if ( unit > (unit ^ 2) )
2577 unit = unit ^ 2;
2579 else
2580 raidon = FALSE;
2582 memcpy (pdev->DiskMirror, DiskMirror, sizeof (DiskMirror));
2583 padapter->raidData[0] = &pdev->DiskMirror[0];
2584 padapter->raidData[2] = &pdev->DiskMirror[1];
2586 spigot1 = spigot2 = FALSE;
2587 pdev->spigots[0] = 1;
2588 pdev->spigots[1] = 2;
2589 pdev->lastsectorlba[0] = InlineIdentify (padapter, 1, 0);
2590 pdev->lastsectorlba[1] = InlineIdentify (padapter, 2, 0);
2592 if ( !(pdev->DiskMirror[1].status & UCBF_SURVIVOR) && pdev->lastsectorlba[0] )
2593 spigot1 = TRUE;
2594 if ( !(pdev->DiskMirror[0].status & UCBF_SURVIVOR) && pdev->lastsectorlba[1] )
2595 spigot2 = TRUE;
2596 if ( pdev->DiskMirror[0].status & DiskMirror[1].status & UCBF_SURVIVOR )
2597 spigot1 = TRUE;
2599 if ( spigot1 && (pdev->DiskMirror[0].status & UCBF_REBUILD) )
2600 InlineReadSignature (padapter, pdev, 0);
2601 if ( spigot2 && (pdev->DiskMirror[1].status & UCBF_REBUILD) )
2602 InlineReadSignature (padapter, pdev, 1);
2604 if ( spigot1 && spigot2 && raidon )
2606 pdev->raid = 1;
2607 if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
2608 pdev->spigot = 2;
2609 else
2610 pdev->spigot = 1;
2611 if ( (pdev->DiskMirror[0].status & UCBF_REBUILD) || (pdev->DiskMirror[1].status & UCBF_REBUILD) )
2612 padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
2614 else
2616 if ( spigot1 )
2618 if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
2619 goto unregister;
2620 pdev->DiskMirror[0].status = UCBF_MIRRORED | UCBF_SURVIVOR;
2621 pdev->spigot = 1;
2623 else
2625 if ( pdev->DiskMirror[1].status & UCBF_REBUILD )
2626 goto unregister;
2627 pdev->DiskMirror[1].status = UCBF_MIRRORED | UCBF_SURVIVOR;
2628 pdev->spigot = 2;
2630 if ( DaleSetup.rebootRebuild && raidon )
2631 padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
2634 if ( raidon )
2635 break;
2639 SetupFinish (padapter, "2220", pshost->irq);
2641 if ( ++Installed < MAXADAPTER )
2642 continue;
2643 break;;
2644 unregister:;
2645 scsi_unregister (pshost);
2648 while ( (pcidev = pci_find_device (VENDOR_PSI, DEVICE_BIGD_1, pcidev)) != NULL )
2650 pshost = scsi_register (tpnt, sizeof(ADAPTER2220I));
2651 padapter = HOSTDATA(pshost);
2653 if ( GetRegs (pshost, TRUE, pcidev) )
2654 goto unregister1;
2656 for ( z = 0; z < BIGD_MAXDRIVES; z++ )
2657 DiskMirror[z].status = inb_p (padapter->regScratchPad + BIGD_RAID_0_STATUS + z);
2659 pshost->max_id = padapter->numberOfDrives;
2660 padapter->failRegister = inb_p (padapter->regScratchPad + BIGD_ALARM_IMAGE);
2661 for ( z = 0; z < padapter->numberOfDrives; z++ )
2663 unit = inb_p (padapter->regScratchPad + BIGD_DEVICE_0 + z);
2664 pdev = &padapter->device[z];
2665 pdev->byte6 = (UCHAR)(((unit & 1) << 4) | 0xE0);
2666 pdev->spigot = (UCHAR)(1 << (unit >> 1));
2667 pdev->sectors = DaleSetup.setupDevice[unit].sectors;
2668 pdev->heads = DaleSetup.setupDevice[unit].heads;
2669 pdev->cylinders = DaleSetup.setupDevice[unit].cylinders;
2670 pdev->blocks = DaleSetup.setupDevice[unit].blocks;
2672 if ( (DiskMirror[unit].signature == SIGNATURE) && (DiskMirror[unit ^ 2].signature == SIGNATURE) &&
2673 (DiskMirror[unit].pairIdentifier == (DiskMirror[unit ^ 2].pairIdentifier ^ 1)) )
2675 raidon = TRUE;
2676 if ( unit > (unit ^ 2) )
2677 unit = unit ^ 2;
2679 else
2680 raidon = FALSE;
2682 spigot1 = spigot2 = FALSE;
2683 memcpy (&pdev->DiskMirror[0], &DiskMirror[unit], sizeof (DISK_MIRROR));
2684 memcpy (&pdev->DiskMirror[1], &DiskMirror[unit ^ 2], sizeof (DISK_MIRROR));
2685 padapter->raidData[unit] = &pdev->DiskMirror[0];
2686 padapter->raidData[unit ^ 2] = &pdev->DiskMirror[1];
2687 pdev->spigots[0] = 1 << (unit >> 1);
2688 pdev->spigots[1] = 1 << ((unit ^ 2) >> 1);
2689 pdev->deviceID[0] = unit;
2690 pdev->deviceID[1] = unit ^ 2;
2691 pdev->lastsectorlba[0] = InlineIdentify (padapter, pdev->spigots[0], unit & 1);
2692 pdev->lastsectorlba[1] = InlineIdentify (padapter, pdev->spigots[1], unit & 1);
2694 if ( !(pdev->DiskMirror[1].status & UCBF_SURVIVOR) && pdev->lastsectorlba[0] )
2695 spigot1 = TRUE;
2696 if ( !(pdev->DiskMirror[0].status & UCBF_SURVIVOR) && pdev->lastsectorlba[1] )
2697 spigot2 = TRUE;
2698 if ( pdev->DiskMirror[0].status & pdev->DiskMirror[1].status & UCBF_SURVIVOR )
2699 spigot1 = TRUE;
2701 if ( spigot1 && (pdev->DiskMirror[0].status & UCBF_REBUILD) )
2702 InlineReadSignature (padapter, pdev, 0);
2703 if ( spigot2 && (pdev->DiskMirror[1].status & UCBF_REBUILD) )
2704 InlineReadSignature (padapter, pdev, 1);
2706 if ( spigot1 && spigot2 && raidon )
2708 pdev->raid = 1;
2709 if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
2710 pdev->spigot = pdev->spigots[1];
2711 else
2712 pdev->spigot = pdev->spigots[0];
2713 if ( (pdev->DiskMirror[0].status & UCBF_REBUILD) || (pdev->DiskMirror[1].status & UCBF_REBUILD) )
2714 padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
2716 else
2718 if ( spigot1 )
2720 if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
2721 goto unregister1;
2722 pdev->DiskMirror[0].status = UCBF_MIRRORED | UCBF_SURVIVOR;
2723 pdev->spigot = pdev->spigots[0];
2725 else
2727 if ( pdev->DiskMirror[1].status & UCBF_REBUILD )
2728 goto unregister;
2729 pdev->DiskMirror[1].status = UCBF_MIRRORED | UCBF_SURVIVOR;
2730 pdev->spigot = pdev->spigots[1];
2732 if ( DaleSetup.rebootRebuild && raidon )
2733 padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
2737 if ( !padapter->numberOfDrives ) // If no ATA devices then scan ATAPI
2739 unit = 0;
2740 for ( spigot1 = 0; spigot1 < 4; spigot1++ )
2742 for ( device = 0; device < 2; device++ )
2744 DEB (printk ("\nPCI2242I: scanning for ID %d ", (spigot1 * 2) + device));
2745 pdev = &(padapter->device[(spigot1 * 2) + device]);
2746 pdev->byte6 = 0x0A | (device << 4);
2747 pdev->spigot = 1 << spigot1;
2748 if ( !AtapiReset (padapter, pdev) )
2750 DEB (printk (" Device found "));
2751 if ( !AtapiIdentify (padapter, pdev) )
2753 DEB (printk (" Device verified"));
2754 unit++;
2755 continue;
2758 pdev->spigot = pdev->byte6 = 0;
2762 if ( unit )
2764 padapter->atapi = TRUE;
2765 padapter->timingAddress = DALE_DATA_MODE3;
2766 outw_p (0x0900, padapter->regIrqControl); // Turn our interrupts on
2767 outw_p (0x0C41, padapter->regDmaMode - 1); // setup for 16 bits, ready enabled, done IRQ enabled, no incriment
2768 outb_p (0xFF, padapter->regFail); // all fail lights and alarm off
2769 pshost->max_id = 8;
2772 SetupFinish (padapter, "2240", pshost->irq);
2774 if ( ++Installed < MAXADAPTER )
2775 continue;
2776 break;;
2777 unregister1:;
2778 scsi_unregister (pshost);
2781 NumAdapters = Installed;
2782 return Installed;
2784 /****************************************************************
2785 * Name: Pci2220i_Abort
2787 * Description: Process the Abort command from the SCSI manager.
2789 * Parameters: SCpnt - Pointer to SCSI command structure.
2791 * Returns: Allways snooze.
2793 ****************************************************************/
2794 int Pci2220i_Abort (Scsi_Cmnd *SCpnt)
2796 PADAPTER2220I padapter = HOSTDATA(SCpnt->host); // Pointer to adapter control structure
2797 POUR_DEVICE pdev = &padapter->device[SCpnt->target];// Pointer to device information
2799 if ( !padapter->SCpnt )
2800 return SCSI_ABORT_NOT_RUNNING;
2802 if ( padapter->atapi )
2804 if ( AtapiReset (padapter, pdev) )
2805 return SCSI_ABORT_ERROR;
2806 OpDone (padapter, DID_ABORT << 16);
2807 return SCSI_ABORT_SUCCESS;
2809 return SCSI_ABORT_SNOOZE;
2811 /****************************************************************
2812 * Name: Pci2220i_Reset
2814 * Description: Process the Reset command from the SCSI manager.
2816 * Parameters: SCpnt - Pointer to SCSI command structure.
2817 * flags - Flags about the reset command
2819 * Returns: No active command at this time, so this means
2820 * that each time we got some kind of response the
2821 * last time through. Tell the mid-level code to
2822 * request sense information in order to decide what
2823 * to do next.
2825 ****************************************************************/
2826 int Pci2220i_Reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
2828 PADAPTER2220I padapter = HOSTDATA(SCpnt->host); // Pointer to adapter control structure
2829 POUR_DEVICE pdev = &padapter->device[SCpnt->target];// Pointer to device information
2831 if ( padapter->atapi )
2833 if ( AtapiReset (padapter, pdev) )
2834 return SCSI_RESET_ERROR;
2835 return SCSI_RESET_SUCCESS;
2837 return SCSI_RESET_PUNT;
2839 /****************************************************************
2840 * Name: Pci2220i_Release
2842 * Description: Release resources allocated for a single each adapter.
2844 * Parameters: pshost - Pointer to SCSI command structure.
2846 * Returns: zero.
2848 ****************************************************************/
2849 int Pci2220i_Release (struct Scsi_Host *pshost)
2851 PADAPTER2220I padapter = HOSTDATA (pshost);
2852 USHORT z;
2854 if ( padapter->reconOn )
2856 padapter->reconOn = FALSE; // shut down the hot reconstruct
2857 if ( padapter->reconPhase )
2858 udelay (300000);
2859 if ( padapter->reconTimer.data ) // is the timer running?
2861 del_timer (&padapter->reconTimer);
2862 padapter->reconTimer.data = 0;
2866 // save RAID status on the board
2867 if ( padapter->bigD )
2869 outb_p (padapter->failRegister, padapter->regScratchPad + BIGD_ALARM_IMAGE);
2870 for ( z = 0; z < BIGD_MAXDRIVES; z++ )
2872 if ( padapter->raidData )
2873 outb_p (padapter->raidData[z]->status, padapter->regScratchPad + BIGD_RAID_0_STATUS + z);
2874 else
2875 outb_p (0, padapter->regScratchPad + BIGD_RAID_0_STATUS);
2878 else
2880 outb_p (padapter->device[0].DiskMirror[0].status, padapter->regScratchPad + DALE_RAID_0_STATUS);
2881 outb_p (padapter->device[0].DiskMirror[1].status, padapter->regScratchPad + DALE_RAID_1_STATUS);
2884 if ( padapter->irqOwned )
2885 free_irq (pshost->irq, padapter);
2886 release_region (pshost->io_port, pshost->n_io_port);
2887 if ( padapter->numberOfDrives )
2888 pci_free_consistent (padapter->pcidev, SECTORSXFER * BYTES_PER_SECTOR, padapter->kBuffer, padapter->kBufferDma);
2889 else
2890 pci_free_consistent (padapter->pcidev, ATAPI_TRANSFER, padapter->kBuffer, padapter->kBufferDma);
2891 scsi_unregister(pshost);
2892 return 0;
2895 #include "sd.h"
2897 /****************************************************************
2898 * Name: Pci2220i_BiosParam
2900 * Description: Process the biosparam request from the SCSI manager to
2901 * return C/H/S data.
2903 * Parameters: disk - Pointer to SCSI disk structure.
2904 * dev - Major/minor number from kernel.
2905 * geom - Pointer to integer array to place geometry data.
2907 * Returns: zero.
2909 ****************************************************************/
2910 int Pci2220i_BiosParam (Scsi_Disk *disk, kdev_t dev, int geom[])
2912 POUR_DEVICE pdev;
2914 if ( !(HOSTDATA(disk->device->host))->atapi )
2916 pdev = &(HOSTDATA(disk->device->host)->device[disk->device->id]);
2918 geom[0] = pdev->heads;
2919 geom[1] = pdev->sectors;
2920 geom[2] = pdev->cylinders;
2922 return 0;
2926 /* Eventually this will go into an include file, but this will be later */
2927 static Scsi_Host_Template driver_template = PCI2220I;
2929 #include "scsi_module.c"