BusLogic.c 149 KB

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