ipr.c 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102
  1. /*
  2. * ipr.c -- driver for IBM Power Linux RAID adapters
  3. *
  4. * Written By: Brian King <brking@us.ibm.com>, IBM Corporation
  5. *
  6. * Copyright (C) 2003, 2004 IBM Corporation
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. /*
  24. * Notes:
  25. *
  26. * This driver is used to control the following SCSI adapters:
  27. *
  28. * IBM iSeries: 5702, 5703, 2780, 5709, 570A, 570B
  29. *
  30. * IBM pSeries: PCI-X Dual Channel Ultra 320 SCSI RAID Adapter
  31. * PCI-X Dual Channel Ultra 320 SCSI Adapter
  32. * PCI-X Dual Channel Ultra 320 SCSI RAID Enablement Card
  33. * Embedded SCSI adapter on p615 and p655 systems
  34. *
  35. * Supported Hardware Features:
  36. * - Ultra 320 SCSI controller
  37. * - PCI-X host interface
  38. * - Embedded PowerPC RISC Processor and Hardware XOR DMA Engine
  39. * - Non-Volatile Write Cache
  40. * - Supports attachment of non-RAID disks, tape, and optical devices
  41. * - RAID Levels 0, 5, 10
  42. * - Hot spare
  43. * - Background Parity Checking
  44. * - Background Data Scrubbing
  45. * - Ability to increase the capacity of an existing RAID 5 disk array
  46. * by adding disks
  47. *
  48. * Driver Features:
  49. * - Tagged command queuing
  50. * - Adapter microcode download
  51. * - PCI hot plug
  52. * - SCSI device hot plug
  53. *
  54. */
  55. #include <linux/config.h>
  56. #include <linux/fs.h>
  57. #include <linux/init.h>
  58. #include <linux/types.h>
  59. #include <linux/errno.h>
  60. #include <linux/kernel.h>
  61. #include <linux/ioport.h>
  62. #include <linux/delay.h>
  63. #include <linux/pci.h>
  64. #include <linux/wait.h>
  65. #include <linux/spinlock.h>
  66. #include <linux/sched.h>
  67. #include <linux/interrupt.h>
  68. #include <linux/blkdev.h>
  69. #include <linux/firmware.h>
  70. #include <linux/module.h>
  71. #include <linux/moduleparam.h>
  72. #include <asm/io.h>
  73. #include <asm/irq.h>
  74. #include <asm/processor.h>
  75. #include <scsi/scsi.h>
  76. #include <scsi/scsi_host.h>
  77. #include <scsi/scsi_tcq.h>
  78. #include <scsi/scsi_eh.h>
  79. #include <scsi/scsi_cmnd.h>
  80. #include <scsi/scsi_request.h>
  81. #include "ipr.h"
  82. /*
  83. * Global Data
  84. */
  85. static struct list_head ipr_ioa_head = LIST_HEAD_INIT(ipr_ioa_head);
  86. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  87. static unsigned int ipr_max_speed = 1;
  88. static int ipr_testmode = 0;
  89. static unsigned int ipr_fastfail = 0;
  90. static unsigned int ipr_transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  91. static DEFINE_SPINLOCK(ipr_driver_lock);
  92. /* This table describes the differences between DMA controller chips */
  93. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  94. { /* Gemstone and Citrine */
  95. .mailbox = 0x0042C,
  96. .cache_line_size = 0x20,
  97. {
  98. .set_interrupt_mask_reg = 0x0022C,
  99. .clr_interrupt_mask_reg = 0x00230,
  100. .sense_interrupt_mask_reg = 0x0022C,
  101. .clr_interrupt_reg = 0x00228,
  102. .sense_interrupt_reg = 0x00224,
  103. .ioarrin_reg = 0x00404,
  104. .sense_uproc_interrupt_reg = 0x00214,
  105. .set_uproc_interrupt_reg = 0x00214,
  106. .clr_uproc_interrupt_reg = 0x00218
  107. }
  108. },
  109. { /* Snipe and Scamp */
  110. .mailbox = 0x0052C,
  111. .cache_line_size = 0x20,
  112. {
  113. .set_interrupt_mask_reg = 0x00288,
  114. .clr_interrupt_mask_reg = 0x0028C,
  115. .sense_interrupt_mask_reg = 0x00288,
  116. .clr_interrupt_reg = 0x00284,
  117. .sense_interrupt_reg = 0x00280,
  118. .ioarrin_reg = 0x00504,
  119. .sense_uproc_interrupt_reg = 0x00290,
  120. .set_uproc_interrupt_reg = 0x00290,
  121. .clr_uproc_interrupt_reg = 0x00294
  122. }
  123. },
  124. };
  125. static const struct ipr_chip_t ipr_chip[] = {
  126. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, &ipr_chip_cfg[0] },
  127. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, &ipr_chip_cfg[0] },
  128. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, &ipr_chip_cfg[1] },
  129. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, &ipr_chip_cfg[1] }
  130. };
  131. static int ipr_max_bus_speeds [] = {
  132. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  133. };
  134. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  135. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  136. module_param_named(max_speed, ipr_max_speed, uint, 0);
  137. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  138. module_param_named(log_level, ipr_log_level, uint, 0);
  139. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  140. module_param_named(testmode, ipr_testmode, int, 0);
  141. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  142. module_param_named(fastfail, ipr_fastfail, int, 0);
  143. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  144. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  145. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  146. MODULE_LICENSE("GPL");
  147. MODULE_VERSION(IPR_DRIVER_VERSION);
  148. static const char *ipr_gpdd_dev_end_states[] = {
  149. "Command complete",
  150. "Terminated by host",
  151. "Terminated by device reset",
  152. "Terminated by bus reset",
  153. "Unknown",
  154. "Command not started"
  155. };
  156. static const char *ipr_gpdd_dev_bus_phases[] = {
  157. "Bus free",
  158. "Arbitration",
  159. "Selection",
  160. "Message out",
  161. "Command",
  162. "Message in",
  163. "Data out",
  164. "Data in",
  165. "Status",
  166. "Reselection",
  167. "Unknown"
  168. };
  169. /* A constant array of IOASCs/URCs/Error Messages */
  170. static const
  171. struct ipr_error_table_t ipr_error_table[] = {
  172. {0x00000000, 1, 1,
  173. "8155: An unknown error was received"},
  174. {0x00330000, 0, 0,
  175. "Soft underlength error"},
  176. {0x005A0000, 0, 0,
  177. "Command to be cancelled not found"},
  178. {0x00808000, 0, 0,
  179. "Qualified success"},
  180. {0x01080000, 1, 1,
  181. "FFFE: Soft device bus error recovered by the IOA"},
  182. {0x01170600, 0, 1,
  183. "FFF9: Device sector reassign successful"},
  184. {0x01170900, 0, 1,
  185. "FFF7: Media error recovered by device rewrite procedures"},
  186. {0x01180200, 0, 1,
  187. "7001: IOA sector reassignment successful"},
  188. {0x01180500, 0, 1,
  189. "FFF9: Soft media error. Sector reassignment recommended"},
  190. {0x01180600, 0, 1,
  191. "FFF7: Media error recovered by IOA rewrite procedures"},
  192. {0x01418000, 0, 1,
  193. "FF3D: Soft PCI bus error recovered by the IOA"},
  194. {0x01440000, 1, 1,
  195. "FFF6: Device hardware error recovered by the IOA"},
  196. {0x01448100, 0, 1,
  197. "FFF6: Device hardware error recovered by the device"},
  198. {0x01448200, 1, 1,
  199. "FF3D: Soft IOA error recovered by the IOA"},
  200. {0x01448300, 0, 1,
  201. "FFFA: Undefined device response recovered by the IOA"},
  202. {0x014A0000, 1, 1,
  203. "FFF6: Device bus error, message or command phase"},
  204. {0x015D0000, 0, 1,
  205. "FFF6: Failure prediction threshold exceeded"},
  206. {0x015D9200, 0, 1,
  207. "8009: Impending cache battery pack failure"},
  208. {0x02040400, 0, 0,
  209. "34FF: Disk device format in progress"},
  210. {0x023F0000, 0, 0,
  211. "Synchronization required"},
  212. {0x024E0000, 0, 0,
  213. "No ready, IOA shutdown"},
  214. {0x025A0000, 0, 0,
  215. "Not ready, IOA has been shutdown"},
  216. {0x02670100, 0, 1,
  217. "3020: Storage subsystem configuration error"},
  218. {0x03110B00, 0, 0,
  219. "FFF5: Medium error, data unreadable, recommend reassign"},
  220. {0x03110C00, 0, 0,
  221. "7000: Medium error, data unreadable, do not reassign"},
  222. {0x03310000, 0, 1,
  223. "FFF3: Disk media format bad"},
  224. {0x04050000, 0, 1,
  225. "3002: Addressed device failed to respond to selection"},
  226. {0x04080000, 1, 1,
  227. "3100: Device bus error"},
  228. {0x04080100, 0, 1,
  229. "3109: IOA timed out a device command"},
  230. {0x04088000, 0, 0,
  231. "3120: SCSI bus is not operational"},
  232. {0x04118000, 0, 1,
  233. "9000: IOA reserved area data check"},
  234. {0x04118100, 0, 1,
  235. "9001: IOA reserved area invalid data pattern"},
  236. {0x04118200, 0, 1,
  237. "9002: IOA reserved area LRC error"},
  238. {0x04320000, 0, 1,
  239. "102E: Out of alternate sectors for disk storage"},
  240. {0x04330000, 1, 1,
  241. "FFF4: Data transfer underlength error"},
  242. {0x04338000, 1, 1,
  243. "FFF4: Data transfer overlength error"},
  244. {0x043E0100, 0, 1,
  245. "3400: Logical unit failure"},
  246. {0x04408500, 0, 1,
  247. "FFF4: Device microcode is corrupt"},
  248. {0x04418000, 1, 1,
  249. "8150: PCI bus error"},
  250. {0x04430000, 1, 0,
  251. "Unsupported device bus message received"},
  252. {0x04440000, 1, 1,
  253. "FFF4: Disk device problem"},
  254. {0x04448200, 1, 1,
  255. "8150: Permanent IOA failure"},
  256. {0x04448300, 0, 1,
  257. "3010: Disk device returned wrong response to IOA"},
  258. {0x04448400, 0, 1,
  259. "8151: IOA microcode error"},
  260. {0x04448500, 0, 0,
  261. "Device bus status error"},
  262. {0x04448600, 0, 1,
  263. "8157: IOA error requiring IOA reset to recover"},
  264. {0x04490000, 0, 0,
  265. "Message reject received from the device"},
  266. {0x04449200, 0, 1,
  267. "8008: A permanent cache battery pack failure occurred"},
  268. {0x0444A000, 0, 1,
  269. "9090: Disk unit has been modified after the last known status"},
  270. {0x0444A200, 0, 1,
  271. "9081: IOA detected device error"},
  272. {0x0444A300, 0, 1,
  273. "9082: IOA detected device error"},
  274. {0x044A0000, 1, 1,
  275. "3110: Device bus error, message or command phase"},
  276. {0x04670400, 0, 1,
  277. "9091: Incorrect hardware configuration change has been detected"},
  278. {0x046E0000, 0, 1,
  279. "FFF4: Command to logical unit failed"},
  280. {0x05240000, 1, 0,
  281. "Illegal request, invalid request type or request packet"},
  282. {0x05250000, 0, 0,
  283. "Illegal request, invalid resource handle"},
  284. {0x05260000, 0, 0,
  285. "Illegal request, invalid field in parameter list"},
  286. {0x05260100, 0, 0,
  287. "Illegal request, parameter not supported"},
  288. {0x05260200, 0, 0,
  289. "Illegal request, parameter value invalid"},
  290. {0x052C0000, 0, 0,
  291. "Illegal request, command sequence error"},
  292. {0x06040500, 0, 1,
  293. "9031: Array protection temporarily suspended, protection resuming"},
  294. {0x06040600, 0, 1,
  295. "9040: Array protection temporarily suspended, protection resuming"},
  296. {0x06290000, 0, 1,
  297. "FFFB: SCSI bus was reset"},
  298. {0x06290500, 0, 0,
  299. "FFFE: SCSI bus transition to single ended"},
  300. {0x06290600, 0, 0,
  301. "FFFE: SCSI bus transition to LVD"},
  302. {0x06298000, 0, 1,
  303. "FFFB: SCSI bus was reset by another initiator"},
  304. {0x063F0300, 0, 1,
  305. "3029: A device replacement has occurred"},
  306. {0x064C8000, 0, 1,
  307. "9051: IOA cache data exists for a missing or failed device"},
  308. {0x06670100, 0, 1,
  309. "9025: Disk unit is not supported at its physical location"},
  310. {0x06670600, 0, 1,
  311. "3020: IOA detected a SCSI bus configuration error"},
  312. {0x06678000, 0, 1,
  313. "3150: SCSI bus configuration error"},
  314. {0x06690200, 0, 1,
  315. "9041: Array protection temporarily suspended"},
  316. {0x06698200, 0, 1,
  317. "9042: Corrupt array parity detected on specified device"},
  318. {0x066B0200, 0, 1,
  319. "9030: Array no longer protected due to missing or failed disk unit"},
  320. {0x066B8200, 0, 1,
  321. "9032: Array exposed but still protected"},
  322. {0x07270000, 0, 0,
  323. "Failure due to other device"},
  324. {0x07278000, 0, 1,
  325. "9008: IOA does not support functions expected by devices"},
  326. {0x07278100, 0, 1,
  327. "9010: Cache data associated with attached devices cannot be found"},
  328. {0x07278200, 0, 1,
  329. "9011: Cache data belongs to devices other than those attached"},
  330. {0x07278400, 0, 1,
  331. "9020: Array missing 2 or more devices with only 1 device present"},
  332. {0x07278500, 0, 1,
  333. "9021: Array missing 2 or more devices with 2 or more devices present"},
  334. {0x07278600, 0, 1,
  335. "9022: Exposed array is missing a required device"},
  336. {0x07278700, 0, 1,
  337. "9023: Array member(s) not at required physical locations"},
  338. {0x07278800, 0, 1,
  339. "9024: Array not functional due to present hardware configuration"},
  340. {0x07278900, 0, 1,
  341. "9026: Array not functional due to present hardware configuration"},
  342. {0x07278A00, 0, 1,
  343. "9027: Array is missing a device and parity is out of sync"},
  344. {0x07278B00, 0, 1,
  345. "9028: Maximum number of arrays already exist"},
  346. {0x07278C00, 0, 1,
  347. "9050: Required cache data cannot be located for a disk unit"},
  348. {0x07278D00, 0, 1,
  349. "9052: Cache data exists for a device that has been modified"},
  350. {0x07278F00, 0, 1,
  351. "9054: IOA resources not available due to previous problems"},
  352. {0x07279100, 0, 1,
  353. "9092: Disk unit requires initialization before use"},
  354. {0x07279200, 0, 1,
  355. "9029: Incorrect hardware configuration change has been detected"},
  356. {0x07279600, 0, 1,
  357. "9060: One or more disk pairs are missing from an array"},
  358. {0x07279700, 0, 1,
  359. "9061: One or more disks are missing from an array"},
  360. {0x07279800, 0, 1,
  361. "9062: One or more disks are missing from an array"},
  362. {0x07279900, 0, 1,
  363. "9063: Maximum number of functional arrays has been exceeded"},
  364. {0x0B260000, 0, 0,
  365. "Aborted command, invalid descriptor"},
  366. {0x0B5A0000, 0, 0,
  367. "Command terminated by host"}
  368. };
  369. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  370. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  371. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  372. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  373. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  374. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  375. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  376. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  377. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  378. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  379. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  380. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  381. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  382. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  383. };
  384. /*
  385. * Function Prototypes
  386. */
  387. static int ipr_reset_alert(struct ipr_cmnd *);
  388. static void ipr_process_ccn(struct ipr_cmnd *);
  389. static void ipr_process_error(struct ipr_cmnd *);
  390. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  391. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  392. enum ipr_shutdown_type);
  393. #ifdef CONFIG_SCSI_IPR_TRACE
  394. /**
  395. * ipr_trc_hook - Add a trace entry to the driver trace
  396. * @ipr_cmd: ipr command struct
  397. * @type: trace type
  398. * @add_data: additional data
  399. *
  400. * Return value:
  401. * none
  402. **/
  403. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  404. u8 type, u32 add_data)
  405. {
  406. struct ipr_trace_entry *trace_entry;
  407. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  408. trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
  409. trace_entry->time = jiffies;
  410. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  411. trace_entry->type = type;
  412. trace_entry->cmd_index = ipr_cmd->cmd_index;
  413. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  414. trace_entry->u.add_data = add_data;
  415. }
  416. #else
  417. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while(0)
  418. #endif
  419. /**
  420. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  421. * @ipr_cmd: ipr command struct
  422. *
  423. * Return value:
  424. * none
  425. **/
  426. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  427. {
  428. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  429. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  430. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  431. ioarcb->write_data_transfer_length = 0;
  432. ioarcb->read_data_transfer_length = 0;
  433. ioarcb->write_ioadl_len = 0;
  434. ioarcb->read_ioadl_len = 0;
  435. ioasa->ioasc = 0;
  436. ioasa->residual_data_len = 0;
  437. ipr_cmd->scsi_cmd = NULL;
  438. ipr_cmd->sense_buffer[0] = 0;
  439. ipr_cmd->dma_use_sg = 0;
  440. }
  441. /**
  442. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  443. * @ipr_cmd: ipr command struct
  444. *
  445. * Return value:
  446. * none
  447. **/
  448. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  449. {
  450. ipr_reinit_ipr_cmnd(ipr_cmd);
  451. ipr_cmd->u.scratch = 0;
  452. ipr_cmd->sibling = NULL;
  453. init_timer(&ipr_cmd->timer);
  454. }
  455. /**
  456. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  457. * @ioa_cfg: ioa config struct
  458. *
  459. * Return value:
  460. * pointer to ipr command struct
  461. **/
  462. static
  463. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  464. {
  465. struct ipr_cmnd *ipr_cmd;
  466. ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
  467. list_del(&ipr_cmd->queue);
  468. ipr_init_ipr_cmnd(ipr_cmd);
  469. return ipr_cmd;
  470. }
  471. /**
  472. * ipr_unmap_sglist - Unmap scatterlist if mapped
  473. * @ioa_cfg: ioa config struct
  474. * @ipr_cmd: ipr command struct
  475. *
  476. * Return value:
  477. * nothing
  478. **/
  479. static void ipr_unmap_sglist(struct ipr_ioa_cfg *ioa_cfg,
  480. struct ipr_cmnd *ipr_cmd)
  481. {
  482. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  483. if (ipr_cmd->dma_use_sg) {
  484. if (scsi_cmd->use_sg > 0) {
  485. pci_unmap_sg(ioa_cfg->pdev, scsi_cmd->request_buffer,
  486. scsi_cmd->use_sg,
  487. scsi_cmd->sc_data_direction);
  488. } else {
  489. pci_unmap_single(ioa_cfg->pdev, ipr_cmd->dma_handle,
  490. scsi_cmd->request_bufflen,
  491. scsi_cmd->sc_data_direction);
  492. }
  493. }
  494. }
  495. /**
  496. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  497. * @ioa_cfg: ioa config struct
  498. * @clr_ints: interrupts to clear
  499. *
  500. * This function masks all interrupts on the adapter, then clears the
  501. * interrupts specified in the mask
  502. *
  503. * Return value:
  504. * none
  505. **/
  506. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  507. u32 clr_ints)
  508. {
  509. volatile u32 int_reg;
  510. /* Stop new interrupts */
  511. ioa_cfg->allow_interrupts = 0;
  512. /* Set interrupt mask to stop all new interrupts */
  513. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  514. /* Clear any pending interrupts */
  515. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg);
  516. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  517. }
  518. /**
  519. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  520. * @ioa_cfg: ioa config struct
  521. *
  522. * Return value:
  523. * 0 on success / -EIO on failure
  524. **/
  525. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  526. {
  527. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  528. if (pcix_cmd_reg == 0) {
  529. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  530. return -EIO;
  531. }
  532. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  533. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  534. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  535. return -EIO;
  536. }
  537. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  538. return 0;
  539. }
  540. /**
  541. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  542. * @ioa_cfg: ioa config struct
  543. *
  544. * Return value:
  545. * 0 on success / -EIO on failure
  546. **/
  547. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  548. {
  549. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  550. if (pcix_cmd_reg) {
  551. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  552. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  553. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  554. return -EIO;
  555. }
  556. } else {
  557. dev_err(&ioa_cfg->pdev->dev,
  558. "Failed to setup PCI-X command register\n");
  559. return -EIO;
  560. }
  561. return 0;
  562. }
  563. /**
  564. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  565. * @ipr_cmd: ipr command struct
  566. *
  567. * This function is invoked by the interrupt handler for
  568. * ops generated by the SCSI mid-layer which are being aborted.
  569. *
  570. * Return value:
  571. * none
  572. **/
  573. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  574. {
  575. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  576. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  577. scsi_cmd->result |= (DID_ERROR << 16);
  578. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  579. scsi_cmd->scsi_done(scsi_cmd);
  580. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  581. }
  582. /**
  583. * ipr_fail_all_ops - Fails all outstanding ops.
  584. * @ioa_cfg: ioa config struct
  585. *
  586. * This function fails all outstanding ops.
  587. *
  588. * Return value:
  589. * none
  590. **/
  591. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  592. {
  593. struct ipr_cmnd *ipr_cmd, *temp;
  594. ENTER;
  595. list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
  596. list_del(&ipr_cmd->queue);
  597. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  598. ipr_cmd->ioasa.ilid = cpu_to_be32(IPR_DRIVER_ILID);
  599. if (ipr_cmd->scsi_cmd)
  600. ipr_cmd->done = ipr_scsi_eh_done;
  601. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
  602. del_timer(&ipr_cmd->timer);
  603. ipr_cmd->done(ipr_cmd);
  604. }
  605. LEAVE;
  606. }
  607. /**
  608. * ipr_do_req - Send driver initiated requests.
  609. * @ipr_cmd: ipr command struct
  610. * @done: done function
  611. * @timeout_func: timeout function
  612. * @timeout: timeout value
  613. *
  614. * This function sends the specified command to the adapter with the
  615. * timeout given. The done function is invoked on command completion.
  616. *
  617. * Return value:
  618. * none
  619. **/
  620. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  621. void (*done) (struct ipr_cmnd *),
  622. void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
  623. {
  624. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  625. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  626. ipr_cmd->done = done;
  627. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  628. ipr_cmd->timer.expires = jiffies + timeout;
  629. ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
  630. add_timer(&ipr_cmd->timer);
  631. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  632. mb();
  633. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  634. ioa_cfg->regs.ioarrin_reg);
  635. }
  636. /**
  637. * ipr_internal_cmd_done - Op done function for an internally generated op.
  638. * @ipr_cmd: ipr command struct
  639. *
  640. * This function is the op done function for an internally generated,
  641. * blocking op. It simply wakes the sleeping thread.
  642. *
  643. * Return value:
  644. * none
  645. **/
  646. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  647. {
  648. if (ipr_cmd->sibling)
  649. ipr_cmd->sibling = NULL;
  650. else
  651. complete(&ipr_cmd->completion);
  652. }
  653. /**
  654. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  655. * @ipr_cmd: ipr command struct
  656. * @timeout_func: function to invoke if command times out
  657. * @timeout: timeout
  658. *
  659. * Return value:
  660. * none
  661. **/
  662. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  663. void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
  664. u32 timeout)
  665. {
  666. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  667. init_completion(&ipr_cmd->completion);
  668. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  669. spin_unlock_irq(ioa_cfg->host->host_lock);
  670. wait_for_completion(&ipr_cmd->completion);
  671. spin_lock_irq(ioa_cfg->host->host_lock);
  672. }
  673. /**
  674. * ipr_send_hcam - Send an HCAM to the adapter.
  675. * @ioa_cfg: ioa config struct
  676. * @type: HCAM type
  677. * @hostrcb: hostrcb struct
  678. *
  679. * This function will send a Host Controlled Async command to the adapter.
  680. * If HCAMs are currently not allowed to be issued to the adapter, it will
  681. * place the hostrcb on the free queue.
  682. *
  683. * Return value:
  684. * none
  685. **/
  686. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  687. struct ipr_hostrcb *hostrcb)
  688. {
  689. struct ipr_cmnd *ipr_cmd;
  690. struct ipr_ioarcb *ioarcb;
  691. if (ioa_cfg->allow_cmds) {
  692. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  693. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  694. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  695. ipr_cmd->u.hostrcb = hostrcb;
  696. ioarcb = &ipr_cmd->ioarcb;
  697. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  698. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  699. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  700. ioarcb->cmd_pkt.cdb[1] = type;
  701. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  702. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  703. ioarcb->read_data_transfer_length = cpu_to_be32(sizeof(hostrcb->hcam));
  704. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  705. ipr_cmd->ioadl[0].flags_and_data_len =
  706. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(hostrcb->hcam));
  707. ipr_cmd->ioadl[0].address = cpu_to_be32(hostrcb->hostrcb_dma);
  708. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  709. ipr_cmd->done = ipr_process_ccn;
  710. else
  711. ipr_cmd->done = ipr_process_error;
  712. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  713. mb();
  714. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  715. ioa_cfg->regs.ioarrin_reg);
  716. } else {
  717. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  718. }
  719. }
  720. /**
  721. * ipr_init_res_entry - Initialize a resource entry struct.
  722. * @res: resource entry struct
  723. *
  724. * Return value:
  725. * none
  726. **/
  727. static void ipr_init_res_entry(struct ipr_resource_entry *res)
  728. {
  729. res->needs_sync_complete = 1;
  730. res->in_erp = 0;
  731. res->add_to_ml = 0;
  732. res->del_from_ml = 0;
  733. res->resetting_device = 0;
  734. res->sdev = NULL;
  735. }
  736. /**
  737. * ipr_handle_config_change - Handle a config change from the adapter
  738. * @ioa_cfg: ioa config struct
  739. * @hostrcb: hostrcb
  740. *
  741. * Return value:
  742. * none
  743. **/
  744. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  745. struct ipr_hostrcb *hostrcb)
  746. {
  747. struct ipr_resource_entry *res = NULL;
  748. struct ipr_config_table_entry *cfgte;
  749. u32 is_ndn = 1;
  750. cfgte = &hostrcb->hcam.u.ccn.cfgte;
  751. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  752. if (!memcmp(&res->cfgte.res_addr, &cfgte->res_addr,
  753. sizeof(cfgte->res_addr))) {
  754. is_ndn = 0;
  755. break;
  756. }
  757. }
  758. if (is_ndn) {
  759. if (list_empty(&ioa_cfg->free_res_q)) {
  760. ipr_send_hcam(ioa_cfg,
  761. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  762. hostrcb);
  763. return;
  764. }
  765. res = list_entry(ioa_cfg->free_res_q.next,
  766. struct ipr_resource_entry, queue);
  767. list_del(&res->queue);
  768. ipr_init_res_entry(res);
  769. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  770. }
  771. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  772. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  773. if (res->sdev) {
  774. res->sdev->hostdata = NULL;
  775. res->del_from_ml = 1;
  776. if (ioa_cfg->allow_ml_add_del)
  777. schedule_work(&ioa_cfg->work_q);
  778. } else
  779. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  780. } else if (!res->sdev) {
  781. res->add_to_ml = 1;
  782. if (ioa_cfg->allow_ml_add_del)
  783. schedule_work(&ioa_cfg->work_q);
  784. }
  785. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  786. }
  787. /**
  788. * ipr_process_ccn - Op done function for a CCN.
  789. * @ipr_cmd: ipr command struct
  790. *
  791. * This function is the op done function for a configuration
  792. * change notification host controlled async from the adapter.
  793. *
  794. * Return value:
  795. * none
  796. **/
  797. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  798. {
  799. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  800. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  801. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  802. list_del(&hostrcb->queue);
  803. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  804. if (ioasc) {
  805. if (ioasc != IPR_IOASC_IOA_WAS_RESET)
  806. dev_err(&ioa_cfg->pdev->dev,
  807. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  808. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  809. } else {
  810. ipr_handle_config_change(ioa_cfg, hostrcb);
  811. }
  812. }
  813. /**
  814. * ipr_log_vpd - Log the passed VPD to the error log.
  815. * @vpids: vendor/product id struct
  816. * @serial_num: serial number string
  817. *
  818. * Return value:
  819. * none
  820. **/
  821. static void ipr_log_vpd(struct ipr_std_inq_vpids *vpids, u8 *serial_num)
  822. {
  823. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  824. + IPR_SERIAL_NUM_LEN];
  825. memcpy(buffer, vpids->vendor_id, IPR_VENDOR_ID_LEN);
  826. memcpy(buffer + IPR_VENDOR_ID_LEN, vpids->product_id,
  827. IPR_PROD_ID_LEN);
  828. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  829. ipr_err("Vendor/Product ID: %s\n", buffer);
  830. memcpy(buffer, serial_num, IPR_SERIAL_NUM_LEN);
  831. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  832. ipr_err(" Serial Number: %s\n", buffer);
  833. }
  834. /**
  835. * ipr_log_cache_error - Log a cache error.
  836. * @ioa_cfg: ioa config struct
  837. * @hostrcb: hostrcb struct
  838. *
  839. * Return value:
  840. * none
  841. **/
  842. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  843. struct ipr_hostrcb *hostrcb)
  844. {
  845. struct ipr_hostrcb_type_02_error *error =
  846. &hostrcb->hcam.u.error.u.type_02_error;
  847. ipr_err("-----Current Configuration-----\n");
  848. ipr_err("Cache Directory Card Information:\n");
  849. ipr_log_vpd(&error->ioa_vpids, error->ioa_sn);
  850. ipr_err("Adapter Card Information:\n");
  851. ipr_log_vpd(&error->cfc_vpids, error->cfc_sn);
  852. ipr_err("-----Expected Configuration-----\n");
  853. ipr_err("Cache Directory Card Information:\n");
  854. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpids,
  855. error->ioa_last_attached_to_cfc_sn);
  856. ipr_err("Adapter Card Information:\n");
  857. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpids,
  858. error->cfc_last_attached_to_ioa_sn);
  859. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  860. be32_to_cpu(error->ioa_data[0]),
  861. be32_to_cpu(error->ioa_data[1]),
  862. be32_to_cpu(error->ioa_data[2]));
  863. }
  864. /**
  865. * ipr_log_config_error - Log a configuration error.
  866. * @ioa_cfg: ioa config struct
  867. * @hostrcb: hostrcb struct
  868. *
  869. * Return value:
  870. * none
  871. **/
  872. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  873. struct ipr_hostrcb *hostrcb)
  874. {
  875. int errors_logged, i;
  876. struct ipr_hostrcb_device_data_entry *dev_entry;
  877. struct ipr_hostrcb_type_03_error *error;
  878. error = &hostrcb->hcam.u.error.u.type_03_error;
  879. errors_logged = be32_to_cpu(error->errors_logged);
  880. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  881. be32_to_cpu(error->errors_detected), errors_logged);
  882. dev_entry = error->dev_entry;
  883. for (i = 0; i < errors_logged; i++, dev_entry++) {
  884. ipr_err_separator;
  885. if (dev_entry->dev_res_addr.bus >= IPR_MAX_NUM_BUSES) {
  886. ipr_err("Device %d: missing\n", i + 1);
  887. } else {
  888. ipr_err("Device %d: %d:%d:%d:%d\n", i + 1,
  889. ioa_cfg->host->host_no, dev_entry->dev_res_addr.bus,
  890. dev_entry->dev_res_addr.target, dev_entry->dev_res_addr.lun);
  891. }
  892. ipr_log_vpd(&dev_entry->dev_vpids, dev_entry->dev_sn);
  893. ipr_err("-----New Device Information-----\n");
  894. ipr_log_vpd(&dev_entry->new_dev_vpids, dev_entry->new_dev_sn);
  895. ipr_err("Cache Directory Card Information:\n");
  896. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpids,
  897. dev_entry->ioa_last_with_dev_sn);
  898. ipr_err("Adapter Card Information:\n");
  899. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpids,
  900. dev_entry->cfc_last_with_dev_sn);
  901. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  902. be32_to_cpu(dev_entry->ioa_data[0]),
  903. be32_to_cpu(dev_entry->ioa_data[1]),
  904. be32_to_cpu(dev_entry->ioa_data[2]),
  905. be32_to_cpu(dev_entry->ioa_data[3]),
  906. be32_to_cpu(dev_entry->ioa_data[4]));
  907. }
  908. }
  909. /**
  910. * ipr_log_array_error - Log an array configuration error.
  911. * @ioa_cfg: ioa config struct
  912. * @hostrcb: hostrcb struct
  913. *
  914. * Return value:
  915. * none
  916. **/
  917. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  918. struct ipr_hostrcb *hostrcb)
  919. {
  920. int i;
  921. struct ipr_hostrcb_type_04_error *error;
  922. struct ipr_hostrcb_array_data_entry *array_entry;
  923. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  924. error = &hostrcb->hcam.u.error.u.type_04_error;
  925. ipr_err_separator;
  926. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  927. error->protection_level,
  928. ioa_cfg->host->host_no,
  929. error->last_func_vset_res_addr.bus,
  930. error->last_func_vset_res_addr.target,
  931. error->last_func_vset_res_addr.lun);
  932. ipr_err_separator;
  933. array_entry = error->array_member;
  934. for (i = 0; i < 18; i++) {
  935. if (!memcmp(array_entry->serial_num, zero_sn, IPR_SERIAL_NUM_LEN))
  936. continue;
  937. if (be32_to_cpu(error->exposed_mode_adn) == i) {
  938. ipr_err("Exposed Array Member %d:\n", i);
  939. } else {
  940. ipr_err("Array Member %d:\n", i);
  941. }
  942. ipr_log_vpd(&array_entry->vpids, array_entry->serial_num);
  943. if (array_entry->dev_res_addr.bus >= IPR_MAX_NUM_BUSES) {
  944. ipr_err("Current Location: unknown\n");
  945. } else {
  946. ipr_err("Current Location: %d:%d:%d:%d\n",
  947. ioa_cfg->host->host_no,
  948. array_entry->dev_res_addr.bus,
  949. array_entry->dev_res_addr.target,
  950. array_entry->dev_res_addr.lun);
  951. }
  952. if (array_entry->expected_dev_res_addr.bus >= IPR_MAX_NUM_BUSES) {
  953. ipr_err("Expected Location: unknown\n");
  954. } else {
  955. ipr_err("Expected Location: %d:%d:%d:%d\n",
  956. ioa_cfg->host->host_no,
  957. array_entry->expected_dev_res_addr.bus,
  958. array_entry->expected_dev_res_addr.target,
  959. array_entry->expected_dev_res_addr.lun);
  960. }
  961. ipr_err_separator;
  962. if (i == 9)
  963. array_entry = error->array_member2;
  964. else
  965. array_entry++;
  966. }
  967. }
  968. /**
  969. * ipr_log_generic_error - Log an adapter error.
  970. * @ioa_cfg: ioa config struct
  971. * @hostrcb: hostrcb struct
  972. *
  973. * Return value:
  974. * none
  975. **/
  976. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  977. struct ipr_hostrcb *hostrcb)
  978. {
  979. int i;
  980. int ioa_data_len = be32_to_cpu(hostrcb->hcam.length);
  981. if (ioa_data_len == 0)
  982. return;
  983. ipr_err("IOA Error Data:\n");
  984. ipr_err("Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F\n");
  985. for (i = 0; i < ioa_data_len / 4; i += 4) {
  986. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  987. be32_to_cpu(hostrcb->hcam.u.raw.data[i]),
  988. be32_to_cpu(hostrcb->hcam.u.raw.data[i+1]),
  989. be32_to_cpu(hostrcb->hcam.u.raw.data[i+2]),
  990. be32_to_cpu(hostrcb->hcam.u.raw.data[i+3]));
  991. }
  992. }
  993. /**
  994. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  995. * @ioasc: IOASC
  996. *
  997. * This function will return the index of into the ipr_error_table
  998. * for the specified IOASC. If the IOASC is not in the table,
  999. * 0 will be returned, which points to the entry used for unknown errors.
  1000. *
  1001. * Return value:
  1002. * index into the ipr_error_table
  1003. **/
  1004. static u32 ipr_get_error(u32 ioasc)
  1005. {
  1006. int i;
  1007. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  1008. if (ipr_error_table[i].ioasc == ioasc)
  1009. return i;
  1010. return 0;
  1011. }
  1012. /**
  1013. * ipr_handle_log_data - Log an adapter error.
  1014. * @ioa_cfg: ioa config struct
  1015. * @hostrcb: hostrcb struct
  1016. *
  1017. * This function logs an adapter error to the system.
  1018. *
  1019. * Return value:
  1020. * none
  1021. **/
  1022. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  1023. struct ipr_hostrcb *hostrcb)
  1024. {
  1025. u32 ioasc;
  1026. int error_index;
  1027. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  1028. return;
  1029. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  1030. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  1031. ioasc = be32_to_cpu(hostrcb->hcam.u.error.failing_dev_ioasc);
  1032. if (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  1033. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER) {
  1034. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  1035. scsi_report_bus_reset(ioa_cfg->host,
  1036. hostrcb->hcam.u.error.failing_dev_res_addr.bus);
  1037. }
  1038. error_index = ipr_get_error(ioasc);
  1039. if (!ipr_error_table[error_index].log_hcam)
  1040. return;
  1041. if (ipr_is_device(&hostrcb->hcam.u.error.failing_dev_res_addr)) {
  1042. ipr_res_err(ioa_cfg, hostrcb->hcam.u.error.failing_dev_res_addr,
  1043. "%s\n", ipr_error_table[error_index].error);
  1044. } else {
  1045. dev_err(&ioa_cfg->pdev->dev, "%s\n",
  1046. ipr_error_table[error_index].error);
  1047. }
  1048. /* Set indication we have logged an error */
  1049. ioa_cfg->errors_logged++;
  1050. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  1051. return;
  1052. switch (hostrcb->hcam.overlay_id) {
  1053. case IPR_HOST_RCB_OVERLAY_ID_1:
  1054. ipr_log_generic_error(ioa_cfg, hostrcb);
  1055. break;
  1056. case IPR_HOST_RCB_OVERLAY_ID_2:
  1057. ipr_log_cache_error(ioa_cfg, hostrcb);
  1058. break;
  1059. case IPR_HOST_RCB_OVERLAY_ID_3:
  1060. ipr_log_config_error(ioa_cfg, hostrcb);
  1061. break;
  1062. case IPR_HOST_RCB_OVERLAY_ID_4:
  1063. case IPR_HOST_RCB_OVERLAY_ID_6:
  1064. ipr_log_array_error(ioa_cfg, hostrcb);
  1065. break;
  1066. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  1067. ipr_log_generic_error(ioa_cfg, hostrcb);
  1068. break;
  1069. default:
  1070. dev_err(&ioa_cfg->pdev->dev,
  1071. "Unknown error received. Overlay ID: %d\n",
  1072. hostrcb->hcam.overlay_id);
  1073. break;
  1074. }
  1075. }
  1076. /**
  1077. * ipr_process_error - Op done function for an adapter error log.
  1078. * @ipr_cmd: ipr command struct
  1079. *
  1080. * This function is the op done function for an error log host
  1081. * controlled async from the adapter. It will log the error and
  1082. * send the HCAM back to the adapter.
  1083. *
  1084. * Return value:
  1085. * none
  1086. **/
  1087. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  1088. {
  1089. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1090. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1091. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  1092. list_del(&hostrcb->queue);
  1093. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  1094. if (!ioasc) {
  1095. ipr_handle_log_data(ioa_cfg, hostrcb);
  1096. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
  1097. dev_err(&ioa_cfg->pdev->dev,
  1098. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1099. }
  1100. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  1101. }
  1102. /**
  1103. * ipr_timeout - An internally generated op has timed out.
  1104. * @ipr_cmd: ipr command struct
  1105. *
  1106. * This function blocks host requests and initiates an
  1107. * adapter reset.
  1108. *
  1109. * Return value:
  1110. * none
  1111. **/
  1112. static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
  1113. {
  1114. unsigned long lock_flags = 0;
  1115. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1116. ENTER;
  1117. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1118. ioa_cfg->errors_logged++;
  1119. dev_err(&ioa_cfg->pdev->dev,
  1120. "Adapter being reset due to command timeout.\n");
  1121. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1122. ioa_cfg->sdt_state = GET_DUMP;
  1123. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  1124. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1125. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1126. LEAVE;
  1127. }
  1128. /**
  1129. * ipr_oper_timeout - Adapter timed out transitioning to operational
  1130. * @ipr_cmd: ipr command struct
  1131. *
  1132. * This function blocks host requests and initiates an
  1133. * adapter reset.
  1134. *
  1135. * Return value:
  1136. * none
  1137. **/
  1138. static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
  1139. {
  1140. unsigned long lock_flags = 0;
  1141. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1142. ENTER;
  1143. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1144. ioa_cfg->errors_logged++;
  1145. dev_err(&ioa_cfg->pdev->dev,
  1146. "Adapter timed out transitioning to operational.\n");
  1147. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  1148. ioa_cfg->sdt_state = GET_DUMP;
  1149. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  1150. if (ipr_fastfail)
  1151. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  1152. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1153. }
  1154. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1155. LEAVE;
  1156. }
  1157. /**
  1158. * ipr_reset_reload - Reset/Reload the IOA
  1159. * @ioa_cfg: ioa config struct
  1160. * @shutdown_type: shutdown type
  1161. *
  1162. * This function resets the adapter and re-initializes it.
  1163. * This function assumes that all new host commands have been stopped.
  1164. * Return value:
  1165. * SUCCESS / FAILED
  1166. **/
  1167. static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
  1168. enum ipr_shutdown_type shutdown_type)
  1169. {
  1170. if (!ioa_cfg->in_reset_reload)
  1171. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  1172. spin_unlock_irq(ioa_cfg->host->host_lock);
  1173. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1174. spin_lock_irq(ioa_cfg->host->host_lock);
  1175. /* If we got hit with a host reset while we were already resetting
  1176. the adapter for some reason, and the reset failed. */
  1177. if (ioa_cfg->ioa_is_dead) {
  1178. ipr_trace;
  1179. return FAILED;
  1180. }
  1181. return SUCCESS;
  1182. }
  1183. /**
  1184. * ipr_find_ses_entry - Find matching SES in SES table
  1185. * @res: resource entry struct of SES
  1186. *
  1187. * Return value:
  1188. * pointer to SES table entry / NULL on failure
  1189. **/
  1190. static const struct ipr_ses_table_entry *
  1191. ipr_find_ses_entry(struct ipr_resource_entry *res)
  1192. {
  1193. int i, j, matches;
  1194. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  1195. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  1196. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  1197. if (ste->compare_product_id_byte[j] == 'X') {
  1198. if (res->cfgte.std_inq_data.vpids.product_id[j] == ste->product_id[j])
  1199. matches++;
  1200. else
  1201. break;
  1202. } else
  1203. matches++;
  1204. }
  1205. if (matches == IPR_PROD_ID_LEN)
  1206. return ste;
  1207. }
  1208. return NULL;
  1209. }
  1210. /**
  1211. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  1212. * @ioa_cfg: ioa config struct
  1213. * @bus: SCSI bus
  1214. * @bus_width: bus width
  1215. *
  1216. * Return value:
  1217. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  1218. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  1219. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  1220. * max 160MHz = max 320MB/sec).
  1221. **/
  1222. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  1223. {
  1224. struct ipr_resource_entry *res;
  1225. const struct ipr_ses_table_entry *ste;
  1226. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  1227. /* Loop through each config table entry in the config table buffer */
  1228. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1229. if (!(IPR_IS_SES_DEVICE(res->cfgte.std_inq_data)))
  1230. continue;
  1231. if (bus != res->cfgte.res_addr.bus)
  1232. continue;
  1233. if (!(ste = ipr_find_ses_entry(res)))
  1234. continue;
  1235. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  1236. }
  1237. return max_xfer_rate;
  1238. }
  1239. /**
  1240. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  1241. * @ioa_cfg: ioa config struct
  1242. * @max_delay: max delay in micro-seconds to wait
  1243. *
  1244. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  1245. *
  1246. * Return value:
  1247. * 0 on success / other on failure
  1248. **/
  1249. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  1250. {
  1251. volatile u32 pcii_reg;
  1252. int delay = 1;
  1253. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  1254. while (delay < max_delay) {
  1255. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  1256. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  1257. return 0;
  1258. /* udelay cannot be used if delay is more than a few milliseconds */
  1259. if ((delay / 1000) > MAX_UDELAY_MS)
  1260. mdelay(delay / 1000);
  1261. else
  1262. udelay(delay);
  1263. delay += delay;
  1264. }
  1265. return -EIO;
  1266. }
  1267. /**
  1268. * ipr_get_ldump_data_section - Dump IOA memory
  1269. * @ioa_cfg: ioa config struct
  1270. * @start_addr: adapter address to dump
  1271. * @dest: destination kernel buffer
  1272. * @length_in_words: length to dump in 4 byte words
  1273. *
  1274. * Return value:
  1275. * 0 on success / -EIO on failure
  1276. **/
  1277. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  1278. u32 start_addr,
  1279. __be32 *dest, u32 length_in_words)
  1280. {
  1281. volatile u32 temp_pcii_reg;
  1282. int i, delay = 0;
  1283. /* Write IOA interrupt reg starting LDUMP state */
  1284. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  1285. ioa_cfg->regs.set_uproc_interrupt_reg);
  1286. /* Wait for IO debug acknowledge */
  1287. if (ipr_wait_iodbg_ack(ioa_cfg,
  1288. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  1289. dev_err(&ioa_cfg->pdev->dev,
  1290. "IOA dump long data transfer timeout\n");
  1291. return -EIO;
  1292. }
  1293. /* Signal LDUMP interlocked - clear IO debug ack */
  1294. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1295. ioa_cfg->regs.clr_interrupt_reg);
  1296. /* Write Mailbox with starting address */
  1297. writel(start_addr, ioa_cfg->ioa_mailbox);
  1298. /* Signal address valid - clear IOA Reset alert */
  1299. writel(IPR_UPROCI_RESET_ALERT,
  1300. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1301. for (i = 0; i < length_in_words; i++) {
  1302. /* Wait for IO debug acknowledge */
  1303. if (ipr_wait_iodbg_ack(ioa_cfg,
  1304. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  1305. dev_err(&ioa_cfg->pdev->dev,
  1306. "IOA dump short data transfer timeout\n");
  1307. return -EIO;
  1308. }
  1309. /* Read data from mailbox and increment destination pointer */
  1310. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  1311. dest++;
  1312. /* For all but the last word of data, signal data received */
  1313. if (i < (length_in_words - 1)) {
  1314. /* Signal dump data received - Clear IO debug Ack */
  1315. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1316. ioa_cfg->regs.clr_interrupt_reg);
  1317. }
  1318. }
  1319. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  1320. writel(IPR_UPROCI_RESET_ALERT,
  1321. ioa_cfg->regs.set_uproc_interrupt_reg);
  1322. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  1323. ioa_cfg->regs.clr_uproc_interrupt_reg);
  1324. /* Signal dump data received - Clear IO debug Ack */
  1325. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  1326. ioa_cfg->regs.clr_interrupt_reg);
  1327. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  1328. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  1329. temp_pcii_reg =
  1330. readl(ioa_cfg->regs.sense_uproc_interrupt_reg);
  1331. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  1332. return 0;
  1333. udelay(10);
  1334. delay += 10;
  1335. }
  1336. return 0;
  1337. }
  1338. #ifdef CONFIG_SCSI_IPR_DUMP
  1339. /**
  1340. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  1341. * @ioa_cfg: ioa config struct
  1342. * @pci_address: adapter address
  1343. * @length: length of data to copy
  1344. *
  1345. * Copy data from PCI adapter to kernel buffer.
  1346. * Note: length MUST be a 4 byte multiple
  1347. * Return value:
  1348. * 0 on success / other on failure
  1349. **/
  1350. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  1351. unsigned long pci_address, u32 length)
  1352. {
  1353. int bytes_copied = 0;
  1354. int cur_len, rc, rem_len, rem_page_len;
  1355. __be32 *page;
  1356. unsigned long lock_flags = 0;
  1357. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  1358. while (bytes_copied < length &&
  1359. (ioa_dump->hdr.len + bytes_copied) < IPR_MAX_IOA_DUMP_SIZE) {
  1360. if (ioa_dump->page_offset >= PAGE_SIZE ||
  1361. ioa_dump->page_offset == 0) {
  1362. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  1363. if (!page) {
  1364. ipr_trace;
  1365. return bytes_copied;
  1366. }
  1367. ioa_dump->page_offset = 0;
  1368. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  1369. ioa_dump->next_page_index++;
  1370. } else
  1371. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  1372. rem_len = length - bytes_copied;
  1373. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  1374. cur_len = min(rem_len, rem_page_len);
  1375. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1376. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  1377. rc = -EIO;
  1378. } else {
  1379. rc = ipr_get_ldump_data_section(ioa_cfg,
  1380. pci_address + bytes_copied,
  1381. &page[ioa_dump->page_offset / 4],
  1382. (cur_len / sizeof(u32)));
  1383. }
  1384. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1385. if (!rc) {
  1386. ioa_dump->page_offset += cur_len;
  1387. bytes_copied += cur_len;
  1388. } else {
  1389. ipr_trace;
  1390. break;
  1391. }
  1392. schedule();
  1393. }
  1394. return bytes_copied;
  1395. }
  1396. /**
  1397. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  1398. * @hdr: dump entry header struct
  1399. *
  1400. * Return value:
  1401. * nothing
  1402. **/
  1403. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  1404. {
  1405. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  1406. hdr->num_elems = 1;
  1407. hdr->offset = sizeof(*hdr);
  1408. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  1409. }
  1410. /**
  1411. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  1412. * @ioa_cfg: ioa config struct
  1413. * @driver_dump: driver dump struct
  1414. *
  1415. * Return value:
  1416. * nothing
  1417. **/
  1418. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  1419. struct ipr_driver_dump *driver_dump)
  1420. {
  1421. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  1422. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  1423. driver_dump->ioa_type_entry.hdr.len =
  1424. sizeof(struct ipr_dump_ioa_type_entry) -
  1425. sizeof(struct ipr_dump_entry_header);
  1426. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1427. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  1428. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  1429. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  1430. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  1431. ucode_vpd->minor_release[1];
  1432. driver_dump->hdr.num_entries++;
  1433. }
  1434. /**
  1435. * ipr_dump_version_data - Fill in the driver version in the dump.
  1436. * @ioa_cfg: ioa config struct
  1437. * @driver_dump: driver dump struct
  1438. *
  1439. * Return value:
  1440. * nothing
  1441. **/
  1442. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  1443. struct ipr_driver_dump *driver_dump)
  1444. {
  1445. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  1446. driver_dump->version_entry.hdr.len =
  1447. sizeof(struct ipr_dump_version_entry) -
  1448. sizeof(struct ipr_dump_entry_header);
  1449. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1450. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  1451. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  1452. driver_dump->hdr.num_entries++;
  1453. }
  1454. /**
  1455. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  1456. * @ioa_cfg: ioa config struct
  1457. * @driver_dump: driver dump struct
  1458. *
  1459. * Return value:
  1460. * nothing
  1461. **/
  1462. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  1463. struct ipr_driver_dump *driver_dump)
  1464. {
  1465. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  1466. driver_dump->trace_entry.hdr.len =
  1467. sizeof(struct ipr_dump_trace_entry) -
  1468. sizeof(struct ipr_dump_entry_header);
  1469. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1470. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  1471. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  1472. driver_dump->hdr.num_entries++;
  1473. }
  1474. /**
  1475. * ipr_dump_location_data - Fill in the IOA location in the dump.
  1476. * @ioa_cfg: ioa config struct
  1477. * @driver_dump: driver dump struct
  1478. *
  1479. * Return value:
  1480. * nothing
  1481. **/
  1482. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  1483. struct ipr_driver_dump *driver_dump)
  1484. {
  1485. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  1486. driver_dump->location_entry.hdr.len =
  1487. sizeof(struct ipr_dump_location_entry) -
  1488. sizeof(struct ipr_dump_entry_header);
  1489. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  1490. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  1491. strcpy(driver_dump->location_entry.location, ioa_cfg->pdev->dev.bus_id);
  1492. driver_dump->hdr.num_entries++;
  1493. }
  1494. /**
  1495. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  1496. * @ioa_cfg: ioa config struct
  1497. * @dump: dump struct
  1498. *
  1499. * Return value:
  1500. * nothing
  1501. **/
  1502. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  1503. {
  1504. unsigned long start_addr, sdt_word;
  1505. unsigned long lock_flags = 0;
  1506. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  1507. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  1508. u32 num_entries, start_off, end_off;
  1509. u32 bytes_to_copy, bytes_copied, rc;
  1510. struct ipr_sdt *sdt;
  1511. int i;
  1512. ENTER;
  1513. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1514. if (ioa_cfg->sdt_state != GET_DUMP) {
  1515. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1516. return;
  1517. }
  1518. start_addr = readl(ioa_cfg->ioa_mailbox);
  1519. if (!ipr_sdt_is_fmt2(start_addr)) {
  1520. dev_err(&ioa_cfg->pdev->dev,
  1521. "Invalid dump table format: %lx\n", start_addr);
  1522. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1523. return;
  1524. }
  1525. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  1526. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  1527. /* Initialize the overall dump header */
  1528. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  1529. driver_dump->hdr.num_entries = 1;
  1530. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  1531. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  1532. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  1533. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  1534. ipr_dump_version_data(ioa_cfg, driver_dump);
  1535. ipr_dump_location_data(ioa_cfg, driver_dump);
  1536. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  1537. ipr_dump_trace_data(ioa_cfg, driver_dump);
  1538. /* Update dump_header */
  1539. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  1540. /* IOA Dump entry */
  1541. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  1542. ioa_dump->format = IPR_SDT_FMT2;
  1543. ioa_dump->hdr.len = 0;
  1544. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  1545. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  1546. /* First entries in sdt are actually a list of dump addresses and
  1547. lengths to gather the real dump data. sdt represents the pointer
  1548. to the ioa generated dump table. Dump data will be extracted based
  1549. on entries in this table */
  1550. sdt = &ioa_dump->sdt;
  1551. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  1552. sizeof(struct ipr_sdt) / sizeof(__be32));
  1553. /* Smart Dump table is ready to use and the first entry is valid */
  1554. if (rc || (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE)) {
  1555. dev_err(&ioa_cfg->pdev->dev,
  1556. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  1557. rc, be32_to_cpu(sdt->hdr.state));
  1558. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  1559. ioa_cfg->sdt_state = DUMP_OBTAINED;
  1560. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1561. return;
  1562. }
  1563. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  1564. if (num_entries > IPR_NUM_SDT_ENTRIES)
  1565. num_entries = IPR_NUM_SDT_ENTRIES;
  1566. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1567. for (i = 0; i < num_entries; i++) {
  1568. if (ioa_dump->hdr.len > IPR_MAX_IOA_DUMP_SIZE) {
  1569. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  1570. break;
  1571. }
  1572. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  1573. sdt_word = be32_to_cpu(sdt->entry[i].bar_str_offset);
  1574. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  1575. end_off = be32_to_cpu(sdt->entry[i].end_offset);
  1576. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word) {
  1577. bytes_to_copy = end_off - start_off;
  1578. if (bytes_to_copy > IPR_MAX_IOA_DUMP_SIZE) {
  1579. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  1580. continue;
  1581. }
  1582. /* Copy data from adapter to driver buffers */
  1583. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  1584. bytes_to_copy);
  1585. ioa_dump->hdr.len += bytes_copied;
  1586. if (bytes_copied != bytes_to_copy) {
  1587. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  1588. break;
  1589. }
  1590. }
  1591. }
  1592. }
  1593. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  1594. /* Update dump_header */
  1595. driver_dump->hdr.len += ioa_dump->hdr.len;
  1596. wmb();
  1597. ioa_cfg->sdt_state = DUMP_OBTAINED;
  1598. LEAVE;
  1599. }
  1600. #else
  1601. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while(0)
  1602. #endif
  1603. /**
  1604. * ipr_release_dump - Free adapter dump memory
  1605. * @kref: kref struct
  1606. *
  1607. * Return value:
  1608. * nothing
  1609. **/
  1610. static void ipr_release_dump(struct kref *kref)
  1611. {
  1612. struct ipr_dump *dump = container_of(kref,struct ipr_dump,kref);
  1613. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  1614. unsigned long lock_flags = 0;
  1615. int i;
  1616. ENTER;
  1617. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1618. ioa_cfg->dump = NULL;
  1619. ioa_cfg->sdt_state = INACTIVE;
  1620. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1621. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  1622. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  1623. kfree(dump);
  1624. LEAVE;
  1625. }
  1626. /**
  1627. * ipr_worker_thread - Worker thread
  1628. * @data: ioa config struct
  1629. *
  1630. * Called at task level from a work thread. This function takes care
  1631. * of adding and removing device from the mid-layer as configuration
  1632. * changes are detected by the adapter.
  1633. *
  1634. * Return value:
  1635. * nothing
  1636. **/
  1637. static void ipr_worker_thread(void *data)
  1638. {
  1639. unsigned long lock_flags;
  1640. struct ipr_resource_entry *res;
  1641. struct scsi_device *sdev;
  1642. struct ipr_dump *dump;
  1643. struct ipr_ioa_cfg *ioa_cfg = data;
  1644. u8 bus, target, lun;
  1645. int did_work;
  1646. ENTER;
  1647. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1648. if (ioa_cfg->sdt_state == GET_DUMP) {
  1649. dump = ioa_cfg->dump;
  1650. if (!dump) {
  1651. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1652. return;
  1653. }
  1654. kref_get(&dump->kref);
  1655. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1656. ipr_get_ioa_dump(ioa_cfg, dump);
  1657. kref_put(&dump->kref, ipr_release_dump);
  1658. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1659. if (ioa_cfg->sdt_state == DUMP_OBTAINED)
  1660. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  1661. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1662. return;
  1663. }
  1664. restart:
  1665. do {
  1666. did_work = 0;
  1667. if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
  1668. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1669. return;
  1670. }
  1671. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1672. if (res->del_from_ml && res->sdev) {
  1673. did_work = 1;
  1674. sdev = res->sdev;
  1675. if (!scsi_device_get(sdev)) {
  1676. res->sdev = NULL;
  1677. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  1678. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1679. scsi_remove_device(sdev);
  1680. scsi_device_put(sdev);
  1681. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1682. }
  1683. break;
  1684. }
  1685. }
  1686. } while(did_work);
  1687. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1688. if (res->add_to_ml) {
  1689. bus = res->cfgte.res_addr.bus;
  1690. target = res->cfgte.res_addr.target;
  1691. lun = res->cfgte.res_addr.lun;
  1692. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1693. scsi_add_device(ioa_cfg->host, bus, target, lun);
  1694. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1695. goto restart;
  1696. }
  1697. }
  1698. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1699. kobject_uevent(&ioa_cfg->host->shost_classdev.kobj, KOBJ_CHANGE, NULL);
  1700. LEAVE;
  1701. }
  1702. #ifdef CONFIG_SCSI_IPR_TRACE
  1703. /**
  1704. * ipr_read_trace - Dump the adapter trace
  1705. * @kobj: kobject struct
  1706. * @buf: buffer
  1707. * @off: offset
  1708. * @count: buffer size
  1709. *
  1710. * Return value:
  1711. * number of bytes printed to buffer
  1712. **/
  1713. static ssize_t ipr_read_trace(struct kobject *kobj, char *buf,
  1714. loff_t off, size_t count)
  1715. {
  1716. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  1717. struct Scsi_Host *shost = class_to_shost(cdev);
  1718. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1719. unsigned long lock_flags = 0;
  1720. int size = IPR_TRACE_SIZE;
  1721. char *src = (char *)ioa_cfg->trace;
  1722. if (off > size)
  1723. return 0;
  1724. if (off + count > size) {
  1725. size -= off;
  1726. count = size;
  1727. }
  1728. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1729. memcpy(buf, &src[off], count);
  1730. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1731. return count;
  1732. }
  1733. static struct bin_attribute ipr_trace_attr = {
  1734. .attr = {
  1735. .name = "trace",
  1736. .mode = S_IRUGO,
  1737. },
  1738. .size = 0,
  1739. .read = ipr_read_trace,
  1740. };
  1741. #endif
  1742. /**
  1743. * ipr_show_fw_version - Show the firmware version
  1744. * @class_dev: class device struct
  1745. * @buf: buffer
  1746. *
  1747. * Return value:
  1748. * number of bytes printed to buffer
  1749. **/
  1750. static ssize_t ipr_show_fw_version(struct class_device *class_dev, char *buf)
  1751. {
  1752. struct Scsi_Host *shost = class_to_shost(class_dev);
  1753. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1754. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  1755. unsigned long lock_flags = 0;
  1756. int len;
  1757. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1758. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  1759. ucode_vpd->major_release, ucode_vpd->card_type,
  1760. ucode_vpd->minor_release[0],
  1761. ucode_vpd->minor_release[1]);
  1762. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1763. return len;
  1764. }
  1765. static struct class_device_attribute ipr_fw_version_attr = {
  1766. .attr = {
  1767. .name = "fw_version",
  1768. .mode = S_IRUGO,
  1769. },
  1770. .show = ipr_show_fw_version,
  1771. };
  1772. /**
  1773. * ipr_show_log_level - Show the adapter's error logging level
  1774. * @class_dev: class device struct
  1775. * @buf: buffer
  1776. *
  1777. * Return value:
  1778. * number of bytes printed to buffer
  1779. **/
  1780. static ssize_t ipr_show_log_level(struct class_device *class_dev, char *buf)
  1781. {
  1782. struct Scsi_Host *shost = class_to_shost(class_dev);
  1783. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1784. unsigned long lock_flags = 0;
  1785. int len;
  1786. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1787. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  1788. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1789. return len;
  1790. }
  1791. /**
  1792. * ipr_store_log_level - Change the adapter's error logging level
  1793. * @class_dev: class device struct
  1794. * @buf: buffer
  1795. *
  1796. * Return value:
  1797. * number of bytes printed to buffer
  1798. **/
  1799. static ssize_t ipr_store_log_level(struct class_device *class_dev,
  1800. const char *buf, size_t count)
  1801. {
  1802. struct Scsi_Host *shost = class_to_shost(class_dev);
  1803. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1804. unsigned long lock_flags = 0;
  1805. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1806. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  1807. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1808. return strlen(buf);
  1809. }
  1810. static struct class_device_attribute ipr_log_level_attr = {
  1811. .attr = {
  1812. .name = "log_level",
  1813. .mode = S_IRUGO | S_IWUSR,
  1814. },
  1815. .show = ipr_show_log_level,
  1816. .store = ipr_store_log_level
  1817. };
  1818. /**
  1819. * ipr_store_diagnostics - IOA Diagnostics interface
  1820. * @class_dev: class_device struct
  1821. * @buf: buffer
  1822. * @count: buffer size
  1823. *
  1824. * This function will reset the adapter and wait a reasonable
  1825. * amount of time for any errors that the adapter might log.
  1826. *
  1827. * Return value:
  1828. * count on success / other on failure
  1829. **/
  1830. static ssize_t ipr_store_diagnostics(struct class_device *class_dev,
  1831. const char *buf, size_t count)
  1832. {
  1833. struct Scsi_Host *shost = class_to_shost(class_dev);
  1834. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1835. unsigned long lock_flags = 0;
  1836. int rc = count;
  1837. if (!capable(CAP_SYS_ADMIN))
  1838. return -EACCES;
  1839. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1840. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1841. ioa_cfg->errors_logged = 0;
  1842. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  1843. if (ioa_cfg->in_reset_reload) {
  1844. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1845. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1846. /* Wait for a second for any errors to be logged */
  1847. msleep(1000);
  1848. } else {
  1849. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1850. return -EIO;
  1851. }
  1852. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1853. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  1854. rc = -EIO;
  1855. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1856. return rc;
  1857. }
  1858. static struct class_device_attribute ipr_diagnostics_attr = {
  1859. .attr = {
  1860. .name = "run_diagnostics",
  1861. .mode = S_IWUSR,
  1862. },
  1863. .store = ipr_store_diagnostics
  1864. };
  1865. /**
  1866. * ipr_store_reset_adapter - Reset the adapter
  1867. * @class_dev: class_device struct
  1868. * @buf: buffer
  1869. * @count: buffer size
  1870. *
  1871. * This function will reset the adapter.
  1872. *
  1873. * Return value:
  1874. * count on success / other on failure
  1875. **/
  1876. static ssize_t ipr_store_reset_adapter(struct class_device *class_dev,
  1877. const char *buf, size_t count)
  1878. {
  1879. struct Scsi_Host *shost = class_to_shost(class_dev);
  1880. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  1881. unsigned long lock_flags;
  1882. int result = count;
  1883. if (!capable(CAP_SYS_ADMIN))
  1884. return -EACCES;
  1885. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  1886. if (!ioa_cfg->in_reset_reload)
  1887. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  1888. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  1889. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  1890. return result;
  1891. }
  1892. static struct class_device_attribute ipr_ioa_reset_attr = {
  1893. .attr = {
  1894. .name = "reset_host",
  1895. .mode = S_IWUSR,
  1896. },
  1897. .store = ipr_store_reset_adapter
  1898. };
  1899. /**
  1900. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  1901. * @buf_len: buffer length
  1902. *
  1903. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  1904. * list to use for microcode download
  1905. *
  1906. * Return value:
  1907. * pointer to sglist / NULL on failure
  1908. **/
  1909. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  1910. {
  1911. int sg_size, order, bsize_elem, num_elem, i, j;
  1912. struct ipr_sglist *sglist;
  1913. struct scatterlist *scatterlist;
  1914. struct page *page;
  1915. /* Get the minimum size per scatter/gather element */
  1916. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  1917. /* Get the actual size per element */
  1918. order = get_order(sg_size);
  1919. /* Determine the actual number of bytes per element */
  1920. bsize_elem = PAGE_SIZE * (1 << order);
  1921. /* Determine the actual number of sg entries needed */
  1922. if (buf_len % bsize_elem)
  1923. num_elem = (buf_len / bsize_elem) + 1;
  1924. else
  1925. num_elem = buf_len / bsize_elem;
  1926. /* Allocate a scatter/gather list for the DMA */
  1927. sglist = kmalloc(sizeof(struct ipr_sglist) +
  1928. (sizeof(struct scatterlist) * (num_elem - 1)),
  1929. GFP_KERNEL);
  1930. if (sglist == NULL) {
  1931. ipr_trace;
  1932. return NULL;
  1933. }
  1934. memset(sglist, 0, sizeof(struct ipr_sglist) +
  1935. (sizeof(struct scatterlist) * (num_elem - 1)));
  1936. scatterlist = sglist->scatterlist;
  1937. sglist->order = order;
  1938. sglist->num_sg = num_elem;
  1939. /* Allocate a bunch of sg elements */
  1940. for (i = 0; i < num_elem; i++) {
  1941. page = alloc_pages(GFP_KERNEL, order);
  1942. if (!page) {
  1943. ipr_trace;
  1944. /* Free up what we already allocated */
  1945. for (j = i - 1; j >= 0; j--)
  1946. __free_pages(scatterlist[j].page, order);
  1947. kfree(sglist);
  1948. return NULL;
  1949. }
  1950. scatterlist[i].page = page;
  1951. }
  1952. return sglist;
  1953. }
  1954. /**
  1955. * ipr_free_ucode_buffer - Frees a microcode download buffer
  1956. * @p_dnld: scatter/gather list pointer
  1957. *
  1958. * Free a DMA'able ucode download buffer previously allocated with
  1959. * ipr_alloc_ucode_buffer
  1960. *
  1961. * Return value:
  1962. * nothing
  1963. **/
  1964. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  1965. {
  1966. int i;
  1967. for (i = 0; i < sglist->num_sg; i++)
  1968. __free_pages(sglist->scatterlist[i].page, sglist->order);
  1969. kfree(sglist);
  1970. }
  1971. /**
  1972. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  1973. * @sglist: scatter/gather list pointer
  1974. * @buffer: buffer pointer
  1975. * @len: buffer length
  1976. *
  1977. * Copy a microcode image from a user buffer into a buffer allocated by
  1978. * ipr_alloc_ucode_buffer
  1979. *
  1980. * Return value:
  1981. * 0 on success / other on failure
  1982. **/
  1983. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  1984. u8 *buffer, u32 len)
  1985. {
  1986. int bsize_elem, i, result = 0;
  1987. struct scatterlist *scatterlist;
  1988. void *kaddr;
  1989. /* Determine the actual number of bytes per element */
  1990. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  1991. scatterlist = sglist->scatterlist;
  1992. for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
  1993. kaddr = kmap(scatterlist[i].page);
  1994. memcpy(kaddr, buffer, bsize_elem);
  1995. kunmap(scatterlist[i].page);
  1996. scatterlist[i].length = bsize_elem;
  1997. if (result != 0) {
  1998. ipr_trace;
  1999. return result;
  2000. }
  2001. }
  2002. if (len % bsize_elem) {
  2003. kaddr = kmap(scatterlist[i].page);
  2004. memcpy(kaddr, buffer, len % bsize_elem);
  2005. kunmap(scatterlist[i].page);
  2006. scatterlist[i].length = len % bsize_elem;
  2007. }
  2008. sglist->buffer_len = len;
  2009. return result;
  2010. }
  2011. /**
  2012. * ipr_map_ucode_buffer - Map a microcode download buffer
  2013. * @ipr_cmd: ipr command struct
  2014. * @sglist: scatter/gather list
  2015. * @len: total length of download buffer
  2016. *
  2017. * Maps a microcode download scatter/gather list for DMA and
  2018. * builds the IOADL.
  2019. *
  2020. * Return value:
  2021. * 0 on success / -EIO on failure
  2022. **/
  2023. static int ipr_map_ucode_buffer(struct ipr_cmnd *ipr_cmd,
  2024. struct ipr_sglist *sglist, int len)
  2025. {
  2026. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2027. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  2028. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  2029. struct scatterlist *scatterlist = sglist->scatterlist;
  2030. int i;
  2031. ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev, scatterlist,
  2032. sglist->num_sg, DMA_TO_DEVICE);
  2033. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2034. ioarcb->write_data_transfer_length = cpu_to_be32(len);
  2035. ioarcb->write_ioadl_len =
  2036. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2037. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  2038. ioadl[i].flags_and_data_len =
  2039. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
  2040. ioadl[i].address =
  2041. cpu_to_be32(sg_dma_address(&scatterlist[i]));
  2042. }
  2043. if (likely(ipr_cmd->dma_use_sg)) {
  2044. ioadl[i-1].flags_and_data_len |=
  2045. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  2046. }
  2047. else {
  2048. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  2049. return -EIO;
  2050. }
  2051. return 0;
  2052. }
  2053. /**
  2054. * ipr_store_update_fw - Update the firmware on the adapter
  2055. * @class_dev: class_device struct
  2056. * @buf: buffer
  2057. * @count: buffer size
  2058. *
  2059. * This function will update the firmware on the adapter.
  2060. *
  2061. * Return value:
  2062. * count on success / other on failure
  2063. **/
  2064. static ssize_t ipr_store_update_fw(struct class_device *class_dev,
  2065. const char *buf, size_t count)
  2066. {
  2067. struct Scsi_Host *shost = class_to_shost(class_dev);
  2068. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2069. struct ipr_ucode_image_header *image_hdr;
  2070. const struct firmware *fw_entry;
  2071. struct ipr_sglist *sglist;
  2072. unsigned long lock_flags;
  2073. char fname[100];
  2074. char *src;
  2075. int len, result, dnld_size;
  2076. if (!capable(CAP_SYS_ADMIN))
  2077. return -EACCES;
  2078. len = snprintf(fname, 99, "%s", buf);
  2079. fname[len-1] = '\0';
  2080. if(request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  2081. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  2082. return -EIO;
  2083. }
  2084. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  2085. if (be32_to_cpu(image_hdr->header_length) > fw_entry->size ||
  2086. (ioa_cfg->vpd_cbs->page3_data.card_type &&
  2087. ioa_cfg->vpd_cbs->page3_data.card_type != image_hdr->card_type)) {
  2088. dev_err(&ioa_cfg->pdev->dev, "Invalid microcode buffer\n");
  2089. release_firmware(fw_entry);
  2090. return -EINVAL;
  2091. }
  2092. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  2093. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  2094. sglist = ipr_alloc_ucode_buffer(dnld_size);
  2095. if (!sglist) {
  2096. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  2097. release_firmware(fw_entry);
  2098. return -ENOMEM;
  2099. }
  2100. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  2101. if (result) {
  2102. dev_err(&ioa_cfg->pdev->dev,
  2103. "Microcode buffer copy to DMA buffer failed\n");
  2104. ipr_free_ucode_buffer(sglist);
  2105. release_firmware(fw_entry);
  2106. return result;
  2107. }
  2108. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2109. if (ioa_cfg->ucode_sglist) {
  2110. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2111. dev_err(&ioa_cfg->pdev->dev,
  2112. "Microcode download already in progress\n");
  2113. ipr_free_ucode_buffer(sglist);
  2114. release_firmware(fw_entry);
  2115. return -EIO;
  2116. }
  2117. ioa_cfg->ucode_sglist = sglist;
  2118. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2119. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2120. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2121. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2122. ioa_cfg->ucode_sglist = NULL;
  2123. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2124. ipr_free_ucode_buffer(sglist);
  2125. release_firmware(fw_entry);
  2126. return count;
  2127. }
  2128. static struct class_device_attribute ipr_update_fw_attr = {
  2129. .attr = {
  2130. .name = "update_fw",
  2131. .mode = S_IWUSR,
  2132. },
  2133. .store = ipr_store_update_fw
  2134. };
  2135. static struct class_device_attribute *ipr_ioa_attrs[] = {
  2136. &ipr_fw_version_attr,
  2137. &ipr_log_level_attr,
  2138. &ipr_diagnostics_attr,
  2139. &ipr_ioa_reset_attr,
  2140. &ipr_update_fw_attr,
  2141. NULL,
  2142. };
  2143. #ifdef CONFIG_SCSI_IPR_DUMP
  2144. /**
  2145. * ipr_read_dump - Dump the adapter
  2146. * @kobj: kobject struct
  2147. * @buf: buffer
  2148. * @off: offset
  2149. * @count: buffer size
  2150. *
  2151. * Return value:
  2152. * number of bytes printed to buffer
  2153. **/
  2154. static ssize_t ipr_read_dump(struct kobject *kobj, char *buf,
  2155. loff_t off, size_t count)
  2156. {
  2157. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  2158. struct Scsi_Host *shost = class_to_shost(cdev);
  2159. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2160. struct ipr_dump *dump;
  2161. unsigned long lock_flags = 0;
  2162. char *src;
  2163. int len;
  2164. size_t rc = count;
  2165. if (!capable(CAP_SYS_ADMIN))
  2166. return -EACCES;
  2167. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2168. dump = ioa_cfg->dump;
  2169. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  2170. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2171. return 0;
  2172. }
  2173. kref_get(&dump->kref);
  2174. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2175. if (off > dump->driver_dump.hdr.len) {
  2176. kref_put(&dump->kref, ipr_release_dump);
  2177. return 0;
  2178. }
  2179. if (off + count > dump->driver_dump.hdr.len) {
  2180. count = dump->driver_dump.hdr.len - off;
  2181. rc = count;
  2182. }
  2183. if (count && off < sizeof(dump->driver_dump)) {
  2184. if (off + count > sizeof(dump->driver_dump))
  2185. len = sizeof(dump->driver_dump) - off;
  2186. else
  2187. len = count;
  2188. src = (u8 *)&dump->driver_dump + off;
  2189. memcpy(buf, src, len);
  2190. buf += len;
  2191. off += len;
  2192. count -= len;
  2193. }
  2194. off -= sizeof(dump->driver_dump);
  2195. if (count && off < offsetof(struct ipr_ioa_dump, ioa_data)) {
  2196. if (off + count > offsetof(struct ipr_ioa_dump, ioa_data))
  2197. len = offsetof(struct ipr_ioa_dump, ioa_data) - off;
  2198. else
  2199. len = count;
  2200. src = (u8 *)&dump->ioa_dump + off;
  2201. memcpy(buf, src, len);
  2202. buf += len;
  2203. off += len;
  2204. count -= len;
  2205. }
  2206. off -= offsetof(struct ipr_ioa_dump, ioa_data);
  2207. while (count) {
  2208. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  2209. len = PAGE_ALIGN(off) - off;
  2210. else
  2211. len = count;
  2212. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  2213. src += off & ~PAGE_MASK;
  2214. memcpy(buf, src, len);
  2215. buf += len;
  2216. off += len;
  2217. count -= len;
  2218. }
  2219. kref_put(&dump->kref, ipr_release_dump);
  2220. return rc;
  2221. }
  2222. /**
  2223. * ipr_alloc_dump - Prepare for adapter dump
  2224. * @ioa_cfg: ioa config struct
  2225. *
  2226. * Return value:
  2227. * 0 on success / other on failure
  2228. **/
  2229. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  2230. {
  2231. struct ipr_dump *dump;
  2232. unsigned long lock_flags = 0;
  2233. ENTER;
  2234. dump = kmalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  2235. if (!dump) {
  2236. ipr_err("Dump memory allocation failed\n");
  2237. return -ENOMEM;
  2238. }
  2239. memset(dump, 0, sizeof(struct ipr_dump));
  2240. kref_init(&dump->kref);
  2241. dump->ioa_cfg = ioa_cfg;
  2242. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2243. if (INACTIVE != ioa_cfg->sdt_state) {
  2244. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2245. kfree(dump);
  2246. return 0;
  2247. }
  2248. ioa_cfg->dump = dump;
  2249. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  2250. if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
  2251. ioa_cfg->dump_taken = 1;
  2252. schedule_work(&ioa_cfg->work_q);
  2253. }
  2254. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2255. LEAVE;
  2256. return 0;
  2257. }
  2258. /**
  2259. * ipr_free_dump - Free adapter dump memory
  2260. * @ioa_cfg: ioa config struct
  2261. *
  2262. * Return value:
  2263. * 0 on success / other on failure
  2264. **/
  2265. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  2266. {
  2267. struct ipr_dump *dump;
  2268. unsigned long lock_flags = 0;
  2269. ENTER;
  2270. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2271. dump = ioa_cfg->dump;
  2272. if (!dump) {
  2273. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2274. return 0;
  2275. }
  2276. ioa_cfg->dump = NULL;
  2277. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2278. kref_put(&dump->kref, ipr_release_dump);
  2279. LEAVE;
  2280. return 0;
  2281. }
  2282. /**
  2283. * ipr_write_dump - Setup dump state of adapter
  2284. * @kobj: kobject struct
  2285. * @buf: buffer
  2286. * @off: offset
  2287. * @count: buffer size
  2288. *
  2289. * Return value:
  2290. * number of bytes printed to buffer
  2291. **/
  2292. static ssize_t ipr_write_dump(struct kobject *kobj, char *buf,
  2293. loff_t off, size_t count)
  2294. {
  2295. struct class_device *cdev = container_of(kobj,struct class_device,kobj);
  2296. struct Scsi_Host *shost = class_to_shost(cdev);
  2297. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2298. int rc;
  2299. if (!capable(CAP_SYS_ADMIN))
  2300. return -EACCES;
  2301. if (buf[0] == '1')
  2302. rc = ipr_alloc_dump(ioa_cfg);
  2303. else if (buf[0] == '0')
  2304. rc = ipr_free_dump(ioa_cfg);
  2305. else
  2306. return -EINVAL;
  2307. if (rc)
  2308. return rc;
  2309. else
  2310. return count;
  2311. }
  2312. static struct bin_attribute ipr_dump_attr = {
  2313. .attr = {
  2314. .name = "dump",
  2315. .mode = S_IRUSR | S_IWUSR,
  2316. },
  2317. .size = 0,
  2318. .read = ipr_read_dump,
  2319. .write = ipr_write_dump
  2320. };
  2321. #else
  2322. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  2323. #endif
  2324. /**
  2325. * ipr_change_queue_depth - Change the device's queue depth
  2326. * @sdev: scsi device struct
  2327. * @qdepth: depth to set
  2328. *
  2329. * Return value:
  2330. * actual depth set
  2331. **/
  2332. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth)
  2333. {
  2334. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  2335. return sdev->queue_depth;
  2336. }
  2337. /**
  2338. * ipr_change_queue_type - Change the device's queue type
  2339. * @dsev: scsi device struct
  2340. * @tag_type: type of tags to use
  2341. *
  2342. * Return value:
  2343. * actual queue type set
  2344. **/
  2345. static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
  2346. {
  2347. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2348. struct ipr_resource_entry *res;
  2349. unsigned long lock_flags = 0;
  2350. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2351. res = (struct ipr_resource_entry *)sdev->hostdata;
  2352. if (res) {
  2353. if (ipr_is_gscsi(res) && sdev->tagged_supported) {
  2354. /*
  2355. * We don't bother quiescing the device here since the
  2356. * adapter firmware does it for us.
  2357. */
  2358. scsi_set_tag_type(sdev, tag_type);
  2359. if (tag_type)
  2360. scsi_activate_tcq(sdev, sdev->queue_depth);
  2361. else
  2362. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  2363. } else
  2364. tag_type = 0;
  2365. } else
  2366. tag_type = 0;
  2367. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2368. return tag_type;
  2369. }
  2370. /**
  2371. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  2372. * @dev: device struct
  2373. * @buf: buffer
  2374. *
  2375. * Return value:
  2376. * number of bytes printed to buffer
  2377. **/
  2378. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  2379. {
  2380. struct scsi_device *sdev = to_scsi_device(dev);
  2381. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  2382. struct ipr_resource_entry *res;
  2383. unsigned long lock_flags = 0;
  2384. ssize_t len = -ENXIO;
  2385. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2386. res = (struct ipr_resource_entry *)sdev->hostdata;
  2387. if (res)
  2388. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->cfgte.res_handle);
  2389. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2390. return len;
  2391. }
  2392. static struct device_attribute ipr_adapter_handle_attr = {
  2393. .attr = {
  2394. .name = "adapter_handle",
  2395. .mode = S_IRUSR,
  2396. },
  2397. .show = ipr_show_adapter_handle
  2398. };
  2399. static struct device_attribute *ipr_dev_attrs[] = {
  2400. &ipr_adapter_handle_attr,
  2401. NULL,
  2402. };
  2403. /**
  2404. * ipr_biosparam - Return the HSC mapping
  2405. * @sdev: scsi device struct
  2406. * @block_device: block device pointer
  2407. * @capacity: capacity of the device
  2408. * @parm: Array containing returned HSC values.
  2409. *
  2410. * This function generates the HSC parms that fdisk uses.
  2411. * We want to make sure we return something that places partitions
  2412. * on 4k boundaries for best performance with the IOA.
  2413. *
  2414. * Return value:
  2415. * 0 on success
  2416. **/
  2417. static int ipr_biosparam(struct scsi_device *sdev,
  2418. struct block_device *block_device,
  2419. sector_t capacity, int *parm)
  2420. {
  2421. int heads, sectors;
  2422. sector_t cylinders;
  2423. heads = 128;
  2424. sectors = 32;
  2425. cylinders = capacity;
  2426. sector_div(cylinders, (128 * 32));
  2427. /* return result */
  2428. parm[0] = heads;
  2429. parm[1] = sectors;
  2430. parm[2] = cylinders;
  2431. return 0;
  2432. }
  2433. /**
  2434. * ipr_slave_destroy - Unconfigure a SCSI device
  2435. * @sdev: scsi device struct
  2436. *
  2437. * Return value:
  2438. * nothing
  2439. **/
  2440. static void ipr_slave_destroy(struct scsi_device *sdev)
  2441. {
  2442. struct ipr_resource_entry *res;
  2443. struct ipr_ioa_cfg *ioa_cfg;
  2444. unsigned long lock_flags = 0;
  2445. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2446. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2447. res = (struct ipr_resource_entry *) sdev->hostdata;
  2448. if (res) {
  2449. sdev->hostdata = NULL;
  2450. res->sdev = NULL;
  2451. }
  2452. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2453. }
  2454. /**
  2455. * ipr_slave_configure - Configure a SCSI device
  2456. * @sdev: scsi device struct
  2457. *
  2458. * This function configures the specified scsi device.
  2459. *
  2460. * Return value:
  2461. * 0 on success
  2462. **/
  2463. static int ipr_slave_configure(struct scsi_device *sdev)
  2464. {
  2465. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2466. struct ipr_resource_entry *res;
  2467. unsigned long lock_flags = 0;
  2468. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2469. res = sdev->hostdata;
  2470. if (res) {
  2471. if (ipr_is_af_dasd_device(res))
  2472. sdev->type = TYPE_RAID;
  2473. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res))
  2474. sdev->scsi_level = 4;
  2475. if (ipr_is_vset_device(res)) {
  2476. sdev->timeout = IPR_VSET_RW_TIMEOUT;
  2477. blk_queue_max_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  2478. }
  2479. if (IPR_IS_DASD_DEVICE(res->cfgte.std_inq_data))
  2480. sdev->allow_restart = 1;
  2481. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  2482. }
  2483. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2484. return 0;
  2485. }
  2486. /**
  2487. * ipr_slave_alloc - Prepare for commands to a device.
  2488. * @sdev: scsi device struct
  2489. *
  2490. * This function saves a pointer to the resource entry
  2491. * in the scsi device struct if the device exists. We
  2492. * can then use this pointer in ipr_queuecommand when
  2493. * handling new commands.
  2494. *
  2495. * Return value:
  2496. * 0 on success
  2497. **/
  2498. static int ipr_slave_alloc(struct scsi_device *sdev)
  2499. {
  2500. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  2501. struct ipr_resource_entry *res;
  2502. unsigned long lock_flags;
  2503. sdev->hostdata = NULL;
  2504. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2505. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2506. if ((res->cfgte.res_addr.bus == sdev->channel) &&
  2507. (res->cfgte.res_addr.target == sdev->id) &&
  2508. (res->cfgte.res_addr.lun == sdev->lun)) {
  2509. res->sdev = sdev;
  2510. res->add_to_ml = 0;
  2511. res->in_erp = 0;
  2512. sdev->hostdata = res;
  2513. res->needs_sync_complete = 1;
  2514. break;
  2515. }
  2516. }
  2517. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2518. return 0;
  2519. }
  2520. /**
  2521. * ipr_eh_host_reset - Reset the host adapter
  2522. * @scsi_cmd: scsi command struct
  2523. *
  2524. * Return value:
  2525. * SUCCESS / FAILED
  2526. **/
  2527. static int __ipr_eh_host_reset(struct scsi_cmnd * scsi_cmd)
  2528. {
  2529. struct ipr_ioa_cfg *ioa_cfg;
  2530. int rc;
  2531. ENTER;
  2532. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  2533. dev_err(&ioa_cfg->pdev->dev,
  2534. "Adapter being reset as a result of error recovery.\n");
  2535. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2536. ioa_cfg->sdt_state = GET_DUMP;
  2537. rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  2538. LEAVE;
  2539. return rc;
  2540. }
  2541. static int ipr_eh_host_reset(struct scsi_cmnd * cmd)
  2542. {
  2543. int rc;
  2544. spin_lock_irq(cmd->device->host->host_lock);
  2545. rc = __ipr_eh_host_reset(cmd);
  2546. spin_unlock_irq(cmd->device->host->host_lock);
  2547. return rc;
  2548. }
  2549. /**
  2550. * ipr_eh_dev_reset - Reset the device
  2551. * @scsi_cmd: scsi command struct
  2552. *
  2553. * This function issues a device reset to the affected device.
  2554. * A LUN reset will be sent to the device first. If that does
  2555. * not work, a target reset will be sent.
  2556. *
  2557. * Return value:
  2558. * SUCCESS / FAILED
  2559. **/
  2560. static int __ipr_eh_dev_reset(struct scsi_cmnd * scsi_cmd)
  2561. {
  2562. struct ipr_cmnd *ipr_cmd;
  2563. struct ipr_ioa_cfg *ioa_cfg;
  2564. struct ipr_resource_entry *res;
  2565. struct ipr_cmd_pkt *cmd_pkt;
  2566. u32 ioasc;
  2567. ENTER;
  2568. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  2569. res = scsi_cmd->device->hostdata;
  2570. if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
  2571. return FAILED;
  2572. /*
  2573. * If we are currently going through reset/reload, return failed. This will force the
  2574. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  2575. * reset to complete
  2576. */
  2577. if (ioa_cfg->in_reset_reload)
  2578. return FAILED;
  2579. if (ioa_cfg->ioa_is_dead)
  2580. return FAILED;
  2581. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  2582. if (ipr_cmd->ioarcb.res_handle == res->cfgte.res_handle) {
  2583. if (ipr_cmd->scsi_cmd)
  2584. ipr_cmd->done = ipr_scsi_eh_done;
  2585. }
  2586. }
  2587. res->resetting_device = 1;
  2588. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  2589. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  2590. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  2591. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  2592. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  2593. ipr_sdev_err(scsi_cmd->device, "Resetting device\n");
  2594. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  2595. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2596. res->resetting_device = 0;
  2597. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2598. LEAVE;
  2599. return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
  2600. }
  2601. static int ipr_eh_dev_reset(struct scsi_cmnd * cmd)
  2602. {
  2603. int rc;
  2604. spin_lock_irq(cmd->device->host->host_lock);
  2605. rc = __ipr_eh_dev_reset(cmd);
  2606. spin_unlock_irq(cmd->device->host->host_lock);
  2607. return rc;
  2608. }
  2609. /**
  2610. * ipr_bus_reset_done - Op done function for bus reset.
  2611. * @ipr_cmd: ipr command struct
  2612. *
  2613. * This function is the op done function for a bus reset
  2614. *
  2615. * Return value:
  2616. * none
  2617. **/
  2618. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  2619. {
  2620. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2621. struct ipr_resource_entry *res;
  2622. ENTER;
  2623. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2624. if (!memcmp(&res->cfgte.res_handle, &ipr_cmd->ioarcb.res_handle,
  2625. sizeof(res->cfgte.res_handle))) {
  2626. scsi_report_bus_reset(ioa_cfg->host, res->cfgte.res_addr.bus);
  2627. break;
  2628. }
  2629. }
  2630. /*
  2631. * If abort has not completed, indicate the reset has, else call the
  2632. * abort's done function to wake the sleeping eh thread
  2633. */
  2634. if (ipr_cmd->sibling->sibling)
  2635. ipr_cmd->sibling->sibling = NULL;
  2636. else
  2637. ipr_cmd->sibling->done(ipr_cmd->sibling);
  2638. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2639. LEAVE;
  2640. }
  2641. /**
  2642. * ipr_abort_timeout - An abort task has timed out
  2643. * @ipr_cmd: ipr command struct
  2644. *
  2645. * This function handles when an abort task times out. If this
  2646. * happens we issue a bus reset since we have resources tied
  2647. * up that must be freed before returning to the midlayer.
  2648. *
  2649. * Return value:
  2650. * none
  2651. **/
  2652. static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
  2653. {
  2654. struct ipr_cmnd *reset_cmd;
  2655. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2656. struct ipr_cmd_pkt *cmd_pkt;
  2657. unsigned long lock_flags = 0;
  2658. ENTER;
  2659. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2660. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  2661. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2662. return;
  2663. }
  2664. ipr_sdev_err(ipr_cmd->u.sdev, "Abort timed out. Resetting bus\n");
  2665. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  2666. ipr_cmd->sibling = reset_cmd;
  2667. reset_cmd->sibling = ipr_cmd;
  2668. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  2669. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  2670. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  2671. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  2672. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  2673. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  2674. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2675. LEAVE;
  2676. }
  2677. /**
  2678. * ipr_cancel_op - Cancel specified op
  2679. * @scsi_cmd: scsi command struct
  2680. *
  2681. * This function cancels specified op.
  2682. *
  2683. * Return value:
  2684. * SUCCESS / FAILED
  2685. **/
  2686. static int ipr_cancel_op(struct scsi_cmnd * scsi_cmd)
  2687. {
  2688. struct ipr_cmnd *ipr_cmd;
  2689. struct ipr_ioa_cfg *ioa_cfg;
  2690. struct ipr_resource_entry *res;
  2691. struct ipr_cmd_pkt *cmd_pkt;
  2692. u32 ioasc;
  2693. int op_found = 0;
  2694. ENTER;
  2695. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  2696. res = scsi_cmd->device->hostdata;
  2697. /* If we are currently going through reset/reload, return failed.
  2698. * This will force the mid-layer to call ipr_eh_host_reset,
  2699. * which will then go to sleep and wait for the reset to complete
  2700. */
  2701. if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
  2702. return FAILED;
  2703. if (!res || (!ipr_is_gscsi(res) && !ipr_is_vset_device(res)))
  2704. return FAILED;
  2705. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  2706. if (ipr_cmd->scsi_cmd == scsi_cmd) {
  2707. ipr_cmd->done = ipr_scsi_eh_done;
  2708. op_found = 1;
  2709. break;
  2710. }
  2711. }
  2712. if (!op_found)
  2713. return SUCCESS;
  2714. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  2715. ipr_cmd->ioarcb.res_handle = res->cfgte.res_handle;
  2716. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  2717. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  2718. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  2719. ipr_cmd->u.sdev = scsi_cmd->device;
  2720. ipr_sdev_err(scsi_cmd->device, "Aborting command: %02X\n", scsi_cmd->cmnd[0]);
  2721. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  2722. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2723. /*
  2724. * If the abort task timed out and we sent a bus reset, we will get
  2725. * one the following responses to the abort
  2726. */
  2727. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  2728. ioasc = 0;
  2729. ipr_trace;
  2730. }
  2731. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2732. res->needs_sync_complete = 1;
  2733. LEAVE;
  2734. return (IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS);
  2735. }
  2736. /**
  2737. * ipr_eh_abort - Abort a single op
  2738. * @scsi_cmd: scsi command struct
  2739. *
  2740. * Return value:
  2741. * SUCCESS / FAILED
  2742. **/
  2743. static int ipr_eh_abort(struct scsi_cmnd * scsi_cmd)
  2744. {
  2745. unsigned long flags;
  2746. int rc;
  2747. ENTER;
  2748. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  2749. rc = ipr_cancel_op(scsi_cmd);
  2750. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  2751. LEAVE;
  2752. return rc;
  2753. }
  2754. /**
  2755. * ipr_handle_other_interrupt - Handle "other" interrupts
  2756. * @ioa_cfg: ioa config struct
  2757. * @int_reg: interrupt register
  2758. *
  2759. * Return value:
  2760. * IRQ_NONE / IRQ_HANDLED
  2761. **/
  2762. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  2763. volatile u32 int_reg)
  2764. {
  2765. irqreturn_t rc = IRQ_HANDLED;
  2766. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  2767. /* Mask the interrupt */
  2768. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  2769. /* Clear the interrupt */
  2770. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
  2771. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  2772. list_del(&ioa_cfg->reset_cmd->queue);
  2773. del_timer(&ioa_cfg->reset_cmd->timer);
  2774. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  2775. } else {
  2776. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  2777. ioa_cfg->ioa_unit_checked = 1;
  2778. else
  2779. dev_err(&ioa_cfg->pdev->dev,
  2780. "Permanent IOA failure. 0x%08X\n", int_reg);
  2781. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2782. ioa_cfg->sdt_state = GET_DUMP;
  2783. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  2784. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2785. }
  2786. return rc;
  2787. }
  2788. /**
  2789. * ipr_isr - Interrupt service routine
  2790. * @irq: irq number
  2791. * @devp: pointer to ioa config struct
  2792. * @regs: pt_regs struct
  2793. *
  2794. * Return value:
  2795. * IRQ_NONE / IRQ_HANDLED
  2796. **/
  2797. static irqreturn_t ipr_isr(int irq, void *devp, struct pt_regs *regs)
  2798. {
  2799. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  2800. unsigned long lock_flags = 0;
  2801. volatile u32 int_reg, int_mask_reg;
  2802. u32 ioasc;
  2803. u16 cmd_index;
  2804. struct ipr_cmnd *ipr_cmd;
  2805. irqreturn_t rc = IRQ_NONE;
  2806. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2807. /* If interrupts are disabled, ignore the interrupt */
  2808. if (!ioa_cfg->allow_interrupts) {
  2809. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2810. return IRQ_NONE;
  2811. }
  2812. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  2813. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  2814. /* If an interrupt on the adapter did not occur, ignore it */
  2815. if (unlikely((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0)) {
  2816. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2817. return IRQ_NONE;
  2818. }
  2819. while (1) {
  2820. ipr_cmd = NULL;
  2821. while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  2822. ioa_cfg->toggle_bit) {
  2823. cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
  2824. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  2825. if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
  2826. ioa_cfg->errors_logged++;
  2827. dev_err(&ioa_cfg->pdev->dev, "Invalid response handle from IOA\n");
  2828. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2829. ioa_cfg->sdt_state = GET_DUMP;
  2830. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2831. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2832. return IRQ_HANDLED;
  2833. }
  2834. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  2835. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2836. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  2837. list_del(&ipr_cmd->queue);
  2838. del_timer(&ipr_cmd->timer);
  2839. ipr_cmd->done(ipr_cmd);
  2840. rc = IRQ_HANDLED;
  2841. if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
  2842. ioa_cfg->hrrq_curr++;
  2843. } else {
  2844. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  2845. ioa_cfg->toggle_bit ^= 1u;
  2846. }
  2847. }
  2848. if (ipr_cmd != NULL) {
  2849. /* Clear the PCI interrupt */
  2850. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg);
  2851. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  2852. } else
  2853. break;
  2854. }
  2855. if (unlikely(rc == IRQ_NONE))
  2856. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  2857. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2858. return rc;
  2859. }
  2860. /**
  2861. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  2862. * @ioa_cfg: ioa config struct
  2863. * @ipr_cmd: ipr command struct
  2864. *
  2865. * Return value:
  2866. * 0 on success / -1 on failure
  2867. **/
  2868. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  2869. struct ipr_cmnd *ipr_cmd)
  2870. {
  2871. int i;
  2872. struct scatterlist *sglist;
  2873. u32 length;
  2874. u32 ioadl_flags = 0;
  2875. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  2876. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  2877. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  2878. length = scsi_cmd->request_bufflen;
  2879. if (length == 0)
  2880. return 0;
  2881. if (scsi_cmd->use_sg) {
  2882. ipr_cmd->dma_use_sg = pci_map_sg(ioa_cfg->pdev,
  2883. scsi_cmd->request_buffer,
  2884. scsi_cmd->use_sg,
  2885. scsi_cmd->sc_data_direction);
  2886. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  2887. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  2888. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2889. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  2890. ioarcb->write_ioadl_len =
  2891. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2892. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  2893. ioadl_flags = IPR_IOADL_FLAGS_READ;
  2894. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  2895. ioarcb->read_ioadl_len =
  2896. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  2897. }
  2898. sglist = scsi_cmd->request_buffer;
  2899. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  2900. ioadl[i].flags_and_data_len =
  2901. cpu_to_be32(ioadl_flags | sg_dma_len(&sglist[i]));
  2902. ioadl[i].address =
  2903. cpu_to_be32(sg_dma_address(&sglist[i]));
  2904. }
  2905. if (likely(ipr_cmd->dma_use_sg)) {
  2906. ioadl[i-1].flags_and_data_len |=
  2907. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  2908. return 0;
  2909. } else
  2910. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  2911. } else {
  2912. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  2913. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  2914. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  2915. ioarcb->write_data_transfer_length = cpu_to_be32(length);
  2916. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  2917. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  2918. ioadl_flags = IPR_IOADL_FLAGS_READ;
  2919. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  2920. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  2921. }
  2922. ipr_cmd->dma_handle = pci_map_single(ioa_cfg->pdev,
  2923. scsi_cmd->request_buffer, length,
  2924. scsi_cmd->sc_data_direction);
  2925. if (likely(!pci_dma_mapping_error(ipr_cmd->dma_handle))) {
  2926. ipr_cmd->dma_use_sg = 1;
  2927. ioadl[0].flags_and_data_len =
  2928. cpu_to_be32(ioadl_flags | length | IPR_IOADL_FLAGS_LAST);
  2929. ioadl[0].address = cpu_to_be32(ipr_cmd->dma_handle);
  2930. return 0;
  2931. } else
  2932. dev_err(&ioa_cfg->pdev->dev, "pci_map_single failed!\n");
  2933. }
  2934. return -1;
  2935. }
  2936. /**
  2937. * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
  2938. * @scsi_cmd: scsi command struct
  2939. *
  2940. * Return value:
  2941. * task attributes
  2942. **/
  2943. static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
  2944. {
  2945. u8 tag[2];
  2946. u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
  2947. if (scsi_populate_tag_msg(scsi_cmd, tag)) {
  2948. switch (tag[0]) {
  2949. case MSG_SIMPLE_TAG:
  2950. rc = IPR_FLAGS_LO_SIMPLE_TASK;
  2951. break;
  2952. case MSG_HEAD_TAG:
  2953. rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
  2954. break;
  2955. case MSG_ORDERED_TAG:
  2956. rc = IPR_FLAGS_LO_ORDERED_TASK;
  2957. break;
  2958. };
  2959. }
  2960. return rc;
  2961. }
  2962. /**
  2963. * ipr_erp_done - Process completion of ERP for a device
  2964. * @ipr_cmd: ipr command struct
  2965. *
  2966. * This function copies the sense buffer into the scsi_cmd
  2967. * struct and pushes the scsi_done function.
  2968. *
  2969. * Return value:
  2970. * nothing
  2971. **/
  2972. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  2973. {
  2974. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  2975. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  2976. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2977. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  2978. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  2979. scsi_cmd->result |= (DID_ERROR << 16);
  2980. ipr_sdev_err(scsi_cmd->device,
  2981. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  2982. } else {
  2983. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  2984. SCSI_SENSE_BUFFERSIZE);
  2985. }
  2986. if (res) {
  2987. res->needs_sync_complete = 1;
  2988. res->in_erp = 0;
  2989. }
  2990. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  2991. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2992. scsi_cmd->scsi_done(scsi_cmd);
  2993. }
  2994. /**
  2995. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  2996. * @ipr_cmd: ipr command struct
  2997. *
  2998. * Return value:
  2999. * none
  3000. **/
  3001. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  3002. {
  3003. struct ipr_ioarcb *ioarcb;
  3004. struct ipr_ioasa *ioasa;
  3005. ioarcb = &ipr_cmd->ioarcb;
  3006. ioasa = &ipr_cmd->ioasa;
  3007. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  3008. ioarcb->write_data_transfer_length = 0;
  3009. ioarcb->read_data_transfer_length = 0;
  3010. ioarcb->write_ioadl_len = 0;
  3011. ioarcb->read_ioadl_len = 0;
  3012. ioasa->ioasc = 0;
  3013. ioasa->residual_data_len = 0;
  3014. }
  3015. /**
  3016. * ipr_erp_request_sense - Send request sense to a device
  3017. * @ipr_cmd: ipr command struct
  3018. *
  3019. * This function sends a request sense to a device as a result
  3020. * of a check condition.
  3021. *
  3022. * Return value:
  3023. * nothing
  3024. **/
  3025. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  3026. {
  3027. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3028. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3029. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  3030. ipr_erp_done(ipr_cmd);
  3031. return;
  3032. }
  3033. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3034. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  3035. cmd_pkt->cdb[0] = REQUEST_SENSE;
  3036. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  3037. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  3038. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  3039. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  3040. ipr_cmd->ioadl[0].flags_and_data_len =
  3041. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | SCSI_SENSE_BUFFERSIZE);
  3042. ipr_cmd->ioadl[0].address =
  3043. cpu_to_be32(ipr_cmd->sense_buffer_dma);
  3044. ipr_cmd->ioarcb.read_ioadl_len =
  3045. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3046. ipr_cmd->ioarcb.read_data_transfer_length =
  3047. cpu_to_be32(SCSI_SENSE_BUFFERSIZE);
  3048. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  3049. IPR_REQUEST_SENSE_TIMEOUT * 2);
  3050. }
  3051. /**
  3052. * ipr_erp_cancel_all - Send cancel all to a device
  3053. * @ipr_cmd: ipr command struct
  3054. *
  3055. * This function sends a cancel all to a device to clear the
  3056. * queue. If we are running TCQ on the device, QERR is set to 1,
  3057. * which means all outstanding ops have been dropped on the floor.
  3058. * Cancel all will return them to us.
  3059. *
  3060. * Return value:
  3061. * nothing
  3062. **/
  3063. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  3064. {
  3065. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3066. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3067. struct ipr_cmd_pkt *cmd_pkt;
  3068. res->in_erp = 1;
  3069. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  3070. if (!scsi_get_tag_type(scsi_cmd->device)) {
  3071. ipr_erp_request_sense(ipr_cmd);
  3072. return;
  3073. }
  3074. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  3075. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  3076. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  3077. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  3078. IPR_CANCEL_ALL_TIMEOUT);
  3079. }
  3080. /**
  3081. * ipr_dump_ioasa - Dump contents of IOASA
  3082. * @ioa_cfg: ioa config struct
  3083. * @ipr_cmd: ipr command struct
  3084. *
  3085. * This function is invoked by the interrupt handler when ops
  3086. * fail. It will log the IOASA if appropriate. Only called
  3087. * for GPDD ops.
  3088. *
  3089. * Return value:
  3090. * none
  3091. **/
  3092. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  3093. struct ipr_cmnd *ipr_cmd)
  3094. {
  3095. int i;
  3096. u16 data_len;
  3097. u32 ioasc;
  3098. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3099. __be32 *ioasa_data = (__be32 *)ioasa;
  3100. int error_index;
  3101. ioasc = be32_to_cpu(ioasa->ioasc) & IPR_IOASC_IOASC_MASK;
  3102. if (0 == ioasc)
  3103. return;
  3104. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  3105. return;
  3106. error_index = ipr_get_error(ioasc);
  3107. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  3108. /* Don't log an error if the IOA already logged one */
  3109. if (ioasa->ilid != 0)
  3110. return;
  3111. if (ipr_error_table[error_index].log_ioasa == 0)
  3112. return;
  3113. }
  3114. ipr_sdev_err(ipr_cmd->scsi_cmd->device, "%s\n",
  3115. ipr_error_table[error_index].error);
  3116. if ((ioasa->u.gpdd.end_state <= ARRAY_SIZE(ipr_gpdd_dev_end_states)) &&
  3117. (ioasa->u.gpdd.bus_phase <= ARRAY_SIZE(ipr_gpdd_dev_bus_phases))) {
  3118. ipr_sdev_err(ipr_cmd->scsi_cmd->device,
  3119. "Device End state: %s Phase: %s\n",
  3120. ipr_gpdd_dev_end_states[ioasa->u.gpdd.end_state],
  3121. ipr_gpdd_dev_bus_phases[ioasa->u.gpdd.bus_phase]);
  3122. }
  3123. if (sizeof(struct ipr_ioasa) < be16_to_cpu(ioasa->ret_stat_len))
  3124. data_len = sizeof(struct ipr_ioasa);
  3125. else
  3126. data_len = be16_to_cpu(ioasa->ret_stat_len);
  3127. ipr_err("IOASA Dump:\n");
  3128. for (i = 0; i < data_len / 4; i += 4) {
  3129. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  3130. be32_to_cpu(ioasa_data[i]),
  3131. be32_to_cpu(ioasa_data[i+1]),
  3132. be32_to_cpu(ioasa_data[i+2]),
  3133. be32_to_cpu(ioasa_data[i+3]));
  3134. }
  3135. }
  3136. /**
  3137. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  3138. * @ioasa: IOASA
  3139. * @sense_buf: sense data buffer
  3140. *
  3141. * Return value:
  3142. * none
  3143. **/
  3144. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  3145. {
  3146. u32 failing_lba;
  3147. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  3148. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  3149. struct ipr_ioasa *ioasa = &ipr_cmd->ioasa;
  3150. u32 ioasc = be32_to_cpu(ioasa->ioasc);
  3151. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  3152. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  3153. return;
  3154. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  3155. if (ipr_is_vset_device(res) &&
  3156. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  3157. ioasa->u.vset.failing_lba_hi != 0) {
  3158. sense_buf[0] = 0x72;
  3159. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  3160. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  3161. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  3162. sense_buf[7] = 12;
  3163. sense_buf[8] = 0;
  3164. sense_buf[9] = 0x0A;
  3165. sense_buf[10] = 0x80;
  3166. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  3167. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  3168. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  3169. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  3170. sense_buf[15] = failing_lba & 0x000000ff;
  3171. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  3172. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  3173. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  3174. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  3175. sense_buf[19] = failing_lba & 0x000000ff;
  3176. } else {
  3177. sense_buf[0] = 0x70;
  3178. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  3179. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  3180. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  3181. /* Illegal request */
  3182. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  3183. (be32_to_cpu(ioasa->ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  3184. sense_buf[7] = 10; /* additional length */
  3185. /* IOARCB was in error */
  3186. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  3187. sense_buf[15] = 0xC0;
  3188. else /* Parameter data was invalid */
  3189. sense_buf[15] = 0x80;
  3190. sense_buf[16] =
  3191. ((IPR_FIELD_POINTER_MASK &
  3192. be32_to_cpu(ioasa->ioasc_specific)) >> 8) & 0xff;
  3193. sense_buf[17] =
  3194. (IPR_FIELD_POINTER_MASK &
  3195. be32_to_cpu(ioasa->ioasc_specific)) & 0xff;
  3196. } else {
  3197. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  3198. if (ipr_is_vset_device(res))
  3199. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  3200. else
  3201. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  3202. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  3203. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  3204. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  3205. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  3206. sense_buf[6] = failing_lba & 0x000000ff;
  3207. }
  3208. sense_buf[7] = 6; /* additional length */
  3209. }
  3210. }
  3211. }
  3212. /**
  3213. * ipr_erp_start - Process an error response for a SCSI op
  3214. * @ioa_cfg: ioa config struct
  3215. * @ipr_cmd: ipr command struct
  3216. *
  3217. * This function determines whether or not to initiate ERP
  3218. * on the affected device.
  3219. *
  3220. * Return value:
  3221. * nothing
  3222. **/
  3223. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  3224. struct ipr_cmnd *ipr_cmd)
  3225. {
  3226. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3227. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  3228. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3229. if (!res) {
  3230. ipr_scsi_eh_done(ipr_cmd);
  3231. return;
  3232. }
  3233. if (ipr_is_gscsi(res))
  3234. ipr_dump_ioasa(ioa_cfg, ipr_cmd);
  3235. else
  3236. ipr_gen_sense(ipr_cmd);
  3237. switch (ioasc & IPR_IOASC_IOASC_MASK) {
  3238. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  3239. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  3240. break;
  3241. case IPR_IOASC_IR_RESOURCE_HANDLE:
  3242. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  3243. break;
  3244. case IPR_IOASC_HW_SEL_TIMEOUT:
  3245. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  3246. res->needs_sync_complete = 1;
  3247. break;
  3248. case IPR_IOASC_SYNC_REQUIRED:
  3249. if (!res->in_erp)
  3250. res->needs_sync_complete = 1;
  3251. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  3252. break;
  3253. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  3254. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  3255. break;
  3256. case IPR_IOASC_BUS_WAS_RESET:
  3257. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  3258. /*
  3259. * Report the bus reset and ask for a retry. The device
  3260. * will give CC/UA the next command.
  3261. */
  3262. if (!res->resetting_device)
  3263. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  3264. scsi_cmd->result |= (DID_ERROR << 16);
  3265. res->needs_sync_complete = 1;
  3266. break;
  3267. case IPR_IOASC_HW_DEV_BUS_STATUS:
  3268. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  3269. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  3270. ipr_erp_cancel_all(ipr_cmd);
  3271. return;
  3272. }
  3273. res->needs_sync_complete = 1;
  3274. break;
  3275. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  3276. break;
  3277. default:
  3278. scsi_cmd->result |= (DID_ERROR << 16);
  3279. if (!ipr_is_vset_device(res))
  3280. res->needs_sync_complete = 1;
  3281. break;
  3282. }
  3283. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3284. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3285. scsi_cmd->scsi_done(scsi_cmd);
  3286. }
  3287. /**
  3288. * ipr_scsi_done - mid-layer done function
  3289. * @ipr_cmd: ipr command struct
  3290. *
  3291. * This function is invoked by the interrupt handler for
  3292. * ops generated by the SCSI mid-layer
  3293. *
  3294. * Return value:
  3295. * none
  3296. **/
  3297. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  3298. {
  3299. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3300. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  3301. u32 ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  3302. scsi_cmd->resid = be32_to_cpu(ipr_cmd->ioasa.residual_data_len);
  3303. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  3304. ipr_unmap_sglist(ioa_cfg, ipr_cmd);
  3305. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3306. scsi_cmd->scsi_done(scsi_cmd);
  3307. } else
  3308. ipr_erp_start(ioa_cfg, ipr_cmd);
  3309. }
  3310. /**
  3311. * ipr_save_ioafp_mode_select - Save adapters mode select data
  3312. * @ioa_cfg: ioa config struct
  3313. * @scsi_cmd: scsi command struct
  3314. *
  3315. * This function saves mode select data for the adapter to
  3316. * use following an adapter reset.
  3317. *
  3318. * Return value:
  3319. * 0 on success / SCSI_MLQUEUE_HOST_BUSY on failure
  3320. **/
  3321. static int ipr_save_ioafp_mode_select(struct ipr_ioa_cfg *ioa_cfg,
  3322. struct scsi_cmnd *scsi_cmd)
  3323. {
  3324. if (!ioa_cfg->saved_mode_pages) {
  3325. ioa_cfg->saved_mode_pages = kmalloc(sizeof(struct ipr_mode_pages),
  3326. GFP_ATOMIC);
  3327. if (!ioa_cfg->saved_mode_pages) {
  3328. dev_err(&ioa_cfg->pdev->dev,
  3329. "IOA mode select buffer allocation failed\n");
  3330. return SCSI_MLQUEUE_HOST_BUSY;
  3331. }
  3332. }
  3333. memcpy(ioa_cfg->saved_mode_pages, scsi_cmd->buffer, scsi_cmd->cmnd[4]);
  3334. ioa_cfg->saved_mode_page_len = scsi_cmd->cmnd[4];
  3335. return 0;
  3336. }
  3337. /**
  3338. * ipr_queuecommand - Queue a mid-layer request
  3339. * @scsi_cmd: scsi command struct
  3340. * @done: done function
  3341. *
  3342. * This function queues a request generated by the mid-layer.
  3343. *
  3344. * Return value:
  3345. * 0 on success
  3346. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  3347. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  3348. **/
  3349. static int ipr_queuecommand(struct scsi_cmnd *scsi_cmd,
  3350. void (*done) (struct scsi_cmnd *))
  3351. {
  3352. struct ipr_ioa_cfg *ioa_cfg;
  3353. struct ipr_resource_entry *res;
  3354. struct ipr_ioarcb *ioarcb;
  3355. struct ipr_cmnd *ipr_cmd;
  3356. int rc = 0;
  3357. scsi_cmd->scsi_done = done;
  3358. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  3359. res = scsi_cmd->device->hostdata;
  3360. scsi_cmd->result = (DID_OK << 16);
  3361. /*
  3362. * We are currently blocking all devices due to a host reset
  3363. * We have told the host to stop giving us new requests, but
  3364. * ERP ops don't count. FIXME
  3365. */
  3366. if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))
  3367. return SCSI_MLQUEUE_HOST_BUSY;
  3368. /*
  3369. * FIXME - Create scsi_set_host_offline interface
  3370. * and the ioa_is_dead check can be removed
  3371. */
  3372. if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
  3373. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  3374. scsi_cmd->result = (DID_NO_CONNECT << 16);
  3375. scsi_cmd->scsi_done(scsi_cmd);
  3376. return 0;
  3377. }
  3378. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  3379. ioarcb = &ipr_cmd->ioarcb;
  3380. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  3381. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  3382. ipr_cmd->scsi_cmd = scsi_cmd;
  3383. ioarcb->res_handle = res->cfgte.res_handle;
  3384. ipr_cmd->done = ipr_scsi_done;
  3385. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_PHYS_LOC(res->cfgte.res_addr));
  3386. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  3387. if (scsi_cmd->underflow == 0)
  3388. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  3389. if (res->needs_sync_complete) {
  3390. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  3391. res->needs_sync_complete = 0;
  3392. }
  3393. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  3394. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  3395. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  3396. ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
  3397. }
  3398. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  3399. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
  3400. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  3401. if (ipr_is_ioa_resource(res) && scsi_cmd->cmnd[0] == MODE_SELECT)
  3402. rc = ipr_save_ioafp_mode_select(ioa_cfg, scsi_cmd);
  3403. if (likely(rc == 0))
  3404. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  3405. if (likely(rc == 0)) {
  3406. mb();
  3407. writel(be32_to_cpu(ipr_cmd->ioarcb.ioarcb_host_pci_addr),
  3408. ioa_cfg->regs.ioarrin_reg);
  3409. } else {
  3410. list_move_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3411. return SCSI_MLQUEUE_HOST_BUSY;
  3412. }
  3413. return 0;
  3414. }
  3415. /**
  3416. * ipr_info - Get information about the card/driver
  3417. * @scsi_host: scsi host struct
  3418. *
  3419. * Return value:
  3420. * pointer to buffer with description string
  3421. **/
  3422. static const char * ipr_ioa_info(struct Scsi_Host *host)
  3423. {
  3424. static char buffer[512];
  3425. struct ipr_ioa_cfg *ioa_cfg;
  3426. unsigned long lock_flags = 0;
  3427. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  3428. spin_lock_irqsave(host->host_lock, lock_flags);
  3429. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  3430. spin_unlock_irqrestore(host->host_lock, lock_flags);
  3431. return buffer;
  3432. }
  3433. static struct scsi_host_template driver_template = {
  3434. .module = THIS_MODULE,
  3435. .name = "IPR",
  3436. .info = ipr_ioa_info,
  3437. .queuecommand = ipr_queuecommand,
  3438. .eh_abort_handler = ipr_eh_abort,
  3439. .eh_device_reset_handler = ipr_eh_dev_reset,
  3440. .eh_host_reset_handler = ipr_eh_host_reset,
  3441. .slave_alloc = ipr_slave_alloc,
  3442. .slave_configure = ipr_slave_configure,
  3443. .slave_destroy = ipr_slave_destroy,
  3444. .change_queue_depth = ipr_change_queue_depth,
  3445. .change_queue_type = ipr_change_queue_type,
  3446. .bios_param = ipr_biosparam,
  3447. .can_queue = IPR_MAX_COMMANDS,
  3448. .this_id = -1,
  3449. .sg_tablesize = IPR_MAX_SGLIST,
  3450. .max_sectors = IPR_IOA_MAX_SECTORS,
  3451. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  3452. .use_clustering = ENABLE_CLUSTERING,
  3453. .shost_attrs = ipr_ioa_attrs,
  3454. .sdev_attrs = ipr_dev_attrs,
  3455. .proc_name = IPR_NAME
  3456. };
  3457. #ifdef CONFIG_PPC_PSERIES
  3458. static const u16 ipr_blocked_processors[] = {
  3459. PV_NORTHSTAR,
  3460. PV_PULSAR,
  3461. PV_POWER4,
  3462. PV_ICESTAR,
  3463. PV_SSTAR,
  3464. PV_POWER4p,
  3465. PV_630,
  3466. PV_630p
  3467. };
  3468. /**
  3469. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  3470. * @ioa_cfg: ioa cfg struct
  3471. *
  3472. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  3473. * certain pSeries hardware. This function determines if the given
  3474. * adapter is in one of these confgurations or not.
  3475. *
  3476. * Return value:
  3477. * 1 if adapter is not supported / 0 if adapter is supported
  3478. **/
  3479. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  3480. {
  3481. u8 rev_id;
  3482. int i;
  3483. if (ioa_cfg->type == 0x5702) {
  3484. if (pci_read_config_byte(ioa_cfg->pdev, PCI_REVISION_ID,
  3485. &rev_id) == PCIBIOS_SUCCESSFUL) {
  3486. if (rev_id < 4) {
  3487. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++){
  3488. if (__is_processor(ipr_blocked_processors[i]))
  3489. return 1;
  3490. }
  3491. }
  3492. }
  3493. }
  3494. return 0;
  3495. }
  3496. #else
  3497. #define ipr_invalid_adapter(ioa_cfg) 0
  3498. #endif
  3499. /**
  3500. * ipr_ioa_bringdown_done - IOA bring down completion.
  3501. * @ipr_cmd: ipr command struct
  3502. *
  3503. * This function processes the completion of an adapter bring down.
  3504. * It wakes any reset sleepers.
  3505. *
  3506. * Return value:
  3507. * IPR_RC_JOB_RETURN
  3508. **/
  3509. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  3510. {
  3511. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3512. ENTER;
  3513. ioa_cfg->in_reset_reload = 0;
  3514. ioa_cfg->reset_retries = 0;
  3515. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3516. wake_up_all(&ioa_cfg->reset_wait_q);
  3517. spin_unlock_irq(ioa_cfg->host->host_lock);
  3518. scsi_unblock_requests(ioa_cfg->host);
  3519. spin_lock_irq(ioa_cfg->host->host_lock);
  3520. LEAVE;
  3521. return IPR_RC_JOB_RETURN;
  3522. }
  3523. /**
  3524. * ipr_ioa_reset_done - IOA reset completion.
  3525. * @ipr_cmd: ipr command struct
  3526. *
  3527. * This function processes the completion of an adapter reset.
  3528. * It schedules any necessary mid-layer add/removes and
  3529. * wakes any reset sleepers.
  3530. *
  3531. * Return value:
  3532. * IPR_RC_JOB_RETURN
  3533. **/
  3534. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  3535. {
  3536. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3537. struct ipr_resource_entry *res;
  3538. struct ipr_hostrcb *hostrcb, *temp;
  3539. int i = 0;
  3540. ENTER;
  3541. ioa_cfg->in_reset_reload = 0;
  3542. ioa_cfg->allow_cmds = 1;
  3543. ioa_cfg->reset_cmd = NULL;
  3544. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3545. if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
  3546. ipr_trace;
  3547. break;
  3548. }
  3549. }
  3550. schedule_work(&ioa_cfg->work_q);
  3551. list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
  3552. list_del(&hostrcb->queue);
  3553. if (i++ < IPR_NUM_LOG_HCAMS)
  3554. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  3555. else
  3556. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  3557. }
  3558. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  3559. ioa_cfg->reset_retries = 0;
  3560. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  3561. wake_up_all(&ioa_cfg->reset_wait_q);
  3562. spin_unlock_irq(ioa_cfg->host->host_lock);
  3563. scsi_unblock_requests(ioa_cfg->host);
  3564. spin_lock_irq(ioa_cfg->host->host_lock);
  3565. if (!ioa_cfg->allow_cmds)
  3566. scsi_block_requests(ioa_cfg->host);
  3567. LEAVE;
  3568. return IPR_RC_JOB_RETURN;
  3569. }
  3570. /**
  3571. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  3572. * @supported_dev: supported device struct
  3573. * @vpids: vendor product id struct
  3574. *
  3575. * Return value:
  3576. * none
  3577. **/
  3578. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  3579. struct ipr_std_inq_vpids *vpids)
  3580. {
  3581. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  3582. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  3583. supported_dev->num_records = 1;
  3584. supported_dev->data_length =
  3585. cpu_to_be16(sizeof(struct ipr_supported_device));
  3586. supported_dev->reserved = 0;
  3587. }
  3588. /**
  3589. * ipr_set_supported_devs - Send Set Supported Devices for a device
  3590. * @ipr_cmd: ipr command struct
  3591. *
  3592. * This function send a Set Supported Devices to the adapter
  3593. *
  3594. * Return value:
  3595. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  3596. **/
  3597. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  3598. {
  3599. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3600. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  3601. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3602. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3603. struct ipr_resource_entry *res = ipr_cmd->u.res;
  3604. ipr_cmd->job_step = ipr_ioa_reset_done;
  3605. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  3606. if (!ipr_is_af_dasd_device(res))
  3607. continue;
  3608. ipr_cmd->u.res = res;
  3609. ipr_set_sup_dev_dflt(supp_dev, &res->cfgte.std_inq_data.vpids);
  3610. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  3611. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3612. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  3613. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  3614. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  3615. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  3616. ioadl->flags_and_data_len = cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST |
  3617. sizeof(struct ipr_supported_device));
  3618. ioadl->address = cpu_to_be32(ioa_cfg->vpd_cbs_dma +
  3619. offsetof(struct ipr_misc_cbs, supp_dev));
  3620. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3621. ioarcb->write_data_transfer_length =
  3622. cpu_to_be32(sizeof(struct ipr_supported_device));
  3623. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  3624. IPR_SET_SUP_DEVICE_TIMEOUT);
  3625. ipr_cmd->job_step = ipr_set_supported_devs;
  3626. return IPR_RC_JOB_RETURN;
  3627. }
  3628. return IPR_RC_JOB_CONTINUE;
  3629. }
  3630. /**
  3631. * ipr_get_mode_page - Locate specified mode page
  3632. * @mode_pages: mode page buffer
  3633. * @page_code: page code to find
  3634. * @len: minimum required length for mode page
  3635. *
  3636. * Return value:
  3637. * pointer to mode page / NULL on failure
  3638. **/
  3639. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  3640. u32 page_code, u32 len)
  3641. {
  3642. struct ipr_mode_page_hdr *mode_hdr;
  3643. u32 page_length;
  3644. u32 length;
  3645. if (!mode_pages || (mode_pages->hdr.length == 0))
  3646. return NULL;
  3647. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  3648. mode_hdr = (struct ipr_mode_page_hdr *)
  3649. (mode_pages->data + mode_pages->hdr.block_desc_len);
  3650. while (length) {
  3651. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  3652. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  3653. return mode_hdr;
  3654. break;
  3655. } else {
  3656. page_length = (sizeof(struct ipr_mode_page_hdr) +
  3657. mode_hdr->page_length);
  3658. length -= page_length;
  3659. mode_hdr = (struct ipr_mode_page_hdr *)
  3660. ((unsigned long)mode_hdr + page_length);
  3661. }
  3662. }
  3663. return NULL;
  3664. }
  3665. /**
  3666. * ipr_check_term_power - Check for term power errors
  3667. * @ioa_cfg: ioa config struct
  3668. * @mode_pages: IOAFP mode pages buffer
  3669. *
  3670. * Check the IOAFP's mode page 28 for term power errors
  3671. *
  3672. * Return value:
  3673. * nothing
  3674. **/
  3675. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  3676. struct ipr_mode_pages *mode_pages)
  3677. {
  3678. int i;
  3679. int entry_length;
  3680. struct ipr_dev_bus_entry *bus;
  3681. struct ipr_mode_page28 *mode_page;
  3682. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  3683. sizeof(struct ipr_mode_page28));
  3684. entry_length = mode_page->entry_length;
  3685. bus = mode_page->bus;
  3686. for (i = 0; i < mode_page->num_entries; i++) {
  3687. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  3688. dev_err(&ioa_cfg->pdev->dev,
  3689. "Term power is absent on scsi bus %d\n",
  3690. bus->res_addr.bus);
  3691. }
  3692. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  3693. }
  3694. }
  3695. /**
  3696. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  3697. * @ioa_cfg: ioa config struct
  3698. *
  3699. * Looks through the config table checking for SES devices. If
  3700. * the SES device is in the SES table indicating a maximum SCSI
  3701. * bus speed, the speed is limited for the bus.
  3702. *
  3703. * Return value:
  3704. * none
  3705. **/
  3706. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  3707. {
  3708. u32 max_xfer_rate;
  3709. int i;
  3710. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  3711. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  3712. ioa_cfg->bus_attr[i].bus_width);
  3713. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  3714. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  3715. }
  3716. }
  3717. /**
  3718. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  3719. * @ioa_cfg: ioa config struct
  3720. * @mode_pages: mode page 28 buffer
  3721. *
  3722. * Updates mode page 28 based on driver configuration
  3723. *
  3724. * Return value:
  3725. * none
  3726. **/
  3727. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  3728. struct ipr_mode_pages *mode_pages)
  3729. {
  3730. int i, entry_length;
  3731. struct ipr_dev_bus_entry *bus;
  3732. struct ipr_bus_attributes *bus_attr;
  3733. struct ipr_mode_page28 *mode_page;
  3734. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  3735. sizeof(struct ipr_mode_page28));
  3736. entry_length = mode_page->entry_length;
  3737. /* Loop for each device bus entry */
  3738. for (i = 0, bus = mode_page->bus;
  3739. i < mode_page->num_entries;
  3740. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  3741. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  3742. dev_err(&ioa_cfg->pdev->dev,
  3743. "Invalid resource address reported: 0x%08X\n",
  3744. IPR_GET_PHYS_LOC(bus->res_addr));
  3745. continue;
  3746. }
  3747. bus_attr = &ioa_cfg->bus_attr[i];
  3748. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  3749. bus->bus_width = bus_attr->bus_width;
  3750. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  3751. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  3752. if (bus_attr->qas_enabled)
  3753. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  3754. else
  3755. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  3756. }
  3757. }
  3758. /**
  3759. * ipr_build_mode_select - Build a mode select command
  3760. * @ipr_cmd: ipr command struct
  3761. * @res_handle: resource handle to send command to
  3762. * @parm: Byte 2 of Mode Sense command
  3763. * @dma_addr: DMA buffer address
  3764. * @xfer_len: data transfer length
  3765. *
  3766. * Return value:
  3767. * none
  3768. **/
  3769. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  3770. __be32 res_handle, u8 parm, u32 dma_addr,
  3771. u8 xfer_len)
  3772. {
  3773. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3774. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3775. ioarcb->res_handle = res_handle;
  3776. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  3777. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3778. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  3779. ioarcb->cmd_pkt.cdb[1] = parm;
  3780. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  3781. ioadl->flags_and_data_len =
  3782. cpu_to_be32(IPR_IOADL_FLAGS_WRITE_LAST | xfer_len);
  3783. ioadl->address = cpu_to_be32(dma_addr);
  3784. ioarcb->write_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3785. ioarcb->write_data_transfer_length = cpu_to_be32(xfer_len);
  3786. }
  3787. /**
  3788. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  3789. * @ipr_cmd: ipr command struct
  3790. *
  3791. * This function sets up the SCSI bus attributes and sends
  3792. * a Mode Select for Page 28 to activate them.
  3793. *
  3794. * Return value:
  3795. * IPR_RC_JOB_RETURN
  3796. **/
  3797. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  3798. {
  3799. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3800. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  3801. int length;
  3802. ENTER;
  3803. if (ioa_cfg->saved_mode_pages) {
  3804. memcpy(mode_pages, ioa_cfg->saved_mode_pages,
  3805. ioa_cfg->saved_mode_page_len);
  3806. length = ioa_cfg->saved_mode_page_len;
  3807. } else {
  3808. ipr_scsi_bus_speed_limit(ioa_cfg);
  3809. ipr_check_term_power(ioa_cfg, mode_pages);
  3810. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  3811. length = mode_pages->hdr.length + 1;
  3812. mode_pages->hdr.length = 0;
  3813. }
  3814. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  3815. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  3816. length);
  3817. ipr_cmd->job_step = ipr_set_supported_devs;
  3818. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  3819. struct ipr_resource_entry, queue);
  3820. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  3821. LEAVE;
  3822. return IPR_RC_JOB_RETURN;
  3823. }
  3824. /**
  3825. * ipr_build_mode_sense - Builds a mode sense command
  3826. * @ipr_cmd: ipr command struct
  3827. * @res: resource entry struct
  3828. * @parm: Byte 2 of mode sense command
  3829. * @dma_addr: DMA address of mode sense buffer
  3830. * @xfer_len: Size of DMA buffer
  3831. *
  3832. * Return value:
  3833. * none
  3834. **/
  3835. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  3836. __be32 res_handle,
  3837. u8 parm, u32 dma_addr, u8 xfer_len)
  3838. {
  3839. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3840. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3841. ioarcb->res_handle = res_handle;
  3842. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  3843. ioarcb->cmd_pkt.cdb[2] = parm;
  3844. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  3845. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  3846. ioadl->flags_and_data_len =
  3847. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  3848. ioadl->address = cpu_to_be32(dma_addr);
  3849. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3850. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  3851. }
  3852. /**
  3853. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  3854. * @ipr_cmd: ipr command struct
  3855. *
  3856. * This function send a Page 28 mode sense to the IOA to
  3857. * retrieve SCSI bus attributes.
  3858. *
  3859. * Return value:
  3860. * IPR_RC_JOB_RETURN
  3861. **/
  3862. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  3863. {
  3864. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3865. ENTER;
  3866. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  3867. 0x28, ioa_cfg->vpd_cbs_dma +
  3868. offsetof(struct ipr_misc_cbs, mode_pages),
  3869. sizeof(struct ipr_mode_pages));
  3870. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  3871. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  3872. LEAVE;
  3873. return IPR_RC_JOB_RETURN;
  3874. }
  3875. /**
  3876. * ipr_init_res_table - Initialize the resource table
  3877. * @ipr_cmd: ipr command struct
  3878. *
  3879. * This function looks through the existing resource table, comparing
  3880. * it with the config table. This function will take care of old/new
  3881. * devices and schedule adding/removing them from the mid-layer
  3882. * as appropriate.
  3883. *
  3884. * Return value:
  3885. * IPR_RC_JOB_CONTINUE
  3886. **/
  3887. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  3888. {
  3889. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3890. struct ipr_resource_entry *res, *temp;
  3891. struct ipr_config_table_entry *cfgte;
  3892. int found, i;
  3893. LIST_HEAD(old_res);
  3894. ENTER;
  3895. if (ioa_cfg->cfg_table->hdr.flags & IPR_UCODE_DOWNLOAD_REQ)
  3896. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  3897. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  3898. list_move_tail(&res->queue, &old_res);
  3899. for (i = 0; i < ioa_cfg->cfg_table->hdr.num_entries; i++) {
  3900. cfgte = &ioa_cfg->cfg_table->dev[i];
  3901. found = 0;
  3902. list_for_each_entry_safe(res, temp, &old_res, queue) {
  3903. if (!memcmp(&res->cfgte.res_addr,
  3904. &cfgte->res_addr, sizeof(cfgte->res_addr))) {
  3905. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  3906. found = 1;
  3907. break;
  3908. }
  3909. }
  3910. if (!found) {
  3911. if (list_empty(&ioa_cfg->free_res_q)) {
  3912. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  3913. break;
  3914. }
  3915. found = 1;
  3916. res = list_entry(ioa_cfg->free_res_q.next,
  3917. struct ipr_resource_entry, queue);
  3918. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  3919. ipr_init_res_entry(res);
  3920. res->add_to_ml = 1;
  3921. }
  3922. if (found)
  3923. memcpy(&res->cfgte, cfgte, sizeof(struct ipr_config_table_entry));
  3924. }
  3925. list_for_each_entry_safe(res, temp, &old_res, queue) {
  3926. if (res->sdev) {
  3927. res->del_from_ml = 1;
  3928. res->sdev->hostdata = NULL;
  3929. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  3930. } else {
  3931. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  3932. }
  3933. }
  3934. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  3935. LEAVE;
  3936. return IPR_RC_JOB_CONTINUE;
  3937. }
  3938. /**
  3939. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  3940. * @ipr_cmd: ipr command struct
  3941. *
  3942. * This function sends a Query IOA Configuration command
  3943. * to the adapter to retrieve the IOA configuration table.
  3944. *
  3945. * Return value:
  3946. * IPR_RC_JOB_RETURN
  3947. **/
  3948. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  3949. {
  3950. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  3951. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3952. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3953. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  3954. ENTER;
  3955. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  3956. ucode_vpd->major_release, ucode_vpd->card_type,
  3957. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  3958. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  3959. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  3960. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  3961. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_config_table) >> 8) & 0xff;
  3962. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_config_table) & 0xff;
  3963. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3964. ioarcb->read_data_transfer_length =
  3965. cpu_to_be32(sizeof(struct ipr_config_table));
  3966. ioadl->address = cpu_to_be32(ioa_cfg->cfg_table_dma);
  3967. ioadl->flags_and_data_len =
  3968. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | sizeof(struct ipr_config_table));
  3969. ipr_cmd->job_step = ipr_init_res_table;
  3970. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  3971. LEAVE;
  3972. return IPR_RC_JOB_RETURN;
  3973. }
  3974. /**
  3975. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  3976. * @ipr_cmd: ipr command struct
  3977. *
  3978. * This utility function sends an inquiry to the adapter.
  3979. *
  3980. * Return value:
  3981. * none
  3982. **/
  3983. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  3984. u32 dma_addr, u8 xfer_len)
  3985. {
  3986. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3987. struct ipr_ioadl_desc *ioadl = ipr_cmd->ioadl;
  3988. ENTER;
  3989. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  3990. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  3991. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  3992. ioarcb->cmd_pkt.cdb[1] = flags;
  3993. ioarcb->cmd_pkt.cdb[2] = page;
  3994. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  3995. ioarcb->read_ioadl_len = cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  3996. ioarcb->read_data_transfer_length = cpu_to_be32(xfer_len);
  3997. ioadl->address = cpu_to_be32(dma_addr);
  3998. ioadl->flags_and_data_len =
  3999. cpu_to_be32(IPR_IOADL_FLAGS_READ_LAST | xfer_len);
  4000. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4001. LEAVE;
  4002. }
  4003. /**
  4004. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  4005. * @ipr_cmd: ipr command struct
  4006. *
  4007. * This function sends a Page 3 inquiry to the adapter
  4008. * to retrieve software VPD information.
  4009. *
  4010. * Return value:
  4011. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4012. **/
  4013. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  4014. {
  4015. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4016. char type[5];
  4017. ENTER;
  4018. /* Grab the type out of the VPD and store it away */
  4019. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  4020. type[4] = '\0';
  4021. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  4022. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  4023. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  4024. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  4025. sizeof(struct ipr_inquiry_page3));
  4026. LEAVE;
  4027. return IPR_RC_JOB_RETURN;
  4028. }
  4029. /**
  4030. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  4031. * @ipr_cmd: ipr command struct
  4032. *
  4033. * This function sends a standard inquiry to the adapter.
  4034. *
  4035. * Return value:
  4036. * IPR_RC_JOB_RETURN
  4037. **/
  4038. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  4039. {
  4040. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4041. ENTER;
  4042. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  4043. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  4044. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  4045. sizeof(struct ipr_ioa_vpd));
  4046. LEAVE;
  4047. return IPR_RC_JOB_RETURN;
  4048. }
  4049. /**
  4050. * ipr_ioafp_indentify_hrrq - Send Identify Host RRQ.
  4051. * @ipr_cmd: ipr command struct
  4052. *
  4053. * This function send an Identify Host Request Response Queue
  4054. * command to establish the HRRQ with the adapter.
  4055. *
  4056. * Return value:
  4057. * IPR_RC_JOB_RETURN
  4058. **/
  4059. static int ipr_ioafp_indentify_hrrq(struct ipr_cmnd *ipr_cmd)
  4060. {
  4061. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4062. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4063. ENTER;
  4064. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  4065. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  4066. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4067. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4068. ioarcb->cmd_pkt.cdb[2] =
  4069. ((u32) ioa_cfg->host_rrq_dma >> 24) & 0xff;
  4070. ioarcb->cmd_pkt.cdb[3] =
  4071. ((u32) ioa_cfg->host_rrq_dma >> 16) & 0xff;
  4072. ioarcb->cmd_pkt.cdb[4] =
  4073. ((u32) ioa_cfg->host_rrq_dma >> 8) & 0xff;
  4074. ioarcb->cmd_pkt.cdb[5] =
  4075. ((u32) ioa_cfg->host_rrq_dma) & 0xff;
  4076. ioarcb->cmd_pkt.cdb[7] =
  4077. ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
  4078. ioarcb->cmd_pkt.cdb[8] =
  4079. (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
  4080. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  4081. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  4082. LEAVE;
  4083. return IPR_RC_JOB_RETURN;
  4084. }
  4085. /**
  4086. * ipr_reset_timer_done - Adapter reset timer function
  4087. * @ipr_cmd: ipr command struct
  4088. *
  4089. * Description: This function is used in adapter reset processing
  4090. * for timing events. If the reset_cmd pointer in the IOA
  4091. * config struct is not this adapter's we are doing nested
  4092. * resets and fail_all_ops will take care of freeing the
  4093. * command block.
  4094. *
  4095. * Return value:
  4096. * none
  4097. **/
  4098. static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
  4099. {
  4100. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4101. unsigned long lock_flags = 0;
  4102. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4103. if (ioa_cfg->reset_cmd == ipr_cmd) {
  4104. list_del(&ipr_cmd->queue);
  4105. ipr_cmd->done(ipr_cmd);
  4106. }
  4107. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4108. }
  4109. /**
  4110. * ipr_reset_start_timer - Start a timer for adapter reset job
  4111. * @ipr_cmd: ipr command struct
  4112. * @timeout: timeout value
  4113. *
  4114. * Description: This function is used in adapter reset processing
  4115. * for timing events. If the reset_cmd pointer in the IOA
  4116. * config struct is not this adapter's we are doing nested
  4117. * resets and fail_all_ops will take care of freeing the
  4118. * command block.
  4119. *
  4120. * Return value:
  4121. * none
  4122. **/
  4123. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  4124. unsigned long timeout)
  4125. {
  4126. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  4127. ipr_cmd->done = ipr_reset_ioa_job;
  4128. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  4129. ipr_cmd->timer.expires = jiffies + timeout;
  4130. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
  4131. add_timer(&ipr_cmd->timer);
  4132. }
  4133. /**
  4134. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  4135. * @ioa_cfg: ioa cfg struct
  4136. *
  4137. * Return value:
  4138. * nothing
  4139. **/
  4140. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  4141. {
  4142. memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
  4143. /* Initialize Host RRQ pointers */
  4144. ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
  4145. ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
  4146. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  4147. ioa_cfg->toggle_bit = 1;
  4148. /* Zero out config table */
  4149. memset(ioa_cfg->cfg_table, 0, sizeof(struct ipr_config_table));
  4150. }
  4151. /**
  4152. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  4153. * @ipr_cmd: ipr command struct
  4154. *
  4155. * This function reinitializes some control blocks and
  4156. * enables destructive diagnostics on the adapter.
  4157. *
  4158. * Return value:
  4159. * IPR_RC_JOB_RETURN
  4160. **/
  4161. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  4162. {
  4163. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4164. volatile u32 int_reg;
  4165. ENTER;
  4166. ipr_cmd->job_step = ipr_ioafp_indentify_hrrq;
  4167. ipr_init_ioa_mem(ioa_cfg);
  4168. ioa_cfg->allow_interrupts = 1;
  4169. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4170. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  4171. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  4172. ioa_cfg->regs.clr_interrupt_mask_reg);
  4173. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4174. return IPR_RC_JOB_CONTINUE;
  4175. }
  4176. /* Enable destructive diagnostics on IOA */
  4177. writel(IPR_DOORBELL, ioa_cfg->regs.set_uproc_interrupt_reg);
  4178. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg);
  4179. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4180. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  4181. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  4182. ipr_cmd->timer.expires = jiffies + (ipr_transop_timeout * HZ);
  4183. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
  4184. ipr_cmd->done = ipr_reset_ioa_job;
  4185. add_timer(&ipr_cmd->timer);
  4186. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  4187. LEAVE;
  4188. return IPR_RC_JOB_RETURN;
  4189. }
  4190. /**
  4191. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  4192. * @ipr_cmd: ipr command struct
  4193. *
  4194. * This function is invoked when an adapter dump has run out
  4195. * of processing time.
  4196. *
  4197. * Return value:
  4198. * IPR_RC_JOB_CONTINUE
  4199. **/
  4200. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  4201. {
  4202. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4203. if (ioa_cfg->sdt_state == GET_DUMP)
  4204. ioa_cfg->sdt_state = ABORT_DUMP;
  4205. ipr_cmd->job_step = ipr_reset_alert;
  4206. return IPR_RC_JOB_CONTINUE;
  4207. }
  4208. /**
  4209. * ipr_unit_check_no_data - Log a unit check/no data error log
  4210. * @ioa_cfg: ioa config struct
  4211. *
  4212. * Logs an error indicating the adapter unit checked, but for some
  4213. * reason, we were unable to fetch the unit check buffer.
  4214. *
  4215. * Return value:
  4216. * nothing
  4217. **/
  4218. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  4219. {
  4220. ioa_cfg->errors_logged++;
  4221. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  4222. }
  4223. /**
  4224. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  4225. * @ioa_cfg: ioa config struct
  4226. *
  4227. * Fetches the unit check buffer from the adapter by clocking the data
  4228. * through the mailbox register.
  4229. *
  4230. * Return value:
  4231. * nothing
  4232. **/
  4233. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  4234. {
  4235. unsigned long mailbox;
  4236. struct ipr_hostrcb *hostrcb;
  4237. struct ipr_uc_sdt sdt;
  4238. int rc, length;
  4239. mailbox = readl(ioa_cfg->ioa_mailbox);
  4240. if (!ipr_sdt_is_fmt2(mailbox)) {
  4241. ipr_unit_check_no_data(ioa_cfg);
  4242. return;
  4243. }
  4244. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  4245. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  4246. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  4247. if (rc || (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE) ||
  4248. !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY)) {
  4249. ipr_unit_check_no_data(ioa_cfg);
  4250. return;
  4251. }
  4252. /* Find length of the first sdt entry (UC buffer) */
  4253. length = (be32_to_cpu(sdt.entry[0].end_offset) -
  4254. be32_to_cpu(sdt.entry[0].bar_str_offset)) & IPR_FMT2_MBX_ADDR_MASK;
  4255. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  4256. struct ipr_hostrcb, queue);
  4257. list_del(&hostrcb->queue);
  4258. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  4259. rc = ipr_get_ldump_data_section(ioa_cfg,
  4260. be32_to_cpu(sdt.entry[0].bar_str_offset),
  4261. (__be32 *)&hostrcb->hcam,
  4262. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  4263. if (!rc)
  4264. ipr_handle_log_data(ioa_cfg, hostrcb);
  4265. else
  4266. ipr_unit_check_no_data(ioa_cfg);
  4267. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  4268. }
  4269. /**
  4270. * ipr_reset_restore_cfg_space - Restore PCI config space.
  4271. * @ipr_cmd: ipr command struct
  4272. *
  4273. * Description: This function restores the saved PCI config space of
  4274. * the adapter, fails all outstanding ops back to the callers, and
  4275. * fetches the dump/unit check if applicable to this reset.
  4276. *
  4277. * Return value:
  4278. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4279. **/
  4280. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  4281. {
  4282. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4283. int rc;
  4284. ENTER;
  4285. rc = pci_restore_state(ioa_cfg->pdev);
  4286. if (rc != PCIBIOS_SUCCESSFUL) {
  4287. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  4288. return IPR_RC_JOB_CONTINUE;
  4289. }
  4290. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  4291. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  4292. return IPR_RC_JOB_CONTINUE;
  4293. }
  4294. ipr_fail_all_ops(ioa_cfg);
  4295. if (ioa_cfg->ioa_unit_checked) {
  4296. ioa_cfg->ioa_unit_checked = 0;
  4297. ipr_get_unit_check_buffer(ioa_cfg);
  4298. ipr_cmd->job_step = ipr_reset_alert;
  4299. ipr_reset_start_timer(ipr_cmd, 0);
  4300. return IPR_RC_JOB_RETURN;
  4301. }
  4302. if (ioa_cfg->in_ioa_bringdown) {
  4303. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  4304. } else {
  4305. ipr_cmd->job_step = ipr_reset_enable_ioa;
  4306. if (GET_DUMP == ioa_cfg->sdt_state) {
  4307. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_TIMEOUT);
  4308. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  4309. schedule_work(&ioa_cfg->work_q);
  4310. return IPR_RC_JOB_RETURN;
  4311. }
  4312. }
  4313. ENTER;
  4314. return IPR_RC_JOB_CONTINUE;
  4315. }
  4316. /**
  4317. * ipr_reset_start_bist - Run BIST on the adapter.
  4318. * @ipr_cmd: ipr command struct
  4319. *
  4320. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  4321. *
  4322. * Return value:
  4323. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4324. **/
  4325. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  4326. {
  4327. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4328. int rc;
  4329. ENTER;
  4330. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  4331. if (rc != PCIBIOS_SUCCESSFUL) {
  4332. ipr_cmd->ioasa.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  4333. rc = IPR_RC_JOB_CONTINUE;
  4334. } else {
  4335. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  4336. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  4337. rc = IPR_RC_JOB_RETURN;
  4338. }
  4339. LEAVE;
  4340. return rc;
  4341. }
  4342. /**
  4343. * ipr_reset_allowed - Query whether or not IOA can be reset
  4344. * @ioa_cfg: ioa config struct
  4345. *
  4346. * Return value:
  4347. * 0 if reset not allowed / non-zero if reset is allowed
  4348. **/
  4349. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  4350. {
  4351. volatile u32 temp_reg;
  4352. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4353. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  4354. }
  4355. /**
  4356. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  4357. * @ipr_cmd: ipr command struct
  4358. *
  4359. * Description: This function waits for adapter permission to run BIST,
  4360. * then runs BIST. If the adapter does not give permission after a
  4361. * reasonable time, we will reset the adapter anyway. The impact of
  4362. * resetting the adapter without warning the adapter is the risk of
  4363. * losing the persistent error log on the adapter. If the adapter is
  4364. * reset while it is writing to the flash on the adapter, the flash
  4365. * segment will have bad ECC and be zeroed.
  4366. *
  4367. * Return value:
  4368. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4369. **/
  4370. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  4371. {
  4372. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4373. int rc = IPR_RC_JOB_RETURN;
  4374. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  4375. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  4376. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  4377. } else {
  4378. ipr_cmd->job_step = ipr_reset_start_bist;
  4379. rc = IPR_RC_JOB_CONTINUE;
  4380. }
  4381. return rc;
  4382. }
  4383. /**
  4384. * ipr_reset_alert_part2 - Alert the adapter of a pending reset
  4385. * @ipr_cmd: ipr command struct
  4386. *
  4387. * Description: This function alerts the adapter that it will be reset.
  4388. * If memory space is not currently enabled, proceed directly
  4389. * to running BIST on the adapter. The timer must always be started
  4390. * so we guarantee we do not run BIST from ipr_isr.
  4391. *
  4392. * Return value:
  4393. * IPR_RC_JOB_RETURN
  4394. **/
  4395. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  4396. {
  4397. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4398. u16 cmd_reg;
  4399. int rc;
  4400. ENTER;
  4401. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  4402. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  4403. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  4404. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg);
  4405. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  4406. } else {
  4407. ipr_cmd->job_step = ipr_reset_start_bist;
  4408. }
  4409. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  4410. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  4411. LEAVE;
  4412. return IPR_RC_JOB_RETURN;
  4413. }
  4414. /**
  4415. * ipr_reset_ucode_download_done - Microcode download completion
  4416. * @ipr_cmd: ipr command struct
  4417. *
  4418. * Description: This function unmaps the microcode download buffer.
  4419. *
  4420. * Return value:
  4421. * IPR_RC_JOB_CONTINUE
  4422. **/
  4423. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  4424. {
  4425. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4426. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  4427. pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
  4428. sglist->num_sg, DMA_TO_DEVICE);
  4429. ipr_cmd->job_step = ipr_reset_alert;
  4430. return IPR_RC_JOB_CONTINUE;
  4431. }
  4432. /**
  4433. * ipr_reset_ucode_download - Download microcode to the adapter
  4434. * @ipr_cmd: ipr command struct
  4435. *
  4436. * Description: This function checks to see if it there is microcode
  4437. * to download to the adapter. If there is, a download is performed.
  4438. *
  4439. * Return value:
  4440. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4441. **/
  4442. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  4443. {
  4444. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4445. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  4446. ENTER;
  4447. ipr_cmd->job_step = ipr_reset_alert;
  4448. if (!sglist)
  4449. return IPR_RC_JOB_CONTINUE;
  4450. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4451. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  4452. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  4453. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  4454. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  4455. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  4456. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  4457. if (ipr_map_ucode_buffer(ipr_cmd, sglist, sglist->buffer_len)) {
  4458. dev_err(&ioa_cfg->pdev->dev,
  4459. "Failed to map microcode download buffer\n");
  4460. return IPR_RC_JOB_CONTINUE;
  4461. }
  4462. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  4463. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  4464. IPR_WRITE_BUFFER_TIMEOUT);
  4465. LEAVE;
  4466. return IPR_RC_JOB_RETURN;
  4467. }
  4468. /**
  4469. * ipr_reset_shutdown_ioa - Shutdown the adapter
  4470. * @ipr_cmd: ipr command struct
  4471. *
  4472. * Description: This function issues an adapter shutdown of the
  4473. * specified type to the specified adapter as part of the
  4474. * adapter reset job.
  4475. *
  4476. * Return value:
  4477. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  4478. **/
  4479. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  4480. {
  4481. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4482. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  4483. unsigned long timeout;
  4484. int rc = IPR_RC_JOB_CONTINUE;
  4485. ENTER;
  4486. if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
  4487. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  4488. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  4489. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  4490. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  4491. if (shutdown_type == IPR_SHUTDOWN_ABBREV)
  4492. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  4493. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  4494. timeout = IPR_INTERNAL_TIMEOUT;
  4495. else
  4496. timeout = IPR_SHUTDOWN_TIMEOUT;
  4497. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  4498. rc = IPR_RC_JOB_RETURN;
  4499. ipr_cmd->job_step = ipr_reset_ucode_download;
  4500. } else
  4501. ipr_cmd->job_step = ipr_reset_alert;
  4502. LEAVE;
  4503. return rc;
  4504. }
  4505. /**
  4506. * ipr_reset_ioa_job - Adapter reset job
  4507. * @ipr_cmd: ipr command struct
  4508. *
  4509. * Description: This function is the job router for the adapter reset job.
  4510. *
  4511. * Return value:
  4512. * none
  4513. **/
  4514. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  4515. {
  4516. u32 rc, ioasc;
  4517. unsigned long scratch = ipr_cmd->u.scratch;
  4518. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4519. do {
  4520. ioasc = be32_to_cpu(ipr_cmd->ioasa.ioasc);
  4521. if (ioa_cfg->reset_cmd != ipr_cmd) {
  4522. /*
  4523. * We are doing nested adapter resets and this is
  4524. * not the current reset job.
  4525. */
  4526. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4527. return;
  4528. }
  4529. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  4530. dev_err(&ioa_cfg->pdev->dev,
  4531. "0x%02X failed with IOASC: 0x%08X\n",
  4532. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  4533. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  4534. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4535. return;
  4536. }
  4537. ipr_reinit_ipr_cmnd(ipr_cmd);
  4538. ipr_cmd->u.scratch = scratch;
  4539. rc = ipr_cmd->job_step(ipr_cmd);
  4540. } while(rc == IPR_RC_JOB_CONTINUE);
  4541. }
  4542. /**
  4543. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  4544. * @ioa_cfg: ioa config struct
  4545. * @job_step: first job step of reset job
  4546. * @shutdown_type: shutdown type
  4547. *
  4548. * Description: This function will initiate the reset of the given adapter
  4549. * starting at the selected job step.
  4550. * If the caller needs to wait on the completion of the reset,
  4551. * the caller must sleep on the reset_wait_q.
  4552. *
  4553. * Return value:
  4554. * none
  4555. **/
  4556. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  4557. int (*job_step) (struct ipr_cmnd *),
  4558. enum ipr_shutdown_type shutdown_type)
  4559. {
  4560. struct ipr_cmnd *ipr_cmd;
  4561. ioa_cfg->in_reset_reload = 1;
  4562. ioa_cfg->allow_cmds = 0;
  4563. scsi_block_requests(ioa_cfg->host);
  4564. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4565. ioa_cfg->reset_cmd = ipr_cmd;
  4566. ipr_cmd->job_step = job_step;
  4567. ipr_cmd->u.shutdown_type = shutdown_type;
  4568. ipr_reset_ioa_job(ipr_cmd);
  4569. }
  4570. /**
  4571. * ipr_initiate_ioa_reset - Initiate an adapter reset
  4572. * @ioa_cfg: ioa config struct
  4573. * @shutdown_type: shutdown type
  4574. *
  4575. * Description: This function will initiate the reset of the given adapter.
  4576. * If the caller needs to wait on the completion of the reset,
  4577. * the caller must sleep on the reset_wait_q.
  4578. *
  4579. * Return value:
  4580. * none
  4581. **/
  4582. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  4583. enum ipr_shutdown_type shutdown_type)
  4584. {
  4585. if (ioa_cfg->ioa_is_dead)
  4586. return;
  4587. if (ioa_cfg->in_reset_reload && ioa_cfg->sdt_state == GET_DUMP)
  4588. ioa_cfg->sdt_state = ABORT_DUMP;
  4589. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  4590. dev_err(&ioa_cfg->pdev->dev,
  4591. "IOA taken offline - error recovery failed\n");
  4592. ioa_cfg->reset_retries = 0;
  4593. ioa_cfg->ioa_is_dead = 1;
  4594. if (ioa_cfg->in_ioa_bringdown) {
  4595. ioa_cfg->reset_cmd = NULL;
  4596. ioa_cfg->in_reset_reload = 0;
  4597. ipr_fail_all_ops(ioa_cfg);
  4598. wake_up_all(&ioa_cfg->reset_wait_q);
  4599. spin_unlock_irq(ioa_cfg->host->host_lock);
  4600. scsi_unblock_requests(ioa_cfg->host);
  4601. spin_lock_irq(ioa_cfg->host->host_lock);
  4602. return;
  4603. } else {
  4604. ioa_cfg->in_ioa_bringdown = 1;
  4605. shutdown_type = IPR_SHUTDOWN_NONE;
  4606. }
  4607. }
  4608. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  4609. shutdown_type);
  4610. }
  4611. /**
  4612. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  4613. * @ioa_cfg: ioa cfg struct
  4614. *
  4615. * Description: This is the second phase of adapter intialization
  4616. * This function takes care of initilizing the adapter to the point
  4617. * where it can accept new commands.
  4618. * Return value:
  4619. * 0 on sucess / -EIO on failure
  4620. **/
  4621. static int __devinit ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  4622. {
  4623. int rc = 0;
  4624. unsigned long host_lock_flags = 0;
  4625. ENTER;
  4626. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  4627. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  4628. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa, IPR_SHUTDOWN_NONE);
  4629. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  4630. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4631. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  4632. if (ioa_cfg->ioa_is_dead) {
  4633. rc = -EIO;
  4634. } else if (ipr_invalid_adapter(ioa_cfg)) {
  4635. if (!ipr_testmode)
  4636. rc = -EIO;
  4637. dev_err(&ioa_cfg->pdev->dev,
  4638. "Adapter not supported in this hardware configuration.\n");
  4639. }
  4640. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  4641. LEAVE;
  4642. return rc;
  4643. }
  4644. /**
  4645. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  4646. * @ioa_cfg: ioa config struct
  4647. *
  4648. * Return value:
  4649. * none
  4650. **/
  4651. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  4652. {
  4653. int i;
  4654. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  4655. if (ioa_cfg->ipr_cmnd_list[i])
  4656. pci_pool_free(ioa_cfg->ipr_cmd_pool,
  4657. ioa_cfg->ipr_cmnd_list[i],
  4658. ioa_cfg->ipr_cmnd_list_dma[i]);
  4659. ioa_cfg->ipr_cmnd_list[i] = NULL;
  4660. }
  4661. if (ioa_cfg->ipr_cmd_pool)
  4662. pci_pool_destroy (ioa_cfg->ipr_cmd_pool);
  4663. ioa_cfg->ipr_cmd_pool = NULL;
  4664. }
  4665. /**
  4666. * ipr_free_mem - Frees memory allocated for an adapter
  4667. * @ioa_cfg: ioa cfg struct
  4668. *
  4669. * Return value:
  4670. * nothing
  4671. **/
  4672. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  4673. {
  4674. int i;
  4675. kfree(ioa_cfg->res_entries);
  4676. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
  4677. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  4678. ipr_free_cmd_blks(ioa_cfg);
  4679. pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  4680. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  4681. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_config_table),
  4682. ioa_cfg->cfg_table,
  4683. ioa_cfg->cfg_table_dma);
  4684. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  4685. pci_free_consistent(ioa_cfg->pdev,
  4686. sizeof(struct ipr_hostrcb),
  4687. ioa_cfg->hostrcb[i],
  4688. ioa_cfg->hostrcb_dma[i]);
  4689. }
  4690. ipr_free_dump(ioa_cfg);
  4691. kfree(ioa_cfg->saved_mode_pages);
  4692. kfree(ioa_cfg->trace);
  4693. }
  4694. /**
  4695. * ipr_free_all_resources - Free all allocated resources for an adapter.
  4696. * @ipr_cmd: ipr command struct
  4697. *
  4698. * This function frees all allocated resources for the
  4699. * specified adapter.
  4700. *
  4701. * Return value:
  4702. * none
  4703. **/
  4704. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  4705. {
  4706. struct pci_dev *pdev = ioa_cfg->pdev;
  4707. ENTER;
  4708. free_irq(pdev->irq, ioa_cfg);
  4709. iounmap(ioa_cfg->hdw_dma_regs);
  4710. pci_release_regions(pdev);
  4711. ipr_free_mem(ioa_cfg);
  4712. scsi_host_put(ioa_cfg->host);
  4713. pci_disable_device(pdev);
  4714. LEAVE;
  4715. }
  4716. /**
  4717. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  4718. * @ioa_cfg: ioa config struct
  4719. *
  4720. * Return value:
  4721. * 0 on success / -ENOMEM on allocation failure
  4722. **/
  4723. static int __devinit ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  4724. {
  4725. struct ipr_cmnd *ipr_cmd;
  4726. struct ipr_ioarcb *ioarcb;
  4727. dma_addr_t dma_addr;
  4728. int i;
  4729. ioa_cfg->ipr_cmd_pool = pci_pool_create (IPR_NAME, ioa_cfg->pdev,
  4730. sizeof(struct ipr_cmnd), 8, 0);
  4731. if (!ioa_cfg->ipr_cmd_pool)
  4732. return -ENOMEM;
  4733. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  4734. ipr_cmd = pci_pool_alloc (ioa_cfg->ipr_cmd_pool, SLAB_KERNEL, &dma_addr);
  4735. if (!ipr_cmd) {
  4736. ipr_free_cmd_blks(ioa_cfg);
  4737. return -ENOMEM;
  4738. }
  4739. memset(ipr_cmd, 0, sizeof(*ipr_cmd));
  4740. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  4741. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  4742. ioarcb = &ipr_cmd->ioarcb;
  4743. ioarcb->ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  4744. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  4745. ioarcb->write_ioadl_addr =
  4746. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioadl));
  4747. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  4748. ioarcb->ioasa_host_pci_addr =
  4749. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, ioasa));
  4750. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  4751. ipr_cmd->cmd_index = i;
  4752. ipr_cmd->ioa_cfg = ioa_cfg;
  4753. ipr_cmd->sense_buffer_dma = dma_addr +
  4754. offsetof(struct ipr_cmnd, sense_buffer);
  4755. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4756. }
  4757. return 0;
  4758. }
  4759. /**
  4760. * ipr_alloc_mem - Allocate memory for an adapter
  4761. * @ioa_cfg: ioa config struct
  4762. *
  4763. * Return value:
  4764. * 0 on success / non-zero for error
  4765. **/
  4766. static int __devinit ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  4767. {
  4768. struct pci_dev *pdev = ioa_cfg->pdev;
  4769. int i, rc = -ENOMEM;
  4770. ENTER;
  4771. ioa_cfg->res_entries = kmalloc(sizeof(struct ipr_resource_entry) *
  4772. IPR_MAX_PHYSICAL_DEVS, GFP_KERNEL);
  4773. if (!ioa_cfg->res_entries)
  4774. goto out;
  4775. memset(ioa_cfg->res_entries, 0,
  4776. sizeof(struct ipr_resource_entry) * IPR_MAX_PHYSICAL_DEVS);
  4777. for (i = 0; i < IPR_MAX_PHYSICAL_DEVS; i++)
  4778. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  4779. ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
  4780. sizeof(struct ipr_misc_cbs),
  4781. &ioa_cfg->vpd_cbs_dma);
  4782. if (!ioa_cfg->vpd_cbs)
  4783. goto out_free_res_entries;
  4784. if (ipr_alloc_cmd_blks(ioa_cfg))
  4785. goto out_free_vpd_cbs;
  4786. ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
  4787. sizeof(u32) * IPR_NUM_CMD_BLKS,
  4788. &ioa_cfg->host_rrq_dma);
  4789. if (!ioa_cfg->host_rrq)
  4790. goto out_ipr_free_cmd_blocks;
  4791. ioa_cfg->cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
  4792. sizeof(struct ipr_config_table),
  4793. &ioa_cfg->cfg_table_dma);
  4794. if (!ioa_cfg->cfg_table)
  4795. goto out_free_host_rrq;
  4796. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  4797. ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
  4798. sizeof(struct ipr_hostrcb),
  4799. &ioa_cfg->hostrcb_dma[i]);
  4800. if (!ioa_cfg->hostrcb[i])
  4801. goto out_free_hostrcb_dma;
  4802. ioa_cfg->hostrcb[i]->hostrcb_dma =
  4803. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  4804. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  4805. }
  4806. ioa_cfg->trace = kmalloc(sizeof(struct ipr_trace_entry) *
  4807. IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
  4808. if (!ioa_cfg->trace)
  4809. goto out_free_hostrcb_dma;
  4810. memset(ioa_cfg->trace, 0,
  4811. sizeof(struct ipr_trace_entry) * IPR_NUM_TRACE_ENTRIES);
  4812. rc = 0;
  4813. out:
  4814. LEAVE;
  4815. return rc;
  4816. out_free_hostrcb_dma:
  4817. while (i-- > 0) {
  4818. pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
  4819. ioa_cfg->hostrcb[i],
  4820. ioa_cfg->hostrcb_dma[i]);
  4821. }
  4822. pci_free_consistent(pdev, sizeof(struct ipr_config_table),
  4823. ioa_cfg->cfg_table, ioa_cfg->cfg_table_dma);
  4824. out_free_host_rrq:
  4825. pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  4826. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  4827. out_ipr_free_cmd_blocks:
  4828. ipr_free_cmd_blks(ioa_cfg);
  4829. out_free_vpd_cbs:
  4830. pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
  4831. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  4832. out_free_res_entries:
  4833. kfree(ioa_cfg->res_entries);
  4834. goto out;
  4835. }
  4836. /**
  4837. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  4838. * @ioa_cfg: ioa config struct
  4839. *
  4840. * Return value:
  4841. * none
  4842. **/
  4843. static void __devinit ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  4844. {
  4845. int i;
  4846. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  4847. ioa_cfg->bus_attr[i].bus = i;
  4848. ioa_cfg->bus_attr[i].qas_enabled = 0;
  4849. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  4850. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  4851. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  4852. else
  4853. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  4854. }
  4855. }
  4856. /**
  4857. * ipr_init_ioa_cfg - Initialize IOA config struct
  4858. * @ioa_cfg: ioa config struct
  4859. * @host: scsi host struct
  4860. * @pdev: PCI dev struct
  4861. *
  4862. * Return value:
  4863. * none
  4864. **/
  4865. static void __devinit ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  4866. struct Scsi_Host *host, struct pci_dev *pdev)
  4867. {
  4868. const struct ipr_interrupt_offsets *p;
  4869. struct ipr_interrupts *t;
  4870. void __iomem *base;
  4871. ioa_cfg->host = host;
  4872. ioa_cfg->pdev = pdev;
  4873. ioa_cfg->log_level = ipr_log_level;
  4874. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  4875. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  4876. sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
  4877. sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
  4878. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  4879. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  4880. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  4881. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  4882. INIT_LIST_HEAD(&ioa_cfg->free_q);
  4883. INIT_LIST_HEAD(&ioa_cfg->pending_q);
  4884. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  4885. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  4886. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  4887. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  4888. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread, ioa_cfg);
  4889. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  4890. ioa_cfg->sdt_state = INACTIVE;
  4891. ipr_initialize_bus_attr(ioa_cfg);
  4892. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  4893. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  4894. host->max_channel = IPR_MAX_BUS_TO_SCAN;
  4895. host->unique_id = host->host_no;
  4896. host->max_cmd_len = IPR_MAX_CDB_LEN;
  4897. pci_set_drvdata(pdev, ioa_cfg);
  4898. p = &ioa_cfg->chip_cfg->regs;
  4899. t = &ioa_cfg->regs;
  4900. base = ioa_cfg->hdw_dma_regs;
  4901. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  4902. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  4903. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  4904. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  4905. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  4906. t->ioarrin_reg = base + p->ioarrin_reg;
  4907. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  4908. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  4909. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  4910. }
  4911. /**
  4912. * ipr_get_chip_cfg - Find adapter chip configuration
  4913. * @dev_id: PCI device id struct
  4914. *
  4915. * Return value:
  4916. * ptr to chip config on success / NULL on failure
  4917. **/
  4918. static const struct ipr_chip_cfg_t * __devinit
  4919. ipr_get_chip_cfg(const struct pci_device_id *dev_id)
  4920. {
  4921. int i;
  4922. if (dev_id->driver_data)
  4923. return (const struct ipr_chip_cfg_t *)dev_id->driver_data;
  4924. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  4925. if (ipr_chip[i].vendor == dev_id->vendor &&
  4926. ipr_chip[i].device == dev_id->device)
  4927. return ipr_chip[i].cfg;
  4928. return NULL;
  4929. }
  4930. /**
  4931. * ipr_probe_ioa - Allocates memory and does first stage of initialization
  4932. * @pdev: PCI device struct
  4933. * @dev_id: PCI device id struct
  4934. *
  4935. * Return value:
  4936. * 0 on success / non-zero on failure
  4937. **/
  4938. static int __devinit ipr_probe_ioa(struct pci_dev *pdev,
  4939. const struct pci_device_id *dev_id)
  4940. {
  4941. struct ipr_ioa_cfg *ioa_cfg;
  4942. struct Scsi_Host *host;
  4943. unsigned long ipr_regs_pci;
  4944. void __iomem *ipr_regs;
  4945. u32 rc = PCIBIOS_SUCCESSFUL;
  4946. ENTER;
  4947. if ((rc = pci_enable_device(pdev))) {
  4948. dev_err(&pdev->dev, "Cannot enable adapter\n");
  4949. goto out;
  4950. }
  4951. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  4952. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  4953. if (!host) {
  4954. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  4955. rc = -ENOMEM;
  4956. goto out_disable;
  4957. }
  4958. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  4959. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  4960. ioa_cfg->chip_cfg = ipr_get_chip_cfg(dev_id);
  4961. if (!ioa_cfg->chip_cfg) {
  4962. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  4963. dev_id->vendor, dev_id->device);
  4964. goto out_scsi_host_put;
  4965. }
  4966. ipr_regs_pci = pci_resource_start(pdev, 0);
  4967. rc = pci_request_regions(pdev, IPR_NAME);
  4968. if (rc < 0) {
  4969. dev_err(&pdev->dev,
  4970. "Couldn't register memory range of registers\n");
  4971. goto out_scsi_host_put;
  4972. }
  4973. ipr_regs = ioremap(ipr_regs_pci, pci_resource_len(pdev, 0));
  4974. if (!ipr_regs) {
  4975. dev_err(&pdev->dev,
  4976. "Couldn't map memory range of registers\n");
  4977. rc = -ENOMEM;
  4978. goto out_release_regions;
  4979. }
  4980. ioa_cfg->hdw_dma_regs = ipr_regs;
  4981. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  4982. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  4983. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  4984. pci_set_master(pdev);
  4985. rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  4986. if (rc < 0) {
  4987. dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
  4988. goto cleanup_nomem;
  4989. }
  4990. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  4991. ioa_cfg->chip_cfg->cache_line_size);
  4992. if (rc != PCIBIOS_SUCCESSFUL) {
  4993. dev_err(&pdev->dev, "Write of cache line size failed\n");
  4994. rc = -EIO;
  4995. goto cleanup_nomem;
  4996. }
  4997. /* Save away PCI config space for use following IOA reset */
  4998. rc = pci_save_state(pdev);
  4999. if (rc != PCIBIOS_SUCCESSFUL) {
  5000. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  5001. rc = -EIO;
  5002. goto cleanup_nomem;
  5003. }
  5004. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  5005. goto cleanup_nomem;
  5006. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  5007. goto cleanup_nomem;
  5008. rc = ipr_alloc_mem(ioa_cfg);
  5009. if (rc < 0) {
  5010. dev_err(&pdev->dev,
  5011. "Couldn't allocate enough memory for device driver!\n");
  5012. goto cleanup_nomem;
  5013. }
  5014. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  5015. rc = request_irq(pdev->irq, ipr_isr, SA_SHIRQ, IPR_NAME, ioa_cfg);
  5016. if (rc) {
  5017. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  5018. pdev->irq, rc);
  5019. goto cleanup_nolog;
  5020. }
  5021. spin_lock(&ipr_driver_lock);
  5022. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  5023. spin_unlock(&ipr_driver_lock);
  5024. LEAVE;
  5025. out:
  5026. return rc;
  5027. cleanup_nolog:
  5028. ipr_free_mem(ioa_cfg);
  5029. cleanup_nomem:
  5030. iounmap(ipr_regs);
  5031. out_release_regions:
  5032. pci_release_regions(pdev);
  5033. out_scsi_host_put:
  5034. scsi_host_put(host);
  5035. out_disable:
  5036. pci_disable_device(pdev);
  5037. goto out;
  5038. }
  5039. /**
  5040. * ipr_scan_vsets - Scans for VSET devices
  5041. * @ioa_cfg: ioa config struct
  5042. *
  5043. * Description: Since the VSET resources do not follow SAM in that we can have
  5044. * sparse LUNs with no LUN 0, we have to scan for these ourselves.
  5045. *
  5046. * Return value:
  5047. * none
  5048. **/
  5049. static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
  5050. {
  5051. int target, lun;
  5052. for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
  5053. for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++ )
  5054. scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
  5055. }
  5056. /**
  5057. * ipr_initiate_ioa_bringdown - Bring down an adapter
  5058. * @ioa_cfg: ioa config struct
  5059. * @shutdown_type: shutdown type
  5060. *
  5061. * Description: This function will initiate bringing down the adapter.
  5062. * This consists of issuing an IOA shutdown to the adapter
  5063. * to flush the cache, and running BIST.
  5064. * If the caller needs to wait on the completion of the reset,
  5065. * the caller must sleep on the reset_wait_q.
  5066. *
  5067. * Return value:
  5068. * none
  5069. **/
  5070. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  5071. enum ipr_shutdown_type shutdown_type)
  5072. {
  5073. ENTER;
  5074. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  5075. ioa_cfg->sdt_state = ABORT_DUMP;
  5076. ioa_cfg->reset_retries = 0;
  5077. ioa_cfg->in_ioa_bringdown = 1;
  5078. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  5079. LEAVE;
  5080. }
  5081. /**
  5082. * __ipr_remove - Remove a single adapter
  5083. * @pdev: pci device struct
  5084. *
  5085. * Adapter hot plug remove entry point.
  5086. *
  5087. * Return value:
  5088. * none
  5089. **/
  5090. static void __ipr_remove(struct pci_dev *pdev)
  5091. {
  5092. unsigned long host_lock_flags = 0;
  5093. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5094. ENTER;
  5095. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  5096. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  5097. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  5098. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5099. flush_scheduled_work();
  5100. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  5101. spin_lock(&ipr_driver_lock);
  5102. list_del(&ioa_cfg->queue);
  5103. spin_unlock(&ipr_driver_lock);
  5104. if (ioa_cfg->sdt_state == ABORT_DUMP)
  5105. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  5106. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  5107. ipr_free_all_resources(ioa_cfg);
  5108. LEAVE;
  5109. }
  5110. /**
  5111. * ipr_remove - IOA hot plug remove entry point
  5112. * @pdev: pci device struct
  5113. *
  5114. * Adapter hot plug remove entry point.
  5115. *
  5116. * Return value:
  5117. * none
  5118. **/
  5119. static void ipr_remove(struct pci_dev *pdev)
  5120. {
  5121. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5122. ENTER;
  5123. ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  5124. &ipr_trace_attr);
  5125. ipr_remove_dump_file(&ioa_cfg->host->shost_classdev.kobj,
  5126. &ipr_dump_attr);
  5127. scsi_remove_host(ioa_cfg->host);
  5128. __ipr_remove(pdev);
  5129. LEAVE;
  5130. }
  5131. /**
  5132. * ipr_probe - Adapter hot plug add entry point
  5133. *
  5134. * Return value:
  5135. * 0 on success / non-zero on failure
  5136. **/
  5137. static int __devinit ipr_probe(struct pci_dev *pdev,
  5138. const struct pci_device_id *dev_id)
  5139. {
  5140. struct ipr_ioa_cfg *ioa_cfg;
  5141. int rc;
  5142. rc = ipr_probe_ioa(pdev, dev_id);
  5143. if (rc)
  5144. return rc;
  5145. ioa_cfg = pci_get_drvdata(pdev);
  5146. rc = ipr_probe_ioa_part2(ioa_cfg);
  5147. if (rc) {
  5148. __ipr_remove(pdev);
  5149. return rc;
  5150. }
  5151. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  5152. if (rc) {
  5153. __ipr_remove(pdev);
  5154. return rc;
  5155. }
  5156. rc = ipr_create_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  5157. &ipr_trace_attr);
  5158. if (rc) {
  5159. scsi_remove_host(ioa_cfg->host);
  5160. __ipr_remove(pdev);
  5161. return rc;
  5162. }
  5163. rc = ipr_create_dump_file(&ioa_cfg->host->shost_classdev.kobj,
  5164. &ipr_dump_attr);
  5165. if (rc) {
  5166. ipr_remove_trace_file(&ioa_cfg->host->shost_classdev.kobj,
  5167. &ipr_trace_attr);
  5168. scsi_remove_host(ioa_cfg->host);
  5169. __ipr_remove(pdev);
  5170. return rc;
  5171. }
  5172. scsi_scan_host(ioa_cfg->host);
  5173. ipr_scan_vsets(ioa_cfg);
  5174. scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
  5175. ioa_cfg->allow_ml_add_del = 1;
  5176. schedule_work(&ioa_cfg->work_q);
  5177. return 0;
  5178. }
  5179. /**
  5180. * ipr_shutdown - Shutdown handler.
  5181. * @pdev: pci device struct
  5182. *
  5183. * This function is invoked upon system shutdown/reboot. It will issue
  5184. * an adapter shutdown to the adapter to flush the write cache.
  5185. *
  5186. * Return value:
  5187. * none
  5188. **/
  5189. static void ipr_shutdown(struct pci_dev *pdev)
  5190. {
  5191. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  5192. unsigned long lock_flags = 0;
  5193. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5194. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  5195. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5196. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5197. }
  5198. static struct pci_device_id ipr_pci_table[] __devinitdata = {
  5199. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5200. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702,
  5201. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5202. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5203. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703,
  5204. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5205. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5206. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D,
  5207. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5208. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  5209. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E,
  5210. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5211. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  5212. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B,
  5213. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5214. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  5215. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E,
  5216. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5217. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  5218. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A,
  5219. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[0] },
  5220. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  5221. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780,
  5222. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  5223. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  5224. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E,
  5225. 0, 0, (kernel_ulong_t)&ipr_chip_cfg[1] },
  5226. { }
  5227. };
  5228. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  5229. static struct pci_driver ipr_driver = {
  5230. .name = IPR_NAME,
  5231. .id_table = ipr_pci_table,
  5232. .probe = ipr_probe,
  5233. .remove = ipr_remove,
  5234. .shutdown = ipr_shutdown,
  5235. };
  5236. /**
  5237. * ipr_init - Module entry point
  5238. *
  5239. * Return value:
  5240. * 0 on success / negative value on failure
  5241. **/
  5242. static int __init ipr_init(void)
  5243. {
  5244. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  5245. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  5246. return pci_module_init(&ipr_driver);
  5247. }
  5248. /**
  5249. * ipr_exit - Module unload
  5250. *
  5251. * Module unload entry point.
  5252. *
  5253. * Return value:
  5254. * none
  5255. **/
  5256. static void __exit ipr_exit(void)
  5257. {
  5258. pci_unregister_driver(&ipr_driver);
  5259. }
  5260. module_init(ipr_init);
  5261. module_exit(ipr_exit);