mptscsih.c 151 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592
  1. /*
  2. * linux/drivers/message/fusion/mptscsih.c
  3. * For use with LSI Logic PCI chip/adapter(s)
  4. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  5. *
  6. * Copyright (c) 1999-2005 LSI Logic Corporation
  7. * (mailto:mpt_linux_developer@lsil.com)
  8. *
  9. */
  10. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  11. /*
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; version 2 of the License.
  15. This program is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. NO WARRANTY
  20. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  21. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  22. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  23. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  24. solely responsible for determining the appropriateness of using and
  25. distributing the Program and assumes all risks associated with its
  26. exercise of rights under this Agreement, including but not limited to
  27. the risks and costs of program errors, damage to or loss of data,
  28. programs or equipment, and unavailability or interruption of operations.
  29. DISCLAIMER OF LIABILITY
  30. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  31. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  32. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  33. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  34. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  35. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  36. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  37. You should have received a copy of the GNU General Public License
  38. along with this program; if not, write to the Free Software
  39. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  40. */
  41. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  42. #include "linux_compat.h" /* linux-2.6 tweaks */
  43. #include <linux/module.h>
  44. #include <linux/kernel.h>
  45. #include <linux/init.h>
  46. #include <linux/errno.h>
  47. #include <linux/kdev_t.h>
  48. #include <linux/blkdev.h>
  49. #include <linux/delay.h> /* for mdelay */
  50. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  51. #include <linux/reboot.h> /* notifier code */
  52. #include <linux/sched.h>
  53. #include <linux/workqueue.h>
  54. #include <scsi/scsi.h>
  55. #include <scsi/scsi_cmnd.h>
  56. #include <scsi/scsi_device.h>
  57. #include <scsi/scsi_host.h>
  58. #include <scsi/scsi_tcq.h>
  59. #include "mptbase.h"
  60. #include "mptscsih.h"
  61. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  62. #define my_NAME "Fusion MPT SCSI Host driver"
  63. #define my_VERSION MPT_LINUX_VERSION_COMMON
  64. #define MYNAM "mptscsih"
  65. MODULE_AUTHOR(MODULEAUTHOR);
  66. MODULE_DESCRIPTION(my_NAME);
  67. MODULE_LICENSE("GPL");
  68. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  69. typedef struct _BIG_SENSE_BUF {
  70. u8 data[MPT_SENSE_BUFFER_ALLOC];
  71. } BIG_SENSE_BUF;
  72. #define MPT_SCANDV_GOOD (0x00000000) /* must be 0 */
  73. #define MPT_SCANDV_DID_RESET (0x00000001)
  74. #define MPT_SCANDV_SENSE (0x00000002)
  75. #define MPT_SCANDV_SOME_ERROR (0x00000004)
  76. #define MPT_SCANDV_SELECTION_TIMEOUT (0x00000008)
  77. #define MPT_SCANDV_ISSUE_SENSE (0x00000010)
  78. #define MPT_SCANDV_FALLBACK (0x00000020)
  79. #define MPT_SCANDV_MAX_RETRIES (10)
  80. #define MPT_ICFLAG_BUF_CAP 0x01 /* ReadBuffer Read Capacity format */
  81. #define MPT_ICFLAG_ECHO 0x02 /* ReadBuffer Echo buffer format */
  82. #define MPT_ICFLAG_PHYS_DISK 0x04 /* Any SCSI IO but do Phys Disk Format */
  83. #define MPT_ICFLAG_TAGGED_CMD 0x08 /* Do tagged IO */
  84. #define MPT_ICFLAG_DID_RESET 0x20 /* Bus Reset occurred with this command */
  85. #define MPT_ICFLAG_RESERVED 0x40 /* Reserved has been issued */
  86. typedef struct _internal_cmd {
  87. char *data; /* data pointer */
  88. dma_addr_t data_dma; /* data dma address */
  89. int size; /* transfer size */
  90. u8 cmd; /* SCSI Op Code */
  91. u8 bus; /* bus number */
  92. u8 id; /* SCSI ID (virtual) */
  93. u8 lun;
  94. u8 flags; /* Bit Field - See above */
  95. u8 physDiskNum; /* Phys disk number, -1 else */
  96. u8 rsvd2;
  97. u8 rsvd;
  98. } INTERNAL_CMD;
  99. typedef struct _negoparms {
  100. u8 width;
  101. u8 offset;
  102. u8 factor;
  103. u8 flags;
  104. } NEGOPARMS;
  105. typedef struct _dv_parameters {
  106. NEGOPARMS max;
  107. NEGOPARMS now;
  108. u8 cmd;
  109. u8 id;
  110. u16 pad1;
  111. } DVPARAMETERS;
  112. /*
  113. * Other private/forward protos...
  114. */
  115. int mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  116. static void mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq);
  117. int mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  118. static int mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  119. SCSIIORequest_t *pReq, int req_idx);
  120. static void mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx);
  121. static void mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply);
  122. static int mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd);
  123. static int mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout );
  124. static u32 SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc);
  125. static int mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout);
  126. static int mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout);
  127. int mptscsih_ioc_reset(MPT_ADAPTER *ioc, int post_reset);
  128. int mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply);
  129. static void mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen);
  130. static void mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56);
  131. static void mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq);
  132. static void mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags);
  133. static void mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id);
  134. static int mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target, int flags);
  135. static int mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus);
  136. int mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *r);
  137. static int mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *iocmd);
  138. static int mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum);
  139. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  140. static int mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io);
  141. static void mptscsih_domainValidation(void *hd);
  142. static int mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id);
  143. static void mptscsih_qas_check(MPT_SCSI_HOST *hd, int id);
  144. static int mptscsih_doDv(MPT_SCSI_HOST *hd, int channel, int target);
  145. static void mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage);
  146. static void mptscsih_fillbuf(char *buffer, int size, int index, int width);
  147. #endif
  148. void mptscsih_remove(struct pci_dev *);
  149. void mptscsih_shutdown(struct pci_dev *);
  150. #ifdef CONFIG_PM
  151. int mptscsih_suspend(struct pci_dev *pdev, pm_message_t state);
  152. int mptscsih_resume(struct pci_dev *pdev);
  153. #endif
  154. #define SNS_LEN(scp) sizeof((scp)->sense_buffer)
  155. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  156. /*
  157. * Domain Validation task structure
  158. */
  159. static DEFINE_SPINLOCK(dvtaskQ_lock);
  160. static int dvtaskQ_active = 0;
  161. static int dvtaskQ_release = 0;
  162. static struct work_struct dvTaskQ_task;
  163. #endif
  164. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  165. /**
  166. * mptscsih_add_sge - Place a simple SGE at address pAddr.
  167. * @pAddr: virtual address for SGE
  168. * @flagslength: SGE flags and data transfer length
  169. * @dma_addr: Physical address
  170. *
  171. * This routine places a MPT request frame back on the MPT adapter's
  172. * FreeQ.
  173. */
  174. static inline void
  175. mptscsih_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  176. {
  177. if (sizeof(dma_addr_t) == sizeof(u64)) {
  178. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  179. u32 tmp = dma_addr & 0xFFFFFFFF;
  180. pSge->FlagsLength = cpu_to_le32(flagslength);
  181. pSge->Address.Low = cpu_to_le32(tmp);
  182. tmp = (u32) ((u64)dma_addr >> 32);
  183. pSge->Address.High = cpu_to_le32(tmp);
  184. } else {
  185. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  186. pSge->FlagsLength = cpu_to_le32(flagslength);
  187. pSge->Address = cpu_to_le32(dma_addr);
  188. }
  189. } /* mptscsih_add_sge() */
  190. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  191. /**
  192. * mptscsih_add_chain - Place a chain SGE at address pAddr.
  193. * @pAddr: virtual address for SGE
  194. * @next: nextChainOffset value (u32's)
  195. * @length: length of next SGL segment
  196. * @dma_addr: Physical address
  197. *
  198. * This routine places a MPT request frame back on the MPT adapter's
  199. * FreeQ.
  200. */
  201. static inline void
  202. mptscsih_add_chain(char *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  203. {
  204. if (sizeof(dma_addr_t) == sizeof(u64)) {
  205. SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
  206. u32 tmp = dma_addr & 0xFFFFFFFF;
  207. pChain->Length = cpu_to_le16(length);
  208. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
  209. pChain->NextChainOffset = next;
  210. pChain->Address.Low = cpu_to_le32(tmp);
  211. tmp = (u32) ((u64)dma_addr >> 32);
  212. pChain->Address.High = cpu_to_le32(tmp);
  213. } else {
  214. SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
  215. pChain->Length = cpu_to_le16(length);
  216. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT | mpt_addr_size();
  217. pChain->NextChainOffset = next;
  218. pChain->Address = cpu_to_le32(dma_addr);
  219. }
  220. } /* mptscsih_add_chain() */
  221. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  222. /*
  223. * mptscsih_getFreeChainBuffer - Function to get a free chain
  224. * from the MPT_SCSI_HOST FreeChainQ.
  225. * @ioc: Pointer to MPT_ADAPTER structure
  226. * @req_idx: Index of the SCSI IO request frame. (output)
  227. *
  228. * return SUCCESS or FAILED
  229. */
  230. static inline int
  231. mptscsih_getFreeChainBuffer(MPT_ADAPTER *ioc, int *retIndex)
  232. {
  233. MPT_FRAME_HDR *chainBuf;
  234. unsigned long flags;
  235. int rc;
  236. int chain_idx;
  237. dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer called\n",
  238. ioc->name));
  239. spin_lock_irqsave(&ioc->FreeQlock, flags);
  240. if (!list_empty(&ioc->FreeChainQ)) {
  241. int offset;
  242. chainBuf = list_entry(ioc->FreeChainQ.next, MPT_FRAME_HDR,
  243. u.frame.linkage.list);
  244. list_del(&chainBuf->u.frame.linkage.list);
  245. offset = (u8 *)chainBuf - (u8 *)ioc->ChainBuffer;
  246. chain_idx = offset / ioc->req_sz;
  247. rc = SUCCESS;
  248. dsgprintk((MYIOC_s_INFO_FMT "getFreeChainBuffer (index %d), got buf=%p\n",
  249. ioc->name, *retIndex, chainBuf));
  250. } else {
  251. rc = FAILED;
  252. chain_idx = MPT_HOST_NO_CHAIN;
  253. dfailprintk((MYIOC_s_ERR_FMT "getFreeChainBuffer failed\n",
  254. ioc->name));
  255. }
  256. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  257. *retIndex = chain_idx;
  258. return rc;
  259. } /* mptscsih_getFreeChainBuffer() */
  260. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  261. /*
  262. * mptscsih_AddSGE - Add a SGE (plus chain buffers) to the
  263. * SCSIIORequest_t Message Frame.
  264. * @ioc: Pointer to MPT_ADAPTER structure
  265. * @SCpnt: Pointer to scsi_cmnd structure
  266. * @pReq: Pointer to SCSIIORequest_t structure
  267. *
  268. * Returns ...
  269. */
  270. static int
  271. mptscsih_AddSGE(MPT_ADAPTER *ioc, struct scsi_cmnd *SCpnt,
  272. SCSIIORequest_t *pReq, int req_idx)
  273. {
  274. char *psge;
  275. char *chainSge;
  276. struct scatterlist *sg;
  277. int frm_sz;
  278. int sges_left, sg_done;
  279. int chain_idx = MPT_HOST_NO_CHAIN;
  280. int sgeOffset;
  281. int numSgeSlots, numSgeThisFrame;
  282. u32 sgflags, sgdir, thisxfer = 0;
  283. int chain_dma_off = 0;
  284. int newIndex;
  285. int ii;
  286. dma_addr_t v2;
  287. u32 RequestNB;
  288. sgdir = le32_to_cpu(pReq->Control) & MPI_SCSIIO_CONTROL_DATADIRECTION_MASK;
  289. if (sgdir == MPI_SCSIIO_CONTROL_WRITE) {
  290. sgdir = MPT_TRANSFER_HOST_TO_IOC;
  291. } else {
  292. sgdir = MPT_TRANSFER_IOC_TO_HOST;
  293. }
  294. psge = (char *) &pReq->SGL;
  295. frm_sz = ioc->req_sz;
  296. /* Map the data portion, if any.
  297. * sges_left = 0 if no data transfer.
  298. */
  299. if ( (sges_left = SCpnt->use_sg) ) {
  300. sges_left = pci_map_sg(ioc->pcidev,
  301. (struct scatterlist *) SCpnt->request_buffer,
  302. SCpnt->use_sg,
  303. SCpnt->sc_data_direction);
  304. if (sges_left == 0)
  305. return FAILED;
  306. } else if (SCpnt->request_bufflen) {
  307. SCpnt->SCp.dma_handle = pci_map_single(ioc->pcidev,
  308. SCpnt->request_buffer,
  309. SCpnt->request_bufflen,
  310. SCpnt->sc_data_direction);
  311. dsgprintk((MYIOC_s_INFO_FMT "SG: non-SG for %p, len=%d\n",
  312. ioc->name, SCpnt, SCpnt->request_bufflen));
  313. mptscsih_add_sge((char *) &pReq->SGL,
  314. 0xD1000000|MPT_SGE_FLAGS_ADDRESSING|sgdir|SCpnt->request_bufflen,
  315. SCpnt->SCp.dma_handle);
  316. return SUCCESS;
  317. }
  318. /* Handle the SG case.
  319. */
  320. sg = (struct scatterlist *) SCpnt->request_buffer;
  321. sg_done = 0;
  322. sgeOffset = sizeof(SCSIIORequest_t) - sizeof(SGE_IO_UNION);
  323. chainSge = NULL;
  324. /* Prior to entering this loop - the following must be set
  325. * current MF: sgeOffset (bytes)
  326. * chainSge (Null if original MF is not a chain buffer)
  327. * sg_done (num SGE done for this MF)
  328. */
  329. nextSGEset:
  330. numSgeSlots = ((frm_sz - sgeOffset) / (sizeof(u32) + sizeof(dma_addr_t)) );
  331. numSgeThisFrame = (sges_left < numSgeSlots) ? sges_left : numSgeSlots;
  332. sgflags = MPT_SGE_FLAGS_SIMPLE_ELEMENT | MPT_SGE_FLAGS_ADDRESSING | sgdir;
  333. /* Get first (num - 1) SG elements
  334. * Skip any SG entries with a length of 0
  335. * NOTE: at finish, sg and psge pointed to NEXT data/location positions
  336. */
  337. for (ii=0; ii < (numSgeThisFrame-1); ii++) {
  338. thisxfer = sg_dma_len(sg);
  339. if (thisxfer == 0) {
  340. sg ++; /* Get next SG element from the OS */
  341. sg_done++;
  342. continue;
  343. }
  344. v2 = sg_dma_address(sg);
  345. mptscsih_add_sge(psge, sgflags | thisxfer, v2);
  346. sg++; /* Get next SG element from the OS */
  347. psge += (sizeof(u32) + sizeof(dma_addr_t));
  348. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  349. sg_done++;
  350. }
  351. if (numSgeThisFrame == sges_left) {
  352. /* Add last element, end of buffer and end of list flags.
  353. */
  354. sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT |
  355. MPT_SGE_FLAGS_END_OF_BUFFER |
  356. MPT_SGE_FLAGS_END_OF_LIST;
  357. /* Add last SGE and set termination flags.
  358. * Note: Last SGE may have a length of 0 - which should be ok.
  359. */
  360. thisxfer = sg_dma_len(sg);
  361. v2 = sg_dma_address(sg);
  362. mptscsih_add_sge(psge, sgflags | thisxfer, v2);
  363. /*
  364. sg++;
  365. psge += (sizeof(u32) + sizeof(dma_addr_t));
  366. */
  367. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  368. sg_done++;
  369. if (chainSge) {
  370. /* The current buffer is a chain buffer,
  371. * but there is not another one.
  372. * Update the chain element
  373. * Offset and Length fields.
  374. */
  375. mptscsih_add_chain((char *)chainSge, 0, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
  376. } else {
  377. /* The current buffer is the original MF
  378. * and there is no Chain buffer.
  379. */
  380. pReq->ChainOffset = 0;
  381. RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
  382. dsgprintk((MYIOC_s_ERR_FMT
  383. "Single Buffer RequestNB=%x, sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
  384. ioc->RequestNB[req_idx] = RequestNB;
  385. }
  386. } else {
  387. /* At least one chain buffer is needed.
  388. * Complete the first MF
  389. * - last SGE element, set the LastElement bit
  390. * - set ChainOffset (words) for orig MF
  391. * (OR finish previous MF chain buffer)
  392. * - update MFStructPtr ChainIndex
  393. * - Populate chain element
  394. * Also
  395. * Loop until done.
  396. */
  397. dsgprintk((MYIOC_s_INFO_FMT "SG: Chain Required! sg done %d\n",
  398. ioc->name, sg_done));
  399. /* Set LAST_ELEMENT flag for last non-chain element
  400. * in the buffer. Since psge points at the NEXT
  401. * SGE element, go back one SGE element, update the flags
  402. * and reset the pointer. (Note: sgflags & thisxfer are already
  403. * set properly).
  404. */
  405. if (sg_done) {
  406. u32 *ptmp = (u32 *) (psge - (sizeof(u32) + sizeof(dma_addr_t)));
  407. sgflags = le32_to_cpu(*ptmp);
  408. sgflags |= MPT_SGE_FLAGS_LAST_ELEMENT;
  409. *ptmp = cpu_to_le32(sgflags);
  410. }
  411. if (chainSge) {
  412. /* The current buffer is a chain buffer.
  413. * chainSge points to the previous Chain Element.
  414. * Update its chain element Offset and Length (must
  415. * include chain element size) fields.
  416. * Old chain element is now complete.
  417. */
  418. u8 nextChain = (u8) (sgeOffset >> 2);
  419. sgeOffset += (sizeof(u32) + sizeof(dma_addr_t));
  420. mptscsih_add_chain((char *)chainSge, nextChain, sgeOffset, ioc->ChainBufferDMA + chain_dma_off);
  421. } else {
  422. /* The original MF buffer requires a chain buffer -
  423. * set the offset.
  424. * Last element in this MF is a chain element.
  425. */
  426. pReq->ChainOffset = (u8) (sgeOffset >> 2);
  427. RequestNB = (((sgeOffset - 1) >> ioc->NBShiftFactor) + 1) & 0x03;
  428. dsgprintk((MYIOC_s_ERR_FMT "Chain Buffer Needed, RequestNB=%x sgeOffset=%d\n", ioc->name, RequestNB, sgeOffset));
  429. ioc->RequestNB[req_idx] = RequestNB;
  430. }
  431. sges_left -= sg_done;
  432. /* NOTE: psge points to the beginning of the chain element
  433. * in current buffer. Get a chain buffer.
  434. */
  435. dsgprintk((MYIOC_s_INFO_FMT
  436. "calling getFreeChainBuffer SCSI cmd=%02x (%p)\n",
  437. ioc->name, pReq->CDB[0], SCpnt));
  438. if ((mptscsih_getFreeChainBuffer(ioc, &newIndex)) == FAILED)
  439. return FAILED;
  440. /* Update the tracking arrays.
  441. * If chainSge == NULL, update ReqToChain, else ChainToChain
  442. */
  443. if (chainSge) {
  444. ioc->ChainToChain[chain_idx] = newIndex;
  445. } else {
  446. ioc->ReqToChain[req_idx] = newIndex;
  447. }
  448. chain_idx = newIndex;
  449. chain_dma_off = ioc->req_sz * chain_idx;
  450. /* Populate the chainSGE for the current buffer.
  451. * - Set chain buffer pointer to psge and fill
  452. * out the Address and Flags fields.
  453. */
  454. chainSge = (char *) psge;
  455. dsgprintk((KERN_INFO " Current buff @ %p (index 0x%x)",
  456. psge, req_idx));
  457. /* Start the SGE for the next buffer
  458. */
  459. psge = (char *) (ioc->ChainBuffer + chain_dma_off);
  460. sgeOffset = 0;
  461. sg_done = 0;
  462. dsgprintk((KERN_INFO " Chain buff @ %p (index 0x%x)\n",
  463. psge, chain_idx));
  464. /* Start the SGE for the next buffer
  465. */
  466. goto nextSGEset;
  467. }
  468. return SUCCESS;
  469. } /* mptscsih_AddSGE() */
  470. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  471. /*
  472. * mptscsih_io_done - Main SCSI IO callback routine registered to
  473. * Fusion MPT (base) driver
  474. * @ioc: Pointer to MPT_ADAPTER structure
  475. * @mf: Pointer to original MPT request frame
  476. * @r: Pointer to MPT reply frame (NULL if TurboReply)
  477. *
  478. * This routine is called from mpt.c::mpt_interrupt() at the completion
  479. * of any SCSI IO request.
  480. * This routine is registered with the Fusion MPT (base) driver at driver
  481. * load/init time via the mpt_register() API call.
  482. *
  483. * Returns 1 indicating alloc'd request frame ptr should be freed.
  484. */
  485. int
  486. mptscsih_io_done(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  487. {
  488. struct scsi_cmnd *sc;
  489. MPT_SCSI_HOST *hd;
  490. SCSIIORequest_t *pScsiReq;
  491. SCSIIOReply_t *pScsiReply;
  492. u16 req_idx;
  493. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  494. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  495. sc = hd->ScsiLookup[req_idx];
  496. if (sc == NULL) {
  497. MPIHeader_t *hdr = (MPIHeader_t *)mf;
  498. /* Remark: writeSDP1 will use the ScsiDoneCtx
  499. * If a SCSI I/O cmd, device disabled by OS and
  500. * completion done. Cannot touch sc struct. Just free mem.
  501. */
  502. if (hdr->Function == MPI_FUNCTION_SCSI_IO_REQUEST)
  503. printk(MYIOC_s_ERR_FMT "NULL ScsiCmd ptr!\n",
  504. ioc->name);
  505. mptscsih_freeChainBuffers(ioc, req_idx);
  506. return 1;
  507. }
  508. dmfprintk((MYIOC_s_INFO_FMT
  509. "ScsiDone (mf=%p,mr=%p,sc=%p,idx=%d)\n",
  510. ioc->name, mf, mr, sc, req_idx));
  511. sc->result = DID_OK << 16; /* Set default reply as OK */
  512. pScsiReq = (SCSIIORequest_t *) mf;
  513. pScsiReply = (SCSIIOReply_t *) mr;
  514. if (pScsiReply == NULL) {
  515. /* special context reply handling */
  516. ;
  517. } else {
  518. u32 xfer_cnt;
  519. u16 status;
  520. u8 scsi_state, scsi_status;
  521. status = le16_to_cpu(pScsiReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  522. scsi_state = pScsiReply->SCSIState;
  523. scsi_status = pScsiReply->SCSIStatus;
  524. xfer_cnt = le32_to_cpu(pScsiReply->TransferCount);
  525. sc->resid = sc->request_bufflen - xfer_cnt;
  526. dreplyprintk((KERN_NOTICE "Reply ha=%d id=%d lun=%d:\n"
  527. "IOCStatus=%04xh SCSIState=%02xh SCSIStatus=%02xh\n"
  528. "resid=%d bufflen=%d xfer_cnt=%d\n",
  529. ioc->id, pScsiReq->TargetID, pScsiReq->LUN[1],
  530. status, scsi_state, scsi_status, sc->resid,
  531. sc->request_bufflen, xfer_cnt));
  532. if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID)
  533. mptscsih_copy_sense_data(sc, hd, mf, pScsiReply);
  534. /*
  535. * Look for + dump FCP ResponseInfo[]!
  536. */
  537. if (scsi_state & MPI_SCSI_STATE_RESPONSE_INFO_VALID) {
  538. printk(KERN_NOTICE " FCP_ResponseInfo=%08xh\n",
  539. le32_to_cpu(pScsiReply->ResponseInfo));
  540. }
  541. switch(status) {
  542. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  543. /* CHECKME!
  544. * Maybe: DRIVER_BUSY | SUGGEST_RETRY | DID_SOFT_ERROR (retry)
  545. * But not: DID_BUS_BUSY lest one risk
  546. * killing interrupt handler:-(
  547. */
  548. sc->result = SAM_STAT_BUSY;
  549. break;
  550. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  551. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  552. sc->result = DID_BAD_TARGET << 16;
  553. break;
  554. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  555. /* Spoof to SCSI Selection Timeout! */
  556. sc->result = DID_NO_CONNECT << 16;
  557. if (hd->sel_timeout[pScsiReq->TargetID] < 0xFFFF)
  558. hd->sel_timeout[pScsiReq->TargetID]++;
  559. break;
  560. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  561. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  562. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  563. /* Linux handles an unsolicited DID_RESET better
  564. * than an unsolicited DID_ABORT.
  565. */
  566. sc->result = DID_RESET << 16;
  567. /* GEM Workaround. */
  568. if (ioc->bus_type == SCSI)
  569. mptscsih_no_negotiate(hd, sc->device->id);
  570. break;
  571. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  572. if ( xfer_cnt >= sc->underflow ) {
  573. /* Sufficient data transfer occurred */
  574. sc->result = (DID_OK << 16) | scsi_status;
  575. } else if ( xfer_cnt == 0 ) {
  576. /* A CRC Error causes this condition; retry */
  577. sc->result = (DRIVER_SENSE << 24) | (DID_OK << 16) |
  578. (CHECK_CONDITION << 1);
  579. sc->sense_buffer[0] = 0x70;
  580. sc->sense_buffer[2] = NO_SENSE;
  581. sc->sense_buffer[12] = 0;
  582. sc->sense_buffer[13] = 0;
  583. } else {
  584. sc->result = DID_SOFT_ERROR << 16;
  585. }
  586. dreplyprintk((KERN_NOTICE "RESIDUAL_MISMATCH: result=%x on id=%d\n", sc->result, sc->target));
  587. break;
  588. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  589. /*
  590. * Do upfront check for valid SenseData and give it
  591. * precedence!
  592. */
  593. sc->result = (DID_OK << 16) | scsi_status;
  594. if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  595. /* Have already saved the status and sense data
  596. */
  597. ;
  598. } else {
  599. if (xfer_cnt < sc->underflow) {
  600. sc->result = DID_SOFT_ERROR << 16;
  601. }
  602. if (scsi_state & (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)) {
  603. /* What to do?
  604. */
  605. sc->result = DID_SOFT_ERROR << 16;
  606. }
  607. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  608. /* Not real sure here either... */
  609. sc->result = DID_RESET << 16;
  610. }
  611. }
  612. dreplyprintk((KERN_NOTICE " sc->underflow={report ERR if < %02xh bytes xfer'd}\n",
  613. sc->underflow));
  614. dreplyprintk((KERN_NOTICE " ActBytesXferd=%02xh\n", xfer_cnt));
  615. /* Report Queue Full
  616. */
  617. if (scsi_status == MPI_SCSI_STATUS_TASK_SET_FULL)
  618. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  619. break;
  620. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  621. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  622. scsi_status = pScsiReply->SCSIStatus;
  623. sc->result = (DID_OK << 16) | scsi_status;
  624. if (scsi_state == 0) {
  625. ;
  626. } else if (scsi_state & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  627. /*
  628. * If running against circa 200003dd 909 MPT f/w,
  629. * may get this (AUTOSENSE_VALID) for actual TASK_SET_FULL
  630. * (QUEUE_FULL) returned from device! --> get 0x0000?128
  631. * and with SenseBytes set to 0.
  632. */
  633. if (pScsiReply->SCSIStatus == MPI_SCSI_STATUS_TASK_SET_FULL)
  634. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  635. }
  636. else if (scsi_state &
  637. (MPI_SCSI_STATE_AUTOSENSE_FAILED | MPI_SCSI_STATE_NO_SCSI_STATUS)
  638. ) {
  639. /*
  640. * What to do?
  641. */
  642. sc->result = DID_SOFT_ERROR << 16;
  643. }
  644. else if (scsi_state & MPI_SCSI_STATE_TERMINATED) {
  645. /* Not real sure here either... */
  646. sc->result = DID_RESET << 16;
  647. }
  648. else if (scsi_state & MPI_SCSI_STATE_QUEUE_TAG_REJECTED) {
  649. /* Device Inq. data indicates that it supports
  650. * QTags, but rejects QTag messages.
  651. * This command completed OK.
  652. *
  653. * Not real sure here either so do nothing... */
  654. }
  655. if (sc->result == MPI_SCSI_STATUS_TASK_SET_FULL)
  656. mptscsih_report_queue_full(sc, pScsiReply, pScsiReq);
  657. /* Add handling of:
  658. * Reservation Conflict, Busy,
  659. * Command Terminated, CHECK
  660. */
  661. break;
  662. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  663. sc->result = DID_SOFT_ERROR << 16;
  664. break;
  665. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  666. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  667. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  668. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  669. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  670. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  671. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  672. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  673. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  674. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  675. default:
  676. /*
  677. * What to do?
  678. */
  679. sc->result = DID_SOFT_ERROR << 16;
  680. break;
  681. } /* switch(status) */
  682. dreplyprintk((KERN_NOTICE " sc->result is %08xh\n", sc->result));
  683. } /* end of address reply case */
  684. /* Unmap the DMA buffers, if any. */
  685. if (sc->use_sg) {
  686. pci_unmap_sg(ioc->pcidev, (struct scatterlist *) sc->request_buffer,
  687. sc->use_sg, sc->sc_data_direction);
  688. } else if (sc->request_bufflen) {
  689. pci_unmap_single(ioc->pcidev, sc->SCp.dma_handle,
  690. sc->request_bufflen, sc->sc_data_direction);
  691. }
  692. hd->ScsiLookup[req_idx] = NULL;
  693. sc->scsi_done(sc); /* Issue the command callback */
  694. /* Free Chain buffers */
  695. mptscsih_freeChainBuffers(ioc, req_idx);
  696. return 1;
  697. }
  698. /*
  699. * mptscsih_flush_running_cmds - For each command found, search
  700. * Scsi_Host instance taskQ and reply to OS.
  701. * Called only if recovering from a FW reload.
  702. * @hd: Pointer to a SCSI HOST structure
  703. *
  704. * Returns: None.
  705. *
  706. * Must be called while new I/Os are being queued.
  707. */
  708. static void
  709. mptscsih_flush_running_cmds(MPT_SCSI_HOST *hd)
  710. {
  711. MPT_ADAPTER *ioc = hd->ioc;
  712. struct scsi_cmnd *SCpnt;
  713. MPT_FRAME_HDR *mf;
  714. int ii;
  715. int max = ioc->req_depth;
  716. dprintk((KERN_INFO MYNAM ": flush_ScsiLookup called\n"));
  717. for (ii= 0; ii < max; ii++) {
  718. if ((SCpnt = hd->ScsiLookup[ii]) != NULL) {
  719. /* Command found.
  720. */
  721. /* Null ScsiLookup index
  722. */
  723. hd->ScsiLookup[ii] = NULL;
  724. mf = MPT_INDEX_2_MFPTR(ioc, ii);
  725. dmfprintk(( "flush: ScsiDone (mf=%p,sc=%p)\n",
  726. mf, SCpnt));
  727. /* Set status, free OS resources (SG DMA buffers)
  728. * Do OS callback
  729. * Free driver resources (chain, msg buffers)
  730. */
  731. if (SCpnt->use_sg) {
  732. pci_unmap_sg(ioc->pcidev,
  733. (struct scatterlist *) SCpnt->request_buffer,
  734. SCpnt->use_sg,
  735. SCpnt->sc_data_direction);
  736. } else if (SCpnt->request_bufflen) {
  737. pci_unmap_single(ioc->pcidev,
  738. SCpnt->SCp.dma_handle,
  739. SCpnt->request_bufflen,
  740. SCpnt->sc_data_direction);
  741. }
  742. SCpnt->result = DID_RESET << 16;
  743. SCpnt->host_scribble = NULL;
  744. /* Free Chain buffers */
  745. mptscsih_freeChainBuffers(ioc, ii);
  746. /* Free Message frames */
  747. mpt_free_msg_frame(ioc, mf);
  748. SCpnt->scsi_done(SCpnt); /* Issue the command callback */
  749. }
  750. }
  751. return;
  752. }
  753. /*
  754. * mptscsih_search_running_cmds - Delete any commands associated
  755. * with the specified target and lun. Function called only
  756. * when a lun is disable by mid-layer.
  757. * Do NOT access the referenced scsi_cmnd structure or
  758. * members. Will cause either a paging or NULL ptr error.
  759. * @hd: Pointer to a SCSI HOST structure
  760. * @target: target id
  761. * @lun: lun
  762. *
  763. * Returns: None.
  764. *
  765. * Called from slave_destroy.
  766. */
  767. static void
  768. mptscsih_search_running_cmds(MPT_SCSI_HOST *hd, uint target, uint lun)
  769. {
  770. SCSIIORequest_t *mf = NULL;
  771. int ii;
  772. int max = hd->ioc->req_depth;
  773. dsprintk((KERN_INFO MYNAM ": search_running target %d lun %d max %d\n",
  774. target, lun, max));
  775. for (ii=0; ii < max; ii++) {
  776. if (hd->ScsiLookup[ii] != NULL) {
  777. mf = (SCSIIORequest_t *)MPT_INDEX_2_MFPTR(hd->ioc, ii);
  778. dsprintk(( "search_running: found (sc=%p, mf = %p) target %d, lun %d \n",
  779. hd->ScsiLookup[ii], mf, mf->TargetID, mf->LUN[1]));
  780. if ((mf->TargetID != ((u8)target)) || (mf->LUN[1] != ((u8) lun)))
  781. continue;
  782. /* Cleanup
  783. */
  784. hd->ScsiLookup[ii] = NULL;
  785. mptscsih_freeChainBuffers(hd->ioc, ii);
  786. mpt_free_msg_frame(hd->ioc, (MPT_FRAME_HDR *)mf);
  787. }
  788. }
  789. return;
  790. }
  791. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  792. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  793. /*
  794. * mptscsih_report_queue_full - Report QUEUE_FULL status returned
  795. * from a SCSI target device.
  796. * @sc: Pointer to scsi_cmnd structure
  797. * @pScsiReply: Pointer to SCSIIOReply_t
  798. * @pScsiReq: Pointer to original SCSI request
  799. *
  800. * This routine periodically reports QUEUE_FULL status returned from a
  801. * SCSI target device. It reports this to the console via kernel
  802. * printk() API call, not more than once every 10 seconds.
  803. */
  804. static void
  805. mptscsih_report_queue_full(struct scsi_cmnd *sc, SCSIIOReply_t *pScsiReply, SCSIIORequest_t *pScsiReq)
  806. {
  807. long time = jiffies;
  808. MPT_SCSI_HOST *hd;
  809. if (sc->device == NULL)
  810. return;
  811. if (sc->device->host == NULL)
  812. return;
  813. if ((hd = (MPT_SCSI_HOST *)sc->device->host->hostdata) == NULL)
  814. return;
  815. if (time - hd->last_queue_full > 10 * HZ) {
  816. dprintk((MYIOC_s_WARN_FMT "Device (%d:%d:%d) reported QUEUE_FULL!\n",
  817. hd->ioc->name, 0, sc->device->id, sc->device->lun));
  818. hd->last_queue_full = time;
  819. }
  820. }
  821. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  822. /*
  823. * mptscsih_remove - Removed scsi devices
  824. * @pdev: Pointer to pci_dev structure
  825. *
  826. *
  827. */
  828. void
  829. mptscsih_remove(struct pci_dev *pdev)
  830. {
  831. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  832. struct Scsi_Host *host = ioc->sh;
  833. MPT_SCSI_HOST *hd;
  834. int count;
  835. unsigned long flags;
  836. int sz1;
  837. if(!host)
  838. return;
  839. scsi_remove_host(host);
  840. if((hd = (MPT_SCSI_HOST *)host->hostdata) == NULL)
  841. return;
  842. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  843. /* Check DV thread active */
  844. count = 10 * HZ;
  845. spin_lock_irqsave(&dvtaskQ_lock, flags);
  846. if (dvtaskQ_active) {
  847. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  848. while(dvtaskQ_active && --count) {
  849. set_current_state(TASK_INTERRUPTIBLE);
  850. schedule_timeout(1);
  851. }
  852. } else {
  853. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  854. }
  855. if (!count)
  856. printk(KERN_ERR MYNAM ": ERROR - DV thread still active!\n");
  857. #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
  858. else
  859. printk(KERN_ERR MYNAM ": DV thread orig %d, count %d\n", 10 * HZ, count);
  860. #endif
  861. #endif
  862. mptscsih_shutdown(pdev);
  863. sz1=0;
  864. if (hd->ScsiLookup != NULL) {
  865. sz1 = hd->ioc->req_depth * sizeof(void *);
  866. kfree(hd->ScsiLookup);
  867. hd->ScsiLookup = NULL;
  868. }
  869. /*
  870. * Free pointer array.
  871. */
  872. kfree(hd->Targets);
  873. hd->Targets = NULL;
  874. dprintk((MYIOC_s_INFO_FMT
  875. "Free'd ScsiLookup (%d) memory\n",
  876. hd->ioc->name, sz1));
  877. kfree(hd->info_kbuf);
  878. /* NULL the Scsi_Host pointer
  879. */
  880. hd->ioc->sh = NULL;
  881. scsi_host_put(host);
  882. mpt_detach(pdev);
  883. }
  884. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  885. /*
  886. * mptscsih_shutdown - reboot notifier
  887. *
  888. */
  889. void
  890. mptscsih_shutdown(struct pci_dev *pdev)
  891. {
  892. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  893. struct Scsi_Host *host = ioc->sh;
  894. MPT_SCSI_HOST *hd;
  895. if(!host)
  896. return;
  897. hd = (MPT_SCSI_HOST *)host->hostdata;
  898. /* Flush the cache of this adapter
  899. */
  900. if(hd != NULL)
  901. mptscsih_synchronize_cache(hd, 0);
  902. }
  903. #ifdef CONFIG_PM
  904. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  905. /*
  906. * mptscsih_suspend - Fusion MPT scsi driver suspend routine.
  907. *
  908. *
  909. */
  910. int
  911. mptscsih_suspend(struct pci_dev *pdev, pm_message_t state)
  912. {
  913. mptscsih_shutdown(pdev);
  914. return mpt_suspend(pdev,state);
  915. }
  916. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  917. /*
  918. * mptscsih_resume - Fusion MPT scsi driver resume routine.
  919. *
  920. *
  921. */
  922. int
  923. mptscsih_resume(struct pci_dev *pdev)
  924. {
  925. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  926. struct Scsi_Host *host = ioc->sh;
  927. MPT_SCSI_HOST *hd;
  928. mpt_resume(pdev);
  929. if(!host)
  930. return 0;
  931. hd = (MPT_SCSI_HOST *)host->hostdata;
  932. if(!hd)
  933. return 0;
  934. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  935. {
  936. unsigned long lflags;
  937. spin_lock_irqsave(&dvtaskQ_lock, lflags);
  938. if (!dvtaskQ_active) {
  939. dvtaskQ_active = 1;
  940. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  941. INIT_WORK(&dvTaskQ_task,
  942. mptscsih_domainValidation, (void *) hd);
  943. schedule_work(&dvTaskQ_task);
  944. } else {
  945. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  946. }
  947. }
  948. #endif
  949. return 0;
  950. }
  951. #endif
  952. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  953. /**
  954. * mptscsih_info - Return information about MPT adapter
  955. * @SChost: Pointer to Scsi_Host structure
  956. *
  957. * (linux scsi_host_template.info routine)
  958. *
  959. * Returns pointer to buffer where information was written.
  960. */
  961. const char *
  962. mptscsih_info(struct Scsi_Host *SChost)
  963. {
  964. MPT_SCSI_HOST *h;
  965. int size = 0;
  966. h = (MPT_SCSI_HOST *)SChost->hostdata;
  967. if (h) {
  968. if (h->info_kbuf == NULL)
  969. if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
  970. return h->info_kbuf;
  971. h->info_kbuf[0] = '\0';
  972. mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
  973. h->info_kbuf[size-1] = '\0';
  974. }
  975. return h->info_kbuf;
  976. }
  977. struct info_str {
  978. char *buffer;
  979. int length;
  980. int offset;
  981. int pos;
  982. };
  983. static void
  984. mptscsih_copy_mem_info(struct info_str *info, char *data, int len)
  985. {
  986. if (info->pos + len > info->length)
  987. len = info->length - info->pos;
  988. if (info->pos + len < info->offset) {
  989. info->pos += len;
  990. return;
  991. }
  992. if (info->pos < info->offset) {
  993. data += (info->offset - info->pos);
  994. len -= (info->offset - info->pos);
  995. }
  996. if (len > 0) {
  997. memcpy(info->buffer + info->pos, data, len);
  998. info->pos += len;
  999. }
  1000. }
  1001. static int
  1002. mptscsih_copy_info(struct info_str *info, char *fmt, ...)
  1003. {
  1004. va_list args;
  1005. char buf[81];
  1006. int len;
  1007. va_start(args, fmt);
  1008. len = vsprintf(buf, fmt, args);
  1009. va_end(args);
  1010. mptscsih_copy_mem_info(info, buf, len);
  1011. return len;
  1012. }
  1013. static int
  1014. mptscsih_host_info(MPT_ADAPTER *ioc, char *pbuf, off_t offset, int len)
  1015. {
  1016. struct info_str info;
  1017. info.buffer = pbuf;
  1018. info.length = len;
  1019. info.offset = offset;
  1020. info.pos = 0;
  1021. mptscsih_copy_info(&info, "%s: %s, ", ioc->name, ioc->prod_name);
  1022. mptscsih_copy_info(&info, "%s%08xh, ", MPT_FW_REV_MAGIC_ID_STRING, ioc->facts.FWVersion.Word);
  1023. mptscsih_copy_info(&info, "Ports=%d, ", ioc->facts.NumberOfPorts);
  1024. mptscsih_copy_info(&info, "MaxQ=%d\n", ioc->req_depth);
  1025. return ((info.pos > info.offset) ? info.pos - info.offset : 0);
  1026. }
  1027. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1028. /**
  1029. * mptscsih_proc_info - Return information about MPT adapter
  1030. *
  1031. * (linux scsi_host_template.info routine)
  1032. *
  1033. * buffer: if write, user data; if read, buffer for user
  1034. * length: if write, return length;
  1035. * offset: if write, 0; if read, the current offset into the buffer from
  1036. * the previous read.
  1037. * hostno: scsi host number
  1038. * func: if write = 1; if read = 0
  1039. */
  1040. int
  1041. mptscsih_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
  1042. int length, int func)
  1043. {
  1044. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1045. MPT_ADAPTER *ioc = hd->ioc;
  1046. int size = 0;
  1047. if (func) {
  1048. /*
  1049. * write is not supported
  1050. */
  1051. } else {
  1052. if (start)
  1053. *start = buffer;
  1054. size = mptscsih_host_info(ioc, buffer, offset, length);
  1055. }
  1056. return size;
  1057. }
  1058. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1059. #define ADD_INDEX_LOG(req_ent) do { } while(0)
  1060. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1061. /**
  1062. * mptscsih_qcmd - Primary Fusion MPT SCSI initiator IO start routine.
  1063. * @SCpnt: Pointer to scsi_cmnd structure
  1064. * @done: Pointer SCSI mid-layer IO completion function
  1065. *
  1066. * (linux scsi_host_template.queuecommand routine)
  1067. * This is the primary SCSI IO start routine. Create a MPI SCSIIORequest
  1068. * from a linux scsi_cmnd request and send it to the IOC.
  1069. *
  1070. * Returns 0. (rtn value discarded by linux scsi mid-layer)
  1071. */
  1072. int
  1073. mptscsih_qcmd(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
  1074. {
  1075. MPT_SCSI_HOST *hd;
  1076. MPT_FRAME_HDR *mf;
  1077. SCSIIORequest_t *pScsiReq;
  1078. VirtDevice *pTarget;
  1079. int target;
  1080. int lun;
  1081. u32 datalen;
  1082. u32 scsictl;
  1083. u32 scsidir;
  1084. u32 cmd_len;
  1085. int my_idx;
  1086. int ii;
  1087. hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata;
  1088. target = SCpnt->device->id;
  1089. lun = SCpnt->device->lun;
  1090. SCpnt->scsi_done = done;
  1091. pTarget = hd->Targets[target];
  1092. dmfprintk((MYIOC_s_INFO_FMT "qcmd: SCpnt=%p, done()=%p\n",
  1093. (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt, done));
  1094. if (hd->resetPending) {
  1095. dtmprintk((MYIOC_s_WARN_FMT "qcmd: SCpnt=%p timeout + 60HZ\n",
  1096. (hd && hd->ioc) ? hd->ioc->name : "ioc?", SCpnt));
  1097. return SCSI_MLQUEUE_HOST_BUSY;
  1098. }
  1099. /*
  1100. * Put together a MPT SCSI request...
  1101. */
  1102. if ((mf = mpt_get_msg_frame(hd->ioc->DoneCtx, hd->ioc)) == NULL) {
  1103. dprintk((MYIOC_s_WARN_FMT "QueueCmd, no msg frames!!\n",
  1104. hd->ioc->name));
  1105. return SCSI_MLQUEUE_HOST_BUSY;
  1106. }
  1107. pScsiReq = (SCSIIORequest_t *) mf;
  1108. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  1109. ADD_INDEX_LOG(my_idx);
  1110. /* TUR's being issued with scsictl=0x02000000 (DATA_IN)!
  1111. * Seems we may receive a buffer (datalen>0) even when there
  1112. * will be no data transfer! GRRRRR...
  1113. */
  1114. if (SCpnt->sc_data_direction == DMA_FROM_DEVICE) {
  1115. datalen = SCpnt->request_bufflen;
  1116. scsidir = MPI_SCSIIO_CONTROL_READ; /* DATA IN (host<--ioc<--dev) */
  1117. } else if (SCpnt->sc_data_direction == DMA_TO_DEVICE) {
  1118. datalen = SCpnt->request_bufflen;
  1119. scsidir = MPI_SCSIIO_CONTROL_WRITE; /* DATA OUT (host-->ioc-->dev) */
  1120. } else {
  1121. datalen = 0;
  1122. scsidir = MPI_SCSIIO_CONTROL_NODATATRANSFER;
  1123. }
  1124. /* Default to untagged. Once a target structure has been allocated,
  1125. * use the Inquiry data to determine if device supports tagged.
  1126. */
  1127. if ( pTarget
  1128. && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)
  1129. && (SCpnt->device->tagged_supported)) {
  1130. scsictl = scsidir | MPI_SCSIIO_CONTROL_SIMPLEQ;
  1131. } else {
  1132. scsictl = scsidir | MPI_SCSIIO_CONTROL_UNTAGGED;
  1133. }
  1134. /* Use the above information to set up the message frame
  1135. */
  1136. pScsiReq->TargetID = (u8) target;
  1137. pScsiReq->Bus = (u8) SCpnt->device->channel;
  1138. pScsiReq->ChainOffset = 0;
  1139. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  1140. pScsiReq->CDBLength = SCpnt->cmd_len;
  1141. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  1142. pScsiReq->Reserved = 0;
  1143. pScsiReq->MsgFlags = mpt_msg_flags();
  1144. pScsiReq->LUN[0] = 0;
  1145. pScsiReq->LUN[1] = lun;
  1146. pScsiReq->LUN[2] = 0;
  1147. pScsiReq->LUN[3] = 0;
  1148. pScsiReq->LUN[4] = 0;
  1149. pScsiReq->LUN[5] = 0;
  1150. pScsiReq->LUN[6] = 0;
  1151. pScsiReq->LUN[7] = 0;
  1152. pScsiReq->Control = cpu_to_le32(scsictl);
  1153. /*
  1154. * Write SCSI CDB into the message
  1155. */
  1156. cmd_len = SCpnt->cmd_len;
  1157. for (ii=0; ii < cmd_len; ii++)
  1158. pScsiReq->CDB[ii] = SCpnt->cmnd[ii];
  1159. for (ii=cmd_len; ii < 16; ii++)
  1160. pScsiReq->CDB[ii] = 0;
  1161. /* DataLength */
  1162. pScsiReq->DataLength = cpu_to_le32(datalen);
  1163. /* SenseBuffer low address */
  1164. pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
  1165. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  1166. /* Now add the SG list
  1167. * Always have a SGE even if null length.
  1168. */
  1169. if (datalen == 0) {
  1170. /* Add a NULL SGE */
  1171. mptscsih_add_sge((char *)&pScsiReq->SGL, MPT_SGE_FLAGS_SSIMPLE_READ | 0,
  1172. (dma_addr_t) -1);
  1173. } else {
  1174. /* Add a 32 or 64 bit SGE */
  1175. if (mptscsih_AddSGE(hd->ioc, SCpnt, pScsiReq, my_idx) != SUCCESS)
  1176. goto fail;
  1177. }
  1178. hd->ScsiLookup[my_idx] = SCpnt;
  1179. SCpnt->host_scribble = NULL;
  1180. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  1181. if (hd->ioc->bus_type == SCSI) {
  1182. int dvStatus = hd->ioc->spi_data.dvStatus[target];
  1183. int issueCmd = 1;
  1184. if (dvStatus || hd->ioc->spi_data.forceDv) {
  1185. if ((dvStatus & MPT_SCSICFG_NEED_DV) ||
  1186. (hd->ioc->spi_data.forceDv & MPT_SCSICFG_NEED_DV)) {
  1187. unsigned long lflags;
  1188. /* Schedule DV if necessary */
  1189. spin_lock_irqsave(&dvtaskQ_lock, lflags);
  1190. if (!dvtaskQ_active) {
  1191. dvtaskQ_active = 1;
  1192. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  1193. INIT_WORK(&dvTaskQ_task, mptscsih_domainValidation, (void *) hd);
  1194. schedule_work(&dvTaskQ_task);
  1195. } else {
  1196. spin_unlock_irqrestore(&dvtaskQ_lock, lflags);
  1197. }
  1198. hd->ioc->spi_data.forceDv &= ~MPT_SCSICFG_NEED_DV;
  1199. }
  1200. /* Trying to do DV to this target, extend timeout.
  1201. * Wait to issue until flag is clear
  1202. */
  1203. if (dvStatus & MPT_SCSICFG_DV_PENDING) {
  1204. mod_timer(&SCpnt->eh_timeout, jiffies + 40 * HZ);
  1205. issueCmd = 0;
  1206. }
  1207. /* Set the DV flags.
  1208. */
  1209. if (dvStatus & MPT_SCSICFG_DV_NOT_DONE)
  1210. mptscsih_set_dvflags(hd, pScsiReq);
  1211. if (!issueCmd)
  1212. goto fail;
  1213. }
  1214. }
  1215. #endif
  1216. mpt_put_msg_frame(hd->ioc->DoneCtx, hd->ioc, mf);
  1217. dmfprintk((MYIOC_s_INFO_FMT "Issued SCSI cmd (%p) mf=%p idx=%d\n",
  1218. hd->ioc->name, SCpnt, mf, my_idx));
  1219. DBG_DUMP_REQUEST_FRAME(mf)
  1220. return 0;
  1221. fail:
  1222. mptscsih_freeChainBuffers(hd->ioc, my_idx);
  1223. mpt_free_msg_frame(hd->ioc, mf);
  1224. return SCSI_MLQUEUE_HOST_BUSY;
  1225. }
  1226. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1227. /*
  1228. * mptscsih_freeChainBuffers - Function to free chain buffers associated
  1229. * with a SCSI IO request
  1230. * @hd: Pointer to the MPT_SCSI_HOST instance
  1231. * @req_idx: Index of the SCSI IO request frame.
  1232. *
  1233. * Called if SG chain buffer allocation fails and mptscsih callbacks.
  1234. * No return.
  1235. */
  1236. static void
  1237. mptscsih_freeChainBuffers(MPT_ADAPTER *ioc, int req_idx)
  1238. {
  1239. MPT_FRAME_HDR *chain;
  1240. unsigned long flags;
  1241. int chain_idx;
  1242. int next;
  1243. /* Get the first chain index and reset
  1244. * tracker state.
  1245. */
  1246. chain_idx = ioc->ReqToChain[req_idx];
  1247. ioc->ReqToChain[req_idx] = MPT_HOST_NO_CHAIN;
  1248. while (chain_idx != MPT_HOST_NO_CHAIN) {
  1249. /* Save the next chain buffer index */
  1250. next = ioc->ChainToChain[chain_idx];
  1251. /* Free this chain buffer and reset
  1252. * tracker
  1253. */
  1254. ioc->ChainToChain[chain_idx] = MPT_HOST_NO_CHAIN;
  1255. chain = (MPT_FRAME_HDR *) (ioc->ChainBuffer
  1256. + (chain_idx * ioc->req_sz));
  1257. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1258. list_add_tail(&chain->u.frame.linkage.list, &ioc->FreeChainQ);
  1259. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1260. dmfprintk((MYIOC_s_INFO_FMT "FreeChainBuffers (index %d)\n",
  1261. ioc->name, chain_idx));
  1262. /* handle next */
  1263. chain_idx = next;
  1264. }
  1265. return;
  1266. }
  1267. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1268. /*
  1269. * Reset Handling
  1270. */
  1271. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1272. /*
  1273. * mptscsih_TMHandler - Generic handler for SCSI Task Management.
  1274. * Fall through to mpt_HardResetHandler if: not operational, too many
  1275. * failed TM requests or handshake failure.
  1276. *
  1277. * @ioc: Pointer to MPT_ADAPTER structure
  1278. * @type: Task Management type
  1279. * @target: Logical Target ID for reset (if appropriate)
  1280. * @lun: Logical Unit for reset (if appropriate)
  1281. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1282. *
  1283. * Remark: Currently invoked from a non-interrupt thread (_bh).
  1284. *
  1285. * Remark: With old EH code, at most 1 SCSI TaskMgmt function per IOC
  1286. * will be active.
  1287. *
  1288. * Returns 0 for SUCCESS or -1 if FAILED.
  1289. */
  1290. static int
  1291. mptscsih_TMHandler(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout)
  1292. {
  1293. MPT_ADAPTER *ioc;
  1294. int rc = -1;
  1295. int doTask = 1;
  1296. u32 ioc_raw_state;
  1297. unsigned long flags;
  1298. /* If FW is being reloaded currently, return success to
  1299. * the calling function.
  1300. */
  1301. if (hd == NULL)
  1302. return 0;
  1303. ioc = hd->ioc;
  1304. if (ioc == NULL) {
  1305. printk(KERN_ERR MYNAM " TMHandler" " NULL ioc!\n");
  1306. return FAILED;
  1307. }
  1308. dtmprintk((MYIOC_s_INFO_FMT "TMHandler Entered!\n", ioc->name));
  1309. // SJR - CHECKME - Can we avoid this here?
  1310. // (mpt_HardResetHandler has this check...)
  1311. spin_lock_irqsave(&ioc->diagLock, flags);
  1312. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)) {
  1313. spin_unlock_irqrestore(&ioc->diagLock, flags);
  1314. return FAILED;
  1315. }
  1316. spin_unlock_irqrestore(&ioc->diagLock, flags);
  1317. /* Wait a fixed amount of time for the TM pending flag to be cleared.
  1318. * If we time out and not bus reset, then we return a FAILED status to the caller.
  1319. * The call to mptscsih_tm_pending_wait() will set the pending flag if we are
  1320. * successful. Otherwise, reload the FW.
  1321. */
  1322. if (mptscsih_tm_pending_wait(hd) == FAILED) {
  1323. if (type == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK) {
  1324. dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler abort: "
  1325. "Timed out waiting for last TM (%d) to complete! \n",
  1326. hd->ioc->name, hd->tmPending));
  1327. return FAILED;
  1328. } else if (type == MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET) {
  1329. dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler target reset: "
  1330. "Timed out waiting for last TM (%d) to complete! \n",
  1331. hd->ioc->name, hd->tmPending));
  1332. return FAILED;
  1333. } else if (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
  1334. dtmprintk((KERN_WARNING MYNAM ": %s: TMHandler bus reset: "
  1335. "Timed out waiting for last TM (%d) to complete! \n",
  1336. hd->ioc->name, hd->tmPending));
  1337. if (hd->tmPending & (1 << MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS))
  1338. return FAILED;
  1339. doTask = 0;
  1340. }
  1341. } else {
  1342. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1343. hd->tmPending |= (1 << type);
  1344. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1345. }
  1346. /* Is operational?
  1347. */
  1348. ioc_raw_state = mpt_GetIocState(hd->ioc, 0);
  1349. #ifdef MPT_DEBUG_RESET
  1350. if ((ioc_raw_state & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL) {
  1351. printk(MYIOC_s_WARN_FMT
  1352. "TM Handler: IOC Not operational(0x%x)!\n",
  1353. hd->ioc->name, ioc_raw_state);
  1354. }
  1355. #endif
  1356. if (doTask && ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL)
  1357. && !(ioc_raw_state & MPI_DOORBELL_ACTIVE)) {
  1358. /* Isse the Task Mgmt request.
  1359. */
  1360. if (hd->hard_resets < -1)
  1361. hd->hard_resets++;
  1362. rc = mptscsih_IssueTaskMgmt(hd, type, channel, target, lun, ctx2abort, timeout);
  1363. if (rc) {
  1364. printk(MYIOC_s_INFO_FMT "Issue of TaskMgmt failed!\n", hd->ioc->name);
  1365. } else {
  1366. dtmprintk((MYIOC_s_INFO_FMT "Issue of TaskMgmt Successful!\n", hd->ioc->name));
  1367. }
  1368. }
  1369. /* Only fall through to the HRH if this is a bus reset
  1370. */
  1371. if ((type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) && (rc ||
  1372. ioc->reload_fw || (ioc->alt_ioc && ioc->alt_ioc->reload_fw))) {
  1373. dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
  1374. hd->ioc->name));
  1375. rc = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
  1376. }
  1377. dtmprintk((MYIOC_s_INFO_FMT "TMHandler rc = %d!\n", hd->ioc->name, rc));
  1378. return rc;
  1379. }
  1380. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1381. /*
  1382. * mptscsih_IssueTaskMgmt - Generic send Task Management function.
  1383. * @hd: Pointer to MPT_SCSI_HOST structure
  1384. * @type: Task Management type
  1385. * @target: Logical Target ID for reset (if appropriate)
  1386. * @lun: Logical Unit for reset (if appropriate)
  1387. * @ctx2abort: Context for the task to be aborted (if appropriate)
  1388. *
  1389. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  1390. * or a non-interrupt thread. In the former, must not call schedule().
  1391. *
  1392. * Not all fields are meaningfull for all task types.
  1393. *
  1394. * Returns 0 for SUCCESS, -999 for "no msg frames",
  1395. * else other non-zero value returned.
  1396. */
  1397. static int
  1398. mptscsih_IssueTaskMgmt(MPT_SCSI_HOST *hd, u8 type, u8 channel, u8 target, u8 lun, int ctx2abort, ulong timeout)
  1399. {
  1400. MPT_FRAME_HDR *mf;
  1401. SCSITaskMgmt_t *pScsiTm;
  1402. int ii;
  1403. int retval;
  1404. /* Return Fail to calling function if no message frames available.
  1405. */
  1406. if ((mf = mpt_get_msg_frame(hd->ioc->TaskCtx, hd->ioc)) == NULL) {
  1407. dfailprintk((MYIOC_s_ERR_FMT "IssueTaskMgmt, no msg frames!!\n",
  1408. hd->ioc->name));
  1409. //return FAILED;
  1410. return -999;
  1411. }
  1412. dtmprintk((MYIOC_s_INFO_FMT "IssueTaskMgmt request @ %p\n",
  1413. hd->ioc->name, mf));
  1414. /* Format the Request
  1415. */
  1416. pScsiTm = (SCSITaskMgmt_t *) mf;
  1417. pScsiTm->TargetID = target;
  1418. pScsiTm->Bus = channel;
  1419. pScsiTm->ChainOffset = 0;
  1420. pScsiTm->Function = MPI_FUNCTION_SCSI_TASK_MGMT;
  1421. pScsiTm->Reserved = 0;
  1422. pScsiTm->TaskType = type;
  1423. pScsiTm->Reserved1 = 0;
  1424. pScsiTm->MsgFlags = (type == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS)
  1425. ? MPI_SCSITASKMGMT_MSGFLAGS_LIPRESET_RESET_OPTION : 0;
  1426. for (ii= 0; ii < 8; ii++) {
  1427. pScsiTm->LUN[ii] = 0;
  1428. }
  1429. pScsiTm->LUN[1] = lun;
  1430. for (ii=0; ii < 7; ii++)
  1431. pScsiTm->Reserved2[ii] = 0;
  1432. pScsiTm->TaskMsgContext = ctx2abort;
  1433. dtmprintk((MYIOC_s_INFO_FMT
  1434. "IssueTaskMgmt: ctx2abort (0x%08x) type=%d\n",
  1435. hd->ioc->name, ctx2abort, type));
  1436. DBG_DUMP_TM_REQUEST_FRAME((u32 *)pScsiTm);
  1437. if ((retval = mpt_send_handshake_request(hd->ioc->TaskCtx, hd->ioc,
  1438. sizeof(SCSITaskMgmt_t), (u32*)pScsiTm,
  1439. CAN_SLEEP)) != 0) {
  1440. dfailprintk((MYIOC_s_ERR_FMT "_send_handshake FAILED!"
  1441. " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
  1442. hd->ioc, mf));
  1443. mpt_free_msg_frame(hd->ioc, mf);
  1444. return retval;
  1445. }
  1446. if(mptscsih_tm_wait_for_completion(hd, timeout) == FAILED) {
  1447. dfailprintk((MYIOC_s_ERR_FMT "_wait_for_completion FAILED!"
  1448. " (hd %p, ioc %p, mf %p) \n", hd->ioc->name, hd,
  1449. hd->ioc, mf));
  1450. mpt_free_msg_frame(hd->ioc, mf);
  1451. dtmprintk((MYIOC_s_INFO_FMT "Calling HardReset! \n",
  1452. hd->ioc->name));
  1453. retval = mpt_HardResetHandler(hd->ioc, CAN_SLEEP);
  1454. }
  1455. return retval;
  1456. }
  1457. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1458. /**
  1459. * mptscsih_abort - Abort linux scsi_cmnd routine, new_eh variant
  1460. * @SCpnt: Pointer to scsi_cmnd structure, IO to be aborted
  1461. *
  1462. * (linux scsi_host_template.eh_abort_handler routine)
  1463. *
  1464. * Returns SUCCESS or FAILED.
  1465. */
  1466. int
  1467. mptscsih_abort(struct scsi_cmnd * SCpnt)
  1468. {
  1469. MPT_SCSI_HOST *hd;
  1470. MPT_ADAPTER *ioc;
  1471. MPT_FRAME_HDR *mf;
  1472. u32 ctx2abort;
  1473. int scpnt_idx;
  1474. /* If we can't locate our host adapter structure, return FAILED status.
  1475. */
  1476. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL) {
  1477. SCpnt->result = DID_RESET << 16;
  1478. SCpnt->scsi_done(SCpnt);
  1479. dfailprintk((KERN_WARNING MYNAM ": mptscsih_abort: "
  1480. "Can't locate host! (sc=%p)\n",
  1481. SCpnt));
  1482. return FAILED;
  1483. }
  1484. ioc = hd->ioc;
  1485. if (hd->resetPending)
  1486. return FAILED;
  1487. printk(KERN_WARNING MYNAM ": %s: >> Attempting task abort! (sc=%p)\n",
  1488. hd->ioc->name, SCpnt);
  1489. if (hd->timeouts < -1)
  1490. hd->timeouts++;
  1491. /* Find this command
  1492. */
  1493. if ((scpnt_idx = SCPNT_TO_LOOKUP_IDX(SCpnt)) < 0) {
  1494. /* Cmd not found in ScsiLookup.
  1495. * Do OS callback.
  1496. */
  1497. SCpnt->result = DID_RESET << 16;
  1498. dtmprintk((KERN_WARNING MYNAM ": %s: mptscsih_abort: "
  1499. "Command not in the active list! (sc=%p)\n",
  1500. hd->ioc->name, SCpnt));
  1501. return SUCCESS;
  1502. }
  1503. /* Most important! Set TaskMsgContext to SCpnt's MsgContext!
  1504. * (the IO to be ABORT'd)
  1505. *
  1506. * NOTE: Since we do not byteswap MsgContext, we do not
  1507. * swap it here either. It is an opaque cookie to
  1508. * the controller, so it does not matter. -DaveM
  1509. */
  1510. mf = MPT_INDEX_2_MFPTR(hd->ioc, scpnt_idx);
  1511. ctx2abort = mf->u.frame.hwhdr.msgctxu.MsgContext;
  1512. hd->abortSCpnt = SCpnt;
  1513. if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK,
  1514. SCpnt->device->channel, SCpnt->device->id, SCpnt->device->lun,
  1515. ctx2abort, 2 /* 2 second timeout */)
  1516. < 0) {
  1517. /* The TM request failed and the subsequent FW-reload failed!
  1518. * Fatal error case.
  1519. */
  1520. printk(MYIOC_s_WARN_FMT "Error issuing abort task! (sc=%p)\n",
  1521. hd->ioc->name, SCpnt);
  1522. /* We must clear our pending flag before clearing our state.
  1523. */
  1524. hd->tmPending = 0;
  1525. hd->tmState = TM_STATE_NONE;
  1526. /* Unmap the DMA buffers, if any. */
  1527. if (SCpnt->use_sg) {
  1528. pci_unmap_sg(ioc->pcidev, (struct scatterlist *) SCpnt->request_buffer,
  1529. SCpnt->use_sg, SCpnt->sc_data_direction);
  1530. } else if (SCpnt->request_bufflen) {
  1531. pci_unmap_single(ioc->pcidev, SCpnt->SCp.dma_handle,
  1532. SCpnt->request_bufflen, SCpnt->sc_data_direction);
  1533. }
  1534. hd->ScsiLookup[scpnt_idx] = NULL;
  1535. SCpnt->result = DID_RESET << 16;
  1536. SCpnt->scsi_done(SCpnt); /* Issue the command callback */
  1537. mptscsih_freeChainBuffers(ioc, scpnt_idx);
  1538. mpt_free_msg_frame(ioc, mf);
  1539. return FAILED;
  1540. }
  1541. return SUCCESS;
  1542. }
  1543. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1544. /**
  1545. * mptscsih_dev_reset - Perform a SCSI TARGET_RESET! new_eh variant
  1546. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1547. *
  1548. * (linux scsi_host_template.eh_dev_reset_handler routine)
  1549. *
  1550. * Returns SUCCESS or FAILED.
  1551. */
  1552. int
  1553. mptscsih_dev_reset(struct scsi_cmnd * SCpnt)
  1554. {
  1555. MPT_SCSI_HOST *hd;
  1556. /* If we can't locate our host adapter structure, return FAILED status.
  1557. */
  1558. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1559. dtmprintk((KERN_WARNING MYNAM ": mptscsih_dev_reset: "
  1560. "Can't locate host! (sc=%p)\n",
  1561. SCpnt));
  1562. return FAILED;
  1563. }
  1564. if (hd->resetPending)
  1565. return FAILED;
  1566. printk(KERN_WARNING MYNAM ": %s: >> Attempting target reset! (sc=%p)\n",
  1567. hd->ioc->name, SCpnt);
  1568. if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_TARGET_RESET,
  1569. SCpnt->device->channel, SCpnt->device->id,
  1570. 0, 0, 5 /* 5 second timeout */)
  1571. < 0){
  1572. /* The TM request failed and the subsequent FW-reload failed!
  1573. * Fatal error case.
  1574. */
  1575. printk(MYIOC_s_WARN_FMT "Error processing TaskMgmt request (sc=%p)\n",
  1576. hd->ioc->name, SCpnt);
  1577. hd->tmPending = 0;
  1578. hd->tmState = TM_STATE_NONE;
  1579. return FAILED;
  1580. }
  1581. return SUCCESS;
  1582. }
  1583. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1584. /**
  1585. * mptscsih_bus_reset - Perform a SCSI BUS_RESET! new_eh variant
  1586. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1587. *
  1588. * (linux scsi_host_template.eh_bus_reset_handler routine)
  1589. *
  1590. * Returns SUCCESS or FAILED.
  1591. */
  1592. int
  1593. mptscsih_bus_reset(struct scsi_cmnd * SCpnt)
  1594. {
  1595. MPT_SCSI_HOST *hd;
  1596. spinlock_t *host_lock = SCpnt->device->host->host_lock;
  1597. /* If we can't locate our host adapter structure, return FAILED status.
  1598. */
  1599. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1600. dtmprintk((KERN_WARNING MYNAM ": mptscsih_bus_reset: "
  1601. "Can't locate host! (sc=%p)\n",
  1602. SCpnt ) );
  1603. return FAILED;
  1604. }
  1605. printk(KERN_WARNING MYNAM ": %s: >> Attempting bus reset! (sc=%p)\n",
  1606. hd->ioc->name, SCpnt);
  1607. if (hd->timeouts < -1)
  1608. hd->timeouts++;
  1609. /* We are now ready to execute the task management request. */
  1610. if (mptscsih_TMHandler(hd, MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS,
  1611. SCpnt->device->channel, 0, 0, 0, 5 /* 5 second timeout */)
  1612. < 0){
  1613. /* The TM request failed and the subsequent FW-reload failed!
  1614. * Fatal error case.
  1615. */
  1616. printk(MYIOC_s_WARN_FMT
  1617. "Error processing TaskMgmt request (sc=%p)\n",
  1618. hd->ioc->name, SCpnt);
  1619. hd->tmPending = 0;
  1620. hd->tmState = TM_STATE_NONE;
  1621. spin_lock_irq(host_lock);
  1622. return FAILED;
  1623. }
  1624. return SUCCESS;
  1625. }
  1626. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1627. /**
  1628. * mptscsih_host_reset - Perform a SCSI host adapter RESET!
  1629. * new_eh variant
  1630. * @SCpnt: Pointer to scsi_cmnd structure, IO which reset is due to
  1631. *
  1632. * (linux scsi_host_template.eh_host_reset_handler routine)
  1633. *
  1634. * Returns SUCCESS or FAILED.
  1635. */
  1636. int
  1637. mptscsih_host_reset(struct scsi_cmnd *SCpnt)
  1638. {
  1639. MPT_SCSI_HOST * hd;
  1640. int status = SUCCESS;
  1641. /* If we can't locate the host to reset, then we failed. */
  1642. if ((hd = (MPT_SCSI_HOST *) SCpnt->device->host->hostdata) == NULL){
  1643. dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: "
  1644. "Can't locate host! (sc=%p)\n",
  1645. SCpnt ) );
  1646. return FAILED;
  1647. }
  1648. printk(KERN_WARNING MYNAM ": %s: >> Attempting host reset! (sc=%p)\n",
  1649. hd->ioc->name, SCpnt);
  1650. /* If our attempts to reset the host failed, then return a failed
  1651. * status. The host will be taken off line by the SCSI mid-layer.
  1652. */
  1653. if (mpt_HardResetHandler(hd->ioc, CAN_SLEEP) < 0){
  1654. status = FAILED;
  1655. } else {
  1656. /* Make sure TM pending is cleared and TM state is set to
  1657. * NONE.
  1658. */
  1659. hd->tmPending = 0;
  1660. hd->tmState = TM_STATE_NONE;
  1661. }
  1662. dtmprintk( ( KERN_WARNING MYNAM ": mptscsih_host_reset: "
  1663. "Status = %s\n",
  1664. (status == SUCCESS) ? "SUCCESS" : "FAILED" ) );
  1665. return status;
  1666. }
  1667. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1668. /**
  1669. * mptscsih_tm_pending_wait - wait for pending task management request to
  1670. * complete.
  1671. * @hd: Pointer to MPT host structure.
  1672. *
  1673. * Returns {SUCCESS,FAILED}.
  1674. */
  1675. static int
  1676. mptscsih_tm_pending_wait(MPT_SCSI_HOST * hd)
  1677. {
  1678. unsigned long flags;
  1679. int loop_count = 4 * 10; /* Wait 10 seconds */
  1680. int status = FAILED;
  1681. do {
  1682. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1683. if (hd->tmState == TM_STATE_NONE) {
  1684. hd->tmState = TM_STATE_IN_PROGRESS;
  1685. hd->tmPending = 1;
  1686. status = SUCCESS;
  1687. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1688. break;
  1689. }
  1690. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1691. msleep(250);
  1692. } while (--loop_count);
  1693. return status;
  1694. }
  1695. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1696. /**
  1697. * mptscsih_tm_wait_for_completion - wait for completion of TM task
  1698. * @hd: Pointer to MPT host structure.
  1699. *
  1700. * Returns {SUCCESS,FAILED}.
  1701. */
  1702. static int
  1703. mptscsih_tm_wait_for_completion(MPT_SCSI_HOST * hd, ulong timeout )
  1704. {
  1705. unsigned long flags;
  1706. int loop_count = 4 * timeout;
  1707. int status = FAILED;
  1708. do {
  1709. spin_lock_irqsave(&hd->ioc->FreeQlock, flags);
  1710. if(hd->tmPending == 0) {
  1711. status = SUCCESS;
  1712. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1713. break;
  1714. }
  1715. spin_unlock_irqrestore(&hd->ioc->FreeQlock, flags);
  1716. msleep_interruptible(250);
  1717. } while (--loop_count);
  1718. return status;
  1719. }
  1720. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1721. /**
  1722. * mptscsih_taskmgmt_complete - Registered with Fusion MPT base driver
  1723. * @ioc: Pointer to MPT_ADAPTER structure
  1724. * @mf: Pointer to SCSI task mgmt request frame
  1725. * @mr: Pointer to SCSI task mgmt reply frame
  1726. *
  1727. * This routine is called from mptbase.c::mpt_interrupt() at the completion
  1728. * of any SCSI task management request.
  1729. * This routine is registered with the MPT (base) driver at driver
  1730. * load/init time via the mpt_register() API call.
  1731. *
  1732. * Returns 1 indicating alloc'd request frame ptr should be freed.
  1733. */
  1734. int
  1735. mptscsih_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  1736. {
  1737. SCSITaskMgmtReply_t *pScsiTmReply;
  1738. SCSITaskMgmt_t *pScsiTmReq;
  1739. MPT_SCSI_HOST *hd;
  1740. unsigned long flags;
  1741. u16 iocstatus;
  1742. u8 tmType;
  1743. dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt completed (mf=%p,mr=%p)\n",
  1744. ioc->name, mf, mr));
  1745. if (ioc->sh) {
  1746. /* Depending on the thread, a timer is activated for
  1747. * the TM request. Delete this timer on completion of TM.
  1748. * Decrement count of outstanding TM requests.
  1749. */
  1750. hd = (MPT_SCSI_HOST *)ioc->sh->hostdata;
  1751. } else {
  1752. dtmprintk((MYIOC_s_WARN_FMT "TaskMgmt Complete: NULL Scsi Host Ptr\n",
  1753. ioc->name));
  1754. return 1;
  1755. }
  1756. if (mr == NULL) {
  1757. dtmprintk((MYIOC_s_WARN_FMT "ERROR! TaskMgmt Reply: NULL Request %p\n",
  1758. ioc->name, mf));
  1759. return 1;
  1760. } else {
  1761. pScsiTmReply = (SCSITaskMgmtReply_t*)mr;
  1762. pScsiTmReq = (SCSITaskMgmt_t*)mf;
  1763. /* Figure out if this was ABORT_TASK, TARGET_RESET, or BUS_RESET! */
  1764. tmType = pScsiTmReq->TaskType;
  1765. dtmprintk((MYIOC_s_WARN_FMT " TaskType = %d, TerminationCount=%d\n",
  1766. ioc->name, tmType, le32_to_cpu(pScsiTmReply->TerminationCount)));
  1767. DBG_DUMP_TM_REPLY_FRAME((u32 *)pScsiTmReply);
  1768. iocstatus = le16_to_cpu(pScsiTmReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  1769. dtmprintk((MYIOC_s_WARN_FMT " SCSI TaskMgmt (%d) IOCStatus=%04x IOCLogInfo=%08x\n",
  1770. ioc->name, tmType, iocstatus, le32_to_cpu(pScsiTmReply->IOCLogInfo)));
  1771. /* Error? (anything non-zero?) */
  1772. if (iocstatus) {
  1773. /* clear flags and continue.
  1774. */
  1775. if (tmType == MPI_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
  1776. hd->abortSCpnt = NULL;
  1777. /* If an internal command is present
  1778. * or the TM failed - reload the FW.
  1779. * FC FW may respond FAILED to an ABORT
  1780. */
  1781. if (tmType == MPI_SCSITASKMGMT_TASKTYPE_RESET_BUS) {
  1782. if ((hd->cmdPtr) ||
  1783. (iocstatus == MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED)) {
  1784. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0) {
  1785. printk((KERN_WARNING
  1786. " Firmware Reload FAILED!!\n"));
  1787. }
  1788. }
  1789. }
  1790. } else {
  1791. dtmprintk((MYIOC_s_WARN_FMT " TaskMgmt SUCCESS\n", ioc->name));
  1792. hd->abortSCpnt = NULL;
  1793. }
  1794. }
  1795. spin_lock_irqsave(&ioc->FreeQlock, flags);
  1796. hd->tmPending = 0;
  1797. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  1798. hd->tmState = TM_STATE_NONE;
  1799. return 1;
  1800. }
  1801. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1802. /*
  1803. * This is anyones guess quite frankly.
  1804. */
  1805. int
  1806. mptscsih_bios_param(struct scsi_device * sdev, struct block_device *bdev,
  1807. sector_t capacity, int geom[])
  1808. {
  1809. int heads;
  1810. int sectors;
  1811. sector_t cylinders;
  1812. ulong dummy;
  1813. heads = 64;
  1814. sectors = 32;
  1815. dummy = heads * sectors;
  1816. cylinders = capacity;
  1817. sector_div(cylinders,dummy);
  1818. /*
  1819. * Handle extended translation size for logical drives
  1820. * > 1Gb
  1821. */
  1822. if ((ulong)capacity >= 0x200000) {
  1823. heads = 255;
  1824. sectors = 63;
  1825. dummy = heads * sectors;
  1826. cylinders = capacity;
  1827. sector_div(cylinders,dummy);
  1828. }
  1829. /* return result */
  1830. geom[0] = heads;
  1831. geom[1] = sectors;
  1832. geom[2] = cylinders;
  1833. dprintk((KERN_NOTICE
  1834. ": bios_param: Id=%i Lun=%i Channel=%i CHS=%i/%i/%i\n",
  1835. sdev->id, sdev->lun,sdev->channel,(int)cylinders,heads,sectors));
  1836. return 0;
  1837. }
  1838. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1839. /*
  1840. * OS entry point to allow host driver to alloc memory
  1841. * for each scsi device. Called once per device the bus scan.
  1842. * Return non-zero if allocation fails.
  1843. * Init memory once per id (not LUN).
  1844. */
  1845. int
  1846. mptscsih_slave_alloc(struct scsi_device *device)
  1847. {
  1848. struct Scsi_Host *host = device->host;
  1849. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1850. VirtDevice *vdev;
  1851. uint target = device->id;
  1852. if (hd == NULL)
  1853. return -ENODEV;
  1854. if ((vdev = hd->Targets[target]) != NULL)
  1855. goto out;
  1856. vdev = kmalloc(sizeof(VirtDevice), GFP_KERNEL);
  1857. if (!vdev) {
  1858. printk(MYIOC_s_ERR_FMT "slave_alloc kmalloc(%zd) FAILED!\n",
  1859. hd->ioc->name, sizeof(VirtDevice));
  1860. return -ENOMEM;
  1861. }
  1862. memset(vdev, 0, sizeof(VirtDevice));
  1863. vdev->tflags = MPT_TARGET_FLAGS_Q_YES;
  1864. vdev->ioc_id = hd->ioc->id;
  1865. vdev->target_id = device->id;
  1866. vdev->bus_id = device->channel;
  1867. vdev->raidVolume = 0;
  1868. hd->Targets[device->id] = vdev;
  1869. if (hd->ioc->bus_type == SCSI) {
  1870. if (hd->ioc->spi_data.isRaid & (1 << device->id)) {
  1871. vdev->raidVolume = 1;
  1872. ddvtprintk((KERN_INFO
  1873. "RAID Volume @ id %d\n", device->id));
  1874. }
  1875. } else {
  1876. vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
  1877. }
  1878. out:
  1879. vdev->num_luns++;
  1880. return 0;
  1881. }
  1882. static int
  1883. mptscsih_is_raid_volume(MPT_SCSI_HOST *hd, uint id)
  1884. {
  1885. int i;
  1886. if (!hd->ioc->spi_data.isRaid || !hd->ioc->spi_data.pIocPg3)
  1887. return 0;
  1888. for (i = 0; i < hd->ioc->spi_data.pIocPg3->NumPhysDisks; i++) {
  1889. if (id == hd->ioc->spi_data.pIocPg3->PhysDisk[i].PhysDiskID)
  1890. return 1;
  1891. }
  1892. return 0;
  1893. }
  1894. /*
  1895. * OS entry point to allow for host driver to free allocated memory
  1896. * Called if no device present or device being unloaded
  1897. */
  1898. void
  1899. mptscsih_slave_destroy(struct scsi_device *device)
  1900. {
  1901. struct Scsi_Host *host = device->host;
  1902. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)host->hostdata;
  1903. VirtDevice *vdev;
  1904. uint target = device->id;
  1905. uint lun = device->lun;
  1906. if (hd == NULL)
  1907. return;
  1908. mptscsih_search_running_cmds(hd, target, lun);
  1909. vdev = hd->Targets[target];
  1910. vdev->luns[0] &= ~(1 << lun);
  1911. if (--vdev->num_luns)
  1912. return;
  1913. kfree(hd->Targets[target]);
  1914. hd->Targets[target] = NULL;
  1915. if (hd->ioc->bus_type == SCSI) {
  1916. if (mptscsih_is_raid_volume(hd, target)) {
  1917. hd->ioc->spi_data.forceDv |= MPT_SCSICFG_RELOAD_IOC_PG3;
  1918. } else {
  1919. hd->ioc->spi_data.dvStatus[target] =
  1920. MPT_SCSICFG_NEGOTIATE;
  1921. if (!hd->negoNvram) {
  1922. hd->ioc->spi_data.dvStatus[target] |=
  1923. MPT_SCSICFG_DV_NOT_DONE;
  1924. }
  1925. }
  1926. }
  1927. }
  1928. static void
  1929. mptscsih_set_queue_depth(struct scsi_device *device, MPT_SCSI_HOST *hd,
  1930. VirtDevice *pTarget, int qdepth)
  1931. {
  1932. int max_depth;
  1933. int tagged;
  1934. if (hd->ioc->bus_type == SCSI) {
  1935. if (pTarget->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY) {
  1936. if (!(pTarget->tflags & MPT_TARGET_FLAGS_Q_YES))
  1937. max_depth = 1;
  1938. else if (((pTarget->inq_data[0] & 0x1f) == 0x00) &&
  1939. (pTarget->minSyncFactor <= MPT_ULTRA160 ))
  1940. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  1941. else
  1942. max_depth = MPT_SCSI_CMD_PER_DEV_LOW;
  1943. } else {
  1944. /* error case - No Inq. Data */
  1945. max_depth = 1;
  1946. }
  1947. } else
  1948. max_depth = MPT_SCSI_CMD_PER_DEV_HIGH;
  1949. if (qdepth > max_depth)
  1950. qdepth = max_depth;
  1951. if (qdepth == 1)
  1952. tagged = 0;
  1953. else
  1954. tagged = MSG_SIMPLE_TAG;
  1955. scsi_adjust_queue_depth(device, tagged, qdepth);
  1956. }
  1957. /*
  1958. * OS entry point to adjust the queue_depths on a per-device basis.
  1959. * Called once per device the bus scan. Use it to force the queue_depth
  1960. * member to 1 if a device does not support Q tags.
  1961. * Return non-zero if fails.
  1962. */
  1963. int
  1964. mptscsih_slave_configure(struct scsi_device *device)
  1965. {
  1966. struct Scsi_Host *sh = device->host;
  1967. VirtDevice *pTarget;
  1968. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *)sh->hostdata;
  1969. if ((hd == NULL) || (hd->Targets == NULL)) {
  1970. return 0;
  1971. }
  1972. dsprintk((MYIOC_s_INFO_FMT
  1973. "device @ %p, id=%d, LUN=%d, channel=%d\n",
  1974. hd->ioc->name, device, device->id, device->lun, device->channel));
  1975. dsprintk((MYIOC_s_INFO_FMT
  1976. "sdtr %d wdtr %d ppr %d inq length=%d\n",
  1977. hd->ioc->name, device->sdtr, device->wdtr,
  1978. device->ppr, device->inquiry_len));
  1979. if (device->id > sh->max_id) {
  1980. /* error case, should never happen */
  1981. scsi_adjust_queue_depth(device, 0, 1);
  1982. goto slave_configure_exit;
  1983. }
  1984. pTarget = hd->Targets[device->id];
  1985. if (pTarget == NULL) {
  1986. /* Driver doesn't know about this device.
  1987. * Kernel may generate a "Dummy Lun 0" which
  1988. * may become a real Lun if a
  1989. * "scsi add-single-device" command is executed
  1990. * while the driver is active (hot-plug a
  1991. * device). LSI Raid controllers need
  1992. * queue_depth set to DEV_HIGH for this reason.
  1993. */
  1994. scsi_adjust_queue_depth(device, MSG_SIMPLE_TAG,
  1995. MPT_SCSI_CMD_PER_DEV_HIGH);
  1996. goto slave_configure_exit;
  1997. }
  1998. mptscsih_initTarget(hd, device->channel, device->id, device->lun,
  1999. device->inquiry, device->inquiry_len );
  2000. mptscsih_set_queue_depth(device, hd, pTarget, MPT_SCSI_CMD_PER_DEV_HIGH);
  2001. dsprintk((MYIOC_s_INFO_FMT
  2002. "Queue depth=%d, tflags=%x\n",
  2003. hd->ioc->name, device->queue_depth, pTarget->tflags));
  2004. dsprintk((MYIOC_s_INFO_FMT
  2005. "negoFlags=%x, maxOffset=%x, SyncFactor=%x\n",
  2006. hd->ioc->name, pTarget->negoFlags, pTarget->maxOffset, pTarget->minSyncFactor));
  2007. slave_configure_exit:
  2008. dsprintk((MYIOC_s_INFO_FMT
  2009. "tagged %d, simple %d, ordered %d\n",
  2010. hd->ioc->name,device->tagged_supported, device->simple_tags,
  2011. device->ordered_tags));
  2012. return 0;
  2013. }
  2014. ssize_t
  2015. mptscsih_store_queue_depth(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  2016. {
  2017. int depth;
  2018. struct scsi_device *sdev = to_scsi_device(dev);
  2019. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) sdev->host->hostdata;
  2020. VirtDevice *pTarget;
  2021. depth = simple_strtoul(buf, NULL, 0);
  2022. if (depth == 0)
  2023. return -EINVAL;
  2024. pTarget = hd->Targets[sdev->id];
  2025. if (pTarget == NULL)
  2026. return -EINVAL;
  2027. mptscsih_set_queue_depth(sdev, (MPT_SCSI_HOST *) sdev->host->hostdata,
  2028. pTarget, depth);
  2029. return count;
  2030. }
  2031. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2032. /*
  2033. * Private routines...
  2034. */
  2035. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2036. /* Utility function to copy sense data from the scsi_cmnd buffer
  2037. * to the FC and SCSI target structures.
  2038. *
  2039. */
  2040. static void
  2041. mptscsih_copy_sense_data(struct scsi_cmnd *sc, MPT_SCSI_HOST *hd, MPT_FRAME_HDR *mf, SCSIIOReply_t *pScsiReply)
  2042. {
  2043. VirtDevice *target;
  2044. SCSIIORequest_t *pReq;
  2045. u32 sense_count = le32_to_cpu(pScsiReply->SenseCount);
  2046. int index;
  2047. /* Get target structure
  2048. */
  2049. pReq = (SCSIIORequest_t *) mf;
  2050. index = (int) pReq->TargetID;
  2051. target = hd->Targets[index];
  2052. if (sense_count) {
  2053. u8 *sense_data;
  2054. int req_index;
  2055. /* Copy the sense received into the scsi command block. */
  2056. req_index = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2057. sense_data = ((u8 *)hd->ioc->sense_buf_pool + (req_index * MPT_SENSE_BUFFER_ALLOC));
  2058. memcpy(sc->sense_buffer, sense_data, SNS_LEN(sc));
  2059. /* Log SMART data (asc = 0x5D, non-IM case only) if required.
  2060. */
  2061. if ((hd->ioc->events) && (hd->ioc->eventTypes & (1 << MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE))) {
  2062. if ((sense_data[12] == 0x5D) && (target->raidVolume == 0)) {
  2063. int idx;
  2064. MPT_ADAPTER *ioc = hd->ioc;
  2065. idx = ioc->eventContext % ioc->eventLogSize;
  2066. ioc->events[idx].event = MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE;
  2067. ioc->events[idx].eventContext = ioc->eventContext;
  2068. ioc->events[idx].data[0] = (pReq->LUN[1] << 24) ||
  2069. (MPI_EVENT_SCSI_DEV_STAT_RC_SMART_DATA << 16) ||
  2070. (pReq->Bus << 8) || pReq->TargetID;
  2071. ioc->events[idx].data[1] = (sense_data[13] << 8) || sense_data[12];
  2072. ioc->eventContext++;
  2073. }
  2074. }
  2075. } else {
  2076. dprintk((MYIOC_s_INFO_FMT "Hmmm... SenseData len=0! (?)\n",
  2077. hd->ioc->name));
  2078. }
  2079. }
  2080. static u32
  2081. SCPNT_TO_LOOKUP_IDX(struct scsi_cmnd *sc)
  2082. {
  2083. MPT_SCSI_HOST *hd;
  2084. int i;
  2085. hd = (MPT_SCSI_HOST *) sc->device->host->hostdata;
  2086. for (i = 0; i < hd->ioc->req_depth; i++) {
  2087. if (hd->ScsiLookup[i] == sc) {
  2088. return i;
  2089. }
  2090. }
  2091. return -1;
  2092. }
  2093. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2094. int
  2095. mptscsih_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  2096. {
  2097. MPT_SCSI_HOST *hd;
  2098. unsigned long flags;
  2099. dtmprintk((KERN_WARNING MYNAM
  2100. ": IOC %s_reset routed to SCSI host driver!\n",
  2101. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  2102. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  2103. /* If a FW reload request arrives after base installed but
  2104. * before all scsi hosts have been attached, then an alt_ioc
  2105. * may have a NULL sh pointer.
  2106. */
  2107. if ((ioc->sh == NULL) || (ioc->sh->hostdata == NULL))
  2108. return 0;
  2109. else
  2110. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2111. if (reset_phase == MPT_IOC_SETUP_RESET) {
  2112. dtmprintk((MYIOC_s_WARN_FMT "Setup-Diag Reset\n", ioc->name));
  2113. /* Clean Up:
  2114. * 1. Set Hard Reset Pending Flag
  2115. * All new commands go to doneQ
  2116. */
  2117. hd->resetPending = 1;
  2118. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  2119. dtmprintk((MYIOC_s_WARN_FMT "Pre-Diag Reset\n", ioc->name));
  2120. /* 2. Flush running commands
  2121. * Clean ScsiLookup (and associated memory)
  2122. * AND clean mytaskQ
  2123. */
  2124. /* 2b. Reply to OS all known outstanding I/O commands.
  2125. */
  2126. mptscsih_flush_running_cmds(hd);
  2127. /* 2c. If there was an internal command that
  2128. * has not completed, configuration or io request,
  2129. * free these resources.
  2130. */
  2131. if (hd->cmdPtr) {
  2132. del_timer(&hd->timer);
  2133. mpt_free_msg_frame(ioc, hd->cmdPtr);
  2134. }
  2135. dtmprintk((MYIOC_s_WARN_FMT "Pre-Reset complete.\n", ioc->name));
  2136. } else {
  2137. dtmprintk((MYIOC_s_WARN_FMT "Post-Diag Reset\n", ioc->name));
  2138. /* Once a FW reload begins, all new OS commands are
  2139. * redirected to the doneQ w/ a reset status.
  2140. * Init all control structures.
  2141. */
  2142. /* ScsiLookup initialization
  2143. */
  2144. {
  2145. int ii;
  2146. for (ii=0; ii < hd->ioc->req_depth; ii++)
  2147. hd->ScsiLookup[ii] = NULL;
  2148. }
  2149. /* 2. Chain Buffer initialization
  2150. */
  2151. /* 4. Renegotiate to all devices, if SCSI
  2152. */
  2153. if (ioc->bus_type == SCSI) {
  2154. dnegoprintk(("writeSDP1: ALL_IDS USE_NVRAM\n"));
  2155. mptscsih_writeSDP1(hd, 0, 0, MPT_SCSICFG_ALL_IDS | MPT_SCSICFG_USE_NVRAM);
  2156. }
  2157. /* 5. Enable new commands to be posted
  2158. */
  2159. spin_lock_irqsave(&ioc->FreeQlock, flags);
  2160. hd->tmPending = 0;
  2161. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  2162. hd->resetPending = 0;
  2163. hd->tmState = TM_STATE_NONE;
  2164. /* 6. If there was an internal command,
  2165. * wake this process up.
  2166. */
  2167. if (hd->cmdPtr) {
  2168. /*
  2169. * Wake up the original calling thread
  2170. */
  2171. hd->pLocal = &hd->localReply;
  2172. hd->pLocal->completion = MPT_SCANDV_DID_RESET;
  2173. hd->scandv_wait_done = 1;
  2174. wake_up(&hd->scandv_waitq);
  2175. hd->cmdPtr = NULL;
  2176. }
  2177. /* 7. Set flag to force DV and re-read IOC Page 3
  2178. */
  2179. if (ioc->bus_type == SCSI) {
  2180. ioc->spi_data.forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
  2181. ddvtprintk(("Set reload IOC Pg3 Flag\n"));
  2182. }
  2183. dtmprintk((MYIOC_s_WARN_FMT "Post-Reset complete.\n", ioc->name));
  2184. }
  2185. return 1; /* currently means nothing really */
  2186. }
  2187. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2188. int
  2189. mptscsih_event_process(MPT_ADAPTER *ioc, EventNotificationReply_t *pEvReply)
  2190. {
  2191. MPT_SCSI_HOST *hd;
  2192. u8 event = le32_to_cpu(pEvReply->Event) & 0xFF;
  2193. devtprintk((MYIOC_s_INFO_FMT "MPT event (=%02Xh) routed to SCSI host driver!\n",
  2194. ioc->name, event));
  2195. switch (event) {
  2196. case MPI_EVENT_UNIT_ATTENTION: /* 03 */
  2197. /* FIXME! */
  2198. break;
  2199. case MPI_EVENT_IOC_BUS_RESET: /* 04 */
  2200. case MPI_EVENT_EXT_BUS_RESET: /* 05 */
  2201. hd = NULL;
  2202. if (ioc->sh) {
  2203. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2204. if (hd && (ioc->bus_type == SCSI) && (hd->soft_resets < -1))
  2205. hd->soft_resets++;
  2206. }
  2207. break;
  2208. case MPI_EVENT_LOGOUT: /* 09 */
  2209. /* FIXME! */
  2210. break;
  2211. /*
  2212. * CHECKME! Don't think we need to do
  2213. * anything for these, but...
  2214. */
  2215. case MPI_EVENT_RESCAN: /* 06 */
  2216. case MPI_EVENT_LINK_STATUS_CHANGE: /* 07 */
  2217. case MPI_EVENT_LOOP_STATE_CHANGE: /* 08 */
  2218. /*
  2219. * CHECKME! Falling thru...
  2220. */
  2221. break;
  2222. case MPI_EVENT_INTEGRATED_RAID: /* 0B */
  2223. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  2224. /* negoNvram set to 0 if DV enabled and to USE_NVRAM if
  2225. * if DV disabled. Need to check for target mode.
  2226. */
  2227. hd = NULL;
  2228. if (ioc->sh)
  2229. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2230. if (hd && (ioc->bus_type == SCSI) && (hd->negoNvram == 0)) {
  2231. ScsiCfgData *pSpi;
  2232. Ioc3PhysDisk_t *pPDisk;
  2233. int numPDisk;
  2234. u8 reason;
  2235. u8 physDiskNum;
  2236. reason = (le32_to_cpu(pEvReply->Data[0]) & 0x00FF0000) >> 16;
  2237. if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
  2238. /* New or replaced disk.
  2239. * Set DV flag and schedule DV.
  2240. */
  2241. pSpi = &ioc->spi_data;
  2242. physDiskNum = (le32_to_cpu(pEvReply->Data[0]) & 0xFF000000) >> 24;
  2243. ddvtprintk(("DV requested for phys disk id %d\n", physDiskNum));
  2244. if (pSpi->pIocPg3) {
  2245. pPDisk = pSpi->pIocPg3->PhysDisk;
  2246. numPDisk =pSpi->pIocPg3->NumPhysDisks;
  2247. while (numPDisk) {
  2248. if (physDiskNum == pPDisk->PhysDiskNum) {
  2249. pSpi->dvStatus[pPDisk->PhysDiskID] = (MPT_SCSICFG_NEED_DV | MPT_SCSICFG_DV_NOT_DONE);
  2250. pSpi->forceDv = MPT_SCSICFG_NEED_DV;
  2251. ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID));
  2252. break;
  2253. }
  2254. pPDisk++;
  2255. numPDisk--;
  2256. }
  2257. if (numPDisk == 0) {
  2258. /* The physical disk that needs DV was not found
  2259. * in the stored IOC Page 3. The driver must reload
  2260. * this page. DV routine will set the NEED_DV flag for
  2261. * all phys disks that have DV_NOT_DONE set.
  2262. */
  2263. pSpi->forceDv = MPT_SCSICFG_NEED_DV | MPT_SCSICFG_RELOAD_IOC_PG3;
  2264. ddvtprintk(("phys disk %d not found. Setting reload IOC Pg3 Flag\n", physDiskNum));
  2265. }
  2266. }
  2267. }
  2268. }
  2269. #endif
  2270. #if defined(MPT_DEBUG_DV) || defined(MPT_DEBUG_DV_TINY)
  2271. printk("Raid Event RF: ");
  2272. {
  2273. u32 *m = (u32 *)pEvReply;
  2274. int ii;
  2275. int n = (int)pEvReply->MsgLength;
  2276. for (ii=6; ii < n; ii++)
  2277. printk(" %08x", le32_to_cpu(m[ii]));
  2278. printk("\n");
  2279. }
  2280. #endif
  2281. break;
  2282. case MPI_EVENT_NONE: /* 00 */
  2283. case MPI_EVENT_LOG_DATA: /* 01 */
  2284. case MPI_EVENT_STATE_CHANGE: /* 02 */
  2285. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  2286. default:
  2287. dprintk((KERN_INFO " Ignoring event (=%02Xh)\n", event));
  2288. break;
  2289. }
  2290. return 1; /* currently means nothing really */
  2291. }
  2292. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2293. /*
  2294. * mptscsih_initTarget - Target, LUN alloc/free functionality.
  2295. * @hd: Pointer to MPT_SCSI_HOST structure
  2296. * @bus_id: Bus number (?)
  2297. * @target_id: SCSI target id
  2298. * @lun: SCSI LUN id
  2299. * @data: Pointer to data
  2300. * @dlen: Number of INQUIRY bytes
  2301. *
  2302. * NOTE: It's only SAFE to call this routine if data points to
  2303. * sane & valid STANDARD INQUIRY data!
  2304. *
  2305. * Allocate and initialize memory for this target.
  2306. * Save inquiry data.
  2307. *
  2308. */
  2309. static void
  2310. mptscsih_initTarget(MPT_SCSI_HOST *hd, int bus_id, int target_id, u8 lun, char *data, int dlen)
  2311. {
  2312. int indexed_lun, lun_index;
  2313. VirtDevice *vdev;
  2314. ScsiCfgData *pSpi;
  2315. char data_56;
  2316. dinitprintk((MYIOC_s_INFO_FMT "initTarget bus=%d id=%d lun=%d hd=%p\n",
  2317. hd->ioc->name, bus_id, target_id, lun, hd));
  2318. /*
  2319. * If the peripheral qualifier filter is enabled then if the target reports a 0x1
  2320. * (i.e. The targer is capable of supporting the specified peripheral device type
  2321. * on this logical unit; however, the physical device is not currently connected
  2322. * to this logical unit) it will be converted to a 0x3 (i.e. The target is not
  2323. * capable of supporting a physical device on this logical unit). This is to work
  2324. * around a bug in th emid-layer in some distributions in which the mid-layer will
  2325. * continue to try to communicate to the LUN and evntually create a dummy LUN.
  2326. */
  2327. if (hd->mpt_pq_filter && dlen && (data[0] & 0xE0))
  2328. data[0] |= 0x40;
  2329. /* Is LUN supported? If so, upper 2 bits will be 0
  2330. * in first byte of inquiry data.
  2331. */
  2332. if (data[0] & 0xe0)
  2333. return;
  2334. if ((vdev = hd->Targets[target_id]) == NULL) {
  2335. return;
  2336. }
  2337. lun_index = (lun >> 5); /* 32 luns per lun_index */
  2338. indexed_lun = (lun % 32);
  2339. vdev->luns[lun_index] |= (1 << indexed_lun);
  2340. if (hd->ioc->bus_type == SCSI) {
  2341. if ((data[0] == TYPE_PROCESSOR) && (hd->ioc->spi_data.Saf_Te)) {
  2342. /* Treat all Processors as SAF-TE if
  2343. * command line option is set */
  2344. vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
  2345. mptscsih_writeIOCPage4(hd, target_id, bus_id);
  2346. }else if ((data[0] == TYPE_PROCESSOR) &&
  2347. !(vdev->tflags & MPT_TARGET_FLAGS_SAF_TE_ISSUED )) {
  2348. if ( dlen > 49 ) {
  2349. vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
  2350. if ( data[44] == 'S' &&
  2351. data[45] == 'A' &&
  2352. data[46] == 'F' &&
  2353. data[47] == '-' &&
  2354. data[48] == 'T' &&
  2355. data[49] == 'E' ) {
  2356. vdev->tflags |= MPT_TARGET_FLAGS_SAF_TE_ISSUED;
  2357. mptscsih_writeIOCPage4(hd, target_id, bus_id);
  2358. }
  2359. }
  2360. }
  2361. if (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_INQUIRY)) {
  2362. if ( dlen > 8 ) {
  2363. memcpy (vdev->inq_data, data, 8);
  2364. } else {
  2365. memcpy (vdev->inq_data, data, dlen);
  2366. }
  2367. /* If have not done DV, set the DV flag.
  2368. */
  2369. pSpi = &hd->ioc->spi_data;
  2370. if ((data[0] == TYPE_TAPE) || (data[0] == TYPE_PROCESSOR)) {
  2371. if (pSpi->dvStatus[target_id] & MPT_SCSICFG_DV_NOT_DONE)
  2372. pSpi->dvStatus[target_id] |= MPT_SCSICFG_NEED_DV;
  2373. }
  2374. vdev->tflags |= MPT_TARGET_FLAGS_VALID_INQUIRY;
  2375. data_56 = 0x0F; /* Default to full capabilities if Inq data length is < 57 */
  2376. if (dlen > 56) {
  2377. if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) {
  2378. /* Update the target capabilities
  2379. */
  2380. data_56 = data[56];
  2381. vdev->tflags |= MPT_TARGET_FLAGS_VALID_56;
  2382. }
  2383. }
  2384. mptscsih_setTargetNegoParms(hd, vdev, data_56);
  2385. } else {
  2386. /* Initial Inquiry may not request enough data bytes to
  2387. * obtain byte 57. DV will; if target doesn't return
  2388. * at least 57 bytes, data[56] will be zero. */
  2389. if (dlen > 56) {
  2390. if ( (!(vdev->tflags & MPT_TARGET_FLAGS_VALID_56))) {
  2391. /* Update the target capabilities
  2392. */
  2393. data_56 = data[56];
  2394. vdev->tflags |= MPT_TARGET_FLAGS_VALID_56;
  2395. mptscsih_setTargetNegoParms(hd, vdev, data_56);
  2396. }
  2397. }
  2398. }
  2399. }
  2400. }
  2401. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2402. /*
  2403. * Update the target negotiation parameters based on the
  2404. * the Inquiry data, adapter capabilities, and NVRAM settings.
  2405. *
  2406. */
  2407. static void
  2408. mptscsih_setTargetNegoParms(MPT_SCSI_HOST *hd, VirtDevice *target, char byte56)
  2409. {
  2410. ScsiCfgData *pspi_data = &hd->ioc->spi_data;
  2411. int id = (int) target->target_id;
  2412. int nvram;
  2413. VirtDevice *vdev;
  2414. int ii;
  2415. u8 width = MPT_NARROW;
  2416. u8 factor = MPT_ASYNC;
  2417. u8 offset = 0;
  2418. u8 version, nfactor;
  2419. u8 noQas = 1;
  2420. target->negoFlags = pspi_data->noQas;
  2421. /* noQas == 0 => device supports QAS. Need byte 56 of Inq to determine
  2422. * support. If available, default QAS to off and allow enabling.
  2423. * If not available, default QAS to on, turn off for non-disks.
  2424. */
  2425. /* Set flags based on Inquiry data
  2426. */
  2427. version = target->inq_data[2] & 0x07;
  2428. if (version < 2) {
  2429. width = 0;
  2430. factor = MPT_ULTRA2;
  2431. offset = pspi_data->maxSyncOffset;
  2432. target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
  2433. } else {
  2434. if (target->inq_data[7] & 0x20) {
  2435. width = 1;
  2436. }
  2437. if (target->inq_data[7] & 0x10) {
  2438. factor = pspi_data->minSyncFactor;
  2439. if (target->tflags & MPT_TARGET_FLAGS_VALID_56) {
  2440. /* bits 2 & 3 show Clocking support */
  2441. if ((byte56 & 0x0C) == 0)
  2442. factor = MPT_ULTRA2;
  2443. else {
  2444. if ((byte56 & 0x03) == 0)
  2445. factor = MPT_ULTRA160;
  2446. else {
  2447. factor = MPT_ULTRA320;
  2448. if (byte56 & 0x02)
  2449. {
  2450. ddvtprintk((KERN_INFO "Enabling QAS due to byte56=%02x on id=%d!\n", byte56, id));
  2451. noQas = 0;
  2452. }
  2453. if (target->inq_data[0] == TYPE_TAPE) {
  2454. if (byte56 & 0x01)
  2455. target->negoFlags |= MPT_TAPE_NEGO_IDP;
  2456. }
  2457. }
  2458. }
  2459. } else {
  2460. ddvtprintk((KERN_INFO "Enabling QAS on id=%d due to ~TARGET_FLAGS_VALID_56!\n", id));
  2461. noQas = 0;
  2462. }
  2463. offset = pspi_data->maxSyncOffset;
  2464. /* If RAID, never disable QAS
  2465. * else if non RAID, do not disable
  2466. * QAS if bit 1 is set
  2467. * bit 1 QAS support, non-raid only
  2468. * bit 0 IU support
  2469. */
  2470. if (target->raidVolume == 1) {
  2471. noQas = 0;
  2472. }
  2473. } else {
  2474. factor = MPT_ASYNC;
  2475. offset = 0;
  2476. }
  2477. }
  2478. if ( (target->inq_data[7] & 0x02) == 0) {
  2479. target->tflags &= ~MPT_TARGET_FLAGS_Q_YES;
  2480. }
  2481. /* Update tflags based on NVRAM settings. (SCSI only)
  2482. */
  2483. if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  2484. nvram = pspi_data->nvram[id];
  2485. nfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
  2486. if (width)
  2487. width = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  2488. if (offset > 0) {
  2489. /* Ensure factor is set to the
  2490. * maximum of: adapter, nvram, inquiry
  2491. */
  2492. if (nfactor) {
  2493. if (nfactor < pspi_data->minSyncFactor )
  2494. nfactor = pspi_data->minSyncFactor;
  2495. factor = max(factor, nfactor);
  2496. if (factor == MPT_ASYNC)
  2497. offset = 0;
  2498. } else {
  2499. offset = 0;
  2500. factor = MPT_ASYNC;
  2501. }
  2502. } else {
  2503. factor = MPT_ASYNC;
  2504. }
  2505. }
  2506. /* Make sure data is consistent
  2507. */
  2508. if ((!width) && (factor < MPT_ULTRA2)) {
  2509. factor = MPT_ULTRA2;
  2510. }
  2511. /* Save the data to the target structure.
  2512. */
  2513. target->minSyncFactor = factor;
  2514. target->maxOffset = offset;
  2515. target->maxWidth = width;
  2516. target->tflags |= MPT_TARGET_FLAGS_VALID_NEGO;
  2517. /* Disable unused features.
  2518. */
  2519. if (!width)
  2520. target->negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  2521. if (!offset)
  2522. target->negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  2523. if ( factor > MPT_ULTRA320 )
  2524. noQas = 0;
  2525. /* GEM, processor WORKAROUND
  2526. */
  2527. if ((target->inq_data[0] == TYPE_PROCESSOR) || (target->inq_data[0] > 0x08)) {
  2528. target->negoFlags |= (MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC);
  2529. pspi_data->dvStatus[id] |= MPT_SCSICFG_BLK_NEGO;
  2530. } else {
  2531. if (noQas && (pspi_data->noQas == 0)) {
  2532. pspi_data->noQas |= MPT_TARGET_NO_NEGO_QAS;
  2533. target->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  2534. /* Disable QAS in a mixed configuration case
  2535. */
  2536. ddvtprintk((KERN_INFO "Disabling QAS due to noQas=%02x on id=%d!\n", noQas, id));
  2537. for (ii = 0; ii < id; ii++) {
  2538. if ( (vdev = hd->Targets[ii]) ) {
  2539. vdev->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  2540. mptscsih_writeSDP1(hd, 0, ii, vdev->negoFlags);
  2541. }
  2542. }
  2543. }
  2544. }
  2545. /* Write SDP1 on this I/O to this target */
  2546. if (pspi_data->dvStatus[id] & MPT_SCSICFG_NEGOTIATE) {
  2547. ddvtprintk((KERN_INFO "MPT_SCSICFG_NEGOTIATE on id=%d!\n", id));
  2548. mptscsih_writeSDP1(hd, 0, id, hd->negoNvram);
  2549. pspi_data->dvStatus[id] &= ~MPT_SCSICFG_NEGOTIATE;
  2550. } else if (pspi_data->dvStatus[id] & MPT_SCSICFG_BLK_NEGO) {
  2551. ddvtprintk((KERN_INFO "MPT_SCSICFG_BLK_NEGO on id=%d!\n", id));
  2552. mptscsih_writeSDP1(hd, 0, id, MPT_SCSICFG_BLK_NEGO);
  2553. pspi_data->dvStatus[id] &= ~MPT_SCSICFG_BLK_NEGO;
  2554. }
  2555. }
  2556. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2557. /* If DV disabled (negoNvram set to USE_NVARM) or if not LUN 0, return.
  2558. * Else set the NEED_DV flag after Read Capacity Issued (disks)
  2559. * or Mode Sense (cdroms).
  2560. *
  2561. * Tapes, initTarget will set this flag on completion of Inquiry command.
  2562. * Called only if DV_NOT_DONE flag is set
  2563. */
  2564. static void
  2565. mptscsih_set_dvflags(MPT_SCSI_HOST *hd, SCSIIORequest_t *pReq)
  2566. {
  2567. u8 cmd;
  2568. ScsiCfgData *pSpi;
  2569. ddvtprintk((" set_dvflags: id=%d lun=%d negoNvram=%x cmd=%x\n",
  2570. pReq->TargetID, pReq->LUN[1], hd->negoNvram, pReq->CDB[0]));
  2571. if ((pReq->LUN[1] != 0) || (hd->negoNvram != 0))
  2572. return;
  2573. cmd = pReq->CDB[0];
  2574. if ((cmd == READ_CAPACITY) || (cmd == MODE_SENSE)) {
  2575. pSpi = &hd->ioc->spi_data;
  2576. if ((pSpi->isRaid & (1 << pReq->TargetID)) && pSpi->pIocPg3) {
  2577. /* Set NEED_DV for all hidden disks
  2578. */
  2579. Ioc3PhysDisk_t *pPDisk = pSpi->pIocPg3->PhysDisk;
  2580. int numPDisk = pSpi->pIocPg3->NumPhysDisks;
  2581. while (numPDisk) {
  2582. pSpi->dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV;
  2583. ddvtprintk(("NEED_DV set for phys disk id %d\n", pPDisk->PhysDiskID));
  2584. pPDisk++;
  2585. numPDisk--;
  2586. }
  2587. }
  2588. pSpi->dvStatus[pReq->TargetID] |= MPT_SCSICFG_NEED_DV;
  2589. ddvtprintk(("NEED_DV set for visible disk id %d\n", pReq->TargetID));
  2590. }
  2591. }
  2592. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2593. /*
  2594. * If no Target, bus reset on 1st I/O. Set the flag to
  2595. * prevent any future negotiations to this device.
  2596. */
  2597. static void
  2598. mptscsih_no_negotiate(MPT_SCSI_HOST *hd, int target_id)
  2599. {
  2600. if ((hd->Targets) && (hd->Targets[target_id] == NULL))
  2601. hd->ioc->spi_data.dvStatus[target_id] |= MPT_SCSICFG_BLK_NEGO;
  2602. return;
  2603. }
  2604. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2605. /*
  2606. * SCSI Config Page functionality ...
  2607. */
  2608. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2609. /* mptscsih_setDevicePage1Flags - add Requested and Configuration fields flags
  2610. * based on width, factor and offset parameters.
  2611. * @width: bus width
  2612. * @factor: sync factor
  2613. * @offset: sync offset
  2614. * @requestedPtr: pointer to requested values (updated)
  2615. * @configurationPtr: pointer to configuration values (updated)
  2616. * @flags: flags to block WDTR or SDTR negotiation
  2617. *
  2618. * Return: None.
  2619. *
  2620. * Remark: Called by writeSDP1 and _dv_params
  2621. */
  2622. static void
  2623. mptscsih_setDevicePage1Flags (u8 width, u8 factor, u8 offset, int *requestedPtr, int *configurationPtr, u8 flags)
  2624. {
  2625. u8 nowide = flags & MPT_TARGET_NO_NEGO_WIDE;
  2626. u8 nosync = flags & MPT_TARGET_NO_NEGO_SYNC;
  2627. *configurationPtr = 0;
  2628. *requestedPtr = width ? MPI_SCSIDEVPAGE1_RP_WIDE : 0;
  2629. *requestedPtr |= (offset << 16) | (factor << 8);
  2630. if (width && offset && !nowide && !nosync) {
  2631. if (factor < MPT_ULTRA160) {
  2632. *requestedPtr |= (MPI_SCSIDEVPAGE1_RP_IU + MPI_SCSIDEVPAGE1_RP_DT);
  2633. if ((flags & MPT_TARGET_NO_NEGO_QAS) == 0)
  2634. *requestedPtr |= MPI_SCSIDEVPAGE1_RP_QAS;
  2635. if (flags & MPT_TAPE_NEGO_IDP)
  2636. *requestedPtr |= 0x08000000;
  2637. } else if (factor < MPT_ULTRA2) {
  2638. *requestedPtr |= MPI_SCSIDEVPAGE1_RP_DT;
  2639. }
  2640. }
  2641. if (nowide)
  2642. *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_WDTR_DISALLOWED;
  2643. if (nosync)
  2644. *configurationPtr |= MPI_SCSIDEVPAGE1_CONF_SDTR_DISALLOWED;
  2645. return;
  2646. }
  2647. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2648. /* mptscsih_writeSDP1 - write SCSI Device Page 1
  2649. * @hd: Pointer to a SCSI Host Strucutre
  2650. * @portnum: IOC port number
  2651. * @target_id: writeSDP1 for single ID
  2652. * @flags: MPT_SCSICFG_ALL_IDS, MPT_SCSICFG_USE_NVRAM, MPT_SCSICFG_BLK_NEGO
  2653. *
  2654. * Return: -EFAULT if read of config page header fails
  2655. * or 0 if success.
  2656. *
  2657. * Remark: If a target has been found, the settings from the
  2658. * target structure are used, else the device is set
  2659. * to async/narrow.
  2660. *
  2661. * Remark: Called during init and after a FW reload.
  2662. * Remark: We do not wait for a return, write pages sequentially.
  2663. */
  2664. static int
  2665. mptscsih_writeSDP1(MPT_SCSI_HOST *hd, int portnum, int target_id, int flags)
  2666. {
  2667. MPT_ADAPTER *ioc = hd->ioc;
  2668. Config_t *pReq;
  2669. SCSIDevicePage1_t *pData;
  2670. VirtDevice *pTarget;
  2671. MPT_FRAME_HDR *mf;
  2672. dma_addr_t dataDma;
  2673. u16 req_idx;
  2674. u32 frameOffset;
  2675. u32 requested, configuration, flagsLength;
  2676. int ii, nvram;
  2677. int id = 0, maxid = 0;
  2678. u8 width;
  2679. u8 factor;
  2680. u8 offset;
  2681. u8 bus = 0;
  2682. u8 negoFlags;
  2683. u8 maxwidth, maxoffset, maxfactor;
  2684. if (ioc->spi_data.sdp1length == 0)
  2685. return 0;
  2686. if (flags & MPT_SCSICFG_ALL_IDS) {
  2687. id = 0;
  2688. maxid = ioc->sh->max_id - 1;
  2689. } else if (ioc->sh) {
  2690. id = target_id;
  2691. maxid = min_t(int, id, ioc->sh->max_id - 1);
  2692. }
  2693. for (; id <= maxid; id++) {
  2694. if (id == ioc->pfacts[portnum].PortSCSIID)
  2695. continue;
  2696. /* Use NVRAM to get adapter and target maximums
  2697. * Data over-riden by target structure information, if present
  2698. */
  2699. maxwidth = ioc->spi_data.maxBusWidth;
  2700. maxoffset = ioc->spi_data.maxSyncOffset;
  2701. maxfactor = ioc->spi_data.minSyncFactor;
  2702. if (ioc->spi_data.nvram && (ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  2703. nvram = ioc->spi_data.nvram[id];
  2704. if (maxwidth)
  2705. maxwidth = nvram & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  2706. if (maxoffset > 0) {
  2707. maxfactor = (nvram & MPT_NVRAM_SYNC_MASK) >> 8;
  2708. if (maxfactor == 0) {
  2709. /* Key for async */
  2710. maxfactor = MPT_ASYNC;
  2711. maxoffset = 0;
  2712. } else if (maxfactor < ioc->spi_data.minSyncFactor) {
  2713. maxfactor = ioc->spi_data.minSyncFactor;
  2714. }
  2715. } else
  2716. maxfactor = MPT_ASYNC;
  2717. }
  2718. /* Set the negotiation flags.
  2719. */
  2720. negoFlags = ioc->spi_data.noQas;
  2721. if (!maxwidth)
  2722. negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  2723. if (!maxoffset)
  2724. negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  2725. if (flags & MPT_SCSICFG_USE_NVRAM) {
  2726. width = maxwidth;
  2727. factor = maxfactor;
  2728. offset = maxoffset;
  2729. } else {
  2730. width = 0;
  2731. factor = MPT_ASYNC;
  2732. offset = 0;
  2733. //negoFlags = 0;
  2734. //negoFlags = MPT_TARGET_NO_NEGO_SYNC;
  2735. }
  2736. /* If id is not a raid volume, get the updated
  2737. * transmission settings from the target structure.
  2738. */
  2739. if (hd->Targets && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) {
  2740. width = pTarget->maxWidth;
  2741. factor = pTarget->minSyncFactor;
  2742. offset = pTarget->maxOffset;
  2743. negoFlags = pTarget->negoFlags;
  2744. }
  2745. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  2746. /* Force to async and narrow if DV has not been executed
  2747. * for this ID
  2748. */
  2749. if ((hd->ioc->spi_data.dvStatus[id] & MPT_SCSICFG_DV_NOT_DONE) != 0) {
  2750. width = 0;
  2751. factor = MPT_ASYNC;
  2752. offset = 0;
  2753. }
  2754. #endif
  2755. if (flags & MPT_SCSICFG_BLK_NEGO)
  2756. negoFlags = MPT_TARGET_NO_NEGO_WIDE | MPT_TARGET_NO_NEGO_SYNC;
  2757. mptscsih_setDevicePage1Flags(width, factor, offset,
  2758. &requested, &configuration, negoFlags);
  2759. dnegoprintk(("writeSDP1: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
  2760. target_id, width, factor, offset, negoFlags, requested, configuration));
  2761. /* Get a MF for this command.
  2762. */
  2763. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  2764. dprintk((MYIOC_s_WARN_FMT "write SDP1: no msg frames!\n",
  2765. ioc->name));
  2766. return -EAGAIN;
  2767. }
  2768. ddvprintk((MYIOC_s_INFO_FMT "WriteSDP1 (mf=%p, id=%d, req=0x%x, cfg=0x%x)\n",
  2769. hd->ioc->name, mf, id, requested, configuration));
  2770. /* Set the request and the data pointers.
  2771. * Request takes: 36 bytes (32 bit SGE)
  2772. * SCSI Device Page 1 requires 16 bytes
  2773. * 40 + 16 <= size of SCSI IO Request = 56 bytes
  2774. * and MF size >= 64 bytes.
  2775. * Place data at end of MF.
  2776. */
  2777. pReq = (Config_t *)mf;
  2778. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2779. frameOffset = ioc->req_sz - sizeof(SCSIDevicePage1_t);
  2780. pData = (SCSIDevicePage1_t *)((u8 *) mf + frameOffset);
  2781. dataDma = ioc->req_frames_dma + (req_idx * ioc->req_sz) + frameOffset;
  2782. /* Complete the request frame (same for all requests).
  2783. */
  2784. pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  2785. pReq->Reserved = 0;
  2786. pReq->ChainOffset = 0;
  2787. pReq->Function = MPI_FUNCTION_CONFIG;
  2788. pReq->ExtPageLength = 0;
  2789. pReq->ExtPageType = 0;
  2790. pReq->MsgFlags = 0;
  2791. for (ii=0; ii < 8; ii++) {
  2792. pReq->Reserved2[ii] = 0;
  2793. }
  2794. pReq->Header.PageVersion = ioc->spi_data.sdp1version;
  2795. pReq->Header.PageLength = ioc->spi_data.sdp1length;
  2796. pReq->Header.PageNumber = 1;
  2797. pReq->Header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  2798. pReq->PageAddress = cpu_to_le32(id | (bus << 8 ));
  2799. /* Add a SGE to the config request.
  2800. */
  2801. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE | ioc->spi_data.sdp1length * 4;
  2802. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
  2803. /* Set up the common data portion
  2804. */
  2805. pData->Header.PageVersion = pReq->Header.PageVersion;
  2806. pData->Header.PageLength = pReq->Header.PageLength;
  2807. pData->Header.PageNumber = pReq->Header.PageNumber;
  2808. pData->Header.PageType = pReq->Header.PageType;
  2809. pData->RequestedParameters = cpu_to_le32(requested);
  2810. pData->Reserved = 0;
  2811. pData->Configuration = cpu_to_le32(configuration);
  2812. dprintk((MYIOC_s_INFO_FMT
  2813. "write SDP1: id %d pgaddr 0x%x req 0x%x config 0x%x\n",
  2814. ioc->name, id, (id | (bus<<8)),
  2815. requested, configuration));
  2816. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  2817. }
  2818. return 0;
  2819. }
  2820. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2821. /* mptscsih_writeIOCPage4 - write IOC Page 4
  2822. * @hd: Pointer to a SCSI Host Structure
  2823. * @target_id: write IOC Page4 for this ID & Bus
  2824. *
  2825. * Return: -EAGAIN if unable to obtain a Message Frame
  2826. * or 0 if success.
  2827. *
  2828. * Remark: We do not wait for a return, write pages sequentially.
  2829. */
  2830. static int
  2831. mptscsih_writeIOCPage4(MPT_SCSI_HOST *hd, int target_id, int bus)
  2832. {
  2833. MPT_ADAPTER *ioc = hd->ioc;
  2834. Config_t *pReq;
  2835. IOCPage4_t *IOCPage4Ptr;
  2836. MPT_FRAME_HDR *mf;
  2837. dma_addr_t dataDma;
  2838. u16 req_idx;
  2839. u32 frameOffset;
  2840. u32 flagsLength;
  2841. int ii;
  2842. /* Get a MF for this command.
  2843. */
  2844. if ((mf = mpt_get_msg_frame(ioc->DoneCtx, ioc)) == NULL) {
  2845. dprintk((MYIOC_s_WARN_FMT "writeIOCPage4 : no msg frames!\n",
  2846. ioc->name));
  2847. return -EAGAIN;
  2848. }
  2849. /* Set the request and the data pointers.
  2850. * Place data at end of MF.
  2851. */
  2852. pReq = (Config_t *)mf;
  2853. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2854. frameOffset = ioc->req_sz - sizeof(IOCPage4_t);
  2855. /* Complete the request frame (same for all requests).
  2856. */
  2857. pReq->Action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  2858. pReq->Reserved = 0;
  2859. pReq->ChainOffset = 0;
  2860. pReq->Function = MPI_FUNCTION_CONFIG;
  2861. pReq->ExtPageLength = 0;
  2862. pReq->ExtPageType = 0;
  2863. pReq->MsgFlags = 0;
  2864. for (ii=0; ii < 8; ii++) {
  2865. pReq->Reserved2[ii] = 0;
  2866. }
  2867. IOCPage4Ptr = ioc->spi_data.pIocPg4;
  2868. dataDma = ioc->spi_data.IocPg4_dma;
  2869. ii = IOCPage4Ptr->ActiveSEP++;
  2870. IOCPage4Ptr->SEP[ii].SEPTargetID = target_id;
  2871. IOCPage4Ptr->SEP[ii].SEPBus = bus;
  2872. pReq->Header = IOCPage4Ptr->Header;
  2873. pReq->PageAddress = cpu_to_le32(target_id | (bus << 8 ));
  2874. /* Add a SGE to the config request.
  2875. */
  2876. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE |
  2877. (IOCPage4Ptr->Header.PageLength + ii) * 4;
  2878. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, dataDma);
  2879. dinitprintk((MYIOC_s_INFO_FMT
  2880. "writeIOCPage4: MaxSEP=%d ActiveSEP=%d id=%d bus=%d\n",
  2881. ioc->name, IOCPage4Ptr->MaxSEP, IOCPage4Ptr->ActiveSEP, target_id, bus));
  2882. mpt_put_msg_frame(ioc->DoneCtx, ioc, mf);
  2883. return 0;
  2884. }
  2885. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2886. /*
  2887. * Bus Scan and Domain Validation functionality ...
  2888. */
  2889. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2890. /*
  2891. * mptscsih_scandv_complete - Scan and DV callback routine registered
  2892. * to Fustion MPT (base) driver.
  2893. *
  2894. * @ioc: Pointer to MPT_ADAPTER structure
  2895. * @mf: Pointer to original MPT request frame
  2896. * @mr: Pointer to MPT reply frame (NULL if TurboReply)
  2897. *
  2898. * This routine is called from mpt.c::mpt_interrupt() at the completion
  2899. * of any SCSI IO request.
  2900. * This routine is registered with the Fusion MPT (base) driver at driver
  2901. * load/init time via the mpt_register() API call.
  2902. *
  2903. * Returns 1 indicating alloc'd request frame ptr should be freed.
  2904. *
  2905. * Remark: Sets a completion code and (possibly) saves sense data
  2906. * in the IOC member localReply structure.
  2907. * Used ONLY for DV and other internal commands.
  2908. */
  2909. int
  2910. mptscsih_scandv_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr)
  2911. {
  2912. MPT_SCSI_HOST *hd;
  2913. SCSIIORequest_t *pReq;
  2914. int completionCode;
  2915. u16 req_idx;
  2916. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  2917. if ((mf == NULL) ||
  2918. (mf >= MPT_INDEX_2_MFPTR(ioc, ioc->req_depth))) {
  2919. printk(MYIOC_s_ERR_FMT
  2920. "ScanDvComplete, %s req frame ptr! (=%p)\n",
  2921. ioc->name, mf?"BAD":"NULL", (void *) mf);
  2922. goto wakeup;
  2923. }
  2924. del_timer(&hd->timer);
  2925. req_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  2926. hd->ScsiLookup[req_idx] = NULL;
  2927. pReq = (SCSIIORequest_t *) mf;
  2928. if (mf != hd->cmdPtr) {
  2929. printk(MYIOC_s_WARN_FMT "ScanDvComplete (mf=%p, cmdPtr=%p, idx=%d)\n",
  2930. hd->ioc->name, (void *)mf, (void *) hd->cmdPtr, req_idx);
  2931. }
  2932. hd->cmdPtr = NULL;
  2933. ddvprintk((MYIOC_s_INFO_FMT "ScanDvComplete (mf=%p,mr=%p,idx=%d)\n",
  2934. hd->ioc->name, mf, mr, req_idx));
  2935. hd->pLocal = &hd->localReply;
  2936. hd->pLocal->scsiStatus = 0;
  2937. /* If target struct exists, clear sense valid flag.
  2938. */
  2939. if (mr == NULL) {
  2940. completionCode = MPT_SCANDV_GOOD;
  2941. } else {
  2942. SCSIIOReply_t *pReply;
  2943. u16 status;
  2944. u8 scsi_status;
  2945. pReply = (SCSIIOReply_t *) mr;
  2946. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  2947. scsi_status = pReply->SCSIStatus;
  2948. ddvtprintk((KERN_NOTICE " IOCStatus=%04xh, SCSIState=%02xh, SCSIStatus=%02xh, IOCLogInfo=%08xh\n",
  2949. status, pReply->SCSIState, scsi_status,
  2950. le32_to_cpu(pReply->IOCLogInfo)));
  2951. switch(status) {
  2952. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  2953. completionCode = MPT_SCANDV_SELECTION_TIMEOUT;
  2954. break;
  2955. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  2956. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  2957. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  2958. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  2959. completionCode = MPT_SCANDV_DID_RESET;
  2960. break;
  2961. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  2962. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  2963. case MPI_IOCSTATUS_SUCCESS: /* 0x0000 */
  2964. if (pReply->Function == MPI_FUNCTION_CONFIG) {
  2965. ConfigReply_t *pr = (ConfigReply_t *)mr;
  2966. completionCode = MPT_SCANDV_GOOD;
  2967. hd->pLocal->header.PageVersion = pr->Header.PageVersion;
  2968. hd->pLocal->header.PageLength = pr->Header.PageLength;
  2969. hd->pLocal->header.PageNumber = pr->Header.PageNumber;
  2970. hd->pLocal->header.PageType = pr->Header.PageType;
  2971. } else if (pReply->Function == MPI_FUNCTION_RAID_ACTION) {
  2972. /* If the RAID Volume request is successful,
  2973. * return GOOD, else indicate that
  2974. * some type of error occurred.
  2975. */
  2976. MpiRaidActionReply_t *pr = (MpiRaidActionReply_t *)mr;
  2977. if (pr->ActionStatus == MPI_RAID_ACTION_ASTATUS_SUCCESS)
  2978. completionCode = MPT_SCANDV_GOOD;
  2979. else
  2980. completionCode = MPT_SCANDV_SOME_ERROR;
  2981. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_VALID) {
  2982. u8 *sense_data;
  2983. int sz;
  2984. /* save sense data in global structure
  2985. */
  2986. completionCode = MPT_SCANDV_SENSE;
  2987. hd->pLocal->scsiStatus = scsi_status;
  2988. sense_data = ((u8 *)hd->ioc->sense_buf_pool +
  2989. (req_idx * MPT_SENSE_BUFFER_ALLOC));
  2990. sz = min_t(int, pReq->SenseBufferLength,
  2991. SCSI_STD_SENSE_BYTES);
  2992. memcpy(hd->pLocal->sense, sense_data, sz);
  2993. ddvprintk((KERN_NOTICE " Check Condition, sense ptr %p\n",
  2994. sense_data));
  2995. } else if (pReply->SCSIState & MPI_SCSI_STATE_AUTOSENSE_FAILED) {
  2996. if (pReq->CDB[0] == INQUIRY)
  2997. completionCode = MPT_SCANDV_ISSUE_SENSE;
  2998. else
  2999. completionCode = MPT_SCANDV_DID_RESET;
  3000. }
  3001. else if (pReply->SCSIState & MPI_SCSI_STATE_NO_SCSI_STATUS)
  3002. completionCode = MPT_SCANDV_DID_RESET;
  3003. else if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  3004. completionCode = MPT_SCANDV_DID_RESET;
  3005. else {
  3006. completionCode = MPT_SCANDV_GOOD;
  3007. hd->pLocal->scsiStatus = scsi_status;
  3008. }
  3009. break;
  3010. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  3011. if (pReply->SCSIState & MPI_SCSI_STATE_TERMINATED)
  3012. completionCode = MPT_SCANDV_DID_RESET;
  3013. else
  3014. completionCode = MPT_SCANDV_SOME_ERROR;
  3015. break;
  3016. default:
  3017. completionCode = MPT_SCANDV_SOME_ERROR;
  3018. break;
  3019. } /* switch(status) */
  3020. ddvtprintk((KERN_NOTICE " completionCode set to %08xh\n",
  3021. completionCode));
  3022. } /* end of address reply case */
  3023. hd->pLocal->completion = completionCode;
  3024. /* MF and RF are freed in mpt_interrupt
  3025. */
  3026. wakeup:
  3027. /* Free Chain buffers (will never chain) in scan or dv */
  3028. //mptscsih_freeChainBuffers(ioc, req_idx);
  3029. /*
  3030. * Wake up the original calling thread
  3031. */
  3032. hd->scandv_wait_done = 1;
  3033. wake_up(&hd->scandv_waitq);
  3034. return 1;
  3035. }
  3036. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3037. /* mptscsih_timer_expired - Call back for timer process.
  3038. * Used only for dv functionality.
  3039. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  3040. *
  3041. */
  3042. void
  3043. mptscsih_timer_expired(unsigned long data)
  3044. {
  3045. MPT_SCSI_HOST *hd = (MPT_SCSI_HOST *) data;
  3046. ddvprintk((MYIOC_s_WARN_FMT "Timer Expired! Cmd %p\n", hd->ioc->name, hd->cmdPtr));
  3047. if (hd->cmdPtr) {
  3048. MPIHeader_t *cmd = (MPIHeader_t *)hd->cmdPtr;
  3049. if (cmd->Function == MPI_FUNCTION_SCSI_IO_REQUEST) {
  3050. /* Desire to issue a task management request here.
  3051. * TM requests MUST be single threaded.
  3052. * If old eh code and no TM current, issue request.
  3053. * If new eh code, do nothing. Wait for OS cmd timeout
  3054. * for bus reset.
  3055. */
  3056. ddvtprintk((MYIOC_s_NOTE_FMT "DV Cmd Timeout: NoOp\n", hd->ioc->name));
  3057. } else {
  3058. /* Perform a FW reload */
  3059. if (mpt_HardResetHandler(hd->ioc, NO_SLEEP) < 0) {
  3060. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", hd->ioc->name);
  3061. }
  3062. }
  3063. } else {
  3064. /* This should NEVER happen */
  3065. printk(MYIOC_s_WARN_FMT "Null cmdPtr!!!!\n", hd->ioc->name);
  3066. }
  3067. /* No more processing.
  3068. * TM call will generate an interrupt for SCSI TM Management.
  3069. * The FW will reply to all outstanding commands, callback will finish cleanup.
  3070. * Hard reset clean-up will free all resources.
  3071. */
  3072. ddvprintk((MYIOC_s_WARN_FMT "Timer Expired Complete!\n", hd->ioc->name));
  3073. return;
  3074. }
  3075. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  3076. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3077. /* mptscsih_do_raid - Format and Issue a RAID volume request message.
  3078. * @hd: Pointer to scsi host structure
  3079. * @action: What do be done.
  3080. * @id: Logical target id.
  3081. * @bus: Target locations bus.
  3082. *
  3083. * Returns: < 0 on a fatal error
  3084. * 0 on success
  3085. *
  3086. * Remark: Wait to return until reply processed by the ISR.
  3087. */
  3088. static int
  3089. mptscsih_do_raid(MPT_SCSI_HOST *hd, u8 action, INTERNAL_CMD *io)
  3090. {
  3091. MpiRaidActionRequest_t *pReq;
  3092. MPT_FRAME_HDR *mf;
  3093. int in_isr;
  3094. in_isr = in_interrupt();
  3095. if (in_isr) {
  3096. dprintk((MYIOC_s_WARN_FMT "Internal raid request not allowed in ISR context!\n",
  3097. hd->ioc->name));
  3098. return -EPERM;
  3099. }
  3100. /* Get and Populate a free Frame
  3101. */
  3102. if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
  3103. ddvprintk((MYIOC_s_WARN_FMT "_do_raid: no msg frames!\n",
  3104. hd->ioc->name));
  3105. return -EAGAIN;
  3106. }
  3107. pReq = (MpiRaidActionRequest_t *)mf;
  3108. pReq->Action = action;
  3109. pReq->Reserved1 = 0;
  3110. pReq->ChainOffset = 0;
  3111. pReq->Function = MPI_FUNCTION_RAID_ACTION;
  3112. pReq->VolumeID = io->id;
  3113. pReq->VolumeBus = io->bus;
  3114. pReq->PhysDiskNum = io->physDiskNum;
  3115. pReq->MsgFlags = 0;
  3116. pReq->Reserved2 = 0;
  3117. pReq->ActionDataWord = 0; /* Reserved for this action */
  3118. //pReq->ActionDataSGE = 0;
  3119. mpt_add_sge((char *)&pReq->ActionDataSGE,
  3120. MPT_SGE_FLAGS_SSIMPLE_READ | 0, (dma_addr_t) -1);
  3121. ddvprintk((MYIOC_s_INFO_FMT "RAID Volume action %x id %d\n",
  3122. hd->ioc->name, action, io->id));
  3123. hd->pLocal = NULL;
  3124. hd->timer.expires = jiffies + HZ*10; /* 10 second timeout */
  3125. hd->scandv_wait_done = 0;
  3126. /* Save cmd pointer, for resource free if timeout or
  3127. * FW reload occurs
  3128. */
  3129. hd->cmdPtr = mf;
  3130. add_timer(&hd->timer);
  3131. mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
  3132. wait_event(hd->scandv_waitq, hd->scandv_wait_done);
  3133. if ((hd->pLocal == NULL) || (hd->pLocal->completion != MPT_SCANDV_GOOD))
  3134. return -1;
  3135. return 0;
  3136. }
  3137. #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */
  3138. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3139. /**
  3140. * mptscsih_do_cmd - Do internal command.
  3141. * @hd: MPT_SCSI_HOST pointer
  3142. * @io: INTERNAL_CMD pointer.
  3143. *
  3144. * Issue the specified internally generated command and do command
  3145. * specific cleanup. For bus scan / DV only.
  3146. * NOTES: If command is Inquiry and status is good,
  3147. * initialize a target structure, save the data
  3148. *
  3149. * Remark: Single threaded access only.
  3150. *
  3151. * Return:
  3152. * < 0 if an illegal command or no resources
  3153. *
  3154. * 0 if good
  3155. *
  3156. * > 0 if command complete but some type of completion error.
  3157. */
  3158. static int
  3159. mptscsih_do_cmd(MPT_SCSI_HOST *hd, INTERNAL_CMD *io)
  3160. {
  3161. MPT_FRAME_HDR *mf;
  3162. SCSIIORequest_t *pScsiReq;
  3163. SCSIIORequest_t ReqCopy;
  3164. int my_idx, ii, dir;
  3165. int rc, cmdTimeout;
  3166. int in_isr;
  3167. char cmdLen;
  3168. char CDB[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  3169. char cmd = io->cmd;
  3170. in_isr = in_interrupt();
  3171. if (in_isr) {
  3172. dprintk((MYIOC_s_WARN_FMT "Internal SCSI IO request not allowed in ISR context!\n",
  3173. hd->ioc->name));
  3174. return -EPERM;
  3175. }
  3176. /* Set command specific information
  3177. */
  3178. switch (cmd) {
  3179. case INQUIRY:
  3180. cmdLen = 6;
  3181. dir = MPI_SCSIIO_CONTROL_READ;
  3182. CDB[0] = cmd;
  3183. CDB[4] = io->size;
  3184. cmdTimeout = 10;
  3185. break;
  3186. case TEST_UNIT_READY:
  3187. cmdLen = 6;
  3188. dir = MPI_SCSIIO_CONTROL_READ;
  3189. cmdTimeout = 10;
  3190. break;
  3191. case START_STOP:
  3192. cmdLen = 6;
  3193. dir = MPI_SCSIIO_CONTROL_READ;
  3194. CDB[0] = cmd;
  3195. CDB[4] = 1; /*Spin up the disk */
  3196. cmdTimeout = 15;
  3197. break;
  3198. case REQUEST_SENSE:
  3199. cmdLen = 6;
  3200. CDB[0] = cmd;
  3201. CDB[4] = io->size;
  3202. dir = MPI_SCSIIO_CONTROL_READ;
  3203. cmdTimeout = 10;
  3204. break;
  3205. case READ_BUFFER:
  3206. cmdLen = 10;
  3207. dir = MPI_SCSIIO_CONTROL_READ;
  3208. CDB[0] = cmd;
  3209. if (io->flags & MPT_ICFLAG_ECHO) {
  3210. CDB[1] = 0x0A;
  3211. } else {
  3212. CDB[1] = 0x02;
  3213. }
  3214. if (io->flags & MPT_ICFLAG_BUF_CAP) {
  3215. CDB[1] |= 0x01;
  3216. }
  3217. CDB[6] = (io->size >> 16) & 0xFF;
  3218. CDB[7] = (io->size >> 8) & 0xFF;
  3219. CDB[8] = io->size & 0xFF;
  3220. cmdTimeout = 10;
  3221. break;
  3222. case WRITE_BUFFER:
  3223. cmdLen = 10;
  3224. dir = MPI_SCSIIO_CONTROL_WRITE;
  3225. CDB[0] = cmd;
  3226. if (io->flags & MPT_ICFLAG_ECHO) {
  3227. CDB[1] = 0x0A;
  3228. } else {
  3229. CDB[1] = 0x02;
  3230. }
  3231. CDB[6] = (io->size >> 16) & 0xFF;
  3232. CDB[7] = (io->size >> 8) & 0xFF;
  3233. CDB[8] = io->size & 0xFF;
  3234. cmdTimeout = 10;
  3235. break;
  3236. case RESERVE:
  3237. cmdLen = 6;
  3238. dir = MPI_SCSIIO_CONTROL_READ;
  3239. CDB[0] = cmd;
  3240. cmdTimeout = 10;
  3241. break;
  3242. case RELEASE:
  3243. cmdLen = 6;
  3244. dir = MPI_SCSIIO_CONTROL_READ;
  3245. CDB[0] = cmd;
  3246. cmdTimeout = 10;
  3247. break;
  3248. case SYNCHRONIZE_CACHE:
  3249. cmdLen = 10;
  3250. dir = MPI_SCSIIO_CONTROL_READ;
  3251. CDB[0] = cmd;
  3252. // CDB[1] = 0x02; /* set immediate bit */
  3253. cmdTimeout = 10;
  3254. break;
  3255. default:
  3256. /* Error Case */
  3257. return -EFAULT;
  3258. }
  3259. /* Get and Populate a free Frame
  3260. */
  3261. if ((mf = mpt_get_msg_frame(hd->ioc->InternalCtx, hd->ioc)) == NULL) {
  3262. ddvprintk((MYIOC_s_WARN_FMT "No msg frames!\n",
  3263. hd->ioc->name));
  3264. return -EBUSY;
  3265. }
  3266. pScsiReq = (SCSIIORequest_t *) mf;
  3267. /* Get the request index */
  3268. my_idx = le16_to_cpu(mf->u.frame.hwhdr.msgctxu.fld.req_idx);
  3269. ADD_INDEX_LOG(my_idx); /* for debug */
  3270. if (io->flags & MPT_ICFLAG_PHYS_DISK) {
  3271. pScsiReq->TargetID = io->physDiskNum;
  3272. pScsiReq->Bus = 0;
  3273. pScsiReq->ChainOffset = 0;
  3274. pScsiReq->Function = MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  3275. } else {
  3276. pScsiReq->TargetID = io->id;
  3277. pScsiReq->Bus = io->bus;
  3278. pScsiReq->ChainOffset = 0;
  3279. pScsiReq->Function = MPI_FUNCTION_SCSI_IO_REQUEST;
  3280. }
  3281. pScsiReq->CDBLength = cmdLen;
  3282. pScsiReq->SenseBufferLength = MPT_SENSE_BUFFER_SIZE;
  3283. pScsiReq->Reserved = 0;
  3284. pScsiReq->MsgFlags = mpt_msg_flags();
  3285. /* MsgContext set in mpt_get_msg_fram call */
  3286. for (ii=0; ii < 8; ii++)
  3287. pScsiReq->LUN[ii] = 0;
  3288. pScsiReq->LUN[1] = io->lun;
  3289. if (io->flags & MPT_ICFLAG_TAGGED_CMD)
  3290. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_SIMPLEQ);
  3291. else
  3292. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  3293. if (cmd == REQUEST_SENSE) {
  3294. pScsiReq->Control = cpu_to_le32(dir | MPI_SCSIIO_CONTROL_UNTAGGED);
  3295. ddvprintk((MYIOC_s_INFO_FMT "Untagged! 0x%2x\n",
  3296. hd->ioc->name, cmd));
  3297. }
  3298. for (ii=0; ii < 16; ii++)
  3299. pScsiReq->CDB[ii] = CDB[ii];
  3300. pScsiReq->DataLength = cpu_to_le32(io->size);
  3301. pScsiReq->SenseBufferLowAddr = cpu_to_le32(hd->ioc->sense_buf_low_dma
  3302. + (my_idx * MPT_SENSE_BUFFER_ALLOC));
  3303. ddvprintk((MYIOC_s_INFO_FMT "Sending Command 0x%x for (%d:%d:%d)\n",
  3304. hd->ioc->name, cmd, io->bus, io->id, io->lun));
  3305. if (dir == MPI_SCSIIO_CONTROL_READ) {
  3306. mpt_add_sge((char *) &pScsiReq->SGL,
  3307. MPT_SGE_FLAGS_SSIMPLE_READ | io->size,
  3308. io->data_dma);
  3309. } else {
  3310. mpt_add_sge((char *) &pScsiReq->SGL,
  3311. MPT_SGE_FLAGS_SSIMPLE_WRITE | io->size,
  3312. io->data_dma);
  3313. }
  3314. /* The ISR will free the request frame, but we need
  3315. * the information to initialize the target. Duplicate.
  3316. */
  3317. memcpy(&ReqCopy, pScsiReq, sizeof(SCSIIORequest_t));
  3318. /* Issue this command after:
  3319. * finish init
  3320. * add timer
  3321. * Wait until the reply has been received
  3322. * ScsiScanDvCtx callback function will
  3323. * set hd->pLocal;
  3324. * set scandv_wait_done and call wake_up
  3325. */
  3326. hd->pLocal = NULL;
  3327. hd->timer.expires = jiffies + HZ*cmdTimeout;
  3328. hd->scandv_wait_done = 0;
  3329. /* Save cmd pointer, for resource free if timeout or
  3330. * FW reload occurs
  3331. */
  3332. hd->cmdPtr = mf;
  3333. add_timer(&hd->timer);
  3334. mpt_put_msg_frame(hd->ioc->InternalCtx, hd->ioc, mf);
  3335. wait_event(hd->scandv_waitq, hd->scandv_wait_done);
  3336. if (hd->pLocal) {
  3337. rc = hd->pLocal->completion;
  3338. hd->pLocal->skip = 0;
  3339. /* Always set fatal error codes in some cases.
  3340. */
  3341. if (rc == MPT_SCANDV_SELECTION_TIMEOUT)
  3342. rc = -ENXIO;
  3343. else if (rc == MPT_SCANDV_SOME_ERROR)
  3344. rc = -rc;
  3345. } else {
  3346. rc = -EFAULT;
  3347. /* This should never happen. */
  3348. ddvprintk((MYIOC_s_INFO_FMT "_do_cmd: Null pLocal!!!\n",
  3349. hd->ioc->name));
  3350. }
  3351. return rc;
  3352. }
  3353. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3354. /**
  3355. * mptscsih_synchronize_cache - Send SYNCHRONIZE_CACHE to all disks.
  3356. * @hd: Pointer to MPT_SCSI_HOST structure
  3357. * @portnum: IOC port number
  3358. *
  3359. * Uses the ISR, but with special processing.
  3360. * MUST be single-threaded.
  3361. *
  3362. * Return: 0 on completion
  3363. */
  3364. static int
  3365. mptscsih_synchronize_cache(MPT_SCSI_HOST *hd, int portnum)
  3366. {
  3367. MPT_ADAPTER *ioc= hd->ioc;
  3368. VirtDevice *pTarget;
  3369. SCSIDevicePage1_t *pcfg1Data = NULL;
  3370. INTERNAL_CMD iocmd;
  3371. CONFIGPARMS cfg;
  3372. dma_addr_t cfg1_dma_addr = -1;
  3373. ConfigPageHeader_t header1;
  3374. int bus = 0;
  3375. int id = 0;
  3376. int lun;
  3377. int indexed_lun, lun_index;
  3378. int hostId = ioc->pfacts[portnum].PortSCSIID;
  3379. int max_id;
  3380. int requested, configuration, data;
  3381. int doConfig = 0;
  3382. u8 flags, factor;
  3383. max_id = ioc->sh->max_id - 1;
  3384. /* Following parameters will not change
  3385. * in this routine.
  3386. */
  3387. iocmd.cmd = SYNCHRONIZE_CACHE;
  3388. iocmd.flags = 0;
  3389. iocmd.physDiskNum = -1;
  3390. iocmd.data = NULL;
  3391. iocmd.data_dma = -1;
  3392. iocmd.size = 0;
  3393. iocmd.rsvd = iocmd.rsvd2 = 0;
  3394. /* No SCSI hosts
  3395. */
  3396. if (hd->Targets == NULL)
  3397. return 0;
  3398. /* Skip the host
  3399. */
  3400. if (id == hostId)
  3401. id++;
  3402. /* Write SDP1 for all SCSI devices
  3403. * Alloc memory and set up config buffer
  3404. */
  3405. if (ioc->bus_type == SCSI) {
  3406. if (ioc->spi_data.sdp1length > 0) {
  3407. pcfg1Data = (SCSIDevicePage1_t *)pci_alloc_consistent(ioc->pcidev,
  3408. ioc->spi_data.sdp1length * 4, &cfg1_dma_addr);
  3409. if (pcfg1Data != NULL) {
  3410. doConfig = 1;
  3411. header1.PageVersion = ioc->spi_data.sdp1version;
  3412. header1.PageLength = ioc->spi_data.sdp1length;
  3413. header1.PageNumber = 1;
  3414. header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3415. cfg.hdr = &header1;
  3416. cfg.physAddr = cfg1_dma_addr;
  3417. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3418. cfg.dir = 1;
  3419. cfg.timeout = 0;
  3420. }
  3421. }
  3422. }
  3423. /* loop through all devices on this port
  3424. */
  3425. while (bus < MPT_MAX_BUS) {
  3426. iocmd.bus = bus;
  3427. iocmd.id = id;
  3428. pTarget = hd->Targets[(int)id];
  3429. if (doConfig) {
  3430. /* Set the negotiation flags */
  3431. if (pTarget && (pTarget = hd->Targets[id]) && !pTarget->raidVolume) {
  3432. flags = pTarget->negoFlags;
  3433. } else {
  3434. flags = hd->ioc->spi_data.noQas;
  3435. if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  3436. data = hd->ioc->spi_data.nvram[id];
  3437. if (data & MPT_NVRAM_WIDE_DISABLE)
  3438. flags |= MPT_TARGET_NO_NEGO_WIDE;
  3439. factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
  3440. if ((factor == 0) || (factor == MPT_ASYNC))
  3441. flags |= MPT_TARGET_NO_NEGO_SYNC;
  3442. }
  3443. }
  3444. /* Force to async, narrow */
  3445. mptscsih_setDevicePage1Flags(0, MPT_ASYNC, 0, &requested,
  3446. &configuration, flags);
  3447. dnegoprintk(("syncronize cache: id=%d width=0 factor=MPT_ASYNC "
  3448. "offset=0 negoFlags=%x request=%x config=%x\n",
  3449. id, flags, requested, configuration));
  3450. pcfg1Data->RequestedParameters = le32_to_cpu(requested);
  3451. pcfg1Data->Reserved = 0;
  3452. pcfg1Data->Configuration = le32_to_cpu(configuration);
  3453. cfg.pageAddr = (bus<<8) | id;
  3454. mpt_config(hd->ioc, &cfg);
  3455. }
  3456. /* If target Ptr NULL or if this target is NOT a disk, skip.
  3457. */
  3458. if ((pTarget) && (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)){
  3459. for (lun=0; lun <= MPT_LAST_LUN; lun++) {
  3460. /* If LUN present, issue the command
  3461. */
  3462. lun_index = (lun >> 5); /* 32 luns per lun_index */
  3463. indexed_lun = (lun % 32);
  3464. if (pTarget->luns[lun_index] & (1<<indexed_lun)) {
  3465. iocmd.lun = lun;
  3466. (void) mptscsih_do_cmd(hd, &iocmd);
  3467. }
  3468. }
  3469. }
  3470. /* get next relevant device */
  3471. id++;
  3472. if (id == hostId)
  3473. id++;
  3474. if (id > max_id) {
  3475. id = 0;
  3476. bus++;
  3477. }
  3478. }
  3479. if (pcfg1Data) {
  3480. pci_free_consistent(ioc->pcidev, header1.PageLength * 4, pcfg1Data, cfg1_dma_addr);
  3481. }
  3482. return 0;
  3483. }
  3484. #ifdef MPTSCSIH_ENABLE_DOMAIN_VALIDATION
  3485. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3486. /**
  3487. * mptscsih_domainValidation - Top level handler for domain validation.
  3488. * @hd: Pointer to MPT_SCSI_HOST structure.
  3489. *
  3490. * Uses the ISR, but with special processing.
  3491. * Called from schedule, should not be in interrupt mode.
  3492. * While thread alive, do dv for all devices needing dv
  3493. *
  3494. * Return: None.
  3495. */
  3496. static void
  3497. mptscsih_domainValidation(void *arg)
  3498. {
  3499. MPT_SCSI_HOST *hd;
  3500. MPT_ADAPTER *ioc;
  3501. unsigned long flags;
  3502. int id, maxid, dvStatus, did;
  3503. int ii, isPhysDisk;
  3504. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3505. dvtaskQ_active = 1;
  3506. if (dvtaskQ_release) {
  3507. dvtaskQ_active = 0;
  3508. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3509. return;
  3510. }
  3511. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3512. /* For this ioc, loop through all devices and do dv to each device.
  3513. * When complete with this ioc, search through the ioc list, and
  3514. * for each scsi ioc found, do dv for all devices. Exit when no
  3515. * device needs dv.
  3516. */
  3517. did = 1;
  3518. while (did) {
  3519. did = 0;
  3520. list_for_each_entry(ioc, &ioc_list, list) {
  3521. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3522. if (dvtaskQ_release) {
  3523. dvtaskQ_active = 0;
  3524. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3525. return;
  3526. }
  3527. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3528. msleep(250);
  3529. /* DV only to SCSI adapters */
  3530. if (ioc->bus_type != SCSI)
  3531. continue;
  3532. /* Make sure everything looks ok */
  3533. if (ioc->sh == NULL)
  3534. continue;
  3535. hd = (MPT_SCSI_HOST *) ioc->sh->hostdata;
  3536. if (hd == NULL)
  3537. continue;
  3538. if ((ioc->spi_data.forceDv & MPT_SCSICFG_RELOAD_IOC_PG3) != 0) {
  3539. mpt_read_ioc_pg_3(ioc);
  3540. if (ioc->spi_data.pIocPg3) {
  3541. Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk;
  3542. int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks;
  3543. while (numPDisk) {
  3544. if (ioc->spi_data.dvStatus[pPDisk->PhysDiskID] & MPT_SCSICFG_DV_NOT_DONE)
  3545. ioc->spi_data.dvStatus[pPDisk->PhysDiskID] |= MPT_SCSICFG_NEED_DV;
  3546. pPDisk++;
  3547. numPDisk--;
  3548. }
  3549. }
  3550. ioc->spi_data.forceDv &= ~MPT_SCSICFG_RELOAD_IOC_PG3;
  3551. }
  3552. maxid = min_t(int, ioc->sh->max_id, MPT_MAX_SCSI_DEVICES);
  3553. for (id = 0; id < maxid; id++) {
  3554. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3555. if (dvtaskQ_release) {
  3556. dvtaskQ_active = 0;
  3557. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3558. return;
  3559. }
  3560. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3561. dvStatus = hd->ioc->spi_data.dvStatus[id];
  3562. if (dvStatus & MPT_SCSICFG_NEED_DV) {
  3563. did++;
  3564. hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_DV_PENDING;
  3565. hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_NEED_DV;
  3566. msleep(250);
  3567. /* If hidden phys disk, block IO's to all
  3568. * raid volumes
  3569. * else, process normally
  3570. */
  3571. isPhysDisk = mptscsih_is_phys_disk(ioc, id);
  3572. if (isPhysDisk) {
  3573. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3574. if (hd->ioc->spi_data.isRaid & (1 << ii)) {
  3575. hd->ioc->spi_data.dvStatus[ii] |= MPT_SCSICFG_DV_PENDING;
  3576. }
  3577. }
  3578. }
  3579. if (mptscsih_doDv(hd, 0, id) == 1) {
  3580. /* Untagged device was busy, try again
  3581. */
  3582. hd->ioc->spi_data.dvStatus[id] |= MPT_SCSICFG_NEED_DV;
  3583. hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_PENDING;
  3584. } else {
  3585. /* DV is complete. Clear flags.
  3586. */
  3587. hd->ioc->spi_data.dvStatus[id] &= ~(MPT_SCSICFG_DV_NOT_DONE | MPT_SCSICFG_DV_PENDING);
  3588. }
  3589. if (isPhysDisk) {
  3590. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3591. if (hd->ioc->spi_data.isRaid & (1 << ii)) {
  3592. hd->ioc->spi_data.dvStatus[ii] &= ~MPT_SCSICFG_DV_PENDING;
  3593. }
  3594. }
  3595. }
  3596. if (hd->ioc->spi_data.noQas)
  3597. mptscsih_qas_check(hd, id);
  3598. }
  3599. }
  3600. }
  3601. }
  3602. spin_lock_irqsave(&dvtaskQ_lock, flags);
  3603. dvtaskQ_active = 0;
  3604. spin_unlock_irqrestore(&dvtaskQ_lock, flags);
  3605. return;
  3606. }
  3607. /* Search IOC page 3 to determine if this is hidden physical disk
  3608. */
  3609. static int
  3610. mptscsih_is_phys_disk(MPT_ADAPTER *ioc, int id)
  3611. {
  3612. if (ioc->spi_data.pIocPg3) {
  3613. Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk;
  3614. int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks;
  3615. while (numPDisk) {
  3616. if (pPDisk->PhysDiskID == id) {
  3617. return 1;
  3618. }
  3619. pPDisk++;
  3620. numPDisk--;
  3621. }
  3622. }
  3623. return 0;
  3624. }
  3625. /* Write SDP1 if no QAS has been enabled
  3626. */
  3627. static void
  3628. mptscsih_qas_check(MPT_SCSI_HOST *hd, int id)
  3629. {
  3630. VirtDevice *pTarget;
  3631. int ii;
  3632. if (hd->Targets == NULL)
  3633. return;
  3634. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3635. if (ii == id)
  3636. continue;
  3637. if ((hd->ioc->spi_data.dvStatus[ii] & MPT_SCSICFG_DV_NOT_DONE) != 0)
  3638. continue;
  3639. pTarget = hd->Targets[ii];
  3640. if ((pTarget != NULL) && (!pTarget->raidVolume)) {
  3641. if ((pTarget->negoFlags & hd->ioc->spi_data.noQas) == 0) {
  3642. pTarget->negoFlags |= hd->ioc->spi_data.noQas;
  3643. dnegoprintk(("writeSDP1: id=%d flags=0\n", id));
  3644. mptscsih_writeSDP1(hd, 0, ii, 0);
  3645. }
  3646. } else {
  3647. if (mptscsih_is_phys_disk(hd->ioc, ii) == 1) {
  3648. dnegoprintk(("writeSDP1: id=%d SCSICFG_USE_NVRAM\n", id));
  3649. mptscsih_writeSDP1(hd, 0, ii, MPT_SCSICFG_USE_NVRAM);
  3650. }
  3651. }
  3652. }
  3653. return;
  3654. }
  3655. #define MPT_GET_NVRAM_VALS 0x01
  3656. #define MPT_UPDATE_MAX 0x02
  3657. #define MPT_SET_MAX 0x04
  3658. #define MPT_SET_MIN 0x08
  3659. #define MPT_FALLBACK 0x10
  3660. #define MPT_SAVE 0x20
  3661. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3662. /**
  3663. * mptscsih_doDv - Perform domain validation to a target.
  3664. * @hd: Pointer to MPT_SCSI_HOST structure.
  3665. * @portnum: IOC port number.
  3666. * @target: Physical ID of this target
  3667. *
  3668. * Uses the ISR, but with special processing.
  3669. * MUST be single-threaded.
  3670. * Test will exit if target is at async & narrow.
  3671. *
  3672. * Return: None.
  3673. */
  3674. static int
  3675. mptscsih_doDv(MPT_SCSI_HOST *hd, int bus_number, int id)
  3676. {
  3677. MPT_ADAPTER *ioc = hd->ioc;
  3678. VirtDevice *pTarget;
  3679. SCSIDevicePage1_t *pcfg1Data;
  3680. SCSIDevicePage0_t *pcfg0Data;
  3681. u8 *pbuf1;
  3682. u8 *pbuf2;
  3683. u8 *pDvBuf;
  3684. dma_addr_t dvbuf_dma = -1;
  3685. dma_addr_t buf1_dma = -1;
  3686. dma_addr_t buf2_dma = -1;
  3687. dma_addr_t cfg1_dma_addr = -1;
  3688. dma_addr_t cfg0_dma_addr = -1;
  3689. ConfigPageHeader_t header1;
  3690. ConfigPageHeader_t header0;
  3691. DVPARAMETERS dv;
  3692. INTERNAL_CMD iocmd;
  3693. CONFIGPARMS cfg;
  3694. int dv_alloc = 0;
  3695. int rc, sz = 0;
  3696. int bufsize = 0;
  3697. int dataBufSize = 0;
  3698. int echoBufSize = 0;
  3699. int notDone;
  3700. int patt;
  3701. int repeat;
  3702. int retcode = 0;
  3703. int nfactor = MPT_ULTRA320;
  3704. char firstPass = 1;
  3705. char doFallback = 0;
  3706. char readPage0;
  3707. char bus, lun;
  3708. char inq0 = 0;
  3709. if (ioc->spi_data.sdp1length == 0)
  3710. return 0;
  3711. if (ioc->spi_data.sdp0length == 0)
  3712. return 0;
  3713. /* If multiple buses are used, require that the initiator
  3714. * id be the same on all buses.
  3715. */
  3716. if (id == ioc->pfacts[0].PortSCSIID)
  3717. return 0;
  3718. lun = 0;
  3719. bus = (u8) bus_number;
  3720. ddvtprintk((MYIOC_s_NOTE_FMT
  3721. "DV started: bus=%d, id=%d dv @ %p\n",
  3722. ioc->name, bus, id, &dv));
  3723. /* Prep DV structure
  3724. */
  3725. memset (&dv, 0, sizeof(DVPARAMETERS));
  3726. dv.id = id;
  3727. /* Populate tmax with the current maximum
  3728. * transfer parameters for this target.
  3729. * Exit if narrow and async.
  3730. */
  3731. dv.cmd = MPT_GET_NVRAM_VALS;
  3732. mptscsih_dv_parms(hd, &dv, NULL);
  3733. /* Prep SCSI IO structure
  3734. */
  3735. iocmd.id = id;
  3736. iocmd.bus = bus;
  3737. iocmd.lun = lun;
  3738. iocmd.flags = 0;
  3739. iocmd.physDiskNum = -1;
  3740. iocmd.rsvd = iocmd.rsvd2 = 0;
  3741. pTarget = hd->Targets[id];
  3742. /* Use tagged commands if possible.
  3743. */
  3744. if (pTarget) {
  3745. if (pTarget->tflags & MPT_TARGET_FLAGS_Q_YES)
  3746. iocmd.flags |= MPT_ICFLAG_TAGGED_CMD;
  3747. else {
  3748. if (hd->ioc->facts.FWVersion.Word < 0x01000600)
  3749. return 0;
  3750. if ((hd->ioc->facts.FWVersion.Word >= 0x01010000) &&
  3751. (hd->ioc->facts.FWVersion.Word < 0x01010B00))
  3752. return 0;
  3753. }
  3754. }
  3755. /* Prep cfg structure
  3756. */
  3757. cfg.pageAddr = (bus<<8) | id;
  3758. cfg.hdr = NULL;
  3759. /* Prep SDP0 header
  3760. */
  3761. header0.PageVersion = ioc->spi_data.sdp0version;
  3762. header0.PageLength = ioc->spi_data.sdp0length;
  3763. header0.PageNumber = 0;
  3764. header0.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3765. /* Prep SDP1 header
  3766. */
  3767. header1.PageVersion = ioc->spi_data.sdp1version;
  3768. header1.PageLength = ioc->spi_data.sdp1length;
  3769. header1.PageNumber = 1;
  3770. header1.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  3771. if (header0.PageLength & 1)
  3772. dv_alloc = (header0.PageLength * 4) + 4;
  3773. dv_alloc += (2048 + (header1.PageLength * 4));
  3774. pDvBuf = pci_alloc_consistent(ioc->pcidev, dv_alloc, &dvbuf_dma);
  3775. if (pDvBuf == NULL)
  3776. return 0;
  3777. sz = 0;
  3778. pbuf1 = (u8 *)pDvBuf;
  3779. buf1_dma = dvbuf_dma;
  3780. sz +=1024;
  3781. pbuf2 = (u8 *) (pDvBuf + sz);
  3782. buf2_dma = dvbuf_dma + sz;
  3783. sz +=1024;
  3784. pcfg0Data = (SCSIDevicePage0_t *) (pDvBuf + sz);
  3785. cfg0_dma_addr = dvbuf_dma + sz;
  3786. sz += header0.PageLength * 4;
  3787. /* 8-byte alignment
  3788. */
  3789. if (header0.PageLength & 1)
  3790. sz += 4;
  3791. pcfg1Data = (SCSIDevicePage1_t *) (pDvBuf + sz);
  3792. cfg1_dma_addr = dvbuf_dma + sz;
  3793. /* Skip this ID? Set cfg.hdr to force config page write
  3794. */
  3795. {
  3796. ScsiCfgData *pspi_data = &hd->ioc->spi_data;
  3797. if (pspi_data->nvram && (pspi_data->nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  3798. /* Set the factor from nvram */
  3799. nfactor = (pspi_data->nvram[id] & MPT_NVRAM_SYNC_MASK) >> 8;
  3800. if (nfactor < pspi_data->minSyncFactor )
  3801. nfactor = pspi_data->minSyncFactor;
  3802. if (!(pspi_data->nvram[id] & MPT_NVRAM_ID_SCAN_ENABLE) ||
  3803. (pspi_data->PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_OFF_DV) ) {
  3804. ddvprintk((MYIOC_s_NOTE_FMT "DV Skipped: bus, id, lun (%d, %d, %d)\n",
  3805. ioc->name, bus, id, lun));
  3806. dv.cmd = MPT_SET_MAX;
  3807. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  3808. cfg.hdr = &header1;
  3809. /* Save the final negotiated settings to
  3810. * SCSI device page 1.
  3811. */
  3812. cfg.physAddr = cfg1_dma_addr;
  3813. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3814. cfg.dir = 1;
  3815. mpt_config(hd->ioc, &cfg);
  3816. goto target_done;
  3817. }
  3818. }
  3819. }
  3820. /* Finish iocmd inititialization - hidden or visible disk? */
  3821. if (ioc->spi_data.pIocPg3) {
  3822. /* Search IOC page 3 for matching id
  3823. */
  3824. Ioc3PhysDisk_t *pPDisk = ioc->spi_data.pIocPg3->PhysDisk;
  3825. int numPDisk = ioc->spi_data.pIocPg3->NumPhysDisks;
  3826. while (numPDisk) {
  3827. if (pPDisk->PhysDiskID == id) {
  3828. /* match */
  3829. iocmd.flags |= MPT_ICFLAG_PHYS_DISK;
  3830. iocmd.physDiskNum = pPDisk->PhysDiskNum;
  3831. /* Quiesce the IM
  3832. */
  3833. if (mptscsih_do_raid(hd, MPI_RAID_ACTION_QUIESCE_PHYS_IO, &iocmd) < 0) {
  3834. ddvprintk((MYIOC_s_ERR_FMT "RAID Queisce FAILED!\n", ioc->name));
  3835. goto target_done;
  3836. }
  3837. break;
  3838. }
  3839. pPDisk++;
  3840. numPDisk--;
  3841. }
  3842. }
  3843. /* RAID Volume ID's may double for a physical device. If RAID but
  3844. * not a physical ID as well, skip DV.
  3845. */
  3846. if ((hd->ioc->spi_data.isRaid & (1 << id)) && !(iocmd.flags & MPT_ICFLAG_PHYS_DISK))
  3847. goto target_done;
  3848. /* Basic Test.
  3849. * Async & Narrow - Inquiry
  3850. * Async & Narrow - Inquiry
  3851. * Maximum transfer rate - Inquiry
  3852. * Compare buffers:
  3853. * If compare, test complete.
  3854. * If miscompare and first pass, repeat
  3855. * If miscompare and not first pass, fall back and repeat
  3856. */
  3857. hd->pLocal = NULL;
  3858. readPage0 = 0;
  3859. sz = SCSI_MAX_INQUIRY_BYTES;
  3860. rc = MPT_SCANDV_GOOD;
  3861. while (1) {
  3862. ddvprintk((MYIOC_s_NOTE_FMT "DV: Start Basic test on id=%d\n", ioc->name, id));
  3863. retcode = 0;
  3864. dv.cmd = MPT_SET_MIN;
  3865. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  3866. cfg.hdr = &header1;
  3867. cfg.physAddr = cfg1_dma_addr;
  3868. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  3869. cfg.dir = 1;
  3870. if (mpt_config(hd->ioc, &cfg) != 0)
  3871. goto target_done;
  3872. /* Wide - narrow - wide workaround case
  3873. */
  3874. if ((rc == MPT_SCANDV_ISSUE_SENSE) && dv.max.width) {
  3875. /* Send an untagged command to reset disk Qs corrupted
  3876. * when a parity error occurs on a Request Sense.
  3877. */
  3878. if ((hd->ioc->facts.FWVersion.Word >= 0x01000600) ||
  3879. ((hd->ioc->facts.FWVersion.Word >= 0x01010000) &&
  3880. (hd->ioc->facts.FWVersion.Word < 0x01010B00)) ) {
  3881. iocmd.cmd = REQUEST_SENSE;
  3882. iocmd.data_dma = buf1_dma;
  3883. iocmd.data = pbuf1;
  3884. iocmd.size = 0x12;
  3885. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3886. goto target_done;
  3887. else {
  3888. if (hd->pLocal == NULL)
  3889. goto target_done;
  3890. rc = hd->pLocal->completion;
  3891. if ((rc == MPT_SCANDV_GOOD) || (rc == MPT_SCANDV_SENSE)) {
  3892. dv.max.width = 0;
  3893. doFallback = 0;
  3894. } else
  3895. goto target_done;
  3896. }
  3897. } else
  3898. goto target_done;
  3899. }
  3900. iocmd.cmd = INQUIRY;
  3901. iocmd.data_dma = buf1_dma;
  3902. iocmd.data = pbuf1;
  3903. iocmd.size = sz;
  3904. memset(pbuf1, 0x00, sz);
  3905. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3906. goto target_done;
  3907. else {
  3908. if (hd->pLocal == NULL)
  3909. goto target_done;
  3910. rc = hd->pLocal->completion;
  3911. if (rc == MPT_SCANDV_GOOD) {
  3912. if (hd->pLocal->scsiStatus == SAM_STAT_BUSY) {
  3913. if ((iocmd.flags & MPT_ICFLAG_TAGGED_CMD) == 0)
  3914. retcode = 1;
  3915. else
  3916. retcode = 0;
  3917. goto target_done;
  3918. }
  3919. } else if (rc == MPT_SCANDV_SENSE) {
  3920. ;
  3921. } else {
  3922. /* If first command doesn't complete
  3923. * with a good status or with a check condition,
  3924. * exit.
  3925. */
  3926. goto target_done;
  3927. }
  3928. }
  3929. /* Reset the size for disks
  3930. */
  3931. inq0 = (*pbuf1) & 0x1F;
  3932. if ((inq0 == 0) && pTarget && !pTarget->raidVolume) {
  3933. sz = 0x40;
  3934. iocmd.size = sz;
  3935. }
  3936. /* Another GEM workaround. Check peripheral device type,
  3937. * if PROCESSOR, quit DV.
  3938. */
  3939. if (inq0 == TYPE_PROCESSOR) {
  3940. mptscsih_initTarget(hd,
  3941. bus,
  3942. id,
  3943. lun,
  3944. pbuf1,
  3945. sz);
  3946. goto target_done;
  3947. }
  3948. if (inq0 > 0x08)
  3949. goto target_done;
  3950. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3951. goto target_done;
  3952. if (sz == 0x40) {
  3953. if ((pTarget->maxWidth == 1) && (pTarget->maxOffset) && (nfactor < 0x0A)
  3954. && (pTarget->minSyncFactor > 0x09)) {
  3955. if ((pbuf1[56] & 0x04) == 0)
  3956. ;
  3957. else if ((pbuf1[56] & 0x01) == 1) {
  3958. pTarget->minSyncFactor =
  3959. nfactor > MPT_ULTRA320 ? nfactor : MPT_ULTRA320;
  3960. } else {
  3961. pTarget->minSyncFactor =
  3962. nfactor > MPT_ULTRA160 ? nfactor : MPT_ULTRA160;
  3963. }
  3964. dv.max.factor = pTarget->minSyncFactor;
  3965. if ((pbuf1[56] & 0x02) == 0) {
  3966. pTarget->negoFlags |= MPT_TARGET_NO_NEGO_QAS;
  3967. hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
  3968. ddvprintk((MYIOC_s_NOTE_FMT
  3969. "DV: Start Basic noQas on id=%d due to pbuf1[56]=%x\n",
  3970. ioc->name, id, pbuf1[56]));
  3971. }
  3972. }
  3973. }
  3974. if (doFallback)
  3975. dv.cmd = MPT_FALLBACK;
  3976. else
  3977. dv.cmd = MPT_SET_MAX;
  3978. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  3979. if (mpt_config(hd->ioc, &cfg) != 0)
  3980. goto target_done;
  3981. if ((!dv.now.width) && (!dv.now.offset))
  3982. goto target_done;
  3983. iocmd.cmd = INQUIRY;
  3984. iocmd.data_dma = buf2_dma;
  3985. iocmd.data = pbuf2;
  3986. iocmd.size = sz;
  3987. memset(pbuf2, 0x00, sz);
  3988. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  3989. goto target_done;
  3990. else if (hd->pLocal == NULL)
  3991. goto target_done;
  3992. else {
  3993. /* Save the return code.
  3994. * If this is the first pass,
  3995. * read SCSI Device Page 0
  3996. * and update the target max parameters.
  3997. */
  3998. rc = hd->pLocal->completion;
  3999. doFallback = 0;
  4000. if (rc == MPT_SCANDV_GOOD) {
  4001. if (!readPage0) {
  4002. u32 sdp0_info;
  4003. u32 sdp0_nego;
  4004. cfg.hdr = &header0;
  4005. cfg.physAddr = cfg0_dma_addr;
  4006. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4007. cfg.dir = 0;
  4008. if (mpt_config(hd->ioc, &cfg) != 0)
  4009. goto target_done;
  4010. sdp0_info = le32_to_cpu(pcfg0Data->Information) & 0x0E;
  4011. sdp0_nego = (le32_to_cpu(pcfg0Data->NegotiatedParameters) & 0xFF00 ) >> 8;
  4012. /* Quantum and Fujitsu workarounds.
  4013. * Quantum: PPR U320 -> PPR reply with Ultra2 and wide
  4014. * Fujitsu: PPR U320 -> Msg Reject and Ultra2 and wide
  4015. * Resetart with a request for U160.
  4016. */
  4017. if ((dv.now.factor == MPT_ULTRA320) && (sdp0_nego == MPT_ULTRA2)) {
  4018. doFallback = 1;
  4019. } else {
  4020. dv.cmd = MPT_UPDATE_MAX;
  4021. mptscsih_dv_parms(hd, &dv, (void *)pcfg0Data);
  4022. /* Update the SCSI device page 1 area
  4023. */
  4024. pcfg1Data->RequestedParameters = pcfg0Data->NegotiatedParameters;
  4025. readPage0 = 1;
  4026. }
  4027. }
  4028. /* Quantum workaround. Restart this test will the fallback
  4029. * flag set.
  4030. */
  4031. if (doFallback == 0) {
  4032. if (memcmp(pbuf1, pbuf2, sz) != 0) {
  4033. if (!firstPass)
  4034. doFallback = 1;
  4035. } else {
  4036. ddvprintk((MYIOC_s_NOTE_FMT
  4037. "DV:Inquiry compared id=%d, calling initTarget\n", ioc->name, id));
  4038. hd->ioc->spi_data.dvStatus[id] &= ~MPT_SCSICFG_DV_NOT_DONE;
  4039. mptscsih_initTarget(hd,
  4040. bus,
  4041. id,
  4042. lun,
  4043. pbuf1,
  4044. sz);
  4045. break; /* test complete */
  4046. }
  4047. }
  4048. } else if (rc == MPT_SCANDV_ISSUE_SENSE)
  4049. doFallback = 1; /* set fallback flag */
  4050. else if ((rc == MPT_SCANDV_DID_RESET) ||
  4051. (rc == MPT_SCANDV_SENSE) ||
  4052. (rc == MPT_SCANDV_FALLBACK))
  4053. doFallback = 1; /* set fallback flag */
  4054. else
  4055. goto target_done;
  4056. firstPass = 0;
  4057. }
  4058. }
  4059. ddvprintk((MYIOC_s_NOTE_FMT "DV: Basic test on id=%d completed OK.\n", ioc->name, id));
  4060. if (ioc->spi_data.mpt_dv == 0)
  4061. goto target_done;
  4062. inq0 = (*pbuf1) & 0x1F;
  4063. /* Continue only for disks
  4064. */
  4065. if (inq0 != 0)
  4066. goto target_done;
  4067. if ( ioc->spi_data.PortFlags == MPI_SCSIPORTPAGE2_PORT_FLAGS_BASIC_DV_ONLY )
  4068. goto target_done;
  4069. /* Start the Enhanced Test.
  4070. * 0) issue TUR to clear out check conditions
  4071. * 1) read capacity of echo (regular) buffer
  4072. * 2) reserve device
  4073. * 3) do write-read-compare data pattern test
  4074. * 4) release
  4075. * 5) update nego parms to target struct
  4076. */
  4077. cfg.hdr = &header1;
  4078. cfg.physAddr = cfg1_dma_addr;
  4079. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  4080. cfg.dir = 1;
  4081. iocmd.cmd = TEST_UNIT_READY;
  4082. iocmd.data_dma = -1;
  4083. iocmd.data = NULL;
  4084. iocmd.size = 0;
  4085. notDone = 1;
  4086. while (notDone) {
  4087. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4088. goto target_done;
  4089. if (hd->pLocal == NULL)
  4090. goto target_done;
  4091. rc = hd->pLocal->completion;
  4092. if (rc == MPT_SCANDV_GOOD)
  4093. notDone = 0;
  4094. else if (rc == MPT_SCANDV_SENSE) {
  4095. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4096. u8 asc = hd->pLocal->sense[12];
  4097. u8 ascq = hd->pLocal->sense[13];
  4098. ddvprintk((MYIOC_s_INFO_FMT
  4099. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
  4100. ioc->name, skey, asc, ascq));
  4101. if (skey == UNIT_ATTENTION)
  4102. notDone++; /* repeat */
  4103. else if ((skey == NOT_READY) &&
  4104. (asc == 0x04)&&(ascq == 0x01)) {
  4105. /* wait then repeat */
  4106. mdelay (2000);
  4107. notDone++;
  4108. } else if ((skey == NOT_READY) && (asc == 0x3A)) {
  4109. /* no medium, try read test anyway */
  4110. notDone = 0;
  4111. } else {
  4112. /* All other errors are fatal.
  4113. */
  4114. ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.",
  4115. ioc->name));
  4116. goto target_done;
  4117. }
  4118. } else
  4119. goto target_done;
  4120. }
  4121. iocmd.cmd = READ_BUFFER;
  4122. iocmd.data_dma = buf1_dma;
  4123. iocmd.data = pbuf1;
  4124. iocmd.size = 4;
  4125. iocmd.flags |= MPT_ICFLAG_BUF_CAP;
  4126. dataBufSize = 0;
  4127. echoBufSize = 0;
  4128. for (patt = 0; patt < 2; patt++) {
  4129. if (patt == 0)
  4130. iocmd.flags |= MPT_ICFLAG_ECHO;
  4131. else
  4132. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4133. notDone = 1;
  4134. while (notDone) {
  4135. bufsize = 0;
  4136. /* If not ready after 8 trials,
  4137. * give up on this device.
  4138. */
  4139. if (notDone > 8)
  4140. goto target_done;
  4141. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4142. goto target_done;
  4143. else if (hd->pLocal == NULL)
  4144. goto target_done;
  4145. else {
  4146. rc = hd->pLocal->completion;
  4147. ddvprintk(("ReadBuffer Comp Code %d", rc));
  4148. ddvprintk((" buff: %0x %0x %0x %0x\n",
  4149. pbuf1[0], pbuf1[1], pbuf1[2], pbuf1[3]));
  4150. if (rc == MPT_SCANDV_GOOD) {
  4151. notDone = 0;
  4152. if (iocmd.flags & MPT_ICFLAG_ECHO) {
  4153. bufsize = ((pbuf1[2] & 0x1F) <<8) | pbuf1[3];
  4154. } else {
  4155. bufsize = pbuf1[1]<<16 | pbuf1[2]<<8 | pbuf1[3];
  4156. }
  4157. } else if (rc == MPT_SCANDV_SENSE) {
  4158. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4159. u8 asc = hd->pLocal->sense[12];
  4160. u8 ascq = hd->pLocal->sense[13];
  4161. ddvprintk((MYIOC_s_INFO_FMT
  4162. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
  4163. ioc->name, skey, asc, ascq));
  4164. if (skey == ILLEGAL_REQUEST) {
  4165. notDone = 0;
  4166. } else if (skey == UNIT_ATTENTION) {
  4167. notDone++; /* repeat */
  4168. } else if ((skey == NOT_READY) &&
  4169. (asc == 0x04)&&(ascq == 0x01)) {
  4170. /* wait then repeat */
  4171. mdelay (2000);
  4172. notDone++;
  4173. } else {
  4174. /* All other errors are fatal.
  4175. */
  4176. ddvprintk((MYIOC_s_INFO_FMT "DV: fatal error.",
  4177. ioc->name));
  4178. goto target_done;
  4179. }
  4180. } else {
  4181. /* All other errors are fatal
  4182. */
  4183. goto target_done;
  4184. }
  4185. }
  4186. }
  4187. if (iocmd.flags & MPT_ICFLAG_ECHO)
  4188. echoBufSize = bufsize;
  4189. else
  4190. dataBufSize = bufsize;
  4191. }
  4192. sz = 0;
  4193. iocmd.flags &= ~MPT_ICFLAG_BUF_CAP;
  4194. /* Use echo buffers if possible,
  4195. * Exit if both buffers are 0.
  4196. */
  4197. if (echoBufSize > 0) {
  4198. iocmd.flags |= MPT_ICFLAG_ECHO;
  4199. if (dataBufSize > 0)
  4200. bufsize = min(echoBufSize, dataBufSize);
  4201. else
  4202. bufsize = echoBufSize;
  4203. } else if (dataBufSize == 0)
  4204. goto target_done;
  4205. ddvprintk((MYIOC_s_INFO_FMT "%s Buffer Capacity %d\n", ioc->name,
  4206. (iocmd.flags & MPT_ICFLAG_ECHO) ? "Echo" : " ", bufsize));
  4207. /* Data buffers for write-read-compare test max 1K.
  4208. */
  4209. sz = min(bufsize, 1024);
  4210. /* --- loop ----
  4211. * On first pass, always issue a reserve.
  4212. * On additional loops, only if a reset has occurred.
  4213. * iocmd.flags indicates if echo or regular buffer
  4214. */
  4215. for (patt = 0; patt < 4; patt++) {
  4216. ddvprintk(("Pattern %d\n", patt));
  4217. if ((iocmd.flags & MPT_ICFLAG_RESERVED) && (iocmd.flags & MPT_ICFLAG_DID_RESET)) {
  4218. iocmd.cmd = TEST_UNIT_READY;
  4219. iocmd.data_dma = -1;
  4220. iocmd.data = NULL;
  4221. iocmd.size = 0;
  4222. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4223. goto target_done;
  4224. iocmd.cmd = RELEASE;
  4225. iocmd.data_dma = -1;
  4226. iocmd.data = NULL;
  4227. iocmd.size = 0;
  4228. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4229. goto target_done;
  4230. else if (hd->pLocal == NULL)
  4231. goto target_done;
  4232. else {
  4233. rc = hd->pLocal->completion;
  4234. ddvprintk(("Release rc %d\n", rc));
  4235. if (rc == MPT_SCANDV_GOOD)
  4236. iocmd.flags &= ~MPT_ICFLAG_RESERVED;
  4237. else
  4238. goto target_done;
  4239. }
  4240. iocmd.flags &= ~MPT_ICFLAG_RESERVED;
  4241. }
  4242. iocmd.flags &= ~MPT_ICFLAG_DID_RESET;
  4243. repeat = 5;
  4244. while (repeat && (!(iocmd.flags & MPT_ICFLAG_RESERVED))) {
  4245. iocmd.cmd = RESERVE;
  4246. iocmd.data_dma = -1;
  4247. iocmd.data = NULL;
  4248. iocmd.size = 0;
  4249. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4250. goto target_done;
  4251. else if (hd->pLocal == NULL)
  4252. goto target_done;
  4253. else {
  4254. rc = hd->pLocal->completion;
  4255. if (rc == MPT_SCANDV_GOOD) {
  4256. iocmd.flags |= MPT_ICFLAG_RESERVED;
  4257. } else if (rc == MPT_SCANDV_SENSE) {
  4258. /* Wait if coming ready
  4259. */
  4260. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4261. u8 asc = hd->pLocal->sense[12];
  4262. u8 ascq = hd->pLocal->sense[13];
  4263. ddvprintk((MYIOC_s_INFO_FMT
  4264. "DV: Reserve Failed: ", ioc->name));
  4265. ddvprintk(("SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n",
  4266. skey, asc, ascq));
  4267. if ((skey == NOT_READY) && (asc == 0x04)&&
  4268. (ascq == 0x01)) {
  4269. /* wait then repeat */
  4270. mdelay (2000);
  4271. notDone++;
  4272. } else {
  4273. ddvprintk((MYIOC_s_INFO_FMT
  4274. "DV: Reserved Failed.", ioc->name));
  4275. goto target_done;
  4276. }
  4277. } else {
  4278. ddvprintk((MYIOC_s_INFO_FMT "DV: Reserved Failed.",
  4279. ioc->name));
  4280. goto target_done;
  4281. }
  4282. }
  4283. }
  4284. mptscsih_fillbuf(pbuf1, sz, patt, 1);
  4285. iocmd.cmd = WRITE_BUFFER;
  4286. iocmd.data_dma = buf1_dma;
  4287. iocmd.data = pbuf1;
  4288. iocmd.size = sz;
  4289. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4290. goto target_done;
  4291. else if (hd->pLocal == NULL)
  4292. goto target_done;
  4293. else {
  4294. rc = hd->pLocal->completion;
  4295. if (rc == MPT_SCANDV_GOOD)
  4296. ; /* Issue read buffer */
  4297. else if (rc == MPT_SCANDV_DID_RESET) {
  4298. /* If using echo buffers, reset to data buffers.
  4299. * Else do Fallback and restart
  4300. * this test (re-issue reserve
  4301. * because of bus reset).
  4302. */
  4303. if ((iocmd.flags & MPT_ICFLAG_ECHO) && (dataBufSize >= bufsize)) {
  4304. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4305. } else {
  4306. dv.cmd = MPT_FALLBACK;
  4307. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4308. if (mpt_config(hd->ioc, &cfg) != 0)
  4309. goto target_done;
  4310. if ((!dv.now.width) && (!dv.now.offset))
  4311. goto target_done;
  4312. }
  4313. iocmd.flags |= MPT_ICFLAG_DID_RESET;
  4314. patt = -1;
  4315. continue;
  4316. } else if (rc == MPT_SCANDV_SENSE) {
  4317. /* Restart data test if UA, else quit.
  4318. */
  4319. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4320. ddvprintk((MYIOC_s_INFO_FMT
  4321. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey,
  4322. hd->pLocal->sense[12], hd->pLocal->sense[13]));
  4323. if (skey == UNIT_ATTENTION) {
  4324. patt = -1;
  4325. continue;
  4326. } else if (skey == ILLEGAL_REQUEST) {
  4327. if (iocmd.flags & MPT_ICFLAG_ECHO) {
  4328. if (dataBufSize >= bufsize) {
  4329. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4330. patt = -1;
  4331. continue;
  4332. }
  4333. }
  4334. goto target_done;
  4335. }
  4336. else
  4337. goto target_done;
  4338. } else {
  4339. /* fatal error */
  4340. goto target_done;
  4341. }
  4342. }
  4343. iocmd.cmd = READ_BUFFER;
  4344. iocmd.data_dma = buf2_dma;
  4345. iocmd.data = pbuf2;
  4346. iocmd.size = sz;
  4347. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4348. goto target_done;
  4349. else if (hd->pLocal == NULL)
  4350. goto target_done;
  4351. else {
  4352. rc = hd->pLocal->completion;
  4353. if (rc == MPT_SCANDV_GOOD) {
  4354. /* If buffers compare,
  4355. * go to next pattern,
  4356. * else, do a fallback and restart
  4357. * data transfer test.
  4358. */
  4359. if (memcmp (pbuf1, pbuf2, sz) == 0) {
  4360. ; /* goto next pattern */
  4361. } else {
  4362. /* Miscompare with Echo buffer, go to data buffer,
  4363. * if that buffer exists.
  4364. * Miscompare with Data buffer, check first 4 bytes,
  4365. * some devices return capacity. Exit in this case.
  4366. */
  4367. if (iocmd.flags & MPT_ICFLAG_ECHO) {
  4368. if (dataBufSize >= bufsize)
  4369. iocmd.flags &= ~MPT_ICFLAG_ECHO;
  4370. else
  4371. goto target_done;
  4372. } else {
  4373. if (dataBufSize == (pbuf2[1]<<16 | pbuf2[2]<<8 | pbuf2[3])) {
  4374. /* Argh. Device returning wrong data.
  4375. * Quit DV for this device.
  4376. */
  4377. goto target_done;
  4378. }
  4379. /* Had an actual miscompare. Slow down.*/
  4380. dv.cmd = MPT_FALLBACK;
  4381. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4382. if (mpt_config(hd->ioc, &cfg) != 0)
  4383. goto target_done;
  4384. if ((!dv.now.width) && (!dv.now.offset))
  4385. goto target_done;
  4386. }
  4387. patt = -1;
  4388. continue;
  4389. }
  4390. } else if (rc == MPT_SCANDV_DID_RESET) {
  4391. /* Do Fallback and restart
  4392. * this test (re-issue reserve
  4393. * because of bus reset).
  4394. */
  4395. dv.cmd = MPT_FALLBACK;
  4396. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4397. if (mpt_config(hd->ioc, &cfg) != 0)
  4398. goto target_done;
  4399. if ((!dv.now.width) && (!dv.now.offset))
  4400. goto target_done;
  4401. iocmd.flags |= MPT_ICFLAG_DID_RESET;
  4402. patt = -1;
  4403. continue;
  4404. } else if (rc == MPT_SCANDV_SENSE) {
  4405. /* Restart data test if UA, else quit.
  4406. */
  4407. u8 skey = hd->pLocal->sense[2] & 0x0F;
  4408. ddvprintk((MYIOC_s_INFO_FMT
  4409. "SenseKey:ASC:ASCQ = (%x:%02x:%02x)\n", ioc->name, skey,
  4410. hd->pLocal->sense[12], hd->pLocal->sense[13]));
  4411. if (skey == UNIT_ATTENTION) {
  4412. patt = -1;
  4413. continue;
  4414. }
  4415. else
  4416. goto target_done;
  4417. } else {
  4418. /* fatal error */
  4419. goto target_done;
  4420. }
  4421. }
  4422. } /* --- end of patt loop ---- */
  4423. target_done:
  4424. if (iocmd.flags & MPT_ICFLAG_RESERVED) {
  4425. iocmd.cmd = RELEASE;
  4426. iocmd.data_dma = -1;
  4427. iocmd.data = NULL;
  4428. iocmd.size = 0;
  4429. if (mptscsih_do_cmd(hd, &iocmd) < 0)
  4430. printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d",
  4431. ioc->name, id);
  4432. else if (hd->pLocal) {
  4433. if (hd->pLocal->completion == MPT_SCANDV_GOOD)
  4434. iocmd.flags &= ~MPT_ICFLAG_RESERVED;
  4435. } else {
  4436. printk(MYIOC_s_INFO_FMT "DV: Release failed. id %d",
  4437. ioc->name, id);
  4438. }
  4439. }
  4440. /* Set if cfg1_dma_addr contents is valid
  4441. */
  4442. if ((cfg.hdr != NULL) && (retcode == 0)){
  4443. /* If disk, not U320, disable QAS
  4444. */
  4445. if ((inq0 == 0) && (dv.now.factor > MPT_ULTRA320)) {
  4446. hd->ioc->spi_data.noQas = MPT_TARGET_NO_NEGO_QAS;
  4447. ddvprintk((MYIOC_s_NOTE_FMT
  4448. "noQas set due to id=%d has factor=%x\n", ioc->name, id, dv.now.factor));
  4449. }
  4450. dv.cmd = MPT_SAVE;
  4451. mptscsih_dv_parms(hd, &dv, (void *)pcfg1Data);
  4452. /* Double writes to SDP1 can cause problems,
  4453. * skip save of the final negotiated settings to
  4454. * SCSI device page 1.
  4455. *
  4456. cfg.hdr = &header1;
  4457. cfg.physAddr = cfg1_dma_addr;
  4458. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  4459. cfg.dir = 1;
  4460. mpt_config(hd->ioc, &cfg);
  4461. */
  4462. }
  4463. /* If this is a RAID Passthrough, enable internal IOs
  4464. */
  4465. if (iocmd.flags & MPT_ICFLAG_PHYS_DISK) {
  4466. if (mptscsih_do_raid(hd, MPI_RAID_ACTION_ENABLE_PHYS_IO, &iocmd) < 0)
  4467. ddvprintk((MYIOC_s_ERR_FMT "RAID Enable FAILED!\n", ioc->name));
  4468. }
  4469. /* Done with the DV scan of the current target
  4470. */
  4471. if (pDvBuf)
  4472. pci_free_consistent(ioc->pcidev, dv_alloc, pDvBuf, dvbuf_dma);
  4473. ddvtprintk((MYIOC_s_INFO_FMT "DV Done id=%d\n",
  4474. ioc->name, id));
  4475. return retcode;
  4476. }
  4477. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4478. /* mptscsih_dv_parms - perform a variety of operations on the
  4479. * parameters used for negotiation.
  4480. * @hd: Pointer to a SCSI host.
  4481. * @dv: Pointer to a structure that contains the maximum and current
  4482. * negotiated parameters.
  4483. */
  4484. static void
  4485. mptscsih_dv_parms(MPT_SCSI_HOST *hd, DVPARAMETERS *dv,void *pPage)
  4486. {
  4487. VirtDevice *pTarget;
  4488. SCSIDevicePage0_t *pPage0;
  4489. SCSIDevicePage1_t *pPage1;
  4490. int val = 0, data, configuration;
  4491. u8 width = 0;
  4492. u8 offset = 0;
  4493. u8 factor = 0;
  4494. u8 negoFlags = 0;
  4495. u8 cmd = dv->cmd;
  4496. u8 id = dv->id;
  4497. switch (cmd) {
  4498. case MPT_GET_NVRAM_VALS:
  4499. ddvprintk((MYIOC_s_NOTE_FMT "Getting NVRAM: ",
  4500. hd->ioc->name));
  4501. /* Get the NVRAM values and save in tmax
  4502. * If not an LVD bus, the adapter minSyncFactor has been
  4503. * already throttled back.
  4504. */
  4505. if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume) {
  4506. width = pTarget->maxWidth;
  4507. offset = pTarget->maxOffset;
  4508. factor = pTarget->minSyncFactor;
  4509. negoFlags = pTarget->negoFlags;
  4510. } else {
  4511. if (hd->ioc->spi_data.nvram && (hd->ioc->spi_data.nvram[id] != MPT_HOST_NVRAM_INVALID)) {
  4512. data = hd->ioc->spi_data.nvram[id];
  4513. width = data & MPT_NVRAM_WIDE_DISABLE ? 0 : 1;
  4514. if ((offset = hd->ioc->spi_data.maxSyncOffset) == 0)
  4515. factor = MPT_ASYNC;
  4516. else {
  4517. factor = (data & MPT_NVRAM_SYNC_MASK) >> MPT_NVRAM_SYNC_SHIFT;
  4518. if ((factor == 0) || (factor == MPT_ASYNC)){
  4519. factor = MPT_ASYNC;
  4520. offset = 0;
  4521. }
  4522. }
  4523. } else {
  4524. width = MPT_NARROW;
  4525. offset = 0;
  4526. factor = MPT_ASYNC;
  4527. }
  4528. /* Set the negotiation flags */
  4529. negoFlags = hd->ioc->spi_data.noQas;
  4530. if (!width)
  4531. negoFlags |= MPT_TARGET_NO_NEGO_WIDE;
  4532. if (!offset)
  4533. negoFlags |= MPT_TARGET_NO_NEGO_SYNC;
  4534. }
  4535. /* limit by adapter capabilities */
  4536. width = min(width, hd->ioc->spi_data.maxBusWidth);
  4537. offset = min(offset, hd->ioc->spi_data.maxSyncOffset);
  4538. factor = max(factor, hd->ioc->spi_data.minSyncFactor);
  4539. /* Check Consistency */
  4540. if (offset && (factor < MPT_ULTRA2) && !width)
  4541. factor = MPT_ULTRA2;
  4542. dv->max.width = width;
  4543. dv->max.offset = offset;
  4544. dv->max.factor = factor;
  4545. dv->max.flags = negoFlags;
  4546. ddvprintk((" id=%d width=%d factor=%x offset=%x flags=%x\n",
  4547. id, width, factor, offset, negoFlags));
  4548. break;
  4549. case MPT_UPDATE_MAX:
  4550. ddvprintk((MYIOC_s_NOTE_FMT
  4551. "Updating with SDP0 Data: ", hd->ioc->name));
  4552. /* Update tmax values with those from Device Page 0.*/
  4553. pPage0 = (SCSIDevicePage0_t *) pPage;
  4554. if (pPage0) {
  4555. val = cpu_to_le32(pPage0->NegotiatedParameters);
  4556. dv->max.width = val & MPI_SCSIDEVPAGE0_NP_WIDE ? 1 : 0;
  4557. dv->max.offset = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_OFFSET_MASK) >> 16;
  4558. dv->max.factor = (val&MPI_SCSIDEVPAGE0_NP_NEG_SYNC_PERIOD_MASK) >> 8;
  4559. }
  4560. dv->now.width = dv->max.width;
  4561. dv->now.offset = dv->max.offset;
  4562. dv->now.factor = dv->max.factor;
  4563. ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x\n",
  4564. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags));
  4565. break;
  4566. case MPT_SET_MAX:
  4567. ddvprintk((MYIOC_s_NOTE_FMT "Setting Max: ",
  4568. hd->ioc->name));
  4569. /* Set current to the max values. Update the config page.*/
  4570. dv->now.width = dv->max.width;
  4571. dv->now.offset = dv->max.offset;
  4572. dv->now.factor = dv->max.factor;
  4573. dv->now.flags = dv->max.flags;
  4574. pPage1 = (SCSIDevicePage1_t *)pPage;
  4575. if (pPage1) {
  4576. mptscsih_setDevicePage1Flags (dv->now.width, dv->now.factor,
  4577. dv->now.offset, &val, &configuration, dv->now.flags);
  4578. dnegoprintk(("Setting Max: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
  4579. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
  4580. pPage1->RequestedParameters = le32_to_cpu(val);
  4581. pPage1->Reserved = 0;
  4582. pPage1->Configuration = le32_to_cpu(configuration);
  4583. }
  4584. ddvprintk(("id=%d width=%d factor=%x offset=%x flags=%x request=%x configuration=%x\n",
  4585. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags, val, configuration));
  4586. break;
  4587. case MPT_SET_MIN:
  4588. ddvprintk((MYIOC_s_NOTE_FMT "Setting Min: ",
  4589. hd->ioc->name));
  4590. /* Set page to asynchronous and narrow
  4591. * Do not update now, breaks fallback routine. */
  4592. width = MPT_NARROW;
  4593. offset = 0;
  4594. factor = MPT_ASYNC;
  4595. negoFlags = dv->max.flags;
  4596. pPage1 = (SCSIDevicePage1_t *)pPage;
  4597. if (pPage1) {
  4598. mptscsih_setDevicePage1Flags (width, factor,
  4599. offset, &val, &configuration, negoFlags);
  4600. dnegoprintk(("Setting Min: id=%d width=%d factor=%x offset=%x negoFlags=%x request=%x config=%x\n",
  4601. id, width, factor, offset, negoFlags, val, configuration));
  4602. pPage1->RequestedParameters = le32_to_cpu(val);
  4603. pPage1->Reserved = 0;
  4604. pPage1->Configuration = le32_to_cpu(configuration);
  4605. }
  4606. ddvprintk(("id=%d width=%d factor=%x offset=%x request=%x config=%x negoFlags=%x\n",
  4607. id, width, factor, offset, val, configuration, negoFlags));
  4608. break;
  4609. case MPT_FALLBACK:
  4610. ddvprintk((MYIOC_s_NOTE_FMT
  4611. "Fallback: Start: offset %d, factor %x, width %d \n",
  4612. hd->ioc->name, dv->now.offset,
  4613. dv->now.factor, dv->now.width));
  4614. width = dv->now.width;
  4615. offset = dv->now.offset;
  4616. factor = dv->now.factor;
  4617. if ((offset) && (dv->max.width)) {
  4618. if (factor < MPT_ULTRA160)
  4619. factor = MPT_ULTRA160;
  4620. else if (factor < MPT_ULTRA2) {
  4621. factor = MPT_ULTRA2;
  4622. width = MPT_WIDE;
  4623. } else if ((factor == MPT_ULTRA2) && width) {
  4624. factor = MPT_ULTRA2;
  4625. width = MPT_NARROW;
  4626. } else if (factor < MPT_ULTRA) {
  4627. factor = MPT_ULTRA;
  4628. width = MPT_WIDE;
  4629. } else if ((factor == MPT_ULTRA) && width) {
  4630. width = MPT_NARROW;
  4631. } else if (factor < MPT_FAST) {
  4632. factor = MPT_FAST;
  4633. width = MPT_WIDE;
  4634. } else if ((factor == MPT_FAST) && width) {
  4635. factor = MPT_FAST;
  4636. width = MPT_NARROW;
  4637. } else if (factor < MPT_SCSI) {
  4638. factor = MPT_SCSI;
  4639. width = MPT_WIDE;
  4640. } else if ((factor == MPT_SCSI) && width) {
  4641. factor = MPT_SCSI;
  4642. width = MPT_NARROW;
  4643. } else {
  4644. factor = MPT_ASYNC;
  4645. offset = 0;
  4646. }
  4647. } else if (offset) {
  4648. width = MPT_NARROW;
  4649. if (factor < MPT_ULTRA)
  4650. factor = MPT_ULTRA;
  4651. else if (factor < MPT_FAST)
  4652. factor = MPT_FAST;
  4653. else if (factor < MPT_SCSI)
  4654. factor = MPT_SCSI;
  4655. else {
  4656. factor = MPT_ASYNC;
  4657. offset = 0;
  4658. }
  4659. } else {
  4660. width = MPT_NARROW;
  4661. factor = MPT_ASYNC;
  4662. }
  4663. dv->max.flags |= MPT_TARGET_NO_NEGO_QAS;
  4664. dv->max.flags &= ~MPT_TAPE_NEGO_IDP;
  4665. dv->now.width = width;
  4666. dv->now.offset = offset;
  4667. dv->now.factor = factor;
  4668. dv->now.flags = dv->max.flags;
  4669. pPage1 = (SCSIDevicePage1_t *)pPage;
  4670. if (pPage1) {
  4671. mptscsih_setDevicePage1Flags (width, factor, offset, &val,
  4672. &configuration, dv->now.flags);
  4673. dnegoprintk(("Finish: id=%d width=%d offset=%d factor=%x flags=%x request=%x config=%x\n",
  4674. id, width, offset, factor, dv->now.flags, val, configuration));
  4675. pPage1->RequestedParameters = le32_to_cpu(val);
  4676. pPage1->Reserved = 0;
  4677. pPage1->Configuration = le32_to_cpu(configuration);
  4678. }
  4679. ddvprintk(("Finish: id=%d offset=%d factor=%x width=%d request=%x config=%x\n",
  4680. id, dv->now.offset, dv->now.factor, dv->now.width, val, configuration));
  4681. break;
  4682. case MPT_SAVE:
  4683. ddvprintk((MYIOC_s_NOTE_FMT
  4684. "Saving to Target structure: ", hd->ioc->name));
  4685. ddvprintk(("id=%d width=%x factor=%x offset=%d flags=%x\n",
  4686. id, dv->now.width, dv->now.factor, dv->now.offset, dv->now.flags));
  4687. /* Save these values to target structures
  4688. * or overwrite nvram (phys disks only).
  4689. */
  4690. if ((hd->Targets)&&((pTarget = hd->Targets[(int)id]) != NULL) && !pTarget->raidVolume ) {
  4691. pTarget->maxWidth = dv->now.width;
  4692. pTarget->maxOffset = dv->now.offset;
  4693. pTarget->minSyncFactor = dv->now.factor;
  4694. pTarget->negoFlags = dv->now.flags;
  4695. } else {
  4696. /* Preserv all flags, use
  4697. * read-modify-write algorithm
  4698. */
  4699. if (hd->ioc->spi_data.nvram) {
  4700. data = hd->ioc->spi_data.nvram[id];
  4701. if (dv->now.width)
  4702. data &= ~MPT_NVRAM_WIDE_DISABLE;
  4703. else
  4704. data |= MPT_NVRAM_WIDE_DISABLE;
  4705. if (!dv->now.offset)
  4706. factor = MPT_ASYNC;
  4707. data &= ~MPT_NVRAM_SYNC_MASK;
  4708. data |= (dv->now.factor << MPT_NVRAM_SYNC_SHIFT) & MPT_NVRAM_SYNC_MASK;
  4709. hd->ioc->spi_data.nvram[id] = data;
  4710. }
  4711. }
  4712. break;
  4713. }
  4714. }
  4715. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4716. /* mptscsih_fillbuf - fill a buffer with a special data pattern
  4717. * cleanup. For bus scan only.
  4718. *
  4719. * @buffer: Pointer to data buffer to be filled.
  4720. * @size: Number of bytes to fill
  4721. * @index: Pattern index
  4722. * @width: bus width, 0 (8 bits) or 1 (16 bits)
  4723. */
  4724. static void
  4725. mptscsih_fillbuf(char *buffer, int size, int index, int width)
  4726. {
  4727. char *ptr = buffer;
  4728. int ii;
  4729. char byte;
  4730. short val;
  4731. switch (index) {
  4732. case 0:
  4733. if (width) {
  4734. /* Pattern: 0000 FFFF 0000 FFFF
  4735. */
  4736. for (ii=0; ii < size; ii++, ptr++) {
  4737. if (ii & 0x02)
  4738. *ptr = 0xFF;
  4739. else
  4740. *ptr = 0x00;
  4741. }
  4742. } else {
  4743. /* Pattern: 00 FF 00 FF
  4744. */
  4745. for (ii=0; ii < size; ii++, ptr++) {
  4746. if (ii & 0x01)
  4747. *ptr = 0xFF;
  4748. else
  4749. *ptr = 0x00;
  4750. }
  4751. }
  4752. break;
  4753. case 1:
  4754. if (width) {
  4755. /* Pattern: 5555 AAAA 5555 AAAA 5555
  4756. */
  4757. for (ii=0; ii < size; ii++, ptr++) {
  4758. if (ii & 0x02)
  4759. *ptr = 0xAA;
  4760. else
  4761. *ptr = 0x55;
  4762. }
  4763. } else {
  4764. /* Pattern: 55 AA 55 AA 55
  4765. */
  4766. for (ii=0; ii < size; ii++, ptr++) {
  4767. if (ii & 0x01)
  4768. *ptr = 0xAA;
  4769. else
  4770. *ptr = 0x55;
  4771. }
  4772. }
  4773. break;
  4774. case 2:
  4775. /* Pattern: 00 01 02 03 04 05
  4776. * ... FE FF 00 01..
  4777. */
  4778. for (ii=0; ii < size; ii++, ptr++)
  4779. *ptr = (char) ii;
  4780. break;
  4781. case 3:
  4782. if (width) {
  4783. /* Wide Pattern: FFFE 0001 FFFD 0002
  4784. * ... 4000 DFFF 8000 EFFF
  4785. */
  4786. byte = 0;
  4787. for (ii=0; ii < size/2; ii++) {
  4788. /* Create the base pattern
  4789. */
  4790. val = (1 << byte);
  4791. /* every 64 (0x40) bytes flip the pattern
  4792. * since we fill 2 bytes / iteration,
  4793. * test for ii = 0x20
  4794. */
  4795. if (ii & 0x20)
  4796. val = ~(val);
  4797. if (ii & 0x01) {
  4798. *ptr = (char)( (val & 0xFF00) >> 8);
  4799. ptr++;
  4800. *ptr = (char)(val & 0xFF);
  4801. byte++;
  4802. byte &= 0x0F;
  4803. } else {
  4804. val = ~val;
  4805. *ptr = (char)( (val & 0xFF00) >> 8);
  4806. ptr++;
  4807. *ptr = (char)(val & 0xFF);
  4808. }
  4809. ptr++;
  4810. }
  4811. } else {
  4812. /* Narrow Pattern: FE 01 FD 02 FB 04
  4813. * .. 7F 80 01 FE 02 FD ... 80 7F
  4814. */
  4815. byte = 0;
  4816. for (ii=0; ii < size; ii++, ptr++) {
  4817. /* Base pattern - first 32 bytes
  4818. */
  4819. if (ii & 0x01) {
  4820. *ptr = (1 << byte);
  4821. byte++;
  4822. byte &= 0x07;
  4823. } else {
  4824. *ptr = (char) (~(1 << byte));
  4825. }
  4826. /* Flip the pattern every 32 bytes
  4827. */
  4828. if (ii & 0x20)
  4829. *ptr = ~(*ptr);
  4830. }
  4831. }
  4832. break;
  4833. }
  4834. }
  4835. #endif /* ~MPTSCSIH_ENABLE_DOMAIN_VALIDATION */
  4836. EXPORT_SYMBOL(mptscsih_remove);
  4837. EXPORT_SYMBOL(mptscsih_shutdown);
  4838. #ifdef CONFIG_PM
  4839. EXPORT_SYMBOL(mptscsih_suspend);
  4840. EXPORT_SYMBOL(mptscsih_resume);
  4841. #endif
  4842. EXPORT_SYMBOL(mptscsih_proc_info);
  4843. EXPORT_SYMBOL(mptscsih_info);
  4844. EXPORT_SYMBOL(mptscsih_qcmd);
  4845. EXPORT_SYMBOL(mptscsih_slave_alloc);
  4846. EXPORT_SYMBOL(mptscsih_slave_destroy);
  4847. EXPORT_SYMBOL(mptscsih_slave_configure);
  4848. EXPORT_SYMBOL(mptscsih_abort);
  4849. EXPORT_SYMBOL(mptscsih_dev_reset);
  4850. EXPORT_SYMBOL(mptscsih_bus_reset);
  4851. EXPORT_SYMBOL(mptscsih_host_reset);
  4852. EXPORT_SYMBOL(mptscsih_bios_param);
  4853. EXPORT_SYMBOL(mptscsih_io_done);
  4854. EXPORT_SYMBOL(mptscsih_taskmgmt_complete);
  4855. EXPORT_SYMBOL(mptscsih_scandv_complete);
  4856. EXPORT_SYMBOL(mptscsih_event_process);
  4857. EXPORT_SYMBOL(mptscsih_ioc_reset);
  4858. EXPORT_SYMBOL(mptscsih_store_queue_depth);
  4859. EXPORT_SYMBOL(mptscsih_timer_expired);
  4860. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/