BusLogic.c 148 KB

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