BusLogic.c 127 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896
  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 blogic_drvr_version "2.1.16"
  20. #define blogic_drvr_date "18 July 2002"
  21. #include <linux/module.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/types.h>
  25. #include <linux/blkdev.h>
  26. #include <linux/delay.h>
  27. #include <linux/ioport.h>
  28. #include <linux/mm.h>
  29. #include <linux/stat.h>
  30. #include <linux/pci.h>
  31. #include <linux/spinlock.h>
  32. #include <linux/jiffies.h>
  33. #include <linux/dma-mapping.h>
  34. #include <linux/slab.h>
  35. #include <scsi/scsicam.h>
  36. #include <asm/dma.h>
  37. #include <asm/io.h>
  38. #include <scsi/scsi.h>
  39. #include <scsi/scsi_cmnd.h>
  40. #include <scsi/scsi_device.h>
  41. #include <scsi/scsi_host.h>
  42. #include <scsi/scsi_tcq.h>
  43. #include "BusLogic.h"
  44. #include "FlashPoint.c"
  45. #ifndef FAILURE
  46. #define FAILURE (-1)
  47. #endif
  48. static struct scsi_host_template blogic_template;
  49. /*
  50. blogic_drvr_options_count 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 blogic_drvr_options_count;
  55. /*
  56. blogic_drvr_options 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 blogic_drvr_options blogic_drvr_options[BLOGIC_MAX_ADAPTERS];
  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. blogic_probe_options is a set of Probe Options to be applied across
  71. all BusLogic Host Adapters.
  72. */
  73. static struct blogic_probe_options blogic_probe_options;
  74. /*
  75. blogic_global_options is a set of Global Options to be applied across
  76. all BusLogic Host Adapters.
  77. */
  78. static struct blogic_global_options blogic_global_options;
  79. static LIST_HEAD(blogic_host_list);
  80. /*
  81. blogic_probeinfo_count is the number of entries in blogic_probeinfo_list.
  82. */
  83. static int blogic_probeinfo_count;
  84. /*
  85. blogic_probeinfo_list 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 blogic_probeinfo *blogic_probeinfo_list;
  91. /*
  92. blogic_cmd_failure_reason holds a string identifying the reason why a
  93. call to blogic_cmd failed. It is only non-NULL when blogic_cmd
  94. returns a failure code.
  95. */
  96. static char *blogic_cmd_failure_reason;
  97. /*
  98. blogic_announce_drvr announces the Driver Version and Date, Author's
  99. Name, Copyright Notice, and Electronic Mail Address.
  100. */
  101. static void blogic_announce_drvr(struct blogic_adapter *adapter)
  102. {
  103. blogic_announce("***** BusLogic SCSI Driver Version " blogic_drvr_version " of " blogic_drvr_date " *****\n", adapter);
  104. blogic_announce("Copyright 1995-1998 by Leonard N. Zubkoff " "<lnz@dandelion.com>\n", adapter);
  105. }
  106. /*
  107. blogic_drvr_info returns the Host Adapter Name to identify this SCSI
  108. Driver and Host Adapter.
  109. */
  110. static const char *blogic_drvr_info(struct Scsi_Host *host)
  111. {
  112. struct blogic_adapter *adapter =
  113. (struct blogic_adapter *) host->hostdata;
  114. return adapter->full_model;
  115. }
  116. /*
  117. blogic_init_ccbs initializes a group of Command Control Blocks (CCBs)
  118. for Host Adapter from the blk_size bytes located at blk_pointer. The newly
  119. created CCBs are added to Host Adapter's free list.
  120. */
  121. static void blogic_init_ccbs(struct blogic_adapter *adapter, void *blk_pointer,
  122. int blk_size, dma_addr_t blkp)
  123. {
  124. struct blogic_ccb *ccb = (struct blogic_ccb *) blk_pointer;
  125. unsigned int offset = 0;
  126. memset(blk_pointer, 0, blk_size);
  127. ccb->allocgrp_head = blkp;
  128. ccb->allocgrp_size = blk_size;
  129. while ((blk_size -= sizeof(struct blogic_ccb)) >= 0) {
  130. ccb->status = BLOGIC_CCB_FREE;
  131. ccb->adapter = adapter;
  132. ccb->dma_handle = (u32) blkp + offset;
  133. if (blogic_flashpoint_type(adapter)) {
  134. ccb->callback = blogic_qcompleted_ccb;
  135. ccb->base_addr = adapter->fpinfo.base_addr;
  136. }
  137. ccb->next = adapter->free_ccbs;
  138. ccb->next_all = adapter->all_ccbs;
  139. adapter->free_ccbs = ccb;
  140. adapter->all_ccbs = ccb;
  141. adapter->alloc_ccbs++;
  142. ccb++;
  143. offset += sizeof(struct blogic_ccb);
  144. }
  145. }
  146. /*
  147. blogic_create_initccbs allocates the initial CCBs for Host Adapter.
  148. */
  149. static bool __init blogic_create_initccbs(struct blogic_adapter *adapter)
  150. {
  151. int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb);
  152. void *blk_pointer;
  153. dma_addr_t blkp;
  154. while (adapter->alloc_ccbs < adapter->initccbs) {
  155. blk_pointer = pci_alloc_consistent(adapter->pci_device,
  156. blk_size, &blkp);
  157. if (blk_pointer == NULL) {
  158. blogic_err("UNABLE TO ALLOCATE CCB GROUP - DETACHING\n",
  159. adapter);
  160. return false;
  161. }
  162. blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp);
  163. }
  164. return true;
  165. }
  166. /*
  167. blogic_destroy_ccbs deallocates the CCBs for Host Adapter.
  168. */
  169. static void blogic_destroy_ccbs(struct blogic_adapter *adapter)
  170. {
  171. struct blogic_ccb *next_ccb = adapter->all_ccbs, *ccb, *lastccb = NULL;
  172. adapter->all_ccbs = NULL;
  173. adapter->free_ccbs = NULL;
  174. while ((ccb = next_ccb) != NULL) {
  175. next_ccb = ccb->next_all;
  176. if (ccb->allocgrp_head) {
  177. if (lastccb)
  178. pci_free_consistent(adapter->pci_device,
  179. lastccb->allocgrp_size, lastccb,
  180. lastccb->allocgrp_head);
  181. lastccb = ccb;
  182. }
  183. }
  184. if (lastccb)
  185. pci_free_consistent(adapter->pci_device, lastccb->allocgrp_size,
  186. lastccb, lastccb->allocgrp_head);
  187. }
  188. /*
  189. blogic_create_addlccbs allocates Additional CCBs for Host Adapter. If
  190. allocation fails and there are no remaining CCBs available, the Driver Queue
  191. Depth is decreased to a known safe value to avoid potential deadlocks when
  192. multiple host adapters share the same IRQ Channel.
  193. */
  194. static void blogic_create_addlccbs(struct blogic_adapter *adapter,
  195. int addl_ccbs, bool print_success)
  196. {
  197. int blk_size = BLOGIC_CCB_GRP_ALLOCSIZE * sizeof(struct blogic_ccb);
  198. int prev_alloc = adapter->alloc_ccbs;
  199. void *blk_pointer;
  200. dma_addr_t blkp;
  201. if (addl_ccbs <= 0)
  202. return;
  203. while (adapter->alloc_ccbs - prev_alloc < addl_ccbs) {
  204. blk_pointer = pci_alloc_consistent(adapter->pci_device,
  205. blk_size, &blkp);
  206. if (blk_pointer == NULL)
  207. break;
  208. blogic_init_ccbs(adapter, blk_pointer, blk_size, blkp);
  209. }
  210. if (adapter->alloc_ccbs > prev_alloc) {
  211. if (print_success)
  212. blogic_notice("Allocated %d additional CCBs (total now %d)\n", adapter, adapter->alloc_ccbs - prev_alloc, adapter->alloc_ccbs);
  213. return;
  214. }
  215. blogic_notice("Failed to allocate additional CCBs\n", adapter);
  216. if (adapter->drvr_qdepth > adapter->alloc_ccbs - adapter->tgt_count) {
  217. adapter->drvr_qdepth = adapter->alloc_ccbs - adapter->tgt_count;
  218. adapter->scsi_host->can_queue = adapter->drvr_qdepth;
  219. }
  220. }
  221. /*
  222. blogic_alloc_ccb allocates a CCB from Host Adapter's free list,
  223. allocating more memory from the Kernel if necessary. The Host Adapter's
  224. Lock should already have been acquired by the caller.
  225. */
  226. static struct blogic_ccb *blogic_alloc_ccb(struct blogic_adapter *adapter)
  227. {
  228. static unsigned long serial;
  229. struct blogic_ccb *ccb;
  230. ccb = adapter->free_ccbs;
  231. if (ccb != NULL) {
  232. ccb->serial = ++serial;
  233. adapter->free_ccbs = ccb->next;
  234. ccb->next = NULL;
  235. if (adapter->free_ccbs == NULL)
  236. blogic_create_addlccbs(adapter, adapter->inc_ccbs,
  237. true);
  238. return ccb;
  239. }
  240. blogic_create_addlccbs(adapter, adapter->inc_ccbs, true);
  241. ccb = adapter->free_ccbs;
  242. if (ccb == NULL)
  243. return NULL;
  244. ccb->serial = ++serial;
  245. adapter->free_ccbs = ccb->next;
  246. ccb->next = NULL;
  247. return ccb;
  248. }
  249. /*
  250. blogic_dealloc_ccb deallocates a CCB, returning it to the Host Adapter's
  251. free list. The Host Adapter's Lock should already have been acquired by the
  252. caller.
  253. */
  254. static void blogic_dealloc_ccb(struct blogic_ccb *ccb)
  255. {
  256. struct blogic_adapter *adapter = ccb->adapter;
  257. scsi_dma_unmap(ccb->command);
  258. pci_unmap_single(adapter->pci_device, ccb->sensedata,
  259. ccb->sense_datalen, PCI_DMA_FROMDEVICE);
  260. ccb->command = NULL;
  261. ccb->status = BLOGIC_CCB_FREE;
  262. ccb->next = adapter->free_ccbs;
  263. adapter->free_ccbs = ccb;
  264. }
  265. /*
  266. blogic_cmd sends the command opcode to adapter, optionally
  267. providing paramlen bytes of param and receiving at most
  268. replylen bytes of reply; any excess reply data is received but
  269. discarded.
  270. On success, this function returns the number of reply bytes read from
  271. the Host Adapter (including any discarded data); on failure, it returns
  272. -1 if the command was invalid, or -2 if a timeout occurred.
  273. blogic_cmd is called exclusively during host adapter detection and
  274. initialization, so performance and latency are not critical, and exclusive
  275. access to the Host Adapter hardware is assumed. Once the host adapter and
  276. driver are initialized, the only Host Adapter command that is issued is the
  277. single byte Execute Mailbox Command operation code, which does not require
  278. waiting for the Host Adapter Ready bit to be set in the Status Register.
  279. */
  280. static int blogic_cmd(struct blogic_adapter *adapter, enum blogic_opcode opcode,
  281. void *param, int paramlen, void *reply, int replylen)
  282. {
  283. unsigned char *param_p = (unsigned char *) param;
  284. unsigned char *reply_p = (unsigned char *) reply;
  285. union blogic_stat_reg statusreg;
  286. union blogic_int_reg intreg;
  287. unsigned long processor_flag = 0;
  288. int reply_b = 0, result;
  289. long timeout;
  290. /*
  291. Clear out the Reply Data if provided.
  292. */
  293. if (replylen > 0)
  294. memset(reply, 0, replylen);
  295. /*
  296. If the IRQ Channel has not yet been acquired, then interrupts
  297. must be disabled while issuing host adapter commands since a
  298. Command Complete interrupt could occur if the IRQ Channel was
  299. previously enabled by another BusLogic Host Adapter or another
  300. driver sharing the same IRQ Channel.
  301. */
  302. if (!adapter->irq_acquired)
  303. local_irq_save(processor_flag);
  304. /*
  305. Wait for the Host Adapter Ready bit to be set and the
  306. Command/Parameter Register Busy bit to be reset in the Status
  307. Register.
  308. */
  309. timeout = 10000;
  310. while (--timeout >= 0) {
  311. statusreg.all = blogic_rdstatus(adapter);
  312. if (statusreg.sr.adapter_ready && !statusreg.sr.cmd_param_busy)
  313. break;
  314. udelay(100);
  315. }
  316. if (timeout < 0) {
  317. blogic_cmd_failure_reason =
  318. "Timeout waiting for Host Adapter Ready";
  319. result = -2;
  320. goto done;
  321. }
  322. /*
  323. Write the opcode to the Command/Parameter Register.
  324. */
  325. adapter->adapter_cmd_complete = false;
  326. blogic_setcmdparam(adapter, opcode);
  327. /*
  328. Write any additional Parameter Bytes.
  329. */
  330. timeout = 10000;
  331. while (paramlen > 0 && --timeout >= 0) {
  332. /*
  333. Wait 100 microseconds to give the Host Adapter enough
  334. time to determine whether the last value written to the
  335. Command/Parameter Register was valid or not. If the
  336. Command Complete bit is set in the Interrupt Register,
  337. then the Command Invalid bit in the Status Register will
  338. be reset if the Operation Code or Parameter was valid
  339. and the command has completed, or set if the Operation
  340. Code or Parameter was invalid. If the Data In Register
  341. Ready bit is set in the Status Register, then the
  342. Operation Code was valid, and data is waiting to be read
  343. back from the Host Adapter. Otherwise, wait for the
  344. Command/Parameter Register Busy bit in the Status
  345. Register to be reset.
  346. */
  347. udelay(100);
  348. intreg.all = blogic_rdint(adapter);
  349. statusreg.all = blogic_rdstatus(adapter);
  350. if (intreg.ir.cmd_complete)
  351. break;
  352. if (adapter->adapter_cmd_complete)
  353. break;
  354. if (statusreg.sr.datain_ready)
  355. break;
  356. if (statusreg.sr.cmd_param_busy)
  357. continue;
  358. blogic_setcmdparam(adapter, *param_p++);
  359. paramlen--;
  360. }
  361. if (timeout < 0) {
  362. blogic_cmd_failure_reason =
  363. "Timeout waiting for Parameter Acceptance";
  364. result = -2;
  365. goto done;
  366. }
  367. /*
  368. The Modify I/O Address command does not cause a Command Complete
  369. Interrupt.
  370. */
  371. if (opcode == BLOGIC_MOD_IOADDR) {
  372. statusreg.all = blogic_rdstatus(adapter);
  373. if (statusreg.sr.cmd_invalid) {
  374. blogic_cmd_failure_reason =
  375. "Modify I/O Address Invalid";
  376. result = -1;
  377. goto done;
  378. }
  379. if (blogic_global_options.trace_config)
  380. blogic_notice("blogic_cmd(%02X) Status = %02X: " "(Modify I/O Address)\n", adapter, opcode, statusreg.all);
  381. result = 0;
  382. goto done;
  383. }
  384. /*
  385. Select an appropriate timeout value for awaiting command completion.
  386. */
  387. switch (opcode) {
  388. case BLOGIC_INQ_DEV0TO7:
  389. case BLOGIC_INQ_DEV8TO15:
  390. case BLOGIC_INQ_DEV:
  391. /* Approximately 60 seconds. */
  392. timeout = 60 * 10000;
  393. break;
  394. default:
  395. /* Approximately 1 second. */
  396. timeout = 10000;
  397. break;
  398. }
  399. /*
  400. Receive any Reply Bytes, waiting for either the Command
  401. Complete bit to be set in the Interrupt Register, or for the
  402. Interrupt Handler to set the Host Adapter Command Completed
  403. bit in the Host Adapter structure.
  404. */
  405. while (--timeout >= 0) {
  406. intreg.all = blogic_rdint(adapter);
  407. statusreg.all = blogic_rdstatus(adapter);
  408. if (intreg.ir.cmd_complete)
  409. break;
  410. if (adapter->adapter_cmd_complete)
  411. break;
  412. if (statusreg.sr.datain_ready) {
  413. if (++reply_b <= replylen)
  414. *reply_p++ = blogic_rddatain(adapter);
  415. else
  416. blogic_rddatain(adapter);
  417. }
  418. if (opcode == BLOGIC_FETCH_LOCALRAM &&
  419. statusreg.sr.adapter_ready)
  420. break;
  421. udelay(100);
  422. }
  423. if (timeout < 0) {
  424. blogic_cmd_failure_reason =
  425. "Timeout waiting for Command Complete";
  426. result = -2;
  427. goto done;
  428. }
  429. /*
  430. Clear any pending Command Complete Interrupt.
  431. */
  432. blogic_intreset(adapter);
  433. /*
  434. Provide tracing information if requested.
  435. */
  436. if (blogic_global_options.trace_config) {
  437. int i;
  438. blogic_notice("blogic_cmd(%02X) Status = %02X: %2d ==> %2d:",
  439. adapter, opcode, statusreg.all, replylen,
  440. reply_b);
  441. if (replylen > reply_b)
  442. replylen = reply_b;
  443. for (i = 0; i < replylen; i++)
  444. blogic_notice(" %02X", adapter,
  445. ((unsigned char *) reply)[i]);
  446. blogic_notice("\n", adapter);
  447. }
  448. /*
  449. Process Command Invalid conditions.
  450. */
  451. if (statusreg.sr.cmd_invalid) {
  452. /*
  453. Some early BusLogic Host Adapters may not recover
  454. properly from a Command Invalid condition, so if this
  455. appears to be the case, a Soft Reset is issued to the
  456. Host Adapter. Potentially invalid commands are never
  457. attempted after Mailbox Initialization is performed,
  458. so there should be no Host Adapter state lost by a
  459. Soft Reset in response to a Command Invalid condition.
  460. */
  461. udelay(1000);
  462. statusreg.all = blogic_rdstatus(adapter);
  463. if (statusreg.sr.cmd_invalid || statusreg.sr.rsvd ||
  464. statusreg.sr.datain_ready ||
  465. statusreg.sr.cmd_param_busy ||
  466. !statusreg.sr.adapter_ready ||
  467. !statusreg.sr.init_reqd ||
  468. statusreg.sr.diag_active ||
  469. statusreg.sr.diag_failed) {
  470. blogic_softreset(adapter);
  471. udelay(1000);
  472. }
  473. blogic_cmd_failure_reason = "Command Invalid";
  474. result = -1;
  475. goto done;
  476. }
  477. /*
  478. Handle Excess Parameters Supplied conditions.
  479. */
  480. if (paramlen > 0) {
  481. blogic_cmd_failure_reason = "Excess Parameters Supplied";
  482. result = -1;
  483. goto done;
  484. }
  485. /*
  486. Indicate the command completed successfully.
  487. */
  488. blogic_cmd_failure_reason = NULL;
  489. result = reply_b;
  490. /*
  491. Restore the interrupt status if necessary and return.
  492. */
  493. done:
  494. if (!adapter->irq_acquired)
  495. local_irq_restore(processor_flag);
  496. return result;
  497. }
  498. /*
  499. blogic_add_probeaddr_isa appends a single ISA I/O Address to the list
  500. of I/O Address and Bus Probe Information to be checked for potential BusLogic
  501. Host Adapters.
  502. */
  503. static void __init blogic_add_probeaddr_isa(unsigned long io_addr)
  504. {
  505. struct blogic_probeinfo *probeinfo;
  506. if (blogic_probeinfo_count >= BLOGIC_MAX_ADAPTERS)
  507. return;
  508. probeinfo = &blogic_probeinfo_list[blogic_probeinfo_count++];
  509. probeinfo->adapter_type = BLOGIC_MULTIMASTER;
  510. probeinfo->adapter_bus_type = BLOGIC_ISA_BUS;
  511. probeinfo->io_addr = io_addr;
  512. probeinfo->pci_device = NULL;
  513. }
  514. /*
  515. blogic_init_probeinfo_isa initializes the list of I/O Address and
  516. Bus Probe Information to be checked for potential BusLogic SCSI Host Adapters
  517. only from the list of standard BusLogic MultiMaster ISA I/O Addresses.
  518. */
  519. static void __init blogic_init_probeinfo_isa(struct blogic_adapter *adapter)
  520. {
  521. /*
  522. If BusLogic Driver Options specifications requested that ISA
  523. Bus Probes be inhibited, do not proceed further.
  524. */
  525. if (blogic_probe_options.noprobe_isa)
  526. return;
  527. /*
  528. Append the list of standard BusLogic MultiMaster ISA I/O Addresses.
  529. */
  530. if (!blogic_probe_options.limited_isa || blogic_probe_options.probe330)
  531. blogic_add_probeaddr_isa(0x330);
  532. if (!blogic_probe_options.limited_isa || blogic_probe_options.probe334)
  533. blogic_add_probeaddr_isa(0x334);
  534. if (!blogic_probe_options.limited_isa || blogic_probe_options.probe230)
  535. blogic_add_probeaddr_isa(0x230);
  536. if (!blogic_probe_options.limited_isa || blogic_probe_options.probe234)
  537. blogic_add_probeaddr_isa(0x234);
  538. if (!blogic_probe_options.limited_isa || blogic_probe_options.probe130)
  539. blogic_add_probeaddr_isa(0x130);
  540. if (!blogic_probe_options.limited_isa || blogic_probe_options.probe134)
  541. blogic_add_probeaddr_isa(0x134);
  542. }
  543. #ifdef CONFIG_PCI
  544. /*
  545. blogic_sort_probeinfo sorts a section of blogic_probeinfo_list in order
  546. of increasing PCI Bus and Device Number.
  547. */
  548. static void __init blogic_sort_probeinfo(struct blogic_probeinfo
  549. *probeinfo_list, int probeinfo_cnt)
  550. {
  551. int last_exchange = probeinfo_cnt - 1, bound, j;
  552. while (last_exchange > 0) {
  553. bound = last_exchange;
  554. last_exchange = 0;
  555. for (j = 0; j < bound; j++) {
  556. struct blogic_probeinfo *probeinfo1 =
  557. &probeinfo_list[j];
  558. struct blogic_probeinfo *probeinfo2 =
  559. &probeinfo_list[j + 1];
  560. if (probeinfo1->bus > probeinfo2->bus ||
  561. (probeinfo1->bus == probeinfo2->bus &&
  562. (probeinfo1->dev > probeinfo2->dev))) {
  563. struct blogic_probeinfo tmp_probeinfo;
  564. memcpy(&tmp_probeinfo, probeinfo1,
  565. sizeof(struct blogic_probeinfo));
  566. memcpy(probeinfo1, probeinfo2,
  567. sizeof(struct blogic_probeinfo));
  568. memcpy(probeinfo2, &tmp_probeinfo,
  569. sizeof(struct blogic_probeinfo));
  570. last_exchange = j;
  571. }
  572. }
  573. }
  574. }
  575. /*
  576. blogic_init_mm_probeinfo initializes the list of I/O Address
  577. and Bus Probe Information to be checked for potential BusLogic MultiMaster
  578. SCSI Host Adapters by interrogating the PCI Configuration Space on PCI
  579. machines as well as from the list of standard BusLogic MultiMaster ISA
  580. I/O Addresses. It returns the number of PCI MultiMaster Host Adapters found.
  581. */
  582. static int __init blogic_init_mm_probeinfo(struct blogic_adapter *adapter)
  583. {
  584. struct blogic_probeinfo *pr_probeinfo =
  585. &blogic_probeinfo_list[blogic_probeinfo_count];
  586. int nonpr_mmindex = blogic_probeinfo_count + 1;
  587. int nonpr_mmcount = 0, mmcount = 0;
  588. bool force_scan_order = false;
  589. bool force_scan_order_checked = false;
  590. bool addr_seen[6];
  591. struct pci_dev *pci_device = NULL;
  592. int i;
  593. if (blogic_probeinfo_count >= BLOGIC_MAX_ADAPTERS)
  594. return 0;
  595. blogic_probeinfo_count++;
  596. for (i = 0; i < 6; i++)
  597. addr_seen[i] = false;
  598. /*
  599. Iterate over the MultiMaster PCI Host Adapters. For each
  600. enumerated host adapter, determine whether its ISA Compatible
  601. I/O Port is enabled and if so, whether it is assigned the
  602. Primary I/O Address. A host adapter that is assigned the
  603. Primary I/O Address will always be the preferred boot device.
  604. The MultiMaster BIOS will first recognize a host adapter at
  605. the Primary I/O Address, then any other PCI host adapters,
  606. and finally any host adapters located at the remaining
  607. standard ISA I/O Addresses. When a PCI host adapter is found
  608. with its ISA Compatible I/O Port enabled, a command is issued
  609. to disable the ISA Compatible I/O Port, and it is noted that the
  610. particular standard ISA I/O Address need not be probed.
  611. */
  612. pr_probeinfo->io_addr = 0;
  613. while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC,
  614. PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
  615. pci_device)) != NULL) {
  616. struct blogic_adapter *adapter = adapter;
  617. struct blogic_adapter_info adapter_info;
  618. enum blogic_isa_ioport mod_ioaddr_req;
  619. unsigned char bus;
  620. unsigned char device;
  621. unsigned int irq_ch;
  622. unsigned long base_addr0;
  623. unsigned long base_addr1;
  624. unsigned long io_addr;
  625. unsigned long pci_addr;
  626. if (pci_enable_device(pci_device))
  627. continue;
  628. if (pci_set_dma_mask(pci_device, DMA_BIT_MASK(32)))
  629. continue;
  630. bus = pci_device->bus->number;
  631. device = pci_device->devfn >> 3;
  632. irq_ch = pci_device->irq;
  633. io_addr = base_addr0 = pci_resource_start(pci_device, 0);
  634. pci_addr = base_addr1 = pci_resource_start(pci_device, 1);
  635. if (pci_resource_flags(pci_device, 0) & IORESOURCE_MEM) {
  636. blogic_err("BusLogic: Base Address0 0x%X not I/O for " "MultiMaster Host Adapter\n", NULL, base_addr0);
  637. blogic_err("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, bus, device, io_addr);
  638. continue;
  639. }
  640. if (pci_resource_flags(pci_device, 1) & IORESOURCE_IO) {
  641. blogic_err("BusLogic: Base Address1 0x%X not Memory for " "MultiMaster Host Adapter\n", NULL, base_addr1);
  642. blogic_err("at PCI Bus %d Device %d PCI Address 0x%X\n", NULL, bus, device, pci_addr);
  643. continue;
  644. }
  645. if (irq_ch == 0) {
  646. blogic_err("BusLogic: IRQ Channel %d invalid for " "MultiMaster Host Adapter\n", NULL, irq_ch);
  647. blogic_err("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, bus, device, io_addr);
  648. continue;
  649. }
  650. if (blogic_global_options.trace_probe) {
  651. blogic_notice("BusLogic: PCI MultiMaster Host Adapter " "detected at\n", NULL);
  652. blogic_notice("BusLogic: PCI Bus %d Device %d I/O Address " "0x%X PCI Address 0x%X\n", NULL, bus, device, io_addr, pci_addr);
  653. }
  654. /*
  655. Issue the Inquire PCI Host Adapter Information command to determine
  656. the ISA Compatible I/O Port. If the ISA Compatible I/O Port is
  657. known and enabled, note that the particular Standard ISA I/O
  658. Address should not be probed.
  659. */
  660. adapter->io_addr = io_addr;
  661. blogic_intreset(adapter);
  662. if (blogic_cmd(adapter, BLOGIC_INQ_PCI_INFO, NULL, 0,
  663. &adapter_info, sizeof(adapter_info)) ==
  664. sizeof(adapter_info)) {
  665. if (adapter_info.isa_port < 6)
  666. addr_seen[adapter_info.isa_port] = true;
  667. } else
  668. adapter_info.isa_port = BLOGIC_IO_DISABLE;
  669. /*
  670. Issue the Modify I/O Address command to disable the
  671. ISA Compatible I/O Port. On PCI Host Adapters, the
  672. Modify I/O Address command allows modification of the
  673. ISA compatible I/O Address that the Host Adapter
  674. responds to; it does not affect the PCI compliant
  675. I/O Address assigned at system initialization.
  676. */
  677. mod_ioaddr_req = BLOGIC_IO_DISABLE;
  678. blogic_cmd(adapter, BLOGIC_MOD_IOADDR, &mod_ioaddr_req,
  679. sizeof(mod_ioaddr_req), NULL, 0);
  680. /*
  681. For the first MultiMaster Host Adapter enumerated,
  682. issue the Fetch Host Adapter Local RAM command to read
  683. byte 45 of the AutoSCSI area, for the setting of the
  684. "Use Bus And Device # For PCI Scanning Seq." option.
  685. Issue the Inquire Board ID command since this option is
  686. only valid for the BT-948/958/958D.
  687. */
  688. if (!force_scan_order_checked) {
  689. struct blogic_fetch_localram fetch_localram;
  690. struct blogic_autoscsi_byte45 autoscsi_byte45;
  691. struct blogic_board_id id;
  692. fetch_localram.offset = BLOGIC_AUTOSCSI_BASE + 45;
  693. fetch_localram.count = sizeof(autoscsi_byte45);
  694. blogic_cmd(adapter, BLOGIC_FETCH_LOCALRAM,
  695. &fetch_localram, sizeof(fetch_localram),
  696. &autoscsi_byte45,
  697. sizeof(autoscsi_byte45));
  698. blogic_cmd(adapter, BLOGIC_GET_BOARD_ID, NULL, 0, &id,
  699. sizeof(id));
  700. if (id.fw_ver_digit1 == '5')
  701. force_scan_order =
  702. autoscsi_byte45.force_scan_order;
  703. force_scan_order_checked = true;
  704. }
  705. /*
  706. Determine whether this MultiMaster Host Adapter has its
  707. ISA Compatible I/O Port enabled and is assigned the
  708. Primary I/O Address. If it does, then it is the Primary
  709. MultiMaster Host Adapter and must be recognized first.
  710. If it does not, then it is added to the list for probing
  711. after any Primary MultiMaster Host Adapter is probed.
  712. */
  713. if (adapter_info.isa_port == BLOGIC_IO_330) {
  714. pr_probeinfo->adapter_type = BLOGIC_MULTIMASTER;
  715. pr_probeinfo->adapter_bus_type = BLOGIC_PCI_BUS;
  716. pr_probeinfo->io_addr = io_addr;
  717. pr_probeinfo->pci_addr = pci_addr;
  718. pr_probeinfo->bus = bus;
  719. pr_probeinfo->dev = device;
  720. pr_probeinfo->irq_ch = irq_ch;
  721. pr_probeinfo->pci_device = pci_dev_get(pci_device);
  722. mmcount++;
  723. } else if (blogic_probeinfo_count < BLOGIC_MAX_ADAPTERS) {
  724. struct blogic_probeinfo *probeinfo =
  725. &blogic_probeinfo_list[blogic_probeinfo_count++];
  726. probeinfo->adapter_type = BLOGIC_MULTIMASTER;
  727. probeinfo->adapter_bus_type = BLOGIC_PCI_BUS;
  728. probeinfo->io_addr = io_addr;
  729. probeinfo->pci_addr = pci_addr;
  730. probeinfo->bus = bus;
  731. probeinfo->dev = device;
  732. probeinfo->irq_ch = irq_ch;
  733. probeinfo->pci_device = pci_dev_get(pci_device);
  734. nonpr_mmcount++;
  735. mmcount++;
  736. } else
  737. blogic_warn("BusLogic: Too many Host Adapters " "detected\n", NULL);
  738. }
  739. /*
  740. If the AutoSCSI "Use Bus And Device # For PCI Scanning Seq."
  741. option is ON for the first enumerated MultiMaster Host Adapter,
  742. and if that host adapter is a BT-948/958/958D, then the
  743. MultiMaster BIOS will recognize MultiMaster Host Adapters in
  744. the order of increasing PCI Bus and Device Number. In that case,
  745. sort the probe information into the same order the BIOS uses.
  746. If this option is OFF, then the MultiMaster BIOS will recognize
  747. MultiMaster Host Adapters in the order they are enumerated by
  748. the PCI BIOS, and hence no sorting is necessary.
  749. */
  750. if (force_scan_order)
  751. blogic_sort_probeinfo(&blogic_probeinfo_list[nonpr_mmindex],
  752. nonpr_mmcount);
  753. /*
  754. If no PCI MultiMaster Host Adapter is assigned the Primary
  755. I/O Address, then the Primary I/O Address must be probed
  756. explicitly before any PCI host adapters are probed.
  757. */
  758. if (!blogic_probe_options.noprobe_isa)
  759. if (pr_probeinfo->io_addr == 0 &&
  760. (!blogic_probe_options.limited_isa ||
  761. blogic_probe_options.probe330)) {
  762. pr_probeinfo->adapter_type = BLOGIC_MULTIMASTER;
  763. pr_probeinfo->adapter_bus_type = BLOGIC_ISA_BUS;
  764. pr_probeinfo->io_addr = 0x330;
  765. }
  766. /*
  767. Append the list of standard BusLogic MultiMaster ISA I/O Addresses,
  768. omitting the Primary I/O Address which has already been handled.
  769. */
  770. if (!blogic_probe_options.noprobe_isa) {
  771. if (!addr_seen[1] &&
  772. (!blogic_probe_options.limited_isa ||
  773. blogic_probe_options.probe334))
  774. blogic_add_probeaddr_isa(0x334);
  775. if (!addr_seen[2] &&
  776. (!blogic_probe_options.limited_isa ||
  777. blogic_probe_options.probe230))
  778. blogic_add_probeaddr_isa(0x230);
  779. if (!addr_seen[3] &&
  780. (!blogic_probe_options.limited_isa ||
  781. blogic_probe_options.probe234))
  782. blogic_add_probeaddr_isa(0x234);
  783. if (!addr_seen[4] &&
  784. (!blogic_probe_options.limited_isa ||
  785. blogic_probe_options.probe130))
  786. blogic_add_probeaddr_isa(0x130);
  787. if (!addr_seen[5] &&
  788. (!blogic_probe_options.limited_isa ||
  789. blogic_probe_options.probe134))
  790. blogic_add_probeaddr_isa(0x134);
  791. }
  792. /*
  793. Iterate over the older non-compliant MultiMaster PCI Host Adapters,
  794. noting the PCI bus location and assigned IRQ Channel.
  795. */
  796. pci_device = NULL;
  797. while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC,
  798. PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC,
  799. pci_device)) != NULL) {
  800. unsigned char bus;
  801. unsigned char device;
  802. unsigned int irq_ch;
  803. unsigned long io_addr;
  804. if (pci_enable_device(pci_device))
  805. continue;
  806. if (pci_set_dma_mask(pci_device, DMA_BIT_MASK(32)))
  807. continue;
  808. bus = pci_device->bus->number;
  809. device = pci_device->devfn >> 3;
  810. irq_ch = pci_device->irq;
  811. io_addr = pci_resource_start(pci_device, 0);
  812. if (io_addr == 0 || irq_ch == 0)
  813. continue;
  814. for (i = 0; i < blogic_probeinfo_count; i++) {
  815. struct blogic_probeinfo *probeinfo =
  816. &blogic_probeinfo_list[i];
  817. if (probeinfo->io_addr == io_addr &&
  818. probeinfo->adapter_type == BLOGIC_MULTIMASTER) {
  819. probeinfo->adapter_bus_type = BLOGIC_PCI_BUS;
  820. probeinfo->pci_addr = 0;
  821. probeinfo->bus = bus;
  822. probeinfo->dev = device;
  823. probeinfo->irq_ch = irq_ch;
  824. probeinfo->pci_device = pci_dev_get(pci_device);
  825. break;
  826. }
  827. }
  828. }
  829. return mmcount;
  830. }
  831. /*
  832. blogic_init_fp_probeinfo initializes the list of I/O Address
  833. and Bus Probe Information to be checked for potential BusLogic FlashPoint
  834. Host Adapters by interrogating the PCI Configuration Space. It returns the
  835. number of FlashPoint Host Adapters found.
  836. */
  837. static int __init blogic_init_fp_probeinfo(struct blogic_adapter *adapter)
  838. {
  839. int fpindex = blogic_probeinfo_count, fpcount = 0;
  840. struct pci_dev *pci_device = NULL;
  841. /*
  842. Interrogate PCI Configuration Space for any FlashPoint Host Adapters.
  843. */
  844. while ((pci_device = pci_get_device(PCI_VENDOR_ID_BUSLOGIC,
  845. PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT,
  846. pci_device)) != NULL) {
  847. unsigned char bus;
  848. unsigned char device;
  849. unsigned int irq_ch;
  850. unsigned long base_addr0;
  851. unsigned long base_addr1;
  852. unsigned long io_addr;
  853. unsigned long pci_addr;
  854. if (pci_enable_device(pci_device))
  855. continue;
  856. if (pci_set_dma_mask(pci_device, DMA_BIT_MASK(32)))
  857. continue;
  858. bus = pci_device->bus->number;
  859. device = pci_device->devfn >> 3;
  860. irq_ch = pci_device->irq;
  861. io_addr = base_addr0 = pci_resource_start(pci_device, 0);
  862. pci_addr = base_addr1 = pci_resource_start(pci_device, 1);
  863. #ifdef CONFIG_SCSI_FLASHPOINT
  864. if (pci_resource_flags(pci_device, 0) & IORESOURCE_MEM) {
  865. blogic_err("BusLogic: Base Address0 0x%X not I/O for " "FlashPoint Host Adapter\n", NULL, base_addr0);
  866. blogic_err("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, bus, device, io_addr);
  867. continue;
  868. }
  869. if (pci_resource_flags(pci_device, 1) & IORESOURCE_IO) {
  870. blogic_err("BusLogic: Base Address1 0x%X not Memory for " "FlashPoint Host Adapter\n", NULL, base_addr1);
  871. blogic_err("at PCI Bus %d Device %d PCI Address 0x%X\n", NULL, bus, device, pci_addr);
  872. continue;
  873. }
  874. if (irq_ch == 0) {
  875. blogic_err("BusLogic: IRQ Channel %d invalid for " "FlashPoint Host Adapter\n", NULL, irq_ch);
  876. blogic_err("at PCI Bus %d Device %d I/O Address 0x%X\n", NULL, bus, device, io_addr);
  877. continue;
  878. }
  879. if (blogic_global_options.trace_probe) {
  880. blogic_notice("BusLogic: FlashPoint Host Adapter " "detected at\n", NULL);
  881. blogic_notice("BusLogic: PCI Bus %d Device %d I/O Address " "0x%X PCI Address 0x%X\n", NULL, bus, device, io_addr, pci_addr);
  882. }
  883. if (blogic_probeinfo_count < BLOGIC_MAX_ADAPTERS) {
  884. struct blogic_probeinfo *probeinfo =
  885. &blogic_probeinfo_list[blogic_probeinfo_count++];
  886. probeinfo->adapter_type = BLOGIC_FLASHPOINT;
  887. probeinfo->adapter_bus_type = BLOGIC_PCI_BUS;
  888. probeinfo->io_addr = io_addr;
  889. probeinfo->pci_addr = pci_addr;
  890. probeinfo->bus = bus;
  891. probeinfo->dev = device;
  892. probeinfo->irq_ch = irq_ch;
  893. probeinfo->pci_device = pci_dev_get(pci_device);
  894. fpcount++;
  895. } else
  896. blogic_warn("BusLogic: Too many Host Adapters " "detected\n", NULL);
  897. #else
  898. blogic_err("BusLogic: FlashPoint Host Adapter detected at " "PCI Bus %d Device %d\n", NULL, bus, device);
  899. blogic_err("BusLogic: I/O Address 0x%X PCI Address 0x%X, irq %d, " "but FlashPoint\n", NULL, io_addr, pci_addr, irq_ch);
  900. blogic_err("BusLogic: support was omitted in this kernel " "configuration.\n", NULL);
  901. #endif
  902. }
  903. /*
  904. The FlashPoint BIOS will scan for FlashPoint Host Adapters in the order of
  905. increasing PCI Bus and Device Number, so sort the probe information into
  906. the same order the BIOS uses.
  907. */
  908. blogic_sort_probeinfo(&blogic_probeinfo_list[fpindex], fpcount);
  909. return fpcount;
  910. }
  911. /*
  912. blogic_init_probeinfo_list initializes the list of I/O Address and Bus
  913. Probe Information to be checked for potential BusLogic SCSI Host Adapters by
  914. interrogating the PCI Configuration Space on PCI machines as well as from the
  915. list of standard BusLogic MultiMaster ISA I/O Addresses. By default, if both
  916. FlashPoint and PCI MultiMaster Host Adapters are present, this driver will
  917. probe for FlashPoint Host Adapters first unless the BIOS primary disk is
  918. controlled by the first PCI MultiMaster Host Adapter, in which case
  919. MultiMaster Host Adapters will be probed first. The BusLogic Driver Options
  920. specifications "MultiMasterFirst" and "FlashPointFirst" can be used to force
  921. a particular probe order.
  922. */
  923. static void __init blogic_init_probeinfo_list(struct blogic_adapter *adapter)
  924. {
  925. /*
  926. If a PCI BIOS is present, interrogate it for MultiMaster and
  927. FlashPoint Host Adapters; otherwise, default to the standard
  928. ISA MultiMaster probe.
  929. */
  930. if (!blogic_probe_options.noprobe_pci) {
  931. if (blogic_probe_options.multimaster_first) {
  932. blogic_init_mm_probeinfo(adapter);
  933. blogic_init_fp_probeinfo(adapter);
  934. } else if (blogic_probe_options.flashpoint_first) {
  935. blogic_init_fp_probeinfo(adapter);
  936. blogic_init_mm_probeinfo(adapter);
  937. } else {
  938. int fpcount = blogic_init_fp_probeinfo(adapter);
  939. int mmcount = blogic_init_mm_probeinfo(adapter);
  940. if (fpcount > 0 && mmcount > 0) {
  941. struct blogic_probeinfo *probeinfo =
  942. &blogic_probeinfo_list[fpcount];
  943. struct blogic_adapter *myadapter = adapter;
  944. struct blogic_fetch_localram fetch_localram;
  945. struct blogic_bios_drvmap d0_mapbyte;
  946. while (probeinfo->adapter_bus_type !=
  947. BLOGIC_PCI_BUS)
  948. probeinfo++;
  949. myadapter->io_addr = probeinfo->io_addr;
  950. fetch_localram.offset =
  951. BLOGIC_BIOS_BASE + BLOGIC_BIOS_DRVMAP;
  952. fetch_localram.count = sizeof(d0_mapbyte);
  953. blogic_cmd(myadapter, BLOGIC_FETCH_LOCALRAM,
  954. &fetch_localram,
  955. sizeof(fetch_localram),
  956. &d0_mapbyte,
  957. sizeof(d0_mapbyte));
  958. /*
  959. If the Map Byte for BIOS Drive 0 indicates
  960. that BIOS Drive 0 is controlled by this
  961. PCI MultiMaster Host Adapter, then reverse
  962. the probe order so that MultiMaster Host
  963. Adapters are probed before FlashPoint Host
  964. Adapters.
  965. */
  966. if (d0_mapbyte.diskgeom != BLOGIC_BIOS_NODISK) {
  967. struct blogic_probeinfo saved_probeinfo[BLOGIC_MAX_ADAPTERS];
  968. int mmcount = blogic_probeinfo_count - fpcount;
  969. memcpy(saved_probeinfo,
  970. blogic_probeinfo_list,
  971. blogic_probeinfo_count * sizeof(struct blogic_probeinfo));
  972. memcpy(&blogic_probeinfo_list[0],
  973. &saved_probeinfo[fpcount],
  974. mmcount * sizeof(struct blogic_probeinfo));
  975. memcpy(&blogic_probeinfo_list[mmcount],
  976. &saved_probeinfo[0],
  977. fpcount * sizeof(struct blogic_probeinfo));
  978. }
  979. }
  980. }
  981. } else {
  982. blogic_init_probeinfo_isa(adapter);
  983. }
  984. }
  985. #else
  986. #define blogic_init_probeinfo_list(adapter) \
  987. blogic_init_probeinfo_isa(adapter)
  988. #endif /* CONFIG_PCI */
  989. /*
  990. blogic_failure prints a standardized error message, and then returns false.
  991. */
  992. static bool blogic_failure(struct blogic_adapter *adapter, char *msg)
  993. {
  994. blogic_announce_drvr(adapter);
  995. if (adapter->adapter_bus_type == BLOGIC_PCI_BUS) {
  996. blogic_err("While configuring BusLogic PCI Host Adapter at\n",
  997. adapter);
  998. blogic_err("Bus %d Device %d I/O Address 0x%X PCI Address 0x%X:\n", adapter, adapter->bus, adapter->dev, adapter->io_addr, adapter->pci_addr);
  999. } else
  1000. blogic_err("While configuring BusLogic Host Adapter at " "I/O Address 0x%X:\n", adapter, adapter->io_addr);
  1001. blogic_err("%s FAILED - DETACHING\n", adapter, msg);
  1002. if (blogic_cmd_failure_reason != NULL)
  1003. blogic_err("ADDITIONAL FAILURE INFO - %s\n", adapter,
  1004. blogic_cmd_failure_reason);
  1005. return false;
  1006. }
  1007. /*
  1008. blogic_probe probes for a BusLogic Host Adapter.
  1009. */
  1010. static bool __init blogic_probe(struct blogic_adapter *adapter)
  1011. {
  1012. union blogic_stat_reg statusreg;
  1013. union blogic_int_reg intreg;
  1014. union blogic_geo_reg georeg;
  1015. /*
  1016. FlashPoint Host Adapters are Probed by the FlashPoint SCCB Manager.
  1017. */
  1018. if (blogic_flashpoint_type(adapter)) {
  1019. struct fpoint_info *fpinfo = &adapter->fpinfo;
  1020. fpinfo->base_addr = (u32) adapter->io_addr;
  1021. fpinfo->irq_ch = adapter->irq_ch;
  1022. fpinfo->present = false;
  1023. if (!(FlashPoint_ProbeHostAdapter(fpinfo) == 0 &&
  1024. fpinfo->present)) {
  1025. blogic_err("BusLogic: FlashPoint Host Adapter detected at " "PCI Bus %d Device %d\n", adapter, adapter->bus, adapter->dev);
  1026. blogic_err("BusLogic: I/O Address 0x%X PCI Address 0x%X, " "but FlashPoint\n", adapter, adapter->io_addr, adapter->pci_addr);
  1027. blogic_err("BusLogic: Probe Function failed to validate it.\n", adapter);
  1028. return false;
  1029. }
  1030. if (blogic_global_options.trace_probe)
  1031. blogic_notice("BusLogic_Probe(0x%X): FlashPoint Found\n", adapter, adapter->io_addr);
  1032. /*
  1033. Indicate the Host Adapter Probe completed successfully.
  1034. */
  1035. return true;
  1036. }
  1037. /*
  1038. Read the Status, Interrupt, and Geometry Registers to test if there are I/O
  1039. ports that respond, and to check the values to determine if they are from a
  1040. BusLogic Host Adapter. A nonexistent I/O port will return 0xFF, in which
  1041. case there is definitely no BusLogic Host Adapter at this base I/O Address.
  1042. The test here is a subset of that used by the BusLogic Host Adapter BIOS.
  1043. */
  1044. statusreg.all = blogic_rdstatus(adapter);
  1045. intreg.all = blogic_rdint(adapter);
  1046. georeg.all = blogic_rdgeom(adapter);
  1047. if (blogic_global_options.trace_probe)
  1048. blogic_notice("BusLogic_Probe(0x%X): Status 0x%02X, Interrupt 0x%02X, " "Geometry 0x%02X\n", adapter, adapter->io_addr, statusreg.all, intreg.all, georeg.all);
  1049. if (statusreg.all == 0 || statusreg.sr.diag_active ||
  1050. statusreg.sr.cmd_param_busy || statusreg.sr.rsvd ||
  1051. statusreg.sr.cmd_invalid || intreg.ir.rsvd != 0)
  1052. return false;
  1053. /*
  1054. Check the undocumented Geometry Register to test if there is
  1055. an I/O port that responded. Adaptec Host Adapters do not
  1056. implement the Geometry Register, so this test helps serve to
  1057. avoid incorrectly recognizing an Adaptec 1542A or 1542B as a
  1058. BusLogic. Unfortunately, the Adaptec 1542C series does respond
  1059. to the Geometry Register I/O port, but it will be rejected
  1060. later when the Inquire Extended Setup Information command is
  1061. issued in blogic_checkadapter. The AMI FastDisk Host Adapter
  1062. is a BusLogic clone that implements the same interface as
  1063. earlier BusLogic Host Adapters, including the undocumented
  1064. commands, and is therefore supported by this driver. However,
  1065. the AMI FastDisk always returns 0x00 upon reading the Geometry
  1066. Register, so the extended translation option should always be
  1067. left disabled on the AMI FastDisk.
  1068. */
  1069. if (georeg.all == 0xFF)
  1070. return false;
  1071. /*
  1072. Indicate the Host Adapter Probe completed successfully.
  1073. */
  1074. return true;
  1075. }
  1076. /*
  1077. blogic_hwreset issues a Hardware Reset to the Host Adapter
  1078. and waits for Host Adapter Diagnostics to complete. If hard_reset is true, a
  1079. Hard Reset is performed which also initiates a SCSI Bus Reset. Otherwise, a
  1080. Soft Reset is performed which only resets the Host Adapter without forcing a
  1081. SCSI Bus Reset.
  1082. */
  1083. static bool blogic_hwreset(struct blogic_adapter *adapter, bool hard_reset)
  1084. {
  1085. union blogic_stat_reg statusreg;
  1086. int timeout;
  1087. /*
  1088. FlashPoint Host Adapters are Hard Reset by the FlashPoint
  1089. SCCB Manager.
  1090. */
  1091. if (blogic_flashpoint_type(adapter)) {
  1092. struct fpoint_info *fpinfo = &adapter->fpinfo;
  1093. fpinfo->softreset = !hard_reset;
  1094. fpinfo->report_underrun = true;
  1095. adapter->cardhandle =
  1096. FlashPoint_HardwareResetHostAdapter(fpinfo);
  1097. if (adapter->cardhandle == (void *)FPOINT_BADCARD_HANDLE)
  1098. return false;
  1099. /*
  1100. Indicate the Host Adapter Hard Reset completed successfully.
  1101. */
  1102. return true;
  1103. }
  1104. /*
  1105. Issue a Hard Reset or Soft Reset Command to the Host Adapter.
  1106. The Host Adapter should respond by setting Diagnostic Active in
  1107. the Status Register.
  1108. */
  1109. if (hard_reset)
  1110. blogic_hardreset(adapter);
  1111. else
  1112. blogic_softreset(adapter);
  1113. /*
  1114. Wait until Diagnostic Active is set in the Status Register.
  1115. */
  1116. timeout = 5 * 10000;
  1117. while (--timeout >= 0) {
  1118. statusreg.all = blogic_rdstatus(adapter);
  1119. if (statusreg.sr.diag_active)
  1120. break;
  1121. udelay(100);
  1122. }
  1123. if (blogic_global_options.trace_hw_reset)
  1124. blogic_notice("BusLogic_HardwareReset(0x%X): Diagnostic Active, " "Status 0x%02X\n", adapter, adapter->io_addr, statusreg.all);
  1125. if (timeout < 0)
  1126. return false;
  1127. /*
  1128. Wait 100 microseconds to allow completion of any initial diagnostic
  1129. activity which might leave the contents of the Status Register
  1130. unpredictable.
  1131. */
  1132. udelay(100);
  1133. /*
  1134. Wait until Diagnostic Active is reset in the Status Register.
  1135. */
  1136. timeout = 10 * 10000;
  1137. while (--timeout >= 0) {
  1138. statusreg.all = blogic_rdstatus(adapter);
  1139. if (!statusreg.sr.diag_active)
  1140. break;
  1141. udelay(100);
  1142. }
  1143. if (blogic_global_options.trace_hw_reset)
  1144. blogic_notice("BusLogic_HardwareReset(0x%X): Diagnostic Completed, " "Status 0x%02X\n", adapter, adapter->io_addr, statusreg.all);
  1145. if (timeout < 0)
  1146. return false;
  1147. /*
  1148. Wait until at least one of the Diagnostic Failure, Host Adapter
  1149. Ready, or Data In Register Ready bits is set in the Status Register.
  1150. */
  1151. timeout = 10000;
  1152. while (--timeout >= 0) {
  1153. statusreg.all = blogic_rdstatus(adapter);
  1154. if (statusreg.sr.diag_failed || statusreg.sr.adapter_ready ||
  1155. statusreg.sr.datain_ready)
  1156. break;
  1157. udelay(100);
  1158. }
  1159. if (blogic_global_options.trace_hw_reset)
  1160. blogic_notice("BusLogic_HardwareReset(0x%X): Host Adapter Ready, " "Status 0x%02X\n", adapter, adapter->io_addr, statusreg.all);
  1161. if (timeout < 0)
  1162. return false;
  1163. /*
  1164. If Diagnostic Failure is set or Host Adapter Ready is reset,
  1165. then an error occurred during the Host Adapter diagnostics.
  1166. If Data In Register Ready is set, then there is an Error Code
  1167. available.
  1168. */
  1169. if (statusreg.sr.diag_failed || !statusreg.sr.adapter_ready) {
  1170. blogic_cmd_failure_reason = NULL;
  1171. blogic_failure(adapter, "HARD RESET DIAGNOSTICS");
  1172. blogic_err("HOST ADAPTER STATUS REGISTER = %02X\n", adapter,
  1173. statusreg.all);
  1174. if (statusreg.sr.datain_ready)
  1175. blogic_err("HOST ADAPTER ERROR CODE = %d\n", adapter,
  1176. blogic_rddatain(adapter));
  1177. return false;
  1178. }
  1179. /*
  1180. Indicate the Host Adapter Hard Reset completed successfully.
  1181. */
  1182. return true;
  1183. }
  1184. /*
  1185. blogic_checkadapter checks to be sure this really is a BusLogic
  1186. Host Adapter.
  1187. */
  1188. static bool __init blogic_checkadapter(struct blogic_adapter *adapter)
  1189. {
  1190. struct blogic_ext_setup ext_setupinfo;
  1191. unsigned char req_replylen;
  1192. bool result = true;
  1193. /*
  1194. FlashPoint Host Adapters do not require this protection.
  1195. */
  1196. if (blogic_flashpoint_type(adapter))
  1197. return true;
  1198. /*
  1199. Issue the Inquire Extended Setup Information command. Only genuine
  1200. BusLogic Host Adapters and true clones support this command.
  1201. Adaptec 1542C series Host Adapters that respond to the Geometry
  1202. Register I/O port will fail this command.
  1203. */
  1204. req_replylen = sizeof(ext_setupinfo);
  1205. if (blogic_cmd(adapter, BLOGIC_INQ_EXTSETUP, &req_replylen,
  1206. sizeof(req_replylen), &ext_setupinfo,
  1207. sizeof(ext_setupinfo)) != sizeof(ext_setupinfo))
  1208. result = false;
  1209. /*
  1210. Provide tracing information if requested and return.
  1211. */
  1212. if (blogic_global_options.trace_probe)
  1213. blogic_notice("BusLogic_Check(0x%X): MultiMaster %s\n", adapter,
  1214. adapter->io_addr,
  1215. (result ? "Found" : "Not Found"));
  1216. return result;
  1217. }
  1218. /*
  1219. blogic_rdconfig reads the Configuration Information
  1220. from Host Adapter and initializes the Host Adapter structure.
  1221. */
  1222. static bool __init blogic_rdconfig(struct blogic_adapter *adapter)
  1223. {
  1224. struct blogic_board_id id;
  1225. struct blogic_config config;
  1226. struct blogic_setup_info setupinfo;
  1227. struct blogic_ext_setup ext_setupinfo;
  1228. unsigned char model[5];
  1229. unsigned char fw_ver_digit3;
  1230. unsigned char fw_ver_letter;
  1231. struct blogic_adapter_info adapter_info;
  1232. struct blogic_fetch_localram fetch_localram;
  1233. struct blogic_autoscsi autoscsi;
  1234. union blogic_geo_reg georeg;
  1235. unsigned char req_replylen;
  1236. unsigned char *tgt, ch;
  1237. int tgt_id, i;
  1238. /*
  1239. Configuration Information for FlashPoint Host Adapters is
  1240. provided in the fpoint_info structure by the FlashPoint
  1241. SCCB Manager's Probe Function. Initialize fields in the
  1242. Host Adapter structure from the fpoint_info structure.
  1243. */
  1244. if (blogic_flashpoint_type(adapter)) {
  1245. struct fpoint_info *fpinfo = &adapter->fpinfo;
  1246. tgt = adapter->model;
  1247. *tgt++ = 'B';
  1248. *tgt++ = 'T';
  1249. *tgt++ = '-';
  1250. for (i = 0; i < sizeof(fpinfo->model); i++)
  1251. *tgt++ = fpinfo->model[i];
  1252. *tgt++ = '\0';
  1253. strcpy(adapter->fw_ver, FLASHPOINT_FW_VER);
  1254. adapter->scsi_id = fpinfo->scsi_id;
  1255. adapter->ext_trans_enable = fpinfo->ext_trans_enable;
  1256. adapter->parity = fpinfo->parity;
  1257. adapter->reset_enabled = !fpinfo->softreset;
  1258. adapter->level_int = true;
  1259. adapter->wide = fpinfo->wide;
  1260. adapter->differential = false;
  1261. adapter->scam = true;
  1262. adapter->ultra = true;
  1263. adapter->ext_lun = true;
  1264. adapter->terminfo_valid = true;
  1265. adapter->low_term = fpinfo->low_term;
  1266. adapter->high_term = fpinfo->high_term;
  1267. adapter->scam_enabled = fpinfo->scam_enabled;
  1268. adapter->scam_lev2 = fpinfo->scam_lev2;
  1269. adapter->drvr_sglimit = BLOGIC_SG_LIMIT;
  1270. adapter->maxdev = (adapter->wide ? 16 : 8);
  1271. adapter->maxlun = 32;
  1272. adapter->initccbs = 4 * BLOGIC_CCB_GRP_ALLOCSIZE;
  1273. adapter->inc_ccbs = BLOGIC_CCB_GRP_ALLOCSIZE;
  1274. adapter->drvr_qdepth = 255;
  1275. adapter->adapter_qdepth = adapter->drvr_qdepth;
  1276. adapter->sync_ok = fpinfo->sync_ok;
  1277. adapter->fast_ok = fpinfo->fast_ok;
  1278. adapter->ultra_ok = fpinfo->ultra_ok;
  1279. adapter->wide_ok = fpinfo->wide_ok;
  1280. adapter->discon_ok = fpinfo->discon_ok;
  1281. adapter->tagq_ok = 0xFFFF;
  1282. goto common;
  1283. }
  1284. /*
  1285. Issue the Inquire Board ID command.
  1286. */
  1287. if (blogic_cmd(adapter, BLOGIC_GET_BOARD_ID, NULL, 0, &id,
  1288. sizeof(id)) != sizeof(id))
  1289. return blogic_failure(adapter, "INQUIRE BOARD ID");
  1290. /*
  1291. Issue the Inquire Configuration command.
  1292. */
  1293. if (blogic_cmd(adapter, BLOGIC_INQ_CONFIG, NULL, 0, &config,
  1294. sizeof(config))
  1295. != sizeof(config))
  1296. return blogic_failure(adapter, "INQUIRE CONFIGURATION");
  1297. /*
  1298. Issue the Inquire Setup Information command.
  1299. */
  1300. req_replylen = sizeof(setupinfo);
  1301. if (blogic_cmd(adapter, BLOGIC_INQ_SETUPINFO, &req_replylen,
  1302. sizeof(req_replylen), &setupinfo,
  1303. sizeof(setupinfo)) != sizeof(setupinfo))
  1304. return blogic_failure(adapter, "INQUIRE SETUP INFORMATION");
  1305. /*
  1306. Issue the Inquire Extended Setup Information command.
  1307. */
  1308. req_replylen = sizeof(ext_setupinfo);
  1309. if (blogic_cmd(adapter, BLOGIC_INQ_EXTSETUP, &req_replylen,
  1310. sizeof(req_replylen), &ext_setupinfo,
  1311. sizeof(ext_setupinfo)) != sizeof(ext_setupinfo))
  1312. return blogic_failure(adapter,
  1313. "INQUIRE EXTENDED SETUP INFORMATION");
  1314. /*
  1315. Issue the Inquire Firmware Version 3rd Digit command.
  1316. */
  1317. fw_ver_digit3 = '\0';
  1318. if (id.fw_ver_digit1 > '0')
  1319. if (blogic_cmd(adapter, BLOGIC_INQ_FWVER_D3, NULL, 0,
  1320. &fw_ver_digit3,
  1321. sizeof(fw_ver_digit3)) != sizeof(fw_ver_digit3))
  1322. return blogic_failure(adapter,
  1323. "INQUIRE FIRMWARE 3RD DIGIT");
  1324. /*
  1325. Issue the Inquire Host Adapter Model Number command.
  1326. */
  1327. if (ext_setupinfo.bus_type == 'A' && id.fw_ver_digit1 == '2')
  1328. /* BusLogic BT-542B ISA 2.xx */
  1329. strcpy(model, "542B");
  1330. else if (ext_setupinfo.bus_type == 'E' && id.fw_ver_digit1 == '2' &&
  1331. (id.fw_ver_digit2 <= '1' || (id.fw_ver_digit2 == '2' &&
  1332. fw_ver_digit3 == '0')))
  1333. /* BusLogic BT-742A EISA 2.1x or 2.20 */
  1334. strcpy(model, "742A");
  1335. else if (ext_setupinfo.bus_type == 'E' && id.fw_ver_digit1 == '0')
  1336. /* AMI FastDisk EISA Series 441 0.x */
  1337. strcpy(model, "747A");
  1338. else {
  1339. req_replylen = sizeof(model);
  1340. if (blogic_cmd(adapter, BLOGIC_INQ_MODELNO, &req_replylen,
  1341. sizeof(req_replylen), &model,
  1342. sizeof(model)) != sizeof(model))
  1343. return blogic_failure(adapter,
  1344. "INQUIRE HOST ADAPTER MODEL NUMBER");
  1345. }
  1346. /*
  1347. BusLogic MultiMaster Host Adapters can be identified by their
  1348. model number and the major version number of their firmware
  1349. as follows:
  1350. 5.xx BusLogic "W" Series Host Adapters:
  1351. BT-948/958/958D
  1352. 4.xx BusLogic "C" Series Host Adapters:
  1353. BT-946C/956C/956CD/747C/757C/757CD/445C/545C/540CF
  1354. 3.xx BusLogic "S" Series Host Adapters:
  1355. BT-747S/747D/757S/757D/445S/545S/542D
  1356. BT-542B/742A (revision H)
  1357. 2.xx BusLogic "A" Series Host Adapters:
  1358. BT-542B/742A (revision G and below)
  1359. 0.xx AMI FastDisk VLB/EISA BusLogic Clone Host Adapter
  1360. */
  1361. /*
  1362. Save the Model Name and Host Adapter Name in the Host Adapter
  1363. structure.
  1364. */
  1365. tgt = adapter->model;
  1366. *tgt++ = 'B';
  1367. *tgt++ = 'T';
  1368. *tgt++ = '-';
  1369. for (i = 0; i < sizeof(model); i++) {
  1370. ch = model[i];
  1371. if (ch == ' ' || ch == '\0')
  1372. break;
  1373. *tgt++ = ch;
  1374. }
  1375. *tgt++ = '\0';
  1376. /*
  1377. Save the Firmware Version in the Host Adapter structure.
  1378. */
  1379. tgt = adapter->fw_ver;
  1380. *tgt++ = id.fw_ver_digit1;
  1381. *tgt++ = '.';
  1382. *tgt++ = id.fw_ver_digit2;
  1383. if (fw_ver_digit3 != ' ' && fw_ver_digit3 != '\0')
  1384. *tgt++ = fw_ver_digit3;
  1385. *tgt = '\0';
  1386. /*
  1387. Issue the Inquire Firmware Version Letter command.
  1388. */
  1389. if (strcmp(adapter->fw_ver, "3.3") >= 0) {
  1390. if (blogic_cmd(adapter, BLOGIC_INQ_FWVER_LETTER, NULL, 0,
  1391. &fw_ver_letter,
  1392. sizeof(fw_ver_letter)) != sizeof(fw_ver_letter))
  1393. return blogic_failure(adapter,
  1394. "INQUIRE FIRMWARE VERSION LETTER");
  1395. if (fw_ver_letter != ' ' && fw_ver_letter != '\0')
  1396. *tgt++ = fw_ver_letter;
  1397. *tgt = '\0';
  1398. }
  1399. /*
  1400. Save the Host Adapter SCSI ID in the Host Adapter structure.
  1401. */
  1402. adapter->scsi_id = config.id;
  1403. /*
  1404. Determine the Bus Type and save it in the Host Adapter structure,
  1405. determine and save the IRQ Channel if necessary, and determine
  1406. and save the DMA Channel for ISA Host Adapters.
  1407. */
  1408. adapter->adapter_bus_type =
  1409. blogic_adater_bus_types[adapter->model[3] - '4'];
  1410. if (adapter->irq_ch == 0) {
  1411. if (config.irq_ch9)
  1412. adapter->irq_ch = 9;
  1413. else if (config.irq_ch10)
  1414. adapter->irq_ch = 10;
  1415. else if (config.irq_ch11)
  1416. adapter->irq_ch = 11;
  1417. else if (config.irq_ch12)
  1418. adapter->irq_ch = 12;
  1419. else if (config.irq_ch14)
  1420. adapter->irq_ch = 14;
  1421. else if (config.irq_ch15)
  1422. adapter->irq_ch = 15;
  1423. }
  1424. if (adapter->adapter_bus_type == BLOGIC_ISA_BUS) {
  1425. if (config.dma_ch5)
  1426. adapter->dma_ch = 5;
  1427. else if (config.dma_ch6)
  1428. adapter->dma_ch = 6;
  1429. else if (config.dma_ch7)
  1430. adapter->dma_ch = 7;
  1431. }
  1432. /*
  1433. Determine whether Extended Translation is enabled and save it in
  1434. the Host Adapter structure.
  1435. */
  1436. georeg.all = blogic_rdgeom(adapter);
  1437. adapter->ext_trans_enable = georeg.gr.ext_trans_enable;
  1438. /*
  1439. Save the Scatter Gather Limits, Level Sensitive Interrupt flag, Wide
  1440. SCSI flag, Differential SCSI flag, SCAM Supported flag, and
  1441. Ultra SCSI flag in the Host Adapter structure.
  1442. */
  1443. adapter->adapter_sglimit = ext_setupinfo.sg_limit;
  1444. adapter->drvr_sglimit = adapter->adapter_sglimit;
  1445. if (adapter->adapter_sglimit > BLOGIC_SG_LIMIT)
  1446. adapter->drvr_sglimit = BLOGIC_SG_LIMIT;
  1447. if (ext_setupinfo.misc.level_int)
  1448. adapter->level_int = true;
  1449. adapter->wide = ext_setupinfo.wide;
  1450. adapter->differential = ext_setupinfo.differential;
  1451. adapter->scam = ext_setupinfo.scam;
  1452. adapter->ultra = ext_setupinfo.ultra;
  1453. /*
  1454. Determine whether Extended LUN Format CCBs are supported and save the
  1455. information in the Host Adapter structure.
  1456. */
  1457. if (adapter->fw_ver[0] == '5' || (adapter->fw_ver[0] == '4' &&
  1458. adapter->wide))
  1459. adapter->ext_lun = true;
  1460. /*
  1461. Issue the Inquire PCI Host Adapter Information command to read the
  1462. Termination Information from "W" series MultiMaster Host Adapters.
  1463. */
  1464. if (adapter->fw_ver[0] == '5') {
  1465. if (blogic_cmd(adapter, BLOGIC_INQ_PCI_INFO, NULL, 0,
  1466. &adapter_info,
  1467. sizeof(adapter_info)) != sizeof(adapter_info))
  1468. return blogic_failure(adapter,
  1469. "INQUIRE PCI HOST ADAPTER INFORMATION");
  1470. /*
  1471. Save the Termination Information in the Host Adapter
  1472. structure.
  1473. */
  1474. if (adapter_info.genericinfo_valid) {
  1475. adapter->terminfo_valid = true;
  1476. adapter->low_term = adapter_info.low_term;
  1477. adapter->high_term = adapter_info.high_term;
  1478. }
  1479. }
  1480. /*
  1481. Issue the Fetch Host Adapter Local RAM command to read the
  1482. AutoSCSI data from "W" and "C" series MultiMaster Host Adapters.
  1483. */
  1484. if (adapter->fw_ver[0] >= '4') {
  1485. fetch_localram.offset = BLOGIC_AUTOSCSI_BASE;
  1486. fetch_localram.count = sizeof(autoscsi);
  1487. if (blogic_cmd(adapter, BLOGIC_FETCH_LOCALRAM, &fetch_localram,
  1488. sizeof(fetch_localram), &autoscsi,
  1489. sizeof(autoscsi)) != sizeof(autoscsi))
  1490. return blogic_failure(adapter,
  1491. "FETCH HOST ADAPTER LOCAL RAM");
  1492. /*
  1493. Save the Parity Checking Enabled, Bus Reset Enabled,
  1494. and Termination Information in the Host Adapter structure.
  1495. */
  1496. adapter->parity = autoscsi.parity;
  1497. adapter->reset_enabled = autoscsi.reset_enabled;
  1498. if (adapter->fw_ver[0] == '4') {
  1499. adapter->terminfo_valid = true;
  1500. adapter->low_term = autoscsi.low_term;
  1501. adapter->high_term = autoscsi.high_term;
  1502. }
  1503. /*
  1504. Save the Wide Permitted, Fast Permitted, Synchronous
  1505. Permitted, Disconnect Permitted, Ultra Permitted, and
  1506. SCAM Information in the Host Adapter structure.
  1507. */
  1508. adapter->wide_ok = autoscsi.wide_ok;
  1509. adapter->fast_ok = autoscsi.fast_ok;
  1510. adapter->sync_ok = autoscsi.sync_ok;
  1511. adapter->discon_ok = autoscsi.discon_ok;
  1512. if (adapter->ultra)
  1513. adapter->ultra_ok = autoscsi.ultra_ok;
  1514. if (adapter->scam) {
  1515. adapter->scam_enabled = autoscsi.scam_enabled;
  1516. adapter->scam_lev2 = autoscsi.scam_lev2;
  1517. }
  1518. }
  1519. /*
  1520. Initialize fields in the Host Adapter structure for "S" and "A"
  1521. series MultiMaster Host Adapters.
  1522. */
  1523. if (adapter->fw_ver[0] < '4') {
  1524. if (setupinfo.sync) {
  1525. adapter->sync_ok = 0xFF;
  1526. if (adapter->adapter_bus_type == BLOGIC_EISA_BUS) {
  1527. if (ext_setupinfo.misc.fast_on_eisa)
  1528. adapter->fast_ok = 0xFF;
  1529. if (strcmp(adapter->model, "BT-757") == 0)
  1530. adapter->wide_ok = 0xFF;
  1531. }
  1532. }
  1533. adapter->discon_ok = 0xFF;
  1534. adapter->parity = setupinfo.parity;
  1535. adapter->reset_enabled = true;
  1536. }
  1537. /*
  1538. Determine the maximum number of Target IDs and Logical Units
  1539. supported by this driver for Wide and Narrow Host Adapters.
  1540. */
  1541. adapter->maxdev = (adapter->wide ? 16 : 8);
  1542. adapter->maxlun = (adapter->ext_lun ? 32 : 8);
  1543. /*
  1544. Select appropriate values for the Mailbox Count, Driver Queue Depth,
  1545. Initial CCBs, and Incremental CCBs variables based on whether
  1546. or not Strict Round Robin Mode is supported. If Strict Round
  1547. Robin Mode is supported, then there is no performance degradation
  1548. in using the maximum possible number of Outgoing and Incoming
  1549. Mailboxes and allowing the Tagged and Untagged Queue Depths to
  1550. determine the actual utilization. If Strict Round Robin Mode is
  1551. not supported, then the Host Adapter must scan all the Outgoing
  1552. Mailboxes whenever an Outgoing Mailbox entry is made, which can
  1553. cause a substantial performance penalty. The host adapters
  1554. actually have room to store the following number of CCBs
  1555. internally; that is, they can internally queue and manage this
  1556. many active commands on the SCSI bus simultaneously. Performance
  1557. measurements demonstrate that the Driver Queue Depth should be
  1558. set to the Mailbox Count, rather than the Host Adapter Queue
  1559. Depth (internal CCB capacity), as it is more efficient to have the
  1560. queued commands waiting in Outgoing Mailboxes if necessary than
  1561. to block the process in the higher levels of the SCSI Subsystem.
  1562. 192 BT-948/958/958D
  1563. 100 BT-946C/956C/956CD/747C/757C/757CD/445C
  1564. 50 BT-545C/540CF
  1565. 30 BT-747S/747D/757S/757D/445S/545S/542D/542B/742A
  1566. */
  1567. if (adapter->fw_ver[0] == '5')
  1568. adapter->adapter_qdepth = 192;
  1569. else if (adapter->fw_ver[0] == '4')
  1570. adapter->adapter_qdepth = (adapter->adapter_bus_type !=
  1571. BLOGIC_ISA_BUS ? 100 : 50);
  1572. else
  1573. adapter->adapter_qdepth = 30;
  1574. if (strcmp(adapter->fw_ver, "3.31") >= 0) {
  1575. adapter->strict_rr = true;
  1576. adapter->mbox_count = BLOGIC_MAX_MAILBOX;
  1577. } else {
  1578. adapter->strict_rr = false;
  1579. adapter->mbox_count = 32;
  1580. }
  1581. adapter->drvr_qdepth = adapter->mbox_count;
  1582. adapter->initccbs = 4 * BLOGIC_CCB_GRP_ALLOCSIZE;
  1583. adapter->inc_ccbs = BLOGIC_CCB_GRP_ALLOCSIZE;
  1584. /*
  1585. Tagged Queuing support is available and operates properly on
  1586. all "W" series MultiMaster Host Adapters, on "C" series
  1587. MultiMaster Host Adapters with firmware version 4.22 and above,
  1588. and on "S" series MultiMaster Host Adapters with firmware version
  1589. 3.35 and above.
  1590. */
  1591. adapter->tagq_ok = 0;
  1592. switch (adapter->fw_ver[0]) {
  1593. case '5':
  1594. adapter->tagq_ok = 0xFFFF;
  1595. break;
  1596. case '4':
  1597. if (strcmp(adapter->fw_ver, "4.22") >= 0)
  1598. adapter->tagq_ok = 0xFFFF;
  1599. break;
  1600. case '3':
  1601. if (strcmp(adapter->fw_ver, "3.35") >= 0)
  1602. adapter->tagq_ok = 0xFFFF;
  1603. break;
  1604. }
  1605. /*
  1606. Determine the Host Adapter BIOS Address if the BIOS is enabled and
  1607. save it in the Host Adapter structure. The BIOS is disabled if the
  1608. bios_addr is 0.
  1609. */
  1610. adapter->bios_addr = ext_setupinfo.bios_addr << 12;
  1611. /*
  1612. ISA Host Adapters require Bounce Buffers if there is more than
  1613. 16MB memory.
  1614. */
  1615. if (adapter->adapter_bus_type == BLOGIC_ISA_BUS &&
  1616. (void *) high_memory > (void *) MAX_DMA_ADDRESS)
  1617. adapter->need_bouncebuf = true;
  1618. /*
  1619. BusLogic BT-445S Host Adapters prior to board revision E have a
  1620. hardware bug whereby when the BIOS is enabled, transfers to/from
  1621. the same address range the BIOS occupies modulo 16MB are handled
  1622. incorrectly. Only properly functioning BT-445S Host Adapters
  1623. have firmware version 3.37, so require that ISA Bounce Buffers
  1624. be used for the buggy BT-445S models if there is more than 16MB
  1625. memory.
  1626. */
  1627. if (adapter->bios_addr > 0 && strcmp(adapter->model, "BT-445S") == 0 &&
  1628. strcmp(adapter->fw_ver, "3.37") < 0 &&
  1629. (void *) high_memory > (void *) MAX_DMA_ADDRESS)
  1630. adapter->need_bouncebuf = true;
  1631. /*
  1632. Initialize parameters common to MultiMaster and FlashPoint
  1633. Host Adapters.
  1634. */
  1635. common:
  1636. /*
  1637. Initialize the Host Adapter Full Model Name from the Model Name.
  1638. */
  1639. strcpy(adapter->full_model, "BusLogic ");
  1640. strcat(adapter->full_model, adapter->model);
  1641. /*
  1642. Select an appropriate value for the Tagged Queue Depth either from a
  1643. BusLogic Driver Options specification, or based on whether this Host
  1644. Adapter requires that ISA Bounce Buffers be used. The Tagged Queue
  1645. Depth is left at 0 for automatic determination in
  1646. BusLogic_SelectQueueDepths. Initialize the Untagged Queue Depth.
  1647. */
  1648. for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++) {
  1649. unsigned char qdepth = 0;
  1650. if (adapter->drvr_opts != NULL &&
  1651. adapter->drvr_opts->qdepth[tgt_id] > 0)
  1652. qdepth = adapter->drvr_opts->qdepth[tgt_id];
  1653. else if (adapter->need_bouncebuf)
  1654. qdepth = BLOGIC_TAG_DEPTH_BB;
  1655. adapter->qdepth[tgt_id] = qdepth;
  1656. }
  1657. if (adapter->need_bouncebuf)
  1658. adapter->untag_qdepth = BLOGIC_UNTAG_DEPTH_BB;
  1659. else
  1660. adapter->untag_qdepth = BLOGIC_UNTAG_DEPTH;
  1661. if (adapter->drvr_opts != NULL)
  1662. adapter->common_qdepth = adapter->drvr_opts->common_qdepth;
  1663. if (adapter->common_qdepth > 0 &&
  1664. adapter->common_qdepth < adapter->untag_qdepth)
  1665. adapter->untag_qdepth = adapter->common_qdepth;
  1666. /*
  1667. Tagged Queuing is only allowed if Disconnect/Reconnect is permitted.
  1668. Therefore, mask the Tagged Queuing Permitted Default bits with the
  1669. Disconnect/Reconnect Permitted bits.
  1670. */
  1671. adapter->tagq_ok &= adapter->discon_ok;
  1672. /*
  1673. Combine the default Tagged Queuing Permitted bits with any
  1674. BusLogic Driver Options Tagged Queuing specification.
  1675. */
  1676. if (adapter->drvr_opts != NULL)
  1677. adapter->tagq_ok = (adapter->drvr_opts->tagq_ok &
  1678. adapter->drvr_opts->tagq_ok_mask) |
  1679. (adapter->tagq_ok & ~adapter->drvr_opts->tagq_ok_mask);
  1680. /*
  1681. Select an appropriate value for Bus Settle Time either from a
  1682. BusLogic Driver Options specification, or from
  1683. BLOGIC_BUS_SETTLE_TIME.
  1684. */
  1685. if (adapter->drvr_opts != NULL &&
  1686. adapter->drvr_opts->bus_settle_time > 0)
  1687. adapter->bus_settle_time = adapter->drvr_opts->bus_settle_time;
  1688. else
  1689. adapter->bus_settle_time = BLOGIC_BUS_SETTLE_TIME;
  1690. /*
  1691. Indicate reading the Host Adapter Configuration completed
  1692. successfully.
  1693. */
  1694. return true;
  1695. }
  1696. /*
  1697. blogic_reportconfig reports the configuration of Host Adapter.
  1698. */
  1699. static bool __init blogic_reportconfig(struct blogic_adapter *adapter)
  1700. {
  1701. unsigned short alltgt_mask = (1 << adapter->maxdev) - 1;
  1702. unsigned short sync_ok, fast_ok;
  1703. unsigned short ultra_ok, wide_ok;
  1704. unsigned short discon_ok, tagq_ok;
  1705. bool common_syncneg, common_tagq_depth;
  1706. char syncstr[BLOGIC_MAXDEV + 1];
  1707. char widestr[BLOGIC_MAXDEV + 1];
  1708. char discon_str[BLOGIC_MAXDEV + 1];
  1709. char tagq_str[BLOGIC_MAXDEV + 1];
  1710. char *syncmsg = syncstr;
  1711. char *widemsg = widestr;
  1712. char *discon_msg = discon_str;
  1713. char *tagq_msg = tagq_str;
  1714. int tgt_id;
  1715. blogic_info("Configuring BusLogic Model %s %s%s%s%s SCSI Host Adapter\n", adapter, adapter->model, blogic_adapter_busnames[adapter->adapter_bus_type], (adapter->wide ? " Wide" : ""), (adapter->differential ? " Differential" : ""), (adapter->ultra ? " Ultra" : ""));
  1716. blogic_info(" Firmware Version: %s, I/O Address: 0x%X, " "IRQ Channel: %d/%s\n", adapter, adapter->fw_ver, adapter->io_addr, adapter->irq_ch, (adapter->level_int ? "Level" : "Edge"));
  1717. if (adapter->adapter_bus_type != BLOGIC_PCI_BUS) {
  1718. blogic_info(" DMA Channel: ", adapter);
  1719. if (adapter->dma_ch > 0)
  1720. blogic_info("%d, ", adapter, adapter->dma_ch);
  1721. else
  1722. blogic_info("None, ", adapter);
  1723. if (adapter->bios_addr > 0)
  1724. blogic_info("BIOS Address: 0x%X, ", adapter,
  1725. adapter->bios_addr);
  1726. else
  1727. blogic_info("BIOS Address: None, ", adapter);
  1728. } else {
  1729. blogic_info(" PCI Bus: %d, Device: %d, Address: ", adapter,
  1730. adapter->bus, adapter->dev);
  1731. if (adapter->pci_addr > 0)
  1732. blogic_info("0x%X, ", adapter, adapter->pci_addr);
  1733. else
  1734. blogic_info("Unassigned, ", adapter);
  1735. }
  1736. blogic_info("Host Adapter SCSI ID: %d\n", adapter, adapter->scsi_id);
  1737. blogic_info(" Parity Checking: %s, Extended Translation: %s\n",
  1738. adapter, (adapter->parity ? "Enabled" : "Disabled"),
  1739. (adapter->ext_trans_enable ? "Enabled" : "Disabled"));
  1740. alltgt_mask &= ~(1 << adapter->scsi_id);
  1741. sync_ok = adapter->sync_ok & alltgt_mask;
  1742. fast_ok = adapter->fast_ok & alltgt_mask;
  1743. ultra_ok = adapter->ultra_ok & alltgt_mask;
  1744. if ((blogic_multimaster_type(adapter) &&
  1745. (adapter->fw_ver[0] >= '4' ||
  1746. adapter->adapter_bus_type == BLOGIC_EISA_BUS)) ||
  1747. blogic_flashpoint_type(adapter)) {
  1748. common_syncneg = false;
  1749. if (sync_ok == 0) {
  1750. syncmsg = "Disabled";
  1751. common_syncneg = true;
  1752. } else if (sync_ok == alltgt_mask) {
  1753. if (fast_ok == 0) {
  1754. syncmsg = "Slow";
  1755. common_syncneg = true;
  1756. } else if (fast_ok == alltgt_mask) {
  1757. if (ultra_ok == 0) {
  1758. syncmsg = "Fast";
  1759. common_syncneg = true;
  1760. } else if (ultra_ok == alltgt_mask) {
  1761. syncmsg = "Ultra";
  1762. common_syncneg = true;
  1763. }
  1764. }
  1765. }
  1766. if (!common_syncneg) {
  1767. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  1768. syncstr[tgt_id] = ((!(sync_ok & (1 << tgt_id))) ? 'N' : (!(fast_ok & (1 << tgt_id)) ? 'S' : (!(ultra_ok & (1 << tgt_id)) ? 'F' : 'U')));
  1769. syncstr[adapter->scsi_id] = '#';
  1770. syncstr[adapter->maxdev] = '\0';
  1771. }
  1772. } else
  1773. syncmsg = (sync_ok == 0 ? "Disabled" : "Enabled");
  1774. wide_ok = adapter->wide_ok & alltgt_mask;
  1775. if (wide_ok == 0)
  1776. widemsg = "Disabled";
  1777. else if (wide_ok == alltgt_mask)
  1778. widemsg = "Enabled";
  1779. else {
  1780. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  1781. widestr[tgt_id] = ((wide_ok & (1 << tgt_id)) ? 'Y' : 'N');
  1782. widestr[adapter->scsi_id] = '#';
  1783. widestr[adapter->maxdev] = '\0';
  1784. }
  1785. discon_ok = adapter->discon_ok & alltgt_mask;
  1786. if (discon_ok == 0)
  1787. discon_msg = "Disabled";
  1788. else if (discon_ok == alltgt_mask)
  1789. discon_msg = "Enabled";
  1790. else {
  1791. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  1792. discon_str[tgt_id] = ((discon_ok & (1 << tgt_id)) ? 'Y' : 'N');
  1793. discon_str[adapter->scsi_id] = '#';
  1794. discon_str[adapter->maxdev] = '\0';
  1795. }
  1796. tagq_ok = adapter->tagq_ok & alltgt_mask;
  1797. if (tagq_ok == 0)
  1798. tagq_msg = "Disabled";
  1799. else if (tagq_ok == alltgt_mask)
  1800. tagq_msg = "Enabled";
  1801. else {
  1802. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  1803. tagq_str[tgt_id] = ((tagq_ok & (1 << tgt_id)) ? 'Y' : 'N');
  1804. tagq_str[adapter->scsi_id] = '#';
  1805. tagq_str[adapter->maxdev] = '\0';
  1806. }
  1807. blogic_info(" Synchronous Negotiation: %s, Wide Negotiation: %s\n",
  1808. adapter, syncmsg, widemsg);
  1809. blogic_info(" Disconnect/Reconnect: %s, Tagged Queuing: %s\n", adapter,
  1810. discon_msg, tagq_msg);
  1811. if (blogic_multimaster_type(adapter)) {
  1812. blogic_info(" Scatter/Gather Limit: %d of %d segments, " "Mailboxes: %d\n", adapter, adapter->drvr_sglimit, adapter->adapter_sglimit, adapter->mbox_count);
  1813. blogic_info(" Driver Queue Depth: %d, " "Host Adapter Queue Depth: %d\n", adapter, adapter->drvr_qdepth, adapter->adapter_qdepth);
  1814. } else
  1815. blogic_info(" Driver Queue Depth: %d, " "Scatter/Gather Limit: %d segments\n", adapter, adapter->drvr_qdepth, adapter->drvr_sglimit);
  1816. blogic_info(" Tagged Queue Depth: ", adapter);
  1817. common_tagq_depth = true;
  1818. for (tgt_id = 1; tgt_id < adapter->maxdev; tgt_id++)
  1819. if (adapter->qdepth[tgt_id] != adapter->qdepth[0]) {
  1820. common_tagq_depth = false;
  1821. break;
  1822. }
  1823. if (common_tagq_depth) {
  1824. if (adapter->qdepth[0] > 0)
  1825. blogic_info("%d", adapter, adapter->qdepth[0]);
  1826. else
  1827. blogic_info("Automatic", adapter);
  1828. } else
  1829. blogic_info("Individual", adapter);
  1830. blogic_info(", Untagged Queue Depth: %d\n", adapter,
  1831. adapter->untag_qdepth);
  1832. if (adapter->terminfo_valid) {
  1833. if (adapter->wide)
  1834. blogic_info(" SCSI Bus Termination: %s", adapter,
  1835. (adapter->low_term ? (adapter->high_term ? "Both Enabled" : "Low Enabled") : (adapter->high_term ? "High Enabled" : "Both Disabled")));
  1836. else
  1837. blogic_info(" SCSI Bus Termination: %s", adapter,
  1838. (adapter->low_term ? "Enabled" : "Disabled"));
  1839. if (adapter->scam)
  1840. blogic_info(", SCAM: %s", adapter,
  1841. (adapter->scam_enabled ? (adapter->scam_lev2 ? "Enabled, Level 2" : "Enabled, Level 1") : "Disabled"));
  1842. blogic_info("\n", adapter);
  1843. }
  1844. /*
  1845. Indicate reporting the Host Adapter configuration completed
  1846. successfully.
  1847. */
  1848. return true;
  1849. }
  1850. /*
  1851. blogic_getres acquires the system resources necessary to use
  1852. Host Adapter.
  1853. */
  1854. static bool __init blogic_getres(struct blogic_adapter *adapter)
  1855. {
  1856. if (adapter->irq_ch == 0) {
  1857. blogic_err("NO LEGAL INTERRUPT CHANNEL ASSIGNED - DETACHING\n",
  1858. adapter);
  1859. return false;
  1860. }
  1861. /*
  1862. Acquire shared access to the IRQ Channel.
  1863. */
  1864. if (request_irq(adapter->irq_ch, blogic_inthandler, IRQF_SHARED,
  1865. adapter->full_model, adapter) < 0) {
  1866. blogic_err("UNABLE TO ACQUIRE IRQ CHANNEL %d - DETACHING\n",
  1867. adapter, adapter->irq_ch);
  1868. return false;
  1869. }
  1870. adapter->irq_acquired = true;
  1871. /*
  1872. Acquire exclusive access to the DMA Channel.
  1873. */
  1874. if (adapter->dma_ch > 0) {
  1875. if (request_dma(adapter->dma_ch, adapter->full_model) < 0) {
  1876. blogic_err("UNABLE TO ACQUIRE DMA CHANNEL %d - DETACHING\n", adapter, adapter->dma_ch);
  1877. return false;
  1878. }
  1879. set_dma_mode(adapter->dma_ch, DMA_MODE_CASCADE);
  1880. enable_dma(adapter->dma_ch);
  1881. adapter->dma_chan_acquired = true;
  1882. }
  1883. /*
  1884. Indicate the System Resource Acquisition completed successfully,
  1885. */
  1886. return true;
  1887. }
  1888. /*
  1889. blogic_relres releases any system resources previously acquired
  1890. by blogic_getres.
  1891. */
  1892. static void blogic_relres(struct blogic_adapter *adapter)
  1893. {
  1894. /*
  1895. Release shared access to the IRQ Channel.
  1896. */
  1897. if (adapter->irq_acquired)
  1898. free_irq(adapter->irq_ch, adapter);
  1899. /*
  1900. Release exclusive access to the DMA Channel.
  1901. */
  1902. if (adapter->dma_chan_acquired)
  1903. free_dma(adapter->dma_ch);
  1904. /*
  1905. Release any allocated memory structs not released elsewhere
  1906. */
  1907. if (adapter->mbox_space)
  1908. pci_free_consistent(adapter->pci_device, adapter->mbox_sz,
  1909. adapter->mbox_space, adapter->mbox_space_handle);
  1910. pci_dev_put(adapter->pci_device);
  1911. adapter->mbox_space = NULL;
  1912. adapter->mbox_space_handle = 0;
  1913. adapter->mbox_sz = 0;
  1914. }
  1915. /*
  1916. blogic_initadapter initializes Host Adapter. This is the only
  1917. function called during SCSI Host Adapter detection which modifies the state
  1918. of the Host Adapter from its initial power on or hard reset state.
  1919. */
  1920. static bool blogic_initadapter(struct blogic_adapter *adapter)
  1921. {
  1922. struct blogic_extmbox_req extmbox_req;
  1923. enum blogic_rr_req rr_req;
  1924. enum blogic_setccb_fmt setccb_fmt;
  1925. int tgt_id;
  1926. /*
  1927. Initialize the pointers to the first and last CCBs that are
  1928. queued for completion processing.
  1929. */
  1930. adapter->firstccb = NULL;
  1931. adapter->lastccb = NULL;
  1932. /*
  1933. Initialize the Bus Device Reset Pending CCB, Tagged Queuing Active,
  1934. Command Successful Flag, Active Commands, and Commands Since Reset
  1935. for each Target Device.
  1936. */
  1937. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) {
  1938. adapter->bdr_pend[tgt_id] = NULL;
  1939. adapter->tgt_flags[tgt_id].tagq_active = false;
  1940. adapter->tgt_flags[tgt_id].cmd_good = false;
  1941. adapter->active_cmds[tgt_id] = 0;
  1942. adapter->cmds_since_rst[tgt_id] = 0;
  1943. }
  1944. /*
  1945. FlashPoint Host Adapters do not use Outgoing and Incoming Mailboxes.
  1946. */
  1947. if (blogic_flashpoint_type(adapter))
  1948. goto done;
  1949. /*
  1950. Initialize the Outgoing and Incoming Mailbox pointers.
  1951. */
  1952. adapter->mbox_sz = adapter->mbox_count * (sizeof(struct blogic_outbox) + sizeof(struct blogic_inbox));
  1953. adapter->mbox_space = pci_alloc_consistent(adapter->pci_device,
  1954. adapter->mbox_sz, &adapter->mbox_space_handle);
  1955. if (adapter->mbox_space == NULL)
  1956. return blogic_failure(adapter, "MAILBOX ALLOCATION");
  1957. adapter->first_outbox = (struct blogic_outbox *) adapter->mbox_space;
  1958. adapter->last_outbox = adapter->first_outbox + adapter->mbox_count - 1;
  1959. adapter->next_outbox = adapter->first_outbox;
  1960. adapter->first_inbox = (struct blogic_inbox *) (adapter->last_outbox + 1);
  1961. adapter->last_inbox = adapter->first_inbox + adapter->mbox_count - 1;
  1962. adapter->next_inbox = adapter->first_inbox;
  1963. /*
  1964. Initialize the Outgoing and Incoming Mailbox structures.
  1965. */
  1966. memset(adapter->first_outbox, 0,
  1967. adapter->mbox_count * sizeof(struct blogic_outbox));
  1968. memset(adapter->first_inbox, 0,
  1969. adapter->mbox_count * sizeof(struct blogic_inbox));
  1970. /*
  1971. Initialize the Host Adapter's Pointer to the Outgoing/Incoming
  1972. Mailboxes.
  1973. */
  1974. extmbox_req.mbox_count = adapter->mbox_count;
  1975. extmbox_req.base_mbox_addr = (u32) adapter->mbox_space_handle;
  1976. if (blogic_cmd(adapter, BLOGIC_INIT_EXT_MBOX, &extmbox_req,
  1977. sizeof(extmbox_req), NULL, 0) < 0)
  1978. return blogic_failure(adapter, "MAILBOX INITIALIZATION");
  1979. /*
  1980. Enable Strict Round Robin Mode if supported by the Host Adapter. In
  1981. Strict Round Robin Mode, the Host Adapter only looks at the next
  1982. Outgoing Mailbox for each new command, rather than scanning
  1983. through all the Outgoing Mailboxes to find any that have new
  1984. commands in them. Strict Round Robin Mode is significantly more
  1985. efficient.
  1986. */
  1987. if (adapter->strict_rr) {
  1988. rr_req = BLOGIC_STRICT_RR_MODE;
  1989. if (blogic_cmd(adapter, BLOGIC_STRICT_RR, &rr_req,
  1990. sizeof(rr_req), NULL, 0) < 0)
  1991. return blogic_failure(adapter,
  1992. "ENABLE STRICT ROUND ROBIN MODE");
  1993. }
  1994. /*
  1995. For Host Adapters that support Extended LUN Format CCBs, issue the
  1996. Set CCB Format command to allow 32 Logical Units per Target Device.
  1997. */
  1998. if (adapter->ext_lun) {
  1999. setccb_fmt = BLOGIC_EXT_LUN_CCB;
  2000. if (blogic_cmd(adapter, BLOGIC_SETCCB_FMT, &setccb_fmt,
  2001. sizeof(setccb_fmt), NULL, 0) < 0)
  2002. return blogic_failure(adapter, "SET CCB FORMAT");
  2003. }
  2004. /*
  2005. Announce Successful Initialization.
  2006. */
  2007. done:
  2008. if (!adapter->adapter_initd) {
  2009. blogic_info("*** %s Initialized Successfully ***\n", adapter,
  2010. adapter->full_model);
  2011. blogic_info("\n", adapter);
  2012. } else
  2013. blogic_warn("*** %s Initialized Successfully ***\n", adapter,
  2014. adapter->full_model);
  2015. adapter->adapter_initd = true;
  2016. /*
  2017. Indicate the Host Adapter Initialization completed successfully.
  2018. */
  2019. return true;
  2020. }
  2021. /*
  2022. blogic_inquiry inquires about the Target Devices accessible
  2023. through Host Adapter.
  2024. */
  2025. static bool __init blogic_inquiry(struct blogic_adapter *adapter)
  2026. {
  2027. u16 installed_devs;
  2028. u8 installed_devs0to7[8];
  2029. struct blogic_setup_info setupinfo;
  2030. u8 sync_period[BLOGIC_MAXDEV];
  2031. unsigned char req_replylen;
  2032. int tgt_id;
  2033. /*
  2034. Wait a few seconds between the Host Adapter Hard Reset which
  2035. initiates a SCSI Bus Reset and issuing any SCSI Commands. Some
  2036. SCSI devices get confused if they receive SCSI Commands too soon
  2037. after a SCSI Bus Reset.
  2038. */
  2039. blogic_delay(adapter->bus_settle_time);
  2040. /*
  2041. FlashPoint Host Adapters do not provide for Target Device Inquiry.
  2042. */
  2043. if (blogic_flashpoint_type(adapter))
  2044. return true;
  2045. /*
  2046. Inhibit the Target Device Inquiry if requested.
  2047. */
  2048. if (adapter->drvr_opts != NULL && adapter->drvr_opts->stop_tgt_inquiry)
  2049. return true;
  2050. /*
  2051. Issue the Inquire Target Devices command for host adapters with
  2052. firmware version 4.25 or later, or the Inquire Installed Devices
  2053. ID 0 to 7 command for older host adapters. This is necessary to
  2054. force Synchronous Transfer Negotiation so that the Inquire Setup
  2055. Information and Inquire Synchronous Period commands will return
  2056. valid data. The Inquire Target Devices command is preferable to
  2057. Inquire Installed Devices ID 0 to 7 since it only probes Logical
  2058. Unit 0 of each Target Device.
  2059. */
  2060. if (strcmp(adapter->fw_ver, "4.25") >= 0) {
  2061. /*
  2062. Issue a Inquire Target Devices command. Inquire Target
  2063. Devices only tests Logical Unit 0 of each Target Device
  2064. unlike the Inquire Installed Devices commands which test
  2065. Logical Units 0 - 7. Two bytes are returned, where byte
  2066. 0 bit 0 set indicates that Target Device 0 exists, and so on.
  2067. */
  2068. if (blogic_cmd(adapter, BLOGIC_INQ_DEV, NULL, 0,
  2069. &installed_devs, sizeof(installed_devs))
  2070. != sizeof(installed_devs))
  2071. return blogic_failure(adapter, "INQUIRE TARGET DEVICES");
  2072. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  2073. adapter->tgt_flags[tgt_id].tgt_exists =
  2074. (installed_devs & (1 << tgt_id) ? true : false);
  2075. } else {
  2076. /*
  2077. Issue an Inquire Installed Devices command. For each
  2078. Target Device, a byte is returned where bit 0 set
  2079. indicates that Logical Unit 0 * exists, bit 1 set
  2080. indicates that Logical Unit 1 exists, and so on.
  2081. */
  2082. if (blogic_cmd(adapter, BLOGIC_INQ_DEV0TO7, NULL, 0,
  2083. &installed_devs0to7, sizeof(installed_devs0to7))
  2084. != sizeof(installed_devs0to7))
  2085. return blogic_failure(adapter,
  2086. "INQUIRE INSTALLED DEVICES ID 0 TO 7");
  2087. for (tgt_id = 0; tgt_id < 8; tgt_id++)
  2088. adapter->tgt_flags[tgt_id].tgt_exists =
  2089. (installed_devs0to7[tgt_id] != 0 ? true : false);
  2090. }
  2091. /*
  2092. Issue the Inquire Setup Information command.
  2093. */
  2094. req_replylen = sizeof(setupinfo);
  2095. if (blogic_cmd(adapter, BLOGIC_INQ_SETUPINFO, &req_replylen,
  2096. sizeof(req_replylen), &setupinfo, sizeof(setupinfo))
  2097. != sizeof(setupinfo))
  2098. return blogic_failure(adapter, "INQUIRE SETUP INFORMATION");
  2099. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  2100. adapter->sync_offset[tgt_id] = (tgt_id < 8 ? setupinfo.sync0to7[tgt_id].offset : setupinfo.sync8to15[tgt_id - 8].offset);
  2101. if (strcmp(adapter->fw_ver, "5.06L") >= 0)
  2102. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  2103. adapter->tgt_flags[tgt_id].wide_active = (tgt_id < 8 ? (setupinfo.wide_tx_active0to7 & (1 << tgt_id) ? true : false) : (setupinfo.wide_tx_active8to15 & (1 << (tgt_id - 8)) ? true : false));
  2104. /*
  2105. Issue the Inquire Synchronous Period command.
  2106. */
  2107. if (adapter->fw_ver[0] >= '3') {
  2108. /* Issue a Inquire Synchronous Period command. For each
  2109. Target Device, a byte is returned which represents the
  2110. Synchronous Transfer Period in units of 10 nanoseconds.
  2111. */
  2112. req_replylen = sizeof(sync_period);
  2113. if (blogic_cmd(adapter, BLOGIC_INQ_SYNC_PERIOD, &req_replylen,
  2114. sizeof(req_replylen), &sync_period,
  2115. sizeof(sync_period)) != sizeof(sync_period))
  2116. return blogic_failure(adapter,
  2117. "INQUIRE SYNCHRONOUS PERIOD");
  2118. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  2119. adapter->sync_period[tgt_id] = sync_period[tgt_id];
  2120. } else
  2121. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  2122. if (setupinfo.sync0to7[tgt_id].offset > 0)
  2123. adapter->sync_period[tgt_id] = 20 + 5 * setupinfo.sync0to7[tgt_id].tx_period;
  2124. /*
  2125. Indicate the Target Device Inquiry completed successfully.
  2126. */
  2127. return true;
  2128. }
  2129. /*
  2130. blogic_inithoststruct initializes the fields in the SCSI Host
  2131. structure. The base, io_port, n_io_ports, irq, and dma_channel fields in the
  2132. SCSI Host structure are intentionally left uninitialized, as this driver
  2133. handles acquisition and release of these resources explicitly, as well as
  2134. ensuring exclusive access to the Host Adapter hardware and data structures
  2135. through explicit acquisition and release of the Host Adapter's Lock.
  2136. */
  2137. static void __init blogic_inithoststruct(struct blogic_adapter *adapter,
  2138. struct Scsi_Host *host)
  2139. {
  2140. host->max_id = adapter->maxdev;
  2141. host->max_lun = adapter->maxlun;
  2142. host->max_channel = 0;
  2143. host->unique_id = adapter->io_addr;
  2144. host->this_id = adapter->scsi_id;
  2145. host->can_queue = adapter->drvr_qdepth;
  2146. host->sg_tablesize = adapter->drvr_sglimit;
  2147. host->unchecked_isa_dma = adapter->need_bouncebuf;
  2148. host->cmd_per_lun = adapter->untag_qdepth;
  2149. }
  2150. /*
  2151. blogic_slaveconfig will actually set the queue depth on individual
  2152. scsi devices as they are permanently added to the device chain. We
  2153. shamelessly rip off the SelectQueueDepths code to make this work mostly
  2154. like it used to. Since we don't get called once at the end of the scan
  2155. but instead get called for each device, we have to do things a bit
  2156. differently.
  2157. */
  2158. static int blogic_slaveconfig(struct scsi_device *dev)
  2159. {
  2160. struct blogic_adapter *adapter =
  2161. (struct blogic_adapter *) dev->host->hostdata;
  2162. int tgt_id = dev->id;
  2163. int qdepth = adapter->qdepth[tgt_id];
  2164. if (adapter->tgt_flags[tgt_id].tagq_ok &&
  2165. (adapter->tagq_ok & (1 << tgt_id))) {
  2166. if (qdepth == 0)
  2167. qdepth = BLOGIC_MAX_AUTO_TAG_DEPTH;
  2168. adapter->qdepth[tgt_id] = qdepth;
  2169. scsi_adjust_queue_depth(dev, MSG_SIMPLE_TAG, qdepth);
  2170. } else {
  2171. adapter->tagq_ok &= ~(1 << tgt_id);
  2172. qdepth = adapter->untag_qdepth;
  2173. adapter->qdepth[tgt_id] = qdepth;
  2174. scsi_adjust_queue_depth(dev, 0, qdepth);
  2175. }
  2176. qdepth = 0;
  2177. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++)
  2178. if (adapter->tgt_flags[tgt_id].tgt_exists)
  2179. qdepth += adapter->qdepth[tgt_id];
  2180. if (qdepth > adapter->alloc_ccbs)
  2181. blogic_create_addlccbs(adapter, qdepth - adapter->alloc_ccbs,
  2182. false);
  2183. return 0;
  2184. }
  2185. /*
  2186. blogic_init probes for BusLogic Host Adapters at the standard
  2187. I/O Addresses where they may be located, initializing, registering, and
  2188. reporting the configuration of each BusLogic Host Adapter it finds. It
  2189. returns the number of BusLogic Host Adapters successfully initialized and
  2190. registered.
  2191. */
  2192. static int __init blogic_init(void)
  2193. {
  2194. int adapter_count = 0, drvr_optindex = 0, probeindex;
  2195. struct blogic_adapter *adapter;
  2196. int ret = 0;
  2197. #ifdef MODULE
  2198. if (BusLogic)
  2199. blogic_setup(BusLogic);
  2200. #endif
  2201. if (blogic_probe_options.noprobe)
  2202. return -ENODEV;
  2203. blogic_probeinfo_list =
  2204. kzalloc(BLOGIC_MAX_ADAPTERS * sizeof(struct blogic_probeinfo),
  2205. GFP_KERNEL);
  2206. if (blogic_probeinfo_list == NULL) {
  2207. blogic_err("BusLogic: Unable to allocate Probe Info List\n",
  2208. NULL);
  2209. return -ENOMEM;
  2210. }
  2211. adapter = kzalloc(sizeof(struct blogic_adapter), GFP_KERNEL);
  2212. if (adapter == NULL) {
  2213. kfree(blogic_probeinfo_list);
  2214. blogic_err("BusLogic: Unable to allocate Prototype Host Adapter\n", NULL);
  2215. return -ENOMEM;
  2216. }
  2217. #ifdef MODULE
  2218. if (BusLogic != NULL)
  2219. blogic_setup(BusLogic);
  2220. #endif
  2221. blogic_init_probeinfo_list(adapter);
  2222. for (probeindex = 0; probeindex < blogic_probeinfo_count; probeindex++) {
  2223. struct blogic_probeinfo *probeinfo =
  2224. &blogic_probeinfo_list[probeindex];
  2225. struct blogic_adapter *myadapter = adapter;
  2226. struct Scsi_Host *host;
  2227. if (probeinfo->io_addr == 0)
  2228. continue;
  2229. memset(myadapter, 0, sizeof(struct blogic_adapter));
  2230. myadapter->adapter_type = probeinfo->adapter_type;
  2231. myadapter->adapter_bus_type = probeinfo->adapter_bus_type;
  2232. myadapter->io_addr = probeinfo->io_addr;
  2233. myadapter->pci_addr = probeinfo->pci_addr;
  2234. myadapter->bus = probeinfo->bus;
  2235. myadapter->dev = probeinfo->dev;
  2236. myadapter->pci_device = probeinfo->pci_device;
  2237. myadapter->irq_ch = probeinfo->irq_ch;
  2238. myadapter->addr_count =
  2239. blogic_adapter_addr_count[myadapter->adapter_type];
  2240. /*
  2241. Make sure region is free prior to probing.
  2242. */
  2243. if (!request_region(myadapter->io_addr, myadapter->addr_count,
  2244. "BusLogic"))
  2245. continue;
  2246. /*
  2247. Probe the Host Adapter. If unsuccessful, abort further
  2248. initialization.
  2249. */
  2250. if (!blogic_probe(myadapter)) {
  2251. release_region(myadapter->io_addr,
  2252. myadapter->addr_count);
  2253. continue;
  2254. }
  2255. /*
  2256. Hard Reset the Host Adapter. If unsuccessful, abort further
  2257. initialization.
  2258. */
  2259. if (!blogic_hwreset(myadapter, true)) {
  2260. release_region(myadapter->io_addr,
  2261. myadapter->addr_count);
  2262. continue;
  2263. }
  2264. /*
  2265. Check the Host Adapter. If unsuccessful, abort further
  2266. initialization.
  2267. */
  2268. if (!blogic_checkadapter(myadapter)) {
  2269. release_region(myadapter->io_addr,
  2270. myadapter->addr_count);
  2271. continue;
  2272. }
  2273. /*
  2274. Initialize the Driver Options field if provided.
  2275. */
  2276. if (drvr_optindex < blogic_drvr_options_count)
  2277. myadapter->drvr_opts =
  2278. &blogic_drvr_options[drvr_optindex++];
  2279. /*
  2280. Announce the Driver Version and Date, Author's Name,
  2281. Copyright Notice, and Electronic Mail Address.
  2282. */
  2283. blogic_announce_drvr(myadapter);
  2284. /*
  2285. Register the SCSI Host structure.
  2286. */
  2287. host = scsi_host_alloc(&blogic_template,
  2288. sizeof(struct blogic_adapter));
  2289. if (host == NULL) {
  2290. release_region(myadapter->io_addr,
  2291. myadapter->addr_count);
  2292. continue;
  2293. }
  2294. myadapter = (struct blogic_adapter *) host->hostdata;
  2295. memcpy(myadapter, adapter, sizeof(struct blogic_adapter));
  2296. myadapter->scsi_host = host;
  2297. myadapter->host_no = host->host_no;
  2298. /*
  2299. Add Host Adapter to the end of the list of registered
  2300. BusLogic Host Adapters.
  2301. */
  2302. list_add_tail(&myadapter->host_list, &blogic_host_list);
  2303. /*
  2304. Read the Host Adapter Configuration, Configure the Host
  2305. Adapter, Acquire the System Resources necessary to use
  2306. the Host Adapter, then Create the Initial CCBs, Initialize
  2307. the Host Adapter, and finally perform Target Device
  2308. Inquiry. From this point onward, any failure will be
  2309. assumed to be due to a problem with the Host Adapter,
  2310. rather than due to having mistakenly identified this port
  2311. as belonging to a BusLogic Host Adapter. The I/O Address
  2312. range will not be released, thereby preventing it from
  2313. being incorrectly identified as any other type of Host
  2314. Adapter.
  2315. */
  2316. if (blogic_rdconfig(myadapter) &&
  2317. blogic_reportconfig(myadapter) &&
  2318. blogic_getres(myadapter) &&
  2319. blogic_create_initccbs(myadapter) &&
  2320. blogic_initadapter(myadapter) &&
  2321. blogic_inquiry(myadapter)) {
  2322. /*
  2323. Initialization has been completed successfully.
  2324. Release and re-register usage of the I/O Address
  2325. range so that the Model Name of the Host Adapter
  2326. will appear, and initialize the SCSI Host structure.
  2327. */
  2328. release_region(myadapter->io_addr,
  2329. myadapter->addr_count);
  2330. if (!request_region(myadapter->io_addr,
  2331. myadapter->addr_count,
  2332. myadapter->full_model)) {
  2333. printk(KERN_WARNING
  2334. "BusLogic: Release and re-register of "
  2335. "port 0x%04lx failed \n",
  2336. (unsigned long)myadapter->io_addr);
  2337. blogic_destroy_ccbs(myadapter);
  2338. blogic_relres(myadapter);
  2339. list_del(&myadapter->host_list);
  2340. scsi_host_put(host);
  2341. ret = -ENOMEM;
  2342. } else {
  2343. blogic_inithoststruct(myadapter,
  2344. host);
  2345. if (scsi_add_host(host, myadapter->pci_device
  2346. ? &myadapter->pci_device->dev
  2347. : NULL)) {
  2348. printk(KERN_WARNING
  2349. "BusLogic: scsi_add_host()"
  2350. "failed!\n");
  2351. blogic_destroy_ccbs(myadapter);
  2352. blogic_relres(myadapter);
  2353. list_del(&myadapter->host_list);
  2354. scsi_host_put(host);
  2355. ret = -ENODEV;
  2356. } else {
  2357. scsi_scan_host(host);
  2358. adapter_count++;
  2359. }
  2360. }
  2361. } else {
  2362. /*
  2363. An error occurred during Host Adapter Configuration
  2364. Querying, Host Adapter Configuration, Resource
  2365. Acquisition, CCB Creation, Host Adapter
  2366. Initialization, or Target Device Inquiry, so
  2367. remove Host Adapter from the list of registered
  2368. BusLogic Host Adapters, destroy the CCBs, Release
  2369. the System Resources, and Unregister the SCSI
  2370. Host.
  2371. */
  2372. blogic_destroy_ccbs(myadapter);
  2373. blogic_relres(myadapter);
  2374. list_del(&myadapter->host_list);
  2375. scsi_host_put(host);
  2376. ret = -ENODEV;
  2377. }
  2378. }
  2379. kfree(adapter);
  2380. kfree(blogic_probeinfo_list);
  2381. blogic_probeinfo_list = NULL;
  2382. return ret;
  2383. }
  2384. /*
  2385. blogic_deladapter releases all resources previously acquired to
  2386. support a specific Host Adapter, including the I/O Address range, and
  2387. unregisters the BusLogic Host Adapter.
  2388. */
  2389. static int __exit blogic_deladapter(struct blogic_adapter *adapter)
  2390. {
  2391. struct Scsi_Host *host = adapter->scsi_host;
  2392. scsi_remove_host(host);
  2393. /*
  2394. FlashPoint Host Adapters must first be released by the FlashPoint
  2395. SCCB Manager.
  2396. */
  2397. if (blogic_flashpoint_type(adapter))
  2398. FlashPoint_ReleaseHostAdapter(adapter->cardhandle);
  2399. /*
  2400. Destroy the CCBs and release any system resources acquired to
  2401. support Host Adapter.
  2402. */
  2403. blogic_destroy_ccbs(adapter);
  2404. blogic_relres(adapter);
  2405. /*
  2406. Release usage of the I/O Address range.
  2407. */
  2408. release_region(adapter->io_addr, adapter->addr_count);
  2409. /*
  2410. Remove Host Adapter from the list of registered BusLogic
  2411. Host Adapters.
  2412. */
  2413. list_del(&adapter->host_list);
  2414. scsi_host_put(host);
  2415. return 0;
  2416. }
  2417. /*
  2418. blogic_qcompleted_ccb queues CCB for completion processing.
  2419. */
  2420. static void blogic_qcompleted_ccb(struct blogic_ccb *ccb)
  2421. {
  2422. struct blogic_adapter *adapter = ccb->adapter;
  2423. ccb->status = BLOGIC_CCB_COMPLETE;
  2424. ccb->next = NULL;
  2425. if (adapter->firstccb == NULL) {
  2426. adapter->firstccb = ccb;
  2427. adapter->lastccb = ccb;
  2428. } else {
  2429. adapter->lastccb->next = ccb;
  2430. adapter->lastccb = ccb;
  2431. }
  2432. adapter->active_cmds[ccb->tgt_id]--;
  2433. }
  2434. /*
  2435. blogic_resultcode computes a SCSI Subsystem Result Code from
  2436. the Host Adapter Status and Target Device Status.
  2437. */
  2438. static int blogic_resultcode(struct blogic_adapter *adapter,
  2439. enum blogic_adapter_status adapter_status,
  2440. enum blogic_tgt_status tgt_status)
  2441. {
  2442. int hoststatus;
  2443. switch (adapter_status) {
  2444. case BLOGIC_CMD_CMPLT_NORMAL:
  2445. case BLOGIC_LINK_CMD_CMPLT:
  2446. case BLOGIC_LINK_CMD_CMPLT_FLAG:
  2447. hoststatus = DID_OK;
  2448. break;
  2449. case BLOGIC_SELECT_TIMEOUT:
  2450. hoststatus = DID_TIME_OUT;
  2451. break;
  2452. case BLOGIC_INVALID_OUTBOX_CODE:
  2453. case BLOGIC_INVALID_CMD_CODE:
  2454. case BLOGIC_BAD_CMD_PARAM:
  2455. blogic_warn("BusLogic Driver Protocol Error 0x%02X\n",
  2456. adapter, adapter_status);
  2457. case BLOGIC_DATA_UNDERRUN:
  2458. case BLOGIC_DATA_OVERRUN:
  2459. case BLOGIC_NOEXPECT_BUSFREE:
  2460. case BLOGIC_LINKCCB_BADLUN:
  2461. case BLOGIC_AUTOREQSENSE_FAIL:
  2462. case BLOGIC_TAGQUEUE_REJECT:
  2463. case BLOGIC_BAD_MSG_RCVD:
  2464. case BLOGIC_HW_FAIL:
  2465. case BLOGIC_BAD_RECONNECT:
  2466. case BLOGIC_ABRT_QUEUE:
  2467. case BLOGIC_ADAPTER_SW_ERROR:
  2468. case BLOGIC_HW_TIMEOUT:
  2469. case BLOGIC_PARITY_ERR:
  2470. hoststatus = DID_ERROR;
  2471. break;
  2472. case BLOGIC_INVALID_BUSPHASE:
  2473. case BLOGIC_NORESPONSE_TO_ATN:
  2474. case BLOGIC_HW_RESET:
  2475. case BLOGIC_RST_FROM_OTHERDEV:
  2476. case BLOGIC_HW_BDR:
  2477. hoststatus = DID_RESET;
  2478. break;
  2479. default:
  2480. blogic_warn("Unknown Host Adapter Status 0x%02X\n", adapter,
  2481. adapter_status);
  2482. hoststatus = DID_ERROR;
  2483. break;
  2484. }
  2485. return (hoststatus << 16) | tgt_status;
  2486. }
  2487. /*
  2488. blogic_scan_inbox scans the Incoming Mailboxes saving any
  2489. Incoming Mailbox entries for completion processing.
  2490. */
  2491. static void blogic_scan_inbox(struct blogic_adapter *adapter)
  2492. {
  2493. /*
  2494. Scan through the Incoming Mailboxes in Strict Round Robin
  2495. fashion, saving any completed CCBs for further processing. It
  2496. is essential that for each CCB and SCSI Command issued, command
  2497. completion processing is performed exactly once. Therefore,
  2498. only Incoming Mailboxes with completion code Command Completed
  2499. Without Error, Command Completed With Error, or Command Aborted
  2500. At Host Request are saved for completion processing. When an
  2501. Incoming Mailbox has a completion code of Aborted Command Not
  2502. Found, the CCB had already completed or been aborted before the
  2503. current Abort request was processed, and so completion processing
  2504. has already occurred and no further action should be taken.
  2505. */
  2506. struct blogic_inbox *next_inbox = adapter->next_inbox;
  2507. enum blogic_cmplt_code comp_code;
  2508. while ((comp_code = next_inbox->comp_code) != BLOGIC_INBOX_FREE) {
  2509. /*
  2510. We are only allowed to do this because we limit our
  2511. architectures we run on to machines where bus_to_virt(
  2512. actually works. There *needs* to be a dma_addr_to_virt()
  2513. in the new PCI DMA mapping interface to replace
  2514. bus_to_virt() or else this code is going to become very
  2515. innefficient.
  2516. */
  2517. struct blogic_ccb *ccb =
  2518. (struct blogic_ccb *) bus_to_virt(next_inbox->ccb);
  2519. if (comp_code != BLOGIC_CMD_NOTFOUND) {
  2520. if (ccb->status == BLOGIC_CCB_ACTIVE ||
  2521. ccb->status == BLOGIC_CCB_RESET) {
  2522. /*
  2523. Save the Completion Code for this CCB and
  2524. queue the CCB for completion processing.
  2525. */
  2526. ccb->comp_code = comp_code;
  2527. blogic_qcompleted_ccb(ccb);
  2528. } else {
  2529. /*
  2530. If a CCB ever appears in an Incoming Mailbox
  2531. and is not marked as status Active or Reset,
  2532. then there is most likely a bug in
  2533. the Host Adapter firmware.
  2534. */
  2535. blogic_warn("Illegal CCB #%ld status %d in " "Incoming Mailbox\n", adapter, ccb->serial, ccb->status);
  2536. }
  2537. }
  2538. next_inbox->comp_code = BLOGIC_INBOX_FREE;
  2539. if (++next_inbox > adapter->last_inbox)
  2540. next_inbox = adapter->first_inbox;
  2541. }
  2542. adapter->next_inbox = next_inbox;
  2543. }
  2544. /*
  2545. blogic_process_ccbs iterates over the completed CCBs for Host
  2546. Adapter setting the SCSI Command Result Codes, deallocating the CCBs, and
  2547. calling the SCSI Subsystem Completion Routines. The Host Adapter's Lock
  2548. should already have been acquired by the caller.
  2549. */
  2550. static void blogic_process_ccbs(struct blogic_adapter *adapter)
  2551. {
  2552. if (adapter->processing_ccbs)
  2553. return;
  2554. adapter->processing_ccbs = true;
  2555. while (adapter->firstccb != NULL) {
  2556. struct blogic_ccb *ccb = adapter->firstccb;
  2557. struct scsi_cmnd *command = ccb->command;
  2558. adapter->firstccb = ccb->next;
  2559. if (adapter->firstccb == NULL)
  2560. adapter->lastccb = NULL;
  2561. /*
  2562. Process the Completed CCB.
  2563. */
  2564. if (ccb->opcode == BLOGIC_BDR) {
  2565. int tgt_id = ccb->tgt_id;
  2566. blogic_warn("Bus Device Reset CCB #%ld to Target " "%d Completed\n", adapter, ccb->serial, tgt_id);
  2567. blogic_inc_count(&adapter->tgt_stats[tgt_id].bdr_done);
  2568. adapter->tgt_flags[tgt_id].tagq_active = false;
  2569. adapter->cmds_since_rst[tgt_id] = 0;
  2570. adapter->last_resetdone[tgt_id] = jiffies;
  2571. /*
  2572. Place CCB back on the Host Adapter's free list.
  2573. */
  2574. blogic_dealloc_ccb(ccb);
  2575. #if 0 /* this needs to be redone different for new EH */
  2576. /*
  2577. Bus Device Reset CCBs have the command field
  2578. non-NULL only when a Bus Device Reset was requested
  2579. for a command that did not have a currently active
  2580. CCB in the Host Adapter (i.e., a Synchronous Bus
  2581. Device Reset), and hence would not have its
  2582. Completion Routine called otherwise.
  2583. */
  2584. while (command != NULL) {
  2585. struct scsi_cmnd *nxt_cmd =
  2586. command->reset_chain;
  2587. command->reset_chain = NULL;
  2588. command->result = DID_RESET << 16;
  2589. command->scsi_done(command);
  2590. command = nxt_cmd;
  2591. }
  2592. #endif
  2593. /*
  2594. Iterate over the CCBs for this Host Adapter
  2595. performing completion processing for any CCBs
  2596. marked as Reset for this Target.
  2597. */
  2598. for (ccb = adapter->all_ccbs; ccb != NULL;
  2599. ccb = ccb->next_all)
  2600. if (ccb->status == BLOGIC_CCB_RESET &&
  2601. ccb->tgt_id == tgt_id) {
  2602. command = ccb->command;
  2603. blogic_dealloc_ccb(ccb);
  2604. adapter->active_cmds[tgt_id]--;
  2605. command->result = DID_RESET << 16;
  2606. command->scsi_done(command);
  2607. }
  2608. adapter->bdr_pend[tgt_id] = NULL;
  2609. } else {
  2610. /*
  2611. Translate the Completion Code, Host Adapter Status,
  2612. and Target Device Status into a SCSI Subsystem
  2613. Result Code.
  2614. */
  2615. switch (ccb->comp_code) {
  2616. case BLOGIC_INBOX_FREE:
  2617. case BLOGIC_CMD_NOTFOUND:
  2618. case BLOGIC_INVALID_CCB:
  2619. blogic_warn("CCB #%ld to Target %d Impossible State\n", adapter, ccb->serial, ccb->tgt_id);
  2620. break;
  2621. case BLOGIC_CMD_COMPLETE_GOOD:
  2622. adapter->tgt_stats[ccb->tgt_id]
  2623. .cmds_complete++;
  2624. adapter->tgt_flags[ccb->tgt_id]
  2625. .cmd_good = true;
  2626. command->result = DID_OK << 16;
  2627. break;
  2628. case BLOGIC_CMD_ABORT_BY_HOST:
  2629. blogic_warn("CCB #%ld to Target %d Aborted\n",
  2630. adapter, ccb->serial, ccb->tgt_id);
  2631. blogic_inc_count(&adapter->tgt_stats[ccb->tgt_id].aborts_done);
  2632. command->result = DID_ABORT << 16;
  2633. break;
  2634. case BLOGIC_CMD_COMPLETE_ERROR:
  2635. command->result = blogic_resultcode(adapter,
  2636. ccb->adapter_status, ccb->tgt_status);
  2637. if (ccb->adapter_status != BLOGIC_SELECT_TIMEOUT) {
  2638. adapter->tgt_stats[ccb->tgt_id]
  2639. .cmds_complete++;
  2640. if (blogic_global_options.trace_err) {
  2641. int i;
  2642. blogic_notice("CCB #%ld Target %d: Result %X Host "
  2643. "Adapter Status %02X " "Target Status %02X\n", adapter, ccb->serial, ccb->tgt_id, command->result, ccb->adapter_status, ccb->tgt_status);
  2644. blogic_notice("CDB ", adapter);
  2645. for (i = 0; i < ccb->cdblen; i++)
  2646. blogic_notice(" %02X", adapter, ccb->cdb[i]);
  2647. blogic_notice("\n", adapter);
  2648. blogic_notice("Sense ", adapter);
  2649. for (i = 0; i < ccb->sense_datalen; i++)
  2650. blogic_notice(" %02X", adapter, command->sense_buffer[i]);
  2651. blogic_notice("\n", adapter);
  2652. }
  2653. }
  2654. break;
  2655. }
  2656. /*
  2657. When an INQUIRY command completes normally, save the
  2658. CmdQue (Tagged Queuing Supported) and WBus16 (16 Bit
  2659. Wide Data Transfers Supported) bits.
  2660. */
  2661. if (ccb->cdb[0] == INQUIRY && ccb->cdb[1] == 0 &&
  2662. ccb->adapter_status == BLOGIC_CMD_CMPLT_NORMAL) {
  2663. struct blogic_tgt_flags *tgt_flags =
  2664. &adapter->tgt_flags[ccb->tgt_id];
  2665. struct scsi_inquiry *inquiry =
  2666. (struct scsi_inquiry *) scsi_sglist(command);
  2667. tgt_flags->tgt_exists = true;
  2668. tgt_flags->tagq_ok = inquiry->CmdQue;
  2669. tgt_flags->wide_ok = inquiry->WBus16;
  2670. }
  2671. /*
  2672. Place CCB back on the Host Adapter's free list.
  2673. */
  2674. blogic_dealloc_ccb(ccb);
  2675. /*
  2676. Call the SCSI Command Completion Routine.
  2677. */
  2678. command->scsi_done(command);
  2679. }
  2680. }
  2681. adapter->processing_ccbs = false;
  2682. }
  2683. /*
  2684. blogic_inthandler handles hardware interrupts from BusLogic Host
  2685. Adapters.
  2686. */
  2687. static irqreturn_t blogic_inthandler(int irq_ch, void *devid)
  2688. {
  2689. struct blogic_adapter *adapter = (struct blogic_adapter *) devid;
  2690. unsigned long processor_flag;
  2691. /*
  2692. Acquire exclusive access to Host Adapter.
  2693. */
  2694. spin_lock_irqsave(adapter->scsi_host->host_lock, processor_flag);
  2695. /*
  2696. Handle Interrupts appropriately for each Host Adapter type.
  2697. */
  2698. if (blogic_multimaster_type(adapter)) {
  2699. union blogic_int_reg intreg;
  2700. /*
  2701. Read the Host Adapter Interrupt Register.
  2702. */
  2703. intreg.all = blogic_rdint(adapter);
  2704. if (intreg.ir.int_valid) {
  2705. /*
  2706. Acknowledge the interrupt and reset the Host Adapter
  2707. Interrupt Register.
  2708. */
  2709. blogic_intreset(adapter);
  2710. /*
  2711. Process valid External SCSI Bus Reset and Incoming
  2712. Mailbox Loaded Interrupts. Command Complete
  2713. Interrupts are noted, and Outgoing Mailbox Available
  2714. Interrupts are ignored, as they are never enabled.
  2715. */
  2716. if (intreg.ir.ext_busreset)
  2717. adapter->adapter_extreset = true;
  2718. else if (intreg.ir.mailin_loaded)
  2719. blogic_scan_inbox(adapter);
  2720. else if (intreg.ir.cmd_complete)
  2721. adapter->adapter_cmd_complete = true;
  2722. }
  2723. } else {
  2724. /*
  2725. Check if there is a pending interrupt for this Host Adapter.
  2726. */
  2727. if (FlashPoint_InterruptPending(adapter->cardhandle))
  2728. switch (FlashPoint_HandleInterrupt(adapter->cardhandle)) {
  2729. case FPOINT_NORMAL_INT:
  2730. break;
  2731. case FPOINT_EXT_RESET:
  2732. adapter->adapter_extreset = true;
  2733. break;
  2734. case FPOINT_INTERN_ERR:
  2735. blogic_warn("Internal FlashPoint Error detected - Resetting Host Adapter\n", adapter);
  2736. adapter->adapter_intern_err = true;
  2737. break;
  2738. }
  2739. }
  2740. /*
  2741. Process any completed CCBs.
  2742. */
  2743. if (adapter->firstccb != NULL)
  2744. blogic_process_ccbs(adapter);
  2745. /*
  2746. Reset the Host Adapter if requested.
  2747. */
  2748. if (adapter->adapter_extreset) {
  2749. blogic_warn("Resetting %s due to External SCSI Bus Reset\n", adapter, adapter->full_model);
  2750. blogic_inc_count(&adapter->ext_resets);
  2751. blogic_resetadapter(adapter, false);
  2752. adapter->adapter_extreset = false;
  2753. } else if (adapter->adapter_intern_err) {
  2754. blogic_warn("Resetting %s due to Host Adapter Internal Error\n", adapter, adapter->full_model);
  2755. blogic_inc_count(&adapter->adapter_intern_errors);
  2756. blogic_resetadapter(adapter, true);
  2757. adapter->adapter_intern_err = false;
  2758. }
  2759. /*
  2760. Release exclusive access to Host Adapter.
  2761. */
  2762. spin_unlock_irqrestore(adapter->scsi_host->host_lock, processor_flag);
  2763. return IRQ_HANDLED;
  2764. }
  2765. /*
  2766. blogic_write_outbox places CCB and Action Code into an Outgoing
  2767. Mailbox for execution by Host Adapter. The Host Adapter's Lock should
  2768. already have been acquired by the caller.
  2769. */
  2770. static bool blogic_write_outbox(struct blogic_adapter *adapter,
  2771. enum blogic_action action, struct blogic_ccb *ccb)
  2772. {
  2773. struct blogic_outbox *next_outbox;
  2774. next_outbox = adapter->next_outbox;
  2775. if (next_outbox->action == BLOGIC_OUTBOX_FREE) {
  2776. ccb->status = BLOGIC_CCB_ACTIVE;
  2777. /*
  2778. The CCB field must be written before the Action Code field
  2779. since the Host Adapter is operating asynchronously and the
  2780. locking code does not protect against simultaneous access
  2781. by the Host Adapter.
  2782. */
  2783. next_outbox->ccb = ccb->dma_handle;
  2784. next_outbox->action = action;
  2785. blogic_execmbox(adapter);
  2786. if (++next_outbox > adapter->last_outbox)
  2787. next_outbox = adapter->first_outbox;
  2788. adapter->next_outbox = next_outbox;
  2789. if (action == BLOGIC_MBOX_START) {
  2790. adapter->active_cmds[ccb->tgt_id]++;
  2791. if (ccb->opcode != BLOGIC_BDR)
  2792. adapter->tgt_stats[ccb->tgt_id].cmds_tried++;
  2793. }
  2794. return true;
  2795. }
  2796. return false;
  2797. }
  2798. /* Error Handling (EH) support */
  2799. static int blogic_hostreset(struct scsi_cmnd *SCpnt)
  2800. {
  2801. struct blogic_adapter *adapter =
  2802. (struct blogic_adapter *) SCpnt->device->host->hostdata;
  2803. unsigned int id = SCpnt->device->id;
  2804. struct blogic_tgt_stats *stats = &adapter->tgt_stats[id];
  2805. int rc;
  2806. spin_lock_irq(SCpnt->device->host->host_lock);
  2807. blogic_inc_count(&stats->adatper_reset_req);
  2808. rc = blogic_resetadapter(adapter, false);
  2809. spin_unlock_irq(SCpnt->device->host->host_lock);
  2810. return rc;
  2811. }
  2812. /*
  2813. blogic_qcmd creates a CCB for Command and places it into an
  2814. Outgoing Mailbox for execution by the associated Host Adapter.
  2815. */
  2816. static int blogic_qcmd_lck(struct scsi_cmnd *command,
  2817. void (*comp_cb) (struct scsi_cmnd *))
  2818. {
  2819. struct blogic_adapter *adapter =
  2820. (struct blogic_adapter *) command->device->host->hostdata;
  2821. struct blogic_tgt_flags *tgt_flags =
  2822. &adapter->tgt_flags[command->device->id];
  2823. struct blogic_tgt_stats *tgt_stats = adapter->tgt_stats;
  2824. unsigned char *cdb = command->cmnd;
  2825. int cdblen = command->cmd_len;
  2826. int tgt_id = command->device->id;
  2827. int lun = command->device->lun;
  2828. int buflen = scsi_bufflen(command);
  2829. int count;
  2830. struct blogic_ccb *ccb;
  2831. /*
  2832. SCSI REQUEST_SENSE commands will be executed automatically by the
  2833. Host Adapter for any errors, so they should not be executed
  2834. explicitly unless the Sense Data is zero indicating that no error
  2835. occurred.
  2836. */
  2837. if (cdb[0] == REQUEST_SENSE && command->sense_buffer[0] != 0) {
  2838. command->result = DID_OK << 16;
  2839. comp_cb(command);
  2840. return 0;
  2841. }
  2842. /*
  2843. Allocate a CCB from the Host Adapter's free list. In the unlikely
  2844. event that there are none available and memory allocation fails,
  2845. wait 1 second and try again. If that fails, the Host Adapter is
  2846. probably hung so signal an error as a Host Adapter Hard Reset
  2847. should be initiated soon.
  2848. */
  2849. ccb = blogic_alloc_ccb(adapter);
  2850. if (ccb == NULL) {
  2851. spin_unlock_irq(adapter->scsi_host->host_lock);
  2852. blogic_delay(1);
  2853. spin_lock_irq(adapter->scsi_host->host_lock);
  2854. ccb = blogic_alloc_ccb(adapter);
  2855. if (ccb == NULL) {
  2856. command->result = DID_ERROR << 16;
  2857. comp_cb(command);
  2858. return 0;
  2859. }
  2860. }
  2861. /*
  2862. Initialize the fields in the BusLogic Command Control Block (CCB).
  2863. */
  2864. count = scsi_dma_map(command);
  2865. BUG_ON(count < 0);
  2866. if (count) {
  2867. struct scatterlist *sg;
  2868. int i;
  2869. ccb->opcode = BLOGIC_INITIATOR_CCB_SG;
  2870. ccb->datalen = count * sizeof(struct blogic_sg_seg);
  2871. if (blogic_multimaster_type(adapter))
  2872. ccb->data = (void *)((unsigned int) ccb->dma_handle +
  2873. ((unsigned long) &ccb->sglist -
  2874. (unsigned long) ccb));
  2875. else
  2876. ccb->data = ccb->sglist;
  2877. scsi_for_each_sg(command, sg, count, i) {
  2878. ccb->sglist[i].segbytes = sg_dma_len(sg);
  2879. ccb->sglist[i].segdata = sg_dma_address(sg);
  2880. }
  2881. } else if (!count) {
  2882. ccb->opcode = BLOGIC_INITIATOR_CCB;
  2883. ccb->datalen = buflen;
  2884. ccb->data = 0;
  2885. }
  2886. switch (cdb[0]) {
  2887. case READ_6:
  2888. case READ_10:
  2889. ccb->datadir = BLOGIC_DATAIN_CHECKED;
  2890. tgt_stats[tgt_id].read_cmds++;
  2891. blogic_addcount(&tgt_stats[tgt_id].bytesread, buflen);
  2892. blogic_incszbucket(tgt_stats[tgt_id].read_sz_buckets, buflen);
  2893. break;
  2894. case WRITE_6:
  2895. case WRITE_10:
  2896. ccb->datadir = BLOGIC_DATAOUT_CHECKED;
  2897. tgt_stats[tgt_id].write_cmds++;
  2898. blogic_addcount(&tgt_stats[tgt_id].byteswritten, buflen);
  2899. blogic_incszbucket(tgt_stats[tgt_id].write_sz_buckets, buflen);
  2900. break;
  2901. default:
  2902. ccb->datadir = BLOGIC_UNCHECKED_TX;
  2903. break;
  2904. }
  2905. ccb->cdblen = cdblen;
  2906. ccb->adapter_status = 0;
  2907. ccb->tgt_status = 0;
  2908. ccb->tgt_id = tgt_id;
  2909. ccb->lun = lun;
  2910. ccb->tag_enable = false;
  2911. ccb->legacytag_enable = false;
  2912. /*
  2913. BusLogic recommends that after a Reset the first couple of
  2914. commands that are sent to a Target Device be sent in a non
  2915. Tagged Queue fashion so that the Host Adapter and Target Device
  2916. can establish Synchronous and Wide Transfer before Queue Tag
  2917. messages can interfere with the Synchronous and Wide Negotiation
  2918. messages. By waiting to enable Tagged Queuing until after the
  2919. first BLOGIC_MAX_TAG_DEPTH commands have been queued, it is
  2920. assured that after a Reset any pending commands are requeued
  2921. before Tagged Queuing is enabled and that the Tagged Queuing
  2922. message will not occur while the partition table is being printed.
  2923. In addition, some devices do not properly handle the transition
  2924. from non-tagged to tagged commands, so it is necessary to wait
  2925. until there are no pending commands for a target device
  2926. before queuing tagged commands.
  2927. */
  2928. if (adapter->cmds_since_rst[tgt_id]++ >= BLOGIC_MAX_TAG_DEPTH &&
  2929. !tgt_flags->tagq_active &&
  2930. adapter->active_cmds[tgt_id] == 0
  2931. && tgt_flags->tagq_ok &&
  2932. (adapter->tagq_ok & (1 << tgt_id))) {
  2933. tgt_flags->tagq_active = true;
  2934. blogic_notice("Tagged Queuing now active for Target %d\n",
  2935. adapter, tgt_id);
  2936. }
  2937. if (tgt_flags->tagq_active) {
  2938. enum blogic_queuetag queuetag = BLOGIC_SIMPLETAG;
  2939. /*
  2940. When using Tagged Queuing with Simple Queue Tags, it
  2941. appears that disk drive controllers do not guarantee that
  2942. a queued command will not remain in a disconnected state
  2943. indefinitely if commands that read or write nearer the
  2944. head position continue to arrive without interruption.
  2945. Therefore, for each Target Device this driver keeps track
  2946. of the last time either the queue was empty or an Ordered
  2947. Queue Tag was issued. If more than 4 seconds (one fifth
  2948. of the 20 second disk timeout) have elapsed since this
  2949. last sequence point, this command will be issued with an
  2950. Ordered Queue Tag rather than a Simple Queue Tag, which
  2951. forces the Target Device to complete all previously
  2952. queued commands before this command may be executed.
  2953. */
  2954. if (adapter->active_cmds[tgt_id] == 0)
  2955. adapter->last_seqpoint[tgt_id] = jiffies;
  2956. else if (time_after(jiffies,
  2957. adapter->last_seqpoint[tgt_id] + 4 * HZ)) {
  2958. adapter->last_seqpoint[tgt_id] = jiffies;
  2959. queuetag = BLOGIC_ORDEREDTAG;
  2960. }
  2961. if (adapter->ext_lun) {
  2962. ccb->tag_enable = true;
  2963. ccb->queuetag = queuetag;
  2964. } else {
  2965. ccb->legacytag_enable = true;
  2966. ccb->legacy_tag = queuetag;
  2967. }
  2968. }
  2969. memcpy(ccb->cdb, cdb, cdblen);
  2970. ccb->sense_datalen = SCSI_SENSE_BUFFERSIZE;
  2971. ccb->sensedata = pci_map_single(adapter->pci_device,
  2972. command->sense_buffer, ccb->sense_datalen,
  2973. PCI_DMA_FROMDEVICE);
  2974. ccb->command = command;
  2975. command->scsi_done = comp_cb;
  2976. if (blogic_multimaster_type(adapter)) {
  2977. /*
  2978. Place the CCB in an Outgoing Mailbox. The higher levels
  2979. of the SCSI Subsystem should not attempt to queue more
  2980. commands than can be placed in Outgoing Mailboxes, so
  2981. there should always be one free. In the unlikely event
  2982. that there are none available, wait 1 second and try
  2983. again. If that fails, the Host Adapter is probably hung
  2984. so signal an error as a Host Adapter Hard Reset should
  2985. be initiated soon.
  2986. */
  2987. if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START, ccb)) {
  2988. spin_unlock_irq(adapter->scsi_host->host_lock);
  2989. blogic_warn("Unable to write Outgoing Mailbox - " "Pausing for 1 second\n", adapter);
  2990. blogic_delay(1);
  2991. spin_lock_irq(adapter->scsi_host->host_lock);
  2992. if (!blogic_write_outbox(adapter, BLOGIC_MBOX_START,
  2993. ccb)) {
  2994. blogic_warn("Still unable to write Outgoing Mailbox - " "Host Adapter Dead?\n", adapter);
  2995. blogic_dealloc_ccb(ccb);
  2996. command->result = DID_ERROR << 16;
  2997. command->scsi_done(command);
  2998. }
  2999. }
  3000. } else {
  3001. /*
  3002. Call the FlashPoint SCCB Manager to start execution of
  3003. the CCB.
  3004. */
  3005. ccb->status = BLOGIC_CCB_ACTIVE;
  3006. adapter->active_cmds[tgt_id]++;
  3007. tgt_stats[tgt_id].cmds_tried++;
  3008. FlashPoint_StartCCB(adapter->cardhandle, ccb);
  3009. /*
  3010. The Command may have already completed and
  3011. blogic_qcompleted_ccb been called, or it may still be
  3012. pending.
  3013. */
  3014. if (ccb->status == BLOGIC_CCB_COMPLETE)
  3015. blogic_process_ccbs(adapter);
  3016. }
  3017. return 0;
  3018. }
  3019. static DEF_SCSI_QCMD(blogic_qcmd)
  3020. #if 0
  3021. /*
  3022. blogic_abort aborts Command if possible.
  3023. */
  3024. static int blogic_abort(struct scsi_cmnd *command)
  3025. {
  3026. struct blogic_adapter *adapter =
  3027. (struct blogic_adapter *) command->device->host->hostdata;
  3028. int tgt_id = command->device->id;
  3029. struct blogic_ccb *ccb;
  3030. blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_request);
  3031. /*
  3032. Attempt to find an Active CCB for this Command. If no Active
  3033. CCB for this Command is found, then no Abort is necessary.
  3034. */
  3035. for (ccb = adapter->all_ccbs; ccb != NULL; ccb = ccb->next_all)
  3036. if (ccb->command == command)
  3037. break;
  3038. if (ccb == NULL) {
  3039. blogic_warn("Unable to Abort Command to Target %d - No CCB Found\n", adapter, tgt_id);
  3040. return SUCCESS;
  3041. } else if (ccb->status == BLOGIC_CCB_COMPLETE) {
  3042. blogic_warn("Unable to Abort Command to Target %d - CCB Completed\n", adapter, tgt_id);
  3043. return SUCCESS;
  3044. } else if (ccb->status == BLOGIC_CCB_RESET) {
  3045. blogic_warn("Unable to Abort Command to Target %d - CCB Reset\n", adapter, tgt_id);
  3046. return SUCCESS;
  3047. }
  3048. if (blogic_multimaster_type(adapter)) {
  3049. /*
  3050. Attempt to Abort this CCB. MultiMaster Firmware versions
  3051. prior to 5.xx do not generate Abort Tag messages, but only
  3052. generate the non-tagged Abort message. Since non-tagged
  3053. commands are not sent by the Host Adapter until the queue
  3054. of outstanding tagged commands has completed, and the
  3055. Abort message is treated as a non-tagged command, it is
  3056. effectively impossible to abort commands when Tagged
  3057. Queuing is active. Firmware version 5.xx does generate
  3058. Abort Tag messages, so it is possible to abort commands
  3059. when Tagged Queuing is active.
  3060. */
  3061. if (adapter->tgt_flags[tgt_id].tagq_active &&
  3062. adapter->fw_ver[0] < '5') {
  3063. blogic_warn("Unable to Abort CCB #%ld to Target %d - Abort Tag Not Supported\n", adapter, ccb->serial, tgt_id);
  3064. return FAILURE;
  3065. } else if (blogic_write_outbox(adapter, BLOGIC_MBOX_ABORT,
  3066. ccb)) {
  3067. blogic_warn("Aborting CCB #%ld to Target %d\n",
  3068. adapter, ccb->serial, tgt_id);
  3069. blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_tried);
  3070. return SUCCESS;
  3071. } else {
  3072. blogic_warn("Unable to Abort CCB #%ld to Target %d - No Outgoing Mailboxes\n", adapter, ccb->serial, tgt_id);
  3073. return FAILURE;
  3074. }
  3075. } else {
  3076. /*
  3077. Call the FlashPoint SCCB Manager to abort execution of
  3078. the CCB.
  3079. */
  3080. blogic_warn("Aborting CCB #%ld to Target %d\n", adapter,
  3081. ccb->serial, tgt_id);
  3082. blogic_inc_count(&adapter->tgt_stats[tgt_id].aborts_tried);
  3083. FlashPoint_AbortCCB(adapter->cardhandle, ccb);
  3084. /*
  3085. The Abort may have already been completed and
  3086. blogic_qcompleted_ccb been called, or it
  3087. may still be pending.
  3088. */
  3089. if (ccb->status == BLOGIC_CCB_COMPLETE)
  3090. blogic_process_ccbs(adapter);
  3091. return SUCCESS;
  3092. }
  3093. return SUCCESS;
  3094. }
  3095. #endif
  3096. /*
  3097. blogic_resetadapter resets Host Adapter if possible, marking all
  3098. currently executing SCSI Commands as having been Reset.
  3099. */
  3100. static int blogic_resetadapter(struct blogic_adapter *adapter, bool hard_reset)
  3101. {
  3102. struct blogic_ccb *ccb;
  3103. int tgt_id;
  3104. /*
  3105. * Attempt to Reset and Reinitialize the Host Adapter.
  3106. */
  3107. if (!(blogic_hwreset(adapter, hard_reset) &&
  3108. blogic_initadapter(adapter))) {
  3109. blogic_err("Resetting %s Failed\n", adapter,
  3110. adapter->full_model);
  3111. return FAILURE;
  3112. }
  3113. /*
  3114. * Deallocate all currently executing CCBs.
  3115. */
  3116. for (ccb = adapter->all_ccbs; ccb != NULL; ccb = ccb->next_all)
  3117. if (ccb->status == BLOGIC_CCB_ACTIVE)
  3118. blogic_dealloc_ccb(ccb);
  3119. /*
  3120. * Wait a few seconds between the Host Adapter Hard Reset which
  3121. * initiates a SCSI Bus Reset and issuing any SCSI Commands. Some
  3122. * SCSI devices get confused if they receive SCSI Commands too soon
  3123. * after a SCSI Bus Reset.
  3124. */
  3125. if (hard_reset) {
  3126. spin_unlock_irq(adapter->scsi_host->host_lock);
  3127. blogic_delay(adapter->bus_settle_time);
  3128. spin_lock_irq(adapter->scsi_host->host_lock);
  3129. }
  3130. for (tgt_id = 0; tgt_id < adapter->maxdev; tgt_id++) {
  3131. adapter->last_resettried[tgt_id] = jiffies;
  3132. adapter->last_resetdone[tgt_id] = jiffies;
  3133. }
  3134. return SUCCESS;
  3135. }
  3136. /*
  3137. blogic_diskparam returns the Heads/Sectors/Cylinders BIOS Disk
  3138. Parameters for Disk. The default disk geometry is 64 heads, 32 sectors, and
  3139. the appropriate number of cylinders so as not to exceed drive capacity. In
  3140. order for disks equal to or larger than 1 GB to be addressable by the BIOS
  3141. without exceeding the BIOS limitation of 1024 cylinders, Extended Translation
  3142. may be enabled in AutoSCSI on FlashPoint Host Adapters and on "W" and "C"
  3143. series MultiMaster Host Adapters, or by a dip switch setting on "S" and "A"
  3144. series MultiMaster Host Adapters. With Extended Translation enabled, drives
  3145. between 1 GB inclusive and 2 GB exclusive are given a disk geometry of 128
  3146. heads and 32 sectors, and drives above 2 GB inclusive are given a disk
  3147. geometry of 255 heads and 63 sectors. However, if the BIOS detects that the
  3148. Extended Translation setting does not match the geometry in the partition
  3149. table, then the translation inferred from the partition table will be used by
  3150. the BIOS, and a warning may be displayed.
  3151. */
  3152. static int blogic_diskparam(struct scsi_device *sdev, struct block_device *dev,
  3153. sector_t capacity, int *params)
  3154. {
  3155. struct blogic_adapter *adapter =
  3156. (struct blogic_adapter *) sdev->host->hostdata;
  3157. struct bios_diskparam *diskparam = (struct bios_diskparam *) params;
  3158. unsigned char *buf;
  3159. if (adapter->ext_trans_enable && capacity >= 2 * 1024 * 1024 /* 1 GB in 512 byte sectors */) {
  3160. if (capacity >= 4 * 1024 * 1024 /* 2 GB in 512 byte sectors */) {
  3161. diskparam->heads = 255;
  3162. diskparam->sectors = 63;
  3163. } else {
  3164. diskparam->heads = 128;
  3165. diskparam->sectors = 32;
  3166. }
  3167. } else {
  3168. diskparam->heads = 64;
  3169. diskparam->sectors = 32;
  3170. }
  3171. diskparam->cylinders = (unsigned long) capacity / (diskparam->heads * diskparam->sectors);
  3172. buf = scsi_bios_ptable(dev);
  3173. if (buf == NULL)
  3174. return 0;
  3175. /*
  3176. If the boot sector partition table flag is valid, search for
  3177. a partition table entry whose end_head matches one of the
  3178. standard BusLogic geometry translations (64/32, 128/32, or 255/63).
  3179. */
  3180. if (*(unsigned short *) (buf + 64) == 0xAA55) {
  3181. struct partition *part1_entry = (struct partition *) buf;
  3182. struct partition *part_entry = part1_entry;
  3183. int saved_cyl = diskparam->cylinders, part_no;
  3184. unsigned char part_end_head = 0, part_end_sector = 0;
  3185. for (part_no = 0; part_no < 4; part_no++) {
  3186. part_end_head = part_entry->end_head;
  3187. part_end_sector = part_entry->end_sector & 0x3F;
  3188. if (part_end_head == 64 - 1) {
  3189. diskparam->heads = 64;
  3190. diskparam->sectors = 32;
  3191. break;
  3192. } else if (part_end_head == 128 - 1) {
  3193. diskparam->heads = 128;
  3194. diskparam->sectors = 32;
  3195. break;
  3196. } else if (part_end_head == 255 - 1) {
  3197. diskparam->heads = 255;
  3198. diskparam->sectors = 63;
  3199. break;
  3200. }
  3201. part_entry++;
  3202. }
  3203. if (part_no == 4) {
  3204. part_end_head = part1_entry->end_head;
  3205. part_end_sector = part1_entry->end_sector & 0x3F;
  3206. }
  3207. diskparam->cylinders = (unsigned long) capacity / (diskparam->heads * diskparam->sectors);
  3208. if (part_no < 4 && part_end_sector == diskparam->sectors) {
  3209. if (diskparam->cylinders != saved_cyl)
  3210. blogic_warn("Adopting Geometry %d/%d from Partition Table\n", adapter, diskparam->heads, diskparam->sectors);
  3211. } else if (part_end_head > 0 || part_end_sector > 0) {
  3212. blogic_warn("Warning: Partition Table appears to " "have Geometry %d/%d which is\n", adapter, part_end_head + 1, part_end_sector);
  3213. blogic_warn("not compatible with current BusLogic " "Host Adapter Geometry %d/%d\n", adapter, diskparam->heads, diskparam->sectors);
  3214. }
  3215. }
  3216. kfree(buf);
  3217. return 0;
  3218. }
  3219. /*
  3220. BugLogic_ProcDirectoryInfo implements /proc/scsi/BusLogic/<N>.
  3221. */
  3222. static int blogic_write_info(struct Scsi_Host *shost, char *procbuf,
  3223. int bytes_avail)
  3224. {
  3225. struct blogic_adapter *adapter =
  3226. (struct blogic_adapter *) shost->hostdata;
  3227. struct blogic_tgt_stats *tgt_stats;
  3228. tgt_stats = adapter->tgt_stats;
  3229. adapter->ext_resets = 0;
  3230. adapter->adapter_intern_errors = 0;
  3231. memset(tgt_stats, 0, BLOGIC_MAXDEV * sizeof(struct blogic_tgt_stats));
  3232. return 0;
  3233. }
  3234. static int blogic_show_info(struct seq_file *m, struct Scsi_Host *shost)
  3235. {
  3236. struct blogic_adapter *adapter = (struct blogic_adapter *) shost->hostdata;
  3237. struct blogic_tgt_stats *tgt_stats;
  3238. int tgt;
  3239. tgt_stats = adapter->tgt_stats;
  3240. seq_write(m, adapter->msgbuf, adapter->msgbuflen);
  3241. seq_printf(m, "\n\
  3242. Current Driver Queue Depth: %d\n\
  3243. Currently Allocated CCBs: %d\n", adapter->drvr_qdepth, adapter->alloc_ccbs);
  3244. seq_printf(m, "\n\n\
  3245. DATA TRANSFER STATISTICS\n\
  3246. \n\
  3247. Target Tagged Queuing Queue Depth Active Attempted Completed\n\
  3248. ====== ============== =========== ====== ========= =========\n");
  3249. for (tgt = 0; tgt < adapter->maxdev; tgt++) {
  3250. struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt];
  3251. if (!tgt_flags->tgt_exists)
  3252. continue;
  3253. seq_printf(m, " %2d %s", tgt, (tgt_flags->tagq_ok ? (tgt_flags->tagq_active ? " Active" : (adapter->tagq_ok & (1 << tgt)
  3254. ? " Permitted" : " Disabled"))
  3255. : "Not Supported"));
  3256. seq_printf(m,
  3257. " %3d %3u %9u %9u\n", adapter->qdepth[tgt], adapter->active_cmds[tgt], tgt_stats[tgt].cmds_tried, tgt_stats[tgt].cmds_complete);
  3258. }
  3259. seq_printf(m, "\n\
  3260. Target Read Commands Write Commands Total Bytes Read Total Bytes Written\n\
  3261. ====== ============= ============== =================== ===================\n");
  3262. for (tgt = 0; tgt < adapter->maxdev; tgt++) {
  3263. struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt];
  3264. if (!tgt_flags->tgt_exists)
  3265. continue;
  3266. seq_printf(m, " %2d %9u %9u", tgt, tgt_stats[tgt].read_cmds, tgt_stats[tgt].write_cmds);
  3267. if (tgt_stats[tgt].bytesread.billions > 0)
  3268. seq_printf(m, " %9u%09u", tgt_stats[tgt].bytesread.billions, tgt_stats[tgt].bytesread.units);
  3269. else
  3270. seq_printf(m, " %9u", tgt_stats[tgt].bytesread.units);
  3271. if (tgt_stats[tgt].byteswritten.billions > 0)
  3272. seq_printf(m, " %9u%09u\n", tgt_stats[tgt].byteswritten.billions, tgt_stats[tgt].byteswritten.units);
  3273. else
  3274. seq_printf(m, " %9u\n", tgt_stats[tgt].byteswritten.units);
  3275. }
  3276. seq_printf(m, "\n\
  3277. Target Command 0-1KB 1-2KB 2-4KB 4-8KB 8-16KB\n\
  3278. ====== ======= ========= ========= ========= ========= =========\n");
  3279. for (tgt = 0; tgt < adapter->maxdev; tgt++) {
  3280. struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt];
  3281. if (!tgt_flags->tgt_exists)
  3282. continue;
  3283. seq_printf(m,
  3284. " %2d Read %9u %9u %9u %9u %9u\n", tgt,
  3285. tgt_stats[tgt].read_sz_buckets[0],
  3286. tgt_stats[tgt].read_sz_buckets[1], tgt_stats[tgt].read_sz_buckets[2], tgt_stats[tgt].read_sz_buckets[3], tgt_stats[tgt].read_sz_buckets[4]);
  3287. seq_printf(m,
  3288. " %2d Write %9u %9u %9u %9u %9u\n", tgt,
  3289. tgt_stats[tgt].write_sz_buckets[0],
  3290. tgt_stats[tgt].write_sz_buckets[1], tgt_stats[tgt].write_sz_buckets[2], tgt_stats[tgt].write_sz_buckets[3], tgt_stats[tgt].write_sz_buckets[4]);
  3291. }
  3292. seq_printf(m, "\n\
  3293. Target Command 16-32KB 32-64KB 64-128KB 128-256KB 256KB+\n\
  3294. ====== ======= ========= ========= ========= ========= =========\n");
  3295. for (tgt = 0; tgt < adapter->maxdev; tgt++) {
  3296. struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt];
  3297. if (!tgt_flags->tgt_exists)
  3298. continue;
  3299. seq_printf(m,
  3300. " %2d Read %9u %9u %9u %9u %9u\n", tgt,
  3301. tgt_stats[tgt].read_sz_buckets[5],
  3302. tgt_stats[tgt].read_sz_buckets[6], tgt_stats[tgt].read_sz_buckets[7], tgt_stats[tgt].read_sz_buckets[8], tgt_stats[tgt].read_sz_buckets[9]);
  3303. seq_printf(m,
  3304. " %2d Write %9u %9u %9u %9u %9u\n", tgt,
  3305. tgt_stats[tgt].write_sz_buckets[5],
  3306. tgt_stats[tgt].write_sz_buckets[6], tgt_stats[tgt].write_sz_buckets[7], tgt_stats[tgt].write_sz_buckets[8], tgt_stats[tgt].write_sz_buckets[9]);
  3307. }
  3308. seq_printf(m, "\n\n\
  3309. ERROR RECOVERY STATISTICS\n\
  3310. \n\
  3311. Command Aborts Bus Device Resets Host Adapter Resets\n\
  3312. Target Requested Completed Requested Completed Requested Completed\n\
  3313. ID \\\\\\\\ Attempted //// \\\\\\\\ Attempted //// \\\\\\\\ Attempted ////\n\
  3314. ====== ===== ===== ===== ===== ===== ===== ===== ===== =====\n");
  3315. for (tgt = 0; tgt < adapter->maxdev; tgt++) {
  3316. struct blogic_tgt_flags *tgt_flags = &adapter->tgt_flags[tgt];
  3317. if (!tgt_flags->tgt_exists)
  3318. continue;
  3319. seq_printf(m, "\
  3320. %2d %5d %5d %5d %5d %5d %5d %5d %5d %5d\n", tgt, tgt_stats[tgt].aborts_request, tgt_stats[tgt].aborts_tried, tgt_stats[tgt].aborts_done, tgt_stats[tgt].bdr_request, tgt_stats[tgt].bdr_tried, tgt_stats[tgt].bdr_done, tgt_stats[tgt].adatper_reset_req, tgt_stats[tgt].adapter_reset_attempt, tgt_stats[tgt].adapter_reset_done);
  3321. }
  3322. seq_printf(m, "\nExternal Host Adapter Resets: %d\n", adapter->ext_resets);
  3323. seq_printf(m, "Host Adapter Internal Errors: %d\n", adapter->adapter_intern_errors);
  3324. return 0;
  3325. }
  3326. /*
  3327. blogic_msg prints Driver Messages.
  3328. */
  3329. static void blogic_msg(enum blogic_msglevel msglevel, char *fmt,
  3330. struct blogic_adapter *adapter, ...)
  3331. {
  3332. static char buf[BLOGIC_LINEBUF_SIZE];
  3333. static bool begin = true;
  3334. va_list args;
  3335. int len = 0;
  3336. va_start(args, adapter);
  3337. len = vsprintf(buf, fmt, args);
  3338. va_end(args);
  3339. if (msglevel == BLOGIC_ANNOUNCE_LEVEL) {
  3340. static int msglines = 0;
  3341. strcpy(&adapter->msgbuf[adapter->msgbuflen], buf);
  3342. adapter->msgbuflen += len;
  3343. if (++msglines <= 2)
  3344. printk("%sscsi: %s", blogic_msglevelmap[msglevel], buf);
  3345. } else if (msglevel == BLOGIC_INFO_LEVEL) {
  3346. strcpy(&adapter->msgbuf[adapter->msgbuflen], buf);
  3347. adapter->msgbuflen += len;
  3348. if (begin) {
  3349. if (buf[0] != '\n' || len > 1)
  3350. printk("%sscsi%d: %s", blogic_msglevelmap[msglevel], adapter->host_no, buf);
  3351. } else
  3352. printk("%s", buf);
  3353. } else {
  3354. if (begin) {
  3355. if (adapter != NULL && adapter->adapter_initd)
  3356. printk("%sscsi%d: %s", blogic_msglevelmap[msglevel], adapter->host_no, buf);
  3357. else
  3358. printk("%s%s", blogic_msglevelmap[msglevel], buf);
  3359. } else
  3360. printk("%s", buf);
  3361. }
  3362. begin = (buf[len - 1] == '\n');
  3363. }
  3364. /*
  3365. blogic_parse parses an individual option keyword. It returns true
  3366. and updates the pointer if the keyword is recognized and false otherwise.
  3367. */
  3368. static bool __init blogic_parse(char **str, char *keyword)
  3369. {
  3370. char *pointer = *str;
  3371. while (*keyword != '\0') {
  3372. char strch = *pointer++;
  3373. char keywordch = *keyword++;
  3374. if (strch >= 'A' && strch <= 'Z')
  3375. strch += 'a' - 'Z';
  3376. if (keywordch >= 'A' && keywordch <= 'Z')
  3377. keywordch += 'a' - 'Z';
  3378. if (strch != keywordch)
  3379. return false;
  3380. }
  3381. *str = pointer;
  3382. return true;
  3383. }
  3384. /*
  3385. blogic_parseopts handles processing of BusLogic Driver Options
  3386. specifications.
  3387. BusLogic Driver Options may be specified either via the Linux Kernel Command
  3388. Line or via the Loadable Kernel Module Installation Facility. Driver Options
  3389. for multiple host adapters may be specified either by separating the option
  3390. strings by a semicolon, or by specifying multiple "BusLogic=" strings on the
  3391. command line. Individual option specifications for a single host adapter are
  3392. separated by commas. The Probing and Debugging Options apply to all host
  3393. adapters whereas the remaining options apply individually only to the
  3394. selected host adapter.
  3395. The BusLogic Driver Probing Options are described in
  3396. <file:Documentation/scsi/BusLogic.txt>.
  3397. */
  3398. static int __init blogic_parseopts(char *options)
  3399. {
  3400. while (true) {
  3401. struct blogic_drvr_options *drvr_opts =
  3402. &blogic_drvr_options[blogic_drvr_options_count++];
  3403. int tgt_id;
  3404. memset(drvr_opts, 0, sizeof(struct blogic_drvr_options));
  3405. while (*options != '\0' && *options != ';') {
  3406. /* Probing Options. */
  3407. if (blogic_parse(&options, "IO:")) {
  3408. unsigned long io_addr = simple_strtoul(options,
  3409. &options, 0);
  3410. blogic_probe_options.limited_isa = true;
  3411. switch (io_addr) {
  3412. case 0x330:
  3413. blogic_probe_options.probe330 = true;
  3414. break;
  3415. case 0x334:
  3416. blogic_probe_options.probe334 = true;
  3417. break;
  3418. case 0x230:
  3419. blogic_probe_options.probe230 = true;
  3420. break;
  3421. case 0x234:
  3422. blogic_probe_options.probe234 = true;
  3423. break;
  3424. case 0x130:
  3425. blogic_probe_options.probe130 = true;
  3426. break;
  3427. case 0x134:
  3428. blogic_probe_options.probe134 = true;
  3429. break;
  3430. default:
  3431. blogic_err("BusLogic: Invalid Driver Options " "(invalid I/O Address 0x%X)\n", NULL, io_addr);
  3432. return 0;
  3433. }
  3434. } else if (blogic_parse(&options, "NoProbeISA"))
  3435. blogic_probe_options.noprobe_isa = true;
  3436. else if (blogic_parse(&options, "NoProbePCI"))
  3437. blogic_probe_options.noprobe_pci = true;
  3438. else if (blogic_parse(&options, "NoProbe"))
  3439. blogic_probe_options.noprobe = true;
  3440. else if (blogic_parse(&options, "NoSortPCI"))
  3441. blogic_probe_options.nosort_pci = true;
  3442. else if (blogic_parse(&options, "MultiMasterFirst"))
  3443. blogic_probe_options.multimaster_first = true;
  3444. else if (blogic_parse(&options, "FlashPointFirst"))
  3445. blogic_probe_options.flashpoint_first = true;
  3446. /* Tagged Queuing Options. */
  3447. else if (blogic_parse(&options, "QueueDepth:[") ||
  3448. blogic_parse(&options, "QD:[")) {
  3449. for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++) {
  3450. unsigned short qdepth = simple_strtoul(options, &options, 0);
  3451. if (qdepth > BLOGIC_MAX_TAG_DEPTH) {
  3452. blogic_err("BusLogic: Invalid Driver Options " "(invalid Queue Depth %d)\n", NULL, qdepth);
  3453. return 0;
  3454. }
  3455. drvr_opts->qdepth[tgt_id] = qdepth;
  3456. if (*options == ',')
  3457. options++;
  3458. else if (*options == ']')
  3459. break;
  3460. else {
  3461. blogic_err("BusLogic: Invalid Driver Options " "(',' or ']' expected at '%s')\n", NULL, options);
  3462. return 0;
  3463. }
  3464. }
  3465. if (*options != ']') {
  3466. blogic_err("BusLogic: Invalid Driver Options " "(']' expected at '%s')\n", NULL, options);
  3467. return 0;
  3468. } else
  3469. options++;
  3470. } else if (blogic_parse(&options, "QueueDepth:") || blogic_parse(&options, "QD:")) {
  3471. unsigned short qdepth = simple_strtoul(options, &options, 0);
  3472. if (qdepth == 0 ||
  3473. qdepth > BLOGIC_MAX_TAG_DEPTH) {
  3474. blogic_err("BusLogic: Invalid Driver Options " "(invalid Queue Depth %d)\n", NULL, qdepth);
  3475. return 0;
  3476. }
  3477. drvr_opts->common_qdepth = qdepth;
  3478. for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++)
  3479. drvr_opts->qdepth[tgt_id] = qdepth;
  3480. } else if (blogic_parse(&options, "TaggedQueuing:") ||
  3481. blogic_parse(&options, "TQ:")) {
  3482. if (blogic_parse(&options, "Default")) {
  3483. drvr_opts->tagq_ok = 0x0000;
  3484. drvr_opts->tagq_ok_mask = 0x0000;
  3485. } else if (blogic_parse(&options, "Enable")) {
  3486. drvr_opts->tagq_ok = 0xFFFF;
  3487. drvr_opts->tagq_ok_mask = 0xFFFF;
  3488. } else if (blogic_parse(&options, "Disable")) {
  3489. drvr_opts->tagq_ok = 0x0000;
  3490. drvr_opts->tagq_ok_mask = 0xFFFF;
  3491. } else {
  3492. unsigned short tgt_bit;
  3493. for (tgt_id = 0, tgt_bit = 1;
  3494. tgt_id < BLOGIC_MAXDEV;
  3495. tgt_id++, tgt_bit <<= 1)
  3496. switch (*options++) {
  3497. case 'Y':
  3498. drvr_opts->tagq_ok |= tgt_bit;
  3499. drvr_opts->tagq_ok_mask |= tgt_bit;
  3500. break;
  3501. case 'N':
  3502. drvr_opts->tagq_ok &= ~tgt_bit;
  3503. drvr_opts->tagq_ok_mask |= tgt_bit;
  3504. break;
  3505. case 'X':
  3506. break;
  3507. default:
  3508. options--;
  3509. tgt_id = BLOGIC_MAXDEV;
  3510. break;
  3511. }
  3512. }
  3513. }
  3514. /* Miscellaneous Options. */
  3515. else if (blogic_parse(&options, "BusSettleTime:") ||
  3516. blogic_parse(&options, "BST:")) {
  3517. unsigned short bus_settle_time =
  3518. simple_strtoul(options, &options, 0);
  3519. if (bus_settle_time > 5 * 60) {
  3520. blogic_err("BusLogic: Invalid Driver Options " "(invalid Bus Settle Time %d)\n", NULL, bus_settle_time);
  3521. return 0;
  3522. }
  3523. drvr_opts->bus_settle_time = bus_settle_time;
  3524. } else if (blogic_parse(&options,
  3525. "InhibitTargetInquiry"))
  3526. drvr_opts->stop_tgt_inquiry = true;
  3527. /* Debugging Options. */
  3528. else if (blogic_parse(&options, "TraceProbe"))
  3529. blogic_global_options.trace_probe = true;
  3530. else if (blogic_parse(&options, "TraceHardwareReset"))
  3531. blogic_global_options.trace_hw_reset = true;
  3532. else if (blogic_parse(&options, "TraceConfiguration"))
  3533. blogic_global_options.trace_config = true;
  3534. else if (blogic_parse(&options, "TraceErrors"))
  3535. blogic_global_options.trace_err = true;
  3536. else if (blogic_parse(&options, "Debug")) {
  3537. blogic_global_options.trace_probe = true;
  3538. blogic_global_options.trace_hw_reset = true;
  3539. blogic_global_options.trace_config = true;
  3540. blogic_global_options.trace_err = true;
  3541. }
  3542. if (*options == ',')
  3543. options++;
  3544. else if (*options != ';' && *options != '\0') {
  3545. blogic_err("BusLogic: Unexpected Driver Option '%s' " "ignored\n", NULL, options);
  3546. *options = '\0';
  3547. }
  3548. }
  3549. if (!(blogic_drvr_options_count == 0 ||
  3550. blogic_probeinfo_count == 0 ||
  3551. blogic_drvr_options_count == blogic_probeinfo_count)) {
  3552. blogic_err("BusLogic: Invalid Driver Options " "(all or no I/O Addresses must be specified)\n", NULL);
  3553. return 0;
  3554. }
  3555. /*
  3556. Tagged Queuing is disabled when the Queue Depth is 1 since queuing
  3557. multiple commands is not possible.
  3558. */
  3559. for (tgt_id = 0; tgt_id < BLOGIC_MAXDEV; tgt_id++)
  3560. if (drvr_opts->qdepth[tgt_id] == 1) {
  3561. unsigned short tgt_bit = 1 << tgt_id;
  3562. drvr_opts->tagq_ok &= ~tgt_bit;
  3563. drvr_opts->tagq_ok_mask |= tgt_bit;
  3564. }
  3565. if (*options == ';')
  3566. options++;
  3567. if (*options == '\0')
  3568. return 0;
  3569. }
  3570. return 1;
  3571. }
  3572. /*
  3573. Get it all started
  3574. */
  3575. static struct scsi_host_template blogic_template = {
  3576. .module = THIS_MODULE,
  3577. .proc_name = "BusLogic",
  3578. .write_info = blogic_write_info,
  3579. .show_info = blogic_show_info,
  3580. .name = "BusLogic",
  3581. .info = blogic_drvr_info,
  3582. .queuecommand = blogic_qcmd,
  3583. .slave_configure = blogic_slaveconfig,
  3584. .bios_param = blogic_diskparam,
  3585. .eh_host_reset_handler = blogic_hostreset,
  3586. #if 0
  3587. .eh_abort_handler = blogic_abort,
  3588. #endif
  3589. .unchecked_isa_dma = 1,
  3590. .max_sectors = 128,
  3591. .use_clustering = ENABLE_CLUSTERING,
  3592. };
  3593. /*
  3594. blogic_setup handles processing of Kernel Command Line Arguments.
  3595. */
  3596. static int __init blogic_setup(char *str)
  3597. {
  3598. int ints[3];
  3599. (void) get_options(str, ARRAY_SIZE(ints), ints);
  3600. if (ints[0] != 0) {
  3601. blogic_err("BusLogic: Obsolete Command Line Entry " "Format Ignored\n", NULL);
  3602. return 0;
  3603. }
  3604. if (str == NULL || *str == '\0')
  3605. return 0;
  3606. return blogic_parseopts(str);
  3607. }
  3608. /*
  3609. * Exit function. Deletes all hosts associated with this driver.
  3610. */
  3611. static void __exit blogic_exit(void)
  3612. {
  3613. struct blogic_adapter *ha, *next;
  3614. list_for_each_entry_safe(ha, next, &blogic_host_list, host_list)
  3615. blogic_deladapter(ha);
  3616. }
  3617. __setup("BusLogic=", blogic_setup);
  3618. #ifdef MODULE
  3619. /*static struct pci_device_id blogic_pci_tbl[] = {
  3620. { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER,
  3621. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  3622. { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC,
  3623. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  3624. { PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT,
  3625. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  3626. { }
  3627. };*/
  3628. static DEFINE_PCI_DEVICE_TABLE(blogic_pci_tbl) = {
  3629. {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER)},
  3630. {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_MULTIMASTER_NC)},
  3631. {PCI_DEVICE(PCI_VENDOR_ID_BUSLOGIC, PCI_DEVICE_ID_BUSLOGIC_FLASHPOINT)},
  3632. {0, },
  3633. };
  3634. #endif
  3635. MODULE_DEVICE_TABLE(pci, blogic_pci_tbl);
  3636. module_init(blogic_init);
  3637. module_exit(blogic_exit);