mpt2sas_scsih.c 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258
  1. /*
  2. * Scsi Host Layer for MPT (Message Passing Technology) based controllers
  3. *
  4. * This code is based on drivers/scsi/mpt2sas/mpt2_scsih.c
  5. * Copyright (C) 2007-2009 LSI Corporation
  6. * (mailto:DL-MPTFusionLinux@lsi.com)
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (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. * NO WARRANTY
  19. * THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  20. * CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  21. * LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  22. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  23. * solely responsible for determining the appropriateness of using and
  24. * distributing the Program and assumes all risks associated with its
  25. * exercise of rights under this Agreement, including but not limited to
  26. * the risks and costs of program errors, damage to or loss of data,
  27. * programs or equipment, and unavailability or interruption of operations.
  28. * DISCLAIMER OF LIABILITY
  29. * NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  30. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  32. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  33. * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  34. * USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  35. * HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  36. * You should have received a copy of the GNU General Public License
  37. * along with this program; if not, write to the Free Software
  38. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
  39. * USA.
  40. */
  41. #include <linux/version.h>
  42. #include <linux/module.h>
  43. #include <linux/kernel.h>
  44. #include <linux/init.h>
  45. #include <linux/errno.h>
  46. #include <linux/blkdev.h>
  47. #include <linux/sched.h>
  48. #include <linux/workqueue.h>
  49. #include <linux/delay.h>
  50. #include <linux/pci.h>
  51. #include <linux/interrupt.h>
  52. #include "mpt2sas_base.h"
  53. MODULE_AUTHOR(MPT2SAS_AUTHOR);
  54. MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
  55. MODULE_LICENSE("GPL");
  56. MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
  57. #define RAID_CHANNEL 1
  58. /* forward proto's */
  59. static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  60. struct _sas_node *sas_expander);
  61. static void _firmware_event_work(struct work_struct *work);
  62. /* global parameters */
  63. LIST_HEAD(mpt2sas_ioc_list);
  64. /* local parameters */
  65. static u8 scsi_io_cb_idx = -1;
  66. static u8 tm_cb_idx = -1;
  67. static u8 ctl_cb_idx = -1;
  68. static u8 base_cb_idx = -1;
  69. static u8 transport_cb_idx = -1;
  70. static u8 config_cb_idx = -1;
  71. static int mpt_ids;
  72. static u8 tm_tr_cb_idx = -1 ;
  73. static u8 tm_sas_control_cb_idx = -1;
  74. /* command line options */
  75. static u32 logging_level;
  76. MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
  77. "(default=0)");
  78. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  79. #define MPT2SAS_MAX_LUN (16895)
  80. static int max_lun = MPT2SAS_MAX_LUN;
  81. module_param(max_lun, int, 0);
  82. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  83. /**
  84. * struct sense_info - common structure for obtaining sense keys
  85. * @skey: sense key
  86. * @asc: additional sense code
  87. * @ascq: additional sense code qualifier
  88. */
  89. struct sense_info {
  90. u8 skey;
  91. u8 asc;
  92. u8 ascq;
  93. };
  94. /**
  95. * struct fw_event_work - firmware event struct
  96. * @list: link list framework
  97. * @work: work object (ioc->fault_reset_work_q)
  98. * @ioc: per adapter object
  99. * @VF_ID: virtual function id
  100. * @VP_ID: virtual port id
  101. * @host_reset_handling: handling events during host reset
  102. * @ignore: flag meaning this event has been marked to ignore
  103. * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
  104. * @event_data: reply event data payload follows
  105. *
  106. * This object stored on ioc->fw_event_list.
  107. */
  108. struct fw_event_work {
  109. struct list_head list;
  110. struct work_struct work;
  111. struct MPT2SAS_ADAPTER *ioc;
  112. u8 VF_ID;
  113. u8 VP_ID;
  114. u8 host_reset_handling;
  115. u8 ignore;
  116. u16 event;
  117. void *event_data;
  118. };
  119. /**
  120. * struct _scsi_io_transfer - scsi io transfer
  121. * @handle: sas device handle (assigned by firmware)
  122. * @is_raid: flag set for hidden raid components
  123. * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
  124. * @data_length: data transfer length
  125. * @data_dma: dma pointer to data
  126. * @sense: sense data
  127. * @lun: lun number
  128. * @cdb_length: cdb length
  129. * @cdb: cdb contents
  130. * @timeout: timeout for this command
  131. * @VF_ID: virtual function id
  132. * @VP_ID: virtual port id
  133. * @valid_reply: flag set for reply message
  134. * @sense_length: sense length
  135. * @ioc_status: ioc status
  136. * @scsi_state: scsi state
  137. * @scsi_status: scsi staus
  138. * @log_info: log information
  139. * @transfer_length: data length transfer when there is a reply message
  140. *
  141. * Used for sending internal scsi commands to devices within this module.
  142. * Refer to _scsi_send_scsi_io().
  143. */
  144. struct _scsi_io_transfer {
  145. u16 handle;
  146. u8 is_raid;
  147. enum dma_data_direction dir;
  148. u32 data_length;
  149. dma_addr_t data_dma;
  150. u8 sense[SCSI_SENSE_BUFFERSIZE];
  151. u32 lun;
  152. u8 cdb_length;
  153. u8 cdb[32];
  154. u8 timeout;
  155. u8 VF_ID;
  156. u8 VP_ID;
  157. u8 valid_reply;
  158. /* the following bits are only valid when 'valid_reply = 1' */
  159. u32 sense_length;
  160. u16 ioc_status;
  161. u8 scsi_state;
  162. u8 scsi_status;
  163. u32 log_info;
  164. u32 transfer_length;
  165. };
  166. /*
  167. * The pci device ids are defined in mpi/mpi2_cnfg.h.
  168. */
  169. static struct pci_device_id scsih_pci_table[] = {
  170. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
  171. PCI_ANY_ID, PCI_ANY_ID },
  172. /* Falcon ~ 2008*/
  173. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
  174. PCI_ANY_ID, PCI_ANY_ID },
  175. /* Liberator ~ 2108 */
  176. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
  177. PCI_ANY_ID, PCI_ANY_ID },
  178. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
  179. PCI_ANY_ID, PCI_ANY_ID },
  180. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
  181. PCI_ANY_ID, PCI_ANY_ID },
  182. /* Meteor ~ 2116 */
  183. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
  184. PCI_ANY_ID, PCI_ANY_ID },
  185. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
  186. PCI_ANY_ID, PCI_ANY_ID },
  187. /* Thunderbolt ~ 2208 */
  188. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
  189. PCI_ANY_ID, PCI_ANY_ID },
  190. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
  191. PCI_ANY_ID, PCI_ANY_ID },
  192. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
  193. PCI_ANY_ID, PCI_ANY_ID },
  194. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
  195. PCI_ANY_ID, PCI_ANY_ID },
  196. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
  197. PCI_ANY_ID, PCI_ANY_ID },
  198. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
  199. PCI_ANY_ID, PCI_ANY_ID },
  200. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_7,
  201. PCI_ANY_ID, PCI_ANY_ID },
  202. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_8,
  203. PCI_ANY_ID, PCI_ANY_ID },
  204. {0} /* Terminating entry */
  205. };
  206. MODULE_DEVICE_TABLE(pci, scsih_pci_table);
  207. /**
  208. * _scsih_set_debug_level - global setting of ioc->logging_level.
  209. *
  210. * Note: The logging levels are defined in mpt2sas_debug.h.
  211. */
  212. static int
  213. _scsih_set_debug_level(const char *val, struct kernel_param *kp)
  214. {
  215. int ret = param_set_int(val, kp);
  216. struct MPT2SAS_ADAPTER *ioc;
  217. if (ret)
  218. return ret;
  219. printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
  220. list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
  221. ioc->logging_level = logging_level;
  222. return 0;
  223. }
  224. module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
  225. &logging_level, 0644);
  226. /**
  227. * _scsih_srch_boot_sas_address - search based on sas_address
  228. * @sas_address: sas address
  229. * @boot_device: boot device object from bios page 2
  230. *
  231. * Returns 1 when there's a match, 0 means no match.
  232. */
  233. static inline int
  234. _scsih_srch_boot_sas_address(u64 sas_address,
  235. Mpi2BootDeviceSasWwid_t *boot_device)
  236. {
  237. return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
  238. }
  239. /**
  240. * _scsih_srch_boot_device_name - search based on device name
  241. * @device_name: device name specified in INDENTIFY fram
  242. * @boot_device: boot device object from bios page 2
  243. *
  244. * Returns 1 when there's a match, 0 means no match.
  245. */
  246. static inline int
  247. _scsih_srch_boot_device_name(u64 device_name,
  248. Mpi2BootDeviceDeviceName_t *boot_device)
  249. {
  250. return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
  251. }
  252. /**
  253. * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
  254. * @enclosure_logical_id: enclosure logical id
  255. * @slot_number: slot number
  256. * @boot_device: boot device object from bios page 2
  257. *
  258. * Returns 1 when there's a match, 0 means no match.
  259. */
  260. static inline int
  261. _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
  262. Mpi2BootDeviceEnclosureSlot_t *boot_device)
  263. {
  264. return (enclosure_logical_id == le64_to_cpu(boot_device->
  265. EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
  266. SlotNumber)) ? 1 : 0;
  267. }
  268. /**
  269. * _scsih_is_boot_device - search for matching boot device.
  270. * @sas_address: sas address
  271. * @device_name: device name specified in INDENTIFY fram
  272. * @enclosure_logical_id: enclosure logical id
  273. * @slot_number: slot number
  274. * @form: specifies boot device form
  275. * @boot_device: boot device object from bios page 2
  276. *
  277. * Returns 1 when there's a match, 0 means no match.
  278. */
  279. static int
  280. _scsih_is_boot_device(u64 sas_address, u64 device_name,
  281. u64 enclosure_logical_id, u16 slot, u8 form,
  282. Mpi2BiosPage2BootDevice_t *boot_device)
  283. {
  284. int rc = 0;
  285. switch (form) {
  286. case MPI2_BIOSPAGE2_FORM_SAS_WWID:
  287. if (!sas_address)
  288. break;
  289. rc = _scsih_srch_boot_sas_address(
  290. sas_address, &boot_device->SasWwid);
  291. break;
  292. case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
  293. if (!enclosure_logical_id)
  294. break;
  295. rc = _scsih_srch_boot_encl_slot(
  296. enclosure_logical_id,
  297. slot, &boot_device->EnclosureSlot);
  298. break;
  299. case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
  300. if (!device_name)
  301. break;
  302. rc = _scsih_srch_boot_device_name(
  303. device_name, &boot_device->DeviceName);
  304. break;
  305. case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
  306. break;
  307. }
  308. return rc;
  309. }
  310. /**
  311. * _scsih_get_sas_address - set the sas_address for given device handle
  312. * @handle: device handle
  313. * @sas_address: sas address
  314. *
  315. * Returns 0 success, non-zero when failure
  316. */
  317. static int
  318. _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  319. u64 *sas_address)
  320. {
  321. Mpi2SasDevicePage0_t sas_device_pg0;
  322. Mpi2ConfigReply_t mpi_reply;
  323. u32 ioc_status;
  324. if (handle <= ioc->sas_hba.num_phys) {
  325. *sas_address = ioc->sas_hba.sas_address;
  326. return 0;
  327. } else
  328. *sas_address = 0;
  329. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  330. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  331. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  332. ioc->name, __FILE__, __LINE__, __func__);
  333. return -ENXIO;
  334. }
  335. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  336. MPI2_IOCSTATUS_MASK;
  337. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  338. printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
  339. "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
  340. __FILE__, __LINE__, __func__);
  341. return -EIO;
  342. }
  343. *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  344. return 0;
  345. }
  346. /**
  347. * _scsih_determine_boot_device - determine boot device.
  348. * @ioc: per adapter object
  349. * @device: either sas_device or raid_device object
  350. * @is_raid: [flag] 1 = raid object, 0 = sas object
  351. *
  352. * Determines whether this device should be first reported device to
  353. * to scsi-ml or sas transport, this purpose is for persistant boot device.
  354. * There are primary, alternate, and current entries in bios page 2. The order
  355. * priority is primary, alternate, then current. This routine saves
  356. * the corresponding device object and is_raid flag in the ioc object.
  357. * The saved data to be used later in _scsih_probe_boot_devices().
  358. */
  359. static void
  360. _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
  361. void *device, u8 is_raid)
  362. {
  363. struct _sas_device *sas_device;
  364. struct _raid_device *raid_device;
  365. u64 sas_address;
  366. u64 device_name;
  367. u64 enclosure_logical_id;
  368. u16 slot;
  369. /* only process this function when driver loads */
  370. if (!ioc->wait_for_port_enable_to_complete)
  371. return;
  372. if (!is_raid) {
  373. sas_device = device;
  374. sas_address = sas_device->sas_address;
  375. device_name = sas_device->device_name;
  376. enclosure_logical_id = sas_device->enclosure_logical_id;
  377. slot = sas_device->slot;
  378. } else {
  379. raid_device = device;
  380. sas_address = raid_device->wwid;
  381. device_name = 0;
  382. enclosure_logical_id = 0;
  383. slot = 0;
  384. }
  385. if (!ioc->req_boot_device.device) {
  386. if (_scsih_is_boot_device(sas_address, device_name,
  387. enclosure_logical_id, slot,
  388. (ioc->bios_pg2.ReqBootDeviceForm &
  389. MPI2_BIOSPAGE2_FORM_MASK),
  390. &ioc->bios_pg2.RequestedBootDevice)) {
  391. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  392. "%s: req_boot_device(0x%016llx)\n",
  393. ioc->name, __func__,
  394. (unsigned long long)sas_address));
  395. ioc->req_boot_device.device = device;
  396. ioc->req_boot_device.is_raid = is_raid;
  397. }
  398. }
  399. if (!ioc->req_alt_boot_device.device) {
  400. if (_scsih_is_boot_device(sas_address, device_name,
  401. enclosure_logical_id, slot,
  402. (ioc->bios_pg2.ReqAltBootDeviceForm &
  403. MPI2_BIOSPAGE2_FORM_MASK),
  404. &ioc->bios_pg2.RequestedAltBootDevice)) {
  405. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  406. "%s: req_alt_boot_device(0x%016llx)\n",
  407. ioc->name, __func__,
  408. (unsigned long long)sas_address));
  409. ioc->req_alt_boot_device.device = device;
  410. ioc->req_alt_boot_device.is_raid = is_raid;
  411. }
  412. }
  413. if (!ioc->current_boot_device.device) {
  414. if (_scsih_is_boot_device(sas_address, device_name,
  415. enclosure_logical_id, slot,
  416. (ioc->bios_pg2.CurrentBootDeviceForm &
  417. MPI2_BIOSPAGE2_FORM_MASK),
  418. &ioc->bios_pg2.CurrentBootDevice)) {
  419. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  420. "%s: current_boot_device(0x%016llx)\n",
  421. ioc->name, __func__,
  422. (unsigned long long)sas_address));
  423. ioc->current_boot_device.device = device;
  424. ioc->current_boot_device.is_raid = is_raid;
  425. }
  426. }
  427. }
  428. /**
  429. * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
  430. * @ioc: per adapter object
  431. * @sas_address: sas address
  432. * Context: Calling function should acquire ioc->sas_device_lock
  433. *
  434. * This searches for sas_device based on sas_address, then return sas_device
  435. * object.
  436. */
  437. struct _sas_device *
  438. mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  439. u64 sas_address)
  440. {
  441. struct _sas_device *sas_device, *r;
  442. r = NULL;
  443. /* check the sas_device_init_list */
  444. list_for_each_entry(sas_device, &ioc->sas_device_init_list,
  445. list) {
  446. if (sas_device->sas_address != sas_address)
  447. continue;
  448. r = sas_device;
  449. goto out;
  450. }
  451. /* then check the sas_device_list */
  452. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  453. if (sas_device->sas_address != sas_address)
  454. continue;
  455. r = sas_device;
  456. goto out;
  457. }
  458. out:
  459. return r;
  460. }
  461. /**
  462. * _scsih_sas_device_find_by_handle - sas device search
  463. * @ioc: per adapter object
  464. * @handle: sas device handle (assigned by firmware)
  465. * Context: Calling function should acquire ioc->sas_device_lock
  466. *
  467. * This searches for sas_device based on sas_address, then return sas_device
  468. * object.
  469. */
  470. static struct _sas_device *
  471. _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  472. {
  473. struct _sas_device *sas_device, *r;
  474. r = NULL;
  475. if (ioc->wait_for_port_enable_to_complete) {
  476. list_for_each_entry(sas_device, &ioc->sas_device_init_list,
  477. list) {
  478. if (sas_device->handle != handle)
  479. continue;
  480. r = sas_device;
  481. goto out;
  482. }
  483. } else {
  484. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  485. if (sas_device->handle != handle)
  486. continue;
  487. r = sas_device;
  488. goto out;
  489. }
  490. }
  491. out:
  492. return r;
  493. }
  494. /**
  495. * _scsih_sas_device_remove - remove sas_device from list.
  496. * @ioc: per adapter object
  497. * @sas_device: the sas_device object
  498. * Context: This function will acquire ioc->sas_device_lock.
  499. *
  500. * Removing object and freeing associated memory from the ioc->sas_device_list.
  501. */
  502. static void
  503. _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
  504. struct _sas_device *sas_device)
  505. {
  506. unsigned long flags;
  507. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  508. list_del(&sas_device->list);
  509. memset(sas_device, 0, sizeof(struct _sas_device));
  510. kfree(sas_device);
  511. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  512. }
  513. /**
  514. * _scsih_sas_device_add - insert sas_device to the list.
  515. * @ioc: per adapter object
  516. * @sas_device: the sas_device object
  517. * Context: This function will acquire ioc->sas_device_lock.
  518. *
  519. * Adding new object to the ioc->sas_device_list.
  520. */
  521. static void
  522. _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
  523. struct _sas_device *sas_device)
  524. {
  525. unsigned long flags;
  526. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
  527. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  528. sas_device->handle, (unsigned long long)sas_device->sas_address));
  529. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  530. list_add_tail(&sas_device->list, &ioc->sas_device_list);
  531. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  532. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  533. sas_device->sas_address_parent))
  534. _scsih_sas_device_remove(ioc, sas_device);
  535. }
  536. /**
  537. * _scsih_sas_device_init_add - insert sas_device to the list.
  538. * @ioc: per adapter object
  539. * @sas_device: the sas_device object
  540. * Context: This function will acquire ioc->sas_device_lock.
  541. *
  542. * Adding new object at driver load time to the ioc->sas_device_init_list.
  543. */
  544. static void
  545. _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
  546. struct _sas_device *sas_device)
  547. {
  548. unsigned long flags;
  549. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
  550. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  551. sas_device->handle, (unsigned long long)sas_device->sas_address));
  552. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  553. list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
  554. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  555. _scsih_determine_boot_device(ioc, sas_device, 0);
  556. }
  557. /**
  558. * _scsih_raid_device_find_by_id - raid device search
  559. * @ioc: per adapter object
  560. * @id: sas device target id
  561. * @channel: sas device channel
  562. * Context: Calling function should acquire ioc->raid_device_lock
  563. *
  564. * This searches for raid_device based on target id, then return raid_device
  565. * object.
  566. */
  567. static struct _raid_device *
  568. _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
  569. {
  570. struct _raid_device *raid_device, *r;
  571. r = NULL;
  572. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  573. if (raid_device->id == id && raid_device->channel == channel) {
  574. r = raid_device;
  575. goto out;
  576. }
  577. }
  578. out:
  579. return r;
  580. }
  581. /**
  582. * _scsih_raid_device_find_by_handle - raid device search
  583. * @ioc: per adapter object
  584. * @handle: sas device handle (assigned by firmware)
  585. * Context: Calling function should acquire ioc->raid_device_lock
  586. *
  587. * This searches for raid_device based on handle, then return raid_device
  588. * object.
  589. */
  590. static struct _raid_device *
  591. _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  592. {
  593. struct _raid_device *raid_device, *r;
  594. r = NULL;
  595. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  596. if (raid_device->handle != handle)
  597. continue;
  598. r = raid_device;
  599. goto out;
  600. }
  601. out:
  602. return r;
  603. }
  604. /**
  605. * _scsih_raid_device_find_by_wwid - raid device search
  606. * @ioc: per adapter object
  607. * @handle: sas device handle (assigned by firmware)
  608. * Context: Calling function should acquire ioc->raid_device_lock
  609. *
  610. * This searches for raid_device based on wwid, then return raid_device
  611. * object.
  612. */
  613. static struct _raid_device *
  614. _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
  615. {
  616. struct _raid_device *raid_device, *r;
  617. r = NULL;
  618. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  619. if (raid_device->wwid != wwid)
  620. continue;
  621. r = raid_device;
  622. goto out;
  623. }
  624. out:
  625. return r;
  626. }
  627. /**
  628. * _scsih_raid_device_add - add raid_device object
  629. * @ioc: per adapter object
  630. * @raid_device: raid_device object
  631. *
  632. * This is added to the raid_device_list link list.
  633. */
  634. static void
  635. _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
  636. struct _raid_device *raid_device)
  637. {
  638. unsigned long flags;
  639. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
  640. "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  641. raid_device->handle, (unsigned long long)raid_device->wwid));
  642. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  643. list_add_tail(&raid_device->list, &ioc->raid_device_list);
  644. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  645. }
  646. /**
  647. * _scsih_raid_device_remove - delete raid_device object
  648. * @ioc: per adapter object
  649. * @raid_device: raid_device object
  650. *
  651. * This is removed from the raid_device_list link list.
  652. */
  653. static void
  654. _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
  655. struct _raid_device *raid_device)
  656. {
  657. unsigned long flags;
  658. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  659. list_del(&raid_device->list);
  660. memset(raid_device, 0, sizeof(struct _raid_device));
  661. kfree(raid_device);
  662. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  663. }
  664. /**
  665. * mpt2sas_scsih_expander_find_by_handle - expander device search
  666. * @ioc: per adapter object
  667. * @handle: expander handle (assigned by firmware)
  668. * Context: Calling function should acquire ioc->sas_device_lock
  669. *
  670. * This searches for expander device based on handle, then returns the
  671. * sas_node object.
  672. */
  673. struct _sas_node *
  674. mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  675. {
  676. struct _sas_node *sas_expander, *r;
  677. r = NULL;
  678. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  679. if (sas_expander->handle != handle)
  680. continue;
  681. r = sas_expander;
  682. goto out;
  683. }
  684. out:
  685. return r;
  686. }
  687. /**
  688. * mpt2sas_scsih_expander_find_by_sas_address - expander device search
  689. * @ioc: per adapter object
  690. * @sas_address: sas address
  691. * Context: Calling function should acquire ioc->sas_node_lock.
  692. *
  693. * This searches for expander device based on sas_address, then returns the
  694. * sas_node object.
  695. */
  696. struct _sas_node *
  697. mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  698. u64 sas_address)
  699. {
  700. struct _sas_node *sas_expander, *r;
  701. r = NULL;
  702. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  703. if (sas_expander->sas_address != sas_address)
  704. continue;
  705. r = sas_expander;
  706. goto out;
  707. }
  708. out:
  709. return r;
  710. }
  711. /**
  712. * _scsih_expander_node_add - insert expander device to the list.
  713. * @ioc: per adapter object
  714. * @sas_expander: the sas_device object
  715. * Context: This function will acquire ioc->sas_node_lock.
  716. *
  717. * Adding new object to the ioc->sas_expander_list.
  718. *
  719. * Return nothing.
  720. */
  721. static void
  722. _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
  723. struct _sas_node *sas_expander)
  724. {
  725. unsigned long flags;
  726. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  727. list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
  728. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  729. }
  730. /**
  731. * _scsih_is_end_device - determines if device is an end device
  732. * @device_info: bitfield providing information about the device.
  733. * Context: none
  734. *
  735. * Returns 1 if end device.
  736. */
  737. static int
  738. _scsih_is_end_device(u32 device_info)
  739. {
  740. if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
  741. ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
  742. (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
  743. (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
  744. return 1;
  745. else
  746. return 0;
  747. }
  748. /**
  749. * mptscsih_get_scsi_lookup - returns scmd entry
  750. * @ioc: per adapter object
  751. * @smid: system request message index
  752. *
  753. * Returns the smid stored scmd pointer.
  754. */
  755. static struct scsi_cmnd *
  756. _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  757. {
  758. return ioc->scsi_lookup[smid - 1].scmd;
  759. }
  760. /**
  761. * _scsih_scsi_lookup_find_by_scmd - scmd lookup
  762. * @ioc: per adapter object
  763. * @smid: system request message index
  764. * @scmd: pointer to scsi command object
  765. * Context: This function will acquire ioc->scsi_lookup_lock.
  766. *
  767. * This will search for a scmd pointer in the scsi_lookup array,
  768. * returning the revelent smid. A returned value of zero means invalid.
  769. */
  770. static u16
  771. _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
  772. *scmd)
  773. {
  774. u16 smid;
  775. unsigned long flags;
  776. int i;
  777. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  778. smid = 0;
  779. for (i = 0; i < ioc->scsiio_depth; i++) {
  780. if (ioc->scsi_lookup[i].scmd == scmd) {
  781. smid = ioc->scsi_lookup[i].smid;
  782. goto out;
  783. }
  784. }
  785. out:
  786. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  787. return smid;
  788. }
  789. /**
  790. * _scsih_scsi_lookup_find_by_target - search for matching channel:id
  791. * @ioc: per adapter object
  792. * @id: target id
  793. * @channel: channel
  794. * Context: This function will acquire ioc->scsi_lookup_lock.
  795. *
  796. * This will search for a matching channel:id in the scsi_lookup array,
  797. * returning 1 if found.
  798. */
  799. static u8
  800. _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
  801. int channel)
  802. {
  803. u8 found;
  804. unsigned long flags;
  805. int i;
  806. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  807. found = 0;
  808. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  809. if (ioc->scsi_lookup[i].scmd &&
  810. (ioc->scsi_lookup[i].scmd->device->id == id &&
  811. ioc->scsi_lookup[i].scmd->device->channel == channel)) {
  812. found = 1;
  813. goto out;
  814. }
  815. }
  816. out:
  817. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  818. return found;
  819. }
  820. /**
  821. * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
  822. * @ioc: per adapter object
  823. * @id: target id
  824. * @lun: lun number
  825. * @channel: channel
  826. * Context: This function will acquire ioc->scsi_lookup_lock.
  827. *
  828. * This will search for a matching channel:id:lun in the scsi_lookup array,
  829. * returning 1 if found.
  830. */
  831. static u8
  832. _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
  833. unsigned int lun, int channel)
  834. {
  835. u8 found;
  836. unsigned long flags;
  837. int i;
  838. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  839. found = 0;
  840. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  841. if (ioc->scsi_lookup[i].scmd &&
  842. (ioc->scsi_lookup[i].scmd->device->id == id &&
  843. ioc->scsi_lookup[i].scmd->device->channel == channel &&
  844. ioc->scsi_lookup[i].scmd->device->lun == lun)) {
  845. found = 1;
  846. goto out;
  847. }
  848. }
  849. out:
  850. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  851. return found;
  852. }
  853. /**
  854. * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
  855. * @ioc: per adapter object
  856. * @smid: system request message index
  857. *
  858. * Returns phys pointer to chain buffer.
  859. */
  860. static dma_addr_t
  861. _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  862. {
  863. return ioc->chain_dma + ((smid - 1) * (ioc->request_sz *
  864. ioc->chains_needed_per_io));
  865. }
  866. /**
  867. * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
  868. * @ioc: per adapter object
  869. * @smid: system request message index
  870. *
  871. * Returns virt pointer to chain buffer.
  872. */
  873. static void *
  874. _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  875. {
  876. return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz *
  877. ioc->chains_needed_per_io)));
  878. }
  879. /**
  880. * _scsih_build_scatter_gather - main sg creation routine
  881. * @ioc: per adapter object
  882. * @scmd: scsi command
  883. * @smid: system request message index
  884. * Context: none.
  885. *
  886. * The main routine that builds scatter gather table from a given
  887. * scsi request sent via the .queuecommand main handler.
  888. *
  889. * Returns 0 success, anything else error
  890. */
  891. static int
  892. _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
  893. struct scsi_cmnd *scmd, u16 smid)
  894. {
  895. Mpi2SCSIIORequest_t *mpi_request;
  896. dma_addr_t chain_dma;
  897. struct scatterlist *sg_scmd;
  898. void *sg_local, *chain;
  899. u32 chain_offset;
  900. u32 chain_length;
  901. u32 chain_flags;
  902. u32 sges_left;
  903. u32 sges_in_segment;
  904. u32 sgl_flags;
  905. u32 sgl_flags_last_element;
  906. u32 sgl_flags_end_buffer;
  907. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  908. /* init scatter gather flags */
  909. sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
  910. if (scmd->sc_data_direction == DMA_TO_DEVICE)
  911. sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
  912. sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
  913. << MPI2_SGE_FLAGS_SHIFT;
  914. sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
  915. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
  916. << MPI2_SGE_FLAGS_SHIFT;
  917. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  918. sg_scmd = scsi_sglist(scmd);
  919. sges_left = scsi_dma_map(scmd);
  920. if (!sges_left) {
  921. sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
  922. " failed: request for %d bytes!\n", scsi_bufflen(scmd));
  923. return -ENOMEM;
  924. }
  925. sg_local = &mpi_request->SGL;
  926. sges_in_segment = ioc->max_sges_in_main_message;
  927. if (sges_left <= sges_in_segment)
  928. goto fill_in_last_segment;
  929. mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
  930. (sges_in_segment * ioc->sge_size))/4;
  931. /* fill in main message segment when there is a chain following */
  932. while (sges_in_segment) {
  933. if (sges_in_segment == 1)
  934. ioc->base_add_sg_single(sg_local,
  935. sgl_flags_last_element | sg_dma_len(sg_scmd),
  936. sg_dma_address(sg_scmd));
  937. else
  938. ioc->base_add_sg_single(sg_local, sgl_flags |
  939. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  940. sg_scmd = sg_next(sg_scmd);
  941. sg_local += ioc->sge_size;
  942. sges_left--;
  943. sges_in_segment--;
  944. }
  945. /* initializing the chain flags and pointers */
  946. chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
  947. chain = _scsih_get_chain_buffer(ioc, smid);
  948. chain_dma = _scsih_get_chain_buffer_dma(ioc, smid);
  949. do {
  950. sges_in_segment = (sges_left <=
  951. ioc->max_sges_in_chain_message) ? sges_left :
  952. ioc->max_sges_in_chain_message;
  953. chain_offset = (sges_left == sges_in_segment) ?
  954. 0 : (sges_in_segment * ioc->sge_size)/4;
  955. chain_length = sges_in_segment * ioc->sge_size;
  956. if (chain_offset) {
  957. chain_offset = chain_offset <<
  958. MPI2_SGE_CHAIN_OFFSET_SHIFT;
  959. chain_length += ioc->sge_size;
  960. }
  961. ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
  962. chain_length, chain_dma);
  963. sg_local = chain;
  964. if (!chain_offset)
  965. goto fill_in_last_segment;
  966. /* fill in chain segments */
  967. while (sges_in_segment) {
  968. if (sges_in_segment == 1)
  969. ioc->base_add_sg_single(sg_local,
  970. sgl_flags_last_element |
  971. sg_dma_len(sg_scmd),
  972. sg_dma_address(sg_scmd));
  973. else
  974. ioc->base_add_sg_single(sg_local, sgl_flags |
  975. sg_dma_len(sg_scmd),
  976. sg_dma_address(sg_scmd));
  977. sg_scmd = sg_next(sg_scmd);
  978. sg_local += ioc->sge_size;
  979. sges_left--;
  980. sges_in_segment--;
  981. }
  982. chain_dma += ioc->request_sz;
  983. chain += ioc->request_sz;
  984. } while (1);
  985. fill_in_last_segment:
  986. /* fill the last segment */
  987. while (sges_left) {
  988. if (sges_left == 1)
  989. ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
  990. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  991. else
  992. ioc->base_add_sg_single(sg_local, sgl_flags |
  993. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  994. sg_scmd = sg_next(sg_scmd);
  995. sg_local += ioc->sge_size;
  996. sges_left--;
  997. }
  998. return 0;
  999. }
  1000. /**
  1001. * _scsih_change_queue_depth - setting device queue depth
  1002. * @sdev: scsi device struct
  1003. * @qdepth: requested queue depth
  1004. *
  1005. * Returns queue depth.
  1006. */
  1007. static int
  1008. _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1009. {
  1010. struct Scsi_Host *shost = sdev->host;
  1011. int max_depth;
  1012. int tag_type;
  1013. max_depth = shost->can_queue;
  1014. if (!sdev->tagged_supported)
  1015. max_depth = 1;
  1016. if (qdepth > max_depth)
  1017. qdepth = max_depth;
  1018. tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG;
  1019. scsi_adjust_queue_depth(sdev, tag_type, qdepth);
  1020. if (sdev->inquiry_len > 7)
  1021. sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
  1022. "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
  1023. sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
  1024. sdev->ordered_tags, sdev->scsi_level,
  1025. (sdev->inquiry[7] & 2) >> 1);
  1026. return sdev->queue_depth;
  1027. }
  1028. /**
  1029. * _scsih_change_queue_type - changing device queue tag type
  1030. * @sdev: scsi device struct
  1031. * @tag_type: requested tag type
  1032. *
  1033. * Returns queue tag type.
  1034. */
  1035. static int
  1036. _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
  1037. {
  1038. if (sdev->tagged_supported) {
  1039. scsi_set_tag_type(sdev, tag_type);
  1040. if (tag_type)
  1041. scsi_activate_tcq(sdev, sdev->queue_depth);
  1042. else
  1043. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1044. } else
  1045. tag_type = 0;
  1046. return tag_type;
  1047. }
  1048. /**
  1049. * _scsih_target_alloc - target add routine
  1050. * @starget: scsi target struct
  1051. *
  1052. * Returns 0 if ok. Any other return is assumed to be an error and
  1053. * the device is ignored.
  1054. */
  1055. static int
  1056. _scsih_target_alloc(struct scsi_target *starget)
  1057. {
  1058. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1059. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1060. struct MPT2SAS_TARGET *sas_target_priv_data;
  1061. struct _sas_device *sas_device;
  1062. struct _raid_device *raid_device;
  1063. unsigned long flags;
  1064. struct sas_rphy *rphy;
  1065. sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
  1066. if (!sas_target_priv_data)
  1067. return -ENOMEM;
  1068. starget->hostdata = sas_target_priv_data;
  1069. sas_target_priv_data->starget = starget;
  1070. sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
  1071. /* RAID volumes */
  1072. if (starget->channel == RAID_CHANNEL) {
  1073. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1074. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1075. starget->channel);
  1076. if (raid_device) {
  1077. sas_target_priv_data->handle = raid_device->handle;
  1078. sas_target_priv_data->sas_address = raid_device->wwid;
  1079. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
  1080. raid_device->starget = starget;
  1081. }
  1082. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1083. return 0;
  1084. }
  1085. /* sas/sata devices */
  1086. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1087. rphy = dev_to_rphy(starget->dev.parent);
  1088. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1089. rphy->identify.sas_address);
  1090. if (sas_device) {
  1091. sas_target_priv_data->handle = sas_device->handle;
  1092. sas_target_priv_data->sas_address = sas_device->sas_address;
  1093. sas_device->starget = starget;
  1094. sas_device->id = starget->id;
  1095. sas_device->channel = starget->channel;
  1096. if (sas_device->hidden_raid_component)
  1097. sas_target_priv_data->flags |=
  1098. MPT_TARGET_FLAGS_RAID_COMPONENT;
  1099. }
  1100. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1101. return 0;
  1102. }
  1103. /**
  1104. * _scsih_target_destroy - target destroy routine
  1105. * @starget: scsi target struct
  1106. *
  1107. * Returns nothing.
  1108. */
  1109. static void
  1110. _scsih_target_destroy(struct scsi_target *starget)
  1111. {
  1112. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1113. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1114. struct MPT2SAS_TARGET *sas_target_priv_data;
  1115. struct _sas_device *sas_device;
  1116. struct _raid_device *raid_device;
  1117. unsigned long flags;
  1118. struct sas_rphy *rphy;
  1119. sas_target_priv_data = starget->hostdata;
  1120. if (!sas_target_priv_data)
  1121. return;
  1122. if (starget->channel == RAID_CHANNEL) {
  1123. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1124. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1125. starget->channel);
  1126. if (raid_device) {
  1127. raid_device->starget = NULL;
  1128. raid_device->sdev = NULL;
  1129. }
  1130. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1131. goto out;
  1132. }
  1133. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1134. rphy = dev_to_rphy(starget->dev.parent);
  1135. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1136. rphy->identify.sas_address);
  1137. if (sas_device && (sas_device->starget == starget) &&
  1138. (sas_device->id == starget->id) &&
  1139. (sas_device->channel == starget->channel))
  1140. sas_device->starget = NULL;
  1141. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1142. out:
  1143. kfree(sas_target_priv_data);
  1144. starget->hostdata = NULL;
  1145. }
  1146. /**
  1147. * _scsih_slave_alloc - device add routine
  1148. * @sdev: scsi device struct
  1149. *
  1150. * Returns 0 if ok. Any other return is assumed to be an error and
  1151. * the device is ignored.
  1152. */
  1153. static int
  1154. _scsih_slave_alloc(struct scsi_device *sdev)
  1155. {
  1156. struct Scsi_Host *shost;
  1157. struct MPT2SAS_ADAPTER *ioc;
  1158. struct MPT2SAS_TARGET *sas_target_priv_data;
  1159. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1160. struct scsi_target *starget;
  1161. struct _raid_device *raid_device;
  1162. struct _sas_device *sas_device;
  1163. unsigned long flags;
  1164. sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
  1165. if (!sas_device_priv_data)
  1166. return -ENOMEM;
  1167. sas_device_priv_data->lun = sdev->lun;
  1168. sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
  1169. starget = scsi_target(sdev);
  1170. sas_target_priv_data = starget->hostdata;
  1171. sas_target_priv_data->num_luns++;
  1172. sas_device_priv_data->sas_target = sas_target_priv_data;
  1173. sdev->hostdata = sas_device_priv_data;
  1174. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
  1175. sdev->no_uld_attach = 1;
  1176. shost = dev_to_shost(&starget->dev);
  1177. ioc = shost_priv(shost);
  1178. if (starget->channel == RAID_CHANNEL) {
  1179. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1180. raid_device = _scsih_raid_device_find_by_id(ioc,
  1181. starget->id, starget->channel);
  1182. if (raid_device)
  1183. raid_device->sdev = sdev; /* raid is single lun */
  1184. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1185. } else {
  1186. /* set TLR bit for SSP devices */
  1187. if (!(ioc->facts.IOCCapabilities &
  1188. MPI2_IOCFACTS_CAPABILITY_TLR))
  1189. goto out;
  1190. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1191. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1192. sas_device_priv_data->sas_target->sas_address);
  1193. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1194. if (sas_device && sas_device->device_info &
  1195. MPI2_SAS_DEVICE_INFO_SSP_TARGET)
  1196. sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
  1197. }
  1198. out:
  1199. return 0;
  1200. }
  1201. /**
  1202. * _scsih_slave_destroy - device destroy routine
  1203. * @sdev: scsi device struct
  1204. *
  1205. * Returns nothing.
  1206. */
  1207. static void
  1208. _scsih_slave_destroy(struct scsi_device *sdev)
  1209. {
  1210. struct MPT2SAS_TARGET *sas_target_priv_data;
  1211. struct scsi_target *starget;
  1212. if (!sdev->hostdata)
  1213. return;
  1214. starget = scsi_target(sdev);
  1215. sas_target_priv_data = starget->hostdata;
  1216. sas_target_priv_data->num_luns--;
  1217. kfree(sdev->hostdata);
  1218. sdev->hostdata = NULL;
  1219. }
  1220. /**
  1221. * _scsih_display_sata_capabilities - sata capabilities
  1222. * @ioc: per adapter object
  1223. * @sas_device: the sas_device object
  1224. * @sdev: scsi device struct
  1225. */
  1226. static void
  1227. _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1228. struct _sas_device *sas_device, struct scsi_device *sdev)
  1229. {
  1230. Mpi2ConfigReply_t mpi_reply;
  1231. Mpi2SasDevicePage0_t sas_device_pg0;
  1232. u32 ioc_status;
  1233. u16 flags;
  1234. u32 device_info;
  1235. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  1236. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
  1237. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1238. ioc->name, __FILE__, __LINE__, __func__);
  1239. return;
  1240. }
  1241. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1242. MPI2_IOCSTATUS_MASK;
  1243. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1244. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1245. ioc->name, __FILE__, __LINE__, __func__);
  1246. return;
  1247. }
  1248. flags = le16_to_cpu(sas_device_pg0.Flags);
  1249. device_info = le16_to_cpu(sas_device_pg0.DeviceInfo);
  1250. sdev_printk(KERN_INFO, sdev,
  1251. "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
  1252. "sw_preserve(%s)\n",
  1253. (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
  1254. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
  1255. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
  1256. "n",
  1257. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
  1258. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
  1259. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
  1260. }
  1261. /**
  1262. * _scsih_get_volume_capabilities - volume capabilities
  1263. * @ioc: per adapter object
  1264. * @sas_device: the raid_device object
  1265. */
  1266. static void
  1267. _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1268. struct _raid_device *raid_device)
  1269. {
  1270. Mpi2RaidVolPage0_t *vol_pg0;
  1271. Mpi2RaidPhysDiskPage0_t pd_pg0;
  1272. Mpi2SasDevicePage0_t sas_device_pg0;
  1273. Mpi2ConfigReply_t mpi_reply;
  1274. u16 sz;
  1275. u8 num_pds;
  1276. if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
  1277. &num_pds)) || !num_pds) {
  1278. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1279. ioc->name, __FILE__, __LINE__, __func__);
  1280. return;
  1281. }
  1282. raid_device->num_pds = num_pds;
  1283. sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
  1284. sizeof(Mpi2RaidVol0PhysDisk_t));
  1285. vol_pg0 = kzalloc(sz, GFP_KERNEL);
  1286. if (!vol_pg0) {
  1287. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1288. ioc->name, __FILE__, __LINE__, __func__);
  1289. return;
  1290. }
  1291. if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
  1292. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
  1293. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1294. ioc->name, __FILE__, __LINE__, __func__);
  1295. kfree(vol_pg0);
  1296. return;
  1297. }
  1298. raid_device->volume_type = vol_pg0->VolumeType;
  1299. /* figure out what the underlying devices are by
  1300. * obtaining the device_info bits for the 1st device
  1301. */
  1302. if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  1303. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
  1304. vol_pg0->PhysDisk[0].PhysDiskNum))) {
  1305. if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  1306. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  1307. le16_to_cpu(pd_pg0.DevHandle)))) {
  1308. raid_device->device_info =
  1309. le32_to_cpu(sas_device_pg0.DeviceInfo);
  1310. }
  1311. }
  1312. kfree(vol_pg0);
  1313. }
  1314. /**
  1315. * _scsih_slave_configure - device configure routine.
  1316. * @sdev: scsi device struct
  1317. *
  1318. * Returns 0 if ok. Any other return is assumed to be an error and
  1319. * the device is ignored.
  1320. */
  1321. static int
  1322. _scsih_slave_configure(struct scsi_device *sdev)
  1323. {
  1324. struct Scsi_Host *shost = sdev->host;
  1325. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1326. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1327. struct MPT2SAS_TARGET *sas_target_priv_data;
  1328. struct _sas_device *sas_device;
  1329. struct _raid_device *raid_device;
  1330. unsigned long flags;
  1331. int qdepth;
  1332. u8 ssp_target = 0;
  1333. char *ds = "";
  1334. char *r_level = "";
  1335. qdepth = 1;
  1336. sas_device_priv_data = sdev->hostdata;
  1337. sas_device_priv_data->configured_lun = 1;
  1338. sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
  1339. sas_target_priv_data = sas_device_priv_data->sas_target;
  1340. /* raid volume handling */
  1341. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
  1342. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1343. raid_device = _scsih_raid_device_find_by_handle(ioc,
  1344. sas_target_priv_data->handle);
  1345. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1346. if (!raid_device) {
  1347. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1348. ioc->name, __FILE__, __LINE__, __func__);
  1349. return 0;
  1350. }
  1351. _scsih_get_volume_capabilities(ioc, raid_device);
  1352. /* RAID Queue Depth Support
  1353. * IS volume = underlying qdepth of drive type, either
  1354. * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
  1355. * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
  1356. */
  1357. if (raid_device->device_info &
  1358. MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1359. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1360. ds = "SSP";
  1361. } else {
  1362. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1363. if (raid_device->device_info &
  1364. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1365. ds = "SATA";
  1366. else
  1367. ds = "STP";
  1368. }
  1369. switch (raid_device->volume_type) {
  1370. case MPI2_RAID_VOL_TYPE_RAID0:
  1371. r_level = "RAID0";
  1372. break;
  1373. case MPI2_RAID_VOL_TYPE_RAID1E:
  1374. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1375. if (ioc->manu_pg10.OEMIdentifier &&
  1376. (ioc->manu_pg10.GenericFlags0 &
  1377. MFG10_GF0_R10_DISPLAY) &&
  1378. !(raid_device->num_pds % 2))
  1379. r_level = "RAID10";
  1380. else
  1381. r_level = "RAID1E";
  1382. break;
  1383. case MPI2_RAID_VOL_TYPE_RAID1:
  1384. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1385. r_level = "RAID1";
  1386. break;
  1387. case MPI2_RAID_VOL_TYPE_RAID10:
  1388. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1389. r_level = "RAID10";
  1390. break;
  1391. case MPI2_RAID_VOL_TYPE_UNKNOWN:
  1392. default:
  1393. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1394. r_level = "RAIDX";
  1395. break;
  1396. }
  1397. sdev_printk(KERN_INFO, sdev, "%s: "
  1398. "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
  1399. r_level, raid_device->handle,
  1400. (unsigned long long)raid_device->wwid,
  1401. raid_device->num_pds, ds);
  1402. _scsih_change_queue_depth(sdev, qdepth);
  1403. return 0;
  1404. }
  1405. /* non-raid handling */
  1406. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1407. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1408. sas_device_priv_data->sas_target->sas_address);
  1409. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1410. if (sas_device) {
  1411. if (sas_target_priv_data->flags &
  1412. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1413. mpt2sas_config_get_volume_handle(ioc,
  1414. sas_device->handle, &sas_device->volume_handle);
  1415. mpt2sas_config_get_volume_wwid(ioc,
  1416. sas_device->volume_handle,
  1417. &sas_device->volume_wwid);
  1418. }
  1419. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1420. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1421. ssp_target = 1;
  1422. ds = "SSP";
  1423. } else {
  1424. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1425. if (sas_device->device_info &
  1426. MPI2_SAS_DEVICE_INFO_STP_TARGET)
  1427. ds = "STP";
  1428. else if (sas_device->device_info &
  1429. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1430. ds = "SATA";
  1431. }
  1432. sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
  1433. "sas_addr(0x%016llx), device_name(0x%016llx)\n",
  1434. ds, sas_device->handle,
  1435. (unsigned long long)sas_device->sas_address,
  1436. (unsigned long long)sas_device->device_name);
  1437. sdev_printk(KERN_INFO, sdev, "%s: "
  1438. "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
  1439. (unsigned long long) sas_device->enclosure_logical_id,
  1440. sas_device->slot);
  1441. if (!ssp_target)
  1442. _scsih_display_sata_capabilities(ioc, sas_device, sdev);
  1443. }
  1444. _scsih_change_queue_depth(sdev, qdepth);
  1445. if (ssp_target)
  1446. sas_read_port_mode_page(sdev);
  1447. return 0;
  1448. }
  1449. /**
  1450. * _scsih_bios_param - fetch head, sector, cylinder info for a disk
  1451. * @sdev: scsi device struct
  1452. * @bdev: pointer to block device context
  1453. * @capacity: device size (in 512 byte sectors)
  1454. * @params: three element array to place output:
  1455. * params[0] number of heads (max 255)
  1456. * params[1] number of sectors (max 63)
  1457. * params[2] number of cylinders
  1458. *
  1459. * Return nothing.
  1460. */
  1461. static int
  1462. _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
  1463. sector_t capacity, int params[])
  1464. {
  1465. int heads;
  1466. int sectors;
  1467. sector_t cylinders;
  1468. ulong dummy;
  1469. heads = 64;
  1470. sectors = 32;
  1471. dummy = heads * sectors;
  1472. cylinders = capacity;
  1473. sector_div(cylinders, dummy);
  1474. /*
  1475. * Handle extended translation size for logical drives
  1476. * > 1Gb
  1477. */
  1478. if ((ulong)capacity >= 0x200000) {
  1479. heads = 255;
  1480. sectors = 63;
  1481. dummy = heads * sectors;
  1482. cylinders = capacity;
  1483. sector_div(cylinders, dummy);
  1484. }
  1485. /* return result */
  1486. params[0] = heads;
  1487. params[1] = sectors;
  1488. params[2] = cylinders;
  1489. return 0;
  1490. }
  1491. /**
  1492. * _scsih_response_code - translation of device response code
  1493. * @ioc: per adapter object
  1494. * @response_code: response code returned by the device
  1495. *
  1496. * Return nothing.
  1497. */
  1498. static void
  1499. _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
  1500. {
  1501. char *desc;
  1502. switch (response_code) {
  1503. case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
  1504. desc = "task management request completed";
  1505. break;
  1506. case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
  1507. desc = "invalid frame";
  1508. break;
  1509. case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1510. desc = "task management request not supported";
  1511. break;
  1512. case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
  1513. desc = "task management request failed";
  1514. break;
  1515. case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1516. desc = "task management request succeeded";
  1517. break;
  1518. case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1519. desc = "invalid lun";
  1520. break;
  1521. case 0xA:
  1522. desc = "overlapped tag attempted";
  1523. break;
  1524. case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1525. desc = "task queued, however not sent to target";
  1526. break;
  1527. default:
  1528. desc = "unknown";
  1529. break;
  1530. }
  1531. printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
  1532. ioc->name, response_code, desc);
  1533. }
  1534. /**
  1535. * _scsih_tm_done - tm completion routine
  1536. * @ioc: per adapter object
  1537. * @smid: system request message index
  1538. * @msix_index: MSIX table index supplied by the OS
  1539. * @reply: reply message frame(lower 32bit addr)
  1540. * Context: none.
  1541. *
  1542. * The callback handler when using scsih_issue_tm.
  1543. *
  1544. * Return 1 meaning mf should be freed from _base_interrupt
  1545. * 0 means the mf is freed from this function.
  1546. */
  1547. static u8
  1548. _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  1549. {
  1550. MPI2DefaultReply_t *mpi_reply;
  1551. if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
  1552. return 1;
  1553. if (ioc->tm_cmds.smid != smid)
  1554. return 1;
  1555. ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
  1556. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  1557. if (mpi_reply) {
  1558. memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  1559. ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
  1560. }
  1561. ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
  1562. complete(&ioc->tm_cmds.done);
  1563. return 1;
  1564. }
  1565. /**
  1566. * mpt2sas_scsih_set_tm_flag - set per target tm_busy
  1567. * @ioc: per adapter object
  1568. * @handle: device handle
  1569. *
  1570. * During taskmangement request, we need to freeze the device queue.
  1571. */
  1572. void
  1573. mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1574. {
  1575. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1576. struct scsi_device *sdev;
  1577. u8 skip = 0;
  1578. shost_for_each_device(sdev, ioc->shost) {
  1579. if (skip)
  1580. continue;
  1581. sas_device_priv_data = sdev->hostdata;
  1582. if (!sas_device_priv_data)
  1583. continue;
  1584. if (sas_device_priv_data->sas_target->handle == handle) {
  1585. sas_device_priv_data->sas_target->tm_busy = 1;
  1586. skip = 1;
  1587. ioc->ignore_loginfos = 1;
  1588. }
  1589. }
  1590. }
  1591. /**
  1592. * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
  1593. * @ioc: per adapter object
  1594. * @handle: device handle
  1595. *
  1596. * During taskmangement request, we need to freeze the device queue.
  1597. */
  1598. void
  1599. mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1600. {
  1601. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1602. struct scsi_device *sdev;
  1603. u8 skip = 0;
  1604. shost_for_each_device(sdev, ioc->shost) {
  1605. if (skip)
  1606. continue;
  1607. sas_device_priv_data = sdev->hostdata;
  1608. if (!sas_device_priv_data)
  1609. continue;
  1610. if (sas_device_priv_data->sas_target->handle == handle) {
  1611. sas_device_priv_data->sas_target->tm_busy = 0;
  1612. skip = 1;
  1613. ioc->ignore_loginfos = 0;
  1614. }
  1615. }
  1616. }
  1617. /**
  1618. * mpt2sas_scsih_issue_tm - main routine for sending tm requests
  1619. * @ioc: per adapter struct
  1620. * @device_handle: device handle
  1621. * @lun: lun number
  1622. * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
  1623. * @smid_task: smid assigned to the task
  1624. * @timeout: timeout in seconds
  1625. * Context: The calling function needs to acquire the tm_cmds.mutex
  1626. *
  1627. * A generic API for sending task management requests to firmware.
  1628. *
  1629. * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
  1630. * this API.
  1631. *
  1632. * The callback index is set inside `ioc->tm_cb_idx`.
  1633. *
  1634. * Return nothing.
  1635. */
  1636. void
  1637. mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
  1638. u8 type, u16 smid_task, ulong timeout)
  1639. {
  1640. Mpi2SCSITaskManagementRequest_t *mpi_request;
  1641. Mpi2SCSITaskManagementReply_t *mpi_reply;
  1642. u16 smid = 0;
  1643. u32 ioc_state;
  1644. unsigned long timeleft;
  1645. if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
  1646. printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
  1647. __func__, ioc->name);
  1648. return;
  1649. }
  1650. if (ioc->shost_recovery) {
  1651. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1652. __func__, ioc->name);
  1653. return;
  1654. }
  1655. ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
  1656. if (ioc_state & MPI2_DOORBELL_USED) {
  1657. dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell "
  1658. "active!\n", ioc->name));
  1659. goto issue_host_reset;
  1660. }
  1661. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  1662. mpt2sas_base_fault_info(ioc, ioc_state &
  1663. MPI2_DOORBELL_DATA_MASK);
  1664. goto issue_host_reset;
  1665. }
  1666. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
  1667. if (!smid) {
  1668. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1669. ioc->name, __func__);
  1670. return;
  1671. }
  1672. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
  1673. " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
  1674. smid_task));
  1675. ioc->tm_cmds.status = MPT2_CMD_PENDING;
  1676. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1677. ioc->tm_cmds.smid = smid;
  1678. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  1679. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  1680. mpi_request->DevHandle = cpu_to_le16(handle);
  1681. mpi_request->TaskType = type;
  1682. mpi_request->TaskMID = cpu_to_le16(smid_task);
  1683. mpi_request->VP_ID = 0; /* TODO */
  1684. mpi_request->VF_ID = 0;
  1685. int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
  1686. mpt2sas_scsih_set_tm_flag(ioc, handle);
  1687. init_completion(&ioc->tm_cmds.done);
  1688. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  1689. timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
  1690. mpt2sas_scsih_clear_tm_flag(ioc, handle);
  1691. if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
  1692. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1693. ioc->name, __func__);
  1694. _debug_dump_mf(mpi_request,
  1695. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  1696. if (!(ioc->tm_cmds.status & MPT2_CMD_RESET))
  1697. goto issue_host_reset;
  1698. }
  1699. if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
  1700. mpi_reply = ioc->tm_cmds.reply;
  1701. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
  1702. "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
  1703. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  1704. le32_to_cpu(mpi_reply->IOCLogInfo),
  1705. le32_to_cpu(mpi_reply->TerminationCount)));
  1706. if (ioc->logging_level & MPT_DEBUG_TM)
  1707. _scsih_response_code(ioc, mpi_reply->ResponseCode);
  1708. }
  1709. return;
  1710. issue_host_reset:
  1711. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER);
  1712. }
  1713. /**
  1714. * _scsih_abort - eh threads main abort routine
  1715. * @sdev: scsi device struct
  1716. *
  1717. * Returns SUCCESS if command aborted else FAILED
  1718. */
  1719. static int
  1720. _scsih_abort(struct scsi_cmnd *scmd)
  1721. {
  1722. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1723. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1724. u16 smid;
  1725. u16 handle;
  1726. int r;
  1727. struct scsi_cmnd *scmd_lookup;
  1728. printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n",
  1729. ioc->name, scmd);
  1730. scsi_print_command(scmd);
  1731. sas_device_priv_data = scmd->device->hostdata;
  1732. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  1733. printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
  1734. ioc->name, scmd);
  1735. scmd->result = DID_NO_CONNECT << 16;
  1736. scmd->scsi_done(scmd);
  1737. r = SUCCESS;
  1738. goto out;
  1739. }
  1740. /* search for the command */
  1741. smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
  1742. if (!smid) {
  1743. scmd->result = DID_RESET << 16;
  1744. r = SUCCESS;
  1745. goto out;
  1746. }
  1747. /* for hidden raid components and volumes this is not supported */
  1748. if (sas_device_priv_data->sas_target->flags &
  1749. MPT_TARGET_FLAGS_RAID_COMPONENT ||
  1750. sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  1751. scmd->result = DID_RESET << 16;
  1752. r = FAILED;
  1753. goto out;
  1754. }
  1755. mutex_lock(&ioc->tm_cmds.mutex);
  1756. handle = sas_device_priv_data->sas_target->handle;
  1757. mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun,
  1758. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
  1759. /* sanity check - see whether command actually completed */
  1760. scmd_lookup = _scsih_scsi_lookup_get(ioc, smid);
  1761. if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number))
  1762. r = FAILED;
  1763. else
  1764. r = SUCCESS;
  1765. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1766. mutex_unlock(&ioc->tm_cmds.mutex);
  1767. out:
  1768. printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n",
  1769. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1770. return r;
  1771. }
  1772. /**
  1773. * _scsih_dev_reset - eh threads main device reset routine
  1774. * @sdev: scsi device struct
  1775. *
  1776. * Returns SUCCESS if command aborted else FAILED
  1777. */
  1778. static int
  1779. _scsih_dev_reset(struct scsi_cmnd *scmd)
  1780. {
  1781. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1782. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1783. struct _sas_device *sas_device;
  1784. unsigned long flags;
  1785. u16 handle;
  1786. int r;
  1787. printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
  1788. ioc->name, scmd);
  1789. scsi_print_command(scmd);
  1790. sas_device_priv_data = scmd->device->hostdata;
  1791. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  1792. printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
  1793. ioc->name, scmd);
  1794. scmd->result = DID_NO_CONNECT << 16;
  1795. scmd->scsi_done(scmd);
  1796. r = SUCCESS;
  1797. goto out;
  1798. }
  1799. /* for hidden raid components obtain the volume_handle */
  1800. handle = 0;
  1801. if (sas_device_priv_data->sas_target->flags &
  1802. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1803. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1804. sas_device = _scsih_sas_device_find_by_handle(ioc,
  1805. sas_device_priv_data->sas_target->handle);
  1806. if (sas_device)
  1807. handle = sas_device->volume_handle;
  1808. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1809. } else
  1810. handle = sas_device_priv_data->sas_target->handle;
  1811. if (!handle) {
  1812. scmd->result = DID_RESET << 16;
  1813. r = FAILED;
  1814. goto out;
  1815. }
  1816. mutex_lock(&ioc->tm_cmds.mutex);
  1817. mpt2sas_scsih_issue_tm(ioc, handle, 0,
  1818. MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
  1819. 30);
  1820. /*
  1821. * sanity check see whether all commands to this device been
  1822. * completed
  1823. */
  1824. if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
  1825. scmd->device->lun, scmd->device->channel))
  1826. r = FAILED;
  1827. else
  1828. r = SUCCESS;
  1829. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1830. mutex_unlock(&ioc->tm_cmds.mutex);
  1831. out:
  1832. printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
  1833. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1834. return r;
  1835. }
  1836. /**
  1837. * _scsih_target_reset - eh threads main target reset routine
  1838. * @sdev: scsi device struct
  1839. *
  1840. * Returns SUCCESS if command aborted else FAILED
  1841. */
  1842. static int
  1843. _scsih_target_reset(struct scsi_cmnd *scmd)
  1844. {
  1845. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1846. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1847. struct _sas_device *sas_device;
  1848. unsigned long flags;
  1849. u16 handle;
  1850. int r;
  1851. printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
  1852. ioc->name, scmd);
  1853. scsi_print_command(scmd);
  1854. sas_device_priv_data = scmd->device->hostdata;
  1855. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  1856. printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
  1857. ioc->name, scmd);
  1858. scmd->result = DID_NO_CONNECT << 16;
  1859. scmd->scsi_done(scmd);
  1860. r = SUCCESS;
  1861. goto out;
  1862. }
  1863. /* for hidden raid components obtain the volume_handle */
  1864. handle = 0;
  1865. if (sas_device_priv_data->sas_target->flags &
  1866. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1867. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1868. sas_device = _scsih_sas_device_find_by_handle(ioc,
  1869. sas_device_priv_data->sas_target->handle);
  1870. if (sas_device)
  1871. handle = sas_device->volume_handle;
  1872. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1873. } else
  1874. handle = sas_device_priv_data->sas_target->handle;
  1875. if (!handle) {
  1876. scmd->result = DID_RESET << 16;
  1877. r = FAILED;
  1878. goto out;
  1879. }
  1880. mutex_lock(&ioc->tm_cmds.mutex);
  1881. mpt2sas_scsih_issue_tm(ioc, handle, 0,
  1882. MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
  1883. /*
  1884. * sanity check see whether all commands to this target been
  1885. * completed
  1886. */
  1887. if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id,
  1888. scmd->device->channel))
  1889. r = FAILED;
  1890. else
  1891. r = SUCCESS;
  1892. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1893. mutex_unlock(&ioc->tm_cmds.mutex);
  1894. out:
  1895. printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n",
  1896. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1897. return r;
  1898. }
  1899. /**
  1900. * _scsih_host_reset - eh threads main host reset routine
  1901. * @sdev: scsi device struct
  1902. *
  1903. * Returns SUCCESS if command aborted else FAILED
  1904. */
  1905. static int
  1906. _scsih_host_reset(struct scsi_cmnd *scmd)
  1907. {
  1908. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1909. int r, retval;
  1910. printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
  1911. ioc->name, scmd);
  1912. scsi_print_command(scmd);
  1913. retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1914. FORCE_BIG_HAMMER);
  1915. r = (retval < 0) ? FAILED : SUCCESS;
  1916. printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
  1917. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1918. return r;
  1919. }
  1920. /**
  1921. * _scsih_fw_event_add - insert and queue up fw_event
  1922. * @ioc: per adapter object
  1923. * @fw_event: object describing the event
  1924. * Context: This function will acquire ioc->fw_event_lock.
  1925. *
  1926. * This adds the firmware event object into link list, then queues it up to
  1927. * be processed from user context.
  1928. *
  1929. * Return nothing.
  1930. */
  1931. static void
  1932. _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
  1933. {
  1934. unsigned long flags;
  1935. if (ioc->firmware_event_thread == NULL)
  1936. return;
  1937. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1938. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  1939. INIT_WORK(&fw_event->work, _firmware_event_work);
  1940. queue_work(ioc->firmware_event_thread, &fw_event->work);
  1941. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1942. }
  1943. /**
  1944. * _scsih_fw_event_free - delete fw_event
  1945. * @ioc: per adapter object
  1946. * @fw_event: object describing the event
  1947. * Context: This function will acquire ioc->fw_event_lock.
  1948. *
  1949. * This removes firmware event object from link list, frees associated memory.
  1950. *
  1951. * Return nothing.
  1952. */
  1953. static void
  1954. _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  1955. *fw_event)
  1956. {
  1957. unsigned long flags;
  1958. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1959. list_del(&fw_event->list);
  1960. kfree(fw_event->event_data);
  1961. kfree(fw_event);
  1962. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1963. }
  1964. /**
  1965. * _scsih_fw_event_add - requeue an event
  1966. * @ioc: per adapter object
  1967. * @fw_event: object describing the event
  1968. * Context: This function will acquire ioc->fw_event_lock.
  1969. *
  1970. * Return nothing.
  1971. */
  1972. static void
  1973. _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  1974. *fw_event, unsigned long delay)
  1975. {
  1976. unsigned long flags;
  1977. if (ioc->firmware_event_thread == NULL)
  1978. return;
  1979. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1980. queue_work(ioc->firmware_event_thread, &fw_event->work);
  1981. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1982. }
  1983. /**
  1984. * _scsih_fw_event_off - turn flag off preventing event handling
  1985. * @ioc: per adapter object
  1986. *
  1987. * Used to prevent handling of firmware events during adapter reset
  1988. * driver unload.
  1989. *
  1990. * Return nothing.
  1991. */
  1992. static void
  1993. _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc)
  1994. {
  1995. unsigned long flags;
  1996. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1997. ioc->fw_events_off = 1;
  1998. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1999. }
  2000. /**
  2001. * _scsih_fw_event_on - turn flag on allowing firmware event handling
  2002. * @ioc: per adapter object
  2003. *
  2004. * Returns nothing.
  2005. */
  2006. static void
  2007. _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc)
  2008. {
  2009. unsigned long flags;
  2010. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2011. ioc->fw_events_off = 0;
  2012. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2013. }
  2014. /**
  2015. * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
  2016. * @ioc: per adapter object
  2017. * @handle: device handle
  2018. *
  2019. * During device pull we need to appropiately set the sdev state.
  2020. */
  2021. static void
  2022. _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2023. {
  2024. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2025. struct scsi_device *sdev;
  2026. shost_for_each_device(sdev, ioc->shost) {
  2027. sas_device_priv_data = sdev->hostdata;
  2028. if (!sas_device_priv_data)
  2029. continue;
  2030. if (!sas_device_priv_data->block)
  2031. continue;
  2032. if (sas_device_priv_data->sas_target->handle == handle) {
  2033. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2034. MPT2SAS_INFO_FMT "SDEV_RUNNING: "
  2035. "handle(0x%04x)\n", ioc->name, handle));
  2036. sas_device_priv_data->block = 0;
  2037. scsi_internal_device_unblock(sdev);
  2038. }
  2039. }
  2040. }
  2041. /**
  2042. * _scsih_block_io_device - set the device state to SDEV_BLOCK
  2043. * @ioc: per adapter object
  2044. * @handle: device handle
  2045. *
  2046. * During device pull we need to appropiately set the sdev state.
  2047. */
  2048. static void
  2049. _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2050. {
  2051. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2052. struct scsi_device *sdev;
  2053. shost_for_each_device(sdev, ioc->shost) {
  2054. sas_device_priv_data = sdev->hostdata;
  2055. if (!sas_device_priv_data)
  2056. continue;
  2057. if (sas_device_priv_data->block)
  2058. continue;
  2059. if (sas_device_priv_data->sas_target->handle == handle) {
  2060. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2061. MPT2SAS_INFO_FMT "SDEV_BLOCK: "
  2062. "handle(0x%04x)\n", ioc->name, handle));
  2063. sas_device_priv_data->block = 1;
  2064. scsi_internal_device_block(sdev);
  2065. }
  2066. }
  2067. }
  2068. /**
  2069. * _scsih_block_io_to_children_attached_to_ex
  2070. * @ioc: per adapter object
  2071. * @sas_expander: the sas_device object
  2072. *
  2073. * This routine set sdev state to SDEV_BLOCK for all devices
  2074. * attached to this expander. This function called when expander is
  2075. * pulled.
  2076. */
  2077. static void
  2078. _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
  2079. struct _sas_node *sas_expander)
  2080. {
  2081. struct _sas_port *mpt2sas_port;
  2082. struct _sas_device *sas_device;
  2083. struct _sas_node *expander_sibling;
  2084. unsigned long flags;
  2085. if (!sas_expander)
  2086. return;
  2087. list_for_each_entry(mpt2sas_port,
  2088. &sas_expander->sas_port_list, port_list) {
  2089. if (mpt2sas_port->remote_identify.device_type ==
  2090. SAS_END_DEVICE) {
  2091. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2092. sas_device =
  2093. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  2094. mpt2sas_port->remote_identify.sas_address);
  2095. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2096. if (!sas_device)
  2097. continue;
  2098. _scsih_block_io_device(ioc, sas_device->handle);
  2099. }
  2100. }
  2101. list_for_each_entry(mpt2sas_port,
  2102. &sas_expander->sas_port_list, port_list) {
  2103. if (mpt2sas_port->remote_identify.device_type ==
  2104. MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  2105. mpt2sas_port->remote_identify.device_type ==
  2106. MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
  2107. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2108. expander_sibling =
  2109. mpt2sas_scsih_expander_find_by_sas_address(
  2110. ioc, mpt2sas_port->remote_identify.sas_address);
  2111. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2112. _scsih_block_io_to_children_attached_to_ex(ioc,
  2113. expander_sibling);
  2114. }
  2115. }
  2116. }
  2117. /**
  2118. * _scsih_block_io_to_children_attached_directly
  2119. * @ioc: per adapter object
  2120. * @event_data: topology change event data
  2121. *
  2122. * This routine set sdev state to SDEV_BLOCK for all devices
  2123. * direct attached during device pull.
  2124. */
  2125. static void
  2126. _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
  2127. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2128. {
  2129. int i;
  2130. u16 handle;
  2131. u16 reason_code;
  2132. u8 phy_number;
  2133. u8 link_rate;
  2134. for (i = 0; i < event_data->NumEntries; i++) {
  2135. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2136. if (!handle)
  2137. continue;
  2138. phy_number = event_data->StartPhyNum + i;
  2139. reason_code = event_data->PHY[i].PhyStatus &
  2140. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2141. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
  2142. _scsih_block_io_device(ioc, handle);
  2143. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) {
  2144. link_rate = event_data->PHY[i].LinkRate >> 4;
  2145. if (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)
  2146. _scsih_ublock_io_device(ioc, handle);
  2147. }
  2148. }
  2149. }
  2150. /**
  2151. * _scsih_tm_tr_send - send task management request
  2152. * @ioc: per adapter object
  2153. * @handle: device handle
  2154. * Context: interrupt time.
  2155. *
  2156. * This code is to initiate the device removal handshake protocal
  2157. * with controller firmware. This function will issue target reset
  2158. * using high priority request queue. It will send a sas iounit
  2159. * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
  2160. *
  2161. * This is designed to send muliple task management request at the same
  2162. * time to the fifo. If the fifo is full, we will append the request,
  2163. * and process it in a future completion.
  2164. */
  2165. static void
  2166. _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2167. {
  2168. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2169. struct MPT2SAS_TARGET *sas_target_priv_data;
  2170. u16 smid;
  2171. struct _sas_device *sas_device;
  2172. unsigned long flags;
  2173. struct _tr_list *delayed_tr;
  2174. if (ioc->shost_recovery) {
  2175. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  2176. __func__, ioc->name);
  2177. return;
  2178. }
  2179. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2180. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2181. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2182. /* skip is hidden raid component */
  2183. if (sas_device && sas_device->hidden_raid_component)
  2184. return;
  2185. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
  2186. if (!smid) {
  2187. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2188. if (!delayed_tr)
  2189. return;
  2190. INIT_LIST_HEAD(&delayed_tr->list);
  2191. delayed_tr->handle = handle;
  2192. delayed_tr->state = MPT2SAS_REQ_SAS_CNTRL;
  2193. list_add_tail(&delayed_tr->list,
  2194. &ioc->delayed_tr_list);
  2195. if (sas_device && sas_device->starget) {
  2196. dewtprintk(ioc, starget_printk(KERN_INFO,
  2197. sas_device->starget, "DELAYED:tr:handle(0x%04x), "
  2198. "(open)\n", handle));
  2199. } else {
  2200. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2201. "DELAYED:tr:handle(0x%04x), (open)\n",
  2202. ioc->name, handle));
  2203. }
  2204. return;
  2205. }
  2206. if (sas_device) {
  2207. sas_device->state |= MPTSAS_STATE_TR_SEND;
  2208. sas_device->state |= MPT2SAS_REQ_SAS_CNTRL;
  2209. if (sas_device->starget && sas_device->starget->hostdata) {
  2210. sas_target_priv_data = sas_device->starget->hostdata;
  2211. sas_target_priv_data->tm_busy = 1;
  2212. dewtprintk(ioc, starget_printk(KERN_INFO,
  2213. sas_device->starget, "tr:handle(0x%04x), (open)\n",
  2214. handle));
  2215. }
  2216. } else {
  2217. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2218. "tr:handle(0x%04x), (open)\n", ioc->name, handle));
  2219. }
  2220. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2221. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2222. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2223. mpi_request->DevHandle = cpu_to_le16(handle);
  2224. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  2225. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2226. }
  2227. /**
  2228. * _scsih_sas_control_complete - completion routine
  2229. * @ioc: per adapter object
  2230. * @smid: system request message index
  2231. * @msix_index: MSIX table index supplied by the OS
  2232. * @reply: reply message frame(lower 32bit addr)
  2233. * Context: interrupt time.
  2234. *
  2235. * This is the sas iounit controll completion routine.
  2236. * This code is part of the code to initiate the device removal
  2237. * handshake protocal with controller firmware.
  2238. *
  2239. * Return 1 meaning mf should be freed from _base_interrupt
  2240. * 0 means the mf is freed from this function.
  2241. */
  2242. static u8
  2243. _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  2244. u8 msix_index, u32 reply)
  2245. {
  2246. unsigned long flags;
  2247. u16 handle;
  2248. struct _sas_device *sas_device;
  2249. Mpi2SasIoUnitControlReply_t *mpi_reply =
  2250. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2251. handle = le16_to_cpu(mpi_reply->DevHandle);
  2252. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2253. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2254. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2255. if (sas_device) {
  2256. sas_device->state |= MPTSAS_STATE_CNTRL_COMPLETE;
  2257. if (sas_device->starget)
  2258. dewtprintk(ioc, starget_printk(KERN_INFO,
  2259. sas_device->starget,
  2260. "sc_complete:handle(0x%04x), "
  2261. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  2262. handle, le16_to_cpu(mpi_reply->IOCStatus),
  2263. le32_to_cpu(mpi_reply->IOCLogInfo)));
  2264. } else {
  2265. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2266. "sc_complete:handle(0x%04x), "
  2267. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  2268. ioc->name, handle, le16_to_cpu(mpi_reply->IOCStatus),
  2269. le32_to_cpu(mpi_reply->IOCLogInfo)));
  2270. }
  2271. return 1;
  2272. }
  2273. /**
  2274. * _scsih_tm_tr_complete -
  2275. * @ioc: per adapter object
  2276. * @smid: system request message index
  2277. * @msix_index: MSIX table index supplied by the OS
  2278. * @reply: reply message frame(lower 32bit addr)
  2279. * Context: interrupt time.
  2280. *
  2281. * This is the target reset completion routine.
  2282. * This code is part of the code to initiate the device removal
  2283. * handshake protocal with controller firmware.
  2284. * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
  2285. *
  2286. * Return 1 meaning mf should be freed from _base_interrupt
  2287. * 0 means the mf is freed from this function.
  2288. */
  2289. static u8
  2290. _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  2291. u32 reply)
  2292. {
  2293. unsigned long flags;
  2294. u16 handle;
  2295. struct _sas_device *sas_device;
  2296. Mpi2SCSITaskManagementReply_t *mpi_reply =
  2297. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2298. Mpi2SasIoUnitControlRequest_t *mpi_request;
  2299. u16 smid_sas_ctrl;
  2300. struct MPT2SAS_TARGET *sas_target_priv_data;
  2301. struct _tr_list *delayed_tr;
  2302. u8 rc;
  2303. handle = le16_to_cpu(mpi_reply->DevHandle);
  2304. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2305. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2306. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2307. if (sas_device) {
  2308. sas_device->state |= MPTSAS_STATE_TR_COMPLETE;
  2309. if (sas_device->starget) {
  2310. dewtprintk(ioc, starget_printk(KERN_INFO,
  2311. sas_device->starget, "tr_complete:handle(0x%04x), "
  2312. "(%s) ioc_status(0x%04x), loginfo(0x%08x), "
  2313. "completed(%d)\n", sas_device->handle,
  2314. (sas_device->state & MPT2SAS_REQ_SAS_CNTRL) ?
  2315. "open" : "active",
  2316. le16_to_cpu(mpi_reply->IOCStatus),
  2317. le32_to_cpu(mpi_reply->IOCLogInfo),
  2318. le32_to_cpu(mpi_reply->TerminationCount)));
  2319. if (sas_device->starget->hostdata) {
  2320. sas_target_priv_data =
  2321. sas_device->starget->hostdata;
  2322. sas_target_priv_data->tm_busy = 0;
  2323. }
  2324. }
  2325. } else {
  2326. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2327. "tr_complete:handle(0x%04x), (open) ioc_status(0x%04x), "
  2328. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  2329. handle, le16_to_cpu(mpi_reply->IOCStatus),
  2330. le32_to_cpu(mpi_reply->IOCLogInfo),
  2331. le32_to_cpu(mpi_reply->TerminationCount)));
  2332. }
  2333. if (!list_empty(&ioc->delayed_tr_list)) {
  2334. delayed_tr = list_entry(ioc->delayed_tr_list.next,
  2335. struct _tr_list, list);
  2336. mpt2sas_base_free_smid(ioc, smid);
  2337. if (delayed_tr->state & MPT2SAS_REQ_SAS_CNTRL)
  2338. _scsih_tm_tr_send(ioc, delayed_tr->handle);
  2339. list_del(&delayed_tr->list);
  2340. kfree(delayed_tr);
  2341. rc = 0; /* tells base_interrupt not to free mf */
  2342. } else
  2343. rc = 1;
  2344. if (sas_device && !(sas_device->state & MPT2SAS_REQ_SAS_CNTRL))
  2345. return rc;
  2346. if (ioc->shost_recovery) {
  2347. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  2348. __func__, ioc->name);
  2349. return rc;
  2350. }
  2351. smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
  2352. if (!smid_sas_ctrl) {
  2353. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2354. ioc->name, __func__);
  2355. return rc;
  2356. }
  2357. if (sas_device)
  2358. sas_device->state |= MPTSAS_STATE_CNTRL_SEND;
  2359. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
  2360. memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  2361. mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  2362. mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  2363. mpi_request->DevHandle = mpi_reply->DevHandle;
  2364. mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
  2365. return rc;
  2366. }
  2367. /**
  2368. * _scsih_check_topo_delete_events - sanity check on topo events
  2369. * @ioc: per adapter object
  2370. * @event_data: the event data payload
  2371. *
  2372. * This routine added to better handle cable breaker.
  2373. *
  2374. * This handles the case where driver recieves multiple expander
  2375. * add and delete events in a single shot. When there is a delete event
  2376. * the routine will void any pending add events waiting in the event queue.
  2377. *
  2378. * Return nothing.
  2379. */
  2380. static void
  2381. _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
  2382. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2383. {
  2384. struct fw_event_work *fw_event;
  2385. Mpi2EventDataSasTopologyChangeList_t *local_event_data;
  2386. u16 expander_handle;
  2387. struct _sas_node *sas_expander;
  2388. unsigned long flags;
  2389. int i, reason_code;
  2390. u16 handle;
  2391. for (i = 0 ; i < event_data->NumEntries; i++) {
  2392. if (event_data->PHY[i].PhyStatus &
  2393. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
  2394. continue;
  2395. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2396. if (!handle)
  2397. continue;
  2398. reason_code = event_data->PHY[i].PhyStatus &
  2399. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2400. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
  2401. _scsih_tm_tr_send(ioc, handle);
  2402. }
  2403. expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  2404. if (expander_handle < ioc->sas_hba.num_phys) {
  2405. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  2406. return;
  2407. }
  2408. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
  2409. || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
  2410. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2411. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  2412. expander_handle);
  2413. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2414. _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
  2415. } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
  2416. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  2417. if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
  2418. return;
  2419. /* mark ignore flag for pending events */
  2420. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2421. list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
  2422. if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
  2423. fw_event->ignore)
  2424. continue;
  2425. local_event_data = fw_event->event_data;
  2426. if (local_event_data->ExpStatus ==
  2427. MPI2_EVENT_SAS_TOPO_ES_ADDED ||
  2428. local_event_data->ExpStatus ==
  2429. MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
  2430. if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
  2431. expander_handle) {
  2432. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  2433. "setting ignoring flag\n", ioc->name));
  2434. fw_event->ignore = 1;
  2435. }
  2436. }
  2437. }
  2438. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2439. }
  2440. /**
  2441. * _scsih_flush_running_cmds - completing outstanding commands.
  2442. * @ioc: per adapter object
  2443. *
  2444. * The flushing out of all pending scmd commands following host reset,
  2445. * where all IO is dropped to the floor.
  2446. *
  2447. * Return nothing.
  2448. */
  2449. static void
  2450. _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
  2451. {
  2452. struct scsi_cmnd *scmd;
  2453. u16 smid;
  2454. u16 count = 0;
  2455. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  2456. scmd = _scsih_scsi_lookup_get(ioc, smid);
  2457. if (!scmd)
  2458. continue;
  2459. count++;
  2460. mpt2sas_base_free_smid(ioc, smid);
  2461. scsi_dma_unmap(scmd);
  2462. scmd->result = DID_RESET << 16;
  2463. scmd->scsi_done(scmd);
  2464. }
  2465. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
  2466. ioc->name, count));
  2467. }
  2468. /**
  2469. * _scsih_setup_eedp - setup MPI request for EEDP transfer
  2470. * @scmd: pointer to scsi command object
  2471. * @mpi_request: pointer to the SCSI_IO reqest message frame
  2472. *
  2473. * Supporting protection 1 and 3.
  2474. *
  2475. * Returns nothing
  2476. */
  2477. static void
  2478. _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
  2479. {
  2480. u16 eedp_flags;
  2481. unsigned char prot_op = scsi_get_prot_op(scmd);
  2482. unsigned char prot_type = scsi_get_prot_type(scmd);
  2483. if (prot_type == SCSI_PROT_DIF_TYPE0 ||
  2484. prot_type == SCSI_PROT_DIF_TYPE2 ||
  2485. prot_op == SCSI_PROT_NORMAL)
  2486. return;
  2487. if (prot_op == SCSI_PROT_READ_STRIP)
  2488. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
  2489. else if (prot_op == SCSI_PROT_WRITE_INSERT)
  2490. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  2491. else
  2492. return;
  2493. mpi_request->EEDPBlockSize = scmd->device->sector_size;
  2494. switch (prot_type) {
  2495. case SCSI_PROT_DIF_TYPE1:
  2496. /*
  2497. * enable ref/guard checking
  2498. * auto increment ref tag
  2499. */
  2500. mpi_request->EEDPFlags = eedp_flags |
  2501. MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  2502. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  2503. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2504. mpi_request->CDB.EEDP32.PrimaryReferenceTag =
  2505. cpu_to_be32(scsi_get_lba(scmd));
  2506. break;
  2507. case SCSI_PROT_DIF_TYPE3:
  2508. /*
  2509. * enable guard checking
  2510. */
  2511. mpi_request->EEDPFlags = eedp_flags |
  2512. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2513. break;
  2514. }
  2515. }
  2516. /**
  2517. * _scsih_eedp_error_handling - return sense code for EEDP errors
  2518. * @scmd: pointer to scsi command object
  2519. * @ioc_status: ioc status
  2520. *
  2521. * Returns nothing
  2522. */
  2523. static void
  2524. _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
  2525. {
  2526. u8 ascq;
  2527. u8 sk;
  2528. u8 host_byte;
  2529. switch (ioc_status) {
  2530. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  2531. ascq = 0x01;
  2532. break;
  2533. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  2534. ascq = 0x02;
  2535. break;
  2536. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  2537. ascq = 0x03;
  2538. break;
  2539. default:
  2540. ascq = 0x00;
  2541. break;
  2542. }
  2543. if (scmd->sc_data_direction == DMA_TO_DEVICE) {
  2544. sk = ILLEGAL_REQUEST;
  2545. host_byte = DID_ABORT;
  2546. } else {
  2547. sk = ABORTED_COMMAND;
  2548. host_byte = DID_OK;
  2549. }
  2550. scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
  2551. scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
  2552. SAM_STAT_CHECK_CONDITION;
  2553. }
  2554. /**
  2555. * _scsih_qcmd - main scsi request entry point
  2556. * @scmd: pointer to scsi command object
  2557. * @done: function pointer to be invoked on completion
  2558. *
  2559. * The callback index is set inside `ioc->scsi_io_cb_idx`.
  2560. *
  2561. * Returns 0 on success. If there's a failure, return either:
  2562. * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
  2563. * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
  2564. */
  2565. static int
  2566. _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
  2567. {
  2568. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2569. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2570. struct MPT2SAS_TARGET *sas_target_priv_data;
  2571. Mpi2SCSIIORequest_t *mpi_request;
  2572. u32 mpi_control;
  2573. u16 smid;
  2574. scmd->scsi_done = done;
  2575. sas_device_priv_data = scmd->device->hostdata;
  2576. if (!sas_device_priv_data) {
  2577. scmd->result = DID_NO_CONNECT << 16;
  2578. scmd->scsi_done(scmd);
  2579. return 0;
  2580. }
  2581. sas_target_priv_data = sas_device_priv_data->sas_target;
  2582. if (!sas_target_priv_data || sas_target_priv_data->handle ==
  2583. MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) {
  2584. scmd->result = DID_NO_CONNECT << 16;
  2585. scmd->scsi_done(scmd);
  2586. return 0;
  2587. }
  2588. /* see if we are busy with task managment stuff */
  2589. if (sas_target_priv_data->tm_busy)
  2590. return SCSI_MLQUEUE_DEVICE_BUSY;
  2591. else if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
  2592. return SCSI_MLQUEUE_HOST_BUSY;
  2593. if (scmd->sc_data_direction == DMA_FROM_DEVICE)
  2594. mpi_control = MPI2_SCSIIO_CONTROL_READ;
  2595. else if (scmd->sc_data_direction == DMA_TO_DEVICE)
  2596. mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
  2597. else
  2598. mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
  2599. /* set tags */
  2600. if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
  2601. if (scmd->device->tagged_supported) {
  2602. if (scmd->device->ordered_tags)
  2603. mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
  2604. else
  2605. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  2606. } else
  2607. /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
  2608. /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
  2609. */
  2610. mpi_control |= (0x500);
  2611. } else
  2612. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  2613. if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON))
  2614. mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
  2615. smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
  2616. if (!smid) {
  2617. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2618. ioc->name, __func__);
  2619. goto out;
  2620. }
  2621. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2622. memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
  2623. _scsih_setup_eedp(scmd, mpi_request);
  2624. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  2625. if (sas_device_priv_data->sas_target->flags &
  2626. MPT_TARGET_FLAGS_RAID_COMPONENT)
  2627. mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  2628. else
  2629. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  2630. mpi_request->DevHandle =
  2631. cpu_to_le16(sas_device_priv_data->sas_target->handle);
  2632. mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
  2633. mpi_request->Control = cpu_to_le32(mpi_control);
  2634. mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
  2635. mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
  2636. mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  2637. mpi_request->SenseBufferLowAddress =
  2638. (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
  2639. mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
  2640. mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
  2641. MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
  2642. mpi_request->VF_ID = 0; /* TODO */
  2643. mpi_request->VP_ID = 0;
  2644. int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
  2645. mpi_request->LUN);
  2646. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  2647. if (!mpi_request->DataLength) {
  2648. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
  2649. } else {
  2650. if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
  2651. mpt2sas_base_free_smid(ioc, smid);
  2652. goto out;
  2653. }
  2654. }
  2655. mpt2sas_base_put_smid_scsi_io(ioc, smid,
  2656. sas_device_priv_data->sas_target->handle);
  2657. return 0;
  2658. out:
  2659. return SCSI_MLQUEUE_HOST_BUSY;
  2660. }
  2661. /**
  2662. * _scsih_normalize_sense - normalize descriptor and fixed format sense data
  2663. * @sense_buffer: sense data returned by target
  2664. * @data: normalized skey/asc/ascq
  2665. *
  2666. * Return nothing.
  2667. */
  2668. static void
  2669. _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
  2670. {
  2671. if ((sense_buffer[0] & 0x7F) >= 0x72) {
  2672. /* descriptor format */
  2673. data->skey = sense_buffer[1] & 0x0F;
  2674. data->asc = sense_buffer[2];
  2675. data->ascq = sense_buffer[3];
  2676. } else {
  2677. /* fixed format */
  2678. data->skey = sense_buffer[2] & 0x0F;
  2679. data->asc = sense_buffer[12];
  2680. data->ascq = sense_buffer[13];
  2681. }
  2682. }
  2683. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  2684. /**
  2685. * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
  2686. * @ioc: per adapter object
  2687. * @scmd: pointer to scsi command object
  2688. * @mpi_reply: reply mf payload returned from firmware
  2689. *
  2690. * scsi_status - SCSI Status code returned from target device
  2691. * scsi_state - state info associated with SCSI_IO determined by ioc
  2692. * ioc_status - ioc supplied status info
  2693. *
  2694. * Return nothing.
  2695. */
  2696. static void
  2697. _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  2698. Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
  2699. {
  2700. u32 response_info;
  2701. u8 *response_bytes;
  2702. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  2703. MPI2_IOCSTATUS_MASK;
  2704. u8 scsi_state = mpi_reply->SCSIState;
  2705. u8 scsi_status = mpi_reply->SCSIStatus;
  2706. char *desc_ioc_state = NULL;
  2707. char *desc_scsi_status = NULL;
  2708. char *desc_scsi_state = ioc->tmp_string;
  2709. u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  2710. if (log_info == 0x31170000)
  2711. return;
  2712. switch (ioc_status) {
  2713. case MPI2_IOCSTATUS_SUCCESS:
  2714. desc_ioc_state = "success";
  2715. break;
  2716. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  2717. desc_ioc_state = "invalid function";
  2718. break;
  2719. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  2720. desc_ioc_state = "scsi recovered error";
  2721. break;
  2722. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  2723. desc_ioc_state = "scsi invalid dev handle";
  2724. break;
  2725. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  2726. desc_ioc_state = "scsi device not there";
  2727. break;
  2728. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  2729. desc_ioc_state = "scsi data overrun";
  2730. break;
  2731. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  2732. desc_ioc_state = "scsi data underrun";
  2733. break;
  2734. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  2735. desc_ioc_state = "scsi io data error";
  2736. break;
  2737. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  2738. desc_ioc_state = "scsi protocol error";
  2739. break;
  2740. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  2741. desc_ioc_state = "scsi task terminated";
  2742. break;
  2743. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  2744. desc_ioc_state = "scsi residual mismatch";
  2745. break;
  2746. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  2747. desc_ioc_state = "scsi task mgmt failed";
  2748. break;
  2749. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  2750. desc_ioc_state = "scsi ioc terminated";
  2751. break;
  2752. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  2753. desc_ioc_state = "scsi ext terminated";
  2754. break;
  2755. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  2756. desc_ioc_state = "eedp guard error";
  2757. break;
  2758. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  2759. desc_ioc_state = "eedp ref tag error";
  2760. break;
  2761. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  2762. desc_ioc_state = "eedp app tag error";
  2763. break;
  2764. default:
  2765. desc_ioc_state = "unknown";
  2766. break;
  2767. }
  2768. switch (scsi_status) {
  2769. case MPI2_SCSI_STATUS_GOOD:
  2770. desc_scsi_status = "good";
  2771. break;
  2772. case MPI2_SCSI_STATUS_CHECK_CONDITION:
  2773. desc_scsi_status = "check condition";
  2774. break;
  2775. case MPI2_SCSI_STATUS_CONDITION_MET:
  2776. desc_scsi_status = "condition met";
  2777. break;
  2778. case MPI2_SCSI_STATUS_BUSY:
  2779. desc_scsi_status = "busy";
  2780. break;
  2781. case MPI2_SCSI_STATUS_INTERMEDIATE:
  2782. desc_scsi_status = "intermediate";
  2783. break;
  2784. case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
  2785. desc_scsi_status = "intermediate condmet";
  2786. break;
  2787. case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
  2788. desc_scsi_status = "reservation conflict";
  2789. break;
  2790. case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
  2791. desc_scsi_status = "command terminated";
  2792. break;
  2793. case MPI2_SCSI_STATUS_TASK_SET_FULL:
  2794. desc_scsi_status = "task set full";
  2795. break;
  2796. case MPI2_SCSI_STATUS_ACA_ACTIVE:
  2797. desc_scsi_status = "aca active";
  2798. break;
  2799. case MPI2_SCSI_STATUS_TASK_ABORTED:
  2800. desc_scsi_status = "task aborted";
  2801. break;
  2802. default:
  2803. desc_scsi_status = "unknown";
  2804. break;
  2805. }
  2806. desc_scsi_state[0] = '\0';
  2807. if (!scsi_state)
  2808. desc_scsi_state = " ";
  2809. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  2810. strcat(desc_scsi_state, "response info ");
  2811. if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  2812. strcat(desc_scsi_state, "state terminated ");
  2813. if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
  2814. strcat(desc_scsi_state, "no status ");
  2815. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
  2816. strcat(desc_scsi_state, "autosense failed ");
  2817. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
  2818. strcat(desc_scsi_state, "autosense valid ");
  2819. scsi_print_command(scmd);
  2820. printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), "
  2821. "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name,
  2822. le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state,
  2823. ioc_status, smid);
  2824. printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
  2825. "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
  2826. scsi_get_resid(scmd));
  2827. printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
  2828. "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
  2829. le32_to_cpu(mpi_reply->TransferCount), scmd->result);
  2830. printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
  2831. "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
  2832. scsi_status, desc_scsi_state, scsi_state);
  2833. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  2834. struct sense_info data;
  2835. _scsih_normalize_sense(scmd->sense_buffer, &data);
  2836. printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
  2837. "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey,
  2838. data.asc, data.ascq);
  2839. }
  2840. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
  2841. response_info = le32_to_cpu(mpi_reply->ResponseInfo);
  2842. response_bytes = (u8 *)&response_info;
  2843. _scsih_response_code(ioc, response_bytes[0]);
  2844. }
  2845. }
  2846. #endif
  2847. /**
  2848. * _scsih_smart_predicted_fault - illuminate Fault LED
  2849. * @ioc: per adapter object
  2850. * @handle: device handle
  2851. *
  2852. * Return nothing.
  2853. */
  2854. static void
  2855. _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2856. {
  2857. Mpi2SepReply_t mpi_reply;
  2858. Mpi2SepRequest_t mpi_request;
  2859. struct scsi_target *starget;
  2860. struct MPT2SAS_TARGET *sas_target_priv_data;
  2861. Mpi2EventNotificationReply_t *event_reply;
  2862. Mpi2EventDataSasDeviceStatusChange_t *event_data;
  2863. struct _sas_device *sas_device;
  2864. ssize_t sz;
  2865. unsigned long flags;
  2866. /* only handle non-raid devices */
  2867. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2868. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2869. if (!sas_device) {
  2870. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2871. return;
  2872. }
  2873. starget = sas_device->starget;
  2874. sas_target_priv_data = starget->hostdata;
  2875. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
  2876. ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
  2877. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2878. return;
  2879. }
  2880. starget_printk(KERN_WARNING, starget, "predicted fault\n");
  2881. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2882. if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
  2883. memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
  2884. mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  2885. mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
  2886. mpi_request.SlotStatus =
  2887. MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT;
  2888. mpi_request.DevHandle = cpu_to_le16(handle);
  2889. mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
  2890. if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
  2891. &mpi_request)) != 0) {
  2892. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  2893. ioc->name, __FILE__, __LINE__, __func__);
  2894. return;
  2895. }
  2896. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
  2897. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2898. "enclosure_processor: ioc_status (0x%04x), "
  2899. "loginfo(0x%08x)\n", ioc->name,
  2900. le16_to_cpu(mpi_reply.IOCStatus),
  2901. le32_to_cpu(mpi_reply.IOCLogInfo)));
  2902. return;
  2903. }
  2904. }
  2905. /* insert into event log */
  2906. sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
  2907. sizeof(Mpi2EventDataSasDeviceStatusChange_t);
  2908. event_reply = kzalloc(sz, GFP_KERNEL);
  2909. if (!event_reply) {
  2910. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  2911. ioc->name, __FILE__, __LINE__, __func__);
  2912. return;
  2913. }
  2914. event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
  2915. event_reply->Event =
  2916. cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
  2917. event_reply->MsgLength = sz/4;
  2918. event_reply->EventDataLength =
  2919. cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
  2920. event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
  2921. event_reply->EventData;
  2922. event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
  2923. event_data->ASC = 0x5D;
  2924. event_data->DevHandle = cpu_to_le16(handle);
  2925. event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
  2926. mpt2sas_ctl_add_to_event_log(ioc, event_reply);
  2927. kfree(event_reply);
  2928. }
  2929. /**
  2930. * _scsih_io_done - scsi request callback
  2931. * @ioc: per adapter object
  2932. * @smid: system request message index
  2933. * @msix_index: MSIX table index supplied by the OS
  2934. * @reply: reply message frame(lower 32bit addr)
  2935. *
  2936. * Callback handler when using _scsih_qcmd.
  2937. *
  2938. * Return 1 meaning mf should be freed from _base_interrupt
  2939. * 0 means the mf is freed from this function.
  2940. */
  2941. static u8
  2942. _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  2943. {
  2944. Mpi2SCSIIORequest_t *mpi_request;
  2945. Mpi2SCSIIOReply_t *mpi_reply;
  2946. struct scsi_cmnd *scmd;
  2947. u16 ioc_status;
  2948. u32 xfer_cnt;
  2949. u8 scsi_state;
  2950. u8 scsi_status;
  2951. u32 log_info;
  2952. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2953. u32 response_code = 0;
  2954. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2955. scmd = _scsih_scsi_lookup_get(ioc, smid);
  2956. if (scmd == NULL)
  2957. return 1;
  2958. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2959. if (mpi_reply == NULL) {
  2960. scmd->result = DID_OK << 16;
  2961. goto out;
  2962. }
  2963. sas_device_priv_data = scmd->device->hostdata;
  2964. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  2965. sas_device_priv_data->sas_target->deleted) {
  2966. scmd->result = DID_NO_CONNECT << 16;
  2967. goto out;
  2968. }
  2969. /* turning off TLR */
  2970. scsi_state = mpi_reply->SCSIState;
  2971. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  2972. response_code =
  2973. le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
  2974. if (!sas_device_priv_data->tlr_snoop_check) {
  2975. sas_device_priv_data->tlr_snoop_check++;
  2976. if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
  2977. response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
  2978. sas_device_priv_data->flags &=
  2979. ~MPT_DEVICE_TLR_ON;
  2980. }
  2981. xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
  2982. scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
  2983. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  2984. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  2985. log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  2986. else
  2987. log_info = 0;
  2988. ioc_status &= MPI2_IOCSTATUS_MASK;
  2989. scsi_status = mpi_reply->SCSIStatus;
  2990. if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  2991. (scsi_status == MPI2_SCSI_STATUS_BUSY ||
  2992. scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
  2993. scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
  2994. ioc_status = MPI2_IOCSTATUS_SUCCESS;
  2995. }
  2996. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  2997. struct sense_info data;
  2998. const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
  2999. smid);
  3000. u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
  3001. le32_to_cpu(mpi_reply->SenseCount));
  3002. memcpy(scmd->sense_buffer, sense_data, sz);
  3003. _scsih_normalize_sense(scmd->sense_buffer, &data);
  3004. /* failure prediction threshold exceeded */
  3005. if (data.asc == 0x5D)
  3006. _scsih_smart_predicted_fault(ioc,
  3007. le16_to_cpu(mpi_reply->DevHandle));
  3008. }
  3009. switch (ioc_status) {
  3010. case MPI2_IOCSTATUS_BUSY:
  3011. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  3012. scmd->result = SAM_STAT_BUSY;
  3013. break;
  3014. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  3015. scmd->result = DID_NO_CONNECT << 16;
  3016. break;
  3017. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  3018. if (sas_device_priv_data->block) {
  3019. scmd->result = (DID_BUS_BUSY << 16);
  3020. break;
  3021. }
  3022. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  3023. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  3024. scmd->result = DID_RESET << 16;
  3025. break;
  3026. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  3027. if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
  3028. scmd->result = DID_SOFT_ERROR << 16;
  3029. else
  3030. scmd->result = (DID_OK << 16) | scsi_status;
  3031. break;
  3032. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  3033. scmd->result = (DID_OK << 16) | scsi_status;
  3034. if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
  3035. break;
  3036. if (xfer_cnt < scmd->underflow) {
  3037. if (scsi_status == SAM_STAT_BUSY)
  3038. scmd->result = SAM_STAT_BUSY;
  3039. else
  3040. scmd->result = DID_SOFT_ERROR << 16;
  3041. } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  3042. MPI2_SCSI_STATE_NO_SCSI_STATUS))
  3043. scmd->result = DID_SOFT_ERROR << 16;
  3044. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3045. scmd->result = DID_RESET << 16;
  3046. else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
  3047. mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
  3048. mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
  3049. scmd->result = (DRIVER_SENSE << 24) |
  3050. SAM_STAT_CHECK_CONDITION;
  3051. scmd->sense_buffer[0] = 0x70;
  3052. scmd->sense_buffer[2] = ILLEGAL_REQUEST;
  3053. scmd->sense_buffer[12] = 0x20;
  3054. scmd->sense_buffer[13] = 0;
  3055. }
  3056. break;
  3057. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  3058. scsi_set_resid(scmd, 0);
  3059. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  3060. case MPI2_IOCSTATUS_SUCCESS:
  3061. scmd->result = (DID_OK << 16) | scsi_status;
  3062. if (response_code ==
  3063. MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
  3064. (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  3065. MPI2_SCSI_STATE_NO_SCSI_STATUS)))
  3066. scmd->result = DID_SOFT_ERROR << 16;
  3067. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3068. scmd->result = DID_RESET << 16;
  3069. break;
  3070. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  3071. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  3072. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  3073. _scsih_eedp_error_handling(scmd, ioc_status);
  3074. break;
  3075. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  3076. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  3077. case MPI2_IOCSTATUS_INVALID_SGL:
  3078. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  3079. case MPI2_IOCSTATUS_INVALID_FIELD:
  3080. case MPI2_IOCSTATUS_INVALID_STATE:
  3081. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  3082. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  3083. default:
  3084. scmd->result = DID_SOFT_ERROR << 16;
  3085. break;
  3086. }
  3087. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3088. if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
  3089. _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
  3090. #endif
  3091. out:
  3092. scsi_dma_unmap(scmd);
  3093. scmd->scsi_done(scmd);
  3094. return 1;
  3095. }
  3096. /**
  3097. * _scsih_sas_host_refresh - refreshing sas host object contents
  3098. * @ioc: per adapter object
  3099. * Context: user
  3100. *
  3101. * During port enable, fw will send topology events for every device. Its
  3102. * possible that the handles may change from the previous setting, so this
  3103. * code keeping handles updating if changed.
  3104. *
  3105. * Return nothing.
  3106. */
  3107. static void
  3108. _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
  3109. {
  3110. u16 sz;
  3111. u16 ioc_status;
  3112. int i;
  3113. Mpi2ConfigReply_t mpi_reply;
  3114. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  3115. u16 attached_handle;
  3116. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
  3117. "updating handles for sas_host(0x%016llx)\n",
  3118. ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
  3119. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
  3120. * sizeof(Mpi2SasIOUnit0PhyData_t));
  3121. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  3122. if (!sas_iounit_pg0) {
  3123. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3124. ioc->name, __FILE__, __LINE__, __func__);
  3125. return;
  3126. }
  3127. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  3128. sas_iounit_pg0, sz)) != 0)
  3129. goto out;
  3130. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  3131. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  3132. goto out;
  3133. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  3134. if (i == 0)
  3135. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  3136. PhyData[0].ControllerDevHandle);
  3137. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  3138. attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
  3139. AttachedDevHandle);
  3140. mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
  3141. attached_handle, i, sas_iounit_pg0->PhyData[i].
  3142. NegotiatedLinkRate >> 4);
  3143. }
  3144. out:
  3145. kfree(sas_iounit_pg0);
  3146. }
  3147. /**
  3148. * _scsih_sas_host_add - create sas host object
  3149. * @ioc: per adapter object
  3150. *
  3151. * Creating host side data object, stored in ioc->sas_hba
  3152. *
  3153. * Return nothing.
  3154. */
  3155. static void
  3156. _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
  3157. {
  3158. int i;
  3159. Mpi2ConfigReply_t mpi_reply;
  3160. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  3161. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  3162. Mpi2SasPhyPage0_t phy_pg0;
  3163. Mpi2SasDevicePage0_t sas_device_pg0;
  3164. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3165. u16 ioc_status;
  3166. u16 sz;
  3167. u16 device_missing_delay;
  3168. mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
  3169. if (!ioc->sas_hba.num_phys) {
  3170. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3171. ioc->name, __FILE__, __LINE__, __func__);
  3172. return;
  3173. }
  3174. /* sas_iounit page 0 */
  3175. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
  3176. sizeof(Mpi2SasIOUnit0PhyData_t));
  3177. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  3178. if (!sas_iounit_pg0) {
  3179. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3180. ioc->name, __FILE__, __LINE__, __func__);
  3181. return;
  3182. }
  3183. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  3184. sas_iounit_pg0, sz))) {
  3185. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3186. ioc->name, __FILE__, __LINE__, __func__);
  3187. goto out;
  3188. }
  3189. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3190. MPI2_IOCSTATUS_MASK;
  3191. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3192. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3193. ioc->name, __FILE__, __LINE__, __func__);
  3194. goto out;
  3195. }
  3196. /* sas_iounit page 1 */
  3197. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  3198. sizeof(Mpi2SasIOUnit1PhyData_t));
  3199. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  3200. if (!sas_iounit_pg1) {
  3201. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3202. ioc->name, __FILE__, __LINE__, __func__);
  3203. goto out;
  3204. }
  3205. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  3206. sas_iounit_pg1, sz))) {
  3207. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3208. ioc->name, __FILE__, __LINE__, __func__);
  3209. goto out;
  3210. }
  3211. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3212. MPI2_IOCSTATUS_MASK;
  3213. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3214. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3215. ioc->name, __FILE__, __LINE__, __func__);
  3216. goto out;
  3217. }
  3218. ioc->io_missing_delay =
  3219. le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
  3220. device_missing_delay =
  3221. le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
  3222. if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  3223. ioc->device_missing_delay = (device_missing_delay &
  3224. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  3225. else
  3226. ioc->device_missing_delay = device_missing_delay &
  3227. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  3228. ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
  3229. ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
  3230. sizeof(struct _sas_phy), GFP_KERNEL);
  3231. if (!ioc->sas_hba.phy) {
  3232. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3233. ioc->name, __FILE__, __LINE__, __func__);
  3234. goto out;
  3235. }
  3236. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  3237. if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  3238. i))) {
  3239. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3240. ioc->name, __FILE__, __LINE__, __func__);
  3241. goto out;
  3242. }
  3243. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3244. MPI2_IOCSTATUS_MASK;
  3245. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3246. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3247. ioc->name, __FILE__, __LINE__, __func__);
  3248. goto out;
  3249. }
  3250. if (i == 0)
  3251. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  3252. PhyData[0].ControllerDevHandle);
  3253. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  3254. ioc->sas_hba.phy[i].phy_id = i;
  3255. mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
  3256. phy_pg0, ioc->sas_hba.parent_dev);
  3257. }
  3258. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  3259. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
  3260. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3261. ioc->name, __FILE__, __LINE__, __func__);
  3262. goto out;
  3263. }
  3264. ioc->sas_hba.enclosure_handle =
  3265. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  3266. ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  3267. printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
  3268. "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
  3269. (unsigned long long) ioc->sas_hba.sas_address,
  3270. ioc->sas_hba.num_phys) ;
  3271. if (ioc->sas_hba.enclosure_handle) {
  3272. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  3273. &enclosure_pg0,
  3274. MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3275. ioc->sas_hba.enclosure_handle))) {
  3276. ioc->sas_hba.enclosure_logical_id =
  3277. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3278. }
  3279. }
  3280. out:
  3281. kfree(sas_iounit_pg1);
  3282. kfree(sas_iounit_pg0);
  3283. }
  3284. /**
  3285. * _scsih_expander_add - creating expander object
  3286. * @ioc: per adapter object
  3287. * @handle: expander handle
  3288. *
  3289. * Creating expander object, stored in ioc->sas_expander_list.
  3290. *
  3291. * Return 0 for success, else error.
  3292. */
  3293. static int
  3294. _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3295. {
  3296. struct _sas_node *sas_expander;
  3297. Mpi2ConfigReply_t mpi_reply;
  3298. Mpi2ExpanderPage0_t expander_pg0;
  3299. Mpi2ExpanderPage1_t expander_pg1;
  3300. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3301. u32 ioc_status;
  3302. u16 parent_handle;
  3303. __le64 sas_address, sas_address_parent = 0;
  3304. int i;
  3305. unsigned long flags;
  3306. struct _sas_port *mpt2sas_port = NULL;
  3307. int rc = 0;
  3308. if (!handle)
  3309. return -1;
  3310. if (ioc->shost_recovery)
  3311. return -1;
  3312. if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  3313. MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
  3314. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3315. ioc->name, __FILE__, __LINE__, __func__);
  3316. return -1;
  3317. }
  3318. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3319. MPI2_IOCSTATUS_MASK;
  3320. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3321. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3322. ioc->name, __FILE__, __LINE__, __func__);
  3323. return -1;
  3324. }
  3325. /* handle out of order topology events */
  3326. parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
  3327. if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
  3328. != 0) {
  3329. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3330. ioc->name, __FILE__, __LINE__, __func__);
  3331. return -1;
  3332. }
  3333. if (sas_address_parent != ioc->sas_hba.sas_address) {
  3334. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3335. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3336. sas_address_parent);
  3337. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3338. if (!sas_expander) {
  3339. rc = _scsih_expander_add(ioc, parent_handle);
  3340. if (rc != 0)
  3341. return rc;
  3342. }
  3343. }
  3344. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3345. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  3346. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3347. sas_address);
  3348. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3349. if (sas_expander)
  3350. return 0;
  3351. sas_expander = kzalloc(sizeof(struct _sas_node),
  3352. GFP_KERNEL);
  3353. if (!sas_expander) {
  3354. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3355. ioc->name, __FILE__, __LINE__, __func__);
  3356. return -1;
  3357. }
  3358. sas_expander->handle = handle;
  3359. sas_expander->num_phys = expander_pg0.NumPhys;
  3360. sas_expander->sas_address_parent = sas_address_parent;
  3361. sas_expander->sas_address = sas_address;
  3362. printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
  3363. " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
  3364. handle, parent_handle, (unsigned long long)
  3365. sas_expander->sas_address, sas_expander->num_phys);
  3366. if (!sas_expander->num_phys)
  3367. goto out_fail;
  3368. sas_expander->phy = kcalloc(sas_expander->num_phys,
  3369. sizeof(struct _sas_phy), GFP_KERNEL);
  3370. if (!sas_expander->phy) {
  3371. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3372. ioc->name, __FILE__, __LINE__, __func__);
  3373. rc = -1;
  3374. goto out_fail;
  3375. }
  3376. INIT_LIST_HEAD(&sas_expander->sas_port_list);
  3377. mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
  3378. sas_address_parent);
  3379. if (!mpt2sas_port) {
  3380. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3381. ioc->name, __FILE__, __LINE__, __func__);
  3382. rc = -1;
  3383. goto out_fail;
  3384. }
  3385. sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
  3386. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  3387. if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
  3388. &expander_pg1, i, handle))) {
  3389. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3390. ioc->name, __FILE__, __LINE__, __func__);
  3391. rc = -1;
  3392. goto out_fail;
  3393. }
  3394. sas_expander->phy[i].handle = handle;
  3395. sas_expander->phy[i].phy_id = i;
  3396. if ((mpt2sas_transport_add_expander_phy(ioc,
  3397. &sas_expander->phy[i], expander_pg1,
  3398. sas_expander->parent_dev))) {
  3399. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3400. ioc->name, __FILE__, __LINE__, __func__);
  3401. rc = -1;
  3402. goto out_fail;
  3403. }
  3404. }
  3405. if (sas_expander->enclosure_handle) {
  3406. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  3407. &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3408. sas_expander->enclosure_handle))) {
  3409. sas_expander->enclosure_logical_id =
  3410. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3411. }
  3412. }
  3413. _scsih_expander_node_add(ioc, sas_expander);
  3414. return 0;
  3415. out_fail:
  3416. if (mpt2sas_port)
  3417. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  3418. sas_address_parent);
  3419. kfree(sas_expander);
  3420. return rc;
  3421. }
  3422. /**
  3423. * _scsih_expander_remove - removing expander object
  3424. * @ioc: per adapter object
  3425. * @sas_address: expander sas_address
  3426. *
  3427. * Return nothing.
  3428. */
  3429. static void
  3430. _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
  3431. {
  3432. struct _sas_node *sas_expander;
  3433. unsigned long flags;
  3434. if (ioc->shost_recovery)
  3435. return;
  3436. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3437. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3438. sas_address);
  3439. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3440. _scsih_expander_node_remove(ioc, sas_expander);
  3441. }
  3442. /**
  3443. * _scsih_add_device - creating sas device object
  3444. * @ioc: per adapter object
  3445. * @handle: sas device handle
  3446. * @phy_num: phy number end device attached to
  3447. * @is_pd: is this hidden raid component
  3448. *
  3449. * Creating end device object, stored in ioc->sas_device_list.
  3450. *
  3451. * Returns 0 for success, non-zero for failure.
  3452. */
  3453. static int
  3454. _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
  3455. {
  3456. Mpi2ConfigReply_t mpi_reply;
  3457. Mpi2SasDevicePage0_t sas_device_pg0;
  3458. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3459. struct _sas_device *sas_device;
  3460. u32 ioc_status;
  3461. __le64 sas_address;
  3462. u32 device_info;
  3463. unsigned long flags;
  3464. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  3465. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  3466. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3467. ioc->name, __FILE__, __LINE__, __func__);
  3468. return -1;
  3469. }
  3470. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3471. MPI2_IOCSTATUS_MASK;
  3472. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3473. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3474. ioc->name, __FILE__, __LINE__, __func__);
  3475. return -1;
  3476. }
  3477. /* check if device is present */
  3478. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  3479. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  3480. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3481. ioc->name, __FILE__, __LINE__, __func__);
  3482. printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
  3483. ioc->name, le16_to_cpu(sas_device_pg0.Flags));
  3484. return -1;
  3485. }
  3486. /* check if there were any issus with discovery */
  3487. if (sas_device_pg0.AccessStatus ==
  3488. MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) {
  3489. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3490. ioc->name, __FILE__, __LINE__, __func__);
  3491. printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n",
  3492. ioc->name, sas_device_pg0.AccessStatus);
  3493. return -1;
  3494. }
  3495. /* check if this is end device */
  3496. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  3497. if (!(_scsih_is_end_device(device_info))) {
  3498. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3499. ioc->name, __FILE__, __LINE__, __func__);
  3500. return -1;
  3501. }
  3502. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  3503. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3504. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  3505. sas_address);
  3506. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3507. if (sas_device) {
  3508. _scsih_ublock_io_device(ioc, handle);
  3509. return 0;
  3510. }
  3511. sas_device = kzalloc(sizeof(struct _sas_device),
  3512. GFP_KERNEL);
  3513. if (!sas_device) {
  3514. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3515. ioc->name, __FILE__, __LINE__, __func__);
  3516. return -1;
  3517. }
  3518. sas_device->handle = handle;
  3519. if (_scsih_get_sas_address(ioc, le16_to_cpu
  3520. (sas_device_pg0.ParentDevHandle),
  3521. &sas_device->sas_address_parent) != 0)
  3522. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3523. ioc->name, __FILE__, __LINE__, __func__);
  3524. sas_device->enclosure_handle =
  3525. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  3526. sas_device->slot =
  3527. le16_to_cpu(sas_device_pg0.Slot);
  3528. sas_device->device_info = device_info;
  3529. sas_device->sas_address = sas_address;
  3530. sas_device->hidden_raid_component = is_pd;
  3531. /* get enclosure_logical_id */
  3532. if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
  3533. ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3534. sas_device->enclosure_handle)))
  3535. sas_device->enclosure_logical_id =
  3536. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3537. /* get device name */
  3538. sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
  3539. if (ioc->wait_for_port_enable_to_complete)
  3540. _scsih_sas_device_init_add(ioc, sas_device);
  3541. else
  3542. _scsih_sas_device_add(ioc, sas_device);
  3543. return 0;
  3544. }
  3545. /**
  3546. * _scsih_remove_device - removing sas device object
  3547. * @ioc: per adapter object
  3548. * @sas_device: the sas_device object
  3549. *
  3550. * Return nothing.
  3551. */
  3552. static void
  3553. _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, struct _sas_device
  3554. *sas_device)
  3555. {
  3556. struct MPT2SAS_TARGET *sas_target_priv_data;
  3557. Mpi2SasIoUnitControlReply_t mpi_reply;
  3558. Mpi2SasIoUnitControlRequest_t mpi_request;
  3559. u16 device_handle, handle;
  3560. if (!sas_device)
  3561. return;
  3562. handle = sas_device->handle;
  3563. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle(0x%04x),"
  3564. " sas_addr(0x%016llx)\n", ioc->name, __func__, handle,
  3565. (unsigned long long) sas_device->sas_address));
  3566. if (sas_device->starget && sas_device->starget->hostdata) {
  3567. sas_target_priv_data = sas_device->starget->hostdata;
  3568. sas_target_priv_data->deleted = 1;
  3569. }
  3570. if (ioc->remove_host || ioc->shost_recovery || !handle)
  3571. goto out;
  3572. if ((sas_device->state & MPTSAS_STATE_TR_COMPLETE)) {
  3573. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "\tskip "
  3574. "target_reset handle(0x%04x)\n", ioc->name,
  3575. handle));
  3576. goto skip_tr;
  3577. }
  3578. /* Target Reset to flush out all the outstanding IO */
  3579. device_handle = (sas_device->hidden_raid_component) ?
  3580. sas_device->volume_handle : handle;
  3581. if (device_handle) {
  3582. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: "
  3583. "handle(0x%04x)\n", ioc->name, device_handle));
  3584. mutex_lock(&ioc->tm_cmds.mutex);
  3585. mpt2sas_scsih_issue_tm(ioc, device_handle, 0,
  3586. MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
  3587. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  3588. mutex_unlock(&ioc->tm_cmds.mutex);
  3589. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset "
  3590. "done: handle(0x%04x)\n", ioc->name, device_handle));
  3591. if (ioc->shost_recovery)
  3592. goto out;
  3593. }
  3594. skip_tr:
  3595. if ((sas_device->state & MPTSAS_STATE_CNTRL_COMPLETE)) {
  3596. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "\tskip "
  3597. "sas_cntrl handle(0x%04x)\n", ioc->name, handle));
  3598. goto out;
  3599. }
  3600. /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
  3601. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle"
  3602. "(0x%04x)\n", ioc->name, handle));
  3603. memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  3604. mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  3605. mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  3606. mpi_request.DevHandle = handle;
  3607. mpi_request.VF_ID = 0; /* TODO */
  3608. mpi_request.VP_ID = 0;
  3609. if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply,
  3610. &mpi_request)) != 0) {
  3611. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3612. ioc->name, __FILE__, __LINE__, __func__);
  3613. }
  3614. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status"
  3615. "(0x%04x), loginfo(0x%08x)\n", ioc->name,
  3616. le16_to_cpu(mpi_reply.IOCStatus),
  3617. le32_to_cpu(mpi_reply.IOCLogInfo)));
  3618. out:
  3619. _scsih_ublock_io_device(ioc, handle);
  3620. mpt2sas_transport_port_remove(ioc, sas_device->sas_address,
  3621. sas_device->sas_address_parent);
  3622. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
  3623. "(0x%016llx)\n", ioc->name, handle,
  3624. (unsigned long long) sas_device->sas_address);
  3625. _scsih_sas_device_remove(ioc, sas_device);
  3626. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle"
  3627. "(0x%04x)\n", ioc->name, __func__, handle));
  3628. }
  3629. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3630. /**
  3631. * _scsih_sas_topology_change_event_debug - debug for topology event
  3632. * @ioc: per adapter object
  3633. * @event_data: event data payload
  3634. * Context: user.
  3635. */
  3636. static void
  3637. _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  3638. Mpi2EventDataSasTopologyChangeList_t *event_data)
  3639. {
  3640. int i;
  3641. u16 handle;
  3642. u16 reason_code;
  3643. u8 phy_number;
  3644. char *status_str = NULL;
  3645. char link_rate[25];
  3646. switch (event_data->ExpStatus) {
  3647. case MPI2_EVENT_SAS_TOPO_ES_ADDED:
  3648. status_str = "add";
  3649. break;
  3650. case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
  3651. status_str = "remove";
  3652. break;
  3653. case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
  3654. status_str = "responding";
  3655. break;
  3656. case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
  3657. status_str = "remove delay";
  3658. break;
  3659. default:
  3660. status_str = "unknown status";
  3661. break;
  3662. }
  3663. printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n",
  3664. ioc->name, status_str);
  3665. printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) "
  3666. "start_phy(%02d), count(%d)\n",
  3667. le16_to_cpu(event_data->ExpanderDevHandle),
  3668. le16_to_cpu(event_data->EnclosureHandle),
  3669. event_data->StartPhyNum, event_data->NumEntries);
  3670. for (i = 0; i < event_data->NumEntries; i++) {
  3671. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3672. if (!handle)
  3673. continue;
  3674. phy_number = event_data->StartPhyNum + i;
  3675. reason_code = event_data->PHY[i].PhyStatus &
  3676. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3677. switch (reason_code) {
  3678. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  3679. snprintf(link_rate, 25, ": add, link(0x%02x)",
  3680. (event_data->PHY[i].LinkRate >> 4));
  3681. status_str = link_rate;
  3682. break;
  3683. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  3684. status_str = ": remove";
  3685. break;
  3686. case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
  3687. status_str = ": remove_delay";
  3688. break;
  3689. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  3690. snprintf(link_rate, 25, ": link(0x%02x)",
  3691. (event_data->PHY[i].LinkRate >> 4));
  3692. status_str = link_rate;
  3693. break;
  3694. case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
  3695. status_str = ": responding";
  3696. break;
  3697. default:
  3698. status_str = ": unknown";
  3699. break;
  3700. }
  3701. printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n",
  3702. phy_number, handle, status_str);
  3703. }
  3704. }
  3705. #endif
  3706. /**
  3707. * _scsih_sas_topology_change_event - handle topology changes
  3708. * @ioc: per adapter object
  3709. * @fw_event: The fw_event_work object
  3710. * Context: user.
  3711. *
  3712. */
  3713. static void
  3714. _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
  3715. struct fw_event_work *fw_event)
  3716. {
  3717. int i;
  3718. u16 parent_handle, handle;
  3719. u16 reason_code;
  3720. u8 phy_number;
  3721. struct _sas_node *sas_expander;
  3722. struct _sas_device *sas_device;
  3723. u64 sas_address;
  3724. unsigned long flags;
  3725. u8 link_rate;
  3726. Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
  3727. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3728. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  3729. _scsih_sas_topology_change_event_debug(ioc, event_data);
  3730. #endif
  3731. if (ioc->shost_recovery)
  3732. return;
  3733. if (!ioc->sas_hba.num_phys)
  3734. _scsih_sas_host_add(ioc);
  3735. else
  3736. _scsih_sas_host_refresh(ioc);
  3737. if (fw_event->ignore) {
  3738. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander "
  3739. "event\n", ioc->name));
  3740. return;
  3741. }
  3742. parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  3743. /* handle expander add */
  3744. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
  3745. if (_scsih_expander_add(ioc, parent_handle) != 0)
  3746. return;
  3747. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3748. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  3749. parent_handle);
  3750. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3751. if (sas_expander)
  3752. sas_address = sas_expander->sas_address;
  3753. else if (parent_handle < ioc->sas_hba.num_phys)
  3754. sas_address = ioc->sas_hba.sas_address;
  3755. else
  3756. return;
  3757. /* handle siblings events */
  3758. for (i = 0; i < event_data->NumEntries; i++) {
  3759. if (fw_event->ignore) {
  3760. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring "
  3761. "expander event\n", ioc->name));
  3762. return;
  3763. }
  3764. if (ioc->shost_recovery)
  3765. return;
  3766. phy_number = event_data->StartPhyNum + i;
  3767. reason_code = event_data->PHY[i].PhyStatus &
  3768. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3769. if ((event_data->PHY[i].PhyStatus &
  3770. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
  3771. MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
  3772. continue;
  3773. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3774. if (!handle)
  3775. continue;
  3776. link_rate = event_data->PHY[i].LinkRate >> 4;
  3777. switch (reason_code) {
  3778. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  3779. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  3780. mpt2sas_transport_update_links(ioc, sas_address,
  3781. handle, phy_number, link_rate);
  3782. if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  3783. break;
  3784. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) {
  3785. _scsih_add_device(ioc, handle, phy_number, 0);
  3786. }
  3787. break;
  3788. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  3789. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3790. sas_device = _scsih_sas_device_find_by_handle(ioc,
  3791. handle);
  3792. if (!sas_device) {
  3793. spin_unlock_irqrestore(&ioc->sas_device_lock,
  3794. flags);
  3795. break;
  3796. }
  3797. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3798. _scsih_remove_device(ioc, sas_device);
  3799. break;
  3800. }
  3801. }
  3802. /* handle expander removal */
  3803. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
  3804. sas_expander)
  3805. _scsih_expander_remove(ioc, sas_address);
  3806. }
  3807. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3808. /**
  3809. * _scsih_sas_device_status_change_event_debug - debug for device event
  3810. * @event_data: event data payload
  3811. * Context: user.
  3812. *
  3813. * Return nothing.
  3814. */
  3815. static void
  3816. _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  3817. Mpi2EventDataSasDeviceStatusChange_t *event_data)
  3818. {
  3819. char *reason_str = NULL;
  3820. switch (event_data->ReasonCode) {
  3821. case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  3822. reason_str = "smart data";
  3823. break;
  3824. case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  3825. reason_str = "unsupported device discovered";
  3826. break;
  3827. case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  3828. reason_str = "internal device reset";
  3829. break;
  3830. case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  3831. reason_str = "internal task abort";
  3832. break;
  3833. case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  3834. reason_str = "internal task abort set";
  3835. break;
  3836. case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  3837. reason_str = "internal clear task set";
  3838. break;
  3839. case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  3840. reason_str = "internal query task";
  3841. break;
  3842. case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
  3843. reason_str = "sata init failure";
  3844. break;
  3845. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
  3846. reason_str = "internal device reset complete";
  3847. break;
  3848. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
  3849. reason_str = "internal task abort complete";
  3850. break;
  3851. case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
  3852. reason_str = "internal async notification";
  3853. break;
  3854. default:
  3855. reason_str = "unknown reason";
  3856. break;
  3857. }
  3858. printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n"
  3859. "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
  3860. reason_str, le16_to_cpu(event_data->DevHandle),
  3861. (unsigned long long)le64_to_cpu(event_data->SASAddress));
  3862. if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
  3863. printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
  3864. event_data->ASC, event_data->ASCQ);
  3865. printk(KERN_INFO "\n");
  3866. }
  3867. #endif
  3868. /**
  3869. * _scsih_sas_device_status_change_event - handle device status change
  3870. * @ioc: per adapter object
  3871. * @fw_event: The fw_event_work object
  3872. * Context: user.
  3873. *
  3874. * Return nothing.
  3875. */
  3876. static void
  3877. _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  3878. struct fw_event_work *fw_event)
  3879. {
  3880. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3881. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  3882. _scsih_sas_device_status_change_event_debug(ioc,
  3883. fw_event->event_data);
  3884. #endif
  3885. }
  3886. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3887. /**
  3888. * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
  3889. * @ioc: per adapter object
  3890. * @event_data: event data payload
  3891. * Context: user.
  3892. *
  3893. * Return nothing.
  3894. */
  3895. static void
  3896. _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  3897. Mpi2EventDataSasEnclDevStatusChange_t *event_data)
  3898. {
  3899. char *reason_str = NULL;
  3900. switch (event_data->ReasonCode) {
  3901. case MPI2_EVENT_SAS_ENCL_RC_ADDED:
  3902. reason_str = "enclosure add";
  3903. break;
  3904. case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
  3905. reason_str = "enclosure remove";
  3906. break;
  3907. default:
  3908. reason_str = "unknown reason";
  3909. break;
  3910. }
  3911. printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n"
  3912. "\thandle(0x%04x), enclosure logical id(0x%016llx)"
  3913. " number slots(%d)\n", ioc->name, reason_str,
  3914. le16_to_cpu(event_data->EnclosureHandle),
  3915. (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
  3916. le16_to_cpu(event_data->StartSlot));
  3917. }
  3918. #endif
  3919. /**
  3920. * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
  3921. * @ioc: per adapter object
  3922. * @fw_event: The fw_event_work object
  3923. * Context: user.
  3924. *
  3925. * Return nothing.
  3926. */
  3927. static void
  3928. _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  3929. struct fw_event_work *fw_event)
  3930. {
  3931. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3932. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  3933. _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
  3934. fw_event->event_data);
  3935. #endif
  3936. }
  3937. /**
  3938. * _scsih_sas_broadcast_primative_event - handle broadcast events
  3939. * @ioc: per adapter object
  3940. * @fw_event: The fw_event_work object
  3941. * Context: user.
  3942. *
  3943. * Return nothing.
  3944. */
  3945. static void
  3946. _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
  3947. struct fw_event_work *fw_event)
  3948. {
  3949. struct scsi_cmnd *scmd;
  3950. u16 smid, handle;
  3951. u32 lun;
  3952. struct MPT2SAS_DEVICE *sas_device_priv_data;
  3953. u32 termination_count;
  3954. u32 query_count;
  3955. Mpi2SCSITaskManagementReply_t *mpi_reply;
  3956. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3957. Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
  3958. #endif
  3959. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: "
  3960. "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
  3961. event_data->PortWidth));
  3962. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  3963. __func__));
  3964. mutex_lock(&ioc->tm_cmds.mutex);
  3965. termination_count = 0;
  3966. query_count = 0;
  3967. mpi_reply = ioc->tm_cmds.reply;
  3968. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  3969. scmd = _scsih_scsi_lookup_get(ioc, smid);
  3970. if (!scmd)
  3971. continue;
  3972. sas_device_priv_data = scmd->device->hostdata;
  3973. if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
  3974. continue;
  3975. /* skip hidden raid components */
  3976. if (sas_device_priv_data->sas_target->flags &
  3977. MPT_TARGET_FLAGS_RAID_COMPONENT)
  3978. continue;
  3979. /* skip volumes */
  3980. if (sas_device_priv_data->sas_target->flags &
  3981. MPT_TARGET_FLAGS_VOLUME)
  3982. continue;
  3983. handle = sas_device_priv_data->sas_target->handle;
  3984. lun = sas_device_priv_data->lun;
  3985. query_count++;
  3986. mpt2sas_scsih_issue_tm(ioc, handle, lun,
  3987. MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
  3988. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  3989. if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
  3990. (mpi_reply->ResponseCode ==
  3991. MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
  3992. mpi_reply->ResponseCode ==
  3993. MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
  3994. continue;
  3995. mpt2sas_scsih_issue_tm(ioc, handle, lun,
  3996. MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30);
  3997. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  3998. termination_count += le32_to_cpu(mpi_reply->TerminationCount);
  3999. }
  4000. ioc->broadcast_aen_busy = 0;
  4001. mutex_unlock(&ioc->tm_cmds.mutex);
  4002. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  4003. "%s - exit, query_count = %d termination_count = %d\n",
  4004. ioc->name, __func__, query_count, termination_count));
  4005. }
  4006. /**
  4007. * _scsih_sas_discovery_event - handle discovery events
  4008. * @ioc: per adapter object
  4009. * @fw_event: The fw_event_work object
  4010. * Context: user.
  4011. *
  4012. * Return nothing.
  4013. */
  4014. static void
  4015. _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
  4016. struct fw_event_work *fw_event)
  4017. {
  4018. Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
  4019. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4020. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
  4021. printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name,
  4022. (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
  4023. "start" : "stop");
  4024. if (event_data->DiscoveryStatus)
  4025. printk("discovery_status(0x%08x)",
  4026. le32_to_cpu(event_data->DiscoveryStatus));
  4027. printk("\n");
  4028. }
  4029. #endif
  4030. if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
  4031. !ioc->sas_hba.num_phys)
  4032. _scsih_sas_host_add(ioc);
  4033. }
  4034. /**
  4035. * _scsih_reprobe_lun - reprobing lun
  4036. * @sdev: scsi device struct
  4037. * @no_uld_attach: sdev->no_uld_attach flag setting
  4038. *
  4039. **/
  4040. static void
  4041. _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
  4042. {
  4043. int rc;
  4044. sdev->no_uld_attach = no_uld_attach ? 1 : 0;
  4045. sdev_printk(KERN_INFO, sdev, "%s raid component\n",
  4046. sdev->no_uld_attach ? "hidding" : "exposing");
  4047. rc = scsi_device_reprobe(sdev);
  4048. }
  4049. /**
  4050. * _scsih_reprobe_target - reprobing target
  4051. * @starget: scsi target struct
  4052. * @no_uld_attach: sdev->no_uld_attach flag setting
  4053. *
  4054. * Note: no_uld_attach flag determines whether the disk device is attached
  4055. * to block layer. A value of `1` means to not attach.
  4056. **/
  4057. static void
  4058. _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
  4059. {
  4060. struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
  4061. if (no_uld_attach)
  4062. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  4063. else
  4064. sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  4065. starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
  4066. _scsih_reprobe_lun);
  4067. }
  4068. /**
  4069. * _scsih_sas_volume_add - add new volume
  4070. * @ioc: per adapter object
  4071. * @element: IR config element data
  4072. * Context: user.
  4073. *
  4074. * Return nothing.
  4075. */
  4076. static void
  4077. _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
  4078. Mpi2EventIrConfigElement_t *element)
  4079. {
  4080. struct _raid_device *raid_device;
  4081. unsigned long flags;
  4082. u64 wwid;
  4083. u16 handle = le16_to_cpu(element->VolDevHandle);
  4084. int rc;
  4085. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  4086. if (!wwid) {
  4087. printk(MPT2SAS_ERR_FMT
  4088. "failure at %s:%d/%s()!\n", ioc->name,
  4089. __FILE__, __LINE__, __func__);
  4090. return;
  4091. }
  4092. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4093. raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
  4094. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4095. if (raid_device)
  4096. return;
  4097. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  4098. if (!raid_device) {
  4099. printk(MPT2SAS_ERR_FMT
  4100. "failure at %s:%d/%s()!\n", ioc->name,
  4101. __FILE__, __LINE__, __func__);
  4102. return;
  4103. }
  4104. raid_device->id = ioc->sas_id++;
  4105. raid_device->channel = RAID_CHANNEL;
  4106. raid_device->handle = handle;
  4107. raid_device->wwid = wwid;
  4108. _scsih_raid_device_add(ioc, raid_device);
  4109. if (!ioc->wait_for_port_enable_to_complete) {
  4110. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  4111. raid_device->id, 0);
  4112. if (rc)
  4113. _scsih_raid_device_remove(ioc, raid_device);
  4114. } else
  4115. _scsih_determine_boot_device(ioc, raid_device, 1);
  4116. }
  4117. /**
  4118. * _scsih_sas_volume_delete - delete volume
  4119. * @ioc: per adapter object
  4120. * @element: IR config element data
  4121. * Context: user.
  4122. *
  4123. * Return nothing.
  4124. */
  4125. static void
  4126. _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc,
  4127. Mpi2EventIrConfigElement_t *element)
  4128. {
  4129. struct _raid_device *raid_device;
  4130. u16 handle = le16_to_cpu(element->VolDevHandle);
  4131. unsigned long flags;
  4132. struct MPT2SAS_TARGET *sas_target_priv_data;
  4133. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4134. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  4135. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4136. if (!raid_device)
  4137. return;
  4138. if (raid_device->starget) {
  4139. sas_target_priv_data = raid_device->starget->hostdata;
  4140. sas_target_priv_data->deleted = 1;
  4141. scsi_remove_target(&raid_device->starget->dev);
  4142. }
  4143. _scsih_raid_device_remove(ioc, raid_device);
  4144. }
  4145. /**
  4146. * _scsih_sas_pd_expose - expose pd component to /dev/sdX
  4147. * @ioc: per adapter object
  4148. * @element: IR config element data
  4149. * Context: user.
  4150. *
  4151. * Return nothing.
  4152. */
  4153. static void
  4154. _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
  4155. Mpi2EventIrConfigElement_t *element)
  4156. {
  4157. struct _sas_device *sas_device;
  4158. unsigned long flags;
  4159. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4160. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4161. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4162. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4163. if (!sas_device)
  4164. return;
  4165. /* exposing raid component */
  4166. sas_device->volume_handle = 0;
  4167. sas_device->volume_wwid = 0;
  4168. sas_device->hidden_raid_component = 0;
  4169. _scsih_reprobe_target(sas_device->starget, 0);
  4170. }
  4171. /**
  4172. * _scsih_sas_pd_hide - hide pd component from /dev/sdX
  4173. * @ioc: per adapter object
  4174. * @element: IR config element data
  4175. * Context: user.
  4176. *
  4177. * Return nothing.
  4178. */
  4179. static void
  4180. _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
  4181. Mpi2EventIrConfigElement_t *element)
  4182. {
  4183. struct _sas_device *sas_device;
  4184. unsigned long flags;
  4185. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4186. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4187. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4188. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4189. if (!sas_device)
  4190. return;
  4191. /* hiding raid component */
  4192. mpt2sas_config_get_volume_handle(ioc, handle,
  4193. &sas_device->volume_handle);
  4194. mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
  4195. &sas_device->volume_wwid);
  4196. sas_device->hidden_raid_component = 1;
  4197. _scsih_reprobe_target(sas_device->starget, 1);
  4198. }
  4199. /**
  4200. * _scsih_sas_pd_delete - delete pd component
  4201. * @ioc: per adapter object
  4202. * @element: IR config element data
  4203. * Context: user.
  4204. *
  4205. * Return nothing.
  4206. */
  4207. static void
  4208. _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
  4209. Mpi2EventIrConfigElement_t *element)
  4210. {
  4211. struct _sas_device *sas_device;
  4212. unsigned long flags;
  4213. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4214. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4215. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4216. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4217. if (!sas_device)
  4218. return;
  4219. _scsih_remove_device(ioc, sas_device);
  4220. }
  4221. /**
  4222. * _scsih_sas_pd_add - remove pd component
  4223. * @ioc: per adapter object
  4224. * @element: IR config element data
  4225. * Context: user.
  4226. *
  4227. * Return nothing.
  4228. */
  4229. static void
  4230. _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
  4231. Mpi2EventIrConfigElement_t *element)
  4232. {
  4233. struct _sas_device *sas_device;
  4234. unsigned long flags;
  4235. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4236. Mpi2ConfigReply_t mpi_reply;
  4237. Mpi2SasDevicePage0_t sas_device_pg0;
  4238. u32 ioc_status;
  4239. u64 sas_address;
  4240. u16 parent_handle;
  4241. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4242. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4243. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4244. if (sas_device) {
  4245. sas_device->hidden_raid_component = 1;
  4246. return;
  4247. }
  4248. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4249. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  4250. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4251. ioc->name, __FILE__, __LINE__, __func__);
  4252. return;
  4253. }
  4254. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4255. MPI2_IOCSTATUS_MASK;
  4256. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4257. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4258. ioc->name, __FILE__, __LINE__, __func__);
  4259. return;
  4260. }
  4261. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  4262. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  4263. mpt2sas_transport_update_links(ioc, sas_address, handle,
  4264. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  4265. _scsih_add_device(ioc, handle, 0, 1);
  4266. }
  4267. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4268. /**
  4269. * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
  4270. * @ioc: per adapter object
  4271. * @event_data: event data payload
  4272. * Context: user.
  4273. *
  4274. * Return nothing.
  4275. */
  4276. static void
  4277. _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4278. Mpi2EventDataIrConfigChangeList_t *event_data)
  4279. {
  4280. Mpi2EventIrConfigElement_t *element;
  4281. u8 element_type;
  4282. int i;
  4283. char *reason_str = NULL, *element_str = NULL;
  4284. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  4285. printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n",
  4286. ioc->name, (le32_to_cpu(event_data->Flags) &
  4287. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
  4288. "foreign" : "native", event_data->NumElements);
  4289. for (i = 0; i < event_data->NumElements; i++, element++) {
  4290. switch (element->ReasonCode) {
  4291. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  4292. reason_str = "add";
  4293. break;
  4294. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  4295. reason_str = "remove";
  4296. break;
  4297. case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
  4298. reason_str = "no change";
  4299. break;
  4300. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  4301. reason_str = "hide";
  4302. break;
  4303. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  4304. reason_str = "unhide";
  4305. break;
  4306. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  4307. reason_str = "volume_created";
  4308. break;
  4309. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  4310. reason_str = "volume_deleted";
  4311. break;
  4312. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  4313. reason_str = "pd_created";
  4314. break;
  4315. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  4316. reason_str = "pd_deleted";
  4317. break;
  4318. default:
  4319. reason_str = "unknown reason";
  4320. break;
  4321. }
  4322. element_type = le16_to_cpu(element->ElementFlags) &
  4323. MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
  4324. switch (element_type) {
  4325. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
  4326. element_str = "volume";
  4327. break;
  4328. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
  4329. element_str = "phys disk";
  4330. break;
  4331. case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
  4332. element_str = "hot spare";
  4333. break;
  4334. default:
  4335. element_str = "unknown element";
  4336. break;
  4337. }
  4338. printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), "
  4339. "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
  4340. reason_str, le16_to_cpu(element->VolDevHandle),
  4341. le16_to_cpu(element->PhysDiskDevHandle),
  4342. element->PhysDiskNum);
  4343. }
  4344. }
  4345. #endif
  4346. /**
  4347. * _scsih_sas_ir_config_change_event - handle ir configuration change events
  4348. * @ioc: per adapter object
  4349. * @fw_event: The fw_event_work object
  4350. * Context: user.
  4351. *
  4352. * Return nothing.
  4353. */
  4354. static void
  4355. _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
  4356. struct fw_event_work *fw_event)
  4357. {
  4358. Mpi2EventIrConfigElement_t *element;
  4359. int i;
  4360. u8 foreign_config;
  4361. Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
  4362. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4363. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4364. _scsih_sas_ir_config_change_event_debug(ioc, event_data);
  4365. #endif
  4366. foreign_config = (le32_to_cpu(event_data->Flags) &
  4367. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
  4368. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  4369. for (i = 0; i < event_data->NumElements; i++, element++) {
  4370. switch (element->ReasonCode) {
  4371. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  4372. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  4373. if (!foreign_config)
  4374. _scsih_sas_volume_add(ioc, element);
  4375. break;
  4376. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  4377. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  4378. if (!foreign_config)
  4379. _scsih_sas_volume_delete(ioc, element);
  4380. break;
  4381. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  4382. _scsih_sas_pd_hide(ioc, element);
  4383. break;
  4384. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  4385. _scsih_sas_pd_expose(ioc, element);
  4386. break;
  4387. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  4388. _scsih_sas_pd_add(ioc, element);
  4389. break;
  4390. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  4391. _scsih_sas_pd_delete(ioc, element);
  4392. break;
  4393. }
  4394. }
  4395. }
  4396. /**
  4397. * _scsih_sas_ir_volume_event - IR volume event
  4398. * @ioc: per adapter object
  4399. * @fw_event: The fw_event_work object
  4400. * Context: user.
  4401. *
  4402. * Return nothing.
  4403. */
  4404. static void
  4405. _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
  4406. struct fw_event_work *fw_event)
  4407. {
  4408. u64 wwid;
  4409. unsigned long flags;
  4410. struct _raid_device *raid_device;
  4411. u16 handle;
  4412. u32 state;
  4413. int rc;
  4414. struct MPT2SAS_TARGET *sas_target_priv_data;
  4415. Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
  4416. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  4417. return;
  4418. handle = le16_to_cpu(event_data->VolDevHandle);
  4419. state = le32_to_cpu(event_data->NewValue);
  4420. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
  4421. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  4422. le32_to_cpu(event_data->PreviousValue), state));
  4423. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4424. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  4425. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4426. switch (state) {
  4427. case MPI2_RAID_VOL_STATE_MISSING:
  4428. case MPI2_RAID_VOL_STATE_FAILED:
  4429. if (!raid_device)
  4430. break;
  4431. if (raid_device->starget) {
  4432. sas_target_priv_data = raid_device->starget->hostdata;
  4433. sas_target_priv_data->deleted = 1;
  4434. scsi_remove_target(&raid_device->starget->dev);
  4435. }
  4436. _scsih_raid_device_remove(ioc, raid_device);
  4437. break;
  4438. case MPI2_RAID_VOL_STATE_ONLINE:
  4439. case MPI2_RAID_VOL_STATE_DEGRADED:
  4440. case MPI2_RAID_VOL_STATE_OPTIMAL:
  4441. if (raid_device)
  4442. break;
  4443. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  4444. if (!wwid) {
  4445. printk(MPT2SAS_ERR_FMT
  4446. "failure at %s:%d/%s()!\n", ioc->name,
  4447. __FILE__, __LINE__, __func__);
  4448. break;
  4449. }
  4450. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  4451. if (!raid_device) {
  4452. printk(MPT2SAS_ERR_FMT
  4453. "failure at %s:%d/%s()!\n", ioc->name,
  4454. __FILE__, __LINE__, __func__);
  4455. break;
  4456. }
  4457. raid_device->id = ioc->sas_id++;
  4458. raid_device->channel = RAID_CHANNEL;
  4459. raid_device->handle = handle;
  4460. raid_device->wwid = wwid;
  4461. _scsih_raid_device_add(ioc, raid_device);
  4462. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  4463. raid_device->id, 0);
  4464. if (rc)
  4465. _scsih_raid_device_remove(ioc, raid_device);
  4466. break;
  4467. case MPI2_RAID_VOL_STATE_INITIALIZING:
  4468. default:
  4469. break;
  4470. }
  4471. }
  4472. /**
  4473. * _scsih_sas_ir_physical_disk_event - PD event
  4474. * @ioc: per adapter object
  4475. * @fw_event: The fw_event_work object
  4476. * Context: user.
  4477. *
  4478. * Return nothing.
  4479. */
  4480. static void
  4481. _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
  4482. struct fw_event_work *fw_event)
  4483. {
  4484. u16 handle, parent_handle;
  4485. u32 state;
  4486. struct _sas_device *sas_device;
  4487. unsigned long flags;
  4488. Mpi2ConfigReply_t mpi_reply;
  4489. Mpi2SasDevicePage0_t sas_device_pg0;
  4490. u32 ioc_status;
  4491. Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
  4492. u64 sas_address;
  4493. if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
  4494. return;
  4495. handle = le16_to_cpu(event_data->PhysDiskDevHandle);
  4496. state = le32_to_cpu(event_data->NewValue);
  4497. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
  4498. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  4499. le32_to_cpu(event_data->PreviousValue), state));
  4500. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4501. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4502. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4503. switch (state) {
  4504. case MPI2_RAID_PD_STATE_ONLINE:
  4505. case MPI2_RAID_PD_STATE_DEGRADED:
  4506. case MPI2_RAID_PD_STATE_REBUILDING:
  4507. case MPI2_RAID_PD_STATE_OPTIMAL:
  4508. if (sas_device) {
  4509. sas_device->hidden_raid_component = 1;
  4510. return;
  4511. }
  4512. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  4513. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  4514. handle))) {
  4515. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4516. ioc->name, __FILE__, __LINE__, __func__);
  4517. return;
  4518. }
  4519. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4520. MPI2_IOCSTATUS_MASK;
  4521. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4522. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4523. ioc->name, __FILE__, __LINE__, __func__);
  4524. return;
  4525. }
  4526. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  4527. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  4528. mpt2sas_transport_update_links(ioc, sas_address, handle,
  4529. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  4530. _scsih_add_device(ioc, handle, 0, 1);
  4531. break;
  4532. case MPI2_RAID_PD_STATE_OFFLINE:
  4533. case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
  4534. case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
  4535. case MPI2_RAID_PD_STATE_HOT_SPARE:
  4536. default:
  4537. break;
  4538. }
  4539. }
  4540. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4541. /**
  4542. * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
  4543. * @ioc: per adapter object
  4544. * @event_data: event data payload
  4545. * Context: user.
  4546. *
  4547. * Return nothing.
  4548. */
  4549. static void
  4550. _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4551. Mpi2EventDataIrOperationStatus_t *event_data)
  4552. {
  4553. char *reason_str = NULL;
  4554. switch (event_data->RAIDOperation) {
  4555. case MPI2_EVENT_IR_RAIDOP_RESYNC:
  4556. reason_str = "resync";
  4557. break;
  4558. case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
  4559. reason_str = "online capacity expansion";
  4560. break;
  4561. case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
  4562. reason_str = "consistency check";
  4563. break;
  4564. default:
  4565. reason_str = "unknown reason";
  4566. break;
  4567. }
  4568. printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
  4569. "\thandle(0x%04x), percent complete(%d)\n",
  4570. ioc->name, reason_str,
  4571. le16_to_cpu(event_data->VolDevHandle),
  4572. event_data->PercentComplete);
  4573. }
  4574. #endif
  4575. /**
  4576. * _scsih_sas_ir_operation_status_event - handle RAID operation events
  4577. * @ioc: per adapter object
  4578. * @fw_event: The fw_event_work object
  4579. * Context: user.
  4580. *
  4581. * Return nothing.
  4582. */
  4583. static void
  4584. _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
  4585. struct fw_event_work *fw_event)
  4586. {
  4587. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4588. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4589. _scsih_sas_ir_operation_status_event_debug(ioc,
  4590. fw_event->event_data);
  4591. #endif
  4592. }
  4593. /**
  4594. * _scsih_task_set_full - handle task set full
  4595. * @ioc: per adapter object
  4596. * @fw_event: The fw_event_work object
  4597. * Context: user.
  4598. *
  4599. * Throttle back qdepth.
  4600. */
  4601. static void
  4602. _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  4603. *fw_event)
  4604. {
  4605. unsigned long flags;
  4606. struct _sas_device *sas_device;
  4607. static struct _raid_device *raid_device;
  4608. struct scsi_device *sdev;
  4609. int depth;
  4610. u16 current_depth;
  4611. u16 handle;
  4612. int id, channel;
  4613. u64 sas_address;
  4614. Mpi2EventDataTaskSetFull_t *event_data = fw_event->event_data;
  4615. current_depth = le16_to_cpu(event_data->CurrentDepth);
  4616. handle = le16_to_cpu(event_data->DevHandle);
  4617. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4618. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4619. if (!sas_device) {
  4620. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4621. return;
  4622. }
  4623. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4624. id = sas_device->id;
  4625. channel = sas_device->channel;
  4626. sas_address = sas_device->sas_address;
  4627. /* if hidden raid component, then change to volume characteristics */
  4628. if (sas_device->hidden_raid_component && sas_device->volume_handle) {
  4629. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4630. raid_device = _scsih_raid_device_find_by_handle(
  4631. ioc, sas_device->volume_handle);
  4632. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4633. if (raid_device) {
  4634. id = raid_device->id;
  4635. channel = raid_device->channel;
  4636. handle = raid_device->handle;
  4637. sas_address = raid_device->wwid;
  4638. }
  4639. }
  4640. if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL)
  4641. starget_printk(KERN_DEBUG, sas_device->starget, "task set "
  4642. "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
  4643. handle, (unsigned long long)sas_address, current_depth);
  4644. shost_for_each_device(sdev, ioc->shost) {
  4645. if (sdev->id == id && sdev->channel == channel) {
  4646. if (current_depth > sdev->queue_depth) {
  4647. if (ioc->logging_level &
  4648. MPT_DEBUG_TASK_SET_FULL)
  4649. sdev_printk(KERN_INFO, sdev, "strange "
  4650. "observation, the queue depth is"
  4651. " (%d) meanwhile fw queue depth "
  4652. "is (%d)\n", sdev->queue_depth,
  4653. current_depth);
  4654. continue;
  4655. }
  4656. depth = scsi_track_queue_full(sdev,
  4657. current_depth - 1);
  4658. if (depth > 0)
  4659. sdev_printk(KERN_INFO, sdev, "Queue depth "
  4660. "reduced to (%d)\n", depth);
  4661. else if (depth < 0)
  4662. sdev_printk(KERN_INFO, sdev, "Tagged Command "
  4663. "Queueing is being disabled\n");
  4664. else if (depth == 0)
  4665. if (ioc->logging_level &
  4666. MPT_DEBUG_TASK_SET_FULL)
  4667. sdev_printk(KERN_INFO, sdev,
  4668. "Queue depth not changed yet\n");
  4669. }
  4670. }
  4671. }
  4672. /**
  4673. * _scsih_mark_responding_sas_device - mark a sas_devices as responding
  4674. * @ioc: per adapter object
  4675. * @sas_address: sas address
  4676. * @slot: enclosure slot id
  4677. * @handle: device handle
  4678. *
  4679. * After host reset, find out whether devices are still responding.
  4680. * Used in _scsi_remove_unresponsive_sas_devices.
  4681. *
  4682. * Return nothing.
  4683. */
  4684. static void
  4685. _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  4686. u16 slot, u16 handle)
  4687. {
  4688. struct MPT2SAS_TARGET *sas_target_priv_data;
  4689. struct scsi_target *starget;
  4690. struct _sas_device *sas_device;
  4691. unsigned long flags;
  4692. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4693. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  4694. if (sas_device->sas_address == sas_address &&
  4695. sas_device->slot == slot && sas_device->starget) {
  4696. sas_device->responding = 1;
  4697. sas_device->state = 0;
  4698. starget = sas_device->starget;
  4699. sas_target_priv_data = starget->hostdata;
  4700. sas_target_priv_data->tm_busy = 0;
  4701. starget_printk(KERN_INFO, sas_device->starget,
  4702. "handle(0x%04x), sas_addr(0x%016llx), enclosure "
  4703. "logical id(0x%016llx), slot(%d)\n", handle,
  4704. (unsigned long long)sas_device->sas_address,
  4705. (unsigned long long)
  4706. sas_device->enclosure_logical_id,
  4707. sas_device->slot);
  4708. if (sas_device->handle == handle)
  4709. goto out;
  4710. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  4711. sas_device->handle);
  4712. sas_device->handle = handle;
  4713. sas_target_priv_data->handle = handle;
  4714. goto out;
  4715. }
  4716. }
  4717. out:
  4718. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4719. }
  4720. /**
  4721. * _scsih_search_responding_sas_devices -
  4722. * @ioc: per adapter object
  4723. *
  4724. * After host reset, find out whether devices are still responding.
  4725. * If not remove.
  4726. *
  4727. * Return nothing.
  4728. */
  4729. static void
  4730. _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
  4731. {
  4732. Mpi2SasDevicePage0_t sas_device_pg0;
  4733. Mpi2ConfigReply_t mpi_reply;
  4734. u16 ioc_status;
  4735. __le64 sas_address;
  4736. u16 handle;
  4737. u32 device_info;
  4738. u16 slot;
  4739. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  4740. if (list_empty(&ioc->sas_device_list))
  4741. return;
  4742. handle = 0xFFFF;
  4743. while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  4744. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  4745. handle))) {
  4746. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4747. MPI2_IOCSTATUS_MASK;
  4748. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  4749. break;
  4750. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  4751. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  4752. if (!(_scsih_is_end_device(device_info)))
  4753. continue;
  4754. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4755. slot = le16_to_cpu(sas_device_pg0.Slot);
  4756. _scsih_mark_responding_sas_device(ioc, sas_address, slot,
  4757. handle);
  4758. }
  4759. }
  4760. /**
  4761. * _scsih_mark_responding_raid_device - mark a raid_device as responding
  4762. * @ioc: per adapter object
  4763. * @wwid: world wide identifier for raid volume
  4764. * @handle: device handle
  4765. *
  4766. * After host reset, find out whether devices are still responding.
  4767. * Used in _scsi_remove_unresponsive_raid_devices.
  4768. *
  4769. * Return nothing.
  4770. */
  4771. static void
  4772. _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
  4773. u16 handle)
  4774. {
  4775. struct MPT2SAS_TARGET *sas_target_priv_data;
  4776. struct scsi_target *starget;
  4777. struct _raid_device *raid_device;
  4778. unsigned long flags;
  4779. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4780. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  4781. if (raid_device->wwid == wwid && raid_device->starget) {
  4782. raid_device->responding = 1;
  4783. starget_printk(KERN_INFO, raid_device->starget,
  4784. "handle(0x%04x), wwid(0x%016llx)\n", handle,
  4785. (unsigned long long)raid_device->wwid);
  4786. if (raid_device->handle == handle)
  4787. goto out;
  4788. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  4789. raid_device->handle);
  4790. raid_device->handle = handle;
  4791. starget = raid_device->starget;
  4792. sas_target_priv_data = starget->hostdata;
  4793. sas_target_priv_data->handle = handle;
  4794. goto out;
  4795. }
  4796. }
  4797. out:
  4798. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4799. }
  4800. /**
  4801. * _scsih_search_responding_raid_devices -
  4802. * @ioc: per adapter object
  4803. *
  4804. * After host reset, find out whether devices are still responding.
  4805. * If not remove.
  4806. *
  4807. * Return nothing.
  4808. */
  4809. static void
  4810. _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
  4811. {
  4812. Mpi2RaidVolPage1_t volume_pg1;
  4813. Mpi2ConfigReply_t mpi_reply;
  4814. u16 ioc_status;
  4815. u16 handle;
  4816. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  4817. if (list_empty(&ioc->raid_device_list))
  4818. return;
  4819. handle = 0xFFFF;
  4820. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  4821. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  4822. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4823. MPI2_IOCSTATUS_MASK;
  4824. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  4825. break;
  4826. handle = le16_to_cpu(volume_pg1.DevHandle);
  4827. _scsih_mark_responding_raid_device(ioc,
  4828. le64_to_cpu(volume_pg1.WWID), handle);
  4829. }
  4830. }
  4831. /**
  4832. * _scsih_mark_responding_expander - mark a expander as responding
  4833. * @ioc: per adapter object
  4834. * @sas_address: sas address
  4835. * @handle:
  4836. *
  4837. * After host reset, find out whether devices are still responding.
  4838. * Used in _scsi_remove_unresponsive_expanders.
  4839. *
  4840. * Return nothing.
  4841. */
  4842. static void
  4843. _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  4844. u16 handle)
  4845. {
  4846. struct _sas_node *sas_expander;
  4847. unsigned long flags;
  4848. int i;
  4849. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4850. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  4851. if (sas_expander->sas_address != sas_address)
  4852. continue;
  4853. sas_expander->responding = 1;
  4854. if (sas_expander->handle == handle)
  4855. goto out;
  4856. printk(KERN_INFO "\texpander(0x%016llx): handle changed"
  4857. " from(0x%04x) to (0x%04x)!!!\n",
  4858. (unsigned long long)sas_expander->sas_address,
  4859. sas_expander->handle, handle);
  4860. sas_expander->handle = handle;
  4861. for (i = 0 ; i < sas_expander->num_phys ; i++)
  4862. sas_expander->phy[i].handle = handle;
  4863. goto out;
  4864. }
  4865. out:
  4866. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4867. }
  4868. /**
  4869. * _scsih_search_responding_expanders -
  4870. * @ioc: per adapter object
  4871. *
  4872. * After host reset, find out whether devices are still responding.
  4873. * If not remove.
  4874. *
  4875. * Return nothing.
  4876. */
  4877. static void
  4878. _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
  4879. {
  4880. Mpi2ExpanderPage0_t expander_pg0;
  4881. Mpi2ConfigReply_t mpi_reply;
  4882. u16 ioc_status;
  4883. __le64 sas_address;
  4884. u16 handle;
  4885. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  4886. if (list_empty(&ioc->sas_expander_list))
  4887. return;
  4888. handle = 0xFFFF;
  4889. while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  4890. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  4891. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4892. MPI2_IOCSTATUS_MASK;
  4893. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  4894. break;
  4895. handle = le16_to_cpu(expander_pg0.DevHandle);
  4896. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  4897. printk(KERN_INFO "\texpander present: handle(0x%04x), "
  4898. "sas_addr(0x%016llx)\n", handle,
  4899. (unsigned long long)sas_address);
  4900. _scsih_mark_responding_expander(ioc, sas_address, handle);
  4901. }
  4902. }
  4903. /**
  4904. * _scsih_remove_unresponding_devices - removing unresponding devices
  4905. * @ioc: per adapter object
  4906. *
  4907. * Return nothing.
  4908. */
  4909. static void
  4910. _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc)
  4911. {
  4912. struct _sas_device *sas_device, *sas_device_next;
  4913. struct _sas_node *sas_expander;
  4914. struct _raid_device *raid_device, *raid_device_next;
  4915. list_for_each_entry_safe(sas_device, sas_device_next,
  4916. &ioc->sas_device_list, list) {
  4917. if (sas_device->responding) {
  4918. sas_device->responding = 0;
  4919. continue;
  4920. }
  4921. if (sas_device->starget)
  4922. starget_printk(KERN_INFO, sas_device->starget,
  4923. "removing: handle(0x%04x), sas_addr(0x%016llx), "
  4924. "enclosure logical id(0x%016llx), slot(%d)\n",
  4925. sas_device->handle,
  4926. (unsigned long long)sas_device->sas_address,
  4927. (unsigned long long)
  4928. sas_device->enclosure_logical_id,
  4929. sas_device->slot);
  4930. /* invalidate the device handle */
  4931. sas_device->handle = 0;
  4932. _scsih_remove_device(ioc, sas_device);
  4933. }
  4934. list_for_each_entry_safe(raid_device, raid_device_next,
  4935. &ioc->raid_device_list, list) {
  4936. if (raid_device->responding) {
  4937. raid_device->responding = 0;
  4938. continue;
  4939. }
  4940. if (raid_device->starget) {
  4941. starget_printk(KERN_INFO, raid_device->starget,
  4942. "removing: handle(0x%04x), wwid(0x%016llx)\n",
  4943. raid_device->handle,
  4944. (unsigned long long)raid_device->wwid);
  4945. scsi_remove_target(&raid_device->starget->dev);
  4946. }
  4947. _scsih_raid_device_remove(ioc, raid_device);
  4948. }
  4949. retry_expander_search:
  4950. sas_expander = NULL;
  4951. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  4952. if (sas_expander->responding) {
  4953. sas_expander->responding = 0;
  4954. continue;
  4955. }
  4956. _scsih_expander_remove(ioc, sas_expander->sas_address);
  4957. goto retry_expander_search;
  4958. }
  4959. }
  4960. /**
  4961. * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
  4962. * @ioc: per adapter object
  4963. * @reset_phase: phase
  4964. *
  4965. * The handler for doing any required cleanup or initialization.
  4966. *
  4967. * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
  4968. * MPT2_IOC_DONE_RESET
  4969. *
  4970. * Return nothing.
  4971. */
  4972. void
  4973. mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
  4974. {
  4975. switch (reset_phase) {
  4976. case MPT2_IOC_PRE_RESET:
  4977. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  4978. "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
  4979. _scsih_fw_event_off(ioc);
  4980. break;
  4981. case MPT2_IOC_AFTER_RESET:
  4982. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  4983. "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
  4984. if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
  4985. ioc->tm_cmds.status |= MPT2_CMD_RESET;
  4986. mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
  4987. complete(&ioc->tm_cmds.done);
  4988. }
  4989. _scsih_fw_event_on(ioc);
  4990. _scsih_flush_running_cmds(ioc);
  4991. break;
  4992. case MPT2_IOC_DONE_RESET:
  4993. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  4994. "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
  4995. _scsih_sas_host_refresh(ioc);
  4996. _scsih_search_responding_sas_devices(ioc);
  4997. _scsih_search_responding_raid_devices(ioc);
  4998. _scsih_search_responding_expanders(ioc);
  4999. break;
  5000. case MPT2_IOC_RUNNING:
  5001. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  5002. "MPT2_IOC_RUNNING\n", ioc->name, __func__));
  5003. _scsih_remove_unresponding_devices(ioc);
  5004. break;
  5005. }
  5006. }
  5007. /**
  5008. * _firmware_event_work - delayed task for processing firmware events
  5009. * @ioc: per adapter object
  5010. * @work: equal to the fw_event_work object
  5011. * Context: user.
  5012. *
  5013. * Return nothing.
  5014. */
  5015. static void
  5016. _firmware_event_work(struct work_struct *work)
  5017. {
  5018. struct fw_event_work *fw_event = container_of(work,
  5019. struct fw_event_work, work);
  5020. unsigned long flags;
  5021. struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
  5022. /* the queue is being flushed so ignore this event */
  5023. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5024. if (ioc->fw_events_off || ioc->remove_host) {
  5025. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5026. _scsih_fw_event_free(ioc, fw_event);
  5027. return;
  5028. }
  5029. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5030. if (ioc->shost_recovery) {
  5031. _scsih_fw_event_requeue(ioc, fw_event, 1000);
  5032. return;
  5033. }
  5034. switch (fw_event->event) {
  5035. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  5036. _scsih_sas_topology_change_event(ioc, fw_event);
  5037. break;
  5038. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5039. _scsih_sas_device_status_change_event(ioc,
  5040. fw_event);
  5041. break;
  5042. case MPI2_EVENT_SAS_DISCOVERY:
  5043. _scsih_sas_discovery_event(ioc,
  5044. fw_event);
  5045. break;
  5046. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  5047. _scsih_sas_broadcast_primative_event(ioc,
  5048. fw_event);
  5049. break;
  5050. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  5051. _scsih_sas_enclosure_dev_status_change_event(ioc,
  5052. fw_event);
  5053. break;
  5054. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  5055. _scsih_sas_ir_config_change_event(ioc, fw_event);
  5056. break;
  5057. case MPI2_EVENT_IR_VOLUME:
  5058. _scsih_sas_ir_volume_event(ioc, fw_event);
  5059. break;
  5060. case MPI2_EVENT_IR_PHYSICAL_DISK:
  5061. _scsih_sas_ir_physical_disk_event(ioc, fw_event);
  5062. break;
  5063. case MPI2_EVENT_IR_OPERATION_STATUS:
  5064. _scsih_sas_ir_operation_status_event(ioc, fw_event);
  5065. break;
  5066. case MPI2_EVENT_TASK_SET_FULL:
  5067. _scsih_task_set_full(ioc, fw_event);
  5068. break;
  5069. }
  5070. _scsih_fw_event_free(ioc, fw_event);
  5071. }
  5072. /**
  5073. * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
  5074. * @ioc: per adapter object
  5075. * @msix_index: MSIX table index supplied by the OS
  5076. * @reply: reply message frame(lower 32bit addr)
  5077. * Context: interrupt.
  5078. *
  5079. * This function merely adds a new work task into ioc->firmware_event_thread.
  5080. * The tasks are worked from _firmware_event_work in user context.
  5081. *
  5082. * Return 1 meaning mf should be freed from _base_interrupt
  5083. * 0 means the mf is freed from this function.
  5084. */
  5085. u8
  5086. mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
  5087. u32 reply)
  5088. {
  5089. struct fw_event_work *fw_event;
  5090. Mpi2EventNotificationReply_t *mpi_reply;
  5091. unsigned long flags;
  5092. u16 event;
  5093. /* events turned off due to host reset or driver unloading */
  5094. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5095. if (ioc->fw_events_off || ioc->remove_host) {
  5096. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5097. return 1;
  5098. }
  5099. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5100. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  5101. event = le16_to_cpu(mpi_reply->Event);
  5102. switch (event) {
  5103. /* handle these */
  5104. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  5105. {
  5106. Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
  5107. (Mpi2EventDataSasBroadcastPrimitive_t *)
  5108. mpi_reply->EventData;
  5109. if (baen_data->Primitive !=
  5110. MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
  5111. ioc->broadcast_aen_busy)
  5112. return 1;
  5113. ioc->broadcast_aen_busy = 1;
  5114. break;
  5115. }
  5116. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  5117. _scsih_check_topo_delete_events(ioc,
  5118. (Mpi2EventDataSasTopologyChangeList_t *)
  5119. mpi_reply->EventData);
  5120. break;
  5121. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5122. case MPI2_EVENT_IR_OPERATION_STATUS:
  5123. case MPI2_EVENT_SAS_DISCOVERY:
  5124. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  5125. case MPI2_EVENT_IR_VOLUME:
  5126. case MPI2_EVENT_IR_PHYSICAL_DISK:
  5127. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  5128. case MPI2_EVENT_TASK_SET_FULL:
  5129. break;
  5130. default: /* ignore the rest */
  5131. return 1;
  5132. }
  5133. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  5134. if (!fw_event) {
  5135. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5136. ioc->name, __FILE__, __LINE__, __func__);
  5137. return 1;
  5138. }
  5139. fw_event->event_data =
  5140. kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC);
  5141. if (!fw_event->event_data) {
  5142. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5143. ioc->name, __FILE__, __LINE__, __func__);
  5144. kfree(fw_event);
  5145. return 1;
  5146. }
  5147. memcpy(fw_event->event_data, mpi_reply->EventData,
  5148. mpi_reply->EventDataLength*4);
  5149. fw_event->ioc = ioc;
  5150. fw_event->VF_ID = mpi_reply->VF_ID;
  5151. fw_event->VP_ID = mpi_reply->VP_ID;
  5152. fw_event->event = event;
  5153. _scsih_fw_event_add(ioc, fw_event);
  5154. return 1;
  5155. }
  5156. /* shost template */
  5157. static struct scsi_host_template scsih_driver_template = {
  5158. .module = THIS_MODULE,
  5159. .name = "Fusion MPT SAS Host",
  5160. .proc_name = MPT2SAS_DRIVER_NAME,
  5161. .queuecommand = _scsih_qcmd,
  5162. .target_alloc = _scsih_target_alloc,
  5163. .slave_alloc = _scsih_slave_alloc,
  5164. .slave_configure = _scsih_slave_configure,
  5165. .target_destroy = _scsih_target_destroy,
  5166. .slave_destroy = _scsih_slave_destroy,
  5167. .change_queue_depth = _scsih_change_queue_depth,
  5168. .change_queue_type = _scsih_change_queue_type,
  5169. .eh_abort_handler = _scsih_abort,
  5170. .eh_device_reset_handler = _scsih_dev_reset,
  5171. .eh_target_reset_handler = _scsih_target_reset,
  5172. .eh_host_reset_handler = _scsih_host_reset,
  5173. .bios_param = _scsih_bios_param,
  5174. .can_queue = 1,
  5175. .this_id = -1,
  5176. .sg_tablesize = MPT2SAS_SG_DEPTH,
  5177. .max_sectors = 8192,
  5178. .cmd_per_lun = 7,
  5179. .use_clustering = ENABLE_CLUSTERING,
  5180. .shost_attrs = mpt2sas_host_attrs,
  5181. .sdev_attrs = mpt2sas_dev_attrs,
  5182. };
  5183. /**
  5184. * _scsih_expander_node_remove - removing expander device from list.
  5185. * @ioc: per adapter object
  5186. * @sas_expander: the sas_device object
  5187. * Context: Calling function should acquire ioc->sas_node_lock.
  5188. *
  5189. * Removing object and freeing associated memory from the
  5190. * ioc->sas_expander_list.
  5191. *
  5192. * Return nothing.
  5193. */
  5194. static void
  5195. _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  5196. struct _sas_node *sas_expander)
  5197. {
  5198. struct _sas_port *mpt2sas_port;
  5199. struct _sas_device *sas_device;
  5200. struct _sas_node *expander_sibling;
  5201. unsigned long flags;
  5202. if (!sas_expander)
  5203. return;
  5204. /* remove sibling ports attached to this expander */
  5205. retry_device_search:
  5206. list_for_each_entry(mpt2sas_port,
  5207. &sas_expander->sas_port_list, port_list) {
  5208. if (mpt2sas_port->remote_identify.device_type ==
  5209. SAS_END_DEVICE) {
  5210. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5211. sas_device =
  5212. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  5213. mpt2sas_port->remote_identify.sas_address);
  5214. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5215. if (!sas_device)
  5216. continue;
  5217. _scsih_remove_device(ioc, sas_device);
  5218. if (ioc->shost_recovery)
  5219. return;
  5220. goto retry_device_search;
  5221. }
  5222. }
  5223. retry_expander_search:
  5224. list_for_each_entry(mpt2sas_port,
  5225. &sas_expander->sas_port_list, port_list) {
  5226. if (mpt2sas_port->remote_identify.device_type ==
  5227. MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  5228. mpt2sas_port->remote_identify.device_type ==
  5229. MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
  5230. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5231. expander_sibling =
  5232. mpt2sas_scsih_expander_find_by_sas_address(
  5233. ioc, mpt2sas_port->remote_identify.sas_address);
  5234. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5235. if (!expander_sibling)
  5236. continue;
  5237. _scsih_expander_remove(ioc,
  5238. expander_sibling->sas_address);
  5239. if (ioc->shost_recovery)
  5240. return;
  5241. goto retry_expander_search;
  5242. }
  5243. }
  5244. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  5245. sas_expander->sas_address_parent);
  5246. printk(MPT2SAS_INFO_FMT "expander_remove: handle"
  5247. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  5248. sas_expander->handle, (unsigned long long)
  5249. sas_expander->sas_address);
  5250. list_del(&sas_expander->list);
  5251. kfree(sas_expander->phy);
  5252. kfree(sas_expander);
  5253. }
  5254. /**
  5255. * _scsih_remove - detach and remove add host
  5256. * @pdev: PCI device struct
  5257. *
  5258. * Return nothing.
  5259. */
  5260. static void __devexit
  5261. _scsih_remove(struct pci_dev *pdev)
  5262. {
  5263. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5264. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5265. struct _sas_port *mpt2sas_port;
  5266. struct _sas_device *sas_device;
  5267. struct _sas_node *expander_sibling;
  5268. struct workqueue_struct *wq;
  5269. unsigned long flags;
  5270. ioc->remove_host = 1;
  5271. _scsih_fw_event_off(ioc);
  5272. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5273. wq = ioc->firmware_event_thread;
  5274. ioc->firmware_event_thread = NULL;
  5275. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5276. if (wq)
  5277. destroy_workqueue(wq);
  5278. /* free ports attached to the sas_host */
  5279. retry_again:
  5280. list_for_each_entry(mpt2sas_port,
  5281. &ioc->sas_hba.sas_port_list, port_list) {
  5282. if (mpt2sas_port->remote_identify.device_type ==
  5283. SAS_END_DEVICE) {
  5284. sas_device =
  5285. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  5286. mpt2sas_port->remote_identify.sas_address);
  5287. if (sas_device) {
  5288. _scsih_remove_device(ioc, sas_device);
  5289. goto retry_again;
  5290. }
  5291. } else {
  5292. expander_sibling =
  5293. mpt2sas_scsih_expander_find_by_sas_address(ioc,
  5294. mpt2sas_port->remote_identify.sas_address);
  5295. if (expander_sibling) {
  5296. _scsih_expander_remove(ioc,
  5297. expander_sibling->sas_address);
  5298. goto retry_again;
  5299. }
  5300. }
  5301. }
  5302. /* free phys attached to the sas_host */
  5303. if (ioc->sas_hba.num_phys) {
  5304. kfree(ioc->sas_hba.phy);
  5305. ioc->sas_hba.phy = NULL;
  5306. ioc->sas_hba.num_phys = 0;
  5307. }
  5308. sas_remove_host(shost);
  5309. mpt2sas_base_detach(ioc);
  5310. list_del(&ioc->list);
  5311. scsi_remove_host(shost);
  5312. scsi_host_put(shost);
  5313. }
  5314. /**
  5315. * _scsih_probe_boot_devices - reports 1st device
  5316. * @ioc: per adapter object
  5317. *
  5318. * If specified in bios page 2, this routine reports the 1st
  5319. * device scsi-ml or sas transport for persistent boot device
  5320. * purposes. Please refer to function _scsih_determine_boot_device()
  5321. */
  5322. static void
  5323. _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
  5324. {
  5325. u8 is_raid;
  5326. void *device;
  5327. struct _sas_device *sas_device;
  5328. struct _raid_device *raid_device;
  5329. u16 handle;
  5330. u64 sas_address_parent;
  5331. u64 sas_address;
  5332. unsigned long flags;
  5333. int rc;
  5334. device = NULL;
  5335. if (ioc->req_boot_device.device) {
  5336. device = ioc->req_boot_device.device;
  5337. is_raid = ioc->req_boot_device.is_raid;
  5338. } else if (ioc->req_alt_boot_device.device) {
  5339. device = ioc->req_alt_boot_device.device;
  5340. is_raid = ioc->req_alt_boot_device.is_raid;
  5341. } else if (ioc->current_boot_device.device) {
  5342. device = ioc->current_boot_device.device;
  5343. is_raid = ioc->current_boot_device.is_raid;
  5344. }
  5345. if (!device)
  5346. return;
  5347. if (is_raid) {
  5348. raid_device = device;
  5349. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5350. raid_device->id, 0);
  5351. if (rc)
  5352. _scsih_raid_device_remove(ioc, raid_device);
  5353. } else {
  5354. sas_device = device;
  5355. handle = sas_device->handle;
  5356. sas_address_parent = sas_device->sas_address_parent;
  5357. sas_address = sas_device->sas_address;
  5358. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5359. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  5360. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5361. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  5362. sas_device->sas_address_parent)) {
  5363. _scsih_sas_device_remove(ioc, sas_device);
  5364. } else if (!sas_device->starget) {
  5365. mpt2sas_transport_port_remove(ioc, sas_address,
  5366. sas_address_parent);
  5367. _scsih_sas_device_remove(ioc, sas_device);
  5368. }
  5369. }
  5370. }
  5371. /**
  5372. * _scsih_probe_raid - reporting raid volumes to scsi-ml
  5373. * @ioc: per adapter object
  5374. *
  5375. * Called during initial loading of the driver.
  5376. */
  5377. static void
  5378. _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
  5379. {
  5380. struct _raid_device *raid_device, *raid_next;
  5381. int rc;
  5382. list_for_each_entry_safe(raid_device, raid_next,
  5383. &ioc->raid_device_list, list) {
  5384. if (raid_device->starget)
  5385. continue;
  5386. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5387. raid_device->id, 0);
  5388. if (rc)
  5389. _scsih_raid_device_remove(ioc, raid_device);
  5390. }
  5391. }
  5392. /**
  5393. * _scsih_probe_sas - reporting sas devices to sas transport
  5394. * @ioc: per adapter object
  5395. *
  5396. * Called during initial loading of the driver.
  5397. */
  5398. static void
  5399. _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
  5400. {
  5401. struct _sas_device *sas_device, *next;
  5402. unsigned long flags;
  5403. /* SAS Device List */
  5404. list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
  5405. list) {
  5406. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5407. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  5408. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5409. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  5410. sas_device->sas_address_parent)) {
  5411. _scsih_sas_device_remove(ioc, sas_device);
  5412. } else if (!sas_device->starget) {
  5413. mpt2sas_transport_port_remove(ioc,
  5414. sas_device->sas_address,
  5415. sas_device->sas_address_parent);
  5416. _scsih_sas_device_remove(ioc, sas_device);
  5417. }
  5418. }
  5419. }
  5420. /**
  5421. * _scsih_probe_devices - probing for devices
  5422. * @ioc: per adapter object
  5423. *
  5424. * Called during initial loading of the driver.
  5425. */
  5426. static void
  5427. _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
  5428. {
  5429. u16 volume_mapping_flags =
  5430. le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
  5431. MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
  5432. if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
  5433. return; /* return when IOC doesn't support initiator mode */
  5434. _scsih_probe_boot_devices(ioc);
  5435. if (ioc->ir_firmware) {
  5436. if ((volume_mapping_flags &
  5437. MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
  5438. _scsih_probe_sas(ioc);
  5439. _scsih_probe_raid(ioc);
  5440. } else {
  5441. _scsih_probe_raid(ioc);
  5442. _scsih_probe_sas(ioc);
  5443. }
  5444. } else
  5445. _scsih_probe_sas(ioc);
  5446. }
  5447. /**
  5448. * _scsih_probe - attach and add scsi host
  5449. * @pdev: PCI device struct
  5450. * @id: pci device id
  5451. *
  5452. * Returns 0 success, anything else error.
  5453. */
  5454. static int
  5455. _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  5456. {
  5457. struct MPT2SAS_ADAPTER *ioc;
  5458. struct Scsi_Host *shost;
  5459. shost = scsi_host_alloc(&scsih_driver_template,
  5460. sizeof(struct MPT2SAS_ADAPTER));
  5461. if (!shost)
  5462. return -ENODEV;
  5463. /* init local params */
  5464. ioc = shost_priv(shost);
  5465. memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
  5466. INIT_LIST_HEAD(&ioc->list);
  5467. list_add_tail(&ioc->list, &mpt2sas_ioc_list);
  5468. ioc->shost = shost;
  5469. ioc->id = mpt_ids++;
  5470. sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
  5471. ioc->pdev = pdev;
  5472. ioc->scsi_io_cb_idx = scsi_io_cb_idx;
  5473. ioc->tm_cb_idx = tm_cb_idx;
  5474. ioc->ctl_cb_idx = ctl_cb_idx;
  5475. ioc->base_cb_idx = base_cb_idx;
  5476. ioc->transport_cb_idx = transport_cb_idx;
  5477. ioc->config_cb_idx = config_cb_idx;
  5478. ioc->tm_tr_cb_idx = tm_tr_cb_idx;
  5479. ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
  5480. ioc->logging_level = logging_level;
  5481. /* misc semaphores and spin locks */
  5482. spin_lock_init(&ioc->ioc_reset_in_progress_lock);
  5483. spin_lock_init(&ioc->scsi_lookup_lock);
  5484. spin_lock_init(&ioc->sas_device_lock);
  5485. spin_lock_init(&ioc->sas_node_lock);
  5486. spin_lock_init(&ioc->fw_event_lock);
  5487. spin_lock_init(&ioc->raid_device_lock);
  5488. INIT_LIST_HEAD(&ioc->sas_device_list);
  5489. INIT_LIST_HEAD(&ioc->sas_device_init_list);
  5490. INIT_LIST_HEAD(&ioc->sas_expander_list);
  5491. INIT_LIST_HEAD(&ioc->fw_event_list);
  5492. INIT_LIST_HEAD(&ioc->raid_device_list);
  5493. INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
  5494. INIT_LIST_HEAD(&ioc->delayed_tr_list);
  5495. /* init shost parameters */
  5496. shost->max_cmd_len = 16;
  5497. shost->max_lun = max_lun;
  5498. shost->transportt = mpt2sas_transport_template;
  5499. shost->unique_id = ioc->id;
  5500. if ((scsi_add_host(shost, &pdev->dev))) {
  5501. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5502. ioc->name, __FILE__, __LINE__, __func__);
  5503. list_del(&ioc->list);
  5504. goto out_add_shost_fail;
  5505. }
  5506. scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
  5507. | SHOST_DIF_TYPE3_PROTECTION);
  5508. scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
  5509. /* event thread */
  5510. snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
  5511. "fw_event%d", ioc->id);
  5512. ioc->firmware_event_thread = create_singlethread_workqueue(
  5513. ioc->firmware_event_name);
  5514. if (!ioc->firmware_event_thread) {
  5515. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5516. ioc->name, __FILE__, __LINE__, __func__);
  5517. goto out_thread_fail;
  5518. }
  5519. ioc->wait_for_port_enable_to_complete = 1;
  5520. if ((mpt2sas_base_attach(ioc))) {
  5521. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5522. ioc->name, __FILE__, __LINE__, __func__);
  5523. goto out_attach_fail;
  5524. }
  5525. ioc->wait_for_port_enable_to_complete = 0;
  5526. _scsih_probe_devices(ioc);
  5527. return 0;
  5528. out_attach_fail:
  5529. destroy_workqueue(ioc->firmware_event_thread);
  5530. out_thread_fail:
  5531. list_del(&ioc->list);
  5532. scsi_remove_host(shost);
  5533. out_add_shost_fail:
  5534. return -ENODEV;
  5535. }
  5536. #ifdef CONFIG_PM
  5537. /**
  5538. * _scsih_suspend - power management suspend main entry point
  5539. * @pdev: PCI device struct
  5540. * @state: PM state change to (usually PCI_D3)
  5541. *
  5542. * Returns 0 success, anything else error.
  5543. */
  5544. static int
  5545. _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
  5546. {
  5547. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5548. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5549. u32 device_state;
  5550. mpt2sas_base_stop_watchdog(ioc);
  5551. flush_scheduled_work();
  5552. scsi_block_requests(shost);
  5553. device_state = pci_choose_state(pdev, state);
  5554. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
  5555. "operating state [D%d]\n", ioc->name, pdev,
  5556. pci_name(pdev), device_state);
  5557. mpt2sas_base_free_resources(ioc);
  5558. pci_save_state(pdev);
  5559. pci_disable_device(pdev);
  5560. pci_set_power_state(pdev, device_state);
  5561. return 0;
  5562. }
  5563. /**
  5564. * _scsih_resume - power management resume main entry point
  5565. * @pdev: PCI device struct
  5566. *
  5567. * Returns 0 success, anything else error.
  5568. */
  5569. static int
  5570. _scsih_resume(struct pci_dev *pdev)
  5571. {
  5572. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5573. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5574. u32 device_state = pdev->current_state;
  5575. int r;
  5576. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
  5577. "operating state [D%d]\n", ioc->name, pdev,
  5578. pci_name(pdev), device_state);
  5579. pci_set_power_state(pdev, PCI_D0);
  5580. pci_enable_wake(pdev, PCI_D0, 0);
  5581. pci_restore_state(pdev);
  5582. ioc->pdev = pdev;
  5583. r = mpt2sas_base_map_resources(ioc);
  5584. if (r)
  5585. return r;
  5586. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
  5587. scsi_unblock_requests(shost);
  5588. mpt2sas_base_start_watchdog(ioc);
  5589. return 0;
  5590. }
  5591. #endif /* CONFIG_PM */
  5592. static struct pci_driver scsih_driver = {
  5593. .name = MPT2SAS_DRIVER_NAME,
  5594. .id_table = scsih_pci_table,
  5595. .probe = _scsih_probe,
  5596. .remove = __devexit_p(_scsih_remove),
  5597. #ifdef CONFIG_PM
  5598. .suspend = _scsih_suspend,
  5599. .resume = _scsih_resume,
  5600. #endif
  5601. };
  5602. /**
  5603. * _scsih_init - main entry point for this driver.
  5604. *
  5605. * Returns 0 success, anything else error.
  5606. */
  5607. static int __init
  5608. _scsih_init(void)
  5609. {
  5610. int error;
  5611. mpt_ids = 0;
  5612. printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
  5613. MPT2SAS_DRIVER_VERSION);
  5614. mpt2sas_transport_template =
  5615. sas_attach_transport(&mpt2sas_transport_functions);
  5616. if (!mpt2sas_transport_template)
  5617. return -ENODEV;
  5618. mpt2sas_base_initialize_callback_handler();
  5619. /* queuecommand callback hander */
  5620. scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
  5621. /* task managment callback handler */
  5622. tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
  5623. /* base internal commands callback handler */
  5624. base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
  5625. /* transport internal commands callback handler */
  5626. transport_cb_idx = mpt2sas_base_register_callback_handler(
  5627. mpt2sas_transport_done);
  5628. /* configuration page API internal commands callback handler */
  5629. config_cb_idx = mpt2sas_base_register_callback_handler(
  5630. mpt2sas_config_done);
  5631. /* ctl module callback handler */
  5632. ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
  5633. tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
  5634. _scsih_tm_tr_complete);
  5635. tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
  5636. _scsih_sas_control_complete);
  5637. mpt2sas_ctl_init();
  5638. error = pci_register_driver(&scsih_driver);
  5639. if (error)
  5640. sas_release_transport(mpt2sas_transport_template);
  5641. return error;
  5642. }
  5643. /**
  5644. * _scsih_exit - exit point for this driver (when it is a module).
  5645. *
  5646. * Returns 0 success, anything else error.
  5647. */
  5648. static void __exit
  5649. _scsih_exit(void)
  5650. {
  5651. printk(KERN_INFO "mpt2sas version %s unloading\n",
  5652. MPT2SAS_DRIVER_VERSION);
  5653. pci_unregister_driver(&scsih_driver);
  5654. sas_release_transport(mpt2sas_transport_template);
  5655. mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
  5656. mpt2sas_base_release_callback_handler(tm_cb_idx);
  5657. mpt2sas_base_release_callback_handler(base_cb_idx);
  5658. mpt2sas_base_release_callback_handler(transport_cb_idx);
  5659. mpt2sas_base_release_callback_handler(config_cb_idx);
  5660. mpt2sas_base_release_callback_handler(ctl_cb_idx);
  5661. mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
  5662. mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
  5663. mpt2sas_ctl_exit();
  5664. }
  5665. module_init(_scsih_init);
  5666. module_exit(_scsih_exit);