mptscsih.c 155 KB

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