ipr.c 206 KB

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