ipr.c 213 KB

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