BusLogic.c 149 KB

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