ipr.c 235 KB

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