BusLogic.c 127 KB

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