ipr.c 261 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396
  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/fs.h>
  56. #include <linux/init.h>
  57. #include <linux/types.h>
  58. #include <linux/errno.h>
  59. #include <linux/kernel.h>
  60. #include <linux/slab.h>
  61. #include <linux/vmalloc.h>
  62. #include <linux/ioport.h>
  63. #include <linux/delay.h>
  64. #include <linux/pci.h>
  65. #include <linux/wait.h>
  66. #include <linux/spinlock.h>
  67. #include <linux/sched.h>
  68. #include <linux/interrupt.h>
  69. #include <linux/blkdev.h>
  70. #include <linux/firmware.h>
  71. #include <linux/module.h>
  72. #include <linux/moduleparam.h>
  73. #include <linux/libata.h>
  74. #include <linux/hdreg.h>
  75. #include <linux/reboot.h>
  76. #include <linux/stringify.h>
  77. #include <asm/io.h>
  78. #include <asm/irq.h>
  79. #include <asm/processor.h>
  80. #include <scsi/scsi.h>
  81. #include <scsi/scsi_host.h>
  82. #include <scsi/scsi_tcq.h>
  83. #include <scsi/scsi_eh.h>
  84. #include <scsi/scsi_cmnd.h>
  85. #include "ipr.h"
  86. /*
  87. * Global Data
  88. */
  89. static LIST_HEAD(ipr_ioa_head);
  90. static unsigned int ipr_log_level = IPR_DEFAULT_LOG_LEVEL;
  91. static unsigned int ipr_max_speed = 1;
  92. static int ipr_testmode = 0;
  93. static unsigned int ipr_fastfail = 0;
  94. static unsigned int ipr_transop_timeout = 0;
  95. static unsigned int ipr_debug = 0;
  96. static unsigned int ipr_max_devs = IPR_DEFAULT_SIS64_DEVS;
  97. static unsigned int ipr_dual_ioa_raid = 1;
  98. static DEFINE_SPINLOCK(ipr_driver_lock);
  99. /* This table describes the differences between DMA controller chips */
  100. static const struct ipr_chip_cfg_t ipr_chip_cfg[] = {
  101. { /* Gemstone, Citrine, Obsidian, and Obsidian-E */
  102. .mailbox = 0x0042C,
  103. .max_cmds = 100,
  104. .cache_line_size = 0x20,
  105. .clear_isr = 1,
  106. {
  107. .set_interrupt_mask_reg = 0x0022C,
  108. .clr_interrupt_mask_reg = 0x00230,
  109. .clr_interrupt_mask_reg32 = 0x00230,
  110. .sense_interrupt_mask_reg = 0x0022C,
  111. .sense_interrupt_mask_reg32 = 0x0022C,
  112. .clr_interrupt_reg = 0x00228,
  113. .clr_interrupt_reg32 = 0x00228,
  114. .sense_interrupt_reg = 0x00224,
  115. .sense_interrupt_reg32 = 0x00224,
  116. .ioarrin_reg = 0x00404,
  117. .sense_uproc_interrupt_reg = 0x00214,
  118. .sense_uproc_interrupt_reg32 = 0x00214,
  119. .set_uproc_interrupt_reg = 0x00214,
  120. .set_uproc_interrupt_reg32 = 0x00214,
  121. .clr_uproc_interrupt_reg = 0x00218,
  122. .clr_uproc_interrupt_reg32 = 0x00218
  123. }
  124. },
  125. { /* Snipe and Scamp */
  126. .mailbox = 0x0052C,
  127. .max_cmds = 100,
  128. .cache_line_size = 0x20,
  129. .clear_isr = 1,
  130. {
  131. .set_interrupt_mask_reg = 0x00288,
  132. .clr_interrupt_mask_reg = 0x0028C,
  133. .clr_interrupt_mask_reg32 = 0x0028C,
  134. .sense_interrupt_mask_reg = 0x00288,
  135. .sense_interrupt_mask_reg32 = 0x00288,
  136. .clr_interrupt_reg = 0x00284,
  137. .clr_interrupt_reg32 = 0x00284,
  138. .sense_interrupt_reg = 0x00280,
  139. .sense_interrupt_reg32 = 0x00280,
  140. .ioarrin_reg = 0x00504,
  141. .sense_uproc_interrupt_reg = 0x00290,
  142. .sense_uproc_interrupt_reg32 = 0x00290,
  143. .set_uproc_interrupt_reg = 0x00290,
  144. .set_uproc_interrupt_reg32 = 0x00290,
  145. .clr_uproc_interrupt_reg = 0x00294,
  146. .clr_uproc_interrupt_reg32 = 0x00294
  147. }
  148. },
  149. { /* CRoC */
  150. .mailbox = 0x00044,
  151. .max_cmds = 1000,
  152. .cache_line_size = 0x20,
  153. .clear_isr = 0,
  154. {
  155. .set_interrupt_mask_reg = 0x00010,
  156. .clr_interrupt_mask_reg = 0x00018,
  157. .clr_interrupt_mask_reg32 = 0x0001C,
  158. .sense_interrupt_mask_reg = 0x00010,
  159. .sense_interrupt_mask_reg32 = 0x00014,
  160. .clr_interrupt_reg = 0x00008,
  161. .clr_interrupt_reg32 = 0x0000C,
  162. .sense_interrupt_reg = 0x00000,
  163. .sense_interrupt_reg32 = 0x00004,
  164. .ioarrin_reg = 0x00070,
  165. .sense_uproc_interrupt_reg = 0x00020,
  166. .sense_uproc_interrupt_reg32 = 0x00024,
  167. .set_uproc_interrupt_reg = 0x00020,
  168. .set_uproc_interrupt_reg32 = 0x00024,
  169. .clr_uproc_interrupt_reg = 0x00028,
  170. .clr_uproc_interrupt_reg32 = 0x0002C,
  171. .init_feedback_reg = 0x0005C,
  172. .dump_addr_reg = 0x00064,
  173. .dump_data_reg = 0x00068,
  174. .endian_swap_reg = 0x00084
  175. }
  176. },
  177. };
  178. static const struct ipr_chip_t ipr_chip[] = {
  179. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  180. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  181. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  182. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  183. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E, IPR_USE_MSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[0] },
  184. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
  185. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP, IPR_USE_LSI, IPR_SIS32, IPR_PCI_CFG, &ipr_chip_cfg[1] },
  186. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] },
  187. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE, IPR_USE_MSI, IPR_SIS64, IPR_MMIO, &ipr_chip_cfg[2] }
  188. };
  189. static int ipr_max_bus_speeds[] = {
  190. IPR_80MBs_SCSI_RATE, IPR_U160_SCSI_RATE, IPR_U320_SCSI_RATE
  191. };
  192. MODULE_AUTHOR("Brian King <brking@us.ibm.com>");
  193. MODULE_DESCRIPTION("IBM Power RAID SCSI Adapter Driver");
  194. module_param_named(max_speed, ipr_max_speed, uint, 0);
  195. MODULE_PARM_DESC(max_speed, "Maximum bus speed (0-2). Default: 1=U160. Speeds: 0=80 MB/s, 1=U160, 2=U320");
  196. module_param_named(log_level, ipr_log_level, uint, 0);
  197. MODULE_PARM_DESC(log_level, "Set to 0 - 4 for increasing verbosity of device driver");
  198. module_param_named(testmode, ipr_testmode, int, 0);
  199. MODULE_PARM_DESC(testmode, "DANGEROUS!!! Allows unsupported configurations");
  200. module_param_named(fastfail, ipr_fastfail, int, S_IRUGO | S_IWUSR);
  201. MODULE_PARM_DESC(fastfail, "Reduce timeouts and retries");
  202. module_param_named(transop_timeout, ipr_transop_timeout, int, 0);
  203. MODULE_PARM_DESC(transop_timeout, "Time in seconds to wait for adapter to come operational (default: 300)");
  204. module_param_named(debug, ipr_debug, int, S_IRUGO | S_IWUSR);
  205. MODULE_PARM_DESC(debug, "Enable device driver debugging logging. Set to 1 to enable. (default: 0)");
  206. module_param_named(dual_ioa_raid, ipr_dual_ioa_raid, int, 0);
  207. MODULE_PARM_DESC(dual_ioa_raid, "Enable dual adapter RAID support. Set to 1 to enable. (default: 1)");
  208. module_param_named(max_devs, ipr_max_devs, int, 0);
  209. MODULE_PARM_DESC(max_devs, "Specify the maximum number of physical devices. "
  210. "[Default=" __stringify(IPR_DEFAULT_SIS64_DEVS) "]");
  211. MODULE_LICENSE("GPL");
  212. MODULE_VERSION(IPR_DRIVER_VERSION);
  213. /* A constant array of IOASCs/URCs/Error Messages */
  214. static const
  215. struct ipr_error_table_t ipr_error_table[] = {
  216. {0x00000000, 1, IPR_DEFAULT_LOG_LEVEL,
  217. "8155: An unknown error was received"},
  218. {0x00330000, 0, 0,
  219. "Soft underlength error"},
  220. {0x005A0000, 0, 0,
  221. "Command to be cancelled not found"},
  222. {0x00808000, 0, 0,
  223. "Qualified success"},
  224. {0x01080000, 1, IPR_DEFAULT_LOG_LEVEL,
  225. "FFFE: Soft device bus error recovered by the IOA"},
  226. {0x01088100, 0, IPR_DEFAULT_LOG_LEVEL,
  227. "4101: Soft device bus fabric error"},
  228. {0x01100100, 0, IPR_DEFAULT_LOG_LEVEL,
  229. "FFFC: Logical block guard error recovered by the device"},
  230. {0x01100300, 0, IPR_DEFAULT_LOG_LEVEL,
  231. "FFFC: Logical block reference tag error recovered by the device"},
  232. {0x01108300, 0, IPR_DEFAULT_LOG_LEVEL,
  233. "4171: Recovered scatter list tag / sequence number error"},
  234. {0x01109000, 0, IPR_DEFAULT_LOG_LEVEL,
  235. "FF3D: Recovered logical block CRC error on IOA to Host transfer"},
  236. {0x01109200, 0, IPR_DEFAULT_LOG_LEVEL,
  237. "4171: Recovered logical block sequence number error on IOA to Host transfer"},
  238. {0x0110A000, 0, IPR_DEFAULT_LOG_LEVEL,
  239. "FFFD: Recovered logical block reference tag error detected by the IOA"},
  240. {0x0110A100, 0, IPR_DEFAULT_LOG_LEVEL,
  241. "FFFD: Logical block guard error recovered by the IOA"},
  242. {0x01170600, 0, IPR_DEFAULT_LOG_LEVEL,
  243. "FFF9: Device sector reassign successful"},
  244. {0x01170900, 0, IPR_DEFAULT_LOG_LEVEL,
  245. "FFF7: Media error recovered by device rewrite procedures"},
  246. {0x01180200, 0, IPR_DEFAULT_LOG_LEVEL,
  247. "7001: IOA sector reassignment successful"},
  248. {0x01180500, 0, IPR_DEFAULT_LOG_LEVEL,
  249. "FFF9: Soft media error. Sector reassignment recommended"},
  250. {0x01180600, 0, IPR_DEFAULT_LOG_LEVEL,
  251. "FFF7: Media error recovered by IOA rewrite procedures"},
  252. {0x01418000, 0, IPR_DEFAULT_LOG_LEVEL,
  253. "FF3D: Soft PCI bus error recovered by the IOA"},
  254. {0x01440000, 1, IPR_DEFAULT_LOG_LEVEL,
  255. "FFF6: Device hardware error recovered by the IOA"},
  256. {0x01448100, 0, IPR_DEFAULT_LOG_LEVEL,
  257. "FFF6: Device hardware error recovered by the device"},
  258. {0x01448200, 1, IPR_DEFAULT_LOG_LEVEL,
  259. "FF3D: Soft IOA error recovered by the IOA"},
  260. {0x01448300, 0, IPR_DEFAULT_LOG_LEVEL,
  261. "FFFA: Undefined device response recovered by the IOA"},
  262. {0x014A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  263. "FFF6: Device bus error, message or command phase"},
  264. {0x014A8000, 0, IPR_DEFAULT_LOG_LEVEL,
  265. "FFFE: Task Management Function failed"},
  266. {0x015D0000, 0, IPR_DEFAULT_LOG_LEVEL,
  267. "FFF6: Failure prediction threshold exceeded"},
  268. {0x015D9200, 0, IPR_DEFAULT_LOG_LEVEL,
  269. "8009: Impending cache battery pack failure"},
  270. {0x02040400, 0, 0,
  271. "34FF: Disk device format in progress"},
  272. {0x02048000, 0, IPR_DEFAULT_LOG_LEVEL,
  273. "9070: IOA requested reset"},
  274. {0x023F0000, 0, 0,
  275. "Synchronization required"},
  276. {0x024E0000, 0, 0,
  277. "No ready, IOA shutdown"},
  278. {0x025A0000, 0, 0,
  279. "Not ready, IOA has been shutdown"},
  280. {0x02670100, 0, IPR_DEFAULT_LOG_LEVEL,
  281. "3020: Storage subsystem configuration error"},
  282. {0x03110B00, 0, 0,
  283. "FFF5: Medium error, data unreadable, recommend reassign"},
  284. {0x03110C00, 0, 0,
  285. "7000: Medium error, data unreadable, do not reassign"},
  286. {0x03310000, 0, IPR_DEFAULT_LOG_LEVEL,
  287. "FFF3: Disk media format bad"},
  288. {0x04050000, 0, IPR_DEFAULT_LOG_LEVEL,
  289. "3002: Addressed device failed to respond to selection"},
  290. {0x04080000, 1, IPR_DEFAULT_LOG_LEVEL,
  291. "3100: Device bus error"},
  292. {0x04080100, 0, IPR_DEFAULT_LOG_LEVEL,
  293. "3109: IOA timed out a device command"},
  294. {0x04088000, 0, 0,
  295. "3120: SCSI bus is not operational"},
  296. {0x04088100, 0, IPR_DEFAULT_LOG_LEVEL,
  297. "4100: Hard device bus fabric error"},
  298. {0x04100100, 0, IPR_DEFAULT_LOG_LEVEL,
  299. "310C: Logical block guard error detected by the device"},
  300. {0x04100300, 0, IPR_DEFAULT_LOG_LEVEL,
  301. "310C: Logical block reference tag error detected by the device"},
  302. {0x04108300, 1, IPR_DEFAULT_LOG_LEVEL,
  303. "4170: Scatter list tag / sequence number error"},
  304. {0x04109000, 1, IPR_DEFAULT_LOG_LEVEL,
  305. "8150: Logical block CRC error on IOA to Host transfer"},
  306. {0x04109200, 1, IPR_DEFAULT_LOG_LEVEL,
  307. "4170: Logical block sequence number error on IOA to Host transfer"},
  308. {0x0410A000, 0, IPR_DEFAULT_LOG_LEVEL,
  309. "310D: Logical block reference tag error detected by the IOA"},
  310. {0x0410A100, 0, IPR_DEFAULT_LOG_LEVEL,
  311. "310D: Logical block guard error detected by the IOA"},
  312. {0x04118000, 0, IPR_DEFAULT_LOG_LEVEL,
  313. "9000: IOA reserved area data check"},
  314. {0x04118100, 0, IPR_DEFAULT_LOG_LEVEL,
  315. "9001: IOA reserved area invalid data pattern"},
  316. {0x04118200, 0, IPR_DEFAULT_LOG_LEVEL,
  317. "9002: IOA reserved area LRC error"},
  318. {0x04118300, 1, IPR_DEFAULT_LOG_LEVEL,
  319. "Hardware Error, IOA metadata access error"},
  320. {0x04320000, 0, IPR_DEFAULT_LOG_LEVEL,
  321. "102E: Out of alternate sectors for disk storage"},
  322. {0x04330000, 1, IPR_DEFAULT_LOG_LEVEL,
  323. "FFF4: Data transfer underlength error"},
  324. {0x04338000, 1, IPR_DEFAULT_LOG_LEVEL,
  325. "FFF4: Data transfer overlength error"},
  326. {0x043E0100, 0, IPR_DEFAULT_LOG_LEVEL,
  327. "3400: Logical unit failure"},
  328. {0x04408500, 0, IPR_DEFAULT_LOG_LEVEL,
  329. "FFF4: Device microcode is corrupt"},
  330. {0x04418000, 1, IPR_DEFAULT_LOG_LEVEL,
  331. "8150: PCI bus error"},
  332. {0x04430000, 1, 0,
  333. "Unsupported device bus message received"},
  334. {0x04440000, 1, IPR_DEFAULT_LOG_LEVEL,
  335. "FFF4: Disk device problem"},
  336. {0x04448200, 1, IPR_DEFAULT_LOG_LEVEL,
  337. "8150: Permanent IOA failure"},
  338. {0x04448300, 0, IPR_DEFAULT_LOG_LEVEL,
  339. "3010: Disk device returned wrong response to IOA"},
  340. {0x04448400, 0, IPR_DEFAULT_LOG_LEVEL,
  341. "8151: IOA microcode error"},
  342. {0x04448500, 0, 0,
  343. "Device bus status error"},
  344. {0x04448600, 0, IPR_DEFAULT_LOG_LEVEL,
  345. "8157: IOA error requiring IOA reset to recover"},
  346. {0x04448700, 0, 0,
  347. "ATA device status error"},
  348. {0x04490000, 0, 0,
  349. "Message reject received from the device"},
  350. {0x04449200, 0, IPR_DEFAULT_LOG_LEVEL,
  351. "8008: A permanent cache battery pack failure occurred"},
  352. {0x0444A000, 0, IPR_DEFAULT_LOG_LEVEL,
  353. "9090: Disk unit has been modified after the last known status"},
  354. {0x0444A200, 0, IPR_DEFAULT_LOG_LEVEL,
  355. "9081: IOA detected device error"},
  356. {0x0444A300, 0, IPR_DEFAULT_LOG_LEVEL,
  357. "9082: IOA detected device error"},
  358. {0x044A0000, 1, IPR_DEFAULT_LOG_LEVEL,
  359. "3110: Device bus error, message or command phase"},
  360. {0x044A8000, 1, IPR_DEFAULT_LOG_LEVEL,
  361. "3110: SAS Command / Task Management Function failed"},
  362. {0x04670400, 0, IPR_DEFAULT_LOG_LEVEL,
  363. "9091: Incorrect hardware configuration change has been detected"},
  364. {0x04678000, 0, IPR_DEFAULT_LOG_LEVEL,
  365. "9073: Invalid multi-adapter configuration"},
  366. {0x04678100, 0, IPR_DEFAULT_LOG_LEVEL,
  367. "4010: Incorrect connection between cascaded expanders"},
  368. {0x04678200, 0, IPR_DEFAULT_LOG_LEVEL,
  369. "4020: Connections exceed IOA design limits"},
  370. {0x04678300, 0, IPR_DEFAULT_LOG_LEVEL,
  371. "4030: Incorrect multipath connection"},
  372. {0x04679000, 0, IPR_DEFAULT_LOG_LEVEL,
  373. "4110: Unsupported enclosure function"},
  374. {0x046E0000, 0, IPR_DEFAULT_LOG_LEVEL,
  375. "FFF4: Command to logical unit failed"},
  376. {0x05240000, 1, 0,
  377. "Illegal request, invalid request type or request packet"},
  378. {0x05250000, 0, 0,
  379. "Illegal request, invalid resource handle"},
  380. {0x05258000, 0, 0,
  381. "Illegal request, commands not allowed to this device"},
  382. {0x05258100, 0, 0,
  383. "Illegal request, command not allowed to a secondary adapter"},
  384. {0x05258200, 0, 0,
  385. "Illegal request, command not allowed to a non-optimized resource"},
  386. {0x05260000, 0, 0,
  387. "Illegal request, invalid field in parameter list"},
  388. {0x05260100, 0, 0,
  389. "Illegal request, parameter not supported"},
  390. {0x05260200, 0, 0,
  391. "Illegal request, parameter value invalid"},
  392. {0x052C0000, 0, 0,
  393. "Illegal request, command sequence error"},
  394. {0x052C8000, 1, 0,
  395. "Illegal request, dual adapter support not enabled"},
  396. {0x06040500, 0, IPR_DEFAULT_LOG_LEVEL,
  397. "9031: Array protection temporarily suspended, protection resuming"},
  398. {0x06040600, 0, IPR_DEFAULT_LOG_LEVEL,
  399. "9040: Array protection temporarily suspended, protection resuming"},
  400. {0x06288000, 0, IPR_DEFAULT_LOG_LEVEL,
  401. "3140: Device bus not ready to ready transition"},
  402. {0x06290000, 0, IPR_DEFAULT_LOG_LEVEL,
  403. "FFFB: SCSI bus was reset"},
  404. {0x06290500, 0, 0,
  405. "FFFE: SCSI bus transition to single ended"},
  406. {0x06290600, 0, 0,
  407. "FFFE: SCSI bus transition to LVD"},
  408. {0x06298000, 0, IPR_DEFAULT_LOG_LEVEL,
  409. "FFFB: SCSI bus was reset by another initiator"},
  410. {0x063F0300, 0, IPR_DEFAULT_LOG_LEVEL,
  411. "3029: A device replacement has occurred"},
  412. {0x064C8000, 0, IPR_DEFAULT_LOG_LEVEL,
  413. "9051: IOA cache data exists for a missing or failed device"},
  414. {0x064C8100, 0, IPR_DEFAULT_LOG_LEVEL,
  415. "9055: Auxiliary cache IOA contains cache data needed by the primary IOA"},
  416. {0x06670100, 0, IPR_DEFAULT_LOG_LEVEL,
  417. "9025: Disk unit is not supported at its physical location"},
  418. {0x06670600, 0, IPR_DEFAULT_LOG_LEVEL,
  419. "3020: IOA detected a SCSI bus configuration error"},
  420. {0x06678000, 0, IPR_DEFAULT_LOG_LEVEL,
  421. "3150: SCSI bus configuration error"},
  422. {0x06678100, 0, IPR_DEFAULT_LOG_LEVEL,
  423. "9074: Asymmetric advanced function disk configuration"},
  424. {0x06678300, 0, IPR_DEFAULT_LOG_LEVEL,
  425. "4040: Incomplete multipath connection between IOA and enclosure"},
  426. {0x06678400, 0, IPR_DEFAULT_LOG_LEVEL,
  427. "4041: Incomplete multipath connection between enclosure and device"},
  428. {0x06678500, 0, IPR_DEFAULT_LOG_LEVEL,
  429. "9075: Incomplete multipath connection between IOA and remote IOA"},
  430. {0x06678600, 0, IPR_DEFAULT_LOG_LEVEL,
  431. "9076: Configuration error, missing remote IOA"},
  432. {0x06679100, 0, IPR_DEFAULT_LOG_LEVEL,
  433. "4050: Enclosure does not support a required multipath function"},
  434. {0x06690000, 0, IPR_DEFAULT_LOG_LEVEL,
  435. "4070: Logically bad block written on device"},
  436. {0x06690200, 0, IPR_DEFAULT_LOG_LEVEL,
  437. "9041: Array protection temporarily suspended"},
  438. {0x06698200, 0, IPR_DEFAULT_LOG_LEVEL,
  439. "9042: Corrupt array parity detected on specified device"},
  440. {0x066B0200, 0, IPR_DEFAULT_LOG_LEVEL,
  441. "9030: Array no longer protected due to missing or failed disk unit"},
  442. {0x066B8000, 0, IPR_DEFAULT_LOG_LEVEL,
  443. "9071: Link operational transition"},
  444. {0x066B8100, 0, IPR_DEFAULT_LOG_LEVEL,
  445. "9072: Link not operational transition"},
  446. {0x066B8200, 0, IPR_DEFAULT_LOG_LEVEL,
  447. "9032: Array exposed but still protected"},
  448. {0x066B8300, 0, IPR_DEFAULT_LOG_LEVEL + 1,
  449. "70DD: Device forced failed by disrupt device command"},
  450. {0x066B9100, 0, IPR_DEFAULT_LOG_LEVEL,
  451. "4061: Multipath redundancy level got better"},
  452. {0x066B9200, 0, IPR_DEFAULT_LOG_LEVEL,
  453. "4060: Multipath redundancy level got worse"},
  454. {0x07270000, 0, 0,
  455. "Failure due to other device"},
  456. {0x07278000, 0, IPR_DEFAULT_LOG_LEVEL,
  457. "9008: IOA does not support functions expected by devices"},
  458. {0x07278100, 0, IPR_DEFAULT_LOG_LEVEL,
  459. "9010: Cache data associated with attached devices cannot be found"},
  460. {0x07278200, 0, IPR_DEFAULT_LOG_LEVEL,
  461. "9011: Cache data belongs to devices other than those attached"},
  462. {0x07278400, 0, IPR_DEFAULT_LOG_LEVEL,
  463. "9020: Array missing 2 or more devices with only 1 device present"},
  464. {0x07278500, 0, IPR_DEFAULT_LOG_LEVEL,
  465. "9021: Array missing 2 or more devices with 2 or more devices present"},
  466. {0x07278600, 0, IPR_DEFAULT_LOG_LEVEL,
  467. "9022: Exposed array is missing a required device"},
  468. {0x07278700, 0, IPR_DEFAULT_LOG_LEVEL,
  469. "9023: Array member(s) not at required physical locations"},
  470. {0x07278800, 0, IPR_DEFAULT_LOG_LEVEL,
  471. "9024: Array not functional due to present hardware configuration"},
  472. {0x07278900, 0, IPR_DEFAULT_LOG_LEVEL,
  473. "9026: Array not functional due to present hardware configuration"},
  474. {0x07278A00, 0, IPR_DEFAULT_LOG_LEVEL,
  475. "9027: Array is missing a device and parity is out of sync"},
  476. {0x07278B00, 0, IPR_DEFAULT_LOG_LEVEL,
  477. "9028: Maximum number of arrays already exist"},
  478. {0x07278C00, 0, IPR_DEFAULT_LOG_LEVEL,
  479. "9050: Required cache data cannot be located for a disk unit"},
  480. {0x07278D00, 0, IPR_DEFAULT_LOG_LEVEL,
  481. "9052: Cache data exists for a device that has been modified"},
  482. {0x07278F00, 0, IPR_DEFAULT_LOG_LEVEL,
  483. "9054: IOA resources not available due to previous problems"},
  484. {0x07279100, 0, IPR_DEFAULT_LOG_LEVEL,
  485. "9092: Disk unit requires initialization before use"},
  486. {0x07279200, 0, IPR_DEFAULT_LOG_LEVEL,
  487. "9029: Incorrect hardware configuration change has been detected"},
  488. {0x07279600, 0, IPR_DEFAULT_LOG_LEVEL,
  489. "9060: One or more disk pairs are missing from an array"},
  490. {0x07279700, 0, IPR_DEFAULT_LOG_LEVEL,
  491. "9061: One or more disks are missing from an array"},
  492. {0x07279800, 0, IPR_DEFAULT_LOG_LEVEL,
  493. "9062: One or more disks are missing from an array"},
  494. {0x07279900, 0, IPR_DEFAULT_LOG_LEVEL,
  495. "9063: Maximum number of functional arrays has been exceeded"},
  496. {0x0B260000, 0, 0,
  497. "Aborted command, invalid descriptor"},
  498. {0x0B5A0000, 0, 0,
  499. "Command terminated by host"}
  500. };
  501. static const struct ipr_ses_table_entry ipr_ses_table[] = {
  502. { "2104-DL1 ", "XXXXXXXXXXXXXXXX", 80 },
  503. { "2104-TL1 ", "XXXXXXXXXXXXXXXX", 80 },
  504. { "HSBP07M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 7 slot */
  505. { "HSBP05M P U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Hidive 5 slot */
  506. { "HSBP05M S U2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* Bowtie */
  507. { "HSBP06E ASU2SCSI", "XXXXXXXXXXXXXXXX", 80 }, /* MartinFenning */
  508. { "2104-DU3 ", "XXXXXXXXXXXXXXXX", 160 },
  509. { "2104-TU3 ", "XXXXXXXXXXXXXXXX", 160 },
  510. { "HSBP04C RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  511. { "HSBP06E RSU2SCSI", "XXXXXXX*XXXXXXXX", 160 },
  512. { "St V1S2 ", "XXXXXXXXXXXXXXXX", 160 },
  513. { "HSBPD4M PU3SCSI", "XXXXXXX*XXXXXXXX", 160 },
  514. { "VSBPD1H U3SCSI", "XXXXXXX*XXXXXXXX", 160 }
  515. };
  516. /*
  517. * Function Prototypes
  518. */
  519. static int ipr_reset_alert(struct ipr_cmnd *);
  520. static void ipr_process_ccn(struct ipr_cmnd *);
  521. static void ipr_process_error(struct ipr_cmnd *);
  522. static void ipr_reset_ioa_job(struct ipr_cmnd *);
  523. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *,
  524. enum ipr_shutdown_type);
  525. #ifdef CONFIG_SCSI_IPR_TRACE
  526. /**
  527. * ipr_trc_hook - Add a trace entry to the driver trace
  528. * @ipr_cmd: ipr command struct
  529. * @type: trace type
  530. * @add_data: additional data
  531. *
  532. * Return value:
  533. * none
  534. **/
  535. static void ipr_trc_hook(struct ipr_cmnd *ipr_cmd,
  536. u8 type, u32 add_data)
  537. {
  538. struct ipr_trace_entry *trace_entry;
  539. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  540. trace_entry = &ioa_cfg->trace[ioa_cfg->trace_index++];
  541. trace_entry->time = jiffies;
  542. trace_entry->op_code = ipr_cmd->ioarcb.cmd_pkt.cdb[0];
  543. trace_entry->type = type;
  544. if (ipr_cmd->ioa_cfg->sis64)
  545. trace_entry->ata_op_code = ipr_cmd->i.ata_ioadl.regs.command;
  546. else
  547. trace_entry->ata_op_code = ipr_cmd->ioarcb.u.add_data.u.regs.command;
  548. trace_entry->cmd_index = ipr_cmd->cmd_index & 0xff;
  549. trace_entry->res_handle = ipr_cmd->ioarcb.res_handle;
  550. trace_entry->u.add_data = add_data;
  551. }
  552. #else
  553. #define ipr_trc_hook(ipr_cmd, type, add_data) do { } while (0)
  554. #endif
  555. /**
  556. * ipr_lock_and_done - Acquire lock and complete command
  557. * @ipr_cmd: ipr command struct
  558. *
  559. * Return value:
  560. * none
  561. **/
  562. static void ipr_lock_and_done(struct ipr_cmnd *ipr_cmd)
  563. {
  564. unsigned long lock_flags;
  565. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  566. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  567. ipr_cmd->done(ipr_cmd);
  568. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  569. }
  570. /**
  571. * ipr_reinit_ipr_cmnd - Re-initialize an IPR Cmnd block for reuse
  572. * @ipr_cmd: ipr command struct
  573. *
  574. * Return value:
  575. * none
  576. **/
  577. static void ipr_reinit_ipr_cmnd(struct ipr_cmnd *ipr_cmd)
  578. {
  579. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  580. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  581. struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
  582. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  583. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  584. ioarcb->data_transfer_length = 0;
  585. ioarcb->read_data_transfer_length = 0;
  586. ioarcb->ioadl_len = 0;
  587. ioarcb->read_ioadl_len = 0;
  588. if (ipr_cmd->ioa_cfg->sis64) {
  589. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  590. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  591. ioasa64->u.gata.status = 0;
  592. } else {
  593. ioarcb->write_ioadl_addr =
  594. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  595. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  596. ioasa->u.gata.status = 0;
  597. }
  598. ioasa->hdr.ioasc = 0;
  599. ioasa->hdr.residual_data_len = 0;
  600. ipr_cmd->scsi_cmd = NULL;
  601. ipr_cmd->qc = NULL;
  602. ipr_cmd->sense_buffer[0] = 0;
  603. ipr_cmd->dma_use_sg = 0;
  604. }
  605. /**
  606. * ipr_init_ipr_cmnd - Initialize an IPR Cmnd block
  607. * @ipr_cmd: ipr command struct
  608. *
  609. * Return value:
  610. * none
  611. **/
  612. static void ipr_init_ipr_cmnd(struct ipr_cmnd *ipr_cmd,
  613. void (*fast_done) (struct ipr_cmnd *))
  614. {
  615. ipr_reinit_ipr_cmnd(ipr_cmd);
  616. ipr_cmd->u.scratch = 0;
  617. ipr_cmd->sibling = NULL;
  618. ipr_cmd->fast_done = fast_done;
  619. init_timer(&ipr_cmd->timer);
  620. }
  621. /**
  622. * __ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block
  623. * @ioa_cfg: ioa config struct
  624. *
  625. * Return value:
  626. * pointer to ipr command struct
  627. **/
  628. static
  629. struct ipr_cmnd *__ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  630. {
  631. struct ipr_cmnd *ipr_cmd;
  632. ipr_cmd = list_entry(ioa_cfg->free_q.next, struct ipr_cmnd, queue);
  633. list_del(&ipr_cmd->queue);
  634. return ipr_cmd;
  635. }
  636. /**
  637. * ipr_get_free_ipr_cmnd - Get a free IPR Cmnd block and initialize it
  638. * @ioa_cfg: ioa config struct
  639. *
  640. * Return value:
  641. * pointer to ipr command struct
  642. **/
  643. static
  644. struct ipr_cmnd *ipr_get_free_ipr_cmnd(struct ipr_ioa_cfg *ioa_cfg)
  645. {
  646. struct ipr_cmnd *ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
  647. ipr_init_ipr_cmnd(ipr_cmd, ipr_lock_and_done);
  648. return ipr_cmd;
  649. }
  650. /**
  651. * ipr_mask_and_clear_interrupts - Mask all and clear specified interrupts
  652. * @ioa_cfg: ioa config struct
  653. * @clr_ints: interrupts to clear
  654. *
  655. * This function masks all interrupts on the adapter, then clears the
  656. * interrupts specified in the mask
  657. *
  658. * Return value:
  659. * none
  660. **/
  661. static void ipr_mask_and_clear_interrupts(struct ipr_ioa_cfg *ioa_cfg,
  662. u32 clr_ints)
  663. {
  664. volatile u32 int_reg;
  665. /* Stop new interrupts */
  666. ioa_cfg->allow_interrupts = 0;
  667. /* Set interrupt mask to stop all new interrupts */
  668. if (ioa_cfg->sis64)
  669. writeq(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  670. else
  671. writel(~0, ioa_cfg->regs.set_interrupt_mask_reg);
  672. /* Clear any pending interrupts */
  673. if (ioa_cfg->sis64)
  674. writel(~0, ioa_cfg->regs.clr_interrupt_reg);
  675. writel(clr_ints, ioa_cfg->regs.clr_interrupt_reg32);
  676. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  677. }
  678. /**
  679. * ipr_save_pcix_cmd_reg - Save PCI-X command register
  680. * @ioa_cfg: ioa config struct
  681. *
  682. * Return value:
  683. * 0 on success / -EIO on failure
  684. **/
  685. static int ipr_save_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  686. {
  687. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  688. if (pcix_cmd_reg == 0)
  689. return 0;
  690. if (pci_read_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  691. &ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  692. dev_err(&ioa_cfg->pdev->dev, "Failed to save PCI-X command register\n");
  693. return -EIO;
  694. }
  695. ioa_cfg->saved_pcix_cmd_reg |= PCI_X_CMD_DPERR_E | PCI_X_CMD_ERO;
  696. return 0;
  697. }
  698. /**
  699. * ipr_set_pcix_cmd_reg - Setup PCI-X command register
  700. * @ioa_cfg: ioa config struct
  701. *
  702. * Return value:
  703. * 0 on success / -EIO on failure
  704. **/
  705. static int ipr_set_pcix_cmd_reg(struct ipr_ioa_cfg *ioa_cfg)
  706. {
  707. int pcix_cmd_reg = pci_find_capability(ioa_cfg->pdev, PCI_CAP_ID_PCIX);
  708. if (pcix_cmd_reg) {
  709. if (pci_write_config_word(ioa_cfg->pdev, pcix_cmd_reg + PCI_X_CMD,
  710. ioa_cfg->saved_pcix_cmd_reg) != PCIBIOS_SUCCESSFUL) {
  711. dev_err(&ioa_cfg->pdev->dev, "Failed to setup PCI-X command register\n");
  712. return -EIO;
  713. }
  714. }
  715. return 0;
  716. }
  717. /**
  718. * ipr_sata_eh_done - done function for aborted SATA commands
  719. * @ipr_cmd: ipr command struct
  720. *
  721. * This function is invoked for ops generated to SATA
  722. * devices which are being aborted.
  723. *
  724. * Return value:
  725. * none
  726. **/
  727. static void ipr_sata_eh_done(struct ipr_cmnd *ipr_cmd)
  728. {
  729. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  730. struct ata_queued_cmd *qc = ipr_cmd->qc;
  731. struct ipr_sata_port *sata_port = qc->ap->private_data;
  732. qc->err_mask |= AC_ERR_OTHER;
  733. sata_port->ioasa.status |= ATA_BUSY;
  734. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  735. ata_qc_complete(qc);
  736. }
  737. /**
  738. * ipr_scsi_eh_done - mid-layer done function for aborted ops
  739. * @ipr_cmd: ipr command struct
  740. *
  741. * This function is invoked by the interrupt handler for
  742. * ops generated by the SCSI mid-layer which are being aborted.
  743. *
  744. * Return value:
  745. * none
  746. **/
  747. static void ipr_scsi_eh_done(struct ipr_cmnd *ipr_cmd)
  748. {
  749. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  750. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  751. scsi_cmd->result |= (DID_ERROR << 16);
  752. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  753. scsi_cmd->scsi_done(scsi_cmd);
  754. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  755. }
  756. /**
  757. * ipr_fail_all_ops - Fails all outstanding ops.
  758. * @ioa_cfg: ioa config struct
  759. *
  760. * This function fails all outstanding ops.
  761. *
  762. * Return value:
  763. * none
  764. **/
  765. static void ipr_fail_all_ops(struct ipr_ioa_cfg *ioa_cfg)
  766. {
  767. struct ipr_cmnd *ipr_cmd, *temp;
  768. ENTER;
  769. list_for_each_entry_safe(ipr_cmd, temp, &ioa_cfg->pending_q, queue) {
  770. list_del(&ipr_cmd->queue);
  771. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_IOA_WAS_RESET);
  772. ipr_cmd->s.ioasa.hdr.ilid = cpu_to_be32(IPR_DRIVER_ILID);
  773. if (ipr_cmd->scsi_cmd)
  774. ipr_cmd->done = ipr_scsi_eh_done;
  775. else if (ipr_cmd->qc)
  776. ipr_cmd->done = ipr_sata_eh_done;
  777. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, IPR_IOASC_IOA_WAS_RESET);
  778. del_timer(&ipr_cmd->timer);
  779. ipr_cmd->done(ipr_cmd);
  780. }
  781. LEAVE;
  782. }
  783. /**
  784. * ipr_send_command - Send driver initiated requests.
  785. * @ipr_cmd: ipr command struct
  786. *
  787. * This function sends a command to the adapter using the correct write call.
  788. * In the case of sis64, calculate the ioarcb size required. Then or in the
  789. * appropriate bits.
  790. *
  791. * Return value:
  792. * none
  793. **/
  794. static void ipr_send_command(struct ipr_cmnd *ipr_cmd)
  795. {
  796. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  797. dma_addr_t send_dma_addr = ipr_cmd->dma_addr;
  798. if (ioa_cfg->sis64) {
  799. /* The default size is 256 bytes */
  800. send_dma_addr |= 0x1;
  801. /* If the number of ioadls * size of ioadl > 128 bytes,
  802. then use a 512 byte ioarcb */
  803. if (ipr_cmd->dma_use_sg * sizeof(struct ipr_ioadl64_desc) > 128 )
  804. send_dma_addr |= 0x4;
  805. writeq(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
  806. } else
  807. writel(send_dma_addr, ioa_cfg->regs.ioarrin_reg);
  808. }
  809. /**
  810. * ipr_do_req - Send driver initiated requests.
  811. * @ipr_cmd: ipr command struct
  812. * @done: done function
  813. * @timeout_func: timeout function
  814. * @timeout: timeout value
  815. *
  816. * This function sends the specified command to the adapter with the
  817. * timeout given. The done function is invoked on command completion.
  818. *
  819. * Return value:
  820. * none
  821. **/
  822. static void ipr_do_req(struct ipr_cmnd *ipr_cmd,
  823. void (*done) (struct ipr_cmnd *),
  824. void (*timeout_func) (struct ipr_cmnd *), u32 timeout)
  825. {
  826. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  827. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  828. ipr_cmd->done = done;
  829. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  830. ipr_cmd->timer.expires = jiffies + timeout;
  831. ipr_cmd->timer.function = (void (*)(unsigned long))timeout_func;
  832. add_timer(&ipr_cmd->timer);
  833. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, 0);
  834. ipr_send_command(ipr_cmd);
  835. }
  836. /**
  837. * ipr_internal_cmd_done - Op done function for an internally generated op.
  838. * @ipr_cmd: ipr command struct
  839. *
  840. * This function is the op done function for an internally generated,
  841. * blocking op. It simply wakes the sleeping thread.
  842. *
  843. * Return value:
  844. * none
  845. **/
  846. static void ipr_internal_cmd_done(struct ipr_cmnd *ipr_cmd)
  847. {
  848. if (ipr_cmd->sibling)
  849. ipr_cmd->sibling = NULL;
  850. else
  851. complete(&ipr_cmd->completion);
  852. }
  853. /**
  854. * ipr_init_ioadl - initialize the ioadl for the correct SIS type
  855. * @ipr_cmd: ipr command struct
  856. * @dma_addr: dma address
  857. * @len: transfer length
  858. * @flags: ioadl flag value
  859. *
  860. * This function initializes an ioadl in the case where there is only a single
  861. * descriptor.
  862. *
  863. * Return value:
  864. * nothing
  865. **/
  866. static void ipr_init_ioadl(struct ipr_cmnd *ipr_cmd, dma_addr_t dma_addr,
  867. u32 len, int flags)
  868. {
  869. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  870. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  871. ipr_cmd->dma_use_sg = 1;
  872. if (ipr_cmd->ioa_cfg->sis64) {
  873. ioadl64->flags = cpu_to_be32(flags);
  874. ioadl64->data_len = cpu_to_be32(len);
  875. ioadl64->address = cpu_to_be64(dma_addr);
  876. ipr_cmd->ioarcb.ioadl_len =
  877. cpu_to_be32(sizeof(struct ipr_ioadl64_desc));
  878. ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
  879. } else {
  880. ioadl->flags_and_data_len = cpu_to_be32(flags | len);
  881. ioadl->address = cpu_to_be32(dma_addr);
  882. if (flags == IPR_IOADL_FLAGS_READ_LAST) {
  883. ipr_cmd->ioarcb.read_ioadl_len =
  884. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  885. ipr_cmd->ioarcb.read_data_transfer_length = cpu_to_be32(len);
  886. } else {
  887. ipr_cmd->ioarcb.ioadl_len =
  888. cpu_to_be32(sizeof(struct ipr_ioadl_desc));
  889. ipr_cmd->ioarcb.data_transfer_length = cpu_to_be32(len);
  890. }
  891. }
  892. }
  893. /**
  894. * ipr_send_blocking_cmd - Send command and sleep on its completion.
  895. * @ipr_cmd: ipr command struct
  896. * @timeout_func: function to invoke if command times out
  897. * @timeout: timeout
  898. *
  899. * Return value:
  900. * none
  901. **/
  902. static void ipr_send_blocking_cmd(struct ipr_cmnd *ipr_cmd,
  903. void (*timeout_func) (struct ipr_cmnd *ipr_cmd),
  904. u32 timeout)
  905. {
  906. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  907. init_completion(&ipr_cmd->completion);
  908. ipr_do_req(ipr_cmd, ipr_internal_cmd_done, timeout_func, timeout);
  909. spin_unlock_irq(ioa_cfg->host->host_lock);
  910. wait_for_completion(&ipr_cmd->completion);
  911. spin_lock_irq(ioa_cfg->host->host_lock);
  912. }
  913. /**
  914. * ipr_send_hcam - Send an HCAM to the adapter.
  915. * @ioa_cfg: ioa config struct
  916. * @type: HCAM type
  917. * @hostrcb: hostrcb struct
  918. *
  919. * This function will send a Host Controlled Async command to the adapter.
  920. * If HCAMs are currently not allowed to be issued to the adapter, it will
  921. * place the hostrcb on the free queue.
  922. *
  923. * Return value:
  924. * none
  925. **/
  926. static void ipr_send_hcam(struct ipr_ioa_cfg *ioa_cfg, u8 type,
  927. struct ipr_hostrcb *hostrcb)
  928. {
  929. struct ipr_cmnd *ipr_cmd;
  930. struct ipr_ioarcb *ioarcb;
  931. if (ioa_cfg->allow_cmds) {
  932. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  933. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  934. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_pending_q);
  935. ipr_cmd->u.hostrcb = hostrcb;
  936. ioarcb = &ipr_cmd->ioarcb;
  937. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  938. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_HCAM;
  939. ioarcb->cmd_pkt.cdb[0] = IPR_HOST_CONTROLLED_ASYNC;
  940. ioarcb->cmd_pkt.cdb[1] = type;
  941. ioarcb->cmd_pkt.cdb[7] = (sizeof(hostrcb->hcam) >> 8) & 0xff;
  942. ioarcb->cmd_pkt.cdb[8] = sizeof(hostrcb->hcam) & 0xff;
  943. ipr_init_ioadl(ipr_cmd, hostrcb->hostrcb_dma,
  944. sizeof(hostrcb->hcam), IPR_IOADL_FLAGS_READ_LAST);
  945. if (type == IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE)
  946. ipr_cmd->done = ipr_process_ccn;
  947. else
  948. ipr_cmd->done = ipr_process_error;
  949. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_IOA_RES_ADDR);
  950. ipr_send_command(ipr_cmd);
  951. } else {
  952. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  953. }
  954. }
  955. /**
  956. * ipr_update_ata_class - Update the ata class in the resource entry
  957. * @res: resource entry struct
  958. * @proto: cfgte device bus protocol value
  959. *
  960. * Return value:
  961. * none
  962. **/
  963. static void ipr_update_ata_class(struct ipr_resource_entry *res, unsigned int proto)
  964. {
  965. switch (proto) {
  966. case IPR_PROTO_SATA:
  967. case IPR_PROTO_SAS_STP:
  968. res->ata_class = ATA_DEV_ATA;
  969. break;
  970. case IPR_PROTO_SATA_ATAPI:
  971. case IPR_PROTO_SAS_STP_ATAPI:
  972. res->ata_class = ATA_DEV_ATAPI;
  973. break;
  974. default:
  975. res->ata_class = ATA_DEV_UNKNOWN;
  976. break;
  977. };
  978. }
  979. /**
  980. * ipr_init_res_entry - Initialize a resource entry struct.
  981. * @res: resource entry struct
  982. * @cfgtew: config table entry wrapper struct
  983. *
  984. * Return value:
  985. * none
  986. **/
  987. static void ipr_init_res_entry(struct ipr_resource_entry *res,
  988. struct ipr_config_table_entry_wrapper *cfgtew)
  989. {
  990. int found = 0;
  991. unsigned int proto;
  992. struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
  993. struct ipr_resource_entry *gscsi_res = NULL;
  994. res->needs_sync_complete = 0;
  995. res->in_erp = 0;
  996. res->add_to_ml = 0;
  997. res->del_from_ml = 0;
  998. res->resetting_device = 0;
  999. res->sdev = NULL;
  1000. res->sata_port = NULL;
  1001. if (ioa_cfg->sis64) {
  1002. proto = cfgtew->u.cfgte64->proto;
  1003. res->res_flags = cfgtew->u.cfgte64->res_flags;
  1004. res->qmodel = IPR_QUEUEING_MODEL64(res);
  1005. res->type = cfgtew->u.cfgte64->res_type;
  1006. memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
  1007. sizeof(res->res_path));
  1008. res->bus = 0;
  1009. memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1010. sizeof(res->dev_lun.scsi_lun));
  1011. res->lun = scsilun_to_int(&res->dev_lun);
  1012. if (res->type == IPR_RES_TYPE_GENERIC_SCSI) {
  1013. list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue) {
  1014. if (gscsi_res->dev_id == cfgtew->u.cfgte64->dev_id) {
  1015. found = 1;
  1016. res->target = gscsi_res->target;
  1017. break;
  1018. }
  1019. }
  1020. if (!found) {
  1021. res->target = find_first_zero_bit(ioa_cfg->target_ids,
  1022. ioa_cfg->max_devs_supported);
  1023. set_bit(res->target, ioa_cfg->target_ids);
  1024. }
  1025. } else if (res->type == IPR_RES_TYPE_IOAFP) {
  1026. res->bus = IPR_IOAFP_VIRTUAL_BUS;
  1027. res->target = 0;
  1028. } else if (res->type == IPR_RES_TYPE_ARRAY) {
  1029. res->bus = IPR_ARRAY_VIRTUAL_BUS;
  1030. res->target = find_first_zero_bit(ioa_cfg->array_ids,
  1031. ioa_cfg->max_devs_supported);
  1032. set_bit(res->target, ioa_cfg->array_ids);
  1033. } else if (res->type == IPR_RES_TYPE_VOLUME_SET) {
  1034. res->bus = IPR_VSET_VIRTUAL_BUS;
  1035. res->target = find_first_zero_bit(ioa_cfg->vset_ids,
  1036. ioa_cfg->max_devs_supported);
  1037. set_bit(res->target, ioa_cfg->vset_ids);
  1038. } else {
  1039. res->target = find_first_zero_bit(ioa_cfg->target_ids,
  1040. ioa_cfg->max_devs_supported);
  1041. set_bit(res->target, ioa_cfg->target_ids);
  1042. }
  1043. } else {
  1044. proto = cfgtew->u.cfgte->proto;
  1045. res->qmodel = IPR_QUEUEING_MODEL(res);
  1046. res->flags = cfgtew->u.cfgte->flags;
  1047. if (res->flags & IPR_IS_IOA_RESOURCE)
  1048. res->type = IPR_RES_TYPE_IOAFP;
  1049. else
  1050. res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
  1051. res->bus = cfgtew->u.cfgte->res_addr.bus;
  1052. res->target = cfgtew->u.cfgte->res_addr.target;
  1053. res->lun = cfgtew->u.cfgte->res_addr.lun;
  1054. res->lun_wwn = get_unaligned_be64(cfgtew->u.cfgte->lun_wwn);
  1055. }
  1056. ipr_update_ata_class(res, proto);
  1057. }
  1058. /**
  1059. * ipr_is_same_device - Determine if two devices are the same.
  1060. * @res: resource entry struct
  1061. * @cfgtew: config table entry wrapper struct
  1062. *
  1063. * Return value:
  1064. * 1 if the devices are the same / 0 otherwise
  1065. **/
  1066. static int ipr_is_same_device(struct ipr_resource_entry *res,
  1067. struct ipr_config_table_entry_wrapper *cfgtew)
  1068. {
  1069. if (res->ioa_cfg->sis64) {
  1070. if (!memcmp(&res->dev_id, &cfgtew->u.cfgte64->dev_id,
  1071. sizeof(cfgtew->u.cfgte64->dev_id)) &&
  1072. !memcmp(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1073. sizeof(cfgtew->u.cfgte64->lun))) {
  1074. return 1;
  1075. }
  1076. } else {
  1077. if (res->bus == cfgtew->u.cfgte->res_addr.bus &&
  1078. res->target == cfgtew->u.cfgte->res_addr.target &&
  1079. res->lun == cfgtew->u.cfgte->res_addr.lun)
  1080. return 1;
  1081. }
  1082. return 0;
  1083. }
  1084. /**
  1085. * ipr_format_res_path - Format the resource path for printing.
  1086. * @res_path: resource path
  1087. * @buf: buffer
  1088. *
  1089. * Return value:
  1090. * pointer to buffer
  1091. **/
  1092. static char *ipr_format_res_path(u8 *res_path, char *buffer, int len)
  1093. {
  1094. int i;
  1095. char *p = buffer;
  1096. *p = '\0';
  1097. p += snprintf(p, buffer + len - p, "%02X", res_path[0]);
  1098. for (i = 1; res_path[i] != 0xff && ((i * 3) < len); i++)
  1099. p += snprintf(p, buffer + len - p, "-%02X", res_path[i]);
  1100. return buffer;
  1101. }
  1102. /**
  1103. * ipr_update_res_entry - Update the resource entry.
  1104. * @res: resource entry struct
  1105. * @cfgtew: config table entry wrapper struct
  1106. *
  1107. * Return value:
  1108. * none
  1109. **/
  1110. static void ipr_update_res_entry(struct ipr_resource_entry *res,
  1111. struct ipr_config_table_entry_wrapper *cfgtew)
  1112. {
  1113. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1114. unsigned int proto;
  1115. int new_path = 0;
  1116. if (res->ioa_cfg->sis64) {
  1117. res->flags = cfgtew->u.cfgte64->flags;
  1118. res->res_flags = cfgtew->u.cfgte64->res_flags;
  1119. res->type = cfgtew->u.cfgte64->res_type;
  1120. memcpy(&res->std_inq_data, &cfgtew->u.cfgte64->std_inq_data,
  1121. sizeof(struct ipr_std_inq_data));
  1122. res->qmodel = IPR_QUEUEING_MODEL64(res);
  1123. proto = cfgtew->u.cfgte64->proto;
  1124. res->res_handle = cfgtew->u.cfgte64->res_handle;
  1125. res->dev_id = cfgtew->u.cfgte64->dev_id;
  1126. memcpy(&res->dev_lun.scsi_lun, &cfgtew->u.cfgte64->lun,
  1127. sizeof(res->dev_lun.scsi_lun));
  1128. if (memcmp(res->res_path, &cfgtew->u.cfgte64->res_path,
  1129. sizeof(res->res_path))) {
  1130. memcpy(res->res_path, &cfgtew->u.cfgte64->res_path,
  1131. sizeof(res->res_path));
  1132. new_path = 1;
  1133. }
  1134. if (res->sdev && new_path)
  1135. sdev_printk(KERN_INFO, res->sdev, "Resource path: %s\n",
  1136. ipr_format_res_path(res->res_path, buffer,
  1137. sizeof(buffer)));
  1138. } else {
  1139. res->flags = cfgtew->u.cfgte->flags;
  1140. if (res->flags & IPR_IS_IOA_RESOURCE)
  1141. res->type = IPR_RES_TYPE_IOAFP;
  1142. else
  1143. res->type = cfgtew->u.cfgte->rsvd_subtype & 0x0f;
  1144. memcpy(&res->std_inq_data, &cfgtew->u.cfgte->std_inq_data,
  1145. sizeof(struct ipr_std_inq_data));
  1146. res->qmodel = IPR_QUEUEING_MODEL(res);
  1147. proto = cfgtew->u.cfgte->proto;
  1148. res->res_handle = cfgtew->u.cfgte->res_handle;
  1149. }
  1150. ipr_update_ata_class(res, proto);
  1151. }
  1152. /**
  1153. * ipr_clear_res_target - Clear the bit in the bit map representing the target
  1154. * for the resource.
  1155. * @res: resource entry struct
  1156. * @cfgtew: config table entry wrapper struct
  1157. *
  1158. * Return value:
  1159. * none
  1160. **/
  1161. static void ipr_clear_res_target(struct ipr_resource_entry *res)
  1162. {
  1163. struct ipr_resource_entry *gscsi_res = NULL;
  1164. struct ipr_ioa_cfg *ioa_cfg = res->ioa_cfg;
  1165. if (!ioa_cfg->sis64)
  1166. return;
  1167. if (res->bus == IPR_ARRAY_VIRTUAL_BUS)
  1168. clear_bit(res->target, ioa_cfg->array_ids);
  1169. else if (res->bus == IPR_VSET_VIRTUAL_BUS)
  1170. clear_bit(res->target, ioa_cfg->vset_ids);
  1171. else if (res->bus == 0 && res->type == IPR_RES_TYPE_GENERIC_SCSI) {
  1172. list_for_each_entry(gscsi_res, &ioa_cfg->used_res_q, queue)
  1173. if (gscsi_res->dev_id == res->dev_id && gscsi_res != res)
  1174. return;
  1175. clear_bit(res->target, ioa_cfg->target_ids);
  1176. } else if (res->bus == 0)
  1177. clear_bit(res->target, ioa_cfg->target_ids);
  1178. }
  1179. /**
  1180. * ipr_handle_config_change - Handle a config change from the adapter
  1181. * @ioa_cfg: ioa config struct
  1182. * @hostrcb: hostrcb
  1183. *
  1184. * Return value:
  1185. * none
  1186. **/
  1187. static void ipr_handle_config_change(struct ipr_ioa_cfg *ioa_cfg,
  1188. struct ipr_hostrcb *hostrcb)
  1189. {
  1190. struct ipr_resource_entry *res = NULL;
  1191. struct ipr_config_table_entry_wrapper cfgtew;
  1192. __be32 cc_res_handle;
  1193. u32 is_ndn = 1;
  1194. if (ioa_cfg->sis64) {
  1195. cfgtew.u.cfgte64 = &hostrcb->hcam.u.ccn.u.cfgte64;
  1196. cc_res_handle = cfgtew.u.cfgte64->res_handle;
  1197. } else {
  1198. cfgtew.u.cfgte = &hostrcb->hcam.u.ccn.u.cfgte;
  1199. cc_res_handle = cfgtew.u.cfgte->res_handle;
  1200. }
  1201. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  1202. if (res->res_handle == cc_res_handle) {
  1203. is_ndn = 0;
  1204. break;
  1205. }
  1206. }
  1207. if (is_ndn) {
  1208. if (list_empty(&ioa_cfg->free_res_q)) {
  1209. ipr_send_hcam(ioa_cfg,
  1210. IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE,
  1211. hostrcb);
  1212. return;
  1213. }
  1214. res = list_entry(ioa_cfg->free_res_q.next,
  1215. struct ipr_resource_entry, queue);
  1216. list_del(&res->queue);
  1217. ipr_init_res_entry(res, &cfgtew);
  1218. list_add_tail(&res->queue, &ioa_cfg->used_res_q);
  1219. }
  1220. ipr_update_res_entry(res, &cfgtew);
  1221. if (hostrcb->hcam.notify_type == IPR_HOST_RCB_NOTIF_TYPE_REM_ENTRY) {
  1222. if (res->sdev) {
  1223. res->del_from_ml = 1;
  1224. res->res_handle = IPR_INVALID_RES_HANDLE;
  1225. if (ioa_cfg->allow_ml_add_del)
  1226. schedule_work(&ioa_cfg->work_q);
  1227. } else {
  1228. ipr_clear_res_target(res);
  1229. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  1230. }
  1231. } else if (!res->sdev || res->del_from_ml) {
  1232. res->add_to_ml = 1;
  1233. if (ioa_cfg->allow_ml_add_del)
  1234. schedule_work(&ioa_cfg->work_q);
  1235. }
  1236. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  1237. }
  1238. /**
  1239. * ipr_process_ccn - Op done function for a CCN.
  1240. * @ipr_cmd: ipr command struct
  1241. *
  1242. * This function is the op done function for a configuration
  1243. * change notification host controlled async from the adapter.
  1244. *
  1245. * Return value:
  1246. * none
  1247. **/
  1248. static void ipr_process_ccn(struct ipr_cmnd *ipr_cmd)
  1249. {
  1250. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  1251. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  1252. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  1253. list_del(&hostrcb->queue);
  1254. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  1255. if (ioasc) {
  1256. if (ioasc != IPR_IOASC_IOA_WAS_RESET)
  1257. dev_err(&ioa_cfg->pdev->dev,
  1258. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  1259. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  1260. } else {
  1261. ipr_handle_config_change(ioa_cfg, hostrcb);
  1262. }
  1263. }
  1264. /**
  1265. * strip_and_pad_whitespace - Strip and pad trailing whitespace.
  1266. * @i: index into buffer
  1267. * @buf: string to modify
  1268. *
  1269. * This function will strip all trailing whitespace, pad the end
  1270. * of the string with a single space, and NULL terminate the string.
  1271. *
  1272. * Return value:
  1273. * new length of string
  1274. **/
  1275. static int strip_and_pad_whitespace(int i, char *buf)
  1276. {
  1277. while (i && buf[i] == ' ')
  1278. i--;
  1279. buf[i+1] = ' ';
  1280. buf[i+2] = '\0';
  1281. return i + 2;
  1282. }
  1283. /**
  1284. * ipr_log_vpd_compact - Log the passed extended VPD compactly.
  1285. * @prefix: string to print at start of printk
  1286. * @hostrcb: hostrcb pointer
  1287. * @vpd: vendor/product id/sn struct
  1288. *
  1289. * Return value:
  1290. * none
  1291. **/
  1292. static void ipr_log_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  1293. struct ipr_vpd *vpd)
  1294. {
  1295. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN + IPR_SERIAL_NUM_LEN + 3];
  1296. int i = 0;
  1297. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  1298. i = strip_and_pad_whitespace(IPR_VENDOR_ID_LEN - 1, buffer);
  1299. memcpy(&buffer[i], vpd->vpids.product_id, IPR_PROD_ID_LEN);
  1300. i = strip_and_pad_whitespace(i + IPR_PROD_ID_LEN - 1, buffer);
  1301. memcpy(&buffer[i], vpd->sn, IPR_SERIAL_NUM_LEN);
  1302. buffer[IPR_SERIAL_NUM_LEN + i] = '\0';
  1303. ipr_hcam_err(hostrcb, "%s VPID/SN: %s\n", prefix, buffer);
  1304. }
  1305. /**
  1306. * ipr_log_vpd - Log the passed VPD to the error log.
  1307. * @vpd: vendor/product id/sn struct
  1308. *
  1309. * Return value:
  1310. * none
  1311. **/
  1312. static void ipr_log_vpd(struct ipr_vpd *vpd)
  1313. {
  1314. char buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN
  1315. + IPR_SERIAL_NUM_LEN];
  1316. memcpy(buffer, vpd->vpids.vendor_id, IPR_VENDOR_ID_LEN);
  1317. memcpy(buffer + IPR_VENDOR_ID_LEN, vpd->vpids.product_id,
  1318. IPR_PROD_ID_LEN);
  1319. buffer[IPR_VENDOR_ID_LEN + IPR_PROD_ID_LEN] = '\0';
  1320. ipr_err("Vendor/Product ID: %s\n", buffer);
  1321. memcpy(buffer, vpd->sn, IPR_SERIAL_NUM_LEN);
  1322. buffer[IPR_SERIAL_NUM_LEN] = '\0';
  1323. ipr_err(" Serial Number: %s\n", buffer);
  1324. }
  1325. /**
  1326. * ipr_log_ext_vpd_compact - Log the passed extended VPD compactly.
  1327. * @prefix: string to print at start of printk
  1328. * @hostrcb: hostrcb pointer
  1329. * @vpd: vendor/product id/sn/wwn struct
  1330. *
  1331. * Return value:
  1332. * none
  1333. **/
  1334. static void ipr_log_ext_vpd_compact(char *prefix, struct ipr_hostrcb *hostrcb,
  1335. struct ipr_ext_vpd *vpd)
  1336. {
  1337. ipr_log_vpd_compact(prefix, hostrcb, &vpd->vpd);
  1338. ipr_hcam_err(hostrcb, "%s WWN: %08X%08X\n", prefix,
  1339. be32_to_cpu(vpd->wwid[0]), be32_to_cpu(vpd->wwid[1]));
  1340. }
  1341. /**
  1342. * ipr_log_ext_vpd - Log the passed extended VPD to the error log.
  1343. * @vpd: vendor/product id/sn/wwn struct
  1344. *
  1345. * Return value:
  1346. * none
  1347. **/
  1348. static void ipr_log_ext_vpd(struct ipr_ext_vpd *vpd)
  1349. {
  1350. ipr_log_vpd(&vpd->vpd);
  1351. ipr_err(" WWN: %08X%08X\n", be32_to_cpu(vpd->wwid[0]),
  1352. be32_to_cpu(vpd->wwid[1]));
  1353. }
  1354. /**
  1355. * ipr_log_enhanced_cache_error - Log a cache error.
  1356. * @ioa_cfg: ioa config struct
  1357. * @hostrcb: hostrcb struct
  1358. *
  1359. * Return value:
  1360. * none
  1361. **/
  1362. static void ipr_log_enhanced_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  1363. struct ipr_hostrcb *hostrcb)
  1364. {
  1365. struct ipr_hostrcb_type_12_error *error;
  1366. if (ioa_cfg->sis64)
  1367. error = &hostrcb->hcam.u.error64.u.type_12_error;
  1368. else
  1369. error = &hostrcb->hcam.u.error.u.type_12_error;
  1370. ipr_err("-----Current Configuration-----\n");
  1371. ipr_err("Cache Directory Card Information:\n");
  1372. ipr_log_ext_vpd(&error->ioa_vpd);
  1373. ipr_err("Adapter Card Information:\n");
  1374. ipr_log_ext_vpd(&error->cfc_vpd);
  1375. ipr_err("-----Expected Configuration-----\n");
  1376. ipr_err("Cache Directory Card Information:\n");
  1377. ipr_log_ext_vpd(&error->ioa_last_attached_to_cfc_vpd);
  1378. ipr_err("Adapter Card Information:\n");
  1379. ipr_log_ext_vpd(&error->cfc_last_attached_to_ioa_vpd);
  1380. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1381. be32_to_cpu(error->ioa_data[0]),
  1382. be32_to_cpu(error->ioa_data[1]),
  1383. be32_to_cpu(error->ioa_data[2]));
  1384. }
  1385. /**
  1386. * ipr_log_cache_error - Log a cache error.
  1387. * @ioa_cfg: ioa config struct
  1388. * @hostrcb: hostrcb struct
  1389. *
  1390. * Return value:
  1391. * none
  1392. **/
  1393. static void ipr_log_cache_error(struct ipr_ioa_cfg *ioa_cfg,
  1394. struct ipr_hostrcb *hostrcb)
  1395. {
  1396. struct ipr_hostrcb_type_02_error *error =
  1397. &hostrcb->hcam.u.error.u.type_02_error;
  1398. ipr_err("-----Current Configuration-----\n");
  1399. ipr_err("Cache Directory Card Information:\n");
  1400. ipr_log_vpd(&error->ioa_vpd);
  1401. ipr_err("Adapter Card Information:\n");
  1402. ipr_log_vpd(&error->cfc_vpd);
  1403. ipr_err("-----Expected Configuration-----\n");
  1404. ipr_err("Cache Directory Card Information:\n");
  1405. ipr_log_vpd(&error->ioa_last_attached_to_cfc_vpd);
  1406. ipr_err("Adapter Card Information:\n");
  1407. ipr_log_vpd(&error->cfc_last_attached_to_ioa_vpd);
  1408. ipr_err("Additional IOA Data: %08X %08X %08X\n",
  1409. be32_to_cpu(error->ioa_data[0]),
  1410. be32_to_cpu(error->ioa_data[1]),
  1411. be32_to_cpu(error->ioa_data[2]));
  1412. }
  1413. /**
  1414. * ipr_log_enhanced_config_error - Log a configuration error.
  1415. * @ioa_cfg: ioa config struct
  1416. * @hostrcb: hostrcb struct
  1417. *
  1418. * Return value:
  1419. * none
  1420. **/
  1421. static void ipr_log_enhanced_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1422. struct ipr_hostrcb *hostrcb)
  1423. {
  1424. int errors_logged, i;
  1425. struct ipr_hostrcb_device_data_entry_enhanced *dev_entry;
  1426. struct ipr_hostrcb_type_13_error *error;
  1427. error = &hostrcb->hcam.u.error.u.type_13_error;
  1428. errors_logged = be32_to_cpu(error->errors_logged);
  1429. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1430. be32_to_cpu(error->errors_detected), errors_logged);
  1431. dev_entry = error->dev;
  1432. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1433. ipr_err_separator;
  1434. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1435. ipr_log_ext_vpd(&dev_entry->vpd);
  1436. ipr_err("-----New Device Information-----\n");
  1437. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1438. ipr_err("Cache Directory Card Information:\n");
  1439. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1440. ipr_err("Adapter Card Information:\n");
  1441. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1442. }
  1443. }
  1444. /**
  1445. * ipr_log_sis64_config_error - Log a device error.
  1446. * @ioa_cfg: ioa config struct
  1447. * @hostrcb: hostrcb struct
  1448. *
  1449. * Return value:
  1450. * none
  1451. **/
  1452. static void ipr_log_sis64_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1453. struct ipr_hostrcb *hostrcb)
  1454. {
  1455. int errors_logged, i;
  1456. struct ipr_hostrcb64_device_data_entry_enhanced *dev_entry;
  1457. struct ipr_hostrcb_type_23_error *error;
  1458. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1459. error = &hostrcb->hcam.u.error64.u.type_23_error;
  1460. errors_logged = be32_to_cpu(error->errors_logged);
  1461. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1462. be32_to_cpu(error->errors_detected), errors_logged);
  1463. dev_entry = error->dev;
  1464. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1465. ipr_err_separator;
  1466. ipr_err("Device %d : %s", i + 1,
  1467. ipr_format_res_path(dev_entry->res_path, buffer,
  1468. sizeof(buffer)));
  1469. ipr_log_ext_vpd(&dev_entry->vpd);
  1470. ipr_err("-----New Device Information-----\n");
  1471. ipr_log_ext_vpd(&dev_entry->new_vpd);
  1472. ipr_err("Cache Directory Card Information:\n");
  1473. ipr_log_ext_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1474. ipr_err("Adapter Card Information:\n");
  1475. ipr_log_ext_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1476. }
  1477. }
  1478. /**
  1479. * ipr_log_config_error - Log a configuration error.
  1480. * @ioa_cfg: ioa config struct
  1481. * @hostrcb: hostrcb struct
  1482. *
  1483. * Return value:
  1484. * none
  1485. **/
  1486. static void ipr_log_config_error(struct ipr_ioa_cfg *ioa_cfg,
  1487. struct ipr_hostrcb *hostrcb)
  1488. {
  1489. int errors_logged, i;
  1490. struct ipr_hostrcb_device_data_entry *dev_entry;
  1491. struct ipr_hostrcb_type_03_error *error;
  1492. error = &hostrcb->hcam.u.error.u.type_03_error;
  1493. errors_logged = be32_to_cpu(error->errors_logged);
  1494. ipr_err("Device Errors Detected/Logged: %d/%d\n",
  1495. be32_to_cpu(error->errors_detected), errors_logged);
  1496. dev_entry = error->dev;
  1497. for (i = 0; i < errors_logged; i++, dev_entry++) {
  1498. ipr_err_separator;
  1499. ipr_phys_res_err(ioa_cfg, dev_entry->dev_res_addr, "Device %d", i + 1);
  1500. ipr_log_vpd(&dev_entry->vpd);
  1501. ipr_err("-----New Device Information-----\n");
  1502. ipr_log_vpd(&dev_entry->new_vpd);
  1503. ipr_err("Cache Directory Card Information:\n");
  1504. ipr_log_vpd(&dev_entry->ioa_last_with_dev_vpd);
  1505. ipr_err("Adapter Card Information:\n");
  1506. ipr_log_vpd(&dev_entry->cfc_last_with_dev_vpd);
  1507. ipr_err("Additional IOA Data: %08X %08X %08X %08X %08X\n",
  1508. be32_to_cpu(dev_entry->ioa_data[0]),
  1509. be32_to_cpu(dev_entry->ioa_data[1]),
  1510. be32_to_cpu(dev_entry->ioa_data[2]),
  1511. be32_to_cpu(dev_entry->ioa_data[3]),
  1512. be32_to_cpu(dev_entry->ioa_data[4]));
  1513. }
  1514. }
  1515. /**
  1516. * ipr_log_enhanced_array_error - Log an array configuration error.
  1517. * @ioa_cfg: ioa config struct
  1518. * @hostrcb: hostrcb struct
  1519. *
  1520. * Return value:
  1521. * none
  1522. **/
  1523. static void ipr_log_enhanced_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1524. struct ipr_hostrcb *hostrcb)
  1525. {
  1526. int i, num_entries;
  1527. struct ipr_hostrcb_type_14_error *error;
  1528. struct ipr_hostrcb_array_data_entry_enhanced *array_entry;
  1529. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1530. error = &hostrcb->hcam.u.error.u.type_14_error;
  1531. ipr_err_separator;
  1532. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1533. error->protection_level,
  1534. ioa_cfg->host->host_no,
  1535. error->last_func_vset_res_addr.bus,
  1536. error->last_func_vset_res_addr.target,
  1537. error->last_func_vset_res_addr.lun);
  1538. ipr_err_separator;
  1539. array_entry = error->array_member;
  1540. num_entries = min_t(u32, be32_to_cpu(error->num_entries),
  1541. ARRAY_SIZE(error->array_member));
  1542. for (i = 0; i < num_entries; i++, array_entry++) {
  1543. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1544. continue;
  1545. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1546. ipr_err("Exposed Array Member %d:\n", i);
  1547. else
  1548. ipr_err("Array Member %d:\n", i);
  1549. ipr_log_ext_vpd(&array_entry->vpd);
  1550. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1551. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1552. "Expected Location");
  1553. ipr_err_separator;
  1554. }
  1555. }
  1556. /**
  1557. * ipr_log_array_error - Log an array configuration error.
  1558. * @ioa_cfg: ioa config struct
  1559. * @hostrcb: hostrcb struct
  1560. *
  1561. * Return value:
  1562. * none
  1563. **/
  1564. static void ipr_log_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1565. struct ipr_hostrcb *hostrcb)
  1566. {
  1567. int i;
  1568. struct ipr_hostrcb_type_04_error *error;
  1569. struct ipr_hostrcb_array_data_entry *array_entry;
  1570. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1571. error = &hostrcb->hcam.u.error.u.type_04_error;
  1572. ipr_err_separator;
  1573. ipr_err("RAID %s Array Configuration: %d:%d:%d:%d\n",
  1574. error->protection_level,
  1575. ioa_cfg->host->host_no,
  1576. error->last_func_vset_res_addr.bus,
  1577. error->last_func_vset_res_addr.target,
  1578. error->last_func_vset_res_addr.lun);
  1579. ipr_err_separator;
  1580. array_entry = error->array_member;
  1581. for (i = 0; i < 18; i++) {
  1582. if (!memcmp(array_entry->vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1583. continue;
  1584. if (be32_to_cpu(error->exposed_mode_adn) == i)
  1585. ipr_err("Exposed Array Member %d:\n", i);
  1586. else
  1587. ipr_err("Array Member %d:\n", i);
  1588. ipr_log_vpd(&array_entry->vpd);
  1589. ipr_phys_res_err(ioa_cfg, array_entry->dev_res_addr, "Current Location");
  1590. ipr_phys_res_err(ioa_cfg, array_entry->expected_dev_res_addr,
  1591. "Expected Location");
  1592. ipr_err_separator;
  1593. if (i == 9)
  1594. array_entry = error->array_member2;
  1595. else
  1596. array_entry++;
  1597. }
  1598. }
  1599. /**
  1600. * ipr_log_hex_data - Log additional hex IOA error data.
  1601. * @ioa_cfg: ioa config struct
  1602. * @data: IOA error data
  1603. * @len: data length
  1604. *
  1605. * Return value:
  1606. * none
  1607. **/
  1608. static void ipr_log_hex_data(struct ipr_ioa_cfg *ioa_cfg, u32 *data, int len)
  1609. {
  1610. int i;
  1611. if (len == 0)
  1612. return;
  1613. if (ioa_cfg->log_level <= IPR_DEFAULT_LOG_LEVEL)
  1614. len = min_t(int, len, IPR_DEFAULT_MAX_ERROR_DUMP);
  1615. for (i = 0; i < len / 4; i += 4) {
  1616. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  1617. be32_to_cpu(data[i]),
  1618. be32_to_cpu(data[i+1]),
  1619. be32_to_cpu(data[i+2]),
  1620. be32_to_cpu(data[i+3]));
  1621. }
  1622. }
  1623. /**
  1624. * ipr_log_enhanced_dual_ioa_error - Log an enhanced dual adapter error.
  1625. * @ioa_cfg: ioa config struct
  1626. * @hostrcb: hostrcb struct
  1627. *
  1628. * Return value:
  1629. * none
  1630. **/
  1631. static void ipr_log_enhanced_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1632. struct ipr_hostrcb *hostrcb)
  1633. {
  1634. struct ipr_hostrcb_type_17_error *error;
  1635. if (ioa_cfg->sis64)
  1636. error = &hostrcb->hcam.u.error64.u.type_17_error;
  1637. else
  1638. error = &hostrcb->hcam.u.error.u.type_17_error;
  1639. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1640. strim(error->failure_reason);
  1641. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1642. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1643. ipr_log_ext_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1644. ipr_log_hex_data(ioa_cfg, error->data,
  1645. be32_to_cpu(hostrcb->hcam.length) -
  1646. (offsetof(struct ipr_hostrcb_error, u) +
  1647. offsetof(struct ipr_hostrcb_type_17_error, data)));
  1648. }
  1649. /**
  1650. * ipr_log_dual_ioa_error - Log a dual adapter error.
  1651. * @ioa_cfg: ioa config struct
  1652. * @hostrcb: hostrcb struct
  1653. *
  1654. * Return value:
  1655. * none
  1656. **/
  1657. static void ipr_log_dual_ioa_error(struct ipr_ioa_cfg *ioa_cfg,
  1658. struct ipr_hostrcb *hostrcb)
  1659. {
  1660. struct ipr_hostrcb_type_07_error *error;
  1661. error = &hostrcb->hcam.u.error.u.type_07_error;
  1662. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1663. strim(error->failure_reason);
  1664. ipr_hcam_err(hostrcb, "%s [PRC: %08X]\n", error->failure_reason,
  1665. be32_to_cpu(hostrcb->hcam.u.error.prc));
  1666. ipr_log_vpd_compact("Remote IOA", hostrcb, &error->vpd);
  1667. ipr_log_hex_data(ioa_cfg, error->data,
  1668. be32_to_cpu(hostrcb->hcam.length) -
  1669. (offsetof(struct ipr_hostrcb_error, u) +
  1670. offsetof(struct ipr_hostrcb_type_07_error, data)));
  1671. }
  1672. static const struct {
  1673. u8 active;
  1674. char *desc;
  1675. } path_active_desc[] = {
  1676. { IPR_PATH_NO_INFO, "Path" },
  1677. { IPR_PATH_ACTIVE, "Active path" },
  1678. { IPR_PATH_NOT_ACTIVE, "Inactive path" }
  1679. };
  1680. static const struct {
  1681. u8 state;
  1682. char *desc;
  1683. } path_state_desc[] = {
  1684. { IPR_PATH_STATE_NO_INFO, "has no path state information available" },
  1685. { IPR_PATH_HEALTHY, "is healthy" },
  1686. { IPR_PATH_DEGRADED, "is degraded" },
  1687. { IPR_PATH_FAILED, "is failed" }
  1688. };
  1689. /**
  1690. * ipr_log_fabric_path - Log a fabric path error
  1691. * @hostrcb: hostrcb struct
  1692. * @fabric: fabric descriptor
  1693. *
  1694. * Return value:
  1695. * none
  1696. **/
  1697. static void ipr_log_fabric_path(struct ipr_hostrcb *hostrcb,
  1698. struct ipr_hostrcb_fabric_desc *fabric)
  1699. {
  1700. int i, j;
  1701. u8 path_state = fabric->path_state;
  1702. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1703. u8 state = path_state & IPR_PATH_STATE_MASK;
  1704. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1705. if (path_active_desc[i].active != active)
  1706. continue;
  1707. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1708. if (path_state_desc[j].state != state)
  1709. continue;
  1710. if (fabric->cascaded_expander == 0xff && fabric->phy == 0xff) {
  1711. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d\n",
  1712. path_active_desc[i].desc, path_state_desc[j].desc,
  1713. fabric->ioa_port);
  1714. } else if (fabric->cascaded_expander == 0xff) {
  1715. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Phy=%d\n",
  1716. path_active_desc[i].desc, path_state_desc[j].desc,
  1717. fabric->ioa_port, fabric->phy);
  1718. } else if (fabric->phy == 0xff) {
  1719. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d\n",
  1720. path_active_desc[i].desc, path_state_desc[j].desc,
  1721. fabric->ioa_port, fabric->cascaded_expander);
  1722. } else {
  1723. ipr_hcam_err(hostrcb, "%s %s: IOA Port=%d, Cascade=%d, Phy=%d\n",
  1724. path_active_desc[i].desc, path_state_desc[j].desc,
  1725. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1726. }
  1727. return;
  1728. }
  1729. }
  1730. ipr_err("Path state=%02X IOA Port=%d Cascade=%d Phy=%d\n", path_state,
  1731. fabric->ioa_port, fabric->cascaded_expander, fabric->phy);
  1732. }
  1733. /**
  1734. * ipr_log64_fabric_path - Log a fabric path error
  1735. * @hostrcb: hostrcb struct
  1736. * @fabric: fabric descriptor
  1737. *
  1738. * Return value:
  1739. * none
  1740. **/
  1741. static void ipr_log64_fabric_path(struct ipr_hostrcb *hostrcb,
  1742. struct ipr_hostrcb64_fabric_desc *fabric)
  1743. {
  1744. int i, j;
  1745. u8 path_state = fabric->path_state;
  1746. u8 active = path_state & IPR_PATH_ACTIVE_MASK;
  1747. u8 state = path_state & IPR_PATH_STATE_MASK;
  1748. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1749. for (i = 0; i < ARRAY_SIZE(path_active_desc); i++) {
  1750. if (path_active_desc[i].active != active)
  1751. continue;
  1752. for (j = 0; j < ARRAY_SIZE(path_state_desc); j++) {
  1753. if (path_state_desc[j].state != state)
  1754. continue;
  1755. ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s\n",
  1756. path_active_desc[i].desc, path_state_desc[j].desc,
  1757. ipr_format_res_path(fabric->res_path, buffer,
  1758. sizeof(buffer)));
  1759. return;
  1760. }
  1761. }
  1762. ipr_err("Path state=%02X Resource Path=%s\n", path_state,
  1763. ipr_format_res_path(fabric->res_path, buffer, sizeof(buffer)));
  1764. }
  1765. static const struct {
  1766. u8 type;
  1767. char *desc;
  1768. } path_type_desc[] = {
  1769. { IPR_PATH_CFG_IOA_PORT, "IOA port" },
  1770. { IPR_PATH_CFG_EXP_PORT, "Expander port" },
  1771. { IPR_PATH_CFG_DEVICE_PORT, "Device port" },
  1772. { IPR_PATH_CFG_DEVICE_LUN, "Device LUN" }
  1773. };
  1774. static const struct {
  1775. u8 status;
  1776. char *desc;
  1777. } path_status_desc[] = {
  1778. { IPR_PATH_CFG_NO_PROB, "Functional" },
  1779. { IPR_PATH_CFG_DEGRADED, "Degraded" },
  1780. { IPR_PATH_CFG_FAILED, "Failed" },
  1781. { IPR_PATH_CFG_SUSPECT, "Suspect" },
  1782. { IPR_PATH_NOT_DETECTED, "Missing" },
  1783. { IPR_PATH_INCORRECT_CONN, "Incorrectly connected" }
  1784. };
  1785. static const char *link_rate[] = {
  1786. "unknown",
  1787. "disabled",
  1788. "phy reset problem",
  1789. "spinup hold",
  1790. "port selector",
  1791. "unknown",
  1792. "unknown",
  1793. "unknown",
  1794. "1.5Gbps",
  1795. "3.0Gbps",
  1796. "unknown",
  1797. "unknown",
  1798. "unknown",
  1799. "unknown",
  1800. "unknown",
  1801. "unknown"
  1802. };
  1803. /**
  1804. * ipr_log_path_elem - Log a fabric path element.
  1805. * @hostrcb: hostrcb struct
  1806. * @cfg: fabric path element struct
  1807. *
  1808. * Return value:
  1809. * none
  1810. **/
  1811. static void ipr_log_path_elem(struct ipr_hostrcb *hostrcb,
  1812. struct ipr_hostrcb_config_element *cfg)
  1813. {
  1814. int i, j;
  1815. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  1816. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  1817. if (type == IPR_PATH_CFG_NOT_EXIST)
  1818. return;
  1819. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  1820. if (path_type_desc[i].type != type)
  1821. continue;
  1822. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  1823. if (path_status_desc[j].status != status)
  1824. continue;
  1825. if (type == IPR_PATH_CFG_IOA_PORT) {
  1826. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, WWN=%08X%08X\n",
  1827. path_status_desc[j].desc, path_type_desc[i].desc,
  1828. cfg->phy, link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1829. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1830. } else {
  1831. if (cfg->cascaded_expander == 0xff && cfg->phy == 0xff) {
  1832. ipr_hcam_err(hostrcb, "%s %s: Link rate=%s, WWN=%08X%08X\n",
  1833. path_status_desc[j].desc, path_type_desc[i].desc,
  1834. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1835. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1836. } else if (cfg->cascaded_expander == 0xff) {
  1837. ipr_hcam_err(hostrcb, "%s %s: Phy=%d, Link rate=%s, "
  1838. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1839. path_type_desc[i].desc, cfg->phy,
  1840. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1841. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1842. } else if (cfg->phy == 0xff) {
  1843. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Link rate=%s, "
  1844. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1845. path_type_desc[i].desc, cfg->cascaded_expander,
  1846. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1847. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1848. } else {
  1849. ipr_hcam_err(hostrcb, "%s %s: Cascade=%d, Phy=%d, Link rate=%s "
  1850. "WWN=%08X%08X\n", path_status_desc[j].desc,
  1851. path_type_desc[i].desc, cfg->cascaded_expander, cfg->phy,
  1852. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1853. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1854. }
  1855. }
  1856. return;
  1857. }
  1858. }
  1859. ipr_hcam_err(hostrcb, "Path element=%02X: Cascade=%d Phy=%d Link rate=%s "
  1860. "WWN=%08X%08X\n", cfg->type_status, cfg->cascaded_expander, cfg->phy,
  1861. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1862. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1863. }
  1864. /**
  1865. * ipr_log64_path_elem - Log a fabric path element.
  1866. * @hostrcb: hostrcb struct
  1867. * @cfg: fabric path element struct
  1868. *
  1869. * Return value:
  1870. * none
  1871. **/
  1872. static void ipr_log64_path_elem(struct ipr_hostrcb *hostrcb,
  1873. struct ipr_hostrcb64_config_element *cfg)
  1874. {
  1875. int i, j;
  1876. u8 desc_id = cfg->descriptor_id & IPR_DESCRIPTOR_MASK;
  1877. u8 type = cfg->type_status & IPR_PATH_CFG_TYPE_MASK;
  1878. u8 status = cfg->type_status & IPR_PATH_CFG_STATUS_MASK;
  1879. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1880. if (type == IPR_PATH_CFG_NOT_EXIST || desc_id != IPR_DESCRIPTOR_SIS64)
  1881. return;
  1882. for (i = 0; i < ARRAY_SIZE(path_type_desc); i++) {
  1883. if (path_type_desc[i].type != type)
  1884. continue;
  1885. for (j = 0; j < ARRAY_SIZE(path_status_desc); j++) {
  1886. if (path_status_desc[j].status != status)
  1887. continue;
  1888. ipr_hcam_err(hostrcb, "%s %s: Resource Path=%s, Link rate=%s, WWN=%08X%08X\n",
  1889. path_status_desc[j].desc, path_type_desc[i].desc,
  1890. ipr_format_res_path(cfg->res_path, buffer,
  1891. sizeof(buffer)),
  1892. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1893. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1894. return;
  1895. }
  1896. }
  1897. ipr_hcam_err(hostrcb, "Path element=%02X: Resource Path=%s, Link rate=%s "
  1898. "WWN=%08X%08X\n", cfg->type_status,
  1899. ipr_format_res_path(cfg->res_path, buffer, sizeof(buffer)),
  1900. link_rate[cfg->link_rate & IPR_PHY_LINK_RATE_MASK],
  1901. be32_to_cpu(cfg->wwid[0]), be32_to_cpu(cfg->wwid[1]));
  1902. }
  1903. /**
  1904. * ipr_log_fabric_error - Log a fabric error.
  1905. * @ioa_cfg: ioa config struct
  1906. * @hostrcb: hostrcb struct
  1907. *
  1908. * Return value:
  1909. * none
  1910. **/
  1911. static void ipr_log_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  1912. struct ipr_hostrcb *hostrcb)
  1913. {
  1914. struct ipr_hostrcb_type_20_error *error;
  1915. struct ipr_hostrcb_fabric_desc *fabric;
  1916. struct ipr_hostrcb_config_element *cfg;
  1917. int i, add_len;
  1918. error = &hostrcb->hcam.u.error.u.type_20_error;
  1919. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1920. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  1921. add_len = be32_to_cpu(hostrcb->hcam.length) -
  1922. (offsetof(struct ipr_hostrcb_error, u) +
  1923. offsetof(struct ipr_hostrcb_type_20_error, desc));
  1924. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  1925. ipr_log_fabric_path(hostrcb, fabric);
  1926. for_each_fabric_cfg(fabric, cfg)
  1927. ipr_log_path_elem(hostrcb, cfg);
  1928. add_len -= be16_to_cpu(fabric->length);
  1929. fabric = (struct ipr_hostrcb_fabric_desc *)
  1930. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  1931. }
  1932. ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
  1933. }
  1934. /**
  1935. * ipr_log_sis64_array_error - Log a sis64 array error.
  1936. * @ioa_cfg: ioa config struct
  1937. * @hostrcb: hostrcb struct
  1938. *
  1939. * Return value:
  1940. * none
  1941. **/
  1942. static void ipr_log_sis64_array_error(struct ipr_ioa_cfg *ioa_cfg,
  1943. struct ipr_hostrcb *hostrcb)
  1944. {
  1945. int i, num_entries;
  1946. struct ipr_hostrcb_type_24_error *error;
  1947. struct ipr_hostrcb64_array_data_entry *array_entry;
  1948. char buffer[IPR_MAX_RES_PATH_LENGTH];
  1949. const u8 zero_sn[IPR_SERIAL_NUM_LEN] = { [0 ... IPR_SERIAL_NUM_LEN-1] = '0' };
  1950. error = &hostrcb->hcam.u.error64.u.type_24_error;
  1951. ipr_err_separator;
  1952. ipr_err("RAID %s Array Configuration: %s\n",
  1953. error->protection_level,
  1954. ipr_format_res_path(error->last_res_path, buffer, sizeof(buffer)));
  1955. ipr_err_separator;
  1956. array_entry = error->array_member;
  1957. num_entries = min_t(u32, error->num_entries,
  1958. ARRAY_SIZE(error->array_member));
  1959. for (i = 0; i < num_entries; i++, array_entry++) {
  1960. if (!memcmp(array_entry->vpd.vpd.sn, zero_sn, IPR_SERIAL_NUM_LEN))
  1961. continue;
  1962. if (error->exposed_mode_adn == i)
  1963. ipr_err("Exposed Array Member %d:\n", i);
  1964. else
  1965. ipr_err("Array Member %d:\n", i);
  1966. ipr_err("Array Member %d:\n", i);
  1967. ipr_log_ext_vpd(&array_entry->vpd);
  1968. ipr_err("Current Location: %s\n",
  1969. ipr_format_res_path(array_entry->res_path, buffer,
  1970. sizeof(buffer)));
  1971. ipr_err("Expected Location: %s\n",
  1972. ipr_format_res_path(array_entry->expected_res_path,
  1973. buffer, sizeof(buffer)));
  1974. ipr_err_separator;
  1975. }
  1976. }
  1977. /**
  1978. * ipr_log_sis64_fabric_error - Log a sis64 fabric error.
  1979. * @ioa_cfg: ioa config struct
  1980. * @hostrcb: hostrcb struct
  1981. *
  1982. * Return value:
  1983. * none
  1984. **/
  1985. static void ipr_log_sis64_fabric_error(struct ipr_ioa_cfg *ioa_cfg,
  1986. struct ipr_hostrcb *hostrcb)
  1987. {
  1988. struct ipr_hostrcb_type_30_error *error;
  1989. struct ipr_hostrcb64_fabric_desc *fabric;
  1990. struct ipr_hostrcb64_config_element *cfg;
  1991. int i, add_len;
  1992. error = &hostrcb->hcam.u.error64.u.type_30_error;
  1993. error->failure_reason[sizeof(error->failure_reason) - 1] = '\0';
  1994. ipr_hcam_err(hostrcb, "%s\n", error->failure_reason);
  1995. add_len = be32_to_cpu(hostrcb->hcam.length) -
  1996. (offsetof(struct ipr_hostrcb64_error, u) +
  1997. offsetof(struct ipr_hostrcb_type_30_error, desc));
  1998. for (i = 0, fabric = error->desc; i < error->num_entries; i++) {
  1999. ipr_log64_fabric_path(hostrcb, fabric);
  2000. for_each_fabric_cfg(fabric, cfg)
  2001. ipr_log64_path_elem(hostrcb, cfg);
  2002. add_len -= be16_to_cpu(fabric->length);
  2003. fabric = (struct ipr_hostrcb64_fabric_desc *)
  2004. ((unsigned long)fabric + be16_to_cpu(fabric->length));
  2005. }
  2006. ipr_log_hex_data(ioa_cfg, (u32 *)fabric, add_len);
  2007. }
  2008. /**
  2009. * ipr_log_generic_error - Log an adapter error.
  2010. * @ioa_cfg: ioa config struct
  2011. * @hostrcb: hostrcb struct
  2012. *
  2013. * Return value:
  2014. * none
  2015. **/
  2016. static void ipr_log_generic_error(struct ipr_ioa_cfg *ioa_cfg,
  2017. struct ipr_hostrcb *hostrcb)
  2018. {
  2019. ipr_log_hex_data(ioa_cfg, hostrcb->hcam.u.raw.data,
  2020. be32_to_cpu(hostrcb->hcam.length));
  2021. }
  2022. /**
  2023. * ipr_get_error - Find the specfied IOASC in the ipr_error_table.
  2024. * @ioasc: IOASC
  2025. *
  2026. * This function will return the index of into the ipr_error_table
  2027. * for the specified IOASC. If the IOASC is not in the table,
  2028. * 0 will be returned, which points to the entry used for unknown errors.
  2029. *
  2030. * Return value:
  2031. * index into the ipr_error_table
  2032. **/
  2033. static u32 ipr_get_error(u32 ioasc)
  2034. {
  2035. int i;
  2036. for (i = 0; i < ARRAY_SIZE(ipr_error_table); i++)
  2037. if (ipr_error_table[i].ioasc == (ioasc & IPR_IOASC_IOASC_MASK))
  2038. return i;
  2039. return 0;
  2040. }
  2041. /**
  2042. * ipr_handle_log_data - Log an adapter error.
  2043. * @ioa_cfg: ioa config struct
  2044. * @hostrcb: hostrcb struct
  2045. *
  2046. * This function logs an adapter error to the system.
  2047. *
  2048. * Return value:
  2049. * none
  2050. **/
  2051. static void ipr_handle_log_data(struct ipr_ioa_cfg *ioa_cfg,
  2052. struct ipr_hostrcb *hostrcb)
  2053. {
  2054. u32 ioasc;
  2055. int error_index;
  2056. if (hostrcb->hcam.notify_type != IPR_HOST_RCB_NOTIF_TYPE_ERROR_LOG_ENTRY)
  2057. return;
  2058. if (hostrcb->hcam.notifications_lost == IPR_HOST_RCB_NOTIFICATIONS_LOST)
  2059. dev_err(&ioa_cfg->pdev->dev, "Error notifications lost\n");
  2060. if (ioa_cfg->sis64)
  2061. ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
  2062. else
  2063. ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  2064. if (!ioa_cfg->sis64 && (ioasc == IPR_IOASC_BUS_WAS_RESET ||
  2065. ioasc == IPR_IOASC_BUS_WAS_RESET_BY_OTHER)) {
  2066. /* Tell the midlayer we had a bus reset so it will handle the UA properly */
  2067. scsi_report_bus_reset(ioa_cfg->host,
  2068. hostrcb->hcam.u.error.fd_res_addr.bus);
  2069. }
  2070. error_index = ipr_get_error(ioasc);
  2071. if (!ipr_error_table[error_index].log_hcam)
  2072. return;
  2073. ipr_hcam_err(hostrcb, "%s\n", ipr_error_table[error_index].error);
  2074. /* Set indication we have logged an error */
  2075. ioa_cfg->errors_logged++;
  2076. if (ioa_cfg->log_level < ipr_error_table[error_index].log_hcam)
  2077. return;
  2078. if (be32_to_cpu(hostrcb->hcam.length) > sizeof(hostrcb->hcam.u.raw))
  2079. hostrcb->hcam.length = cpu_to_be32(sizeof(hostrcb->hcam.u.raw));
  2080. switch (hostrcb->hcam.overlay_id) {
  2081. case IPR_HOST_RCB_OVERLAY_ID_2:
  2082. ipr_log_cache_error(ioa_cfg, hostrcb);
  2083. break;
  2084. case IPR_HOST_RCB_OVERLAY_ID_3:
  2085. ipr_log_config_error(ioa_cfg, hostrcb);
  2086. break;
  2087. case IPR_HOST_RCB_OVERLAY_ID_4:
  2088. case IPR_HOST_RCB_OVERLAY_ID_6:
  2089. ipr_log_array_error(ioa_cfg, hostrcb);
  2090. break;
  2091. case IPR_HOST_RCB_OVERLAY_ID_7:
  2092. ipr_log_dual_ioa_error(ioa_cfg, hostrcb);
  2093. break;
  2094. case IPR_HOST_RCB_OVERLAY_ID_12:
  2095. ipr_log_enhanced_cache_error(ioa_cfg, hostrcb);
  2096. break;
  2097. case IPR_HOST_RCB_OVERLAY_ID_13:
  2098. ipr_log_enhanced_config_error(ioa_cfg, hostrcb);
  2099. break;
  2100. case IPR_HOST_RCB_OVERLAY_ID_14:
  2101. case IPR_HOST_RCB_OVERLAY_ID_16:
  2102. ipr_log_enhanced_array_error(ioa_cfg, hostrcb);
  2103. break;
  2104. case IPR_HOST_RCB_OVERLAY_ID_17:
  2105. ipr_log_enhanced_dual_ioa_error(ioa_cfg, hostrcb);
  2106. break;
  2107. case IPR_HOST_RCB_OVERLAY_ID_20:
  2108. ipr_log_fabric_error(ioa_cfg, hostrcb);
  2109. break;
  2110. case IPR_HOST_RCB_OVERLAY_ID_23:
  2111. ipr_log_sis64_config_error(ioa_cfg, hostrcb);
  2112. break;
  2113. case IPR_HOST_RCB_OVERLAY_ID_24:
  2114. case IPR_HOST_RCB_OVERLAY_ID_26:
  2115. ipr_log_sis64_array_error(ioa_cfg, hostrcb);
  2116. break;
  2117. case IPR_HOST_RCB_OVERLAY_ID_30:
  2118. ipr_log_sis64_fabric_error(ioa_cfg, hostrcb);
  2119. break;
  2120. case IPR_HOST_RCB_OVERLAY_ID_1:
  2121. case IPR_HOST_RCB_OVERLAY_ID_DEFAULT:
  2122. default:
  2123. ipr_log_generic_error(ioa_cfg, hostrcb);
  2124. break;
  2125. }
  2126. }
  2127. /**
  2128. * ipr_process_error - Op done function for an adapter error log.
  2129. * @ipr_cmd: ipr command struct
  2130. *
  2131. * This function is the op done function for an error log host
  2132. * controlled async from the adapter. It will log the error and
  2133. * send the HCAM back to the adapter.
  2134. *
  2135. * Return value:
  2136. * none
  2137. **/
  2138. static void ipr_process_error(struct ipr_cmnd *ipr_cmd)
  2139. {
  2140. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2141. struct ipr_hostrcb *hostrcb = ipr_cmd->u.hostrcb;
  2142. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  2143. u32 fd_ioasc;
  2144. if (ioa_cfg->sis64)
  2145. fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error64.fd_ioasc);
  2146. else
  2147. fd_ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  2148. list_del(&hostrcb->queue);
  2149. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  2150. if (!ioasc) {
  2151. ipr_handle_log_data(ioa_cfg, hostrcb);
  2152. if (fd_ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED)
  2153. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  2154. } else if (ioasc != IPR_IOASC_IOA_WAS_RESET) {
  2155. dev_err(&ioa_cfg->pdev->dev,
  2156. "Host RCB failed with IOASC: 0x%08X\n", ioasc);
  2157. }
  2158. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  2159. }
  2160. /**
  2161. * ipr_timeout - An internally generated op has timed out.
  2162. * @ipr_cmd: ipr command struct
  2163. *
  2164. * This function blocks host requests and initiates an
  2165. * adapter reset.
  2166. *
  2167. * Return value:
  2168. * none
  2169. **/
  2170. static void ipr_timeout(struct ipr_cmnd *ipr_cmd)
  2171. {
  2172. unsigned long lock_flags = 0;
  2173. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2174. ENTER;
  2175. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2176. ioa_cfg->errors_logged++;
  2177. dev_err(&ioa_cfg->pdev->dev,
  2178. "Adapter being reset due to command timeout.\n");
  2179. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2180. ioa_cfg->sdt_state = GET_DUMP;
  2181. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd)
  2182. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2183. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2184. LEAVE;
  2185. }
  2186. /**
  2187. * ipr_oper_timeout - Adapter timed out transitioning to operational
  2188. * @ipr_cmd: ipr command struct
  2189. *
  2190. * This function blocks host requests and initiates an
  2191. * adapter reset.
  2192. *
  2193. * Return value:
  2194. * none
  2195. **/
  2196. static void ipr_oper_timeout(struct ipr_cmnd *ipr_cmd)
  2197. {
  2198. unsigned long lock_flags = 0;
  2199. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  2200. ENTER;
  2201. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2202. ioa_cfg->errors_logged++;
  2203. dev_err(&ioa_cfg->pdev->dev,
  2204. "Adapter timed out transitioning to operational.\n");
  2205. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  2206. ioa_cfg->sdt_state = GET_DUMP;
  2207. if (!ioa_cfg->in_reset_reload || ioa_cfg->reset_cmd == ipr_cmd) {
  2208. if (ipr_fastfail)
  2209. ioa_cfg->reset_retries += IPR_NUM_RESET_RELOAD_RETRIES;
  2210. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2211. }
  2212. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2213. LEAVE;
  2214. }
  2215. /**
  2216. * ipr_reset_reload - Reset/Reload the IOA
  2217. * @ioa_cfg: ioa config struct
  2218. * @shutdown_type: shutdown type
  2219. *
  2220. * This function resets the adapter and re-initializes it.
  2221. * This function assumes that all new host commands have been stopped.
  2222. * Return value:
  2223. * SUCCESS / FAILED
  2224. **/
  2225. static int ipr_reset_reload(struct ipr_ioa_cfg *ioa_cfg,
  2226. enum ipr_shutdown_type shutdown_type)
  2227. {
  2228. if (!ioa_cfg->in_reset_reload)
  2229. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  2230. spin_unlock_irq(ioa_cfg->host->host_lock);
  2231. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2232. spin_lock_irq(ioa_cfg->host->host_lock);
  2233. /* If we got hit with a host reset while we were already resetting
  2234. the adapter for some reason, and the reset failed. */
  2235. if (ioa_cfg->ioa_is_dead) {
  2236. ipr_trace;
  2237. return FAILED;
  2238. }
  2239. return SUCCESS;
  2240. }
  2241. /**
  2242. * ipr_find_ses_entry - Find matching SES in SES table
  2243. * @res: resource entry struct of SES
  2244. *
  2245. * Return value:
  2246. * pointer to SES table entry / NULL on failure
  2247. **/
  2248. static const struct ipr_ses_table_entry *
  2249. ipr_find_ses_entry(struct ipr_resource_entry *res)
  2250. {
  2251. int i, j, matches;
  2252. struct ipr_std_inq_vpids *vpids;
  2253. const struct ipr_ses_table_entry *ste = ipr_ses_table;
  2254. for (i = 0; i < ARRAY_SIZE(ipr_ses_table); i++, ste++) {
  2255. for (j = 0, matches = 0; j < IPR_PROD_ID_LEN; j++) {
  2256. if (ste->compare_product_id_byte[j] == 'X') {
  2257. vpids = &res->std_inq_data.vpids;
  2258. if (vpids->product_id[j] == ste->product_id[j])
  2259. matches++;
  2260. else
  2261. break;
  2262. } else
  2263. matches++;
  2264. }
  2265. if (matches == IPR_PROD_ID_LEN)
  2266. return ste;
  2267. }
  2268. return NULL;
  2269. }
  2270. /**
  2271. * ipr_get_max_scsi_speed - Determine max SCSI speed for a given bus
  2272. * @ioa_cfg: ioa config struct
  2273. * @bus: SCSI bus
  2274. * @bus_width: bus width
  2275. *
  2276. * Return value:
  2277. * SCSI bus speed in units of 100KHz, 1600 is 160 MHz
  2278. * For a 2-byte wide SCSI bus, the maximum transfer speed is
  2279. * twice the maximum transfer rate (e.g. for a wide enabled bus,
  2280. * max 160MHz = max 320MB/sec).
  2281. **/
  2282. static u32 ipr_get_max_scsi_speed(struct ipr_ioa_cfg *ioa_cfg, u8 bus, u8 bus_width)
  2283. {
  2284. struct ipr_resource_entry *res;
  2285. const struct ipr_ses_table_entry *ste;
  2286. u32 max_xfer_rate = IPR_MAX_SCSI_RATE(bus_width);
  2287. /* Loop through each config table entry in the config table buffer */
  2288. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2289. if (!(IPR_IS_SES_DEVICE(res->std_inq_data)))
  2290. continue;
  2291. if (bus != res->bus)
  2292. continue;
  2293. if (!(ste = ipr_find_ses_entry(res)))
  2294. continue;
  2295. max_xfer_rate = (ste->max_bus_speed_limit * 10) / (bus_width / 8);
  2296. }
  2297. return max_xfer_rate;
  2298. }
  2299. /**
  2300. * ipr_wait_iodbg_ack - Wait for an IODEBUG ACK from the IOA
  2301. * @ioa_cfg: ioa config struct
  2302. * @max_delay: max delay in micro-seconds to wait
  2303. *
  2304. * Waits for an IODEBUG ACK from the IOA, doing busy looping.
  2305. *
  2306. * Return value:
  2307. * 0 on success / other on failure
  2308. **/
  2309. static int ipr_wait_iodbg_ack(struct ipr_ioa_cfg *ioa_cfg, int max_delay)
  2310. {
  2311. volatile u32 pcii_reg;
  2312. int delay = 1;
  2313. /* Read interrupt reg until IOA signals IO Debug Acknowledge */
  2314. while (delay < max_delay) {
  2315. pcii_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  2316. if (pcii_reg & IPR_PCII_IO_DEBUG_ACKNOWLEDGE)
  2317. return 0;
  2318. /* udelay cannot be used if delay is more than a few milliseconds */
  2319. if ((delay / 1000) > MAX_UDELAY_MS)
  2320. mdelay(delay / 1000);
  2321. else
  2322. udelay(delay);
  2323. delay += delay;
  2324. }
  2325. return -EIO;
  2326. }
  2327. /**
  2328. * ipr_get_sis64_dump_data_section - Dump IOA memory
  2329. * @ioa_cfg: ioa config struct
  2330. * @start_addr: adapter address to dump
  2331. * @dest: destination kernel buffer
  2332. * @length_in_words: length to dump in 4 byte words
  2333. *
  2334. * Return value:
  2335. * 0 on success
  2336. **/
  2337. static int ipr_get_sis64_dump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  2338. u32 start_addr,
  2339. __be32 *dest, u32 length_in_words)
  2340. {
  2341. int i;
  2342. for (i = 0; i < length_in_words; i++) {
  2343. writel(start_addr+(i*4), ioa_cfg->regs.dump_addr_reg);
  2344. *dest = cpu_to_be32(readl(ioa_cfg->regs.dump_data_reg));
  2345. dest++;
  2346. }
  2347. return 0;
  2348. }
  2349. /**
  2350. * ipr_get_ldump_data_section - Dump IOA memory
  2351. * @ioa_cfg: ioa config struct
  2352. * @start_addr: adapter address to dump
  2353. * @dest: destination kernel buffer
  2354. * @length_in_words: length to dump in 4 byte words
  2355. *
  2356. * Return value:
  2357. * 0 on success / -EIO on failure
  2358. **/
  2359. static int ipr_get_ldump_data_section(struct ipr_ioa_cfg *ioa_cfg,
  2360. u32 start_addr,
  2361. __be32 *dest, u32 length_in_words)
  2362. {
  2363. volatile u32 temp_pcii_reg;
  2364. int i, delay = 0;
  2365. if (ioa_cfg->sis64)
  2366. return ipr_get_sis64_dump_data_section(ioa_cfg, start_addr,
  2367. dest, length_in_words);
  2368. /* Write IOA interrupt reg starting LDUMP state */
  2369. writel((IPR_UPROCI_RESET_ALERT | IPR_UPROCI_IO_DEBUG_ALERT),
  2370. ioa_cfg->regs.set_uproc_interrupt_reg32);
  2371. /* Wait for IO debug acknowledge */
  2372. if (ipr_wait_iodbg_ack(ioa_cfg,
  2373. IPR_LDUMP_MAX_LONG_ACK_DELAY_IN_USEC)) {
  2374. dev_err(&ioa_cfg->pdev->dev,
  2375. "IOA dump long data transfer timeout\n");
  2376. return -EIO;
  2377. }
  2378. /* Signal LDUMP interlocked - clear IO debug ack */
  2379. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2380. ioa_cfg->regs.clr_interrupt_reg);
  2381. /* Write Mailbox with starting address */
  2382. writel(start_addr, ioa_cfg->ioa_mailbox);
  2383. /* Signal address valid - clear IOA Reset alert */
  2384. writel(IPR_UPROCI_RESET_ALERT,
  2385. ioa_cfg->regs.clr_uproc_interrupt_reg32);
  2386. for (i = 0; i < length_in_words; i++) {
  2387. /* Wait for IO debug acknowledge */
  2388. if (ipr_wait_iodbg_ack(ioa_cfg,
  2389. IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC)) {
  2390. dev_err(&ioa_cfg->pdev->dev,
  2391. "IOA dump short data transfer timeout\n");
  2392. return -EIO;
  2393. }
  2394. /* Read data from mailbox and increment destination pointer */
  2395. *dest = cpu_to_be32(readl(ioa_cfg->ioa_mailbox));
  2396. dest++;
  2397. /* For all but the last word of data, signal data received */
  2398. if (i < (length_in_words - 1)) {
  2399. /* Signal dump data received - Clear IO debug Ack */
  2400. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2401. ioa_cfg->regs.clr_interrupt_reg);
  2402. }
  2403. }
  2404. /* Signal end of block transfer. Set reset alert then clear IO debug ack */
  2405. writel(IPR_UPROCI_RESET_ALERT,
  2406. ioa_cfg->regs.set_uproc_interrupt_reg32);
  2407. writel(IPR_UPROCI_IO_DEBUG_ALERT,
  2408. ioa_cfg->regs.clr_uproc_interrupt_reg32);
  2409. /* Signal dump data received - Clear IO debug Ack */
  2410. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE,
  2411. ioa_cfg->regs.clr_interrupt_reg);
  2412. /* Wait for IOA to signal LDUMP exit - IOA reset alert will be cleared */
  2413. while (delay < IPR_LDUMP_MAX_SHORT_ACK_DELAY_IN_USEC) {
  2414. temp_pcii_reg =
  2415. readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
  2416. if (!(temp_pcii_reg & IPR_UPROCI_RESET_ALERT))
  2417. return 0;
  2418. udelay(10);
  2419. delay += 10;
  2420. }
  2421. return 0;
  2422. }
  2423. #ifdef CONFIG_SCSI_IPR_DUMP
  2424. /**
  2425. * ipr_sdt_copy - Copy Smart Dump Table to kernel buffer
  2426. * @ioa_cfg: ioa config struct
  2427. * @pci_address: adapter address
  2428. * @length: length of data to copy
  2429. *
  2430. * Copy data from PCI adapter to kernel buffer.
  2431. * Note: length MUST be a 4 byte multiple
  2432. * Return value:
  2433. * 0 on success / other on failure
  2434. **/
  2435. static int ipr_sdt_copy(struct ipr_ioa_cfg *ioa_cfg,
  2436. unsigned long pci_address, u32 length)
  2437. {
  2438. int bytes_copied = 0;
  2439. int cur_len, rc, rem_len, rem_page_len, max_dump_size;
  2440. __be32 *page;
  2441. unsigned long lock_flags = 0;
  2442. struct ipr_ioa_dump *ioa_dump = &ioa_cfg->dump->ioa_dump;
  2443. if (ioa_cfg->sis64)
  2444. max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
  2445. else
  2446. max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
  2447. while (bytes_copied < length &&
  2448. (ioa_dump->hdr.len + bytes_copied) < max_dump_size) {
  2449. if (ioa_dump->page_offset >= PAGE_SIZE ||
  2450. ioa_dump->page_offset == 0) {
  2451. page = (__be32 *)__get_free_page(GFP_ATOMIC);
  2452. if (!page) {
  2453. ipr_trace;
  2454. return bytes_copied;
  2455. }
  2456. ioa_dump->page_offset = 0;
  2457. ioa_dump->ioa_data[ioa_dump->next_page_index] = page;
  2458. ioa_dump->next_page_index++;
  2459. } else
  2460. page = ioa_dump->ioa_data[ioa_dump->next_page_index - 1];
  2461. rem_len = length - bytes_copied;
  2462. rem_page_len = PAGE_SIZE - ioa_dump->page_offset;
  2463. cur_len = min(rem_len, rem_page_len);
  2464. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2465. if (ioa_cfg->sdt_state == ABORT_DUMP) {
  2466. rc = -EIO;
  2467. } else {
  2468. rc = ipr_get_ldump_data_section(ioa_cfg,
  2469. pci_address + bytes_copied,
  2470. &page[ioa_dump->page_offset / 4],
  2471. (cur_len / sizeof(u32)));
  2472. }
  2473. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2474. if (!rc) {
  2475. ioa_dump->page_offset += cur_len;
  2476. bytes_copied += cur_len;
  2477. } else {
  2478. ipr_trace;
  2479. break;
  2480. }
  2481. schedule();
  2482. }
  2483. return bytes_copied;
  2484. }
  2485. /**
  2486. * ipr_init_dump_entry_hdr - Initialize a dump entry header.
  2487. * @hdr: dump entry header struct
  2488. *
  2489. * Return value:
  2490. * nothing
  2491. **/
  2492. static void ipr_init_dump_entry_hdr(struct ipr_dump_entry_header *hdr)
  2493. {
  2494. hdr->eye_catcher = IPR_DUMP_EYE_CATCHER;
  2495. hdr->num_elems = 1;
  2496. hdr->offset = sizeof(*hdr);
  2497. hdr->status = IPR_DUMP_STATUS_SUCCESS;
  2498. }
  2499. /**
  2500. * ipr_dump_ioa_type_data - Fill in the adapter type in the dump.
  2501. * @ioa_cfg: ioa config struct
  2502. * @driver_dump: driver dump struct
  2503. *
  2504. * Return value:
  2505. * nothing
  2506. **/
  2507. static void ipr_dump_ioa_type_data(struct ipr_ioa_cfg *ioa_cfg,
  2508. struct ipr_driver_dump *driver_dump)
  2509. {
  2510. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  2511. ipr_init_dump_entry_hdr(&driver_dump->ioa_type_entry.hdr);
  2512. driver_dump->ioa_type_entry.hdr.len =
  2513. sizeof(struct ipr_dump_ioa_type_entry) -
  2514. sizeof(struct ipr_dump_entry_header);
  2515. driver_dump->ioa_type_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2516. driver_dump->ioa_type_entry.hdr.id = IPR_DUMP_DRIVER_TYPE_ID;
  2517. driver_dump->ioa_type_entry.type = ioa_cfg->type;
  2518. driver_dump->ioa_type_entry.fw_version = (ucode_vpd->major_release << 24) |
  2519. (ucode_vpd->card_type << 16) | (ucode_vpd->minor_release[0] << 8) |
  2520. ucode_vpd->minor_release[1];
  2521. driver_dump->hdr.num_entries++;
  2522. }
  2523. /**
  2524. * ipr_dump_version_data - Fill in the driver version in the dump.
  2525. * @ioa_cfg: ioa config struct
  2526. * @driver_dump: driver dump struct
  2527. *
  2528. * Return value:
  2529. * nothing
  2530. **/
  2531. static void ipr_dump_version_data(struct ipr_ioa_cfg *ioa_cfg,
  2532. struct ipr_driver_dump *driver_dump)
  2533. {
  2534. ipr_init_dump_entry_hdr(&driver_dump->version_entry.hdr);
  2535. driver_dump->version_entry.hdr.len =
  2536. sizeof(struct ipr_dump_version_entry) -
  2537. sizeof(struct ipr_dump_entry_header);
  2538. driver_dump->version_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  2539. driver_dump->version_entry.hdr.id = IPR_DUMP_DRIVER_VERSION_ID;
  2540. strcpy(driver_dump->version_entry.version, IPR_DRIVER_VERSION);
  2541. driver_dump->hdr.num_entries++;
  2542. }
  2543. /**
  2544. * ipr_dump_trace_data - Fill in the IOA trace in the dump.
  2545. * @ioa_cfg: ioa config struct
  2546. * @driver_dump: driver dump struct
  2547. *
  2548. * Return value:
  2549. * nothing
  2550. **/
  2551. static void ipr_dump_trace_data(struct ipr_ioa_cfg *ioa_cfg,
  2552. struct ipr_driver_dump *driver_dump)
  2553. {
  2554. ipr_init_dump_entry_hdr(&driver_dump->trace_entry.hdr);
  2555. driver_dump->trace_entry.hdr.len =
  2556. sizeof(struct ipr_dump_trace_entry) -
  2557. sizeof(struct ipr_dump_entry_header);
  2558. driver_dump->trace_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2559. driver_dump->trace_entry.hdr.id = IPR_DUMP_TRACE_ID;
  2560. memcpy(driver_dump->trace_entry.trace, ioa_cfg->trace, IPR_TRACE_SIZE);
  2561. driver_dump->hdr.num_entries++;
  2562. }
  2563. /**
  2564. * ipr_dump_location_data - Fill in the IOA location in the dump.
  2565. * @ioa_cfg: ioa config struct
  2566. * @driver_dump: driver dump struct
  2567. *
  2568. * Return value:
  2569. * nothing
  2570. **/
  2571. static void ipr_dump_location_data(struct ipr_ioa_cfg *ioa_cfg,
  2572. struct ipr_driver_dump *driver_dump)
  2573. {
  2574. ipr_init_dump_entry_hdr(&driver_dump->location_entry.hdr);
  2575. driver_dump->location_entry.hdr.len =
  2576. sizeof(struct ipr_dump_location_entry) -
  2577. sizeof(struct ipr_dump_entry_header);
  2578. driver_dump->location_entry.hdr.data_type = IPR_DUMP_DATA_TYPE_ASCII;
  2579. driver_dump->location_entry.hdr.id = IPR_DUMP_LOCATION_ID;
  2580. strcpy(driver_dump->location_entry.location, dev_name(&ioa_cfg->pdev->dev));
  2581. driver_dump->hdr.num_entries++;
  2582. }
  2583. /**
  2584. * ipr_get_ioa_dump - Perform a dump of the driver and adapter.
  2585. * @ioa_cfg: ioa config struct
  2586. * @dump: dump struct
  2587. *
  2588. * Return value:
  2589. * nothing
  2590. **/
  2591. static void ipr_get_ioa_dump(struct ipr_ioa_cfg *ioa_cfg, struct ipr_dump *dump)
  2592. {
  2593. unsigned long start_addr, sdt_word;
  2594. unsigned long lock_flags = 0;
  2595. struct ipr_driver_dump *driver_dump = &dump->driver_dump;
  2596. struct ipr_ioa_dump *ioa_dump = &dump->ioa_dump;
  2597. u32 num_entries, max_num_entries, start_off, end_off;
  2598. u32 max_dump_size, bytes_to_copy, bytes_copied, rc;
  2599. struct ipr_sdt *sdt;
  2600. int valid = 1;
  2601. int i;
  2602. ENTER;
  2603. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2604. if (ioa_cfg->sdt_state != READ_DUMP) {
  2605. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2606. return;
  2607. }
  2608. if (ioa_cfg->sis64) {
  2609. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2610. ssleep(IPR_DUMP_DELAY_SECONDS);
  2611. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2612. }
  2613. start_addr = readl(ioa_cfg->ioa_mailbox);
  2614. if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(start_addr)) {
  2615. dev_err(&ioa_cfg->pdev->dev,
  2616. "Invalid dump table format: %lx\n", start_addr);
  2617. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2618. return;
  2619. }
  2620. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA initiated\n");
  2621. driver_dump->hdr.eye_catcher = IPR_DUMP_EYE_CATCHER;
  2622. /* Initialize the overall dump header */
  2623. driver_dump->hdr.len = sizeof(struct ipr_driver_dump);
  2624. driver_dump->hdr.num_entries = 1;
  2625. driver_dump->hdr.first_entry_offset = sizeof(struct ipr_dump_header);
  2626. driver_dump->hdr.status = IPR_DUMP_STATUS_SUCCESS;
  2627. driver_dump->hdr.os = IPR_DUMP_OS_LINUX;
  2628. driver_dump->hdr.driver_name = IPR_DUMP_DRIVER_NAME;
  2629. ipr_dump_version_data(ioa_cfg, driver_dump);
  2630. ipr_dump_location_data(ioa_cfg, driver_dump);
  2631. ipr_dump_ioa_type_data(ioa_cfg, driver_dump);
  2632. ipr_dump_trace_data(ioa_cfg, driver_dump);
  2633. /* Update dump_header */
  2634. driver_dump->hdr.len += sizeof(struct ipr_dump_entry_header);
  2635. /* IOA Dump entry */
  2636. ipr_init_dump_entry_hdr(&ioa_dump->hdr);
  2637. ioa_dump->hdr.len = 0;
  2638. ioa_dump->hdr.data_type = IPR_DUMP_DATA_TYPE_BINARY;
  2639. ioa_dump->hdr.id = IPR_DUMP_IOA_DUMP_ID;
  2640. /* First entries in sdt are actually a list of dump addresses and
  2641. lengths to gather the real dump data. sdt represents the pointer
  2642. to the ioa generated dump table. Dump data will be extracted based
  2643. on entries in this table */
  2644. sdt = &ioa_dump->sdt;
  2645. if (ioa_cfg->sis64) {
  2646. max_num_entries = IPR_FMT3_NUM_SDT_ENTRIES;
  2647. max_dump_size = IPR_FMT3_MAX_IOA_DUMP_SIZE;
  2648. } else {
  2649. max_num_entries = IPR_FMT2_NUM_SDT_ENTRIES;
  2650. max_dump_size = IPR_FMT2_MAX_IOA_DUMP_SIZE;
  2651. }
  2652. bytes_to_copy = offsetof(struct ipr_sdt, entry) +
  2653. (max_num_entries * sizeof(struct ipr_sdt_entry));
  2654. rc = ipr_get_ldump_data_section(ioa_cfg, start_addr, (__be32 *)sdt,
  2655. bytes_to_copy / sizeof(__be32));
  2656. /* Smart Dump table is ready to use and the first entry is valid */
  2657. if (rc || ((be32_to_cpu(sdt->hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
  2658. (be32_to_cpu(sdt->hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
  2659. dev_err(&ioa_cfg->pdev->dev,
  2660. "Dump of IOA failed. Dump table not valid: %d, %X.\n",
  2661. rc, be32_to_cpu(sdt->hdr.state));
  2662. driver_dump->hdr.status = IPR_DUMP_STATUS_FAILED;
  2663. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2664. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2665. return;
  2666. }
  2667. num_entries = be32_to_cpu(sdt->hdr.num_entries_used);
  2668. if (num_entries > max_num_entries)
  2669. num_entries = max_num_entries;
  2670. /* Update dump length to the actual data to be copied */
  2671. dump->driver_dump.hdr.len += sizeof(struct ipr_sdt_header);
  2672. if (ioa_cfg->sis64)
  2673. dump->driver_dump.hdr.len += num_entries * sizeof(struct ipr_sdt_entry);
  2674. else
  2675. dump->driver_dump.hdr.len += max_num_entries * sizeof(struct ipr_sdt_entry);
  2676. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2677. for (i = 0; i < num_entries; i++) {
  2678. if (ioa_dump->hdr.len > max_dump_size) {
  2679. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2680. break;
  2681. }
  2682. if (sdt->entry[i].flags & IPR_SDT_VALID_ENTRY) {
  2683. sdt_word = be32_to_cpu(sdt->entry[i].start_token);
  2684. if (ioa_cfg->sis64)
  2685. bytes_to_copy = be32_to_cpu(sdt->entry[i].end_token);
  2686. else {
  2687. start_off = sdt_word & IPR_FMT2_MBX_ADDR_MASK;
  2688. end_off = be32_to_cpu(sdt->entry[i].end_token);
  2689. if (ipr_sdt_is_fmt2(sdt_word) && sdt_word)
  2690. bytes_to_copy = end_off - start_off;
  2691. else
  2692. valid = 0;
  2693. }
  2694. if (valid) {
  2695. if (bytes_to_copy > max_dump_size) {
  2696. sdt->entry[i].flags &= ~IPR_SDT_VALID_ENTRY;
  2697. continue;
  2698. }
  2699. /* Copy data from adapter to driver buffers */
  2700. bytes_copied = ipr_sdt_copy(ioa_cfg, sdt_word,
  2701. bytes_to_copy);
  2702. ioa_dump->hdr.len += bytes_copied;
  2703. if (bytes_copied != bytes_to_copy) {
  2704. driver_dump->hdr.status = IPR_DUMP_STATUS_QUAL_SUCCESS;
  2705. break;
  2706. }
  2707. }
  2708. }
  2709. }
  2710. dev_err(&ioa_cfg->pdev->dev, "Dump of IOA completed.\n");
  2711. /* Update dump_header */
  2712. driver_dump->hdr.len += ioa_dump->hdr.len;
  2713. wmb();
  2714. ioa_cfg->sdt_state = DUMP_OBTAINED;
  2715. LEAVE;
  2716. }
  2717. #else
  2718. #define ipr_get_ioa_dump(ioa_cfg, dump) do { } while (0)
  2719. #endif
  2720. /**
  2721. * ipr_release_dump - Free adapter dump memory
  2722. * @kref: kref struct
  2723. *
  2724. * Return value:
  2725. * nothing
  2726. **/
  2727. static void ipr_release_dump(struct kref *kref)
  2728. {
  2729. struct ipr_dump *dump = container_of(kref, struct ipr_dump, kref);
  2730. struct ipr_ioa_cfg *ioa_cfg = dump->ioa_cfg;
  2731. unsigned long lock_flags = 0;
  2732. int i;
  2733. ENTER;
  2734. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2735. ioa_cfg->dump = NULL;
  2736. ioa_cfg->sdt_state = INACTIVE;
  2737. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2738. for (i = 0; i < dump->ioa_dump.next_page_index; i++)
  2739. free_page((unsigned long) dump->ioa_dump.ioa_data[i]);
  2740. vfree(dump->ioa_dump.ioa_data);
  2741. kfree(dump);
  2742. LEAVE;
  2743. }
  2744. /**
  2745. * ipr_worker_thread - Worker thread
  2746. * @work: ioa config struct
  2747. *
  2748. * Called at task level from a work thread. This function takes care
  2749. * of adding and removing device from the mid-layer as configuration
  2750. * changes are detected by the adapter.
  2751. *
  2752. * Return value:
  2753. * nothing
  2754. **/
  2755. static void ipr_worker_thread(struct work_struct *work)
  2756. {
  2757. unsigned long lock_flags;
  2758. struct ipr_resource_entry *res;
  2759. struct scsi_device *sdev;
  2760. struct ipr_dump *dump;
  2761. struct ipr_ioa_cfg *ioa_cfg =
  2762. container_of(work, struct ipr_ioa_cfg, work_q);
  2763. u8 bus, target, lun;
  2764. int did_work;
  2765. ENTER;
  2766. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2767. if (ioa_cfg->sdt_state == READ_DUMP) {
  2768. dump = ioa_cfg->dump;
  2769. if (!dump) {
  2770. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2771. return;
  2772. }
  2773. kref_get(&dump->kref);
  2774. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2775. ipr_get_ioa_dump(ioa_cfg, dump);
  2776. kref_put(&dump->kref, ipr_release_dump);
  2777. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2778. if (ioa_cfg->sdt_state == DUMP_OBTAINED && !ioa_cfg->dump_timeout)
  2779. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  2780. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2781. return;
  2782. }
  2783. restart:
  2784. do {
  2785. did_work = 0;
  2786. if (!ioa_cfg->allow_cmds || !ioa_cfg->allow_ml_add_del) {
  2787. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2788. return;
  2789. }
  2790. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2791. if (res->del_from_ml && res->sdev) {
  2792. did_work = 1;
  2793. sdev = res->sdev;
  2794. if (!scsi_device_get(sdev)) {
  2795. if (!res->add_to_ml)
  2796. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  2797. else
  2798. res->del_from_ml = 0;
  2799. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2800. scsi_remove_device(sdev);
  2801. scsi_device_put(sdev);
  2802. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2803. }
  2804. break;
  2805. }
  2806. }
  2807. } while (did_work);
  2808. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  2809. if (res->add_to_ml) {
  2810. bus = res->bus;
  2811. target = res->target;
  2812. lun = res->lun;
  2813. res->add_to_ml = 0;
  2814. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2815. scsi_add_device(ioa_cfg->host, bus, target, lun);
  2816. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2817. goto restart;
  2818. }
  2819. }
  2820. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2821. kobject_uevent(&ioa_cfg->host->shost_dev.kobj, KOBJ_CHANGE);
  2822. LEAVE;
  2823. }
  2824. #ifdef CONFIG_SCSI_IPR_TRACE
  2825. /**
  2826. * ipr_read_trace - Dump the adapter trace
  2827. * @filp: open sysfs file
  2828. * @kobj: kobject struct
  2829. * @bin_attr: bin_attribute struct
  2830. * @buf: buffer
  2831. * @off: offset
  2832. * @count: buffer size
  2833. *
  2834. * Return value:
  2835. * number of bytes printed to buffer
  2836. **/
  2837. static ssize_t ipr_read_trace(struct file *filp, struct kobject *kobj,
  2838. struct bin_attribute *bin_attr,
  2839. char *buf, loff_t off, size_t count)
  2840. {
  2841. struct device *dev = container_of(kobj, struct device, kobj);
  2842. struct Scsi_Host *shost = class_to_shost(dev);
  2843. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2844. unsigned long lock_flags = 0;
  2845. ssize_t ret;
  2846. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2847. ret = memory_read_from_buffer(buf, count, &off, ioa_cfg->trace,
  2848. IPR_TRACE_SIZE);
  2849. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2850. return ret;
  2851. }
  2852. static struct bin_attribute ipr_trace_attr = {
  2853. .attr = {
  2854. .name = "trace",
  2855. .mode = S_IRUGO,
  2856. },
  2857. .size = 0,
  2858. .read = ipr_read_trace,
  2859. };
  2860. #endif
  2861. /**
  2862. * ipr_show_fw_version - Show the firmware version
  2863. * @dev: class device struct
  2864. * @buf: buffer
  2865. *
  2866. * Return value:
  2867. * number of bytes printed to buffer
  2868. **/
  2869. static ssize_t ipr_show_fw_version(struct device *dev,
  2870. struct device_attribute *attr, char *buf)
  2871. {
  2872. struct Scsi_Host *shost = class_to_shost(dev);
  2873. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2874. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  2875. unsigned long lock_flags = 0;
  2876. int len;
  2877. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2878. len = snprintf(buf, PAGE_SIZE, "%02X%02X%02X%02X\n",
  2879. ucode_vpd->major_release, ucode_vpd->card_type,
  2880. ucode_vpd->minor_release[0],
  2881. ucode_vpd->minor_release[1]);
  2882. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2883. return len;
  2884. }
  2885. static struct device_attribute ipr_fw_version_attr = {
  2886. .attr = {
  2887. .name = "fw_version",
  2888. .mode = S_IRUGO,
  2889. },
  2890. .show = ipr_show_fw_version,
  2891. };
  2892. /**
  2893. * ipr_show_log_level - Show the adapter's error logging level
  2894. * @dev: class device struct
  2895. * @buf: buffer
  2896. *
  2897. * Return value:
  2898. * number of bytes printed to buffer
  2899. **/
  2900. static ssize_t ipr_show_log_level(struct device *dev,
  2901. struct device_attribute *attr, char *buf)
  2902. {
  2903. struct Scsi_Host *shost = class_to_shost(dev);
  2904. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2905. unsigned long lock_flags = 0;
  2906. int len;
  2907. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2908. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->log_level);
  2909. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2910. return len;
  2911. }
  2912. /**
  2913. * ipr_store_log_level - Change the adapter's error logging level
  2914. * @dev: class device struct
  2915. * @buf: buffer
  2916. *
  2917. * Return value:
  2918. * number of bytes printed to buffer
  2919. **/
  2920. static ssize_t ipr_store_log_level(struct device *dev,
  2921. struct device_attribute *attr,
  2922. const char *buf, size_t count)
  2923. {
  2924. struct Scsi_Host *shost = class_to_shost(dev);
  2925. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2926. unsigned long lock_flags = 0;
  2927. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2928. ioa_cfg->log_level = simple_strtoul(buf, NULL, 10);
  2929. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2930. return strlen(buf);
  2931. }
  2932. static struct device_attribute ipr_log_level_attr = {
  2933. .attr = {
  2934. .name = "log_level",
  2935. .mode = S_IRUGO | S_IWUSR,
  2936. },
  2937. .show = ipr_show_log_level,
  2938. .store = ipr_store_log_level
  2939. };
  2940. /**
  2941. * ipr_store_diagnostics - IOA Diagnostics interface
  2942. * @dev: device struct
  2943. * @buf: buffer
  2944. * @count: buffer size
  2945. *
  2946. * This function will reset the adapter and wait a reasonable
  2947. * amount of time for any errors that the adapter might log.
  2948. *
  2949. * Return value:
  2950. * count on success / other on failure
  2951. **/
  2952. static ssize_t ipr_store_diagnostics(struct device *dev,
  2953. struct device_attribute *attr,
  2954. const char *buf, size_t count)
  2955. {
  2956. struct Scsi_Host *shost = class_to_shost(dev);
  2957. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  2958. unsigned long lock_flags = 0;
  2959. int rc = count;
  2960. if (!capable(CAP_SYS_ADMIN))
  2961. return -EACCES;
  2962. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2963. while (ioa_cfg->in_reset_reload) {
  2964. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2965. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2966. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2967. }
  2968. ioa_cfg->errors_logged = 0;
  2969. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  2970. if (ioa_cfg->in_reset_reload) {
  2971. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2972. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  2973. /* Wait for a second for any errors to be logged */
  2974. msleep(1000);
  2975. } else {
  2976. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2977. return -EIO;
  2978. }
  2979. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  2980. if (ioa_cfg->in_reset_reload || ioa_cfg->errors_logged)
  2981. rc = -EIO;
  2982. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  2983. return rc;
  2984. }
  2985. static struct device_attribute ipr_diagnostics_attr = {
  2986. .attr = {
  2987. .name = "run_diagnostics",
  2988. .mode = S_IWUSR,
  2989. },
  2990. .store = ipr_store_diagnostics
  2991. };
  2992. /**
  2993. * ipr_show_adapter_state - Show the adapter's state
  2994. * @class_dev: device struct
  2995. * @buf: buffer
  2996. *
  2997. * Return value:
  2998. * number of bytes printed to buffer
  2999. **/
  3000. static ssize_t ipr_show_adapter_state(struct device *dev,
  3001. struct device_attribute *attr, char *buf)
  3002. {
  3003. struct Scsi_Host *shost = class_to_shost(dev);
  3004. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3005. unsigned long lock_flags = 0;
  3006. int len;
  3007. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3008. if (ioa_cfg->ioa_is_dead)
  3009. len = snprintf(buf, PAGE_SIZE, "offline\n");
  3010. else
  3011. len = snprintf(buf, PAGE_SIZE, "online\n");
  3012. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3013. return len;
  3014. }
  3015. /**
  3016. * ipr_store_adapter_state - Change adapter state
  3017. * @dev: device struct
  3018. * @buf: buffer
  3019. * @count: buffer size
  3020. *
  3021. * This function will change the adapter's state.
  3022. *
  3023. * Return value:
  3024. * count on success / other on failure
  3025. **/
  3026. static ssize_t ipr_store_adapter_state(struct device *dev,
  3027. struct device_attribute *attr,
  3028. const char *buf, size_t count)
  3029. {
  3030. struct Scsi_Host *shost = class_to_shost(dev);
  3031. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3032. unsigned long lock_flags;
  3033. int result = count;
  3034. if (!capable(CAP_SYS_ADMIN))
  3035. return -EACCES;
  3036. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3037. if (ioa_cfg->ioa_is_dead && !strncmp(buf, "online", 6)) {
  3038. ioa_cfg->ioa_is_dead = 0;
  3039. ioa_cfg->reset_retries = 0;
  3040. ioa_cfg->in_ioa_bringdown = 0;
  3041. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  3042. }
  3043. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3044. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3045. return result;
  3046. }
  3047. static struct device_attribute ipr_ioa_state_attr = {
  3048. .attr = {
  3049. .name = "online_state",
  3050. .mode = S_IRUGO | S_IWUSR,
  3051. },
  3052. .show = ipr_show_adapter_state,
  3053. .store = ipr_store_adapter_state
  3054. };
  3055. /**
  3056. * ipr_store_reset_adapter - Reset the adapter
  3057. * @dev: device struct
  3058. * @buf: buffer
  3059. * @count: buffer size
  3060. *
  3061. * This function will reset the adapter.
  3062. *
  3063. * Return value:
  3064. * count on success / other on failure
  3065. **/
  3066. static ssize_t ipr_store_reset_adapter(struct device *dev,
  3067. struct device_attribute *attr,
  3068. const char *buf, size_t count)
  3069. {
  3070. struct Scsi_Host *shost = class_to_shost(dev);
  3071. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3072. unsigned long lock_flags;
  3073. int result = count;
  3074. if (!capable(CAP_SYS_ADMIN))
  3075. return -EACCES;
  3076. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3077. if (!ioa_cfg->in_reset_reload)
  3078. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3079. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3080. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3081. return result;
  3082. }
  3083. static struct device_attribute ipr_ioa_reset_attr = {
  3084. .attr = {
  3085. .name = "reset_host",
  3086. .mode = S_IWUSR,
  3087. },
  3088. .store = ipr_store_reset_adapter
  3089. };
  3090. /**
  3091. * ipr_alloc_ucode_buffer - Allocates a microcode download buffer
  3092. * @buf_len: buffer length
  3093. *
  3094. * Allocates a DMA'able buffer in chunks and assembles a scatter/gather
  3095. * list to use for microcode download
  3096. *
  3097. * Return value:
  3098. * pointer to sglist / NULL on failure
  3099. **/
  3100. static struct ipr_sglist *ipr_alloc_ucode_buffer(int buf_len)
  3101. {
  3102. int sg_size, order, bsize_elem, num_elem, i, j;
  3103. struct ipr_sglist *sglist;
  3104. struct scatterlist *scatterlist;
  3105. struct page *page;
  3106. /* Get the minimum size per scatter/gather element */
  3107. sg_size = buf_len / (IPR_MAX_SGLIST - 1);
  3108. /* Get the actual size per element */
  3109. order = get_order(sg_size);
  3110. /* Determine the actual number of bytes per element */
  3111. bsize_elem = PAGE_SIZE * (1 << order);
  3112. /* Determine the actual number of sg entries needed */
  3113. if (buf_len % bsize_elem)
  3114. num_elem = (buf_len / bsize_elem) + 1;
  3115. else
  3116. num_elem = buf_len / bsize_elem;
  3117. /* Allocate a scatter/gather list for the DMA */
  3118. sglist = kzalloc(sizeof(struct ipr_sglist) +
  3119. (sizeof(struct scatterlist) * (num_elem - 1)),
  3120. GFP_KERNEL);
  3121. if (sglist == NULL) {
  3122. ipr_trace;
  3123. return NULL;
  3124. }
  3125. scatterlist = sglist->scatterlist;
  3126. sg_init_table(scatterlist, num_elem);
  3127. sglist->order = order;
  3128. sglist->num_sg = num_elem;
  3129. /* Allocate a bunch of sg elements */
  3130. for (i = 0; i < num_elem; i++) {
  3131. page = alloc_pages(GFP_KERNEL, order);
  3132. if (!page) {
  3133. ipr_trace;
  3134. /* Free up what we already allocated */
  3135. for (j = i - 1; j >= 0; j--)
  3136. __free_pages(sg_page(&scatterlist[j]), order);
  3137. kfree(sglist);
  3138. return NULL;
  3139. }
  3140. sg_set_page(&scatterlist[i], page, 0, 0);
  3141. }
  3142. return sglist;
  3143. }
  3144. /**
  3145. * ipr_free_ucode_buffer - Frees a microcode download buffer
  3146. * @p_dnld: scatter/gather list pointer
  3147. *
  3148. * Free a DMA'able ucode download buffer previously allocated with
  3149. * ipr_alloc_ucode_buffer
  3150. *
  3151. * Return value:
  3152. * nothing
  3153. **/
  3154. static void ipr_free_ucode_buffer(struct ipr_sglist *sglist)
  3155. {
  3156. int i;
  3157. for (i = 0; i < sglist->num_sg; i++)
  3158. __free_pages(sg_page(&sglist->scatterlist[i]), sglist->order);
  3159. kfree(sglist);
  3160. }
  3161. /**
  3162. * ipr_copy_ucode_buffer - Copy user buffer to kernel buffer
  3163. * @sglist: scatter/gather list pointer
  3164. * @buffer: buffer pointer
  3165. * @len: buffer length
  3166. *
  3167. * Copy a microcode image from a user buffer into a buffer allocated by
  3168. * ipr_alloc_ucode_buffer
  3169. *
  3170. * Return value:
  3171. * 0 on success / other on failure
  3172. **/
  3173. static int ipr_copy_ucode_buffer(struct ipr_sglist *sglist,
  3174. u8 *buffer, u32 len)
  3175. {
  3176. int bsize_elem, i, result = 0;
  3177. struct scatterlist *scatterlist;
  3178. void *kaddr;
  3179. /* Determine the actual number of bytes per element */
  3180. bsize_elem = PAGE_SIZE * (1 << sglist->order);
  3181. scatterlist = sglist->scatterlist;
  3182. for (i = 0; i < (len / bsize_elem); i++, buffer += bsize_elem) {
  3183. struct page *page = sg_page(&scatterlist[i]);
  3184. kaddr = kmap(page);
  3185. memcpy(kaddr, buffer, bsize_elem);
  3186. kunmap(page);
  3187. scatterlist[i].length = bsize_elem;
  3188. if (result != 0) {
  3189. ipr_trace;
  3190. return result;
  3191. }
  3192. }
  3193. if (len % bsize_elem) {
  3194. struct page *page = sg_page(&scatterlist[i]);
  3195. kaddr = kmap(page);
  3196. memcpy(kaddr, buffer, len % bsize_elem);
  3197. kunmap(page);
  3198. scatterlist[i].length = len % bsize_elem;
  3199. }
  3200. sglist->buffer_len = len;
  3201. return result;
  3202. }
  3203. /**
  3204. * ipr_build_ucode_ioadl64 - Build a microcode download IOADL
  3205. * @ipr_cmd: ipr command struct
  3206. * @sglist: scatter/gather list
  3207. *
  3208. * Builds a microcode download IOA data list (IOADL).
  3209. *
  3210. **/
  3211. static void ipr_build_ucode_ioadl64(struct ipr_cmnd *ipr_cmd,
  3212. struct ipr_sglist *sglist)
  3213. {
  3214. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3215. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  3216. struct scatterlist *scatterlist = sglist->scatterlist;
  3217. int i;
  3218. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  3219. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3220. ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
  3221. ioarcb->ioadl_len =
  3222. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  3223. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  3224. ioadl64[i].flags = cpu_to_be32(IPR_IOADL_FLAGS_WRITE);
  3225. ioadl64[i].data_len = cpu_to_be32(sg_dma_len(&scatterlist[i]));
  3226. ioadl64[i].address = cpu_to_be64(sg_dma_address(&scatterlist[i]));
  3227. }
  3228. ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3229. }
  3230. /**
  3231. * ipr_build_ucode_ioadl - Build a microcode download IOADL
  3232. * @ipr_cmd: ipr command struct
  3233. * @sglist: scatter/gather list
  3234. *
  3235. * Builds a microcode download IOA data list (IOADL).
  3236. *
  3237. **/
  3238. static void ipr_build_ucode_ioadl(struct ipr_cmnd *ipr_cmd,
  3239. struct ipr_sglist *sglist)
  3240. {
  3241. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  3242. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  3243. struct scatterlist *scatterlist = sglist->scatterlist;
  3244. int i;
  3245. ipr_cmd->dma_use_sg = sglist->num_dma_sg;
  3246. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  3247. ioarcb->data_transfer_length = cpu_to_be32(sglist->buffer_len);
  3248. ioarcb->ioadl_len =
  3249. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  3250. for (i = 0; i < ipr_cmd->dma_use_sg; i++) {
  3251. ioadl[i].flags_and_data_len =
  3252. cpu_to_be32(IPR_IOADL_FLAGS_WRITE | sg_dma_len(&scatterlist[i]));
  3253. ioadl[i].address =
  3254. cpu_to_be32(sg_dma_address(&scatterlist[i]));
  3255. }
  3256. ioadl[i-1].flags_and_data_len |=
  3257. cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  3258. }
  3259. /**
  3260. * ipr_update_ioa_ucode - Update IOA's microcode
  3261. * @ioa_cfg: ioa config struct
  3262. * @sglist: scatter/gather list
  3263. *
  3264. * Initiate an adapter reset to update the IOA's microcode
  3265. *
  3266. * Return value:
  3267. * 0 on success / -EIO on failure
  3268. **/
  3269. static int ipr_update_ioa_ucode(struct ipr_ioa_cfg *ioa_cfg,
  3270. struct ipr_sglist *sglist)
  3271. {
  3272. unsigned long lock_flags;
  3273. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3274. while (ioa_cfg->in_reset_reload) {
  3275. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3276. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3277. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3278. }
  3279. if (ioa_cfg->ucode_sglist) {
  3280. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3281. dev_err(&ioa_cfg->pdev->dev,
  3282. "Microcode download already in progress\n");
  3283. return -EIO;
  3284. }
  3285. sglist->num_dma_sg = pci_map_sg(ioa_cfg->pdev, sglist->scatterlist,
  3286. sglist->num_sg, DMA_TO_DEVICE);
  3287. if (!sglist->num_dma_sg) {
  3288. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3289. dev_err(&ioa_cfg->pdev->dev,
  3290. "Failed to map microcode download buffer!\n");
  3291. return -EIO;
  3292. }
  3293. ioa_cfg->ucode_sglist = sglist;
  3294. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  3295. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3296. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  3297. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3298. ioa_cfg->ucode_sglist = NULL;
  3299. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3300. return 0;
  3301. }
  3302. /**
  3303. * ipr_store_update_fw - Update the firmware on the adapter
  3304. * @class_dev: device struct
  3305. * @buf: buffer
  3306. * @count: buffer size
  3307. *
  3308. * This function will update the firmware on the adapter.
  3309. *
  3310. * Return value:
  3311. * count on success / other on failure
  3312. **/
  3313. static ssize_t ipr_store_update_fw(struct device *dev,
  3314. struct device_attribute *attr,
  3315. const char *buf, size_t count)
  3316. {
  3317. struct Scsi_Host *shost = class_to_shost(dev);
  3318. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3319. struct ipr_ucode_image_header *image_hdr;
  3320. const struct firmware *fw_entry;
  3321. struct ipr_sglist *sglist;
  3322. char fname[100];
  3323. char *src;
  3324. int len, result, dnld_size;
  3325. if (!capable(CAP_SYS_ADMIN))
  3326. return -EACCES;
  3327. len = snprintf(fname, 99, "%s", buf);
  3328. fname[len-1] = '\0';
  3329. if (request_firmware(&fw_entry, fname, &ioa_cfg->pdev->dev)) {
  3330. dev_err(&ioa_cfg->pdev->dev, "Firmware file %s not found\n", fname);
  3331. return -EIO;
  3332. }
  3333. image_hdr = (struct ipr_ucode_image_header *)fw_entry->data;
  3334. src = (u8 *)image_hdr + be32_to_cpu(image_hdr->header_length);
  3335. dnld_size = fw_entry->size - be32_to_cpu(image_hdr->header_length);
  3336. sglist = ipr_alloc_ucode_buffer(dnld_size);
  3337. if (!sglist) {
  3338. dev_err(&ioa_cfg->pdev->dev, "Microcode buffer allocation failed\n");
  3339. release_firmware(fw_entry);
  3340. return -ENOMEM;
  3341. }
  3342. result = ipr_copy_ucode_buffer(sglist, src, dnld_size);
  3343. if (result) {
  3344. dev_err(&ioa_cfg->pdev->dev,
  3345. "Microcode buffer copy to DMA buffer failed\n");
  3346. goto out;
  3347. }
  3348. ipr_info("Updating microcode, please be patient. This may take up to 30 minutes.\n");
  3349. result = ipr_update_ioa_ucode(ioa_cfg, sglist);
  3350. if (!result)
  3351. result = count;
  3352. out:
  3353. ipr_free_ucode_buffer(sglist);
  3354. release_firmware(fw_entry);
  3355. return result;
  3356. }
  3357. static struct device_attribute ipr_update_fw_attr = {
  3358. .attr = {
  3359. .name = "update_fw",
  3360. .mode = S_IWUSR,
  3361. },
  3362. .store = ipr_store_update_fw
  3363. };
  3364. /**
  3365. * ipr_show_fw_type - Show the adapter's firmware type.
  3366. * @dev: class device struct
  3367. * @buf: buffer
  3368. *
  3369. * Return value:
  3370. * number of bytes printed to buffer
  3371. **/
  3372. static ssize_t ipr_show_fw_type(struct device *dev,
  3373. struct device_attribute *attr, char *buf)
  3374. {
  3375. struct Scsi_Host *shost = class_to_shost(dev);
  3376. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3377. unsigned long lock_flags = 0;
  3378. int len;
  3379. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3380. len = snprintf(buf, PAGE_SIZE, "%d\n", ioa_cfg->sis64);
  3381. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3382. return len;
  3383. }
  3384. static struct device_attribute ipr_ioa_fw_type_attr = {
  3385. .attr = {
  3386. .name = "fw_type",
  3387. .mode = S_IRUGO,
  3388. },
  3389. .show = ipr_show_fw_type
  3390. };
  3391. static struct device_attribute *ipr_ioa_attrs[] = {
  3392. &ipr_fw_version_attr,
  3393. &ipr_log_level_attr,
  3394. &ipr_diagnostics_attr,
  3395. &ipr_ioa_state_attr,
  3396. &ipr_ioa_reset_attr,
  3397. &ipr_update_fw_attr,
  3398. &ipr_ioa_fw_type_attr,
  3399. NULL,
  3400. };
  3401. #ifdef CONFIG_SCSI_IPR_DUMP
  3402. /**
  3403. * ipr_read_dump - Dump the adapter
  3404. * @filp: open sysfs file
  3405. * @kobj: kobject struct
  3406. * @bin_attr: bin_attribute struct
  3407. * @buf: buffer
  3408. * @off: offset
  3409. * @count: buffer size
  3410. *
  3411. * Return value:
  3412. * number of bytes printed to buffer
  3413. **/
  3414. static ssize_t ipr_read_dump(struct file *filp, struct kobject *kobj,
  3415. struct bin_attribute *bin_attr,
  3416. char *buf, loff_t off, size_t count)
  3417. {
  3418. struct device *cdev = container_of(kobj, struct device, kobj);
  3419. struct Scsi_Host *shost = class_to_shost(cdev);
  3420. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3421. struct ipr_dump *dump;
  3422. unsigned long lock_flags = 0;
  3423. char *src;
  3424. int len, sdt_end;
  3425. size_t rc = count;
  3426. if (!capable(CAP_SYS_ADMIN))
  3427. return -EACCES;
  3428. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3429. dump = ioa_cfg->dump;
  3430. if (ioa_cfg->sdt_state != DUMP_OBTAINED || !dump) {
  3431. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3432. return 0;
  3433. }
  3434. kref_get(&dump->kref);
  3435. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3436. if (off > dump->driver_dump.hdr.len) {
  3437. kref_put(&dump->kref, ipr_release_dump);
  3438. return 0;
  3439. }
  3440. if (off + count > dump->driver_dump.hdr.len) {
  3441. count = dump->driver_dump.hdr.len - off;
  3442. rc = count;
  3443. }
  3444. if (count && off < sizeof(dump->driver_dump)) {
  3445. if (off + count > sizeof(dump->driver_dump))
  3446. len = sizeof(dump->driver_dump) - off;
  3447. else
  3448. len = count;
  3449. src = (u8 *)&dump->driver_dump + off;
  3450. memcpy(buf, src, len);
  3451. buf += len;
  3452. off += len;
  3453. count -= len;
  3454. }
  3455. off -= sizeof(dump->driver_dump);
  3456. if (ioa_cfg->sis64)
  3457. sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
  3458. (be32_to_cpu(dump->ioa_dump.sdt.hdr.num_entries_used) *
  3459. sizeof(struct ipr_sdt_entry));
  3460. else
  3461. sdt_end = offsetof(struct ipr_ioa_dump, sdt.entry) +
  3462. (IPR_FMT2_NUM_SDT_ENTRIES * sizeof(struct ipr_sdt_entry));
  3463. if (count && off < sdt_end) {
  3464. if (off + count > sdt_end)
  3465. len = sdt_end - off;
  3466. else
  3467. len = count;
  3468. src = (u8 *)&dump->ioa_dump + off;
  3469. memcpy(buf, src, len);
  3470. buf += len;
  3471. off += len;
  3472. count -= len;
  3473. }
  3474. off -= sdt_end;
  3475. while (count) {
  3476. if ((off & PAGE_MASK) != ((off + count) & PAGE_MASK))
  3477. len = PAGE_ALIGN(off) - off;
  3478. else
  3479. len = count;
  3480. src = (u8 *)dump->ioa_dump.ioa_data[(off & PAGE_MASK) >> PAGE_SHIFT];
  3481. src += off & ~PAGE_MASK;
  3482. memcpy(buf, src, len);
  3483. buf += len;
  3484. off += len;
  3485. count -= len;
  3486. }
  3487. kref_put(&dump->kref, ipr_release_dump);
  3488. return rc;
  3489. }
  3490. /**
  3491. * ipr_alloc_dump - Prepare for adapter dump
  3492. * @ioa_cfg: ioa config struct
  3493. *
  3494. * Return value:
  3495. * 0 on success / other on failure
  3496. **/
  3497. static int ipr_alloc_dump(struct ipr_ioa_cfg *ioa_cfg)
  3498. {
  3499. struct ipr_dump *dump;
  3500. __be32 **ioa_data;
  3501. unsigned long lock_flags = 0;
  3502. dump = kzalloc(sizeof(struct ipr_dump), GFP_KERNEL);
  3503. if (!dump) {
  3504. ipr_err("Dump memory allocation failed\n");
  3505. return -ENOMEM;
  3506. }
  3507. if (ioa_cfg->sis64)
  3508. ioa_data = vmalloc(IPR_FMT3_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
  3509. else
  3510. ioa_data = vmalloc(IPR_FMT2_MAX_NUM_DUMP_PAGES * sizeof(__be32 *));
  3511. if (!ioa_data) {
  3512. ipr_err("Dump memory allocation failed\n");
  3513. kfree(dump);
  3514. return -ENOMEM;
  3515. }
  3516. dump->ioa_dump.ioa_data = ioa_data;
  3517. kref_init(&dump->kref);
  3518. dump->ioa_cfg = ioa_cfg;
  3519. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3520. if (INACTIVE != ioa_cfg->sdt_state) {
  3521. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3522. vfree(dump->ioa_dump.ioa_data);
  3523. kfree(dump);
  3524. return 0;
  3525. }
  3526. ioa_cfg->dump = dump;
  3527. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  3528. if (ioa_cfg->ioa_is_dead && !ioa_cfg->dump_taken) {
  3529. ioa_cfg->dump_taken = 1;
  3530. schedule_work(&ioa_cfg->work_q);
  3531. }
  3532. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3533. return 0;
  3534. }
  3535. /**
  3536. * ipr_free_dump - Free adapter dump memory
  3537. * @ioa_cfg: ioa config struct
  3538. *
  3539. * Return value:
  3540. * 0 on success / other on failure
  3541. **/
  3542. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg)
  3543. {
  3544. struct ipr_dump *dump;
  3545. unsigned long lock_flags = 0;
  3546. ENTER;
  3547. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3548. dump = ioa_cfg->dump;
  3549. if (!dump) {
  3550. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3551. return 0;
  3552. }
  3553. ioa_cfg->dump = NULL;
  3554. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3555. kref_put(&dump->kref, ipr_release_dump);
  3556. LEAVE;
  3557. return 0;
  3558. }
  3559. /**
  3560. * ipr_write_dump - Setup dump state of adapter
  3561. * @filp: open sysfs file
  3562. * @kobj: kobject struct
  3563. * @bin_attr: bin_attribute struct
  3564. * @buf: buffer
  3565. * @off: offset
  3566. * @count: buffer size
  3567. *
  3568. * Return value:
  3569. * number of bytes printed to buffer
  3570. **/
  3571. static ssize_t ipr_write_dump(struct file *filp, struct kobject *kobj,
  3572. struct bin_attribute *bin_attr,
  3573. char *buf, loff_t off, size_t count)
  3574. {
  3575. struct device *cdev = container_of(kobj, struct device, kobj);
  3576. struct Scsi_Host *shost = class_to_shost(cdev);
  3577. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  3578. int rc;
  3579. if (!capable(CAP_SYS_ADMIN))
  3580. return -EACCES;
  3581. if (buf[0] == '1')
  3582. rc = ipr_alloc_dump(ioa_cfg);
  3583. else if (buf[0] == '0')
  3584. rc = ipr_free_dump(ioa_cfg);
  3585. else
  3586. return -EINVAL;
  3587. if (rc)
  3588. return rc;
  3589. else
  3590. return count;
  3591. }
  3592. static struct bin_attribute ipr_dump_attr = {
  3593. .attr = {
  3594. .name = "dump",
  3595. .mode = S_IRUSR | S_IWUSR,
  3596. },
  3597. .size = 0,
  3598. .read = ipr_read_dump,
  3599. .write = ipr_write_dump
  3600. };
  3601. #else
  3602. static int ipr_free_dump(struct ipr_ioa_cfg *ioa_cfg) { return 0; };
  3603. #endif
  3604. /**
  3605. * ipr_change_queue_depth - Change the device's queue depth
  3606. * @sdev: scsi device struct
  3607. * @qdepth: depth to set
  3608. * @reason: calling context
  3609. *
  3610. * Return value:
  3611. * actual depth set
  3612. **/
  3613. static int ipr_change_queue_depth(struct scsi_device *sdev, int qdepth,
  3614. int reason)
  3615. {
  3616. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3617. struct ipr_resource_entry *res;
  3618. unsigned long lock_flags = 0;
  3619. if (reason != SCSI_QDEPTH_DEFAULT)
  3620. return -EOPNOTSUPP;
  3621. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3622. res = (struct ipr_resource_entry *)sdev->hostdata;
  3623. if (res && ipr_is_gata(res) && qdepth > IPR_MAX_CMD_PER_ATA_LUN)
  3624. qdepth = IPR_MAX_CMD_PER_ATA_LUN;
  3625. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3626. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  3627. return sdev->queue_depth;
  3628. }
  3629. /**
  3630. * ipr_change_queue_type - Change the device's queue type
  3631. * @dsev: scsi device struct
  3632. * @tag_type: type of tags to use
  3633. *
  3634. * Return value:
  3635. * actual queue type set
  3636. **/
  3637. static int ipr_change_queue_type(struct scsi_device *sdev, int tag_type)
  3638. {
  3639. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3640. struct ipr_resource_entry *res;
  3641. unsigned long lock_flags = 0;
  3642. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3643. res = (struct ipr_resource_entry *)sdev->hostdata;
  3644. if (res) {
  3645. if (ipr_is_gscsi(res) && sdev->tagged_supported) {
  3646. /*
  3647. * We don't bother quiescing the device here since the
  3648. * adapter firmware does it for us.
  3649. */
  3650. scsi_set_tag_type(sdev, tag_type);
  3651. if (tag_type)
  3652. scsi_activate_tcq(sdev, sdev->queue_depth);
  3653. else
  3654. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  3655. } else
  3656. tag_type = 0;
  3657. } else
  3658. tag_type = 0;
  3659. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3660. return tag_type;
  3661. }
  3662. /**
  3663. * ipr_show_adapter_handle - Show the adapter's resource handle for this device
  3664. * @dev: device struct
  3665. * @attr: device attribute structure
  3666. * @buf: buffer
  3667. *
  3668. * Return value:
  3669. * number of bytes printed to buffer
  3670. **/
  3671. static ssize_t ipr_show_adapter_handle(struct device *dev, struct device_attribute *attr, char *buf)
  3672. {
  3673. struct scsi_device *sdev = to_scsi_device(dev);
  3674. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3675. struct ipr_resource_entry *res;
  3676. unsigned long lock_flags = 0;
  3677. ssize_t len = -ENXIO;
  3678. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3679. res = (struct ipr_resource_entry *)sdev->hostdata;
  3680. if (res)
  3681. len = snprintf(buf, PAGE_SIZE, "%08X\n", res->res_handle);
  3682. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3683. return len;
  3684. }
  3685. static struct device_attribute ipr_adapter_handle_attr = {
  3686. .attr = {
  3687. .name = "adapter_handle",
  3688. .mode = S_IRUSR,
  3689. },
  3690. .show = ipr_show_adapter_handle
  3691. };
  3692. /**
  3693. * ipr_show_resource_path - Show the resource path or the resource address for
  3694. * this device.
  3695. * @dev: device struct
  3696. * @attr: device attribute structure
  3697. * @buf: buffer
  3698. *
  3699. * Return value:
  3700. * number of bytes printed to buffer
  3701. **/
  3702. static ssize_t ipr_show_resource_path(struct device *dev, struct device_attribute *attr, char *buf)
  3703. {
  3704. struct scsi_device *sdev = to_scsi_device(dev);
  3705. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3706. struct ipr_resource_entry *res;
  3707. unsigned long lock_flags = 0;
  3708. ssize_t len = -ENXIO;
  3709. char buffer[IPR_MAX_RES_PATH_LENGTH];
  3710. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3711. res = (struct ipr_resource_entry *)sdev->hostdata;
  3712. if (res && ioa_cfg->sis64)
  3713. len = snprintf(buf, PAGE_SIZE, "%s\n",
  3714. ipr_format_res_path(res->res_path, buffer,
  3715. sizeof(buffer)));
  3716. else if (res)
  3717. len = snprintf(buf, PAGE_SIZE, "%d:%d:%d:%d\n", ioa_cfg->host->host_no,
  3718. res->bus, res->target, res->lun);
  3719. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3720. return len;
  3721. }
  3722. static struct device_attribute ipr_resource_path_attr = {
  3723. .attr = {
  3724. .name = "resource_path",
  3725. .mode = S_IRUGO,
  3726. },
  3727. .show = ipr_show_resource_path
  3728. };
  3729. /**
  3730. * ipr_show_device_id - Show the device_id for this device.
  3731. * @dev: device struct
  3732. * @attr: device attribute structure
  3733. * @buf: buffer
  3734. *
  3735. * Return value:
  3736. * number of bytes printed to buffer
  3737. **/
  3738. static ssize_t ipr_show_device_id(struct device *dev, struct device_attribute *attr, char *buf)
  3739. {
  3740. struct scsi_device *sdev = to_scsi_device(dev);
  3741. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3742. struct ipr_resource_entry *res;
  3743. unsigned long lock_flags = 0;
  3744. ssize_t len = -ENXIO;
  3745. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3746. res = (struct ipr_resource_entry *)sdev->hostdata;
  3747. if (res && ioa_cfg->sis64)
  3748. len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->dev_id);
  3749. else if (res)
  3750. len = snprintf(buf, PAGE_SIZE, "0x%llx\n", res->lun_wwn);
  3751. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3752. return len;
  3753. }
  3754. static struct device_attribute ipr_device_id_attr = {
  3755. .attr = {
  3756. .name = "device_id",
  3757. .mode = S_IRUGO,
  3758. },
  3759. .show = ipr_show_device_id
  3760. };
  3761. /**
  3762. * ipr_show_resource_type - Show the resource type for this device.
  3763. * @dev: device struct
  3764. * @attr: device attribute structure
  3765. * @buf: buffer
  3766. *
  3767. * Return value:
  3768. * number of bytes printed to buffer
  3769. **/
  3770. static ssize_t ipr_show_resource_type(struct device *dev, struct device_attribute *attr, char *buf)
  3771. {
  3772. struct scsi_device *sdev = to_scsi_device(dev);
  3773. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)sdev->host->hostdata;
  3774. struct ipr_resource_entry *res;
  3775. unsigned long lock_flags = 0;
  3776. ssize_t len = -ENXIO;
  3777. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3778. res = (struct ipr_resource_entry *)sdev->hostdata;
  3779. if (res)
  3780. len = snprintf(buf, PAGE_SIZE, "%x\n", res->type);
  3781. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3782. return len;
  3783. }
  3784. static struct device_attribute ipr_resource_type_attr = {
  3785. .attr = {
  3786. .name = "resource_type",
  3787. .mode = S_IRUGO,
  3788. },
  3789. .show = ipr_show_resource_type
  3790. };
  3791. static struct device_attribute *ipr_dev_attrs[] = {
  3792. &ipr_adapter_handle_attr,
  3793. &ipr_resource_path_attr,
  3794. &ipr_device_id_attr,
  3795. &ipr_resource_type_attr,
  3796. NULL,
  3797. };
  3798. /**
  3799. * ipr_biosparam - Return the HSC mapping
  3800. * @sdev: scsi device struct
  3801. * @block_device: block device pointer
  3802. * @capacity: capacity of the device
  3803. * @parm: Array containing returned HSC values.
  3804. *
  3805. * This function generates the HSC parms that fdisk uses.
  3806. * We want to make sure we return something that places partitions
  3807. * on 4k boundaries for best performance with the IOA.
  3808. *
  3809. * Return value:
  3810. * 0 on success
  3811. **/
  3812. static int ipr_biosparam(struct scsi_device *sdev,
  3813. struct block_device *block_device,
  3814. sector_t capacity, int *parm)
  3815. {
  3816. int heads, sectors;
  3817. sector_t cylinders;
  3818. heads = 128;
  3819. sectors = 32;
  3820. cylinders = capacity;
  3821. sector_div(cylinders, (128 * 32));
  3822. /* return result */
  3823. parm[0] = heads;
  3824. parm[1] = sectors;
  3825. parm[2] = cylinders;
  3826. return 0;
  3827. }
  3828. /**
  3829. * ipr_find_starget - Find target based on bus/target.
  3830. * @starget: scsi target struct
  3831. *
  3832. * Return value:
  3833. * resource entry pointer if found / NULL if not found
  3834. **/
  3835. static struct ipr_resource_entry *ipr_find_starget(struct scsi_target *starget)
  3836. {
  3837. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  3838. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  3839. struct ipr_resource_entry *res;
  3840. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3841. if ((res->bus == starget->channel) &&
  3842. (res->target == starget->id)) {
  3843. return res;
  3844. }
  3845. }
  3846. return NULL;
  3847. }
  3848. static struct ata_port_info sata_port_info;
  3849. /**
  3850. * ipr_target_alloc - Prepare for commands to a SCSI target
  3851. * @starget: scsi target struct
  3852. *
  3853. * If the device is a SATA device, this function allocates an
  3854. * ATA port with libata, else it does nothing.
  3855. *
  3856. * Return value:
  3857. * 0 on success / non-0 on failure
  3858. **/
  3859. static int ipr_target_alloc(struct scsi_target *starget)
  3860. {
  3861. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  3862. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  3863. struct ipr_sata_port *sata_port;
  3864. struct ata_port *ap;
  3865. struct ipr_resource_entry *res;
  3866. unsigned long lock_flags;
  3867. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3868. res = ipr_find_starget(starget);
  3869. starget->hostdata = NULL;
  3870. if (res && ipr_is_gata(res)) {
  3871. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3872. sata_port = kzalloc(sizeof(*sata_port), GFP_KERNEL);
  3873. if (!sata_port)
  3874. return -ENOMEM;
  3875. ap = ata_sas_port_alloc(&ioa_cfg->ata_host, &sata_port_info, shost);
  3876. if (ap) {
  3877. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3878. sata_port->ioa_cfg = ioa_cfg;
  3879. sata_port->ap = ap;
  3880. sata_port->res = res;
  3881. res->sata_port = sata_port;
  3882. ap->private_data = sata_port;
  3883. starget->hostdata = sata_port;
  3884. } else {
  3885. kfree(sata_port);
  3886. return -ENOMEM;
  3887. }
  3888. }
  3889. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3890. return 0;
  3891. }
  3892. /**
  3893. * ipr_target_destroy - Destroy a SCSI target
  3894. * @starget: scsi target struct
  3895. *
  3896. * If the device was a SATA device, this function frees the libata
  3897. * ATA port, else it does nothing.
  3898. *
  3899. **/
  3900. static void ipr_target_destroy(struct scsi_target *starget)
  3901. {
  3902. struct ipr_sata_port *sata_port = starget->hostdata;
  3903. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  3904. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) shost->hostdata;
  3905. if (ioa_cfg->sis64) {
  3906. if (!ipr_find_starget(starget)) {
  3907. if (starget->channel == IPR_ARRAY_VIRTUAL_BUS)
  3908. clear_bit(starget->id, ioa_cfg->array_ids);
  3909. else if (starget->channel == IPR_VSET_VIRTUAL_BUS)
  3910. clear_bit(starget->id, ioa_cfg->vset_ids);
  3911. else if (starget->channel == 0)
  3912. clear_bit(starget->id, ioa_cfg->target_ids);
  3913. }
  3914. }
  3915. if (sata_port) {
  3916. starget->hostdata = NULL;
  3917. ata_sas_port_destroy(sata_port->ap);
  3918. kfree(sata_port);
  3919. }
  3920. }
  3921. /**
  3922. * ipr_find_sdev - Find device based on bus/target/lun.
  3923. * @sdev: scsi device struct
  3924. *
  3925. * Return value:
  3926. * resource entry pointer if found / NULL if not found
  3927. **/
  3928. static struct ipr_resource_entry *ipr_find_sdev(struct scsi_device *sdev)
  3929. {
  3930. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3931. struct ipr_resource_entry *res;
  3932. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  3933. if ((res->bus == sdev->channel) &&
  3934. (res->target == sdev->id) &&
  3935. (res->lun == sdev->lun))
  3936. return res;
  3937. }
  3938. return NULL;
  3939. }
  3940. /**
  3941. * ipr_slave_destroy - Unconfigure a SCSI device
  3942. * @sdev: scsi device struct
  3943. *
  3944. * Return value:
  3945. * nothing
  3946. **/
  3947. static void ipr_slave_destroy(struct scsi_device *sdev)
  3948. {
  3949. struct ipr_resource_entry *res;
  3950. struct ipr_ioa_cfg *ioa_cfg;
  3951. unsigned long lock_flags = 0;
  3952. ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3953. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3954. res = (struct ipr_resource_entry *) sdev->hostdata;
  3955. if (res) {
  3956. if (res->sata_port)
  3957. res->sata_port->ap->link.device[0].class = ATA_DEV_NONE;
  3958. sdev->hostdata = NULL;
  3959. res->sdev = NULL;
  3960. res->sata_port = NULL;
  3961. }
  3962. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3963. }
  3964. /**
  3965. * ipr_slave_configure - Configure a SCSI device
  3966. * @sdev: scsi device struct
  3967. *
  3968. * This function configures the specified scsi device.
  3969. *
  3970. * Return value:
  3971. * 0 on success
  3972. **/
  3973. static int ipr_slave_configure(struct scsi_device *sdev)
  3974. {
  3975. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  3976. struct ipr_resource_entry *res;
  3977. struct ata_port *ap = NULL;
  3978. unsigned long lock_flags = 0;
  3979. char buffer[IPR_MAX_RES_PATH_LENGTH];
  3980. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  3981. res = sdev->hostdata;
  3982. if (res) {
  3983. if (ipr_is_af_dasd_device(res))
  3984. sdev->type = TYPE_RAID;
  3985. if (ipr_is_af_dasd_device(res) || ipr_is_ioa_resource(res)) {
  3986. sdev->scsi_level = 4;
  3987. sdev->no_uld_attach = 1;
  3988. }
  3989. if (ipr_is_vset_device(res)) {
  3990. blk_queue_rq_timeout(sdev->request_queue,
  3991. IPR_VSET_RW_TIMEOUT);
  3992. blk_queue_max_hw_sectors(sdev->request_queue, IPR_VSET_MAX_SECTORS);
  3993. }
  3994. if (ipr_is_gata(res) && res->sata_port)
  3995. ap = res->sata_port->ap;
  3996. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  3997. if (ap) {
  3998. scsi_adjust_queue_depth(sdev, 0, IPR_MAX_CMD_PER_ATA_LUN);
  3999. ata_sas_slave_configure(sdev, ap);
  4000. } else
  4001. scsi_adjust_queue_depth(sdev, 0, sdev->host->cmd_per_lun);
  4002. if (ioa_cfg->sis64)
  4003. sdev_printk(KERN_INFO, sdev, "Resource path: %s\n",
  4004. ipr_format_res_path(res->res_path, buffer,
  4005. sizeof(buffer)));
  4006. return 0;
  4007. }
  4008. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4009. return 0;
  4010. }
  4011. /**
  4012. * ipr_ata_slave_alloc - Prepare for commands to a SATA device
  4013. * @sdev: scsi device struct
  4014. *
  4015. * This function initializes an ATA port so that future commands
  4016. * sent through queuecommand will work.
  4017. *
  4018. * Return value:
  4019. * 0 on success
  4020. **/
  4021. static int ipr_ata_slave_alloc(struct scsi_device *sdev)
  4022. {
  4023. struct ipr_sata_port *sata_port = NULL;
  4024. int rc = -ENXIO;
  4025. ENTER;
  4026. if (sdev->sdev_target)
  4027. sata_port = sdev->sdev_target->hostdata;
  4028. if (sata_port) {
  4029. rc = ata_sas_port_init(sata_port->ap);
  4030. if (rc == 0)
  4031. rc = ata_sas_sync_probe(sata_port->ap);
  4032. }
  4033. if (rc)
  4034. ipr_slave_destroy(sdev);
  4035. LEAVE;
  4036. return rc;
  4037. }
  4038. /**
  4039. * ipr_slave_alloc - Prepare for commands to a device.
  4040. * @sdev: scsi device struct
  4041. *
  4042. * This function saves a pointer to the resource entry
  4043. * in the scsi device struct if the device exists. We
  4044. * can then use this pointer in ipr_queuecommand when
  4045. * handling new commands.
  4046. *
  4047. * Return value:
  4048. * 0 on success / -ENXIO if device does not exist
  4049. **/
  4050. static int ipr_slave_alloc(struct scsi_device *sdev)
  4051. {
  4052. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *) sdev->host->hostdata;
  4053. struct ipr_resource_entry *res;
  4054. unsigned long lock_flags;
  4055. int rc = -ENXIO;
  4056. sdev->hostdata = NULL;
  4057. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4058. res = ipr_find_sdev(sdev);
  4059. if (res) {
  4060. res->sdev = sdev;
  4061. res->add_to_ml = 0;
  4062. res->in_erp = 0;
  4063. sdev->hostdata = res;
  4064. if (!ipr_is_naca_model(res))
  4065. res->needs_sync_complete = 1;
  4066. rc = 0;
  4067. if (ipr_is_gata(res)) {
  4068. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4069. return ipr_ata_slave_alloc(sdev);
  4070. }
  4071. }
  4072. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4073. return rc;
  4074. }
  4075. /**
  4076. * ipr_eh_host_reset - Reset the host adapter
  4077. * @scsi_cmd: scsi command struct
  4078. *
  4079. * Return value:
  4080. * SUCCESS / FAILED
  4081. **/
  4082. static int __ipr_eh_host_reset(struct scsi_cmnd *scsi_cmd)
  4083. {
  4084. struct ipr_ioa_cfg *ioa_cfg;
  4085. int rc;
  4086. ENTER;
  4087. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  4088. if (!ioa_cfg->in_reset_reload) {
  4089. dev_err(&ioa_cfg->pdev->dev,
  4090. "Adapter being reset as a result of error recovery.\n");
  4091. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  4092. ioa_cfg->sdt_state = GET_DUMP;
  4093. }
  4094. rc = ipr_reset_reload(ioa_cfg, IPR_SHUTDOWN_ABBREV);
  4095. LEAVE;
  4096. return rc;
  4097. }
  4098. static int ipr_eh_host_reset(struct scsi_cmnd *cmd)
  4099. {
  4100. int rc;
  4101. spin_lock_irq(cmd->device->host->host_lock);
  4102. rc = __ipr_eh_host_reset(cmd);
  4103. spin_unlock_irq(cmd->device->host->host_lock);
  4104. return rc;
  4105. }
  4106. /**
  4107. * ipr_device_reset - Reset the device
  4108. * @ioa_cfg: ioa config struct
  4109. * @res: resource entry struct
  4110. *
  4111. * This function issues a device reset to the affected device.
  4112. * If the device is a SCSI device, a LUN reset will be sent
  4113. * to the device first. If that does not work, a target reset
  4114. * will be sent. If the device is a SATA device, a PHY reset will
  4115. * be sent.
  4116. *
  4117. * Return value:
  4118. * 0 on success / non-zero on failure
  4119. **/
  4120. static int ipr_device_reset(struct ipr_ioa_cfg *ioa_cfg,
  4121. struct ipr_resource_entry *res)
  4122. {
  4123. struct ipr_cmnd *ipr_cmd;
  4124. struct ipr_ioarcb *ioarcb;
  4125. struct ipr_cmd_pkt *cmd_pkt;
  4126. struct ipr_ioarcb_ata_regs *regs;
  4127. u32 ioasc;
  4128. ENTER;
  4129. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4130. ioarcb = &ipr_cmd->ioarcb;
  4131. cmd_pkt = &ioarcb->cmd_pkt;
  4132. if (ipr_cmd->ioa_cfg->sis64) {
  4133. regs = &ipr_cmd->i.ata_ioadl.regs;
  4134. ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
  4135. } else
  4136. regs = &ioarcb->u.add_data.u.regs;
  4137. ioarcb->res_handle = res->res_handle;
  4138. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4139. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  4140. if (ipr_is_gata(res)) {
  4141. cmd_pkt->cdb[2] = IPR_ATA_PHY_RESET;
  4142. ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(regs->flags));
  4143. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  4144. }
  4145. ipr_send_blocking_cmd(ipr_cmd, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  4146. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4147. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4148. if (ipr_is_gata(res) && res->sata_port && ioasc != IPR_IOASC_IOA_WAS_RESET) {
  4149. if (ipr_cmd->ioa_cfg->sis64)
  4150. memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
  4151. sizeof(struct ipr_ioasa_gata));
  4152. else
  4153. memcpy(&res->sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
  4154. sizeof(struct ipr_ioasa_gata));
  4155. }
  4156. LEAVE;
  4157. return IPR_IOASC_SENSE_KEY(ioasc) ? -EIO : 0;
  4158. }
  4159. /**
  4160. * ipr_sata_reset - Reset the SATA port
  4161. * @link: SATA link to reset
  4162. * @classes: class of the attached device
  4163. *
  4164. * This function issues a SATA phy reset to the affected ATA link.
  4165. *
  4166. * Return value:
  4167. * 0 on success / non-zero on failure
  4168. **/
  4169. static int ipr_sata_reset(struct ata_link *link, unsigned int *classes,
  4170. unsigned long deadline)
  4171. {
  4172. struct ipr_sata_port *sata_port = link->ap->private_data;
  4173. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  4174. struct ipr_resource_entry *res;
  4175. unsigned long lock_flags = 0;
  4176. int rc = -ENXIO;
  4177. ENTER;
  4178. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4179. while (ioa_cfg->in_reset_reload) {
  4180. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4181. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  4182. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4183. }
  4184. res = sata_port->res;
  4185. if (res) {
  4186. rc = ipr_device_reset(ioa_cfg, res);
  4187. *classes = res->ata_class;
  4188. }
  4189. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4190. LEAVE;
  4191. return rc;
  4192. }
  4193. /**
  4194. * ipr_eh_dev_reset - Reset the device
  4195. * @scsi_cmd: scsi command struct
  4196. *
  4197. * This function issues a device reset to the affected device.
  4198. * A LUN reset will be sent to the device first. If that does
  4199. * not work, a target reset will be sent.
  4200. *
  4201. * Return value:
  4202. * SUCCESS / FAILED
  4203. **/
  4204. static int __ipr_eh_dev_reset(struct scsi_cmnd *scsi_cmd)
  4205. {
  4206. struct ipr_cmnd *ipr_cmd;
  4207. struct ipr_ioa_cfg *ioa_cfg;
  4208. struct ipr_resource_entry *res;
  4209. struct ata_port *ap;
  4210. int rc = 0;
  4211. ENTER;
  4212. ioa_cfg = (struct ipr_ioa_cfg *) scsi_cmd->device->host->hostdata;
  4213. res = scsi_cmd->device->hostdata;
  4214. if (!res)
  4215. return FAILED;
  4216. /*
  4217. * If we are currently going through reset/reload, return failed. This will force the
  4218. * mid-layer to call ipr_eh_host_reset, which will then go to sleep and wait for the
  4219. * reset to complete
  4220. */
  4221. if (ioa_cfg->in_reset_reload)
  4222. return FAILED;
  4223. if (ioa_cfg->ioa_is_dead)
  4224. return FAILED;
  4225. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  4226. if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
  4227. if (ipr_cmd->scsi_cmd)
  4228. ipr_cmd->done = ipr_scsi_eh_done;
  4229. if (ipr_cmd->qc)
  4230. ipr_cmd->done = ipr_sata_eh_done;
  4231. if (ipr_cmd->qc && !(ipr_cmd->qc->flags & ATA_QCFLAG_FAILED)) {
  4232. ipr_cmd->qc->err_mask |= AC_ERR_TIMEOUT;
  4233. ipr_cmd->qc->flags |= ATA_QCFLAG_FAILED;
  4234. }
  4235. }
  4236. }
  4237. res->resetting_device = 1;
  4238. scmd_printk(KERN_ERR, scsi_cmd, "Resetting device\n");
  4239. if (ipr_is_gata(res) && res->sata_port) {
  4240. ap = res->sata_port->ap;
  4241. spin_unlock_irq(scsi_cmd->device->host->host_lock);
  4242. ata_std_error_handler(ap);
  4243. spin_lock_irq(scsi_cmd->device->host->host_lock);
  4244. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  4245. if (ipr_cmd->ioarcb.res_handle == res->res_handle) {
  4246. rc = -EIO;
  4247. break;
  4248. }
  4249. }
  4250. } else
  4251. rc = ipr_device_reset(ioa_cfg, res);
  4252. res->resetting_device = 0;
  4253. LEAVE;
  4254. return rc ? FAILED : SUCCESS;
  4255. }
  4256. static int ipr_eh_dev_reset(struct scsi_cmnd *cmd)
  4257. {
  4258. int rc;
  4259. spin_lock_irq(cmd->device->host->host_lock);
  4260. rc = __ipr_eh_dev_reset(cmd);
  4261. spin_unlock_irq(cmd->device->host->host_lock);
  4262. return rc;
  4263. }
  4264. /**
  4265. * ipr_bus_reset_done - Op done function for bus reset.
  4266. * @ipr_cmd: ipr command struct
  4267. *
  4268. * This function is the op done function for a bus reset
  4269. *
  4270. * Return value:
  4271. * none
  4272. **/
  4273. static void ipr_bus_reset_done(struct ipr_cmnd *ipr_cmd)
  4274. {
  4275. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4276. struct ipr_resource_entry *res;
  4277. ENTER;
  4278. if (!ioa_cfg->sis64)
  4279. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  4280. if (res->res_handle == ipr_cmd->ioarcb.res_handle) {
  4281. scsi_report_bus_reset(ioa_cfg->host, res->bus);
  4282. break;
  4283. }
  4284. }
  4285. /*
  4286. * If abort has not completed, indicate the reset has, else call the
  4287. * abort's done function to wake the sleeping eh thread
  4288. */
  4289. if (ipr_cmd->sibling->sibling)
  4290. ipr_cmd->sibling->sibling = NULL;
  4291. else
  4292. ipr_cmd->sibling->done(ipr_cmd->sibling);
  4293. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4294. LEAVE;
  4295. }
  4296. /**
  4297. * ipr_abort_timeout - An abort task has timed out
  4298. * @ipr_cmd: ipr command struct
  4299. *
  4300. * This function handles when an abort task times out. If this
  4301. * happens we issue a bus reset since we have resources tied
  4302. * up that must be freed before returning to the midlayer.
  4303. *
  4304. * Return value:
  4305. * none
  4306. **/
  4307. static void ipr_abort_timeout(struct ipr_cmnd *ipr_cmd)
  4308. {
  4309. struct ipr_cmnd *reset_cmd;
  4310. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4311. struct ipr_cmd_pkt *cmd_pkt;
  4312. unsigned long lock_flags = 0;
  4313. ENTER;
  4314. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4315. if (ipr_cmd->completion.done || ioa_cfg->in_reset_reload) {
  4316. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4317. return;
  4318. }
  4319. sdev_printk(KERN_ERR, ipr_cmd->u.sdev, "Abort timed out. Resetting bus.\n");
  4320. reset_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4321. ipr_cmd->sibling = reset_cmd;
  4322. reset_cmd->sibling = ipr_cmd;
  4323. reset_cmd->ioarcb.res_handle = ipr_cmd->ioarcb.res_handle;
  4324. cmd_pkt = &reset_cmd->ioarcb.cmd_pkt;
  4325. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4326. cmd_pkt->cdb[0] = IPR_RESET_DEVICE;
  4327. cmd_pkt->cdb[2] = IPR_RESET_TYPE_SELECT | IPR_BUS_RESET;
  4328. ipr_do_req(reset_cmd, ipr_bus_reset_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  4329. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4330. LEAVE;
  4331. }
  4332. /**
  4333. * ipr_cancel_op - Cancel specified op
  4334. * @scsi_cmd: scsi command struct
  4335. *
  4336. * This function cancels specified op.
  4337. *
  4338. * Return value:
  4339. * SUCCESS / FAILED
  4340. **/
  4341. static int ipr_cancel_op(struct scsi_cmnd *scsi_cmd)
  4342. {
  4343. struct ipr_cmnd *ipr_cmd;
  4344. struct ipr_ioa_cfg *ioa_cfg;
  4345. struct ipr_resource_entry *res;
  4346. struct ipr_cmd_pkt *cmd_pkt;
  4347. u32 ioasc, int_reg;
  4348. int op_found = 0;
  4349. ENTER;
  4350. ioa_cfg = (struct ipr_ioa_cfg *)scsi_cmd->device->host->hostdata;
  4351. res = scsi_cmd->device->hostdata;
  4352. /* If we are currently going through reset/reload, return failed.
  4353. * This will force the mid-layer to call ipr_eh_host_reset,
  4354. * which will then go to sleep and wait for the reset to complete
  4355. */
  4356. if (ioa_cfg->in_reset_reload || ioa_cfg->ioa_is_dead)
  4357. return FAILED;
  4358. if (!res)
  4359. return FAILED;
  4360. /*
  4361. * If we are aborting a timed out op, chances are that the timeout was caused
  4362. * by a still not detected EEH error. In such cases, reading a register will
  4363. * trigger the EEH recovery infrastructure.
  4364. */
  4365. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4366. if (!ipr_is_gscsi(res))
  4367. return FAILED;
  4368. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  4369. if (ipr_cmd->scsi_cmd == scsi_cmd) {
  4370. ipr_cmd->done = ipr_scsi_eh_done;
  4371. op_found = 1;
  4372. break;
  4373. }
  4374. }
  4375. if (!op_found)
  4376. return SUCCESS;
  4377. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  4378. ipr_cmd->ioarcb.res_handle = res->res_handle;
  4379. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  4380. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4381. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  4382. ipr_cmd->u.sdev = scsi_cmd->device;
  4383. scmd_printk(KERN_ERR, scsi_cmd, "Aborting command: %02X\n",
  4384. scsi_cmd->cmnd[0]);
  4385. ipr_send_blocking_cmd(ipr_cmd, ipr_abort_timeout, IPR_CANCEL_ALL_TIMEOUT);
  4386. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4387. /*
  4388. * If the abort task timed out and we sent a bus reset, we will get
  4389. * one the following responses to the abort
  4390. */
  4391. if (ioasc == IPR_IOASC_BUS_WAS_RESET || ioasc == IPR_IOASC_SYNC_REQUIRED) {
  4392. ioasc = 0;
  4393. ipr_trace;
  4394. }
  4395. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4396. if (!ipr_is_naca_model(res))
  4397. res->needs_sync_complete = 1;
  4398. LEAVE;
  4399. return IPR_IOASC_SENSE_KEY(ioasc) ? FAILED : SUCCESS;
  4400. }
  4401. /**
  4402. * ipr_eh_abort - Abort a single op
  4403. * @scsi_cmd: scsi command struct
  4404. *
  4405. * Return value:
  4406. * SUCCESS / FAILED
  4407. **/
  4408. static int ipr_eh_abort(struct scsi_cmnd *scsi_cmd)
  4409. {
  4410. unsigned long flags;
  4411. int rc;
  4412. ENTER;
  4413. spin_lock_irqsave(scsi_cmd->device->host->host_lock, flags);
  4414. rc = ipr_cancel_op(scsi_cmd);
  4415. spin_unlock_irqrestore(scsi_cmd->device->host->host_lock, flags);
  4416. LEAVE;
  4417. return rc;
  4418. }
  4419. /**
  4420. * ipr_handle_other_interrupt - Handle "other" interrupts
  4421. * @ioa_cfg: ioa config struct
  4422. * @int_reg: interrupt register
  4423. *
  4424. * Return value:
  4425. * IRQ_NONE / IRQ_HANDLED
  4426. **/
  4427. static irqreturn_t ipr_handle_other_interrupt(struct ipr_ioa_cfg *ioa_cfg,
  4428. u32 int_reg)
  4429. {
  4430. irqreturn_t rc = IRQ_HANDLED;
  4431. u32 int_mask_reg;
  4432. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
  4433. int_reg &= ~int_mask_reg;
  4434. /* If an interrupt on the adapter did not occur, ignore it.
  4435. * Or in the case of SIS 64, check for a stage change interrupt.
  4436. */
  4437. if ((int_reg & IPR_PCII_OPER_INTERRUPTS) == 0) {
  4438. if (ioa_cfg->sis64) {
  4439. int_mask_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  4440. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  4441. if (int_reg & IPR_PCII_IPL_STAGE_CHANGE) {
  4442. /* clear stage change */
  4443. writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.clr_interrupt_reg);
  4444. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg) & ~int_mask_reg;
  4445. list_del(&ioa_cfg->reset_cmd->queue);
  4446. del_timer(&ioa_cfg->reset_cmd->timer);
  4447. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  4448. return IRQ_HANDLED;
  4449. }
  4450. }
  4451. return IRQ_NONE;
  4452. }
  4453. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  4454. /* Mask the interrupt */
  4455. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.set_interrupt_mask_reg);
  4456. /* Clear the interrupt */
  4457. writel(IPR_PCII_IOA_TRANS_TO_OPER, ioa_cfg->regs.clr_interrupt_reg);
  4458. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  4459. list_del(&ioa_cfg->reset_cmd->queue);
  4460. del_timer(&ioa_cfg->reset_cmd->timer);
  4461. ipr_reset_ioa_job(ioa_cfg->reset_cmd);
  4462. } else if ((int_reg & IPR_PCII_HRRQ_UPDATED) == int_reg) {
  4463. if (ioa_cfg->clear_isr) {
  4464. if (ipr_debug && printk_ratelimit())
  4465. dev_err(&ioa_cfg->pdev->dev,
  4466. "Spurious interrupt detected. 0x%08X\n", int_reg);
  4467. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
  4468. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  4469. return IRQ_NONE;
  4470. }
  4471. } else {
  4472. if (int_reg & IPR_PCII_IOA_UNIT_CHECKED)
  4473. ioa_cfg->ioa_unit_checked = 1;
  4474. else
  4475. dev_err(&ioa_cfg->pdev->dev,
  4476. "Permanent IOA failure. 0x%08X\n", int_reg);
  4477. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  4478. ioa_cfg->sdt_state = GET_DUMP;
  4479. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  4480. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  4481. }
  4482. return rc;
  4483. }
  4484. /**
  4485. * ipr_isr_eh - Interrupt service routine error handler
  4486. * @ioa_cfg: ioa config struct
  4487. * @msg: message to log
  4488. *
  4489. * Return value:
  4490. * none
  4491. **/
  4492. static void ipr_isr_eh(struct ipr_ioa_cfg *ioa_cfg, char *msg)
  4493. {
  4494. ioa_cfg->errors_logged++;
  4495. dev_err(&ioa_cfg->pdev->dev, "%s\n", msg);
  4496. if (WAIT_FOR_DUMP == ioa_cfg->sdt_state)
  4497. ioa_cfg->sdt_state = GET_DUMP;
  4498. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  4499. }
  4500. /**
  4501. * ipr_isr - Interrupt service routine
  4502. * @irq: irq number
  4503. * @devp: pointer to ioa config struct
  4504. *
  4505. * Return value:
  4506. * IRQ_NONE / IRQ_HANDLED
  4507. **/
  4508. static irqreturn_t ipr_isr(int irq, void *devp)
  4509. {
  4510. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  4511. unsigned long lock_flags = 0;
  4512. u32 int_reg = 0;
  4513. u32 ioasc;
  4514. u16 cmd_index;
  4515. int num_hrrq = 0;
  4516. int irq_none = 0;
  4517. struct ipr_cmnd *ipr_cmd, *temp;
  4518. irqreturn_t rc = IRQ_NONE;
  4519. LIST_HEAD(doneq);
  4520. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  4521. /* If interrupts are disabled, ignore the interrupt */
  4522. if (!ioa_cfg->allow_interrupts) {
  4523. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4524. return IRQ_NONE;
  4525. }
  4526. while (1) {
  4527. ipr_cmd = NULL;
  4528. while ((be32_to_cpu(*ioa_cfg->hrrq_curr) & IPR_HRRQ_TOGGLE_BIT) ==
  4529. ioa_cfg->toggle_bit) {
  4530. cmd_index = (be32_to_cpu(*ioa_cfg->hrrq_curr) &
  4531. IPR_HRRQ_REQ_RESP_HANDLE_MASK) >> IPR_HRRQ_REQ_RESP_HANDLE_SHIFT;
  4532. if (unlikely(cmd_index >= IPR_NUM_CMD_BLKS)) {
  4533. ipr_isr_eh(ioa_cfg, "Invalid response handle from IOA");
  4534. rc = IRQ_HANDLED;
  4535. goto unlock_out;
  4536. }
  4537. ipr_cmd = ioa_cfg->ipr_cmnd_list[cmd_index];
  4538. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4539. ipr_trc_hook(ipr_cmd, IPR_TRACE_FINISH, ioasc);
  4540. list_move_tail(&ipr_cmd->queue, &doneq);
  4541. rc = IRQ_HANDLED;
  4542. if (ioa_cfg->hrrq_curr < ioa_cfg->hrrq_end) {
  4543. ioa_cfg->hrrq_curr++;
  4544. } else {
  4545. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  4546. ioa_cfg->toggle_bit ^= 1u;
  4547. }
  4548. }
  4549. if (ipr_cmd && !ioa_cfg->clear_isr)
  4550. break;
  4551. if (ipr_cmd != NULL) {
  4552. /* Clear the PCI interrupt */
  4553. num_hrrq = 0;
  4554. do {
  4555. writel(IPR_PCII_HRRQ_UPDATED, ioa_cfg->regs.clr_interrupt_reg32);
  4556. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  4557. } while (int_reg & IPR_PCII_HRRQ_UPDATED &&
  4558. num_hrrq++ < IPR_MAX_HRRQ_RETRIES);
  4559. } else if (rc == IRQ_NONE && irq_none == 0) {
  4560. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  4561. irq_none++;
  4562. } else if (num_hrrq == IPR_MAX_HRRQ_RETRIES &&
  4563. int_reg & IPR_PCII_HRRQ_UPDATED) {
  4564. ipr_isr_eh(ioa_cfg, "Error clearing HRRQ");
  4565. rc = IRQ_HANDLED;
  4566. goto unlock_out;
  4567. } else
  4568. break;
  4569. }
  4570. if (unlikely(rc == IRQ_NONE))
  4571. rc = ipr_handle_other_interrupt(ioa_cfg, int_reg);
  4572. unlock_out:
  4573. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  4574. list_for_each_entry_safe(ipr_cmd, temp, &doneq, queue) {
  4575. list_del(&ipr_cmd->queue);
  4576. del_timer(&ipr_cmd->timer);
  4577. ipr_cmd->fast_done(ipr_cmd);
  4578. }
  4579. return rc;
  4580. }
  4581. /**
  4582. * ipr_build_ioadl64 - Build a scatter/gather list and map the buffer
  4583. * @ioa_cfg: ioa config struct
  4584. * @ipr_cmd: ipr command struct
  4585. *
  4586. * Return value:
  4587. * 0 on success / -1 on failure
  4588. **/
  4589. static int ipr_build_ioadl64(struct ipr_ioa_cfg *ioa_cfg,
  4590. struct ipr_cmnd *ipr_cmd)
  4591. {
  4592. int i, nseg;
  4593. struct scatterlist *sg;
  4594. u32 length;
  4595. u32 ioadl_flags = 0;
  4596. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4597. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4598. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  4599. length = scsi_bufflen(scsi_cmd);
  4600. if (!length)
  4601. return 0;
  4602. nseg = scsi_dma_map(scsi_cmd);
  4603. if (nseg < 0) {
  4604. if (printk_ratelimit())
  4605. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  4606. return -1;
  4607. }
  4608. ipr_cmd->dma_use_sg = nseg;
  4609. ioarcb->data_transfer_length = cpu_to_be32(length);
  4610. ioarcb->ioadl_len =
  4611. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  4612. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  4613. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  4614. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4615. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE)
  4616. ioadl_flags = IPR_IOADL_FLAGS_READ;
  4617. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  4618. ioadl64[i].flags = cpu_to_be32(ioadl_flags);
  4619. ioadl64[i].data_len = cpu_to_be32(sg_dma_len(sg));
  4620. ioadl64[i].address = cpu_to_be64(sg_dma_address(sg));
  4621. }
  4622. ioadl64[i-1].flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  4623. return 0;
  4624. }
  4625. /**
  4626. * ipr_build_ioadl - Build a scatter/gather list and map the buffer
  4627. * @ioa_cfg: ioa config struct
  4628. * @ipr_cmd: ipr command struct
  4629. *
  4630. * Return value:
  4631. * 0 on success / -1 on failure
  4632. **/
  4633. static int ipr_build_ioadl(struct ipr_ioa_cfg *ioa_cfg,
  4634. struct ipr_cmnd *ipr_cmd)
  4635. {
  4636. int i, nseg;
  4637. struct scatterlist *sg;
  4638. u32 length;
  4639. u32 ioadl_flags = 0;
  4640. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4641. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4642. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  4643. length = scsi_bufflen(scsi_cmd);
  4644. if (!length)
  4645. return 0;
  4646. nseg = scsi_dma_map(scsi_cmd);
  4647. if (nseg < 0) {
  4648. dev_err(&ioa_cfg->pdev->dev, "pci_map_sg failed!\n");
  4649. return -1;
  4650. }
  4651. ipr_cmd->dma_use_sg = nseg;
  4652. if (scsi_cmd->sc_data_direction == DMA_TO_DEVICE) {
  4653. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  4654. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  4655. ioarcb->data_transfer_length = cpu_to_be32(length);
  4656. ioarcb->ioadl_len =
  4657. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  4658. } else if (scsi_cmd->sc_data_direction == DMA_FROM_DEVICE) {
  4659. ioadl_flags = IPR_IOADL_FLAGS_READ;
  4660. ioarcb->read_data_transfer_length = cpu_to_be32(length);
  4661. ioarcb->read_ioadl_len =
  4662. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  4663. }
  4664. if (ipr_cmd->dma_use_sg <= ARRAY_SIZE(ioarcb->u.add_data.u.ioadl)) {
  4665. ioadl = ioarcb->u.add_data.u.ioadl;
  4666. ioarcb->write_ioadl_addr = cpu_to_be32((ipr_cmd->dma_addr) +
  4667. offsetof(struct ipr_ioarcb, u.add_data));
  4668. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  4669. }
  4670. scsi_for_each_sg(scsi_cmd, sg, ipr_cmd->dma_use_sg, i) {
  4671. ioadl[i].flags_and_data_len =
  4672. cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  4673. ioadl[i].address = cpu_to_be32(sg_dma_address(sg));
  4674. }
  4675. ioadl[i-1].flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  4676. return 0;
  4677. }
  4678. /**
  4679. * ipr_get_task_attributes - Translate SPI Q-Tag to task attributes
  4680. * @scsi_cmd: scsi command struct
  4681. *
  4682. * Return value:
  4683. * task attributes
  4684. **/
  4685. static u8 ipr_get_task_attributes(struct scsi_cmnd *scsi_cmd)
  4686. {
  4687. u8 tag[2];
  4688. u8 rc = IPR_FLAGS_LO_UNTAGGED_TASK;
  4689. if (scsi_populate_tag_msg(scsi_cmd, tag)) {
  4690. switch (tag[0]) {
  4691. case MSG_SIMPLE_TAG:
  4692. rc = IPR_FLAGS_LO_SIMPLE_TASK;
  4693. break;
  4694. case MSG_HEAD_TAG:
  4695. rc = IPR_FLAGS_LO_HEAD_OF_Q_TASK;
  4696. break;
  4697. case MSG_ORDERED_TAG:
  4698. rc = IPR_FLAGS_LO_ORDERED_TASK;
  4699. break;
  4700. };
  4701. }
  4702. return rc;
  4703. }
  4704. /**
  4705. * ipr_erp_done - Process completion of ERP for a device
  4706. * @ipr_cmd: ipr command struct
  4707. *
  4708. * This function copies the sense buffer into the scsi_cmd
  4709. * struct and pushes the scsi_done function.
  4710. *
  4711. * Return value:
  4712. * nothing
  4713. **/
  4714. static void ipr_erp_done(struct ipr_cmnd *ipr_cmd)
  4715. {
  4716. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4717. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  4718. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  4719. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4720. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  4721. scsi_cmd->result |= (DID_ERROR << 16);
  4722. scmd_printk(KERN_ERR, scsi_cmd,
  4723. "Request Sense failed with IOASC: 0x%08X\n", ioasc);
  4724. } else {
  4725. memcpy(scsi_cmd->sense_buffer, ipr_cmd->sense_buffer,
  4726. SCSI_SENSE_BUFFERSIZE);
  4727. }
  4728. if (res) {
  4729. if (!ipr_is_naca_model(res))
  4730. res->needs_sync_complete = 1;
  4731. res->in_erp = 0;
  4732. }
  4733. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  4734. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  4735. scsi_cmd->scsi_done(scsi_cmd);
  4736. }
  4737. /**
  4738. * ipr_reinit_ipr_cmnd_for_erp - Re-initialize a cmnd block to be used for ERP
  4739. * @ipr_cmd: ipr command struct
  4740. *
  4741. * Return value:
  4742. * none
  4743. **/
  4744. static void ipr_reinit_ipr_cmnd_for_erp(struct ipr_cmnd *ipr_cmd)
  4745. {
  4746. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  4747. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  4748. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  4749. memset(&ioarcb->cmd_pkt, 0, sizeof(struct ipr_cmd_pkt));
  4750. ioarcb->data_transfer_length = 0;
  4751. ioarcb->read_data_transfer_length = 0;
  4752. ioarcb->ioadl_len = 0;
  4753. ioarcb->read_ioadl_len = 0;
  4754. ioasa->hdr.ioasc = 0;
  4755. ioasa->hdr.residual_data_len = 0;
  4756. if (ipr_cmd->ioa_cfg->sis64)
  4757. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  4758. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  4759. else {
  4760. ioarcb->write_ioadl_addr =
  4761. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  4762. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  4763. }
  4764. }
  4765. /**
  4766. * ipr_erp_request_sense - Send request sense to a device
  4767. * @ipr_cmd: ipr command struct
  4768. *
  4769. * This function sends a request sense to a device as a result
  4770. * of a check condition.
  4771. *
  4772. * Return value:
  4773. * nothing
  4774. **/
  4775. static void ipr_erp_request_sense(struct ipr_cmnd *ipr_cmd)
  4776. {
  4777. struct ipr_cmd_pkt *cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  4778. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4779. if (IPR_IOASC_SENSE_KEY(ioasc) > 0) {
  4780. ipr_erp_done(ipr_cmd);
  4781. return;
  4782. }
  4783. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  4784. cmd_pkt->request_type = IPR_RQTYPE_SCSICDB;
  4785. cmd_pkt->cdb[0] = REQUEST_SENSE;
  4786. cmd_pkt->cdb[4] = SCSI_SENSE_BUFFERSIZE;
  4787. cmd_pkt->flags_hi |= IPR_FLAGS_HI_SYNC_OVERRIDE;
  4788. cmd_pkt->flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  4789. cmd_pkt->timeout = cpu_to_be16(IPR_REQUEST_SENSE_TIMEOUT / HZ);
  4790. ipr_init_ioadl(ipr_cmd, ipr_cmd->sense_buffer_dma,
  4791. SCSI_SENSE_BUFFERSIZE, IPR_IOADL_FLAGS_READ_LAST);
  4792. ipr_do_req(ipr_cmd, ipr_erp_done, ipr_timeout,
  4793. IPR_REQUEST_SENSE_TIMEOUT * 2);
  4794. }
  4795. /**
  4796. * ipr_erp_cancel_all - Send cancel all to a device
  4797. * @ipr_cmd: ipr command struct
  4798. *
  4799. * This function sends a cancel all to a device to clear the
  4800. * queue. If we are running TCQ on the device, QERR is set to 1,
  4801. * which means all outstanding ops have been dropped on the floor.
  4802. * Cancel all will return them to us.
  4803. *
  4804. * Return value:
  4805. * nothing
  4806. **/
  4807. static void ipr_erp_cancel_all(struct ipr_cmnd *ipr_cmd)
  4808. {
  4809. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4810. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  4811. struct ipr_cmd_pkt *cmd_pkt;
  4812. res->in_erp = 1;
  4813. ipr_reinit_ipr_cmnd_for_erp(ipr_cmd);
  4814. if (!scsi_get_tag_type(scsi_cmd->device)) {
  4815. ipr_erp_request_sense(ipr_cmd);
  4816. return;
  4817. }
  4818. cmd_pkt = &ipr_cmd->ioarcb.cmd_pkt;
  4819. cmd_pkt->request_type = IPR_RQTYPE_IOACMD;
  4820. cmd_pkt->cdb[0] = IPR_CANCEL_ALL_REQUESTS;
  4821. ipr_do_req(ipr_cmd, ipr_erp_request_sense, ipr_timeout,
  4822. IPR_CANCEL_ALL_TIMEOUT);
  4823. }
  4824. /**
  4825. * ipr_dump_ioasa - Dump contents of IOASA
  4826. * @ioa_cfg: ioa config struct
  4827. * @ipr_cmd: ipr command struct
  4828. * @res: resource entry struct
  4829. *
  4830. * This function is invoked by the interrupt handler when ops
  4831. * fail. It will log the IOASA if appropriate. Only called
  4832. * for GPDD ops.
  4833. *
  4834. * Return value:
  4835. * none
  4836. **/
  4837. static void ipr_dump_ioasa(struct ipr_ioa_cfg *ioa_cfg,
  4838. struct ipr_cmnd *ipr_cmd, struct ipr_resource_entry *res)
  4839. {
  4840. int i;
  4841. u16 data_len;
  4842. u32 ioasc, fd_ioasc;
  4843. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  4844. __be32 *ioasa_data = (__be32 *)ioasa;
  4845. int error_index;
  4846. ioasc = be32_to_cpu(ioasa->hdr.ioasc) & IPR_IOASC_IOASC_MASK;
  4847. fd_ioasc = be32_to_cpu(ioasa->hdr.fd_ioasc) & IPR_IOASC_IOASC_MASK;
  4848. if (0 == ioasc)
  4849. return;
  4850. if (ioa_cfg->log_level < IPR_DEFAULT_LOG_LEVEL)
  4851. return;
  4852. if (ioasc == IPR_IOASC_BUS_WAS_RESET && fd_ioasc)
  4853. error_index = ipr_get_error(fd_ioasc);
  4854. else
  4855. error_index = ipr_get_error(ioasc);
  4856. if (ioa_cfg->log_level < IPR_MAX_LOG_LEVEL) {
  4857. /* Don't log an error if the IOA already logged one */
  4858. if (ioasa->hdr.ilid != 0)
  4859. return;
  4860. if (!ipr_is_gscsi(res))
  4861. return;
  4862. if (ipr_error_table[error_index].log_ioasa == 0)
  4863. return;
  4864. }
  4865. ipr_res_err(ioa_cfg, res, "%s\n", ipr_error_table[error_index].error);
  4866. data_len = be16_to_cpu(ioasa->hdr.ret_stat_len);
  4867. if (ioa_cfg->sis64 && sizeof(struct ipr_ioasa64) < data_len)
  4868. data_len = sizeof(struct ipr_ioasa64);
  4869. else if (!ioa_cfg->sis64 && sizeof(struct ipr_ioasa) < data_len)
  4870. data_len = sizeof(struct ipr_ioasa);
  4871. ipr_err("IOASA Dump:\n");
  4872. for (i = 0; i < data_len / 4; i += 4) {
  4873. ipr_err("%08X: %08X %08X %08X %08X\n", i*4,
  4874. be32_to_cpu(ioasa_data[i]),
  4875. be32_to_cpu(ioasa_data[i+1]),
  4876. be32_to_cpu(ioasa_data[i+2]),
  4877. be32_to_cpu(ioasa_data[i+3]));
  4878. }
  4879. }
  4880. /**
  4881. * ipr_gen_sense - Generate SCSI sense data from an IOASA
  4882. * @ioasa: IOASA
  4883. * @sense_buf: sense data buffer
  4884. *
  4885. * Return value:
  4886. * none
  4887. **/
  4888. static void ipr_gen_sense(struct ipr_cmnd *ipr_cmd)
  4889. {
  4890. u32 failing_lba;
  4891. u8 *sense_buf = ipr_cmd->scsi_cmd->sense_buffer;
  4892. struct ipr_resource_entry *res = ipr_cmd->scsi_cmd->device->hostdata;
  4893. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  4894. u32 ioasc = be32_to_cpu(ioasa->hdr.ioasc);
  4895. memset(sense_buf, 0, SCSI_SENSE_BUFFERSIZE);
  4896. if (ioasc >= IPR_FIRST_DRIVER_IOASC)
  4897. return;
  4898. ipr_cmd->scsi_cmd->result = SAM_STAT_CHECK_CONDITION;
  4899. if (ipr_is_vset_device(res) &&
  4900. ioasc == IPR_IOASC_MED_DO_NOT_REALLOC &&
  4901. ioasa->u.vset.failing_lba_hi != 0) {
  4902. sense_buf[0] = 0x72;
  4903. sense_buf[1] = IPR_IOASC_SENSE_KEY(ioasc);
  4904. sense_buf[2] = IPR_IOASC_SENSE_CODE(ioasc);
  4905. sense_buf[3] = IPR_IOASC_SENSE_QUAL(ioasc);
  4906. sense_buf[7] = 12;
  4907. sense_buf[8] = 0;
  4908. sense_buf[9] = 0x0A;
  4909. sense_buf[10] = 0x80;
  4910. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_hi);
  4911. sense_buf[12] = (failing_lba & 0xff000000) >> 24;
  4912. sense_buf[13] = (failing_lba & 0x00ff0000) >> 16;
  4913. sense_buf[14] = (failing_lba & 0x0000ff00) >> 8;
  4914. sense_buf[15] = failing_lba & 0x000000ff;
  4915. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  4916. sense_buf[16] = (failing_lba & 0xff000000) >> 24;
  4917. sense_buf[17] = (failing_lba & 0x00ff0000) >> 16;
  4918. sense_buf[18] = (failing_lba & 0x0000ff00) >> 8;
  4919. sense_buf[19] = failing_lba & 0x000000ff;
  4920. } else {
  4921. sense_buf[0] = 0x70;
  4922. sense_buf[2] = IPR_IOASC_SENSE_KEY(ioasc);
  4923. sense_buf[12] = IPR_IOASC_SENSE_CODE(ioasc);
  4924. sense_buf[13] = IPR_IOASC_SENSE_QUAL(ioasc);
  4925. /* Illegal request */
  4926. if ((IPR_IOASC_SENSE_KEY(ioasc) == 0x05) &&
  4927. (be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_FIELD_POINTER_VALID)) {
  4928. sense_buf[7] = 10; /* additional length */
  4929. /* IOARCB was in error */
  4930. if (IPR_IOASC_SENSE_CODE(ioasc) == 0x24)
  4931. sense_buf[15] = 0xC0;
  4932. else /* Parameter data was invalid */
  4933. sense_buf[15] = 0x80;
  4934. sense_buf[16] =
  4935. ((IPR_FIELD_POINTER_MASK &
  4936. be32_to_cpu(ioasa->hdr.ioasc_specific)) >> 8) & 0xff;
  4937. sense_buf[17] =
  4938. (IPR_FIELD_POINTER_MASK &
  4939. be32_to_cpu(ioasa->hdr.ioasc_specific)) & 0xff;
  4940. } else {
  4941. if (ioasc == IPR_IOASC_MED_DO_NOT_REALLOC) {
  4942. if (ipr_is_vset_device(res))
  4943. failing_lba = be32_to_cpu(ioasa->u.vset.failing_lba_lo);
  4944. else
  4945. failing_lba = be32_to_cpu(ioasa->u.dasd.failing_lba);
  4946. sense_buf[0] |= 0x80; /* Or in the Valid bit */
  4947. sense_buf[3] = (failing_lba & 0xff000000) >> 24;
  4948. sense_buf[4] = (failing_lba & 0x00ff0000) >> 16;
  4949. sense_buf[5] = (failing_lba & 0x0000ff00) >> 8;
  4950. sense_buf[6] = failing_lba & 0x000000ff;
  4951. }
  4952. sense_buf[7] = 6; /* additional length */
  4953. }
  4954. }
  4955. }
  4956. /**
  4957. * ipr_get_autosense - Copy autosense data to sense buffer
  4958. * @ipr_cmd: ipr command struct
  4959. *
  4960. * This function copies the autosense buffer to the buffer
  4961. * in the scsi_cmd, if there is autosense available.
  4962. *
  4963. * Return value:
  4964. * 1 if autosense was available / 0 if not
  4965. **/
  4966. static int ipr_get_autosense(struct ipr_cmnd *ipr_cmd)
  4967. {
  4968. struct ipr_ioasa *ioasa = &ipr_cmd->s.ioasa;
  4969. struct ipr_ioasa64 *ioasa64 = &ipr_cmd->s.ioasa64;
  4970. if ((be32_to_cpu(ioasa->hdr.ioasc_specific) & IPR_AUTOSENSE_VALID) == 0)
  4971. return 0;
  4972. if (ipr_cmd->ioa_cfg->sis64)
  4973. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa64->auto_sense.data,
  4974. min_t(u16, be16_to_cpu(ioasa64->auto_sense.auto_sense_len),
  4975. SCSI_SENSE_BUFFERSIZE));
  4976. else
  4977. memcpy(ipr_cmd->scsi_cmd->sense_buffer, ioasa->auto_sense.data,
  4978. min_t(u16, be16_to_cpu(ioasa->auto_sense.auto_sense_len),
  4979. SCSI_SENSE_BUFFERSIZE));
  4980. return 1;
  4981. }
  4982. /**
  4983. * ipr_erp_start - Process an error response for a SCSI op
  4984. * @ioa_cfg: ioa config struct
  4985. * @ipr_cmd: ipr command struct
  4986. *
  4987. * This function determines whether or not to initiate ERP
  4988. * on the affected device.
  4989. *
  4990. * Return value:
  4991. * nothing
  4992. **/
  4993. static void ipr_erp_start(struct ipr_ioa_cfg *ioa_cfg,
  4994. struct ipr_cmnd *ipr_cmd)
  4995. {
  4996. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  4997. struct ipr_resource_entry *res = scsi_cmd->device->hostdata;
  4998. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  4999. u32 masked_ioasc = ioasc & IPR_IOASC_IOASC_MASK;
  5000. if (!res) {
  5001. ipr_scsi_eh_done(ipr_cmd);
  5002. return;
  5003. }
  5004. if (!ipr_is_gscsi(res) && masked_ioasc != IPR_IOASC_HW_DEV_BUS_STATUS)
  5005. ipr_gen_sense(ipr_cmd);
  5006. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  5007. switch (masked_ioasc) {
  5008. case IPR_IOASC_ABORTED_CMD_TERM_BY_HOST:
  5009. if (ipr_is_naca_model(res))
  5010. scsi_cmd->result |= (DID_ABORT << 16);
  5011. else
  5012. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5013. break;
  5014. case IPR_IOASC_IR_RESOURCE_HANDLE:
  5015. case IPR_IOASC_IR_NO_CMDS_TO_2ND_IOA:
  5016. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  5017. break;
  5018. case IPR_IOASC_HW_SEL_TIMEOUT:
  5019. scsi_cmd->result |= (DID_NO_CONNECT << 16);
  5020. if (!ipr_is_naca_model(res))
  5021. res->needs_sync_complete = 1;
  5022. break;
  5023. case IPR_IOASC_SYNC_REQUIRED:
  5024. if (!res->in_erp)
  5025. res->needs_sync_complete = 1;
  5026. scsi_cmd->result |= (DID_IMM_RETRY << 16);
  5027. break;
  5028. case IPR_IOASC_MED_DO_NOT_REALLOC: /* prevent retries */
  5029. case IPR_IOASA_IR_DUAL_IOA_DISABLED:
  5030. scsi_cmd->result |= (DID_PASSTHROUGH << 16);
  5031. break;
  5032. case IPR_IOASC_BUS_WAS_RESET:
  5033. case IPR_IOASC_BUS_WAS_RESET_BY_OTHER:
  5034. /*
  5035. * Report the bus reset and ask for a retry. The device
  5036. * will give CC/UA the next command.
  5037. */
  5038. if (!res->resetting_device)
  5039. scsi_report_bus_reset(ioa_cfg->host, scsi_cmd->device->channel);
  5040. scsi_cmd->result |= (DID_ERROR << 16);
  5041. if (!ipr_is_naca_model(res))
  5042. res->needs_sync_complete = 1;
  5043. break;
  5044. case IPR_IOASC_HW_DEV_BUS_STATUS:
  5045. scsi_cmd->result |= IPR_IOASC_SENSE_STATUS(ioasc);
  5046. if (IPR_IOASC_SENSE_STATUS(ioasc) == SAM_STAT_CHECK_CONDITION) {
  5047. if (!ipr_get_autosense(ipr_cmd)) {
  5048. if (!ipr_is_naca_model(res)) {
  5049. ipr_erp_cancel_all(ipr_cmd);
  5050. return;
  5051. }
  5052. }
  5053. }
  5054. if (!ipr_is_naca_model(res))
  5055. res->needs_sync_complete = 1;
  5056. break;
  5057. case IPR_IOASC_NR_INIT_CMD_REQUIRED:
  5058. break;
  5059. default:
  5060. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  5061. scsi_cmd->result |= (DID_ERROR << 16);
  5062. if (!ipr_is_vset_device(res) && !ipr_is_naca_model(res))
  5063. res->needs_sync_complete = 1;
  5064. break;
  5065. }
  5066. scsi_dma_unmap(ipr_cmd->scsi_cmd);
  5067. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5068. scsi_cmd->scsi_done(scsi_cmd);
  5069. }
  5070. /**
  5071. * ipr_scsi_done - mid-layer done function
  5072. * @ipr_cmd: ipr command struct
  5073. *
  5074. * This function is invoked by the interrupt handler for
  5075. * ops generated by the SCSI mid-layer
  5076. *
  5077. * Return value:
  5078. * none
  5079. **/
  5080. static void ipr_scsi_done(struct ipr_cmnd *ipr_cmd)
  5081. {
  5082. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5083. struct scsi_cmnd *scsi_cmd = ipr_cmd->scsi_cmd;
  5084. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5085. unsigned long lock_flags;
  5086. scsi_set_resid(scsi_cmd, be32_to_cpu(ipr_cmd->s.ioasa.hdr.residual_data_len));
  5087. if (likely(IPR_IOASC_SENSE_KEY(ioasc) == 0)) {
  5088. scsi_dma_unmap(scsi_cmd);
  5089. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5090. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5091. scsi_cmd->scsi_done(scsi_cmd);
  5092. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5093. } else {
  5094. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  5095. ipr_erp_start(ioa_cfg, ipr_cmd);
  5096. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  5097. }
  5098. }
  5099. /**
  5100. * ipr_queuecommand - Queue a mid-layer request
  5101. * @shost: scsi host struct
  5102. * @scsi_cmd: scsi command struct
  5103. *
  5104. * This function queues a request generated by the mid-layer.
  5105. *
  5106. * Return value:
  5107. * 0 on success
  5108. * SCSI_MLQUEUE_DEVICE_BUSY if device is busy
  5109. * SCSI_MLQUEUE_HOST_BUSY if host is busy
  5110. **/
  5111. static int ipr_queuecommand(struct Scsi_Host *shost,
  5112. struct scsi_cmnd *scsi_cmd)
  5113. {
  5114. struct ipr_ioa_cfg *ioa_cfg;
  5115. struct ipr_resource_entry *res;
  5116. struct ipr_ioarcb *ioarcb;
  5117. struct ipr_cmnd *ipr_cmd;
  5118. unsigned long lock_flags;
  5119. int rc;
  5120. ioa_cfg = (struct ipr_ioa_cfg *)shost->hostdata;
  5121. spin_lock_irqsave(shost->host_lock, lock_flags);
  5122. scsi_cmd->result = (DID_OK << 16);
  5123. res = scsi_cmd->device->hostdata;
  5124. /*
  5125. * We are currently blocking all devices due to a host reset
  5126. * We have told the host to stop giving us new requests, but
  5127. * ERP ops don't count. FIXME
  5128. */
  5129. if (unlikely(!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead)) {
  5130. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5131. return SCSI_MLQUEUE_HOST_BUSY;
  5132. }
  5133. /*
  5134. * FIXME - Create scsi_set_host_offline interface
  5135. * and the ioa_is_dead check can be removed
  5136. */
  5137. if (unlikely(ioa_cfg->ioa_is_dead || !res)) {
  5138. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5139. goto err_nodev;
  5140. }
  5141. if (ipr_is_gata(res) && res->sata_port) {
  5142. rc = ata_sas_queuecmd(scsi_cmd, res->sata_port->ap);
  5143. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5144. return rc;
  5145. }
  5146. ipr_cmd = __ipr_get_free_ipr_cmnd(ioa_cfg);
  5147. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5148. ipr_init_ipr_cmnd(ipr_cmd, ipr_scsi_done);
  5149. ioarcb = &ipr_cmd->ioarcb;
  5150. memcpy(ioarcb->cmd_pkt.cdb, scsi_cmd->cmnd, scsi_cmd->cmd_len);
  5151. ipr_cmd->scsi_cmd = scsi_cmd;
  5152. ipr_cmd->done = ipr_scsi_eh_done;
  5153. if (ipr_is_gscsi(res) || ipr_is_vset_device(res)) {
  5154. if (scsi_cmd->underflow == 0)
  5155. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5156. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  5157. if (ipr_is_gscsi(res))
  5158. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_DELAY_AFTER_RST;
  5159. ioarcb->cmd_pkt.flags_lo |= IPR_FLAGS_LO_ALIGNED_BFR;
  5160. ioarcb->cmd_pkt.flags_lo |= ipr_get_task_attributes(scsi_cmd);
  5161. }
  5162. if (scsi_cmd->cmnd[0] >= 0xC0 &&
  5163. (!ipr_is_gscsi(res) || scsi_cmd->cmnd[0] == IPR_QUERY_RSRC_STATE))
  5164. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5165. if (ioa_cfg->sis64)
  5166. rc = ipr_build_ioadl64(ioa_cfg, ipr_cmd);
  5167. else
  5168. rc = ipr_build_ioadl(ioa_cfg, ipr_cmd);
  5169. spin_lock_irqsave(shost->host_lock, lock_flags);
  5170. if (unlikely(rc || (!ioa_cfg->allow_cmds && !ioa_cfg->ioa_is_dead))) {
  5171. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5172. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5173. if (!rc)
  5174. scsi_dma_unmap(scsi_cmd);
  5175. return SCSI_MLQUEUE_HOST_BUSY;
  5176. }
  5177. if (unlikely(ioa_cfg->ioa_is_dead)) {
  5178. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5179. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5180. scsi_dma_unmap(scsi_cmd);
  5181. goto err_nodev;
  5182. }
  5183. ioarcb->res_handle = res->res_handle;
  5184. if (res->needs_sync_complete) {
  5185. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_SYNC_COMPLETE;
  5186. res->needs_sync_complete = 0;
  5187. }
  5188. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  5189. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
  5190. ipr_send_command(ipr_cmd);
  5191. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5192. return 0;
  5193. err_nodev:
  5194. spin_lock_irqsave(shost->host_lock, lock_flags);
  5195. memset(scsi_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  5196. scsi_cmd->result = (DID_NO_CONNECT << 16);
  5197. scsi_cmd->scsi_done(scsi_cmd);
  5198. spin_unlock_irqrestore(shost->host_lock, lock_flags);
  5199. return 0;
  5200. }
  5201. /**
  5202. * ipr_ioctl - IOCTL handler
  5203. * @sdev: scsi device struct
  5204. * @cmd: IOCTL cmd
  5205. * @arg: IOCTL arg
  5206. *
  5207. * Return value:
  5208. * 0 on success / other on failure
  5209. **/
  5210. static int ipr_ioctl(struct scsi_device *sdev, int cmd, void __user *arg)
  5211. {
  5212. struct ipr_resource_entry *res;
  5213. res = (struct ipr_resource_entry *)sdev->hostdata;
  5214. if (res && ipr_is_gata(res)) {
  5215. if (cmd == HDIO_GET_IDENTITY)
  5216. return -ENOTTY;
  5217. return ata_sas_scsi_ioctl(res->sata_port->ap, sdev, cmd, arg);
  5218. }
  5219. return -EINVAL;
  5220. }
  5221. /**
  5222. * ipr_info - Get information about the card/driver
  5223. * @scsi_host: scsi host struct
  5224. *
  5225. * Return value:
  5226. * pointer to buffer with description string
  5227. **/
  5228. static const char *ipr_ioa_info(struct Scsi_Host *host)
  5229. {
  5230. static char buffer[512];
  5231. struct ipr_ioa_cfg *ioa_cfg;
  5232. unsigned long lock_flags = 0;
  5233. ioa_cfg = (struct ipr_ioa_cfg *) host->hostdata;
  5234. spin_lock_irqsave(host->host_lock, lock_flags);
  5235. sprintf(buffer, "IBM %X Storage Adapter", ioa_cfg->type);
  5236. spin_unlock_irqrestore(host->host_lock, lock_flags);
  5237. return buffer;
  5238. }
  5239. static struct scsi_host_template driver_template = {
  5240. .module = THIS_MODULE,
  5241. .name = "IPR",
  5242. .info = ipr_ioa_info,
  5243. .ioctl = ipr_ioctl,
  5244. .queuecommand = ipr_queuecommand,
  5245. .eh_abort_handler = ipr_eh_abort,
  5246. .eh_device_reset_handler = ipr_eh_dev_reset,
  5247. .eh_host_reset_handler = ipr_eh_host_reset,
  5248. .slave_alloc = ipr_slave_alloc,
  5249. .slave_configure = ipr_slave_configure,
  5250. .slave_destroy = ipr_slave_destroy,
  5251. .target_alloc = ipr_target_alloc,
  5252. .target_destroy = ipr_target_destroy,
  5253. .change_queue_depth = ipr_change_queue_depth,
  5254. .change_queue_type = ipr_change_queue_type,
  5255. .bios_param = ipr_biosparam,
  5256. .can_queue = IPR_MAX_COMMANDS,
  5257. .this_id = -1,
  5258. .sg_tablesize = IPR_MAX_SGLIST,
  5259. .max_sectors = IPR_IOA_MAX_SECTORS,
  5260. .cmd_per_lun = IPR_MAX_CMD_PER_LUN,
  5261. .use_clustering = ENABLE_CLUSTERING,
  5262. .shost_attrs = ipr_ioa_attrs,
  5263. .sdev_attrs = ipr_dev_attrs,
  5264. .proc_name = IPR_NAME
  5265. };
  5266. /**
  5267. * ipr_ata_phy_reset - libata phy_reset handler
  5268. * @ap: ata port to reset
  5269. *
  5270. **/
  5271. static void ipr_ata_phy_reset(struct ata_port *ap)
  5272. {
  5273. unsigned long flags;
  5274. struct ipr_sata_port *sata_port = ap->private_data;
  5275. struct ipr_resource_entry *res = sata_port->res;
  5276. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5277. int rc;
  5278. ENTER;
  5279. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5280. while (ioa_cfg->in_reset_reload) {
  5281. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5282. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5283. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5284. }
  5285. if (!ioa_cfg->allow_cmds)
  5286. goto out_unlock;
  5287. rc = ipr_device_reset(ioa_cfg, res);
  5288. if (rc) {
  5289. ap->link.device[0].class = ATA_DEV_NONE;
  5290. goto out_unlock;
  5291. }
  5292. ap->link.device[0].class = res->ata_class;
  5293. if (ap->link.device[0].class == ATA_DEV_UNKNOWN)
  5294. ap->link.device[0].class = ATA_DEV_NONE;
  5295. out_unlock:
  5296. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5297. LEAVE;
  5298. }
  5299. /**
  5300. * ipr_ata_post_internal - Cleanup after an internal command
  5301. * @qc: ATA queued command
  5302. *
  5303. * Return value:
  5304. * none
  5305. **/
  5306. static void ipr_ata_post_internal(struct ata_queued_cmd *qc)
  5307. {
  5308. struct ipr_sata_port *sata_port = qc->ap->private_data;
  5309. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5310. struct ipr_cmnd *ipr_cmd;
  5311. unsigned long flags;
  5312. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5313. while (ioa_cfg->in_reset_reload) {
  5314. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5315. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  5316. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  5317. }
  5318. list_for_each_entry(ipr_cmd, &ioa_cfg->pending_q, queue) {
  5319. if (ipr_cmd->qc == qc) {
  5320. ipr_device_reset(ioa_cfg, sata_port->res);
  5321. break;
  5322. }
  5323. }
  5324. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  5325. }
  5326. /**
  5327. * ipr_copy_sata_tf - Copy a SATA taskfile to an IOA data structure
  5328. * @regs: destination
  5329. * @tf: source ATA taskfile
  5330. *
  5331. * Return value:
  5332. * none
  5333. **/
  5334. static void ipr_copy_sata_tf(struct ipr_ioarcb_ata_regs *regs,
  5335. struct ata_taskfile *tf)
  5336. {
  5337. regs->feature = tf->feature;
  5338. regs->nsect = tf->nsect;
  5339. regs->lbal = tf->lbal;
  5340. regs->lbam = tf->lbam;
  5341. regs->lbah = tf->lbah;
  5342. regs->device = tf->device;
  5343. regs->command = tf->command;
  5344. regs->hob_feature = tf->hob_feature;
  5345. regs->hob_nsect = tf->hob_nsect;
  5346. regs->hob_lbal = tf->hob_lbal;
  5347. regs->hob_lbam = tf->hob_lbam;
  5348. regs->hob_lbah = tf->hob_lbah;
  5349. regs->ctl = tf->ctl;
  5350. }
  5351. /**
  5352. * ipr_sata_done - done function for SATA commands
  5353. * @ipr_cmd: ipr command struct
  5354. *
  5355. * This function is invoked by the interrupt handler for
  5356. * ops generated by the SCSI mid-layer to SATA devices
  5357. *
  5358. * Return value:
  5359. * none
  5360. **/
  5361. static void ipr_sata_done(struct ipr_cmnd *ipr_cmd)
  5362. {
  5363. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5364. struct ata_queued_cmd *qc = ipr_cmd->qc;
  5365. struct ipr_sata_port *sata_port = qc->ap->private_data;
  5366. struct ipr_resource_entry *res = sata_port->res;
  5367. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5368. if (ipr_cmd->ioa_cfg->sis64)
  5369. memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa64.u.gata,
  5370. sizeof(struct ipr_ioasa_gata));
  5371. else
  5372. memcpy(&sata_port->ioasa, &ipr_cmd->s.ioasa.u.gata,
  5373. sizeof(struct ipr_ioasa_gata));
  5374. ipr_dump_ioasa(ioa_cfg, ipr_cmd, res);
  5375. if (be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc_specific) & IPR_ATA_DEVICE_WAS_RESET)
  5376. scsi_report_device_reset(ioa_cfg->host, res->bus, res->target);
  5377. if (IPR_IOASC_SENSE_KEY(ioasc) > RECOVERED_ERROR)
  5378. qc->err_mask |= __ac_err_mask(sata_port->ioasa.status);
  5379. else
  5380. qc->err_mask |= ac_err_mask(sata_port->ioasa.status);
  5381. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5382. ata_qc_complete(qc);
  5383. }
  5384. /**
  5385. * ipr_build_ata_ioadl64 - Build an ATA scatter/gather list
  5386. * @ipr_cmd: ipr command struct
  5387. * @qc: ATA queued command
  5388. *
  5389. **/
  5390. static void ipr_build_ata_ioadl64(struct ipr_cmnd *ipr_cmd,
  5391. struct ata_queued_cmd *qc)
  5392. {
  5393. u32 ioadl_flags = 0;
  5394. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5395. struct ipr_ioadl64_desc *ioadl64 = ipr_cmd->i.ioadl64;
  5396. struct ipr_ioadl64_desc *last_ioadl64 = NULL;
  5397. int len = qc->nbytes;
  5398. struct scatterlist *sg;
  5399. unsigned int si;
  5400. dma_addr_t dma_addr = ipr_cmd->dma_addr;
  5401. if (len == 0)
  5402. return;
  5403. if (qc->dma_dir == DMA_TO_DEVICE) {
  5404. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  5405. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5406. } else if (qc->dma_dir == DMA_FROM_DEVICE)
  5407. ioadl_flags = IPR_IOADL_FLAGS_READ;
  5408. ioarcb->data_transfer_length = cpu_to_be32(len);
  5409. ioarcb->ioadl_len =
  5410. cpu_to_be32(sizeof(struct ipr_ioadl64_desc) * ipr_cmd->dma_use_sg);
  5411. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  5412. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ata_ioadl));
  5413. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  5414. ioadl64->flags = cpu_to_be32(ioadl_flags);
  5415. ioadl64->data_len = cpu_to_be32(sg_dma_len(sg));
  5416. ioadl64->address = cpu_to_be64(sg_dma_address(sg));
  5417. last_ioadl64 = ioadl64;
  5418. ioadl64++;
  5419. }
  5420. if (likely(last_ioadl64))
  5421. last_ioadl64->flags |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  5422. }
  5423. /**
  5424. * ipr_build_ata_ioadl - Build an ATA scatter/gather list
  5425. * @ipr_cmd: ipr command struct
  5426. * @qc: ATA queued command
  5427. *
  5428. **/
  5429. static void ipr_build_ata_ioadl(struct ipr_cmnd *ipr_cmd,
  5430. struct ata_queued_cmd *qc)
  5431. {
  5432. u32 ioadl_flags = 0;
  5433. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5434. struct ipr_ioadl_desc *ioadl = ipr_cmd->i.ioadl;
  5435. struct ipr_ioadl_desc *last_ioadl = NULL;
  5436. int len = qc->nbytes;
  5437. struct scatterlist *sg;
  5438. unsigned int si;
  5439. if (len == 0)
  5440. return;
  5441. if (qc->dma_dir == DMA_TO_DEVICE) {
  5442. ioadl_flags = IPR_IOADL_FLAGS_WRITE;
  5443. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5444. ioarcb->data_transfer_length = cpu_to_be32(len);
  5445. ioarcb->ioadl_len =
  5446. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  5447. } else if (qc->dma_dir == DMA_FROM_DEVICE) {
  5448. ioadl_flags = IPR_IOADL_FLAGS_READ;
  5449. ioarcb->read_data_transfer_length = cpu_to_be32(len);
  5450. ioarcb->read_ioadl_len =
  5451. cpu_to_be32(sizeof(struct ipr_ioadl_desc) * ipr_cmd->dma_use_sg);
  5452. }
  5453. for_each_sg(qc->sg, sg, qc->n_elem, si) {
  5454. ioadl->flags_and_data_len = cpu_to_be32(ioadl_flags | sg_dma_len(sg));
  5455. ioadl->address = cpu_to_be32(sg_dma_address(sg));
  5456. last_ioadl = ioadl;
  5457. ioadl++;
  5458. }
  5459. if (likely(last_ioadl))
  5460. last_ioadl->flags_and_data_len |= cpu_to_be32(IPR_IOADL_FLAGS_LAST);
  5461. }
  5462. /**
  5463. * ipr_qc_issue - Issue a SATA qc to a device
  5464. * @qc: queued command
  5465. *
  5466. * Return value:
  5467. * 0 if success
  5468. **/
  5469. static unsigned int ipr_qc_issue(struct ata_queued_cmd *qc)
  5470. {
  5471. struct ata_port *ap = qc->ap;
  5472. struct ipr_sata_port *sata_port = ap->private_data;
  5473. struct ipr_resource_entry *res = sata_port->res;
  5474. struct ipr_ioa_cfg *ioa_cfg = sata_port->ioa_cfg;
  5475. struct ipr_cmnd *ipr_cmd;
  5476. struct ipr_ioarcb *ioarcb;
  5477. struct ipr_ioarcb_ata_regs *regs;
  5478. if (unlikely(!ioa_cfg->allow_cmds || ioa_cfg->ioa_is_dead))
  5479. return AC_ERR_SYSTEM;
  5480. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  5481. ioarcb = &ipr_cmd->ioarcb;
  5482. if (ioa_cfg->sis64) {
  5483. regs = &ipr_cmd->i.ata_ioadl.regs;
  5484. ioarcb->add_cmd_parms_offset = cpu_to_be16(sizeof(*ioarcb));
  5485. } else
  5486. regs = &ioarcb->u.add_data.u.regs;
  5487. memset(regs, 0, sizeof(*regs));
  5488. ioarcb->add_cmd_parms_len = cpu_to_be16(sizeof(*regs));
  5489. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  5490. ipr_cmd->qc = qc;
  5491. ipr_cmd->done = ipr_sata_done;
  5492. ipr_cmd->ioarcb.res_handle = res->res_handle;
  5493. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_ATA_PASSTHRU;
  5494. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_LINK_DESC;
  5495. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_NO_ULEN_CHK;
  5496. ipr_cmd->dma_use_sg = qc->n_elem;
  5497. if (ioa_cfg->sis64)
  5498. ipr_build_ata_ioadl64(ipr_cmd, qc);
  5499. else
  5500. ipr_build_ata_ioadl(ipr_cmd, qc);
  5501. regs->flags |= IPR_ATA_FLAG_STATUS_ON_GOOD_COMPLETION;
  5502. ipr_copy_sata_tf(regs, &qc->tf);
  5503. memcpy(ioarcb->cmd_pkt.cdb, qc->cdb, IPR_MAX_CDB_LEN);
  5504. ipr_trc_hook(ipr_cmd, IPR_TRACE_START, IPR_GET_RES_PHYS_LOC(res));
  5505. switch (qc->tf.protocol) {
  5506. case ATA_PROT_NODATA:
  5507. case ATA_PROT_PIO:
  5508. break;
  5509. case ATA_PROT_DMA:
  5510. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  5511. break;
  5512. case ATAPI_PROT_PIO:
  5513. case ATAPI_PROT_NODATA:
  5514. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  5515. break;
  5516. case ATAPI_PROT_DMA:
  5517. regs->flags |= IPR_ATA_FLAG_PACKET_CMD;
  5518. regs->flags |= IPR_ATA_FLAG_XFER_TYPE_DMA;
  5519. break;
  5520. default:
  5521. WARN_ON(1);
  5522. return AC_ERR_INVALID;
  5523. }
  5524. ipr_send_command(ipr_cmd);
  5525. return 0;
  5526. }
  5527. /**
  5528. * ipr_qc_fill_rtf - Read result TF
  5529. * @qc: ATA queued command
  5530. *
  5531. * Return value:
  5532. * true
  5533. **/
  5534. static bool ipr_qc_fill_rtf(struct ata_queued_cmd *qc)
  5535. {
  5536. struct ipr_sata_port *sata_port = qc->ap->private_data;
  5537. struct ipr_ioasa_gata *g = &sata_port->ioasa;
  5538. struct ata_taskfile *tf = &qc->result_tf;
  5539. tf->feature = g->error;
  5540. tf->nsect = g->nsect;
  5541. tf->lbal = g->lbal;
  5542. tf->lbam = g->lbam;
  5543. tf->lbah = g->lbah;
  5544. tf->device = g->device;
  5545. tf->command = g->status;
  5546. tf->hob_nsect = g->hob_nsect;
  5547. tf->hob_lbal = g->hob_lbal;
  5548. tf->hob_lbam = g->hob_lbam;
  5549. tf->hob_lbah = g->hob_lbah;
  5550. tf->ctl = g->alt_status;
  5551. return true;
  5552. }
  5553. static struct ata_port_operations ipr_sata_ops = {
  5554. .phy_reset = ipr_ata_phy_reset,
  5555. .hardreset = ipr_sata_reset,
  5556. .post_internal_cmd = ipr_ata_post_internal,
  5557. .qc_prep = ata_noop_qc_prep,
  5558. .qc_issue = ipr_qc_issue,
  5559. .qc_fill_rtf = ipr_qc_fill_rtf,
  5560. .port_start = ata_sas_port_start,
  5561. .port_stop = ata_sas_port_stop
  5562. };
  5563. static struct ata_port_info sata_port_info = {
  5564. .flags = ATA_FLAG_SATA | ATA_FLAG_PIO_DMA,
  5565. .pio_mask = ATA_PIO4_ONLY,
  5566. .mwdma_mask = ATA_MWDMA2,
  5567. .udma_mask = ATA_UDMA6,
  5568. .port_ops = &ipr_sata_ops
  5569. };
  5570. #ifdef CONFIG_PPC_PSERIES
  5571. static const u16 ipr_blocked_processors[] = {
  5572. PVR_NORTHSTAR,
  5573. PVR_PULSAR,
  5574. PVR_POWER4,
  5575. PVR_ICESTAR,
  5576. PVR_SSTAR,
  5577. PVR_POWER4p,
  5578. PVR_630,
  5579. PVR_630p
  5580. };
  5581. /**
  5582. * ipr_invalid_adapter - Determine if this adapter is supported on this hardware
  5583. * @ioa_cfg: ioa cfg struct
  5584. *
  5585. * Adapters that use Gemstone revision < 3.1 do not work reliably on
  5586. * certain pSeries hardware. This function determines if the given
  5587. * adapter is in one of these confgurations or not.
  5588. *
  5589. * Return value:
  5590. * 1 if adapter is not supported / 0 if adapter is supported
  5591. **/
  5592. static int ipr_invalid_adapter(struct ipr_ioa_cfg *ioa_cfg)
  5593. {
  5594. int i;
  5595. if ((ioa_cfg->type == 0x5702) && (ioa_cfg->pdev->revision < 4)) {
  5596. for (i = 0; i < ARRAY_SIZE(ipr_blocked_processors); i++) {
  5597. if (pvr_version_is(ipr_blocked_processors[i]))
  5598. return 1;
  5599. }
  5600. }
  5601. return 0;
  5602. }
  5603. #else
  5604. #define ipr_invalid_adapter(ioa_cfg) 0
  5605. #endif
  5606. /**
  5607. * ipr_ioa_bringdown_done - IOA bring down completion.
  5608. * @ipr_cmd: ipr command struct
  5609. *
  5610. * This function processes the completion of an adapter bring down.
  5611. * It wakes any reset sleepers.
  5612. *
  5613. * Return value:
  5614. * IPR_RC_JOB_RETURN
  5615. **/
  5616. static int ipr_ioa_bringdown_done(struct ipr_cmnd *ipr_cmd)
  5617. {
  5618. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5619. ENTER;
  5620. ioa_cfg->in_reset_reload = 0;
  5621. ioa_cfg->reset_retries = 0;
  5622. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5623. wake_up_all(&ioa_cfg->reset_wait_q);
  5624. spin_unlock_irq(ioa_cfg->host->host_lock);
  5625. scsi_unblock_requests(ioa_cfg->host);
  5626. spin_lock_irq(ioa_cfg->host->host_lock);
  5627. LEAVE;
  5628. return IPR_RC_JOB_RETURN;
  5629. }
  5630. /**
  5631. * ipr_ioa_reset_done - IOA reset completion.
  5632. * @ipr_cmd: ipr command struct
  5633. *
  5634. * This function processes the completion of an adapter reset.
  5635. * It schedules any necessary mid-layer add/removes and
  5636. * wakes any reset sleepers.
  5637. *
  5638. * Return value:
  5639. * IPR_RC_JOB_RETURN
  5640. **/
  5641. static int ipr_ioa_reset_done(struct ipr_cmnd *ipr_cmd)
  5642. {
  5643. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5644. struct ipr_resource_entry *res;
  5645. struct ipr_hostrcb *hostrcb, *temp;
  5646. int i = 0;
  5647. ENTER;
  5648. ioa_cfg->in_reset_reload = 0;
  5649. ioa_cfg->allow_cmds = 1;
  5650. ioa_cfg->reset_cmd = NULL;
  5651. ioa_cfg->doorbell |= IPR_RUNTIME_RESET;
  5652. list_for_each_entry(res, &ioa_cfg->used_res_q, queue) {
  5653. if (ioa_cfg->allow_ml_add_del && (res->add_to_ml || res->del_from_ml)) {
  5654. ipr_trace;
  5655. break;
  5656. }
  5657. }
  5658. schedule_work(&ioa_cfg->work_q);
  5659. list_for_each_entry_safe(hostrcb, temp, &ioa_cfg->hostrcb_free_q, queue) {
  5660. list_del(&hostrcb->queue);
  5661. if (i++ < IPR_NUM_LOG_HCAMS)
  5662. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_LOG_DATA, hostrcb);
  5663. else
  5664. ipr_send_hcam(ioa_cfg, IPR_HCAM_CDB_OP_CODE_CONFIG_CHANGE, hostrcb);
  5665. }
  5666. scsi_report_bus_reset(ioa_cfg->host, IPR_VSET_BUS);
  5667. dev_info(&ioa_cfg->pdev->dev, "IOA initialized.\n");
  5668. ioa_cfg->reset_retries = 0;
  5669. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5670. wake_up_all(&ioa_cfg->reset_wait_q);
  5671. spin_unlock(ioa_cfg->host->host_lock);
  5672. scsi_unblock_requests(ioa_cfg->host);
  5673. spin_lock(ioa_cfg->host->host_lock);
  5674. if (!ioa_cfg->allow_cmds)
  5675. scsi_block_requests(ioa_cfg->host);
  5676. LEAVE;
  5677. return IPR_RC_JOB_RETURN;
  5678. }
  5679. /**
  5680. * ipr_set_sup_dev_dflt - Initialize a Set Supported Device buffer
  5681. * @supported_dev: supported device struct
  5682. * @vpids: vendor product id struct
  5683. *
  5684. * Return value:
  5685. * none
  5686. **/
  5687. static void ipr_set_sup_dev_dflt(struct ipr_supported_device *supported_dev,
  5688. struct ipr_std_inq_vpids *vpids)
  5689. {
  5690. memset(supported_dev, 0, sizeof(struct ipr_supported_device));
  5691. memcpy(&supported_dev->vpids, vpids, sizeof(struct ipr_std_inq_vpids));
  5692. supported_dev->num_records = 1;
  5693. supported_dev->data_length =
  5694. cpu_to_be16(sizeof(struct ipr_supported_device));
  5695. supported_dev->reserved = 0;
  5696. }
  5697. /**
  5698. * ipr_set_supported_devs - Send Set Supported Devices for a device
  5699. * @ipr_cmd: ipr command struct
  5700. *
  5701. * This function sends a Set Supported Devices to the adapter
  5702. *
  5703. * Return value:
  5704. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5705. **/
  5706. static int ipr_set_supported_devs(struct ipr_cmnd *ipr_cmd)
  5707. {
  5708. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5709. struct ipr_supported_device *supp_dev = &ioa_cfg->vpd_cbs->supp_dev;
  5710. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5711. struct ipr_resource_entry *res = ipr_cmd->u.res;
  5712. ipr_cmd->job_step = ipr_ioa_reset_done;
  5713. list_for_each_entry_continue(res, &ioa_cfg->used_res_q, queue) {
  5714. if (!ipr_is_scsi_disk(res))
  5715. continue;
  5716. ipr_cmd->u.res = res;
  5717. ipr_set_sup_dev_dflt(supp_dev, &res->std_inq_data.vpids);
  5718. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  5719. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5720. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  5721. ioarcb->cmd_pkt.cdb[0] = IPR_SET_SUPPORTED_DEVICES;
  5722. ioarcb->cmd_pkt.cdb[1] = IPR_SET_ALL_SUPPORTED_DEVICES;
  5723. ioarcb->cmd_pkt.cdb[7] = (sizeof(struct ipr_supported_device) >> 8) & 0xff;
  5724. ioarcb->cmd_pkt.cdb[8] = sizeof(struct ipr_supported_device) & 0xff;
  5725. ipr_init_ioadl(ipr_cmd,
  5726. ioa_cfg->vpd_cbs_dma +
  5727. offsetof(struct ipr_misc_cbs, supp_dev),
  5728. sizeof(struct ipr_supported_device),
  5729. IPR_IOADL_FLAGS_WRITE_LAST);
  5730. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  5731. IPR_SET_SUP_DEVICE_TIMEOUT);
  5732. if (!ioa_cfg->sis64)
  5733. ipr_cmd->job_step = ipr_set_supported_devs;
  5734. return IPR_RC_JOB_RETURN;
  5735. }
  5736. return IPR_RC_JOB_CONTINUE;
  5737. }
  5738. /**
  5739. * ipr_get_mode_page - Locate specified mode page
  5740. * @mode_pages: mode page buffer
  5741. * @page_code: page code to find
  5742. * @len: minimum required length for mode page
  5743. *
  5744. * Return value:
  5745. * pointer to mode page / NULL on failure
  5746. **/
  5747. static void *ipr_get_mode_page(struct ipr_mode_pages *mode_pages,
  5748. u32 page_code, u32 len)
  5749. {
  5750. struct ipr_mode_page_hdr *mode_hdr;
  5751. u32 page_length;
  5752. u32 length;
  5753. if (!mode_pages || (mode_pages->hdr.length == 0))
  5754. return NULL;
  5755. length = (mode_pages->hdr.length + 1) - 4 - mode_pages->hdr.block_desc_len;
  5756. mode_hdr = (struct ipr_mode_page_hdr *)
  5757. (mode_pages->data + mode_pages->hdr.block_desc_len);
  5758. while (length) {
  5759. if (IPR_GET_MODE_PAGE_CODE(mode_hdr) == page_code) {
  5760. if (mode_hdr->page_length >= (len - sizeof(struct ipr_mode_page_hdr)))
  5761. return mode_hdr;
  5762. break;
  5763. } else {
  5764. page_length = (sizeof(struct ipr_mode_page_hdr) +
  5765. mode_hdr->page_length);
  5766. length -= page_length;
  5767. mode_hdr = (struct ipr_mode_page_hdr *)
  5768. ((unsigned long)mode_hdr + page_length);
  5769. }
  5770. }
  5771. return NULL;
  5772. }
  5773. /**
  5774. * ipr_check_term_power - Check for term power errors
  5775. * @ioa_cfg: ioa config struct
  5776. * @mode_pages: IOAFP mode pages buffer
  5777. *
  5778. * Check the IOAFP's mode page 28 for term power errors
  5779. *
  5780. * Return value:
  5781. * nothing
  5782. **/
  5783. static void ipr_check_term_power(struct ipr_ioa_cfg *ioa_cfg,
  5784. struct ipr_mode_pages *mode_pages)
  5785. {
  5786. int i;
  5787. int entry_length;
  5788. struct ipr_dev_bus_entry *bus;
  5789. struct ipr_mode_page28 *mode_page;
  5790. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  5791. sizeof(struct ipr_mode_page28));
  5792. entry_length = mode_page->entry_length;
  5793. bus = mode_page->bus;
  5794. for (i = 0; i < mode_page->num_entries; i++) {
  5795. if (bus->flags & IPR_SCSI_ATTR_NO_TERM_PWR) {
  5796. dev_err(&ioa_cfg->pdev->dev,
  5797. "Term power is absent on scsi bus %d\n",
  5798. bus->res_addr.bus);
  5799. }
  5800. bus = (struct ipr_dev_bus_entry *)((char *)bus + entry_length);
  5801. }
  5802. }
  5803. /**
  5804. * ipr_scsi_bus_speed_limit - Limit the SCSI speed based on SES table
  5805. * @ioa_cfg: ioa config struct
  5806. *
  5807. * Looks through the config table checking for SES devices. If
  5808. * the SES device is in the SES table indicating a maximum SCSI
  5809. * bus speed, the speed is limited for the bus.
  5810. *
  5811. * Return value:
  5812. * none
  5813. **/
  5814. static void ipr_scsi_bus_speed_limit(struct ipr_ioa_cfg *ioa_cfg)
  5815. {
  5816. u32 max_xfer_rate;
  5817. int i;
  5818. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  5819. max_xfer_rate = ipr_get_max_scsi_speed(ioa_cfg, i,
  5820. ioa_cfg->bus_attr[i].bus_width);
  5821. if (max_xfer_rate < ioa_cfg->bus_attr[i].max_xfer_rate)
  5822. ioa_cfg->bus_attr[i].max_xfer_rate = max_xfer_rate;
  5823. }
  5824. }
  5825. /**
  5826. * ipr_modify_ioafp_mode_page_28 - Modify IOAFP Mode Page 28
  5827. * @ioa_cfg: ioa config struct
  5828. * @mode_pages: mode page 28 buffer
  5829. *
  5830. * Updates mode page 28 based on driver configuration
  5831. *
  5832. * Return value:
  5833. * none
  5834. **/
  5835. static void ipr_modify_ioafp_mode_page_28(struct ipr_ioa_cfg *ioa_cfg,
  5836. struct ipr_mode_pages *mode_pages)
  5837. {
  5838. int i, entry_length;
  5839. struct ipr_dev_bus_entry *bus;
  5840. struct ipr_bus_attributes *bus_attr;
  5841. struct ipr_mode_page28 *mode_page;
  5842. mode_page = ipr_get_mode_page(mode_pages, 0x28,
  5843. sizeof(struct ipr_mode_page28));
  5844. entry_length = mode_page->entry_length;
  5845. /* Loop for each device bus entry */
  5846. for (i = 0, bus = mode_page->bus;
  5847. i < mode_page->num_entries;
  5848. i++, bus = (struct ipr_dev_bus_entry *)((u8 *)bus + entry_length)) {
  5849. if (bus->res_addr.bus > IPR_MAX_NUM_BUSES) {
  5850. dev_err(&ioa_cfg->pdev->dev,
  5851. "Invalid resource address reported: 0x%08X\n",
  5852. IPR_GET_PHYS_LOC(bus->res_addr));
  5853. continue;
  5854. }
  5855. bus_attr = &ioa_cfg->bus_attr[i];
  5856. bus->extended_reset_delay = IPR_EXTENDED_RESET_DELAY;
  5857. bus->bus_width = bus_attr->bus_width;
  5858. bus->max_xfer_rate = cpu_to_be32(bus_attr->max_xfer_rate);
  5859. bus->flags &= ~IPR_SCSI_ATTR_QAS_MASK;
  5860. if (bus_attr->qas_enabled)
  5861. bus->flags |= IPR_SCSI_ATTR_ENABLE_QAS;
  5862. else
  5863. bus->flags |= IPR_SCSI_ATTR_DISABLE_QAS;
  5864. }
  5865. }
  5866. /**
  5867. * ipr_build_mode_select - Build a mode select command
  5868. * @ipr_cmd: ipr command struct
  5869. * @res_handle: resource handle to send command to
  5870. * @parm: Byte 2 of Mode Sense command
  5871. * @dma_addr: DMA buffer address
  5872. * @xfer_len: data transfer length
  5873. *
  5874. * Return value:
  5875. * none
  5876. **/
  5877. static void ipr_build_mode_select(struct ipr_cmnd *ipr_cmd,
  5878. __be32 res_handle, u8 parm,
  5879. dma_addr_t dma_addr, u8 xfer_len)
  5880. {
  5881. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5882. ioarcb->res_handle = res_handle;
  5883. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  5884. ioarcb->cmd_pkt.flags_hi |= IPR_FLAGS_HI_WRITE_NOT_READ;
  5885. ioarcb->cmd_pkt.cdb[0] = MODE_SELECT;
  5886. ioarcb->cmd_pkt.cdb[1] = parm;
  5887. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  5888. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_WRITE_LAST);
  5889. }
  5890. /**
  5891. * ipr_ioafp_mode_select_page28 - Issue Mode Select Page 28 to IOA
  5892. * @ipr_cmd: ipr command struct
  5893. *
  5894. * This function sets up the SCSI bus attributes and sends
  5895. * a Mode Select for Page 28 to activate them.
  5896. *
  5897. * Return value:
  5898. * IPR_RC_JOB_RETURN
  5899. **/
  5900. static int ipr_ioafp_mode_select_page28(struct ipr_cmnd *ipr_cmd)
  5901. {
  5902. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5903. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  5904. int length;
  5905. ENTER;
  5906. ipr_scsi_bus_speed_limit(ioa_cfg);
  5907. ipr_check_term_power(ioa_cfg, mode_pages);
  5908. ipr_modify_ioafp_mode_page_28(ioa_cfg, mode_pages);
  5909. length = mode_pages->hdr.length + 1;
  5910. mode_pages->hdr.length = 0;
  5911. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  5912. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  5913. length);
  5914. ipr_cmd->job_step = ipr_set_supported_devs;
  5915. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  5916. struct ipr_resource_entry, queue);
  5917. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  5918. LEAVE;
  5919. return IPR_RC_JOB_RETURN;
  5920. }
  5921. /**
  5922. * ipr_build_mode_sense - Builds a mode sense command
  5923. * @ipr_cmd: ipr command struct
  5924. * @res: resource entry struct
  5925. * @parm: Byte 2 of mode sense command
  5926. * @dma_addr: DMA address of mode sense buffer
  5927. * @xfer_len: Size of DMA buffer
  5928. *
  5929. * Return value:
  5930. * none
  5931. **/
  5932. static void ipr_build_mode_sense(struct ipr_cmnd *ipr_cmd,
  5933. __be32 res_handle,
  5934. u8 parm, dma_addr_t dma_addr, u8 xfer_len)
  5935. {
  5936. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  5937. ioarcb->res_handle = res_handle;
  5938. ioarcb->cmd_pkt.cdb[0] = MODE_SENSE;
  5939. ioarcb->cmd_pkt.cdb[2] = parm;
  5940. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  5941. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  5942. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
  5943. }
  5944. /**
  5945. * ipr_reset_cmd_failed - Handle failure of IOA reset command
  5946. * @ipr_cmd: ipr command struct
  5947. *
  5948. * This function handles the failure of an IOA bringup command.
  5949. *
  5950. * Return value:
  5951. * IPR_RC_JOB_RETURN
  5952. **/
  5953. static int ipr_reset_cmd_failed(struct ipr_cmnd *ipr_cmd)
  5954. {
  5955. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5956. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5957. dev_err(&ioa_cfg->pdev->dev,
  5958. "0x%02X failed with IOASC: 0x%08X\n",
  5959. ipr_cmd->ioarcb.cmd_pkt.cdb[0], ioasc);
  5960. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  5961. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  5962. return IPR_RC_JOB_RETURN;
  5963. }
  5964. /**
  5965. * ipr_reset_mode_sense_failed - Handle failure of IOAFP mode sense
  5966. * @ipr_cmd: ipr command struct
  5967. *
  5968. * This function handles the failure of a Mode Sense to the IOAFP.
  5969. * Some adapters do not handle all mode pages.
  5970. *
  5971. * Return value:
  5972. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  5973. **/
  5974. static int ipr_reset_mode_sense_failed(struct ipr_cmnd *ipr_cmd)
  5975. {
  5976. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5977. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  5978. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  5979. ipr_cmd->job_step = ipr_set_supported_devs;
  5980. ipr_cmd->u.res = list_entry(ioa_cfg->used_res_q.next,
  5981. struct ipr_resource_entry, queue);
  5982. return IPR_RC_JOB_CONTINUE;
  5983. }
  5984. return ipr_reset_cmd_failed(ipr_cmd);
  5985. }
  5986. /**
  5987. * ipr_ioafp_mode_sense_page28 - Issue Mode Sense Page 28 to IOA
  5988. * @ipr_cmd: ipr command struct
  5989. *
  5990. * This function send a Page 28 mode sense to the IOA to
  5991. * retrieve SCSI bus attributes.
  5992. *
  5993. * Return value:
  5994. * IPR_RC_JOB_RETURN
  5995. **/
  5996. static int ipr_ioafp_mode_sense_page28(struct ipr_cmnd *ipr_cmd)
  5997. {
  5998. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  5999. ENTER;
  6000. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  6001. 0x28, ioa_cfg->vpd_cbs_dma +
  6002. offsetof(struct ipr_misc_cbs, mode_pages),
  6003. sizeof(struct ipr_mode_pages));
  6004. ipr_cmd->job_step = ipr_ioafp_mode_select_page28;
  6005. ipr_cmd->job_step_failed = ipr_reset_mode_sense_failed;
  6006. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6007. LEAVE;
  6008. return IPR_RC_JOB_RETURN;
  6009. }
  6010. /**
  6011. * ipr_ioafp_mode_select_page24 - Issue Mode Select to IOA
  6012. * @ipr_cmd: ipr command struct
  6013. *
  6014. * This function enables dual IOA RAID support if possible.
  6015. *
  6016. * Return value:
  6017. * IPR_RC_JOB_RETURN
  6018. **/
  6019. static int ipr_ioafp_mode_select_page24(struct ipr_cmnd *ipr_cmd)
  6020. {
  6021. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6022. struct ipr_mode_pages *mode_pages = &ioa_cfg->vpd_cbs->mode_pages;
  6023. struct ipr_mode_page24 *mode_page;
  6024. int length;
  6025. ENTER;
  6026. mode_page = ipr_get_mode_page(mode_pages, 0x24,
  6027. sizeof(struct ipr_mode_page24));
  6028. if (mode_page)
  6029. mode_page->flags |= IPR_ENABLE_DUAL_IOA_AF;
  6030. length = mode_pages->hdr.length + 1;
  6031. mode_pages->hdr.length = 0;
  6032. ipr_build_mode_select(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE), 0x11,
  6033. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, mode_pages),
  6034. length);
  6035. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6036. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6037. LEAVE;
  6038. return IPR_RC_JOB_RETURN;
  6039. }
  6040. /**
  6041. * ipr_reset_mode_sense_page24_failed - Handle failure of IOAFP mode sense
  6042. * @ipr_cmd: ipr command struct
  6043. *
  6044. * This function handles the failure of a Mode Sense to the IOAFP.
  6045. * Some adapters do not handle all mode pages.
  6046. *
  6047. * Return value:
  6048. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6049. **/
  6050. static int ipr_reset_mode_sense_page24_failed(struct ipr_cmnd *ipr_cmd)
  6051. {
  6052. u32 ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  6053. if (ioasc == IPR_IOASC_IR_INVALID_REQ_TYPE_OR_PKT) {
  6054. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6055. return IPR_RC_JOB_CONTINUE;
  6056. }
  6057. return ipr_reset_cmd_failed(ipr_cmd);
  6058. }
  6059. /**
  6060. * ipr_ioafp_mode_sense_page24 - Issue Page 24 Mode Sense to IOA
  6061. * @ipr_cmd: ipr command struct
  6062. *
  6063. * This function send a mode sense to the IOA to retrieve
  6064. * the IOA Advanced Function Control mode page.
  6065. *
  6066. * Return value:
  6067. * IPR_RC_JOB_RETURN
  6068. **/
  6069. static int ipr_ioafp_mode_sense_page24(struct ipr_cmnd *ipr_cmd)
  6070. {
  6071. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6072. ENTER;
  6073. ipr_build_mode_sense(ipr_cmd, cpu_to_be32(IPR_IOA_RES_HANDLE),
  6074. 0x24, ioa_cfg->vpd_cbs_dma +
  6075. offsetof(struct ipr_misc_cbs, mode_pages),
  6076. sizeof(struct ipr_mode_pages));
  6077. ipr_cmd->job_step = ipr_ioafp_mode_select_page24;
  6078. ipr_cmd->job_step_failed = ipr_reset_mode_sense_page24_failed;
  6079. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6080. LEAVE;
  6081. return IPR_RC_JOB_RETURN;
  6082. }
  6083. /**
  6084. * ipr_init_res_table - Initialize the resource table
  6085. * @ipr_cmd: ipr command struct
  6086. *
  6087. * This function looks through the existing resource table, comparing
  6088. * it with the config table. This function will take care of old/new
  6089. * devices and schedule adding/removing them from the mid-layer
  6090. * as appropriate.
  6091. *
  6092. * Return value:
  6093. * IPR_RC_JOB_CONTINUE
  6094. **/
  6095. static int ipr_init_res_table(struct ipr_cmnd *ipr_cmd)
  6096. {
  6097. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6098. struct ipr_resource_entry *res, *temp;
  6099. struct ipr_config_table_entry_wrapper cfgtew;
  6100. int entries, found, flag, i;
  6101. LIST_HEAD(old_res);
  6102. ENTER;
  6103. if (ioa_cfg->sis64)
  6104. flag = ioa_cfg->u.cfg_table64->hdr64.flags;
  6105. else
  6106. flag = ioa_cfg->u.cfg_table->hdr.flags;
  6107. if (flag & IPR_UCODE_DOWNLOAD_REQ)
  6108. dev_err(&ioa_cfg->pdev->dev, "Microcode download required\n");
  6109. list_for_each_entry_safe(res, temp, &ioa_cfg->used_res_q, queue)
  6110. list_move_tail(&res->queue, &old_res);
  6111. if (ioa_cfg->sis64)
  6112. entries = be16_to_cpu(ioa_cfg->u.cfg_table64->hdr64.num_entries);
  6113. else
  6114. entries = ioa_cfg->u.cfg_table->hdr.num_entries;
  6115. for (i = 0; i < entries; i++) {
  6116. if (ioa_cfg->sis64)
  6117. cfgtew.u.cfgte64 = &ioa_cfg->u.cfg_table64->dev[i];
  6118. else
  6119. cfgtew.u.cfgte = &ioa_cfg->u.cfg_table->dev[i];
  6120. found = 0;
  6121. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6122. if (ipr_is_same_device(res, &cfgtew)) {
  6123. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6124. found = 1;
  6125. break;
  6126. }
  6127. }
  6128. if (!found) {
  6129. if (list_empty(&ioa_cfg->free_res_q)) {
  6130. dev_err(&ioa_cfg->pdev->dev, "Too many devices attached\n");
  6131. break;
  6132. }
  6133. found = 1;
  6134. res = list_entry(ioa_cfg->free_res_q.next,
  6135. struct ipr_resource_entry, queue);
  6136. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6137. ipr_init_res_entry(res, &cfgtew);
  6138. res->add_to_ml = 1;
  6139. } else if (res->sdev && (ipr_is_vset_device(res) || ipr_is_scsi_disk(res)))
  6140. res->sdev->allow_restart = 1;
  6141. if (found)
  6142. ipr_update_res_entry(res, &cfgtew);
  6143. }
  6144. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6145. if (res->sdev) {
  6146. res->del_from_ml = 1;
  6147. res->res_handle = IPR_INVALID_RES_HANDLE;
  6148. list_move_tail(&res->queue, &ioa_cfg->used_res_q);
  6149. }
  6150. }
  6151. list_for_each_entry_safe(res, temp, &old_res, queue) {
  6152. ipr_clear_res_target(res);
  6153. list_move_tail(&res->queue, &ioa_cfg->free_res_q);
  6154. }
  6155. if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  6156. ipr_cmd->job_step = ipr_ioafp_mode_sense_page24;
  6157. else
  6158. ipr_cmd->job_step = ipr_ioafp_mode_sense_page28;
  6159. LEAVE;
  6160. return IPR_RC_JOB_CONTINUE;
  6161. }
  6162. /**
  6163. * ipr_ioafp_query_ioa_cfg - Send a Query IOA Config to the adapter.
  6164. * @ipr_cmd: ipr command struct
  6165. *
  6166. * This function sends a Query IOA Configuration command
  6167. * to the adapter to retrieve the IOA configuration table.
  6168. *
  6169. * Return value:
  6170. * IPR_RC_JOB_RETURN
  6171. **/
  6172. static int ipr_ioafp_query_ioa_cfg(struct ipr_cmnd *ipr_cmd)
  6173. {
  6174. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6175. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6176. struct ipr_inquiry_page3 *ucode_vpd = &ioa_cfg->vpd_cbs->page3_data;
  6177. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  6178. ENTER;
  6179. if (cap->cap & IPR_CAP_DUAL_IOA_RAID)
  6180. ioa_cfg->dual_raid = 1;
  6181. dev_info(&ioa_cfg->pdev->dev, "Adapter firmware version: %02X%02X%02X%02X\n",
  6182. ucode_vpd->major_release, ucode_vpd->card_type,
  6183. ucode_vpd->minor_release[0], ucode_vpd->minor_release[1]);
  6184. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6185. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6186. ioarcb->cmd_pkt.cdb[0] = IPR_QUERY_IOA_CONFIG;
  6187. ioarcb->cmd_pkt.cdb[6] = (ioa_cfg->cfg_table_size >> 16) & 0xff;
  6188. ioarcb->cmd_pkt.cdb[7] = (ioa_cfg->cfg_table_size >> 8) & 0xff;
  6189. ioarcb->cmd_pkt.cdb[8] = ioa_cfg->cfg_table_size & 0xff;
  6190. ipr_init_ioadl(ipr_cmd, ioa_cfg->cfg_table_dma, ioa_cfg->cfg_table_size,
  6191. IPR_IOADL_FLAGS_READ_LAST);
  6192. ipr_cmd->job_step = ipr_init_res_table;
  6193. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6194. LEAVE;
  6195. return IPR_RC_JOB_RETURN;
  6196. }
  6197. /**
  6198. * ipr_ioafp_inquiry - Send an Inquiry to the adapter.
  6199. * @ipr_cmd: ipr command struct
  6200. *
  6201. * This utility function sends an inquiry to the adapter.
  6202. *
  6203. * Return value:
  6204. * none
  6205. **/
  6206. static void ipr_ioafp_inquiry(struct ipr_cmnd *ipr_cmd, u8 flags, u8 page,
  6207. dma_addr_t dma_addr, u8 xfer_len)
  6208. {
  6209. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6210. ENTER;
  6211. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6212. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6213. ioarcb->cmd_pkt.cdb[0] = INQUIRY;
  6214. ioarcb->cmd_pkt.cdb[1] = flags;
  6215. ioarcb->cmd_pkt.cdb[2] = page;
  6216. ioarcb->cmd_pkt.cdb[4] = xfer_len;
  6217. ipr_init_ioadl(ipr_cmd, dma_addr, xfer_len, IPR_IOADL_FLAGS_READ_LAST);
  6218. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6219. LEAVE;
  6220. }
  6221. /**
  6222. * ipr_inquiry_page_supported - Is the given inquiry page supported
  6223. * @page0: inquiry page 0 buffer
  6224. * @page: page code.
  6225. *
  6226. * This function determines if the specified inquiry page is supported.
  6227. *
  6228. * Return value:
  6229. * 1 if page is supported / 0 if not
  6230. **/
  6231. static int ipr_inquiry_page_supported(struct ipr_inquiry_page0 *page0, u8 page)
  6232. {
  6233. int i;
  6234. for (i = 0; i < min_t(u8, page0->len, IPR_INQUIRY_PAGE0_ENTRIES); i++)
  6235. if (page0->page[i] == page)
  6236. return 1;
  6237. return 0;
  6238. }
  6239. /**
  6240. * ipr_ioafp_cap_inquiry - Send a Page 0xD0 Inquiry to the adapter.
  6241. * @ipr_cmd: ipr command struct
  6242. *
  6243. * This function sends a Page 0xD0 inquiry to the adapter
  6244. * to retrieve adapter capabilities.
  6245. *
  6246. * Return value:
  6247. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6248. **/
  6249. static int ipr_ioafp_cap_inquiry(struct ipr_cmnd *ipr_cmd)
  6250. {
  6251. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6252. struct ipr_inquiry_page0 *page0 = &ioa_cfg->vpd_cbs->page0_data;
  6253. struct ipr_inquiry_cap *cap = &ioa_cfg->vpd_cbs->cap;
  6254. ENTER;
  6255. ipr_cmd->job_step = ipr_ioafp_query_ioa_cfg;
  6256. memset(cap, 0, sizeof(*cap));
  6257. if (ipr_inquiry_page_supported(page0, 0xD0)) {
  6258. ipr_ioafp_inquiry(ipr_cmd, 1, 0xD0,
  6259. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, cap),
  6260. sizeof(struct ipr_inquiry_cap));
  6261. return IPR_RC_JOB_RETURN;
  6262. }
  6263. LEAVE;
  6264. return IPR_RC_JOB_CONTINUE;
  6265. }
  6266. /**
  6267. * ipr_ioafp_page3_inquiry - Send a Page 3 Inquiry to the adapter.
  6268. * @ipr_cmd: ipr command struct
  6269. *
  6270. * This function sends a Page 3 inquiry to the adapter
  6271. * to retrieve software VPD information.
  6272. *
  6273. * Return value:
  6274. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6275. **/
  6276. static int ipr_ioafp_page3_inquiry(struct ipr_cmnd *ipr_cmd)
  6277. {
  6278. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6279. ENTER;
  6280. ipr_cmd->job_step = ipr_ioafp_cap_inquiry;
  6281. ipr_ioafp_inquiry(ipr_cmd, 1, 3,
  6282. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page3_data),
  6283. sizeof(struct ipr_inquiry_page3));
  6284. LEAVE;
  6285. return IPR_RC_JOB_RETURN;
  6286. }
  6287. /**
  6288. * ipr_ioafp_page0_inquiry - Send a Page 0 Inquiry to the adapter.
  6289. * @ipr_cmd: ipr command struct
  6290. *
  6291. * This function sends a Page 0 inquiry to the adapter
  6292. * to retrieve supported inquiry pages.
  6293. *
  6294. * Return value:
  6295. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6296. **/
  6297. static int ipr_ioafp_page0_inquiry(struct ipr_cmnd *ipr_cmd)
  6298. {
  6299. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6300. char type[5];
  6301. ENTER;
  6302. /* Grab the type out of the VPD and store it away */
  6303. memcpy(type, ioa_cfg->vpd_cbs->ioa_vpd.std_inq_data.vpids.product_id, 4);
  6304. type[4] = '\0';
  6305. ioa_cfg->type = simple_strtoul((char *)type, NULL, 16);
  6306. ipr_cmd->job_step = ipr_ioafp_page3_inquiry;
  6307. ipr_ioafp_inquiry(ipr_cmd, 1, 0,
  6308. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, page0_data),
  6309. sizeof(struct ipr_inquiry_page0));
  6310. LEAVE;
  6311. return IPR_RC_JOB_RETURN;
  6312. }
  6313. /**
  6314. * ipr_ioafp_std_inquiry - Send a Standard Inquiry to the adapter.
  6315. * @ipr_cmd: ipr command struct
  6316. *
  6317. * This function sends a standard inquiry to the adapter.
  6318. *
  6319. * Return value:
  6320. * IPR_RC_JOB_RETURN
  6321. **/
  6322. static int ipr_ioafp_std_inquiry(struct ipr_cmnd *ipr_cmd)
  6323. {
  6324. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6325. ENTER;
  6326. ipr_cmd->job_step = ipr_ioafp_page0_inquiry;
  6327. ipr_ioafp_inquiry(ipr_cmd, 0, 0,
  6328. ioa_cfg->vpd_cbs_dma + offsetof(struct ipr_misc_cbs, ioa_vpd),
  6329. sizeof(struct ipr_ioa_vpd));
  6330. LEAVE;
  6331. return IPR_RC_JOB_RETURN;
  6332. }
  6333. /**
  6334. * ipr_ioafp_identify_hrrq - Send Identify Host RRQ.
  6335. * @ipr_cmd: ipr command struct
  6336. *
  6337. * This function send an Identify Host Request Response Queue
  6338. * command to establish the HRRQ with the adapter.
  6339. *
  6340. * Return value:
  6341. * IPR_RC_JOB_RETURN
  6342. **/
  6343. static int ipr_ioafp_identify_hrrq(struct ipr_cmnd *ipr_cmd)
  6344. {
  6345. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6346. struct ipr_ioarcb *ioarcb = &ipr_cmd->ioarcb;
  6347. ENTER;
  6348. dev_info(&ioa_cfg->pdev->dev, "Starting IOA initialization sequence.\n");
  6349. ioarcb->cmd_pkt.cdb[0] = IPR_ID_HOST_RR_Q;
  6350. ioarcb->res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6351. ioarcb->cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  6352. if (ioa_cfg->sis64)
  6353. ioarcb->cmd_pkt.cdb[1] = 0x1;
  6354. ioarcb->cmd_pkt.cdb[2] =
  6355. ((u64) ioa_cfg->host_rrq_dma >> 24) & 0xff;
  6356. ioarcb->cmd_pkt.cdb[3] =
  6357. ((u64) ioa_cfg->host_rrq_dma >> 16) & 0xff;
  6358. ioarcb->cmd_pkt.cdb[4] =
  6359. ((u64) ioa_cfg->host_rrq_dma >> 8) & 0xff;
  6360. ioarcb->cmd_pkt.cdb[5] =
  6361. ((u64) ioa_cfg->host_rrq_dma) & 0xff;
  6362. ioarcb->cmd_pkt.cdb[7] =
  6363. ((sizeof(u32) * IPR_NUM_CMD_BLKS) >> 8) & 0xff;
  6364. ioarcb->cmd_pkt.cdb[8] =
  6365. (sizeof(u32) * IPR_NUM_CMD_BLKS) & 0xff;
  6366. if (ioa_cfg->sis64) {
  6367. ioarcb->cmd_pkt.cdb[10] =
  6368. ((u64) ioa_cfg->host_rrq_dma >> 56) & 0xff;
  6369. ioarcb->cmd_pkt.cdb[11] =
  6370. ((u64) ioa_cfg->host_rrq_dma >> 48) & 0xff;
  6371. ioarcb->cmd_pkt.cdb[12] =
  6372. ((u64) ioa_cfg->host_rrq_dma >> 40) & 0xff;
  6373. ioarcb->cmd_pkt.cdb[13] =
  6374. ((u64) ioa_cfg->host_rrq_dma >> 32) & 0xff;
  6375. }
  6376. ipr_cmd->job_step = ipr_ioafp_std_inquiry;
  6377. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, IPR_INTERNAL_TIMEOUT);
  6378. LEAVE;
  6379. return IPR_RC_JOB_RETURN;
  6380. }
  6381. /**
  6382. * ipr_reset_timer_done - Adapter reset timer function
  6383. * @ipr_cmd: ipr command struct
  6384. *
  6385. * Description: This function is used in adapter reset processing
  6386. * for timing events. If the reset_cmd pointer in the IOA
  6387. * config struct is not this adapter's we are doing nested
  6388. * resets and fail_all_ops will take care of freeing the
  6389. * command block.
  6390. *
  6391. * Return value:
  6392. * none
  6393. **/
  6394. static void ipr_reset_timer_done(struct ipr_cmnd *ipr_cmd)
  6395. {
  6396. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6397. unsigned long lock_flags = 0;
  6398. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  6399. if (ioa_cfg->reset_cmd == ipr_cmd) {
  6400. list_del(&ipr_cmd->queue);
  6401. ipr_cmd->done(ipr_cmd);
  6402. }
  6403. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  6404. }
  6405. /**
  6406. * ipr_reset_start_timer - Start a timer for adapter reset job
  6407. * @ipr_cmd: ipr command struct
  6408. * @timeout: timeout value
  6409. *
  6410. * Description: This function is used in adapter reset processing
  6411. * for timing events. If the reset_cmd pointer in the IOA
  6412. * config struct is not this adapter's we are doing nested
  6413. * resets and fail_all_ops will take care of freeing the
  6414. * command block.
  6415. *
  6416. * Return value:
  6417. * none
  6418. **/
  6419. static void ipr_reset_start_timer(struct ipr_cmnd *ipr_cmd,
  6420. unsigned long timeout)
  6421. {
  6422. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  6423. ipr_cmd->done = ipr_reset_ioa_job;
  6424. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  6425. ipr_cmd->timer.expires = jiffies + timeout;
  6426. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_reset_timer_done;
  6427. add_timer(&ipr_cmd->timer);
  6428. }
  6429. /**
  6430. * ipr_init_ioa_mem - Initialize ioa_cfg control block
  6431. * @ioa_cfg: ioa cfg struct
  6432. *
  6433. * Return value:
  6434. * nothing
  6435. **/
  6436. static void ipr_init_ioa_mem(struct ipr_ioa_cfg *ioa_cfg)
  6437. {
  6438. memset(ioa_cfg->host_rrq, 0, sizeof(u32) * IPR_NUM_CMD_BLKS);
  6439. /* Initialize Host RRQ pointers */
  6440. ioa_cfg->hrrq_start = ioa_cfg->host_rrq;
  6441. ioa_cfg->hrrq_end = &ioa_cfg->host_rrq[IPR_NUM_CMD_BLKS - 1];
  6442. ioa_cfg->hrrq_curr = ioa_cfg->hrrq_start;
  6443. ioa_cfg->toggle_bit = 1;
  6444. /* Zero out config table */
  6445. memset(ioa_cfg->u.cfg_table, 0, ioa_cfg->cfg_table_size);
  6446. }
  6447. /**
  6448. * ipr_reset_next_stage - Process IPL stage change based on feedback register.
  6449. * @ipr_cmd: ipr command struct
  6450. *
  6451. * Return value:
  6452. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6453. **/
  6454. static int ipr_reset_next_stage(struct ipr_cmnd *ipr_cmd)
  6455. {
  6456. unsigned long stage, stage_time;
  6457. u32 feedback;
  6458. volatile u32 int_reg;
  6459. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6460. u64 maskval = 0;
  6461. feedback = readl(ioa_cfg->regs.init_feedback_reg);
  6462. stage = feedback & IPR_IPL_INIT_STAGE_MASK;
  6463. stage_time = feedback & IPR_IPL_INIT_STAGE_TIME_MASK;
  6464. ipr_dbg("IPL stage = 0x%lx, IPL stage time = %ld\n", stage, stage_time);
  6465. /* sanity check the stage_time value */
  6466. if (stage_time == 0)
  6467. stage_time = IPR_IPL_INIT_DEFAULT_STAGE_TIME;
  6468. else if (stage_time < IPR_IPL_INIT_MIN_STAGE_TIME)
  6469. stage_time = IPR_IPL_INIT_MIN_STAGE_TIME;
  6470. else if (stage_time > IPR_LONG_OPERATIONAL_TIMEOUT)
  6471. stage_time = IPR_LONG_OPERATIONAL_TIMEOUT;
  6472. if (stage == IPR_IPL_INIT_STAGE_UNKNOWN) {
  6473. writel(IPR_PCII_IPL_STAGE_CHANGE, ioa_cfg->regs.set_interrupt_mask_reg);
  6474. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  6475. stage_time = ioa_cfg->transop_timeout;
  6476. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  6477. } else if (stage == IPR_IPL_INIT_STAGE_TRANSOP) {
  6478. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  6479. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  6480. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  6481. maskval = IPR_PCII_IPL_STAGE_CHANGE;
  6482. maskval = (maskval << 32) | IPR_PCII_IOA_TRANS_TO_OPER;
  6483. writeq(maskval, ioa_cfg->regs.set_interrupt_mask_reg);
  6484. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  6485. return IPR_RC_JOB_CONTINUE;
  6486. }
  6487. }
  6488. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  6489. ipr_cmd->timer.expires = jiffies + stage_time * HZ;
  6490. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
  6491. ipr_cmd->done = ipr_reset_ioa_job;
  6492. add_timer(&ipr_cmd->timer);
  6493. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  6494. return IPR_RC_JOB_RETURN;
  6495. }
  6496. /**
  6497. * ipr_reset_enable_ioa - Enable the IOA following a reset.
  6498. * @ipr_cmd: ipr command struct
  6499. *
  6500. * This function reinitializes some control blocks and
  6501. * enables destructive diagnostics on the adapter.
  6502. *
  6503. * Return value:
  6504. * IPR_RC_JOB_RETURN
  6505. **/
  6506. static int ipr_reset_enable_ioa(struct ipr_cmnd *ipr_cmd)
  6507. {
  6508. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6509. volatile u32 int_reg;
  6510. volatile u64 maskval;
  6511. ENTER;
  6512. ipr_cmd->job_step = ipr_ioafp_identify_hrrq;
  6513. ipr_init_ioa_mem(ioa_cfg);
  6514. ioa_cfg->allow_interrupts = 1;
  6515. if (ioa_cfg->sis64) {
  6516. /* Set the adapter to the correct endian mode. */
  6517. writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
  6518. int_reg = readl(ioa_cfg->regs.endian_swap_reg);
  6519. }
  6520. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg32);
  6521. if (int_reg & IPR_PCII_IOA_TRANS_TO_OPER) {
  6522. writel((IPR_PCII_ERROR_INTERRUPTS | IPR_PCII_HRRQ_UPDATED),
  6523. ioa_cfg->regs.clr_interrupt_mask_reg32);
  6524. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  6525. return IPR_RC_JOB_CONTINUE;
  6526. }
  6527. /* Enable destructive diagnostics on IOA */
  6528. writel(ioa_cfg->doorbell, ioa_cfg->regs.set_uproc_interrupt_reg32);
  6529. if (ioa_cfg->sis64) {
  6530. maskval = IPR_PCII_IPL_STAGE_CHANGE;
  6531. maskval = (maskval << 32) | IPR_PCII_OPER_INTERRUPTS;
  6532. writeq(maskval, ioa_cfg->regs.clr_interrupt_mask_reg);
  6533. } else
  6534. writel(IPR_PCII_OPER_INTERRUPTS, ioa_cfg->regs.clr_interrupt_mask_reg32);
  6535. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  6536. dev_info(&ioa_cfg->pdev->dev, "Initializing IOA.\n");
  6537. if (ioa_cfg->sis64) {
  6538. ipr_cmd->job_step = ipr_reset_next_stage;
  6539. return IPR_RC_JOB_CONTINUE;
  6540. }
  6541. ipr_cmd->timer.data = (unsigned long) ipr_cmd;
  6542. ipr_cmd->timer.expires = jiffies + (ioa_cfg->transop_timeout * HZ);
  6543. ipr_cmd->timer.function = (void (*)(unsigned long))ipr_oper_timeout;
  6544. ipr_cmd->done = ipr_reset_ioa_job;
  6545. add_timer(&ipr_cmd->timer);
  6546. list_add_tail(&ipr_cmd->queue, &ioa_cfg->pending_q);
  6547. LEAVE;
  6548. return IPR_RC_JOB_RETURN;
  6549. }
  6550. /**
  6551. * ipr_reset_wait_for_dump - Wait for a dump to timeout.
  6552. * @ipr_cmd: ipr command struct
  6553. *
  6554. * This function is invoked when an adapter dump has run out
  6555. * of processing time.
  6556. *
  6557. * Return value:
  6558. * IPR_RC_JOB_CONTINUE
  6559. **/
  6560. static int ipr_reset_wait_for_dump(struct ipr_cmnd *ipr_cmd)
  6561. {
  6562. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6563. if (ioa_cfg->sdt_state == GET_DUMP)
  6564. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  6565. else if (ioa_cfg->sdt_state == READ_DUMP)
  6566. ioa_cfg->sdt_state = ABORT_DUMP;
  6567. ioa_cfg->dump_timeout = 1;
  6568. ipr_cmd->job_step = ipr_reset_alert;
  6569. return IPR_RC_JOB_CONTINUE;
  6570. }
  6571. /**
  6572. * ipr_unit_check_no_data - Log a unit check/no data error log
  6573. * @ioa_cfg: ioa config struct
  6574. *
  6575. * Logs an error indicating the adapter unit checked, but for some
  6576. * reason, we were unable to fetch the unit check buffer.
  6577. *
  6578. * Return value:
  6579. * nothing
  6580. **/
  6581. static void ipr_unit_check_no_data(struct ipr_ioa_cfg *ioa_cfg)
  6582. {
  6583. ioa_cfg->errors_logged++;
  6584. dev_err(&ioa_cfg->pdev->dev, "IOA unit check with no data\n");
  6585. }
  6586. /**
  6587. * ipr_get_unit_check_buffer - Get the unit check buffer from the IOA
  6588. * @ioa_cfg: ioa config struct
  6589. *
  6590. * Fetches the unit check buffer from the adapter by clocking the data
  6591. * through the mailbox register.
  6592. *
  6593. * Return value:
  6594. * nothing
  6595. **/
  6596. static void ipr_get_unit_check_buffer(struct ipr_ioa_cfg *ioa_cfg)
  6597. {
  6598. unsigned long mailbox;
  6599. struct ipr_hostrcb *hostrcb;
  6600. struct ipr_uc_sdt sdt;
  6601. int rc, length;
  6602. u32 ioasc;
  6603. mailbox = readl(ioa_cfg->ioa_mailbox);
  6604. if (!ioa_cfg->sis64 && !ipr_sdt_is_fmt2(mailbox)) {
  6605. ipr_unit_check_no_data(ioa_cfg);
  6606. return;
  6607. }
  6608. memset(&sdt, 0, sizeof(struct ipr_uc_sdt));
  6609. rc = ipr_get_ldump_data_section(ioa_cfg, mailbox, (__be32 *) &sdt,
  6610. (sizeof(struct ipr_uc_sdt)) / sizeof(__be32));
  6611. if (rc || !(sdt.entry[0].flags & IPR_SDT_VALID_ENTRY) ||
  6612. ((be32_to_cpu(sdt.hdr.state) != IPR_FMT3_SDT_READY_TO_USE) &&
  6613. (be32_to_cpu(sdt.hdr.state) != IPR_FMT2_SDT_READY_TO_USE))) {
  6614. ipr_unit_check_no_data(ioa_cfg);
  6615. return;
  6616. }
  6617. /* Find length of the first sdt entry (UC buffer) */
  6618. if (be32_to_cpu(sdt.hdr.state) == IPR_FMT3_SDT_READY_TO_USE)
  6619. length = be32_to_cpu(sdt.entry[0].end_token);
  6620. else
  6621. length = (be32_to_cpu(sdt.entry[0].end_token) -
  6622. be32_to_cpu(sdt.entry[0].start_token)) &
  6623. IPR_FMT2_MBX_ADDR_MASK;
  6624. hostrcb = list_entry(ioa_cfg->hostrcb_free_q.next,
  6625. struct ipr_hostrcb, queue);
  6626. list_del(&hostrcb->queue);
  6627. memset(&hostrcb->hcam, 0, sizeof(hostrcb->hcam));
  6628. rc = ipr_get_ldump_data_section(ioa_cfg,
  6629. be32_to_cpu(sdt.entry[0].start_token),
  6630. (__be32 *)&hostrcb->hcam,
  6631. min(length, (int)sizeof(hostrcb->hcam)) / sizeof(__be32));
  6632. if (!rc) {
  6633. ipr_handle_log_data(ioa_cfg, hostrcb);
  6634. ioasc = be32_to_cpu(hostrcb->hcam.u.error.fd_ioasc);
  6635. if (ioasc == IPR_IOASC_NR_IOA_RESET_REQUIRED &&
  6636. ioa_cfg->sdt_state == GET_DUMP)
  6637. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  6638. } else
  6639. ipr_unit_check_no_data(ioa_cfg);
  6640. list_add_tail(&hostrcb->queue, &ioa_cfg->hostrcb_free_q);
  6641. }
  6642. /**
  6643. * ipr_reset_get_unit_check_job - Call to get the unit check buffer.
  6644. * @ipr_cmd: ipr command struct
  6645. *
  6646. * Description: This function will call to get the unit check buffer.
  6647. *
  6648. * Return value:
  6649. * IPR_RC_JOB_RETURN
  6650. **/
  6651. static int ipr_reset_get_unit_check_job(struct ipr_cmnd *ipr_cmd)
  6652. {
  6653. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6654. ENTER;
  6655. ioa_cfg->ioa_unit_checked = 0;
  6656. ipr_get_unit_check_buffer(ioa_cfg);
  6657. ipr_cmd->job_step = ipr_reset_alert;
  6658. ipr_reset_start_timer(ipr_cmd, 0);
  6659. LEAVE;
  6660. return IPR_RC_JOB_RETURN;
  6661. }
  6662. /**
  6663. * ipr_reset_restore_cfg_space - Restore PCI config space.
  6664. * @ipr_cmd: ipr command struct
  6665. *
  6666. * Description: This function restores the saved PCI config space of
  6667. * the adapter, fails all outstanding ops back to the callers, and
  6668. * fetches the dump/unit check if applicable to this reset.
  6669. *
  6670. * Return value:
  6671. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6672. **/
  6673. static int ipr_reset_restore_cfg_space(struct ipr_cmnd *ipr_cmd)
  6674. {
  6675. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6676. u32 int_reg;
  6677. ENTER;
  6678. ioa_cfg->pdev->state_saved = true;
  6679. pci_restore_state(ioa_cfg->pdev);
  6680. if (ipr_set_pcix_cmd_reg(ioa_cfg)) {
  6681. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  6682. return IPR_RC_JOB_CONTINUE;
  6683. }
  6684. ipr_fail_all_ops(ioa_cfg);
  6685. if (ioa_cfg->sis64) {
  6686. /* Set the adapter to the correct endian mode. */
  6687. writel(IPR_ENDIAN_SWAP_KEY, ioa_cfg->regs.endian_swap_reg);
  6688. int_reg = readl(ioa_cfg->regs.endian_swap_reg);
  6689. }
  6690. if (ioa_cfg->ioa_unit_checked) {
  6691. if (ioa_cfg->sis64) {
  6692. ipr_cmd->job_step = ipr_reset_get_unit_check_job;
  6693. ipr_reset_start_timer(ipr_cmd, IPR_DUMP_DELAY_TIMEOUT);
  6694. return IPR_RC_JOB_RETURN;
  6695. } else {
  6696. ioa_cfg->ioa_unit_checked = 0;
  6697. ipr_get_unit_check_buffer(ioa_cfg);
  6698. ipr_cmd->job_step = ipr_reset_alert;
  6699. ipr_reset_start_timer(ipr_cmd, 0);
  6700. return IPR_RC_JOB_RETURN;
  6701. }
  6702. }
  6703. if (ioa_cfg->in_ioa_bringdown) {
  6704. ipr_cmd->job_step = ipr_ioa_bringdown_done;
  6705. } else {
  6706. ipr_cmd->job_step = ipr_reset_enable_ioa;
  6707. if (GET_DUMP == ioa_cfg->sdt_state) {
  6708. ioa_cfg->sdt_state = READ_DUMP;
  6709. ioa_cfg->dump_timeout = 0;
  6710. if (ioa_cfg->sis64)
  6711. ipr_reset_start_timer(ipr_cmd, IPR_SIS64_DUMP_TIMEOUT);
  6712. else
  6713. ipr_reset_start_timer(ipr_cmd, IPR_SIS32_DUMP_TIMEOUT);
  6714. ipr_cmd->job_step = ipr_reset_wait_for_dump;
  6715. schedule_work(&ioa_cfg->work_q);
  6716. return IPR_RC_JOB_RETURN;
  6717. }
  6718. }
  6719. LEAVE;
  6720. return IPR_RC_JOB_CONTINUE;
  6721. }
  6722. /**
  6723. * ipr_reset_bist_done - BIST has completed on the adapter.
  6724. * @ipr_cmd: ipr command struct
  6725. *
  6726. * Description: Unblock config space and resume the reset process.
  6727. *
  6728. * Return value:
  6729. * IPR_RC_JOB_CONTINUE
  6730. **/
  6731. static int ipr_reset_bist_done(struct ipr_cmnd *ipr_cmd)
  6732. {
  6733. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6734. ENTER;
  6735. if (ioa_cfg->cfg_locked)
  6736. pci_cfg_access_unlock(ioa_cfg->pdev);
  6737. ioa_cfg->cfg_locked = 0;
  6738. ipr_cmd->job_step = ipr_reset_restore_cfg_space;
  6739. LEAVE;
  6740. return IPR_RC_JOB_CONTINUE;
  6741. }
  6742. /**
  6743. * ipr_reset_start_bist - Run BIST on the adapter.
  6744. * @ipr_cmd: ipr command struct
  6745. *
  6746. * Description: This function runs BIST on the adapter, then delays 2 seconds.
  6747. *
  6748. * Return value:
  6749. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6750. **/
  6751. static int ipr_reset_start_bist(struct ipr_cmnd *ipr_cmd)
  6752. {
  6753. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6754. int rc = PCIBIOS_SUCCESSFUL;
  6755. ENTER;
  6756. if (ioa_cfg->ipr_chip->bist_method == IPR_MMIO)
  6757. writel(IPR_UPROCI_SIS64_START_BIST,
  6758. ioa_cfg->regs.set_uproc_interrupt_reg32);
  6759. else
  6760. rc = pci_write_config_byte(ioa_cfg->pdev, PCI_BIST, PCI_BIST_START);
  6761. if (rc == PCIBIOS_SUCCESSFUL) {
  6762. ipr_cmd->job_step = ipr_reset_bist_done;
  6763. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  6764. rc = IPR_RC_JOB_RETURN;
  6765. } else {
  6766. if (ioa_cfg->cfg_locked)
  6767. pci_cfg_access_unlock(ipr_cmd->ioa_cfg->pdev);
  6768. ioa_cfg->cfg_locked = 0;
  6769. ipr_cmd->s.ioasa.hdr.ioasc = cpu_to_be32(IPR_IOASC_PCI_ACCESS_ERROR);
  6770. rc = IPR_RC_JOB_CONTINUE;
  6771. }
  6772. LEAVE;
  6773. return rc;
  6774. }
  6775. /**
  6776. * ipr_reset_slot_reset_done - Clear PCI reset to the adapter
  6777. * @ipr_cmd: ipr command struct
  6778. *
  6779. * Description: This clears PCI reset to the adapter and delays two seconds.
  6780. *
  6781. * Return value:
  6782. * IPR_RC_JOB_RETURN
  6783. **/
  6784. static int ipr_reset_slot_reset_done(struct ipr_cmnd *ipr_cmd)
  6785. {
  6786. ENTER;
  6787. pci_set_pcie_reset_state(ipr_cmd->ioa_cfg->pdev, pcie_deassert_reset);
  6788. ipr_cmd->job_step = ipr_reset_bist_done;
  6789. ipr_reset_start_timer(ipr_cmd, IPR_WAIT_FOR_BIST_TIMEOUT);
  6790. LEAVE;
  6791. return IPR_RC_JOB_RETURN;
  6792. }
  6793. /**
  6794. * ipr_reset_slot_reset - Reset the PCI slot of the adapter.
  6795. * @ipr_cmd: ipr command struct
  6796. *
  6797. * Description: This asserts PCI reset to the adapter.
  6798. *
  6799. * Return value:
  6800. * IPR_RC_JOB_RETURN
  6801. **/
  6802. static int ipr_reset_slot_reset(struct ipr_cmnd *ipr_cmd)
  6803. {
  6804. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6805. struct pci_dev *pdev = ioa_cfg->pdev;
  6806. ENTER;
  6807. pci_set_pcie_reset_state(pdev, pcie_warm_reset);
  6808. ipr_cmd->job_step = ipr_reset_slot_reset_done;
  6809. ipr_reset_start_timer(ipr_cmd, IPR_PCI_RESET_TIMEOUT);
  6810. LEAVE;
  6811. return IPR_RC_JOB_RETURN;
  6812. }
  6813. /**
  6814. * ipr_reset_block_config_access_wait - Wait for permission to block config access
  6815. * @ipr_cmd: ipr command struct
  6816. *
  6817. * Description: This attempts to block config access to the IOA.
  6818. *
  6819. * Return value:
  6820. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6821. **/
  6822. static int ipr_reset_block_config_access_wait(struct ipr_cmnd *ipr_cmd)
  6823. {
  6824. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6825. int rc = IPR_RC_JOB_CONTINUE;
  6826. if (pci_cfg_access_trylock(ioa_cfg->pdev)) {
  6827. ioa_cfg->cfg_locked = 1;
  6828. ipr_cmd->job_step = ioa_cfg->reset;
  6829. } else {
  6830. if (ipr_cmd->u.time_left) {
  6831. rc = IPR_RC_JOB_RETURN;
  6832. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  6833. ipr_reset_start_timer(ipr_cmd,
  6834. IPR_CHECK_FOR_RESET_TIMEOUT);
  6835. } else {
  6836. ipr_cmd->job_step = ioa_cfg->reset;
  6837. dev_err(&ioa_cfg->pdev->dev,
  6838. "Timed out waiting to lock config access. Resetting anyway.\n");
  6839. }
  6840. }
  6841. return rc;
  6842. }
  6843. /**
  6844. * ipr_reset_block_config_access - Block config access to the IOA
  6845. * @ipr_cmd: ipr command struct
  6846. *
  6847. * Description: This attempts to block config access to the IOA
  6848. *
  6849. * Return value:
  6850. * IPR_RC_JOB_CONTINUE
  6851. **/
  6852. static int ipr_reset_block_config_access(struct ipr_cmnd *ipr_cmd)
  6853. {
  6854. ipr_cmd->ioa_cfg->cfg_locked = 0;
  6855. ipr_cmd->job_step = ipr_reset_block_config_access_wait;
  6856. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  6857. return IPR_RC_JOB_CONTINUE;
  6858. }
  6859. /**
  6860. * ipr_reset_allowed - Query whether or not IOA can be reset
  6861. * @ioa_cfg: ioa config struct
  6862. *
  6863. * Return value:
  6864. * 0 if reset not allowed / non-zero if reset is allowed
  6865. **/
  6866. static int ipr_reset_allowed(struct ipr_ioa_cfg *ioa_cfg)
  6867. {
  6868. volatile u32 temp_reg;
  6869. temp_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  6870. return ((temp_reg & IPR_PCII_CRITICAL_OPERATION) == 0);
  6871. }
  6872. /**
  6873. * ipr_reset_wait_to_start_bist - Wait for permission to reset IOA.
  6874. * @ipr_cmd: ipr command struct
  6875. *
  6876. * Description: This function waits for adapter permission to run BIST,
  6877. * then runs BIST. If the adapter does not give permission after a
  6878. * reasonable time, we will reset the adapter anyway. The impact of
  6879. * resetting the adapter without warning the adapter is the risk of
  6880. * losing the persistent error log on the adapter. If the adapter is
  6881. * reset while it is writing to the flash on the adapter, the flash
  6882. * segment will have bad ECC and be zeroed.
  6883. *
  6884. * Return value:
  6885. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6886. **/
  6887. static int ipr_reset_wait_to_start_bist(struct ipr_cmnd *ipr_cmd)
  6888. {
  6889. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6890. int rc = IPR_RC_JOB_RETURN;
  6891. if (!ipr_reset_allowed(ioa_cfg) && ipr_cmd->u.time_left) {
  6892. ipr_cmd->u.time_left -= IPR_CHECK_FOR_RESET_TIMEOUT;
  6893. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  6894. } else {
  6895. ipr_cmd->job_step = ipr_reset_block_config_access;
  6896. rc = IPR_RC_JOB_CONTINUE;
  6897. }
  6898. return rc;
  6899. }
  6900. /**
  6901. * ipr_reset_alert - Alert the adapter of a pending reset
  6902. * @ipr_cmd: ipr command struct
  6903. *
  6904. * Description: This function alerts the adapter that it will be reset.
  6905. * If memory space is not currently enabled, proceed directly
  6906. * to running BIST on the adapter. The timer must always be started
  6907. * so we guarantee we do not run BIST from ipr_isr.
  6908. *
  6909. * Return value:
  6910. * IPR_RC_JOB_RETURN
  6911. **/
  6912. static int ipr_reset_alert(struct ipr_cmnd *ipr_cmd)
  6913. {
  6914. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6915. u16 cmd_reg;
  6916. int rc;
  6917. ENTER;
  6918. rc = pci_read_config_word(ioa_cfg->pdev, PCI_COMMAND, &cmd_reg);
  6919. if ((rc == PCIBIOS_SUCCESSFUL) && (cmd_reg & PCI_COMMAND_MEMORY)) {
  6920. ipr_mask_and_clear_interrupts(ioa_cfg, ~0);
  6921. writel(IPR_UPROCI_RESET_ALERT, ioa_cfg->regs.set_uproc_interrupt_reg32);
  6922. ipr_cmd->job_step = ipr_reset_wait_to_start_bist;
  6923. } else {
  6924. ipr_cmd->job_step = ipr_reset_block_config_access;
  6925. }
  6926. ipr_cmd->u.time_left = IPR_WAIT_FOR_RESET_TIMEOUT;
  6927. ipr_reset_start_timer(ipr_cmd, IPR_CHECK_FOR_RESET_TIMEOUT);
  6928. LEAVE;
  6929. return IPR_RC_JOB_RETURN;
  6930. }
  6931. /**
  6932. * ipr_reset_ucode_download_done - Microcode download completion
  6933. * @ipr_cmd: ipr command struct
  6934. *
  6935. * Description: This function unmaps the microcode download buffer.
  6936. *
  6937. * Return value:
  6938. * IPR_RC_JOB_CONTINUE
  6939. **/
  6940. static int ipr_reset_ucode_download_done(struct ipr_cmnd *ipr_cmd)
  6941. {
  6942. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6943. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  6944. pci_unmap_sg(ioa_cfg->pdev, sglist->scatterlist,
  6945. sglist->num_sg, DMA_TO_DEVICE);
  6946. ipr_cmd->job_step = ipr_reset_alert;
  6947. return IPR_RC_JOB_CONTINUE;
  6948. }
  6949. /**
  6950. * ipr_reset_ucode_download - Download microcode to the adapter
  6951. * @ipr_cmd: ipr command struct
  6952. *
  6953. * Description: This function checks to see if it there is microcode
  6954. * to download to the adapter. If there is, a download is performed.
  6955. *
  6956. * Return value:
  6957. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6958. **/
  6959. static int ipr_reset_ucode_download(struct ipr_cmnd *ipr_cmd)
  6960. {
  6961. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6962. struct ipr_sglist *sglist = ioa_cfg->ucode_sglist;
  6963. ENTER;
  6964. ipr_cmd->job_step = ipr_reset_alert;
  6965. if (!sglist)
  6966. return IPR_RC_JOB_CONTINUE;
  6967. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  6968. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_SCSICDB;
  6969. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = WRITE_BUFFER;
  6970. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_WR_BUF_DOWNLOAD_AND_SAVE;
  6971. ipr_cmd->ioarcb.cmd_pkt.cdb[6] = (sglist->buffer_len & 0xff0000) >> 16;
  6972. ipr_cmd->ioarcb.cmd_pkt.cdb[7] = (sglist->buffer_len & 0x00ff00) >> 8;
  6973. ipr_cmd->ioarcb.cmd_pkt.cdb[8] = sglist->buffer_len & 0x0000ff;
  6974. if (ioa_cfg->sis64)
  6975. ipr_build_ucode_ioadl64(ipr_cmd, sglist);
  6976. else
  6977. ipr_build_ucode_ioadl(ipr_cmd, sglist);
  6978. ipr_cmd->job_step = ipr_reset_ucode_download_done;
  6979. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout,
  6980. IPR_WRITE_BUFFER_TIMEOUT);
  6981. LEAVE;
  6982. return IPR_RC_JOB_RETURN;
  6983. }
  6984. /**
  6985. * ipr_reset_shutdown_ioa - Shutdown the adapter
  6986. * @ipr_cmd: ipr command struct
  6987. *
  6988. * Description: This function issues an adapter shutdown of the
  6989. * specified type to the specified adapter as part of the
  6990. * adapter reset job.
  6991. *
  6992. * Return value:
  6993. * IPR_RC_JOB_CONTINUE / IPR_RC_JOB_RETURN
  6994. **/
  6995. static int ipr_reset_shutdown_ioa(struct ipr_cmnd *ipr_cmd)
  6996. {
  6997. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  6998. enum ipr_shutdown_type shutdown_type = ipr_cmd->u.shutdown_type;
  6999. unsigned long timeout;
  7000. int rc = IPR_RC_JOB_CONTINUE;
  7001. ENTER;
  7002. if (shutdown_type != IPR_SHUTDOWN_NONE && !ioa_cfg->ioa_is_dead) {
  7003. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  7004. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  7005. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  7006. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = shutdown_type;
  7007. if (shutdown_type == IPR_SHUTDOWN_NORMAL)
  7008. timeout = IPR_SHUTDOWN_TIMEOUT;
  7009. else if (shutdown_type == IPR_SHUTDOWN_PREPARE_FOR_NORMAL)
  7010. timeout = IPR_INTERNAL_TIMEOUT;
  7011. else if (ioa_cfg->dual_raid && ipr_dual_ioa_raid)
  7012. timeout = IPR_DUAL_IOA_ABBR_SHUTDOWN_TO;
  7013. else
  7014. timeout = IPR_ABBREV_SHUTDOWN_TIMEOUT;
  7015. ipr_do_req(ipr_cmd, ipr_reset_ioa_job, ipr_timeout, timeout);
  7016. rc = IPR_RC_JOB_RETURN;
  7017. ipr_cmd->job_step = ipr_reset_ucode_download;
  7018. } else
  7019. ipr_cmd->job_step = ipr_reset_alert;
  7020. LEAVE;
  7021. return rc;
  7022. }
  7023. /**
  7024. * ipr_reset_ioa_job - Adapter reset job
  7025. * @ipr_cmd: ipr command struct
  7026. *
  7027. * Description: This function is the job router for the adapter reset job.
  7028. *
  7029. * Return value:
  7030. * none
  7031. **/
  7032. static void ipr_reset_ioa_job(struct ipr_cmnd *ipr_cmd)
  7033. {
  7034. u32 rc, ioasc;
  7035. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  7036. do {
  7037. ioasc = be32_to_cpu(ipr_cmd->s.ioasa.hdr.ioasc);
  7038. if (ioa_cfg->reset_cmd != ipr_cmd) {
  7039. /*
  7040. * We are doing nested adapter resets and this is
  7041. * not the current reset job.
  7042. */
  7043. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  7044. return;
  7045. }
  7046. if (IPR_IOASC_SENSE_KEY(ioasc)) {
  7047. rc = ipr_cmd->job_step_failed(ipr_cmd);
  7048. if (rc == IPR_RC_JOB_RETURN)
  7049. return;
  7050. }
  7051. ipr_reinit_ipr_cmnd(ipr_cmd);
  7052. ipr_cmd->job_step_failed = ipr_reset_cmd_failed;
  7053. rc = ipr_cmd->job_step(ipr_cmd);
  7054. } while (rc == IPR_RC_JOB_CONTINUE);
  7055. }
  7056. /**
  7057. * _ipr_initiate_ioa_reset - Initiate an adapter reset
  7058. * @ioa_cfg: ioa config struct
  7059. * @job_step: first job step of reset job
  7060. * @shutdown_type: shutdown type
  7061. *
  7062. * Description: This function will initiate the reset of the given adapter
  7063. * starting at the selected job step.
  7064. * If the caller needs to wait on the completion of the reset,
  7065. * the caller must sleep on the reset_wait_q.
  7066. *
  7067. * Return value:
  7068. * none
  7069. **/
  7070. static void _ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  7071. int (*job_step) (struct ipr_cmnd *),
  7072. enum ipr_shutdown_type shutdown_type)
  7073. {
  7074. struct ipr_cmnd *ipr_cmd;
  7075. ioa_cfg->in_reset_reload = 1;
  7076. ioa_cfg->allow_cmds = 0;
  7077. scsi_block_requests(ioa_cfg->host);
  7078. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  7079. ioa_cfg->reset_cmd = ipr_cmd;
  7080. ipr_cmd->job_step = job_step;
  7081. ipr_cmd->u.shutdown_type = shutdown_type;
  7082. ipr_reset_ioa_job(ipr_cmd);
  7083. }
  7084. /**
  7085. * ipr_initiate_ioa_reset - Initiate an adapter reset
  7086. * @ioa_cfg: ioa config struct
  7087. * @shutdown_type: shutdown type
  7088. *
  7089. * Description: This function will initiate the reset of the given adapter.
  7090. * If the caller needs to wait on the completion of the reset,
  7091. * the caller must sleep on the reset_wait_q.
  7092. *
  7093. * Return value:
  7094. * none
  7095. **/
  7096. static void ipr_initiate_ioa_reset(struct ipr_ioa_cfg *ioa_cfg,
  7097. enum ipr_shutdown_type shutdown_type)
  7098. {
  7099. if (ioa_cfg->ioa_is_dead)
  7100. return;
  7101. if (ioa_cfg->in_reset_reload) {
  7102. if (ioa_cfg->sdt_state == GET_DUMP)
  7103. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  7104. else if (ioa_cfg->sdt_state == READ_DUMP)
  7105. ioa_cfg->sdt_state = ABORT_DUMP;
  7106. }
  7107. if (ioa_cfg->reset_retries++ >= IPR_NUM_RESET_RELOAD_RETRIES) {
  7108. dev_err(&ioa_cfg->pdev->dev,
  7109. "IOA taken offline - error recovery failed\n");
  7110. ioa_cfg->reset_retries = 0;
  7111. ioa_cfg->ioa_is_dead = 1;
  7112. if (ioa_cfg->in_ioa_bringdown) {
  7113. ioa_cfg->reset_cmd = NULL;
  7114. ioa_cfg->in_reset_reload = 0;
  7115. ipr_fail_all_ops(ioa_cfg);
  7116. wake_up_all(&ioa_cfg->reset_wait_q);
  7117. spin_unlock_irq(ioa_cfg->host->host_lock);
  7118. scsi_unblock_requests(ioa_cfg->host);
  7119. spin_lock_irq(ioa_cfg->host->host_lock);
  7120. return;
  7121. } else {
  7122. ioa_cfg->in_ioa_bringdown = 1;
  7123. shutdown_type = IPR_SHUTDOWN_NONE;
  7124. }
  7125. }
  7126. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_shutdown_ioa,
  7127. shutdown_type);
  7128. }
  7129. /**
  7130. * ipr_reset_freeze - Hold off all I/O activity
  7131. * @ipr_cmd: ipr command struct
  7132. *
  7133. * Description: If the PCI slot is frozen, hold off all I/O
  7134. * activity; then, as soon as the slot is available again,
  7135. * initiate an adapter reset.
  7136. */
  7137. static int ipr_reset_freeze(struct ipr_cmnd *ipr_cmd)
  7138. {
  7139. /* Disallow new interrupts, avoid loop */
  7140. ipr_cmd->ioa_cfg->allow_interrupts = 0;
  7141. list_add_tail(&ipr_cmd->queue, &ipr_cmd->ioa_cfg->pending_q);
  7142. ipr_cmd->done = ipr_reset_ioa_job;
  7143. return IPR_RC_JOB_RETURN;
  7144. }
  7145. /**
  7146. * ipr_pci_frozen - Called when slot has experienced a PCI bus error.
  7147. * @pdev: PCI device struct
  7148. *
  7149. * Description: This routine is called to tell us that the PCI bus
  7150. * is down. Can't do anything here, except put the device driver
  7151. * into a holding pattern, waiting for the PCI bus to come back.
  7152. */
  7153. static void ipr_pci_frozen(struct pci_dev *pdev)
  7154. {
  7155. unsigned long flags = 0;
  7156. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  7157. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  7158. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_freeze, IPR_SHUTDOWN_NONE);
  7159. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  7160. }
  7161. /**
  7162. * ipr_pci_slot_reset - Called when PCI slot has been reset.
  7163. * @pdev: PCI device struct
  7164. *
  7165. * Description: This routine is called by the pci error recovery
  7166. * code after the PCI slot has been reset, just before we
  7167. * should resume normal operations.
  7168. */
  7169. static pci_ers_result_t ipr_pci_slot_reset(struct pci_dev *pdev)
  7170. {
  7171. unsigned long flags = 0;
  7172. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  7173. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  7174. if (ioa_cfg->needs_warm_reset)
  7175. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7176. else
  7177. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_restore_cfg_space,
  7178. IPR_SHUTDOWN_NONE);
  7179. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  7180. return PCI_ERS_RESULT_RECOVERED;
  7181. }
  7182. /**
  7183. * ipr_pci_perm_failure - Called when PCI slot is dead for good.
  7184. * @pdev: PCI device struct
  7185. *
  7186. * Description: This routine is called when the PCI bus has
  7187. * permanently failed.
  7188. */
  7189. static void ipr_pci_perm_failure(struct pci_dev *pdev)
  7190. {
  7191. unsigned long flags = 0;
  7192. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  7193. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  7194. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  7195. ioa_cfg->sdt_state = ABORT_DUMP;
  7196. ioa_cfg->reset_retries = IPR_NUM_RESET_RELOAD_RETRIES;
  7197. ioa_cfg->in_ioa_bringdown = 1;
  7198. ioa_cfg->allow_cmds = 0;
  7199. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7200. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  7201. }
  7202. /**
  7203. * ipr_pci_error_detected - Called when a PCI error is detected.
  7204. * @pdev: PCI device struct
  7205. * @state: PCI channel state
  7206. *
  7207. * Description: Called when a PCI error is detected.
  7208. *
  7209. * Return value:
  7210. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  7211. */
  7212. static pci_ers_result_t ipr_pci_error_detected(struct pci_dev *pdev,
  7213. pci_channel_state_t state)
  7214. {
  7215. switch (state) {
  7216. case pci_channel_io_frozen:
  7217. ipr_pci_frozen(pdev);
  7218. return PCI_ERS_RESULT_NEED_RESET;
  7219. case pci_channel_io_perm_failure:
  7220. ipr_pci_perm_failure(pdev);
  7221. return PCI_ERS_RESULT_DISCONNECT;
  7222. break;
  7223. default:
  7224. break;
  7225. }
  7226. return PCI_ERS_RESULT_NEED_RESET;
  7227. }
  7228. /**
  7229. * ipr_probe_ioa_part2 - Initializes IOAs found in ipr_probe_ioa(..)
  7230. * @ioa_cfg: ioa cfg struct
  7231. *
  7232. * Description: This is the second phase of adapter intialization
  7233. * This function takes care of initilizing the adapter to the point
  7234. * where it can accept new commands.
  7235. * Return value:
  7236. * 0 on success / -EIO on failure
  7237. **/
  7238. static int ipr_probe_ioa_part2(struct ipr_ioa_cfg *ioa_cfg)
  7239. {
  7240. int rc = 0;
  7241. unsigned long host_lock_flags = 0;
  7242. ENTER;
  7243. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  7244. dev_dbg(&ioa_cfg->pdev->dev, "ioa_cfg adx: 0x%p\n", ioa_cfg);
  7245. if (ioa_cfg->needs_hard_reset) {
  7246. ioa_cfg->needs_hard_reset = 0;
  7247. ipr_initiate_ioa_reset(ioa_cfg, IPR_SHUTDOWN_NONE);
  7248. } else
  7249. _ipr_initiate_ioa_reset(ioa_cfg, ipr_reset_enable_ioa,
  7250. IPR_SHUTDOWN_NONE);
  7251. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  7252. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  7253. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  7254. if (ioa_cfg->ioa_is_dead) {
  7255. rc = -EIO;
  7256. } else if (ipr_invalid_adapter(ioa_cfg)) {
  7257. if (!ipr_testmode)
  7258. rc = -EIO;
  7259. dev_err(&ioa_cfg->pdev->dev,
  7260. "Adapter not supported in this hardware configuration.\n");
  7261. }
  7262. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  7263. LEAVE;
  7264. return rc;
  7265. }
  7266. /**
  7267. * ipr_free_cmd_blks - Frees command blocks allocated for an adapter
  7268. * @ioa_cfg: ioa config struct
  7269. *
  7270. * Return value:
  7271. * none
  7272. **/
  7273. static void ipr_free_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  7274. {
  7275. int i;
  7276. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  7277. if (ioa_cfg->ipr_cmnd_list[i])
  7278. pci_pool_free(ioa_cfg->ipr_cmd_pool,
  7279. ioa_cfg->ipr_cmnd_list[i],
  7280. ioa_cfg->ipr_cmnd_list_dma[i]);
  7281. ioa_cfg->ipr_cmnd_list[i] = NULL;
  7282. }
  7283. if (ioa_cfg->ipr_cmd_pool)
  7284. pci_pool_destroy(ioa_cfg->ipr_cmd_pool);
  7285. kfree(ioa_cfg->ipr_cmnd_list);
  7286. kfree(ioa_cfg->ipr_cmnd_list_dma);
  7287. ioa_cfg->ipr_cmnd_list = NULL;
  7288. ioa_cfg->ipr_cmnd_list_dma = NULL;
  7289. ioa_cfg->ipr_cmd_pool = NULL;
  7290. }
  7291. /**
  7292. * ipr_free_mem - Frees memory allocated for an adapter
  7293. * @ioa_cfg: ioa cfg struct
  7294. *
  7295. * Return value:
  7296. * nothing
  7297. **/
  7298. static void ipr_free_mem(struct ipr_ioa_cfg *ioa_cfg)
  7299. {
  7300. int i;
  7301. kfree(ioa_cfg->res_entries);
  7302. pci_free_consistent(ioa_cfg->pdev, sizeof(struct ipr_misc_cbs),
  7303. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  7304. ipr_free_cmd_blks(ioa_cfg);
  7305. pci_free_consistent(ioa_cfg->pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  7306. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  7307. pci_free_consistent(ioa_cfg->pdev, ioa_cfg->cfg_table_size,
  7308. ioa_cfg->u.cfg_table,
  7309. ioa_cfg->cfg_table_dma);
  7310. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  7311. pci_free_consistent(ioa_cfg->pdev,
  7312. sizeof(struct ipr_hostrcb),
  7313. ioa_cfg->hostrcb[i],
  7314. ioa_cfg->hostrcb_dma[i]);
  7315. }
  7316. ipr_free_dump(ioa_cfg);
  7317. kfree(ioa_cfg->trace);
  7318. }
  7319. /**
  7320. * ipr_free_all_resources - Free all allocated resources for an adapter.
  7321. * @ipr_cmd: ipr command struct
  7322. *
  7323. * This function frees all allocated resources for the
  7324. * specified adapter.
  7325. *
  7326. * Return value:
  7327. * none
  7328. **/
  7329. static void ipr_free_all_resources(struct ipr_ioa_cfg *ioa_cfg)
  7330. {
  7331. struct pci_dev *pdev = ioa_cfg->pdev;
  7332. ENTER;
  7333. free_irq(pdev->irq, ioa_cfg);
  7334. pci_disable_msi(pdev);
  7335. iounmap(ioa_cfg->hdw_dma_regs);
  7336. pci_release_regions(pdev);
  7337. ipr_free_mem(ioa_cfg);
  7338. scsi_host_put(ioa_cfg->host);
  7339. pci_disable_device(pdev);
  7340. LEAVE;
  7341. }
  7342. /**
  7343. * ipr_alloc_cmd_blks - Allocate command blocks for an adapter
  7344. * @ioa_cfg: ioa config struct
  7345. *
  7346. * Return value:
  7347. * 0 on success / -ENOMEM on allocation failure
  7348. **/
  7349. static int ipr_alloc_cmd_blks(struct ipr_ioa_cfg *ioa_cfg)
  7350. {
  7351. struct ipr_cmnd *ipr_cmd;
  7352. struct ipr_ioarcb *ioarcb;
  7353. dma_addr_t dma_addr;
  7354. int i;
  7355. ioa_cfg->ipr_cmd_pool = pci_pool_create(IPR_NAME, ioa_cfg->pdev,
  7356. sizeof(struct ipr_cmnd), 512, 0);
  7357. if (!ioa_cfg->ipr_cmd_pool)
  7358. return -ENOMEM;
  7359. ioa_cfg->ipr_cmnd_list = kcalloc(IPR_NUM_CMD_BLKS, sizeof(struct ipr_cmnd *), GFP_KERNEL);
  7360. ioa_cfg->ipr_cmnd_list_dma = kcalloc(IPR_NUM_CMD_BLKS, sizeof(dma_addr_t), GFP_KERNEL);
  7361. if (!ioa_cfg->ipr_cmnd_list || !ioa_cfg->ipr_cmnd_list_dma) {
  7362. ipr_free_cmd_blks(ioa_cfg);
  7363. return -ENOMEM;
  7364. }
  7365. for (i = 0; i < IPR_NUM_CMD_BLKS; i++) {
  7366. ipr_cmd = pci_pool_alloc(ioa_cfg->ipr_cmd_pool, GFP_KERNEL, &dma_addr);
  7367. if (!ipr_cmd) {
  7368. ipr_free_cmd_blks(ioa_cfg);
  7369. return -ENOMEM;
  7370. }
  7371. memset(ipr_cmd, 0, sizeof(*ipr_cmd));
  7372. ioa_cfg->ipr_cmnd_list[i] = ipr_cmd;
  7373. ioa_cfg->ipr_cmnd_list_dma[i] = dma_addr;
  7374. ioarcb = &ipr_cmd->ioarcb;
  7375. ipr_cmd->dma_addr = dma_addr;
  7376. if (ioa_cfg->sis64)
  7377. ioarcb->a.ioarcb_host_pci_addr64 = cpu_to_be64(dma_addr);
  7378. else
  7379. ioarcb->a.ioarcb_host_pci_addr = cpu_to_be32(dma_addr);
  7380. ioarcb->host_response_handle = cpu_to_be32(i << 2);
  7381. if (ioa_cfg->sis64) {
  7382. ioarcb->u.sis64_addr_data.data_ioadl_addr =
  7383. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, i.ioadl64));
  7384. ioarcb->u.sis64_addr_data.ioasa_host_pci_addr =
  7385. cpu_to_be64(dma_addr + offsetof(struct ipr_cmnd, s.ioasa64));
  7386. } else {
  7387. ioarcb->write_ioadl_addr =
  7388. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, i.ioadl));
  7389. ioarcb->read_ioadl_addr = ioarcb->write_ioadl_addr;
  7390. ioarcb->ioasa_host_pci_addr =
  7391. cpu_to_be32(dma_addr + offsetof(struct ipr_cmnd, s.ioasa));
  7392. }
  7393. ioarcb->ioasa_len = cpu_to_be16(sizeof(struct ipr_ioasa));
  7394. ipr_cmd->cmd_index = i;
  7395. ipr_cmd->ioa_cfg = ioa_cfg;
  7396. ipr_cmd->sense_buffer_dma = dma_addr +
  7397. offsetof(struct ipr_cmnd, sense_buffer);
  7398. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  7399. }
  7400. return 0;
  7401. }
  7402. /**
  7403. * ipr_alloc_mem - Allocate memory for an adapter
  7404. * @ioa_cfg: ioa config struct
  7405. *
  7406. * Return value:
  7407. * 0 on success / non-zero for error
  7408. **/
  7409. static int ipr_alloc_mem(struct ipr_ioa_cfg *ioa_cfg)
  7410. {
  7411. struct pci_dev *pdev = ioa_cfg->pdev;
  7412. int i, rc = -ENOMEM;
  7413. ENTER;
  7414. ioa_cfg->res_entries = kzalloc(sizeof(struct ipr_resource_entry) *
  7415. ioa_cfg->max_devs_supported, GFP_KERNEL);
  7416. if (!ioa_cfg->res_entries)
  7417. goto out;
  7418. if (ioa_cfg->sis64) {
  7419. ioa_cfg->target_ids = kzalloc(sizeof(unsigned long) *
  7420. BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
  7421. ioa_cfg->array_ids = kzalloc(sizeof(unsigned long) *
  7422. BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
  7423. ioa_cfg->vset_ids = kzalloc(sizeof(unsigned long) *
  7424. BITS_TO_LONGS(ioa_cfg->max_devs_supported), GFP_KERNEL);
  7425. }
  7426. for (i = 0; i < ioa_cfg->max_devs_supported; i++) {
  7427. list_add_tail(&ioa_cfg->res_entries[i].queue, &ioa_cfg->free_res_q);
  7428. ioa_cfg->res_entries[i].ioa_cfg = ioa_cfg;
  7429. }
  7430. ioa_cfg->vpd_cbs = pci_alloc_consistent(ioa_cfg->pdev,
  7431. sizeof(struct ipr_misc_cbs),
  7432. &ioa_cfg->vpd_cbs_dma);
  7433. if (!ioa_cfg->vpd_cbs)
  7434. goto out_free_res_entries;
  7435. if (ipr_alloc_cmd_blks(ioa_cfg))
  7436. goto out_free_vpd_cbs;
  7437. ioa_cfg->host_rrq = pci_alloc_consistent(ioa_cfg->pdev,
  7438. sizeof(u32) * IPR_NUM_CMD_BLKS,
  7439. &ioa_cfg->host_rrq_dma);
  7440. if (!ioa_cfg->host_rrq)
  7441. goto out_ipr_free_cmd_blocks;
  7442. ioa_cfg->u.cfg_table = pci_alloc_consistent(ioa_cfg->pdev,
  7443. ioa_cfg->cfg_table_size,
  7444. &ioa_cfg->cfg_table_dma);
  7445. if (!ioa_cfg->u.cfg_table)
  7446. goto out_free_host_rrq;
  7447. for (i = 0; i < IPR_NUM_HCAMS; i++) {
  7448. ioa_cfg->hostrcb[i] = pci_alloc_consistent(ioa_cfg->pdev,
  7449. sizeof(struct ipr_hostrcb),
  7450. &ioa_cfg->hostrcb_dma[i]);
  7451. if (!ioa_cfg->hostrcb[i])
  7452. goto out_free_hostrcb_dma;
  7453. ioa_cfg->hostrcb[i]->hostrcb_dma =
  7454. ioa_cfg->hostrcb_dma[i] + offsetof(struct ipr_hostrcb, hcam);
  7455. ioa_cfg->hostrcb[i]->ioa_cfg = ioa_cfg;
  7456. list_add_tail(&ioa_cfg->hostrcb[i]->queue, &ioa_cfg->hostrcb_free_q);
  7457. }
  7458. ioa_cfg->trace = kzalloc(sizeof(struct ipr_trace_entry) *
  7459. IPR_NUM_TRACE_ENTRIES, GFP_KERNEL);
  7460. if (!ioa_cfg->trace)
  7461. goto out_free_hostrcb_dma;
  7462. rc = 0;
  7463. out:
  7464. LEAVE;
  7465. return rc;
  7466. out_free_hostrcb_dma:
  7467. while (i-- > 0) {
  7468. pci_free_consistent(pdev, sizeof(struct ipr_hostrcb),
  7469. ioa_cfg->hostrcb[i],
  7470. ioa_cfg->hostrcb_dma[i]);
  7471. }
  7472. pci_free_consistent(pdev, ioa_cfg->cfg_table_size,
  7473. ioa_cfg->u.cfg_table,
  7474. ioa_cfg->cfg_table_dma);
  7475. out_free_host_rrq:
  7476. pci_free_consistent(pdev, sizeof(u32) * IPR_NUM_CMD_BLKS,
  7477. ioa_cfg->host_rrq, ioa_cfg->host_rrq_dma);
  7478. out_ipr_free_cmd_blocks:
  7479. ipr_free_cmd_blks(ioa_cfg);
  7480. out_free_vpd_cbs:
  7481. pci_free_consistent(pdev, sizeof(struct ipr_misc_cbs),
  7482. ioa_cfg->vpd_cbs, ioa_cfg->vpd_cbs_dma);
  7483. out_free_res_entries:
  7484. kfree(ioa_cfg->res_entries);
  7485. goto out;
  7486. }
  7487. /**
  7488. * ipr_initialize_bus_attr - Initialize SCSI bus attributes to default values
  7489. * @ioa_cfg: ioa config struct
  7490. *
  7491. * Return value:
  7492. * none
  7493. **/
  7494. static void ipr_initialize_bus_attr(struct ipr_ioa_cfg *ioa_cfg)
  7495. {
  7496. int i;
  7497. for (i = 0; i < IPR_MAX_NUM_BUSES; i++) {
  7498. ioa_cfg->bus_attr[i].bus = i;
  7499. ioa_cfg->bus_attr[i].qas_enabled = 0;
  7500. ioa_cfg->bus_attr[i].bus_width = IPR_DEFAULT_BUS_WIDTH;
  7501. if (ipr_max_speed < ARRAY_SIZE(ipr_max_bus_speeds))
  7502. ioa_cfg->bus_attr[i].max_xfer_rate = ipr_max_bus_speeds[ipr_max_speed];
  7503. else
  7504. ioa_cfg->bus_attr[i].max_xfer_rate = IPR_U160_SCSI_RATE;
  7505. }
  7506. }
  7507. /**
  7508. * ipr_init_ioa_cfg - Initialize IOA config struct
  7509. * @ioa_cfg: ioa config struct
  7510. * @host: scsi host struct
  7511. * @pdev: PCI dev struct
  7512. *
  7513. * Return value:
  7514. * none
  7515. **/
  7516. static void ipr_init_ioa_cfg(struct ipr_ioa_cfg *ioa_cfg,
  7517. struct Scsi_Host *host, struct pci_dev *pdev)
  7518. {
  7519. const struct ipr_interrupt_offsets *p;
  7520. struct ipr_interrupts *t;
  7521. void __iomem *base;
  7522. ioa_cfg->host = host;
  7523. ioa_cfg->pdev = pdev;
  7524. ioa_cfg->log_level = ipr_log_level;
  7525. ioa_cfg->doorbell = IPR_DOORBELL;
  7526. sprintf(ioa_cfg->eye_catcher, IPR_EYECATCHER);
  7527. sprintf(ioa_cfg->trace_start, IPR_TRACE_START_LABEL);
  7528. sprintf(ioa_cfg->ipr_free_label, IPR_FREEQ_LABEL);
  7529. sprintf(ioa_cfg->ipr_pending_label, IPR_PENDQ_LABEL);
  7530. sprintf(ioa_cfg->cfg_table_start, IPR_CFG_TBL_START);
  7531. sprintf(ioa_cfg->resource_table_label, IPR_RES_TABLE_LABEL);
  7532. sprintf(ioa_cfg->ipr_hcam_label, IPR_HCAM_LABEL);
  7533. sprintf(ioa_cfg->ipr_cmd_label, IPR_CMD_LABEL);
  7534. INIT_LIST_HEAD(&ioa_cfg->free_q);
  7535. INIT_LIST_HEAD(&ioa_cfg->pending_q);
  7536. INIT_LIST_HEAD(&ioa_cfg->hostrcb_free_q);
  7537. INIT_LIST_HEAD(&ioa_cfg->hostrcb_pending_q);
  7538. INIT_LIST_HEAD(&ioa_cfg->free_res_q);
  7539. INIT_LIST_HEAD(&ioa_cfg->used_res_q);
  7540. INIT_WORK(&ioa_cfg->work_q, ipr_worker_thread);
  7541. init_waitqueue_head(&ioa_cfg->reset_wait_q);
  7542. init_waitqueue_head(&ioa_cfg->msi_wait_q);
  7543. ioa_cfg->sdt_state = INACTIVE;
  7544. ipr_initialize_bus_attr(ioa_cfg);
  7545. ioa_cfg->max_devs_supported = ipr_max_devs;
  7546. if (ioa_cfg->sis64) {
  7547. host->max_id = IPR_MAX_SIS64_TARGETS_PER_BUS;
  7548. host->max_lun = IPR_MAX_SIS64_LUNS_PER_TARGET;
  7549. if (ipr_max_devs > IPR_MAX_SIS64_DEVS)
  7550. ioa_cfg->max_devs_supported = IPR_MAX_SIS64_DEVS;
  7551. } else {
  7552. host->max_id = IPR_MAX_NUM_TARGETS_PER_BUS;
  7553. host->max_lun = IPR_MAX_NUM_LUNS_PER_TARGET;
  7554. if (ipr_max_devs > IPR_MAX_PHYSICAL_DEVS)
  7555. ioa_cfg->max_devs_supported = IPR_MAX_PHYSICAL_DEVS;
  7556. }
  7557. host->max_channel = IPR_MAX_BUS_TO_SCAN;
  7558. host->unique_id = host->host_no;
  7559. host->max_cmd_len = IPR_MAX_CDB_LEN;
  7560. host->can_queue = ioa_cfg->max_cmds;
  7561. pci_set_drvdata(pdev, ioa_cfg);
  7562. p = &ioa_cfg->chip_cfg->regs;
  7563. t = &ioa_cfg->regs;
  7564. base = ioa_cfg->hdw_dma_regs;
  7565. t->set_interrupt_mask_reg = base + p->set_interrupt_mask_reg;
  7566. t->clr_interrupt_mask_reg = base + p->clr_interrupt_mask_reg;
  7567. t->clr_interrupt_mask_reg32 = base + p->clr_interrupt_mask_reg32;
  7568. t->sense_interrupt_mask_reg = base + p->sense_interrupt_mask_reg;
  7569. t->sense_interrupt_mask_reg32 = base + p->sense_interrupt_mask_reg32;
  7570. t->clr_interrupt_reg = base + p->clr_interrupt_reg;
  7571. t->clr_interrupt_reg32 = base + p->clr_interrupt_reg32;
  7572. t->sense_interrupt_reg = base + p->sense_interrupt_reg;
  7573. t->sense_interrupt_reg32 = base + p->sense_interrupt_reg32;
  7574. t->ioarrin_reg = base + p->ioarrin_reg;
  7575. t->sense_uproc_interrupt_reg = base + p->sense_uproc_interrupt_reg;
  7576. t->sense_uproc_interrupt_reg32 = base + p->sense_uproc_interrupt_reg32;
  7577. t->set_uproc_interrupt_reg = base + p->set_uproc_interrupt_reg;
  7578. t->set_uproc_interrupt_reg32 = base + p->set_uproc_interrupt_reg32;
  7579. t->clr_uproc_interrupt_reg = base + p->clr_uproc_interrupt_reg;
  7580. t->clr_uproc_interrupt_reg32 = base + p->clr_uproc_interrupt_reg32;
  7581. if (ioa_cfg->sis64) {
  7582. t->init_feedback_reg = base + p->init_feedback_reg;
  7583. t->dump_addr_reg = base + p->dump_addr_reg;
  7584. t->dump_data_reg = base + p->dump_data_reg;
  7585. t->endian_swap_reg = base + p->endian_swap_reg;
  7586. }
  7587. }
  7588. /**
  7589. * ipr_get_chip_info - Find adapter chip information
  7590. * @dev_id: PCI device id struct
  7591. *
  7592. * Return value:
  7593. * ptr to chip information on success / NULL on failure
  7594. **/
  7595. static const struct ipr_chip_t *
  7596. ipr_get_chip_info(const struct pci_device_id *dev_id)
  7597. {
  7598. int i;
  7599. for (i = 0; i < ARRAY_SIZE(ipr_chip); i++)
  7600. if (ipr_chip[i].vendor == dev_id->vendor &&
  7601. ipr_chip[i].device == dev_id->device)
  7602. return &ipr_chip[i];
  7603. return NULL;
  7604. }
  7605. /**
  7606. * ipr_test_intr - Handle the interrupt generated in ipr_test_msi().
  7607. * @pdev: PCI device struct
  7608. *
  7609. * Description: Simply set the msi_received flag to 1 indicating that
  7610. * Message Signaled Interrupts are supported.
  7611. *
  7612. * Return value:
  7613. * 0 on success / non-zero on failure
  7614. **/
  7615. static irqreturn_t ipr_test_intr(int irq, void *devp)
  7616. {
  7617. struct ipr_ioa_cfg *ioa_cfg = (struct ipr_ioa_cfg *)devp;
  7618. unsigned long lock_flags = 0;
  7619. irqreturn_t rc = IRQ_HANDLED;
  7620. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7621. ioa_cfg->msi_received = 1;
  7622. wake_up(&ioa_cfg->msi_wait_q);
  7623. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7624. return rc;
  7625. }
  7626. /**
  7627. * ipr_test_msi - Test for Message Signaled Interrupt (MSI) support.
  7628. * @pdev: PCI device struct
  7629. *
  7630. * Description: The return value from pci_enable_msi() can not always be
  7631. * trusted. This routine sets up and initiates a test interrupt to determine
  7632. * if the interrupt is received via the ipr_test_intr() service routine.
  7633. * If the tests fails, the driver will fall back to LSI.
  7634. *
  7635. * Return value:
  7636. * 0 on success / non-zero on failure
  7637. **/
  7638. static int ipr_test_msi(struct ipr_ioa_cfg *ioa_cfg, struct pci_dev *pdev)
  7639. {
  7640. int rc;
  7641. volatile u32 int_reg;
  7642. unsigned long lock_flags = 0;
  7643. ENTER;
  7644. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7645. init_waitqueue_head(&ioa_cfg->msi_wait_q);
  7646. ioa_cfg->msi_received = 0;
  7647. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  7648. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.clr_interrupt_mask_reg32);
  7649. int_reg = readl(ioa_cfg->regs.sense_interrupt_mask_reg);
  7650. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7651. rc = request_irq(pdev->irq, ipr_test_intr, 0, IPR_NAME, ioa_cfg);
  7652. if (rc) {
  7653. dev_err(&pdev->dev, "Can not assign irq %d\n", pdev->irq);
  7654. return rc;
  7655. } else if (ipr_debug)
  7656. dev_info(&pdev->dev, "IRQ assigned: %d\n", pdev->irq);
  7657. writel(IPR_PCII_IO_DEBUG_ACKNOWLEDGE, ioa_cfg->regs.sense_interrupt_reg32);
  7658. int_reg = readl(ioa_cfg->regs.sense_interrupt_reg);
  7659. wait_event_timeout(ioa_cfg->msi_wait_q, ioa_cfg->msi_received, HZ);
  7660. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  7661. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  7662. if (!ioa_cfg->msi_received) {
  7663. /* MSI test failed */
  7664. dev_info(&pdev->dev, "MSI test failed. Falling back to LSI.\n");
  7665. rc = -EOPNOTSUPP;
  7666. } else if (ipr_debug)
  7667. dev_info(&pdev->dev, "MSI test succeeded.\n");
  7668. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  7669. free_irq(pdev->irq, ioa_cfg);
  7670. LEAVE;
  7671. return rc;
  7672. }
  7673. /**
  7674. * ipr_probe_ioa - Allocates memory and does first stage of initialization
  7675. * @pdev: PCI device struct
  7676. * @dev_id: PCI device id struct
  7677. *
  7678. * Return value:
  7679. * 0 on success / non-zero on failure
  7680. **/
  7681. static int ipr_probe_ioa(struct pci_dev *pdev,
  7682. const struct pci_device_id *dev_id)
  7683. {
  7684. struct ipr_ioa_cfg *ioa_cfg;
  7685. struct Scsi_Host *host;
  7686. unsigned long ipr_regs_pci;
  7687. void __iomem *ipr_regs;
  7688. int rc = PCIBIOS_SUCCESSFUL;
  7689. volatile u32 mask, uproc, interrupts;
  7690. ENTER;
  7691. if ((rc = pci_enable_device(pdev))) {
  7692. dev_err(&pdev->dev, "Cannot enable adapter\n");
  7693. goto out;
  7694. }
  7695. dev_info(&pdev->dev, "Found IOA with IRQ: %d\n", pdev->irq);
  7696. host = scsi_host_alloc(&driver_template, sizeof(*ioa_cfg));
  7697. if (!host) {
  7698. dev_err(&pdev->dev, "call to scsi_host_alloc failed!\n");
  7699. rc = -ENOMEM;
  7700. goto out_disable;
  7701. }
  7702. ioa_cfg = (struct ipr_ioa_cfg *)host->hostdata;
  7703. memset(ioa_cfg, 0, sizeof(struct ipr_ioa_cfg));
  7704. ata_host_init(&ioa_cfg->ata_host, &pdev->dev, &ipr_sata_ops);
  7705. ioa_cfg->ipr_chip = ipr_get_chip_info(dev_id);
  7706. if (!ioa_cfg->ipr_chip) {
  7707. dev_err(&pdev->dev, "Unknown adapter chipset 0x%04X 0x%04X\n",
  7708. dev_id->vendor, dev_id->device);
  7709. goto out_scsi_host_put;
  7710. }
  7711. /* set SIS 32 or SIS 64 */
  7712. ioa_cfg->sis64 = ioa_cfg->ipr_chip->sis_type == IPR_SIS64 ? 1 : 0;
  7713. ioa_cfg->chip_cfg = ioa_cfg->ipr_chip->cfg;
  7714. ioa_cfg->clear_isr = ioa_cfg->chip_cfg->clear_isr;
  7715. ioa_cfg->max_cmds = ioa_cfg->chip_cfg->max_cmds;
  7716. if (ipr_transop_timeout)
  7717. ioa_cfg->transop_timeout = ipr_transop_timeout;
  7718. else if (dev_id->driver_data & IPR_USE_LONG_TRANSOP_TIMEOUT)
  7719. ioa_cfg->transop_timeout = IPR_LONG_OPERATIONAL_TIMEOUT;
  7720. else
  7721. ioa_cfg->transop_timeout = IPR_OPERATIONAL_TIMEOUT;
  7722. ioa_cfg->revid = pdev->revision;
  7723. ipr_regs_pci = pci_resource_start(pdev, 0);
  7724. rc = pci_request_regions(pdev, IPR_NAME);
  7725. if (rc < 0) {
  7726. dev_err(&pdev->dev,
  7727. "Couldn't register memory range of registers\n");
  7728. goto out_scsi_host_put;
  7729. }
  7730. ipr_regs = pci_ioremap_bar(pdev, 0);
  7731. if (!ipr_regs) {
  7732. dev_err(&pdev->dev,
  7733. "Couldn't map memory range of registers\n");
  7734. rc = -ENOMEM;
  7735. goto out_release_regions;
  7736. }
  7737. ioa_cfg->hdw_dma_regs = ipr_regs;
  7738. ioa_cfg->hdw_dma_regs_pci = ipr_regs_pci;
  7739. ioa_cfg->ioa_mailbox = ioa_cfg->chip_cfg->mailbox + ipr_regs;
  7740. ipr_init_ioa_cfg(ioa_cfg, host, pdev);
  7741. pci_set_master(pdev);
  7742. if (ioa_cfg->sis64) {
  7743. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  7744. if (rc < 0) {
  7745. dev_dbg(&pdev->dev, "Failed to set 64 bit PCI DMA mask\n");
  7746. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  7747. }
  7748. } else
  7749. rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  7750. if (rc < 0) {
  7751. dev_err(&pdev->dev, "Failed to set PCI DMA mask\n");
  7752. goto cleanup_nomem;
  7753. }
  7754. rc = pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
  7755. ioa_cfg->chip_cfg->cache_line_size);
  7756. if (rc != PCIBIOS_SUCCESSFUL) {
  7757. dev_err(&pdev->dev, "Write of cache line size failed\n");
  7758. rc = -EIO;
  7759. goto cleanup_nomem;
  7760. }
  7761. /* Enable MSI style interrupts if they are supported. */
  7762. if (ioa_cfg->ipr_chip->intr_type == IPR_USE_MSI && !pci_enable_msi(pdev)) {
  7763. rc = ipr_test_msi(ioa_cfg, pdev);
  7764. if (rc == -EOPNOTSUPP)
  7765. pci_disable_msi(pdev);
  7766. else if (rc)
  7767. goto out_msi_disable;
  7768. else
  7769. dev_info(&pdev->dev, "MSI enabled with IRQ: %d\n", pdev->irq);
  7770. } else if (ipr_debug)
  7771. dev_info(&pdev->dev, "Cannot enable MSI.\n");
  7772. /* Save away PCI config space for use following IOA reset */
  7773. rc = pci_save_state(pdev);
  7774. if (rc != PCIBIOS_SUCCESSFUL) {
  7775. dev_err(&pdev->dev, "Failed to save PCI config space\n");
  7776. rc = -EIO;
  7777. goto out_msi_disable;
  7778. }
  7779. if ((rc = ipr_save_pcix_cmd_reg(ioa_cfg)))
  7780. goto out_msi_disable;
  7781. if ((rc = ipr_set_pcix_cmd_reg(ioa_cfg)))
  7782. goto out_msi_disable;
  7783. if (ioa_cfg->sis64)
  7784. ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr64)
  7785. + ((sizeof(struct ipr_config_table_entry64)
  7786. * ioa_cfg->max_devs_supported)));
  7787. else
  7788. ioa_cfg->cfg_table_size = (sizeof(struct ipr_config_table_hdr)
  7789. + ((sizeof(struct ipr_config_table_entry)
  7790. * ioa_cfg->max_devs_supported)));
  7791. rc = ipr_alloc_mem(ioa_cfg);
  7792. if (rc < 0) {
  7793. dev_err(&pdev->dev,
  7794. "Couldn't allocate enough memory for device driver!\n");
  7795. goto out_msi_disable;
  7796. }
  7797. /*
  7798. * If HRRQ updated interrupt is not masked, or reset alert is set,
  7799. * the card is in an unknown state and needs a hard reset
  7800. */
  7801. mask = readl(ioa_cfg->regs.sense_interrupt_mask_reg32);
  7802. interrupts = readl(ioa_cfg->regs.sense_interrupt_reg32);
  7803. uproc = readl(ioa_cfg->regs.sense_uproc_interrupt_reg32);
  7804. if ((mask & IPR_PCII_HRRQ_UPDATED) == 0 || (uproc & IPR_UPROCI_RESET_ALERT))
  7805. ioa_cfg->needs_hard_reset = 1;
  7806. if ((interrupts & IPR_PCII_ERROR_INTERRUPTS) || reset_devices)
  7807. ioa_cfg->needs_hard_reset = 1;
  7808. if (interrupts & IPR_PCII_IOA_UNIT_CHECKED)
  7809. ioa_cfg->ioa_unit_checked = 1;
  7810. ipr_mask_and_clear_interrupts(ioa_cfg, ~IPR_PCII_IOA_TRANS_TO_OPER);
  7811. rc = request_irq(pdev->irq, ipr_isr,
  7812. ioa_cfg->msi_received ? 0 : IRQF_SHARED,
  7813. IPR_NAME, ioa_cfg);
  7814. if (rc) {
  7815. dev_err(&pdev->dev, "Couldn't register IRQ %d! rc=%d\n",
  7816. pdev->irq, rc);
  7817. goto cleanup_nolog;
  7818. }
  7819. if ((dev_id->driver_data & IPR_USE_PCI_WARM_RESET) ||
  7820. (dev_id->device == PCI_DEVICE_ID_IBM_OBSIDIAN_E && !ioa_cfg->revid)) {
  7821. ioa_cfg->needs_warm_reset = 1;
  7822. ioa_cfg->reset = ipr_reset_slot_reset;
  7823. } else
  7824. ioa_cfg->reset = ipr_reset_start_bist;
  7825. spin_lock(&ipr_driver_lock);
  7826. list_add_tail(&ioa_cfg->queue, &ipr_ioa_head);
  7827. spin_unlock(&ipr_driver_lock);
  7828. LEAVE;
  7829. out:
  7830. return rc;
  7831. cleanup_nolog:
  7832. ipr_free_mem(ioa_cfg);
  7833. out_msi_disable:
  7834. pci_disable_msi(pdev);
  7835. cleanup_nomem:
  7836. iounmap(ipr_regs);
  7837. out_release_regions:
  7838. pci_release_regions(pdev);
  7839. out_scsi_host_put:
  7840. scsi_host_put(host);
  7841. out_disable:
  7842. pci_disable_device(pdev);
  7843. goto out;
  7844. }
  7845. /**
  7846. * ipr_scan_vsets - Scans for VSET devices
  7847. * @ioa_cfg: ioa config struct
  7848. *
  7849. * Description: Since the VSET resources do not follow SAM in that we can have
  7850. * sparse LUNs with no LUN 0, we have to scan for these ourselves.
  7851. *
  7852. * Return value:
  7853. * none
  7854. **/
  7855. static void ipr_scan_vsets(struct ipr_ioa_cfg *ioa_cfg)
  7856. {
  7857. int target, lun;
  7858. for (target = 0; target < IPR_MAX_NUM_TARGETS_PER_BUS; target++)
  7859. for (lun = 0; lun < IPR_MAX_NUM_VSET_LUNS_PER_TARGET; lun++)
  7860. scsi_add_device(ioa_cfg->host, IPR_VSET_BUS, target, lun);
  7861. }
  7862. /**
  7863. * ipr_initiate_ioa_bringdown - Bring down an adapter
  7864. * @ioa_cfg: ioa config struct
  7865. * @shutdown_type: shutdown type
  7866. *
  7867. * Description: This function will initiate bringing down the adapter.
  7868. * This consists of issuing an IOA shutdown to the adapter
  7869. * to flush the cache, and running BIST.
  7870. * If the caller needs to wait on the completion of the reset,
  7871. * the caller must sleep on the reset_wait_q.
  7872. *
  7873. * Return value:
  7874. * none
  7875. **/
  7876. static void ipr_initiate_ioa_bringdown(struct ipr_ioa_cfg *ioa_cfg,
  7877. enum ipr_shutdown_type shutdown_type)
  7878. {
  7879. ENTER;
  7880. if (ioa_cfg->sdt_state == WAIT_FOR_DUMP)
  7881. ioa_cfg->sdt_state = ABORT_DUMP;
  7882. ioa_cfg->reset_retries = 0;
  7883. ioa_cfg->in_ioa_bringdown = 1;
  7884. ipr_initiate_ioa_reset(ioa_cfg, shutdown_type);
  7885. LEAVE;
  7886. }
  7887. /**
  7888. * __ipr_remove - Remove a single adapter
  7889. * @pdev: pci device struct
  7890. *
  7891. * Adapter hot plug remove entry point.
  7892. *
  7893. * Return value:
  7894. * none
  7895. **/
  7896. static void __ipr_remove(struct pci_dev *pdev)
  7897. {
  7898. unsigned long host_lock_flags = 0;
  7899. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  7900. ENTER;
  7901. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  7902. while (ioa_cfg->in_reset_reload) {
  7903. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  7904. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  7905. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  7906. }
  7907. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  7908. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  7909. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  7910. flush_work(&ioa_cfg->work_q);
  7911. spin_lock_irqsave(ioa_cfg->host->host_lock, host_lock_flags);
  7912. spin_lock(&ipr_driver_lock);
  7913. list_del(&ioa_cfg->queue);
  7914. spin_unlock(&ipr_driver_lock);
  7915. if (ioa_cfg->sdt_state == ABORT_DUMP)
  7916. ioa_cfg->sdt_state = WAIT_FOR_DUMP;
  7917. spin_unlock_irqrestore(ioa_cfg->host->host_lock, host_lock_flags);
  7918. ipr_free_all_resources(ioa_cfg);
  7919. LEAVE;
  7920. }
  7921. /**
  7922. * ipr_remove - IOA hot plug remove entry point
  7923. * @pdev: pci device struct
  7924. *
  7925. * Adapter hot plug remove entry point.
  7926. *
  7927. * Return value:
  7928. * none
  7929. **/
  7930. static void ipr_remove(struct pci_dev *pdev)
  7931. {
  7932. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  7933. ENTER;
  7934. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  7935. &ipr_trace_attr);
  7936. ipr_remove_dump_file(&ioa_cfg->host->shost_dev.kobj,
  7937. &ipr_dump_attr);
  7938. scsi_remove_host(ioa_cfg->host);
  7939. __ipr_remove(pdev);
  7940. LEAVE;
  7941. }
  7942. /**
  7943. * ipr_probe - Adapter hot plug add entry point
  7944. *
  7945. * Return value:
  7946. * 0 on success / non-zero on failure
  7947. **/
  7948. static int ipr_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id)
  7949. {
  7950. struct ipr_ioa_cfg *ioa_cfg;
  7951. int rc;
  7952. rc = ipr_probe_ioa(pdev, dev_id);
  7953. if (rc)
  7954. return rc;
  7955. ioa_cfg = pci_get_drvdata(pdev);
  7956. rc = ipr_probe_ioa_part2(ioa_cfg);
  7957. if (rc) {
  7958. __ipr_remove(pdev);
  7959. return rc;
  7960. }
  7961. rc = scsi_add_host(ioa_cfg->host, &pdev->dev);
  7962. if (rc) {
  7963. __ipr_remove(pdev);
  7964. return rc;
  7965. }
  7966. rc = ipr_create_trace_file(&ioa_cfg->host->shost_dev.kobj,
  7967. &ipr_trace_attr);
  7968. if (rc) {
  7969. scsi_remove_host(ioa_cfg->host);
  7970. __ipr_remove(pdev);
  7971. return rc;
  7972. }
  7973. rc = ipr_create_dump_file(&ioa_cfg->host->shost_dev.kobj,
  7974. &ipr_dump_attr);
  7975. if (rc) {
  7976. ipr_remove_trace_file(&ioa_cfg->host->shost_dev.kobj,
  7977. &ipr_trace_attr);
  7978. scsi_remove_host(ioa_cfg->host);
  7979. __ipr_remove(pdev);
  7980. return rc;
  7981. }
  7982. scsi_scan_host(ioa_cfg->host);
  7983. ipr_scan_vsets(ioa_cfg);
  7984. scsi_add_device(ioa_cfg->host, IPR_IOA_BUS, IPR_IOA_TARGET, IPR_IOA_LUN);
  7985. ioa_cfg->allow_ml_add_del = 1;
  7986. ioa_cfg->host->max_channel = IPR_VSET_BUS;
  7987. schedule_work(&ioa_cfg->work_q);
  7988. return 0;
  7989. }
  7990. /**
  7991. * ipr_shutdown - Shutdown handler.
  7992. * @pdev: pci device struct
  7993. *
  7994. * This function is invoked upon system shutdown/reboot. It will issue
  7995. * an adapter shutdown to the adapter to flush the write cache.
  7996. *
  7997. * Return value:
  7998. * none
  7999. **/
  8000. static void ipr_shutdown(struct pci_dev *pdev)
  8001. {
  8002. struct ipr_ioa_cfg *ioa_cfg = pci_get_drvdata(pdev);
  8003. unsigned long lock_flags = 0;
  8004. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8005. while (ioa_cfg->in_reset_reload) {
  8006. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8007. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  8008. spin_lock_irqsave(ioa_cfg->host->host_lock, lock_flags);
  8009. }
  8010. ipr_initiate_ioa_bringdown(ioa_cfg, IPR_SHUTDOWN_NORMAL);
  8011. spin_unlock_irqrestore(ioa_cfg->host->host_lock, lock_flags);
  8012. wait_event(ioa_cfg->reset_wait_q, !ioa_cfg->in_reset_reload);
  8013. }
  8014. static struct pci_device_id ipr_pci_table[] = {
  8015. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  8016. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5702, 0, 0, 0 },
  8017. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  8018. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_5703, 0, 0, 0 },
  8019. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  8020. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573D, 0, 0, 0 },
  8021. { PCI_VENDOR_ID_MYLEX, PCI_DEVICE_ID_IBM_GEMSTONE,
  8022. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_573E, 0, 0, 0 },
  8023. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  8024. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571B, 0, 0, 0 },
  8025. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  8026. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572E, 0, 0, 0 },
  8027. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  8028. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571A, 0, 0, 0 },
  8029. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE,
  8030. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575B, 0, 0,
  8031. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8032. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  8033. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  8034. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  8035. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  8036. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8037. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_OBSIDIAN,
  8038. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  8039. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8040. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  8041. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572A, 0, 0, 0 },
  8042. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  8043. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572B, 0, 0,
  8044. IPR_USE_LONG_TRANSOP_TIMEOUT},
  8045. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN,
  8046. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_575C, 0, 0,
  8047. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8048. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  8049. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574E, 0, 0,
  8050. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8051. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  8052. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B3, 0, 0, 0 },
  8053. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  8054. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CC, 0, 0, 0 },
  8055. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_OBSIDIAN_E,
  8056. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B7, 0, 0,
  8057. IPR_USE_LONG_TRANSOP_TIMEOUT | IPR_USE_PCI_WARM_RESET },
  8058. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_SNIPE,
  8059. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_2780, 0, 0, 0 },
  8060. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  8061. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571E, 0, 0, 0 },
  8062. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  8063. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_571F, 0, 0,
  8064. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8065. { PCI_VENDOR_ID_ADAPTEC2, PCI_DEVICE_ID_ADAPTEC2_SCAMP,
  8066. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_572F, 0, 0,
  8067. IPR_USE_LONG_TRANSOP_TIMEOUT },
  8068. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  8069. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B5, 0, 0, 0 },
  8070. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  8071. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_574D, 0, 0, 0 },
  8072. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  8073. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B2, 0, 0, 0 },
  8074. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  8075. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C3, 0, 0, 0 },
  8076. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROC_FPGA_E2,
  8077. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C4, 0, 0, 0 },
  8078. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  8079. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B4, 0, 0, 0 },
  8080. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  8081. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57B1, 0, 0, 0 },
  8082. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  8083. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C6, 0, 0, 0 },
  8084. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  8085. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57C8, 0, 0, 0 },
  8086. { PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CROCODILE,
  8087. PCI_VENDOR_ID_IBM, IPR_SUBS_DEV_ID_57CE, 0, 0, 0 },
  8088. { }
  8089. };
  8090. MODULE_DEVICE_TABLE(pci, ipr_pci_table);
  8091. static const struct pci_error_handlers ipr_err_handler = {
  8092. .error_detected = ipr_pci_error_detected,
  8093. .slot_reset = ipr_pci_slot_reset,
  8094. };
  8095. static struct pci_driver ipr_driver = {
  8096. .name = IPR_NAME,
  8097. .id_table = ipr_pci_table,
  8098. .probe = ipr_probe,
  8099. .remove = ipr_remove,
  8100. .shutdown = ipr_shutdown,
  8101. .err_handler = &ipr_err_handler,
  8102. };
  8103. /**
  8104. * ipr_halt_done - Shutdown prepare completion
  8105. *
  8106. * Return value:
  8107. * none
  8108. **/
  8109. static void ipr_halt_done(struct ipr_cmnd *ipr_cmd)
  8110. {
  8111. struct ipr_ioa_cfg *ioa_cfg = ipr_cmd->ioa_cfg;
  8112. list_add_tail(&ipr_cmd->queue, &ioa_cfg->free_q);
  8113. }
  8114. /**
  8115. * ipr_halt - Issue shutdown prepare to all adapters
  8116. *
  8117. * Return value:
  8118. * NOTIFY_OK on success / NOTIFY_DONE on failure
  8119. **/
  8120. static int ipr_halt(struct notifier_block *nb, ulong event, void *buf)
  8121. {
  8122. struct ipr_cmnd *ipr_cmd;
  8123. struct ipr_ioa_cfg *ioa_cfg;
  8124. unsigned long flags = 0;
  8125. if (event != SYS_RESTART && event != SYS_HALT && event != SYS_POWER_OFF)
  8126. return NOTIFY_DONE;
  8127. spin_lock(&ipr_driver_lock);
  8128. list_for_each_entry(ioa_cfg, &ipr_ioa_head, queue) {
  8129. spin_lock_irqsave(ioa_cfg->host->host_lock, flags);
  8130. if (!ioa_cfg->allow_cmds) {
  8131. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8132. continue;
  8133. }
  8134. ipr_cmd = ipr_get_free_ipr_cmnd(ioa_cfg);
  8135. ipr_cmd->ioarcb.res_handle = cpu_to_be32(IPR_IOA_RES_HANDLE);
  8136. ipr_cmd->ioarcb.cmd_pkt.request_type = IPR_RQTYPE_IOACMD;
  8137. ipr_cmd->ioarcb.cmd_pkt.cdb[0] = IPR_IOA_SHUTDOWN;
  8138. ipr_cmd->ioarcb.cmd_pkt.cdb[1] = IPR_SHUTDOWN_PREPARE_FOR_NORMAL;
  8139. ipr_do_req(ipr_cmd, ipr_halt_done, ipr_timeout, IPR_DEVICE_RESET_TIMEOUT);
  8140. spin_unlock_irqrestore(ioa_cfg->host->host_lock, flags);
  8141. }
  8142. spin_unlock(&ipr_driver_lock);
  8143. return NOTIFY_OK;
  8144. }
  8145. static struct notifier_block ipr_notifier = {
  8146. ipr_halt, NULL, 0
  8147. };
  8148. /**
  8149. * ipr_init - Module entry point
  8150. *
  8151. * Return value:
  8152. * 0 on success / negative value on failure
  8153. **/
  8154. static int __init ipr_init(void)
  8155. {
  8156. ipr_info("IBM Power RAID SCSI Device Driver version: %s %s\n",
  8157. IPR_DRIVER_VERSION, IPR_DRIVER_DATE);
  8158. register_reboot_notifier(&ipr_notifier);
  8159. return pci_register_driver(&ipr_driver);
  8160. }
  8161. /**
  8162. * ipr_exit - Module unload
  8163. *
  8164. * Module unload entry point.
  8165. *
  8166. * Return value:
  8167. * none
  8168. **/
  8169. static void __exit ipr_exit(void)
  8170. {
  8171. unregister_reboot_notifier(&ipr_notifier);
  8172. pci_unregister_driver(&ipr_driver);
  8173. }
  8174. module_init(ipr_init);
  8175. module_exit(ipr_exit);