ipr.c 258 KB

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