ipr.c 207 KB

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