ipr.c 248 KB

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