qla1280.c 135 KB

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