BusLogic.c 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632
  1. /*
  2. Linux Driver for BusLogic MultiMaster and FlashPoint SCSI Host Adapters
  3. Copyright 1995-1998 by Leonard N. Zubkoff <lnz@dandelion.com>
  4. This program is free software; you may redistribute and/or modify it under
  5. the terms of the GNU General Public License Version 2 as published by the
  6. Free Software Foundation.
  7. This program is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
  9. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  10. for complete details.
  11. The author respectfully requests that any modifications to this software be
  12. sent directly to him for evaluation and testing.
  13. Special thanks to Wayne Yen, Jin-Lon Hon, and Alex Win of BusLogic, whose
  14. advice has been invaluable, to David Gentzel, for writing the original Linux
  15. BusLogic driver, and to Paul Gortmaker, for being such a dedicated test site.
  16. Finally, special thanks to Mylex/BusLogic for making the FlashPoint SCCB
  17. Manager available as freely redistributable source code.
  18. */
  19. #define BusLogic_DriverVersion "2.1.16"
  20. #define BusLogic_DriverDate "18 July 2002"
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/types.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/delay.h>
  27. #include <linux/ioport.h>
  28. #include <linux/mm.h>
  29. #include <linux/stat.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/jiffies.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/slab.h>
  35. #include <scsi/scsicam.h>
  36. #include <asm/dma.h>
  37. #include <asm/io.h>
  38. #include <scsi/scsi.h>
  39. #include <scsi/scsi_cmnd.h>
  40. #include <scsi/scsi_device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi_tcq.h>
  43. #include "BusLogic.h"
  44. #include "FlashPoint.c"
  45. #ifndef FAILURE
  46. #define FAILURE (-1)
  47. #endif
  48. static struct scsi_host_template Bus_Logic_template;
  49. /*
  50. BusLogic_DriverOptionsCount is a count of the number of BusLogic Driver
  51. Options specifications provided via the Linux Kernel Command Line or via
  52. the Loadable Kernel Module Installation Facility.
  53. */
  54. static int BusLogic_DriverOptionsCount;
  55. /*
  56. BusLogic_DriverOptions is an array of Driver Options structures representing
  57. BusLogic Driver Options specifications provided via the Linux Kernel Command
  58. Line or via the Loadable Kernel Module Installation Facility.
  59. */
  60. static struct BusLogic_DriverOptions BusLogic_DriverOptions[BusLogic_MaxHostAdapters];
  61. /*
  62. BusLogic can be assigned a string by insmod.
  63. */
  64. MODULE_LICENSE("GPL");
  65. #ifdef MODULE
  66. static char *BusLogic;
  67. module_param(BusLogic, charp, 0);
  68. #endif
  69. /*
  70. BusLogic_ProbeOptions is a set of Probe Options to be applied across
  71. all BusLogic Host Adapters.
  72. */
  73. static struct BusLogic_ProbeOptions BusLogic_ProbeOptions;
  74. /*
  75. BusLogic_GlobalOptions is a set of Global Options to be applied across
  76. all BusLogic Host Adapters.
  77. */
  78. static struct BusLogic_GlobalOptions BusLogic_GlobalOptions;
  79. static LIST_HEAD(BusLogic_host_list);
  80. /*
  81. BusLogic_ProbeInfoCount is the number of entries in BusLogic_ProbeInfoList.
  82. */
  83. static int BusLogic_ProbeInfoCount;
  84. /*
  85. BusLogic_ProbeInfoList is the list of I/O Addresses and Bus Probe Information
  86. to be checked for potential BusLogic Host Adapters. It is initialized by
  87. interrogating the PCI Configuration Space on PCI machines as well as from the
  88. list of standard BusLogic I/O Addresses.
  89. */
  90. static struct BusLogic_ProbeInfo *BusLogic_ProbeInfoList;
  91. /*
  92. BusLogic_CommandFailureReason holds a string identifying the reason why a
  93. call to BusLogic_Command failed. It is only non-NULL when BusLogic_Command
  94. returns a failure code.
  95. */
  96. static char *BusLogic_CommandFailureReason;
  97. /*
  98. BusLogic_AnnounceDriver announces the Driver Version and Date, Author's
  99. Name, Copyright Notice, and Electronic Mail Address.
  100. */
  101. static void BusLogic_AnnounceDriver(struct BusLogic_HostAdapter *HostAdapter)
  102. {
  103. BusLogic_Announce("***** BusLogic SCSI Driver Version " BusLogic_DriverVersion " of " BusLogic_DriverDate " *****\n", HostAdapter);
  104. BusLogic_Announce("Copyright 1995-1998 by Leonard N. Zubkoff " "<lnz@dandelion.com>\n", HostAdapter);
  105. }
  106. /*
  107. BusLogic_DriverInfo returns the Host Adapter Name to identify this SCSI
  108. Driver and Host Adapter.
  109. */
  110. static const char *BusLogic_DriverInfo(struct Scsi_Host *Host)
  111. {
  112. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) Host->hostdata;
  113. return HostAdapter->FullModelName;
  114. }
  115. /*
  116. BusLogic_InitializeCCBs initializes a group of Command Control Blocks (CCBs)
  117. for Host Adapter from the BlockSize bytes located at BlockPointer. The newly
  118. created CCBs are added to Host Adapter's free list.
  119. */
  120. static void BusLogic_InitializeCCBs(struct BusLogic_HostAdapter *HostAdapter, void *BlockPointer, int BlockSize, dma_addr_t BlockPointerHandle)
  121. {
  122. struct BusLogic_CCB *CCB = (struct BusLogic_CCB *) BlockPointer;
  123. unsigned int offset = 0;
  124. memset(BlockPointer, 0, BlockSize);
  125. CCB->AllocationGroupHead = BlockPointerHandle;
  126. CCB->AllocationGroupSize = BlockSize;
  127. while ((BlockSize -= sizeof(struct BusLogic_CCB)) >= 0) {
  128. CCB->Status = BusLogic_CCB_Free;
  129. CCB->HostAdapter = HostAdapter;
  130. CCB->DMA_Handle = (u32) BlockPointerHandle + offset;
  131. if (BusLogic_FlashPointHostAdapterP(HostAdapter)) {
  132. CCB->CallbackFunction = BusLogic_QueueCompletedCCB;
  133. CCB->BaseAddress = HostAdapter->FlashPointInfo.BaseAddress;
  134. }
  135. CCB->Next = HostAdapter->Free_CCBs;
  136. CCB->NextAll = HostAdapter->All_CCBs;
  137. HostAdapter->Free_CCBs = CCB;
  138. HostAdapter->All_CCBs = CCB;
  139. HostAdapter->AllocatedCCBs++;
  140. CCB++;
  141. offset += sizeof(struct BusLogic_CCB);
  142. }
  143. }
  144. /*
  145. BusLogic_CreateInitialCCBs allocates the initial CCBs for Host Adapter.
  146. */
  147. static bool __init BusLogic_CreateInitialCCBs(struct BusLogic_HostAdapter *HostAdapter)
  148. {
  149. int BlockSize = BusLogic_CCB_AllocationGroupSize * sizeof(struct BusLogic_CCB);
  150. void *BlockPointer;
  151. dma_addr_t BlockPointerHandle;
  152. while (HostAdapter->AllocatedCCBs < HostAdapter->InitialCCBs) {
  153. BlockPointer = pci_alloc_consistent(HostAdapter->PCI_Device, BlockSize, &BlockPointerHandle);
  154. if (BlockPointer == NULL) {
  155. BusLogic_Error("UNABLE TO ALLOCATE CCB GROUP - DETACHING\n", HostAdapter);
  156. return false;
  157. }
  158. BusLogic_InitializeCCBs(HostAdapter, BlockPointer, BlockSize, BlockPointerHandle);
  159. }
  160. return true;
  161. }
  162. /*
  163. BusLogic_DestroyCCBs deallocates the CCBs for Host Adapter.
  164. */
  165. static void BusLogic_DestroyCCBs(struct BusLogic_HostAdapter *HostAdapter)
  166. {
  167. struct BusLogic_CCB *NextCCB = HostAdapter->All_CCBs, *CCB, *Last_CCB = NULL;
  168. HostAdapter->All_CCBs = NULL;
  169. HostAdapter->Free_CCBs = NULL;
  170. while ((CCB = NextCCB) != NULL) {
  171. NextCCB = CCB->NextAll;
  172. if (CCB->AllocationGroupHead) {
  173. if (Last_CCB)
  174. pci_free_consistent(HostAdapter->PCI_Device, Last_CCB->AllocationGroupSize, Last_CCB, Last_CCB->AllocationGroupHead);
  175. Last_CCB = CCB;
  176. }
  177. }
  178. if (Last_CCB)
  179. pci_free_consistent(HostAdapter->PCI_Device, Last_CCB->AllocationGroupSize, Last_CCB, Last_CCB->AllocationGroupHead);
  180. }
  181. /*
  182. BusLogic_CreateAdditionalCCBs allocates Additional CCBs for Host Adapter. If
  183. allocation fails and there are no remaining CCBs available, the Driver Queue
  184. Depth is decreased to a known safe value to avoid potential deadlocks when
  185. multiple host adapters share the same IRQ Channel.
  186. */
  187. static void BusLogic_CreateAdditionalCCBs(struct BusLogic_HostAdapter *HostAdapter, int AdditionalCCBs, bool SuccessMessageP)
  188. {
  189. int BlockSize = BusLogic_CCB_AllocationGroupSize * sizeof(struct BusLogic_CCB);
  190. int PreviouslyAllocated = HostAdapter->AllocatedCCBs;
  191. void *BlockPointer;
  192. dma_addr_t BlockPointerHandle;
  193. if (AdditionalCCBs <= 0)
  194. return;
  195. while (HostAdapter->AllocatedCCBs - PreviouslyAllocated < AdditionalCCBs) {
  196. BlockPointer = pci_alloc_consistent(HostAdapter->PCI_Device, BlockSize, &BlockPointerHandle);
  197. if (BlockPointer == NULL)
  198. break;
  199. BusLogic_InitializeCCBs(HostAdapter, BlockPointer, BlockSize, BlockPointerHandle);
  200. }
  201. if (HostAdapter->AllocatedCCBs > PreviouslyAllocated) {
  202. if (SuccessMessageP)
  203. BusLogic_Notice("Allocated %d additional CCBs (total now %d)\n", HostAdapter, HostAdapter->AllocatedCCBs - PreviouslyAllocated, HostAdapter->AllocatedCCBs);
  204. return;
  205. }
  206. BusLogic_Notice("Failed to allocate additional CCBs\n", HostAdapter);
  207. if (HostAdapter->DriverQueueDepth > HostAdapter->AllocatedCCBs - HostAdapter->TargetDeviceCount) {
  208. HostAdapter->DriverQueueDepth = HostAdapter->AllocatedCCBs - HostAdapter->TargetDeviceCount;
  209. HostAdapter->SCSI_Host->can_queue = HostAdapter->DriverQueueDepth;
  210. }
  211. }
  212. /*
  213. BusLogic_AllocateCCB allocates a CCB from Host Adapter's free list,
  214. allocating more memory from the Kernel if necessary. The Host Adapter's
  215. Lock should already have been acquired by the caller.
  216. */
  217. static struct BusLogic_CCB *BusLogic_AllocateCCB(struct BusLogic_HostAdapter
  218. *HostAdapter)
  219. {
  220. static unsigned long SerialNumber = 0;
  221. struct BusLogic_CCB *CCB;
  222. CCB = HostAdapter->Free_CCBs;
  223. if (CCB != NULL) {
  224. CCB->SerialNumber = ++SerialNumber;
  225. HostAdapter->Free_CCBs = CCB->Next;
  226. CCB->Next = NULL;
  227. if (HostAdapter->Free_CCBs == NULL)
  228. BusLogic_CreateAdditionalCCBs(HostAdapter, HostAdapter->IncrementalCCBs, true);
  229. return CCB;
  230. }
  231. BusLogic_CreateAdditionalCCBs(HostAdapter, HostAdapter->IncrementalCCBs, true);
  232. CCB = HostAdapter->Free_CCBs;
  233. if (CCB == NULL)
  234. return NULL;
  235. CCB->SerialNumber = ++SerialNumber;
  236. HostAdapter->Free_CCBs = CCB->Next;
  237. CCB->Next = NULL;
  238. return CCB;
  239. }
  240. /*
  241. BusLogic_DeallocateCCB deallocates a CCB, returning it to the Host Adapter's
  242. free list. The Host Adapter's Lock should already have been acquired by the
  243. caller.
  244. */
  245. static void BusLogic_DeallocateCCB(struct BusLogic_CCB *CCB)
  246. {
  247. struct BusLogic_HostAdapter *HostAdapter = CCB->HostAdapter;
  248. scsi_dma_unmap(CCB->Command);
  249. pci_unmap_single(HostAdapter->PCI_Device, CCB->SenseDataPointer,
  250. CCB->SenseDataLength, PCI_DMA_FROMDEVICE);
  251. CCB->Command = NULL;
  252. CCB->Status = BusLogic_CCB_Free;
  253. CCB->Next = HostAdapter->Free_CCBs;
  254. HostAdapter->Free_CCBs = CCB;
  255. }
  256. /*
  257. BusLogic_Command sends the command OperationCode to HostAdapter, optionally
  258. providing ParameterLength bytes of ParameterData and receiving at most
  259. ReplyLength bytes of ReplyData; any excess reply data is received but
  260. discarded.
  261. On success, this function returns the number of reply bytes read from
  262. the Host Adapter (including any discarded data); on failure, it returns
  263. -1 if the command was invalid, or -2 if a timeout occurred.
  264. BusLogic_Command is called exclusively during host adapter detection and
  265. initialization, so performance and latency are not critical, and exclusive
  266. access to the Host Adapter hardware is assumed. Once the host adapter and
  267. driver are initialized, the only Host Adapter command that is issued is the
  268. single byte Execute Mailbox Command operation code, which does not require
  269. waiting for the Host Adapter Ready bit to be set in the Status Register.
  270. */
  271. static int BusLogic_Command(struct BusLogic_HostAdapter *HostAdapter, enum BusLogic_OperationCode OperationCode, void *ParameterData, int ParameterLength, void *ReplyData, int ReplyLength)
  272. {
  273. unsigned char *ParameterPointer = (unsigned char *) ParameterData;
  274. unsigned char *ReplyPointer = (unsigned char *) ReplyData;
  275. union BusLogic_StatusRegister StatusRegister;
  276. union BusLogic_InterruptRegister InterruptRegister;
  277. unsigned long ProcessorFlags = 0;
  278. int ReplyBytes = 0, Result;
  279. long TimeoutCounter;
  280. /*
  281. Clear out the Reply Data if provided.
  282. */
  283. if (ReplyLength > 0)
  284. memset(ReplyData, 0, ReplyLength);
  285. /*
  286. If the IRQ Channel has not yet been acquired, then interrupts must be
  287. disabled while issuing host adapter commands since a Command Complete
  288. interrupt could occur if the IRQ Channel was previously enabled by another
  289. BusLogic Host Adapter or another driver sharing the same IRQ Channel.
  290. */
  291. if (!HostAdapter->IRQ_ChannelAcquired)
  292. local_irq_save(ProcessorFlags);
  293. /*
  294. Wait for the Host Adapter Ready bit to be set and the Command/Parameter
  295. Register Busy bit to be reset in the Status Register.
  296. */
  297. TimeoutCounter = 10000;
  298. while (--TimeoutCounter >= 0) {
  299. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  300. if (StatusRegister.sr.HostAdapterReady && !StatusRegister.sr.CommandParameterRegisterBusy)
  301. break;
  302. udelay(100);
  303. }
  304. if (TimeoutCounter < 0) {
  305. BusLogic_CommandFailureReason = "Timeout waiting for Host Adapter Ready";
  306. Result = -2;
  307. goto Done;
  308. }
  309. /*
  310. Write the OperationCode to the Command/Parameter Register.
  311. */
  312. HostAdapter->HostAdapterCommandCompleted = false;
  313. BusLogic_WriteCommandParameterRegister(HostAdapter, OperationCode);
  314. /*
  315. Write any additional Parameter Bytes.
  316. */
  317. TimeoutCounter = 10000;
  318. while (ParameterLength > 0 && --TimeoutCounter >= 0) {
  319. /*
  320. Wait 100 microseconds to give the Host Adapter enough time to determine
  321. whether the last value written to the Command/Parameter Register was
  322. valid or not. If the Command Complete bit is set in the Interrupt
  323. Register, then the Command Invalid bit in the Status Register will be
  324. reset if the Operation Code or Parameter was valid and the command
  325. has completed, or set if the Operation Code or Parameter was invalid.
  326. If the Data In Register Ready bit is set in the Status Register, then
  327. the Operation Code was valid, and data is waiting to be read back
  328. from the Host Adapter. Otherwise, wait for the Command/Parameter
  329. Register Busy bit in the Status Register to be reset.
  330. */
  331. udelay(100);
  332. InterruptRegister.All = BusLogic_ReadInterruptRegister(HostAdapter);
  333. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  334. if (InterruptRegister.ir.CommandComplete)
  335. break;
  336. if (HostAdapter->HostAdapterCommandCompleted)
  337. break;
  338. if (StatusRegister.sr.DataInRegisterReady)
  339. break;
  340. if (StatusRegister.sr.CommandParameterRegisterBusy)
  341. continue;
  342. BusLogic_WriteCommandParameterRegister(HostAdapter, *ParameterPointer++);
  343. ParameterLength--;
  344. }
  345. if (TimeoutCounter < 0) {
  346. BusLogic_CommandFailureReason = "Timeout waiting for Parameter Acceptance";
  347. Result = -2;
  348. goto Done;
  349. }
  350. /*
  351. The Modify I/O Address command does not cause a Command Complete Interrupt.
  352. */
  353. if (OperationCode == BusLogic_ModifyIOAddress) {
  354. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  355. if (StatusRegister.sr.CommandInvalid) {
  356. BusLogic_CommandFailureReason = "Modify I/O Address Invalid";
  357. Result = -1;
  358. goto Done;
  359. }
  360. if (BusLogic_GlobalOptions.TraceConfiguration)
  361. BusLogic_Notice("BusLogic_Command(%02X) Status = %02X: " "(Modify I/O Address)\n", HostAdapter, OperationCode, StatusRegister.All);
  362. Result = 0;
  363. goto Done;
  364. }
  365. /*
  366. Select an appropriate timeout value for awaiting command completion.
  367. */
  368. switch (OperationCode) {
  369. case BusLogic_InquireInstalledDevicesID0to7:
  370. case BusLogic_InquireInstalledDevicesID8to15:
  371. case BusLogic_InquireTargetDevices:
  372. /* Approximately 60 seconds. */
  373. TimeoutCounter = 60 * 10000;
  374. break;
  375. default:
  376. /* Approximately 1 second. */
  377. TimeoutCounter = 10000;
  378. break;
  379. }
  380. /*
  381. Receive any Reply Bytes, waiting for either the Command Complete bit to
  382. be set in the Interrupt Register, or for the Interrupt Handler to set the
  383. Host Adapter Command Completed bit in the Host Adapter structure.
  384. */
  385. while (--TimeoutCounter >= 0) {
  386. InterruptRegister.All = BusLogic_ReadInterruptRegister(HostAdapter);
  387. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  388. if (InterruptRegister.ir.CommandComplete)
  389. break;
  390. if (HostAdapter->HostAdapterCommandCompleted)
  391. break;
  392. if (StatusRegister.sr.DataInRegisterReady) {
  393. if (++ReplyBytes <= ReplyLength)
  394. *ReplyPointer++ = BusLogic_ReadDataInRegister(HostAdapter);
  395. else
  396. BusLogic_ReadDataInRegister(HostAdapter);
  397. }
  398. if (OperationCode == BusLogic_FetchHostAdapterLocalRAM && StatusRegister.sr.HostAdapterReady)
  399. break;
  400. udelay(100);
  401. }
  402. if (TimeoutCounter < 0) {
  403. BusLogic_CommandFailureReason = "Timeout waiting for Command Complete";
  404. Result = -2;
  405. goto Done;
  406. }
  407. /*
  408. Clear any pending Command Complete Interrupt.
  409. */
  410. BusLogic_InterruptReset(HostAdapter);
  411. /*
  412. Provide tracing information if requested.
  413. */
  414. if (BusLogic_GlobalOptions.TraceConfiguration) {
  415. int i;
  416. BusLogic_Notice("BusLogic_Command(%02X) Status = %02X: %2d ==> %2d:", HostAdapter, OperationCode, StatusRegister.All, ReplyLength, ReplyBytes);
  417. if (ReplyLength > ReplyBytes)
  418. ReplyLength = ReplyBytes;
  419. for (i = 0; i < ReplyLength; i++)
  420. BusLogic_Notice(" %02X", HostAdapter, ((unsigned char *) ReplyData)[i]);
  421. BusLogic_Notice("\n", HostAdapter);
  422. }
  423. /*
  424. Process Command Invalid conditions.
  425. */
  426. if (StatusRegister.sr.CommandInvalid) {
  427. /*
  428. Some early BusLogic Host Adapters may not recover properly from
  429. a Command Invalid condition, so if this appears to be the case,
  430. a Soft Reset is issued to the Host Adapter. Potentially invalid
  431. commands are never attempted after Mailbox Initialization is
  432. performed, so there should be no Host Adapter state lost by a
  433. Soft Reset in response to a Command Invalid condition.
  434. */
  435. udelay(1000);
  436. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  437. if (StatusRegister.sr.CommandInvalid ||
  438. StatusRegister.sr.Reserved ||
  439. StatusRegister.sr.DataInRegisterReady ||
  440. StatusRegister.sr.CommandParameterRegisterBusy || !StatusRegister.sr.HostAdapterReady || !StatusRegister.sr.InitializationRequired || StatusRegister.sr.DiagnosticActive || StatusRegister.sr.DiagnosticFailure) {
  441. BusLogic_SoftReset(HostAdapter);
  442. udelay(1000);
  443. }
  444. BusLogic_CommandFailureReason = "Command Invalid";
  445. Result = -1;
  446. goto Done;
  447. }
  448. /*
  449. Handle Excess Parameters Supplied conditions.
  450. */
  451. if (ParameterLength > 0) {
  452. BusLogic_CommandFailureReason = "Excess Parameters Supplied";
  453. Result = -1;
  454. goto Done;
  455. }
  456. /*
  457. Indicate the command completed successfully.
  458. */
  459. BusLogic_CommandFailureReason = NULL;
  460. Result = ReplyBytes;
  461. /*
  462. Restore the interrupt status if necessary and return.
  463. */
  464. Done:
  465. if (!HostAdapter->IRQ_ChannelAcquired)
  466. local_irq_restore(ProcessorFlags);
  467. return Result;
  468. }
  469. /*
  470. BusLogic_AppendProbeAddressISA appends a single ISA I/O Address to the list
  471. of I/O Address and Bus Probe Information to be checked for potential BusLogic
  472. Host Adapters.
  473. */
  474. static void __init BusLogic_AppendProbeAddressISA(unsigned long IO_Address)
  475. {
  476. struct BusLogic_ProbeInfo *ProbeInfo;
  477. if (BusLogic_ProbeInfoCount >= BusLogic_MaxHostAdapters)
  478. return;
  479. ProbeInfo = &BusLogic_ProbeInfoList[BusLogic_ProbeInfoCount++];
  480. ProbeInfo->HostAdapterType = BusLogic_MultiMaster;
  481. ProbeInfo->HostAdapterBusType = BusLogic_ISA_Bus;
  482. ProbeInfo->IO_Address = IO_Address;
  483. ProbeInfo->PCI_Device = NULL;
  484. }
  485. /*
  486. BusLogic_InitializeProbeInfoListISA initializes the list of I/O Address and
  487. Bus Probe Information to be checked for potential BusLogic SCSI Host Adapters
  488. only from the list of standard BusLogic MultiMaster ISA I/O Addresses.
  489. */
  490. static void __init BusLogic_InitializeProbeInfoListISA(struct BusLogic_HostAdapter
  491. *PrototypeHostAdapter)
  492. {
  493. /*
  494. If BusLogic Driver Options specifications requested that ISA Bus Probes
  495. be inhibited, do not proceed further.
  496. */
  497. if (BusLogic_ProbeOptions.NoProbeISA)
  498. return;
  499. /*
  500. Append the list of standard BusLogic MultiMaster ISA I/O Addresses.
  501. */
  502. if (!BusLogic_ProbeOptions.LimitedProbeISA || BusLogic_ProbeOptions.Probe330)
  503. BusLogic_AppendProbeAddressISA(0x330);
  504. if (!BusLogic_ProbeOptions.LimitedProbeISA || BusLogic_ProbeOptions.Probe334)
  505. BusLogic_AppendProbeAddressISA(0x334);
  506. if (!BusLogic_ProbeOptions.LimitedProbeISA || BusLogic_ProbeOptions.Probe230)
  507. BusLogic_AppendProbeAddressISA(0x230);
  508. if (!BusLogic_ProbeOptions.LimitedProbeISA || BusLogic_ProbeOptions.Probe234)
  509. BusLogic_AppendProbeAddressISA(0x234);
  510. if (!BusLogic_ProbeOptions.LimitedProbeISA || BusLogic_ProbeOptions.Probe130)
  511. BusLogic_AppendProbeAddressISA(0x130);
  512. if (!BusLogic_ProbeOptions.LimitedProbeISA || BusLogic_ProbeOptions.Probe134)
  513. BusLogic_AppendProbeAddressISA(0x134);
  514. }
  515. #ifdef CONFIG_PCI
  516. /*
  517. BusLogic_SortProbeInfo sorts a section of BusLogic_ProbeInfoList in order
  518. of increasing PCI Bus and Device Number.
  519. */
  520. static void __init BusLogic_SortProbeInfo(struct BusLogic_ProbeInfo *ProbeInfoList, int ProbeInfoCount)
  521. {
  522. int LastInterchange = ProbeInfoCount - 1, Bound, j;
  523. while (LastInterchange > 0) {
  524. Bound = LastInterchange;
  525. LastInterchange = 0;
  526. for (j = 0; j < Bound; j++) {
  527. struct BusLogic_ProbeInfo *ProbeInfo1 = &ProbeInfoList[j];
  528. struct BusLogic_ProbeInfo *ProbeInfo2 = &ProbeInfoList[j + 1];
  529. if (ProbeInfo1->Bus > ProbeInfo2->Bus || (ProbeInfo1->Bus == ProbeInfo2->Bus && (ProbeInfo1->Device > ProbeInfo2->Device))) {
  530. struct BusLogic_ProbeInfo TempProbeInfo;
  531. memcpy(&TempProbeInfo, ProbeInfo1, sizeof(struct BusLogic_ProbeInfo));
  532. memcpy(ProbeInfo1, ProbeInfo2, sizeof(struct BusLogic_ProbeInfo));
  533. memcpy(ProbeInfo2, &TempProbeInfo, sizeof(struct BusLogic_ProbeInfo));
  534. LastInterchange = j;
  535. }
  536. }
  537. }
  538. }
  539. /*
  540. BusLogic_InitializeMultiMasterProbeInfo initializes the list of I/O Address
  541. and Bus Probe Information to be checked for potential BusLogic MultiMaster
  542. SCSI Host Adapters by interrogating the PCI Configuration Space on PCI
  543. machines as well as from the list of standard BusLogic MultiMaster ISA
  544. I/O Addresses. It returns the number of PCI MultiMaster Host Adapters found.
  545. */
  546. static int __init BusLogic_InitializeMultiMasterProbeInfo(struct BusLogic_HostAdapter
  547. *PrototypeHostAdapter)
  548. {
  549. struct BusLogic_ProbeInfo *PrimaryProbeInfo = &BusLogic_ProbeInfoList[BusLogic_ProbeInfoCount];
  550. int NonPrimaryPCIMultiMasterIndex = BusLogic_ProbeInfoCount + 1;
  551. int NonPrimaryPCIMultiMasterCount = 0, PCIMultiMasterCount = 0;
  552. bool ForceBusDeviceScanningOrder = false;
  553. bool ForceBusDeviceScanningOrderChecked = false;
  554. bool StandardAddressSeen[6];
  555. struct pci_dev *PCI_Device = NULL;
  556. int i;
  557. if (BusLogic_ProbeInfoCount >= BusLogic_MaxHostAdapters)
  558. return 0;
  559. BusLogic_ProbeInfoCount++;
  560. for (i = 0; i < 6; i++)
  561. StandardAddressSeen[i] = false;
  562. /*
  563. Iterate over the MultiMaster PCI Host Adapters. For each enumerated host
  564. adapter, determine whether its ISA Compatible I/O Port is enabled and if
  565. so, whether it is assigned the Primary I/O Address. A host adapter that is
  566. assigned the Primary I/O Address will always be the preferred boot device.
  567. The MultiMaster BIOS will first recognize a host adapter at the Primary I/O
  568. Address, then any other PCI host adapters, and finally any host adapters
  569. located at the remaining standard ISA I/O Addresses. When a PCI host
  570. adapter is found with its ISA Compatible I/O Port enabled, a command is
  571. issued to disable the ISA Compatible I/O Port, and it is noted that the
  572. particular standard ISA I/O Address need not be probed.
  573. */
  574. PrimaryProbeInfo->IO_Address = 0;
  575. while ((PCI_Device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER, PCI_Device)) != NULL) {
  576. struct BusLogic_HostAdapter *HostAdapter = PrototypeHostAdapter;
  577. struct BusLogic_PCIHostAdapterInformation PCIHostAdapterInformation;
  578. enum BusLogic_ISACompatibleIOPort ModifyIOAddressRequest;
  579. unsigned char Bus;
  580. unsigned char Device;
  581. unsigned int IRQ_Channel;
  582. unsigned long BaseAddress0;
  583. unsigned long BaseAddress1;
  584. unsigned long IO_Address;
  585. unsigned long PCI_Address;
  586. if (pci_enable_device(PCI_Device))
  587. continue;
  588. if (pci_set_dma_mask(PCI_Device, DMA_BIT_MASK(32) ))
  589. continue;
  590. Bus = PCI_Device->bus->number;
  591. Device = PCI_Device->devfn >> 3;
  592. IRQ_Channel = PCI_Device->irq;
  593. IO_Address = BaseAddress0 = pci_resource_start(PCI_Device, 0);
  594. PCI_Address = BaseAddress1 = pci_resource_start(PCI_Device, 1);
  595. if (pci_resource_flags(PCI_Device, 0) & IORESOURCE_MEM) {
  596. BusLogic_Error("BusLogic: Base Address0 0x%X not I/O for " "MultiMaster Host Adapter\n", NULL, BaseAddress0);
  597. BusLogic_Error("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, Bus, Device, IO_Address);
  598. continue;
  599. }
  600. if (pci_resource_flags(PCI_Device, 1) & IORESOURCE_IO) {
  601. BusLogic_Error("BusLogic: Base Address1 0x%X not Memory for " "MultiMaster Host Adapter\n", NULL, BaseAddress1);
  602. BusLogic_Error("at PCI Bus %d Device %d PCI Address 0x%X\n", NULL, Bus, Device, PCI_Address);
  603. continue;
  604. }
  605. if (IRQ_Channel == 0) {
  606. BusLogic_Error("BusLogic: IRQ Channel %d invalid for " "MultiMaster Host Adapter\n", NULL, IRQ_Channel);
  607. BusLogic_Error("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, Bus, Device, IO_Address);
  608. continue;
  609. }
  610. if (BusLogic_GlobalOptions.TraceProbe) {
  611. BusLogic_Notice("BusLogic: PCI MultiMaster Host Adapter " "detected at\n", NULL);
  612. BusLogic_Notice("BusLogic: PCI Bus %d Device %d I/O Address " "0x%X PCI Address 0x%X\n", NULL, Bus, Device, IO_Address, PCI_Address);
  613. }
  614. /*
  615. Issue the Inquire PCI Host Adapter Information command to determine
  616. the ISA Compatible I/O Port. If the ISA Compatible I/O Port is
  617. known and enabled, note that the particular Standard ISA I/O
  618. Address should not be probed.
  619. */
  620. HostAdapter->IO_Address = IO_Address;
  621. BusLogic_InterruptReset(HostAdapter);
  622. if (BusLogic_Command(HostAdapter, BusLogic_InquirePCIHostAdapterInformation, NULL, 0, &PCIHostAdapterInformation, sizeof(PCIHostAdapterInformation))
  623. == sizeof(PCIHostAdapterInformation)) {
  624. if (PCIHostAdapterInformation.ISACompatibleIOPort < 6)
  625. StandardAddressSeen[PCIHostAdapterInformation.ISACompatibleIOPort] = true;
  626. } else
  627. PCIHostAdapterInformation.ISACompatibleIOPort = BusLogic_IO_Disable;
  628. /*
  629. * Issue the Modify I/O Address command to disable the ISA Compatible
  630. * I/O Port. On PCI Host Adapters, the Modify I/O Address command
  631. * allows modification of the ISA compatible I/O Address that the Host
  632. * Adapter responds to; it does not affect the PCI compliant I/O Address
  633. * assigned at system initialization.
  634. */
  635. ModifyIOAddressRequest = BusLogic_IO_Disable;
  636. BusLogic_Command(HostAdapter, BusLogic_ModifyIOAddress, &ModifyIOAddressRequest, sizeof(ModifyIOAddressRequest), NULL, 0);
  637. /*
  638. For the first MultiMaster Host Adapter enumerated, issue the Fetch
  639. Host Adapter Local RAM command to read byte 45 of the AutoSCSI area,
  640. for the setting of the "Use Bus And Device # For PCI Scanning Seq."
  641. option. Issue the Inquire Board ID command since this option is
  642. only valid for the BT-948/958/958D.
  643. */
  644. if (!ForceBusDeviceScanningOrderChecked) {
  645. struct BusLogic_FetchHostAdapterLocalRAMRequest FetchHostAdapterLocalRAMRequest;
  646. struct BusLogic_AutoSCSIByte45 AutoSCSIByte45;
  647. struct BusLogic_BoardID BoardID;
  648. FetchHostAdapterLocalRAMRequest.ByteOffset = BusLogic_AutoSCSI_BaseOffset + 45;
  649. FetchHostAdapterLocalRAMRequest.ByteCount = sizeof(AutoSCSIByte45);
  650. BusLogic_Command(HostAdapter, BusLogic_FetchHostAdapterLocalRAM, &FetchHostAdapterLocalRAMRequest, sizeof(FetchHostAdapterLocalRAMRequest), &AutoSCSIByte45, sizeof(AutoSCSIByte45));
  651. BusLogic_Command(HostAdapter, BusLogic_InquireBoardID, NULL, 0, &BoardID, sizeof(BoardID));
  652. if (BoardID.FirmwareVersion1stDigit == '5')
  653. ForceBusDeviceScanningOrder = AutoSCSIByte45.ForceBusDeviceScanningOrder;
  654. ForceBusDeviceScanningOrderChecked = true;
  655. }
  656. /*
  657. Determine whether this MultiMaster Host Adapter has its ISA
  658. Compatible I/O Port enabled and is assigned the Primary I/O Address.
  659. If it does, then it is the Primary MultiMaster Host Adapter and must
  660. be recognized first. If it does not, then it is added to the list
  661. for probing after any Primary MultiMaster Host Adapter is probed.
  662. */
  663. if (PCIHostAdapterInformation.ISACompatibleIOPort == BusLogic_IO_330) {
  664. PrimaryProbeInfo->HostAdapterType = BusLogic_MultiMaster;
  665. PrimaryProbeInfo->HostAdapterBusType = BusLogic_PCI_Bus;
  666. PrimaryProbeInfo->IO_Address = IO_Address;
  667. PrimaryProbeInfo->PCI_Address = PCI_Address;
  668. PrimaryProbeInfo->Bus = Bus;
  669. PrimaryProbeInfo->Device = Device;
  670. PrimaryProbeInfo->IRQ_Channel = IRQ_Channel;
  671. PrimaryProbeInfo->PCI_Device = pci_dev_get(PCI_Device);
  672. PCIMultiMasterCount++;
  673. } else if (BusLogic_ProbeInfoCount < BusLogic_MaxHostAdapters) {
  674. struct BusLogic_ProbeInfo *ProbeInfo = &BusLogic_ProbeInfoList[BusLogic_ProbeInfoCount++];
  675. ProbeInfo->HostAdapterType = BusLogic_MultiMaster;
  676. ProbeInfo->HostAdapterBusType = BusLogic_PCI_Bus;
  677. ProbeInfo->IO_Address = IO_Address;
  678. ProbeInfo->PCI_Address = PCI_Address;
  679. ProbeInfo->Bus = Bus;
  680. ProbeInfo->Device = Device;
  681. ProbeInfo->IRQ_Channel = IRQ_Channel;
  682. ProbeInfo->PCI_Device = pci_dev_get(PCI_Device);
  683. NonPrimaryPCIMultiMasterCount++;
  684. PCIMultiMasterCount++;
  685. } else
  686. BusLogic_Warning("BusLogic: Too many Host Adapters " "detected\n", NULL);
  687. }
  688. /*
  689. If the AutoSCSI "Use Bus And Device # For PCI Scanning Seq." option is ON
  690. for the first enumerated MultiMaster Host Adapter, and if that host adapter
  691. is a BT-948/958/958D, then the MultiMaster BIOS will recognize MultiMaster
  692. Host Adapters in the order of increasing PCI Bus and Device Number. In
  693. that case, sort the probe information into the same order the BIOS uses.
  694. If this option is OFF, then the MultiMaster BIOS will recognize MultiMaster
  695. Host Adapters in the order they are enumerated by the PCI BIOS, and hence
  696. no sorting is necessary.
  697. */
  698. if (ForceBusDeviceScanningOrder)
  699. BusLogic_SortProbeInfo(&BusLogic_ProbeInfoList[NonPrimaryPCIMultiMasterIndex], NonPrimaryPCIMultiMasterCount);
  700. /*
  701. If no PCI MultiMaster Host Adapter is assigned the Primary I/O Address,
  702. then the Primary I/O Address must be probed explicitly before any PCI
  703. host adapters are probed.
  704. */
  705. if (!BusLogic_ProbeOptions.NoProbeISA)
  706. if (PrimaryProbeInfo->IO_Address == 0 &&
  707. (!BusLogic_ProbeOptions.LimitedProbeISA ||
  708. BusLogic_ProbeOptions.Probe330)) {
  709. PrimaryProbeInfo->HostAdapterType = BusLogic_MultiMaster;
  710. PrimaryProbeInfo->HostAdapterBusType = BusLogic_ISA_Bus;
  711. PrimaryProbeInfo->IO_Address = 0x330;
  712. }
  713. /*
  714. Append the list of standard BusLogic MultiMaster ISA I/O Addresses,
  715. omitting the Primary I/O Address which has already been handled.
  716. */
  717. if (!BusLogic_ProbeOptions.NoProbeISA) {
  718. if (!StandardAddressSeen[1] &&
  719. (!BusLogic_ProbeOptions.LimitedProbeISA ||
  720. BusLogic_ProbeOptions.Probe334))
  721. BusLogic_AppendProbeAddressISA(0x334);
  722. if (!StandardAddressSeen[2] &&
  723. (!BusLogic_ProbeOptions.LimitedProbeISA ||
  724. BusLogic_ProbeOptions.Probe230))
  725. BusLogic_AppendProbeAddressISA(0x230);
  726. if (!StandardAddressSeen[3] &&
  727. (!BusLogic_ProbeOptions.LimitedProbeISA ||
  728. BusLogic_ProbeOptions.Probe234))
  729. BusLogic_AppendProbeAddressISA(0x234);
  730. if (!StandardAddressSeen[4] &&
  731. (!BusLogic_ProbeOptions.LimitedProbeISA ||
  732. BusLogic_ProbeOptions.Probe130))
  733. BusLogic_AppendProbeAddressISA(0x130);
  734. if (!StandardAddressSeen[5] &&
  735. (!BusLogic_ProbeOptions.LimitedProbeISA ||
  736. BusLogic_ProbeOptions.Probe134))
  737. BusLogic_AppendProbeAddressISA(0x134);
  738. }
  739. /*
  740. Iterate over the older non-compliant MultiMaster PCI Host Adapters,
  741. noting the PCI bus location and assigned IRQ Channel.
  742. */
  743. PCI_Device = NULL;
  744. while ((PCI_Device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC, PCI_Device)) != NULL) {
  745. unsigned char Bus;
  746. unsigned char Device;
  747. unsigned int IRQ_Channel;
  748. unsigned long IO_Address;
  749. if (pci_enable_device(PCI_Device))
  750. continue;
  751. if (pci_set_dma_mask(PCI_Device, DMA_BIT_MASK(32)))
  752. continue;
  753. Bus = PCI_Device->bus->number;
  754. Device = PCI_Device->devfn >> 3;
  755. IRQ_Channel = PCI_Device->irq;
  756. IO_Address = pci_resource_start(PCI_Device, 0);
  757. if (IO_Address == 0 || IRQ_Channel == 0)
  758. continue;
  759. for (i = 0; i < BusLogic_ProbeInfoCount; i++) {
  760. struct BusLogic_ProbeInfo *ProbeInfo = &BusLogic_ProbeInfoList[i];
  761. if (ProbeInfo->IO_Address == IO_Address && ProbeInfo->HostAdapterType == BusLogic_MultiMaster) {
  762. ProbeInfo->HostAdapterBusType = BusLogic_PCI_Bus;
  763. ProbeInfo->PCI_Address = 0;
  764. ProbeInfo->Bus = Bus;
  765. ProbeInfo->Device = Device;
  766. ProbeInfo->IRQ_Channel = IRQ_Channel;
  767. ProbeInfo->PCI_Device = pci_dev_get(PCI_Device);
  768. break;
  769. }
  770. }
  771. }
  772. return PCIMultiMasterCount;
  773. }
  774. /*
  775. BusLogic_InitializeFlashPointProbeInfo initializes the list of I/O Address
  776. and Bus Probe Information to be checked for potential BusLogic FlashPoint
  777. Host Adapters by interrogating the PCI Configuration Space. It returns the
  778. number of FlashPoint Host Adapters found.
  779. */
  780. static int __init BusLogic_InitializeFlashPointProbeInfo(struct BusLogic_HostAdapter
  781. *PrototypeHostAdapter)
  782. {
  783. int FlashPointIndex = BusLogic_ProbeInfoCount, FlashPointCount = 0;
  784. struct pci_dev *PCI_Device = NULL;
  785. /*
  786. Interrogate PCI Configuration Space for any FlashPoint Host Adapters.
  787. */
  788. while ((PCI_Device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT, PCI_Device)) != NULL) {
  789. unsigned char Bus;
  790. unsigned char Device;
  791. unsigned int IRQ_Channel;
  792. unsigned long BaseAddress0;
  793. unsigned long BaseAddress1;
  794. unsigned long IO_Address;
  795. unsigned long PCI_Address;
  796. if (pci_enable_device(PCI_Device))
  797. continue;
  798. if (pci_set_dma_mask(PCI_Device, DMA_BIT_MASK(32)))
  799. continue;
  800. Bus = PCI_Device->bus->number;
  801. Device = PCI_Device->devfn >> 3;
  802. IRQ_Channel = PCI_Device->irq;
  803. IO_Address = BaseAddress0 = pci_resource_start(PCI_Device, 0);
  804. PCI_Address = BaseAddress1 = pci_resource_start(PCI_Device, 1);
  805. #ifdef CONFIG_SCSI_FLASHPOINT
  806. if (pci_resource_flags(PCI_Device, 0) & IORESOURCE_MEM) {
  807. BusLogic_Error("BusLogic: Base Address0 0x%X not I/O for " "FlashPoint Host Adapter\n", NULL, BaseAddress0);
  808. BusLogic_Error("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, Bus, Device, IO_Address);
  809. continue;
  810. }
  811. if (pci_resource_flags(PCI_Device, 1) & IORESOURCE_IO) {
  812. BusLogic_Error("BusLogic: Base Address1 0x%X not Memory for " "FlashPoint Host Adapter\n", NULL, BaseAddress1);
  813. BusLogic_Error("at PCI Bus %d Device %d PCI Address 0x%X\n", NULL, Bus, Device, PCI_Address);
  814. continue;
  815. }
  816. if (IRQ_Channel == 0) {
  817. BusLogic_Error("BusLogic: IRQ Channel %d invalid for " "FlashPoint Host Adapter\n", NULL, IRQ_Channel);
  818. BusLogic_Error("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, Bus, Device, IO_Address);
  819. continue;
  820. }
  821. if (BusLogic_GlobalOptions.TraceProbe) {
  822. BusLogic_Notice("BusLogic: FlashPoint Host Adapter " "detected at\n", NULL);
  823. BusLogic_Notice("BusLogic: PCI Bus %d Device %d I/O Address " "0x%X PCI Address 0x%X\n", NULL, Bus, Device, IO_Address, PCI_Address);
  824. }
  825. if (BusLogic_ProbeInfoCount < BusLogic_MaxHostAdapters) {
  826. struct BusLogic_ProbeInfo *ProbeInfo = &BusLogic_ProbeInfoList[BusLogic_ProbeInfoCount++];
  827. ProbeInfo->HostAdapterType = BusLogic_FlashPoint;
  828. ProbeInfo->HostAdapterBusType = BusLogic_PCI_Bus;
  829. ProbeInfo->IO_Address = IO_Address;
  830. ProbeInfo->PCI_Address = PCI_Address;
  831. ProbeInfo->Bus = Bus;
  832. ProbeInfo->Device = Device;
  833. ProbeInfo->IRQ_Channel = IRQ_Channel;
  834. ProbeInfo->PCI_Device = pci_dev_get(PCI_Device);
  835. FlashPointCount++;
  836. } else
  837. BusLogic_Warning("BusLogic: Too many Host Adapters " "detected\n", NULL);
  838. #else
  839. BusLogic_Error("BusLogic: FlashPoint Host Adapter detected at " "PCI Bus %d Device %d\n", NULL, Bus, Device);
  840. BusLogic_Error("BusLogic: I/O Address 0x%X PCI Address 0x%X, irq %d, " "but FlashPoint\n", NULL, IO_Address, PCI_Address, IRQ_Channel);
  841. BusLogic_Error("BusLogic: support was omitted in this kernel " "configuration.\n", NULL);
  842. #endif
  843. }
  844. /*
  845. The FlashPoint BIOS will scan for FlashPoint Host Adapters in the order of
  846. increasing PCI Bus and Device Number, so sort the probe information into
  847. the same order the BIOS uses.
  848. */
  849. BusLogic_SortProbeInfo(&BusLogic_ProbeInfoList[FlashPointIndex], FlashPointCount);
  850. return FlashPointCount;
  851. }
  852. /*
  853. BusLogic_InitializeProbeInfoList initializes the list of I/O Address and Bus
  854. Probe Information to be checked for potential BusLogic SCSI Host Adapters by
  855. interrogating the PCI Configuration Space on PCI machines as well as from the
  856. list of standard BusLogic MultiMaster ISA I/O Addresses. By default, if both
  857. FlashPoint and PCI MultiMaster Host Adapters are present, this driver will
  858. probe for FlashPoint Host Adapters first unless the BIOS primary disk is
  859. controlled by the first PCI MultiMaster Host Adapter, in which case
  860. MultiMaster Host Adapters will be probed first. The BusLogic Driver Options
  861. specifications "MultiMasterFirst" and "FlashPointFirst" can be used to force
  862. a particular probe order.
  863. */
  864. static void __init BusLogic_InitializeProbeInfoList(struct BusLogic_HostAdapter
  865. *PrototypeHostAdapter)
  866. {
  867. /*
  868. If a PCI BIOS is present, interrogate it for MultiMaster and FlashPoint
  869. Host Adapters; otherwise, default to the standard ISA MultiMaster probe.
  870. */
  871. if (!BusLogic_ProbeOptions.NoProbePCI) {
  872. if (BusLogic_ProbeOptions.MultiMasterFirst) {
  873. BusLogic_InitializeMultiMasterProbeInfo(PrototypeHostAdapter);
  874. BusLogic_InitializeFlashPointProbeInfo(PrototypeHostAdapter);
  875. } else if (BusLogic_ProbeOptions.FlashPointFirst) {
  876. BusLogic_InitializeFlashPointProbeInfo(PrototypeHostAdapter);
  877. BusLogic_InitializeMultiMasterProbeInfo(PrototypeHostAdapter);
  878. } else {
  879. int FlashPointCount = BusLogic_InitializeFlashPointProbeInfo(PrototypeHostAdapter);
  880. int PCIMultiMasterCount = BusLogic_InitializeMultiMasterProbeInfo(PrototypeHostAdapter);
  881. if (FlashPointCount > 0 && PCIMultiMasterCount > 0) {
  882. struct BusLogic_ProbeInfo *ProbeInfo = &BusLogic_ProbeInfoList[FlashPointCount];
  883. struct BusLogic_HostAdapter *HostAdapter = PrototypeHostAdapter;
  884. struct BusLogic_FetchHostAdapterLocalRAMRequest FetchHostAdapterLocalRAMRequest;
  885. struct BusLogic_BIOSDriveMapByte Drive0MapByte;
  886. while (ProbeInfo->HostAdapterBusType != BusLogic_PCI_Bus)
  887. ProbeInfo++;
  888. HostAdapter->IO_Address = ProbeInfo->IO_Address;
  889. FetchHostAdapterLocalRAMRequest.ByteOffset = BusLogic_BIOS_BaseOffset + BusLogic_BIOS_DriveMapOffset + 0;
  890. FetchHostAdapterLocalRAMRequest.ByteCount = sizeof(Drive0MapByte);
  891. BusLogic_Command(HostAdapter, BusLogic_FetchHostAdapterLocalRAM, &FetchHostAdapterLocalRAMRequest, sizeof(FetchHostAdapterLocalRAMRequest), &Drive0MapByte, sizeof(Drive0MapByte));
  892. /*
  893. If the Map Byte for BIOS Drive 0 indicates that BIOS Drive 0
  894. is controlled by this PCI MultiMaster Host Adapter, then
  895. reverse the probe order so that MultiMaster Host Adapters are
  896. probed before FlashPoint Host Adapters.
  897. */
  898. if (Drive0MapByte.DiskGeometry != BusLogic_BIOS_Disk_Not_Installed) {
  899. struct BusLogic_ProbeInfo SavedProbeInfo[BusLogic_MaxHostAdapters];
  900. int MultiMasterCount = BusLogic_ProbeInfoCount - FlashPointCount;
  901. memcpy(SavedProbeInfo, BusLogic_ProbeInfoList, BusLogic_ProbeInfoCount * sizeof(struct BusLogic_ProbeInfo));
  902. memcpy(&BusLogic_ProbeInfoList[0], &SavedProbeInfo[FlashPointCount], MultiMasterCount * sizeof(struct BusLogic_ProbeInfo));
  903. memcpy(&BusLogic_ProbeInfoList[MultiMasterCount], &SavedProbeInfo[0], FlashPointCount * sizeof(struct BusLogic_ProbeInfo));
  904. }
  905. }
  906. }
  907. } else
  908. BusLogic_InitializeProbeInfoListISA(PrototypeHostAdapter);
  909. }
  910. #else
  911. #define BusLogic_InitializeProbeInfoList(adapter) \
  912. BusLogic_InitializeProbeInfoListISA(adapter)
  913. #endif /* CONFIG_PCI */
  914. /*
  915. BusLogic_Failure prints a standardized error message, and then returns false.
  916. */
  917. static bool BusLogic_Failure(struct BusLogic_HostAdapter *HostAdapter, char *ErrorMessage)
  918. {
  919. BusLogic_AnnounceDriver(HostAdapter);
  920. if (HostAdapter->HostAdapterBusType == BusLogic_PCI_Bus) {
  921. BusLogic_Error("While configuring BusLogic PCI Host Adapter at\n", HostAdapter);
  922. BusLogic_Error("Bus %d Device %d I/O Address 0x%X PCI Address 0x%X:\n", HostAdapter, HostAdapter->Bus, HostAdapter->Device, HostAdapter->IO_Address, HostAdapter->PCI_Address);
  923. } else
  924. BusLogic_Error("While configuring BusLogic Host Adapter at " "I/O Address 0x%X:\n", HostAdapter, HostAdapter->IO_Address);
  925. BusLogic_Error("%s FAILED - DETACHING\n", HostAdapter, ErrorMessage);
  926. if (BusLogic_CommandFailureReason != NULL)
  927. BusLogic_Error("ADDITIONAL FAILURE INFO - %s\n", HostAdapter, BusLogic_CommandFailureReason);
  928. return false;
  929. }
  930. /*
  931. BusLogic_ProbeHostAdapter probes for a BusLogic Host Adapter.
  932. */
  933. static bool __init BusLogic_ProbeHostAdapter(struct BusLogic_HostAdapter *HostAdapter)
  934. {
  935. union BusLogic_StatusRegister StatusRegister;
  936. union BusLogic_InterruptRegister InterruptRegister;
  937. union BusLogic_GeometryRegister GeometryRegister;
  938. /*
  939. FlashPoint Host Adapters are Probed by the FlashPoint SCCB Manager.
  940. */
  941. if (BusLogic_FlashPointHostAdapterP(HostAdapter)) {
  942. struct FlashPoint_Info *FlashPointInfo = &HostAdapter->FlashPointInfo;
  943. FlashPointInfo->BaseAddress = (u32) HostAdapter->IO_Address;
  944. FlashPointInfo->IRQ_Channel = HostAdapter->IRQ_Channel;
  945. FlashPointInfo->Present = false;
  946. if (!(FlashPoint_ProbeHostAdapter(FlashPointInfo) == 0 && FlashPointInfo->Present)) {
  947. BusLogic_Error("BusLogic: FlashPoint Host Adapter detected at " "PCI Bus %d Device %d\n", HostAdapter, HostAdapter->Bus, HostAdapter->Device);
  948. BusLogic_Error("BusLogic: I/O Address 0x%X PCI Address 0x%X, " "but FlashPoint\n", HostAdapter, HostAdapter->IO_Address, HostAdapter->PCI_Address);
  949. BusLogic_Error("BusLogic: Probe Function failed to validate it.\n", HostAdapter);
  950. return false;
  951. }
  952. if (BusLogic_GlobalOptions.TraceProbe)
  953. BusLogic_Notice("BusLogic_Probe(0x%X): FlashPoint Found\n", HostAdapter, HostAdapter->IO_Address);
  954. /*
  955. Indicate the Host Adapter Probe completed successfully.
  956. */
  957. return true;
  958. }
  959. /*
  960. Read the Status, Interrupt, and Geometry Registers to test if there are I/O
  961. ports that respond, and to check the values to determine if they are from a
  962. BusLogic Host Adapter. A nonexistent I/O port will return 0xFF, in which
  963. case there is definitely no BusLogic Host Adapter at this base I/O Address.
  964. The test here is a subset of that used by the BusLogic Host Adapter BIOS.
  965. */
  966. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  967. InterruptRegister.All = BusLogic_ReadInterruptRegister(HostAdapter);
  968. GeometryRegister.All = BusLogic_ReadGeometryRegister(HostAdapter);
  969. if (BusLogic_GlobalOptions.TraceProbe)
  970. BusLogic_Notice("BusLogic_Probe(0x%X): Status 0x%02X, Interrupt 0x%02X, " "Geometry 0x%02X\n", HostAdapter, HostAdapter->IO_Address, StatusRegister.All, InterruptRegister.All, GeometryRegister.All);
  971. if (StatusRegister.All == 0 || StatusRegister.sr.DiagnosticActive || StatusRegister.sr.CommandParameterRegisterBusy || StatusRegister.sr.Reserved || StatusRegister.sr.CommandInvalid || InterruptRegister.ir.Reserved != 0)
  972. return false;
  973. /*
  974. Check the undocumented Geometry Register to test if there is an I/O port
  975. that responded. Adaptec Host Adapters do not implement the Geometry
  976. Register, so this test helps serve to avoid incorrectly recognizing an
  977. Adaptec 1542A or 1542B as a BusLogic. Unfortunately, the Adaptec 1542C
  978. series does respond to the Geometry Register I/O port, but it will be
  979. rejected later when the Inquire Extended Setup Information command is
  980. issued in BusLogic_CheckHostAdapter. The AMI FastDisk Host Adapter is a
  981. BusLogic clone that implements the same interface as earlier BusLogic
  982. Host Adapters, including the undocumented commands, and is therefore
  983. supported by this driver. However, the AMI FastDisk always returns 0x00
  984. upon reading the Geometry Register, so the extended translation option
  985. should always be left disabled on the AMI FastDisk.
  986. */
  987. if (GeometryRegister.All == 0xFF)
  988. return false;
  989. /*
  990. Indicate the Host Adapter Probe completed successfully.
  991. */
  992. return true;
  993. }
  994. /*
  995. BusLogic_HardwareResetHostAdapter issues a Hardware Reset to the Host Adapter
  996. and waits for Host Adapter Diagnostics to complete. If HardReset is true, a
  997. Hard Reset is performed which also initiates a SCSI Bus Reset. Otherwise, a
  998. Soft Reset is performed which only resets the Host Adapter without forcing a
  999. SCSI Bus Reset.
  1000. */
  1001. static bool BusLogic_HardwareResetHostAdapter(struct BusLogic_HostAdapter
  1002. *HostAdapter, bool HardReset)
  1003. {
  1004. union BusLogic_StatusRegister StatusRegister;
  1005. int TimeoutCounter;
  1006. /*
  1007. FlashPoint Host Adapters are Hard Reset by the FlashPoint SCCB Manager.
  1008. */
  1009. if (BusLogic_FlashPointHostAdapterP(HostAdapter)) {
  1010. struct FlashPoint_Info *FlashPointInfo = &HostAdapter->FlashPointInfo;
  1011. FlashPointInfo->HostSoftReset = !HardReset;
  1012. FlashPointInfo->ReportDataUnderrun = true;
  1013. HostAdapter->CardHandle = FlashPoint_HardwareResetHostAdapter(FlashPointInfo);
  1014. if (HostAdapter->CardHandle == FlashPoint_BadCardHandle)
  1015. return false;
  1016. /*
  1017. Indicate the Host Adapter Hard Reset completed successfully.
  1018. */
  1019. return true;
  1020. }
  1021. /*
  1022. Issue a Hard Reset or Soft Reset Command to the Host Adapter. The Host
  1023. Adapter should respond by setting Diagnostic Active in the Status Register.
  1024. */
  1025. if (HardReset)
  1026. BusLogic_HardReset(HostAdapter);
  1027. else
  1028. BusLogic_SoftReset(HostAdapter);
  1029. /*
  1030. Wait until Diagnostic Active is set in the Status Register.
  1031. */
  1032. TimeoutCounter = 5 * 10000;
  1033. while (--TimeoutCounter >= 0) {
  1034. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  1035. if (StatusRegister.sr.DiagnosticActive)
  1036. break;
  1037. udelay(100);
  1038. }
  1039. if (BusLogic_GlobalOptions.TraceHardwareReset)
  1040. BusLogic_Notice("BusLogic_HardwareReset(0x%X): Diagnostic Active, " "Status 0x%02X\n", HostAdapter, HostAdapter->IO_Address, StatusRegister.All);
  1041. if (TimeoutCounter < 0)
  1042. return false;
  1043. /*
  1044. Wait 100 microseconds to allow completion of any initial diagnostic
  1045. activity which might leave the contents of the Status Register
  1046. unpredictable.
  1047. */
  1048. udelay(100);
  1049. /*
  1050. Wait until Diagnostic Active is reset in the Status Register.
  1051. */
  1052. TimeoutCounter = 10 * 10000;
  1053. while (--TimeoutCounter >= 0) {
  1054. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  1055. if (!StatusRegister.sr.DiagnosticActive)
  1056. break;
  1057. udelay(100);
  1058. }
  1059. if (BusLogic_GlobalOptions.TraceHardwareReset)
  1060. BusLogic_Notice("BusLogic_HardwareReset(0x%X): Diagnostic Completed, " "Status 0x%02X\n", HostAdapter, HostAdapter->IO_Address, StatusRegister.All);
  1061. if (TimeoutCounter < 0)
  1062. return false;
  1063. /*
  1064. Wait until at least one of the Diagnostic Failure, Host Adapter Ready,
  1065. or Data In Register Ready bits is set in the Status Register.
  1066. */
  1067. TimeoutCounter = 10000;
  1068. while (--TimeoutCounter >= 0) {
  1069. StatusRegister.All = BusLogic_ReadStatusRegister(HostAdapter);
  1070. if (StatusRegister.sr.DiagnosticFailure || StatusRegister.sr.HostAdapterReady || StatusRegister.sr.DataInRegisterReady)
  1071. break;
  1072. udelay(100);
  1073. }
  1074. if (BusLogic_GlobalOptions.TraceHardwareReset)
  1075. BusLogic_Notice("BusLogic_HardwareReset(0x%X): Host Adapter Ready, " "Status 0x%02X\n", HostAdapter, HostAdapter->IO_Address, StatusRegister.All);
  1076. if (TimeoutCounter < 0)
  1077. return false;
  1078. /*
  1079. If Diagnostic Failure is set or Host Adapter Ready is reset, then an
  1080. error occurred during the Host Adapter diagnostics. If Data In Register
  1081. Ready is set, then there is an Error Code available.
  1082. */
  1083. if (StatusRegister.sr.DiagnosticFailure || !StatusRegister.sr.HostAdapterReady) {
  1084. BusLogic_CommandFailureReason = NULL;
  1085. BusLogic_Failure(HostAdapter, "HARD RESET DIAGNOSTICS");
  1086. BusLogic_Error("HOST ADAPTER STATUS REGISTER = %02X\n", HostAdapter, StatusRegister.All);
  1087. if (StatusRegister.sr.DataInRegisterReady) {
  1088. unsigned char ErrorCode = BusLogic_ReadDataInRegister(HostAdapter);
  1089. BusLogic_Error("HOST ADAPTER ERROR CODE = %d\n", HostAdapter, ErrorCode);
  1090. }
  1091. return false;
  1092. }
  1093. /*
  1094. Indicate the Host Adapter Hard Reset completed successfully.
  1095. */
  1096. return true;
  1097. }
  1098. /*
  1099. BusLogic_CheckHostAdapter checks to be sure this really is a BusLogic
  1100. Host Adapter.
  1101. */
  1102. static bool __init BusLogic_CheckHostAdapter(struct BusLogic_HostAdapter *HostAdapter)
  1103. {
  1104. struct BusLogic_ExtendedSetupInformation ExtendedSetupInformation;
  1105. unsigned char RequestedReplyLength;
  1106. bool Result = true;
  1107. /*
  1108. FlashPoint Host Adapters do not require this protection.
  1109. */
  1110. if (BusLogic_FlashPointHostAdapterP(HostAdapter))
  1111. return true;
  1112. /*
  1113. Issue the Inquire Extended Setup Information command. Only genuine
  1114. BusLogic Host Adapters and true clones support this command. Adaptec 1542C
  1115. series Host Adapters that respond to the Geometry Register I/O port will
  1116. fail this command.
  1117. */
  1118. RequestedReplyLength = sizeof(ExtendedSetupInformation);
  1119. if (BusLogic_Command(HostAdapter, BusLogic_InquireExtendedSetupInformation, &RequestedReplyLength, sizeof(RequestedReplyLength), &ExtendedSetupInformation, sizeof(ExtendedSetupInformation))
  1120. != sizeof(ExtendedSetupInformation))
  1121. Result = false;
  1122. /*
  1123. Provide tracing information if requested and return.
  1124. */
  1125. if (BusLogic_GlobalOptions.TraceProbe)
  1126. BusLogic_Notice("BusLogic_Check(0x%X): MultiMaster %s\n", HostAdapter, HostAdapter->IO_Address, (Result ? "Found" : "Not Found"));
  1127. return Result;
  1128. }
  1129. /*
  1130. BusLogic_ReadHostAdapterConfiguration reads the Configuration Information
  1131. from Host Adapter and initializes the Host Adapter structure.
  1132. */
  1133. static bool __init BusLogic_ReadHostAdapterConfiguration(struct BusLogic_HostAdapter
  1134. *HostAdapter)
  1135. {
  1136. struct BusLogic_BoardID BoardID;
  1137. struct BusLogic_Configuration Configuration;
  1138. struct BusLogic_SetupInformation SetupInformation;
  1139. struct BusLogic_ExtendedSetupInformation ExtendedSetupInformation;
  1140. unsigned char HostAdapterModelNumber[5];
  1141. unsigned char FirmwareVersion3rdDigit;
  1142. unsigned char FirmwareVersionLetter;
  1143. struct BusLogic_PCIHostAdapterInformation PCIHostAdapterInformation;
  1144. struct BusLogic_FetchHostAdapterLocalRAMRequest FetchHostAdapterLocalRAMRequest;
  1145. struct BusLogic_AutoSCSIData AutoSCSIData;
  1146. union BusLogic_GeometryRegister GeometryRegister;
  1147. unsigned char RequestedReplyLength;
  1148. unsigned char *TargetPointer, Character;
  1149. int TargetID, i;
  1150. /*
  1151. Configuration Information for FlashPoint Host Adapters is provided in the
  1152. FlashPoint_Info structure by the FlashPoint SCCB Manager's Probe Function.
  1153. Initialize fields in the Host Adapter structure from the FlashPoint_Info
  1154. structure.
  1155. */
  1156. if (BusLogic_FlashPointHostAdapterP(HostAdapter)) {
  1157. struct FlashPoint_Info *FlashPointInfo = &HostAdapter->FlashPointInfo;
  1158. TargetPointer = HostAdapter->ModelName;
  1159. *TargetPointer++ = 'B';
  1160. *TargetPointer++ = 'T';
  1161. *TargetPointer++ = '-';
  1162. for (i = 0; i < sizeof(FlashPointInfo->ModelNumber); i++)
  1163. *TargetPointer++ = FlashPointInfo->ModelNumber[i];
  1164. *TargetPointer++ = '\0';
  1165. strcpy(HostAdapter->FirmwareVersion, FlashPoint_FirmwareVersion);
  1166. HostAdapter->SCSI_ID = FlashPointInfo->SCSI_ID;
  1167. HostAdapter->ExtendedTranslationEnabled = FlashPointInfo->ExtendedTranslationEnabled;
  1168. HostAdapter->ParityCheckingEnabled = FlashPointInfo->ParityCheckingEnabled;
  1169. HostAdapter->BusResetEnabled = !FlashPointInfo->HostSoftReset;
  1170. HostAdapter->LevelSensitiveInterrupt = true;
  1171. HostAdapter->HostWideSCSI = FlashPointInfo->HostWideSCSI;
  1172. HostAdapter->HostDifferentialSCSI = false;
  1173. HostAdapter->HostSupportsSCAM = true;
  1174. HostAdapter->HostUltraSCSI = true;
  1175. HostAdapter->ExtendedLUNSupport = true;
  1176. HostAdapter->TerminationInfoValid = true;
  1177. HostAdapter->LowByteTerminated = FlashPointInfo->LowByteTerminated;
  1178. HostAdapter->HighByteTerminated = FlashPointInfo->HighByteTerminated;
  1179. HostAdapter->SCAM_Enabled = FlashPointInfo->SCAM_Enabled;
  1180. HostAdapter->SCAM_Level2 = FlashPointInfo->SCAM_Level2;
  1181. HostAdapter->DriverScatterGatherLimit = BusLogic_ScatterGatherLimit;
  1182. HostAdapter->MaxTargetDevices = (HostAdapter->HostWideSCSI ? 16 : 8);
  1183. HostAdapter->MaxLogicalUnits = 32;
  1184. HostAdapter->InitialCCBs = 4 * BusLogic_CCB_AllocationGroupSize;
  1185. HostAdapter->IncrementalCCBs = BusLogic_CCB_AllocationGroupSize;
  1186. HostAdapter->DriverQueueDepth = 255;
  1187. HostAdapter->HostAdapterQueueDepth = HostAdapter->DriverQueueDepth;
  1188. HostAdapter->SynchronousPermitted = FlashPointInfo->SynchronousPermitted;
  1189. HostAdapter->FastPermitted = FlashPointInfo->FastPermitted;
  1190. HostAdapter->UltraPermitted = FlashPointInfo->UltraPermitted;
  1191. HostAdapter->WidePermitted = FlashPointInfo->WidePermitted;
  1192. HostAdapter->DisconnectPermitted = FlashPointInfo->DisconnectPermitted;
  1193. HostAdapter->TaggedQueuingPermitted = 0xFFFF;
  1194. goto Common;
  1195. }
  1196. /*
  1197. Issue the Inquire Board ID command.
  1198. */
  1199. if (BusLogic_Command(HostAdapter, BusLogic_InquireBoardID, NULL, 0, &BoardID, sizeof(BoardID)) != sizeof(BoardID))
  1200. return BusLogic_Failure(HostAdapter, "INQUIRE BOARD ID");
  1201. /*
  1202. Issue the Inquire Configuration command.
  1203. */
  1204. if (BusLogic_Command(HostAdapter, BusLogic_InquireConfiguration, NULL, 0, &Configuration, sizeof(Configuration))
  1205. != sizeof(Configuration))
  1206. return BusLogic_Failure(HostAdapter, "INQUIRE CONFIGURATION");
  1207. /*
  1208. Issue the Inquire Setup Information command.
  1209. */
  1210. RequestedReplyLength = sizeof(SetupInformation);
  1211. if (BusLogic_Command(HostAdapter, BusLogic_InquireSetupInformation, &RequestedReplyLength, sizeof(RequestedReplyLength), &SetupInformation, sizeof(SetupInformation))
  1212. != sizeof(SetupInformation))
  1213. return BusLogic_Failure(HostAdapter, "INQUIRE SETUP INFORMATION");
  1214. /*
  1215. Issue the Inquire Extended Setup Information command.
  1216. */
  1217. RequestedReplyLength = sizeof(ExtendedSetupInformation);
  1218. if (BusLogic_Command(HostAdapter, BusLogic_InquireExtendedSetupInformation, &RequestedReplyLength, sizeof(RequestedReplyLength), &ExtendedSetupInformation, sizeof(ExtendedSetupInformation))
  1219. != sizeof(ExtendedSetupInformation))
  1220. return BusLogic_Failure(HostAdapter, "INQUIRE EXTENDED SETUP INFORMATION");
  1221. /*
  1222. Issue the Inquire Firmware Version 3rd Digit command.
  1223. */
  1224. FirmwareVersion3rdDigit = '\0';
  1225. if (BoardID.FirmwareVersion1stDigit > '0')
  1226. if (BusLogic_Command(HostAdapter, BusLogic_InquireFirmwareVersion3rdDigit, NULL, 0, &FirmwareVersion3rdDigit, sizeof(FirmwareVersion3rdDigit))
  1227. != sizeof(FirmwareVersion3rdDigit))
  1228. return BusLogic_Failure(HostAdapter, "INQUIRE FIRMWARE 3RD DIGIT");
  1229. /*
  1230. Issue the Inquire Host Adapter Model Number command.
  1231. */
  1232. if (ExtendedSetupInformation.BusType == 'A' && BoardID.FirmwareVersion1stDigit == '2')
  1233. /* BusLogic BT-542B ISA 2.xx */
  1234. strcpy(HostAdapterModelNumber, "542B");
  1235. else if (ExtendedSetupInformation.BusType == 'E' && BoardID.FirmwareVersion1stDigit == '2' && (BoardID.FirmwareVersion2ndDigit <= '1' || (BoardID.FirmwareVersion2ndDigit == '2' && FirmwareVersion3rdDigit == '0')))
  1236. /* BusLogic BT-742A EISA 2.1x or 2.20 */
  1237. strcpy(HostAdapterModelNumber, "742A");
  1238. else if (ExtendedSetupInformation.BusType == 'E' && BoardID.FirmwareVersion1stDigit == '0')
  1239. /* AMI FastDisk EISA Series 441 0.x */
  1240. strcpy(HostAdapterModelNumber, "747A");
  1241. else {
  1242. RequestedReplyLength = sizeof(HostAdapterModelNumber);
  1243. if (BusLogic_Command(HostAdapter, BusLogic_InquireHostAdapterModelNumber, &RequestedReplyLength, sizeof(RequestedReplyLength), &HostAdapterModelNumber, sizeof(HostAdapterModelNumber))
  1244. != sizeof(HostAdapterModelNumber))
  1245. return BusLogic_Failure(HostAdapter, "INQUIRE HOST ADAPTER MODEL NUMBER");
  1246. }
  1247. /*
  1248. BusLogic MultiMaster Host Adapters can be identified by their model number
  1249. and the major version number of their firmware as follows:
  1250. 5.xx BusLogic "W" Series Host Adapters:
  1251. BT-948/958/958D
  1252. 4.xx BusLogic "C" Series Host Adapters:
  1253. BT-946C/956C/956CD/747C/757C/757CD/445C/545C/540CF
  1254. 3.xx BusLogic "S" Series Host Adapters:
  1255. BT-747S/747D/757S/757D/445S/545S/542D
  1256. BT-542B/742A (revision H)
  1257. 2.xx BusLogic "A" Series Host Adapters:
  1258. BT-542B/742A (revision G and below)
  1259. 0.xx AMI FastDisk VLB/EISA BusLogic Clone Host Adapter
  1260. */
  1261. /*
  1262. Save the Model Name and Host Adapter Name in the Host Adapter structure.
  1263. */
  1264. TargetPointer = HostAdapter->ModelName;
  1265. *TargetPointer++ = 'B';
  1266. *TargetPointer++ = 'T';
  1267. *TargetPointer++ = '-';
  1268. for (i = 0; i < sizeof(HostAdapterModelNumber); i++) {
  1269. Character = HostAdapterModelNumber[i];
  1270. if (Character == ' ' || Character == '\0')
  1271. break;
  1272. *TargetPointer++ = Character;
  1273. }
  1274. *TargetPointer++ = '\0';
  1275. /*
  1276. Save the Firmware Version in the Host Adapter structure.
  1277. */
  1278. TargetPointer = HostAdapter->FirmwareVersion;
  1279. *TargetPointer++ = BoardID.FirmwareVersion1stDigit;
  1280. *TargetPointer++ = '.';
  1281. *TargetPointer++ = BoardID.FirmwareVersion2ndDigit;
  1282. if (FirmwareVersion3rdDigit != ' ' && FirmwareVersion3rdDigit != '\0')
  1283. *TargetPointer++ = FirmwareVersion3rdDigit;
  1284. *TargetPointer = '\0';
  1285. /*
  1286. Issue the Inquire Firmware Version Letter command.
  1287. */
  1288. if (strcmp(HostAdapter->FirmwareVersion, "3.3") >= 0) {
  1289. if (BusLogic_Command(HostAdapter, BusLogic_InquireFirmwareVersionLetter, NULL, 0, &FirmwareVersionLetter, sizeof(FirmwareVersionLetter))
  1290. != sizeof(FirmwareVersionLetter))
  1291. return BusLogic_Failure(HostAdapter, "INQUIRE FIRMWARE VERSION LETTER");
  1292. if (FirmwareVersionLetter != ' ' && FirmwareVersionLetter != '\0')
  1293. *TargetPointer++ = FirmwareVersionLetter;
  1294. *TargetPointer = '\0';
  1295. }
  1296. /*
  1297. Save the Host Adapter SCSI ID in the Host Adapter structure.
  1298. */
  1299. HostAdapter->SCSI_ID = Configuration.HostAdapterID;
  1300. /*
  1301. Determine the Bus Type and save it in the Host Adapter structure, determine
  1302. and save the IRQ Channel if necessary, and determine and save the DMA
  1303. Channel for ISA Host Adapters.
  1304. */
  1305. HostAdapter->HostAdapterBusType = BusLogic_HostAdapterBusTypes[HostAdapter->ModelName[3] - '4'];
  1306. if (HostAdapter->IRQ_Channel == 0) {
  1307. if (Configuration.IRQ_Channel9)
  1308. HostAdapter->IRQ_Channel = 9;
  1309. else if (Configuration.IRQ_Channel10)
  1310. HostAdapter->IRQ_Channel = 10;
  1311. else if (Configuration.IRQ_Channel11)
  1312. HostAdapter->IRQ_Channel = 11;
  1313. else if (Configuration.IRQ_Channel12)
  1314. HostAdapter->IRQ_Channel = 12;
  1315. else if (Configuration.IRQ_Channel14)
  1316. HostAdapter->IRQ_Channel = 14;
  1317. else if (Configuration.IRQ_Channel15)
  1318. HostAdapter->IRQ_Channel = 15;
  1319. }
  1320. if (HostAdapter->HostAdapterBusType == BusLogic_ISA_Bus) {
  1321. if (Configuration.DMA_Channel5)
  1322. HostAdapter->DMA_Channel = 5;
  1323. else if (Configuration.DMA_Channel6)
  1324. HostAdapter->DMA_Channel = 6;
  1325. else if (Configuration.DMA_Channel7)
  1326. HostAdapter->DMA_Channel = 7;
  1327. }
  1328. /*
  1329. Determine whether Extended Translation is enabled and save it in
  1330. the Host Adapter structure.
  1331. */
  1332. GeometryRegister.All = BusLogic_ReadGeometryRegister(HostAdapter);
  1333. HostAdapter->ExtendedTranslationEnabled = GeometryRegister.gr.ExtendedTranslationEnabled;
  1334. /*
  1335. Save the Scatter Gather Limits, Level Sensitive Interrupt flag, Wide
  1336. SCSI flag, Differential SCSI flag, SCAM Supported flag, and
  1337. Ultra SCSI flag in the Host Adapter structure.
  1338. */
  1339. HostAdapter->HostAdapterScatterGatherLimit = ExtendedSetupInformation.ScatterGatherLimit;
  1340. HostAdapter->DriverScatterGatherLimit = HostAdapter->HostAdapterScatterGatherLimit;
  1341. if (HostAdapter->HostAdapterScatterGatherLimit > BusLogic_ScatterGatherLimit)
  1342. HostAdapter->DriverScatterGatherLimit = BusLogic_ScatterGatherLimit;
  1343. if (ExtendedSetupInformation.Misc.LevelSensitiveInterrupt)
  1344. HostAdapter->LevelSensitiveInterrupt = true;
  1345. HostAdapter->HostWideSCSI = ExtendedSetupInformation.HostWideSCSI;
  1346. HostAdapter->HostDifferentialSCSI = ExtendedSetupInformation.HostDifferentialSCSI;
  1347. HostAdapter->HostSupportsSCAM = ExtendedSetupInformation.HostSupportsSCAM;
  1348. HostAdapter->HostUltraSCSI = ExtendedSetupInformation.HostUltraSCSI;
  1349. /*
  1350. Determine whether Extended LUN Format CCBs are supported and save the
  1351. information in the Host Adapter structure.
  1352. */
  1353. if (HostAdapter->FirmwareVersion[0] == '5' || (HostAdapter->FirmwareVersion[0] == '4' && HostAdapter->HostWideSCSI))
  1354. HostAdapter->ExtendedLUNSupport = true;
  1355. /*
  1356. Issue the Inquire PCI Host Adapter Information command to read the
  1357. Termination Information from "W" series MultiMaster Host Adapters.
  1358. */
  1359. if (HostAdapter->FirmwareVersion[0] == '5') {
  1360. if (BusLogic_Command(HostAdapter, BusLogic_InquirePCIHostAdapterInformation, NULL, 0, &PCIHostAdapterInformation, sizeof(PCIHostAdapterInformation))
  1361. != sizeof(PCIHostAdapterInformation))
  1362. return BusLogic_Failure(HostAdapter, "INQUIRE PCI HOST ADAPTER INFORMATION");
  1363. /*
  1364. Save the Termination Information in the Host Adapter structure.
  1365. */
  1366. if (PCIHostAdapterInformation.GenericInfoValid) {
  1367. HostAdapter->TerminationInfoValid = true;
  1368. HostAdapter->LowByteTerminated = PCIHostAdapterInformation.LowByteTerminated;
  1369. HostAdapter->HighByteTerminated = PCIHostAdapterInformation.HighByteTerminated;
  1370. }
  1371. }
  1372. /*
  1373. Issue the Fetch Host Adapter Local RAM command to read the AutoSCSI data
  1374. from "W" and "C" series MultiMaster Host Adapters.
  1375. */
  1376. if (HostAdapter->FirmwareVersion[0] >= '4') {
  1377. FetchHostAdapterLocalRAMRequest.ByteOffset = BusLogic_AutoSCSI_BaseOffset;
  1378. FetchHostAdapterLocalRAMRequest.ByteCount = sizeof(AutoSCSIData);
  1379. if (BusLogic_Command(HostAdapter, BusLogic_FetchHostAdapterLocalRAM, &FetchHostAdapterLocalRAMRequest, sizeof(FetchHostAdapterLocalRAMRequest), &AutoSCSIData, sizeof(AutoSCSIData))
  1380. != sizeof(AutoSCSIData))
  1381. return BusLogic_Failure(HostAdapter, "FETCH HOST ADAPTER LOCAL RAM");
  1382. /*
  1383. Save the Parity Checking Enabled, Bus Reset Enabled, and Termination
  1384. Information in the Host Adapter structure.
  1385. */
  1386. HostAdapter->ParityCheckingEnabled = AutoSCSIData.ParityCheckingEnabled;
  1387. HostAdapter->BusResetEnabled = AutoSCSIData.BusResetEnabled;
  1388. if (HostAdapter->FirmwareVersion[0] == '4') {
  1389. HostAdapter->TerminationInfoValid = true;
  1390. HostAdapter->LowByteTerminated = AutoSCSIData.LowByteTerminated;
  1391. HostAdapter->HighByteTerminated = AutoSCSIData.HighByteTerminated;
  1392. }
  1393. /*
  1394. Save the Wide Permitted, Fast Permitted, Synchronous Permitted,
  1395. Disconnect Permitted, Ultra Permitted, and SCAM Information in the
  1396. Host Adapter structure.
  1397. */
  1398. HostAdapter->WidePermitted = AutoSCSIData.WidePermitted;
  1399. HostAdapter->FastPermitted = AutoSCSIData.FastPermitted;
  1400. HostAdapter->SynchronousPermitted = AutoSCSIData.SynchronousPermitted;
  1401. HostAdapter->DisconnectPermitted = AutoSCSIData.DisconnectPermitted;
  1402. if (HostAdapter->HostUltraSCSI)
  1403. HostAdapter->UltraPermitted = AutoSCSIData.UltraPermitted;
  1404. if (HostAdapter->HostSupportsSCAM) {
  1405. HostAdapter->SCAM_Enabled = AutoSCSIData.SCAM_Enabled;
  1406. HostAdapter->SCAM_Level2 = AutoSCSIData.SCAM_Level2;
  1407. }
  1408. }
  1409. /*
  1410. Initialize fields in the Host Adapter structure for "S" and "A" series
  1411. MultiMaster Host Adapters.
  1412. */
  1413. if (HostAdapter->FirmwareVersion[0] < '4') {
  1414. if (SetupInformation.SynchronousInitiationEnabled) {
  1415. HostAdapter->SynchronousPermitted = 0xFF;
  1416. if (HostAdapter->HostAdapterBusType == BusLogic_EISA_Bus) {
  1417. if (ExtendedSetupInformation.Misc.FastOnEISA)
  1418. HostAdapter->FastPermitted = 0xFF;
  1419. if (strcmp(HostAdapter->ModelName, "BT-757") == 0)
  1420. HostAdapter->WidePermitted = 0xFF;
  1421. }
  1422. }
  1423. HostAdapter->DisconnectPermitted = 0xFF;
  1424. HostAdapter->ParityCheckingEnabled = SetupInformation.ParityCheckingEnabled;
  1425. HostAdapter->BusResetEnabled = true;
  1426. }
  1427. /*
  1428. Determine the maximum number of Target IDs and Logical Units supported by
  1429. this driver for Wide and Narrow Host Adapters.
  1430. */
  1431. HostAdapter->MaxTargetDevices = (HostAdapter->HostWideSCSI ? 16 : 8);
  1432. HostAdapter->MaxLogicalUnits = (HostAdapter->ExtendedLUNSupport ? 32 : 8);
  1433. /*
  1434. Select appropriate values for the Mailbox Count, Driver Queue Depth,
  1435. Initial CCBs, and Incremental CCBs variables based on whether or not Strict
  1436. Round Robin Mode is supported. If Strict Round Robin Mode is supported,
  1437. then there is no performance degradation in using the maximum possible
  1438. number of Outgoing and Incoming Mailboxes and allowing the Tagged and
  1439. Untagged Queue Depths to determine the actual utilization. If Strict Round
  1440. Robin Mode is not supported, then the Host Adapter must scan all the
  1441. Outgoing Mailboxes whenever an Outgoing Mailbox entry is made, which can
  1442. cause a substantial performance penalty. The host adapters actually have
  1443. room to store the following number of CCBs internally; that is, they can
  1444. internally queue and manage this many active commands on the SCSI bus
  1445. simultaneously. Performance measurements demonstrate that the Driver Queue
  1446. Depth should be set to the Mailbox Count, rather than the Host Adapter
  1447. Queue Depth (internal CCB capacity), as it is more efficient to have the
  1448. queued commands waiting in Outgoing Mailboxes if necessary than to block
  1449. the process in the higher levels of the SCSI Subsystem.
  1450. 192 BT-948/958/958D
  1451. 100 BT-946C/956C/956CD/747C/757C/757CD/445C
  1452. 50 BT-545C/540CF
  1453. 30 BT-747S/747D/757S/757D/445S/545S/542D/542B/742A
  1454. */
  1455. if (HostAdapter->FirmwareVersion[0] == '5')
  1456. HostAdapter->HostAdapterQueueDepth = 192;
  1457. else if (HostAdapter->FirmwareVersion[0] == '4')
  1458. HostAdapter->HostAdapterQueueDepth = (HostAdapter->HostAdapterBusType != BusLogic_ISA_Bus ? 100 : 50);
  1459. else
  1460. HostAdapter->HostAdapterQueueDepth = 30;
  1461. if (strcmp(HostAdapter->FirmwareVersion, "3.31") >= 0) {
  1462. HostAdapter->StrictRoundRobinModeSupport = true;
  1463. HostAdapter->MailboxCount = BusLogic_MaxMailboxes;
  1464. } else {
  1465. HostAdapter->StrictRoundRobinModeSupport = false;
  1466. HostAdapter->MailboxCount = 32;
  1467. }
  1468. HostAdapter->DriverQueueDepth = HostAdapter->MailboxCount;
  1469. HostAdapter->InitialCCBs = 4 * BusLogic_CCB_AllocationGroupSize;
  1470. HostAdapter->IncrementalCCBs = BusLogic_CCB_AllocationGroupSize;
  1471. /*
  1472. Tagged Queuing support is available and operates properly on all "W" series
  1473. MultiMaster Host Adapters, on "C" series MultiMaster Host Adapters with
  1474. firmware version 4.22 and above, and on "S" series MultiMaster Host
  1475. Adapters with firmware version 3.35 and above.
  1476. */
  1477. HostAdapter->TaggedQueuingPermitted = 0;
  1478. switch (HostAdapter->FirmwareVersion[0]) {
  1479. case '5':
  1480. HostAdapter->TaggedQueuingPermitted = 0xFFFF;
  1481. break;
  1482. case '4':
  1483. if (strcmp(HostAdapter->FirmwareVersion, "4.22") >= 0)
  1484. HostAdapter->TaggedQueuingPermitted = 0xFFFF;
  1485. break;
  1486. case '3':
  1487. if (strcmp(HostAdapter->FirmwareVersion, "3.35") >= 0)
  1488. HostAdapter->TaggedQueuingPermitted = 0xFFFF;
  1489. break;
  1490. }
  1491. /*
  1492. Determine the Host Adapter BIOS Address if the BIOS is enabled and
  1493. save it in the Host Adapter structure. The BIOS is disabled if the
  1494. BIOS_Address is 0.
  1495. */
  1496. HostAdapter->BIOS_Address = ExtendedSetupInformation.BIOS_Address << 12;
  1497. /*
  1498. ISA Host Adapters require Bounce Buffers if there is more than 16MB memory.
  1499. */
  1500. if (HostAdapter->HostAdapterBusType == BusLogic_ISA_Bus && (void *) high_memory > (void *) MAX_DMA_ADDRESS)
  1501. HostAdapter->BounceBuffersRequired = true;
  1502. /*
  1503. BusLogic BT-445S Host Adapters prior to board revision E have a hardware
  1504. bug whereby when the BIOS is enabled, transfers to/from the same address
  1505. range the BIOS occupies modulo 16MB are handled incorrectly. Only properly
  1506. functioning BT-445S Host Adapters have firmware version 3.37, so require
  1507. that ISA Bounce Buffers be used for the buggy BT-445S models if there is
  1508. more than 16MB memory.
  1509. */
  1510. if (HostAdapter->BIOS_Address > 0 && strcmp(HostAdapter->ModelName, "BT-445S") == 0 && strcmp(HostAdapter->FirmwareVersion, "3.37") < 0 && (void *) high_memory > (void *) MAX_DMA_ADDRESS)
  1511. HostAdapter->BounceBuffersRequired = true;
  1512. /*
  1513. Initialize parameters common to MultiMaster and FlashPoint Host Adapters.
  1514. */
  1515. Common:
  1516. /*
  1517. Initialize the Host Adapter Full Model Name from the Model Name.
  1518. */
  1519. strcpy(HostAdapter->FullModelName, "BusLogic ");
  1520. strcat(HostAdapter->FullModelName, HostAdapter->ModelName);
  1521. /*
  1522. Select an appropriate value for the Tagged Queue Depth either from a
  1523. BusLogic Driver Options specification, or based on whether this Host
  1524. Adapter requires that ISA Bounce Buffers be used. The Tagged Queue Depth
  1525. is left at 0 for automatic determination in BusLogic_SelectQueueDepths.
  1526. Initialize the Untagged Queue Depth.
  1527. */
  1528. for (TargetID = 0; TargetID < BusLogic_MaxTargetDevices; TargetID++) {
  1529. unsigned char QueueDepth = 0;
  1530. if (HostAdapter->DriverOptions != NULL && HostAdapter->DriverOptions->QueueDepth[TargetID] > 0)
  1531. QueueDepth = HostAdapter->DriverOptions->QueueDepth[TargetID];
  1532. else if (HostAdapter->BounceBuffersRequired)
  1533. QueueDepth = BusLogic_TaggedQueueDepthBB;
  1534. HostAdapter->QueueDepth[TargetID] = QueueDepth;
  1535. }
  1536. if (HostAdapter->BounceBuffersRequired)
  1537. HostAdapter->UntaggedQueueDepth = BusLogic_UntaggedQueueDepthBB;
  1538. else
  1539. HostAdapter->UntaggedQueueDepth = BusLogic_UntaggedQueueDepth;
  1540. if (HostAdapter->DriverOptions != NULL)
  1541. HostAdapter->CommonQueueDepth = HostAdapter->DriverOptions->CommonQueueDepth;
  1542. if (HostAdapter->CommonQueueDepth > 0 && HostAdapter->CommonQueueDepth < HostAdapter->UntaggedQueueDepth)
  1543. HostAdapter->UntaggedQueueDepth = HostAdapter->CommonQueueDepth;
  1544. /*
  1545. Tagged Queuing is only allowed if Disconnect/Reconnect is permitted.
  1546. Therefore, mask the Tagged Queuing Permitted Default bits with the
  1547. Disconnect/Reconnect Permitted bits.
  1548. */
  1549. HostAdapter->TaggedQueuingPermitted &= HostAdapter->DisconnectPermitted;
  1550. /*
  1551. Combine the default Tagged Queuing Permitted bits with any BusLogic Driver
  1552. Options Tagged Queuing specification.
  1553. */
  1554. if (HostAdapter->DriverOptions != NULL)
  1555. HostAdapter->TaggedQueuingPermitted =
  1556. (HostAdapter->DriverOptions->TaggedQueuingPermitted & HostAdapter->DriverOptions->TaggedQueuingPermittedMask) | (HostAdapter->TaggedQueuingPermitted & ~HostAdapter->DriverOptions->TaggedQueuingPermittedMask);
  1557. /*
  1558. Select an appropriate value for Bus Settle Time either from a BusLogic
  1559. Driver Options specification, or from BusLogic_DefaultBusSettleTime.
  1560. */
  1561. if (HostAdapter->DriverOptions != NULL && HostAdapter->DriverOptions->BusSettleTime > 0)
  1562. HostAdapter->BusSettleTime = HostAdapter->DriverOptions->BusSettleTime;
  1563. else
  1564. HostAdapter->BusSettleTime = BusLogic_DefaultBusSettleTime;
  1565. /*
  1566. Indicate reading the Host Adapter Configuration completed successfully.
  1567. */
  1568. return true;
  1569. }
  1570. /*
  1571. BusLogic_ReportHostAdapterConfiguration reports the configuration of
  1572. Host Adapter.
  1573. */
  1574. static bool __init BusLogic_ReportHostAdapterConfiguration(struct BusLogic_HostAdapter
  1575. *HostAdapter)
  1576. {
  1577. unsigned short AllTargetsMask = (1 << HostAdapter->MaxTargetDevices) - 1;
  1578. unsigned short SynchronousPermitted, FastPermitted;
  1579. unsigned short UltraPermitted, WidePermitted;
  1580. unsigned short DisconnectPermitted, TaggedQueuingPermitted;
  1581. bool CommonSynchronousNegotiation, CommonTaggedQueueDepth;
  1582. char SynchronousString[BusLogic_MaxTargetDevices + 1];
  1583. char WideString[BusLogic_MaxTargetDevices + 1];
  1584. char DisconnectString[BusLogic_MaxTargetDevices + 1];
  1585. char TaggedQueuingString[BusLogic_MaxTargetDevices + 1];
  1586. char *SynchronousMessage = SynchronousString;
  1587. char *WideMessage = WideString;
  1588. char *DisconnectMessage = DisconnectString;
  1589. char *TaggedQueuingMessage = TaggedQueuingString;
  1590. int TargetID;
  1591. BusLogic_Info("Configuring BusLogic Model %s %s%s%s%s SCSI Host Adapter\n",
  1592. HostAdapter, HostAdapter->ModelName,
  1593. BusLogic_HostAdapterBusNames[HostAdapter->HostAdapterBusType], (HostAdapter->HostWideSCSI ? " Wide" : ""), (HostAdapter->HostDifferentialSCSI ? " Differential" : ""), (HostAdapter->HostUltraSCSI ? " Ultra" : ""));
  1594. BusLogic_Info(" Firmware Version: %s, I/O Address: 0x%X, " "IRQ Channel: %d/%s\n", HostAdapter, HostAdapter->FirmwareVersion, HostAdapter->IO_Address, HostAdapter->IRQ_Channel, (HostAdapter->LevelSensitiveInterrupt ? "Level" : "Edge"));
  1595. if (HostAdapter->HostAdapterBusType != BusLogic_PCI_Bus) {
  1596. BusLogic_Info(" DMA Channel: ", HostAdapter);
  1597. if (HostAdapter->DMA_Channel > 0)
  1598. BusLogic_Info("%d, ", HostAdapter, HostAdapter->DMA_Channel);
  1599. else
  1600. BusLogic_Info("None, ", HostAdapter);
  1601. if (HostAdapter->BIOS_Address > 0)
  1602. BusLogic_Info("BIOS Address: 0x%X, ", HostAdapter, HostAdapter->BIOS_Address);
  1603. else
  1604. BusLogic_Info("BIOS Address: None, ", HostAdapter);
  1605. } else {
  1606. BusLogic_Info(" PCI Bus: %d, Device: %d, Address: ", HostAdapter, HostAdapter->Bus, HostAdapter->Device);
  1607. if (HostAdapter->PCI_Address > 0)
  1608. BusLogic_Info("0x%X, ", HostAdapter, HostAdapter->PCI_Address);
  1609. else
  1610. BusLogic_Info("Unassigned, ", HostAdapter);
  1611. }
  1612. BusLogic_Info("Host Adapter SCSI ID: %d\n", HostAdapter, HostAdapter->SCSI_ID);
  1613. BusLogic_Info(" Parity Checking: %s, Extended Translation: %s\n", HostAdapter, (HostAdapter->ParityCheckingEnabled ? "Enabled" : "Disabled"), (HostAdapter->ExtendedTranslationEnabled ? "Enabled" : "Disabled"));
  1614. AllTargetsMask &= ~(1 << HostAdapter->SCSI_ID);
  1615. SynchronousPermitted = HostAdapter->SynchronousPermitted & AllTargetsMask;
  1616. FastPermitted = HostAdapter->FastPermitted & AllTargetsMask;
  1617. UltraPermitted = HostAdapter->UltraPermitted & AllTargetsMask;
  1618. if ((BusLogic_MultiMasterHostAdapterP(HostAdapter) && (HostAdapter->FirmwareVersion[0] >= '4' || HostAdapter->HostAdapterBusType == BusLogic_EISA_Bus)) || BusLogic_FlashPointHostAdapterP(HostAdapter)) {
  1619. CommonSynchronousNegotiation = false;
  1620. if (SynchronousPermitted == 0) {
  1621. SynchronousMessage = "Disabled";
  1622. CommonSynchronousNegotiation = true;
  1623. } else if (SynchronousPermitted == AllTargetsMask) {
  1624. if (FastPermitted == 0) {
  1625. SynchronousMessage = "Slow";
  1626. CommonSynchronousNegotiation = true;
  1627. } else if (FastPermitted == AllTargetsMask) {
  1628. if (UltraPermitted == 0) {
  1629. SynchronousMessage = "Fast";
  1630. CommonSynchronousNegotiation = true;
  1631. } else if (UltraPermitted == AllTargetsMask) {
  1632. SynchronousMessage = "Ultra";
  1633. CommonSynchronousNegotiation = true;
  1634. }
  1635. }
  1636. }
  1637. if (!CommonSynchronousNegotiation) {
  1638. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1639. SynchronousString[TargetID] = ((!(SynchronousPermitted & (1 << TargetID))) ? 'N' : (!(FastPermitted & (1 << TargetID)) ? 'S' : (!(UltraPermitted & (1 << TargetID)) ? 'F' : 'U')));
  1640. SynchronousString[HostAdapter->SCSI_ID] = '#';
  1641. SynchronousString[HostAdapter->MaxTargetDevices] = '\0';
  1642. }
  1643. } else
  1644. SynchronousMessage = (SynchronousPermitted == 0 ? "Disabled" : "Enabled");
  1645. WidePermitted = HostAdapter->WidePermitted & AllTargetsMask;
  1646. if (WidePermitted == 0)
  1647. WideMessage = "Disabled";
  1648. else if (WidePermitted == AllTargetsMask)
  1649. WideMessage = "Enabled";
  1650. else {
  1651. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1652. WideString[TargetID] = ((WidePermitted & (1 << TargetID)) ? 'Y' : 'N');
  1653. WideString[HostAdapter->SCSI_ID] = '#';
  1654. WideString[HostAdapter->MaxTargetDevices] = '\0';
  1655. }
  1656. DisconnectPermitted = HostAdapter->DisconnectPermitted & AllTargetsMask;
  1657. if (DisconnectPermitted == 0)
  1658. DisconnectMessage = "Disabled";
  1659. else if (DisconnectPermitted == AllTargetsMask)
  1660. DisconnectMessage = "Enabled";
  1661. else {
  1662. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1663. DisconnectString[TargetID] = ((DisconnectPermitted & (1 << TargetID)) ? 'Y' : 'N');
  1664. DisconnectString[HostAdapter->SCSI_ID] = '#';
  1665. DisconnectString[HostAdapter->MaxTargetDevices] = '\0';
  1666. }
  1667. TaggedQueuingPermitted = HostAdapter->TaggedQueuingPermitted & AllTargetsMask;
  1668. if (TaggedQueuingPermitted == 0)
  1669. TaggedQueuingMessage = "Disabled";
  1670. else if (TaggedQueuingPermitted == AllTargetsMask)
  1671. TaggedQueuingMessage = "Enabled";
  1672. else {
  1673. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1674. TaggedQueuingString[TargetID] = ((TaggedQueuingPermitted & (1 << TargetID)) ? 'Y' : 'N');
  1675. TaggedQueuingString[HostAdapter->SCSI_ID] = '#';
  1676. TaggedQueuingString[HostAdapter->MaxTargetDevices] = '\0';
  1677. }
  1678. BusLogic_Info(" Synchronous Negotiation: %s, Wide Negotiation: %s\n", HostAdapter, SynchronousMessage, WideMessage);
  1679. BusLogic_Info(" Disconnect/Reconnect: %s, Tagged Queuing: %s\n", HostAdapter, DisconnectMessage, TaggedQueuingMessage);
  1680. if (BusLogic_MultiMasterHostAdapterP(HostAdapter)) {
  1681. BusLogic_Info(" Scatter/Gather Limit: %d of %d segments, " "Mailboxes: %d\n", HostAdapter, HostAdapter->DriverScatterGatherLimit, HostAdapter->HostAdapterScatterGatherLimit, HostAdapter->MailboxCount);
  1682. BusLogic_Info(" Driver Queue Depth: %d, " "Host Adapter Queue Depth: %d\n", HostAdapter, HostAdapter->DriverQueueDepth, HostAdapter->HostAdapterQueueDepth);
  1683. } else
  1684. BusLogic_Info(" Driver Queue Depth: %d, " "Scatter/Gather Limit: %d segments\n", HostAdapter, HostAdapter->DriverQueueDepth, HostAdapter->DriverScatterGatherLimit);
  1685. BusLogic_Info(" Tagged Queue Depth: ", HostAdapter);
  1686. CommonTaggedQueueDepth = true;
  1687. for (TargetID = 1; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1688. if (HostAdapter->QueueDepth[TargetID] != HostAdapter->QueueDepth[0]) {
  1689. CommonTaggedQueueDepth = false;
  1690. break;
  1691. }
  1692. if (CommonTaggedQueueDepth) {
  1693. if (HostAdapter->QueueDepth[0] > 0)
  1694. BusLogic_Info("%d", HostAdapter, HostAdapter->QueueDepth[0]);
  1695. else
  1696. BusLogic_Info("Automatic", HostAdapter);
  1697. } else
  1698. BusLogic_Info("Individual", HostAdapter);
  1699. BusLogic_Info(", Untagged Queue Depth: %d\n", HostAdapter, HostAdapter->UntaggedQueueDepth);
  1700. if (HostAdapter->TerminationInfoValid) {
  1701. if (HostAdapter->HostWideSCSI)
  1702. BusLogic_Info(" SCSI Bus Termination: %s", HostAdapter, (HostAdapter->LowByteTerminated ? (HostAdapter->HighByteTerminated ? "Both Enabled" : "Low Enabled")
  1703. : (HostAdapter->HighByteTerminated ? "High Enabled" : "Both Disabled")));
  1704. else
  1705. BusLogic_Info(" SCSI Bus Termination: %s", HostAdapter, (HostAdapter->LowByteTerminated ? "Enabled" : "Disabled"));
  1706. if (HostAdapter->HostSupportsSCAM)
  1707. BusLogic_Info(", SCAM: %s", HostAdapter, (HostAdapter->SCAM_Enabled ? (HostAdapter->SCAM_Level2 ? "Enabled, Level 2" : "Enabled, Level 1")
  1708. : "Disabled"));
  1709. BusLogic_Info("\n", HostAdapter);
  1710. }
  1711. /*
  1712. Indicate reporting the Host Adapter configuration completed successfully.
  1713. */
  1714. return true;
  1715. }
  1716. /*
  1717. BusLogic_AcquireResources acquires the system resources necessary to use
  1718. Host Adapter.
  1719. */
  1720. static bool __init BusLogic_AcquireResources(struct BusLogic_HostAdapter *HostAdapter)
  1721. {
  1722. if (HostAdapter->IRQ_Channel == 0) {
  1723. BusLogic_Error("NO LEGAL INTERRUPT CHANNEL ASSIGNED - DETACHING\n", HostAdapter);
  1724. return false;
  1725. }
  1726. /*
  1727. Acquire shared access to the IRQ Channel.
  1728. */
  1729. if (request_irq(HostAdapter->IRQ_Channel, BusLogic_InterruptHandler, IRQF_SHARED, HostAdapter->FullModelName, HostAdapter) < 0) {
  1730. BusLogic_Error("UNABLE TO ACQUIRE IRQ CHANNEL %d - DETACHING\n", HostAdapter, HostAdapter->IRQ_Channel);
  1731. return false;
  1732. }
  1733. HostAdapter->IRQ_ChannelAcquired = true;
  1734. /*
  1735. Acquire exclusive access to the DMA Channel.
  1736. */
  1737. if (HostAdapter->DMA_Channel > 0) {
  1738. if (request_dma(HostAdapter->DMA_Channel, HostAdapter->FullModelName) < 0) {
  1739. BusLogic_Error("UNABLE TO ACQUIRE DMA CHANNEL %d - DETACHING\n", HostAdapter, HostAdapter->DMA_Channel);
  1740. return false;
  1741. }
  1742. set_dma_mode(HostAdapter->DMA_Channel, DMA_MODE_CASCADE);
  1743. enable_dma(HostAdapter->DMA_Channel);
  1744. HostAdapter->DMA_ChannelAcquired = true;
  1745. }
  1746. /*
  1747. Indicate the System Resource Acquisition completed successfully,
  1748. */
  1749. return true;
  1750. }
  1751. /*
  1752. BusLogic_ReleaseResources releases any system resources previously acquired
  1753. by BusLogic_AcquireResources.
  1754. */
  1755. static void BusLogic_ReleaseResources(struct BusLogic_HostAdapter *HostAdapter)
  1756. {
  1757. /*
  1758. Release shared access to the IRQ Channel.
  1759. */
  1760. if (HostAdapter->IRQ_ChannelAcquired)
  1761. free_irq(HostAdapter->IRQ_Channel, HostAdapter);
  1762. /*
  1763. Release exclusive access to the DMA Channel.
  1764. */
  1765. if (HostAdapter->DMA_ChannelAcquired)
  1766. free_dma(HostAdapter->DMA_Channel);
  1767. /*
  1768. Release any allocated memory structs not released elsewhere
  1769. */
  1770. if (HostAdapter->MailboxSpace)
  1771. pci_free_consistent(HostAdapter->PCI_Device, HostAdapter->MailboxSize, HostAdapter->MailboxSpace, HostAdapter->MailboxSpaceHandle);
  1772. pci_dev_put(HostAdapter->PCI_Device);
  1773. HostAdapter->MailboxSpace = NULL;
  1774. HostAdapter->MailboxSpaceHandle = 0;
  1775. HostAdapter->MailboxSize = 0;
  1776. }
  1777. /*
  1778. BusLogic_InitializeHostAdapter initializes Host Adapter. This is the only
  1779. function called during SCSI Host Adapter detection which modifies the state
  1780. of the Host Adapter from its initial power on or hard reset state.
  1781. */
  1782. static bool BusLogic_InitializeHostAdapter(struct BusLogic_HostAdapter
  1783. *HostAdapter)
  1784. {
  1785. struct BusLogic_ExtendedMailboxRequest ExtendedMailboxRequest;
  1786. enum BusLogic_RoundRobinModeRequest RoundRobinModeRequest;
  1787. enum BusLogic_SetCCBFormatRequest SetCCBFormatRequest;
  1788. int TargetID;
  1789. /*
  1790. Initialize the pointers to the first and last CCBs that are queued for
  1791. completion processing.
  1792. */
  1793. HostAdapter->FirstCompletedCCB = NULL;
  1794. HostAdapter->LastCompletedCCB = NULL;
  1795. /*
  1796. Initialize the Bus Device Reset Pending CCB, Tagged Queuing Active,
  1797. Command Successful Flag, Active Commands, and Commands Since Reset
  1798. for each Target Device.
  1799. */
  1800. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  1801. HostAdapter->BusDeviceResetPendingCCB[TargetID] = NULL;
  1802. HostAdapter->TargetFlags[TargetID].TaggedQueuingActive = false;
  1803. HostAdapter->TargetFlags[TargetID].CommandSuccessfulFlag = false;
  1804. HostAdapter->ActiveCommands[TargetID] = 0;
  1805. HostAdapter->CommandsSinceReset[TargetID] = 0;
  1806. }
  1807. /*
  1808. FlashPoint Host Adapters do not use Outgoing and Incoming Mailboxes.
  1809. */
  1810. if (BusLogic_FlashPointHostAdapterP(HostAdapter))
  1811. goto Done;
  1812. /*
  1813. Initialize the Outgoing and Incoming Mailbox pointers.
  1814. */
  1815. HostAdapter->MailboxSize = HostAdapter->MailboxCount * (sizeof(struct BusLogic_OutgoingMailbox) + sizeof(struct BusLogic_IncomingMailbox));
  1816. HostAdapter->MailboxSpace = pci_alloc_consistent(HostAdapter->PCI_Device, HostAdapter->MailboxSize, &HostAdapter->MailboxSpaceHandle);
  1817. if (HostAdapter->MailboxSpace == NULL)
  1818. return BusLogic_Failure(HostAdapter, "MAILBOX ALLOCATION");
  1819. HostAdapter->FirstOutgoingMailbox = (struct BusLogic_OutgoingMailbox *) HostAdapter->MailboxSpace;
  1820. HostAdapter->LastOutgoingMailbox = HostAdapter->FirstOutgoingMailbox + HostAdapter->MailboxCount - 1;
  1821. HostAdapter->NextOutgoingMailbox = HostAdapter->FirstOutgoingMailbox;
  1822. HostAdapter->FirstIncomingMailbox = (struct BusLogic_IncomingMailbox *) (HostAdapter->LastOutgoingMailbox + 1);
  1823. HostAdapter->LastIncomingMailbox = HostAdapter->FirstIncomingMailbox + HostAdapter->MailboxCount - 1;
  1824. HostAdapter->NextIncomingMailbox = HostAdapter->FirstIncomingMailbox;
  1825. /*
  1826. Initialize the Outgoing and Incoming Mailbox structures.
  1827. */
  1828. memset(HostAdapter->FirstOutgoingMailbox, 0, HostAdapter->MailboxCount * sizeof(struct BusLogic_OutgoingMailbox));
  1829. memset(HostAdapter->FirstIncomingMailbox, 0, HostAdapter->MailboxCount * sizeof(struct BusLogic_IncomingMailbox));
  1830. /*
  1831. Initialize the Host Adapter's Pointer to the Outgoing/Incoming Mailboxes.
  1832. */
  1833. ExtendedMailboxRequest.MailboxCount = HostAdapter->MailboxCount;
  1834. ExtendedMailboxRequest.BaseMailboxAddress = (u32) HostAdapter->MailboxSpaceHandle;
  1835. if (BusLogic_Command(HostAdapter, BusLogic_InitializeExtendedMailbox, &ExtendedMailboxRequest, sizeof(ExtendedMailboxRequest), NULL, 0) < 0)
  1836. return BusLogic_Failure(HostAdapter, "MAILBOX INITIALIZATION");
  1837. /*
  1838. Enable Strict Round Robin Mode if supported by the Host Adapter. In
  1839. Strict Round Robin Mode, the Host Adapter only looks at the next Outgoing
  1840. Mailbox for each new command, rather than scanning through all the
  1841. Outgoing Mailboxes to find any that have new commands in them. Strict
  1842. Round Robin Mode is significantly more efficient.
  1843. */
  1844. if (HostAdapter->StrictRoundRobinModeSupport) {
  1845. RoundRobinModeRequest = BusLogic_StrictRoundRobinMode;
  1846. if (BusLogic_Command(HostAdapter, BusLogic_EnableStrictRoundRobinMode, &RoundRobinModeRequest, sizeof(RoundRobinModeRequest), NULL, 0) < 0)
  1847. return BusLogic_Failure(HostAdapter, "ENABLE STRICT ROUND ROBIN MODE");
  1848. }
  1849. /*
  1850. For Host Adapters that support Extended LUN Format CCBs, issue the Set CCB
  1851. Format command to allow 32 Logical Units per Target Device.
  1852. */
  1853. if (HostAdapter->ExtendedLUNSupport) {
  1854. SetCCBFormatRequest = BusLogic_ExtendedLUNFormatCCB;
  1855. if (BusLogic_Command(HostAdapter, BusLogic_SetCCBFormat, &SetCCBFormatRequest, sizeof(SetCCBFormatRequest), NULL, 0) < 0)
  1856. return BusLogic_Failure(HostAdapter, "SET CCB FORMAT");
  1857. }
  1858. /*
  1859. Announce Successful Initialization.
  1860. */
  1861. Done:
  1862. if (!HostAdapter->HostAdapterInitialized) {
  1863. BusLogic_Info("*** %s Initialized Successfully ***\n", HostAdapter, HostAdapter->FullModelName);
  1864. BusLogic_Info("\n", HostAdapter);
  1865. } else
  1866. BusLogic_Warning("*** %s Initialized Successfully ***\n", HostAdapter, HostAdapter->FullModelName);
  1867. HostAdapter->HostAdapterInitialized = true;
  1868. /*
  1869. Indicate the Host Adapter Initialization completed successfully.
  1870. */
  1871. return true;
  1872. }
  1873. /*
  1874. BusLogic_TargetDeviceInquiry inquires about the Target Devices accessible
  1875. through Host Adapter.
  1876. */
  1877. static bool __init BusLogic_TargetDeviceInquiry(struct BusLogic_HostAdapter
  1878. *HostAdapter)
  1879. {
  1880. u16 InstalledDevices;
  1881. u8 InstalledDevicesID0to7[8];
  1882. struct BusLogic_SetupInformation SetupInformation;
  1883. u8 SynchronousPeriod[BusLogic_MaxTargetDevices];
  1884. unsigned char RequestedReplyLength;
  1885. int TargetID;
  1886. /*
  1887. Wait a few seconds between the Host Adapter Hard Reset which initiates
  1888. a SCSI Bus Reset and issuing any SCSI Commands. Some SCSI devices get
  1889. confused if they receive SCSI Commands too soon after a SCSI Bus Reset.
  1890. */
  1891. BusLogic_Delay(HostAdapter->BusSettleTime);
  1892. /*
  1893. FlashPoint Host Adapters do not provide for Target Device Inquiry.
  1894. */
  1895. if (BusLogic_FlashPointHostAdapterP(HostAdapter))
  1896. return true;
  1897. /*
  1898. Inhibit the Target Device Inquiry if requested.
  1899. */
  1900. if (HostAdapter->DriverOptions != NULL && HostAdapter->DriverOptions->LocalOptions.InhibitTargetInquiry)
  1901. return true;
  1902. /*
  1903. Issue the Inquire Target Devices command for host adapters with firmware
  1904. version 4.25 or later, or the Inquire Installed Devices ID 0 to 7 command
  1905. for older host adapters. This is necessary to force Synchronous Transfer
  1906. Negotiation so that the Inquire Setup Information and Inquire Synchronous
  1907. Period commands will return valid data. The Inquire Target Devices command
  1908. is preferable to Inquire Installed Devices ID 0 to 7 since it only probes
  1909. Logical Unit 0 of each Target Device.
  1910. */
  1911. if (strcmp(HostAdapter->FirmwareVersion, "4.25") >= 0) {
  1912. /*
  1913. * Issue a Inquire Target Devices command. Inquire Target Devices only
  1914. * tests Logical Unit 0 of each Target Device unlike the Inquire Installed
  1915. * Devices commands which test Logical Units 0 - 7. Two bytes are
  1916. * returned, where byte 0 bit 0 set indicates that Target Device 0 exists,
  1917. * and so on.
  1918. */
  1919. if (BusLogic_Command(HostAdapter, BusLogic_InquireTargetDevices, NULL, 0, &InstalledDevices, sizeof(InstalledDevices))
  1920. != sizeof(InstalledDevices))
  1921. return BusLogic_Failure(HostAdapter, "INQUIRE TARGET DEVICES");
  1922. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1923. HostAdapter->TargetFlags[TargetID].TargetExists = (InstalledDevices & (1 << TargetID) ? true : false);
  1924. } else {
  1925. /*
  1926. * Issue an Inquire Installed Devices command. For each Target Device,
  1927. * a byte is returned where bit 0 set indicates that Logical Unit 0
  1928. * exists, bit 1 set indicates that Logical Unit 1 exists, and so on.
  1929. */
  1930. if (BusLogic_Command(HostAdapter, BusLogic_InquireInstalledDevicesID0to7, NULL, 0, &InstalledDevicesID0to7, sizeof(InstalledDevicesID0to7))
  1931. != sizeof(InstalledDevicesID0to7))
  1932. return BusLogic_Failure(HostAdapter, "INQUIRE INSTALLED DEVICES ID 0 TO 7");
  1933. for (TargetID = 0; TargetID < 8; TargetID++)
  1934. HostAdapter->TargetFlags[TargetID].TargetExists = (InstalledDevicesID0to7[TargetID] != 0 ? true : false);
  1935. }
  1936. /*
  1937. Issue the Inquire Setup Information command.
  1938. */
  1939. RequestedReplyLength = sizeof(SetupInformation);
  1940. if (BusLogic_Command(HostAdapter, BusLogic_InquireSetupInformation, &RequestedReplyLength, sizeof(RequestedReplyLength), &SetupInformation, sizeof(SetupInformation))
  1941. != sizeof(SetupInformation))
  1942. return BusLogic_Failure(HostAdapter, "INQUIRE SETUP INFORMATION");
  1943. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1944. HostAdapter->SynchronousOffset[TargetID] = (TargetID < 8 ? SetupInformation.SynchronousValuesID0to7[TargetID].Offset : SetupInformation.SynchronousValuesID8to15[TargetID - 8].Offset);
  1945. if (strcmp(HostAdapter->FirmwareVersion, "5.06L") >= 0)
  1946. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1947. HostAdapter->TargetFlags[TargetID].WideTransfersActive = (TargetID < 8 ? (SetupInformation.WideTransfersActiveID0to7 & (1 << TargetID)
  1948. ? true : false)
  1949. : (SetupInformation.WideTransfersActiveID8to15 & (1 << (TargetID - 8))
  1950. ? true : false));
  1951. /*
  1952. Issue the Inquire Synchronous Period command.
  1953. */
  1954. if (HostAdapter->FirmwareVersion[0] >= '3') {
  1955. /* Issue a Inquire Synchronous Period command. For each Target Device,
  1956. * a byte is returned which represents the Synchronous Transfer Period
  1957. * in units of 10 nanoseconds.
  1958. */
  1959. RequestedReplyLength = sizeof(SynchronousPeriod);
  1960. if (BusLogic_Command(HostAdapter, BusLogic_InquireSynchronousPeriod, &RequestedReplyLength, sizeof(RequestedReplyLength), &SynchronousPeriod, sizeof(SynchronousPeriod))
  1961. != sizeof(SynchronousPeriod))
  1962. return BusLogic_Failure(HostAdapter, "INQUIRE SYNCHRONOUS PERIOD");
  1963. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1964. HostAdapter->SynchronousPeriod[TargetID] = SynchronousPeriod[TargetID];
  1965. } else
  1966. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  1967. if (SetupInformation.SynchronousValuesID0to7[TargetID].Offset > 0)
  1968. HostAdapter->SynchronousPeriod[TargetID] = 20 + 5 * SetupInformation.SynchronousValuesID0to7[TargetID]
  1969. .TransferPeriod;
  1970. /*
  1971. Indicate the Target Device Inquiry completed successfully.
  1972. */
  1973. return true;
  1974. }
  1975. /*
  1976. BusLogic_InitializeHostStructure initializes the fields in the SCSI Host
  1977. structure. The base, io_port, n_io_ports, irq, and dma_channel fields in the
  1978. SCSI Host structure are intentionally left uninitialized, as this driver
  1979. handles acquisition and release of these resources explicitly, as well as
  1980. ensuring exclusive access to the Host Adapter hardware and data structures
  1981. through explicit acquisition and release of the Host Adapter's Lock.
  1982. */
  1983. static void __init BusLogic_InitializeHostStructure(struct BusLogic_HostAdapter
  1984. *HostAdapter, struct Scsi_Host *Host)
  1985. {
  1986. Host->max_id = HostAdapter->MaxTargetDevices;
  1987. Host->max_lun = HostAdapter->MaxLogicalUnits;
  1988. Host->max_channel = 0;
  1989. Host->unique_id = HostAdapter->IO_Address;
  1990. Host->this_id = HostAdapter->SCSI_ID;
  1991. Host->can_queue = HostAdapter->DriverQueueDepth;
  1992. Host->sg_tablesize = HostAdapter->DriverScatterGatherLimit;
  1993. Host->unchecked_isa_dma = HostAdapter->BounceBuffersRequired;
  1994. Host->cmd_per_lun = HostAdapter->UntaggedQueueDepth;
  1995. }
  1996. /*
  1997. BusLogic_SlaveConfigure will actually set the queue depth on individual
  1998. scsi devices as they are permanently added to the device chain. We
  1999. shamelessly rip off the SelectQueueDepths code to make this work mostly
  2000. like it used to. Since we don't get called once at the end of the scan
  2001. but instead get called for each device, we have to do things a bit
  2002. differently.
  2003. */
  2004. static int BusLogic_SlaveConfigure(struct scsi_device *Device)
  2005. {
  2006. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) Device->host->hostdata;
  2007. int TargetID = Device->id;
  2008. int QueueDepth = HostAdapter->QueueDepth[TargetID];
  2009. if (HostAdapter->TargetFlags[TargetID].TaggedQueuingSupported && (HostAdapter->TaggedQueuingPermitted & (1 << TargetID))) {
  2010. if (QueueDepth == 0)
  2011. QueueDepth = BusLogic_MaxAutomaticTaggedQueueDepth;
  2012. HostAdapter->QueueDepth[TargetID] = QueueDepth;
  2013. scsi_adjust_queue_depth(Device, MSG_SIMPLE_TAG, QueueDepth);
  2014. } else {
  2015. HostAdapter->TaggedQueuingPermitted &= ~(1 << TargetID);
  2016. QueueDepth = HostAdapter->UntaggedQueueDepth;
  2017. HostAdapter->QueueDepth[TargetID] = QueueDepth;
  2018. scsi_adjust_queue_depth(Device, 0, QueueDepth);
  2019. }
  2020. QueueDepth = 0;
  2021. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++)
  2022. if (HostAdapter->TargetFlags[TargetID].TargetExists) {
  2023. QueueDepth += HostAdapter->QueueDepth[TargetID];
  2024. }
  2025. if (QueueDepth > HostAdapter->AllocatedCCBs)
  2026. BusLogic_CreateAdditionalCCBs(HostAdapter, QueueDepth - HostAdapter->AllocatedCCBs, false);
  2027. return 0;
  2028. }
  2029. /*
  2030. BusLogic_DetectHostAdapter probes for BusLogic Host Adapters at the standard
  2031. I/O Addresses where they may be located, initializing, registering, and
  2032. reporting the configuration of each BusLogic Host Adapter it finds. It
  2033. returns the number of BusLogic Host Adapters successfully initialized and
  2034. registered.
  2035. */
  2036. static int __init BusLogic_init(void)
  2037. {
  2038. int BusLogicHostAdapterCount = 0, DriverOptionsIndex = 0, ProbeIndex;
  2039. struct BusLogic_HostAdapter *PrototypeHostAdapter;
  2040. int ret = 0;
  2041. #ifdef MODULE
  2042. if (BusLogic)
  2043. BusLogic_Setup(BusLogic);
  2044. #endif
  2045. if (BusLogic_ProbeOptions.NoProbe)
  2046. return -ENODEV;
  2047. BusLogic_ProbeInfoList =
  2048. kzalloc(BusLogic_MaxHostAdapters * sizeof(struct BusLogic_ProbeInfo), GFP_KERNEL);
  2049. if (BusLogic_ProbeInfoList == NULL) {
  2050. BusLogic_Error("BusLogic: Unable to allocate Probe Info List\n", NULL);
  2051. return -ENOMEM;
  2052. }
  2053. PrototypeHostAdapter =
  2054. kzalloc(sizeof(struct BusLogic_HostAdapter), GFP_KERNEL);
  2055. if (PrototypeHostAdapter == NULL) {
  2056. kfree(BusLogic_ProbeInfoList);
  2057. BusLogic_Error("BusLogic: Unable to allocate Prototype " "Host Adapter\n", NULL);
  2058. return -ENOMEM;
  2059. }
  2060. #ifdef MODULE
  2061. if (BusLogic != NULL)
  2062. BusLogic_Setup(BusLogic);
  2063. #endif
  2064. BusLogic_InitializeProbeInfoList(PrototypeHostAdapter);
  2065. for (ProbeIndex = 0; ProbeIndex < BusLogic_ProbeInfoCount; ProbeIndex++) {
  2066. struct BusLogic_ProbeInfo *ProbeInfo = &BusLogic_ProbeInfoList[ProbeIndex];
  2067. struct BusLogic_HostAdapter *HostAdapter = PrototypeHostAdapter;
  2068. struct Scsi_Host *Host;
  2069. if (ProbeInfo->IO_Address == 0)
  2070. continue;
  2071. memset(HostAdapter, 0, sizeof(struct BusLogic_HostAdapter));
  2072. HostAdapter->HostAdapterType = ProbeInfo->HostAdapterType;
  2073. HostAdapter->HostAdapterBusType = ProbeInfo->HostAdapterBusType;
  2074. HostAdapter->IO_Address = ProbeInfo->IO_Address;
  2075. HostAdapter->PCI_Address = ProbeInfo->PCI_Address;
  2076. HostAdapter->Bus = ProbeInfo->Bus;
  2077. HostAdapter->Device = ProbeInfo->Device;
  2078. HostAdapter->PCI_Device = ProbeInfo->PCI_Device;
  2079. HostAdapter->IRQ_Channel = ProbeInfo->IRQ_Channel;
  2080. HostAdapter->AddressCount = BusLogic_HostAdapterAddressCount[HostAdapter->HostAdapterType];
  2081. /*
  2082. Make sure region is free prior to probing.
  2083. */
  2084. if (!request_region(HostAdapter->IO_Address, HostAdapter->AddressCount,
  2085. "BusLogic"))
  2086. continue;
  2087. /*
  2088. Probe the Host Adapter. If unsuccessful, abort further initialization.
  2089. */
  2090. if (!BusLogic_ProbeHostAdapter(HostAdapter)) {
  2091. release_region(HostAdapter->IO_Address, HostAdapter->AddressCount);
  2092. continue;
  2093. }
  2094. /*
  2095. Hard Reset the Host Adapter. If unsuccessful, abort further
  2096. initialization.
  2097. */
  2098. if (!BusLogic_HardwareResetHostAdapter(HostAdapter, true)) {
  2099. release_region(HostAdapter->IO_Address, HostAdapter->AddressCount);
  2100. continue;
  2101. }
  2102. /*
  2103. Check the Host Adapter. If unsuccessful, abort further initialization.
  2104. */
  2105. if (!BusLogic_CheckHostAdapter(HostAdapter)) {
  2106. release_region(HostAdapter->IO_Address, HostAdapter->AddressCount);
  2107. continue;
  2108. }
  2109. /*
  2110. Initialize the Driver Options field if provided.
  2111. */
  2112. if (DriverOptionsIndex < BusLogic_DriverOptionsCount)
  2113. HostAdapter->DriverOptions = &BusLogic_DriverOptions[DriverOptionsIndex++];
  2114. /*
  2115. Announce the Driver Version and Date, Author's Name, Copyright Notice,
  2116. and Electronic Mail Address.
  2117. */
  2118. BusLogic_AnnounceDriver(HostAdapter);
  2119. /*
  2120. Register the SCSI Host structure.
  2121. */
  2122. Host = scsi_host_alloc(&Bus_Logic_template, sizeof(struct BusLogic_HostAdapter));
  2123. if (Host == NULL) {
  2124. release_region(HostAdapter->IO_Address, HostAdapter->AddressCount);
  2125. continue;
  2126. }
  2127. HostAdapter = (struct BusLogic_HostAdapter *) Host->hostdata;
  2128. memcpy(HostAdapter, PrototypeHostAdapter, sizeof(struct BusLogic_HostAdapter));
  2129. HostAdapter->SCSI_Host = Host;
  2130. HostAdapter->HostNumber = Host->host_no;
  2131. /*
  2132. Add Host Adapter to the end of the list of registered BusLogic
  2133. Host Adapters.
  2134. */
  2135. list_add_tail(&HostAdapter->host_list, &BusLogic_host_list);
  2136. /*
  2137. Read the Host Adapter Configuration, Configure the Host Adapter,
  2138. Acquire the System Resources necessary to use the Host Adapter, then
  2139. Create the Initial CCBs, Initialize the Host Adapter, and finally
  2140. perform Target Device Inquiry.
  2141. From this point onward, any failure will be assumed to be due to a
  2142. problem with the Host Adapter, rather than due to having mistakenly
  2143. identified this port as belonging to a BusLogic Host Adapter. The
  2144. I/O Address range will not be released, thereby preventing it from
  2145. being incorrectly identified as any other type of Host Adapter.
  2146. */
  2147. if (BusLogic_ReadHostAdapterConfiguration(HostAdapter) &&
  2148. BusLogic_ReportHostAdapterConfiguration(HostAdapter) &&
  2149. BusLogic_AcquireResources(HostAdapter) &&
  2150. BusLogic_CreateInitialCCBs(HostAdapter) &&
  2151. BusLogic_InitializeHostAdapter(HostAdapter) &&
  2152. BusLogic_TargetDeviceInquiry(HostAdapter)) {
  2153. /*
  2154. Initialization has been completed successfully. Release and
  2155. re-register usage of the I/O Address range so that the Model
  2156. Name of the Host Adapter will appear, and initialize the SCSI
  2157. Host structure.
  2158. */
  2159. release_region(HostAdapter->IO_Address,
  2160. HostAdapter->AddressCount);
  2161. if (!request_region(HostAdapter->IO_Address,
  2162. HostAdapter->AddressCount,
  2163. HostAdapter->FullModelName)) {
  2164. printk(KERN_WARNING
  2165. "BusLogic: Release and re-register of "
  2166. "port 0x%04lx failed \n",
  2167. (unsigned long)HostAdapter->IO_Address);
  2168. BusLogic_DestroyCCBs(HostAdapter);
  2169. BusLogic_ReleaseResources(HostAdapter);
  2170. list_del(&HostAdapter->host_list);
  2171. scsi_host_put(Host);
  2172. ret = -ENOMEM;
  2173. } else {
  2174. BusLogic_InitializeHostStructure(HostAdapter,
  2175. Host);
  2176. if (scsi_add_host(Host, HostAdapter->PCI_Device
  2177. ? &HostAdapter->PCI_Device->dev
  2178. : NULL)) {
  2179. printk(KERN_WARNING
  2180. "BusLogic: scsi_add_host()"
  2181. "failed!\n");
  2182. BusLogic_DestroyCCBs(HostAdapter);
  2183. BusLogic_ReleaseResources(HostAdapter);
  2184. list_del(&HostAdapter->host_list);
  2185. scsi_host_put(Host);
  2186. ret = -ENODEV;
  2187. } else {
  2188. scsi_scan_host(Host);
  2189. BusLogicHostAdapterCount++;
  2190. }
  2191. }
  2192. } else {
  2193. /*
  2194. An error occurred during Host Adapter Configuration Querying, Host
  2195. Adapter Configuration, Resource Acquisition, CCB Creation, Host
  2196. Adapter Initialization, or Target Device Inquiry, so remove Host
  2197. Adapter from the list of registered BusLogic Host Adapters, destroy
  2198. the CCBs, Release the System Resources, and Unregister the SCSI
  2199. Host.
  2200. */
  2201. BusLogic_DestroyCCBs(HostAdapter);
  2202. BusLogic_ReleaseResources(HostAdapter);
  2203. list_del(&HostAdapter->host_list);
  2204. scsi_host_put(Host);
  2205. ret = -ENODEV;
  2206. }
  2207. }
  2208. kfree(PrototypeHostAdapter);
  2209. kfree(BusLogic_ProbeInfoList);
  2210. BusLogic_ProbeInfoList = NULL;
  2211. return ret;
  2212. }
  2213. /*
  2214. BusLogic_ReleaseHostAdapter releases all resources previously acquired to
  2215. support a specific Host Adapter, including the I/O Address range, and
  2216. unregisters the BusLogic Host Adapter.
  2217. */
  2218. static int __exit BusLogic_ReleaseHostAdapter(struct BusLogic_HostAdapter *HostAdapter)
  2219. {
  2220. struct Scsi_Host *Host = HostAdapter->SCSI_Host;
  2221. scsi_remove_host(Host);
  2222. /*
  2223. FlashPoint Host Adapters must first be released by the FlashPoint
  2224. SCCB Manager.
  2225. */
  2226. if (BusLogic_FlashPointHostAdapterP(HostAdapter))
  2227. FlashPoint_ReleaseHostAdapter(HostAdapter->CardHandle);
  2228. /*
  2229. Destroy the CCBs and release any system resources acquired to
  2230. support Host Adapter.
  2231. */
  2232. BusLogic_DestroyCCBs(HostAdapter);
  2233. BusLogic_ReleaseResources(HostAdapter);
  2234. /*
  2235. Release usage of the I/O Address range.
  2236. */
  2237. release_region(HostAdapter->IO_Address, HostAdapter->AddressCount);
  2238. /*
  2239. Remove Host Adapter from the list of registered BusLogic Host Adapters.
  2240. */
  2241. list_del(&HostAdapter->host_list);
  2242. scsi_host_put(Host);
  2243. return 0;
  2244. }
  2245. /*
  2246. BusLogic_QueueCompletedCCB queues CCB for completion processing.
  2247. */
  2248. static void BusLogic_QueueCompletedCCB(struct BusLogic_CCB *CCB)
  2249. {
  2250. struct BusLogic_HostAdapter *HostAdapter = CCB->HostAdapter;
  2251. CCB->Status = BusLogic_CCB_Completed;
  2252. CCB->Next = NULL;
  2253. if (HostAdapter->FirstCompletedCCB == NULL) {
  2254. HostAdapter->FirstCompletedCCB = CCB;
  2255. HostAdapter->LastCompletedCCB = CCB;
  2256. } else {
  2257. HostAdapter->LastCompletedCCB->Next = CCB;
  2258. HostAdapter->LastCompletedCCB = CCB;
  2259. }
  2260. HostAdapter->ActiveCommands[CCB->TargetID]--;
  2261. }
  2262. /*
  2263. BusLogic_ComputeResultCode computes a SCSI Subsystem Result Code from
  2264. the Host Adapter Status and Target Device Status.
  2265. */
  2266. static int BusLogic_ComputeResultCode(struct BusLogic_HostAdapter *HostAdapter, enum BusLogic_HostAdapterStatus HostAdapterStatus, enum BusLogic_TargetDeviceStatus TargetDeviceStatus)
  2267. {
  2268. int HostStatus;
  2269. switch (HostAdapterStatus) {
  2270. case BusLogic_CommandCompletedNormally:
  2271. case BusLogic_LinkedCommandCompleted:
  2272. case BusLogic_LinkedCommandCompletedWithFlag:
  2273. HostStatus = DID_OK;
  2274. break;
  2275. case BusLogic_SCSISelectionTimeout:
  2276. HostStatus = DID_TIME_OUT;
  2277. break;
  2278. case BusLogic_InvalidOutgoingMailboxActionCode:
  2279. case BusLogic_InvalidCommandOperationCode:
  2280. case BusLogic_InvalidCommandParameter:
  2281. BusLogic_Warning("BusLogic Driver Protocol Error 0x%02X\n", HostAdapter, HostAdapterStatus);
  2282. case BusLogic_DataUnderRun:
  2283. case BusLogic_DataOverRun:
  2284. case BusLogic_UnexpectedBusFree:
  2285. case BusLogic_LinkedCCBhasInvalidLUN:
  2286. case BusLogic_AutoRequestSenseFailed:
  2287. case BusLogic_TaggedQueuingMessageRejected:
  2288. case BusLogic_UnsupportedMessageReceived:
  2289. case BusLogic_HostAdapterHardwareFailed:
  2290. case BusLogic_TargetDeviceReconnectedImproperly:
  2291. case BusLogic_AbortQueueGenerated:
  2292. case BusLogic_HostAdapterSoftwareError:
  2293. case BusLogic_HostAdapterHardwareTimeoutError:
  2294. case BusLogic_SCSIParityErrorDetected:
  2295. HostStatus = DID_ERROR;
  2296. break;
  2297. case BusLogic_InvalidBusPhaseRequested:
  2298. case BusLogic_TargetFailedResponseToATN:
  2299. case BusLogic_HostAdapterAssertedRST:
  2300. case BusLogic_OtherDeviceAssertedRST:
  2301. case BusLogic_HostAdapterAssertedBusDeviceReset:
  2302. HostStatus = DID_RESET;
  2303. break;
  2304. default:
  2305. BusLogic_Warning("Unknown Host Adapter Status 0x%02X\n", HostAdapter, HostAdapterStatus);
  2306. HostStatus = DID_ERROR;
  2307. break;
  2308. }
  2309. return (HostStatus << 16) | TargetDeviceStatus;
  2310. }
  2311. /*
  2312. BusLogic_ScanIncomingMailboxes scans the Incoming Mailboxes saving any
  2313. Incoming Mailbox entries for completion processing.
  2314. */
  2315. static void BusLogic_ScanIncomingMailboxes(struct BusLogic_HostAdapter *HostAdapter)
  2316. {
  2317. /*
  2318. Scan through the Incoming Mailboxes in Strict Round Robin fashion, saving
  2319. any completed CCBs for further processing. It is essential that for each
  2320. CCB and SCSI Command issued, command completion processing is performed
  2321. exactly once. Therefore, only Incoming Mailboxes with completion code
  2322. Command Completed Without Error, Command Completed With Error, or Command
  2323. Aborted At Host Request are saved for completion processing. When an
  2324. Incoming Mailbox has a completion code of Aborted Command Not Found, the
  2325. CCB had already completed or been aborted before the current Abort request
  2326. was processed, and so completion processing has already occurred and no
  2327. further action should be taken.
  2328. */
  2329. struct BusLogic_IncomingMailbox *NextIncomingMailbox = HostAdapter->NextIncomingMailbox;
  2330. enum BusLogic_CompletionCode CompletionCode;
  2331. while ((CompletionCode = NextIncomingMailbox->CompletionCode) != BusLogic_IncomingMailboxFree) {
  2332. /*
  2333. We are only allowed to do this because we limit our architectures we
  2334. run on to machines where bus_to_virt() actually works. There *needs*
  2335. to be a dma_addr_to_virt() in the new PCI DMA mapping interface to
  2336. replace bus_to_virt() or else this code is going to become very
  2337. innefficient.
  2338. */
  2339. struct BusLogic_CCB *CCB = (struct BusLogic_CCB *) Bus_to_Virtual(NextIncomingMailbox->CCB);
  2340. if (CompletionCode != BusLogic_AbortedCommandNotFound) {
  2341. if (CCB->Status == BusLogic_CCB_Active || CCB->Status == BusLogic_CCB_Reset) {
  2342. /*
  2343. Save the Completion Code for this CCB and queue the CCB
  2344. for completion processing.
  2345. */
  2346. CCB->CompletionCode = CompletionCode;
  2347. BusLogic_QueueCompletedCCB(CCB);
  2348. } else {
  2349. /*
  2350. If a CCB ever appears in an Incoming Mailbox and is not marked
  2351. as status Active or Reset, then there is most likely a bug in
  2352. the Host Adapter firmware.
  2353. */
  2354. BusLogic_Warning("Illegal CCB #%ld status %d in " "Incoming Mailbox\n", HostAdapter, CCB->SerialNumber, CCB->Status);
  2355. }
  2356. }
  2357. NextIncomingMailbox->CompletionCode = BusLogic_IncomingMailboxFree;
  2358. if (++NextIncomingMailbox > HostAdapter->LastIncomingMailbox)
  2359. NextIncomingMailbox = HostAdapter->FirstIncomingMailbox;
  2360. }
  2361. HostAdapter->NextIncomingMailbox = NextIncomingMailbox;
  2362. }
  2363. /*
  2364. BusLogic_ProcessCompletedCCBs iterates over the completed CCBs for Host
  2365. Adapter setting the SCSI Command Result Codes, deallocating the CCBs, and
  2366. calling the SCSI Subsystem Completion Routines. The Host Adapter's Lock
  2367. should already have been acquired by the caller.
  2368. */
  2369. static void BusLogic_ProcessCompletedCCBs(struct BusLogic_HostAdapter *HostAdapter)
  2370. {
  2371. if (HostAdapter->ProcessCompletedCCBsActive)
  2372. return;
  2373. HostAdapter->ProcessCompletedCCBsActive = true;
  2374. while (HostAdapter->FirstCompletedCCB != NULL) {
  2375. struct BusLogic_CCB *CCB = HostAdapter->FirstCompletedCCB;
  2376. struct scsi_cmnd *Command = CCB->Command;
  2377. HostAdapter->FirstCompletedCCB = CCB->Next;
  2378. if (HostAdapter->FirstCompletedCCB == NULL)
  2379. HostAdapter->LastCompletedCCB = NULL;
  2380. /*
  2381. Process the Completed CCB.
  2382. */
  2383. if (CCB->Opcode == BusLogic_BusDeviceReset) {
  2384. int TargetID = CCB->TargetID;
  2385. BusLogic_Warning("Bus Device Reset CCB #%ld to Target " "%d Completed\n", HostAdapter, CCB->SerialNumber, TargetID);
  2386. BusLogic_IncrementErrorCounter(&HostAdapter->TargetStatistics[TargetID].BusDeviceResetsCompleted);
  2387. HostAdapter->TargetFlags[TargetID].TaggedQueuingActive = false;
  2388. HostAdapter->CommandsSinceReset[TargetID] = 0;
  2389. HostAdapter->LastResetCompleted[TargetID] = jiffies;
  2390. /*
  2391. Place CCB back on the Host Adapter's free list.
  2392. */
  2393. BusLogic_DeallocateCCB(CCB);
  2394. #if 0 /* this needs to be redone different for new EH */
  2395. /*
  2396. Bus Device Reset CCBs have the Command field non-NULL only when a
  2397. Bus Device Reset was requested for a Command that did not have a
  2398. currently active CCB in the Host Adapter (i.e., a Synchronous
  2399. Bus Device Reset), and hence would not have its Completion Routine
  2400. called otherwise.
  2401. */
  2402. while (Command != NULL) {
  2403. struct scsi_cmnd *NextCommand = Command->reset_chain;
  2404. Command->reset_chain = NULL;
  2405. Command->result = DID_RESET << 16;
  2406. Command->scsi_done(Command);
  2407. Command = NextCommand;
  2408. }
  2409. #endif
  2410. /*
  2411. Iterate over the CCBs for this Host Adapter performing completion
  2412. processing for any CCBs marked as Reset for this Target.
  2413. */
  2414. for (CCB = HostAdapter->All_CCBs; CCB != NULL; CCB = CCB->NextAll)
  2415. if (CCB->Status == BusLogic_CCB_Reset && CCB->TargetID == TargetID) {
  2416. Command = CCB->Command;
  2417. BusLogic_DeallocateCCB(CCB);
  2418. HostAdapter->ActiveCommands[TargetID]--;
  2419. Command->result = DID_RESET << 16;
  2420. Command->scsi_done(Command);
  2421. }
  2422. HostAdapter->BusDeviceResetPendingCCB[TargetID] = NULL;
  2423. } else {
  2424. /*
  2425. Translate the Completion Code, Host Adapter Status, and Target
  2426. Device Status into a SCSI Subsystem Result Code.
  2427. */
  2428. switch (CCB->CompletionCode) {
  2429. case BusLogic_IncomingMailboxFree:
  2430. case BusLogic_AbortedCommandNotFound:
  2431. case BusLogic_InvalidCCB:
  2432. BusLogic_Warning("CCB #%ld to Target %d Impossible State\n", HostAdapter, CCB->SerialNumber, CCB->TargetID);
  2433. break;
  2434. case BusLogic_CommandCompletedWithoutError:
  2435. HostAdapter->TargetStatistics[CCB->TargetID]
  2436. .CommandsCompleted++;
  2437. HostAdapter->TargetFlags[CCB->TargetID]
  2438. .CommandSuccessfulFlag = true;
  2439. Command->result = DID_OK << 16;
  2440. break;
  2441. case BusLogic_CommandAbortedAtHostRequest:
  2442. BusLogic_Warning("CCB #%ld to Target %d Aborted\n", HostAdapter, CCB->SerialNumber, CCB->TargetID);
  2443. BusLogic_IncrementErrorCounter(&HostAdapter->TargetStatistics[CCB->TargetID]
  2444. .CommandAbortsCompleted);
  2445. Command->result = DID_ABORT << 16;
  2446. break;
  2447. case BusLogic_CommandCompletedWithError:
  2448. Command->result = BusLogic_ComputeResultCode(HostAdapter, CCB->HostAdapterStatus, CCB->TargetDeviceStatus);
  2449. if (CCB->HostAdapterStatus != BusLogic_SCSISelectionTimeout) {
  2450. HostAdapter->TargetStatistics[CCB->TargetID]
  2451. .CommandsCompleted++;
  2452. if (BusLogic_GlobalOptions.TraceErrors) {
  2453. int i;
  2454. BusLogic_Notice("CCB #%ld Target %d: Result %X Host "
  2455. "Adapter Status %02X " "Target Status %02X\n", HostAdapter, CCB->SerialNumber, CCB->TargetID, Command->result, CCB->HostAdapterStatus, CCB->TargetDeviceStatus);
  2456. BusLogic_Notice("CDB ", HostAdapter);
  2457. for (i = 0; i < CCB->CDB_Length; i++)
  2458. BusLogic_Notice(" %02X", HostAdapter, CCB->CDB[i]);
  2459. BusLogic_Notice("\n", HostAdapter);
  2460. BusLogic_Notice("Sense ", HostAdapter);
  2461. for (i = 0; i < CCB->SenseDataLength; i++)
  2462. BusLogic_Notice(" %02X", HostAdapter, Command->sense_buffer[i]);
  2463. BusLogic_Notice("\n", HostAdapter);
  2464. }
  2465. }
  2466. break;
  2467. }
  2468. /*
  2469. When an INQUIRY command completes normally, save the
  2470. CmdQue (Tagged Queuing Supported) and WBus16 (16 Bit
  2471. Wide Data Transfers Supported) bits.
  2472. */
  2473. if (CCB->CDB[0] == INQUIRY && CCB->CDB[1] == 0 && CCB->HostAdapterStatus == BusLogic_CommandCompletedNormally) {
  2474. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[CCB->TargetID];
  2475. struct SCSI_Inquiry *InquiryResult =
  2476. (struct SCSI_Inquiry *) scsi_sglist(Command);
  2477. TargetFlags->TargetExists = true;
  2478. TargetFlags->TaggedQueuingSupported = InquiryResult->CmdQue;
  2479. TargetFlags->WideTransfersSupported = InquiryResult->WBus16;
  2480. }
  2481. /*
  2482. Place CCB back on the Host Adapter's free list.
  2483. */
  2484. BusLogic_DeallocateCCB(CCB);
  2485. /*
  2486. Call the SCSI Command Completion Routine.
  2487. */
  2488. Command->scsi_done(Command);
  2489. }
  2490. }
  2491. HostAdapter->ProcessCompletedCCBsActive = false;
  2492. }
  2493. /*
  2494. BusLogic_InterruptHandler handles hardware interrupts from BusLogic Host
  2495. Adapters.
  2496. */
  2497. static irqreturn_t BusLogic_InterruptHandler(int IRQ_Channel, void *DeviceIdentifier)
  2498. {
  2499. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) DeviceIdentifier;
  2500. unsigned long ProcessorFlags;
  2501. /*
  2502. Acquire exclusive access to Host Adapter.
  2503. */
  2504. spin_lock_irqsave(HostAdapter->SCSI_Host->host_lock, ProcessorFlags);
  2505. /*
  2506. Handle Interrupts appropriately for each Host Adapter type.
  2507. */
  2508. if (BusLogic_MultiMasterHostAdapterP(HostAdapter)) {
  2509. union BusLogic_InterruptRegister InterruptRegister;
  2510. /*
  2511. Read the Host Adapter Interrupt Register.
  2512. */
  2513. InterruptRegister.All = BusLogic_ReadInterruptRegister(HostAdapter);
  2514. if (InterruptRegister.ir.InterruptValid) {
  2515. /*
  2516. Acknowledge the interrupt and reset the Host Adapter
  2517. Interrupt Register.
  2518. */
  2519. BusLogic_InterruptReset(HostAdapter);
  2520. /*
  2521. Process valid External SCSI Bus Reset and Incoming Mailbox
  2522. Loaded Interrupts. Command Complete Interrupts are noted,
  2523. and Outgoing Mailbox Available Interrupts are ignored, as
  2524. they are never enabled.
  2525. */
  2526. if (InterruptRegister.ir.ExternalBusReset)
  2527. HostAdapter->HostAdapterExternalReset = true;
  2528. else if (InterruptRegister.ir.IncomingMailboxLoaded)
  2529. BusLogic_ScanIncomingMailboxes(HostAdapter);
  2530. else if (InterruptRegister.ir.CommandComplete)
  2531. HostAdapter->HostAdapterCommandCompleted = true;
  2532. }
  2533. } else {
  2534. /*
  2535. Check if there is a pending interrupt for this Host Adapter.
  2536. */
  2537. if (FlashPoint_InterruptPending(HostAdapter->CardHandle))
  2538. switch (FlashPoint_HandleInterrupt(HostAdapter->CardHandle)) {
  2539. case FlashPoint_NormalInterrupt:
  2540. break;
  2541. case FlashPoint_ExternalBusReset:
  2542. HostAdapter->HostAdapterExternalReset = true;
  2543. break;
  2544. case FlashPoint_InternalError:
  2545. BusLogic_Warning("Internal FlashPoint Error detected" " - Resetting Host Adapter\n", HostAdapter);
  2546. HostAdapter->HostAdapterInternalError = true;
  2547. break;
  2548. }
  2549. }
  2550. /*
  2551. Process any completed CCBs.
  2552. */
  2553. if (HostAdapter->FirstCompletedCCB != NULL)
  2554. BusLogic_ProcessCompletedCCBs(HostAdapter);
  2555. /*
  2556. Reset the Host Adapter if requested.
  2557. */
  2558. if (HostAdapter->HostAdapterExternalReset) {
  2559. BusLogic_Warning("Resetting %s due to External SCSI Bus Reset\n", HostAdapter, HostAdapter->FullModelName);
  2560. BusLogic_IncrementErrorCounter(&HostAdapter->ExternalHostAdapterResets);
  2561. BusLogic_ResetHostAdapter(HostAdapter, false);
  2562. HostAdapter->HostAdapterExternalReset = false;
  2563. } else if (HostAdapter->HostAdapterInternalError) {
  2564. BusLogic_Warning("Resetting %s due to Host Adapter Internal Error\n", HostAdapter, HostAdapter->FullModelName);
  2565. BusLogic_IncrementErrorCounter(&HostAdapter->HostAdapterInternalErrors);
  2566. BusLogic_ResetHostAdapter(HostAdapter, true);
  2567. HostAdapter->HostAdapterInternalError = false;
  2568. }
  2569. /*
  2570. Release exclusive access to Host Adapter.
  2571. */
  2572. spin_unlock_irqrestore(HostAdapter->SCSI_Host->host_lock, ProcessorFlags);
  2573. return IRQ_HANDLED;
  2574. }
  2575. /*
  2576. BusLogic_WriteOutgoingMailbox places CCB and Action Code into an Outgoing
  2577. Mailbox for execution by Host Adapter. The Host Adapter's Lock should
  2578. already have been acquired by the caller.
  2579. */
  2580. static bool BusLogic_WriteOutgoingMailbox(struct BusLogic_HostAdapter
  2581. *HostAdapter, enum BusLogic_ActionCode ActionCode, struct BusLogic_CCB *CCB)
  2582. {
  2583. struct BusLogic_OutgoingMailbox *NextOutgoingMailbox;
  2584. NextOutgoingMailbox = HostAdapter->NextOutgoingMailbox;
  2585. if (NextOutgoingMailbox->ActionCode == BusLogic_OutgoingMailboxFree) {
  2586. CCB->Status = BusLogic_CCB_Active;
  2587. /*
  2588. The CCB field must be written before the Action Code field since
  2589. the Host Adapter is operating asynchronously and the locking code
  2590. does not protect against simultaneous access by the Host Adapter.
  2591. */
  2592. NextOutgoingMailbox->CCB = CCB->DMA_Handle;
  2593. NextOutgoingMailbox->ActionCode = ActionCode;
  2594. BusLogic_StartMailboxCommand(HostAdapter);
  2595. if (++NextOutgoingMailbox > HostAdapter->LastOutgoingMailbox)
  2596. NextOutgoingMailbox = HostAdapter->FirstOutgoingMailbox;
  2597. HostAdapter->NextOutgoingMailbox = NextOutgoingMailbox;
  2598. if (ActionCode == BusLogic_MailboxStartCommand) {
  2599. HostAdapter->ActiveCommands[CCB->TargetID]++;
  2600. if (CCB->Opcode != BusLogic_BusDeviceReset)
  2601. HostAdapter->TargetStatistics[CCB->TargetID].CommandsAttempted++;
  2602. }
  2603. return true;
  2604. }
  2605. return false;
  2606. }
  2607. /* Error Handling (EH) support */
  2608. static int BusLogic_host_reset(struct scsi_cmnd * SCpnt)
  2609. {
  2610. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) SCpnt->device->host->hostdata;
  2611. unsigned int id = SCpnt->device->id;
  2612. struct BusLogic_TargetStatistics *stats = &HostAdapter->TargetStatistics[id];
  2613. int rc;
  2614. spin_lock_irq(SCpnt->device->host->host_lock);
  2615. BusLogic_IncrementErrorCounter(&stats->HostAdapterResetsRequested);
  2616. rc = BusLogic_ResetHostAdapter(HostAdapter, false);
  2617. spin_unlock_irq(SCpnt->device->host->host_lock);
  2618. return rc;
  2619. }
  2620. /*
  2621. BusLogic_QueueCommand creates a CCB for Command and places it into an
  2622. Outgoing Mailbox for execution by the associated Host Adapter.
  2623. */
  2624. static int BusLogic_QueueCommand_lck(struct scsi_cmnd *Command, void (*CompletionRoutine) (struct scsi_cmnd *))
  2625. {
  2626. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) Command->device->host->hostdata;
  2627. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[Command->device->id];
  2628. struct BusLogic_TargetStatistics *TargetStatistics = HostAdapter->TargetStatistics;
  2629. unsigned char *CDB = Command->cmnd;
  2630. int CDB_Length = Command->cmd_len;
  2631. int TargetID = Command->device->id;
  2632. int LogicalUnit = Command->device->lun;
  2633. int BufferLength = scsi_bufflen(Command);
  2634. int Count;
  2635. struct BusLogic_CCB *CCB;
  2636. /*
  2637. SCSI REQUEST_SENSE commands will be executed automatically by the Host
  2638. Adapter for any errors, so they should not be executed explicitly unless
  2639. the Sense Data is zero indicating that no error occurred.
  2640. */
  2641. if (CDB[0] == REQUEST_SENSE && Command->sense_buffer[0] != 0) {
  2642. Command->result = DID_OK << 16;
  2643. CompletionRoutine(Command);
  2644. return 0;
  2645. }
  2646. /*
  2647. Allocate a CCB from the Host Adapter's free list. In the unlikely event
  2648. that there are none available and memory allocation fails, wait 1 second
  2649. and try again. If that fails, the Host Adapter is probably hung so signal
  2650. an error as a Host Adapter Hard Reset should be initiated soon.
  2651. */
  2652. CCB = BusLogic_AllocateCCB(HostAdapter);
  2653. if (CCB == NULL) {
  2654. spin_unlock_irq(HostAdapter->SCSI_Host->host_lock);
  2655. BusLogic_Delay(1);
  2656. spin_lock_irq(HostAdapter->SCSI_Host->host_lock);
  2657. CCB = BusLogic_AllocateCCB(HostAdapter);
  2658. if (CCB == NULL) {
  2659. Command->result = DID_ERROR << 16;
  2660. CompletionRoutine(Command);
  2661. return 0;
  2662. }
  2663. }
  2664. /*
  2665. Initialize the fields in the BusLogic Command Control Block (CCB).
  2666. */
  2667. Count = scsi_dma_map(Command);
  2668. BUG_ON(Count < 0);
  2669. if (Count) {
  2670. struct scatterlist *sg;
  2671. int i;
  2672. CCB->Opcode = BusLogic_InitiatorCCB_ScatterGather;
  2673. CCB->DataLength = Count * sizeof(struct BusLogic_ScatterGatherSegment);
  2674. if (BusLogic_MultiMasterHostAdapterP(HostAdapter))
  2675. CCB->DataPointer = (unsigned int) CCB->DMA_Handle + ((unsigned long) &CCB->ScatterGatherList - (unsigned long) CCB);
  2676. else
  2677. CCB->DataPointer = Virtual_to_32Bit_Virtual(CCB->ScatterGatherList);
  2678. scsi_for_each_sg(Command, sg, Count, i) {
  2679. CCB->ScatterGatherList[i].SegmentByteCount =
  2680. sg_dma_len(sg);
  2681. CCB->ScatterGatherList[i].SegmentDataPointer =
  2682. sg_dma_address(sg);
  2683. }
  2684. } else if (!Count) {
  2685. CCB->Opcode = BusLogic_InitiatorCCB;
  2686. CCB->DataLength = BufferLength;
  2687. CCB->DataPointer = 0;
  2688. }
  2689. switch (CDB[0]) {
  2690. case READ_6:
  2691. case READ_10:
  2692. CCB->DataDirection = BusLogic_DataInLengthChecked;
  2693. TargetStatistics[TargetID].ReadCommands++;
  2694. BusLogic_IncrementByteCounter(&TargetStatistics[TargetID].TotalBytesRead, BufferLength);
  2695. BusLogic_IncrementSizeBucket(TargetStatistics[TargetID].ReadCommandSizeBuckets, BufferLength);
  2696. break;
  2697. case WRITE_6:
  2698. case WRITE_10:
  2699. CCB->DataDirection = BusLogic_DataOutLengthChecked;
  2700. TargetStatistics[TargetID].WriteCommands++;
  2701. BusLogic_IncrementByteCounter(&TargetStatistics[TargetID].TotalBytesWritten, BufferLength);
  2702. BusLogic_IncrementSizeBucket(TargetStatistics[TargetID].WriteCommandSizeBuckets, BufferLength);
  2703. break;
  2704. default:
  2705. CCB->DataDirection = BusLogic_UncheckedDataTransfer;
  2706. break;
  2707. }
  2708. CCB->CDB_Length = CDB_Length;
  2709. CCB->HostAdapterStatus = 0;
  2710. CCB->TargetDeviceStatus = 0;
  2711. CCB->TargetID = TargetID;
  2712. CCB->LogicalUnit = LogicalUnit;
  2713. CCB->TagEnable = false;
  2714. CCB->LegacyTagEnable = false;
  2715. /*
  2716. BusLogic recommends that after a Reset the first couple of commands that
  2717. are sent to a Target Device be sent in a non Tagged Queue fashion so that
  2718. the Host Adapter and Target Device can establish Synchronous and Wide
  2719. Transfer before Queue Tag messages can interfere with the Synchronous and
  2720. Wide Negotiation messages. By waiting to enable Tagged Queuing until after
  2721. the first BusLogic_MaxTaggedQueueDepth commands have been queued, it is
  2722. assured that after a Reset any pending commands are requeued before Tagged
  2723. Queuing is enabled and that the Tagged Queuing message will not occur while
  2724. the partition table is being printed. In addition, some devices do not
  2725. properly handle the transition from non-tagged to tagged commands, so it is
  2726. necessary to wait until there are no pending commands for a target device
  2727. before queuing tagged commands.
  2728. */
  2729. if (HostAdapter->CommandsSinceReset[TargetID]++ >=
  2730. BusLogic_MaxTaggedQueueDepth && !TargetFlags->TaggedQueuingActive && HostAdapter->ActiveCommands[TargetID] == 0 && TargetFlags->TaggedQueuingSupported && (HostAdapter->TaggedQueuingPermitted & (1 << TargetID))) {
  2731. TargetFlags->TaggedQueuingActive = true;
  2732. BusLogic_Notice("Tagged Queuing now active for Target %d\n", HostAdapter, TargetID);
  2733. }
  2734. if (TargetFlags->TaggedQueuingActive) {
  2735. enum BusLogic_QueueTag QueueTag = BusLogic_SimpleQueueTag;
  2736. /*
  2737. When using Tagged Queuing with Simple Queue Tags, it appears that disk
  2738. drive controllers do not guarantee that a queued command will not
  2739. remain in a disconnected state indefinitely if commands that read or
  2740. write nearer the head position continue to arrive without interruption.
  2741. Therefore, for each Target Device this driver keeps track of the last
  2742. time either the queue was empty or an Ordered Queue Tag was issued. If
  2743. more than 4 seconds (one fifth of the 20 second disk timeout) have
  2744. elapsed since this last sequence point, this command will be issued
  2745. with an Ordered Queue Tag rather than a Simple Queue Tag, which forces
  2746. the Target Device to complete all previously queued commands before
  2747. this command may be executed.
  2748. */
  2749. if (HostAdapter->ActiveCommands[TargetID] == 0)
  2750. HostAdapter->LastSequencePoint[TargetID] = jiffies;
  2751. else if (time_after(jiffies, HostAdapter->LastSequencePoint[TargetID] + 4 * HZ)) {
  2752. HostAdapter->LastSequencePoint[TargetID] = jiffies;
  2753. QueueTag = BusLogic_OrderedQueueTag;
  2754. }
  2755. if (HostAdapter->ExtendedLUNSupport) {
  2756. CCB->TagEnable = true;
  2757. CCB->QueueTag = QueueTag;
  2758. } else {
  2759. CCB->LegacyTagEnable = true;
  2760. CCB->LegacyQueueTag = QueueTag;
  2761. }
  2762. }
  2763. memcpy(CCB->CDB, CDB, CDB_Length);
  2764. CCB->SenseDataLength = SCSI_SENSE_BUFFERSIZE;
  2765. CCB->SenseDataPointer = pci_map_single(HostAdapter->PCI_Device, Command->sense_buffer, CCB->SenseDataLength, PCI_DMA_FROMDEVICE);
  2766. CCB->Command = Command;
  2767. Command->scsi_done = CompletionRoutine;
  2768. if (BusLogic_MultiMasterHostAdapterP(HostAdapter)) {
  2769. /*
  2770. Place the CCB in an Outgoing Mailbox. The higher levels of the SCSI
  2771. Subsystem should not attempt to queue more commands than can be placed
  2772. in Outgoing Mailboxes, so there should always be one free. In the
  2773. unlikely event that there are none available, wait 1 second and try
  2774. again. If that fails, the Host Adapter is probably hung so signal an
  2775. error as a Host Adapter Hard Reset should be initiated soon.
  2776. */
  2777. if (!BusLogic_WriteOutgoingMailbox(HostAdapter, BusLogic_MailboxStartCommand, CCB)) {
  2778. spin_unlock_irq(HostAdapter->SCSI_Host->host_lock);
  2779. BusLogic_Warning("Unable to write Outgoing Mailbox - " "Pausing for 1 second\n", HostAdapter);
  2780. BusLogic_Delay(1);
  2781. spin_lock_irq(HostAdapter->SCSI_Host->host_lock);
  2782. if (!BusLogic_WriteOutgoingMailbox(HostAdapter, BusLogic_MailboxStartCommand, CCB)) {
  2783. BusLogic_Warning("Still unable to write Outgoing Mailbox - " "Host Adapter Dead?\n", HostAdapter);
  2784. BusLogic_DeallocateCCB(CCB);
  2785. Command->result = DID_ERROR << 16;
  2786. Command->scsi_done(Command);
  2787. }
  2788. }
  2789. } else {
  2790. /*
  2791. Call the FlashPoint SCCB Manager to start execution of the CCB.
  2792. */
  2793. CCB->Status = BusLogic_CCB_Active;
  2794. HostAdapter->ActiveCommands[TargetID]++;
  2795. TargetStatistics[TargetID].CommandsAttempted++;
  2796. FlashPoint_StartCCB(HostAdapter->CardHandle, CCB);
  2797. /*
  2798. The Command may have already completed and BusLogic_QueueCompletedCCB
  2799. been called, or it may still be pending.
  2800. */
  2801. if (CCB->Status == BusLogic_CCB_Completed)
  2802. BusLogic_ProcessCompletedCCBs(HostAdapter);
  2803. }
  2804. return 0;
  2805. }
  2806. static DEF_SCSI_QCMD(BusLogic_QueueCommand)
  2807. #if 0
  2808. /*
  2809. BusLogic_AbortCommand aborts Command if possible.
  2810. */
  2811. static int BusLogic_AbortCommand(struct scsi_cmnd *Command)
  2812. {
  2813. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) Command->device->host->hostdata;
  2814. int TargetID = Command->device->id;
  2815. struct BusLogic_CCB *CCB;
  2816. BusLogic_IncrementErrorCounter(&HostAdapter->TargetStatistics[TargetID].CommandAbortsRequested);
  2817. /*
  2818. Attempt to find an Active CCB for this Command. If no Active CCB for this
  2819. Command is found, then no Abort is necessary.
  2820. */
  2821. for (CCB = HostAdapter->All_CCBs; CCB != NULL; CCB = CCB->NextAll)
  2822. if (CCB->Command == Command)
  2823. break;
  2824. if (CCB == NULL) {
  2825. BusLogic_Warning("Unable to Abort Command to Target %d - " "No CCB Found\n", HostAdapter, TargetID);
  2826. return SUCCESS;
  2827. } else if (CCB->Status == BusLogic_CCB_Completed) {
  2828. BusLogic_Warning("Unable to Abort Command to Target %d - " "CCB Completed\n", HostAdapter, TargetID);
  2829. return SUCCESS;
  2830. } else if (CCB->Status == BusLogic_CCB_Reset) {
  2831. BusLogic_Warning("Unable to Abort Command to Target %d - " "CCB Reset\n", HostAdapter, TargetID);
  2832. return SUCCESS;
  2833. }
  2834. if (BusLogic_MultiMasterHostAdapterP(HostAdapter)) {
  2835. /*
  2836. Attempt to Abort this CCB. MultiMaster Firmware versions prior to 5.xx
  2837. do not generate Abort Tag messages, but only generate the non-tagged
  2838. Abort message. Since non-tagged commands are not sent by the Host
  2839. Adapter until the queue of outstanding tagged commands has completed,
  2840. and the Abort message is treated as a non-tagged command, it is
  2841. effectively impossible to abort commands when Tagged Queuing is active.
  2842. Firmware version 5.xx does generate Abort Tag messages, so it is
  2843. possible to abort commands when Tagged Queuing is active.
  2844. */
  2845. if (HostAdapter->TargetFlags[TargetID].TaggedQueuingActive && HostAdapter->FirmwareVersion[0] < '5') {
  2846. BusLogic_Warning("Unable to Abort CCB #%ld to Target %d - " "Abort Tag Not Supported\n", HostAdapter, CCB->SerialNumber, TargetID);
  2847. return FAILURE;
  2848. } else if (BusLogic_WriteOutgoingMailbox(HostAdapter, BusLogic_MailboxAbortCommand, CCB)) {
  2849. BusLogic_Warning("Aborting CCB #%ld to Target %d\n", HostAdapter, CCB->SerialNumber, TargetID);
  2850. BusLogic_IncrementErrorCounter(&HostAdapter->TargetStatistics[TargetID].CommandAbortsAttempted);
  2851. return SUCCESS;
  2852. } else {
  2853. BusLogic_Warning("Unable to Abort CCB #%ld to Target %d - " "No Outgoing Mailboxes\n", HostAdapter, CCB->SerialNumber, TargetID);
  2854. return FAILURE;
  2855. }
  2856. } else {
  2857. /*
  2858. Call the FlashPoint SCCB Manager to abort execution of the CCB.
  2859. */
  2860. BusLogic_Warning("Aborting CCB #%ld to Target %d\n", HostAdapter, CCB->SerialNumber, TargetID);
  2861. BusLogic_IncrementErrorCounter(&HostAdapter->TargetStatistics[TargetID].CommandAbortsAttempted);
  2862. FlashPoint_AbortCCB(HostAdapter->CardHandle, CCB);
  2863. /*
  2864. The Abort may have already been completed and
  2865. BusLogic_QueueCompletedCCB been called, or it
  2866. may still be pending.
  2867. */
  2868. if (CCB->Status == BusLogic_CCB_Completed) {
  2869. BusLogic_ProcessCompletedCCBs(HostAdapter);
  2870. }
  2871. return SUCCESS;
  2872. }
  2873. return SUCCESS;
  2874. }
  2875. #endif
  2876. /*
  2877. BusLogic_ResetHostAdapter resets Host Adapter if possible, marking all
  2878. currently executing SCSI Commands as having been Reset.
  2879. */
  2880. static int BusLogic_ResetHostAdapter(struct BusLogic_HostAdapter *HostAdapter, bool HardReset)
  2881. {
  2882. struct BusLogic_CCB *CCB;
  2883. int TargetID;
  2884. /*
  2885. * Attempt to Reset and Reinitialize the Host Adapter.
  2886. */
  2887. if (!(BusLogic_HardwareResetHostAdapter(HostAdapter, HardReset) && BusLogic_InitializeHostAdapter(HostAdapter))) {
  2888. BusLogic_Error("Resetting %s Failed\n", HostAdapter, HostAdapter->FullModelName);
  2889. return FAILURE;
  2890. }
  2891. /*
  2892. * Deallocate all currently executing CCBs.
  2893. */
  2894. for (CCB = HostAdapter->All_CCBs; CCB != NULL; CCB = CCB->NextAll)
  2895. if (CCB->Status == BusLogic_CCB_Active)
  2896. BusLogic_DeallocateCCB(CCB);
  2897. /*
  2898. * Wait a few seconds between the Host Adapter Hard Reset which
  2899. * initiates a SCSI Bus Reset and issuing any SCSI Commands. Some
  2900. * SCSI devices get confused if they receive SCSI Commands too soon
  2901. * after a SCSI Bus Reset.
  2902. */
  2903. if (HardReset) {
  2904. spin_unlock_irq(HostAdapter->SCSI_Host->host_lock);
  2905. BusLogic_Delay(HostAdapter->BusSettleTime);
  2906. spin_lock_irq(HostAdapter->SCSI_Host->host_lock);
  2907. }
  2908. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  2909. HostAdapter->LastResetAttempted[TargetID] = jiffies;
  2910. HostAdapter->LastResetCompleted[TargetID] = jiffies;
  2911. }
  2912. return SUCCESS;
  2913. }
  2914. /*
  2915. BusLogic_BIOSDiskParameters returns the Heads/Sectors/Cylinders BIOS Disk
  2916. Parameters for Disk. The default disk geometry is 64 heads, 32 sectors, and
  2917. the appropriate number of cylinders so as not to exceed drive capacity. In
  2918. order for disks equal to or larger than 1 GB to be addressable by the BIOS
  2919. without exceeding the BIOS limitation of 1024 cylinders, Extended Translation
  2920. may be enabled in AutoSCSI on FlashPoint Host Adapters and on "W" and "C"
  2921. series MultiMaster Host Adapters, or by a dip switch setting on "S" and "A"
  2922. series MultiMaster Host Adapters. With Extended Translation enabled, drives
  2923. between 1 GB inclusive and 2 GB exclusive are given a disk geometry of 128
  2924. heads and 32 sectors, and drives above 2 GB inclusive are given a disk
  2925. geometry of 255 heads and 63 sectors. However, if the BIOS detects that the
  2926. Extended Translation setting does not match the geometry in the partition
  2927. table, then the translation inferred from the partition table will be used by
  2928. the BIOS, and a warning may be displayed.
  2929. */
  2930. static int BusLogic_BIOSDiskParameters(struct scsi_device *sdev, struct block_device *Device, sector_t capacity, int *Parameters)
  2931. {
  2932. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) sdev->host->hostdata;
  2933. struct BIOS_DiskParameters *DiskParameters = (struct BIOS_DiskParameters *) Parameters;
  2934. unsigned char *buf;
  2935. if (HostAdapter->ExtendedTranslationEnabled && capacity >= 2 * 1024 * 1024 /* 1 GB in 512 byte sectors */ ) {
  2936. if (capacity >= 4 * 1024 * 1024 /* 2 GB in 512 byte sectors */ ) {
  2937. DiskParameters->Heads = 255;
  2938. DiskParameters->Sectors = 63;
  2939. } else {
  2940. DiskParameters->Heads = 128;
  2941. DiskParameters->Sectors = 32;
  2942. }
  2943. } else {
  2944. DiskParameters->Heads = 64;
  2945. DiskParameters->Sectors = 32;
  2946. }
  2947. DiskParameters->Cylinders = (unsigned long) capacity / (DiskParameters->Heads * DiskParameters->Sectors);
  2948. buf = scsi_bios_ptable(Device);
  2949. if (buf == NULL)
  2950. return 0;
  2951. /*
  2952. If the boot sector partition table flag is valid, search for a partition
  2953. table entry whose end_head matches one of the standard BusLogic geometry
  2954. translations (64/32, 128/32, or 255/63).
  2955. */
  2956. if (*(unsigned short *) (buf + 64) == 0xAA55) {
  2957. struct partition *FirstPartitionEntry = (struct partition *) buf;
  2958. struct partition *PartitionEntry = FirstPartitionEntry;
  2959. int SavedCylinders = DiskParameters->Cylinders, PartitionNumber;
  2960. unsigned char PartitionEntryEndHead = 0, PartitionEntryEndSector = 0;
  2961. for (PartitionNumber = 0; PartitionNumber < 4; PartitionNumber++) {
  2962. PartitionEntryEndHead = PartitionEntry->end_head;
  2963. PartitionEntryEndSector = PartitionEntry->end_sector & 0x3F;
  2964. if (PartitionEntryEndHead == 64 - 1) {
  2965. DiskParameters->Heads = 64;
  2966. DiskParameters->Sectors = 32;
  2967. break;
  2968. } else if (PartitionEntryEndHead == 128 - 1) {
  2969. DiskParameters->Heads = 128;
  2970. DiskParameters->Sectors = 32;
  2971. break;
  2972. } else if (PartitionEntryEndHead == 255 - 1) {
  2973. DiskParameters->Heads = 255;
  2974. DiskParameters->Sectors = 63;
  2975. break;
  2976. }
  2977. PartitionEntry++;
  2978. }
  2979. if (PartitionNumber == 4) {
  2980. PartitionEntryEndHead = FirstPartitionEntry->end_head;
  2981. PartitionEntryEndSector = FirstPartitionEntry->end_sector & 0x3F;
  2982. }
  2983. DiskParameters->Cylinders = (unsigned long) capacity / (DiskParameters->Heads * DiskParameters->Sectors);
  2984. if (PartitionNumber < 4 && PartitionEntryEndSector == DiskParameters->Sectors) {
  2985. if (DiskParameters->Cylinders != SavedCylinders)
  2986. BusLogic_Warning("Adopting Geometry %d/%d from Partition Table\n", HostAdapter, DiskParameters->Heads, DiskParameters->Sectors);
  2987. } else if (PartitionEntryEndHead > 0 || PartitionEntryEndSector > 0) {
  2988. BusLogic_Warning("Warning: Partition Table appears to " "have Geometry %d/%d which is\n", HostAdapter, PartitionEntryEndHead + 1, PartitionEntryEndSector);
  2989. BusLogic_Warning("not compatible with current BusLogic " "Host Adapter Geometry %d/%d\n", HostAdapter, DiskParameters->Heads, DiskParameters->Sectors);
  2990. }
  2991. }
  2992. kfree(buf);
  2993. return 0;
  2994. }
  2995. /*
  2996. BugLogic_ProcDirectoryInfo implements /proc/scsi/BusLogic/<N>.
  2997. */
  2998. static int BusLogic_ProcDirectoryInfo(struct Scsi_Host *shost, char *ProcBuffer, char **StartPointer, off_t Offset, int BytesAvailable, int WriteFlag)
  2999. {
  3000. struct BusLogic_HostAdapter *HostAdapter = (struct BusLogic_HostAdapter *) shost->hostdata;
  3001. struct BusLogic_TargetStatistics *TargetStatistics;
  3002. int TargetID, Length;
  3003. char *Buffer;
  3004. TargetStatistics = HostAdapter->TargetStatistics;
  3005. if (WriteFlag) {
  3006. HostAdapter->ExternalHostAdapterResets = 0;
  3007. HostAdapter->HostAdapterInternalErrors = 0;
  3008. memset(TargetStatistics, 0, BusLogic_MaxTargetDevices * sizeof(struct BusLogic_TargetStatistics));
  3009. return 0;
  3010. }
  3011. Buffer = HostAdapter->MessageBuffer;
  3012. Length = HostAdapter->MessageBufferLength;
  3013. Length += sprintf(&Buffer[Length], "\n\
  3014. Current Driver Queue Depth: %d\n\
  3015. Currently Allocated CCBs: %d\n", HostAdapter->DriverQueueDepth, HostAdapter->AllocatedCCBs);
  3016. Length += sprintf(&Buffer[Length], "\n\n\
  3017. DATA TRANSFER STATISTICS\n\
  3018. \n\
  3019. Target Tagged Queuing Queue Depth Active Attempted Completed\n\
  3020. ====== ============== =========== ====== ========= =========\n");
  3021. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  3022. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[TargetID];
  3023. if (!TargetFlags->TargetExists)
  3024. continue;
  3025. Length += sprintf(&Buffer[Length], " %2d %s", TargetID, (TargetFlags->TaggedQueuingSupported ? (TargetFlags->TaggedQueuingActive ? " Active" : (HostAdapter->TaggedQueuingPermitted & (1 << TargetID)
  3026. ? " Permitted" : " Disabled"))
  3027. : "Not Supported"));
  3028. Length += sprintf(&Buffer[Length],
  3029. " %3d %3u %9u %9u\n", HostAdapter->QueueDepth[TargetID], HostAdapter->ActiveCommands[TargetID], TargetStatistics[TargetID].CommandsAttempted, TargetStatistics[TargetID].CommandsCompleted);
  3030. }
  3031. Length += sprintf(&Buffer[Length], "\n\
  3032. Target Read Commands Write Commands Total Bytes Read Total Bytes Written\n\
  3033. ====== ============= ============== =================== ===================\n");
  3034. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  3035. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[TargetID];
  3036. if (!TargetFlags->TargetExists)
  3037. continue;
  3038. Length += sprintf(&Buffer[Length], " %2d %9u %9u", TargetID, TargetStatistics[TargetID].ReadCommands, TargetStatistics[TargetID].WriteCommands);
  3039. if (TargetStatistics[TargetID].TotalBytesRead.Billions > 0)
  3040. Length += sprintf(&Buffer[Length], " %9u%09u", TargetStatistics[TargetID].TotalBytesRead.Billions, TargetStatistics[TargetID].TotalBytesRead.Units);
  3041. else
  3042. Length += sprintf(&Buffer[Length], " %9u", TargetStatistics[TargetID].TotalBytesRead.Units);
  3043. if (TargetStatistics[TargetID].TotalBytesWritten.Billions > 0)
  3044. Length += sprintf(&Buffer[Length], " %9u%09u\n", TargetStatistics[TargetID].TotalBytesWritten.Billions, TargetStatistics[TargetID].TotalBytesWritten.Units);
  3045. else
  3046. Length += sprintf(&Buffer[Length], " %9u\n", TargetStatistics[TargetID].TotalBytesWritten.Units);
  3047. }
  3048. Length += sprintf(&Buffer[Length], "\n\
  3049. Target Command 0-1KB 1-2KB 2-4KB 4-8KB 8-16KB\n\
  3050. ====== ======= ========= ========= ========= ========= =========\n");
  3051. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  3052. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[TargetID];
  3053. if (!TargetFlags->TargetExists)
  3054. continue;
  3055. Length +=
  3056. sprintf(&Buffer[Length],
  3057. " %2d Read %9u %9u %9u %9u %9u\n", TargetID,
  3058. TargetStatistics[TargetID].ReadCommandSizeBuckets[0],
  3059. TargetStatistics[TargetID].ReadCommandSizeBuckets[1], TargetStatistics[TargetID].ReadCommandSizeBuckets[2], TargetStatistics[TargetID].ReadCommandSizeBuckets[3], TargetStatistics[TargetID].ReadCommandSizeBuckets[4]);
  3060. Length +=
  3061. sprintf(&Buffer[Length],
  3062. " %2d Write %9u %9u %9u %9u %9u\n", TargetID,
  3063. TargetStatistics[TargetID].WriteCommandSizeBuckets[0],
  3064. TargetStatistics[TargetID].WriteCommandSizeBuckets[1], TargetStatistics[TargetID].WriteCommandSizeBuckets[2], TargetStatistics[TargetID].WriteCommandSizeBuckets[3], TargetStatistics[TargetID].WriteCommandSizeBuckets[4]);
  3065. }
  3066. Length += sprintf(&Buffer[Length], "\n\
  3067. Target Command 16-32KB 32-64KB 64-128KB 128-256KB 256KB+\n\
  3068. ====== ======= ========= ========= ========= ========= =========\n");
  3069. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  3070. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[TargetID];
  3071. if (!TargetFlags->TargetExists)
  3072. continue;
  3073. Length +=
  3074. sprintf(&Buffer[Length],
  3075. " %2d Read %9u %9u %9u %9u %9u\n", TargetID,
  3076. TargetStatistics[TargetID].ReadCommandSizeBuckets[5],
  3077. TargetStatistics[TargetID].ReadCommandSizeBuckets[6], TargetStatistics[TargetID].ReadCommandSizeBuckets[7], TargetStatistics[TargetID].ReadCommandSizeBuckets[8], TargetStatistics[TargetID].ReadCommandSizeBuckets[9]);
  3078. Length +=
  3079. sprintf(&Buffer[Length],
  3080. " %2d Write %9u %9u %9u %9u %9u\n", TargetID,
  3081. TargetStatistics[TargetID].WriteCommandSizeBuckets[5],
  3082. TargetStatistics[TargetID].WriteCommandSizeBuckets[6], TargetStatistics[TargetID].WriteCommandSizeBuckets[7], TargetStatistics[TargetID].WriteCommandSizeBuckets[8], TargetStatistics[TargetID].WriteCommandSizeBuckets[9]);
  3083. }
  3084. Length += sprintf(&Buffer[Length], "\n\n\
  3085. ERROR RECOVERY STATISTICS\n\
  3086. \n\
  3087. Command Aborts Bus Device Resets Host Adapter Resets\n\
  3088. Target Requested Completed Requested Completed Requested Completed\n\
  3089. ID \\\\\\\\ Attempted //// \\\\\\\\ Attempted //// \\\\\\\\ Attempted ////\n\
  3090. ====== ===== ===== ===== ===== ===== ===== ===== ===== =====\n");
  3091. for (TargetID = 0; TargetID < HostAdapter->MaxTargetDevices; TargetID++) {
  3092. struct BusLogic_TargetFlags *TargetFlags = &HostAdapter->TargetFlags[TargetID];
  3093. if (!TargetFlags->TargetExists)
  3094. continue;
  3095. Length += sprintf(&Buffer[Length], "\
  3096. %2d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", TargetID, TargetStatistics[TargetID].CommandAbortsRequested, TargetStatistics[TargetID].CommandAbortsAttempted, TargetStatistics[TargetID].CommandAbortsCompleted, TargetStatistics[TargetID].BusDeviceResetsRequested, TargetStatistics[TargetID].BusDeviceResetsAttempted, TargetStatistics[TargetID].BusDeviceResetsCompleted, TargetStatistics[TargetID].HostAdapterResetsRequested, TargetStatistics[TargetID].HostAdapterResetsAttempted, TargetStatistics[TargetID].HostAdapterResetsCompleted);
  3097. }
  3098. Length += sprintf(&Buffer[Length], "\nExternal Host Adapter Resets: %d\n", HostAdapter->ExternalHostAdapterResets);
  3099. Length += sprintf(&Buffer[Length], "Host Adapter Internal Errors: %d\n", HostAdapter->HostAdapterInternalErrors);
  3100. if (Length >= BusLogic_MessageBufferSize)
  3101. BusLogic_Error("Message Buffer length %d exceeds size %d\n", HostAdapter, Length, BusLogic_MessageBufferSize);
  3102. if ((Length -= Offset) <= 0)
  3103. return 0;
  3104. if (Length >= BytesAvailable)
  3105. Length = BytesAvailable;
  3106. memcpy(ProcBuffer, HostAdapter->MessageBuffer + Offset, Length);
  3107. *StartPointer = ProcBuffer;
  3108. return Length;
  3109. }
  3110. /*
  3111. BusLogic_Message prints Driver Messages.
  3112. */
  3113. static void BusLogic_Message(enum BusLogic_MessageLevel MessageLevel, char *Format, struct BusLogic_HostAdapter *HostAdapter, ...)
  3114. {
  3115. static char Buffer[BusLogic_LineBufferSize];
  3116. static bool BeginningOfLine = true;
  3117. va_list Arguments;
  3118. int Length = 0;
  3119. va_start(Arguments, HostAdapter);
  3120. Length = vsprintf(Buffer, Format, Arguments);
  3121. va_end(Arguments);
  3122. if (MessageLevel == BusLogic_AnnounceLevel) {
  3123. static int AnnouncementLines = 0;
  3124. strcpy(&HostAdapter->MessageBuffer[HostAdapter->MessageBufferLength], Buffer);
  3125. HostAdapter->MessageBufferLength += Length;
  3126. if (++AnnouncementLines <= 2)
  3127. printk("%sscsi: %s", BusLogic_MessageLevelMap[MessageLevel], Buffer);
  3128. } else if (MessageLevel == BusLogic_InfoLevel) {
  3129. strcpy(&HostAdapter->MessageBuffer[HostAdapter->MessageBufferLength], Buffer);
  3130. HostAdapter->MessageBufferLength += Length;
  3131. if (BeginningOfLine) {
  3132. if (Buffer[0] != '\n' || Length > 1)
  3133. printk("%sscsi%d: %s", BusLogic_MessageLevelMap[MessageLevel], HostAdapter->HostNumber, Buffer);
  3134. } else
  3135. printk("%s", Buffer);
  3136. } else {
  3137. if (BeginningOfLine) {
  3138. if (HostAdapter != NULL && HostAdapter->HostAdapterInitialized)
  3139. printk("%sscsi%d: %s", BusLogic_MessageLevelMap[MessageLevel], HostAdapter->HostNumber, Buffer);
  3140. else
  3141. printk("%s%s", BusLogic_MessageLevelMap[MessageLevel], Buffer);
  3142. } else
  3143. printk("%s", Buffer);
  3144. }
  3145. BeginningOfLine = (Buffer[Length - 1] == '\n');
  3146. }
  3147. /*
  3148. BusLogic_ParseKeyword parses an individual option keyword. It returns true
  3149. and updates the pointer if the keyword is recognized and false otherwise.
  3150. */
  3151. static bool __init BusLogic_ParseKeyword(char **StringPointer, char *Keyword)
  3152. {
  3153. char *Pointer = *StringPointer;
  3154. while (*Keyword != '\0') {
  3155. char StringChar = *Pointer++;
  3156. char KeywordChar = *Keyword++;
  3157. if (StringChar >= 'A' && StringChar <= 'Z')
  3158. StringChar += 'a' - 'Z';
  3159. if (KeywordChar >= 'A' && KeywordChar <= 'Z')
  3160. KeywordChar += 'a' - 'Z';
  3161. if (StringChar != KeywordChar)
  3162. return false;
  3163. }
  3164. *StringPointer = Pointer;
  3165. return true;
  3166. }
  3167. /*
  3168. BusLogic_ParseDriverOptions handles processing of BusLogic Driver Options
  3169. specifications.
  3170. BusLogic Driver Options may be specified either via the Linux Kernel Command
  3171. Line or via the Loadable Kernel Module Installation Facility. Driver Options
  3172. for multiple host adapters may be specified either by separating the option
  3173. strings by a semicolon, or by specifying multiple "BusLogic=" strings on the
  3174. command line. Individual option specifications for a single host adapter are
  3175. separated by commas. The Probing and Debugging Options apply to all host
  3176. adapters whereas the remaining options apply individually only to the
  3177. selected host adapter.
  3178. The BusLogic Driver Probing Options are described in
  3179. <file:Documentation/scsi/BusLogic.txt>.
  3180. */
  3181. static int __init BusLogic_ParseDriverOptions(char *OptionsString)
  3182. {
  3183. while (true) {
  3184. struct BusLogic_DriverOptions *DriverOptions = &BusLogic_DriverOptions[BusLogic_DriverOptionsCount++];
  3185. int TargetID;
  3186. memset(DriverOptions, 0, sizeof(struct BusLogic_DriverOptions));
  3187. while (*OptionsString != '\0' && *OptionsString != ';') {
  3188. /* Probing Options. */
  3189. if (BusLogic_ParseKeyword(&OptionsString, "IO:")) {
  3190. unsigned long IO_Address = simple_strtoul(OptionsString, &OptionsString, 0);
  3191. BusLogic_ProbeOptions.LimitedProbeISA = true;
  3192. switch (IO_Address) {
  3193. case 0x330:
  3194. BusLogic_ProbeOptions.Probe330 = true;
  3195. break;
  3196. case 0x334:
  3197. BusLogic_ProbeOptions.Probe334 = true;
  3198. break;
  3199. case 0x230:
  3200. BusLogic_ProbeOptions.Probe230 = true;
  3201. break;
  3202. case 0x234:
  3203. BusLogic_ProbeOptions.Probe234 = true;
  3204. break;
  3205. case 0x130:
  3206. BusLogic_ProbeOptions.Probe130 = true;
  3207. break;
  3208. case 0x134:
  3209. BusLogic_ProbeOptions.Probe134 = true;
  3210. break;
  3211. default:
  3212. BusLogic_Error("BusLogic: Invalid Driver Options " "(invalid I/O Address 0x%X)\n", NULL, IO_Address);
  3213. return 0;
  3214. }
  3215. } else if (BusLogic_ParseKeyword(&OptionsString, "NoProbeISA"))
  3216. BusLogic_ProbeOptions.NoProbeISA = true;
  3217. else if (BusLogic_ParseKeyword(&OptionsString, "NoProbePCI"))
  3218. BusLogic_ProbeOptions.NoProbePCI = true;
  3219. else if (BusLogic_ParseKeyword(&OptionsString, "NoProbe"))
  3220. BusLogic_ProbeOptions.NoProbe = true;
  3221. else if (BusLogic_ParseKeyword(&OptionsString, "NoSortPCI"))
  3222. BusLogic_ProbeOptions.NoSortPCI = true;
  3223. else if (BusLogic_ParseKeyword(&OptionsString, "MultiMasterFirst"))
  3224. BusLogic_ProbeOptions.MultiMasterFirst = true;
  3225. else if (BusLogic_ParseKeyword(&OptionsString, "FlashPointFirst"))
  3226. BusLogic_ProbeOptions.FlashPointFirst = true;
  3227. /* Tagged Queuing Options. */
  3228. else if (BusLogic_ParseKeyword(&OptionsString, "QueueDepth:[") || BusLogic_ParseKeyword(&OptionsString, "QD:[")) {
  3229. for (TargetID = 0; TargetID < BusLogic_MaxTargetDevices; TargetID++) {
  3230. unsigned short QueueDepth = simple_strtoul(OptionsString, &OptionsString, 0);
  3231. if (QueueDepth > BusLogic_MaxTaggedQueueDepth) {
  3232. BusLogic_Error("BusLogic: Invalid Driver Options " "(invalid Queue Depth %d)\n", NULL, QueueDepth);
  3233. return 0;
  3234. }
  3235. DriverOptions->QueueDepth[TargetID] = QueueDepth;
  3236. if (*OptionsString == ',')
  3237. OptionsString++;
  3238. else if (*OptionsString == ']')
  3239. break;
  3240. else {
  3241. BusLogic_Error("BusLogic: Invalid Driver Options " "(',' or ']' expected at '%s')\n", NULL, OptionsString);
  3242. return 0;
  3243. }
  3244. }
  3245. if (*OptionsString != ']') {
  3246. BusLogic_Error("BusLogic: Invalid Driver Options " "(']' expected at '%s')\n", NULL, OptionsString);
  3247. return 0;
  3248. } else
  3249. OptionsString++;
  3250. } else if (BusLogic_ParseKeyword(&OptionsString, "QueueDepth:") || BusLogic_ParseKeyword(&OptionsString, "QD:")) {
  3251. unsigned short QueueDepth = simple_strtoul(OptionsString, &OptionsString, 0);
  3252. if (QueueDepth == 0 || QueueDepth > BusLogic_MaxTaggedQueueDepth) {
  3253. BusLogic_Error("BusLogic: Invalid Driver Options " "(invalid Queue Depth %d)\n", NULL, QueueDepth);
  3254. return 0;
  3255. }
  3256. DriverOptions->CommonQueueDepth = QueueDepth;
  3257. for (TargetID = 0; TargetID < BusLogic_MaxTargetDevices; TargetID++)
  3258. DriverOptions->QueueDepth[TargetID] = QueueDepth;
  3259. } else if (BusLogic_ParseKeyword(&OptionsString, "TaggedQueuing:") || BusLogic_ParseKeyword(&OptionsString, "TQ:")) {
  3260. if (BusLogic_ParseKeyword(&OptionsString, "Default")) {
  3261. DriverOptions->TaggedQueuingPermitted = 0x0000;
  3262. DriverOptions->TaggedQueuingPermittedMask = 0x0000;
  3263. } else if (BusLogic_ParseKeyword(&OptionsString, "Enable")) {
  3264. DriverOptions->TaggedQueuingPermitted = 0xFFFF;
  3265. DriverOptions->TaggedQueuingPermittedMask = 0xFFFF;
  3266. } else if (BusLogic_ParseKeyword(&OptionsString, "Disable")) {
  3267. DriverOptions->TaggedQueuingPermitted = 0x0000;
  3268. DriverOptions->TaggedQueuingPermittedMask = 0xFFFF;
  3269. } else {
  3270. unsigned short TargetBit;
  3271. for (TargetID = 0, TargetBit = 1; TargetID < BusLogic_MaxTargetDevices; TargetID++, TargetBit <<= 1)
  3272. switch (*OptionsString++) {
  3273. case 'Y':
  3274. DriverOptions->TaggedQueuingPermitted |= TargetBit;
  3275. DriverOptions->TaggedQueuingPermittedMask |= TargetBit;
  3276. break;
  3277. case 'N':
  3278. DriverOptions->TaggedQueuingPermitted &= ~TargetBit;
  3279. DriverOptions->TaggedQueuingPermittedMask |= TargetBit;
  3280. break;
  3281. case 'X':
  3282. break;
  3283. default:
  3284. OptionsString--;
  3285. TargetID = BusLogic_MaxTargetDevices;
  3286. break;
  3287. }
  3288. }
  3289. }
  3290. /* Miscellaneous Options. */
  3291. else if (BusLogic_ParseKeyword(&OptionsString, "BusSettleTime:") || BusLogic_ParseKeyword(&OptionsString, "BST:")) {
  3292. unsigned short BusSettleTime = simple_strtoul(OptionsString, &OptionsString, 0);
  3293. if (BusSettleTime > 5 * 60) {
  3294. BusLogic_Error("BusLogic: Invalid Driver Options " "(invalid Bus Settle Time %d)\n", NULL, BusSettleTime);
  3295. return 0;
  3296. }
  3297. DriverOptions->BusSettleTime = BusSettleTime;
  3298. } else if (BusLogic_ParseKeyword(&OptionsString, "InhibitTargetInquiry"))
  3299. DriverOptions->LocalOptions.InhibitTargetInquiry = true;
  3300. /* Debugging Options. */
  3301. else if (BusLogic_ParseKeyword(&OptionsString, "TraceProbe"))
  3302. BusLogic_GlobalOptions.TraceProbe = true;
  3303. else if (BusLogic_ParseKeyword(&OptionsString, "TraceHardwareReset"))
  3304. BusLogic_GlobalOptions.TraceHardwareReset = true;
  3305. else if (BusLogic_ParseKeyword(&OptionsString, "TraceConfiguration"))
  3306. BusLogic_GlobalOptions.TraceConfiguration = true;
  3307. else if (BusLogic_ParseKeyword(&OptionsString, "TraceErrors"))
  3308. BusLogic_GlobalOptions.TraceErrors = true;
  3309. else if (BusLogic_ParseKeyword(&OptionsString, "Debug")) {
  3310. BusLogic_GlobalOptions.TraceProbe = true;
  3311. BusLogic_GlobalOptions.TraceHardwareReset = true;
  3312. BusLogic_GlobalOptions.TraceConfiguration = true;
  3313. BusLogic_GlobalOptions.TraceErrors = true;
  3314. }
  3315. if (*OptionsString == ',')
  3316. OptionsString++;
  3317. else if (*OptionsString != ';' && *OptionsString != '\0') {
  3318. BusLogic_Error("BusLogic: Unexpected Driver Option '%s' " "ignored\n", NULL, OptionsString);
  3319. *OptionsString = '\0';
  3320. }
  3321. }
  3322. if (!(BusLogic_DriverOptionsCount == 0 || BusLogic_ProbeInfoCount == 0 || BusLogic_DriverOptionsCount == BusLogic_ProbeInfoCount)) {
  3323. BusLogic_Error("BusLogic: Invalid Driver Options " "(all or no I/O Addresses must be specified)\n", NULL);
  3324. return 0;
  3325. }
  3326. /*
  3327. Tagged Queuing is disabled when the Queue Depth is 1 since queuing
  3328. multiple commands is not possible.
  3329. */
  3330. for (TargetID = 0; TargetID < BusLogic_MaxTargetDevices; TargetID++)
  3331. if (DriverOptions->QueueDepth[TargetID] == 1) {
  3332. unsigned short TargetBit = 1 << TargetID;
  3333. DriverOptions->TaggedQueuingPermitted &= ~TargetBit;
  3334. DriverOptions->TaggedQueuingPermittedMask |= TargetBit;
  3335. }
  3336. if (*OptionsString == ';')
  3337. OptionsString++;
  3338. if (*OptionsString == '\0')
  3339. return 0;
  3340. }
  3341. return 1;
  3342. }
  3343. /*
  3344. Get it all started
  3345. */
  3346. static struct scsi_host_template Bus_Logic_template = {
  3347. .module = THIS_MODULE,
  3348. .proc_name = "BusLogic",
  3349. .proc_info = BusLogic_ProcDirectoryInfo,
  3350. .name = "BusLogic",
  3351. .info = BusLogic_DriverInfo,
  3352. .queuecommand = BusLogic_QueueCommand,
  3353. .slave_configure = BusLogic_SlaveConfigure,
  3354. .bios_param = BusLogic_BIOSDiskParameters,
  3355. .eh_host_reset_handler = BusLogic_host_reset,
  3356. #if 0
  3357. .eh_abort_handler = BusLogic_AbortCommand,
  3358. #endif
  3359. .unchecked_isa_dma = 1,
  3360. .max_sectors = 128,
  3361. .use_clustering = ENABLE_CLUSTERING,
  3362. };
  3363. /*
  3364. BusLogic_Setup handles processing of Kernel Command Line Arguments.
  3365. */
  3366. static int __init BusLogic_Setup(char *str)
  3367. {
  3368. int ints[3];
  3369. (void) get_options(str, ARRAY_SIZE(ints), ints);
  3370. if (ints[0] != 0) {
  3371. BusLogic_Error("BusLogic: Obsolete Command Line Entry " "Format Ignored\n", NULL);
  3372. return 0;
  3373. }
  3374. if (str == NULL || *str == '\0')
  3375. return 0;
  3376. return BusLogic_ParseDriverOptions(str);
  3377. }
  3378. /*
  3379. * Exit function. Deletes all hosts associated with this driver.
  3380. */
  3381. static void __exit BusLogic_exit(void)
  3382. {
  3383. struct BusLogic_HostAdapter *ha, *next;
  3384. list_for_each_entry_safe(ha, next, &BusLogic_host_list, host_list)
  3385. BusLogic_ReleaseHostAdapter(ha);
  3386. }
  3387. __setup("BusLogic=", BusLogic_Setup);
  3388. #ifdef MODULE
  3389. static struct pci_device_id BusLogic_pci_tbl[] __devinitdata = {
  3390. { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
  3391. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  3392. { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC,
  3393. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  3394. { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT,
  3395. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  3396. { }
  3397. };
  3398. #endif
  3399. MODULE_DEVICE_TABLE(pci, BusLogic_pci_tbl);
  3400. module_init(BusLogic_init);
  3401. module_exit(BusLogic_exit);