ipr.c 242 KB

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