BusLogic.c 148 KB

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