ipr.c 219 KB

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