pci2220i.c 89 KB

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