ipr.c 300 KB

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