pci2220i.c
上传用户:lgb322
上传日期:2013-02-24
资源大小:30529k
文件大小:90k
源码类别:

嵌入式Linux

开发平台:

Unix_Linux

  1. /****************************************************************************
  2.  * Perceptive Solutions, Inc. PCI-2220I device driver for Linux.
  3.  *
  4.  * pci2220i.c - Linux Host Driver for PCI-2220I EIDE RAID Adapters
  5.  *
  6.  * Copyright (c) 1997-1999 Perceptive Solutions, Inc.
  7.  * All Rights Reserved.
  8.  *
  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.
  13.  *
  14.  * Technical updates and product information at:
  15.  *  http://www.psidisk.com
  16.  *
  17.  * Please send questions, comments, bug reports to:
  18.  *  tech@psidisk.com Technical Support
  19.  *
  20.  *
  21.  * Revisions 1.10 Mar-26-1999
  22.  * - Updated driver for RAID and hot reconstruct support.
  23.  *
  24.  * Revisions 1.11 Mar-26-1999
  25.  * - Fixed spinlock and PCI configuration.
  26.  *
  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
  31.  *
  32.  * Revision 2.10 March-27-2000
  33.  * - Added support for dynamic DMA
  34.  *
  35.  ****************************************************************************/
  36. //#define DEBUG 1
  37. #include <linux/module.h>
  38. #include <linux/kernel.h>
  39. #include <linux/types.h>
  40. #include <linux/string.h>
  41. #include <linux/slab.h>
  42. #include <linux/pci.h>
  43. #include <linux/ioport.h>
  44. #include <linux/delay.h>
  45. #include <linux/sched.h>
  46. #include <linux/proc_fs.h>
  47. #include <linux/stat.h>
  48. #include <linux/kdev_t.h>
  49. #include <linux/blk.h>
  50. #include <linux/timer.h>
  51. #include <linux/spinlock.h>
  52. #include <asm/dma.h>
  53. #include <asm/system.h>
  54. #include <asm/io.h>
  55. #include "scsi.h"
  56. #include "hosts.h"
  57. #include "pci2220i.h"
  58. #include "psi_dale.h"
  59. #define PCI2220I_VERSION "2.10"
  60. #define READ_CMD IDE_CMD_READ_MULTIPLE
  61. #define WRITE_CMD IDE_CMD_WRITE_MULTIPLE
  62. #define MAX_BUS_MASTER_BLOCKS SECTORSXFER // This is the maximum we can bus master
  63. #ifdef DEBUG
  64. #define DEB(x) x
  65. #define STOP_HERE() {int st;for(st=0;st<100;st++){st=1;}}
  66. #else
  67. #define DEB(x)
  68. #define STOP_HERE()
  69. #endif
  70. #define MAXADAPTER 4 // Increase this and the sizes of the arrays below, if you need more.
  71. typedef struct
  72. {
  73. UCHAR byte6; // device select register image
  74. UCHAR spigot; // spigot number
  75. UCHAR spigots[2]; // RAID spigots
  76. UCHAR deviceID[2]; // device ID codes
  77. USHORT sectors; // number of sectors per track
  78. USHORT heads; // number of heads
  79. USHORT cylinders; // number of cylinders for this device
  80. USHORT spareword; // placeholder
  81. ULONG blocks; // number of blocks on device
  82. DISK_MIRROR DiskMirror[2]; // RAID status and control
  83. ULONG lastsectorlba[2]; // last addressable sector on the drive
  84. USHORT raid; // RAID active flag
  85. USHORT mirrorRecon;
  86. UCHAR reconOn;
  87. USHORT reconCount;
  88. USHORT reconIsStarting; // indicate hot reconstruct is starting
  89. UCHAR cmdDrqInt; // flag for command interrupt
  90. UCHAR packet; // command packet size in bytes
  91. } OUR_DEVICE, *POUR_DEVICE;
  92. typedef struct
  93. {
  94. USHORT  bigD; // identity is a PCI-2240I if true, otherwise a PCI-2220I
  95. USHORT  atapi; // this interface is for ATAPI devices only
  96. ULONG  regDmaDesc; // address of the DMA discriptor register for direction of transfer
  97. ULONG  regDmaCmdStat; // Byte #1 of DMA command status register
  98. ULONG  regDmaAddrPci; // 32 bit register for PCI address of DMA
  99. ULONG  regDmaAddrLoc; // 32 bit register for local bus address of DMA
  100. ULONG  regDmaCount; // 32 bit register for DMA transfer count
  101. ULONG  regDmaMode; // 32 bit register for DMA mode control
  102. ULONG  regRemap; // 32 bit local space remap
  103. ULONG  regDesc; // 32 bit local region descriptor
  104. ULONG  regRange; // 32 bit local range
  105. ULONG  regIrqControl; // 16 bit Interrupt enable/disable and status
  106. ULONG  regScratchPad; // scratch pad I/O base address
  107. ULONG  regBase; // Base I/O register for data space
  108. ULONG  regData; // data register I/O address
  109. ULONG  regError; // error register I/O address
  110. ULONG  regSectCount; // sector count register I/O address
  111. ULONG  regLba0; // least significant byte of LBA
  112. ULONG  regLba8; // next least significant byte of LBA
  113. ULONG  regLba16; // next most significan byte of LBA
  114. ULONG  regLba24; // head and most 4 significant bits of LBA
  115. ULONG  regStatCmd; // status on read and command on write register
  116. ULONG  regStatSel; // board status on read and spigot select on write register
  117. ULONG  regFail; // fail bits control register
  118. ULONG  regAltStat; // alternate status and drive control register
  119. ULONG  basePort; // PLX base I/O port
  120. USHORT  timingMode; // timing mode currently set for adapter
  121. USHORT  timingPIO; // TRUE if PIO timing is active
  122. struct pci_dev *pcidev;
  123. ULONG  timingAddress; // address to use on adapter for current timing mode
  124. ULONG  irqOwned; // owned IRQ or zero if shared
  125. UCHAR  numberOfDrives; // saved number of drives on this controller
  126. UCHAR  failRegister; // current inverted data in fail register
  127. OUR_DEVICE  device[BIGD_MAXDRIVES];
  128. DISK_MIRROR *raidData[BIGD_MAXDRIVES];
  129. ULONG  startSector;
  130. USHORT  sectorCount;
  131. ULONG  readCount;
  132. UCHAR *currentSgBuffer;
  133. ULONG  currentSgCount;
  134. USHORT  nextSg;
  135. UCHAR  cmd;
  136. Scsi_Cmnd *SCpnt;
  137. POUR_DEVICE  pdev; // current device opearating on
  138. USHORT  devInReconIndex;
  139. USHORT  expectingIRQ;
  140. USHORT  reconOn; // Hot reconstruct is to be done.
  141. USHORT  reconPhase; // Hot reconstruct operation is in progress.
  142. ULONG  reconSize;
  143. USHORT  demoFail; // flag for RAID failure demonstration
  144. USHORT  survivor;
  145. USHORT  failinprog;
  146. struct timer_list reconTimer;
  147. struct timer_list timer;
  148. UCHAR *kBuffer;
  149. dma_addr_t  kBufferDma;
  150. UCHAR  reqSense;
  151. UCHAR  atapiCdb[16];
  152. UCHAR  atapiSpecial;
  153. } ADAPTER2220I, *PADAPTER2220I;
  154. #define HOSTDATA(host) ((PADAPTER2220I)&host->hostdata)
  155. #define RECON_PHASE_READY 0x01
  156. #define RECON_PHASE_COPY 0x02
  157. #define RECON_PHASE_UPDATE 0x03
  158. #define RECON_PHASE_LAST 0x04
  159. #define RECON_PHASE_END 0x07
  160. #define RECON_PHASE_MARKING 0x80
  161. #define RECON_PHASE_FAILOVER 0xFF
  162. static struct Scsi_Host     *PsiHost[MAXADAPTER] = {NULL,};  // One for each adapter
  163. static int NumAdapters = 0;
  164. static int Installed = 0;
  165. static SETUP DaleSetup;
  166. static DISK_MIRROR DiskMirror[BIGD_MAXDRIVES];
  167. static ULONG ModeArray[] = {DALE_DATA_MODE2, DALE_DATA_MODE3, DALE_DATA_MODE4, DALE_DATA_MODE5};
  168. static ULONG ModeArray2[] = {BIGD_DATA_MODE2, BIGD_DATA_MODE3, BIGD_DATA_MODE4, BIGD_DATA_MODE5};
  169. static void ReconTimerExpiry (unsigned long data);
  170. /*******************************************************************************************************
  171.  * Name: Alarm
  172.  *
  173.  * Description: Sound the for the given device
  174.  *
  175.  * Parameters: padapter - Pointer adapter data structure.
  176.  * device  - Device number.
  177.  *
  178.  * Returns: Nothing.
  179.  *
  180.  ******************************************************************************************************/
  181. static void Alarm (PADAPTER2220I padapter, UCHAR device)
  182. {
  183. UCHAR zc;
  184. if ( padapter->bigD )
  185. {
  186. zc = device | (FAIL_ANY | FAIL_AUDIBLE);
  187. if ( padapter->failRegister & FAIL_ANY ) 
  188. zc |= FAIL_MULTIPLE;
  189. padapter->failRegister = zc;
  190. outb_p (~zc, padapter->regFail);
  191. }
  192. else
  193. outb_p (0x3C | (1 << device), padapter->regFail); // sound alarm and set fail light
  194. }
  195. /****************************************************************
  196.  * Name: MuteAlarm :LOCAL
  197.  *
  198.  * Description: Mute the audible alarm.
  199.  *
  200.  * Parameters: padapter - Pointer adapter data structure.
  201.  *
  202.  * Returns: TRUE if drive does not assert DRQ in time.
  203.  *
  204.  ****************************************************************/
  205. static void MuteAlarm (PADAPTER2220I padapter)
  206. {
  207. UCHAR old;
  208. if ( padapter->bigD )
  209. {
  210. padapter->failRegister &= ~FAIL_AUDIBLE;
  211. outb_p (~padapter->failRegister, padapter->regFail);
  212. }
  213. else
  214. {
  215. old = (inb_p (padapter->regStatSel) >> 3) | (inb_p (padapter->regStatSel) & 0x83);
  216. outb_p (old | 0x40, padapter->regFail);
  217. }
  218. }
  219. /****************************************************************
  220.  * Name: WaitReady :LOCAL
  221.  *
  222.  * Description: Wait for device ready.
  223.  *
  224.  * Parameters: padapter - Pointer adapter data structure.
  225.  *
  226.  * Returns: TRUE if drive does not assert DRQ in time.
  227.  *
  228.  ****************************************************************/
  229. static int WaitReady (PADAPTER2220I padapter)
  230. {
  231. ULONG z;
  232. UCHAR status;
  233. for ( z = 0;  z < (TIMEOUT_READY * 4);  z++ )
  234. {
  235. status = inb_p (padapter->regStatCmd);
  236. if ( (status & (IDE_STATUS_DRDY | IDE_STATUS_BUSY)) == IDE_STATUS_DRDY )
  237. return 0;
  238. udelay (250);
  239. }
  240. return status;
  241. }
  242. /****************************************************************
  243.  * Name: WaitReadyReset :LOCAL
  244.  *
  245.  * Description: Wait for device ready.
  246.  *
  247.  * Parameters: padapter - Pointer adapter data structure.
  248.  *
  249.  * Returns: TRUE if drive does not assert DRQ in time.
  250.  *
  251.  ****************************************************************/
  252. static int WaitReadyReset (PADAPTER2220I padapter)
  253. {
  254. ULONG z;
  255. UCHAR status;
  256. for ( z = 0;  z < (125 * 16);  z++ ) // wait up to 1/4 second
  257. {
  258. status = inb_p (padapter->regStatCmd);
  259. if ( (status & (IDE_STATUS_DRDY | IDE_STATUS_BUSY)) == IDE_STATUS_DRDY )
  260. {
  261. DEB (printk ("nPCI2220I:  Reset took %ld mSec to be ready", z / 8));
  262. return 0;
  263. }
  264. udelay (125);
  265. }
  266. DEB (printk ("nPCI2220I:  Reset took more than 2 Seconds to come ready, Disk Failure"));
  267. return status;
  268. }
  269. /****************************************************************
  270.  * Name: WaitDrq :LOCAL
  271.  *
  272.  * Description: Wait for device ready for data transfer.
  273.  *
  274.  * Parameters: padapter - Pointer adapter data structure.
  275.  *
  276.  * Returns: TRUE if drive does not assert DRQ in time.
  277.  *
  278.  ****************************************************************/
  279. static int WaitDrq (PADAPTER2220I padapter)
  280. {
  281. ULONG z;
  282. UCHAR status;
  283. for ( z = 0;  z < (TIMEOUT_DRQ * 4);  z++ )
  284. {
  285. status = inb_p (padapter->regStatCmd);
  286. if ( status & IDE_STATUS_DRQ )
  287. return 0;
  288. udelay (250);
  289. }
  290. return status;
  291. }
  292. /****************************************************************
  293.  * Name: AtapiWaitReady :LOCAL
  294.  *
  295.  * Description: Wait for device busy and DRQ to be cleared.
  296.  *
  297.  * Parameters: padapter - Pointer adapter data structure.
  298.  * msec  - Number of milliseconds to wait.
  299.  *
  300.  * Returns: TRUE if drive does not clear busy in time.
  301.  *
  302.  ****************************************************************/
  303. static int AtapiWaitReady (PADAPTER2220I padapter, int msec)
  304. {
  305. int z;
  306. for ( z = 0;  z < (msec * 16);  z++ )
  307. {
  308. if ( !(inb_p (padapter->regStatCmd) & (IDE_STATUS_BUSY | IDE_STATUS_DRQ)) )
  309. return FALSE;
  310. udelay (125);
  311. }
  312. return TRUE;
  313. }
  314. /****************************************************************
  315.  * Name: AtapiWaitDrq :LOCAL
  316.  *
  317.  * Description: Wait for device ready for data transfer.
  318.  *
  319.  * Parameters: padapter - Pointer adapter data structure.
  320.  * msec  - Number of milliseconds to wait.
  321.  *
  322.  * Returns: TRUE if drive does not assert DRQ in time.
  323.  *
  324.  ****************************************************************/
  325. static int AtapiWaitDrq (PADAPTER2220I padapter, int msec)
  326. {
  327. ULONG z;
  328. for ( z = 0;  z < (msec * 16);  z++ )
  329. {
  330. if ( inb_p (padapter->regStatCmd) & IDE_STATUS_DRQ )
  331. return 0;
  332. udelay (128);
  333. }
  334. return TRUE;
  335. }
  336. /****************************************************************
  337.  * Name: HardReset :LOCAL
  338.  *
  339.  * Description: Wait for device ready for data transfer.
  340.  *
  341.  * Parameters: padapter - Pointer adapter data structure.
  342.  * pdev  - Pointer to device.
  343.  * spigot  - Spigot number.
  344.  *
  345.  * Returns: TRUE if drive does not assert DRQ in time.
  346.  *
  347.  ****************************************************************/
  348. static int HardReset (PADAPTER2220I padapter, POUR_DEVICE pdev, UCHAR spigot)
  349. {
  350. DEB (printk ("npci2220i:RESET  spigot = %X  devices = %d, %d", spigot, pdev->deviceID[0], pdev->deviceID[1]));
  351. mdelay (100); // just wait 100 mSec to let drives flush
  352. SelectSpigot (padapter, spigot | SEL_IRQ_OFF);
  353. outb_p (0x0E, padapter->regAltStat); // reset the suvivor
  354. udelay (100); // wait a little
  355. outb_p (0x08, padapter->regAltStat); // clear the reset
  356. udelay (100);
  357. outb_p (0xA0, padapter->regLba24); // select the master drive
  358. if ( WaitReadyReset (padapter) )
  359. {
  360. DEB (printk ("npci2220i: master not ready after reset"));
  361. return TRUE;
  362. }
  363. outb_p (0xB0, padapter->regLba24); // try the slave drive
  364. if ( (inb_p (padapter->regStatCmd) & (IDE_STATUS_DRDY | IDE_STATUS_BUSY)) == IDE_STATUS_DRDY ) 
  365. {
  366. DEB (printk ("nPCI2220I: initializing slave drive on spigot %X", spigot));
  367. outb_p (SECTORSXFER, padapter->regSectCount);
  368. WriteCommand (padapter, IDE_CMD_SET_MULTIPLE);
  369. if ( WaitReady (padapter) )
  370. {
  371. DEB (printk ("npci2220i: slave not ready after set multiple"));
  372. return TRUE;
  373. }
  374. }
  375. outb_p (0xA0, padapter->regLba24); // select the drive
  376. outb_p (SECTORSXFER, padapter->regSectCount);
  377. WriteCommand (padapter, IDE_CMD_SET_MULTIPLE);
  378. if ( WaitReady (padapter) )
  379. {
  380. DEB (printk ("npci2220i: master not ready after set multiple"));
  381. return TRUE;
  382. }
  383. return FALSE;
  384. }
  385. /****************************************************************
  386.  * Name: AtapiReset :LOCAL
  387.  *
  388.  * Description: Wait for device ready for data transfer.
  389.  *
  390.  * Parameters: padapter - Pointer adapter data structure.
  391.  * pdev  - Pointer to device.
  392.  *
  393.  * Returns: TRUE if drive does not come ready.
  394.  *
  395.  ****************************************************************/
  396. static int AtapiReset (PADAPTER2220I padapter, POUR_DEVICE pdev)
  397. {
  398. SelectSpigot (padapter, pdev->spigot);
  399. AtapiDevice (padapter, pdev->byte6);
  400. AtapiCountLo (padapter, 0);
  401. AtapiCountHi (padapter, 0);
  402. WriteCommand (padapter, IDE_COMMAND_ATAPI_RESET);
  403. udelay (125);
  404. if ( AtapiWaitReady (padapter, 1000) )
  405. return TRUE;
  406. if ( inb_p (padapter->regStatCmd) || (inb_p (padapter->regLba8) != 0x14) || (inb_p (padapter->regLba16) != 0xEB) )
  407. return TRUE;
  408. return FALSE;
  409. }
  410. /****************************************************************
  411.  * Name: WalkScatGath :LOCAL
  412.  *
  413.  * Description: Transfer data to/from scatter/gather buffers.
  414.  *
  415.  * Parameters: padapter - Pointer adapter data structure.
  416.  * datain   - TRUE if data read.
  417.  * length   - Number of bytes to transfer.
  418.  *
  419.  * Returns: Nothing.
  420.  *
  421.  ****************************************************************/
  422. static void WalkScatGath (PADAPTER2220I padapter, UCHAR datain, ULONG length)
  423. {
  424. ULONG  count;
  425. UCHAR *buffer = padapter->kBuffer;
  426. while ( length )
  427. {
  428. count = ( length > padapter->currentSgCount ) ? padapter->currentSgCount : length; 
  429. if ( datain )
  430. memcpy (padapter->currentSgBuffer, buffer, count);
  431. else
  432. memcpy (buffer, padapter->currentSgBuffer, count);
  433. padapter->currentSgCount -= count;
  434. if ( !padapter->currentSgCount )
  435. {
  436. if ( padapter->nextSg < padapter->SCpnt->use_sg )
  437. {
  438. padapter->currentSgBuffer = ((struct scatterlist *)padapter->SCpnt->request_buffer)[padapter->nextSg].address;
  439. padapter->currentSgCount = ((struct scatterlist *)padapter->SCpnt->request_buffer)[padapter->nextSg].length;
  440. padapter->nextSg++;
  441. }
  442. }
  443. else
  444. padapter->currentSgBuffer += count;
  445. length -= count;
  446. buffer += count;
  447. }
  448. }
  449. /****************************************************************
  450.  * Name: BusMaster :LOCAL
  451.  *
  452.  * Description: Do a bus master I/O.
  453.  *
  454.  * Parameters: padapter - Pointer adapter data structure.
  455.  * datain  - TRUE if data read.
  456.  * irq  - TRUE if bus master interrupt expected.
  457.  *
  458.  * Returns: Nothing.
  459.  *
  460.  ****************************************************************/
  461. static void BusMaster (PADAPTER2220I padapter, UCHAR datain, UCHAR irq)
  462. {
  463. ULONG zl;
  464. zl = ( padapter->sectorCount > MAX_BUS_MASTER_BLOCKS ) ? MAX_BUS_MASTER_BLOCKS : padapter->sectorCount;
  465. padapter->sectorCount -= zl;
  466. zl *= (ULONG)BYTES_PER_SECTOR;
  467. if ( datain )
  468. {
  469. padapter->readCount = zl;
  470. outb_p (8, padapter->regDmaDesc); // read operation
  471. if ( padapter->bigD )
  472. {
  473. if ( irq && !padapter->sectorCount )
  474. outb_p (0x0C, padapter->regDmaMode); // interrupt on
  475. else
  476. outb_p (0x08, padapter->regDmaMode); // no interrupt
  477. }
  478. else 
  479. {
  480. if ( irq && !padapter->sectorCount )
  481. outb_p (0x05, padapter->regDmaMode); // interrupt on
  482. else
  483. outb_p (0x01, padapter->regDmaMode); // no interrupt
  484. }
  485. }
  486. else
  487. {
  488. outb_p (0x00, padapter->regDmaDesc); // write operation
  489. if ( padapter->bigD )
  490. outb_p (0x08, padapter->regDmaMode); // no interrupt
  491. else
  492. outb_p (0x01, padapter->regDmaMode); // no interrupt
  493. WalkScatGath (padapter, FALSE, zl);
  494. }
  495. outl (padapter->timingAddress, padapter->regDmaAddrLoc);
  496. outl (padapter->kBufferDma, padapter->regDmaAddrPci);
  497. outl (zl, padapter->regDmaCount);
  498. outb_p (0x03, padapter->regDmaCmdStat); // kick the DMA engine in gear
  499. }
  500. /****************************************************************
  501.  * Name: AtapiBusMaster :LOCAL
  502.  *
  503.  * Description: Do a bus master I/O.
  504.  *
  505.  * Parameters: padapter - Pointer adapter data structure.
  506.  * datain  - TRUE if data read.
  507.  * length  - Number of bytes to transfer.
  508.  *
  509.  * Returns: Nothing.
  510.  *
  511.  ****************************************************************/
  512. static void AtapiBusMaster (PADAPTER2220I padapter, UCHAR datain, ULONG length)
  513. {
  514. outl (padapter->timingAddress, padapter->regDmaAddrLoc);
  515. outl (padapter->kBufferDma, padapter->regDmaAddrPci);
  516. outl (length, padapter->regDmaCount);
  517. if ( datain )
  518. {
  519. if ( padapter->readCount )
  520. WalkScatGath (padapter, TRUE, padapter->readCount);
  521. outb_p (0x08, padapter->regDmaDesc); // read operation
  522. outb_p (0x08, padapter->regDmaMode); // no interrupt
  523. padapter->readCount = length;
  524. }
  525. else
  526. {
  527. outb_p (0x00, padapter->regDmaDesc); // write operation
  528. outb_p (0x08, padapter->regDmaMode); // no interrupt
  529. if ( !padapter->atapiSpecial )
  530. WalkScatGath (padapter, FALSE, length);
  531. }
  532. outb_p (0x03, padapter->regDmaCmdStat); // kick the DMA engine in gear
  533. }
  534. /****************************************************************
  535.  * Name: WriteData :LOCAL
  536.  *
  537.  * Description: Write data to device.
  538.  *
  539.  * Parameters: padapter - Pointer adapter data structure.
  540.  *
  541.  * Returns: TRUE if drive does not assert DRQ in time.
  542.  *
  543.  ****************************************************************/
  544. static int WriteData (PADAPTER2220I padapter)
  545. {
  546. ULONG zl;
  547. if ( !WaitDrq (padapter) )
  548. {
  549. if ( padapter->timingPIO )
  550. {
  551. zl = (padapter->sectorCount > MAX_BUS_MASTER_BLOCKS) ? MAX_BUS_MASTER_BLOCKS : padapter->sectorCount;
  552. WalkScatGath (padapter, FALSE, zl * BYTES_PER_SECTOR);
  553. outsw (padapter->regData, padapter->kBuffer, zl * (BYTES_PER_SECTOR / 2));
  554. padapter->sectorCount -= zl;
  555. }
  556. else
  557. BusMaster (padapter, 0, 0);
  558. return 0;
  559. }
  560. padapter->cmd = 0; // null out the command byte
  561. return 1;
  562. }
  563. /****************************************************************
  564.  * Name: WriteDataBoth :LOCAL
  565.  *
  566.  * Description: Write data to device.
  567.  *
  568.  * Parameters: padapter - Pointer to adapter structure.
  569.  * pdev  - Pointer to device structure
  570.  *
  571.  * Returns: Index + 1 of drive not failed or zero for OK.
  572.  *
  573.  ****************************************************************/
  574. static int WriteDataBoth (PADAPTER2220I padapter, POUR_DEVICE pdev)
  575. {
  576. ULONG zl;
  577. UCHAR status0, status1;
  578. SelectSpigot (padapter, pdev->spigots[0]);
  579. status0 = WaitDrq (padapter);
  580. if ( !status0 )
  581. {
  582. SelectSpigot (padapter, pdev->spigots[1]);
  583. status1 = WaitDrq (padapter);
  584. if ( !status1 )
  585. {
  586. SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1] | padapter->bigD);
  587. if ( padapter->timingPIO )
  588. {
  589. zl = (padapter->sectorCount > MAX_BUS_MASTER_BLOCKS) ? MAX_BUS_MASTER_BLOCKS : padapter->sectorCount;
  590. WalkScatGath (padapter, FALSE, zl * BYTES_PER_SECTOR);
  591. outsw (padapter->regData, padapter->kBuffer, zl * (BYTES_PER_SECTOR / 2));
  592. padapter->sectorCount -= zl;
  593. }
  594. else
  595. BusMaster (padapter, 0, 0);
  596. return 0;
  597. }
  598. }
  599. padapter->cmd = 0; // null out the command byte
  600. if ( status0 )
  601. return 2;
  602. return 1;
  603. }
  604. /****************************************************************
  605.  * Name: IdeCmd :LOCAL
  606.  *
  607.  * Description: Process an IDE command.
  608.  *
  609.  * Parameters: padapter - Pointer adapter data structure.
  610.  * pdev  - Pointer to device.
  611.  *
  612.  * Returns: Zero if no error or status register contents on error.
  613.  *
  614.  ****************************************************************/
  615. static UCHAR IdeCmd (PADAPTER2220I padapter, POUR_DEVICE pdev)
  616. {
  617. UCHAR status;
  618. SelectSpigot (padapter, pdev->spigot | padapter->bigD); // select the spigot
  619. outb_p (pdev->byte6 | ((UCHAR *)(&padapter->startSector))[3], padapter->regLba24); // select the drive
  620. status = WaitReady (padapter);
  621. if ( !status )
  622. {
  623. outb_p (padapter->sectorCount, padapter->regSectCount);
  624. outb_p (((UCHAR *)(&padapter->startSector))[0], padapter->regLba0);
  625. outb_p (((UCHAR *)(&padapter->startSector))[1], padapter->regLba8);
  626. outb_p (((UCHAR *)(&padapter->startSector))[2], padapter->regLba16);
  627. padapter->expectingIRQ = TRUE;
  628. WriteCommand (padapter, padapter->cmd);
  629. return 0;
  630. }
  631. padapter->cmd = 0; // null out the command byte
  632. return status;
  633. }
  634. /****************************************************************
  635.  * Name: IdeCmdBoth :LOCAL
  636.  *
  637.  * Description: Process an IDE command to both drivers.
  638.  *
  639.  * Parameters: padapter - Pointer adapter data structure.
  640.  * pdev  - Pointer to device structure
  641.  *
  642.  * Returns: Index + 1 of drive not failed or zero for OK.
  643.  *
  644.  ****************************************************************/
  645. static UCHAR IdeCmdBoth (PADAPTER2220I padapter, POUR_DEVICE pdev)
  646. {
  647. UCHAR status0;
  648. UCHAR status1;
  649. SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1]); // select the spigots
  650. outb_p (padapter->pdev->byte6 | ((UCHAR *)(&padapter->startSector))[3], padapter->regLba24);// select the drive
  651. SelectSpigot (padapter, pdev->spigots[0]);
  652. status0 = WaitReady (padapter);
  653. if ( !status0 )
  654. {
  655. SelectSpigot (padapter, pdev->spigots[1]);
  656. status1 = WaitReady (padapter);
  657. if ( !status1 )
  658. {
  659. SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1] | padapter->bigD);
  660. outb_p (padapter->sectorCount, padapter->regSectCount);
  661. outb_p (((UCHAR *)(&padapter->startSector))[0], padapter->regLba0);
  662. outb_p (((UCHAR *)(&padapter->startSector))[1], padapter->regLba8);
  663. outb_p (((UCHAR *)(&padapter->startSector))[2], padapter->regLba16);
  664. padapter->expectingIRQ = TRUE;
  665. WriteCommand (padapter, padapter->cmd);
  666. return 0;
  667. }
  668. }
  669. padapter->cmd = 0; // null out the command byte
  670. if ( status0 )
  671. return 2;
  672. return 1;
  673. }
  674. /****************************************************************
  675.  * Name: OpDone :LOCAL
  676.  *
  677.  * Description: Complete an operatoin done sequence.
  678.  *
  679.  * Parameters: padapter - Pointer to host data block.
  680.  * spigot  - Spigot select code.
  681.  * device  - Device byte code.
  682.  *
  683.  * Returns: Nothing.
  684.  *
  685.  ****************************************************************/
  686. static void OpDone (PADAPTER2220I padapter, ULONG result)
  687. {
  688. Scsi_Cmnd    *SCpnt = padapter->SCpnt;
  689. if ( padapter->reconPhase )
  690. {
  691. padapter->reconPhase = 0;
  692. if ( padapter->SCpnt )
  693. {
  694. Pci2220i_QueueCommand (SCpnt, SCpnt->scsi_done);
  695. }
  696. else
  697. {
  698. if ( padapter->reconOn )
  699. {
  700. ReconTimerExpiry ((unsigned long)padapter);
  701. }
  702. }
  703. }
  704. else
  705. {
  706. padapter->cmd = 0;
  707. padapter->SCpnt = NULL;
  708. padapter->pdev = NULL;
  709. SCpnt->result = result;
  710. SCpnt->scsi_done (SCpnt);
  711. if ( padapter->reconOn && !padapter->reconTimer.data )
  712. {
  713. padapter->reconTimer.expires = jiffies + (HZ / 4); // start in 1/4 second
  714. padapter->reconTimer.data = (unsigned long)padapter;
  715. add_timer (&padapter->reconTimer);
  716. }
  717. }
  718. }
  719. /****************************************************************
  720.  * Name: InlineIdentify :LOCAL
  721.  *
  722.  * Description: Do an intline inquiry on a drive.
  723.  *
  724.  * Parameters: padapter - Pointer to host data block.
  725.  * spigot  - Spigot select code.
  726.  * device  - Device byte code.
  727.  *
  728.  * Returns: Last addressable sector or zero if none.
  729.  *
  730.  ****************************************************************/
  731. static ULONG InlineIdentify (PADAPTER2220I padapter, UCHAR spigot, UCHAR device)
  732. {
  733. PIDENTIFY_DATA pid = (PIDENTIFY_DATA)padapter->kBuffer;
  734. SelectSpigot (padapter, spigot | SEL_IRQ_OFF); // select the spigot
  735. outb_p ((device << 4) | 0xA0, padapter->regLba24); // select the drive
  736. if ( WaitReady (padapter) )
  737. return 0;
  738. WriteCommand (padapter, IDE_COMMAND_IDENTIFY);
  739. if ( WaitDrq (padapter) )
  740. return 0;
  741. insw (padapter->regData, padapter->kBuffer, sizeof (IDENTIFY_DATA) >> 1);
  742. return (pid->LBATotalSectors - 1);
  743. }
  744. /****************************************************************
  745.  * Name: AtapiIdentify :LOCAL
  746.  *
  747.  * Description: Do an intline inquiry on a drive.
  748.  *
  749.  * Parameters: padapter - Pointer to host data block.
  750.  * pdev  - Pointer to device table.
  751.  *
  752.  * Returns: TRUE on error.
  753.  *
  754.  ****************************************************************/
  755. static ULONG AtapiIdentify (PADAPTER2220I padapter, POUR_DEVICE pdev)
  756. {
  757. ATAPI_GENERAL_0 ag0;
  758. USHORT zs;
  759. int z;
  760. AtapiDevice (padapter, pdev->byte6);
  761. WriteCommand (padapter, IDE_COMMAND_ATAPI_IDENTIFY);
  762. if ( AtapiWaitDrq (padapter, 3000) )
  763. return TRUE;
  764. *(USHORT *)&ag0 = inw_p (padapter->regData);
  765. for ( z = 0;  z < 255;  z++ )
  766. zs = inw_p (padapter->regData);
  767. if ( ag0.ProtocolType == 2 )
  768. {
  769. if ( ag0.CmdDrqType == 1 )
  770. pdev->cmdDrqInt = TRUE;
  771. switch ( ag0.CmdPacketSize )
  772. {
  773. case 0:
  774. pdev->packet = 6;
  775. break;
  776. case 1:
  777. pdev->packet = 8;
  778. break;
  779. default:
  780. pdev->packet = 6;
  781. break;
  782. }
  783. return FALSE;
  784. }
  785. return TRUE;
  786. }
  787. /****************************************************************
  788.  * Name: Atapi2Scsi
  789.  *
  790.  * Description: Convert ATAPI data to SCSI data.
  791.  *
  792.  * Parameters: padapter - Pointer adapter data structure.
  793.  * SCpnt  - Pointer to SCSI command structure.
  794.  *
  795.  * Returns: Nothing.
  796.  *
  797.  ****************************************************************/
  798. void Atapi2Scsi (PADAPTER2220I padapter, Scsi_Cmnd *SCpnt)
  799. {
  800. UCHAR *buff = padapter->currentSgBuffer;
  801.  
  802. switch ( SCpnt->cmnd[0] )
  803. {
  804. case SCSIOP_MODE_SENSE:
  805. buff[0] = padapter->kBuffer[1];
  806. buff[1] = padapter->kBuffer[2];
  807. buff[2] = padapter->kBuffer[3];
  808. buff[3] = padapter->kBuffer[7];
  809. memcpy (&buff[4], &padapter->kBuffer[8], padapter->atapiCdb[8] - 8);
  810. break;
  811. case SCSIOP_INQUIRY:
  812. padapter->kBuffer[2] = 2;
  813. memcpy (buff, padapter->kBuffer, padapter->currentSgCount);
  814. break;
  815. default:
  816. if ( padapter->readCount )
  817. WalkScatGath (padapter, TRUE, padapter->readCount);
  818. break;
  819. }
  820. }
  821. /****************************************************************
  822.  * Name: Scsi2Atapi
  823.  *
  824.  * Description: Convert SCSI packet command to Atapi packet command.
  825.  *
  826.  * Parameters: padapter - Pointer adapter data structure.
  827.  * SCpnt  - Pointer to SCSI command structure.
  828.  *
  829.  * Returns: Nothing.
  830.  *
  831.  ****************************************************************/
  832. static void Scsi2Atapi (PADAPTER2220I padapter, Scsi_Cmnd *SCpnt)
  833. {
  834. UCHAR *cdb = SCpnt->cmnd;
  835. UCHAR *buff = padapter->currentSgBuffer;
  836. switch (cdb[0]) 
  837. {
  838. case SCSIOP_READ6:
  839.             padapter->atapiCdb[0] = SCSIOP_READ;
  840. padapter->atapiCdb[1] = cdb[1] & 0xE0;
  841.             padapter->atapiCdb[3] = cdb[1] & 0x1F;
  842. padapter->atapiCdb[4] = cdb[2];
  843. padapter->atapiCdb[5] = cdb[3];
  844. padapter->atapiCdb[8] = cdb[4];
  845. padapter->atapiCdb[9] = cdb[5];
  846. break;
  847. case SCSIOP_WRITE6:
  848.             padapter->atapiCdb[0] = SCSIOP_WRITE;
  849. padapter->atapiCdb[1] = cdb[1] & 0xE0;
  850.             padapter->atapiCdb[3] = cdb[1] & 0x1F;
  851. padapter->atapiCdb[4] = cdb[2];
  852. padapter->atapiCdb[5] = cdb[3];
  853. padapter->atapiCdb[8] = cdb[4];
  854. padapter->atapiCdb[9] = cdb[5];
  855. break;
  856.         case SCSIOP_MODE_SENSE: 
  857.             padapter->atapiCdb[0] = SCSIOP_MODE_SENSE10;
  858. padapter->atapiCdb[2] = cdb[2];
  859. padapter->atapiCdb[8] = cdb[4] + 4;
  860.             break;
  861.         case SCSIOP_MODE_SELECT: 
  862. padapter->atapiSpecial = TRUE;
  863. padapter->atapiCdb[0] = SCSIOP_MODE_SELECT10;
  864. padapter->atapiCdb[1] = cdb[1] | 0x10;
  865. memcpy (padapter->kBuffer, buff, 4);
  866. padapter->kBuffer[4] = padapter->kBuffer[5] = 0;
  867. padapter->kBuffer[6] = padapter->kBuffer[7] = 0;
  868. memcpy (&padapter->kBuffer[8], &buff[4], cdb[4] - 4);
  869. padapter->atapiCdb[8] = cdb[4] + 4;
  870. break;
  871.     }
  872. }
  873. /****************************************************************
  874.  * Name: AtapiSendCdb
  875.  *
  876.  * Description: Send the CDB packet to the device.
  877.  *
  878.  * Parameters: padapter - Pointer adapter data structure.
  879.  * pdev  - Pointer to device.
  880.  * cdb  - Pointer to 16 byte SCSI cdb.
  881.  *
  882.  * Returns: Nothing.
  883.  *
  884.  ****************************************************************/
  885. static void AtapiSendCdb (PADAPTER2220I padapter, POUR_DEVICE pdev, CHAR *cdb)
  886. {
  887. 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]));
  888. outsw (padapter->regData, cdb, pdev->packet);
  889. }
  890. /****************************************************************
  891.  * Name: AtapiRequestSense
  892.  *
  893.  * Description: Send the CDB packet to the device.
  894.  *
  895.  * Parameters: padapter - Pointer adapter data structure.
  896.  * pdev  - Pointer to device.
  897.  * SCpnt  - Pointer to SCSI command structure.
  898.  * pass  - If true then this is the second pass to send cdb.
  899.  *
  900.  * Returns: TRUE on error.
  901.  *
  902.  ****************************************************************/
  903. static int AtapiRequestSense (PADAPTER2220I padapter, POUR_DEVICE pdev, Scsi_Cmnd *SCpnt, UCHAR pass)
  904. {
  905. UCHAR cdb[16] = {SCSIOP_REQUEST_SENSE,0,0,0,16,0,0,0,0,0,0,0,0,0,0,0};
  906. DEB (printk ("nPCI2242I: AUTO REQUEST SENSE"));
  907. cdb[4] = (UCHAR)(sizeof (SCpnt->sense_buffer));
  908. if ( !pass )
  909. {
  910. padapter->reqSense = TRUE;
  911.   AtapiCountLo (padapter, cdb[4]);
  912. AtapiCountHi (padapter, 0);
  913. outb_p (0, padapter->regError);
  914. WriteCommand (padapter, IDE_COMMAND_ATAPI_PACKET);
  915. if ( pdev->cmdDrqInt )
  916. return FALSE;
  917. if ( AtapiWaitDrq (padapter, 500) )
  918. return TRUE;
  919. }
  920. AtapiSendCdb (padapter, pdev, cdb);
  921. return FALSE;
  922. }
  923. /****************************************************************
  924.  * Name: InlineReadSignature :LOCAL
  925.  *
  926.  * Description: Do an inline read RAID sigature.
  927.  *
  928.  * Parameters: padapter - Pointer adapter data structure.
  929.  * pdev  - Pointer to device.
  930.  * index  - index of data to read.
  931.  *
  932.  * Returns: Zero if no error or status register contents on error.
  933.  *
  934.  ****************************************************************/
  935. static UCHAR InlineReadSignature (PADAPTER2220I padapter, POUR_DEVICE pdev, int index)
  936. {
  937. UCHAR status;
  938. ULONG zl = pdev->lastsectorlba[index];
  939. SelectSpigot (padapter, pdev->spigots[index] | SEL_IRQ_OFF); // select the spigot without interrupts
  940. outb_p (pdev->byte6 | ((UCHAR *)&zl)[3], padapter->regLba24);
  941. status = WaitReady (padapter);
  942. if ( !status )
  943. {
  944. outb_p (((UCHAR *)&zl)[2], padapter->regLba16);
  945. outb_p (((UCHAR *)&zl)[1], padapter->regLba8); 
  946. outb_p (((UCHAR *)&zl)[0], padapter->regLba0);
  947. outb_p (1, padapter->regSectCount);
  948. WriteCommand (padapter, IDE_COMMAND_READ);
  949. status = WaitDrq (padapter);
  950. if ( !status )
  951. {
  952. insw (padapter->regData, padapter->kBuffer, BYTES_PER_SECTOR / 2);
  953. ((ULONG *)(&pdev->DiskMirror[index]))[0] = ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[0];
  954. ((ULONG *)(&pdev->DiskMirror[index]))[1] = ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[1];
  955. // some drives assert DRQ before IRQ so let's make sure we clear the IRQ
  956. WaitReady (padapter);
  957. return 0;
  958. }
  959. }
  960. return status;
  961. }
  962. /****************************************************************
  963.  * Name: DecodeError :LOCAL
  964.  *
  965.  * Description: Decode and process device errors.
  966.  *
  967.  * Parameters: padapter - Pointer to adapter data.
  968.  * status - Status register code.
  969.  *
  970.  * Returns: The driver status code.
  971.  *
  972.  ****************************************************************/
  973. static ULONG DecodeError (PADAPTER2220I padapter, UCHAR status)
  974. {
  975. UCHAR error;
  976. padapter->expectingIRQ = 0;
  977. if ( status & IDE_STATUS_WRITE_FAULT )
  978. {
  979. return DID_PARITY << 16;
  980. }
  981. if ( status & IDE_STATUS_BUSY )
  982. return DID_BUS_BUSY << 16;
  983. error = inb_p (padapter->regError);
  984. DEB(printk ("npci2220i error register: %x", error));
  985. switch ( error )
  986. {
  987. case IDE_ERROR_AMNF:
  988. case IDE_ERROR_TKONF:
  989. case IDE_ERROR_ABRT:
  990. case IDE_ERROR_IDFN:
  991. case IDE_ERROR_UNC:
  992. case IDE_ERROR_BBK:
  993. default:
  994. return DID_ERROR << 16;
  995. }
  996. return DID_ERROR << 16;
  997. }
  998. /****************************************************************
  999.  * Name: StartTimer :LOCAL
  1000.  *
  1001.  * Description: Start the timer.
  1002.  *
  1003.  * Parameters: ipadapter - Pointer adapter data structure.
  1004.  *
  1005.  * Returns: Nothing.
  1006.  *
  1007.  ****************************************************************/
  1008. static void StartTimer (PADAPTER2220I padapter)
  1009. {
  1010. padapter->timer.expires = jiffies + TIMEOUT_DATA;
  1011. add_timer (&padapter->timer);
  1012. }
  1013. /****************************************************************
  1014.  * Name: WriteSignature :LOCAL
  1015.  *
  1016.  * Description: Start the timer.
  1017.  *
  1018.  * Parameters: padapter - Pointer adapter data structure.
  1019.  * pdev  - Pointer to our device.
  1020.  * spigot  - Selected spigot.
  1021.  * index  - index of mirror signature on device.
  1022.  *
  1023.  * Returns: TRUE on any error.
  1024.  *
  1025.  ****************************************************************/
  1026. static int WriteSignature (PADAPTER2220I padapter, POUR_DEVICE pdev, UCHAR spigot, int index)
  1027. {
  1028. ULONG zl;
  1029. SelectSpigot (padapter, spigot);
  1030. zl = pdev->lastsectorlba[index];
  1031. outb_p (pdev->byte6 | ((UCHAR *)&zl)[3], padapter->regLba24);
  1032. outb_p (((UCHAR *)&zl)[2], padapter->regLba16);
  1033. outb_p (((UCHAR *)&zl)[1], padapter->regLba8);
  1034. outb_p (((UCHAR *)&zl)[0], padapter->regLba0);
  1035. outb_p (1, padapter->regSectCount);
  1036. WriteCommand (padapter, IDE_COMMAND_WRITE);
  1037. if ( WaitDrq (padapter) )
  1038. return TRUE;
  1039. StartTimer (padapter);
  1040. padapter->expectingIRQ = TRUE;
  1041. ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[0] = ((ULONG *)(&pdev->DiskMirror[index]))[0];
  1042. ((ULONG *)(&padapter->kBuffer[DISK_MIRROR_POSITION]))[1] = ((ULONG *)(&pdev->DiskMirror[index]))[1];
  1043. outsw (padapter->regData, padapter->kBuffer, BYTES_PER_SECTOR / 2);
  1044. return FALSE;
  1045. }
  1046. /*******************************************************************************************************
  1047.  * Name: InitFailover
  1048.  *
  1049.  * Description: This is the beginning of the failover routine
  1050.  *
  1051.  * Parameters: SCpnt  - Pointer to SCSI command structure.
  1052.  * padapter - Pointer adapter data structure.
  1053.  * pdev  - Pointer to our device.
  1054.  *
  1055.  * Returns: TRUE on error.
  1056.  *
  1057.  ******************************************************************************************************/
  1058. static int InitFailover (PADAPTER2220I padapter, POUR_DEVICE pdev)
  1059. {
  1060. UCHAR spigot;
  1061. DEB (printk ("npci2220i:  Initialize failover process - survivor = %d", pdev->deviceID[padapter->survivor]));
  1062. pdev->raid = FALSE; //initializes system for non raid mode
  1063. pdev->reconOn = FALSE;
  1064. spigot = pdev->spigots[padapter->survivor];
  1065. if ( pdev->DiskMirror[padapter->survivor].status & UCBF_REBUILD )
  1066. {
  1067. DEB (printk ("n         failed, is survivor"));
  1068. return (TRUE); 
  1069. }
  1070. if ( HardReset (padapter, pdev, spigot) )
  1071. {
  1072. DEB (printk ("n         failed, reset"));
  1073. return TRUE;
  1074. }
  1075. Alarm (padapter, pdev->deviceID[padapter->survivor ^ 1]);
  1076. pdev->DiskMirror[padapter->survivor].status = UCBF_MIRRORED | UCBF_SURVIVOR; //clear present status
  1077. if ( WriteSignature (padapter, pdev, spigot, padapter->survivor) )
  1078. {
  1079. DEB (printk ("n         failed, write signature"));
  1080. return TRUE;
  1081. }
  1082. padapter->failinprog = TRUE;
  1083. return FALSE;
  1084. }
  1085. /****************************************************************
  1086.  * Name: TimerExpiry :LOCAL
  1087.  *
  1088.  * Description: Timer expiry routine.
  1089.  *
  1090.  * Parameters: data - Pointer adapter data structure.
  1091.  *
  1092.  * Returns: Nothing.
  1093.  *
  1094.  ****************************************************************/
  1095. static void TimerExpiry (unsigned long data)
  1096. {
  1097. PADAPTER2220I padapter = (PADAPTER2220I)data;
  1098. POUR_DEVICE pdev = padapter->pdev;
  1099. UCHAR status = IDE_STATUS_BUSY;
  1100. UCHAR temp, temp1;
  1101.     unsigned long flags;
  1102.     /*
  1103.      * Disable interrupts, if they aren't already disabled and acquire
  1104.      * the I/O spinlock.
  1105.      */
  1106.     spin_lock_irqsave (&io_request_lock, flags);
  1107. DEB (printk ("nPCI2220I: Timeout expired "));
  1108. if ( padapter->failinprog )
  1109. {
  1110. DEB (printk ("in failover process"));
  1111. OpDone (padapter, DecodeError (padapter, inb_p (padapter->regStatCmd)));
  1112. goto timerExpiryDone;
  1113. }
  1114. while ( padapter->reconPhase )
  1115. {
  1116. DEB (printk ("in recon phase %X", padapter->reconPhase));
  1117. switch ( padapter->reconPhase )
  1118. {
  1119. case RECON_PHASE_MARKING:
  1120. case RECON_PHASE_LAST:
  1121. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 1 : 0;
  1122. DEB (printk ("npci2220i: FAILURE 1"));
  1123. if ( InitFailover (padapter, pdev) )
  1124. OpDone (padapter, DID_ERROR << 16);
  1125. goto timerExpiryDone;
  1126. case RECON_PHASE_READY:
  1127. OpDone (padapter, DID_ERROR << 16);
  1128. goto timerExpiryDone;
  1129. case RECON_PHASE_COPY:
  1130. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1131. DEB (printk ("npci2220i: FAILURE 2"));
  1132. DEB (printk ("n       spig/stat = %X", inb_p (padapter->regStatSel));
  1133. if ( InitFailover (padapter, pdev) )
  1134. OpDone (padapter, DID_ERROR << 16);
  1135. goto timerExpiryDone;
  1136. case RECON_PHASE_UPDATE:
  1137. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1138. DEB (printk ("npci2220i: FAILURE 3")));
  1139. if ( InitFailover (padapter, pdev) )
  1140. OpDone (padapter, DID_ERROR << 16);
  1141. goto timerExpiryDone;
  1142. case RECON_PHASE_END:
  1143. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1144. DEB (printk ("npci2220i: FAILURE 4"));
  1145. if ( InitFailover (padapter, pdev) )
  1146. OpDone (padapter, DID_ERROR << 16);
  1147. goto timerExpiryDone;
  1148. default:
  1149. goto timerExpiryDone;
  1150. }
  1151. }
  1152. while ( padapter->cmd )
  1153. {
  1154. outb_p (0x08, padapter->regDmaCmdStat); // cancel interrupt from DMA engine
  1155. if ( pdev->raid )
  1156. {
  1157. if ( padapter->cmd == WRITE_CMD )
  1158. {
  1159. DEB (printk ("in RAID write operation"));
  1160. temp = ( pdev->spigot & (SEL_1 | SEL_2) ) ? SEL_1 : SEL_3;
  1161. if ( inb_p (padapter->regStatSel) & temp )
  1162. {
  1163. DEB (printk ("npci2220i: Determined A OK"));
  1164. SelectSpigot (padapter, temp | SEL_IRQ_OFF); // Masking the interrupt during spigot select
  1165. temp = inb_p (padapter->regStatCmd);
  1166. }
  1167. else
  1168. temp = IDE_STATUS_BUSY;
  1169. temp1 = ( pdev->spigot & (SEL_1 | SEL_2) ) ? SEL_2 : SEL_4;
  1170. if ( inb (padapter->regStatSel) & temp1 )
  1171. {
  1172. DEB (printk ("npci2220i: Determined B OK"));
  1173. SelectSpigot (padapter, temp1 | SEL_IRQ_OFF); // Masking the interrupt during spigot select
  1174. temp1 = inb_p (padapter->regStatCmd);
  1175. }
  1176. else
  1177. temp1 = IDE_STATUS_BUSY;
  1178. if ( (temp & IDE_STATUS_BUSY) || (temp1 & IDE_STATUS_BUSY) )
  1179. {
  1180. DEB (printk ("npci2220i: Status A: %X   B: %X", temp & 0xFF, temp1 & 0xFF));
  1181.   if ( (temp & IDE_STATUS_BUSY) && (temp1 & IDE_STATUS_BUSY) ) 
  1182. {
  1183. status = temp;
  1184. break;
  1185. }
  1186. else
  1187. {
  1188. if ( temp & IDE_STATUS_BUSY )
  1189. padapter->survivor = 1;
  1190. else
  1191. padapter->survivor = 0;
  1192. if ( InitFailover (padapter, pdev) )
  1193. {
  1194. status = inb_p (padapter->regStatCmd);
  1195. break;
  1196. }
  1197. goto timerExpiryDone;
  1198. }
  1199. }
  1200. }
  1201. else
  1202. {
  1203. DEB (printk ("in RAID read operation"));
  1204. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1205. DEB (printk ("npci2220i: FAILURE 6"));
  1206. if ( InitFailover (padapter, pdev) )
  1207. {
  1208. status = inb_p (padapter->regStatCmd);
  1209. break;
  1210. }
  1211. goto timerExpiryDone;
  1212. }
  1213. }
  1214. else
  1215. {
  1216. DEB (printk ("in I/O operation"));
  1217. status = inb_p (padapter->regStatCmd);
  1218. }
  1219. break;
  1220. }
  1221. OpDone (padapter, DecodeError (padapter, status));
  1222. timerExpiryDone:;
  1223.     /*
  1224.      * Release the I/O spinlock and restore the original flags
  1225.      * which will enable interrupts if and only if they were
  1226.      * enabled on entry.
  1227.      */
  1228.     spin_unlock_irqrestore (&io_request_lock, flags);
  1229. }
  1230. /****************************************************************
  1231.  * Name: SetReconstruct :LOCAL
  1232.  *
  1233.  * Description: Set the reconstruct up.
  1234.  *
  1235.  * Parameters: pdev - Pointer to device structure.
  1236.  * index - Mirror index number.
  1237.  *
  1238.  * Returns: Number of sectors on new disk required.
  1239.  *
  1240.  ****************************************************************/
  1241. static LONG SetReconstruct (POUR_DEVICE pdev, int index)
  1242. {
  1243. pdev->DiskMirror[index].status = UCBF_MIRRORED; // setup the flags
  1244. pdev->DiskMirror[index ^ 1].status = UCBF_MIRRORED | UCBF_REBUILD;
  1245. pdev->DiskMirror[index ^ 1].reconstructPoint = 0; // start the reconstruct
  1246. pdev->reconCount = 1990; // mark target drive early
  1247. return pdev->DiskMirror[index].reconstructPoint;
  1248. }
  1249. /****************************************************************
  1250.  * Name: ReconTimerExpiry :LOCAL
  1251.  *
  1252.  * Description: Reconstruct timer expiry routine.
  1253.  *
  1254.  * Parameters: data - Pointer adapter data structure.
  1255.  *
  1256.  * Returns: Nothing.
  1257.  *
  1258.  ****************************************************************/
  1259. static void ReconTimerExpiry (unsigned long data)
  1260. {
  1261. PADAPTER2220I padapter;
  1262. POUR_DEVICE pdev;
  1263. ULONG testsize = 0;
  1264. PIDENTIFY_DATA pid;
  1265. USHORT minmode;
  1266. ULONG zl;
  1267. UCHAR zc;
  1268. USHORT z;
  1269.     unsigned long flags;
  1270.     /*
  1271.      * Disable interrupts, if they aren't already disabled and acquire
  1272.      * the I/O spinlock.
  1273.      */
  1274.     spin_lock_irqsave (&io_request_lock, flags);
  1275. padapter = (PADAPTER2220I)data;
  1276. if ( padapter->SCpnt )
  1277. goto reconTimerExpiry;
  1278. padapter->reconTimer.data = 0;
  1279. for ( z = padapter->devInReconIndex + 1;  z < BIGD_MAXDRIVES;  z++ )
  1280. {
  1281. if ( padapter->device[z].reconOn )
  1282. break;
  1283. }
  1284. if ( z < BIGD_MAXDRIVES )
  1285. pdev = &padapter->device[z];
  1286. else
  1287. {
  1288. for ( z = 0;  z < BIGD_MAXDRIVES;  z++ )
  1289. {
  1290. if ( padapter->device[z].reconOn )
  1291. break;
  1292. }
  1293. if ( z < BIGD_MAXDRIVES )
  1294. pdev = &padapter->device[z];
  1295. else
  1296. {
  1297. padapter->reconOn = FALSE;
  1298. goto reconTimerExpiry;
  1299. }
  1300. }
  1301. padapter->devInReconIndex = z;
  1302. pid = (PIDENTIFY_DATA)padapter->kBuffer;
  1303. padapter->pdev = pdev;
  1304. if ( pdev->reconIsStarting )
  1305. {
  1306. pdev->reconIsStarting = FALSE;
  1307. pdev->reconOn = FALSE;
  1308. while ( (pdev->DiskMirror[0].signature == SIGNATURE) && (pdev->DiskMirror[1].signature == SIGNATURE) &&
  1309.  (pdev->DiskMirror[0].pairIdentifier == (pdev->DiskMirror[1].pairIdentifier ^ 1)) )
  1310. {
  1311. if ( (pdev->DiskMirror[0].status & UCBF_MATCHED) && (pdev->DiskMirror[1].status & UCBF_MATCHED) )
  1312. break;;
  1313. if ( pdev->DiskMirror[0].status & UCBF_SURVIVOR ) // is first drive survivor?
  1314. testsize = SetReconstruct (pdev, 0);
  1315. else
  1316. if ( pdev->DiskMirror[1].status & UCBF_SURVIVOR ) // is second drive survivor?
  1317. testsize = SetReconstruct (pdev, 1);
  1318. if ( (pdev->DiskMirror[0].status & UCBF_REBUILD) || (pdev->DiskMirror[1].status & UCBF_REBUILD) )
  1319. {
  1320. if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
  1321. pdev->mirrorRecon = 0;
  1322. else
  1323. pdev->mirrorRecon = 1;
  1324. pdev->reconOn = TRUE;
  1325. }
  1326. break;
  1327. }
  1328. if ( !pdev->reconOn )
  1329. goto reconTimerExpiry;
  1330. if ( padapter->bigD )
  1331. {
  1332. padapter->failRegister = 0;
  1333. outb_p (~padapter->failRegister, padapter->regFail);
  1334. }
  1335. else
  1336. {
  1337. zc = ((inb_p (padapter->regStatSel) >> 3) | inb_p (padapter->regStatSel)) & 0x83; // mute the alarm
  1338. outb_p (0xFF, padapter->regFail);
  1339. }
  1340. while ( 1 )
  1341. {
  1342. DEB (printk ("npci2220i: hard reset issue"));
  1343. if ( HardReset (padapter, pdev, pdev->spigots[pdev->mirrorRecon]) )
  1344. {
  1345. DEB (printk ("npci2220i: sub 1"));
  1346. break;
  1347. }
  1348. pdev->lastsectorlba[pdev->mirrorRecon] = InlineIdentify (padapter, pdev->spigots[pdev->mirrorRecon], pdev->deviceID[pdev->mirrorRecon] & 1);
  1349. if ( pdev->lastsectorlba[pdev->mirrorRecon] < testsize )
  1350. {
  1351. DEB (printk ("npci2220i: sub 2 %ld %ld", pdev->lastsectorlba[pdev->mirrorRecon], testsize));
  1352. break;
  1353. }
  1354.         // test LBA and multiper sector transfer compatability
  1355. if (!pid->SupportLBA || (pid->NumSectorsPerInt < SECTORSXFER) || !pid->Valid_64_70 )
  1356. {
  1357. DEB (printk ("npci2220i: sub 3"));
  1358. break;
  1359. }
  1360.         // test PIO/bus matering mode compatability
  1361. if ( (pid->MinPIOCycleWithoutFlow > 240) && !pid->SupportIORDYDisable && !padapter->timingPIO )
  1362. {
  1363. DEB (printk ("npci2220i: sub 4"));
  1364. break;
  1365. }
  1366. if ( pid->MinPIOCycleWithoutFlow <= 120 ) // setup timing mode of drive
  1367. minmode = 5;
  1368. else
  1369. {
  1370. if ( pid->MinPIOCylceWithFlow <= 150 )
  1371. minmode = 4;
  1372. else
  1373. {
  1374. if ( pid->MinPIOCylceWithFlow <= 180 )
  1375. minmode = 3;
  1376. else
  1377. {
  1378. if ( pid->MinPIOCylceWithFlow <= 240 )
  1379. minmode = 2;
  1380. else
  1381. {
  1382. DEB (printk ("npci2220i: sub 5"));
  1383. break;
  1384. }
  1385. }
  1386. }
  1387. }
  1388. if ( padapter->timingMode > minmode ) // set minimum timing mode
  1389. padapter->timingMode = minmode;
  1390. if ( padapter->timingMode >= 2 )
  1391. padapter->timingAddress = ModeArray[padapter->timingMode - 2];
  1392. else
  1393. padapter->timingPIO = TRUE;
  1394. padapter->reconOn = TRUE;
  1395. break;
  1396. }
  1397. if ( !pdev->reconOn )
  1398. {
  1399. padapter->survivor = pdev->mirrorRecon ^ 1;
  1400. padapter->reconPhase = RECON_PHASE_FAILOVER;
  1401. DEB (printk ("npci2220i: FAILURE 7"));
  1402. InitFailover (padapter, pdev);
  1403. goto reconTimerExpiry;
  1404. }
  1405. pdev->raid = TRUE;
  1406. if ( WriteSignature (padapter, pdev, pdev->spigot, pdev->mirrorRecon ^ 1) )
  1407. goto reconTimerExpiry;
  1408. padapter->reconPhase = RECON_PHASE_MARKING;
  1409. goto reconTimerExpiry;
  1410. }
  1411. //**********************************
  1412. // reconstruct copy starts here
  1413. //**********************************
  1414. if ( pdev->reconCount++ > 2000 )
  1415. {
  1416. pdev->reconCount = 0;
  1417. if ( WriteSignature (padapter, pdev, pdev->spigots[pdev->mirrorRecon], pdev->mirrorRecon) )
  1418. {
  1419. padapter->survivor = pdev->mirrorRecon ^ 1;
  1420. padapter->reconPhase = RECON_PHASE_FAILOVER;
  1421. DEB (printk ("npci2220i: FAILURE 8"));
  1422. InitFailover (padapter, pdev);
  1423. goto reconTimerExpiry;
  1424. }
  1425. padapter->reconPhase = RECON_PHASE_UPDATE;
  1426. goto reconTimerExpiry;
  1427. }
  1428. zl = pdev->DiskMirror[pdev->mirrorRecon].reconstructPoint;
  1429. padapter->reconSize = pdev->DiskMirror[pdev->mirrorRecon ^ 1].reconstructPoint - zl;
  1430. if ( padapter->reconSize > MAX_BUS_MASTER_BLOCKS )
  1431. padapter->reconSize = MAX_BUS_MASTER_BLOCKS;
  1432. if ( padapter->reconSize )
  1433. {
  1434. SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1]); // select the spigots
  1435. outb_p (pdev->byte6 | ((UCHAR *)(&zl))[3], padapter->regLba24); // select the drive
  1436. SelectSpigot (padapter, pdev->spigot);
  1437. if ( WaitReady (padapter) )
  1438. goto reconTimerExpiry;
  1439. SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon]);
  1440. if ( WaitReady (padapter) )
  1441. {
  1442. padapter->survivor = pdev->mirrorRecon ^ 1;
  1443. padapter->reconPhase = RECON_PHASE_FAILOVER;
  1444. DEB (printk ("npci2220i: FAILURE 9"));
  1445. InitFailover (padapter, pdev);
  1446. goto reconTimerExpiry;
  1447. }
  1448. SelectSpigot (padapter, pdev->spigots[0] | pdev->spigots[1]);
  1449. outb_p (padapter->reconSize & 0xFF, padapter->regSectCount);
  1450. outb_p (((UCHAR *)(&zl))[0], padapter->regLba0);
  1451. outb_p (((UCHAR *)(&zl))[1], padapter->regLba8);
  1452. outb_p (((UCHAR *)(&zl))[2], padapter->regLba16);
  1453. padapter->expectingIRQ = TRUE;
  1454. padapter->reconPhase = RECON_PHASE_READY;
  1455. SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon]);
  1456. WriteCommand (padapter, WRITE_CMD);
  1457. StartTimer (padapter);
  1458. SelectSpigot (padapter, pdev->spigot);
  1459. WriteCommand (padapter, READ_CMD);
  1460. goto reconTimerExpiry;
  1461. }
  1462. pdev->DiskMirror[pdev->mirrorRecon].status = UCBF_MIRRORED | UCBF_MATCHED;
  1463. pdev->DiskMirror[pdev->mirrorRecon ^ 1].status = UCBF_MIRRORED | UCBF_MATCHED;
  1464. if ( WriteSignature (padapter, pdev, pdev->spigot, pdev->mirrorRecon ^ 1) )
  1465. goto reconTimerExpiry;
  1466. padapter->reconPhase = RECON_PHASE_LAST;
  1467. reconTimerExpiry:;
  1468.     /*
  1469.      * Release the I/O spinlock and restore the original flags
  1470.      * which will enable interrupts if and only if they were
  1471.      * enabled on entry.
  1472.      */
  1473.     spin_unlock_irqrestore (&io_request_lock, flags);
  1474. }
  1475. /****************************************************************
  1476.  * Name: Irq_Handler :LOCAL
  1477.  *
  1478.  * Description: Interrupt handler.
  1479.  *
  1480.  * Parameters: irq - Hardware IRQ number.
  1481.  * dev_id -
  1482.  * regs -
  1483.  *
  1484.  * Returns: TRUE if drive is not ready in time.
  1485.  *
  1486.  ****************************************************************/
  1487. static void Irq_Handler (int irq, void *dev_id, struct pt_regs *regs)
  1488. {
  1489. struct Scsi_Host   *shost = NULL; // Pointer to host data block
  1490. PADAPTER2220I padapter; // Pointer to adapter control structure
  1491. POUR_DEVICE pdev;
  1492. Scsi_Cmnd    *SCpnt;
  1493. UCHAR status;
  1494. UCHAR status1;
  1495. ATAPI_STATUS statusa;
  1496. ATAPI_REASON reasona;
  1497. ATAPI_ERROR errora;
  1498. int z;
  1499. ULONG zl;
  1500.     unsigned long flags;
  1501.     /*
  1502.      * Disable interrupts, if they aren't already disabled and acquire
  1503.      * the I/O spinlock.
  1504.      */
  1505.     spin_lock_irqsave (&io_request_lock, flags);
  1506. // DEB (printk ("npci2220i received interruptn"));
  1507. for ( z = 0; z < NumAdapters;  z++ ) // scan for interrupt to process
  1508. {
  1509. if ( PsiHost[z]->irq == (UCHAR)(irq & 0xFF) )
  1510. {
  1511. if ( inw_p (HOSTDATA(PsiHost[z])->regIrqControl) & 0x8000 )
  1512. {
  1513. shost = PsiHost[z];
  1514. break;
  1515. }
  1516. }
  1517. }
  1518. if ( !shost )
  1519. {
  1520. DEB (printk ("npci2220i: not my interrupt"));
  1521. goto irq_return;
  1522. }
  1523. padapter = HOSTDATA(shost);
  1524. pdev = padapter->pdev;
  1525. SCpnt = padapter->SCpnt;
  1526. outb_p (0x08, padapter->regDmaCmdStat); // cancel interrupt from DMA engine
  1527. if ( padapter->atapi && SCpnt )
  1528. {
  1529. *(char *)&statusa = inb_p (padapter->regStatCmd); // read the device status
  1530. *(char *)&reasona = inb_p (padapter->regSectCount); // read the device interrupt reason
  1531. if ( !statusa.bsy )
  1532. {
  1533. if ( statusa.drq ) // test for transfer phase
  1534. {
  1535. if ( !reasona.cod ) // test for data phase
  1536. {
  1537. z = (ULONG)inb_p (padapter->regLba8) | (ULONG)(inb_p (padapter->regLba16) << 8);
  1538. if ( padapter->reqSense )
  1539. insw (padapter->regData, SCpnt->sense_buffer, z / 2);
  1540. else
  1541. AtapiBusMaster (padapter, reasona.io, z);
  1542. goto irq_return;
  1543. }
  1544. if ( reasona.cod && !reasona.io ) // test for command packet phase
  1545. {
  1546. if ( padapter->reqSense )
  1547. AtapiRequestSense (padapter, pdev, SCpnt, TRUE);
  1548. else
  1549. AtapiSendCdb (padapter, pdev, padapter->atapiCdb);
  1550. goto irq_return;
  1551. }
  1552. }
  1553. else
  1554. {
  1555. if ( reasona.io && statusa.drdy ) // test for status phase
  1556. {
  1557. Atapi2Scsi (padapter, SCpnt);
  1558. if ( statusa.check )
  1559. {
  1560. *(UCHAR *)&errora = inb_p (padapter->regError); // read the device error
  1561. if ( errora.senseKey )
  1562. {
  1563. if ( padapter->reqSense || AtapiRequestSense (padapter, pdev, SCpnt, FALSE) )
  1564. OpDone (padapter, DID_ERROR << 16);
  1565. }
  1566. else
  1567. {
  1568. if ( errora.ili || errora.abort )
  1569. OpDone (padapter, DID_ERROR << 16);
  1570. else
  1571. OpDone (padapter, DID_OK << 16);
  1572. }
  1573. }
  1574. else
  1575. if ( padapter->reqSense )
  1576. {
  1577. DEB (printk ("PCI2242I: Sense codes - %X %X %X ", ((UCHAR *)SCpnt->sense_buffer)[0], ((UCHAR *)SCpnt->sense_buffer)[12], ((UCHAR *)SCpnt->sense_buffer)[13]));
  1578. OpDone (padapter, (DRIVER_SENSE << 24) | (DID_OK << 16) | 2);
  1579. }
  1580. else
  1581. OpDone (padapter, DID_OK << 16);
  1582. }
  1583. }
  1584. }
  1585. goto irq_return;
  1586. }
  1587. if ( !padapter->expectingIRQ || !(SCpnt || padapter->reconPhase) )
  1588. {
  1589. DEB(printk ("npci2220i Unsolicited interruptn"));
  1590. STOP_HERE ();
  1591. goto irq_return;
  1592. }
  1593. padapter->expectingIRQ = 0;
  1594. if ( padapter->failinprog )
  1595. {
  1596. DEB (printk ("npci2220i interrupt failover complete"));
  1597. padapter->failinprog = FALSE;
  1598. status = inb_p (padapter->regStatCmd); // read the device status
  1599. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1600. {
  1601. DEB (printk ("npci2220i: interrupt failover error from drive %X", status));
  1602. padapter->cmd = 0;
  1603. }
  1604. else
  1605. {
  1606. DEB (printk ("npci2220i: restarting failed opertation."));
  1607. pdev->spigot = (padapter->survivor) ? pdev->spigots[1] : pdev->spigots[0];
  1608. del_timer (&padapter->timer);
  1609. if ( padapter->reconPhase )
  1610. OpDone (padapter, DID_OK << 16);
  1611. else
  1612. Pci2220i_QueueCommand (SCpnt, SCpnt->scsi_done);
  1613. goto irq_return;
  1614. }
  1615. }
  1616. if ( padapter->reconPhase )
  1617. {
  1618. switch ( padapter->reconPhase )
  1619. {
  1620. case RECON_PHASE_MARKING:
  1621. case RECON_PHASE_LAST:
  1622. status = inb_p (padapter->regStatCmd); // read the device status
  1623. del_timer (&padapter->timer);
  1624. if ( padapter->reconPhase == RECON_PHASE_LAST )
  1625. {
  1626. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1627. {
  1628. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 1 : 0;
  1629. DEB (printk ("npci2220i: FAILURE 10"));
  1630. if ( InitFailover (padapter, pdev) )
  1631. OpDone (padapter, DecodeError (padapter, status));
  1632. goto irq_return;
  1633. }
  1634. if ( WriteSignature (padapter, pdev, pdev->spigots[pdev->mirrorRecon], pdev->mirrorRecon) )
  1635. {
  1636. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1637. DEB (printk ("npci2220i: FAILURE 11"));
  1638. if ( InitFailover (padapter, pdev) )
  1639. OpDone (padapter, DecodeError (padapter, status));
  1640. goto irq_return;
  1641. }
  1642. padapter->reconPhase = RECON_PHASE_END;
  1643. goto irq_return;
  1644. }
  1645. OpDone (padapter, DID_OK << 16);
  1646. goto irq_return;
  1647. case RECON_PHASE_READY:
  1648. status = inb_p (padapter->regStatCmd); // read the device status
  1649. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1650. {
  1651. del_timer (&padapter->timer);
  1652. OpDone (padapter, DecodeError (padapter, status));
  1653. goto irq_return;
  1654. }
  1655. SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon]);
  1656. if ( WaitDrq (padapter) )
  1657. {
  1658. del_timer (&padapter->timer);
  1659. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1660. DEB (printk ("npci2220i: FAILURE 12"));
  1661. if ( InitFailover (padapter, pdev) )
  1662. OpDone (padapter, DecodeError (padapter, status));
  1663. goto irq_return;
  1664. }
  1665. SelectSpigot (padapter, pdev->spigot | SEL_COPY | padapter->bigD);
  1666. padapter->reconPhase = RECON_PHASE_COPY;
  1667. padapter->expectingIRQ = TRUE;
  1668. if ( padapter->timingPIO )
  1669. {
  1670. insw (padapter->regData, padapter->kBuffer, padapter->reconSize * (BYTES_PER_SECTOR / 2));
  1671. }
  1672. else
  1673. {
  1674. if ( (padapter->timingMode > 3) )
  1675. {
  1676. if ( padapter->bigD )
  1677. outl (BIGD_DATA_MODE3, padapter->regDmaAddrLoc);
  1678. else
  1679. outl (DALE_DATA_MODE3, padapter->regDmaAddrLoc);
  1680. }
  1681. else
  1682. outl (padapter->timingAddress, padapter->regDmaAddrLoc);
  1683. outl (padapter->kBufferDma, padapter->regDmaAddrPci);
  1684. outl (padapter->reconSize * BYTES_PER_SECTOR, padapter->regDmaCount);
  1685. outb_p (8, padapter->regDmaDesc); // read operation
  1686. if ( padapter->bigD )
  1687. outb_p (8, padapter->regDmaMode); // no interrupt
  1688. else
  1689. outb_p (1, padapter->regDmaMode); // no interrupt
  1690. outb_p (0x03, padapter->regDmaCmdStat); // kick the DMA engine in gear
  1691. }
  1692. goto irq_return;
  1693. case RECON_PHASE_COPY:
  1694. pdev->DiskMirror[pdev->mirrorRecon].reconstructPoint += padapter->reconSize;
  1695. case RECON_PHASE_UPDATE:
  1696. SelectSpigot (padapter, pdev->spigots[pdev->mirrorRecon] | SEL_IRQ_OFF);
  1697. status = inb_p (padapter->regStatCmd); // read the device status
  1698. del_timer (&padapter->timer);
  1699. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1700. {
  1701. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1702. DEB (printk ("npci2220i: FAILURE 13"));
  1703. DEB (printk ("n  status register = %X   error = %X", status, inb_p (padapter->regError)));
  1704. if ( InitFailover (padapter, pdev) )
  1705. OpDone (padapter, DecodeError (padapter, status));
  1706. goto irq_return;
  1707. }
  1708. OpDone (padapter, DID_OK << 16);
  1709. goto irq_return;
  1710. case RECON_PHASE_END:
  1711. status = inb_p (padapter->regStatCmd); // read the device status
  1712. del_timer (&padapter->timer);
  1713. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1714. {
  1715. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 0 : 1;
  1716. DEB (printk ("npci2220i: FAILURE 14"));
  1717. if ( InitFailover (padapter, pdev) )
  1718. OpDone (padapter, DecodeError (padapter, status));
  1719. goto irq_return;
  1720. }
  1721. pdev->reconOn = 0;
  1722. if ( padapter->bigD )
  1723. {
  1724. for ( z = 0;  z < padapter->numberOfDrives;  z++ )
  1725. {
  1726. if ( padapter->device[z].DiskMirror[0].status & UCBF_SURVIVOR )
  1727. {
  1728. Alarm (padapter, padapter->device[z].deviceID[0] ^ 2);
  1729. MuteAlarm (padapter);
  1730. }
  1731. if ( padapter->device[z].DiskMirror[1].status & UCBF_SURVIVOR )
  1732. {
  1733. Alarm (padapter, padapter->device[z].deviceID[1] ^ 2);
  1734. MuteAlarm (padapter);
  1735. }
  1736. }
  1737. }
  1738. OpDone (padapter, DID_OK << 16);
  1739. goto irq_return;
  1740. default:
  1741. goto irq_return;
  1742. }
  1743. }
  1744. switch ( padapter->cmd ) // decide how to handle the interrupt
  1745. {
  1746. case READ_CMD:
  1747. if ( padapter->sectorCount )
  1748. {
  1749. status = inb_p (padapter->regStatCmd); // read the device status
  1750. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1751. {
  1752. if ( pdev->raid )
  1753. {
  1754. padapter->survivor = ( pdev->spigot == pdev->spigots[0] ) ? 1 : 0;
  1755. del_timer (&padapter->timer);
  1756. DEB (printk ("npci2220i: FAILURE 15"));
  1757. if ( !InitFailover (padapter, pdev) )
  1758. goto irq_return;
  1759. }
  1760. break;
  1761. }
  1762. if ( padapter->timingPIO )
  1763. {
  1764. insw (padapter->regData, padapter->kBuffer, padapter->readCount / 2);
  1765. padapter->sectorCount -= padapter->readCount / BYTES_PER_SECTOR;
  1766. WalkScatGath (padapter, TRUE, padapter->readCount);
  1767. if ( !padapter->sectorCount )
  1768. {
  1769. status = 0;
  1770. break;
  1771. }
  1772. }
  1773. else
  1774. {
  1775. if ( padapter->readCount )
  1776. WalkScatGath (padapter, TRUE, padapter->readCount);
  1777. BusMaster (padapter, 1, 1);
  1778. }
  1779. padapter->expectingIRQ = TRUE;
  1780. goto irq_return;
  1781. }
  1782. if ( padapter->readCount && !padapter->timingPIO )
  1783. WalkScatGath (padapter, TRUE, padapter->readCount);
  1784. status = 0;
  1785. break;
  1786. case WRITE_CMD:
  1787. if ( pdev->raid )
  1788. {
  1789. SelectSpigot (padapter, pdev->spigots[0] | SEL_IRQ_OFF);
  1790. status = inb_p (padapter->regStatCmd); // read the device status
  1791. SelectSpigot (padapter, pdev->spigots[1] | SEL_IRQ_OFF);
  1792. status1 = inb_p (padapter->regStatCmd); // read the device status
  1793. }
  1794. else
  1795. SelectSpigot (padapter, pdev->spigot | SEL_IRQ_OFF);
  1796. status = inb_p (padapter->regStatCmd); // read the device status
  1797. status1 = 0;
  1798. if ( status & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1799. {
  1800. if ( pdev->raid && !(status1 & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT)) )
  1801. {
  1802. padapter->survivor = 1;
  1803. del_timer (&padapter->timer);
  1804. SelectSpigot (padapter, pdev->spigot | SEL_IRQ_OFF);
  1805. DEB (printk ("npci2220i: FAILURE 16  status = %X  error = %X", status, inb_p (padapter->regError)));
  1806. if ( !InitFailover (padapter, pdev) )
  1807. goto irq_return;
  1808. }
  1809. break;
  1810. }
  1811. if ( pdev->raid )
  1812. {
  1813. if ( status1 & (IDE_STATUS_ERROR | IDE_STATUS_WRITE_FAULT) )
  1814. {
  1815. padapter->survivor = 0;
  1816. del_timer (&padapter->timer);
  1817. DEB (printk ("npci2220i: FAILURE 17  status = %X  error = %X", status1, inb_p (padapter->regError)));
  1818. if ( !InitFailover (padapter, pdev) )
  1819. goto irq_return;
  1820. status = status1;
  1821. break;
  1822. }
  1823. if ( padapter->sectorCount )
  1824. {
  1825. status = WriteDataBoth (padapter, pdev);
  1826. if ( status )
  1827. {
  1828. padapter->survivor = status >> 1;
  1829. del_timer (&padapter->timer);
  1830. DEB (printk ("npci2220i: FAILURE 18"));
  1831. if ( !InitFailover (padapter, pdev) )
  1832. goto irq_return;
  1833. SelectSpigot (padapter, pdev->spigots[status] | SEL_IRQ_OFF);
  1834. status = inb_p (padapter->regStatCmd); // read the device status
  1835. break;
  1836. }
  1837. padapter->expectingIRQ = TRUE;
  1838. goto irq_return;
  1839. }
  1840. status = 0;
  1841. break;
  1842. }
  1843. if ( padapter->sectorCount )
  1844. {
  1845. SelectSpigot (padapter, pdev->spigot | padapter->bigD);
  1846. status = WriteData (padapter);
  1847. if ( status )
  1848. break;
  1849. padapter->expectingIRQ = TRUE;
  1850. goto irq_return;
  1851. }
  1852. status = 0;
  1853. break;
  1854. case IDE_COMMAND_IDENTIFY:
  1855. {
  1856. PINQUIRYDATA pinquiryData  = SCpnt->request_buffer;
  1857. PIDENTIFY_DATA pid = (PIDENTIFY_DATA)padapter->kBuffer;
  1858. status = inb_p (padapter->regStatCmd);
  1859. if ( status & IDE_STATUS_DRQ )
  1860. {
  1861. insw (padapter->regData, pid, sizeof (IDENTIFY_DATA) >> 1);
  1862. memset (pinquiryData, 0, SCpnt->request_bufflen); // Zero INQUIRY data structure.
  1863. pinquiryData->DeviceType = 0;
  1864. pinquiryData->Versions = 2;
  1865. pinquiryData->AdditionalLength = 35 - 4;
  1866. // Fill in vendor identification fields.
  1867. for ( z = 0;  z < 20;  z += 2 )
  1868. {
  1869. pinquiryData->VendorId[z]   = ((UCHAR *)pid->ModelNumber)[z + 1];
  1870. pinquiryData->VendorId[z + 1] = ((UCHAR *)pid->ModelNumber)[z];
  1871. }
  1872. // Initialize unused portion of product id.
  1873. for ( z = 0;  z < 4;  z++ )
  1874. pinquiryData->ProductId[12 + z] = ' ';
  1875. // Move firmware revision from IDENTIFY data to
  1876. // product revision in INQUIRY data.
  1877. for ( z = 0;  z < 4;  z += 2 )
  1878. {
  1879. pinquiryData->ProductRevisionLevel[z]  = ((UCHAR *)pid->FirmwareRevision)[z + 1];
  1880. pinquiryData->ProductRevisionLevel[z + 1] = ((UCHAR *)pid->FirmwareRevision)[z];
  1881. }
  1882. if ( pdev == padapter->device )
  1883. *((USHORT *)(&pinquiryData->VendorSpecific)) = DEVICE_DALE_1;
  1884. status = 0;
  1885. }
  1886. break;
  1887. }
  1888. default:
  1889. status = 0;
  1890. break;
  1891. }
  1892. del_timer (&padapter->timer);
  1893. if ( status )
  1894. {
  1895. DEB (printk ("npci2220i Interrupt handler return error"));
  1896. zl = DecodeError (padapter, status);
  1897. }
  1898. else
  1899. zl = DID_OK << 16;
  1900. OpDone (padapter, zl);
  1901. irq_return:;
  1902.     /*
  1903.      * Release the I/O spinlock and restore the original flags
  1904.      * which will enable interrupts if and only if they were
  1905.      * enabled on entry.
  1906.      */
  1907.     spin_unlock_irqrestore (&io_request_lock, flags);
  1908. }
  1909. /****************************************************************
  1910.  * Name: Pci2220i_QueueCommand
  1911.  *
  1912.  * Description: Process a queued command from the SCSI manager.
  1913.  *
  1914.  * Parameters: SCpnt - Pointer to SCSI command structure.
  1915.  * done  - Pointer to done function to call.
  1916.  *
  1917.  * Returns: Status code.
  1918.  *
  1919.  ****************************************************************/
  1920. int Pci2220i_QueueCommand (Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
  1921. {
  1922. UCHAR    *cdb = (UCHAR *)SCpnt->cmnd; // Pointer to SCSI CDB
  1923. PADAPTER2220I padapter = HOSTDATA(SCpnt->host); // Pointer to adapter control structure
  1924. POUR_DEVICE pdev  = &padapter->device[SCpnt->target];// Pointer to device information
  1925. UCHAR rc; // command return code
  1926. int z; 
  1927. PDEVICE_RAID1 pdr;
  1928. SCpnt->scsi_done = done;
  1929. padapter->SCpnt = SCpnt;   // Save this command data
  1930. padapter->readCount = 0;
  1931. if ( SCpnt->use_sg )
  1932. {
  1933. padapter->currentSgBuffer = ((struct scatterlist *)SCpnt->request_buffer)[0].address;
  1934. padapter->currentSgCount = ((struct scatterlist *)SCpnt->request_buffer)[0].length;
  1935. }
  1936. else
  1937. {
  1938. padapter->currentSgBuffer = SCpnt->request_buffer;
  1939. padapter->currentSgCount = SCpnt->request_bufflen;
  1940. }
  1941. padapter->nextSg = 1;
  1942. if ( !done )
  1943. {
  1944. printk("pci2220i_queuecommand: %02X: done can't be NULLn", *cdb);
  1945. return 0;
  1946. }
  1947. if ( padapter->atapi )
  1948. {
  1949. UCHAR zlo, zhi;
  1950. DEB (printk ("nPCI2242I: ID %d, LUN %d opcode %X ", SCpnt->target, SCpnt->lun, *cdb));
  1951. padapter->pdev = pdev;
  1952. if ( !pdev->byte6 || SCpnt->lun )
  1953. {
  1954. OpDone (padapter, DID_BAD_TARGET << 16);
  1955. return 0;
  1956. }
  1957. padapter->atapiSpecial = FALSE;
  1958. padapter->reqSense = FALSE;
  1959. memset (padapter->atapiCdb, 0, 16);
  1960. SelectSpigot (padapter, pdev->spigot); // select the spigot
  1961. AtapiDevice (padapter, pdev->byte6); // select the drive
  1962. if ( AtapiWaitReady (padapter, 100) )
  1963. {
  1964. OpDone (padapter, DID_NO_CONNECT << 16);
  1965. return 0;
  1966. }
  1967. switch ( cdb[0] ) 
  1968. {
  1969. case SCSIOP_MODE_SENSE:
  1970. case SCSIOP_MODE_SELECT:
  1971. Scsi2Atapi (padapter, SCpnt);
  1972. z = SCpnt->request_bufflen + 4;
  1973. break;
  1974. case SCSIOP_READ6:
  1975. case SCSIOP_WRITE6:
  1976. Scsi2Atapi (padapter, SCpnt);
  1977. z = SCpnt->request_bufflen;
  1978. break;
  1979. default:
  1980. memcpy (padapter->atapiCdb, cdb, SCpnt->cmd_len);
  1981. z = SCpnt->request_bufflen;
  1982. break;
  1983. }
  1984. if ( z > ATAPI_TRANSFER )
  1985. z = ATAPI_TRANSFER;
  1986.     zlo = (UCHAR)(z & 0xFF);
  1987.     zhi = (UCHAR)(z >> 8);
  1988.   AtapiCountLo (padapter, zlo);
  1989.     AtapiCountHi (padapter, zhi);
  1990.     outb_p (0, padapter->regError);
  1991. WriteCommand (padapter, IDE_COMMAND_ATAPI_PACKET);
  1992. if ( pdev->cmdDrqInt )
  1993. return 0;
  1994. if ( AtapiWaitDrq (padapter, 500) )
  1995. {
  1996. OpDone (padapter, DID_ERROR << 16);
  1997. return 0;
  1998. }
  1999. AtapiSendCdb (padapter, pdev, padapter->atapiCdb);
  2000. return 0;
  2001. }
  2002. if ( padapter->reconPhase )
  2003. return 0;
  2004. if ( padapter->reconTimer.data )
  2005. {
  2006. del_timer (&padapter->reconTimer);
  2007. padapter->reconTimer.data = 0;
  2008. }
  2009. if ( (SCpnt->target >= padapter->numberOfDrives) || SCpnt->lun )
  2010. {
  2011. OpDone (padapter, DID_BAD_TARGET << 16);
  2012. return 0;
  2013. }
  2014. switch ( *cdb )
  2015. {
  2016. case SCSIOP_INQUIRY:    // inquiry CDB
  2017. {
  2018. if ( cdb[2] == SC_MY_RAID )
  2019. {
  2020. switch ( cdb[3] ) 
  2021. {
  2022. case MY_SCSI_REBUILD:
  2023. for ( z = 0;  z < padapter->numberOfDrives;  z++ )
  2024. {
  2025. pdev = &padapter->device[z];
  2026. if ( ((pdev->DiskMirror[0].status & UCBF_SURVIVOR) && (pdev->DiskMirror[1].status & UCBF_MIRRORED)) ||
  2027.  ((pdev->DiskMirror[1].status & UCBF_SURVIVOR) && (pdev->DiskMirror[0].status & UCBF_MIRRORED)) )
  2028. {
  2029. padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
  2030. }
  2031. }
  2032. OpDone (padapter, DID_OK << 16);
  2033. break;
  2034. case MY_SCSI_ALARMMUTE:
  2035. MuteAlarm (padapter);
  2036. OpDone (padapter, DID_OK << 16);
  2037. break;
  2038. case MY_SCSI_DEMOFAIL:
  2039. padapter->demoFail = TRUE;
  2040. OpDone (padapter, DID_OK << 16);
  2041. break;
  2042. default:
  2043. z = cdb[5]; // get index
  2044. pdr = (PDEVICE_RAID1)SCpnt->request_buffer;
  2045. if ( padapter->raidData[z] )
  2046. {
  2047. memcpy (&pdr->DiskRaid1, padapter->raidData[z], sizeof (DISK_MIRROR));
  2048. if ( padapter->raidData[z]->reconstructPoint > padapter->raidData[z ^ 2]->reconstructPoint )
  2049. pdr->TotalSectors = padapter->raidData[z]->reconstructPoint;
  2050. else
  2051. pdr->TotalSectors = padapter->raidData[z ^ 2]->reconstructPoint;
  2052. }
  2053. else
  2054. memset (pdr, 0, sizeof (DEVICE_RAID1));
  2055. OpDone (padapter, DID_OK << 16);
  2056. break;
  2057. }
  2058. return 0;
  2059. }
  2060. padapter->cmd = IDE_COMMAND_IDENTIFY;
  2061. break;
  2062. }
  2063. case SCSIOP_TEST_UNIT_READY: // test unit ready CDB
  2064. OpDone (padapter, DID_OK << 16);
  2065. return 0;
  2066. case SCSIOP_READ_CAPACITY:    // read capctiy CDB
  2067. {
  2068. PREAD_CAPACITY_DATA pdata = (PREAD_CAPACITY_DATA)SCpnt->request_buffer;
  2069. pdata->blksiz = 0x20000;
  2070. XANY2SCSI ((UCHAR *)&pdata->blks, pdev->blocks);
  2071. OpDone (padapter, DID_OK << 16);
  2072. return 0;
  2073. }
  2074. case SCSIOP_VERIFY: // verify CDB
  2075. padapter->startSector = XSCSI2LONG (&cdb[2]);
  2076. padapter->sectorCount = (UCHAR)((USHORT)cdb[8] | ((USHORT)cdb[7] << 8));
  2077. padapter->cmd = IDE_COMMAND_VERIFY;
  2078. break;
  2079. case SCSIOP_READ: // read10 CDB
  2080. padapter->startSector = XSCSI2LONG (&cdb[2]);
  2081. padapter->sectorCount = (USHORT)cdb[8] | ((USHORT)cdb[7] << 8);
  2082. padapter->cmd = READ_CMD;
  2083. break;
  2084. case SCSIOP_READ6: // read6  CDB
  2085. padapter->startSector = SCSI2LONG (&cdb[1]);
  2086. padapter->sectorCount = cdb[4];
  2087. padapter->cmd = READ_CMD;
  2088. break;
  2089. case SCSIOP_WRITE: // write10 CDB
  2090. padapter->startSector = XSCSI2LONG (&cdb[2]);
  2091. padapter->sectorCount = (USHORT)cdb[8] | ((USHORT)cdb[7] << 8);
  2092. padapter->cmd = WRITE_CMD;
  2093. break;
  2094. case SCSIOP_WRITE6: // write6  CDB
  2095. padapter->startSector = SCSI2LONG (&cdb[1]);
  2096. padapter->sectorCount = cdb[4];
  2097. padapter->cmd = WRITE_CMD;
  2098. break;
  2099. default:
  2100. DEB (printk ("pci2220i_queuecommand: Unsupported command %02Xn", *cdb));
  2101. OpDone (padapter, DID_ERROR << 16);
  2102. return 0;
  2103. }
  2104. if ( padapter->reconPhase )
  2105. return 0;
  2106. padapter->pdev = pdev;
  2107. while ( padapter->demoFail )
  2108. {
  2109. pdev = padapter->pdev = &padapter->device[0];
  2110. padapter->demoFail = FALSE;
  2111. if ( !pdev->raid || 
  2112.  (pdev->DiskMirror[0].status & UCBF_SURVIVOR) || 
  2113.  (pdev->DiskMirror[1].status & UCBF_SURVIVOR) )
  2114. {
  2115. break;
  2116. }
  2117. if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
  2118. padapter->survivor = 1;
  2119. else
  2120. padapter->survivor = 0;
  2121. DEB (printk ("npci2220i: FAILURE 19"));
  2122. if ( InitFailover (padapter, pdev) )
  2123. break;
  2124. return 0;
  2125. }
  2126. StartTimer (padapter);
  2127. if ( pdev->raid && (padapter->cmd == WRITE_CMD) )
  2128. {
  2129. rc = IdeCmdBoth (padapter, pdev);
  2130. if ( !rc )
  2131. rc = WriteDataBoth (padapter, pdev);
  2132. if ( rc )
  2133. {
  2134. del_timer (&padapter->timer);
  2135. padapter->expectingIRQ = 0;
  2136. padapter->survivor = rc >> 1;
  2137. DEB (printk ("npci2220i: FAILURE 20"));
  2138. if ( InitFailover (padapter, pdev) )
  2139. {
  2140. OpDone (padapter, DID_ERROR << 16);
  2141. return 0;
  2142. }
  2143. }
  2144. }
  2145. else
  2146. {
  2147. rc = IdeCmd (padapter, pdev);
  2148. if ( (padapter->cmd == WRITE_CMD) && !rc )
  2149. rc = WriteData (padapter);
  2150. if ( rc )
  2151. {
  2152. del_timer (&padapter->timer);
  2153. padapter->expectingIRQ = 0;
  2154. if ( pdev->raid )
  2155. {
  2156. padapter->survivor = (pdev->spigot ^ 3) >> 1;
  2157. DEB (printk ("npci2220i: FAILURE 21"));
  2158. if ( !InitFailover (padapter, pdev) )
  2159. return 0;
  2160. }
  2161. OpDone (padapter, DID_ERROR << 16);
  2162. return 0;
  2163. }
  2164. }
  2165. return 0;
  2166. }
  2167. static void internal_done(Scsi_Cmnd *SCpnt)
  2168. {
  2169. SCpnt->SCp.Status++;
  2170. }
  2171. /****************************************************************
  2172.  * Name: Pci2220i_Command
  2173.  *
  2174.  * Description: Process a command from the SCSI manager.
  2175.  *
  2176.  * Parameters: SCpnt - Pointer to SCSI command structure.
  2177.  *
  2178.  * Returns: Status code.
  2179.  *
  2180.  ****************************************************************/
  2181. int Pci2220i_Command (Scsi_Cmnd *SCpnt)
  2182. {
  2183. Pci2220i_QueueCommand (SCpnt, internal_done);
  2184.     SCpnt->SCp.Status = 0;
  2185. while (!SCpnt->SCp.Status)
  2186. barrier ();
  2187. return SCpnt->result;
  2188. }
  2189. /****************************************************************
  2190.  * Name: ReadFlash
  2191.  *
  2192.  * Description: Read information from controller Flash memory.
  2193.  *
  2194.  * Parameters: padapter - Pointer to host interface data structure.
  2195.  * pdata  - Pointer to data structures.
  2196.  * base  - base address in Flash.
  2197.  * length  - lenght of data space in bytes.
  2198.  *
  2199.  * Returns: Nothing.
  2200.  *
  2201.  ****************************************************************/
  2202. static VOID ReadFlash (PADAPTER2220I padapter, VOID *pdata, ULONG base, ULONG length)
  2203. {
  2204. ULONG  oldremap;
  2205. UCHAR  olddesc;
  2206. ULONG  z;
  2207. UCHAR *pd = (UCHAR *)pdata;
  2208. oldremap = inl (padapter->regRemap); // save values to restore later
  2209. olddesc  = inb_p (padapter->regDesc);
  2210. outl (base | 1, padapter->regRemap); // remap to Flash space as specified
  2211. outb_p (0x40, padapter->regDesc); // describe remap region as 8 bit
  2212. for ( z = 0;  z < length;  z++) // get "length" data count
  2213. *pd++ = inb_p (padapter->regBase + z); // read in the data
  2214. outl (oldremap, padapter->regRemap); // restore remap register values
  2215. outb_p (olddesc, padapter->regDesc);
  2216. }
  2217. /****************************************************************
  2218.  * Name: GetRegs
  2219.  *
  2220.  * Description: Initialize the regester information.
  2221.  *
  2222.  * Parameters: pshost   - Pointer to SCSI host data structure.
  2223.  * bigd   - PCI-2240I identifier
  2224.  * pcidev   - Pointer to device data structure.
  2225.  *
  2226.  * Returns: TRUE if failure to install.
  2227.  *
  2228.  ****************************************************************/
  2229. static USHORT GetRegs (struct Scsi_Host *pshost, BOOL bigd, struct pci_dev *pcidev)
  2230. {
  2231. PADAPTER2220I padapter;
  2232. int setirq;
  2233. int z;
  2234. USHORT zr, zl;
  2235. UCHAR    *consistent;
  2236. dma_addr_t consistentDma;
  2237. padapter = HOSTDATA(pshost);
  2238. memset (padapter, 0, sizeof (ADAPTER2220I));
  2239. memset (&DaleSetup, 0, sizeof (DaleSetup));
  2240. memset (DiskMirror, 0, sizeof (DiskMirror));
  2241. zr = pci_resource_start (pcidev, 1);
  2242. zl = pci_resource_start (pcidev, 2);
  2243. padapter->basePort = zr;
  2244. padapter->regRemap = zr + RTR_LOCAL_REMAP; // 32 bit local space remap
  2245. padapter->regDesc = zr + RTR_REGIONS;    // 32 bit local region descriptor
  2246. padapter->regRange = zr + RTR_LOCAL_RANGE; // 32 bit local range
  2247. padapter->regIrqControl = zr + RTR_INT_CONTROL_STATUS; // 16 bit interupt control and status
  2248. padapter->regScratchPad = zr + RTR_MAILBOX;    // 16 byte scratchpad I/O base address
  2249. padapter->regBase = zl;
  2250. padapter->regData = zl + REG_DATA; // data register I/O address
  2251. padapter->regError = zl + REG_ERROR; // error register I/O address
  2252. padapter->regSectCount = zl + REG_SECTOR_COUNT; // sector count register I/O address
  2253. padapter->regLba0 = zl + REG_LBA_0; // least significant byte of LBA
  2254. padapter->regLba8 = zl + REG_LBA_8; // next least significant byte of LBA
  2255. padapter->regLba16 = zl + REG_LBA_16; // next most significan byte of LBA
  2256. padapter->regLba24 = zl + REG_LBA_24; // head and most 4 significant bits of LBA
  2257. padapter->regStatCmd = zl + REG_STAT_CMD; // status on read and command on write register
  2258. padapter->regStatSel = zl + REG_STAT_SEL; // board status on read and spigot select on write register
  2259. padapter->regFail = zl + REG_FAIL;
  2260. padapter->regAltStat = zl + REG_ALT_STAT;
  2261. padapter->pcidev = pcidev;
  2262. if ( bigd )
  2263. {
  2264. padapter->regDmaDesc = zr + RTR_DMA0_DESC_PTR; // address of the DMA discriptor register for direction of transfer
  2265. padapter->regDmaCmdStat = zr + RTR_DMA_COMMAND_STATUS; // Byte #0 of DMA command status register
  2266. padapter->regDmaAddrPci = zr + RTR_DMA0_PCI_ADDR; // 32 bit register for PCI address of DMA
  2267. padapter->regDmaAddrLoc = zr + RTR_DMA0_LOCAL_ADDR; // 32 bit register for local bus address of DMA
  2268. padapter->regDmaCount = zr + RTR_DMA0_COUNT; // 32 bit register for DMA transfer count
  2269. padapter->regDmaMode = zr + RTR_DMA0_MODE + 1; // 32 bit register for DMA mode control
  2270. padapter->bigD = SEL_NEW_SPEED_1; // set spigot speed control bit
  2271. }
  2272. else
  2273. {
  2274. padapter->regDmaDesc = zl + RTL_DMA1_DESC_PTR; // address of the DMA discriptor register for direction of transfer
  2275. padapter->regDmaCmdStat = zl + RTL_DMA_COMMAND_STATUS + 1; // Byte #1 of DMA command status register
  2276. padapter->regDmaAddrPci = zl + RTL_DMA1_PCI_ADDR; // 32 bit register for PCI address of DMA
  2277. padapter->regDmaAddrLoc = zl + RTL_DMA1_LOCAL_ADDR; // 32 bit register for local bus address of DMA
  2278. padapter->regDmaCount = zl + RTL_DMA1_COUNT; // 32 bit register for DMA transfer count
  2279. padapter->regDmaMode = zl + RTL_DMA1_MODE + 1; // 32 bit register for DMA mode control
  2280. }
  2281. padapter->numberOfDrives = inb_p (padapter->regScratchPad + BIGD_NUM_DRIVES);
  2282. if ( !bigd && !padapter->numberOfDrives ) // if no devices on this board
  2283. return TRUE;
  2284. pshost->irq = pcidev->irq;
  2285. setirq = 1;
  2286. for ( z = 0;  z < Installed;  z++ ) // scan for shared interrupts
  2287. {
  2288. if ( PsiHost[z]->irq == pshost->irq ) // if shared then, don't posses
  2289. setirq = 0;
  2290. }
  2291. if ( setirq ) // if not shared, posses
  2292. {
  2293. if ( request_irq (pshost->irq, Irq_Handler, SA_SHIRQ, "pci2220i", padapter) < 0 )
  2294. {
  2295. if ( request_irq (pshost->irq, Irq_Handler, SA_INTERRUPT | SA_SHIRQ, "pci2220i", padapter) < 0 )
  2296. {
  2297. printk ("Unable to allocate IRQ for PCI-2220I controller.n");
  2298. return TRUE;
  2299. }
  2300. }
  2301. padapter->irqOwned = pshost->irq; // set IRQ as owned
  2302. }
  2303. if ( padapter->numberOfDrives )
  2304. consistent = pci_alloc_consistent (pcidev, SECTORSXFER * BYTES_PER_SECTOR, &consistentDma);
  2305. else
  2306. consistent = pci_alloc_consistent (pcidev, ATAPI_TRANSFER, &consistentDma);
  2307. if ( !consistent )
  2308. {
  2309. printk ("Unable to allocate DMA buffer for PCI-2220I controller.n");
  2310. free_irq (pshost->irq, padapter);
  2311. return TRUE;
  2312. }
  2313. padapter->kBuffer = consistent;
  2314. padapter->kBufferDma = consistentDma;
  2315. PsiHost[Installed] = pshost; // save SCSI_HOST pointer
  2316. pshost->io_port = padapter->basePort;
  2317. pshost->n_io_port = 0xFF;
  2318. pshost->unique_id = padapter->regBase;
  2319. outb_p (0x01, padapter->regRange); // fix our range register because other drivers want to tromp on it
  2320. padapter->timingMode = inb_p (padapter->regScratchPad + DALE_TIMING_MODE);
  2321. if ( padapter->timingMode >= 2 )
  2322. {
  2323. if ( bigd )
  2324. padapter->timingAddress = ModeArray2[padapter->timingMode - 2];
  2325. else
  2326. padapter->timingAddress = ModeArray[padapter->timingMode - 2];
  2327. }
  2328. else
  2329. padapter->timingPIO = TRUE;
  2330. ReadFlash (padapter, &DaleSetup, DALE_FLASH_SETUP, sizeof (SETUP));
  2331. ReadFlash (padapter, &DiskMirror, DALE_FLASH_RAID, sizeof (DiskMirror));
  2332. return FALSE;
  2333. }
  2334. /****************************************************************
  2335.  * Name: SetupFinish
  2336.  *
  2337.  * Description: Complete the driver initialization process for a card
  2338.  *
  2339.  * Parameters: padapter  - Pointer to SCSI host data structure.
  2340.  * str   - Pointer to board type string.
  2341.  *
  2342.  * Returns: Nothing.
  2343.  *
  2344.  ****************************************************************/
  2345. VOID SetupFinish (PADAPTER2220I padapter, char *str, int irq)
  2346. {
  2347. init_timer (&padapter->timer);
  2348. padapter->timer.function = TimerExpiry;
  2349. padapter->timer.data = (unsigned long)padapter;
  2350. init_timer (&padapter->reconTimer);
  2351. padapter->reconTimer.function = ReconTimerExpiry;
  2352. padapter->reconTimer.data = (unsigned long)padapter;
  2353. printk("nPCI-%sI EIDE CONTROLLER: at I/O = %lX/%lX  IRQ = %dn", str, padapter->basePort, padapter->regBase, irq);
  2354. printk("Version %s, Compiled %s %snn", PCI2220I_VERSION, __DATE__, __TIME__);
  2355. }
  2356. /****************************************************************
  2357.  * Name: Pci2220i_Detect
  2358.  *
  2359.  * Description: Detect and initialize our boards.
  2360.  *
  2361.  * Parameters: tpnt - Pointer to SCSI host template structure.
  2362.  *
  2363.  * Returns: Number of adapters installed.
  2364.  *
  2365.  ****************************************************************/
  2366. int Pci2220i_Detect (Scsi_Host_Template *tpnt)
  2367. {
  2368. struct Scsi_Host   *pshost;
  2369. PADAPTER2220I     padapter;
  2370. POUR_DEVICE pdev;
  2371. int unit;
  2372. int z;
  2373. USHORT raidon;
  2374. UCHAR spigot1, spigot2;
  2375. UCHAR device;
  2376. struct pci_dev    *pcidev = NULL;
  2377. if ( !pci_present () )
  2378. {
  2379. printk ("pci2220i: PCI BIOS not presentn");
  2380. return 0;
  2381. }
  2382. while ( (pcidev = pci_find_device (VENDOR_PSI, DEVICE_DALE_1, pcidev)) != NULL )
  2383. {
  2384. if (pci_enable_device(pcidev))
  2385. continue;
  2386. pshost = scsi_register (tpnt, sizeof(ADAPTER2220I));
  2387. if(pshost==NULL)
  2388. continue;
  2389. padapter = HOSTDATA(pshost);
  2390. if ( GetRegs (pshost, FALSE, pcidev) )
  2391. goto unregister;
  2392. scsi_set_pci_device(pshost, pcidev);
  2393. pshost->max_id = padapter->numberOfDrives;
  2394. for ( z = 0;  z < padapter->numberOfDrives;  z++ )
  2395. {
  2396. unit = inb_p (padapter->regScratchPad + DALE_CHANNEL_DEVICE_0 + z) & 0x0F;
  2397. pdev = &padapter->device[z];
  2398. pdev->byte6 = (UCHAR)(((unit & 1) << 4) | 0xE0);
  2399. pdev->spigot = (UCHAR)(1 << (unit >> 1));
  2400. pdev->sectors = DaleSetup.setupDevice[unit].sectors;
  2401. pdev->heads = DaleSetup.setupDevice[unit].heads;
  2402. pdev->cylinders = DaleSetup.setupDevice[unit].cylinders;
  2403. pdev->blocks = DaleSetup.setupDevice[unit].blocks;
  2404. if ( !z )
  2405. {
  2406. DiskMirror[0].status = inb_p (padapter->regScratchPad + DALE_RAID_0_STATUS);
  2407. DiskMirror[1].status = inb_p (padapter->regScratchPad + DALE_RAID_1_STATUS);
  2408. if ( (DiskMirror[0].signature == SIGNATURE) && (DiskMirror[1].signature == SIGNATURE) &&
  2409.      (DiskMirror[0].pairIdentifier == (DiskMirror[1].pairIdentifier ^ 1)) )
  2410. {  
  2411. raidon = TRUE;
  2412. if ( unit > (unit ^ 2) )
  2413. unit = unit ^ 2;
  2414. }
  2415. else
  2416. raidon = FALSE;
  2417. memcpy (pdev->DiskMirror, DiskMirror, sizeof (DiskMirror));
  2418. padapter->raidData[0] = &pdev->DiskMirror[0];
  2419. padapter->raidData[2] = &pdev->DiskMirror[1];
  2420. spigot1 = spigot2 = FALSE;
  2421. pdev->spigots[0] = 1;
  2422. pdev->spigots[1] = 2;
  2423. pdev->lastsectorlba[0] = InlineIdentify (padapter, 1, 0);
  2424. pdev->lastsectorlba[1] = InlineIdentify (padapter, 2, 0);
  2425. if ( !(pdev->DiskMirror[1].status & UCBF_SURVIVOR) && pdev->lastsectorlba[0] )
  2426. spigot1 = TRUE;
  2427. if ( !(pdev->DiskMirror[0].status & UCBF_SURVIVOR) && pdev->lastsectorlba[1] )
  2428. spigot2 = TRUE;
  2429. if ( pdev->DiskMirror[0].status & DiskMirror[1].status & UCBF_SURVIVOR )
  2430. spigot1 = TRUE;
  2431. if ( spigot1 && (pdev->DiskMirror[0].status & UCBF_REBUILD) )
  2432. InlineReadSignature (padapter, pdev, 0);
  2433. if ( spigot2 && (pdev->DiskMirror[1].status & UCBF_REBUILD) )
  2434. InlineReadSignature (padapter, pdev, 1);
  2435. if ( spigot1 && spigot2 && raidon )
  2436. {
  2437. pdev->raid = 1;
  2438. if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
  2439. pdev->spigot = 2;
  2440. else
  2441. pdev->spigot = 1;
  2442. if ( (pdev->DiskMirror[0].status & UCBF_REBUILD) || (pdev->DiskMirror[1].status & UCBF_REBUILD) )
  2443. padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
  2444. }
  2445. else
  2446. {
  2447. if ( spigot1 )
  2448. {
  2449. if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
  2450. goto unregister;
  2451. pdev->DiskMirror[0].status = UCBF_MIRRORED | UCBF_SURVIVOR;
  2452. pdev->spigot = 1;
  2453. }
  2454. else
  2455. {
  2456. if ( pdev->DiskMirror[1].status & UCBF_REBUILD )
  2457. goto unregister;
  2458. pdev->DiskMirror[1].status = UCBF_MIRRORED | UCBF_SURVIVOR;
  2459. pdev->spigot = 2;
  2460. }
  2461. if ( DaleSetup.rebootRebuild && raidon )
  2462. padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
  2463. }
  2464. if ( raidon )
  2465. break;
  2466. }
  2467. }
  2468. SetupFinish (padapter, "2220", pshost->irq);
  2469. if ( ++Installed < MAXADAPTER )
  2470. continue;
  2471. break;;
  2472. unregister:;
  2473. scsi_unregister (pshost);
  2474. }
  2475. while ( (pcidev = pci_find_device (VENDOR_PSI, DEVICE_BIGD_1, pcidev)) != NULL )
  2476. {
  2477. pshost = scsi_register (tpnt, sizeof(ADAPTER2220I));
  2478. padapter = HOSTDATA(pshost);
  2479. if ( GetRegs (pshost, TRUE, pcidev) )
  2480. goto unregister1;
  2481. for ( z = 0;  z < BIGD_MAXDRIVES;  z++ )
  2482. DiskMirror[z].status = inb_p (padapter->regScratchPad + BIGD_RAID_0_STATUS + z);
  2483. scsi_set_pci_device(pshost, pcidev);
  2484. pshost->max_id = padapter->numberOfDrives;
  2485. padapter->failRegister = inb_p (padapter->regScratchPad + BIGD_ALARM_IMAGE);
  2486. for ( z = 0;  z < padapter->numberOfDrives;  z++ )
  2487. {
  2488. unit = inb_p (padapter->regScratchPad + BIGD_DEVICE_0 + z);
  2489. pdev = &padapter->device[z];
  2490. pdev->byte6 = (UCHAR)(((unit & 1) << 4) | 0xE0);
  2491. pdev->spigot = (UCHAR)(1 << (unit >> 1));
  2492. pdev->sectors = DaleSetup.setupDevice[unit].sectors;
  2493. pdev->heads = DaleSetup.setupDevice[unit].heads;
  2494. pdev->cylinders = DaleSetup.setupDevice[unit].cylinders;
  2495. pdev->blocks = DaleSetup.setupDevice[unit].blocks;
  2496. if ( (DiskMirror[unit].signature == SIGNATURE) && (DiskMirror[unit ^ 2].signature == SIGNATURE) &&
  2497.      (DiskMirror[unit].pairIdentifier == (DiskMirror[unit ^ 2].pairIdentifier ^ 1)) )
  2498. {  
  2499. raidon = TRUE;
  2500. if ( unit > (unit ^ 2) )
  2501. unit = unit ^ 2;
  2502. }
  2503. else
  2504. raidon = FALSE;
  2505. spigot1 = spigot2 = FALSE;
  2506. memcpy (&pdev->DiskMirror[0], &DiskMirror[unit], sizeof (DISK_MIRROR));
  2507. memcpy (&pdev->DiskMirror[1], &DiskMirror[unit ^ 2], sizeof (DISK_MIRROR));
  2508. padapter->raidData[unit]  = &pdev->DiskMirror[0];
  2509. padapter->raidData[unit ^ 2] = &pdev->DiskMirror[1];
  2510. pdev->spigots[0] = 1 << (unit >> 1);
  2511. pdev->spigots[1] = 1 << ((unit ^ 2) >> 1);
  2512. pdev->deviceID[0] = unit;
  2513. pdev->deviceID[1] = unit ^ 2;
  2514. pdev->lastsectorlba[0] = InlineIdentify (padapter, pdev->spigots[0], unit & 1);
  2515. pdev->lastsectorlba[1] = InlineIdentify (padapter, pdev->spigots[1], unit & 1);
  2516. if ( !(pdev->DiskMirror[1].status & UCBF_SURVIVOR) && pdev->lastsectorlba[0] )
  2517. spigot1 = TRUE;
  2518. if ( !(pdev->DiskMirror[0].status & UCBF_SURVIVOR) && pdev->lastsectorlba[1] )
  2519. spigot2 = TRUE;
  2520. if ( pdev->DiskMirror[0].status & pdev->DiskMirror[1].status & UCBF_SURVIVOR )
  2521. spigot1 = TRUE;
  2522. if ( spigot1 && (pdev->DiskMirror[0].status & UCBF_REBUILD) )
  2523. InlineReadSignature (padapter, pdev, 0);
  2524. if ( spigot2 && (pdev->DiskMirror[1].status & UCBF_REBUILD) )
  2525. InlineReadSignature (padapter, pdev, 1);
  2526. if ( spigot1 && spigot2 && raidon )
  2527. {
  2528. pdev->raid = 1;
  2529. if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
  2530. pdev->spigot = pdev->spigots[1];
  2531. else
  2532. pdev->spigot = pdev->spigots[0];
  2533. if ( (pdev->DiskMirror[0].status & UCBF_REBUILD) || (pdev->DiskMirror[1].status & UCBF_REBUILD) )
  2534. padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
  2535. }
  2536. else
  2537. {
  2538. if ( spigot1 )
  2539. {
  2540. if ( pdev->DiskMirror[0].status & UCBF_REBUILD )
  2541. goto unregister1;
  2542. pdev->DiskMirror[0].status = UCBF_MIRRORED | UCBF_SURVIVOR;
  2543. pdev->spigot = pdev->spigots[0];
  2544. }
  2545. else
  2546. {
  2547. if ( pdev->DiskMirror[1].status & UCBF_REBUILD )
  2548. goto unregister;
  2549. pdev->DiskMirror[1].status = UCBF_MIRRORED | UCBF_SURVIVOR;
  2550. pdev->spigot = pdev->spigots[1];
  2551. }
  2552. if ( DaleSetup.rebootRebuild && raidon )
  2553. padapter->reconOn = pdev->reconOn = pdev->reconIsStarting = TRUE;
  2554. }
  2555. }
  2556. if ( !padapter->numberOfDrives ) // If no ATA devices then scan ATAPI
  2557. {
  2558. unit = 0;
  2559. for ( spigot1 = 0;  spigot1 < 4;  spigot1++ )
  2560. {
  2561. for ( device = 0;  device < 2;  device++ )
  2562. {
  2563. DEB (printk ("nPCI2242I: scanning for ID %d ", (spigot1 * 2) + device));
  2564. pdev = &(padapter->device[(spigot1 * 2) + device]);
  2565. pdev->byte6 = 0x0A | (device << 4);
  2566. pdev->spigot = 1 << spigot1;
  2567. if ( !AtapiReset (padapter, pdev) )
  2568. {
  2569. DEB (printk (" Device found "));
  2570. if ( !AtapiIdentify (padapter, pdev) )
  2571. {
  2572. DEB (printk (" Device verified"));
  2573. unit++;
  2574. continue;
  2575. }
  2576. }
  2577. pdev->spigot = pdev->byte6 = 0;
  2578. }
  2579. }
  2580. if ( unit )
  2581. {
  2582. padapter->atapi = TRUE;
  2583. padapter->timingAddress = DALE_DATA_MODE3;
  2584. outw_p (0x0900, padapter->regIrqControl); // Turn our interrupts on
  2585. outw_p (0x0C41, padapter->regDmaMode - 1); // setup for 16 bits, ready enabled, done IRQ enabled, no incriment
  2586. outb_p (0xFF, padapter->regFail); // all fail lights and alarm off
  2587. pshost->max_id = 8;
  2588. }
  2589. }
  2590. SetupFinish (padapter, "2240", pshost->irq);
  2591. if ( ++Installed < MAXADAPTER )
  2592. continue;
  2593. break;;
  2594. unregister1:;
  2595. scsi_unregister (pshost);
  2596. }
  2597. NumAdapters = Installed;
  2598. return Installed;
  2599. }
  2600. /****************************************************************
  2601.  * Name: Pci2220i_Abort
  2602.  *
  2603.  * Description: Process the Abort command from the SCSI manager.
  2604.  *
  2605.  * Parameters: SCpnt - Pointer to SCSI command structure.
  2606.  *
  2607.  * Returns: Allways snooze.
  2608.  *
  2609.  ****************************************************************/
  2610. int Pci2220i_Abort (Scsi_Cmnd *SCpnt)
  2611. {
  2612. PADAPTER2220I padapter = HOSTDATA(SCpnt->host); // Pointer to adapter control structure
  2613. POUR_DEVICE pdev  = &padapter->device[SCpnt->target];// Pointer to device information
  2614. if ( !padapter->SCpnt )
  2615. return SCSI_ABORT_NOT_RUNNING;
  2616. if ( padapter->atapi )
  2617. {
  2618. if ( AtapiReset (padapter, pdev) )
  2619. return SCSI_ABORT_ERROR;
  2620. OpDone (padapter, DID_ABORT << 16);
  2621. return SCSI_ABORT_SUCCESS;
  2622. }
  2623. return SCSI_ABORT_SNOOZE;
  2624. }
  2625. /****************************************************************
  2626.  * Name: Pci2220i_Reset
  2627.  *
  2628.  * Description: Process the Reset command from the SCSI manager.
  2629.  *
  2630.  * Parameters: SCpnt - Pointer to SCSI command structure.
  2631.  * flags - Flags about the reset command
  2632.  *
  2633.  * Returns: No active command at this time, so this means
  2634.  * that each time we got some kind of response the
  2635.  * last time through.  Tell the mid-level code to
  2636.  * request sense information in order to decide what
  2637.  * to do next.
  2638.  *
  2639.  ****************************************************************/
  2640. int Pci2220i_Reset (Scsi_Cmnd *SCpnt, unsigned int reset_flags)
  2641. {
  2642. PADAPTER2220I padapter = HOSTDATA(SCpnt->host); // Pointer to adapter control structure
  2643. POUR_DEVICE pdev  = &padapter->device[SCpnt->target];// Pointer to device information
  2644. if ( padapter->atapi )
  2645. {
  2646. if ( AtapiReset (padapter, pdev) )
  2647. return SCSI_RESET_ERROR;
  2648. return SCSI_RESET_SUCCESS;
  2649. }
  2650. return SCSI_RESET_PUNT;
  2651. }
  2652. /****************************************************************
  2653.  * Name: Pci2220i_Release
  2654.  *
  2655.  * Description: Release resources allocated for a single each adapter.
  2656.  *
  2657.  * Parameters: pshost - Pointer to SCSI command structure.
  2658.  *
  2659.  * Returns: zero.
  2660.  *
  2661.  ****************************************************************/
  2662. int Pci2220i_Release (struct Scsi_Host *pshost)
  2663. {
  2664.     PADAPTER2220I padapter = HOSTDATA (pshost);
  2665. USHORT z;
  2666. if ( padapter->reconOn )
  2667. {
  2668. padapter->reconOn = FALSE; // shut down the hot reconstruct
  2669. if ( padapter->reconPhase )
  2670. mdelay (300);
  2671. if ( padapter->reconTimer.data ) // is the timer running?
  2672. {
  2673. del_timer (&padapter->reconTimer);
  2674. padapter->reconTimer.data = 0;
  2675. }
  2676. }
  2677. // save RAID status on the board
  2678. if ( padapter->bigD )
  2679. {
  2680. outb_p (padapter->failRegister, padapter->regScratchPad + BIGD_ALARM_IMAGE);
  2681. for ( z = 0;  z < BIGD_MAXDRIVES;  z++ )
  2682. {
  2683. if ( padapter->raidData )
  2684. outb_p (padapter->raidData[z]->status, padapter->regScratchPad + BIGD_RAID_0_STATUS + z);
  2685. else
  2686. outb_p (0, padapter->regScratchPad + BIGD_RAID_0_STATUS);
  2687. }
  2688. }
  2689. else
  2690. {
  2691. outb_p (padapter->device[0].DiskMirror[0].status, padapter->regScratchPad + DALE_RAID_0_STATUS);
  2692. outb_p (padapter->device[0].DiskMirror[1].status, padapter->regScratchPad + DALE_RAID_1_STATUS);
  2693. }
  2694. if ( padapter->irqOwned )
  2695. free_irq (pshost->irq, padapter);
  2696.     release_region (pshost->io_port, pshost->n_io_port);
  2697. if ( padapter->numberOfDrives )
  2698. pci_free_consistent (padapter->pcidev, SECTORSXFER * BYTES_PER_SECTOR, padapter->kBuffer, padapter->kBufferDma);
  2699. else
  2700. pci_free_consistent (padapter->pcidev, ATAPI_TRANSFER, padapter->kBuffer, padapter->kBufferDma);
  2701.     scsi_unregister(pshost);
  2702.     return 0;
  2703. }
  2704. #include "sd.h"
  2705. /****************************************************************
  2706.  * Name: Pci2220i_BiosParam
  2707.  *
  2708.  * Description: Process the biosparam request from the SCSI manager to
  2709.  * return C/H/S data.
  2710.  *
  2711.  * Parameters: disk - Pointer to SCSI disk structure.
  2712.  * dev  - Major/minor number from kernel.
  2713.  * geom - Pointer to integer array to place geometry data.
  2714.  *
  2715.  * Returns: zero.
  2716.  *
  2717.  ****************************************************************/
  2718. int Pci2220i_BiosParam (Scsi_Disk *disk, kdev_t dev, int geom[])
  2719. {
  2720. POUR_DEVICE pdev;
  2721. if ( !(HOSTDATA(disk->device->host))->atapi )
  2722. {
  2723. pdev = &(HOSTDATA(disk->device->host)->device[disk->device->id]);
  2724. geom[0] = pdev->heads;
  2725. geom[1] = pdev->sectors;
  2726. geom[2] = pdev->cylinders;
  2727. }
  2728. return 0;
  2729. }
  2730. MODULE_LICENSE("Dual BSD/GPL");
  2731. /* Eventually this will go into an include file, but this will be later */
  2732. static Scsi_Host_Template driver_template = PCI2220I;
  2733. #include "scsi_module.c"