qla1280.c 121 KB

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