ipr.c 301 KB

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