ipr.c 296 KB

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