ipr.c 182 KB

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