qla1280.c 125 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488
  1. /******************************************************************************
  2. * QLOGIC LINUX SOFTWARE
  3. *
  4. * QLogic QLA1280 (Ultra2) and QLA12160 (Ultra3) SCSI driver
  5. * Copyright (C) 2000 Qlogic Corporation (www.qlogic.com)
  6. * Copyright (C) 2001-2004 Jes Sorensen, Wild Open Source Inc.
  7. * Copyright (C) 2003-2004 Christoph Hellwig
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. ******************************************************************************/
  20. #define QLA1280_VERSION "3.27.1"
  21. /*****************************************************************************
  22. Revision History:
  23. Rev 3.27.1, February 8, 2010, Michael Reed
  24. - Retain firmware image for error recovery.
  25. Rev 3.27, February 10, 2009, Michael Reed
  26. - General code cleanup.
  27. - Improve error recovery.
  28. Rev 3.26, January 16, 2006 Jes Sorensen
  29. - Ditch all < 2.6 support
  30. Rev 3.25.1, February 10, 2005 Christoph Hellwig
  31. - use pci_map_single to map non-S/G requests
  32. - remove qla1280_proc_info
  33. Rev 3.25, September 28, 2004, Christoph Hellwig
  34. - add support for ISP1020/1040
  35. - don't include "scsi.h" anymore for 2.6.x
  36. Rev 3.24.4 June 7, 2004 Christoph Hellwig
  37. - restructure firmware loading, cleanup initialization code
  38. - prepare support for ISP1020/1040 chips
  39. Rev 3.24.3 January 19, 2004, Jes Sorensen
  40. - Handle PCI DMA mask settings correctly
  41. - Correct order of error handling in probe_one, free_irq should not
  42. be called if request_irq failed
  43. Rev 3.24.2 January 19, 2004, James Bottomley & Andrew Vasquez
  44. - Big endian fixes (James)
  45. - Remove bogus IOCB content on zero data transfer commands (Andrew)
  46. Rev 3.24.1 January 5, 2004, Jes Sorensen
  47. - Initialize completion queue to avoid OOPS on probe
  48. - Handle interrupts during mailbox testing
  49. Rev 3.24 November 17, 2003, Christoph Hellwig
  50. - use struct list_head for completion queue
  51. - avoid old Scsi_FOO typedefs
  52. - cleanup 2.4 compat glue a bit
  53. - use <scsi/scsi_*.h> headers on 2.6 instead of "scsi.h"
  54. - make initialization for memory mapped vs port I/O more similar
  55. - remove broken pci config space manipulation
  56. - kill more cruft
  57. - this is an almost perfect 2.6 scsi driver now! ;)
  58. Rev 3.23.39 December 17, 2003, Jes Sorensen
  59. - Delete completion queue from srb if mailbox command failed to
  60. to avoid qla1280_done completeting qla1280_error_action's
  61. obsolete context
  62. - Reduce arguments for qla1280_done
  63. Rev 3.23.38 October 18, 2003, Christoph Hellwig
  64. - Convert to new-style hotplugable driver for 2.6
  65. - Fix missing scsi_unregister/scsi_host_put on HBA removal
  66. - Kill some more cruft
  67. Rev 3.23.37 October 1, 2003, Jes Sorensen
  68. - Make MMIO depend on CONFIG_X86_VISWS instead of yet another
  69. random CONFIG option
  70. - Clean up locking in probe path
  71. Rev 3.23.36 October 1, 2003, Christoph Hellwig
  72. - queuecommand only ever receives new commands - clear flags
  73. - Reintegrate lost fixes from Linux 2.5
  74. Rev 3.23.35 August 14, 2003, Jes Sorensen
  75. - Build against 2.6
  76. Rev 3.23.34 July 23, 2003, Jes Sorensen
  77. - Remove pointless TRUE/FALSE macros
  78. - Clean up vchan handling
  79. Rev 3.23.33 July 3, 2003, Jes Sorensen
  80. - Don't define register access macros before define determining MMIO.
  81. This just happened to work out on ia64 but not elsewhere.
  82. - Don't try and read from the card while it is in reset as
  83. it won't respond and causes an MCA
  84. Rev 3.23.32 June 23, 2003, Jes Sorensen
  85. - Basic support for boot time arguments
  86. Rev 3.23.31 June 8, 2003, Jes Sorensen
  87. - Reduce boot time messages
  88. Rev 3.23.30 June 6, 2003, Jes Sorensen
  89. - Do not enable sync/wide/ppr before it has been determined
  90. that the target device actually supports it
  91. - Enable DMA arbitration for multi channel controllers
  92. Rev 3.23.29 June 3, 2003, Jes Sorensen
  93. - Port to 2.5.69
  94. Rev 3.23.28 June 3, 2003, Jes Sorensen
  95. - Eliminate duplicate marker commands on bus resets
  96. - Handle outstanding commands appropriately on bus/device resets
  97. Rev 3.23.27 May 28, 2003, Jes Sorensen
  98. - Remove bogus input queue code, let the Linux SCSI layer do the work
  99. - Clean up NVRAM handling, only read it once from the card
  100. - Add a number of missing default nvram parameters
  101. Rev 3.23.26 Beta May 28, 2003, Jes Sorensen
  102. - Use completion queue for mailbox commands instead of busy wait
  103. Rev 3.23.25 Beta May 27, 2003, James Bottomley
  104. - Migrate to use new error handling code
  105. Rev 3.23.24 Beta May 21, 2003, James Bottomley
  106. - Big endian support
  107. - Cleanup data direction code
  108. Rev 3.23.23 Beta May 12, 2003, Jes Sorensen
  109. - Switch to using MMIO instead of PIO
  110. Rev 3.23.22 Beta April 15, 2003, Jes Sorensen
  111. - Fix PCI parity problem with 12160 during reset.
  112. Rev 3.23.21 Beta April 14, 2003, Jes Sorensen
  113. - Use pci_map_page()/pci_unmap_page() instead of map_single version.
  114. Rev 3.23.20 Beta April 9, 2003, Jes Sorensen
  115. - Remove < 2.4.x support
  116. - Introduce HOST_LOCK to make the spin lock changes portable.
  117. - Remove a bunch of idiotic and unnecessary typedef's
  118. - Kill all leftovers of target-mode support which never worked anyway
  119. Rev 3.23.19 Beta April 11, 2002, Linus Torvalds
  120. - Do qla1280_pci_config() before calling request_irq() and
  121. request_region()
  122. - Use pci_dma_hi32() to handle upper word of DMA addresses instead
  123. of large shifts
  124. - Hand correct arguments to free_irq() in case of failure
  125. Rev 3.23.18 Beta April 11, 2002, Jes Sorensen
  126. - Run source through Lindent and clean up the output
  127. Rev 3.23.17 Beta April 11, 2002, Jes Sorensen
  128. - Update SCSI firmware to qla1280 v8.15.00 and qla12160 v10.04.32
  129. Rev 3.23.16 Beta March 19, 2002, Jes Sorensen
  130. - Rely on mailbox commands generating interrupts - do not
  131. run qla1280_isr() from ql1280_mailbox_command()
  132. - Remove device_reg_t
  133. - Integrate ql12160_set_target_parameters() with 1280 version
  134. - Make qla1280_setup() non static
  135. - Do not call qla1280_check_for_dead_scsi_bus() on every I/O request
  136. sent to the card - this command pauses the firmware!!!
  137. Rev 3.23.15 Beta March 19, 2002, Jes Sorensen
  138. - Clean up qla1280.h - remove obsolete QL_DEBUG_LEVEL_x definitions
  139. - Remove a pile of pointless and confusing (srb_t **) and
  140. (scsi_lu_t *) typecasts
  141. - Explicit mark that we do not use the new error handling (for now)
  142. - Remove scsi_qla_host_t and use 'struct' instead
  143. - Remove in_abort, watchdog_enabled, dpc, dpc_sched, bios_enabled,
  144. pci_64bit_slot flags which weren't used for anything anyway
  145. - Grab host->host_lock while calling qla1280_isr() from abort()
  146. - Use spin_lock()/spin_unlock() in qla1280_intr_handler() - we
  147. do not need to save/restore flags in the interrupt handler
  148. - Enable interrupts early (before any mailbox access) in preparation
  149. for cleaning up the mailbox handling
  150. Rev 3.23.14 Beta March 14, 2002, Jes Sorensen
  151. - Further cleanups. Remove all trace of QL_DEBUG_LEVEL_x and replace
  152. it with proper use of dprintk().
  153. - Make qla1280_print_scsi_cmd() and qla1280_dump_buffer() both take
  154. a debug level argument to determine if data is to be printed
  155. - Add KERN_* info to printk()
  156. Rev 3.23.13 Beta March 14, 2002, Jes Sorensen
  157. - Significant cosmetic cleanups
  158. - Change debug code to use dprintk() and remove #if mess
  159. Rev 3.23.12 Beta March 13, 2002, Jes Sorensen
  160. - More cosmetic cleanups, fix places treating return as function
  161. - use cpu_relax() in qla1280_debounce_register()
  162. Rev 3.23.11 Beta March 13, 2002, Jes Sorensen
  163. - Make it compile under 2.5.5
  164. Rev 3.23.10 Beta October 1, 2001, Jes Sorensen
  165. - Do no typecast short * to long * in QL1280BoardTbl, this
  166. broke miserably on big endian boxes
  167. Rev 3.23.9 Beta September 30, 2001, Jes Sorensen
  168. - Remove pre 2.2 hack for checking for reentrance in interrupt handler
  169. - Make data types used to receive from SCSI_{BUS,TCN,LUN}_32
  170. unsigned int to match the types from struct scsi_cmnd
  171. Rev 3.23.8 Beta September 29, 2001, Jes Sorensen
  172. - Remove bogus timer_t typedef from qla1280.h
  173. - Remove obsolete pre 2.2 PCI setup code, use proper #define's
  174. for PCI_ values, call pci_set_master()
  175. - Fix memleak of qla1280_buffer on module unload
  176. - Only compile module parsing code #ifdef MODULE - should be
  177. changed to use individual MODULE_PARM's later
  178. - Remove dummy_buffer that was never modified nor printed
  179. - ENTER()/LEAVE() are noops unless QL_DEBUG_LEVEL_3, hence remove
  180. #ifdef QL_DEBUG_LEVEL_3/#endif around ENTER()/LEAVE() calls
  181. - Remove \r from print statements, this is Linux, not DOS
  182. - Remove obsolete QLA1280_{SCSILU,INTR,RING}_{LOCK,UNLOCK}
  183. dummy macros
  184. - Remove C++ compile hack in header file as Linux driver are not
  185. supposed to be compiled as C++
  186. - Kill MS_64BITS macro as it makes the code more readable
  187. - Remove unnecessary flags.in_interrupts bit
  188. Rev 3.23.7 Beta August 20, 2001, Jes Sorensen
  189. - Dont' check for set flags on q->q_flag one by one in qla1280_next()
  190. - Check whether the interrupt was generated by the QLA1280 before
  191. doing any processing
  192. - qla1280_status_entry(): Only zero out part of sense_buffer that
  193. is not being copied into
  194. - Remove more superflouous typecasts
  195. - qla1280_32bit_start_scsi() replace home-brew memcpy() with memcpy()
  196. Rev 3.23.6 Beta August 20, 2001, Tony Luck, Intel
  197. - Don't walk the entire list in qla1280_putq_t() just to directly
  198. grab the pointer to the last element afterwards
  199. Rev 3.23.5 Beta August 9, 2001, Jes Sorensen
  200. - Don't use IRQF_DISABLED, it's use is deprecated for this kinda driver
  201. Rev 3.23.4 Beta August 8, 2001, Jes Sorensen
  202. - Set dev->max_sectors to 1024
  203. Rev 3.23.3 Beta August 6, 2001, Jes Sorensen
  204. - Provide compat macros for pci_enable_device(), pci_find_subsys()
  205. and scsi_set_pci_device()
  206. - Call scsi_set_pci_device() for all devices
  207. - Reduce size of kernel version dependent device probe code
  208. - Move duplicate probe/init code to separate function
  209. - Handle error if qla1280_mem_alloc() fails
  210. - Kill OFFSET() macro and use Linux's PCI definitions instead
  211. - Kill private structure defining PCI config space (struct config_reg)
  212. - Only allocate I/O port region if not in MMIO mode
  213. - Remove duplicate (unused) sanity check of sife of srb_t
  214. Rev 3.23.2 Beta August 6, 2001, Jes Sorensen
  215. - Change home-brew memset() implementations to use memset()
  216. - Remove all references to COMTRACE() - accessing a PC's COM2 serial
  217. port directly is not legal under Linux.
  218. Rev 3.23.1 Beta April 24, 2001, Jes Sorensen
  219. - Remove pre 2.2 kernel support
  220. - clean up 64 bit DMA setting to use 2.4 API (provide backwards compat)
  221. - Fix MMIO access to use readl/writel instead of directly
  222. dereferencing pointers
  223. - Nuke MSDOS debugging code
  224. - Change true/false data types to int from uint8_t
  225. - Use int for counters instead of uint8_t etc.
  226. - Clean up size & byte order conversion macro usage
  227. Rev 3.23 Beta January 11, 2001 BN Qlogic
  228. - Added check of device_id when handling non
  229. QLA12160s during detect().
  230. Rev 3.22 Beta January 5, 2001 BN Qlogic
  231. - Changed queue_task() to schedule_task()
  232. for kernels 2.4.0 and higher.
  233. Note: 2.4.0-testxx kernels released prior to
  234. the actual 2.4.0 kernel release on January 2001
  235. will get compile/link errors with schedule_task().
  236. Please update your kernel to released 2.4.0 level,
  237. or comment lines in this file flagged with 3.22
  238. to resolve compile/link error of schedule_task().
  239. - Added -DCONFIG_SMP in addition to -D__SMP__
  240. in Makefile for 2.4.0 builds of driver as module.
  241. Rev 3.21 Beta January 4, 2001 BN Qlogic
  242. - Changed criteria of 64/32 Bit mode of HBA
  243. operation according to BITS_PER_LONG rather
  244. than HBA's NVRAM setting of >4Gig memory bit;
  245. so that the HBA auto-configures without the need
  246. to setup each system individually.
  247. Rev 3.20 Beta December 5, 2000 BN Qlogic
  248. - Added priority handling to IA-64 onboard SCSI
  249. ISP12160 chip for kernels greater than 2.3.18.
  250. - Added irqrestore for qla1280_intr_handler.
  251. - Enabled /proc/scsi/qla1280 interface.
  252. - Clear /proc/scsi/qla1280 counters in detect().
  253. Rev 3.19 Beta October 13, 2000 BN Qlogic
  254. - Declare driver_template for new kernel
  255. (2.4.0 and greater) scsi initialization scheme.
  256. - Update /proc/scsi entry for 2.3.18 kernels and
  257. above as qla1280
  258. Rev 3.18 Beta October 10, 2000 BN Qlogic
  259. - Changed scan order of adapters to map
  260. the QLA12160 followed by the QLA1280.
  261. Rev 3.17 Beta September 18, 2000 BN Qlogic
  262. - Removed warnings for 32 bit 2.4.x compiles
  263. - Corrected declared size for request and response
  264. DMA addresses that are kept in each ha
  265. Rev. 3.16 Beta August 25, 2000 BN Qlogic
  266. - Corrected 64 bit addressing issue on IA-64
  267. where the upper 32 bits were not properly
  268. passed to the RISC engine.
  269. Rev. 3.15 Beta August 22, 2000 BN Qlogic
  270. - Modified qla1280_setup_chip to properly load
  271. ISP firmware for greater that 4 Gig memory on IA-64
  272. Rev. 3.14 Beta August 16, 2000 BN Qlogic
  273. - Added setting of dma_mask to full 64 bit
  274. if flags.enable_64bit_addressing is set in NVRAM
  275. Rev. 3.13 Beta August 16, 2000 BN Qlogic
  276. - Use new PCI DMA mapping APIs for 2.4.x kernel
  277. Rev. 3.12 July 18, 2000 Redhat & BN Qlogic
  278. - Added check of pci_enable_device to detect() for 2.3.x
  279. - Use pci_resource_start() instead of
  280. pdev->resource[0].start in detect() for 2.3.x
  281. - Updated driver version
  282. Rev. 3.11 July 14, 2000 BN Qlogic
  283. - Updated SCSI Firmware to following versions:
  284. qla1x80: 8.13.08
  285. qla1x160: 10.04.08
  286. - Updated driver version to 3.11
  287. Rev. 3.10 June 23, 2000 BN Qlogic
  288. - Added filtering of AMI SubSys Vendor ID devices
  289. Rev. 3.9
  290. - DEBUG_QLA1280 undefined and new version BN Qlogic
  291. Rev. 3.08b May 9, 2000 MD Dell
  292. - Added logic to check against AMI subsystem vendor ID
  293. Rev. 3.08 May 4, 2000 DG Qlogic
  294. - Added logic to check for PCI subsystem ID.
  295. Rev. 3.07 Apr 24, 2000 DG & BN Qlogic
  296. - Updated SCSI Firmware to following versions:
  297. qla12160: 10.01.19
  298. qla1280: 8.09.00
  299. Rev. 3.06 Apr 12, 2000 DG & BN Qlogic
  300. - Internal revision; not released
  301. Rev. 3.05 Mar 28, 2000 DG & BN Qlogic
  302. - Edit correction for virt_to_bus and PROC.
  303. Rev. 3.04 Mar 28, 2000 DG & BN Qlogic
  304. - Merge changes from ia64 port.
  305. Rev. 3.03 Mar 28, 2000 BN Qlogic
  306. - Increase version to reflect new code drop with compile fix
  307. of issue with inclusion of linux/spinlock for 2.3 kernels
  308. Rev. 3.02 Mar 15, 2000 BN Qlogic
  309. - Merge qla1280_proc_info from 2.10 code base
  310. Rev. 3.01 Feb 10, 2000 BN Qlogic
  311. - Corrected code to compile on a 2.2.x kernel.
  312. Rev. 3.00 Jan 17, 2000 DG Qlogic
  313. - Added 64-bit support.
  314. Rev. 2.07 Nov 9, 1999 DG Qlogic
  315. - Added new routine to set target parameters for ISP12160.
  316. Rev. 2.06 Sept 10, 1999 DG Qlogic
  317. - Added support for ISP12160 Ultra 3 chip.
  318. Rev. 2.03 August 3, 1999 Fred Lewis, Intel DuPont
  319. - Modified code to remove errors generated when compiling with
  320. Cygnus IA64 Compiler.
  321. - Changed conversion of pointers to unsigned longs instead of integers.
  322. - Changed type of I/O port variables from uint32_t to unsigned long.
  323. - Modified OFFSET macro to work with 64-bit as well as 32-bit.
  324. - Changed sprintf and printk format specifiers for pointers to %p.
  325. - Changed some int to long type casts where needed in sprintf & printk.
  326. - Added l modifiers to sprintf and printk format specifiers for longs.
  327. - Removed unused local variables.
  328. Rev. 1.20 June 8, 1999 DG, Qlogic
  329. Changes to support RedHat release 6.0 (kernel 2.2.5).
  330. - Added SCSI exclusive access lock (io_request_lock) when accessing
  331. the adapter.
  332. - Added changes for the new LINUX interface template. Some new error
  333. handling routines have been added to the template, but for now we
  334. will use the old ones.
  335. - Initial Beta Release.
  336. *****************************************************************************/
  337. #include <linux/module.h>
  338. #include <linux/types.h>
  339. #include <linux/string.h>
  340. #include <linux/errno.h>
  341. #include <linux/kernel.h>
  342. #include <linux/ioport.h>
  343. #include <linux/delay.h>
  344. #include <linux/timer.h>
  345. #include <linux/pci.h>
  346. #include <linux/proc_fs.h>
  347. #include <linux/stat.h>
  348. #include <linux/pci_ids.h>
  349. #include <linux/interrupt.h>
  350. #include <linux/init.h>
  351. #include <linux/dma-mapping.h>
  352. #include <linux/firmware.h>
  353. #include <asm/io.h>
  354. #include <asm/irq.h>
  355. #include <asm/byteorder.h>
  356. #include <asm/processor.h>
  357. #include <asm/types.h>
  358. #include <scsi/scsi.h>
  359. #include <scsi/scsi_cmnd.h>
  360. #include <scsi/scsi_device.h>
  361. #include <scsi/scsi_host.h>
  362. #include <scsi/scsi_tcq.h>
  363. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  364. #include <asm/sn/io.h>
  365. #endif
  366. /*
  367. * Compile time Options:
  368. * 0 - Disable and 1 - Enable
  369. */
  370. #define DEBUG_QLA1280_INTR 0
  371. #define DEBUG_PRINT_NVRAM 0
  372. #define DEBUG_QLA1280 0
  373. #define MEMORY_MAPPED_IO 1
  374. #include "qla1280.h"
  375. #ifndef BITS_PER_LONG
  376. #error "BITS_PER_LONG not defined!"
  377. #endif
  378. #if (BITS_PER_LONG == 64) || defined CONFIG_HIGHMEM
  379. #define QLA_64BIT_PTR 1
  380. #endif
  381. #ifdef QLA_64BIT_PTR
  382. #define pci_dma_hi32(a) ((a >> 16) >> 16)
  383. #else
  384. #define pci_dma_hi32(a) 0
  385. #endif
  386. #define pci_dma_lo32(a) (a & 0xffffffff)
  387. #define NVRAM_DELAY() udelay(500) /* 2 microseconds */
  388. #if defined(__ia64__) && !defined(ia64_platform_is)
  389. #define ia64_platform_is(foo) (!strcmp(x, platform_name))
  390. #endif
  391. #define IS_ISP1040(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020)
  392. #define IS_ISP1x40(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1020 || \
  393. ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP1240)
  394. #define IS_ISP1x160(ha) (ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP10160 || \
  395. ha->pdev->device == PCI_DEVICE_ID_QLOGIC_ISP12160)
  396. static int qla1280_probe_one(struct pci_dev *, const struct pci_device_id *);
  397. static void qla1280_remove_one(struct pci_dev *);
  398. /*
  399. * QLogic Driver Support Function Prototypes.
  400. */
  401. static void qla1280_done(struct scsi_qla_host *);
  402. static int qla1280_get_token(char *);
  403. static int qla1280_setup(char *s) __init;
  404. /*
  405. * QLogic ISP1280 Hardware Support Function Prototypes.
  406. */
  407. static int qla1280_load_firmware(struct scsi_qla_host *);
  408. static int qla1280_init_rings(struct scsi_qla_host *);
  409. static int qla1280_nvram_config(struct scsi_qla_host *);
  410. static int qla1280_mailbox_command(struct scsi_qla_host *,
  411. uint8_t, uint16_t *);
  412. static int qla1280_bus_reset(struct scsi_qla_host *, int);
  413. static int qla1280_device_reset(struct scsi_qla_host *, int, int);
  414. static int qla1280_abort_command(struct scsi_qla_host *, struct srb *, int);
  415. static int qla1280_abort_isp(struct scsi_qla_host *);
  416. #ifdef QLA_64BIT_PTR
  417. static int qla1280_64bit_start_scsi(struct scsi_qla_host *, struct srb *);
  418. #else
  419. static int qla1280_32bit_start_scsi(struct scsi_qla_host *, struct srb *);
  420. #endif
  421. static void qla1280_nv_write(struct scsi_qla_host *, uint16_t);
  422. static void qla1280_poll(struct scsi_qla_host *);
  423. static void qla1280_reset_adapter(struct scsi_qla_host *);
  424. static void qla1280_marker(struct scsi_qla_host *, int, int, int, u8);
  425. static void qla1280_isp_cmd(struct scsi_qla_host *);
  426. static void qla1280_isr(struct scsi_qla_host *, struct list_head *);
  427. static void qla1280_rst_aen(struct scsi_qla_host *);
  428. static void qla1280_status_entry(struct scsi_qla_host *, struct response *,
  429. struct list_head *);
  430. static void qla1280_error_entry(struct scsi_qla_host *, struct response *,
  431. struct list_head *);
  432. static uint16_t qla1280_get_nvram_word(struct scsi_qla_host *, uint32_t);
  433. static uint16_t qla1280_nvram_request(struct scsi_qla_host *, uint32_t);
  434. static uint16_t qla1280_debounce_register(volatile uint16_t __iomem *);
  435. static request_t *qla1280_req_pkt(struct scsi_qla_host *);
  436. static int qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *,
  437. unsigned int);
  438. static void qla1280_get_target_parameters(struct scsi_qla_host *,
  439. struct scsi_device *);
  440. static int qla1280_set_target_parameters(struct scsi_qla_host *, int, int);
  441. static struct qla_driver_setup driver_setup;
  442. /*
  443. * convert scsi data direction to request_t control flags
  444. */
  445. static inline uint16_t
  446. qla1280_data_direction(struct scsi_cmnd *cmnd)
  447. {
  448. switch(cmnd->sc_data_direction) {
  449. case DMA_FROM_DEVICE:
  450. return BIT_5;
  451. case DMA_TO_DEVICE:
  452. return BIT_6;
  453. case DMA_BIDIRECTIONAL:
  454. return BIT_5 | BIT_6;
  455. /*
  456. * We could BUG() on default here if one of the four cases aren't
  457. * met, but then again if we receive something like that from the
  458. * SCSI layer we have more serious problems. This shuts up GCC.
  459. */
  460. case DMA_NONE:
  461. default:
  462. return 0;
  463. }
  464. }
  465. #if DEBUG_QLA1280
  466. static void __qla1280_print_scsi_cmd(struct scsi_cmnd * cmd);
  467. static void __qla1280_dump_buffer(char *, int);
  468. #endif
  469. /*
  470. * insmod needs to find the variable and make it point to something
  471. */
  472. #ifdef MODULE
  473. static char *qla1280;
  474. /* insmod qla1280 options=verbose" */
  475. module_param(qla1280, charp, 0);
  476. #else
  477. __setup("qla1280=", qla1280_setup);
  478. #endif
  479. /*
  480. * We use the scsi_pointer structure that's included with each scsi_command
  481. * to overlay our struct srb over it. qla1280_init() checks that a srb is not
  482. * bigger than a scsi_pointer.
  483. */
  484. #define CMD_SP(Cmnd) &Cmnd->SCp
  485. #define CMD_CDBLEN(Cmnd) Cmnd->cmd_len
  486. #define CMD_CDBP(Cmnd) Cmnd->cmnd
  487. #define CMD_SNSP(Cmnd) Cmnd->sense_buffer
  488. #define CMD_SNSLEN(Cmnd) SCSI_SENSE_BUFFERSIZE
  489. #define CMD_RESULT(Cmnd) Cmnd->result
  490. #define CMD_HANDLE(Cmnd) Cmnd->host_scribble
  491. #define CMD_REQUEST(Cmnd) Cmnd->request->cmd
  492. #define CMD_HOST(Cmnd) Cmnd->device->host
  493. #define SCSI_BUS_32(Cmnd) Cmnd->device->channel
  494. #define SCSI_TCN_32(Cmnd) Cmnd->device->id
  495. #define SCSI_LUN_32(Cmnd) Cmnd->device->lun
  496. /*****************************************/
  497. /* ISP Boards supported by this driver */
  498. /*****************************************/
  499. struct qla_boards {
  500. char *name; /* Board ID String */
  501. int numPorts; /* Number of SCSI ports */
  502. int fw_index; /* index into qla1280_fw_tbl for firmware */
  503. };
  504. /* NOTE: the last argument in each entry is used to index ql1280_board_tbl */
  505. static struct pci_device_id qla1280_pci_tbl[] = {
  506. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP12160,
  507. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  508. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1020,
  509. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
  510. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1080,
  511. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
  512. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1240,
  513. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
  514. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP1280,
  515. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
  516. {PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP10160,
  517. PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
  518. {0,}
  519. };
  520. MODULE_DEVICE_TABLE(pci, qla1280_pci_tbl);
  521. DEFINE_MUTEX(qla1280_firmware_mutex);
  522. struct qla_fw {
  523. char *fwname;
  524. const struct firmware *fw;
  525. };
  526. #define QL_NUM_FW_IMAGES 3
  527. struct qla_fw qla1280_fw_tbl[QL_NUM_FW_IMAGES] = {
  528. {"qlogic/1040.bin", NULL}, /* image 0 */
  529. {"qlogic/1280.bin", NULL}, /* image 1 */
  530. {"qlogic/12160.bin", NULL}, /* image 2 */
  531. };
  532. /* NOTE: Order of boards in this table must match order in qla1280_pci_tbl */
  533. static struct qla_boards ql1280_board_tbl[] = {
  534. {.name = "QLA12160", .numPorts = 2, .fw_index = 2},
  535. {.name = "QLA1040" , .numPorts = 1, .fw_index = 0},
  536. {.name = "QLA1080" , .numPorts = 1, .fw_index = 1},
  537. {.name = "QLA1240" , .numPorts = 2, .fw_index = 1},
  538. {.name = "QLA1280" , .numPorts = 2, .fw_index = 1},
  539. {.name = "QLA10160", .numPorts = 1, .fw_index = 2},
  540. {.name = " ", .numPorts = 0, .fw_index = -1},
  541. };
  542. static int qla1280_verbose = 1;
  543. #if DEBUG_QLA1280
  544. static int ql_debug_level = 1;
  545. #define dprintk(level, format, a...) \
  546. do { if (ql_debug_level >= level) printk(KERN_ERR format, ##a); } while(0)
  547. #define qla1280_dump_buffer(level, buf, size) \
  548. if (ql_debug_level >= level) __qla1280_dump_buffer(buf, size)
  549. #define qla1280_print_scsi_cmd(level, cmd) \
  550. if (ql_debug_level >= level) __qla1280_print_scsi_cmd(cmd)
  551. #else
  552. #define ql_debug_level 0
  553. #define dprintk(level, format, a...) do{}while(0)
  554. #define qla1280_dump_buffer(a, b, c) do{}while(0)
  555. #define qla1280_print_scsi_cmd(a, b) do{}while(0)
  556. #endif
  557. #define ENTER(x) dprintk(3, "qla1280 : Entering %s()\n", x);
  558. #define LEAVE(x) dprintk(3, "qla1280 : Leaving %s()\n", x);
  559. #define ENTER_INTR(x) dprintk(4, "qla1280 : Entering %s()\n", x);
  560. #define LEAVE_INTR(x) dprintk(4, "qla1280 : Leaving %s()\n", x);
  561. static int qla1280_read_nvram(struct scsi_qla_host *ha)
  562. {
  563. uint16_t *wptr;
  564. uint8_t chksum;
  565. int cnt, i;
  566. struct nvram *nv;
  567. ENTER("qla1280_read_nvram");
  568. if (driver_setup.no_nvram)
  569. return 1;
  570. printk(KERN_INFO "scsi(%ld): Reading NVRAM\n", ha->host_no);
  571. wptr = (uint16_t *)&ha->nvram;
  572. nv = &ha->nvram;
  573. chksum = 0;
  574. for (cnt = 0; cnt < 3; cnt++) {
  575. *wptr = qla1280_get_nvram_word(ha, cnt);
  576. chksum += *wptr & 0xff;
  577. chksum += (*wptr >> 8) & 0xff;
  578. wptr++;
  579. }
  580. if (nv->id0 != 'I' || nv->id1 != 'S' ||
  581. nv->id2 != 'P' || nv->id3 != ' ' || nv->version < 1) {
  582. dprintk(2, "Invalid nvram ID or version!\n");
  583. chksum = 1;
  584. } else {
  585. for (; cnt < sizeof(struct nvram); cnt++) {
  586. *wptr = qla1280_get_nvram_word(ha, cnt);
  587. chksum += *wptr & 0xff;
  588. chksum += (*wptr >> 8) & 0xff;
  589. wptr++;
  590. }
  591. }
  592. dprintk(3, "qla1280_read_nvram: NVRAM Magic ID= %c %c %c %02x"
  593. " version %i\n", nv->id0, nv->id1, nv->id2, nv->id3,
  594. nv->version);
  595. if (chksum) {
  596. if (!driver_setup.no_nvram)
  597. printk(KERN_WARNING "scsi(%ld): Unable to identify or "
  598. "validate NVRAM checksum, using default "
  599. "settings\n", ha->host_no);
  600. ha->nvram_valid = 0;
  601. } else
  602. ha->nvram_valid = 1;
  603. /* The firmware interface is, um, interesting, in that the
  604. * actual firmware image on the chip is little endian, thus,
  605. * the process of taking that image to the CPU would end up
  606. * little endian. However, the firmware interface requires it
  607. * to be read a word (two bytes) at a time.
  608. *
  609. * The net result of this would be that the word (and
  610. * doubleword) quantites in the firmware would be correct, but
  611. * the bytes would be pairwise reversed. Since most of the
  612. * firmware quantites are, in fact, bytes, we do an extra
  613. * le16_to_cpu() in the firmware read routine.
  614. *
  615. * The upshot of all this is that the bytes in the firmware
  616. * are in the correct places, but the 16 and 32 bit quantites
  617. * are still in little endian format. We fix that up below by
  618. * doing extra reverses on them */
  619. nv->isp_parameter = cpu_to_le16(nv->isp_parameter);
  620. nv->firmware_feature.w = cpu_to_le16(nv->firmware_feature.w);
  621. for(i = 0; i < MAX_BUSES; i++) {
  622. nv->bus[i].selection_timeout = cpu_to_le16(nv->bus[i].selection_timeout);
  623. nv->bus[i].max_queue_depth = cpu_to_le16(nv->bus[i].max_queue_depth);
  624. }
  625. dprintk(1, "qla1280_read_nvram: Completed Reading NVRAM\n");
  626. LEAVE("qla1280_read_nvram");
  627. return chksum;
  628. }
  629. /**************************************************************************
  630. * qla1280_info
  631. * Return a string describing the driver.
  632. **************************************************************************/
  633. static const char *
  634. qla1280_info(struct Scsi_Host *host)
  635. {
  636. static char qla1280_scsi_name_buffer[125];
  637. char *bp;
  638. struct scsi_qla_host *ha;
  639. struct qla_boards *bdp;
  640. bp = &qla1280_scsi_name_buffer[0];
  641. ha = (struct scsi_qla_host *)host->hostdata;
  642. bdp = &ql1280_board_tbl[ha->devnum];
  643. memset(bp, 0, sizeof(qla1280_scsi_name_buffer));
  644. sprintf (bp,
  645. "QLogic %s PCI to SCSI Host Adapter\n"
  646. " Firmware version: %2d.%02d.%02d, Driver version %s",
  647. &bdp->name[0], ha->fwver1, ha->fwver2, ha->fwver3,
  648. QLA1280_VERSION);
  649. return bp;
  650. }
  651. /**************************************************************************
  652. * qla1280_queuecommand
  653. * Queue a command to the controller.
  654. *
  655. * Note:
  656. * The mid-level driver tries to ensures that queuecommand never gets invoked
  657. * concurrently with itself or the interrupt handler (although the
  658. * interrupt handler may call this routine as part of request-completion
  659. * handling). Unfortunely, it sometimes calls the scheduler in interrupt
  660. * context which is a big NO! NO!.
  661. **************************************************************************/
  662. static int
  663. qla1280_queuecommand_lck(struct scsi_cmnd *cmd, void (*fn)(struct scsi_cmnd *))
  664. {
  665. struct Scsi_Host *host = cmd->device->host;
  666. struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
  667. struct srb *sp = (struct srb *)CMD_SP(cmd);
  668. int status;
  669. cmd->scsi_done = fn;
  670. sp->cmd = cmd;
  671. sp->flags = 0;
  672. sp->wait = NULL;
  673. CMD_HANDLE(cmd) = (unsigned char *)NULL;
  674. qla1280_print_scsi_cmd(5, cmd);
  675. #ifdef QLA_64BIT_PTR
  676. /*
  677. * Using 64 bit commands if the PCI bridge doesn't support it is a
  678. * bit wasteful, however this should really only happen if one's
  679. * PCI controller is completely broken, like the BCM1250. For
  680. * sane hardware this is not an issue.
  681. */
  682. status = qla1280_64bit_start_scsi(ha, sp);
  683. #else
  684. status = qla1280_32bit_start_scsi(ha, sp);
  685. #endif
  686. return status;
  687. }
  688. static DEF_SCSI_QCMD(qla1280_queuecommand)
  689. enum action {
  690. ABORT_COMMAND,
  691. DEVICE_RESET,
  692. BUS_RESET,
  693. ADAPTER_RESET,
  694. };
  695. static void qla1280_mailbox_timeout(struct timer_list *t)
  696. {
  697. struct scsi_qla_host *ha = from_timer(ha, t, mailbox_timer);
  698. struct device_reg __iomem *reg;
  699. reg = ha->iobase;
  700. ha->mailbox_out[0] = RD_REG_WORD(&reg->mailbox0);
  701. printk(KERN_ERR "scsi(%ld): mailbox timed out, mailbox0 %04x, "
  702. "ictrl %04x, istatus %04x\n", ha->host_no, ha->mailbox_out[0],
  703. RD_REG_WORD(&reg->ictrl), RD_REG_WORD(&reg->istatus));
  704. complete(ha->mailbox_wait);
  705. }
  706. static int
  707. _qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp,
  708. struct completion *wait)
  709. {
  710. int status = FAILED;
  711. struct scsi_cmnd *cmd = sp->cmd;
  712. spin_unlock_irq(ha->host->host_lock);
  713. wait_for_completion_timeout(wait, 4*HZ);
  714. spin_lock_irq(ha->host->host_lock);
  715. sp->wait = NULL;
  716. if(CMD_HANDLE(cmd) == COMPLETED_HANDLE) {
  717. status = SUCCESS;
  718. (*cmd->scsi_done)(cmd);
  719. }
  720. return status;
  721. }
  722. static int
  723. qla1280_wait_for_single_command(struct scsi_qla_host *ha, struct srb *sp)
  724. {
  725. DECLARE_COMPLETION_ONSTACK(wait);
  726. sp->wait = &wait;
  727. return _qla1280_wait_for_single_command(ha, sp, &wait);
  728. }
  729. static int
  730. qla1280_wait_for_pending_commands(struct scsi_qla_host *ha, int bus, int target)
  731. {
  732. int cnt;
  733. int status;
  734. struct srb *sp;
  735. struct scsi_cmnd *cmd;
  736. status = SUCCESS;
  737. /*
  738. * Wait for all commands with the designated bus/target
  739. * to be completed by the firmware
  740. */
  741. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  742. sp = ha->outstanding_cmds[cnt];
  743. if (sp) {
  744. cmd = sp->cmd;
  745. if (bus >= 0 && SCSI_BUS_32(cmd) != bus)
  746. continue;
  747. if (target >= 0 && SCSI_TCN_32(cmd) != target)
  748. continue;
  749. status = qla1280_wait_for_single_command(ha, sp);
  750. if (status == FAILED)
  751. break;
  752. }
  753. }
  754. return status;
  755. }
  756. /**************************************************************************
  757. * qla1280_error_action
  758. * The function will attempt to perform a specified error action and
  759. * wait for the results (or time out).
  760. *
  761. * Input:
  762. * cmd = Linux SCSI command packet of the command that cause the
  763. * bus reset.
  764. * action = error action to take (see action_t)
  765. *
  766. * Returns:
  767. * SUCCESS or FAILED
  768. *
  769. **************************************************************************/
  770. static int
  771. qla1280_error_action(struct scsi_cmnd *cmd, enum action action)
  772. {
  773. struct scsi_qla_host *ha;
  774. int bus, target, lun;
  775. struct srb *sp;
  776. int i, found;
  777. int result=FAILED;
  778. int wait_for_bus=-1;
  779. int wait_for_target = -1;
  780. DECLARE_COMPLETION_ONSTACK(wait);
  781. ENTER("qla1280_error_action");
  782. ha = (struct scsi_qla_host *)(CMD_HOST(cmd)->hostdata);
  783. sp = (struct srb *)CMD_SP(cmd);
  784. bus = SCSI_BUS_32(cmd);
  785. target = SCSI_TCN_32(cmd);
  786. lun = SCSI_LUN_32(cmd);
  787. dprintk(4, "error_action %i, istatus 0x%04x\n", action,
  788. RD_REG_WORD(&ha->iobase->istatus));
  789. dprintk(4, "host_cmd 0x%04x, ictrl 0x%04x, jiffies %li\n",
  790. RD_REG_WORD(&ha->iobase->host_cmd),
  791. RD_REG_WORD(&ha->iobase->ictrl), jiffies);
  792. if (qla1280_verbose)
  793. printk(KERN_INFO "scsi(%li): Resetting Cmnd=0x%p, "
  794. "Handle=0x%p, action=0x%x\n",
  795. ha->host_no, cmd, CMD_HANDLE(cmd), action);
  796. /*
  797. * Check to see if we have the command in the outstanding_cmds[]
  798. * array. If not then it must have completed before this error
  799. * action was initiated. If the error_action isn't ABORT_COMMAND
  800. * then the driver must proceed with the requested action.
  801. */
  802. found = -1;
  803. for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
  804. if (sp == ha->outstanding_cmds[i]) {
  805. found = i;
  806. sp->wait = &wait; /* we'll wait for it to complete */
  807. break;
  808. }
  809. }
  810. if (found < 0) { /* driver doesn't have command */
  811. result = SUCCESS;
  812. if (qla1280_verbose) {
  813. printk(KERN_INFO
  814. "scsi(%ld:%d:%d:%d): specified command has "
  815. "already completed.\n", ha->host_no, bus,
  816. target, lun);
  817. }
  818. }
  819. switch (action) {
  820. case ABORT_COMMAND:
  821. dprintk(1, "qla1280: RISC aborting command\n");
  822. /*
  823. * The abort might fail due to race when the host_lock
  824. * is released to issue the abort. As such, we
  825. * don't bother to check the return status.
  826. */
  827. if (found >= 0)
  828. qla1280_abort_command(ha, sp, found);
  829. break;
  830. case DEVICE_RESET:
  831. if (qla1280_verbose)
  832. printk(KERN_INFO
  833. "scsi(%ld:%d:%d:%d): Queueing device reset "
  834. "command.\n", ha->host_no, bus, target, lun);
  835. if (qla1280_device_reset(ha, bus, target) == 0) {
  836. /* issued device reset, set wait conditions */
  837. wait_for_bus = bus;
  838. wait_for_target = target;
  839. }
  840. break;
  841. case BUS_RESET:
  842. if (qla1280_verbose)
  843. printk(KERN_INFO "qla1280(%ld:%d): Issued bus "
  844. "reset.\n", ha->host_no, bus);
  845. if (qla1280_bus_reset(ha, bus) == 0) {
  846. /* issued bus reset, set wait conditions */
  847. wait_for_bus = bus;
  848. }
  849. break;
  850. case ADAPTER_RESET:
  851. default:
  852. if (qla1280_verbose) {
  853. printk(KERN_INFO
  854. "scsi(%ld): Issued ADAPTER RESET\n",
  855. ha->host_no);
  856. printk(KERN_INFO "scsi(%ld): I/O processing will "
  857. "continue automatically\n", ha->host_no);
  858. }
  859. ha->flags.reset_active = 1;
  860. if (qla1280_abort_isp(ha) != 0) { /* it's dead */
  861. result = FAILED;
  862. }
  863. ha->flags.reset_active = 0;
  864. }
  865. /*
  866. * At this point, the host_lock has been released and retaken
  867. * by the issuance of the mailbox command.
  868. * Wait for the command passed in by the mid-layer if it
  869. * was found by the driver. It might have been returned
  870. * between eh recovery steps, hence the check of the "found"
  871. * variable.
  872. */
  873. if (found >= 0)
  874. result = _qla1280_wait_for_single_command(ha, sp, &wait);
  875. if (action == ABORT_COMMAND && result != SUCCESS) {
  876. printk(KERN_WARNING
  877. "scsi(%li:%i:%i:%i): "
  878. "Unable to abort command!\n",
  879. ha->host_no, bus, target, lun);
  880. }
  881. /*
  882. * If the command passed in by the mid-layer has been
  883. * returned by the board, then wait for any additional
  884. * commands which are supposed to complete based upon
  885. * the error action.
  886. *
  887. * All commands are unconditionally returned during a
  888. * call to qla1280_abort_isp(), ADAPTER_RESET. No need
  889. * to wait for them.
  890. */
  891. if (result == SUCCESS && wait_for_bus >= 0) {
  892. result = qla1280_wait_for_pending_commands(ha,
  893. wait_for_bus, wait_for_target);
  894. }
  895. dprintk(1, "RESET returning %d\n", result);
  896. LEAVE("qla1280_error_action");
  897. return result;
  898. }
  899. /**************************************************************************
  900. * qla1280_abort
  901. * Abort the specified SCSI command(s).
  902. **************************************************************************/
  903. static int
  904. qla1280_eh_abort(struct scsi_cmnd * cmd)
  905. {
  906. int rc;
  907. spin_lock_irq(cmd->device->host->host_lock);
  908. rc = qla1280_error_action(cmd, ABORT_COMMAND);
  909. spin_unlock_irq(cmd->device->host->host_lock);
  910. return rc;
  911. }
  912. /**************************************************************************
  913. * qla1280_device_reset
  914. * Reset the specified SCSI device
  915. **************************************************************************/
  916. static int
  917. qla1280_eh_device_reset(struct scsi_cmnd *cmd)
  918. {
  919. int rc;
  920. spin_lock_irq(cmd->device->host->host_lock);
  921. rc = qla1280_error_action(cmd, DEVICE_RESET);
  922. spin_unlock_irq(cmd->device->host->host_lock);
  923. return rc;
  924. }
  925. /**************************************************************************
  926. * qla1280_bus_reset
  927. * Reset the specified bus.
  928. **************************************************************************/
  929. static int
  930. qla1280_eh_bus_reset(struct scsi_cmnd *cmd)
  931. {
  932. int rc;
  933. spin_lock_irq(cmd->device->host->host_lock);
  934. rc = qla1280_error_action(cmd, BUS_RESET);
  935. spin_unlock_irq(cmd->device->host->host_lock);
  936. return rc;
  937. }
  938. /**************************************************************************
  939. * qla1280_adapter_reset
  940. * Reset the specified adapter (both channels)
  941. **************************************************************************/
  942. static int
  943. qla1280_eh_adapter_reset(struct scsi_cmnd *cmd)
  944. {
  945. int rc;
  946. spin_lock_irq(cmd->device->host->host_lock);
  947. rc = qla1280_error_action(cmd, ADAPTER_RESET);
  948. spin_unlock_irq(cmd->device->host->host_lock);
  949. return rc;
  950. }
  951. static int
  952. qla1280_biosparam(struct scsi_device *sdev, struct block_device *bdev,
  953. sector_t capacity, int geom[])
  954. {
  955. int heads, sectors, cylinders;
  956. heads = 64;
  957. sectors = 32;
  958. cylinders = (unsigned long)capacity / (heads * sectors);
  959. if (cylinders > 1024) {
  960. heads = 255;
  961. sectors = 63;
  962. cylinders = (unsigned long)capacity / (heads * sectors);
  963. /* if (cylinders > 1023)
  964. cylinders = 1023; */
  965. }
  966. geom[0] = heads;
  967. geom[1] = sectors;
  968. geom[2] = cylinders;
  969. return 0;
  970. }
  971. /* disable risc and host interrupts */
  972. static inline void
  973. qla1280_disable_intrs(struct scsi_qla_host *ha)
  974. {
  975. WRT_REG_WORD(&ha->iobase->ictrl, 0);
  976. RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
  977. }
  978. /* enable risc and host interrupts */
  979. static inline void
  980. qla1280_enable_intrs(struct scsi_qla_host *ha)
  981. {
  982. WRT_REG_WORD(&ha->iobase->ictrl, (ISP_EN_INT | ISP_EN_RISC));
  983. RD_REG_WORD(&ha->iobase->ictrl); /* PCI Posted Write flush */
  984. }
  985. /**************************************************************************
  986. * qla1280_intr_handler
  987. * Handles the H/W interrupt
  988. **************************************************************************/
  989. static irqreturn_t
  990. qla1280_intr_handler(int irq, void *dev_id)
  991. {
  992. struct scsi_qla_host *ha;
  993. struct device_reg __iomem *reg;
  994. u16 data;
  995. int handled = 0;
  996. ENTER_INTR ("qla1280_intr_handler");
  997. ha = (struct scsi_qla_host *)dev_id;
  998. spin_lock(ha->host->host_lock);
  999. ha->isr_count++;
  1000. reg = ha->iobase;
  1001. qla1280_disable_intrs(ha);
  1002. data = qla1280_debounce_register(&reg->istatus);
  1003. /* Check for pending interrupts. */
  1004. if (data & RISC_INT) {
  1005. qla1280_isr(ha, &ha->done_q);
  1006. handled = 1;
  1007. }
  1008. if (!list_empty(&ha->done_q))
  1009. qla1280_done(ha);
  1010. spin_unlock(ha->host->host_lock);
  1011. qla1280_enable_intrs(ha);
  1012. LEAVE_INTR("qla1280_intr_handler");
  1013. return IRQ_RETVAL(handled);
  1014. }
  1015. static int
  1016. qla1280_set_target_parameters(struct scsi_qla_host *ha, int bus, int target)
  1017. {
  1018. uint8_t mr;
  1019. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1020. struct nvram *nv;
  1021. int status, lun;
  1022. nv = &ha->nvram;
  1023. mr = BIT_3 | BIT_2 | BIT_1 | BIT_0;
  1024. /* Set Target Parameters. */
  1025. mb[0] = MBC_SET_TARGET_PARAMETERS;
  1026. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1027. mb[2] = nv->bus[bus].target[target].parameter.renegotiate_on_error << 8;
  1028. mb[2] |= nv->bus[bus].target[target].parameter.stop_queue_on_check << 9;
  1029. mb[2] |= nv->bus[bus].target[target].parameter.auto_request_sense << 10;
  1030. mb[2] |= nv->bus[bus].target[target].parameter.tag_queuing << 11;
  1031. mb[2] |= nv->bus[bus].target[target].parameter.enable_sync << 12;
  1032. mb[2] |= nv->bus[bus].target[target].parameter.enable_wide << 13;
  1033. mb[2] |= nv->bus[bus].target[target].parameter.parity_checking << 14;
  1034. mb[2] |= nv->bus[bus].target[target].parameter.disconnect_allowed << 15;
  1035. if (IS_ISP1x160(ha)) {
  1036. mb[2] |= nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr << 5;
  1037. mb[3] = (nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8);
  1038. mb[6] = (nv->bus[bus].target[target].ppr_1x160.flags.ppr_options << 8) |
  1039. nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width;
  1040. mr |= BIT_6;
  1041. } else {
  1042. mb[3] = (nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8);
  1043. }
  1044. mb[3] |= nv->bus[bus].target[target].sync_period;
  1045. status = qla1280_mailbox_command(ha, mr, mb);
  1046. /* Set Device Queue Parameters. */
  1047. for (lun = 0; lun < MAX_LUNS; lun++) {
  1048. mb[0] = MBC_SET_DEVICE_QUEUE;
  1049. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1050. mb[1] |= lun;
  1051. mb[2] = nv->bus[bus].max_queue_depth;
  1052. mb[3] = nv->bus[bus].target[target].execution_throttle;
  1053. status |= qla1280_mailbox_command(ha, 0x0f, mb);
  1054. }
  1055. if (status)
  1056. printk(KERN_WARNING "scsi(%ld:%i:%i): "
  1057. "qla1280_set_target_parameters() failed\n",
  1058. ha->host_no, bus, target);
  1059. return status;
  1060. }
  1061. /**************************************************************************
  1062. * qla1280_slave_configure
  1063. *
  1064. * Description:
  1065. * Determines the queue depth for a given device. There are two ways
  1066. * a queue depth can be obtained for a tagged queueing device. One
  1067. * way is the default queue depth which is determined by whether
  1068. * If it is defined, then it is used
  1069. * as the default queue depth. Otherwise, we use either 4 or 8 as the
  1070. * default queue depth (dependent on the number of hardware SCBs).
  1071. **************************************************************************/
  1072. static int
  1073. qla1280_slave_configure(struct scsi_device *device)
  1074. {
  1075. struct scsi_qla_host *ha;
  1076. int default_depth = 3;
  1077. int bus = device->channel;
  1078. int target = device->id;
  1079. int status = 0;
  1080. struct nvram *nv;
  1081. unsigned long flags;
  1082. ha = (struct scsi_qla_host *)device->host->hostdata;
  1083. nv = &ha->nvram;
  1084. if (qla1280_check_for_dead_scsi_bus(ha, bus))
  1085. return 1;
  1086. if (device->tagged_supported &&
  1087. (ha->bus_settings[bus].qtag_enables & (BIT_0 << target))) {
  1088. scsi_change_queue_depth(device, ha->bus_settings[bus].hiwat);
  1089. } else {
  1090. scsi_change_queue_depth(device, default_depth);
  1091. }
  1092. nv->bus[bus].target[target].parameter.enable_sync = device->sdtr;
  1093. nv->bus[bus].target[target].parameter.enable_wide = device->wdtr;
  1094. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = device->ppr;
  1095. if (driver_setup.no_sync ||
  1096. (driver_setup.sync_mask &&
  1097. (~driver_setup.sync_mask & (1 << target))))
  1098. nv->bus[bus].target[target].parameter.enable_sync = 0;
  1099. if (driver_setup.no_wide ||
  1100. (driver_setup.wide_mask &&
  1101. (~driver_setup.wide_mask & (1 << target))))
  1102. nv->bus[bus].target[target].parameter.enable_wide = 0;
  1103. if (IS_ISP1x160(ha)) {
  1104. if (driver_setup.no_ppr ||
  1105. (driver_setup.ppr_mask &&
  1106. (~driver_setup.ppr_mask & (1 << target))))
  1107. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 0;
  1108. }
  1109. spin_lock_irqsave(ha->host->host_lock, flags);
  1110. if (nv->bus[bus].target[target].parameter.enable_sync)
  1111. status = qla1280_set_target_parameters(ha, bus, target);
  1112. qla1280_get_target_parameters(ha, device);
  1113. spin_unlock_irqrestore(ha->host->host_lock, flags);
  1114. return status;
  1115. }
  1116. /*
  1117. * qla1280_done
  1118. * Process completed commands.
  1119. *
  1120. * Input:
  1121. * ha = adapter block pointer.
  1122. */
  1123. static void
  1124. qla1280_done(struct scsi_qla_host *ha)
  1125. {
  1126. struct srb *sp;
  1127. struct list_head *done_q;
  1128. int bus, target, lun;
  1129. struct scsi_cmnd *cmd;
  1130. ENTER("qla1280_done");
  1131. done_q = &ha->done_q;
  1132. while (!list_empty(done_q)) {
  1133. sp = list_entry(done_q->next, struct srb, list);
  1134. list_del(&sp->list);
  1135. cmd = sp->cmd;
  1136. bus = SCSI_BUS_32(cmd);
  1137. target = SCSI_TCN_32(cmd);
  1138. lun = SCSI_LUN_32(cmd);
  1139. switch ((CMD_RESULT(cmd) >> 16)) {
  1140. case DID_RESET:
  1141. /* Issue marker command. */
  1142. if (!ha->flags.abort_isp_active)
  1143. qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
  1144. break;
  1145. case DID_ABORT:
  1146. sp->flags &= ~SRB_ABORT_PENDING;
  1147. sp->flags |= SRB_ABORTED;
  1148. break;
  1149. default:
  1150. break;
  1151. }
  1152. /* Release memory used for this I/O */
  1153. scsi_dma_unmap(cmd);
  1154. /* Call the mid-level driver interrupt handler */
  1155. ha->actthreads--;
  1156. if (sp->wait == NULL)
  1157. (*(cmd)->scsi_done)(cmd);
  1158. else
  1159. complete(sp->wait);
  1160. }
  1161. LEAVE("qla1280_done");
  1162. }
  1163. /*
  1164. * Translates a ISP error to a Linux SCSI error
  1165. */
  1166. static int
  1167. qla1280_return_status(struct response * sts, struct scsi_cmnd *cp)
  1168. {
  1169. int host_status = DID_ERROR;
  1170. uint16_t comp_status = le16_to_cpu(sts->comp_status);
  1171. uint16_t state_flags = le16_to_cpu(sts->state_flags);
  1172. uint32_t residual_length = le32_to_cpu(sts->residual_length);
  1173. uint16_t scsi_status = le16_to_cpu(sts->scsi_status);
  1174. #if DEBUG_QLA1280_INTR
  1175. static char *reason[] = {
  1176. "DID_OK",
  1177. "DID_NO_CONNECT",
  1178. "DID_BUS_BUSY",
  1179. "DID_TIME_OUT",
  1180. "DID_BAD_TARGET",
  1181. "DID_ABORT",
  1182. "DID_PARITY",
  1183. "DID_ERROR",
  1184. "DID_RESET",
  1185. "DID_BAD_INTR"
  1186. };
  1187. #endif /* DEBUG_QLA1280_INTR */
  1188. ENTER("qla1280_return_status");
  1189. #if DEBUG_QLA1280_INTR
  1190. /*
  1191. dprintk(1, "qla1280_return_status: compl status = 0x%04x\n",
  1192. comp_status);
  1193. */
  1194. #endif
  1195. switch (comp_status) {
  1196. case CS_COMPLETE:
  1197. host_status = DID_OK;
  1198. break;
  1199. case CS_INCOMPLETE:
  1200. if (!(state_flags & SF_GOT_BUS))
  1201. host_status = DID_NO_CONNECT;
  1202. else if (!(state_flags & SF_GOT_TARGET))
  1203. host_status = DID_BAD_TARGET;
  1204. else if (!(state_flags & SF_SENT_CDB))
  1205. host_status = DID_ERROR;
  1206. else if (!(state_flags & SF_TRANSFERRED_DATA))
  1207. host_status = DID_ERROR;
  1208. else if (!(state_flags & SF_GOT_STATUS))
  1209. host_status = DID_ERROR;
  1210. else if (!(state_flags & SF_GOT_SENSE))
  1211. host_status = DID_ERROR;
  1212. break;
  1213. case CS_RESET:
  1214. host_status = DID_RESET;
  1215. break;
  1216. case CS_ABORTED:
  1217. host_status = DID_ABORT;
  1218. break;
  1219. case CS_TIMEOUT:
  1220. host_status = DID_TIME_OUT;
  1221. break;
  1222. case CS_DATA_OVERRUN:
  1223. dprintk(2, "Data overrun 0x%x\n", residual_length);
  1224. dprintk(2, "qla1280_return_status: response packet data\n");
  1225. qla1280_dump_buffer(2, (char *)sts, RESPONSE_ENTRY_SIZE);
  1226. host_status = DID_ERROR;
  1227. break;
  1228. case CS_DATA_UNDERRUN:
  1229. if ((scsi_bufflen(cp) - residual_length) <
  1230. cp->underflow) {
  1231. printk(KERN_WARNING
  1232. "scsi: Underflow detected - retrying "
  1233. "command.\n");
  1234. host_status = DID_ERROR;
  1235. } else {
  1236. scsi_set_resid(cp, residual_length);
  1237. host_status = DID_OK;
  1238. }
  1239. break;
  1240. default:
  1241. host_status = DID_ERROR;
  1242. break;
  1243. }
  1244. #if DEBUG_QLA1280_INTR
  1245. dprintk(1, "qla1280 ISP status: host status (%s) scsi status %x\n",
  1246. reason[host_status], scsi_status);
  1247. #endif
  1248. LEAVE("qla1280_return_status");
  1249. return (scsi_status & 0xff) | (host_status << 16);
  1250. }
  1251. /****************************************************************************/
  1252. /* QLogic ISP1280 Hardware Support Functions. */
  1253. /****************************************************************************/
  1254. /*
  1255. * qla1280_initialize_adapter
  1256. * Initialize board.
  1257. *
  1258. * Input:
  1259. * ha = adapter block pointer.
  1260. *
  1261. * Returns:
  1262. * 0 = success
  1263. */
  1264. static int
  1265. qla1280_initialize_adapter(struct scsi_qla_host *ha)
  1266. {
  1267. struct device_reg __iomem *reg;
  1268. int status;
  1269. int bus;
  1270. unsigned long flags;
  1271. ENTER("qla1280_initialize_adapter");
  1272. /* Clear adapter flags. */
  1273. ha->flags.online = 0;
  1274. ha->flags.disable_host_adapter = 0;
  1275. ha->flags.reset_active = 0;
  1276. ha->flags.abort_isp_active = 0;
  1277. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  1278. if (ia64_platform_is("sn2")) {
  1279. printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
  1280. "dual channel lockup workaround\n", ha->host_no);
  1281. ha->flags.use_pci_vchannel = 1;
  1282. driver_setup.no_nvram = 1;
  1283. }
  1284. #endif
  1285. /* TODO: implement support for the 1040 nvram format */
  1286. if (IS_ISP1040(ha))
  1287. driver_setup.no_nvram = 1;
  1288. dprintk(1, "Configure PCI space for adapter...\n");
  1289. reg = ha->iobase;
  1290. /* Insure mailbox registers are free. */
  1291. WRT_REG_WORD(&reg->semaphore, 0);
  1292. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  1293. WRT_REG_WORD(&reg->host_cmd, HC_CLR_HOST_INT);
  1294. RD_REG_WORD(&reg->host_cmd);
  1295. if (qla1280_read_nvram(ha)) {
  1296. dprintk(2, "qla1280_initialize_adapter: failed to read "
  1297. "NVRAM\n");
  1298. }
  1299. /*
  1300. * It's necessary to grab the spin here as qla1280_mailbox_command
  1301. * needs to be able to drop the lock unconditionally to wait
  1302. * for completion.
  1303. */
  1304. spin_lock_irqsave(ha->host->host_lock, flags);
  1305. status = qla1280_load_firmware(ha);
  1306. if (status) {
  1307. printk(KERN_ERR "scsi(%li): initialize: pci probe failed!\n",
  1308. ha->host_no);
  1309. goto out;
  1310. }
  1311. /* Setup adapter based on NVRAM parameters. */
  1312. dprintk(1, "scsi(%ld): Configure NVRAM parameters\n", ha->host_no);
  1313. qla1280_nvram_config(ha);
  1314. if (ha->flags.disable_host_adapter) {
  1315. status = 1;
  1316. goto out;
  1317. }
  1318. status = qla1280_init_rings(ha);
  1319. if (status)
  1320. goto out;
  1321. /* Issue SCSI reset, if we can't reset twice then bus is dead */
  1322. for (bus = 0; bus < ha->ports; bus++) {
  1323. if (!ha->bus_settings[bus].disable_scsi_reset &&
  1324. qla1280_bus_reset(ha, bus) &&
  1325. qla1280_bus_reset(ha, bus))
  1326. ha->bus_settings[bus].scsi_bus_dead = 1;
  1327. }
  1328. ha->flags.online = 1;
  1329. out:
  1330. spin_unlock_irqrestore(ha->host->host_lock, flags);
  1331. if (status)
  1332. dprintk(2, "qla1280_initialize_adapter: **** FAILED ****\n");
  1333. LEAVE("qla1280_initialize_adapter");
  1334. return status;
  1335. }
  1336. /*
  1337. * qla1280_request_firmware
  1338. * Acquire firmware for chip. Retain in memory
  1339. * for error recovery.
  1340. *
  1341. * Input:
  1342. * ha = adapter block pointer.
  1343. *
  1344. * Returns:
  1345. * Pointer to firmware image or an error code
  1346. * cast to pointer via ERR_PTR().
  1347. */
  1348. static const struct firmware *
  1349. qla1280_request_firmware(struct scsi_qla_host *ha)
  1350. {
  1351. const struct firmware *fw;
  1352. int err;
  1353. int index;
  1354. char *fwname;
  1355. spin_unlock_irq(ha->host->host_lock);
  1356. mutex_lock(&qla1280_firmware_mutex);
  1357. index = ql1280_board_tbl[ha->devnum].fw_index;
  1358. fw = qla1280_fw_tbl[index].fw;
  1359. if (fw)
  1360. goto out;
  1361. fwname = qla1280_fw_tbl[index].fwname;
  1362. err = request_firmware(&fw, fwname, &ha->pdev->dev);
  1363. if (err) {
  1364. fw = ERR_PTR(err);
  1365. goto unlock;
  1366. }
  1367. if ((fw->size % 2) || (fw->size < 6)) {
  1368. printk(KERN_ERR "Invalid firmware length %zu in image \"%s\"\n",
  1369. fw->size, fwname);
  1370. release_firmware(fw);
  1371. fw = ERR_PTR(-EINVAL);
  1372. goto unlock;
  1373. }
  1374. qla1280_fw_tbl[index].fw = fw;
  1375. out:
  1376. ha->fwver1 = fw->data[0];
  1377. ha->fwver2 = fw->data[1];
  1378. ha->fwver3 = fw->data[2];
  1379. unlock:
  1380. mutex_unlock(&qla1280_firmware_mutex);
  1381. spin_lock_irq(ha->host->host_lock);
  1382. return fw;
  1383. }
  1384. /*
  1385. * Chip diagnostics
  1386. * Test chip for proper operation.
  1387. *
  1388. * Input:
  1389. * ha = adapter block pointer.
  1390. *
  1391. * Returns:
  1392. * 0 = success.
  1393. */
  1394. static int
  1395. qla1280_chip_diag(struct scsi_qla_host *ha)
  1396. {
  1397. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1398. struct device_reg __iomem *reg = ha->iobase;
  1399. int status = 0;
  1400. int cnt;
  1401. uint16_t data;
  1402. dprintk(3, "qla1280_chip_diag: testing device at 0x%p \n", &reg->id_l);
  1403. dprintk(1, "scsi(%ld): Verifying chip\n", ha->host_no);
  1404. /* Soft reset chip and wait for it to finish. */
  1405. WRT_REG_WORD(&reg->ictrl, ISP_RESET);
  1406. /*
  1407. * We can't do a traditional PCI write flush here by reading
  1408. * back the register. The card will not respond once the reset
  1409. * is in action and we end up with a machine check exception
  1410. * instead. Nothing to do but wait and hope for the best.
  1411. * A portable pci_write_flush(pdev) call would be very useful here.
  1412. */
  1413. udelay(20);
  1414. data = qla1280_debounce_register(&reg->ictrl);
  1415. /*
  1416. * Yet another QLogic gem ;-(
  1417. */
  1418. for (cnt = 1000000; cnt && data & ISP_RESET; cnt--) {
  1419. udelay(5);
  1420. data = RD_REG_WORD(&reg->ictrl);
  1421. }
  1422. if (!cnt)
  1423. goto fail;
  1424. /* Reset register cleared by chip reset. */
  1425. dprintk(3, "qla1280_chip_diag: reset register cleared by chip reset\n");
  1426. WRT_REG_WORD(&reg->cfg_1, 0);
  1427. /* Reset RISC and disable BIOS which
  1428. allows RISC to execute out of RAM. */
  1429. WRT_REG_WORD(&reg->host_cmd, HC_RESET_RISC |
  1430. HC_RELEASE_RISC | HC_DISABLE_BIOS);
  1431. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1432. data = qla1280_debounce_register(&reg->mailbox0);
  1433. /*
  1434. * I *LOVE* this code!
  1435. */
  1436. for (cnt = 1000000; cnt && data == MBS_BUSY; cnt--) {
  1437. udelay(5);
  1438. data = RD_REG_WORD(&reg->mailbox0);
  1439. }
  1440. if (!cnt)
  1441. goto fail;
  1442. /* Check product ID of chip */
  1443. dprintk(3, "qla1280_chip_diag: Checking product ID of chip\n");
  1444. if (RD_REG_WORD(&reg->mailbox1) != PROD_ID_1 ||
  1445. (RD_REG_WORD(&reg->mailbox2) != PROD_ID_2 &&
  1446. RD_REG_WORD(&reg->mailbox2) != PROD_ID_2a) ||
  1447. RD_REG_WORD(&reg->mailbox3) != PROD_ID_3 ||
  1448. RD_REG_WORD(&reg->mailbox4) != PROD_ID_4) {
  1449. printk(KERN_INFO "qla1280: Wrong product ID = "
  1450. "0x%x,0x%x,0x%x,0x%x\n",
  1451. RD_REG_WORD(&reg->mailbox1),
  1452. RD_REG_WORD(&reg->mailbox2),
  1453. RD_REG_WORD(&reg->mailbox3),
  1454. RD_REG_WORD(&reg->mailbox4));
  1455. goto fail;
  1456. }
  1457. /*
  1458. * Enable ints early!!!
  1459. */
  1460. qla1280_enable_intrs(ha);
  1461. dprintk(1, "qla1280_chip_diag: Checking mailboxes of chip\n");
  1462. /* Wrap Incoming Mailboxes Test. */
  1463. mb[0] = MBC_MAILBOX_REGISTER_TEST;
  1464. mb[1] = 0xAAAA;
  1465. mb[2] = 0x5555;
  1466. mb[3] = 0xAA55;
  1467. mb[4] = 0x55AA;
  1468. mb[5] = 0xA5A5;
  1469. mb[6] = 0x5A5A;
  1470. mb[7] = 0x2525;
  1471. status = qla1280_mailbox_command(ha, 0xff, mb);
  1472. if (status)
  1473. goto fail;
  1474. if (mb[1] != 0xAAAA || mb[2] != 0x5555 || mb[3] != 0xAA55 ||
  1475. mb[4] != 0x55AA || mb[5] != 0xA5A5 || mb[6] != 0x5A5A ||
  1476. mb[7] != 0x2525) {
  1477. printk(KERN_INFO "qla1280: Failed mbox check\n");
  1478. goto fail;
  1479. }
  1480. dprintk(3, "qla1280_chip_diag: exiting normally\n");
  1481. return 0;
  1482. fail:
  1483. dprintk(2, "qla1280_chip_diag: **** FAILED ****\n");
  1484. return status;
  1485. }
  1486. static int
  1487. qla1280_load_firmware_pio(struct scsi_qla_host *ha)
  1488. {
  1489. /* enter with host_lock acquired */
  1490. const struct firmware *fw;
  1491. const __le16 *fw_data;
  1492. uint16_t risc_address, risc_code_size;
  1493. uint16_t mb[MAILBOX_REGISTER_COUNT], i;
  1494. int err = 0;
  1495. fw = qla1280_request_firmware(ha);
  1496. if (IS_ERR(fw))
  1497. return PTR_ERR(fw);
  1498. fw_data = (const __le16 *)&fw->data[0];
  1499. ha->fwstart = __le16_to_cpu(fw_data[2]);
  1500. /* Load RISC code. */
  1501. risc_address = ha->fwstart;
  1502. fw_data = (const __le16 *)&fw->data[6];
  1503. risc_code_size = (fw->size - 6) / 2;
  1504. for (i = 0; i < risc_code_size; i++) {
  1505. mb[0] = MBC_WRITE_RAM_WORD;
  1506. mb[1] = risc_address + i;
  1507. mb[2] = __le16_to_cpu(fw_data[i]);
  1508. err = qla1280_mailbox_command(ha, BIT_0 | BIT_1 | BIT_2, mb);
  1509. if (err) {
  1510. printk(KERN_ERR "scsi(%li): Failed to load firmware\n",
  1511. ha->host_no);
  1512. break;
  1513. }
  1514. }
  1515. return err;
  1516. }
  1517. #define DUMP_IT_BACK 0 /* for debug of RISC loading */
  1518. static int
  1519. qla1280_load_firmware_dma(struct scsi_qla_host *ha)
  1520. {
  1521. /* enter with host_lock acquired */
  1522. const struct firmware *fw;
  1523. const __le16 *fw_data;
  1524. uint16_t risc_address, risc_code_size;
  1525. uint16_t mb[MAILBOX_REGISTER_COUNT], cnt;
  1526. int err = 0, num, i;
  1527. #if DUMP_IT_BACK
  1528. uint8_t *sp, *tbuf;
  1529. dma_addr_t p_tbuf;
  1530. tbuf = pci_alloc_consistent(ha->pdev, 8000, &p_tbuf);
  1531. if (!tbuf)
  1532. return -ENOMEM;
  1533. #endif
  1534. fw = qla1280_request_firmware(ha);
  1535. if (IS_ERR(fw))
  1536. return PTR_ERR(fw);
  1537. fw_data = (const __le16 *)&fw->data[0];
  1538. ha->fwstart = __le16_to_cpu(fw_data[2]);
  1539. /* Load RISC code. */
  1540. risc_address = ha->fwstart;
  1541. fw_data = (const __le16 *)&fw->data[6];
  1542. risc_code_size = (fw->size - 6) / 2;
  1543. dprintk(1, "%s: DMA RISC code (%i) words\n",
  1544. __func__, risc_code_size);
  1545. num = 0;
  1546. while (risc_code_size > 0) {
  1547. int warn __attribute__((unused)) = 0;
  1548. cnt = 2000 >> 1;
  1549. if (cnt > risc_code_size)
  1550. cnt = risc_code_size;
  1551. dprintk(2, "qla1280_setup_chip: loading risc @ =(0x%p),"
  1552. "%d,%d(0x%x)\n",
  1553. fw_data, cnt, num, risc_address);
  1554. for(i = 0; i < cnt; i++)
  1555. ((__le16 *)ha->request_ring)[i] = fw_data[i];
  1556. mb[0] = MBC_LOAD_RAM;
  1557. mb[1] = risc_address;
  1558. mb[4] = cnt;
  1559. mb[3] = ha->request_dma & 0xffff;
  1560. mb[2] = (ha->request_dma >> 16) & 0xffff;
  1561. mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
  1562. mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
  1563. dprintk(2, "%s: op=%d 0x%p = 0x%4x,0x%4x,0x%4x,0x%4x\n",
  1564. __func__, mb[0],
  1565. (void *)(long)ha->request_dma,
  1566. mb[6], mb[7], mb[2], mb[3]);
  1567. err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
  1568. BIT_1 | BIT_0, mb);
  1569. if (err) {
  1570. printk(KERN_ERR "scsi(%li): Failed to load partial "
  1571. "segment of f\n", ha->host_no);
  1572. goto out;
  1573. }
  1574. #if DUMP_IT_BACK
  1575. mb[0] = MBC_DUMP_RAM;
  1576. mb[1] = risc_address;
  1577. mb[4] = cnt;
  1578. mb[3] = p_tbuf & 0xffff;
  1579. mb[2] = (p_tbuf >> 16) & 0xffff;
  1580. mb[7] = pci_dma_hi32(p_tbuf) & 0xffff;
  1581. mb[6] = pci_dma_hi32(p_tbuf) >> 16;
  1582. err = qla1280_mailbox_command(ha, BIT_4 | BIT_3 | BIT_2 |
  1583. BIT_1 | BIT_0, mb);
  1584. if (err) {
  1585. printk(KERN_ERR
  1586. "Failed to dump partial segment of f/w\n");
  1587. goto out;
  1588. }
  1589. sp = (uint8_t *)ha->request_ring;
  1590. for (i = 0; i < (cnt << 1); i++) {
  1591. if (tbuf[i] != sp[i] && warn++ < 10) {
  1592. printk(KERN_ERR "%s: FW compare error @ "
  1593. "byte(0x%x) loop#=%x\n",
  1594. __func__, i, num);
  1595. printk(KERN_ERR "%s: FWbyte=%x "
  1596. "FWfromChip=%x\n",
  1597. __func__, sp[i], tbuf[i]);
  1598. /*break; */
  1599. }
  1600. }
  1601. #endif
  1602. risc_address += cnt;
  1603. risc_code_size = risc_code_size - cnt;
  1604. fw_data = fw_data + cnt;
  1605. num++;
  1606. }
  1607. out:
  1608. #if DUMP_IT_BACK
  1609. pci_free_consistent(ha->pdev, 8000, tbuf, p_tbuf);
  1610. #endif
  1611. return err;
  1612. }
  1613. static int
  1614. qla1280_start_firmware(struct scsi_qla_host *ha)
  1615. {
  1616. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1617. int err;
  1618. dprintk(1, "%s: Verifying checksum of loaded RISC code.\n",
  1619. __func__);
  1620. /* Verify checksum of loaded RISC code. */
  1621. mb[0] = MBC_VERIFY_CHECKSUM;
  1622. /* mb[1] = ql12_risc_code_addr01; */
  1623. mb[1] = ha->fwstart;
  1624. err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1625. if (err) {
  1626. printk(KERN_ERR "scsi(%li): RISC checksum failed.\n", ha->host_no);
  1627. return err;
  1628. }
  1629. /* Start firmware execution. */
  1630. dprintk(1, "%s: start firmware running.\n", __func__);
  1631. mb[0] = MBC_EXECUTE_FIRMWARE;
  1632. mb[1] = ha->fwstart;
  1633. err = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1634. if (err) {
  1635. printk(KERN_ERR "scsi(%li): Failed to start firmware\n",
  1636. ha->host_no);
  1637. }
  1638. return err;
  1639. }
  1640. static int
  1641. qla1280_load_firmware(struct scsi_qla_host *ha)
  1642. {
  1643. /* enter with host_lock taken */
  1644. int err;
  1645. err = qla1280_chip_diag(ha);
  1646. if (err)
  1647. goto out;
  1648. if (IS_ISP1040(ha))
  1649. err = qla1280_load_firmware_pio(ha);
  1650. else
  1651. err = qla1280_load_firmware_dma(ha);
  1652. if (err)
  1653. goto out;
  1654. err = qla1280_start_firmware(ha);
  1655. out:
  1656. return err;
  1657. }
  1658. /*
  1659. * Initialize rings
  1660. *
  1661. * Input:
  1662. * ha = adapter block pointer.
  1663. * ha->request_ring = request ring virtual address
  1664. * ha->response_ring = response ring virtual address
  1665. * ha->request_dma = request ring physical address
  1666. * ha->response_dma = response ring physical address
  1667. *
  1668. * Returns:
  1669. * 0 = success.
  1670. */
  1671. static int
  1672. qla1280_init_rings(struct scsi_qla_host *ha)
  1673. {
  1674. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1675. int status = 0;
  1676. ENTER("qla1280_init_rings");
  1677. /* Clear outstanding commands array. */
  1678. memset(ha->outstanding_cmds, 0,
  1679. sizeof(struct srb *) * MAX_OUTSTANDING_COMMANDS);
  1680. /* Initialize request queue. */
  1681. ha->request_ring_ptr = ha->request_ring;
  1682. ha->req_ring_index = 0;
  1683. ha->req_q_cnt = REQUEST_ENTRY_CNT;
  1684. /* mb[0] = MBC_INIT_REQUEST_QUEUE; */
  1685. mb[0] = MBC_INIT_REQUEST_QUEUE_A64;
  1686. mb[1] = REQUEST_ENTRY_CNT;
  1687. mb[3] = ha->request_dma & 0xffff;
  1688. mb[2] = (ha->request_dma >> 16) & 0xffff;
  1689. mb[4] = 0;
  1690. mb[7] = pci_dma_hi32(ha->request_dma) & 0xffff;
  1691. mb[6] = pci_dma_hi32(ha->request_dma) >> 16;
  1692. if (!(status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_4 |
  1693. BIT_3 | BIT_2 | BIT_1 | BIT_0,
  1694. &mb[0]))) {
  1695. /* Initialize response queue. */
  1696. ha->response_ring_ptr = ha->response_ring;
  1697. ha->rsp_ring_index = 0;
  1698. /* mb[0] = MBC_INIT_RESPONSE_QUEUE; */
  1699. mb[0] = MBC_INIT_RESPONSE_QUEUE_A64;
  1700. mb[1] = RESPONSE_ENTRY_CNT;
  1701. mb[3] = ha->response_dma & 0xffff;
  1702. mb[2] = (ha->response_dma >> 16) & 0xffff;
  1703. mb[5] = 0;
  1704. mb[7] = pci_dma_hi32(ha->response_dma) & 0xffff;
  1705. mb[6] = pci_dma_hi32(ha->response_dma) >> 16;
  1706. status = qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_5 |
  1707. BIT_3 | BIT_2 | BIT_1 | BIT_0,
  1708. &mb[0]);
  1709. }
  1710. if (status)
  1711. dprintk(2, "qla1280_init_rings: **** FAILED ****\n");
  1712. LEAVE("qla1280_init_rings");
  1713. return status;
  1714. }
  1715. static void
  1716. qla1280_print_settings(struct nvram *nv)
  1717. {
  1718. dprintk(1, "qla1280 : initiator scsi id bus[0]=%d\n",
  1719. nv->bus[0].config_1.initiator_id);
  1720. dprintk(1, "qla1280 : initiator scsi id bus[1]=%d\n",
  1721. nv->bus[1].config_1.initiator_id);
  1722. dprintk(1, "qla1280 : bus reset delay[0]=%d\n",
  1723. nv->bus[0].bus_reset_delay);
  1724. dprintk(1, "qla1280 : bus reset delay[1]=%d\n",
  1725. nv->bus[1].bus_reset_delay);
  1726. dprintk(1, "qla1280 : retry count[0]=%d\n", nv->bus[0].retry_count);
  1727. dprintk(1, "qla1280 : retry delay[0]=%d\n", nv->bus[0].retry_delay);
  1728. dprintk(1, "qla1280 : retry count[1]=%d\n", nv->bus[1].retry_count);
  1729. dprintk(1, "qla1280 : retry delay[1]=%d\n", nv->bus[1].retry_delay);
  1730. dprintk(1, "qla1280 : async data setup time[0]=%d\n",
  1731. nv->bus[0].config_2.async_data_setup_time);
  1732. dprintk(1, "qla1280 : async data setup time[1]=%d\n",
  1733. nv->bus[1].config_2.async_data_setup_time);
  1734. dprintk(1, "qla1280 : req/ack active negation[0]=%d\n",
  1735. nv->bus[0].config_2.req_ack_active_negation);
  1736. dprintk(1, "qla1280 : req/ack active negation[1]=%d\n",
  1737. nv->bus[1].config_2.req_ack_active_negation);
  1738. dprintk(1, "qla1280 : data line active negation[0]=%d\n",
  1739. nv->bus[0].config_2.data_line_active_negation);
  1740. dprintk(1, "qla1280 : data line active negation[1]=%d\n",
  1741. nv->bus[1].config_2.data_line_active_negation);
  1742. dprintk(1, "qla1280 : disable loading risc code=%d\n",
  1743. nv->cntr_flags_1.disable_loading_risc_code);
  1744. dprintk(1, "qla1280 : enable 64bit addressing=%d\n",
  1745. nv->cntr_flags_1.enable_64bit_addressing);
  1746. dprintk(1, "qla1280 : selection timeout limit[0]=%d\n",
  1747. nv->bus[0].selection_timeout);
  1748. dprintk(1, "qla1280 : selection timeout limit[1]=%d\n",
  1749. nv->bus[1].selection_timeout);
  1750. dprintk(1, "qla1280 : max queue depth[0]=%d\n",
  1751. nv->bus[0].max_queue_depth);
  1752. dprintk(1, "qla1280 : max queue depth[1]=%d\n",
  1753. nv->bus[1].max_queue_depth);
  1754. }
  1755. static void
  1756. qla1280_set_target_defaults(struct scsi_qla_host *ha, int bus, int target)
  1757. {
  1758. struct nvram *nv = &ha->nvram;
  1759. nv->bus[bus].target[target].parameter.renegotiate_on_error = 1;
  1760. nv->bus[bus].target[target].parameter.auto_request_sense = 1;
  1761. nv->bus[bus].target[target].parameter.tag_queuing = 1;
  1762. nv->bus[bus].target[target].parameter.enable_sync = 1;
  1763. #if 1 /* Some SCSI Processors do not seem to like this */
  1764. nv->bus[bus].target[target].parameter.enable_wide = 1;
  1765. #endif
  1766. nv->bus[bus].target[target].execution_throttle =
  1767. nv->bus[bus].max_queue_depth - 1;
  1768. nv->bus[bus].target[target].parameter.parity_checking = 1;
  1769. nv->bus[bus].target[target].parameter.disconnect_allowed = 1;
  1770. if (IS_ISP1x160(ha)) {
  1771. nv->bus[bus].target[target].flags.flags1x160.device_enable = 1;
  1772. nv->bus[bus].target[target].flags.flags1x160.sync_offset = 0x0e;
  1773. nv->bus[bus].target[target].sync_period = 9;
  1774. nv->bus[bus].target[target].ppr_1x160.flags.enable_ppr = 1;
  1775. nv->bus[bus].target[target].ppr_1x160.flags.ppr_options = 2;
  1776. nv->bus[bus].target[target].ppr_1x160.flags.ppr_bus_width = 1;
  1777. } else {
  1778. nv->bus[bus].target[target].flags.flags1x80.device_enable = 1;
  1779. nv->bus[bus].target[target].flags.flags1x80.sync_offset = 12;
  1780. nv->bus[bus].target[target].sync_period = 10;
  1781. }
  1782. }
  1783. static void
  1784. qla1280_set_defaults(struct scsi_qla_host *ha)
  1785. {
  1786. struct nvram *nv = &ha->nvram;
  1787. int bus, target;
  1788. dprintk(1, "Using defaults for NVRAM: \n");
  1789. memset(nv, 0, sizeof(struct nvram));
  1790. /* nv->cntr_flags_1.disable_loading_risc_code = 1; */
  1791. nv->firmware_feature.f.enable_fast_posting = 1;
  1792. nv->firmware_feature.f.disable_synchronous_backoff = 1;
  1793. nv->termination.scsi_bus_0_control = 3;
  1794. nv->termination.scsi_bus_1_control = 3;
  1795. nv->termination.auto_term_support = 1;
  1796. /*
  1797. * Set default FIFO magic - What appropriate values would be here
  1798. * is unknown. This is what I have found testing with 12160s.
  1799. *
  1800. * Now, I would love the magic decoder ring for this one, the
  1801. * header file provided by QLogic seems to be bogus or incomplete
  1802. * at best.
  1803. */
  1804. nv->isp_config.burst_enable = 1;
  1805. if (IS_ISP1040(ha))
  1806. nv->isp_config.fifo_threshold |= 3;
  1807. else
  1808. nv->isp_config.fifo_threshold |= 4;
  1809. if (IS_ISP1x160(ha))
  1810. nv->isp_parameter = 0x01; /* fast memory enable */
  1811. for (bus = 0; bus < MAX_BUSES; bus++) {
  1812. nv->bus[bus].config_1.initiator_id = 7;
  1813. nv->bus[bus].config_2.req_ack_active_negation = 1;
  1814. nv->bus[bus].config_2.data_line_active_negation = 1;
  1815. nv->bus[bus].selection_timeout = 250;
  1816. nv->bus[bus].max_queue_depth = 32;
  1817. if (IS_ISP1040(ha)) {
  1818. nv->bus[bus].bus_reset_delay = 3;
  1819. nv->bus[bus].config_2.async_data_setup_time = 6;
  1820. nv->bus[bus].retry_delay = 1;
  1821. } else {
  1822. nv->bus[bus].bus_reset_delay = 5;
  1823. nv->bus[bus].config_2.async_data_setup_time = 8;
  1824. }
  1825. for (target = 0; target < MAX_TARGETS; target++)
  1826. qla1280_set_target_defaults(ha, bus, target);
  1827. }
  1828. }
  1829. static int
  1830. qla1280_config_target(struct scsi_qla_host *ha, int bus, int target)
  1831. {
  1832. struct nvram *nv = &ha->nvram;
  1833. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1834. int status, lun;
  1835. uint16_t flag;
  1836. /* Set Target Parameters. */
  1837. mb[0] = MBC_SET_TARGET_PARAMETERS;
  1838. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1839. /*
  1840. * Do not enable sync and ppr for the initial INQUIRY run. We
  1841. * enable this later if we determine the target actually
  1842. * supports it.
  1843. */
  1844. mb[2] = (TP_RENEGOTIATE | TP_AUTO_REQUEST_SENSE | TP_TAGGED_QUEUE
  1845. | TP_WIDE | TP_PARITY | TP_DISCONNECT);
  1846. if (IS_ISP1x160(ha))
  1847. mb[3] = nv->bus[bus].target[target].flags.flags1x160.sync_offset << 8;
  1848. else
  1849. mb[3] = nv->bus[bus].target[target].flags.flags1x80.sync_offset << 8;
  1850. mb[3] |= nv->bus[bus].target[target].sync_period;
  1851. status = qla1280_mailbox_command(ha, 0x0f, mb);
  1852. /* Save Tag queuing enable flag. */
  1853. flag = (BIT_0 << target);
  1854. if (nv->bus[bus].target[target].parameter.tag_queuing)
  1855. ha->bus_settings[bus].qtag_enables |= flag;
  1856. /* Save Device enable flag. */
  1857. if (IS_ISP1x160(ha)) {
  1858. if (nv->bus[bus].target[target].flags.flags1x160.device_enable)
  1859. ha->bus_settings[bus].device_enables |= flag;
  1860. ha->bus_settings[bus].lun_disables |= 0;
  1861. } else {
  1862. if (nv->bus[bus].target[target].flags.flags1x80.device_enable)
  1863. ha->bus_settings[bus].device_enables |= flag;
  1864. /* Save LUN disable flag. */
  1865. if (nv->bus[bus].target[target].flags.flags1x80.lun_disable)
  1866. ha->bus_settings[bus].lun_disables |= flag;
  1867. }
  1868. /* Set Device Queue Parameters. */
  1869. for (lun = 0; lun < MAX_LUNS; lun++) {
  1870. mb[0] = MBC_SET_DEVICE_QUEUE;
  1871. mb[1] = (uint16_t)((bus ? target | BIT_7 : target) << 8);
  1872. mb[1] |= lun;
  1873. mb[2] = nv->bus[bus].max_queue_depth;
  1874. mb[3] = nv->bus[bus].target[target].execution_throttle;
  1875. status |= qla1280_mailbox_command(ha, 0x0f, mb);
  1876. }
  1877. return status;
  1878. }
  1879. static int
  1880. qla1280_config_bus(struct scsi_qla_host *ha, int bus)
  1881. {
  1882. struct nvram *nv = &ha->nvram;
  1883. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1884. int target, status;
  1885. /* SCSI Reset Disable. */
  1886. ha->bus_settings[bus].disable_scsi_reset =
  1887. nv->bus[bus].config_1.scsi_reset_disable;
  1888. /* Initiator ID. */
  1889. ha->bus_settings[bus].id = nv->bus[bus].config_1.initiator_id;
  1890. mb[0] = MBC_SET_INITIATOR_ID;
  1891. mb[1] = bus ? ha->bus_settings[bus].id | BIT_7 :
  1892. ha->bus_settings[bus].id;
  1893. status = qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1894. /* Reset Delay. */
  1895. ha->bus_settings[bus].bus_reset_delay =
  1896. nv->bus[bus].bus_reset_delay;
  1897. /* Command queue depth per device. */
  1898. ha->bus_settings[bus].hiwat = nv->bus[bus].max_queue_depth - 1;
  1899. /* Set target parameters. */
  1900. for (target = 0; target < MAX_TARGETS; target++)
  1901. status |= qla1280_config_target(ha, bus, target);
  1902. return status;
  1903. }
  1904. static int
  1905. qla1280_nvram_config(struct scsi_qla_host *ha)
  1906. {
  1907. struct device_reg __iomem *reg = ha->iobase;
  1908. struct nvram *nv = &ha->nvram;
  1909. int bus, target, status = 0;
  1910. uint16_t mb[MAILBOX_REGISTER_COUNT];
  1911. ENTER("qla1280_nvram_config");
  1912. if (ha->nvram_valid) {
  1913. /* Always force AUTO sense for LINUX SCSI */
  1914. for (bus = 0; bus < MAX_BUSES; bus++)
  1915. for (target = 0; target < MAX_TARGETS; target++) {
  1916. nv->bus[bus].target[target].parameter.
  1917. auto_request_sense = 1;
  1918. }
  1919. } else {
  1920. qla1280_set_defaults(ha);
  1921. }
  1922. qla1280_print_settings(nv);
  1923. /* Disable RISC load of firmware. */
  1924. ha->flags.disable_risc_code_load =
  1925. nv->cntr_flags_1.disable_loading_risc_code;
  1926. if (IS_ISP1040(ha)) {
  1927. uint16_t hwrev, cfg1, cdma_conf, ddma_conf;
  1928. hwrev = RD_REG_WORD(&reg->cfg_0) & ISP_CFG0_HWMSK;
  1929. cfg1 = RD_REG_WORD(&reg->cfg_1) & ~(BIT_4 | BIT_5 | BIT_6);
  1930. cdma_conf = RD_REG_WORD(&reg->cdma_cfg);
  1931. ddma_conf = RD_REG_WORD(&reg->ddma_cfg);
  1932. /* Busted fifo, says mjacob. */
  1933. if (hwrev != ISP_CFG0_1040A)
  1934. cfg1 |= nv->isp_config.fifo_threshold << 4;
  1935. cfg1 |= nv->isp_config.burst_enable << 2;
  1936. WRT_REG_WORD(&reg->cfg_1, cfg1);
  1937. WRT_REG_WORD(&reg->cdma_cfg, cdma_conf | CDMA_CONF_BENAB);
  1938. WRT_REG_WORD(&reg->ddma_cfg, cdma_conf | DDMA_CONF_BENAB);
  1939. } else {
  1940. uint16_t cfg1, term;
  1941. /* Set ISP hardware DMA burst */
  1942. cfg1 = nv->isp_config.fifo_threshold << 4;
  1943. cfg1 |= nv->isp_config.burst_enable << 2;
  1944. /* Enable DMA arbitration on dual channel controllers */
  1945. if (ha->ports > 1)
  1946. cfg1 |= BIT_13;
  1947. WRT_REG_WORD(&reg->cfg_1, cfg1);
  1948. /* Set SCSI termination. */
  1949. WRT_REG_WORD(&reg->gpio_enable,
  1950. BIT_7 | BIT_3 | BIT_2 | BIT_1 | BIT_0);
  1951. term = nv->termination.scsi_bus_1_control;
  1952. term |= nv->termination.scsi_bus_0_control << 2;
  1953. term |= nv->termination.auto_term_support << 7;
  1954. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1955. WRT_REG_WORD(&reg->gpio_data, term);
  1956. }
  1957. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  1958. /* ISP parameter word. */
  1959. mb[0] = MBC_SET_SYSTEM_PARAMETER;
  1960. mb[1] = nv->isp_parameter;
  1961. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, &mb[0]);
  1962. if (IS_ISP1x40(ha)) {
  1963. /* clock rate - for qla1240 and older, only */
  1964. mb[0] = MBC_SET_CLOCK_RATE;
  1965. mb[1] = 40;
  1966. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1967. }
  1968. /* Firmware feature word. */
  1969. mb[0] = MBC_SET_FIRMWARE_FEATURES;
  1970. mb[1] = nv->firmware_feature.f.enable_fast_posting;
  1971. mb[1] |= nv->firmware_feature.f.report_lvd_bus_transition << 1;
  1972. mb[1] |= nv->firmware_feature.f.disable_synchronous_backoff << 5;
  1973. #if defined(CONFIG_IA64_GENERIC) || defined (CONFIG_IA64_SGI_SN2)
  1974. if (ia64_platform_is("sn2")) {
  1975. printk(KERN_INFO "scsi(%li): Enabling SN2 PCI DMA "
  1976. "workaround\n", ha->host_no);
  1977. mb[1] |= nv->firmware_feature.f.unused_9 << 9; /* XXX */
  1978. }
  1979. #endif
  1980. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  1981. /* Retry count and delay. */
  1982. mb[0] = MBC_SET_RETRY_COUNT;
  1983. mb[1] = nv->bus[0].retry_count;
  1984. mb[2] = nv->bus[0].retry_delay;
  1985. mb[6] = nv->bus[1].retry_count;
  1986. mb[7] = nv->bus[1].retry_delay;
  1987. status |= qla1280_mailbox_command(ha, BIT_7 | BIT_6 | BIT_2 |
  1988. BIT_1 | BIT_0, &mb[0]);
  1989. /* ASYNC data setup time. */
  1990. mb[0] = MBC_SET_ASYNC_DATA_SETUP;
  1991. mb[1] = nv->bus[0].config_2.async_data_setup_time;
  1992. mb[2] = nv->bus[1].config_2.async_data_setup_time;
  1993. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  1994. /* Active negation states. */
  1995. mb[0] = MBC_SET_ACTIVE_NEGATION;
  1996. mb[1] = 0;
  1997. if (nv->bus[0].config_2.req_ack_active_negation)
  1998. mb[1] |= BIT_5;
  1999. if (nv->bus[0].config_2.data_line_active_negation)
  2000. mb[1] |= BIT_4;
  2001. mb[2] = 0;
  2002. if (nv->bus[1].config_2.req_ack_active_negation)
  2003. mb[2] |= BIT_5;
  2004. if (nv->bus[1].config_2.data_line_active_negation)
  2005. mb[2] |= BIT_4;
  2006. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2007. mb[0] = MBC_SET_DATA_OVERRUN_RECOVERY;
  2008. mb[1] = 2; /* Reset SCSI bus and return all outstanding IO */
  2009. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  2010. /* thingy */
  2011. mb[0] = MBC_SET_PCI_CONTROL;
  2012. mb[1] = BIT_1; /* Data DMA Channel Burst Enable */
  2013. mb[2] = BIT_1; /* Command DMA Channel Burst Enable */
  2014. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2015. mb[0] = MBC_SET_TAG_AGE_LIMIT;
  2016. mb[1] = 8;
  2017. status |= qla1280_mailbox_command(ha, BIT_1 | BIT_0, mb);
  2018. /* Selection timeout. */
  2019. mb[0] = MBC_SET_SELECTION_TIMEOUT;
  2020. mb[1] = nv->bus[0].selection_timeout;
  2021. mb[2] = nv->bus[1].selection_timeout;
  2022. status |= qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, mb);
  2023. for (bus = 0; bus < ha->ports; bus++)
  2024. status |= qla1280_config_bus(ha, bus);
  2025. if (status)
  2026. dprintk(2, "qla1280_nvram_config: **** FAILED ****\n");
  2027. LEAVE("qla1280_nvram_config");
  2028. return status;
  2029. }
  2030. /*
  2031. * Get NVRAM data word
  2032. * Calculates word position in NVRAM and calls request routine to
  2033. * get the word from NVRAM.
  2034. *
  2035. * Input:
  2036. * ha = adapter block pointer.
  2037. * address = NVRAM word address.
  2038. *
  2039. * Returns:
  2040. * data word.
  2041. */
  2042. static uint16_t
  2043. qla1280_get_nvram_word(struct scsi_qla_host *ha, uint32_t address)
  2044. {
  2045. uint32_t nv_cmd;
  2046. uint16_t data;
  2047. nv_cmd = address << 16;
  2048. nv_cmd |= NV_READ_OP;
  2049. data = le16_to_cpu(qla1280_nvram_request(ha, nv_cmd));
  2050. dprintk(8, "qla1280_get_nvram_word: exiting normally NVRAM data = "
  2051. "0x%x", data);
  2052. return data;
  2053. }
  2054. /*
  2055. * NVRAM request
  2056. * Sends read command to NVRAM and gets data from NVRAM.
  2057. *
  2058. * Input:
  2059. * ha = adapter block pointer.
  2060. * nv_cmd = Bit 26 = start bit
  2061. * Bit 25, 24 = opcode
  2062. * Bit 23-16 = address
  2063. * Bit 15-0 = write data
  2064. *
  2065. * Returns:
  2066. * data word.
  2067. */
  2068. static uint16_t
  2069. qla1280_nvram_request(struct scsi_qla_host *ha, uint32_t nv_cmd)
  2070. {
  2071. struct device_reg __iomem *reg = ha->iobase;
  2072. int cnt;
  2073. uint16_t data = 0;
  2074. uint16_t reg_data;
  2075. /* Send command to NVRAM. */
  2076. nv_cmd <<= 5;
  2077. for (cnt = 0; cnt < 11; cnt++) {
  2078. if (nv_cmd & BIT_31)
  2079. qla1280_nv_write(ha, NV_DATA_OUT);
  2080. else
  2081. qla1280_nv_write(ha, 0);
  2082. nv_cmd <<= 1;
  2083. }
  2084. /* Read data from NVRAM. */
  2085. for (cnt = 0; cnt < 16; cnt++) {
  2086. WRT_REG_WORD(&reg->nvram, (NV_SELECT | NV_CLOCK));
  2087. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2088. NVRAM_DELAY();
  2089. data <<= 1;
  2090. reg_data = RD_REG_WORD(&reg->nvram);
  2091. if (reg_data & NV_DATA_IN)
  2092. data |= BIT_0;
  2093. WRT_REG_WORD(&reg->nvram, NV_SELECT);
  2094. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2095. NVRAM_DELAY();
  2096. }
  2097. /* Deselect chip. */
  2098. WRT_REG_WORD(&reg->nvram, NV_DESELECT);
  2099. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2100. NVRAM_DELAY();
  2101. return data;
  2102. }
  2103. static void
  2104. qla1280_nv_write(struct scsi_qla_host *ha, uint16_t data)
  2105. {
  2106. struct device_reg __iomem *reg = ha->iobase;
  2107. WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
  2108. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2109. NVRAM_DELAY();
  2110. WRT_REG_WORD(&reg->nvram, data | NV_SELECT | NV_CLOCK);
  2111. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2112. NVRAM_DELAY();
  2113. WRT_REG_WORD(&reg->nvram, data | NV_SELECT);
  2114. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2115. NVRAM_DELAY();
  2116. }
  2117. /*
  2118. * Mailbox Command
  2119. * Issue mailbox command and waits for completion.
  2120. *
  2121. * Input:
  2122. * ha = adapter block pointer.
  2123. * mr = mailbox registers to load.
  2124. * mb = data pointer for mailbox registers.
  2125. *
  2126. * Output:
  2127. * mb[MAILBOX_REGISTER_COUNT] = returned mailbox data.
  2128. *
  2129. * Returns:
  2130. * 0 = success
  2131. */
  2132. static int
  2133. qla1280_mailbox_command(struct scsi_qla_host *ha, uint8_t mr, uint16_t *mb)
  2134. {
  2135. struct device_reg __iomem *reg = ha->iobase;
  2136. int status = 0;
  2137. int cnt;
  2138. uint16_t *optr, *iptr;
  2139. uint16_t __iomem *mptr;
  2140. uint16_t data;
  2141. DECLARE_COMPLETION_ONSTACK(wait);
  2142. ENTER("qla1280_mailbox_command");
  2143. if (ha->mailbox_wait) {
  2144. printk(KERN_ERR "Warning mailbox wait already in use!\n");
  2145. }
  2146. ha->mailbox_wait = &wait;
  2147. /*
  2148. * We really should start out by verifying that the mailbox is
  2149. * available before starting sending the command data
  2150. */
  2151. /* Load mailbox registers. */
  2152. mptr = (uint16_t __iomem *) &reg->mailbox0;
  2153. iptr = mb;
  2154. for (cnt = 0; cnt < MAILBOX_REGISTER_COUNT; cnt++) {
  2155. if (mr & BIT_0) {
  2156. WRT_REG_WORD(mptr, (*iptr));
  2157. }
  2158. mr >>= 1;
  2159. mptr++;
  2160. iptr++;
  2161. }
  2162. /* Issue set host interrupt command. */
  2163. /* set up a timer just in case we're really jammed */
  2164. timer_setup(&ha->mailbox_timer, qla1280_mailbox_timeout, 0);
  2165. mod_timer(&ha->mailbox_timer, jiffies + 20 * HZ);
  2166. spin_unlock_irq(ha->host->host_lock);
  2167. WRT_REG_WORD(&reg->host_cmd, HC_SET_HOST_INT);
  2168. data = qla1280_debounce_register(&reg->istatus);
  2169. wait_for_completion(&wait);
  2170. del_timer_sync(&ha->mailbox_timer);
  2171. spin_lock_irq(ha->host->host_lock);
  2172. ha->mailbox_wait = NULL;
  2173. /* Check for mailbox command timeout. */
  2174. if (ha->mailbox_out[0] != MBS_CMD_CMP) {
  2175. printk(KERN_WARNING "qla1280_mailbox_command: Command failed, "
  2176. "mailbox0 = 0x%04x, mailbox_out0 = 0x%04x, istatus = "
  2177. "0x%04x\n",
  2178. mb[0], ha->mailbox_out[0], RD_REG_WORD(&reg->istatus));
  2179. printk(KERN_WARNING "m0 %04x, m1 %04x, m2 %04x, m3 %04x\n",
  2180. RD_REG_WORD(&reg->mailbox0), RD_REG_WORD(&reg->mailbox1),
  2181. RD_REG_WORD(&reg->mailbox2), RD_REG_WORD(&reg->mailbox3));
  2182. printk(KERN_WARNING "m4 %04x, m5 %04x, m6 %04x, m7 %04x\n",
  2183. RD_REG_WORD(&reg->mailbox4), RD_REG_WORD(&reg->mailbox5),
  2184. RD_REG_WORD(&reg->mailbox6), RD_REG_WORD(&reg->mailbox7));
  2185. status = 1;
  2186. }
  2187. /* Load return mailbox registers. */
  2188. optr = mb;
  2189. iptr = (uint16_t *) &ha->mailbox_out[0];
  2190. mr = MAILBOX_REGISTER_COUNT;
  2191. memcpy(optr, iptr, MAILBOX_REGISTER_COUNT * sizeof(uint16_t));
  2192. if (ha->flags.reset_marker)
  2193. qla1280_rst_aen(ha);
  2194. if (status)
  2195. dprintk(2, "qla1280_mailbox_command: **** FAILED, mailbox0 = "
  2196. "0x%x ****\n", mb[0]);
  2197. LEAVE("qla1280_mailbox_command");
  2198. return status;
  2199. }
  2200. /*
  2201. * qla1280_poll
  2202. * Polls ISP for interrupts.
  2203. *
  2204. * Input:
  2205. * ha = adapter block pointer.
  2206. */
  2207. static void
  2208. qla1280_poll(struct scsi_qla_host *ha)
  2209. {
  2210. struct device_reg __iomem *reg = ha->iobase;
  2211. uint16_t data;
  2212. LIST_HEAD(done_q);
  2213. /* ENTER("qla1280_poll"); */
  2214. /* Check for pending interrupts. */
  2215. data = RD_REG_WORD(&reg->istatus);
  2216. if (data & RISC_INT)
  2217. qla1280_isr(ha, &done_q);
  2218. if (!ha->mailbox_wait) {
  2219. if (ha->flags.reset_marker)
  2220. qla1280_rst_aen(ha);
  2221. }
  2222. if (!list_empty(&done_q))
  2223. qla1280_done(ha);
  2224. /* LEAVE("qla1280_poll"); */
  2225. }
  2226. /*
  2227. * qla1280_bus_reset
  2228. * Issue SCSI bus reset.
  2229. *
  2230. * Input:
  2231. * ha = adapter block pointer.
  2232. * bus = SCSI bus number.
  2233. *
  2234. * Returns:
  2235. * 0 = success
  2236. */
  2237. static int
  2238. qla1280_bus_reset(struct scsi_qla_host *ha, int bus)
  2239. {
  2240. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2241. uint16_t reset_delay;
  2242. int status;
  2243. dprintk(3, "qla1280_bus_reset: entered\n");
  2244. if (qla1280_verbose)
  2245. printk(KERN_INFO "scsi(%li:%i): Resetting SCSI BUS\n",
  2246. ha->host_no, bus);
  2247. reset_delay = ha->bus_settings[bus].bus_reset_delay;
  2248. mb[0] = MBC_BUS_RESET;
  2249. mb[1] = reset_delay;
  2250. mb[2] = (uint16_t) bus;
  2251. status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  2252. if (status) {
  2253. if (ha->bus_settings[bus].failed_reset_count > 2)
  2254. ha->bus_settings[bus].scsi_bus_dead = 1;
  2255. ha->bus_settings[bus].failed_reset_count++;
  2256. } else {
  2257. spin_unlock_irq(ha->host->host_lock);
  2258. ssleep(reset_delay);
  2259. spin_lock_irq(ha->host->host_lock);
  2260. ha->bus_settings[bus].scsi_bus_dead = 0;
  2261. ha->bus_settings[bus].failed_reset_count = 0;
  2262. ha->bus_settings[bus].reset_marker = 0;
  2263. /* Issue marker command. */
  2264. qla1280_marker(ha, bus, 0, 0, MK_SYNC_ALL);
  2265. }
  2266. /*
  2267. * We should probably call qla1280_set_target_parameters()
  2268. * here as well for all devices on the bus.
  2269. */
  2270. if (status)
  2271. dprintk(2, "qla1280_bus_reset: **** FAILED ****\n");
  2272. else
  2273. dprintk(3, "qla1280_bus_reset: exiting normally\n");
  2274. return status;
  2275. }
  2276. /*
  2277. * qla1280_device_reset
  2278. * Issue bus device reset message to the target.
  2279. *
  2280. * Input:
  2281. * ha = adapter block pointer.
  2282. * bus = SCSI BUS number.
  2283. * target = SCSI ID.
  2284. *
  2285. * Returns:
  2286. * 0 = success
  2287. */
  2288. static int
  2289. qla1280_device_reset(struct scsi_qla_host *ha, int bus, int target)
  2290. {
  2291. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2292. int status;
  2293. ENTER("qla1280_device_reset");
  2294. mb[0] = MBC_ABORT_TARGET;
  2295. mb[1] = (bus ? (target | BIT_7) : target) << 8;
  2296. mb[2] = 1;
  2297. status = qla1280_mailbox_command(ha, BIT_2 | BIT_1 | BIT_0, &mb[0]);
  2298. /* Issue marker command. */
  2299. qla1280_marker(ha, bus, target, 0, MK_SYNC_ID);
  2300. if (status)
  2301. dprintk(2, "qla1280_device_reset: **** FAILED ****\n");
  2302. LEAVE("qla1280_device_reset");
  2303. return status;
  2304. }
  2305. /*
  2306. * qla1280_abort_command
  2307. * Abort command aborts a specified IOCB.
  2308. *
  2309. * Input:
  2310. * ha = adapter block pointer.
  2311. * sp = SB structure pointer.
  2312. *
  2313. * Returns:
  2314. * 0 = success
  2315. */
  2316. static int
  2317. qla1280_abort_command(struct scsi_qla_host *ha, struct srb * sp, int handle)
  2318. {
  2319. uint16_t mb[MAILBOX_REGISTER_COUNT];
  2320. unsigned int bus, target, lun;
  2321. int status;
  2322. ENTER("qla1280_abort_command");
  2323. bus = SCSI_BUS_32(sp->cmd);
  2324. target = SCSI_TCN_32(sp->cmd);
  2325. lun = SCSI_LUN_32(sp->cmd);
  2326. sp->flags |= SRB_ABORT_PENDING;
  2327. mb[0] = MBC_ABORT_COMMAND;
  2328. mb[1] = (bus ? target | BIT_7 : target) << 8 | lun;
  2329. mb[2] = handle >> 16;
  2330. mb[3] = handle & 0xffff;
  2331. status = qla1280_mailbox_command(ha, 0x0f, &mb[0]);
  2332. if (status) {
  2333. dprintk(2, "qla1280_abort_command: **** FAILED ****\n");
  2334. sp->flags &= ~SRB_ABORT_PENDING;
  2335. }
  2336. LEAVE("qla1280_abort_command");
  2337. return status;
  2338. }
  2339. /*
  2340. * qla1280_reset_adapter
  2341. * Reset adapter.
  2342. *
  2343. * Input:
  2344. * ha = adapter block pointer.
  2345. */
  2346. static void
  2347. qla1280_reset_adapter(struct scsi_qla_host *ha)
  2348. {
  2349. struct device_reg __iomem *reg = ha->iobase;
  2350. ENTER("qla1280_reset_adapter");
  2351. /* Disable ISP chip */
  2352. ha->flags.online = 0;
  2353. WRT_REG_WORD(&reg->ictrl, ISP_RESET);
  2354. WRT_REG_WORD(&reg->host_cmd,
  2355. HC_RESET_RISC | HC_RELEASE_RISC | HC_DISABLE_BIOS);
  2356. RD_REG_WORD(&reg->id_l); /* Flush PCI write */
  2357. LEAVE("qla1280_reset_adapter");
  2358. }
  2359. /*
  2360. * Issue marker command.
  2361. * Function issues marker IOCB.
  2362. *
  2363. * Input:
  2364. * ha = adapter block pointer.
  2365. * bus = SCSI BUS number
  2366. * id = SCSI ID
  2367. * lun = SCSI LUN
  2368. * type = marker modifier
  2369. */
  2370. static void
  2371. qla1280_marker(struct scsi_qla_host *ha, int bus, int id, int lun, u8 type)
  2372. {
  2373. struct mrk_entry *pkt;
  2374. ENTER("qla1280_marker");
  2375. /* Get request packet. */
  2376. if ((pkt = (struct mrk_entry *) qla1280_req_pkt(ha))) {
  2377. pkt->entry_type = MARKER_TYPE;
  2378. pkt->lun = (uint8_t) lun;
  2379. pkt->target = (uint8_t) (bus ? (id | BIT_7) : id);
  2380. pkt->modifier = type;
  2381. pkt->entry_status = 0;
  2382. /* Issue command to ISP */
  2383. qla1280_isp_cmd(ha);
  2384. }
  2385. LEAVE("qla1280_marker");
  2386. }
  2387. /*
  2388. * qla1280_64bit_start_scsi
  2389. * The start SCSI is responsible for building request packets on
  2390. * request ring and modifying ISP input pointer.
  2391. *
  2392. * Input:
  2393. * ha = adapter block pointer.
  2394. * sp = SB structure pointer.
  2395. *
  2396. * Returns:
  2397. * 0 = success, was able to issue command.
  2398. */
  2399. #ifdef QLA_64BIT_PTR
  2400. static int
  2401. qla1280_64bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
  2402. {
  2403. struct device_reg __iomem *reg = ha->iobase;
  2404. struct scsi_cmnd *cmd = sp->cmd;
  2405. cmd_a64_entry_t *pkt;
  2406. __le32 *dword_ptr;
  2407. dma_addr_t dma_handle;
  2408. int status = 0;
  2409. int cnt;
  2410. int req_cnt;
  2411. int seg_cnt;
  2412. u8 dir;
  2413. ENTER("qla1280_64bit_start_scsi:");
  2414. /* Calculate number of entries and segments required. */
  2415. req_cnt = 1;
  2416. seg_cnt = scsi_dma_map(cmd);
  2417. if (seg_cnt > 0) {
  2418. if (seg_cnt > 2) {
  2419. req_cnt += (seg_cnt - 2) / 5;
  2420. if ((seg_cnt - 2) % 5)
  2421. req_cnt++;
  2422. }
  2423. } else if (seg_cnt < 0) {
  2424. status = 1;
  2425. goto out;
  2426. }
  2427. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2428. /* Calculate number of free request entries. */
  2429. cnt = RD_REG_WORD(&reg->mailbox4);
  2430. if (ha->req_ring_index < cnt)
  2431. ha->req_q_cnt = cnt - ha->req_ring_index;
  2432. else
  2433. ha->req_q_cnt =
  2434. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2435. }
  2436. dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
  2437. ha->req_q_cnt, seg_cnt);
  2438. /* If room for request in request ring. */
  2439. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2440. status = SCSI_MLQUEUE_HOST_BUSY;
  2441. dprintk(2, "qla1280_start_scsi: in-ptr=0x%x req_q_cnt="
  2442. "0x%xreq_cnt=0x%x", ha->req_ring_index, ha->req_q_cnt,
  2443. req_cnt);
  2444. goto out;
  2445. }
  2446. /* Check for room in outstanding command list. */
  2447. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
  2448. ha->outstanding_cmds[cnt] != NULL; cnt++);
  2449. if (cnt >= MAX_OUTSTANDING_COMMANDS) {
  2450. status = SCSI_MLQUEUE_HOST_BUSY;
  2451. dprintk(2, "qla1280_start_scsi: NO ROOM IN "
  2452. "OUTSTANDING ARRAY, req_q_cnt=0x%x", ha->req_q_cnt);
  2453. goto out;
  2454. }
  2455. ha->outstanding_cmds[cnt] = sp;
  2456. ha->req_q_cnt -= req_cnt;
  2457. CMD_HANDLE(sp->cmd) = (unsigned char *)(unsigned long)(cnt + 1);
  2458. dprintk(2, "start: cmd=%p sp=%p CDB=%xm, handle %lx\n", cmd, sp,
  2459. cmd->cmnd[0], (long)CMD_HANDLE(sp->cmd));
  2460. dprintk(2, " bus %i, target %i, lun %i\n",
  2461. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2462. qla1280_dump_buffer(2, cmd->cmnd, MAX_COMMAND_SIZE);
  2463. /*
  2464. * Build command packet.
  2465. */
  2466. pkt = (cmd_a64_entry_t *) ha->request_ring_ptr;
  2467. pkt->entry_type = COMMAND_A64_TYPE;
  2468. pkt->entry_count = (uint8_t) req_cnt;
  2469. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2470. pkt->entry_status = 0;
  2471. pkt->handle = cpu_to_le32(cnt);
  2472. /* Zero out remaining portion of packet. */
  2473. memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
  2474. /* Set ISP command timeout. */
  2475. pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
  2476. /* Set device target ID and LUN */
  2477. pkt->lun = SCSI_LUN_32(cmd);
  2478. pkt->target = SCSI_BUS_32(cmd) ?
  2479. (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
  2480. /* Enable simple tag queuing if device supports it. */
  2481. if (cmd->device->simple_tags)
  2482. pkt->control_flags |= cpu_to_le16(BIT_3);
  2483. /* Load SCSI command packet. */
  2484. pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
  2485. memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
  2486. /* dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
  2487. /* Set transfer direction. */
  2488. dir = qla1280_data_direction(cmd);
  2489. pkt->control_flags |= cpu_to_le16(dir);
  2490. /* Set total data segment count. */
  2491. pkt->dseg_count = cpu_to_le16(seg_cnt);
  2492. /*
  2493. * Load data segments.
  2494. */
  2495. if (seg_cnt) { /* If data transfer. */
  2496. struct scatterlist *sg, *s;
  2497. int remseg = seg_cnt;
  2498. sg = scsi_sglist(cmd);
  2499. /* Setup packet address segment pointer. */
  2500. dword_ptr = (u32 *)&pkt->dseg_0_address;
  2501. /* Load command entry data segments. */
  2502. for_each_sg(sg, s, seg_cnt, cnt) {
  2503. if (cnt == 2)
  2504. break;
  2505. dma_handle = sg_dma_address(s);
  2506. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2507. if (ha->flags.use_pci_vchannel)
  2508. sn_pci_set_vchan(ha->pdev,
  2509. (unsigned long *)&dma_handle,
  2510. SCSI_BUS_32(cmd));
  2511. #endif
  2512. *dword_ptr++ =
  2513. cpu_to_le32(pci_dma_lo32(dma_handle));
  2514. *dword_ptr++ =
  2515. cpu_to_le32(pci_dma_hi32(dma_handle));
  2516. *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
  2517. dprintk(3, "S/G Segment phys_addr=%x %x, len=0x%x\n",
  2518. cpu_to_le32(pci_dma_hi32(dma_handle)),
  2519. cpu_to_le32(pci_dma_lo32(dma_handle)),
  2520. cpu_to_le32(sg_dma_len(sg_next(s))));
  2521. remseg--;
  2522. }
  2523. dprintk(5, "qla1280_64bit_start_scsi: Scatter/gather "
  2524. "command packet data - b %i, t %i, l %i \n",
  2525. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd),
  2526. SCSI_LUN_32(cmd));
  2527. qla1280_dump_buffer(5, (char *)pkt,
  2528. REQUEST_ENTRY_SIZE);
  2529. /*
  2530. * Build continuation packets.
  2531. */
  2532. dprintk(3, "S/G Building Continuation...seg_cnt=0x%x "
  2533. "remains\n", seg_cnt);
  2534. while (remseg > 0) {
  2535. /* Update sg start */
  2536. sg = s;
  2537. /* Adjust ring index. */
  2538. ha->req_ring_index++;
  2539. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2540. ha->req_ring_index = 0;
  2541. ha->request_ring_ptr =
  2542. ha->request_ring;
  2543. } else
  2544. ha->request_ring_ptr++;
  2545. pkt = (cmd_a64_entry_t *)ha->request_ring_ptr;
  2546. /* Zero out packet. */
  2547. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2548. /* Load packet defaults. */
  2549. ((struct cont_a64_entry *) pkt)->entry_type =
  2550. CONTINUE_A64_TYPE;
  2551. ((struct cont_a64_entry *) pkt)->entry_count = 1;
  2552. ((struct cont_a64_entry *) pkt)->sys_define =
  2553. (uint8_t)ha->req_ring_index;
  2554. /* Setup packet address segment pointer. */
  2555. dword_ptr =
  2556. (u32 *)&((struct cont_a64_entry *) pkt)->dseg_0_address;
  2557. /* Load continuation entry data segments. */
  2558. for_each_sg(sg, s, remseg, cnt) {
  2559. if (cnt == 5)
  2560. break;
  2561. dma_handle = sg_dma_address(s);
  2562. #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
  2563. if (ha->flags.use_pci_vchannel)
  2564. sn_pci_set_vchan(ha->pdev,
  2565. (unsigned long *)&dma_handle,
  2566. SCSI_BUS_32(cmd));
  2567. #endif
  2568. *dword_ptr++ =
  2569. cpu_to_le32(pci_dma_lo32(dma_handle));
  2570. *dword_ptr++ =
  2571. cpu_to_le32(pci_dma_hi32(dma_handle));
  2572. *dword_ptr++ =
  2573. cpu_to_le32(sg_dma_len(s));
  2574. dprintk(3, "S/G Segment Cont. phys_addr=%x %x, len=0x%x\n",
  2575. cpu_to_le32(pci_dma_hi32(dma_handle)),
  2576. cpu_to_le32(pci_dma_lo32(dma_handle)),
  2577. cpu_to_le32(sg_dma_len(s)));
  2578. }
  2579. remseg -= cnt;
  2580. dprintk(5, "qla1280_64bit_start_scsi: "
  2581. "continuation packet data - b %i, t "
  2582. "%i, l %i \n", SCSI_BUS_32(cmd),
  2583. SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2584. qla1280_dump_buffer(5, (char *)pkt,
  2585. REQUEST_ENTRY_SIZE);
  2586. }
  2587. } else { /* No data transfer */
  2588. dprintk(5, "qla1280_64bit_start_scsi: No data, command "
  2589. "packet data - b %i, t %i, l %i \n",
  2590. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2591. qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
  2592. }
  2593. /* Adjust ring index. */
  2594. ha->req_ring_index++;
  2595. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2596. ha->req_ring_index = 0;
  2597. ha->request_ring_ptr = ha->request_ring;
  2598. } else
  2599. ha->request_ring_ptr++;
  2600. /* Set chip new ring index. */
  2601. dprintk(2,
  2602. "qla1280_64bit_start_scsi: Wakeup RISC for pending command\n");
  2603. sp->flags |= SRB_SENT;
  2604. ha->actthreads++;
  2605. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2606. /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
  2607. mmiowb();
  2608. out:
  2609. if (status)
  2610. dprintk(2, "qla1280_64bit_start_scsi: **** FAILED ****\n");
  2611. else
  2612. dprintk(3, "qla1280_64bit_start_scsi: exiting normally\n");
  2613. return status;
  2614. }
  2615. #else /* !QLA_64BIT_PTR */
  2616. /*
  2617. * qla1280_32bit_start_scsi
  2618. * The start SCSI is responsible for building request packets on
  2619. * request ring and modifying ISP input pointer.
  2620. *
  2621. * The Qlogic firmware interface allows every queue slot to have a SCSI
  2622. * command and up to 4 scatter/gather (SG) entries. If we need more
  2623. * than 4 SG entries, then continuation entries are used that can
  2624. * hold another 7 entries each. The start routine determines if there
  2625. * is eought empty slots then build the combination of requests to
  2626. * fulfill the OS request.
  2627. *
  2628. * Input:
  2629. * ha = adapter block pointer.
  2630. * sp = SCSI Request Block structure pointer.
  2631. *
  2632. * Returns:
  2633. * 0 = success, was able to issue command.
  2634. */
  2635. static int
  2636. qla1280_32bit_start_scsi(struct scsi_qla_host *ha, struct srb * sp)
  2637. {
  2638. struct device_reg __iomem *reg = ha->iobase;
  2639. struct scsi_cmnd *cmd = sp->cmd;
  2640. struct cmd_entry *pkt;
  2641. __le32 *dword_ptr;
  2642. int status = 0;
  2643. int cnt;
  2644. int req_cnt;
  2645. int seg_cnt;
  2646. u8 dir;
  2647. ENTER("qla1280_32bit_start_scsi");
  2648. dprintk(1, "32bit_start: cmd=%p sp=%p CDB=%x\n", cmd, sp,
  2649. cmd->cmnd[0]);
  2650. /* Calculate number of entries and segments required. */
  2651. req_cnt = 1;
  2652. seg_cnt = scsi_dma_map(cmd);
  2653. if (seg_cnt) {
  2654. /*
  2655. * if greater than four sg entries then we need to allocate
  2656. * continuation entries
  2657. */
  2658. if (seg_cnt > 4) {
  2659. req_cnt += (seg_cnt - 4) / 7;
  2660. if ((seg_cnt - 4) % 7)
  2661. req_cnt++;
  2662. }
  2663. dprintk(3, "S/G Transfer cmd=%p seg_cnt=0x%x, req_cnt=%x\n",
  2664. cmd, seg_cnt, req_cnt);
  2665. } else if (seg_cnt < 0) {
  2666. status = 1;
  2667. goto out;
  2668. }
  2669. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2670. /* Calculate number of free request entries. */
  2671. cnt = RD_REG_WORD(&reg->mailbox4);
  2672. if (ha->req_ring_index < cnt)
  2673. ha->req_q_cnt = cnt - ha->req_ring_index;
  2674. else
  2675. ha->req_q_cnt =
  2676. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2677. }
  2678. dprintk(3, "Number of free entries=(%d) seg_cnt=0x%x\n",
  2679. ha->req_q_cnt, seg_cnt);
  2680. /* If room for request in request ring. */
  2681. if ((req_cnt + 2) >= ha->req_q_cnt) {
  2682. status = SCSI_MLQUEUE_HOST_BUSY;
  2683. dprintk(2, "qla1280_32bit_start_scsi: in-ptr=0x%x, "
  2684. "req_q_cnt=0x%x, req_cnt=0x%x", ha->req_ring_index,
  2685. ha->req_q_cnt, req_cnt);
  2686. goto out;
  2687. }
  2688. /* Check for empty slot in outstanding command list. */
  2689. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS &&
  2690. (ha->outstanding_cmds[cnt] != 0); cnt++) ;
  2691. if (cnt >= MAX_OUTSTANDING_COMMANDS) {
  2692. status = SCSI_MLQUEUE_HOST_BUSY;
  2693. dprintk(2, "qla1280_32bit_start_scsi: NO ROOM IN OUTSTANDING "
  2694. "ARRAY, req_q_cnt=0x%x\n", ha->req_q_cnt);
  2695. goto out;
  2696. }
  2697. CMD_HANDLE(sp->cmd) = (unsigned char *) (unsigned long)(cnt + 1);
  2698. ha->outstanding_cmds[cnt] = sp;
  2699. ha->req_q_cnt -= req_cnt;
  2700. /*
  2701. * Build command packet.
  2702. */
  2703. pkt = (struct cmd_entry *) ha->request_ring_ptr;
  2704. pkt->entry_type = COMMAND_TYPE;
  2705. pkt->entry_count = (uint8_t) req_cnt;
  2706. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2707. pkt->entry_status = 0;
  2708. pkt->handle = cpu_to_le32(cnt);
  2709. /* Zero out remaining portion of packet. */
  2710. memset(((char *)pkt + 8), 0, (REQUEST_ENTRY_SIZE - 8));
  2711. /* Set ISP command timeout. */
  2712. pkt->timeout = cpu_to_le16(cmd->request->timeout/HZ);
  2713. /* Set device target ID and LUN */
  2714. pkt->lun = SCSI_LUN_32(cmd);
  2715. pkt->target = SCSI_BUS_32(cmd) ?
  2716. (SCSI_TCN_32(cmd) | BIT_7) : SCSI_TCN_32(cmd);
  2717. /* Enable simple tag queuing if device supports it. */
  2718. if (cmd->device->simple_tags)
  2719. pkt->control_flags |= cpu_to_le16(BIT_3);
  2720. /* Load SCSI command packet. */
  2721. pkt->cdb_len = cpu_to_le16(CMD_CDBLEN(cmd));
  2722. memcpy(pkt->scsi_cdb, CMD_CDBP(cmd), CMD_CDBLEN(cmd));
  2723. /*dprintk(1, "Build packet for command[0]=0x%x\n",pkt->scsi_cdb[0]); */
  2724. /* Set transfer direction. */
  2725. dir = qla1280_data_direction(cmd);
  2726. pkt->control_flags |= cpu_to_le16(dir);
  2727. /* Set total data segment count. */
  2728. pkt->dseg_count = cpu_to_le16(seg_cnt);
  2729. /*
  2730. * Load data segments.
  2731. */
  2732. if (seg_cnt) {
  2733. struct scatterlist *sg, *s;
  2734. int remseg = seg_cnt;
  2735. sg = scsi_sglist(cmd);
  2736. /* Setup packet address segment pointer. */
  2737. dword_ptr = &pkt->dseg_0_address;
  2738. dprintk(3, "Building S/G data segments..\n");
  2739. qla1280_dump_buffer(1, (char *)sg, 4 * 16);
  2740. /* Load command entry data segments. */
  2741. for_each_sg(sg, s, seg_cnt, cnt) {
  2742. if (cnt == 4)
  2743. break;
  2744. *dword_ptr++ =
  2745. cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
  2746. *dword_ptr++ = cpu_to_le32(sg_dma_len(s));
  2747. dprintk(3, "S/G Segment phys_addr=0x%lx, len=0x%x\n",
  2748. (pci_dma_lo32(sg_dma_address(s))),
  2749. (sg_dma_len(s)));
  2750. remseg--;
  2751. }
  2752. /*
  2753. * Build continuation packets.
  2754. */
  2755. dprintk(3, "S/G Building Continuation"
  2756. "...seg_cnt=0x%x remains\n", seg_cnt);
  2757. while (remseg > 0) {
  2758. /* Continue from end point */
  2759. sg = s;
  2760. /* Adjust ring index. */
  2761. ha->req_ring_index++;
  2762. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2763. ha->req_ring_index = 0;
  2764. ha->request_ring_ptr =
  2765. ha->request_ring;
  2766. } else
  2767. ha->request_ring_ptr++;
  2768. pkt = (struct cmd_entry *)ha->request_ring_ptr;
  2769. /* Zero out packet. */
  2770. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2771. /* Load packet defaults. */
  2772. ((struct cont_entry *) pkt)->
  2773. entry_type = CONTINUE_TYPE;
  2774. ((struct cont_entry *) pkt)->entry_count = 1;
  2775. ((struct cont_entry *) pkt)->sys_define =
  2776. (uint8_t) ha->req_ring_index;
  2777. /* Setup packet address segment pointer. */
  2778. dword_ptr =
  2779. &((struct cont_entry *) pkt)->dseg_0_address;
  2780. /* Load continuation entry data segments. */
  2781. for_each_sg(sg, s, remseg, cnt) {
  2782. if (cnt == 7)
  2783. break;
  2784. *dword_ptr++ =
  2785. cpu_to_le32(pci_dma_lo32(sg_dma_address(s)));
  2786. *dword_ptr++ =
  2787. cpu_to_le32(sg_dma_len(s));
  2788. dprintk(1,
  2789. "S/G Segment Cont. phys_addr=0x%x, "
  2790. "len=0x%x\n",
  2791. cpu_to_le32(pci_dma_lo32(sg_dma_address(s))),
  2792. cpu_to_le32(sg_dma_len(s)));
  2793. }
  2794. remseg -= cnt;
  2795. dprintk(5, "qla1280_32bit_start_scsi: "
  2796. "continuation packet data - "
  2797. "scsi(%i:%i:%i)\n", SCSI_BUS_32(cmd),
  2798. SCSI_TCN_32(cmd), SCSI_LUN_32(cmd));
  2799. qla1280_dump_buffer(5, (char *)pkt,
  2800. REQUEST_ENTRY_SIZE);
  2801. }
  2802. } else { /* No data transfer at all */
  2803. dprintk(5, "qla1280_32bit_start_scsi: No data, command "
  2804. "packet data - \n");
  2805. qla1280_dump_buffer(5, (char *)pkt, REQUEST_ENTRY_SIZE);
  2806. }
  2807. dprintk(5, "qla1280_32bit_start_scsi: First IOCB block:\n");
  2808. qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
  2809. REQUEST_ENTRY_SIZE);
  2810. /* Adjust ring index. */
  2811. ha->req_ring_index++;
  2812. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2813. ha->req_ring_index = 0;
  2814. ha->request_ring_ptr = ha->request_ring;
  2815. } else
  2816. ha->request_ring_ptr++;
  2817. /* Set chip new ring index. */
  2818. dprintk(2, "qla1280_32bit_start_scsi: Wakeup RISC "
  2819. "for pending command\n");
  2820. sp->flags |= SRB_SENT;
  2821. ha->actthreads++;
  2822. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2823. /* Enforce mmio write ordering; see comment in qla1280_isp_cmd(). */
  2824. mmiowb();
  2825. out:
  2826. if (status)
  2827. dprintk(2, "qla1280_32bit_start_scsi: **** FAILED ****\n");
  2828. LEAVE("qla1280_32bit_start_scsi");
  2829. return status;
  2830. }
  2831. #endif
  2832. /*
  2833. * qla1280_req_pkt
  2834. * Function is responsible for locking ring and
  2835. * getting a zeroed out request packet.
  2836. *
  2837. * Input:
  2838. * ha = adapter block pointer.
  2839. *
  2840. * Returns:
  2841. * 0 = failed to get slot.
  2842. */
  2843. static request_t *
  2844. qla1280_req_pkt(struct scsi_qla_host *ha)
  2845. {
  2846. struct device_reg __iomem *reg = ha->iobase;
  2847. request_t *pkt = NULL;
  2848. int cnt;
  2849. uint32_t timer;
  2850. ENTER("qla1280_req_pkt");
  2851. /*
  2852. * This can be called from interrupt context, damn it!!!
  2853. */
  2854. /* Wait for 30 seconds for slot. */
  2855. for (timer = 15000000; timer; timer--) {
  2856. if (ha->req_q_cnt > 0) {
  2857. /* Calculate number of free request entries. */
  2858. cnt = RD_REG_WORD(&reg->mailbox4);
  2859. if (ha->req_ring_index < cnt)
  2860. ha->req_q_cnt = cnt - ha->req_ring_index;
  2861. else
  2862. ha->req_q_cnt =
  2863. REQUEST_ENTRY_CNT - (ha->req_ring_index - cnt);
  2864. }
  2865. /* Found empty request ring slot? */
  2866. if (ha->req_q_cnt > 0) {
  2867. ha->req_q_cnt--;
  2868. pkt = ha->request_ring_ptr;
  2869. /* Zero out packet. */
  2870. memset(pkt, 0, REQUEST_ENTRY_SIZE);
  2871. /*
  2872. * How can this be right when we have a ring
  2873. * size of 512???
  2874. */
  2875. /* Set system defined field. */
  2876. pkt->sys_define = (uint8_t) ha->req_ring_index;
  2877. /* Set entry count. */
  2878. pkt->entry_count = 1;
  2879. break;
  2880. }
  2881. udelay(2); /* 10 */
  2882. /* Check for pending interrupts. */
  2883. qla1280_poll(ha);
  2884. }
  2885. if (!pkt)
  2886. dprintk(2, "qla1280_req_pkt: **** FAILED ****\n");
  2887. else
  2888. dprintk(3, "qla1280_req_pkt: exiting normally\n");
  2889. return pkt;
  2890. }
  2891. /*
  2892. * qla1280_isp_cmd
  2893. * Function is responsible for modifying ISP input pointer.
  2894. * Releases ring lock.
  2895. *
  2896. * Input:
  2897. * ha = adapter block pointer.
  2898. */
  2899. static void
  2900. qla1280_isp_cmd(struct scsi_qla_host *ha)
  2901. {
  2902. struct device_reg __iomem *reg = ha->iobase;
  2903. ENTER("qla1280_isp_cmd");
  2904. dprintk(5, "qla1280_isp_cmd: IOCB data:\n");
  2905. qla1280_dump_buffer(5, (char *)ha->request_ring_ptr,
  2906. REQUEST_ENTRY_SIZE);
  2907. /* Adjust ring index. */
  2908. ha->req_ring_index++;
  2909. if (ha->req_ring_index == REQUEST_ENTRY_CNT) {
  2910. ha->req_ring_index = 0;
  2911. ha->request_ring_ptr = ha->request_ring;
  2912. } else
  2913. ha->request_ring_ptr++;
  2914. /*
  2915. * Update request index to mailbox4 (Request Queue In).
  2916. * The mmiowb() ensures that this write is ordered with writes by other
  2917. * CPUs. Without the mmiowb(), it is possible for the following:
  2918. * CPUA posts write of index 5 to mailbox4
  2919. * CPUA releases host lock
  2920. * CPUB acquires host lock
  2921. * CPUB posts write of index 6 to mailbox4
  2922. * On PCI bus, order reverses and write of 6 posts, then index 5,
  2923. * causing chip to issue full queue of stale commands
  2924. * The mmiowb() prevents future writes from crossing the barrier.
  2925. * See Documentation/driver-api/device-io.rst for more information.
  2926. */
  2927. WRT_REG_WORD(&reg->mailbox4, ha->req_ring_index);
  2928. mmiowb();
  2929. LEAVE("qla1280_isp_cmd");
  2930. }
  2931. /****************************************************************************/
  2932. /* Interrupt Service Routine. */
  2933. /****************************************************************************/
  2934. /****************************************************************************
  2935. * qla1280_isr
  2936. * Calls I/O done on command completion.
  2937. *
  2938. * Input:
  2939. * ha = adapter block pointer.
  2940. * done_q = done queue.
  2941. ****************************************************************************/
  2942. static void
  2943. qla1280_isr(struct scsi_qla_host *ha, struct list_head *done_q)
  2944. {
  2945. struct device_reg __iomem *reg = ha->iobase;
  2946. struct response *pkt;
  2947. struct srb *sp = NULL;
  2948. uint16_t mailbox[MAILBOX_REGISTER_COUNT];
  2949. uint16_t *wptr;
  2950. uint32_t index;
  2951. u16 istatus;
  2952. ENTER("qla1280_isr");
  2953. istatus = RD_REG_WORD(&reg->istatus);
  2954. if (!(istatus & (RISC_INT | PCI_INT)))
  2955. return;
  2956. /* Save mailbox register 5 */
  2957. mailbox[5] = RD_REG_WORD(&reg->mailbox5);
  2958. /* Check for mailbox interrupt. */
  2959. mailbox[0] = RD_REG_WORD_dmasync(&reg->semaphore);
  2960. if (mailbox[0] & BIT_0) {
  2961. /* Get mailbox data. */
  2962. /* dprintk(1, "qla1280_isr: In Get mailbox data \n"); */
  2963. wptr = &mailbox[0];
  2964. *wptr++ = RD_REG_WORD(&reg->mailbox0);
  2965. *wptr++ = RD_REG_WORD(&reg->mailbox1);
  2966. *wptr = RD_REG_WORD(&reg->mailbox2);
  2967. if (mailbox[0] != MBA_SCSI_COMPLETION) {
  2968. wptr++;
  2969. *wptr++ = RD_REG_WORD(&reg->mailbox3);
  2970. *wptr++ = RD_REG_WORD(&reg->mailbox4);
  2971. wptr++;
  2972. *wptr++ = RD_REG_WORD(&reg->mailbox6);
  2973. *wptr = RD_REG_WORD(&reg->mailbox7);
  2974. }
  2975. /* Release mailbox registers. */
  2976. WRT_REG_WORD(&reg->semaphore, 0);
  2977. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  2978. dprintk(5, "qla1280_isr: mailbox interrupt mailbox[0] = 0x%x",
  2979. mailbox[0]);
  2980. /* Handle asynchronous event */
  2981. switch (mailbox[0]) {
  2982. case MBA_SCSI_COMPLETION: /* Response completion */
  2983. dprintk(5, "qla1280_isr: mailbox SCSI response "
  2984. "completion\n");
  2985. if (ha->flags.online) {
  2986. /* Get outstanding command index. */
  2987. index = mailbox[2] << 16 | mailbox[1];
  2988. /* Validate handle. */
  2989. if (index < MAX_OUTSTANDING_COMMANDS)
  2990. sp = ha->outstanding_cmds[index];
  2991. else
  2992. sp = NULL;
  2993. if (sp) {
  2994. /* Free outstanding command slot. */
  2995. ha->outstanding_cmds[index] = NULL;
  2996. /* Save ISP completion status */
  2997. CMD_RESULT(sp->cmd) = 0;
  2998. CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
  2999. /* Place block on done queue */
  3000. list_add_tail(&sp->list, done_q);
  3001. } else {
  3002. /*
  3003. * If we get here we have a real problem!
  3004. */
  3005. printk(KERN_WARNING
  3006. "qla1280: ISP invalid handle\n");
  3007. }
  3008. }
  3009. break;
  3010. case MBA_BUS_RESET: /* SCSI Bus Reset */
  3011. ha->flags.reset_marker = 1;
  3012. index = mailbox[6] & BIT_0;
  3013. ha->bus_settings[index].reset_marker = 1;
  3014. printk(KERN_DEBUG "qla1280_isr(): index %i "
  3015. "asynchronous BUS_RESET\n", index);
  3016. break;
  3017. case MBA_SYSTEM_ERR: /* System Error */
  3018. printk(KERN_WARNING
  3019. "qla1280: ISP System Error - mbx1=%xh, mbx2="
  3020. "%xh, mbx3=%xh\n", mailbox[1], mailbox[2],
  3021. mailbox[3]);
  3022. break;
  3023. case MBA_REQ_TRANSFER_ERR: /* Request Transfer Error */
  3024. printk(KERN_WARNING
  3025. "qla1280: ISP Request Transfer Error\n");
  3026. break;
  3027. case MBA_RSP_TRANSFER_ERR: /* Response Transfer Error */
  3028. printk(KERN_WARNING
  3029. "qla1280: ISP Response Transfer Error\n");
  3030. break;
  3031. case MBA_WAKEUP_THRES: /* Request Queue Wake-up */
  3032. dprintk(2, "qla1280_isr: asynchronous WAKEUP_THRES\n");
  3033. break;
  3034. case MBA_TIMEOUT_RESET: /* Execution Timeout Reset */
  3035. dprintk(2,
  3036. "qla1280_isr: asynchronous TIMEOUT_RESET\n");
  3037. break;
  3038. case MBA_DEVICE_RESET: /* Bus Device Reset */
  3039. printk(KERN_INFO "qla1280_isr(): asynchronous "
  3040. "BUS_DEVICE_RESET\n");
  3041. ha->flags.reset_marker = 1;
  3042. index = mailbox[6] & BIT_0;
  3043. ha->bus_settings[index].reset_marker = 1;
  3044. break;
  3045. case MBA_BUS_MODE_CHANGE:
  3046. dprintk(2,
  3047. "qla1280_isr: asynchronous BUS_MODE_CHANGE\n");
  3048. break;
  3049. default:
  3050. /* dprintk(1, "qla1280_isr: default case of switch MB \n"); */
  3051. if (mailbox[0] < MBA_ASYNC_EVENT) {
  3052. wptr = &mailbox[0];
  3053. memcpy((uint16_t *) ha->mailbox_out, wptr,
  3054. MAILBOX_REGISTER_COUNT *
  3055. sizeof(uint16_t));
  3056. if(ha->mailbox_wait != NULL)
  3057. complete(ha->mailbox_wait);
  3058. }
  3059. break;
  3060. }
  3061. } else {
  3062. WRT_REG_WORD(&reg->host_cmd, HC_CLR_RISC_INT);
  3063. }
  3064. /*
  3065. * We will receive interrupts during mailbox testing prior to
  3066. * the card being marked online, hence the double check.
  3067. */
  3068. if (!(ha->flags.online && !ha->mailbox_wait)) {
  3069. dprintk(2, "qla1280_isr: Response pointer Error\n");
  3070. goto out;
  3071. }
  3072. if (mailbox[5] >= RESPONSE_ENTRY_CNT)
  3073. goto out;
  3074. while (ha->rsp_ring_index != mailbox[5]) {
  3075. pkt = ha->response_ring_ptr;
  3076. dprintk(5, "qla1280_isr: ha->rsp_ring_index = 0x%x, mailbox[5]"
  3077. " = 0x%x\n", ha->rsp_ring_index, mailbox[5]);
  3078. dprintk(5,"qla1280_isr: response packet data\n");
  3079. qla1280_dump_buffer(5, (char *)pkt, RESPONSE_ENTRY_SIZE);
  3080. if (pkt->entry_type == STATUS_TYPE) {
  3081. if ((le16_to_cpu(pkt->scsi_status) & 0xff)
  3082. || pkt->comp_status || pkt->entry_status) {
  3083. dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
  3084. "0x%x mailbox[5] = 0x%x, comp_status "
  3085. "= 0x%x, scsi_status = 0x%x\n",
  3086. ha->rsp_ring_index, mailbox[5],
  3087. le16_to_cpu(pkt->comp_status),
  3088. le16_to_cpu(pkt->scsi_status));
  3089. }
  3090. } else {
  3091. dprintk(2, "qla1280_isr: ha->rsp_ring_index = "
  3092. "0x%x, mailbox[5] = 0x%x\n",
  3093. ha->rsp_ring_index, mailbox[5]);
  3094. dprintk(2, "qla1280_isr: response packet data\n");
  3095. qla1280_dump_buffer(2, (char *)pkt,
  3096. RESPONSE_ENTRY_SIZE);
  3097. }
  3098. if (pkt->entry_type == STATUS_TYPE || pkt->entry_status) {
  3099. dprintk(2, "status: Cmd %p, handle %i\n",
  3100. ha->outstanding_cmds[pkt->handle]->cmd,
  3101. pkt->handle);
  3102. if (pkt->entry_type == STATUS_TYPE)
  3103. qla1280_status_entry(ha, pkt, done_q);
  3104. else
  3105. qla1280_error_entry(ha, pkt, done_q);
  3106. /* Adjust ring index. */
  3107. ha->rsp_ring_index++;
  3108. if (ha->rsp_ring_index == RESPONSE_ENTRY_CNT) {
  3109. ha->rsp_ring_index = 0;
  3110. ha->response_ring_ptr = ha->response_ring;
  3111. } else
  3112. ha->response_ring_ptr++;
  3113. WRT_REG_WORD(&reg->mailbox5, ha->rsp_ring_index);
  3114. }
  3115. }
  3116. out:
  3117. LEAVE("qla1280_isr");
  3118. }
  3119. /*
  3120. * qla1280_rst_aen
  3121. * Processes asynchronous reset.
  3122. *
  3123. * Input:
  3124. * ha = adapter block pointer.
  3125. */
  3126. static void
  3127. qla1280_rst_aen(struct scsi_qla_host *ha)
  3128. {
  3129. uint8_t bus;
  3130. ENTER("qla1280_rst_aen");
  3131. if (ha->flags.online && !ha->flags.reset_active &&
  3132. !ha->flags.abort_isp_active) {
  3133. ha->flags.reset_active = 1;
  3134. while (ha->flags.reset_marker) {
  3135. /* Issue marker command. */
  3136. ha->flags.reset_marker = 0;
  3137. for (bus = 0; bus < ha->ports &&
  3138. !ha->flags.reset_marker; bus++) {
  3139. if (ha->bus_settings[bus].reset_marker) {
  3140. ha->bus_settings[bus].reset_marker = 0;
  3141. qla1280_marker(ha, bus, 0, 0,
  3142. MK_SYNC_ALL);
  3143. }
  3144. }
  3145. }
  3146. }
  3147. LEAVE("qla1280_rst_aen");
  3148. }
  3149. /*
  3150. * qla1280_status_entry
  3151. * Processes received ISP status entry.
  3152. *
  3153. * Input:
  3154. * ha = adapter block pointer.
  3155. * pkt = entry pointer.
  3156. * done_q = done queue.
  3157. */
  3158. static void
  3159. qla1280_status_entry(struct scsi_qla_host *ha, struct response *pkt,
  3160. struct list_head *done_q)
  3161. {
  3162. unsigned int bus, target, lun;
  3163. int sense_sz;
  3164. struct srb *sp;
  3165. struct scsi_cmnd *cmd;
  3166. uint32_t handle = le32_to_cpu(pkt->handle);
  3167. uint16_t scsi_status = le16_to_cpu(pkt->scsi_status);
  3168. uint16_t comp_status = le16_to_cpu(pkt->comp_status);
  3169. ENTER("qla1280_status_entry");
  3170. /* Validate handle. */
  3171. if (handle < MAX_OUTSTANDING_COMMANDS)
  3172. sp = ha->outstanding_cmds[handle];
  3173. else
  3174. sp = NULL;
  3175. if (!sp) {
  3176. printk(KERN_WARNING "qla1280: Status Entry invalid handle\n");
  3177. goto out;
  3178. }
  3179. /* Free outstanding command slot. */
  3180. ha->outstanding_cmds[handle] = NULL;
  3181. cmd = sp->cmd;
  3182. /* Generate LU queue on cntrl, target, LUN */
  3183. bus = SCSI_BUS_32(cmd);
  3184. target = SCSI_TCN_32(cmd);
  3185. lun = SCSI_LUN_32(cmd);
  3186. if (comp_status || scsi_status) {
  3187. dprintk(3, "scsi: comp_status = 0x%x, scsi_status = "
  3188. "0x%x, handle = 0x%x\n", comp_status,
  3189. scsi_status, handle);
  3190. }
  3191. /* Target busy or queue full */
  3192. if ((scsi_status & 0xFF) == SAM_STAT_TASK_SET_FULL ||
  3193. (scsi_status & 0xFF) == SAM_STAT_BUSY) {
  3194. CMD_RESULT(cmd) = scsi_status & 0xff;
  3195. } else {
  3196. /* Save ISP completion status */
  3197. CMD_RESULT(cmd) = qla1280_return_status(pkt, cmd);
  3198. if (scsi_status & SAM_STAT_CHECK_CONDITION) {
  3199. if (comp_status != CS_ARS_FAILED) {
  3200. uint16_t req_sense_length =
  3201. le16_to_cpu(pkt->req_sense_length);
  3202. if (req_sense_length < CMD_SNSLEN(cmd))
  3203. sense_sz = req_sense_length;
  3204. else
  3205. /*
  3206. * scsi_cmnd->sense_buffer is
  3207. * 64 bytes, why only copy 63?
  3208. * This looks wrong! /Jes
  3209. */
  3210. sense_sz = CMD_SNSLEN(cmd) - 1;
  3211. memcpy(cmd->sense_buffer,
  3212. &pkt->req_sense_data, sense_sz);
  3213. } else
  3214. sense_sz = 0;
  3215. memset(cmd->sense_buffer + sense_sz, 0,
  3216. SCSI_SENSE_BUFFERSIZE - sense_sz);
  3217. dprintk(2, "qla1280_status_entry: Check "
  3218. "condition Sense data, b %i, t %i, "
  3219. "l %i\n", bus, target, lun);
  3220. if (sense_sz)
  3221. qla1280_dump_buffer(2,
  3222. (char *)cmd->sense_buffer,
  3223. sense_sz);
  3224. }
  3225. }
  3226. CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
  3227. /* Place command on done queue. */
  3228. list_add_tail(&sp->list, done_q);
  3229. out:
  3230. LEAVE("qla1280_status_entry");
  3231. }
  3232. /*
  3233. * qla1280_error_entry
  3234. * Processes error entry.
  3235. *
  3236. * Input:
  3237. * ha = adapter block pointer.
  3238. * pkt = entry pointer.
  3239. * done_q = done queue.
  3240. */
  3241. static void
  3242. qla1280_error_entry(struct scsi_qla_host *ha, struct response *pkt,
  3243. struct list_head *done_q)
  3244. {
  3245. struct srb *sp;
  3246. uint32_t handle = le32_to_cpu(pkt->handle);
  3247. ENTER("qla1280_error_entry");
  3248. if (pkt->entry_status & BIT_3)
  3249. dprintk(2, "qla1280_error_entry: BAD PAYLOAD flag error\n");
  3250. else if (pkt->entry_status & BIT_2)
  3251. dprintk(2, "qla1280_error_entry: BAD HEADER flag error\n");
  3252. else if (pkt->entry_status & BIT_1)
  3253. dprintk(2, "qla1280_error_entry: FULL flag error\n");
  3254. else
  3255. dprintk(2, "qla1280_error_entry: UNKNOWN flag error\n");
  3256. /* Validate handle. */
  3257. if (handle < MAX_OUTSTANDING_COMMANDS)
  3258. sp = ha->outstanding_cmds[handle];
  3259. else
  3260. sp = NULL;
  3261. if (sp) {
  3262. /* Free outstanding command slot. */
  3263. ha->outstanding_cmds[handle] = NULL;
  3264. /* Bad payload or header */
  3265. if (pkt->entry_status & (BIT_3 + BIT_2)) {
  3266. /* Bad payload or header, set error status. */
  3267. /* CMD_RESULT(sp->cmd) = CS_BAD_PAYLOAD; */
  3268. CMD_RESULT(sp->cmd) = DID_ERROR << 16;
  3269. } else if (pkt->entry_status & BIT_1) { /* FULL flag */
  3270. CMD_RESULT(sp->cmd) = DID_BUS_BUSY << 16;
  3271. } else {
  3272. /* Set error status. */
  3273. CMD_RESULT(sp->cmd) = DID_ERROR << 16;
  3274. }
  3275. CMD_HANDLE(sp->cmd) = COMPLETED_HANDLE;
  3276. /* Place command on done queue. */
  3277. list_add_tail(&sp->list, done_q);
  3278. }
  3279. #ifdef QLA_64BIT_PTR
  3280. else if (pkt->entry_type == COMMAND_A64_TYPE) {
  3281. printk(KERN_WARNING "!qla1280: Error Entry invalid handle");
  3282. }
  3283. #endif
  3284. LEAVE("qla1280_error_entry");
  3285. }
  3286. /*
  3287. * qla1280_abort_isp
  3288. * Resets ISP and aborts all outstanding commands.
  3289. *
  3290. * Input:
  3291. * ha = adapter block pointer.
  3292. *
  3293. * Returns:
  3294. * 0 = success
  3295. */
  3296. static int
  3297. qla1280_abort_isp(struct scsi_qla_host *ha)
  3298. {
  3299. struct device_reg __iomem *reg = ha->iobase;
  3300. struct srb *sp;
  3301. int status = 0;
  3302. int cnt;
  3303. int bus;
  3304. ENTER("qla1280_abort_isp");
  3305. if (ha->flags.abort_isp_active || !ha->flags.online)
  3306. goto out;
  3307. ha->flags.abort_isp_active = 1;
  3308. /* Disable ISP interrupts. */
  3309. qla1280_disable_intrs(ha);
  3310. WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
  3311. RD_REG_WORD(&reg->id_l);
  3312. printk(KERN_INFO "scsi(%li): dequeuing outstanding commands\n",
  3313. ha->host_no);
  3314. /* Dequeue all commands in outstanding command list. */
  3315. for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
  3316. struct scsi_cmnd *cmd;
  3317. sp = ha->outstanding_cmds[cnt];
  3318. if (sp) {
  3319. cmd = sp->cmd;
  3320. CMD_RESULT(cmd) = DID_RESET << 16;
  3321. CMD_HANDLE(cmd) = COMPLETED_HANDLE;
  3322. ha->outstanding_cmds[cnt] = NULL;
  3323. list_add_tail(&sp->list, &ha->done_q);
  3324. }
  3325. }
  3326. qla1280_done(ha);
  3327. status = qla1280_load_firmware(ha);
  3328. if (status)
  3329. goto out;
  3330. /* Setup adapter based on NVRAM parameters. */
  3331. qla1280_nvram_config (ha);
  3332. status = qla1280_init_rings(ha);
  3333. if (status)
  3334. goto out;
  3335. /* Issue SCSI reset. */
  3336. for (bus = 0; bus < ha->ports; bus++)
  3337. qla1280_bus_reset(ha, bus);
  3338. ha->flags.abort_isp_active = 0;
  3339. out:
  3340. if (status) {
  3341. printk(KERN_WARNING
  3342. "qla1280: ISP error recovery failed, board disabled");
  3343. qla1280_reset_adapter(ha);
  3344. dprintk(2, "qla1280_abort_isp: **** FAILED ****\n");
  3345. }
  3346. LEAVE("qla1280_abort_isp");
  3347. return status;
  3348. }
  3349. /*
  3350. * qla1280_debounce_register
  3351. * Debounce register.
  3352. *
  3353. * Input:
  3354. * port = register address.
  3355. *
  3356. * Returns:
  3357. * register value.
  3358. */
  3359. static u16
  3360. qla1280_debounce_register(volatile u16 __iomem * addr)
  3361. {
  3362. volatile u16 ret;
  3363. volatile u16 ret2;
  3364. ret = RD_REG_WORD(addr);
  3365. ret2 = RD_REG_WORD(addr);
  3366. if (ret == ret2)
  3367. return ret;
  3368. do {
  3369. cpu_relax();
  3370. ret = RD_REG_WORD(addr);
  3371. ret2 = RD_REG_WORD(addr);
  3372. } while (ret != ret2);
  3373. return ret;
  3374. }
  3375. /************************************************************************
  3376. * qla1280_check_for_dead_scsi_bus *
  3377. * *
  3378. * This routine checks for a dead SCSI bus *
  3379. ************************************************************************/
  3380. #define SET_SXP_BANK 0x0100
  3381. #define SCSI_PHASE_INVALID 0x87FF
  3382. static int
  3383. qla1280_check_for_dead_scsi_bus(struct scsi_qla_host *ha, unsigned int bus)
  3384. {
  3385. uint16_t config_reg, scsi_control;
  3386. struct device_reg __iomem *reg = ha->iobase;
  3387. if (ha->bus_settings[bus].scsi_bus_dead) {
  3388. WRT_REG_WORD(&reg->host_cmd, HC_PAUSE_RISC);
  3389. config_reg = RD_REG_WORD(&reg->cfg_1);
  3390. WRT_REG_WORD(&reg->cfg_1, SET_SXP_BANK);
  3391. scsi_control = RD_REG_WORD(&reg->scsiControlPins);
  3392. WRT_REG_WORD(&reg->cfg_1, config_reg);
  3393. WRT_REG_WORD(&reg->host_cmd, HC_RELEASE_RISC);
  3394. if (scsi_control == SCSI_PHASE_INVALID) {
  3395. ha->bus_settings[bus].scsi_bus_dead = 1;
  3396. return 1; /* bus is dead */
  3397. } else {
  3398. ha->bus_settings[bus].scsi_bus_dead = 0;
  3399. ha->bus_settings[bus].failed_reset_count = 0;
  3400. }
  3401. }
  3402. return 0; /* bus is not dead */
  3403. }
  3404. static void
  3405. qla1280_get_target_parameters(struct scsi_qla_host *ha,
  3406. struct scsi_device *device)
  3407. {
  3408. uint16_t mb[MAILBOX_REGISTER_COUNT];
  3409. int bus, target, lun;
  3410. bus = device->channel;
  3411. target = device->id;
  3412. lun = device->lun;
  3413. mb[0] = MBC_GET_TARGET_PARAMETERS;
  3414. mb[1] = (uint16_t) (bus ? target | BIT_7 : target);
  3415. mb[1] <<= 8;
  3416. qla1280_mailbox_command(ha, BIT_6 | BIT_3 | BIT_2 | BIT_1 | BIT_0,
  3417. &mb[0]);
  3418. printk(KERN_INFO "scsi(%li:%d:%d:%d):", ha->host_no, bus, target, lun);
  3419. if (mb[3] != 0) {
  3420. printk(" Sync: period %d, offset %d",
  3421. (mb[3] & 0xff), (mb[3] >> 8));
  3422. if (mb[2] & BIT_13)
  3423. printk(", Wide");
  3424. if ((mb[2] & BIT_5) && ((mb[6] >> 8) & 0xff) >= 2)
  3425. printk(", DT");
  3426. } else
  3427. printk(" Async");
  3428. if (device->simple_tags)
  3429. printk(", Tagged queuing: depth %d", device->queue_depth);
  3430. printk("\n");
  3431. }
  3432. #if DEBUG_QLA1280
  3433. static void
  3434. __qla1280_dump_buffer(char *b, int size)
  3435. {
  3436. int cnt;
  3437. u8 c;
  3438. printk(KERN_DEBUG " 0 1 2 3 4 5 6 7 8 9 Ah "
  3439. "Bh Ch Dh Eh Fh\n");
  3440. printk(KERN_DEBUG "---------------------------------------------"
  3441. "------------------\n");
  3442. for (cnt = 0; cnt < size;) {
  3443. c = *b++;
  3444. printk("0x%02x", c);
  3445. cnt++;
  3446. if (!(cnt % 16))
  3447. printk("\n");
  3448. else
  3449. printk(" ");
  3450. }
  3451. if (cnt % 16)
  3452. printk("\n");
  3453. }
  3454. /**************************************************************************
  3455. * ql1280_print_scsi_cmd
  3456. *
  3457. **************************************************************************/
  3458. static void
  3459. __qla1280_print_scsi_cmd(struct scsi_cmnd *cmd)
  3460. {
  3461. struct scsi_qla_host *ha;
  3462. struct Scsi_Host *host = CMD_HOST(cmd);
  3463. struct srb *sp;
  3464. /* struct scatterlist *sg; */
  3465. int i;
  3466. ha = (struct scsi_qla_host *)host->hostdata;
  3467. sp = (struct srb *)CMD_SP(cmd);
  3468. printk("SCSI Command @= 0x%p, Handle=0x%p\n", cmd, CMD_HANDLE(cmd));
  3469. printk(" chan=%d, target = 0x%02x, lun = 0x%02x, cmd_len = 0x%02x\n",
  3470. SCSI_BUS_32(cmd), SCSI_TCN_32(cmd), SCSI_LUN_32(cmd),
  3471. CMD_CDBLEN(cmd));
  3472. printk(" CDB = ");
  3473. for (i = 0; i < cmd->cmd_len; i++) {
  3474. printk("0x%02x ", cmd->cmnd[i]);
  3475. }
  3476. printk(" seg_cnt =%d\n", scsi_sg_count(cmd));
  3477. printk(" request buffer=0x%p, request buffer len=0x%x\n",
  3478. scsi_sglist(cmd), scsi_bufflen(cmd));
  3479. /* if (cmd->use_sg)
  3480. {
  3481. sg = (struct scatterlist *) cmd->request_buffer;
  3482. printk(" SG buffer: \n");
  3483. qla1280_dump_buffer(1, (char *)sg, (cmd->use_sg*sizeof(struct scatterlist)));
  3484. } */
  3485. printk(" tag=%d, transfersize=0x%x \n",
  3486. cmd->tag, cmd->transfersize);
  3487. printk(" SP=0x%p\n", CMD_SP(cmd));
  3488. printk(" underflow size = 0x%x, direction=0x%x\n",
  3489. cmd->underflow, cmd->sc_data_direction);
  3490. }
  3491. /**************************************************************************
  3492. * ql1280_dump_device
  3493. *
  3494. **************************************************************************/
  3495. static void
  3496. ql1280_dump_device(struct scsi_qla_host *ha)
  3497. {
  3498. struct scsi_cmnd *cp;
  3499. struct srb *sp;
  3500. int i;
  3501. printk(KERN_DEBUG "Outstanding Commands on controller:\n");
  3502. for (i = 0; i < MAX_OUTSTANDING_COMMANDS; i++) {
  3503. if ((sp = ha->outstanding_cmds[i]) == NULL)
  3504. continue;
  3505. if ((cp = sp->cmd) == NULL)
  3506. continue;
  3507. qla1280_print_scsi_cmd(1, cp);
  3508. }
  3509. }
  3510. #endif
  3511. enum tokens {
  3512. TOKEN_NVRAM,
  3513. TOKEN_SYNC,
  3514. TOKEN_WIDE,
  3515. TOKEN_PPR,
  3516. TOKEN_VERBOSE,
  3517. TOKEN_DEBUG,
  3518. };
  3519. struct setup_tokens {
  3520. char *token;
  3521. int val;
  3522. };
  3523. static struct setup_tokens setup_token[] __initdata =
  3524. {
  3525. { "nvram", TOKEN_NVRAM },
  3526. { "sync", TOKEN_SYNC },
  3527. { "wide", TOKEN_WIDE },
  3528. { "ppr", TOKEN_PPR },
  3529. { "verbose", TOKEN_VERBOSE },
  3530. { "debug", TOKEN_DEBUG },
  3531. };
  3532. /**************************************************************************
  3533. * qla1280_setup
  3534. *
  3535. * Handle boot parameters. This really needs to be changed so one
  3536. * can specify per adapter parameters.
  3537. **************************************************************************/
  3538. static int __init
  3539. qla1280_setup(char *s)
  3540. {
  3541. char *cp, *ptr;
  3542. unsigned long val;
  3543. int toke;
  3544. cp = s;
  3545. while (cp && (ptr = strchr(cp, ':'))) {
  3546. ptr++;
  3547. if (!strcmp(ptr, "yes")) {
  3548. val = 0x10000;
  3549. ptr += 3;
  3550. } else if (!strcmp(ptr, "no")) {
  3551. val = 0;
  3552. ptr += 2;
  3553. } else
  3554. val = simple_strtoul(ptr, &ptr, 0);
  3555. switch ((toke = qla1280_get_token(cp))) {
  3556. case TOKEN_NVRAM:
  3557. if (!val)
  3558. driver_setup.no_nvram = 1;
  3559. break;
  3560. case TOKEN_SYNC:
  3561. if (!val)
  3562. driver_setup.no_sync = 1;
  3563. else if (val != 0x10000)
  3564. driver_setup.sync_mask = val;
  3565. break;
  3566. case TOKEN_WIDE:
  3567. if (!val)
  3568. driver_setup.no_wide = 1;
  3569. else if (val != 0x10000)
  3570. driver_setup.wide_mask = val;
  3571. break;
  3572. case TOKEN_PPR:
  3573. if (!val)
  3574. driver_setup.no_ppr = 1;
  3575. else if (val != 0x10000)
  3576. driver_setup.ppr_mask = val;
  3577. break;
  3578. case TOKEN_VERBOSE:
  3579. qla1280_verbose = val;
  3580. break;
  3581. default:
  3582. printk(KERN_INFO "qla1280: unknown boot option %s\n",
  3583. cp);
  3584. }
  3585. cp = strchr(ptr, ';');
  3586. if (cp)
  3587. cp++;
  3588. else {
  3589. break;
  3590. }
  3591. }
  3592. return 1;
  3593. }
  3594. static int __init
  3595. qla1280_get_token(char *str)
  3596. {
  3597. char *sep;
  3598. long ret = -1;
  3599. int i;
  3600. sep = strchr(str, ':');
  3601. if (sep) {
  3602. for (i = 0; i < ARRAY_SIZE(setup_token); i++) {
  3603. if (!strncmp(setup_token[i].token, str, (sep - str))) {
  3604. ret = setup_token[i].val;
  3605. break;
  3606. }
  3607. }
  3608. }
  3609. return ret;
  3610. }
  3611. static struct scsi_host_template qla1280_driver_template = {
  3612. .module = THIS_MODULE,
  3613. .proc_name = "qla1280",
  3614. .name = "Qlogic ISP 1280/12160",
  3615. .info = qla1280_info,
  3616. .slave_configure = qla1280_slave_configure,
  3617. .queuecommand = qla1280_queuecommand,
  3618. .eh_abort_handler = qla1280_eh_abort,
  3619. .eh_device_reset_handler= qla1280_eh_device_reset,
  3620. .eh_bus_reset_handler = qla1280_eh_bus_reset,
  3621. .eh_host_reset_handler = qla1280_eh_adapter_reset,
  3622. .bios_param = qla1280_biosparam,
  3623. .can_queue = MAX_OUTSTANDING_COMMANDS,
  3624. .this_id = -1,
  3625. .sg_tablesize = SG_ALL,
  3626. .use_clustering = ENABLE_CLUSTERING,
  3627. };
  3628. static int
  3629. qla1280_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
  3630. {
  3631. int devnum = id->driver_data;
  3632. struct qla_boards *bdp = &ql1280_board_tbl[devnum];
  3633. struct Scsi_Host *host;
  3634. struct scsi_qla_host *ha;
  3635. int error = -ENODEV;
  3636. /* Bypass all AMI SUBSYS VENDOR IDs */
  3637. if (pdev->subsystem_vendor == PCI_VENDOR_ID_AMI) {
  3638. printk(KERN_INFO
  3639. "qla1280: Skipping AMI SubSys Vendor ID Chip\n");
  3640. goto error;
  3641. }
  3642. printk(KERN_INFO "qla1280: %s found on PCI bus %i, dev %i\n",
  3643. bdp->name, pdev->bus->number, PCI_SLOT(pdev->devfn));
  3644. if (pci_enable_device(pdev)) {
  3645. printk(KERN_WARNING
  3646. "qla1280: Failed to enabled pci device, aborting.\n");
  3647. goto error;
  3648. }
  3649. pci_set_master(pdev);
  3650. error = -ENOMEM;
  3651. host = scsi_host_alloc(&qla1280_driver_template, sizeof(*ha));
  3652. if (!host) {
  3653. printk(KERN_WARNING
  3654. "qla1280: Failed to register host, aborting.\n");
  3655. goto error_disable_device;
  3656. }
  3657. ha = (struct scsi_qla_host *)host->hostdata;
  3658. memset(ha, 0, sizeof(struct scsi_qla_host));
  3659. ha->pdev = pdev;
  3660. ha->devnum = devnum; /* specifies microcode load address */
  3661. #ifdef QLA_64BIT_PTR
  3662. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
  3663. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32))) {
  3664. printk(KERN_WARNING "scsi(%li): Unable to set a "
  3665. "suitable DMA mask - aborting\n", ha->host_no);
  3666. error = -ENODEV;
  3667. goto error_put_host;
  3668. }
  3669. } else
  3670. dprintk(2, "scsi(%li): 64 Bit PCI Addressing Enabled\n",
  3671. ha->host_no);
  3672. #else
  3673. if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32))) {
  3674. printk(KERN_WARNING "scsi(%li): Unable to set a "
  3675. "suitable DMA mask - aborting\n", ha->host_no);
  3676. error = -ENODEV;
  3677. goto error_put_host;
  3678. }
  3679. #endif
  3680. ha->request_ring = pci_alloc_consistent(ha->pdev,
  3681. ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
  3682. &ha->request_dma);
  3683. if (!ha->request_ring) {
  3684. printk(KERN_INFO "qla1280: Failed to get request memory\n");
  3685. goto error_put_host;
  3686. }
  3687. ha->response_ring = pci_alloc_consistent(ha->pdev,
  3688. ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
  3689. &ha->response_dma);
  3690. if (!ha->response_ring) {
  3691. printk(KERN_INFO "qla1280: Failed to get response memory\n");
  3692. goto error_free_request_ring;
  3693. }
  3694. ha->ports = bdp->numPorts;
  3695. ha->host = host;
  3696. ha->host_no = host->host_no;
  3697. host->irq = pdev->irq;
  3698. host->max_channel = bdp->numPorts - 1;
  3699. host->max_lun = MAX_LUNS - 1;
  3700. host->max_id = MAX_TARGETS;
  3701. host->max_sectors = 1024;
  3702. host->unique_id = host->host_no;
  3703. error = -ENODEV;
  3704. #if MEMORY_MAPPED_IO
  3705. ha->mmpbase = pci_ioremap_bar(ha->pdev, 1);
  3706. if (!ha->mmpbase) {
  3707. printk(KERN_INFO "qla1280: Unable to map I/O memory\n");
  3708. goto error_free_response_ring;
  3709. }
  3710. host->base = (unsigned long)ha->mmpbase;
  3711. ha->iobase = (struct device_reg __iomem *)ha->mmpbase;
  3712. #else
  3713. host->io_port = pci_resource_start(ha->pdev, 0);
  3714. if (!request_region(host->io_port, 0xff, "qla1280")) {
  3715. printk(KERN_INFO "qla1280: Failed to reserve i/o region "
  3716. "0x%04lx-0x%04lx - already in use\n",
  3717. host->io_port, host->io_port + 0xff);
  3718. goto error_free_response_ring;
  3719. }
  3720. ha->iobase = (struct device_reg *)host->io_port;
  3721. #endif
  3722. INIT_LIST_HEAD(&ha->done_q);
  3723. /* Disable ISP interrupts. */
  3724. qla1280_disable_intrs(ha);
  3725. if (request_irq(pdev->irq, qla1280_intr_handler, IRQF_SHARED,
  3726. "qla1280", ha)) {
  3727. printk("qla1280 : Failed to reserve interrupt %d already "
  3728. "in use\n", pdev->irq);
  3729. goto error_release_region;
  3730. }
  3731. /* load the F/W, read paramaters, and init the H/W */
  3732. if (qla1280_initialize_adapter(ha)) {
  3733. printk(KERN_INFO "qla1x160: Failed to initialize adapter\n");
  3734. goto error_free_irq;
  3735. }
  3736. /* set our host ID (need to do something about our two IDs) */
  3737. host->this_id = ha->bus_settings[0].id;
  3738. pci_set_drvdata(pdev, host);
  3739. error = scsi_add_host(host, &pdev->dev);
  3740. if (error)
  3741. goto error_disable_adapter;
  3742. scsi_scan_host(host);
  3743. return 0;
  3744. error_disable_adapter:
  3745. qla1280_disable_intrs(ha);
  3746. error_free_irq:
  3747. free_irq(pdev->irq, ha);
  3748. error_release_region:
  3749. #if MEMORY_MAPPED_IO
  3750. iounmap(ha->mmpbase);
  3751. #else
  3752. release_region(host->io_port, 0xff);
  3753. #endif
  3754. error_free_response_ring:
  3755. pci_free_consistent(ha->pdev,
  3756. ((RESPONSE_ENTRY_CNT + 1) * sizeof(struct response)),
  3757. ha->response_ring, ha->response_dma);
  3758. error_free_request_ring:
  3759. pci_free_consistent(ha->pdev,
  3760. ((REQUEST_ENTRY_CNT + 1) * sizeof(request_t)),
  3761. ha->request_ring, ha->request_dma);
  3762. error_put_host:
  3763. scsi_host_put(host);
  3764. error_disable_device:
  3765. pci_disable_device(pdev);
  3766. error:
  3767. return error;
  3768. }
  3769. static void
  3770. qla1280_remove_one(struct pci_dev *pdev)
  3771. {
  3772. struct Scsi_Host *host = pci_get_drvdata(pdev);
  3773. struct scsi_qla_host *ha = (struct scsi_qla_host *)host->hostdata;
  3774. scsi_remove_host(host);
  3775. qla1280_disable_intrs(ha);
  3776. free_irq(pdev->irq, ha);
  3777. #if MEMORY_MAPPED_IO
  3778. iounmap(ha->mmpbase);
  3779. #else
  3780. release_region(host->io_port, 0xff);
  3781. #endif
  3782. pci_free_consistent(ha->pdev,
  3783. ((REQUEST_ENTRY_CNT + 1) * (sizeof(request_t))),
  3784. ha->request_ring, ha->request_dma);
  3785. pci_free_consistent(ha->pdev,
  3786. ((RESPONSE_ENTRY_CNT + 1) * (sizeof(struct response))),
  3787. ha->response_ring, ha->response_dma);
  3788. pci_disable_device(pdev);
  3789. scsi_host_put(host);
  3790. }
  3791. static struct pci_driver qla1280_pci_driver = {
  3792. .name = "qla1280",
  3793. .id_table = qla1280_pci_tbl,
  3794. .probe = qla1280_probe_one,
  3795. .remove = qla1280_remove_one,
  3796. };
  3797. static int __init
  3798. qla1280_init(void)
  3799. {
  3800. if (sizeof(struct srb) > sizeof(struct scsi_pointer)) {
  3801. printk(KERN_WARNING
  3802. "qla1280: struct srb too big, aborting\n");
  3803. return -EINVAL;
  3804. }
  3805. #ifdef MODULE
  3806. /*
  3807. * If we are called as a module, the qla1280 pointer may not be null
  3808. * and it would point to our bootup string, just like on the lilo
  3809. * command line. IF not NULL, then process this config string with
  3810. * qla1280_setup
  3811. *
  3812. * Boot time Options
  3813. * To add options at boot time add a line to your lilo.conf file like:
  3814. * append="qla1280=verbose,max_tags:{{255,255,255,255},{255,255,255,255}}"
  3815. * which will result in the first four devices on the first two
  3816. * controllers being set to a tagged queue depth of 32.
  3817. */
  3818. if (qla1280)
  3819. qla1280_setup(qla1280);
  3820. #endif
  3821. return pci_register_driver(&qla1280_pci_driver);
  3822. }
  3823. static void __exit
  3824. qla1280_exit(void)
  3825. {
  3826. int i;
  3827. pci_unregister_driver(&qla1280_pci_driver);
  3828. /* release any allocated firmware images */
  3829. for (i = 0; i < QL_NUM_FW_IMAGES; i++) {
  3830. release_firmware(qla1280_fw_tbl[i].fw);
  3831. qla1280_fw_tbl[i].fw = NULL;
  3832. }
  3833. }
  3834. module_init(qla1280_init);
  3835. module_exit(qla1280_exit);
  3836. MODULE_AUTHOR("Qlogic & Jes Sorensen");
  3837. MODULE_DESCRIPTION("Qlogic ISP SCSI (qla1x80/qla1x160) driver");
  3838. MODULE_LICENSE("GPL");
  3839. MODULE_FIRMWARE("qlogic/1040.bin");
  3840. MODULE_FIRMWARE("qlogic/1280.bin");
  3841. MODULE_FIRMWARE("qlogic/12160.bin");
  3842. MODULE_VERSION(QLA1280_VERSION);
  3843. /*
  3844. * Overrides for Emacs so that we almost follow Linus's tabbing style.
  3845. * Emacs will notice this stuff at the end of the file and automatically
  3846. * adjust the settings for this buffer only. This must remain at the end
  3847. * of the file.
  3848. * ---------------------------------------------------------------------------
  3849. * Local variables:
  3850. * c-basic-offset: 8
  3851. * tab-width: 8
  3852. * End:
  3853. */