ipr.c 210 KB

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