mpt2sas_scsih.c 234 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247
  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-2010 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/module.h>
  42. #include <linux/kernel.h>
  43. #include <linux/init.h>
  44. #include <linux/errno.h>
  45. #include <linux/blkdev.h>
  46. #include <linux/sched.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/delay.h>
  49. #include <linux/pci.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/aer.h>
  52. #include <linux/raid_class.h>
  53. #include <linux/slab.h>
  54. #include "mpt2sas_base.h"
  55. MODULE_AUTHOR(MPT2SAS_AUTHOR);
  56. MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
  57. MODULE_LICENSE("GPL");
  58. MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
  59. #define RAID_CHANNEL 1
  60. /* forward proto's */
  61. static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  62. struct _sas_node *sas_expander);
  63. static void _firmware_event_work(struct work_struct *work);
  64. static u8 _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid);
  65. static void _scsih_scan_start(struct Scsi_Host *shost);
  66. static int _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time);
  67. /* global parameters */
  68. LIST_HEAD(mpt2sas_ioc_list);
  69. /* local parameters */
  70. static u8 scsi_io_cb_idx = -1;
  71. static u8 tm_cb_idx = -1;
  72. static u8 ctl_cb_idx = -1;
  73. static u8 base_cb_idx = -1;
  74. static u8 port_enable_cb_idx = -1;
  75. static u8 transport_cb_idx = -1;
  76. static u8 scsih_cb_idx = -1;
  77. static u8 config_cb_idx = -1;
  78. static int mpt_ids;
  79. static u8 tm_tr_cb_idx = -1 ;
  80. static u8 tm_tr_volume_cb_idx = -1 ;
  81. static u8 tm_sas_control_cb_idx = -1;
  82. /* command line options */
  83. static u32 logging_level;
  84. MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
  85. "(default=0)");
  86. static ushort max_sectors = 0xFFFF;
  87. module_param(max_sectors, ushort, 0);
  88. MODULE_PARM_DESC(max_sectors, "max sectors, range 64 to 8192 default=8192");
  89. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  90. #define MPT2SAS_MAX_LUN (16895)
  91. static int max_lun = MPT2SAS_MAX_LUN;
  92. module_param(max_lun, int, 0);
  93. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  94. /* diag_buffer_enable is bitwise
  95. * bit 0 set = TRACE
  96. * bit 1 set = SNAPSHOT
  97. * bit 2 set = EXTENDED
  98. *
  99. * Either bit can be set, or both
  100. */
  101. static int diag_buffer_enable = -1;
  102. module_param(diag_buffer_enable, int, 0);
  103. MODULE_PARM_DESC(diag_buffer_enable, " post diag buffers "
  104. "(TRACE=1/SNAPSHOT=2/EXTENDED=4/default=0)");
  105. /**
  106. * struct sense_info - common structure for obtaining sense keys
  107. * @skey: sense key
  108. * @asc: additional sense code
  109. * @ascq: additional sense code qualifier
  110. */
  111. struct sense_info {
  112. u8 skey;
  113. u8 asc;
  114. u8 ascq;
  115. };
  116. #define MPT2SAS_TURN_ON_FAULT_LED (0xFFFC)
  117. #define MPT2SAS_PORT_ENABLE_COMPLETE (0xFFFD)
  118. #define MPT2SAS_REMOVE_UNRESPONDING_DEVICES (0xFFFF)
  119. /**
  120. * struct fw_event_work - firmware event struct
  121. * @list: link list framework
  122. * @work: work object (ioc->fault_reset_work_q)
  123. * @cancel_pending_work: flag set during reset handling
  124. * @ioc: per adapter object
  125. * @device_handle: device handle
  126. * @VF_ID: virtual function id
  127. * @VP_ID: virtual port id
  128. * @ignore: flag meaning this event has been marked to ignore
  129. * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
  130. * @event_data: reply event data payload follows
  131. *
  132. * This object stored on ioc->fw_event_list.
  133. */
  134. struct fw_event_work {
  135. struct list_head list;
  136. u8 cancel_pending_work;
  137. struct delayed_work delayed_work;
  138. struct MPT2SAS_ADAPTER *ioc;
  139. u16 device_handle;
  140. u8 VF_ID;
  141. u8 VP_ID;
  142. u8 ignore;
  143. u16 event;
  144. void *event_data;
  145. };
  146. /* raid transport support */
  147. static struct raid_template *mpt2sas_raid_template;
  148. /**
  149. * struct _scsi_io_transfer - scsi io transfer
  150. * @handle: sas device handle (assigned by firmware)
  151. * @is_raid: flag set for hidden raid components
  152. * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
  153. * @data_length: data transfer length
  154. * @data_dma: dma pointer to data
  155. * @sense: sense data
  156. * @lun: lun number
  157. * @cdb_length: cdb length
  158. * @cdb: cdb contents
  159. * @timeout: timeout for this command
  160. * @VF_ID: virtual function id
  161. * @VP_ID: virtual port id
  162. * @valid_reply: flag set for reply message
  163. * @sense_length: sense length
  164. * @ioc_status: ioc status
  165. * @scsi_state: scsi state
  166. * @scsi_status: scsi staus
  167. * @log_info: log information
  168. * @transfer_length: data length transfer when there is a reply message
  169. *
  170. * Used for sending internal scsi commands to devices within this module.
  171. * Refer to _scsi_send_scsi_io().
  172. */
  173. struct _scsi_io_transfer {
  174. u16 handle;
  175. u8 is_raid;
  176. enum dma_data_direction dir;
  177. u32 data_length;
  178. dma_addr_t data_dma;
  179. u8 sense[SCSI_SENSE_BUFFERSIZE];
  180. u32 lun;
  181. u8 cdb_length;
  182. u8 cdb[32];
  183. u8 timeout;
  184. u8 VF_ID;
  185. u8 VP_ID;
  186. u8 valid_reply;
  187. /* the following bits are only valid when 'valid_reply = 1' */
  188. u32 sense_length;
  189. u16 ioc_status;
  190. u8 scsi_state;
  191. u8 scsi_status;
  192. u32 log_info;
  193. u32 transfer_length;
  194. };
  195. /*
  196. * The pci device ids are defined in mpi/mpi2_cnfg.h.
  197. */
  198. static struct pci_device_id scsih_pci_table[] = {
  199. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
  200. PCI_ANY_ID, PCI_ANY_ID },
  201. /* Falcon ~ 2008*/
  202. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
  203. PCI_ANY_ID, PCI_ANY_ID },
  204. /* Liberator ~ 2108 */
  205. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
  206. PCI_ANY_ID, PCI_ANY_ID },
  207. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
  208. PCI_ANY_ID, PCI_ANY_ID },
  209. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
  210. PCI_ANY_ID, PCI_ANY_ID },
  211. /* Meteor ~ 2116 */
  212. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
  213. PCI_ANY_ID, PCI_ANY_ID },
  214. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
  215. PCI_ANY_ID, PCI_ANY_ID },
  216. /* Thunderbolt ~ 2208 */
  217. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
  218. PCI_ANY_ID, PCI_ANY_ID },
  219. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
  220. PCI_ANY_ID, PCI_ANY_ID },
  221. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
  222. PCI_ANY_ID, PCI_ANY_ID },
  223. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
  224. PCI_ANY_ID, PCI_ANY_ID },
  225. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
  226. PCI_ANY_ID, PCI_ANY_ID },
  227. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
  228. PCI_ANY_ID, PCI_ANY_ID },
  229. /* Mustang ~ 2308 */
  230. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_1,
  231. PCI_ANY_ID, PCI_ANY_ID },
  232. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_2,
  233. PCI_ANY_ID, PCI_ANY_ID },
  234. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2308_3,
  235. PCI_ANY_ID, PCI_ANY_ID },
  236. /* SSS6200 */
  237. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SSS6200,
  238. PCI_ANY_ID, PCI_ANY_ID },
  239. {0} /* Terminating entry */
  240. };
  241. MODULE_DEVICE_TABLE(pci, scsih_pci_table);
  242. /**
  243. * _scsih_set_debug_level - global setting of ioc->logging_level.
  244. *
  245. * Note: The logging levels are defined in mpt2sas_debug.h.
  246. */
  247. static int
  248. _scsih_set_debug_level(const char *val, struct kernel_param *kp)
  249. {
  250. int ret = param_set_int(val, kp);
  251. struct MPT2SAS_ADAPTER *ioc;
  252. if (ret)
  253. return ret;
  254. printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
  255. list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
  256. ioc->logging_level = logging_level;
  257. return 0;
  258. }
  259. module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
  260. &logging_level, 0644);
  261. /**
  262. * _scsih_srch_boot_sas_address - search based on sas_address
  263. * @sas_address: sas address
  264. * @boot_device: boot device object from bios page 2
  265. *
  266. * Returns 1 when there's a match, 0 means no match.
  267. */
  268. static inline int
  269. _scsih_srch_boot_sas_address(u64 sas_address,
  270. Mpi2BootDeviceSasWwid_t *boot_device)
  271. {
  272. return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
  273. }
  274. /**
  275. * _scsih_srch_boot_device_name - search based on device name
  276. * @device_name: device name specified in INDENTIFY fram
  277. * @boot_device: boot device object from bios page 2
  278. *
  279. * Returns 1 when there's a match, 0 means no match.
  280. */
  281. static inline int
  282. _scsih_srch_boot_device_name(u64 device_name,
  283. Mpi2BootDeviceDeviceName_t *boot_device)
  284. {
  285. return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
  286. }
  287. /**
  288. * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
  289. * @enclosure_logical_id: enclosure logical id
  290. * @slot_number: slot number
  291. * @boot_device: boot device object from bios page 2
  292. *
  293. * Returns 1 when there's a match, 0 means no match.
  294. */
  295. static inline int
  296. _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
  297. Mpi2BootDeviceEnclosureSlot_t *boot_device)
  298. {
  299. return (enclosure_logical_id == le64_to_cpu(boot_device->
  300. EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
  301. SlotNumber)) ? 1 : 0;
  302. }
  303. /**
  304. * _scsih_is_boot_device - search for matching boot device.
  305. * @sas_address: sas address
  306. * @device_name: device name specified in INDENTIFY fram
  307. * @enclosure_logical_id: enclosure logical id
  308. * @slot_number: slot number
  309. * @form: specifies boot device form
  310. * @boot_device: boot device object from bios page 2
  311. *
  312. * Returns 1 when there's a match, 0 means no match.
  313. */
  314. static int
  315. _scsih_is_boot_device(u64 sas_address, u64 device_name,
  316. u64 enclosure_logical_id, u16 slot, u8 form,
  317. Mpi2BiosPage2BootDevice_t *boot_device)
  318. {
  319. int rc = 0;
  320. switch (form) {
  321. case MPI2_BIOSPAGE2_FORM_SAS_WWID:
  322. if (!sas_address)
  323. break;
  324. rc = _scsih_srch_boot_sas_address(
  325. sas_address, &boot_device->SasWwid);
  326. break;
  327. case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
  328. if (!enclosure_logical_id)
  329. break;
  330. rc = _scsih_srch_boot_encl_slot(
  331. enclosure_logical_id,
  332. slot, &boot_device->EnclosureSlot);
  333. break;
  334. case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
  335. if (!device_name)
  336. break;
  337. rc = _scsih_srch_boot_device_name(
  338. device_name, &boot_device->DeviceName);
  339. break;
  340. case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
  341. break;
  342. }
  343. return rc;
  344. }
  345. /**
  346. * _scsih_get_sas_address - set the sas_address for given device handle
  347. * @handle: device handle
  348. * @sas_address: sas address
  349. *
  350. * Returns 0 success, non-zero when failure
  351. */
  352. static int
  353. _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  354. u64 *sas_address)
  355. {
  356. Mpi2SasDevicePage0_t sas_device_pg0;
  357. Mpi2ConfigReply_t mpi_reply;
  358. u32 ioc_status;
  359. if (handle <= ioc->sas_hba.num_phys) {
  360. *sas_address = ioc->sas_hba.sas_address;
  361. return 0;
  362. } else
  363. *sas_address = 0;
  364. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  365. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  366. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  367. ioc->name, __FILE__, __LINE__, __func__);
  368. return -ENXIO;
  369. }
  370. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  371. MPI2_IOCSTATUS_MASK;
  372. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  373. printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
  374. "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
  375. __FILE__, __LINE__, __func__);
  376. return -EIO;
  377. }
  378. *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  379. return 0;
  380. }
  381. /**
  382. * _scsih_determine_boot_device - determine boot device.
  383. * @ioc: per adapter object
  384. * @device: either sas_device or raid_device object
  385. * @is_raid: [flag] 1 = raid object, 0 = sas object
  386. *
  387. * Determines whether this device should be first reported device to
  388. * to scsi-ml or sas transport, this purpose is for persistent boot device.
  389. * There are primary, alternate, and current entries in bios page 2. The order
  390. * priority is primary, alternate, then current. This routine saves
  391. * the corresponding device object and is_raid flag in the ioc object.
  392. * The saved data to be used later in _scsih_probe_boot_devices().
  393. */
  394. static void
  395. _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
  396. void *device, u8 is_raid)
  397. {
  398. struct _sas_device *sas_device;
  399. struct _raid_device *raid_device;
  400. u64 sas_address;
  401. u64 device_name;
  402. u64 enclosure_logical_id;
  403. u16 slot;
  404. /* only process this function when driver loads */
  405. if (!ioc->is_driver_loading)
  406. return;
  407. /* no Bios, return immediately */
  408. if (!ioc->bios_pg3.BiosVersion)
  409. return;
  410. if (!is_raid) {
  411. sas_device = device;
  412. sas_address = sas_device->sas_address;
  413. device_name = sas_device->device_name;
  414. enclosure_logical_id = sas_device->enclosure_logical_id;
  415. slot = sas_device->slot;
  416. } else {
  417. raid_device = device;
  418. sas_address = raid_device->wwid;
  419. device_name = 0;
  420. enclosure_logical_id = 0;
  421. slot = 0;
  422. }
  423. if (!ioc->req_boot_device.device) {
  424. if (_scsih_is_boot_device(sas_address, device_name,
  425. enclosure_logical_id, slot,
  426. (ioc->bios_pg2.ReqBootDeviceForm &
  427. MPI2_BIOSPAGE2_FORM_MASK),
  428. &ioc->bios_pg2.RequestedBootDevice)) {
  429. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  430. "%s: req_boot_device(0x%016llx)\n",
  431. ioc->name, __func__,
  432. (unsigned long long)sas_address));
  433. ioc->req_boot_device.device = device;
  434. ioc->req_boot_device.is_raid = is_raid;
  435. }
  436. }
  437. if (!ioc->req_alt_boot_device.device) {
  438. if (_scsih_is_boot_device(sas_address, device_name,
  439. enclosure_logical_id, slot,
  440. (ioc->bios_pg2.ReqAltBootDeviceForm &
  441. MPI2_BIOSPAGE2_FORM_MASK),
  442. &ioc->bios_pg2.RequestedAltBootDevice)) {
  443. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  444. "%s: req_alt_boot_device(0x%016llx)\n",
  445. ioc->name, __func__,
  446. (unsigned long long)sas_address));
  447. ioc->req_alt_boot_device.device = device;
  448. ioc->req_alt_boot_device.is_raid = is_raid;
  449. }
  450. }
  451. if (!ioc->current_boot_device.device) {
  452. if (_scsih_is_boot_device(sas_address, device_name,
  453. enclosure_logical_id, slot,
  454. (ioc->bios_pg2.CurrentBootDeviceForm &
  455. MPI2_BIOSPAGE2_FORM_MASK),
  456. &ioc->bios_pg2.CurrentBootDevice)) {
  457. dinitprintk(ioc, printk(MPT2SAS_INFO_FMT
  458. "%s: current_boot_device(0x%016llx)\n",
  459. ioc->name, __func__,
  460. (unsigned long long)sas_address));
  461. ioc->current_boot_device.device = device;
  462. ioc->current_boot_device.is_raid = is_raid;
  463. }
  464. }
  465. }
  466. /**
  467. * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
  468. * @ioc: per adapter object
  469. * @sas_address: sas address
  470. * Context: Calling function should acquire ioc->sas_device_lock
  471. *
  472. * This searches for sas_device based on sas_address, then return sas_device
  473. * object.
  474. */
  475. struct _sas_device *
  476. mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  477. u64 sas_address)
  478. {
  479. struct _sas_device *sas_device;
  480. list_for_each_entry(sas_device, &ioc->sas_device_list, list)
  481. if (sas_device->sas_address == sas_address)
  482. return sas_device;
  483. list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
  484. if (sas_device->sas_address == sas_address)
  485. return sas_device;
  486. return NULL;
  487. }
  488. /**
  489. * _scsih_sas_device_find_by_handle - sas device search
  490. * @ioc: per adapter object
  491. * @handle: sas device handle (assigned by firmware)
  492. * Context: Calling function should acquire ioc->sas_device_lock
  493. *
  494. * This searches for sas_device based on sas_address, then return sas_device
  495. * object.
  496. */
  497. static struct _sas_device *
  498. _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  499. {
  500. struct _sas_device *sas_device;
  501. list_for_each_entry(sas_device, &ioc->sas_device_list, list)
  502. if (sas_device->handle == handle)
  503. return sas_device;
  504. list_for_each_entry(sas_device, &ioc->sas_device_init_list, list)
  505. if (sas_device->handle == handle)
  506. return sas_device;
  507. return NULL;
  508. }
  509. /**
  510. * _scsih_sas_device_remove - remove sas_device from list.
  511. * @ioc: per adapter object
  512. * @sas_device: the sas_device object
  513. * Context: This function will acquire ioc->sas_device_lock.
  514. *
  515. * Removing object and freeing associated memory from the ioc->sas_device_list.
  516. */
  517. static void
  518. _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
  519. struct _sas_device *sas_device)
  520. {
  521. unsigned long flags;
  522. if (!sas_device)
  523. return;
  524. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  525. if (mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  526. sas_device->sas_address)) {
  527. list_del(&sas_device->list);
  528. kfree(sas_device);
  529. }
  530. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  531. }
  532. /**
  533. * _scsih_sas_device_add - insert sas_device to the list.
  534. * @ioc: per adapter object
  535. * @sas_device: the sas_device object
  536. * Context: This function will acquire ioc->sas_device_lock.
  537. *
  538. * Adding new object to the ioc->sas_device_list.
  539. */
  540. static void
  541. _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
  542. struct _sas_device *sas_device)
  543. {
  544. unsigned long flags;
  545. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
  546. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  547. sas_device->handle, (unsigned long long)sas_device->sas_address));
  548. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  549. list_add_tail(&sas_device->list, &ioc->sas_device_list);
  550. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  551. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  552. sas_device->sas_address_parent))
  553. _scsih_sas_device_remove(ioc, sas_device);
  554. }
  555. /**
  556. * _scsih_sas_device_init_add - insert sas_device to the list.
  557. * @ioc: per adapter object
  558. * @sas_device: the sas_device object
  559. * Context: This function will acquire ioc->sas_device_lock.
  560. *
  561. * Adding new object at driver load time to the ioc->sas_device_init_list.
  562. */
  563. static void
  564. _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
  565. struct _sas_device *sas_device)
  566. {
  567. unsigned long flags;
  568. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
  569. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  570. sas_device->handle, (unsigned long long)sas_device->sas_address));
  571. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  572. list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
  573. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  574. _scsih_determine_boot_device(ioc, sas_device, 0);
  575. }
  576. /**
  577. * _scsih_raid_device_find_by_id - raid device search
  578. * @ioc: per adapter object
  579. * @id: sas device target id
  580. * @channel: sas device channel
  581. * Context: Calling function should acquire ioc->raid_device_lock
  582. *
  583. * This searches for raid_device based on target id, then return raid_device
  584. * object.
  585. */
  586. static struct _raid_device *
  587. _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
  588. {
  589. struct _raid_device *raid_device, *r;
  590. r = NULL;
  591. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  592. if (raid_device->id == id && raid_device->channel == channel) {
  593. r = raid_device;
  594. goto out;
  595. }
  596. }
  597. out:
  598. return r;
  599. }
  600. /**
  601. * _scsih_raid_device_find_by_handle - raid device search
  602. * @ioc: per adapter object
  603. * @handle: sas device handle (assigned by firmware)
  604. * Context: Calling function should acquire ioc->raid_device_lock
  605. *
  606. * This searches for raid_device based on handle, then return raid_device
  607. * object.
  608. */
  609. static struct _raid_device *
  610. _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  611. {
  612. struct _raid_device *raid_device, *r;
  613. r = NULL;
  614. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  615. if (raid_device->handle != handle)
  616. continue;
  617. r = raid_device;
  618. goto out;
  619. }
  620. out:
  621. return r;
  622. }
  623. /**
  624. * _scsih_raid_device_find_by_wwid - raid device search
  625. * @ioc: per adapter object
  626. * @handle: sas device handle (assigned by firmware)
  627. * Context: Calling function should acquire ioc->raid_device_lock
  628. *
  629. * This searches for raid_device based on wwid, then return raid_device
  630. * object.
  631. */
  632. static struct _raid_device *
  633. _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
  634. {
  635. struct _raid_device *raid_device, *r;
  636. r = NULL;
  637. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  638. if (raid_device->wwid != wwid)
  639. continue;
  640. r = raid_device;
  641. goto out;
  642. }
  643. out:
  644. return r;
  645. }
  646. /**
  647. * _scsih_raid_device_add - add raid_device object
  648. * @ioc: per adapter object
  649. * @raid_device: raid_device object
  650. *
  651. * This is added to the raid_device_list link list.
  652. */
  653. static void
  654. _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
  655. struct _raid_device *raid_device)
  656. {
  657. unsigned long flags;
  658. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle"
  659. "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  660. raid_device->handle, (unsigned long long)raid_device->wwid));
  661. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  662. list_add_tail(&raid_device->list, &ioc->raid_device_list);
  663. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  664. }
  665. /**
  666. * _scsih_raid_device_remove - delete raid_device object
  667. * @ioc: per adapter object
  668. * @raid_device: raid_device object
  669. *
  670. * This is removed from the raid_device_list link list.
  671. */
  672. static void
  673. _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
  674. struct _raid_device *raid_device)
  675. {
  676. unsigned long flags;
  677. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  678. list_del(&raid_device->list);
  679. memset(raid_device, 0, sizeof(struct _raid_device));
  680. kfree(raid_device);
  681. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  682. }
  683. /**
  684. * mpt2sas_scsih_expander_find_by_handle - expander device search
  685. * @ioc: per adapter object
  686. * @handle: expander handle (assigned by firmware)
  687. * Context: Calling function should acquire ioc->sas_device_lock
  688. *
  689. * This searches for expander device based on handle, then returns the
  690. * sas_node object.
  691. */
  692. struct _sas_node *
  693. mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  694. {
  695. struct _sas_node *sas_expander, *r;
  696. r = NULL;
  697. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  698. if (sas_expander->handle != handle)
  699. continue;
  700. r = sas_expander;
  701. goto out;
  702. }
  703. out:
  704. return r;
  705. }
  706. /**
  707. * mpt2sas_scsih_expander_find_by_sas_address - expander device search
  708. * @ioc: per adapter object
  709. * @sas_address: sas address
  710. * Context: Calling function should acquire ioc->sas_node_lock.
  711. *
  712. * This searches for expander device based on sas_address, then returns the
  713. * sas_node object.
  714. */
  715. struct _sas_node *
  716. mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  717. u64 sas_address)
  718. {
  719. struct _sas_node *sas_expander, *r;
  720. r = NULL;
  721. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  722. if (sas_expander->sas_address != sas_address)
  723. continue;
  724. r = sas_expander;
  725. goto out;
  726. }
  727. out:
  728. return r;
  729. }
  730. /**
  731. * _scsih_expander_node_add - insert expander device to the list.
  732. * @ioc: per adapter object
  733. * @sas_expander: the sas_device object
  734. * Context: This function will acquire ioc->sas_node_lock.
  735. *
  736. * Adding new object to the ioc->sas_expander_list.
  737. *
  738. * Return nothing.
  739. */
  740. static void
  741. _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
  742. struct _sas_node *sas_expander)
  743. {
  744. unsigned long flags;
  745. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  746. list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
  747. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  748. }
  749. /**
  750. * _scsih_is_end_device - determines if device is an end device
  751. * @device_info: bitfield providing information about the device.
  752. * Context: none
  753. *
  754. * Returns 1 if end device.
  755. */
  756. static int
  757. _scsih_is_end_device(u32 device_info)
  758. {
  759. if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
  760. ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
  761. (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
  762. (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
  763. return 1;
  764. else
  765. return 0;
  766. }
  767. /**
  768. * _scsih_scsi_lookup_get - returns scmd entry
  769. * @ioc: per adapter object
  770. * @smid: system request message index
  771. *
  772. * Returns the smid stored scmd pointer.
  773. */
  774. static struct scsi_cmnd *
  775. _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  776. {
  777. return ioc->scsi_lookup[smid - 1].scmd;
  778. }
  779. /**
  780. * _scsih_scsi_lookup_get_clear - returns scmd entry
  781. * @ioc: per adapter object
  782. * @smid: system request message index
  783. *
  784. * Returns the smid stored scmd pointer.
  785. * Then will derefrence the stored scmd pointer.
  786. */
  787. static inline struct scsi_cmnd *
  788. _scsih_scsi_lookup_get_clear(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  789. {
  790. unsigned long flags;
  791. struct scsi_cmnd *scmd;
  792. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  793. scmd = ioc->scsi_lookup[smid - 1].scmd;
  794. ioc->scsi_lookup[smid - 1].scmd = NULL;
  795. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  796. return scmd;
  797. }
  798. /**
  799. * _scsih_scsi_lookup_find_by_scmd - scmd lookup
  800. * @ioc: per adapter object
  801. * @smid: system request message index
  802. * @scmd: pointer to scsi command object
  803. * Context: This function will acquire ioc->scsi_lookup_lock.
  804. *
  805. * This will search for a scmd pointer in the scsi_lookup array,
  806. * returning the revelent smid. A returned value of zero means invalid.
  807. */
  808. static u16
  809. _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
  810. *scmd)
  811. {
  812. u16 smid;
  813. unsigned long flags;
  814. int i;
  815. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  816. smid = 0;
  817. for (i = 0; i < ioc->scsiio_depth; i++) {
  818. if (ioc->scsi_lookup[i].scmd == scmd) {
  819. smid = ioc->scsi_lookup[i].smid;
  820. goto out;
  821. }
  822. }
  823. out:
  824. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  825. return smid;
  826. }
  827. /**
  828. * _scsih_scsi_lookup_find_by_target - search for matching channel:id
  829. * @ioc: per adapter object
  830. * @id: target id
  831. * @channel: channel
  832. * Context: This function will acquire ioc->scsi_lookup_lock.
  833. *
  834. * This will search for a matching channel:id in the scsi_lookup array,
  835. * returning 1 if found.
  836. */
  837. static u8
  838. _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
  839. int channel)
  840. {
  841. u8 found;
  842. unsigned long flags;
  843. int i;
  844. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  845. found = 0;
  846. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  847. if (ioc->scsi_lookup[i].scmd &&
  848. (ioc->scsi_lookup[i].scmd->device->id == id &&
  849. ioc->scsi_lookup[i].scmd->device->channel == channel)) {
  850. found = 1;
  851. goto out;
  852. }
  853. }
  854. out:
  855. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  856. return found;
  857. }
  858. /**
  859. * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
  860. * @ioc: per adapter object
  861. * @id: target id
  862. * @lun: lun number
  863. * @channel: channel
  864. * Context: This function will acquire ioc->scsi_lookup_lock.
  865. *
  866. * This will search for a matching channel:id:lun in the scsi_lookup array,
  867. * returning 1 if found.
  868. */
  869. static u8
  870. _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
  871. unsigned int lun, int channel)
  872. {
  873. u8 found;
  874. unsigned long flags;
  875. int i;
  876. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  877. found = 0;
  878. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  879. if (ioc->scsi_lookup[i].scmd &&
  880. (ioc->scsi_lookup[i].scmd->device->id == id &&
  881. ioc->scsi_lookup[i].scmd->device->channel == channel &&
  882. ioc->scsi_lookup[i].scmd->device->lun == lun)) {
  883. found = 1;
  884. goto out;
  885. }
  886. }
  887. out:
  888. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  889. return found;
  890. }
  891. /**
  892. * _scsih_get_chain_buffer_tracker - obtain chain tracker
  893. * @ioc: per adapter object
  894. * @smid: smid associated to an IO request
  895. *
  896. * Returns chain tracker(from ioc->free_chain_list)
  897. */
  898. static struct chain_tracker *
  899. _scsih_get_chain_buffer_tracker(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  900. {
  901. struct chain_tracker *chain_req;
  902. unsigned long flags;
  903. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  904. if (list_empty(&ioc->free_chain_list)) {
  905. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  906. printk(MPT2SAS_WARN_FMT "chain buffers not available\n",
  907. ioc->name);
  908. return NULL;
  909. }
  910. chain_req = list_entry(ioc->free_chain_list.next,
  911. struct chain_tracker, tracker_list);
  912. list_del_init(&chain_req->tracker_list);
  913. list_add_tail(&chain_req->tracker_list,
  914. &ioc->scsi_lookup[smid - 1].chain_list);
  915. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  916. return chain_req;
  917. }
  918. /**
  919. * _scsih_build_scatter_gather - main sg creation routine
  920. * @ioc: per adapter object
  921. * @scmd: scsi command
  922. * @smid: system request message index
  923. * Context: none.
  924. *
  925. * The main routine that builds scatter gather table from a given
  926. * scsi request sent via the .queuecommand main handler.
  927. *
  928. * Returns 0 success, anything else error
  929. */
  930. static int
  931. _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
  932. struct scsi_cmnd *scmd, u16 smid)
  933. {
  934. Mpi2SCSIIORequest_t *mpi_request;
  935. dma_addr_t chain_dma;
  936. struct scatterlist *sg_scmd;
  937. void *sg_local, *chain;
  938. u32 chain_offset;
  939. u32 chain_length;
  940. u32 chain_flags;
  941. int sges_left;
  942. u32 sges_in_segment;
  943. u32 sgl_flags;
  944. u32 sgl_flags_last_element;
  945. u32 sgl_flags_end_buffer;
  946. struct chain_tracker *chain_req;
  947. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  948. /* init scatter gather flags */
  949. sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
  950. if (scmd->sc_data_direction == DMA_TO_DEVICE)
  951. sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
  952. sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
  953. << MPI2_SGE_FLAGS_SHIFT;
  954. sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
  955. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
  956. << MPI2_SGE_FLAGS_SHIFT;
  957. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  958. sg_scmd = scsi_sglist(scmd);
  959. sges_left = scsi_dma_map(scmd);
  960. if (sges_left < 0) {
  961. sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
  962. " failed: request for %d bytes!\n", scsi_bufflen(scmd));
  963. return -ENOMEM;
  964. }
  965. sg_local = &mpi_request->SGL;
  966. sges_in_segment = ioc->max_sges_in_main_message;
  967. if (sges_left <= sges_in_segment)
  968. goto fill_in_last_segment;
  969. mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
  970. (sges_in_segment * ioc->sge_size))/4;
  971. /* fill in main message segment when there is a chain following */
  972. while (sges_in_segment) {
  973. if (sges_in_segment == 1)
  974. ioc->base_add_sg_single(sg_local,
  975. sgl_flags_last_element | sg_dma_len(sg_scmd),
  976. sg_dma_address(sg_scmd));
  977. else
  978. ioc->base_add_sg_single(sg_local, sgl_flags |
  979. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  980. sg_scmd = sg_next(sg_scmd);
  981. sg_local += ioc->sge_size;
  982. sges_left--;
  983. sges_in_segment--;
  984. }
  985. /* initializing the chain flags and pointers */
  986. chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
  987. chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
  988. if (!chain_req)
  989. return -1;
  990. chain = chain_req->chain_buffer;
  991. chain_dma = chain_req->chain_buffer_dma;
  992. do {
  993. sges_in_segment = (sges_left <=
  994. ioc->max_sges_in_chain_message) ? sges_left :
  995. ioc->max_sges_in_chain_message;
  996. chain_offset = (sges_left == sges_in_segment) ?
  997. 0 : (sges_in_segment * ioc->sge_size)/4;
  998. chain_length = sges_in_segment * ioc->sge_size;
  999. if (chain_offset) {
  1000. chain_offset = chain_offset <<
  1001. MPI2_SGE_CHAIN_OFFSET_SHIFT;
  1002. chain_length += ioc->sge_size;
  1003. }
  1004. ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
  1005. chain_length, chain_dma);
  1006. sg_local = chain;
  1007. if (!chain_offset)
  1008. goto fill_in_last_segment;
  1009. /* fill in chain segments */
  1010. while (sges_in_segment) {
  1011. if (sges_in_segment == 1)
  1012. ioc->base_add_sg_single(sg_local,
  1013. sgl_flags_last_element |
  1014. sg_dma_len(sg_scmd),
  1015. sg_dma_address(sg_scmd));
  1016. else
  1017. ioc->base_add_sg_single(sg_local, sgl_flags |
  1018. sg_dma_len(sg_scmd),
  1019. sg_dma_address(sg_scmd));
  1020. sg_scmd = sg_next(sg_scmd);
  1021. sg_local += ioc->sge_size;
  1022. sges_left--;
  1023. sges_in_segment--;
  1024. }
  1025. chain_req = _scsih_get_chain_buffer_tracker(ioc, smid);
  1026. if (!chain_req)
  1027. return -1;
  1028. chain = chain_req->chain_buffer;
  1029. chain_dma = chain_req->chain_buffer_dma;
  1030. } while (1);
  1031. fill_in_last_segment:
  1032. /* fill the last segment */
  1033. while (sges_left) {
  1034. if (sges_left == 1)
  1035. ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
  1036. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  1037. else
  1038. ioc->base_add_sg_single(sg_local, sgl_flags |
  1039. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  1040. sg_scmd = sg_next(sg_scmd);
  1041. sg_local += ioc->sge_size;
  1042. sges_left--;
  1043. }
  1044. return 0;
  1045. }
  1046. /**
  1047. * _scsih_adjust_queue_depth - setting device queue depth
  1048. * @sdev: scsi device struct
  1049. * @qdepth: requested queue depth
  1050. *
  1051. *
  1052. * Returns nothing
  1053. */
  1054. static void
  1055. _scsih_adjust_queue_depth(struct scsi_device *sdev, int qdepth)
  1056. {
  1057. struct Scsi_Host *shost = sdev->host;
  1058. int max_depth;
  1059. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1060. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1061. struct MPT2SAS_TARGET *sas_target_priv_data;
  1062. struct _sas_device *sas_device;
  1063. unsigned long flags;
  1064. max_depth = shost->can_queue;
  1065. /* limit max device queue for SATA to 32 */
  1066. sas_device_priv_data = sdev->hostdata;
  1067. if (!sas_device_priv_data)
  1068. goto not_sata;
  1069. sas_target_priv_data = sas_device_priv_data->sas_target;
  1070. if (!sas_target_priv_data)
  1071. goto not_sata;
  1072. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
  1073. goto not_sata;
  1074. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1075. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1076. sas_device_priv_data->sas_target->sas_address);
  1077. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1078. if (sas_device && sas_device->device_info &
  1079. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1080. max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
  1081. not_sata:
  1082. if (!sdev->tagged_supported)
  1083. max_depth = 1;
  1084. if (qdepth > max_depth)
  1085. qdepth = max_depth;
  1086. scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
  1087. }
  1088. /**
  1089. * _scsih_change_queue_depth - setting device queue depth
  1090. * @sdev: scsi device struct
  1091. * @qdepth: requested queue depth
  1092. * @reason: SCSI_QDEPTH_DEFAULT/SCSI_QDEPTH_QFULL/SCSI_QDEPTH_RAMP_UP
  1093. * (see include/scsi/scsi_host.h for definition)
  1094. *
  1095. * Returns queue depth.
  1096. */
  1097. static int
  1098. _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
  1099. {
  1100. if (reason == SCSI_QDEPTH_DEFAULT || reason == SCSI_QDEPTH_RAMP_UP)
  1101. _scsih_adjust_queue_depth(sdev, qdepth);
  1102. else if (reason == SCSI_QDEPTH_QFULL)
  1103. scsi_track_queue_full(sdev, qdepth);
  1104. else
  1105. return -EOPNOTSUPP;
  1106. if (sdev->inquiry_len > 7)
  1107. sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
  1108. "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
  1109. sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
  1110. sdev->ordered_tags, sdev->scsi_level,
  1111. (sdev->inquiry[7] & 2) >> 1);
  1112. return sdev->queue_depth;
  1113. }
  1114. /**
  1115. * _scsih_change_queue_type - changing device queue tag type
  1116. * @sdev: scsi device struct
  1117. * @tag_type: requested tag type
  1118. *
  1119. * Returns queue tag type.
  1120. */
  1121. static int
  1122. _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
  1123. {
  1124. if (sdev->tagged_supported) {
  1125. scsi_set_tag_type(sdev, tag_type);
  1126. if (tag_type)
  1127. scsi_activate_tcq(sdev, sdev->queue_depth);
  1128. else
  1129. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1130. } else
  1131. tag_type = 0;
  1132. return tag_type;
  1133. }
  1134. /**
  1135. * _scsih_target_alloc - target add routine
  1136. * @starget: scsi target struct
  1137. *
  1138. * Returns 0 if ok. Any other return is assumed to be an error and
  1139. * the device is ignored.
  1140. */
  1141. static int
  1142. _scsih_target_alloc(struct scsi_target *starget)
  1143. {
  1144. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1145. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1146. struct MPT2SAS_TARGET *sas_target_priv_data;
  1147. struct _sas_device *sas_device;
  1148. struct _raid_device *raid_device;
  1149. unsigned long flags;
  1150. struct sas_rphy *rphy;
  1151. sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
  1152. if (!sas_target_priv_data)
  1153. return -ENOMEM;
  1154. starget->hostdata = sas_target_priv_data;
  1155. sas_target_priv_data->starget = starget;
  1156. sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
  1157. /* RAID volumes */
  1158. if (starget->channel == RAID_CHANNEL) {
  1159. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1160. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1161. starget->channel);
  1162. if (raid_device) {
  1163. sas_target_priv_data->handle = raid_device->handle;
  1164. sas_target_priv_data->sas_address = raid_device->wwid;
  1165. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
  1166. sas_target_priv_data->raid_device = raid_device;
  1167. raid_device->starget = starget;
  1168. }
  1169. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1170. return 0;
  1171. }
  1172. /* sas/sata devices */
  1173. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1174. rphy = dev_to_rphy(starget->dev.parent);
  1175. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1176. rphy->identify.sas_address);
  1177. if (sas_device) {
  1178. sas_target_priv_data->handle = sas_device->handle;
  1179. sas_target_priv_data->sas_address = sas_device->sas_address;
  1180. sas_device->starget = starget;
  1181. sas_device->id = starget->id;
  1182. sas_device->channel = starget->channel;
  1183. if (test_bit(sas_device->handle, ioc->pd_handles))
  1184. sas_target_priv_data->flags |=
  1185. MPT_TARGET_FLAGS_RAID_COMPONENT;
  1186. }
  1187. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1188. return 0;
  1189. }
  1190. /**
  1191. * _scsih_target_destroy - target destroy routine
  1192. * @starget: scsi target struct
  1193. *
  1194. * Returns nothing.
  1195. */
  1196. static void
  1197. _scsih_target_destroy(struct scsi_target *starget)
  1198. {
  1199. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1200. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1201. struct MPT2SAS_TARGET *sas_target_priv_data;
  1202. struct _sas_device *sas_device;
  1203. struct _raid_device *raid_device;
  1204. unsigned long flags;
  1205. struct sas_rphy *rphy;
  1206. sas_target_priv_data = starget->hostdata;
  1207. if (!sas_target_priv_data)
  1208. return;
  1209. if (starget->channel == RAID_CHANNEL) {
  1210. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1211. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1212. starget->channel);
  1213. if (raid_device) {
  1214. raid_device->starget = NULL;
  1215. raid_device->sdev = NULL;
  1216. }
  1217. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1218. goto out;
  1219. }
  1220. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1221. rphy = dev_to_rphy(starget->dev.parent);
  1222. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1223. rphy->identify.sas_address);
  1224. if (sas_device && (sas_device->starget == starget) &&
  1225. (sas_device->id == starget->id) &&
  1226. (sas_device->channel == starget->channel))
  1227. sas_device->starget = NULL;
  1228. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1229. out:
  1230. kfree(sas_target_priv_data);
  1231. starget->hostdata = NULL;
  1232. }
  1233. /**
  1234. * _scsih_slave_alloc - device add routine
  1235. * @sdev: scsi device struct
  1236. *
  1237. * Returns 0 if ok. Any other return is assumed to be an error and
  1238. * the device is ignored.
  1239. */
  1240. static int
  1241. _scsih_slave_alloc(struct scsi_device *sdev)
  1242. {
  1243. struct Scsi_Host *shost;
  1244. struct MPT2SAS_ADAPTER *ioc;
  1245. struct MPT2SAS_TARGET *sas_target_priv_data;
  1246. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1247. struct scsi_target *starget;
  1248. struct _raid_device *raid_device;
  1249. unsigned long flags;
  1250. sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
  1251. if (!sas_device_priv_data)
  1252. return -ENOMEM;
  1253. sas_device_priv_data->lun = sdev->lun;
  1254. sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
  1255. starget = scsi_target(sdev);
  1256. sas_target_priv_data = starget->hostdata;
  1257. sas_target_priv_data->num_luns++;
  1258. sas_device_priv_data->sas_target = sas_target_priv_data;
  1259. sdev->hostdata = sas_device_priv_data;
  1260. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
  1261. sdev->no_uld_attach = 1;
  1262. shost = dev_to_shost(&starget->dev);
  1263. ioc = shost_priv(shost);
  1264. if (starget->channel == RAID_CHANNEL) {
  1265. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1266. raid_device = _scsih_raid_device_find_by_id(ioc,
  1267. starget->id, starget->channel);
  1268. if (raid_device)
  1269. raid_device->sdev = sdev; /* raid is single lun */
  1270. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1271. }
  1272. return 0;
  1273. }
  1274. /**
  1275. * _scsih_slave_destroy - device destroy routine
  1276. * @sdev: scsi device struct
  1277. *
  1278. * Returns nothing.
  1279. */
  1280. static void
  1281. _scsih_slave_destroy(struct scsi_device *sdev)
  1282. {
  1283. struct MPT2SAS_TARGET *sas_target_priv_data;
  1284. struct scsi_target *starget;
  1285. if (!sdev->hostdata)
  1286. return;
  1287. starget = scsi_target(sdev);
  1288. sas_target_priv_data = starget->hostdata;
  1289. sas_target_priv_data->num_luns--;
  1290. kfree(sdev->hostdata);
  1291. sdev->hostdata = NULL;
  1292. }
  1293. /**
  1294. * _scsih_display_sata_capabilities - sata capabilities
  1295. * @ioc: per adapter object
  1296. * @sas_device: the sas_device object
  1297. * @sdev: scsi device struct
  1298. */
  1299. static void
  1300. _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1301. struct _sas_device *sas_device, struct scsi_device *sdev)
  1302. {
  1303. Mpi2ConfigReply_t mpi_reply;
  1304. Mpi2SasDevicePage0_t sas_device_pg0;
  1305. u32 ioc_status;
  1306. u16 flags;
  1307. u32 device_info;
  1308. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  1309. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
  1310. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1311. ioc->name, __FILE__, __LINE__, __func__);
  1312. return;
  1313. }
  1314. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1315. MPI2_IOCSTATUS_MASK;
  1316. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1317. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1318. ioc->name, __FILE__, __LINE__, __func__);
  1319. return;
  1320. }
  1321. flags = le16_to_cpu(sas_device_pg0.Flags);
  1322. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  1323. sdev_printk(KERN_INFO, sdev,
  1324. "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
  1325. "sw_preserve(%s)\n",
  1326. (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
  1327. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
  1328. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
  1329. "n",
  1330. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
  1331. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
  1332. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
  1333. }
  1334. /**
  1335. * _scsih_is_raid - return boolean indicating device is raid volume
  1336. * @dev the device struct object
  1337. */
  1338. static int
  1339. _scsih_is_raid(struct device *dev)
  1340. {
  1341. struct scsi_device *sdev = to_scsi_device(dev);
  1342. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1343. if (ioc->is_warpdrive)
  1344. return 0;
  1345. return (sdev->channel == RAID_CHANNEL) ? 1 : 0;
  1346. }
  1347. /**
  1348. * _scsih_get_resync - get raid volume resync percent complete
  1349. * @dev the device struct object
  1350. */
  1351. static void
  1352. _scsih_get_resync(struct device *dev)
  1353. {
  1354. struct scsi_device *sdev = to_scsi_device(dev);
  1355. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1356. static struct _raid_device *raid_device;
  1357. unsigned long flags;
  1358. Mpi2RaidVolPage0_t vol_pg0;
  1359. Mpi2ConfigReply_t mpi_reply;
  1360. u32 volume_status_flags;
  1361. u8 percent_complete = 0;
  1362. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1363. raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
  1364. sdev->channel);
  1365. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1366. if (!raid_device || ioc->is_warpdrive)
  1367. goto out;
  1368. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
  1369. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
  1370. sizeof(Mpi2RaidVolPage0_t))) {
  1371. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1372. ioc->name, __FILE__, __LINE__, __func__);
  1373. goto out;
  1374. }
  1375. volume_status_flags = le32_to_cpu(vol_pg0.VolumeStatusFlags);
  1376. if (volume_status_flags & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS)
  1377. percent_complete = raid_device->percent_complete;
  1378. out:
  1379. raid_set_resync(mpt2sas_raid_template, dev, percent_complete);
  1380. }
  1381. /**
  1382. * _scsih_get_state - get raid volume level
  1383. * @dev the device struct object
  1384. */
  1385. static void
  1386. _scsih_get_state(struct device *dev)
  1387. {
  1388. struct scsi_device *sdev = to_scsi_device(dev);
  1389. struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
  1390. static struct _raid_device *raid_device;
  1391. unsigned long flags;
  1392. Mpi2RaidVolPage0_t vol_pg0;
  1393. Mpi2ConfigReply_t mpi_reply;
  1394. u32 volstate;
  1395. enum raid_state state = RAID_STATE_UNKNOWN;
  1396. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1397. raid_device = _scsih_raid_device_find_by_id(ioc, sdev->id,
  1398. sdev->channel);
  1399. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1400. if (!raid_device)
  1401. goto out;
  1402. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, &vol_pg0,
  1403. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle,
  1404. sizeof(Mpi2RaidVolPage0_t))) {
  1405. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1406. ioc->name, __FILE__, __LINE__, __func__);
  1407. goto out;
  1408. }
  1409. volstate = le32_to_cpu(vol_pg0.VolumeStatusFlags);
  1410. if (volstate & MPI2_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS) {
  1411. state = RAID_STATE_RESYNCING;
  1412. goto out;
  1413. }
  1414. switch (vol_pg0.VolumeState) {
  1415. case MPI2_RAID_VOL_STATE_OPTIMAL:
  1416. case MPI2_RAID_VOL_STATE_ONLINE:
  1417. state = RAID_STATE_ACTIVE;
  1418. break;
  1419. case MPI2_RAID_VOL_STATE_DEGRADED:
  1420. state = RAID_STATE_DEGRADED;
  1421. break;
  1422. case MPI2_RAID_VOL_STATE_FAILED:
  1423. case MPI2_RAID_VOL_STATE_MISSING:
  1424. state = RAID_STATE_OFFLINE;
  1425. break;
  1426. }
  1427. out:
  1428. raid_set_state(mpt2sas_raid_template, dev, state);
  1429. }
  1430. /**
  1431. * _scsih_set_level - set raid level
  1432. * @sdev: scsi device struct
  1433. * @raid_device: raid_device object
  1434. */
  1435. static void
  1436. _scsih_set_level(struct scsi_device *sdev, struct _raid_device *raid_device)
  1437. {
  1438. enum raid_level level = RAID_LEVEL_UNKNOWN;
  1439. switch (raid_device->volume_type) {
  1440. case MPI2_RAID_VOL_TYPE_RAID0:
  1441. level = RAID_LEVEL_0;
  1442. break;
  1443. case MPI2_RAID_VOL_TYPE_RAID10:
  1444. level = RAID_LEVEL_10;
  1445. break;
  1446. case MPI2_RAID_VOL_TYPE_RAID1E:
  1447. level = RAID_LEVEL_1E;
  1448. break;
  1449. case MPI2_RAID_VOL_TYPE_RAID1:
  1450. level = RAID_LEVEL_1;
  1451. break;
  1452. }
  1453. raid_set_level(mpt2sas_raid_template, &sdev->sdev_gendev, level);
  1454. }
  1455. /**
  1456. * _scsih_get_volume_capabilities - volume capabilities
  1457. * @ioc: per adapter object
  1458. * @sas_device: the raid_device object
  1459. */
  1460. static void
  1461. _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1462. struct _raid_device *raid_device)
  1463. {
  1464. Mpi2RaidVolPage0_t *vol_pg0;
  1465. Mpi2RaidPhysDiskPage0_t pd_pg0;
  1466. Mpi2SasDevicePage0_t sas_device_pg0;
  1467. Mpi2ConfigReply_t mpi_reply;
  1468. u16 sz;
  1469. u8 num_pds;
  1470. if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
  1471. &num_pds)) || !num_pds) {
  1472. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1473. ioc->name, __FILE__, __LINE__, __func__);
  1474. return;
  1475. }
  1476. raid_device->num_pds = num_pds;
  1477. sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
  1478. sizeof(Mpi2RaidVol0PhysDisk_t));
  1479. vol_pg0 = kzalloc(sz, GFP_KERNEL);
  1480. if (!vol_pg0) {
  1481. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1482. ioc->name, __FILE__, __LINE__, __func__);
  1483. return;
  1484. }
  1485. if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
  1486. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
  1487. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1488. ioc->name, __FILE__, __LINE__, __func__);
  1489. kfree(vol_pg0);
  1490. return;
  1491. }
  1492. raid_device->volume_type = vol_pg0->VolumeType;
  1493. /* figure out what the underlying devices are by
  1494. * obtaining the device_info bits for the 1st device
  1495. */
  1496. if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  1497. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
  1498. vol_pg0->PhysDisk[0].PhysDiskNum))) {
  1499. if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  1500. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  1501. le16_to_cpu(pd_pg0.DevHandle)))) {
  1502. raid_device->device_info =
  1503. le32_to_cpu(sas_device_pg0.DeviceInfo);
  1504. }
  1505. }
  1506. kfree(vol_pg0);
  1507. }
  1508. /**
  1509. * _scsih_disable_ddio - Disable direct I/O for all the volumes
  1510. * @ioc: per adapter object
  1511. */
  1512. static void
  1513. _scsih_disable_ddio(struct MPT2SAS_ADAPTER *ioc)
  1514. {
  1515. Mpi2RaidVolPage1_t vol_pg1;
  1516. Mpi2ConfigReply_t mpi_reply;
  1517. struct _raid_device *raid_device;
  1518. u16 handle;
  1519. u16 ioc_status;
  1520. handle = 0xFFFF;
  1521. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  1522. &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  1523. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1524. MPI2_IOCSTATUS_MASK;
  1525. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  1526. break;
  1527. handle = le16_to_cpu(vol_pg1.DevHandle);
  1528. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  1529. if (raid_device)
  1530. raid_device->direct_io_enabled = 0;
  1531. }
  1532. return;
  1533. }
  1534. /**
  1535. * _scsih_get_num_volumes - Get number of volumes in the ioc
  1536. * @ioc: per adapter object
  1537. */
  1538. static u8
  1539. _scsih_get_num_volumes(struct MPT2SAS_ADAPTER *ioc)
  1540. {
  1541. Mpi2RaidVolPage1_t vol_pg1;
  1542. Mpi2ConfigReply_t mpi_reply;
  1543. u16 handle;
  1544. u8 vol_cnt = 0;
  1545. u16 ioc_status;
  1546. handle = 0xFFFF;
  1547. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  1548. &vol_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  1549. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1550. MPI2_IOCSTATUS_MASK;
  1551. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  1552. break;
  1553. vol_cnt++;
  1554. handle = le16_to_cpu(vol_pg1.DevHandle);
  1555. }
  1556. return vol_cnt;
  1557. }
  1558. /**
  1559. * _scsih_init_warpdrive_properties - Set properties for warpdrive direct I/O.
  1560. * @ioc: per adapter object
  1561. * @raid_device: the raid_device object
  1562. */
  1563. static void
  1564. _scsih_init_warpdrive_properties(struct MPT2SAS_ADAPTER *ioc,
  1565. struct _raid_device *raid_device)
  1566. {
  1567. Mpi2RaidVolPage0_t *vol_pg0;
  1568. Mpi2RaidPhysDiskPage0_t pd_pg0;
  1569. Mpi2ConfigReply_t mpi_reply;
  1570. u16 sz;
  1571. u8 num_pds, count;
  1572. u64 mb = 1024 * 1024;
  1573. u64 tb_2 = 2 * mb * mb;
  1574. u64 capacity;
  1575. u32 stripe_sz;
  1576. u8 i, stripe_exp;
  1577. if (!ioc->is_warpdrive)
  1578. return;
  1579. if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS) {
  1580. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1581. "globally as drives are exposed\n", ioc->name);
  1582. return;
  1583. }
  1584. if (_scsih_get_num_volumes(ioc) > 1) {
  1585. _scsih_disable_ddio(ioc);
  1586. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1587. "globally as number of drives > 1\n", ioc->name);
  1588. return;
  1589. }
  1590. if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
  1591. &num_pds)) || !num_pds) {
  1592. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1593. "Failure in computing number of drives\n", ioc->name);
  1594. return;
  1595. }
  1596. sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
  1597. sizeof(Mpi2RaidVol0PhysDisk_t));
  1598. vol_pg0 = kzalloc(sz, GFP_KERNEL);
  1599. if (!vol_pg0) {
  1600. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1601. "Memory allocation failure for RVPG0\n", ioc->name);
  1602. return;
  1603. }
  1604. if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
  1605. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
  1606. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1607. "Failure in retrieving RVPG0\n", ioc->name);
  1608. kfree(vol_pg0);
  1609. return;
  1610. }
  1611. /*
  1612. * WARPDRIVE:If number of physical disks in a volume exceeds the max pds
  1613. * assumed for WARPDRIVE, disable direct I/O
  1614. */
  1615. if (num_pds > MPT_MAX_WARPDRIVE_PDS) {
  1616. printk(MPT2SAS_WARN_FMT "WarpDrive : Direct IO is disabled "
  1617. "for the drive with handle(0x%04x): num_mem=%d, "
  1618. "max_mem_allowed=%d\n", ioc->name, raid_device->handle,
  1619. num_pds, MPT_MAX_WARPDRIVE_PDS);
  1620. kfree(vol_pg0);
  1621. return;
  1622. }
  1623. for (count = 0; count < num_pds; count++) {
  1624. if (mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  1625. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
  1626. vol_pg0->PhysDisk[count].PhysDiskNum) ||
  1627. pd_pg0.DevHandle == MPT2SAS_INVALID_DEVICE_HANDLE) {
  1628. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is "
  1629. "disabled for the drive with handle(0x%04x) member"
  1630. "handle retrieval failed for member number=%d\n",
  1631. ioc->name, raid_device->handle,
  1632. vol_pg0->PhysDisk[count].PhysDiskNum);
  1633. goto out_error;
  1634. }
  1635. raid_device->pd_handle[count] = le16_to_cpu(pd_pg0.DevHandle);
  1636. }
  1637. /*
  1638. * Assumption for WD: Direct I/O is not supported if the volume is
  1639. * not RAID0, if the stripe size is not 64KB, if the block size is
  1640. * not 512 and if the volume size is >2TB
  1641. */
  1642. if (raid_device->volume_type != MPI2_RAID_VOL_TYPE_RAID0 ||
  1643. le16_to_cpu(vol_pg0->BlockSize) != 512) {
  1644. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1645. "for the drive with handle(0x%04x): type=%d, "
  1646. "s_sz=%uK, blk_size=%u\n", ioc->name,
  1647. raid_device->handle, raid_device->volume_type,
  1648. le32_to_cpu(vol_pg0->StripeSize)/2,
  1649. le16_to_cpu(vol_pg0->BlockSize));
  1650. goto out_error;
  1651. }
  1652. capacity = (u64) le16_to_cpu(vol_pg0->BlockSize) *
  1653. (le64_to_cpu(vol_pg0->MaxLBA) + 1);
  1654. if (capacity > tb_2) {
  1655. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1656. "for the drive with handle(0x%04x) since drive sz > 2TB\n",
  1657. ioc->name, raid_device->handle);
  1658. goto out_error;
  1659. }
  1660. stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
  1661. stripe_exp = 0;
  1662. for (i = 0; i < 32; i++) {
  1663. if (stripe_sz & 1)
  1664. break;
  1665. stripe_exp++;
  1666. stripe_sz >>= 1;
  1667. }
  1668. if (i == 32) {
  1669. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is disabled "
  1670. "for the drive with handle(0x%04x) invalid stripe sz %uK\n",
  1671. ioc->name, raid_device->handle,
  1672. le32_to_cpu(vol_pg0->StripeSize)/2);
  1673. goto out_error;
  1674. }
  1675. raid_device->stripe_exponent = stripe_exp;
  1676. raid_device->direct_io_enabled = 1;
  1677. printk(MPT2SAS_INFO_FMT "WarpDrive : Direct IO is Enabled for the drive"
  1678. " with handle(0x%04x)\n", ioc->name, raid_device->handle);
  1679. /*
  1680. * WARPDRIVE: Though the following fields are not used for direct IO,
  1681. * stored for future purpose:
  1682. */
  1683. raid_device->max_lba = le64_to_cpu(vol_pg0->MaxLBA);
  1684. raid_device->stripe_sz = le32_to_cpu(vol_pg0->StripeSize);
  1685. raid_device->block_sz = le16_to_cpu(vol_pg0->BlockSize);
  1686. kfree(vol_pg0);
  1687. return;
  1688. out_error:
  1689. raid_device->direct_io_enabled = 0;
  1690. for (count = 0; count < num_pds; count++)
  1691. raid_device->pd_handle[count] = 0;
  1692. kfree(vol_pg0);
  1693. return;
  1694. }
  1695. /**
  1696. * _scsih_enable_tlr - setting TLR flags
  1697. * @ioc: per adapter object
  1698. * @sdev: scsi device struct
  1699. *
  1700. * Enabling Transaction Layer Retries for tape devices when
  1701. * vpd page 0x90 is present
  1702. *
  1703. */
  1704. static void
  1705. _scsih_enable_tlr(struct MPT2SAS_ADAPTER *ioc, struct scsi_device *sdev)
  1706. {
  1707. /* only for TAPE */
  1708. if (sdev->type != TYPE_TAPE)
  1709. return;
  1710. if (!(ioc->facts.IOCCapabilities & MPI2_IOCFACTS_CAPABILITY_TLR))
  1711. return;
  1712. sas_enable_tlr(sdev);
  1713. sdev_printk(KERN_INFO, sdev, "TLR %s\n",
  1714. sas_is_tlr_enabled(sdev) ? "Enabled" : "Disabled");
  1715. return;
  1716. }
  1717. /**
  1718. * _scsih_slave_configure - device configure routine.
  1719. * @sdev: scsi device struct
  1720. *
  1721. * Returns 0 if ok. Any other return is assumed to be an error and
  1722. * the device is ignored.
  1723. */
  1724. static int
  1725. _scsih_slave_configure(struct scsi_device *sdev)
  1726. {
  1727. struct Scsi_Host *shost = sdev->host;
  1728. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1729. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1730. struct MPT2SAS_TARGET *sas_target_priv_data;
  1731. struct _sas_device *sas_device;
  1732. struct _raid_device *raid_device;
  1733. unsigned long flags;
  1734. int qdepth;
  1735. u8 ssp_target = 0;
  1736. char *ds = "";
  1737. char *r_level = "";
  1738. qdepth = 1;
  1739. sas_device_priv_data = sdev->hostdata;
  1740. sas_device_priv_data->configured_lun = 1;
  1741. sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
  1742. sas_target_priv_data = sas_device_priv_data->sas_target;
  1743. /* raid volume handling */
  1744. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
  1745. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1746. raid_device = _scsih_raid_device_find_by_handle(ioc,
  1747. sas_target_priv_data->handle);
  1748. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1749. if (!raid_device) {
  1750. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1751. ioc->name, __FILE__, __LINE__, __func__);
  1752. return 0;
  1753. }
  1754. _scsih_get_volume_capabilities(ioc, raid_device);
  1755. /*
  1756. * WARPDRIVE: Initialize the required data for Direct IO
  1757. */
  1758. _scsih_init_warpdrive_properties(ioc, raid_device);
  1759. /* RAID Queue Depth Support
  1760. * IS volume = underlying qdepth of drive type, either
  1761. * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
  1762. * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
  1763. */
  1764. if (raid_device->device_info &
  1765. MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1766. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1767. ds = "SSP";
  1768. } else {
  1769. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1770. if (raid_device->device_info &
  1771. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1772. ds = "SATA";
  1773. else
  1774. ds = "STP";
  1775. }
  1776. switch (raid_device->volume_type) {
  1777. case MPI2_RAID_VOL_TYPE_RAID0:
  1778. r_level = "RAID0";
  1779. break;
  1780. case MPI2_RAID_VOL_TYPE_RAID1E:
  1781. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1782. if (ioc->manu_pg10.OEMIdentifier &&
  1783. (le32_to_cpu(ioc->manu_pg10.GenericFlags0) &
  1784. MFG10_GF0_R10_DISPLAY) &&
  1785. !(raid_device->num_pds % 2))
  1786. r_level = "RAID10";
  1787. else
  1788. r_level = "RAID1E";
  1789. break;
  1790. case MPI2_RAID_VOL_TYPE_RAID1:
  1791. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1792. r_level = "RAID1";
  1793. break;
  1794. case MPI2_RAID_VOL_TYPE_RAID10:
  1795. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1796. r_level = "RAID10";
  1797. break;
  1798. case MPI2_RAID_VOL_TYPE_UNKNOWN:
  1799. default:
  1800. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1801. r_level = "RAIDX";
  1802. break;
  1803. }
  1804. if (!ioc->hide_ir_msg)
  1805. sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
  1806. "wwid(0x%016llx), pd_count(%d), type(%s)\n",
  1807. r_level, raid_device->handle,
  1808. (unsigned long long)raid_device->wwid,
  1809. raid_device->num_pds, ds);
  1810. _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
  1811. /* raid transport support */
  1812. if (!ioc->is_warpdrive)
  1813. _scsih_set_level(sdev, raid_device);
  1814. return 0;
  1815. }
  1816. /* non-raid handling */
  1817. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1818. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1819. sas_device_priv_data->sas_target->sas_address);
  1820. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1821. if (sas_device) {
  1822. if (sas_target_priv_data->flags &
  1823. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1824. mpt2sas_config_get_volume_handle(ioc,
  1825. sas_device->handle, &sas_device->volume_handle);
  1826. mpt2sas_config_get_volume_wwid(ioc,
  1827. sas_device->volume_handle,
  1828. &sas_device->volume_wwid);
  1829. }
  1830. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1831. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1832. ssp_target = 1;
  1833. ds = "SSP";
  1834. } else {
  1835. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1836. if (sas_device->device_info &
  1837. MPI2_SAS_DEVICE_INFO_STP_TARGET)
  1838. ds = "STP";
  1839. else if (sas_device->device_info &
  1840. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1841. ds = "SATA";
  1842. }
  1843. sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
  1844. "sas_addr(0x%016llx), phy(%d), device_name(0x%016llx)\n",
  1845. ds, sas_device->handle,
  1846. (unsigned long long)sas_device->sas_address,
  1847. sas_device->phy,
  1848. (unsigned long long)sas_device->device_name);
  1849. sdev_printk(KERN_INFO, sdev, "%s: "
  1850. "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
  1851. (unsigned long long) sas_device->enclosure_logical_id,
  1852. sas_device->slot);
  1853. if (!ssp_target)
  1854. _scsih_display_sata_capabilities(ioc, sas_device, sdev);
  1855. }
  1856. _scsih_change_queue_depth(sdev, qdepth, SCSI_QDEPTH_DEFAULT);
  1857. if (ssp_target) {
  1858. sas_read_port_mode_page(sdev);
  1859. _scsih_enable_tlr(ioc, sdev);
  1860. }
  1861. return 0;
  1862. }
  1863. /**
  1864. * _scsih_bios_param - fetch head, sector, cylinder info for a disk
  1865. * @sdev: scsi device struct
  1866. * @bdev: pointer to block device context
  1867. * @capacity: device size (in 512 byte sectors)
  1868. * @params: three element array to place output:
  1869. * params[0] number of heads (max 255)
  1870. * params[1] number of sectors (max 63)
  1871. * params[2] number of cylinders
  1872. *
  1873. * Return nothing.
  1874. */
  1875. static int
  1876. _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
  1877. sector_t capacity, int params[])
  1878. {
  1879. int heads;
  1880. int sectors;
  1881. sector_t cylinders;
  1882. ulong dummy;
  1883. heads = 64;
  1884. sectors = 32;
  1885. dummy = heads * sectors;
  1886. cylinders = capacity;
  1887. sector_div(cylinders, dummy);
  1888. /*
  1889. * Handle extended translation size for logical drives
  1890. * > 1Gb
  1891. */
  1892. if ((ulong)capacity >= 0x200000) {
  1893. heads = 255;
  1894. sectors = 63;
  1895. dummy = heads * sectors;
  1896. cylinders = capacity;
  1897. sector_div(cylinders, dummy);
  1898. }
  1899. /* return result */
  1900. params[0] = heads;
  1901. params[1] = sectors;
  1902. params[2] = cylinders;
  1903. return 0;
  1904. }
  1905. /**
  1906. * _scsih_response_code - translation of device response code
  1907. * @ioc: per adapter object
  1908. * @response_code: response code returned by the device
  1909. *
  1910. * Return nothing.
  1911. */
  1912. static void
  1913. _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
  1914. {
  1915. char *desc;
  1916. switch (response_code) {
  1917. case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
  1918. desc = "task management request completed";
  1919. break;
  1920. case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
  1921. desc = "invalid frame";
  1922. break;
  1923. case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1924. desc = "task management request not supported";
  1925. break;
  1926. case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
  1927. desc = "task management request failed";
  1928. break;
  1929. case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1930. desc = "task management request succeeded";
  1931. break;
  1932. case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1933. desc = "invalid lun";
  1934. break;
  1935. case 0xA:
  1936. desc = "overlapped tag attempted";
  1937. break;
  1938. case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1939. desc = "task queued, however not sent to target";
  1940. break;
  1941. default:
  1942. desc = "unknown";
  1943. break;
  1944. }
  1945. printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
  1946. ioc->name, response_code, desc);
  1947. }
  1948. /**
  1949. * _scsih_tm_done - tm completion routine
  1950. * @ioc: per adapter object
  1951. * @smid: system request message index
  1952. * @msix_index: MSIX table index supplied by the OS
  1953. * @reply: reply message frame(lower 32bit addr)
  1954. * Context: none.
  1955. *
  1956. * The callback handler when using scsih_issue_tm.
  1957. *
  1958. * Return 1 meaning mf should be freed from _base_interrupt
  1959. * 0 means the mf is freed from this function.
  1960. */
  1961. static u8
  1962. _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  1963. {
  1964. MPI2DefaultReply_t *mpi_reply;
  1965. if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
  1966. return 1;
  1967. if (ioc->tm_cmds.smid != smid)
  1968. return 1;
  1969. mpt2sas_base_flush_reply_queues(ioc);
  1970. ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
  1971. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  1972. if (mpi_reply) {
  1973. memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  1974. ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
  1975. }
  1976. ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
  1977. complete(&ioc->tm_cmds.done);
  1978. return 1;
  1979. }
  1980. /**
  1981. * mpt2sas_scsih_set_tm_flag - set per target tm_busy
  1982. * @ioc: per adapter object
  1983. * @handle: device handle
  1984. *
  1985. * During taskmangement request, we need to freeze the device queue.
  1986. */
  1987. void
  1988. mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1989. {
  1990. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1991. struct scsi_device *sdev;
  1992. u8 skip = 0;
  1993. shost_for_each_device(sdev, ioc->shost) {
  1994. if (skip)
  1995. continue;
  1996. sas_device_priv_data = sdev->hostdata;
  1997. if (!sas_device_priv_data)
  1998. continue;
  1999. if (sas_device_priv_data->sas_target->handle == handle) {
  2000. sas_device_priv_data->sas_target->tm_busy = 1;
  2001. skip = 1;
  2002. ioc->ignore_loginfos = 1;
  2003. }
  2004. }
  2005. }
  2006. /**
  2007. * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
  2008. * @ioc: per adapter object
  2009. * @handle: device handle
  2010. *
  2011. * During taskmangement request, we need to freeze the device queue.
  2012. */
  2013. void
  2014. mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2015. {
  2016. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2017. struct scsi_device *sdev;
  2018. u8 skip = 0;
  2019. shost_for_each_device(sdev, ioc->shost) {
  2020. if (skip)
  2021. continue;
  2022. sas_device_priv_data = sdev->hostdata;
  2023. if (!sas_device_priv_data)
  2024. continue;
  2025. if (sas_device_priv_data->sas_target->handle == handle) {
  2026. sas_device_priv_data->sas_target->tm_busy = 0;
  2027. skip = 1;
  2028. ioc->ignore_loginfos = 0;
  2029. }
  2030. }
  2031. }
  2032. /**
  2033. * mpt2sas_scsih_issue_tm - main routine for sending tm requests
  2034. * @ioc: per adapter struct
  2035. * @device_handle: device handle
  2036. * @channel: the channel assigned by the OS
  2037. * @id: the id assigned by the OS
  2038. * @lun: lun number
  2039. * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
  2040. * @smid_task: smid assigned to the task
  2041. * @timeout: timeout in seconds
  2042. * @serial_number: the serial_number from scmd
  2043. * @m_type: TM_MUTEX_ON or TM_MUTEX_OFF
  2044. * Context: user
  2045. *
  2046. * A generic API for sending task management requests to firmware.
  2047. *
  2048. * The callback index is set inside `ioc->tm_cb_idx`.
  2049. *
  2050. * Return SUCCESS or FAILED.
  2051. */
  2052. int
  2053. mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint channel,
  2054. uint id, uint lun, u8 type, u16 smid_task, ulong timeout,
  2055. unsigned long serial_number, enum mutex_type m_type)
  2056. {
  2057. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2058. Mpi2SCSITaskManagementReply_t *mpi_reply;
  2059. u16 smid = 0;
  2060. u32 ioc_state;
  2061. unsigned long timeleft;
  2062. struct scsiio_tracker *scsi_lookup = NULL;
  2063. int rc;
  2064. if (m_type == TM_MUTEX_ON)
  2065. mutex_lock(&ioc->tm_cmds.mutex);
  2066. if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
  2067. printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
  2068. __func__, ioc->name);
  2069. rc = FAILED;
  2070. goto err_out;
  2071. }
  2072. if (ioc->shost_recovery || ioc->remove_host ||
  2073. ioc->pci_error_recovery) {
  2074. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  2075. __func__, ioc->name);
  2076. rc = FAILED;
  2077. goto err_out;
  2078. }
  2079. ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
  2080. if (ioc_state & MPI2_DOORBELL_USED) {
  2081. dhsprintk(ioc, printk(MPT2SAS_INFO_FMT "unexpected doorbell "
  2082. "active!\n", ioc->name));
  2083. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2084. FORCE_BIG_HAMMER);
  2085. rc = (!rc) ? SUCCESS : FAILED;
  2086. goto err_out;
  2087. }
  2088. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  2089. mpt2sas_base_fault_info(ioc, ioc_state &
  2090. MPI2_DOORBELL_DATA_MASK);
  2091. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2092. FORCE_BIG_HAMMER);
  2093. rc = (!rc) ? SUCCESS : FAILED;
  2094. goto err_out;
  2095. }
  2096. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
  2097. if (!smid) {
  2098. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2099. ioc->name, __func__);
  2100. rc = FAILED;
  2101. goto err_out;
  2102. }
  2103. if (type == MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK)
  2104. scsi_lookup = &ioc->scsi_lookup[smid_task - 1];
  2105. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
  2106. " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
  2107. smid_task));
  2108. ioc->tm_cmds.status = MPT2_CMD_PENDING;
  2109. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2110. ioc->tm_cmds.smid = smid;
  2111. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2112. memset(ioc->tm_cmds.reply, 0, sizeof(Mpi2SCSITaskManagementReply_t));
  2113. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2114. mpi_request->DevHandle = cpu_to_le16(handle);
  2115. mpi_request->TaskType = type;
  2116. mpi_request->TaskMID = cpu_to_le16(smid_task);
  2117. int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
  2118. mpt2sas_scsih_set_tm_flag(ioc, handle);
  2119. init_completion(&ioc->tm_cmds.done);
  2120. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2121. timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
  2122. if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
  2123. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  2124. ioc->name, __func__);
  2125. _debug_dump_mf(mpi_request,
  2126. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  2127. if (!(ioc->tm_cmds.status & MPT2_CMD_RESET)) {
  2128. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2129. FORCE_BIG_HAMMER);
  2130. rc = (!rc) ? SUCCESS : FAILED;
  2131. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  2132. mpt2sas_scsih_clear_tm_flag(ioc, handle);
  2133. goto err_out;
  2134. }
  2135. }
  2136. if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
  2137. mpi_reply = ioc->tm_cmds.reply;
  2138. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
  2139. "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
  2140. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  2141. le32_to_cpu(mpi_reply->IOCLogInfo),
  2142. le32_to_cpu(mpi_reply->TerminationCount)));
  2143. if (ioc->logging_level & MPT_DEBUG_TM) {
  2144. _scsih_response_code(ioc, mpi_reply->ResponseCode);
  2145. if (mpi_reply->IOCStatus)
  2146. _debug_dump_mf(mpi_request,
  2147. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  2148. }
  2149. }
  2150. switch (type) {
  2151. case MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK:
  2152. rc = SUCCESS;
  2153. if (scsi_lookup->scmd == NULL)
  2154. break;
  2155. rc = FAILED;
  2156. break;
  2157. case MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET:
  2158. if (_scsih_scsi_lookup_find_by_target(ioc, id, channel))
  2159. rc = FAILED;
  2160. else
  2161. rc = SUCCESS;
  2162. break;
  2163. case MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET:
  2164. case MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET:
  2165. if (_scsih_scsi_lookup_find_by_lun(ioc, id, lun, channel))
  2166. rc = FAILED;
  2167. else
  2168. rc = SUCCESS;
  2169. break;
  2170. case MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK:
  2171. rc = SUCCESS;
  2172. break;
  2173. default:
  2174. rc = FAILED;
  2175. break;
  2176. }
  2177. mpt2sas_scsih_clear_tm_flag(ioc, handle);
  2178. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  2179. if (m_type == TM_MUTEX_ON)
  2180. mutex_unlock(&ioc->tm_cmds.mutex);
  2181. return rc;
  2182. err_out:
  2183. if (m_type == TM_MUTEX_ON)
  2184. mutex_unlock(&ioc->tm_cmds.mutex);
  2185. return rc;
  2186. }
  2187. /**
  2188. * _scsih_tm_display_info - displays info about the device
  2189. * @ioc: per adapter struct
  2190. * @scmd: pointer to scsi command object
  2191. *
  2192. * Called by task management callback handlers.
  2193. */
  2194. static void
  2195. _scsih_tm_display_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd)
  2196. {
  2197. struct scsi_target *starget = scmd->device->sdev_target;
  2198. struct MPT2SAS_TARGET *priv_target = starget->hostdata;
  2199. struct _sas_device *sas_device = NULL;
  2200. unsigned long flags;
  2201. char *device_str = NULL;
  2202. if (!priv_target)
  2203. return;
  2204. if (ioc->hide_ir_msg)
  2205. device_str = "WarpDrive";
  2206. else
  2207. device_str = "volume";
  2208. scsi_print_command(scmd);
  2209. if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  2210. starget_printk(KERN_INFO, starget, "%s handle(0x%04x), "
  2211. "%s wwid(0x%016llx)\n", device_str, priv_target->handle,
  2212. device_str, (unsigned long long)priv_target->sas_address);
  2213. } else {
  2214. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2215. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  2216. priv_target->sas_address);
  2217. if (sas_device) {
  2218. if (priv_target->flags &
  2219. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2220. starget_printk(KERN_INFO, starget,
  2221. "volume handle(0x%04x), "
  2222. "volume wwid(0x%016llx)\n",
  2223. sas_device->volume_handle,
  2224. (unsigned long long)sas_device->volume_wwid);
  2225. }
  2226. starget_printk(KERN_INFO, starget,
  2227. "handle(0x%04x), sas_address(0x%016llx), phy(%d)\n",
  2228. sas_device->handle,
  2229. (unsigned long long)sas_device->sas_address,
  2230. sas_device->phy);
  2231. starget_printk(KERN_INFO, starget,
  2232. "enclosure_logical_id(0x%016llx), slot(%d)\n",
  2233. (unsigned long long)sas_device->enclosure_logical_id,
  2234. sas_device->slot);
  2235. }
  2236. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2237. }
  2238. }
  2239. /**
  2240. * _scsih_abort - eh threads main abort routine
  2241. * @scmd: pointer to scsi command object
  2242. *
  2243. * Returns SUCCESS if command aborted else FAILED
  2244. */
  2245. static int
  2246. _scsih_abort(struct scsi_cmnd *scmd)
  2247. {
  2248. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2249. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2250. u16 smid;
  2251. u16 handle;
  2252. int r;
  2253. sdev_printk(KERN_INFO, scmd->device, "attempting task abort! "
  2254. "scmd(%p)\n", scmd);
  2255. _scsih_tm_display_info(ioc, scmd);
  2256. sas_device_priv_data = scmd->device->hostdata;
  2257. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  2258. sdev_printk(KERN_INFO, scmd->device, "device been deleted! "
  2259. "scmd(%p)\n", scmd);
  2260. scmd->result = DID_NO_CONNECT << 16;
  2261. scmd->scsi_done(scmd);
  2262. r = SUCCESS;
  2263. goto out;
  2264. }
  2265. /* search for the command */
  2266. smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
  2267. if (!smid) {
  2268. scmd->result = DID_RESET << 16;
  2269. r = SUCCESS;
  2270. goto out;
  2271. }
  2272. /* for hidden raid components and volumes this is not supported */
  2273. if (sas_device_priv_data->sas_target->flags &
  2274. MPT_TARGET_FLAGS_RAID_COMPONENT ||
  2275. sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  2276. scmd->result = DID_RESET << 16;
  2277. r = FAILED;
  2278. goto out;
  2279. }
  2280. mpt2sas_halt_firmware(ioc);
  2281. handle = sas_device_priv_data->sas_target->handle;
  2282. r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
  2283. scmd->device->id, scmd->device->lun,
  2284. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
  2285. scmd->serial_number, TM_MUTEX_ON);
  2286. out:
  2287. sdev_printk(KERN_INFO, scmd->device, "task abort: %s scmd(%p)\n",
  2288. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2289. return r;
  2290. }
  2291. /**
  2292. * _scsih_dev_reset - eh threads main device reset routine
  2293. * @scmd: pointer to scsi command object
  2294. *
  2295. * Returns SUCCESS if command aborted else FAILED
  2296. */
  2297. static int
  2298. _scsih_dev_reset(struct scsi_cmnd *scmd)
  2299. {
  2300. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2301. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2302. struct _sas_device *sas_device;
  2303. unsigned long flags;
  2304. u16 handle;
  2305. int r;
  2306. struct scsi_target *starget = scmd->device->sdev_target;
  2307. starget_printk(KERN_INFO, starget, "attempting device reset! "
  2308. "scmd(%p)\n", scmd);
  2309. _scsih_tm_display_info(ioc, scmd);
  2310. sas_device_priv_data = scmd->device->hostdata;
  2311. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  2312. starget_printk(KERN_INFO, starget, "device been deleted! "
  2313. "scmd(%p)\n", scmd);
  2314. scmd->result = DID_NO_CONNECT << 16;
  2315. scmd->scsi_done(scmd);
  2316. r = SUCCESS;
  2317. goto out;
  2318. }
  2319. /* for hidden raid components obtain the volume_handle */
  2320. handle = 0;
  2321. if (sas_device_priv_data->sas_target->flags &
  2322. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2323. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2324. sas_device = _scsih_sas_device_find_by_handle(ioc,
  2325. sas_device_priv_data->sas_target->handle);
  2326. if (sas_device)
  2327. handle = sas_device->volume_handle;
  2328. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2329. } else
  2330. handle = sas_device_priv_data->sas_target->handle;
  2331. if (!handle) {
  2332. scmd->result = DID_RESET << 16;
  2333. r = FAILED;
  2334. goto out;
  2335. }
  2336. r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
  2337. scmd->device->id, scmd->device->lun,
  2338. MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, 0, 30, 0,
  2339. TM_MUTEX_ON);
  2340. out:
  2341. sdev_printk(KERN_INFO, scmd->device, "device reset: %s scmd(%p)\n",
  2342. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2343. return r;
  2344. }
  2345. /**
  2346. * _scsih_target_reset - eh threads main target reset routine
  2347. * @scmd: pointer to scsi command object
  2348. *
  2349. * Returns SUCCESS if command aborted else FAILED
  2350. */
  2351. static int
  2352. _scsih_target_reset(struct scsi_cmnd *scmd)
  2353. {
  2354. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2355. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2356. struct _sas_device *sas_device;
  2357. unsigned long flags;
  2358. u16 handle;
  2359. int r;
  2360. struct scsi_target *starget = scmd->device->sdev_target;
  2361. starget_printk(KERN_INFO, starget, "attempting target reset! "
  2362. "scmd(%p)\n", scmd);
  2363. _scsih_tm_display_info(ioc, scmd);
  2364. sas_device_priv_data = scmd->device->hostdata;
  2365. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  2366. starget_printk(KERN_INFO, starget, "target been deleted! "
  2367. "scmd(%p)\n", scmd);
  2368. scmd->result = DID_NO_CONNECT << 16;
  2369. scmd->scsi_done(scmd);
  2370. r = SUCCESS;
  2371. goto out;
  2372. }
  2373. /* for hidden raid components obtain the volume_handle */
  2374. handle = 0;
  2375. if (sas_device_priv_data->sas_target->flags &
  2376. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  2377. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2378. sas_device = _scsih_sas_device_find_by_handle(ioc,
  2379. sas_device_priv_data->sas_target->handle);
  2380. if (sas_device)
  2381. handle = sas_device->volume_handle;
  2382. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2383. } else
  2384. handle = sas_device_priv_data->sas_target->handle;
  2385. if (!handle) {
  2386. scmd->result = DID_RESET << 16;
  2387. r = FAILED;
  2388. goto out;
  2389. }
  2390. r = mpt2sas_scsih_issue_tm(ioc, handle, scmd->device->channel,
  2391. scmd->device->id, 0, MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0,
  2392. 30, 0, TM_MUTEX_ON);
  2393. out:
  2394. starget_printk(KERN_INFO, starget, "target reset: %s scmd(%p)\n",
  2395. ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2396. return r;
  2397. }
  2398. /**
  2399. * _scsih_host_reset - eh threads main host reset routine
  2400. * @scmd: pointer to scsi command object
  2401. *
  2402. * Returns SUCCESS if command aborted else FAILED
  2403. */
  2404. static int
  2405. _scsih_host_reset(struct scsi_cmnd *scmd)
  2406. {
  2407. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2408. int r, retval;
  2409. printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
  2410. ioc->name, scmd);
  2411. scsi_print_command(scmd);
  2412. retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  2413. FORCE_BIG_HAMMER);
  2414. r = (retval < 0) ? FAILED : SUCCESS;
  2415. printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
  2416. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  2417. return r;
  2418. }
  2419. /**
  2420. * _scsih_fw_event_add - insert and queue up fw_event
  2421. * @ioc: per adapter object
  2422. * @fw_event: object describing the event
  2423. * Context: This function will acquire ioc->fw_event_lock.
  2424. *
  2425. * This adds the firmware event object into link list, then queues it up to
  2426. * be processed from user context.
  2427. *
  2428. * Return nothing.
  2429. */
  2430. static void
  2431. _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
  2432. {
  2433. unsigned long flags;
  2434. if (ioc->firmware_event_thread == NULL)
  2435. return;
  2436. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2437. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  2438. INIT_DELAYED_WORK(&fw_event->delayed_work, _firmware_event_work);
  2439. queue_delayed_work(ioc->firmware_event_thread,
  2440. &fw_event->delayed_work, 0);
  2441. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2442. }
  2443. /**
  2444. * _scsih_fw_event_free - delete fw_event
  2445. * @ioc: per adapter object
  2446. * @fw_event: object describing the event
  2447. * Context: This function will acquire ioc->fw_event_lock.
  2448. *
  2449. * This removes firmware event object from link list, frees associated memory.
  2450. *
  2451. * Return nothing.
  2452. */
  2453. static void
  2454. _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  2455. *fw_event)
  2456. {
  2457. unsigned long flags;
  2458. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2459. list_del(&fw_event->list);
  2460. kfree(fw_event->event_data);
  2461. kfree(fw_event);
  2462. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2463. }
  2464. /**
  2465. * _scsih_error_recovery_delete_devices - remove devices not responding
  2466. * @ioc: per adapter object
  2467. *
  2468. * Return nothing.
  2469. */
  2470. static void
  2471. _scsih_error_recovery_delete_devices(struct MPT2SAS_ADAPTER *ioc)
  2472. {
  2473. struct fw_event_work *fw_event;
  2474. if (ioc->is_driver_loading)
  2475. return;
  2476. fw_event->event = MPT2SAS_REMOVE_UNRESPONDING_DEVICES;
  2477. fw_event->ioc = ioc;
  2478. _scsih_fw_event_add(ioc, fw_event);
  2479. }
  2480. /**
  2481. * mpt2sas_port_enable_complete - port enable completed (fake event)
  2482. * @ioc: per adapter object
  2483. *
  2484. * Return nothing.
  2485. */
  2486. void
  2487. mpt2sas_port_enable_complete(struct MPT2SAS_ADAPTER *ioc)
  2488. {
  2489. struct fw_event_work *fw_event;
  2490. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  2491. if (!fw_event)
  2492. return;
  2493. fw_event->event = MPT2SAS_PORT_ENABLE_COMPLETE;
  2494. fw_event->ioc = ioc;
  2495. _scsih_fw_event_add(ioc, fw_event);
  2496. }
  2497. /**
  2498. * _scsih_fw_event_cleanup_queue - cleanup event queue
  2499. * @ioc: per adapter object
  2500. *
  2501. * Walk the firmware event queue, either killing timers, or waiting
  2502. * for outstanding events to complete
  2503. *
  2504. * Return nothing.
  2505. */
  2506. static void
  2507. _scsih_fw_event_cleanup_queue(struct MPT2SAS_ADAPTER *ioc)
  2508. {
  2509. struct fw_event_work *fw_event, *next;
  2510. if (list_empty(&ioc->fw_event_list) ||
  2511. !ioc->firmware_event_thread || in_interrupt())
  2512. return;
  2513. list_for_each_entry_safe(fw_event, next, &ioc->fw_event_list, list) {
  2514. if (cancel_delayed_work(&fw_event->delayed_work)) {
  2515. _scsih_fw_event_free(ioc, fw_event);
  2516. continue;
  2517. }
  2518. fw_event->cancel_pending_work = 1;
  2519. }
  2520. }
  2521. /**
  2522. * _scsih_ublock_io_all_device - unblock every device
  2523. * @ioc: per adapter object
  2524. *
  2525. * change the device state from block to running
  2526. */
  2527. static void
  2528. _scsih_ublock_io_all_device(struct MPT2SAS_ADAPTER *ioc)
  2529. {
  2530. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2531. struct scsi_device *sdev;
  2532. shost_for_each_device(sdev, ioc->shost) {
  2533. sas_device_priv_data = sdev->hostdata;
  2534. if (!sas_device_priv_data)
  2535. continue;
  2536. if (!sas_device_priv_data->block)
  2537. continue;
  2538. sas_device_priv_data->block = 0;
  2539. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_running, "
  2540. "handle(0x%04x)\n",
  2541. sas_device_priv_data->sas_target->handle));
  2542. scsi_internal_device_unblock(sdev);
  2543. }
  2544. }
  2545. /**
  2546. * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
  2547. * @ioc: per adapter object
  2548. * @handle: device handle
  2549. *
  2550. * During device pull we need to appropiately set the sdev state.
  2551. */
  2552. static void
  2553. _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2554. {
  2555. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2556. struct scsi_device *sdev;
  2557. shost_for_each_device(sdev, ioc->shost) {
  2558. sas_device_priv_data = sdev->hostdata;
  2559. if (!sas_device_priv_data)
  2560. continue;
  2561. if (!sas_device_priv_data->block)
  2562. continue;
  2563. if (sas_device_priv_data->sas_target->handle == handle) {
  2564. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2565. MPT2SAS_INFO_FMT "SDEV_RUNNING: "
  2566. "handle(0x%04x)\n", ioc->name, handle));
  2567. sas_device_priv_data->block = 0;
  2568. scsi_internal_device_unblock(sdev);
  2569. }
  2570. }
  2571. }
  2572. /**
  2573. * _scsih_block_io_all_device - set the device state to SDEV_BLOCK
  2574. * @ioc: per adapter object
  2575. * @handle: device handle
  2576. *
  2577. * During device pull we need to appropiately set the sdev state.
  2578. */
  2579. static void
  2580. _scsih_block_io_all_device(struct MPT2SAS_ADAPTER *ioc)
  2581. {
  2582. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2583. struct scsi_device *sdev;
  2584. shost_for_each_device(sdev, ioc->shost) {
  2585. sas_device_priv_data = sdev->hostdata;
  2586. if (!sas_device_priv_data)
  2587. continue;
  2588. if (sas_device_priv_data->block)
  2589. continue;
  2590. sas_device_priv_data->block = 1;
  2591. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev, "device_blocked, "
  2592. "handle(0x%04x)\n",
  2593. sas_device_priv_data->sas_target->handle));
  2594. scsi_internal_device_block(sdev);
  2595. }
  2596. }
  2597. /**
  2598. * _scsih_block_io_device - set the device state to SDEV_BLOCK
  2599. * @ioc: per adapter object
  2600. * @handle: device handle
  2601. *
  2602. * During device pull we need to appropiately set the sdev state.
  2603. */
  2604. static void
  2605. _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2606. {
  2607. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2608. struct scsi_device *sdev;
  2609. shost_for_each_device(sdev, ioc->shost) {
  2610. sas_device_priv_data = sdev->hostdata;
  2611. if (!sas_device_priv_data)
  2612. continue;
  2613. if (sas_device_priv_data->block)
  2614. continue;
  2615. if (sas_device_priv_data->sas_target->handle == handle) {
  2616. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2617. MPT2SAS_INFO_FMT "SDEV_BLOCK: "
  2618. "handle(0x%04x)\n", ioc->name, handle));
  2619. sas_device_priv_data->block = 1;
  2620. scsi_internal_device_block(sdev);
  2621. }
  2622. }
  2623. }
  2624. /**
  2625. * _scsih_block_io_to_children_attached_to_ex
  2626. * @ioc: per adapter object
  2627. * @sas_expander: the sas_device object
  2628. *
  2629. * This routine set sdev state to SDEV_BLOCK for all devices
  2630. * attached to this expander. This function called when expander is
  2631. * pulled.
  2632. */
  2633. static void
  2634. _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
  2635. struct _sas_node *sas_expander)
  2636. {
  2637. struct _sas_port *mpt2sas_port;
  2638. struct _sas_device *sas_device;
  2639. struct _sas_node *expander_sibling;
  2640. unsigned long flags;
  2641. if (!sas_expander)
  2642. return;
  2643. list_for_each_entry(mpt2sas_port,
  2644. &sas_expander->sas_port_list, port_list) {
  2645. if (mpt2sas_port->remote_identify.device_type ==
  2646. SAS_END_DEVICE) {
  2647. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2648. sas_device =
  2649. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  2650. mpt2sas_port->remote_identify.sas_address);
  2651. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2652. if (!sas_device)
  2653. continue;
  2654. _scsih_block_io_device(ioc, sas_device->handle);
  2655. }
  2656. }
  2657. list_for_each_entry(mpt2sas_port,
  2658. &sas_expander->sas_port_list, port_list) {
  2659. if (mpt2sas_port->remote_identify.device_type ==
  2660. SAS_EDGE_EXPANDER_DEVICE ||
  2661. mpt2sas_port->remote_identify.device_type ==
  2662. SAS_FANOUT_EXPANDER_DEVICE) {
  2663. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2664. expander_sibling =
  2665. mpt2sas_scsih_expander_find_by_sas_address(
  2666. ioc, mpt2sas_port->remote_identify.sas_address);
  2667. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2668. _scsih_block_io_to_children_attached_to_ex(ioc,
  2669. expander_sibling);
  2670. }
  2671. }
  2672. }
  2673. /**
  2674. * _scsih_block_io_to_children_attached_directly
  2675. * @ioc: per adapter object
  2676. * @event_data: topology change event data
  2677. *
  2678. * This routine set sdev state to SDEV_BLOCK for all devices
  2679. * direct attached during device pull.
  2680. */
  2681. static void
  2682. _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
  2683. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2684. {
  2685. int i;
  2686. u16 handle;
  2687. u16 reason_code;
  2688. u8 phy_number;
  2689. for (i = 0; i < event_data->NumEntries; i++) {
  2690. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2691. if (!handle)
  2692. continue;
  2693. phy_number = event_data->StartPhyNum + i;
  2694. reason_code = event_data->PHY[i].PhyStatus &
  2695. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2696. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
  2697. _scsih_block_io_device(ioc, handle);
  2698. }
  2699. }
  2700. /**
  2701. * _scsih_tm_tr_send - send task management request
  2702. * @ioc: per adapter object
  2703. * @handle: device handle
  2704. * Context: interrupt time.
  2705. *
  2706. * This code is to initiate the device removal handshake protocol
  2707. * with controller firmware. This function will issue target reset
  2708. * using high priority request queue. It will send a sas iounit
  2709. * control request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
  2710. *
  2711. * This is designed to send muliple task management request at the same
  2712. * time to the fifo. If the fifo is full, we will append the request,
  2713. * and process it in a future completion.
  2714. */
  2715. static void
  2716. _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2717. {
  2718. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2719. u16 smid;
  2720. struct _sas_device *sas_device;
  2721. struct MPT2SAS_TARGET *sas_target_priv_data;
  2722. unsigned long flags;
  2723. struct _tr_list *delayed_tr;
  2724. if (ioc->shost_recovery || ioc->remove_host ||
  2725. ioc->pci_error_recovery) {
  2726. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2727. "progress!\n", __func__, ioc->name));
  2728. return;
  2729. }
  2730. /* if PD, then return */
  2731. if (test_bit(handle, ioc->pd_handles))
  2732. return;
  2733. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2734. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2735. if (sas_device && sas_device->starget &&
  2736. sas_device->starget->hostdata) {
  2737. sas_target_priv_data = sas_device->starget->hostdata;
  2738. sas_target_priv_data->deleted = 1;
  2739. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2740. "setting delete flag: handle(0x%04x), "
  2741. "sas_addr(0x%016llx)\n", ioc->name, handle,
  2742. (unsigned long long) sas_device->sas_address));
  2743. }
  2744. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2745. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
  2746. if (!smid) {
  2747. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2748. if (!delayed_tr)
  2749. return;
  2750. INIT_LIST_HEAD(&delayed_tr->list);
  2751. delayed_tr->handle = handle;
  2752. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
  2753. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2754. "DELAYED:tr:handle(0x%04x), (open)\n",
  2755. ioc->name, handle));
  2756. return;
  2757. }
  2758. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
  2759. "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
  2760. ioc->tm_tr_cb_idx));
  2761. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2762. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2763. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2764. mpi_request->DevHandle = cpu_to_le16(handle);
  2765. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  2766. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2767. }
  2768. /**
  2769. * _scsih_sas_control_complete - completion routine
  2770. * @ioc: per adapter object
  2771. * @smid: system request message index
  2772. * @msix_index: MSIX table index supplied by the OS
  2773. * @reply: reply message frame(lower 32bit addr)
  2774. * Context: interrupt time.
  2775. *
  2776. * This is the sas iounit control completion routine.
  2777. * This code is part of the code to initiate the device removal
  2778. * handshake protocol with controller firmware.
  2779. *
  2780. * Return 1 meaning mf should be freed from _base_interrupt
  2781. * 0 means the mf is freed from this function.
  2782. */
  2783. static u8
  2784. _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  2785. u8 msix_index, u32 reply)
  2786. {
  2787. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  2788. Mpi2SasIoUnitControlReply_t *mpi_reply =
  2789. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2790. #endif
  2791. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2792. "sc_complete:handle(0x%04x), (open) "
  2793. "smid(%d), ioc_status(0x%04x), loginfo(0x%08x)\n",
  2794. ioc->name, le16_to_cpu(mpi_reply->DevHandle), smid,
  2795. le16_to_cpu(mpi_reply->IOCStatus),
  2796. le32_to_cpu(mpi_reply->IOCLogInfo)));
  2797. return 1;
  2798. }
  2799. /**
  2800. * _scsih_tm_tr_volume_send - send target reset request for volumes
  2801. * @ioc: per adapter object
  2802. * @handle: device handle
  2803. * Context: interrupt time.
  2804. *
  2805. * This is designed to send muliple task management request at the same
  2806. * time to the fifo. If the fifo is full, we will append the request,
  2807. * and process it in a future completion.
  2808. */
  2809. static void
  2810. _scsih_tm_tr_volume_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2811. {
  2812. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2813. u16 smid;
  2814. struct _tr_list *delayed_tr;
  2815. if (ioc->shost_recovery || ioc->remove_host ||
  2816. ioc->pci_error_recovery) {
  2817. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2818. "progress!\n", __func__, ioc->name));
  2819. return;
  2820. }
  2821. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_volume_cb_idx);
  2822. if (!smid) {
  2823. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2824. if (!delayed_tr)
  2825. return;
  2826. INIT_LIST_HEAD(&delayed_tr->list);
  2827. delayed_tr->handle = handle;
  2828. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_volume_list);
  2829. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2830. "DELAYED:tr:handle(0x%04x), (open)\n",
  2831. ioc->name, handle));
  2832. return;
  2833. }
  2834. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "tr_send:handle(0x%04x), "
  2835. "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid,
  2836. ioc->tm_tr_volume_cb_idx));
  2837. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2838. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2839. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2840. mpi_request->DevHandle = cpu_to_le16(handle);
  2841. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  2842. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2843. }
  2844. /**
  2845. * _scsih_tm_volume_tr_complete - target reset completion
  2846. * @ioc: per adapter object
  2847. * @smid: system request message index
  2848. * @msix_index: MSIX table index supplied by the OS
  2849. * @reply: reply message frame(lower 32bit addr)
  2850. * Context: interrupt time.
  2851. *
  2852. * Return 1 meaning mf should be freed from _base_interrupt
  2853. * 0 means the mf is freed from this function.
  2854. */
  2855. static u8
  2856. _scsih_tm_volume_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  2857. u8 msix_index, u32 reply)
  2858. {
  2859. u16 handle;
  2860. Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
  2861. Mpi2SCSITaskManagementReply_t *mpi_reply =
  2862. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2863. if (ioc->shost_recovery || ioc->remove_host ||
  2864. ioc->pci_error_recovery) {
  2865. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2866. "progress!\n", __func__, ioc->name));
  2867. return 1;
  2868. }
  2869. mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
  2870. handle = le16_to_cpu(mpi_request_tm->DevHandle);
  2871. if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
  2872. dewtprintk(ioc, printk("spurious interrupt: "
  2873. "handle(0x%04x:0x%04x), smid(%d)!!!\n", handle,
  2874. le16_to_cpu(mpi_reply->DevHandle), smid));
  2875. return 0;
  2876. }
  2877. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2878. "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
  2879. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  2880. handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
  2881. le32_to_cpu(mpi_reply->IOCLogInfo),
  2882. le32_to_cpu(mpi_reply->TerminationCount)));
  2883. return _scsih_check_for_pending_tm(ioc, smid);
  2884. }
  2885. /**
  2886. * _scsih_tm_tr_complete -
  2887. * @ioc: per adapter object
  2888. * @smid: system request message index
  2889. * @msix_index: MSIX table index supplied by the OS
  2890. * @reply: reply message frame(lower 32bit addr)
  2891. * Context: interrupt time.
  2892. *
  2893. * This is the target reset completion routine.
  2894. * This code is part of the code to initiate the device removal
  2895. * handshake protocol with controller firmware.
  2896. * It will send a sas iounit control request (MPI2_SAS_OP_REMOVE_DEVICE)
  2897. *
  2898. * Return 1 meaning mf should be freed from _base_interrupt
  2899. * 0 means the mf is freed from this function.
  2900. */
  2901. static u8
  2902. _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  2903. u32 reply)
  2904. {
  2905. u16 handle;
  2906. Mpi2SCSITaskManagementRequest_t *mpi_request_tm;
  2907. Mpi2SCSITaskManagementReply_t *mpi_reply =
  2908. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2909. Mpi2SasIoUnitControlRequest_t *mpi_request;
  2910. u16 smid_sas_ctrl;
  2911. if (ioc->shost_recovery || ioc->remove_host ||
  2912. ioc->pci_error_recovery) {
  2913. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: host reset in "
  2914. "progress!\n", __func__, ioc->name));
  2915. return 1;
  2916. }
  2917. mpi_request_tm = mpt2sas_base_get_msg_frame(ioc, smid);
  2918. handle = le16_to_cpu(mpi_request_tm->DevHandle);
  2919. if (handle != le16_to_cpu(mpi_reply->DevHandle)) {
  2920. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "spurious interrupt: "
  2921. "handle(0x%04x:0x%04x), smid(%d)!!!\n", ioc->name, handle,
  2922. le16_to_cpu(mpi_reply->DevHandle), smid));
  2923. return 0;
  2924. }
  2925. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2926. "tr_complete:handle(0x%04x), (open) smid(%d), ioc_status(0x%04x), "
  2927. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  2928. handle, smid, le16_to_cpu(mpi_reply->IOCStatus),
  2929. le32_to_cpu(mpi_reply->IOCLogInfo),
  2930. le32_to_cpu(mpi_reply->TerminationCount)));
  2931. smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
  2932. if (!smid_sas_ctrl) {
  2933. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2934. ioc->name, __func__);
  2935. return 1;
  2936. }
  2937. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sc_send:handle(0x%04x), "
  2938. "(open), smid(%d), cb(%d)\n", ioc->name, handle, smid_sas_ctrl,
  2939. ioc->tm_sas_control_cb_idx));
  2940. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
  2941. memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  2942. mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  2943. mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  2944. mpi_request->DevHandle = mpi_request_tm->DevHandle;
  2945. mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
  2946. return _scsih_check_for_pending_tm(ioc, smid);
  2947. }
  2948. /**
  2949. * _scsih_check_for_pending_tm - check for pending task management
  2950. * @ioc: per adapter object
  2951. * @smid: system request message index
  2952. *
  2953. * This will check delayed target reset list, and feed the
  2954. * next reqeust.
  2955. *
  2956. * Return 1 meaning mf should be freed from _base_interrupt
  2957. * 0 means the mf is freed from this function.
  2958. */
  2959. static u8
  2960. _scsih_check_for_pending_tm(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  2961. {
  2962. struct _tr_list *delayed_tr;
  2963. if (!list_empty(&ioc->delayed_tr_volume_list)) {
  2964. delayed_tr = list_entry(ioc->delayed_tr_volume_list.next,
  2965. struct _tr_list, list);
  2966. mpt2sas_base_free_smid(ioc, smid);
  2967. _scsih_tm_tr_volume_send(ioc, delayed_tr->handle);
  2968. list_del(&delayed_tr->list);
  2969. kfree(delayed_tr);
  2970. return 0;
  2971. }
  2972. if (!list_empty(&ioc->delayed_tr_list)) {
  2973. delayed_tr = list_entry(ioc->delayed_tr_list.next,
  2974. struct _tr_list, list);
  2975. mpt2sas_base_free_smid(ioc, smid);
  2976. _scsih_tm_tr_send(ioc, delayed_tr->handle);
  2977. list_del(&delayed_tr->list);
  2978. kfree(delayed_tr);
  2979. return 0;
  2980. }
  2981. return 1;
  2982. }
  2983. /**
  2984. * _scsih_check_topo_delete_events - sanity check on topo events
  2985. * @ioc: per adapter object
  2986. * @event_data: the event data payload
  2987. *
  2988. * This routine added to better handle cable breaker.
  2989. *
  2990. * This handles the case where driver receives multiple expander
  2991. * add and delete events in a single shot. When there is a delete event
  2992. * the routine will void any pending add events waiting in the event queue.
  2993. *
  2994. * Return nothing.
  2995. */
  2996. static void
  2997. _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
  2998. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2999. {
  3000. struct fw_event_work *fw_event;
  3001. Mpi2EventDataSasTopologyChangeList_t *local_event_data;
  3002. u16 expander_handle;
  3003. struct _sas_node *sas_expander;
  3004. unsigned long flags;
  3005. int i, reason_code;
  3006. u16 handle;
  3007. for (i = 0 ; i < event_data->NumEntries; i++) {
  3008. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3009. if (!handle)
  3010. continue;
  3011. reason_code = event_data->PHY[i].PhyStatus &
  3012. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3013. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
  3014. _scsih_tm_tr_send(ioc, handle);
  3015. }
  3016. expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  3017. if (expander_handle < ioc->sas_hba.num_phys) {
  3018. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  3019. return;
  3020. }
  3021. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
  3022. || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
  3023. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3024. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  3025. expander_handle);
  3026. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3027. _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
  3028. } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
  3029. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  3030. if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
  3031. return;
  3032. /* mark ignore flag for pending events */
  3033. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  3034. list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
  3035. if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
  3036. fw_event->ignore)
  3037. continue;
  3038. local_event_data = fw_event->event_data;
  3039. if (local_event_data->ExpStatus ==
  3040. MPI2_EVENT_SAS_TOPO_ES_ADDED ||
  3041. local_event_data->ExpStatus ==
  3042. MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
  3043. if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
  3044. expander_handle) {
  3045. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  3046. "setting ignoring flag\n", ioc->name));
  3047. fw_event->ignore = 1;
  3048. }
  3049. }
  3050. }
  3051. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  3052. }
  3053. /**
  3054. * _scsih_set_volume_delete_flag - setting volume delete flag
  3055. * @ioc: per adapter object
  3056. * @handle: device handle
  3057. *
  3058. * This
  3059. * Return nothing.
  3060. */
  3061. static void
  3062. _scsih_set_volume_delete_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3063. {
  3064. struct _raid_device *raid_device;
  3065. struct MPT2SAS_TARGET *sas_target_priv_data;
  3066. unsigned long flags;
  3067. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  3068. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  3069. if (raid_device && raid_device->starget &&
  3070. raid_device->starget->hostdata) {
  3071. sas_target_priv_data =
  3072. raid_device->starget->hostdata;
  3073. sas_target_priv_data->deleted = 1;
  3074. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  3075. "setting delete flag: handle(0x%04x), "
  3076. "wwid(0x%016llx)\n", ioc->name, handle,
  3077. (unsigned long long) raid_device->wwid));
  3078. }
  3079. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  3080. }
  3081. /**
  3082. * _scsih_set_volume_handle_for_tr - set handle for target reset to volume
  3083. * @handle: input handle
  3084. * @a: handle for volume a
  3085. * @b: handle for volume b
  3086. *
  3087. * IR firmware only supports two raid volumes. The purpose of this
  3088. * routine is to set the volume handle in either a or b. When the given
  3089. * input handle is non-zero, or when a and b have not been set before.
  3090. */
  3091. static void
  3092. _scsih_set_volume_handle_for_tr(u16 handle, u16 *a, u16 *b)
  3093. {
  3094. if (!handle || handle == *a || handle == *b)
  3095. return;
  3096. if (!*a)
  3097. *a = handle;
  3098. else if (!*b)
  3099. *b = handle;
  3100. }
  3101. /**
  3102. * _scsih_check_ir_config_unhide_events - check for UNHIDE events
  3103. * @ioc: per adapter object
  3104. * @event_data: the event data payload
  3105. * Context: interrupt time.
  3106. *
  3107. * This routine will send target reset to volume, followed by target
  3108. * resets to the PDs. This is called when a PD has been removed, or
  3109. * volume has been deleted or removed. When the target reset is sent
  3110. * to volume, the PD target resets need to be queued to start upon
  3111. * completion of the volume target reset.
  3112. *
  3113. * Return nothing.
  3114. */
  3115. static void
  3116. _scsih_check_ir_config_unhide_events(struct MPT2SAS_ADAPTER *ioc,
  3117. Mpi2EventDataIrConfigChangeList_t *event_data)
  3118. {
  3119. Mpi2EventIrConfigElement_t *element;
  3120. int i;
  3121. u16 handle, volume_handle, a, b;
  3122. struct _tr_list *delayed_tr;
  3123. a = 0;
  3124. b = 0;
  3125. if (ioc->is_warpdrive)
  3126. return;
  3127. /* Volume Resets for Deleted or Removed */
  3128. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  3129. for (i = 0; i < event_data->NumElements; i++, element++) {
  3130. if (element->ReasonCode ==
  3131. MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED ||
  3132. element->ReasonCode ==
  3133. MPI2_EVENT_IR_CHANGE_RC_REMOVED) {
  3134. volume_handle = le16_to_cpu(element->VolDevHandle);
  3135. _scsih_set_volume_delete_flag(ioc, volume_handle);
  3136. _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
  3137. }
  3138. }
  3139. /* Volume Resets for UNHIDE events */
  3140. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  3141. for (i = 0; i < event_data->NumElements; i++, element++) {
  3142. if (le32_to_cpu(event_data->Flags) &
  3143. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG)
  3144. continue;
  3145. if (element->ReasonCode == MPI2_EVENT_IR_CHANGE_RC_UNHIDE) {
  3146. volume_handle = le16_to_cpu(element->VolDevHandle);
  3147. _scsih_set_volume_handle_for_tr(volume_handle, &a, &b);
  3148. }
  3149. }
  3150. if (a)
  3151. _scsih_tm_tr_volume_send(ioc, a);
  3152. if (b)
  3153. _scsih_tm_tr_volume_send(ioc, b);
  3154. /* PD target resets */
  3155. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  3156. for (i = 0; i < event_data->NumElements; i++, element++) {
  3157. if (element->ReasonCode != MPI2_EVENT_IR_CHANGE_RC_UNHIDE)
  3158. continue;
  3159. handle = le16_to_cpu(element->PhysDiskDevHandle);
  3160. volume_handle = le16_to_cpu(element->VolDevHandle);
  3161. clear_bit(handle, ioc->pd_handles);
  3162. if (!volume_handle)
  3163. _scsih_tm_tr_send(ioc, handle);
  3164. else if (volume_handle == a || volume_handle == b) {
  3165. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  3166. BUG_ON(!delayed_tr);
  3167. INIT_LIST_HEAD(&delayed_tr->list);
  3168. delayed_tr->handle = handle;
  3169. list_add_tail(&delayed_tr->list, &ioc->delayed_tr_list);
  3170. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  3171. "DELAYED:tr:handle(0x%04x), (open)\n", ioc->name,
  3172. handle));
  3173. } else
  3174. _scsih_tm_tr_send(ioc, handle);
  3175. }
  3176. }
  3177. /**
  3178. * _scsih_check_volume_delete_events - set delete flag for volumes
  3179. * @ioc: per adapter object
  3180. * @event_data: the event data payload
  3181. * Context: interrupt time.
  3182. *
  3183. * This will handle the case when the cable connected to entire volume is
  3184. * pulled. We will take care of setting the deleted flag so normal IO will
  3185. * not be sent.
  3186. *
  3187. * Return nothing.
  3188. */
  3189. static void
  3190. _scsih_check_volume_delete_events(struct MPT2SAS_ADAPTER *ioc,
  3191. Mpi2EventDataIrVolume_t *event_data)
  3192. {
  3193. u32 state;
  3194. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  3195. return;
  3196. state = le32_to_cpu(event_data->NewValue);
  3197. if (state == MPI2_RAID_VOL_STATE_MISSING || state ==
  3198. MPI2_RAID_VOL_STATE_FAILED)
  3199. _scsih_set_volume_delete_flag(ioc,
  3200. le16_to_cpu(event_data->VolDevHandle));
  3201. }
  3202. /**
  3203. * _scsih_flush_running_cmds - completing outstanding commands.
  3204. * @ioc: per adapter object
  3205. *
  3206. * The flushing out of all pending scmd commands following host reset,
  3207. * where all IO is dropped to the floor.
  3208. *
  3209. * Return nothing.
  3210. */
  3211. static void
  3212. _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
  3213. {
  3214. struct scsi_cmnd *scmd;
  3215. u16 smid;
  3216. u16 count = 0;
  3217. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  3218. scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
  3219. if (!scmd)
  3220. continue;
  3221. count++;
  3222. mpt2sas_base_free_smid(ioc, smid);
  3223. scsi_dma_unmap(scmd);
  3224. if (ioc->pci_error_recovery)
  3225. scmd->result = DID_NO_CONNECT << 16;
  3226. else
  3227. scmd->result = DID_RESET << 16;
  3228. scmd->scsi_done(scmd);
  3229. }
  3230. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
  3231. ioc->name, count));
  3232. }
  3233. /**
  3234. * _scsih_setup_eedp - setup MPI request for EEDP transfer
  3235. * @scmd: pointer to scsi command object
  3236. * @mpi_request: pointer to the SCSI_IO reqest message frame
  3237. *
  3238. * Supporting protection 1 and 3.
  3239. *
  3240. * Returns nothing
  3241. */
  3242. static void
  3243. _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
  3244. {
  3245. u16 eedp_flags;
  3246. unsigned char prot_op = scsi_get_prot_op(scmd);
  3247. unsigned char prot_type = scsi_get_prot_type(scmd);
  3248. if (prot_type == SCSI_PROT_DIF_TYPE0 || prot_op == SCSI_PROT_NORMAL)
  3249. return;
  3250. if (prot_op == SCSI_PROT_READ_STRIP)
  3251. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
  3252. else if (prot_op == SCSI_PROT_WRITE_INSERT)
  3253. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  3254. else
  3255. return;
  3256. switch (prot_type) {
  3257. case SCSI_PROT_DIF_TYPE1:
  3258. case SCSI_PROT_DIF_TYPE2:
  3259. /*
  3260. * enable ref/guard checking
  3261. * auto increment ref tag
  3262. */
  3263. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  3264. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  3265. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  3266. mpi_request->CDB.EEDP32.PrimaryReferenceTag =
  3267. cpu_to_be32(scsi_get_lba(scmd));
  3268. break;
  3269. case SCSI_PROT_DIF_TYPE3:
  3270. /*
  3271. * enable guard checking
  3272. */
  3273. eedp_flags |= MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  3274. break;
  3275. }
  3276. mpi_request->EEDPBlockSize = cpu_to_le32(scmd->device->sector_size);
  3277. mpi_request->EEDPFlags = cpu_to_le16(eedp_flags);
  3278. }
  3279. /**
  3280. * _scsih_eedp_error_handling - return sense code for EEDP errors
  3281. * @scmd: pointer to scsi command object
  3282. * @ioc_status: ioc status
  3283. *
  3284. * Returns nothing
  3285. */
  3286. static void
  3287. _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
  3288. {
  3289. u8 ascq;
  3290. u8 sk;
  3291. u8 host_byte;
  3292. switch (ioc_status) {
  3293. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  3294. ascq = 0x01;
  3295. break;
  3296. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  3297. ascq = 0x02;
  3298. break;
  3299. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  3300. ascq = 0x03;
  3301. break;
  3302. default:
  3303. ascq = 0x00;
  3304. break;
  3305. }
  3306. if (scmd->sc_data_direction == DMA_TO_DEVICE) {
  3307. sk = ILLEGAL_REQUEST;
  3308. host_byte = DID_ABORT;
  3309. } else {
  3310. sk = ABORTED_COMMAND;
  3311. host_byte = DID_OK;
  3312. }
  3313. scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
  3314. scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
  3315. SAM_STAT_CHECK_CONDITION;
  3316. }
  3317. /**
  3318. * _scsih_scsi_direct_io_get - returns direct io flag
  3319. * @ioc: per adapter object
  3320. * @smid: system request message index
  3321. *
  3322. * Returns the smid stored scmd pointer.
  3323. */
  3324. static inline u8
  3325. _scsih_scsi_direct_io_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  3326. {
  3327. return ioc->scsi_lookup[smid - 1].direct_io;
  3328. }
  3329. /**
  3330. * _scsih_scsi_direct_io_set - sets direct io flag
  3331. * @ioc: per adapter object
  3332. * @smid: system request message index
  3333. * @direct_io: Zero or non-zero value to set in the direct_io flag
  3334. *
  3335. * Returns Nothing.
  3336. */
  3337. static inline void
  3338. _scsih_scsi_direct_io_set(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 direct_io)
  3339. {
  3340. ioc->scsi_lookup[smid - 1].direct_io = direct_io;
  3341. }
  3342. /**
  3343. * _scsih_setup_direct_io - setup MPI request for WARPDRIVE Direct I/O
  3344. * @ioc: per adapter object
  3345. * @scmd: pointer to scsi command object
  3346. * @raid_device: pointer to raid device data structure
  3347. * @mpi_request: pointer to the SCSI_IO reqest message frame
  3348. * @smid: system request message index
  3349. *
  3350. * Returns nothing
  3351. */
  3352. static void
  3353. _scsih_setup_direct_io(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  3354. struct _raid_device *raid_device, Mpi2SCSIIORequest_t *mpi_request,
  3355. u16 smid)
  3356. {
  3357. u32 v_lba, p_lba, stripe_off, stripe_unit, column, io_size;
  3358. u32 stripe_sz, stripe_exp;
  3359. u8 num_pds, *cdb_ptr, *tmp_ptr, *lba_ptr1, *lba_ptr2;
  3360. u8 cdb0 = scmd->cmnd[0];
  3361. /*
  3362. * Try Direct I/O to RAID memeber disks
  3363. */
  3364. if (cdb0 == READ_16 || cdb0 == READ_10 ||
  3365. cdb0 == WRITE_16 || cdb0 == WRITE_10) {
  3366. cdb_ptr = mpi_request->CDB.CDB32;
  3367. if ((cdb0 < READ_16) || !(cdb_ptr[2] | cdb_ptr[3] | cdb_ptr[4]
  3368. | cdb_ptr[5])) {
  3369. io_size = scsi_bufflen(scmd) >> 9;
  3370. /* get virtual lba */
  3371. lba_ptr1 = lba_ptr2 = (cdb0 < READ_16) ? &cdb_ptr[2] :
  3372. &cdb_ptr[6];
  3373. tmp_ptr = (u8 *)&v_lba + 3;
  3374. *tmp_ptr-- = *lba_ptr1++;
  3375. *tmp_ptr-- = *lba_ptr1++;
  3376. *tmp_ptr-- = *lba_ptr1++;
  3377. *tmp_ptr = *lba_ptr1;
  3378. if (((u64)v_lba + (u64)io_size - 1) <=
  3379. (u32)raid_device->max_lba) {
  3380. stripe_sz = raid_device->stripe_sz;
  3381. stripe_exp = raid_device->stripe_exponent;
  3382. stripe_off = v_lba & (stripe_sz - 1);
  3383. /* Check whether IO falls within a stripe */
  3384. if ((stripe_off + io_size) <= stripe_sz) {
  3385. num_pds = raid_device->num_pds;
  3386. p_lba = v_lba >> stripe_exp;
  3387. stripe_unit = p_lba / num_pds;
  3388. column = p_lba % num_pds;
  3389. p_lba = (stripe_unit << stripe_exp) +
  3390. stripe_off;
  3391. mpi_request->DevHandle =
  3392. cpu_to_le16(raid_device->
  3393. pd_handle[column]);
  3394. tmp_ptr = (u8 *)&p_lba + 3;
  3395. *lba_ptr2++ = *tmp_ptr--;
  3396. *lba_ptr2++ = *tmp_ptr--;
  3397. *lba_ptr2++ = *tmp_ptr--;
  3398. *lba_ptr2 = *tmp_ptr;
  3399. /*
  3400. * WD: To indicate this I/O is directI/O
  3401. */
  3402. _scsih_scsi_direct_io_set(ioc, smid, 1);
  3403. }
  3404. }
  3405. }
  3406. }
  3407. }
  3408. /**
  3409. * _scsih_qcmd - main scsi request entry point
  3410. * @scmd: pointer to scsi command object
  3411. * @done: function pointer to be invoked on completion
  3412. *
  3413. * The callback index is set inside `ioc->scsi_io_cb_idx`.
  3414. *
  3415. * Returns 0 on success. If there's a failure, return either:
  3416. * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
  3417. * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
  3418. */
  3419. static int
  3420. _scsih_qcmd_lck(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
  3421. {
  3422. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  3423. struct MPT2SAS_DEVICE *sas_device_priv_data;
  3424. struct MPT2SAS_TARGET *sas_target_priv_data;
  3425. struct _raid_device *raid_device;
  3426. Mpi2SCSIIORequest_t *mpi_request;
  3427. u32 mpi_control;
  3428. u16 smid;
  3429. scmd->scsi_done = done;
  3430. sas_device_priv_data = scmd->device->hostdata;
  3431. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  3432. scmd->result = DID_NO_CONNECT << 16;
  3433. scmd->scsi_done(scmd);
  3434. return 0;
  3435. }
  3436. if (ioc->pci_error_recovery || ioc->remove_host) {
  3437. scmd->result = DID_NO_CONNECT << 16;
  3438. scmd->scsi_done(scmd);
  3439. return 0;
  3440. }
  3441. sas_target_priv_data = sas_device_priv_data->sas_target;
  3442. /* invalid device handle */
  3443. if (sas_target_priv_data->handle == MPT2SAS_INVALID_DEVICE_HANDLE) {
  3444. scmd->result = DID_NO_CONNECT << 16;
  3445. scmd->scsi_done(scmd);
  3446. return 0;
  3447. }
  3448. /* host recovery or link resets sent via IOCTLs */
  3449. if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
  3450. return SCSI_MLQUEUE_HOST_BUSY;
  3451. /* device busy with task management */
  3452. else if (sas_device_priv_data->block || sas_target_priv_data->tm_busy)
  3453. return SCSI_MLQUEUE_DEVICE_BUSY;
  3454. /* device has been deleted */
  3455. else if (sas_target_priv_data->deleted) {
  3456. scmd->result = DID_NO_CONNECT << 16;
  3457. scmd->scsi_done(scmd);
  3458. return 0;
  3459. }
  3460. if (scmd->sc_data_direction == DMA_FROM_DEVICE)
  3461. mpi_control = MPI2_SCSIIO_CONTROL_READ;
  3462. else if (scmd->sc_data_direction == DMA_TO_DEVICE)
  3463. mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
  3464. else
  3465. mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
  3466. /* set tags */
  3467. if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
  3468. if (scmd->device->tagged_supported) {
  3469. if (scmd->device->ordered_tags)
  3470. mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
  3471. else
  3472. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  3473. } else
  3474. /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
  3475. /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
  3476. */
  3477. mpi_control |= (0x500);
  3478. } else
  3479. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  3480. /* Make sure Device is not raid volume.
  3481. * We do not expose raid functionality to upper layer for warpdrive.
  3482. */
  3483. if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
  3484. sas_is_tlr_enabled(scmd->device) && scmd->cmd_len != 32)
  3485. mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
  3486. smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
  3487. if (!smid) {
  3488. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  3489. ioc->name, __func__);
  3490. goto out;
  3491. }
  3492. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3493. memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
  3494. _scsih_setup_eedp(scmd, mpi_request);
  3495. if (scmd->cmd_len == 32)
  3496. mpi_control |= 4 << MPI2_SCSIIO_CONTROL_ADDCDBLEN_SHIFT;
  3497. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  3498. if (sas_device_priv_data->sas_target->flags &
  3499. MPT_TARGET_FLAGS_RAID_COMPONENT)
  3500. mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  3501. else
  3502. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  3503. mpi_request->DevHandle =
  3504. cpu_to_le16(sas_device_priv_data->sas_target->handle);
  3505. mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
  3506. mpi_request->Control = cpu_to_le32(mpi_control);
  3507. mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
  3508. mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
  3509. mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  3510. mpi_request->SenseBufferLowAddress =
  3511. mpt2sas_base_get_sense_buffer_dma(ioc, smid);
  3512. mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
  3513. mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
  3514. MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
  3515. mpi_request->VF_ID = 0; /* TODO */
  3516. mpi_request->VP_ID = 0;
  3517. int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
  3518. mpi_request->LUN);
  3519. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  3520. if (!mpi_request->DataLength) {
  3521. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
  3522. } else {
  3523. if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
  3524. mpt2sas_base_free_smid(ioc, smid);
  3525. goto out;
  3526. }
  3527. }
  3528. raid_device = sas_target_priv_data->raid_device;
  3529. if (raid_device && raid_device->direct_io_enabled)
  3530. _scsih_setup_direct_io(ioc, scmd, raid_device, mpi_request,
  3531. smid);
  3532. if (likely(mpi_request->Function == MPI2_FUNCTION_SCSI_IO_REQUEST))
  3533. mpt2sas_base_put_smid_scsi_io(ioc, smid,
  3534. le16_to_cpu(mpi_request->DevHandle));
  3535. else
  3536. mpt2sas_base_put_smid_default(ioc, smid);
  3537. return 0;
  3538. out:
  3539. return SCSI_MLQUEUE_HOST_BUSY;
  3540. }
  3541. static DEF_SCSI_QCMD(_scsih_qcmd)
  3542. /**
  3543. * _scsih_normalize_sense - normalize descriptor and fixed format sense data
  3544. * @sense_buffer: sense data returned by target
  3545. * @data: normalized skey/asc/ascq
  3546. *
  3547. * Return nothing.
  3548. */
  3549. static void
  3550. _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
  3551. {
  3552. if ((sense_buffer[0] & 0x7F) >= 0x72) {
  3553. /* descriptor format */
  3554. data->skey = sense_buffer[1] & 0x0F;
  3555. data->asc = sense_buffer[2];
  3556. data->ascq = sense_buffer[3];
  3557. } else {
  3558. /* fixed format */
  3559. data->skey = sense_buffer[2] & 0x0F;
  3560. data->asc = sense_buffer[12];
  3561. data->ascq = sense_buffer[13];
  3562. }
  3563. }
  3564. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3565. /**
  3566. * _scsih_scsi_ioc_info - translated non-successful SCSI_IO request
  3567. * @ioc: per adapter object
  3568. * @scmd: pointer to scsi command object
  3569. * @mpi_reply: reply mf payload returned from firmware
  3570. *
  3571. * scsi_status - SCSI Status code returned from target device
  3572. * scsi_state - state info associated with SCSI_IO determined by ioc
  3573. * ioc_status - ioc supplied status info
  3574. *
  3575. * Return nothing.
  3576. */
  3577. static void
  3578. _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  3579. Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
  3580. {
  3581. u32 response_info;
  3582. u8 *response_bytes;
  3583. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  3584. MPI2_IOCSTATUS_MASK;
  3585. u8 scsi_state = mpi_reply->SCSIState;
  3586. u8 scsi_status = mpi_reply->SCSIStatus;
  3587. char *desc_ioc_state = NULL;
  3588. char *desc_scsi_status = NULL;
  3589. char *desc_scsi_state = ioc->tmp_string;
  3590. u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  3591. struct _sas_device *sas_device = NULL;
  3592. unsigned long flags;
  3593. struct scsi_target *starget = scmd->device->sdev_target;
  3594. struct MPT2SAS_TARGET *priv_target = starget->hostdata;
  3595. char *device_str = NULL;
  3596. if (!priv_target)
  3597. return;
  3598. if (ioc->hide_ir_msg)
  3599. device_str = "WarpDrive";
  3600. else
  3601. device_str = "volume";
  3602. if (log_info == 0x31170000)
  3603. return;
  3604. switch (ioc_status) {
  3605. case MPI2_IOCSTATUS_SUCCESS:
  3606. desc_ioc_state = "success";
  3607. break;
  3608. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  3609. desc_ioc_state = "invalid function";
  3610. break;
  3611. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  3612. desc_ioc_state = "scsi recovered error";
  3613. break;
  3614. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  3615. desc_ioc_state = "scsi invalid dev handle";
  3616. break;
  3617. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  3618. desc_ioc_state = "scsi device not there";
  3619. break;
  3620. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  3621. desc_ioc_state = "scsi data overrun";
  3622. break;
  3623. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  3624. desc_ioc_state = "scsi data underrun";
  3625. break;
  3626. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  3627. desc_ioc_state = "scsi io data error";
  3628. break;
  3629. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  3630. desc_ioc_state = "scsi protocol error";
  3631. break;
  3632. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  3633. desc_ioc_state = "scsi task terminated";
  3634. break;
  3635. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  3636. desc_ioc_state = "scsi residual mismatch";
  3637. break;
  3638. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  3639. desc_ioc_state = "scsi task mgmt failed";
  3640. break;
  3641. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  3642. desc_ioc_state = "scsi ioc terminated";
  3643. break;
  3644. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  3645. desc_ioc_state = "scsi ext terminated";
  3646. break;
  3647. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  3648. desc_ioc_state = "eedp guard error";
  3649. break;
  3650. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  3651. desc_ioc_state = "eedp ref tag error";
  3652. break;
  3653. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  3654. desc_ioc_state = "eedp app tag error";
  3655. break;
  3656. default:
  3657. desc_ioc_state = "unknown";
  3658. break;
  3659. }
  3660. switch (scsi_status) {
  3661. case MPI2_SCSI_STATUS_GOOD:
  3662. desc_scsi_status = "good";
  3663. break;
  3664. case MPI2_SCSI_STATUS_CHECK_CONDITION:
  3665. desc_scsi_status = "check condition";
  3666. break;
  3667. case MPI2_SCSI_STATUS_CONDITION_MET:
  3668. desc_scsi_status = "condition met";
  3669. break;
  3670. case MPI2_SCSI_STATUS_BUSY:
  3671. desc_scsi_status = "busy";
  3672. break;
  3673. case MPI2_SCSI_STATUS_INTERMEDIATE:
  3674. desc_scsi_status = "intermediate";
  3675. break;
  3676. case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
  3677. desc_scsi_status = "intermediate condmet";
  3678. break;
  3679. case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
  3680. desc_scsi_status = "reservation conflict";
  3681. break;
  3682. case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
  3683. desc_scsi_status = "command terminated";
  3684. break;
  3685. case MPI2_SCSI_STATUS_TASK_SET_FULL:
  3686. desc_scsi_status = "task set full";
  3687. break;
  3688. case MPI2_SCSI_STATUS_ACA_ACTIVE:
  3689. desc_scsi_status = "aca active";
  3690. break;
  3691. case MPI2_SCSI_STATUS_TASK_ABORTED:
  3692. desc_scsi_status = "task aborted";
  3693. break;
  3694. default:
  3695. desc_scsi_status = "unknown";
  3696. break;
  3697. }
  3698. desc_scsi_state[0] = '\0';
  3699. if (!scsi_state)
  3700. desc_scsi_state = " ";
  3701. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  3702. strcat(desc_scsi_state, "response info ");
  3703. if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3704. strcat(desc_scsi_state, "state terminated ");
  3705. if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
  3706. strcat(desc_scsi_state, "no status ");
  3707. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
  3708. strcat(desc_scsi_state, "autosense failed ");
  3709. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
  3710. strcat(desc_scsi_state, "autosense valid ");
  3711. scsi_print_command(scmd);
  3712. if (priv_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  3713. printk(MPT2SAS_WARN_FMT "\t%s wwid(0x%016llx)\n", ioc->name,
  3714. device_str, (unsigned long long)priv_target->sas_address);
  3715. } else {
  3716. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3717. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  3718. priv_target->sas_address);
  3719. if (sas_device) {
  3720. printk(MPT2SAS_WARN_FMT "\tsas_address(0x%016llx), "
  3721. "phy(%d)\n", ioc->name, sas_device->sas_address,
  3722. sas_device->phy);
  3723. printk(MPT2SAS_WARN_FMT
  3724. "\tenclosure_logical_id(0x%016llx), slot(%d)\n",
  3725. ioc->name, sas_device->enclosure_logical_id,
  3726. sas_device->slot);
  3727. }
  3728. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3729. }
  3730. printk(MPT2SAS_WARN_FMT "\thandle(0x%04x), ioc_status(%s)(0x%04x), "
  3731. "smid(%d)\n", ioc->name, le16_to_cpu(mpi_reply->DevHandle),
  3732. desc_ioc_state, ioc_status, smid);
  3733. printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
  3734. "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
  3735. scsi_get_resid(scmd));
  3736. printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
  3737. "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
  3738. le32_to_cpu(mpi_reply->TransferCount), scmd->result);
  3739. printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
  3740. "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
  3741. scsi_status, desc_scsi_state, scsi_state);
  3742. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  3743. struct sense_info data;
  3744. _scsih_normalize_sense(scmd->sense_buffer, &data);
  3745. printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
  3746. "[0x%02x,0x%02x,0x%02x], count(%d)\n", ioc->name, data.skey,
  3747. data.asc, data.ascq, le32_to_cpu(mpi_reply->SenseCount));
  3748. }
  3749. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
  3750. response_info = le32_to_cpu(mpi_reply->ResponseInfo);
  3751. response_bytes = (u8 *)&response_info;
  3752. _scsih_response_code(ioc, response_bytes[0]);
  3753. }
  3754. }
  3755. #endif
  3756. /**
  3757. * _scsih_turn_on_fault_led - illuminate Fault LED
  3758. * @ioc: per adapter object
  3759. * @handle: device handle
  3760. * Context: process
  3761. *
  3762. * Return nothing.
  3763. */
  3764. static void
  3765. _scsih_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3766. {
  3767. Mpi2SepReply_t mpi_reply;
  3768. Mpi2SepRequest_t mpi_request;
  3769. memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
  3770. mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  3771. mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
  3772. mpi_request.SlotStatus =
  3773. cpu_to_le32(MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT);
  3774. mpi_request.DevHandle = cpu_to_le16(handle);
  3775. mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
  3776. if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
  3777. &mpi_request)) != 0) {
  3778. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n", ioc->name,
  3779. __FILE__, __LINE__, __func__);
  3780. return;
  3781. }
  3782. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
  3783. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "enclosure_processor: "
  3784. "ioc_status (0x%04x), loginfo(0x%08x)\n", ioc->name,
  3785. le16_to_cpu(mpi_reply.IOCStatus),
  3786. le32_to_cpu(mpi_reply.IOCLogInfo)));
  3787. return;
  3788. }
  3789. }
  3790. /**
  3791. * _scsih_send_event_to_turn_on_fault_led - fire delayed event
  3792. * @ioc: per adapter object
  3793. * @handle: device handle
  3794. * Context: interrupt.
  3795. *
  3796. * Return nothing.
  3797. */
  3798. static void
  3799. _scsih_send_event_to_turn_on_fault_led(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3800. {
  3801. struct fw_event_work *fw_event;
  3802. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  3803. if (!fw_event)
  3804. return;
  3805. fw_event->event = MPT2SAS_TURN_ON_FAULT_LED;
  3806. fw_event->device_handle = handle;
  3807. fw_event->ioc = ioc;
  3808. _scsih_fw_event_add(ioc, fw_event);
  3809. }
  3810. /**
  3811. * _scsih_smart_predicted_fault - process smart errors
  3812. * @ioc: per adapter object
  3813. * @handle: device handle
  3814. * Context: interrupt.
  3815. *
  3816. * Return nothing.
  3817. */
  3818. static void
  3819. _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3820. {
  3821. struct scsi_target *starget;
  3822. struct MPT2SAS_TARGET *sas_target_priv_data;
  3823. Mpi2EventNotificationReply_t *event_reply;
  3824. Mpi2EventDataSasDeviceStatusChange_t *event_data;
  3825. struct _sas_device *sas_device;
  3826. ssize_t sz;
  3827. unsigned long flags;
  3828. /* only handle non-raid devices */
  3829. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3830. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  3831. if (!sas_device) {
  3832. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3833. return;
  3834. }
  3835. starget = sas_device->starget;
  3836. sas_target_priv_data = starget->hostdata;
  3837. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
  3838. ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
  3839. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3840. return;
  3841. }
  3842. starget_printk(KERN_WARNING, starget, "predicted fault\n");
  3843. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3844. if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM)
  3845. _scsih_send_event_to_turn_on_fault_led(ioc, handle);
  3846. /* insert into event log */
  3847. sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
  3848. sizeof(Mpi2EventDataSasDeviceStatusChange_t);
  3849. event_reply = kzalloc(sz, GFP_KERNEL);
  3850. if (!event_reply) {
  3851. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3852. ioc->name, __FILE__, __LINE__, __func__);
  3853. return;
  3854. }
  3855. event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
  3856. event_reply->Event =
  3857. cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
  3858. event_reply->MsgLength = sz/4;
  3859. event_reply->EventDataLength =
  3860. cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
  3861. event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
  3862. event_reply->EventData;
  3863. event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
  3864. event_data->ASC = 0x5D;
  3865. event_data->DevHandle = cpu_to_le16(handle);
  3866. event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
  3867. mpt2sas_ctl_add_to_event_log(ioc, event_reply);
  3868. kfree(event_reply);
  3869. }
  3870. /**
  3871. * _scsih_io_done - scsi request callback
  3872. * @ioc: per adapter object
  3873. * @smid: system request message index
  3874. * @msix_index: MSIX table index supplied by the OS
  3875. * @reply: reply message frame(lower 32bit addr)
  3876. *
  3877. * Callback handler when using _scsih_qcmd.
  3878. *
  3879. * Return 1 meaning mf should be freed from _base_interrupt
  3880. * 0 means the mf is freed from this function.
  3881. */
  3882. static u8
  3883. _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  3884. {
  3885. Mpi2SCSIIORequest_t *mpi_request;
  3886. Mpi2SCSIIOReply_t *mpi_reply;
  3887. struct scsi_cmnd *scmd;
  3888. u16 ioc_status;
  3889. u32 xfer_cnt;
  3890. u8 scsi_state;
  3891. u8 scsi_status;
  3892. u32 log_info;
  3893. struct MPT2SAS_DEVICE *sas_device_priv_data;
  3894. u32 response_code = 0;
  3895. unsigned long flags;
  3896. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  3897. scmd = _scsih_scsi_lookup_get_clear(ioc, smid);
  3898. if (scmd == NULL)
  3899. return 1;
  3900. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  3901. if (mpi_reply == NULL) {
  3902. scmd->result = DID_OK << 16;
  3903. goto out;
  3904. }
  3905. sas_device_priv_data = scmd->device->hostdata;
  3906. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  3907. sas_device_priv_data->sas_target->deleted) {
  3908. scmd->result = DID_NO_CONNECT << 16;
  3909. goto out;
  3910. }
  3911. /*
  3912. * WARPDRIVE: If direct_io is set then it is directIO,
  3913. * the failed direct I/O should be redirected to volume
  3914. */
  3915. if (_scsih_scsi_direct_io_get(ioc, smid)) {
  3916. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  3917. ioc->scsi_lookup[smid - 1].scmd = scmd;
  3918. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  3919. _scsih_scsi_direct_io_set(ioc, smid, 0);
  3920. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  3921. mpi_request->DevHandle =
  3922. cpu_to_le16(sas_device_priv_data->sas_target->handle);
  3923. mpt2sas_base_put_smid_scsi_io(ioc, smid,
  3924. sas_device_priv_data->sas_target->handle);
  3925. return 0;
  3926. }
  3927. /* turning off TLR */
  3928. scsi_state = mpi_reply->SCSIState;
  3929. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  3930. response_code =
  3931. le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
  3932. if (!sas_device_priv_data->tlr_snoop_check) {
  3933. sas_device_priv_data->tlr_snoop_check++;
  3934. /* Make sure Device is not raid volume.
  3935. * We do not expose raid functionality to upper layer for warpdrive.
  3936. */
  3937. if (!ioc->is_warpdrive && !_scsih_is_raid(&scmd->device->sdev_gendev) &&
  3938. sas_is_tlr_enabled(scmd->device) &&
  3939. response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME) {
  3940. sas_disable_tlr(scmd->device);
  3941. sdev_printk(KERN_INFO, scmd->device, "TLR disabled\n");
  3942. }
  3943. }
  3944. xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
  3945. scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
  3946. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  3947. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  3948. log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  3949. else
  3950. log_info = 0;
  3951. ioc_status &= MPI2_IOCSTATUS_MASK;
  3952. scsi_status = mpi_reply->SCSIStatus;
  3953. if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  3954. (scsi_status == MPI2_SCSI_STATUS_BUSY ||
  3955. scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
  3956. scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
  3957. ioc_status = MPI2_IOCSTATUS_SUCCESS;
  3958. }
  3959. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  3960. struct sense_info data;
  3961. const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
  3962. smid);
  3963. u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
  3964. le32_to_cpu(mpi_reply->SenseCount));
  3965. memcpy(scmd->sense_buffer, sense_data, sz);
  3966. _scsih_normalize_sense(scmd->sense_buffer, &data);
  3967. /* failure prediction threshold exceeded */
  3968. if (data.asc == 0x5D)
  3969. _scsih_smart_predicted_fault(ioc,
  3970. le16_to_cpu(mpi_reply->DevHandle));
  3971. }
  3972. switch (ioc_status) {
  3973. case MPI2_IOCSTATUS_BUSY:
  3974. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  3975. scmd->result = SAM_STAT_BUSY;
  3976. break;
  3977. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  3978. scmd->result = DID_NO_CONNECT << 16;
  3979. break;
  3980. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  3981. if (sas_device_priv_data->block) {
  3982. scmd->result = DID_TRANSPORT_DISRUPTED << 16;
  3983. goto out;
  3984. }
  3985. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  3986. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  3987. scmd->result = DID_RESET << 16;
  3988. break;
  3989. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  3990. if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
  3991. scmd->result = DID_SOFT_ERROR << 16;
  3992. else
  3993. scmd->result = (DID_OK << 16) | scsi_status;
  3994. break;
  3995. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  3996. scmd->result = (DID_OK << 16) | scsi_status;
  3997. if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
  3998. break;
  3999. if (xfer_cnt < scmd->underflow) {
  4000. if (scsi_status == SAM_STAT_BUSY)
  4001. scmd->result = SAM_STAT_BUSY;
  4002. else
  4003. scmd->result = DID_SOFT_ERROR << 16;
  4004. } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  4005. MPI2_SCSI_STATE_NO_SCSI_STATUS))
  4006. scmd->result = DID_SOFT_ERROR << 16;
  4007. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  4008. scmd->result = DID_RESET << 16;
  4009. else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
  4010. mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
  4011. mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
  4012. scmd->result = (DRIVER_SENSE << 24) |
  4013. SAM_STAT_CHECK_CONDITION;
  4014. scmd->sense_buffer[0] = 0x70;
  4015. scmd->sense_buffer[2] = ILLEGAL_REQUEST;
  4016. scmd->sense_buffer[12] = 0x20;
  4017. scmd->sense_buffer[13] = 0;
  4018. }
  4019. break;
  4020. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  4021. scsi_set_resid(scmd, 0);
  4022. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  4023. case MPI2_IOCSTATUS_SUCCESS:
  4024. scmd->result = (DID_OK << 16) | scsi_status;
  4025. if (response_code ==
  4026. MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
  4027. (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  4028. MPI2_SCSI_STATE_NO_SCSI_STATUS)))
  4029. scmd->result = DID_SOFT_ERROR << 16;
  4030. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  4031. scmd->result = DID_RESET << 16;
  4032. break;
  4033. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  4034. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  4035. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  4036. _scsih_eedp_error_handling(scmd, ioc_status);
  4037. break;
  4038. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  4039. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  4040. case MPI2_IOCSTATUS_INVALID_SGL:
  4041. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  4042. case MPI2_IOCSTATUS_INVALID_FIELD:
  4043. case MPI2_IOCSTATUS_INVALID_STATE:
  4044. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  4045. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  4046. default:
  4047. scmd->result = DID_SOFT_ERROR << 16;
  4048. break;
  4049. }
  4050. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4051. if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
  4052. _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
  4053. #endif
  4054. out:
  4055. scsi_dma_unmap(scmd);
  4056. scmd->scsi_done(scmd);
  4057. return 1;
  4058. }
  4059. /**
  4060. * _scsih_sas_host_refresh - refreshing sas host object contents
  4061. * @ioc: per adapter object
  4062. * Context: user
  4063. *
  4064. * During port enable, fw will send topology events for every device. Its
  4065. * possible that the handles may change from the previous setting, so this
  4066. * code keeping handles updating if changed.
  4067. *
  4068. * Return nothing.
  4069. */
  4070. static void
  4071. _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
  4072. {
  4073. u16 sz;
  4074. u16 ioc_status;
  4075. int i;
  4076. Mpi2ConfigReply_t mpi_reply;
  4077. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  4078. u16 attached_handle;
  4079. u8 link_rate;
  4080. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
  4081. "updating handles for sas_host(0x%016llx)\n",
  4082. ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
  4083. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
  4084. * sizeof(Mpi2SasIOUnit0PhyData_t));
  4085. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  4086. if (!sas_iounit_pg0) {
  4087. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4088. ioc->name, __FILE__, __LINE__, __func__);
  4089. return;
  4090. }
  4091. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  4092. sas_iounit_pg0, sz)) != 0)
  4093. goto out;
  4094. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  4095. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  4096. goto out;
  4097. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  4098. link_rate = sas_iounit_pg0->PhyData[i].NegotiatedLinkRate >> 4;
  4099. if (i == 0)
  4100. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  4101. PhyData[0].ControllerDevHandle);
  4102. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  4103. attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
  4104. AttachedDevHandle);
  4105. if (attached_handle && link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  4106. link_rate = MPI2_SAS_NEG_LINK_RATE_1_5;
  4107. mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
  4108. attached_handle, i, link_rate);
  4109. }
  4110. out:
  4111. kfree(sas_iounit_pg0);
  4112. }
  4113. /**
  4114. * _scsih_sas_host_add - create sas host object
  4115. * @ioc: per adapter object
  4116. *
  4117. * Creating host side data object, stored in ioc->sas_hba
  4118. *
  4119. * Return nothing.
  4120. */
  4121. static void
  4122. _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
  4123. {
  4124. int i;
  4125. Mpi2ConfigReply_t mpi_reply;
  4126. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  4127. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  4128. Mpi2SasPhyPage0_t phy_pg0;
  4129. Mpi2SasDevicePage0_t sas_device_pg0;
  4130. Mpi2SasEnclosurePage0_t enclosure_pg0;
  4131. u16 ioc_status;
  4132. u16 sz;
  4133. u16 device_missing_delay;
  4134. mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
  4135. if (!ioc->sas_hba.num_phys) {
  4136. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4137. ioc->name, __FILE__, __LINE__, __func__);
  4138. return;
  4139. }
  4140. /* sas_iounit page 0 */
  4141. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
  4142. sizeof(Mpi2SasIOUnit0PhyData_t));
  4143. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  4144. if (!sas_iounit_pg0) {
  4145. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4146. ioc->name, __FILE__, __LINE__, __func__);
  4147. return;
  4148. }
  4149. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  4150. sas_iounit_pg0, sz))) {
  4151. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4152. ioc->name, __FILE__, __LINE__, __func__);
  4153. goto out;
  4154. }
  4155. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4156. MPI2_IOCSTATUS_MASK;
  4157. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4158. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4159. ioc->name, __FILE__, __LINE__, __func__);
  4160. goto out;
  4161. }
  4162. /* sas_iounit page 1 */
  4163. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  4164. sizeof(Mpi2SasIOUnit1PhyData_t));
  4165. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  4166. if (!sas_iounit_pg1) {
  4167. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4168. ioc->name, __FILE__, __LINE__, __func__);
  4169. goto out;
  4170. }
  4171. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  4172. sas_iounit_pg1, sz))) {
  4173. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4174. ioc->name, __FILE__, __LINE__, __func__);
  4175. goto out;
  4176. }
  4177. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4178. MPI2_IOCSTATUS_MASK;
  4179. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4180. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4181. ioc->name, __FILE__, __LINE__, __func__);
  4182. goto out;
  4183. }
  4184. ioc->io_missing_delay =
  4185. le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
  4186. device_missing_delay =
  4187. le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
  4188. if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  4189. ioc->device_missing_delay = (device_missing_delay &
  4190. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  4191. else
  4192. ioc->device_missing_delay = device_missing_delay &
  4193. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  4194. ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
  4195. ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
  4196. sizeof(struct _sas_phy), GFP_KERNEL);
  4197. if (!ioc->sas_hba.phy) {
  4198. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4199. ioc->name, __FILE__, __LINE__, __func__);
  4200. goto out;
  4201. }
  4202. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  4203. if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  4204. i))) {
  4205. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4206. ioc->name, __FILE__, __LINE__, __func__);
  4207. goto out;
  4208. }
  4209. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4210. MPI2_IOCSTATUS_MASK;
  4211. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4212. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4213. ioc->name, __FILE__, __LINE__, __func__);
  4214. goto out;
  4215. }
  4216. if (i == 0)
  4217. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  4218. PhyData[0].ControllerDevHandle);
  4219. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  4220. ioc->sas_hba.phy[i].phy_id = i;
  4221. mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
  4222. phy_pg0, ioc->sas_hba.parent_dev);
  4223. }
  4224. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4225. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
  4226. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4227. ioc->name, __FILE__, __LINE__, __func__);
  4228. goto out;
  4229. }
  4230. ioc->sas_hba.enclosure_handle =
  4231. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  4232. ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4233. printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
  4234. "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
  4235. (unsigned long long) ioc->sas_hba.sas_address,
  4236. ioc->sas_hba.num_phys) ;
  4237. if (ioc->sas_hba.enclosure_handle) {
  4238. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  4239. &enclosure_pg0,
  4240. MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  4241. ioc->sas_hba.enclosure_handle))) {
  4242. ioc->sas_hba.enclosure_logical_id =
  4243. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  4244. }
  4245. }
  4246. out:
  4247. kfree(sas_iounit_pg1);
  4248. kfree(sas_iounit_pg0);
  4249. }
  4250. /**
  4251. * _scsih_expander_add - creating expander object
  4252. * @ioc: per adapter object
  4253. * @handle: expander handle
  4254. *
  4255. * Creating expander object, stored in ioc->sas_expander_list.
  4256. *
  4257. * Return 0 for success, else error.
  4258. */
  4259. static int
  4260. _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  4261. {
  4262. struct _sas_node *sas_expander;
  4263. Mpi2ConfigReply_t mpi_reply;
  4264. Mpi2ExpanderPage0_t expander_pg0;
  4265. Mpi2ExpanderPage1_t expander_pg1;
  4266. Mpi2SasEnclosurePage0_t enclosure_pg0;
  4267. u32 ioc_status;
  4268. u16 parent_handle;
  4269. u64 sas_address, sas_address_parent = 0;
  4270. int i;
  4271. unsigned long flags;
  4272. struct _sas_port *mpt2sas_port = NULL;
  4273. int rc = 0;
  4274. if (!handle)
  4275. return -1;
  4276. if (ioc->shost_recovery || ioc->pci_error_recovery)
  4277. return -1;
  4278. if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  4279. MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
  4280. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4281. ioc->name, __FILE__, __LINE__, __func__);
  4282. return -1;
  4283. }
  4284. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4285. MPI2_IOCSTATUS_MASK;
  4286. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4287. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4288. ioc->name, __FILE__, __LINE__, __func__);
  4289. return -1;
  4290. }
  4291. /* handle out of order topology events */
  4292. parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
  4293. if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
  4294. != 0) {
  4295. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4296. ioc->name, __FILE__, __LINE__, __func__);
  4297. return -1;
  4298. }
  4299. if (sas_address_parent != ioc->sas_hba.sas_address) {
  4300. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4301. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  4302. sas_address_parent);
  4303. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4304. if (!sas_expander) {
  4305. rc = _scsih_expander_add(ioc, parent_handle);
  4306. if (rc != 0)
  4307. return rc;
  4308. }
  4309. }
  4310. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4311. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  4312. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  4313. sas_address);
  4314. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4315. if (sas_expander)
  4316. return 0;
  4317. sas_expander = kzalloc(sizeof(struct _sas_node),
  4318. GFP_KERNEL);
  4319. if (!sas_expander) {
  4320. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4321. ioc->name, __FILE__, __LINE__, __func__);
  4322. return -1;
  4323. }
  4324. sas_expander->handle = handle;
  4325. sas_expander->num_phys = expander_pg0.NumPhys;
  4326. sas_expander->sas_address_parent = sas_address_parent;
  4327. sas_expander->sas_address = sas_address;
  4328. printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
  4329. " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
  4330. handle, parent_handle, (unsigned long long)
  4331. sas_expander->sas_address, sas_expander->num_phys);
  4332. if (!sas_expander->num_phys)
  4333. goto out_fail;
  4334. sas_expander->phy = kcalloc(sas_expander->num_phys,
  4335. sizeof(struct _sas_phy), GFP_KERNEL);
  4336. if (!sas_expander->phy) {
  4337. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4338. ioc->name, __FILE__, __LINE__, __func__);
  4339. rc = -1;
  4340. goto out_fail;
  4341. }
  4342. INIT_LIST_HEAD(&sas_expander->sas_port_list);
  4343. mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
  4344. sas_address_parent);
  4345. if (!mpt2sas_port) {
  4346. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4347. ioc->name, __FILE__, __LINE__, __func__);
  4348. rc = -1;
  4349. goto out_fail;
  4350. }
  4351. sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
  4352. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  4353. if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
  4354. &expander_pg1, i, handle))) {
  4355. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4356. ioc->name, __FILE__, __LINE__, __func__);
  4357. rc = -1;
  4358. goto out_fail;
  4359. }
  4360. sas_expander->phy[i].handle = handle;
  4361. sas_expander->phy[i].phy_id = i;
  4362. if ((mpt2sas_transport_add_expander_phy(ioc,
  4363. &sas_expander->phy[i], expander_pg1,
  4364. sas_expander->parent_dev))) {
  4365. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4366. ioc->name, __FILE__, __LINE__, __func__);
  4367. rc = -1;
  4368. goto out_fail;
  4369. }
  4370. }
  4371. if (sas_expander->enclosure_handle) {
  4372. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  4373. &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  4374. sas_expander->enclosure_handle))) {
  4375. sas_expander->enclosure_logical_id =
  4376. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  4377. }
  4378. }
  4379. _scsih_expander_node_add(ioc, sas_expander);
  4380. return 0;
  4381. out_fail:
  4382. if (mpt2sas_port)
  4383. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  4384. sas_address_parent);
  4385. kfree(sas_expander);
  4386. return rc;
  4387. }
  4388. /**
  4389. * _scsih_done - scsih callback handler.
  4390. * @ioc: per adapter object
  4391. * @smid: system request message index
  4392. * @msix_index: MSIX table index supplied by the OS
  4393. * @reply: reply message frame(lower 32bit addr)
  4394. *
  4395. * Callback handler when sending internal generated message frames.
  4396. * The callback index passed is `ioc->scsih_cb_idx`
  4397. *
  4398. * Return 1 meaning mf should be freed from _base_interrupt
  4399. * 0 means the mf is freed from this function.
  4400. */
  4401. static u8
  4402. _scsih_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  4403. {
  4404. MPI2DefaultReply_t *mpi_reply;
  4405. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  4406. if (ioc->scsih_cmds.status == MPT2_CMD_NOT_USED)
  4407. return 1;
  4408. if (ioc->scsih_cmds.smid != smid)
  4409. return 1;
  4410. ioc->scsih_cmds.status |= MPT2_CMD_COMPLETE;
  4411. if (mpi_reply) {
  4412. memcpy(ioc->scsih_cmds.reply, mpi_reply,
  4413. mpi_reply->MsgLength*4);
  4414. ioc->scsih_cmds.status |= MPT2_CMD_REPLY_VALID;
  4415. }
  4416. ioc->scsih_cmds.status &= ~MPT2_CMD_PENDING;
  4417. complete(&ioc->scsih_cmds.done);
  4418. return 1;
  4419. }
  4420. /**
  4421. * mpt2sas_expander_remove - removing expander object
  4422. * @ioc: per adapter object
  4423. * @sas_address: expander sas_address
  4424. *
  4425. * Return nothing.
  4426. */
  4427. void
  4428. mpt2sas_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
  4429. {
  4430. struct _sas_node *sas_expander;
  4431. unsigned long flags;
  4432. if (ioc->shost_recovery)
  4433. return;
  4434. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4435. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  4436. sas_address);
  4437. if (!sas_expander) {
  4438. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4439. return;
  4440. }
  4441. list_del(&sas_expander->list);
  4442. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4443. _scsih_expander_node_remove(ioc, sas_expander);
  4444. }
  4445. /**
  4446. * _scsih_check_access_status - check access flags
  4447. * @ioc: per adapter object
  4448. * @sas_address: sas address
  4449. * @handle: sas device handle
  4450. * @access_flags: errors returned during discovery of the device
  4451. *
  4452. * Return 0 for success, else failure
  4453. */
  4454. static u8
  4455. _scsih_check_access_status(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  4456. u16 handle, u8 access_status)
  4457. {
  4458. u8 rc = 1;
  4459. char *desc = NULL;
  4460. switch (access_status) {
  4461. case MPI2_SAS_DEVICE0_ASTATUS_NO_ERRORS:
  4462. case MPI2_SAS_DEVICE0_ASTATUS_SATA_NEEDS_INITIALIZATION:
  4463. rc = 0;
  4464. break;
  4465. case MPI2_SAS_DEVICE0_ASTATUS_SATA_CAPABILITY_FAILED:
  4466. desc = "sata capability failed";
  4467. break;
  4468. case MPI2_SAS_DEVICE0_ASTATUS_SATA_AFFILIATION_CONFLICT:
  4469. desc = "sata affiliation conflict";
  4470. break;
  4471. case MPI2_SAS_DEVICE0_ASTATUS_ROUTE_NOT_ADDRESSABLE:
  4472. desc = "route not addressable";
  4473. break;
  4474. case MPI2_SAS_DEVICE0_ASTATUS_SMP_ERROR_NOT_ADDRESSABLE:
  4475. desc = "smp error not addressable";
  4476. break;
  4477. case MPI2_SAS_DEVICE0_ASTATUS_DEVICE_BLOCKED:
  4478. desc = "device blocked";
  4479. break;
  4480. case MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED:
  4481. case MPI2_SAS_DEVICE0_ASTATUS_SIF_UNKNOWN:
  4482. case MPI2_SAS_DEVICE0_ASTATUS_SIF_AFFILIATION_CONFLICT:
  4483. case MPI2_SAS_DEVICE0_ASTATUS_SIF_DIAG:
  4484. case MPI2_SAS_DEVICE0_ASTATUS_SIF_IDENTIFICATION:
  4485. case MPI2_SAS_DEVICE0_ASTATUS_SIF_CHECK_POWER:
  4486. case MPI2_SAS_DEVICE0_ASTATUS_SIF_PIO_SN:
  4487. case MPI2_SAS_DEVICE0_ASTATUS_SIF_MDMA_SN:
  4488. case MPI2_SAS_DEVICE0_ASTATUS_SIF_UDMA_SN:
  4489. case MPI2_SAS_DEVICE0_ASTATUS_SIF_ZONING_VIOLATION:
  4490. case MPI2_SAS_DEVICE0_ASTATUS_SIF_NOT_ADDRESSABLE:
  4491. case MPI2_SAS_DEVICE0_ASTATUS_SIF_MAX:
  4492. desc = "sata initialization failed";
  4493. break;
  4494. default:
  4495. desc = "unknown";
  4496. break;
  4497. }
  4498. if (!rc)
  4499. return 0;
  4500. printk(MPT2SAS_ERR_FMT "discovery errors(%s): sas_address(0x%016llx), "
  4501. "handle(0x%04x)\n", ioc->name, desc,
  4502. (unsigned long long)sas_address, handle);
  4503. return rc;
  4504. }
  4505. static void
  4506. _scsih_check_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  4507. {
  4508. Mpi2ConfigReply_t mpi_reply;
  4509. Mpi2SasDevicePage0_t sas_device_pg0;
  4510. struct _sas_device *sas_device;
  4511. u32 ioc_status;
  4512. unsigned long flags;
  4513. u64 sas_address;
  4514. struct scsi_target *starget;
  4515. struct MPT2SAS_TARGET *sas_target_priv_data;
  4516. u32 device_info;
  4517. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4518. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle)))
  4519. return;
  4520. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  4521. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  4522. return;
  4523. /* check if this is end device */
  4524. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  4525. if (!(_scsih_is_end_device(device_info)))
  4526. return;
  4527. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4528. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4529. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4530. sas_address);
  4531. if (!sas_device) {
  4532. printk(MPT2SAS_ERR_FMT "device is not present "
  4533. "handle(0x%04x), no sas_device!!!\n", ioc->name, handle);
  4534. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4535. return;
  4536. }
  4537. if (unlikely(sas_device->handle != handle)) {
  4538. starget = sas_device->starget;
  4539. sas_target_priv_data = starget->hostdata;
  4540. starget_printk(KERN_INFO, starget, "handle changed from(0x%04x)"
  4541. " to (0x%04x)!!!\n", sas_device->handle, handle);
  4542. sas_target_priv_data->handle = handle;
  4543. sas_device->handle = handle;
  4544. }
  4545. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4546. /* check if device is present */
  4547. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  4548. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  4549. printk(MPT2SAS_ERR_FMT "device is not present "
  4550. "handle(0x%04x), flags!!!\n", ioc->name, handle);
  4551. return;
  4552. }
  4553. /* check if there were any issues with discovery */
  4554. if (_scsih_check_access_status(ioc, sas_address, handle,
  4555. sas_device_pg0.AccessStatus))
  4556. return;
  4557. _scsih_ublock_io_device(ioc, handle);
  4558. }
  4559. /**
  4560. * _scsih_add_device - creating sas device object
  4561. * @ioc: per adapter object
  4562. * @handle: sas device handle
  4563. * @phy_num: phy number end device attached to
  4564. * @is_pd: is this hidden raid component
  4565. *
  4566. * Creating end device object, stored in ioc->sas_device_list.
  4567. *
  4568. * Returns 0 for success, non-zero for failure.
  4569. */
  4570. static int
  4571. _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
  4572. {
  4573. Mpi2ConfigReply_t mpi_reply;
  4574. Mpi2SasDevicePage0_t sas_device_pg0;
  4575. Mpi2SasEnclosurePage0_t enclosure_pg0;
  4576. struct _sas_device *sas_device;
  4577. u32 ioc_status;
  4578. __le64 sas_address;
  4579. u32 device_info;
  4580. unsigned long flags;
  4581. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4582. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  4583. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4584. ioc->name, __FILE__, __LINE__, __func__);
  4585. return -1;
  4586. }
  4587. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4588. MPI2_IOCSTATUS_MASK;
  4589. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4590. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4591. ioc->name, __FILE__, __LINE__, __func__);
  4592. return -1;
  4593. }
  4594. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4595. /* check if device is present */
  4596. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  4597. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  4598. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4599. ioc->name, __FILE__, __LINE__, __func__);
  4600. printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
  4601. ioc->name, le16_to_cpu(sas_device_pg0.Flags));
  4602. return -1;
  4603. }
  4604. /* check if there were any issues with discovery */
  4605. if (_scsih_check_access_status(ioc, sas_address, handle,
  4606. sas_device_pg0.AccessStatus))
  4607. return -1;
  4608. /* check if this is end device */
  4609. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  4610. if (!(_scsih_is_end_device(device_info))) {
  4611. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4612. ioc->name, __FILE__, __LINE__, __func__);
  4613. return -1;
  4614. }
  4615. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4616. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4617. sas_address);
  4618. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4619. if (sas_device)
  4620. return 0;
  4621. sas_device = kzalloc(sizeof(struct _sas_device),
  4622. GFP_KERNEL);
  4623. if (!sas_device) {
  4624. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4625. ioc->name, __FILE__, __LINE__, __func__);
  4626. return -1;
  4627. }
  4628. sas_device->handle = handle;
  4629. if (_scsih_get_sas_address(ioc, le16_to_cpu
  4630. (sas_device_pg0.ParentDevHandle),
  4631. &sas_device->sas_address_parent) != 0)
  4632. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4633. ioc->name, __FILE__, __LINE__, __func__);
  4634. sas_device->enclosure_handle =
  4635. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  4636. sas_device->slot =
  4637. le16_to_cpu(sas_device_pg0.Slot);
  4638. sas_device->device_info = device_info;
  4639. sas_device->sas_address = sas_address;
  4640. sas_device->phy = sas_device_pg0.PhyNum;
  4641. /* get enclosure_logical_id */
  4642. if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
  4643. ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  4644. sas_device->enclosure_handle)))
  4645. sas_device->enclosure_logical_id =
  4646. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  4647. /* get device name */
  4648. sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
  4649. if (ioc->wait_for_discovery_to_complete)
  4650. _scsih_sas_device_init_add(ioc, sas_device);
  4651. else
  4652. _scsih_sas_device_add(ioc, sas_device);
  4653. return 0;
  4654. }
  4655. /**
  4656. * _scsih_remove_device - removing sas device object
  4657. * @ioc: per adapter object
  4658. * @sas_device_delete: the sas_device object
  4659. *
  4660. * Return nothing.
  4661. */
  4662. static void
  4663. _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc,
  4664. struct _sas_device *sas_device)
  4665. {
  4666. struct _sas_device sas_device_backup;
  4667. struct MPT2SAS_TARGET *sas_target_priv_data;
  4668. if (!sas_device)
  4669. return;
  4670. memcpy(&sas_device_backup, sas_device, sizeof(struct _sas_device));
  4671. _scsih_sas_device_remove(ioc, sas_device);
  4672. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: "
  4673. "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  4674. sas_device_backup.handle, (unsigned long long)
  4675. sas_device_backup.sas_address));
  4676. if (sas_device_backup.starget && sas_device_backup.starget->hostdata) {
  4677. sas_target_priv_data = sas_device_backup.starget->hostdata;
  4678. sas_target_priv_data->deleted = 1;
  4679. }
  4680. _scsih_ublock_io_device(ioc, sas_device_backup.handle);
  4681. if (!ioc->hide_drives)
  4682. mpt2sas_transport_port_remove(ioc,
  4683. sas_device_backup.sas_address,
  4684. sas_device_backup.sas_address_parent);
  4685. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
  4686. "(0x%016llx)\n", ioc->name, sas_device_backup.handle,
  4687. (unsigned long long) sas_device_backup.sas_address);
  4688. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: "
  4689. "handle(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  4690. sas_device_backup.handle, (unsigned long long)
  4691. sas_device_backup.sas_address));
  4692. }
  4693. /**
  4694. * mpt2sas_device_remove - removing device object
  4695. * @ioc: per adapter object
  4696. * @sas_address: expander sas_address
  4697. *
  4698. * Return nothing.
  4699. */
  4700. void
  4701. mpt2sas_device_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
  4702. {
  4703. struct _sas_device *sas_device;
  4704. unsigned long flags;
  4705. if (ioc->shost_recovery)
  4706. return;
  4707. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4708. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  4709. sas_address);
  4710. if (!sas_device) {
  4711. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4712. return;
  4713. }
  4714. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4715. _scsih_remove_device(ioc, sas_device);
  4716. }
  4717. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4718. /**
  4719. * _scsih_sas_topology_change_event_debug - debug for topology event
  4720. * @ioc: per adapter object
  4721. * @event_data: event data payload
  4722. * Context: user.
  4723. */
  4724. static void
  4725. _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4726. Mpi2EventDataSasTopologyChangeList_t *event_data)
  4727. {
  4728. int i;
  4729. u16 handle;
  4730. u16 reason_code;
  4731. u8 phy_number;
  4732. char *status_str = NULL;
  4733. u8 link_rate, prev_link_rate;
  4734. switch (event_data->ExpStatus) {
  4735. case MPI2_EVENT_SAS_TOPO_ES_ADDED:
  4736. status_str = "add";
  4737. break;
  4738. case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
  4739. status_str = "remove";
  4740. break;
  4741. case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
  4742. case 0:
  4743. status_str = "responding";
  4744. break;
  4745. case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
  4746. status_str = "remove delay";
  4747. break;
  4748. default:
  4749. status_str = "unknown status";
  4750. break;
  4751. }
  4752. printk(MPT2SAS_INFO_FMT "sas topology change: (%s)\n",
  4753. ioc->name, status_str);
  4754. printk(KERN_INFO "\thandle(0x%04x), enclosure_handle(0x%04x) "
  4755. "start_phy(%02d), count(%d)\n",
  4756. le16_to_cpu(event_data->ExpanderDevHandle),
  4757. le16_to_cpu(event_data->EnclosureHandle),
  4758. event_data->StartPhyNum, event_data->NumEntries);
  4759. for (i = 0; i < event_data->NumEntries; i++) {
  4760. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  4761. if (!handle)
  4762. continue;
  4763. phy_number = event_data->StartPhyNum + i;
  4764. reason_code = event_data->PHY[i].PhyStatus &
  4765. MPI2_EVENT_SAS_TOPO_RC_MASK;
  4766. switch (reason_code) {
  4767. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  4768. status_str = "target add";
  4769. break;
  4770. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  4771. status_str = "target remove";
  4772. break;
  4773. case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
  4774. status_str = "delay target remove";
  4775. break;
  4776. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  4777. status_str = "link rate change";
  4778. break;
  4779. case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
  4780. status_str = "target responding";
  4781. break;
  4782. default:
  4783. status_str = "unknown";
  4784. break;
  4785. }
  4786. link_rate = event_data->PHY[i].LinkRate >> 4;
  4787. prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
  4788. printk(KERN_INFO "\tphy(%02d), attached_handle(0x%04x): %s:"
  4789. " link rate: new(0x%02x), old(0x%02x)\n", phy_number,
  4790. handle, status_str, link_rate, prev_link_rate);
  4791. }
  4792. }
  4793. #endif
  4794. /**
  4795. * _scsih_sas_topology_change_event - handle topology changes
  4796. * @ioc: per adapter object
  4797. * @fw_event: The fw_event_work object
  4798. * Context: user.
  4799. *
  4800. */
  4801. static void
  4802. _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
  4803. struct fw_event_work *fw_event)
  4804. {
  4805. int i;
  4806. u16 parent_handle, handle;
  4807. u16 reason_code;
  4808. u8 phy_number, max_phys;
  4809. struct _sas_node *sas_expander;
  4810. struct _sas_device *sas_device;
  4811. u64 sas_address;
  4812. unsigned long flags;
  4813. u8 link_rate, prev_link_rate;
  4814. Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
  4815. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4816. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4817. _scsih_sas_topology_change_event_debug(ioc, event_data);
  4818. #endif
  4819. if (ioc->shost_recovery || ioc->remove_host || ioc->pci_error_recovery)
  4820. return;
  4821. if (!ioc->sas_hba.num_phys)
  4822. _scsih_sas_host_add(ioc);
  4823. else
  4824. _scsih_sas_host_refresh(ioc);
  4825. if (fw_event->ignore) {
  4826. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring expander "
  4827. "event\n", ioc->name));
  4828. return;
  4829. }
  4830. parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  4831. /* handle expander add */
  4832. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
  4833. if (_scsih_expander_add(ioc, parent_handle) != 0)
  4834. return;
  4835. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4836. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  4837. parent_handle);
  4838. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4839. if (sas_expander) {
  4840. sas_address = sas_expander->sas_address;
  4841. max_phys = sas_expander->num_phys;
  4842. } else if (parent_handle < ioc->sas_hba.num_phys) {
  4843. sas_address = ioc->sas_hba.sas_address;
  4844. max_phys = ioc->sas_hba.num_phys;
  4845. } else
  4846. return;
  4847. /* handle siblings events */
  4848. for (i = 0; i < event_data->NumEntries; i++) {
  4849. if (fw_event->ignore) {
  4850. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "ignoring "
  4851. "expander event\n", ioc->name));
  4852. return;
  4853. }
  4854. if (ioc->shost_recovery || ioc->remove_host ||
  4855. ioc->pci_error_recovery)
  4856. return;
  4857. phy_number = event_data->StartPhyNum + i;
  4858. if (phy_number >= max_phys)
  4859. continue;
  4860. reason_code = event_data->PHY[i].PhyStatus &
  4861. MPI2_EVENT_SAS_TOPO_RC_MASK;
  4862. if ((event_data->PHY[i].PhyStatus &
  4863. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
  4864. MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
  4865. continue;
  4866. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  4867. if (!handle)
  4868. continue;
  4869. link_rate = event_data->PHY[i].LinkRate >> 4;
  4870. prev_link_rate = event_data->PHY[i].LinkRate & 0xF;
  4871. switch (reason_code) {
  4872. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  4873. if (link_rate == prev_link_rate)
  4874. break;
  4875. mpt2sas_transport_update_links(ioc, sas_address,
  4876. handle, phy_number, link_rate);
  4877. if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  4878. break;
  4879. _scsih_check_device(ioc, handle);
  4880. break;
  4881. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  4882. mpt2sas_transport_update_links(ioc, sas_address,
  4883. handle, phy_number, link_rate);
  4884. _scsih_add_device(ioc, handle, phy_number, 0);
  4885. break;
  4886. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  4887. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4888. sas_device = _scsih_sas_device_find_by_handle(ioc,
  4889. handle);
  4890. if (!sas_device) {
  4891. spin_unlock_irqrestore(&ioc->sas_device_lock,
  4892. flags);
  4893. break;
  4894. }
  4895. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4896. _scsih_remove_device(ioc, sas_device);
  4897. break;
  4898. }
  4899. }
  4900. /* handle expander removal */
  4901. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
  4902. sas_expander)
  4903. mpt2sas_expander_remove(ioc, sas_address);
  4904. }
  4905. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4906. /**
  4907. * _scsih_sas_device_status_change_event_debug - debug for device event
  4908. * @event_data: event data payload
  4909. * Context: user.
  4910. *
  4911. * Return nothing.
  4912. */
  4913. static void
  4914. _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4915. Mpi2EventDataSasDeviceStatusChange_t *event_data)
  4916. {
  4917. char *reason_str = NULL;
  4918. switch (event_data->ReasonCode) {
  4919. case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  4920. reason_str = "smart data";
  4921. break;
  4922. case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  4923. reason_str = "unsupported device discovered";
  4924. break;
  4925. case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  4926. reason_str = "internal device reset";
  4927. break;
  4928. case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  4929. reason_str = "internal task abort";
  4930. break;
  4931. case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  4932. reason_str = "internal task abort set";
  4933. break;
  4934. case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  4935. reason_str = "internal clear task set";
  4936. break;
  4937. case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  4938. reason_str = "internal query task";
  4939. break;
  4940. case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
  4941. reason_str = "sata init failure";
  4942. break;
  4943. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
  4944. reason_str = "internal device reset complete";
  4945. break;
  4946. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
  4947. reason_str = "internal task abort complete";
  4948. break;
  4949. case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
  4950. reason_str = "internal async notification";
  4951. break;
  4952. case MPI2_EVENT_SAS_DEV_STAT_RC_EXPANDER_REDUCED_FUNCTIONALITY:
  4953. reason_str = "expander reduced functionality";
  4954. break;
  4955. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_EXPANDER_REDUCED_FUNCTIONALITY:
  4956. reason_str = "expander reduced functionality complete";
  4957. break;
  4958. default:
  4959. reason_str = "unknown reason";
  4960. break;
  4961. }
  4962. printk(MPT2SAS_INFO_FMT "device status change: (%s)\n"
  4963. "\thandle(0x%04x), sas address(0x%016llx), tag(%d)",
  4964. ioc->name, reason_str, le16_to_cpu(event_data->DevHandle),
  4965. (unsigned long long)le64_to_cpu(event_data->SASAddress),
  4966. le16_to_cpu(event_data->TaskTag));
  4967. if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
  4968. printk(MPT2SAS_INFO_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
  4969. event_data->ASC, event_data->ASCQ);
  4970. printk(KERN_INFO "\n");
  4971. }
  4972. #endif
  4973. /**
  4974. * _scsih_sas_device_status_change_event - handle device status change
  4975. * @ioc: per adapter object
  4976. * @fw_event: The fw_event_work object
  4977. * Context: user.
  4978. *
  4979. * Return nothing.
  4980. */
  4981. static void
  4982. _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  4983. struct fw_event_work *fw_event)
  4984. {
  4985. struct MPT2SAS_TARGET *target_priv_data;
  4986. struct _sas_device *sas_device;
  4987. u64 sas_address;
  4988. unsigned long flags;
  4989. Mpi2EventDataSasDeviceStatusChange_t *event_data =
  4990. fw_event->event_data;
  4991. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4992. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4993. _scsih_sas_device_status_change_event_debug(ioc,
  4994. event_data);
  4995. #endif
  4996. /* In MPI Revision K (0xC), the internal device reset complete was
  4997. * implemented, so avoid setting tm_busy flag for older firmware.
  4998. */
  4999. if ((ioc->facts.HeaderVersion >> 8) < 0xC)
  5000. return;
  5001. if (event_data->ReasonCode !=
  5002. MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET &&
  5003. event_data->ReasonCode !=
  5004. MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET)
  5005. return;
  5006. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5007. sas_address = le64_to_cpu(event_data->SASAddress);
  5008. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  5009. sas_address);
  5010. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5011. if (!sas_device || !sas_device->starget)
  5012. return;
  5013. target_priv_data = sas_device->starget->hostdata;
  5014. if (!target_priv_data)
  5015. return;
  5016. if (event_data->ReasonCode ==
  5017. MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET)
  5018. target_priv_data->tm_busy = 1;
  5019. else
  5020. target_priv_data->tm_busy = 0;
  5021. }
  5022. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5023. /**
  5024. * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
  5025. * @ioc: per adapter object
  5026. * @event_data: event data payload
  5027. * Context: user.
  5028. *
  5029. * Return nothing.
  5030. */
  5031. static void
  5032. _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  5033. Mpi2EventDataSasEnclDevStatusChange_t *event_data)
  5034. {
  5035. char *reason_str = NULL;
  5036. switch (event_data->ReasonCode) {
  5037. case MPI2_EVENT_SAS_ENCL_RC_ADDED:
  5038. reason_str = "enclosure add";
  5039. break;
  5040. case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
  5041. reason_str = "enclosure remove";
  5042. break;
  5043. default:
  5044. reason_str = "unknown reason";
  5045. break;
  5046. }
  5047. printk(MPT2SAS_INFO_FMT "enclosure status change: (%s)\n"
  5048. "\thandle(0x%04x), enclosure logical id(0x%016llx)"
  5049. " number slots(%d)\n", ioc->name, reason_str,
  5050. le16_to_cpu(event_data->EnclosureHandle),
  5051. (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
  5052. le16_to_cpu(event_data->StartSlot));
  5053. }
  5054. #endif
  5055. /**
  5056. * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
  5057. * @ioc: per adapter object
  5058. * @fw_event: The fw_event_work object
  5059. * Context: user.
  5060. *
  5061. * Return nothing.
  5062. */
  5063. static void
  5064. _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  5065. struct fw_event_work *fw_event)
  5066. {
  5067. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5068. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5069. _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
  5070. fw_event->event_data);
  5071. #endif
  5072. }
  5073. /**
  5074. * _scsih_sas_broadcast_primative_event - handle broadcast events
  5075. * @ioc: per adapter object
  5076. * @fw_event: The fw_event_work object
  5077. * Context: user.
  5078. *
  5079. * Return nothing.
  5080. */
  5081. static void
  5082. _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
  5083. struct fw_event_work *fw_event)
  5084. {
  5085. struct scsi_cmnd *scmd;
  5086. struct scsi_device *sdev;
  5087. u16 smid, handle;
  5088. u32 lun;
  5089. struct MPT2SAS_DEVICE *sas_device_priv_data;
  5090. u32 termination_count;
  5091. u32 query_count;
  5092. Mpi2SCSITaskManagementReply_t *mpi_reply;
  5093. Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
  5094. u16 ioc_status;
  5095. unsigned long flags;
  5096. int r;
  5097. u8 max_retries = 0;
  5098. u8 task_abort_retries;
  5099. mutex_lock(&ioc->tm_cmds.mutex);
  5100. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: phy number(%d), "
  5101. "width(%d)\n", ioc->name, __func__, event_data->PhyNum,
  5102. event_data->PortWidth));
  5103. _scsih_block_io_all_device(ioc);
  5104. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  5105. mpi_reply = ioc->tm_cmds.reply;
  5106. broadcast_aen_retry:
  5107. /* sanity checks for retrying this loop */
  5108. if (max_retries++ == 5) {
  5109. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: giving up\n",
  5110. ioc->name, __func__));
  5111. goto out;
  5112. } else if (max_retries > 1)
  5113. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: %d retry\n",
  5114. ioc->name, __func__, max_retries - 1));
  5115. termination_count = 0;
  5116. query_count = 0;
  5117. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  5118. if (ioc->shost_recovery)
  5119. goto out;
  5120. scmd = _scsih_scsi_lookup_get(ioc, smid);
  5121. if (!scmd)
  5122. continue;
  5123. sdev = scmd->device;
  5124. sas_device_priv_data = sdev->hostdata;
  5125. if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
  5126. continue;
  5127. /* skip hidden raid components */
  5128. if (sas_device_priv_data->sas_target->flags &
  5129. MPT_TARGET_FLAGS_RAID_COMPONENT)
  5130. continue;
  5131. /* skip volumes */
  5132. if (sas_device_priv_data->sas_target->flags &
  5133. MPT_TARGET_FLAGS_VOLUME)
  5134. continue;
  5135. handle = sas_device_priv_data->sas_target->handle;
  5136. lun = sas_device_priv_data->lun;
  5137. query_count++;
  5138. if (ioc->shost_recovery)
  5139. goto out;
  5140. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  5141. r = mpt2sas_scsih_issue_tm(ioc, handle, 0, 0, lun,
  5142. MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30, 0,
  5143. TM_MUTEX_OFF);
  5144. if (r == FAILED) {
  5145. sdev_printk(KERN_WARNING, sdev,
  5146. "mpt2sas_scsih_issue_tm: FAILED when sending "
  5147. "QUERY_TASK: scmd(%p)\n", scmd);
  5148. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  5149. goto broadcast_aen_retry;
  5150. }
  5151. ioc_status = le16_to_cpu(mpi_reply->IOCStatus)
  5152. & MPI2_IOCSTATUS_MASK;
  5153. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5154. sdev_printk(KERN_WARNING, sdev, "query task: FAILED "
  5155. "with IOCSTATUS(0x%04x), scmd(%p)\n", ioc_status,
  5156. scmd);
  5157. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  5158. goto broadcast_aen_retry;
  5159. }
  5160. /* see if IO is still owned by IOC and target */
  5161. if (mpi_reply->ResponseCode ==
  5162. MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
  5163. mpi_reply->ResponseCode ==
  5164. MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC) {
  5165. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  5166. continue;
  5167. }
  5168. task_abort_retries = 0;
  5169. tm_retry:
  5170. if (task_abort_retries++ == 60) {
  5171. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  5172. "%s: ABORT_TASK: giving up\n", ioc->name,
  5173. __func__));
  5174. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  5175. goto broadcast_aen_retry;
  5176. }
  5177. if (ioc->shost_recovery)
  5178. goto out_no_lock;
  5179. r = mpt2sas_scsih_issue_tm(ioc, handle, sdev->channel, sdev->id,
  5180. sdev->lun, MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30,
  5181. scmd->serial_number, TM_MUTEX_OFF);
  5182. if (r == FAILED) {
  5183. sdev_printk(KERN_WARNING, sdev,
  5184. "mpt2sas_scsih_issue_tm: ABORT_TASK: FAILED : "
  5185. "scmd(%p)\n", scmd);
  5186. goto tm_retry;
  5187. }
  5188. if (task_abort_retries > 1)
  5189. sdev_printk(KERN_WARNING, sdev,
  5190. "mpt2sas_scsih_issue_tm: ABORT_TASK: RETRIES (%d):"
  5191. " scmd(%p)\n",
  5192. task_abort_retries - 1, scmd);
  5193. termination_count += le32_to_cpu(mpi_reply->TerminationCount);
  5194. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  5195. }
  5196. if (ioc->broadcast_aen_pending) {
  5197. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: loop back due to"
  5198. " pending AEN\n", ioc->name, __func__));
  5199. ioc->broadcast_aen_pending = 0;
  5200. goto broadcast_aen_retry;
  5201. }
  5202. out:
  5203. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  5204. out_no_lock:
  5205. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  5206. "%s - exit, query_count = %d termination_count = %d\n",
  5207. ioc->name, __func__, query_count, termination_count));
  5208. ioc->broadcast_aen_busy = 0;
  5209. if (!ioc->shost_recovery)
  5210. _scsih_ublock_io_all_device(ioc);
  5211. mutex_unlock(&ioc->tm_cmds.mutex);
  5212. }
  5213. /**
  5214. * _scsih_sas_discovery_event - handle discovery events
  5215. * @ioc: per adapter object
  5216. * @fw_event: The fw_event_work object
  5217. * Context: user.
  5218. *
  5219. * Return nothing.
  5220. */
  5221. static void
  5222. _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
  5223. struct fw_event_work *fw_event)
  5224. {
  5225. Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
  5226. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5227. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
  5228. printk(MPT2SAS_INFO_FMT "discovery event: (%s)", ioc->name,
  5229. (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
  5230. "start" : "stop");
  5231. if (event_data->DiscoveryStatus)
  5232. printk("discovery_status(0x%08x)",
  5233. le32_to_cpu(event_data->DiscoveryStatus));
  5234. printk("\n");
  5235. }
  5236. #endif
  5237. if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
  5238. !ioc->sas_hba.num_phys)
  5239. _scsih_sas_host_add(ioc);
  5240. }
  5241. /**
  5242. * _scsih_reprobe_lun - reprobing lun
  5243. * @sdev: scsi device struct
  5244. * @no_uld_attach: sdev->no_uld_attach flag setting
  5245. *
  5246. **/
  5247. static void
  5248. _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
  5249. {
  5250. int rc;
  5251. sdev->no_uld_attach = no_uld_attach ? 1 : 0;
  5252. sdev_printk(KERN_INFO, sdev, "%s raid component\n",
  5253. sdev->no_uld_attach ? "hidding" : "exposing");
  5254. rc = scsi_device_reprobe(sdev);
  5255. }
  5256. /**
  5257. * _scsih_reprobe_target - reprobing target
  5258. * @starget: scsi target struct
  5259. * @no_uld_attach: sdev->no_uld_attach flag setting
  5260. *
  5261. * Note: no_uld_attach flag determines whether the disk device is attached
  5262. * to block layer. A value of `1` means to not attach.
  5263. **/
  5264. static void
  5265. _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
  5266. {
  5267. struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
  5268. if (no_uld_attach)
  5269. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  5270. else
  5271. sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  5272. starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
  5273. _scsih_reprobe_lun);
  5274. }
  5275. /**
  5276. * _scsih_sas_volume_add - add new volume
  5277. * @ioc: per adapter object
  5278. * @element: IR config element data
  5279. * Context: user.
  5280. *
  5281. * Return nothing.
  5282. */
  5283. static void
  5284. _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
  5285. Mpi2EventIrConfigElement_t *element)
  5286. {
  5287. struct _raid_device *raid_device;
  5288. unsigned long flags;
  5289. u64 wwid;
  5290. u16 handle = le16_to_cpu(element->VolDevHandle);
  5291. int rc;
  5292. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  5293. if (!wwid) {
  5294. printk(MPT2SAS_ERR_FMT
  5295. "failure at %s:%d/%s()!\n", ioc->name,
  5296. __FILE__, __LINE__, __func__);
  5297. return;
  5298. }
  5299. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5300. raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
  5301. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5302. if (raid_device)
  5303. return;
  5304. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  5305. if (!raid_device) {
  5306. printk(MPT2SAS_ERR_FMT
  5307. "failure at %s:%d/%s()!\n", ioc->name,
  5308. __FILE__, __LINE__, __func__);
  5309. return;
  5310. }
  5311. raid_device->id = ioc->sas_id++;
  5312. raid_device->channel = RAID_CHANNEL;
  5313. raid_device->handle = handle;
  5314. raid_device->wwid = wwid;
  5315. _scsih_raid_device_add(ioc, raid_device);
  5316. if (!ioc->wait_for_discovery_to_complete) {
  5317. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5318. raid_device->id, 0);
  5319. if (rc)
  5320. _scsih_raid_device_remove(ioc, raid_device);
  5321. } else
  5322. _scsih_determine_boot_device(ioc, raid_device, 1);
  5323. }
  5324. /**
  5325. * _scsih_sas_volume_delete - delete volume
  5326. * @ioc: per adapter object
  5327. * @handle: volume device handle
  5328. * Context: user.
  5329. *
  5330. * Return nothing.
  5331. */
  5332. static void
  5333. _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  5334. {
  5335. struct _raid_device *raid_device;
  5336. unsigned long flags;
  5337. struct MPT2SAS_TARGET *sas_target_priv_data;
  5338. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5339. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  5340. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5341. if (!raid_device)
  5342. return;
  5343. if (raid_device->starget) {
  5344. sas_target_priv_data = raid_device->starget->hostdata;
  5345. sas_target_priv_data->deleted = 1;
  5346. scsi_remove_target(&raid_device->starget->dev);
  5347. }
  5348. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
  5349. "(0x%016llx)\n", ioc->name, raid_device->handle,
  5350. (unsigned long long) raid_device->wwid);
  5351. _scsih_raid_device_remove(ioc, raid_device);
  5352. }
  5353. /**
  5354. * _scsih_sas_pd_expose - expose pd component to /dev/sdX
  5355. * @ioc: per adapter object
  5356. * @element: IR config element data
  5357. * Context: user.
  5358. *
  5359. * Return nothing.
  5360. */
  5361. static void
  5362. _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
  5363. Mpi2EventIrConfigElement_t *element)
  5364. {
  5365. struct _sas_device *sas_device;
  5366. unsigned long flags;
  5367. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  5368. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5369. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  5370. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5371. if (!sas_device)
  5372. return;
  5373. /* exposing raid component */
  5374. sas_device->volume_handle = 0;
  5375. sas_device->volume_wwid = 0;
  5376. clear_bit(handle, ioc->pd_handles);
  5377. _scsih_reprobe_target(sas_device->starget, 0);
  5378. }
  5379. /**
  5380. * _scsih_sas_pd_hide - hide pd component from /dev/sdX
  5381. * @ioc: per adapter object
  5382. * @element: IR config element data
  5383. * Context: user.
  5384. *
  5385. * Return nothing.
  5386. */
  5387. static void
  5388. _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
  5389. Mpi2EventIrConfigElement_t *element)
  5390. {
  5391. struct _sas_device *sas_device;
  5392. unsigned long flags;
  5393. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  5394. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5395. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  5396. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5397. if (!sas_device)
  5398. return;
  5399. /* hiding raid component */
  5400. mpt2sas_config_get_volume_handle(ioc, handle,
  5401. &sas_device->volume_handle);
  5402. mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
  5403. &sas_device->volume_wwid);
  5404. set_bit(handle, ioc->pd_handles);
  5405. _scsih_reprobe_target(sas_device->starget, 1);
  5406. }
  5407. /**
  5408. * _scsih_sas_pd_delete - delete pd component
  5409. * @ioc: per adapter object
  5410. * @element: IR config element data
  5411. * Context: user.
  5412. *
  5413. * Return nothing.
  5414. */
  5415. static void
  5416. _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
  5417. Mpi2EventIrConfigElement_t *element)
  5418. {
  5419. struct _sas_device *sas_device;
  5420. unsigned long flags;
  5421. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  5422. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5423. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  5424. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5425. if (!sas_device)
  5426. return;
  5427. _scsih_remove_device(ioc, sas_device);
  5428. }
  5429. /**
  5430. * _scsih_sas_pd_add - remove pd component
  5431. * @ioc: per adapter object
  5432. * @element: IR config element data
  5433. * Context: user.
  5434. *
  5435. * Return nothing.
  5436. */
  5437. static void
  5438. _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
  5439. Mpi2EventIrConfigElement_t *element)
  5440. {
  5441. struct _sas_device *sas_device;
  5442. unsigned long flags;
  5443. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  5444. Mpi2ConfigReply_t mpi_reply;
  5445. Mpi2SasDevicePage0_t sas_device_pg0;
  5446. u32 ioc_status;
  5447. u64 sas_address;
  5448. u16 parent_handle;
  5449. set_bit(handle, ioc->pd_handles);
  5450. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5451. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  5452. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5453. if (sas_device)
  5454. return;
  5455. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  5456. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  5457. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5458. ioc->name, __FILE__, __LINE__, __func__);
  5459. return;
  5460. }
  5461. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5462. MPI2_IOCSTATUS_MASK;
  5463. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5464. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5465. ioc->name, __FILE__, __LINE__, __func__);
  5466. return;
  5467. }
  5468. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  5469. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  5470. mpt2sas_transport_update_links(ioc, sas_address, handle,
  5471. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  5472. _scsih_add_device(ioc, handle, 0, 1);
  5473. }
  5474. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5475. /**
  5476. * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
  5477. * @ioc: per adapter object
  5478. * @event_data: event data payload
  5479. * Context: user.
  5480. *
  5481. * Return nothing.
  5482. */
  5483. static void
  5484. _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  5485. Mpi2EventDataIrConfigChangeList_t *event_data)
  5486. {
  5487. Mpi2EventIrConfigElement_t *element;
  5488. u8 element_type;
  5489. int i;
  5490. char *reason_str = NULL, *element_str = NULL;
  5491. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  5492. printk(MPT2SAS_INFO_FMT "raid config change: (%s), elements(%d)\n",
  5493. ioc->name, (le32_to_cpu(event_data->Flags) &
  5494. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
  5495. "foreign" : "native", event_data->NumElements);
  5496. for (i = 0; i < event_data->NumElements; i++, element++) {
  5497. switch (element->ReasonCode) {
  5498. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  5499. reason_str = "add";
  5500. break;
  5501. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  5502. reason_str = "remove";
  5503. break;
  5504. case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
  5505. reason_str = "no change";
  5506. break;
  5507. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  5508. reason_str = "hide";
  5509. break;
  5510. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  5511. reason_str = "unhide";
  5512. break;
  5513. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  5514. reason_str = "volume_created";
  5515. break;
  5516. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  5517. reason_str = "volume_deleted";
  5518. break;
  5519. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  5520. reason_str = "pd_created";
  5521. break;
  5522. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  5523. reason_str = "pd_deleted";
  5524. break;
  5525. default:
  5526. reason_str = "unknown reason";
  5527. break;
  5528. }
  5529. element_type = le16_to_cpu(element->ElementFlags) &
  5530. MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
  5531. switch (element_type) {
  5532. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
  5533. element_str = "volume";
  5534. break;
  5535. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
  5536. element_str = "phys disk";
  5537. break;
  5538. case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
  5539. element_str = "hot spare";
  5540. break;
  5541. default:
  5542. element_str = "unknown element";
  5543. break;
  5544. }
  5545. printk(KERN_INFO "\t(%s:%s), vol handle(0x%04x), "
  5546. "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
  5547. reason_str, le16_to_cpu(element->VolDevHandle),
  5548. le16_to_cpu(element->PhysDiskDevHandle),
  5549. element->PhysDiskNum);
  5550. }
  5551. }
  5552. #endif
  5553. /**
  5554. * _scsih_sas_ir_config_change_event - handle ir configuration change events
  5555. * @ioc: per adapter object
  5556. * @fw_event: The fw_event_work object
  5557. * Context: user.
  5558. *
  5559. * Return nothing.
  5560. */
  5561. static void
  5562. _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
  5563. struct fw_event_work *fw_event)
  5564. {
  5565. Mpi2EventIrConfigElement_t *element;
  5566. int i;
  5567. u8 foreign_config;
  5568. Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
  5569. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5570. if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5571. && !ioc->hide_ir_msg)
  5572. _scsih_sas_ir_config_change_event_debug(ioc, event_data);
  5573. #endif
  5574. if (ioc->shost_recovery)
  5575. return;
  5576. foreign_config = (le32_to_cpu(event_data->Flags) &
  5577. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
  5578. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  5579. for (i = 0; i < event_data->NumElements; i++, element++) {
  5580. switch (element->ReasonCode) {
  5581. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  5582. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  5583. if (!foreign_config)
  5584. _scsih_sas_volume_add(ioc, element);
  5585. break;
  5586. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  5587. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  5588. if (!foreign_config)
  5589. _scsih_sas_volume_delete(ioc,
  5590. le16_to_cpu(element->VolDevHandle));
  5591. break;
  5592. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  5593. if (!ioc->is_warpdrive)
  5594. _scsih_sas_pd_hide(ioc, element);
  5595. break;
  5596. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  5597. if (!ioc->is_warpdrive)
  5598. _scsih_sas_pd_expose(ioc, element);
  5599. break;
  5600. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  5601. if (!ioc->is_warpdrive)
  5602. _scsih_sas_pd_add(ioc, element);
  5603. break;
  5604. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  5605. if (!ioc->is_warpdrive)
  5606. _scsih_sas_pd_delete(ioc, element);
  5607. break;
  5608. }
  5609. }
  5610. }
  5611. /**
  5612. * _scsih_sas_ir_volume_event - IR volume event
  5613. * @ioc: per adapter object
  5614. * @fw_event: The fw_event_work object
  5615. * Context: user.
  5616. *
  5617. * Return nothing.
  5618. */
  5619. static void
  5620. _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
  5621. struct fw_event_work *fw_event)
  5622. {
  5623. u64 wwid;
  5624. unsigned long flags;
  5625. struct _raid_device *raid_device;
  5626. u16 handle;
  5627. u32 state;
  5628. int rc;
  5629. Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
  5630. if (ioc->shost_recovery)
  5631. return;
  5632. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  5633. return;
  5634. handle = le16_to_cpu(event_data->VolDevHandle);
  5635. state = le32_to_cpu(event_data->NewValue);
  5636. if (!ioc->hide_ir_msg)
  5637. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
  5638. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  5639. le32_to_cpu(event_data->PreviousValue), state));
  5640. switch (state) {
  5641. case MPI2_RAID_VOL_STATE_MISSING:
  5642. case MPI2_RAID_VOL_STATE_FAILED:
  5643. _scsih_sas_volume_delete(ioc, handle);
  5644. break;
  5645. case MPI2_RAID_VOL_STATE_ONLINE:
  5646. case MPI2_RAID_VOL_STATE_DEGRADED:
  5647. case MPI2_RAID_VOL_STATE_OPTIMAL:
  5648. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5649. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  5650. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5651. if (raid_device)
  5652. break;
  5653. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  5654. if (!wwid) {
  5655. printk(MPT2SAS_ERR_FMT
  5656. "failure at %s:%d/%s()!\n", ioc->name,
  5657. __FILE__, __LINE__, __func__);
  5658. break;
  5659. }
  5660. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  5661. if (!raid_device) {
  5662. printk(MPT2SAS_ERR_FMT
  5663. "failure at %s:%d/%s()!\n", ioc->name,
  5664. __FILE__, __LINE__, __func__);
  5665. break;
  5666. }
  5667. raid_device->id = ioc->sas_id++;
  5668. raid_device->channel = RAID_CHANNEL;
  5669. raid_device->handle = handle;
  5670. raid_device->wwid = wwid;
  5671. _scsih_raid_device_add(ioc, raid_device);
  5672. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5673. raid_device->id, 0);
  5674. if (rc)
  5675. _scsih_raid_device_remove(ioc, raid_device);
  5676. break;
  5677. case MPI2_RAID_VOL_STATE_INITIALIZING:
  5678. default:
  5679. break;
  5680. }
  5681. }
  5682. /**
  5683. * _scsih_sas_ir_physical_disk_event - PD event
  5684. * @ioc: per adapter object
  5685. * @fw_event: The fw_event_work object
  5686. * Context: user.
  5687. *
  5688. * Return nothing.
  5689. */
  5690. static void
  5691. _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
  5692. struct fw_event_work *fw_event)
  5693. {
  5694. u16 handle, parent_handle;
  5695. u32 state;
  5696. struct _sas_device *sas_device;
  5697. unsigned long flags;
  5698. Mpi2ConfigReply_t mpi_reply;
  5699. Mpi2SasDevicePage0_t sas_device_pg0;
  5700. u32 ioc_status;
  5701. Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
  5702. u64 sas_address;
  5703. if (ioc->shost_recovery)
  5704. return;
  5705. if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
  5706. return;
  5707. handle = le16_to_cpu(event_data->PhysDiskDevHandle);
  5708. state = le32_to_cpu(event_data->NewValue);
  5709. if (!ioc->hide_ir_msg)
  5710. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: handle(0x%04x), "
  5711. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  5712. le32_to_cpu(event_data->PreviousValue), state));
  5713. switch (state) {
  5714. case MPI2_RAID_PD_STATE_ONLINE:
  5715. case MPI2_RAID_PD_STATE_DEGRADED:
  5716. case MPI2_RAID_PD_STATE_REBUILDING:
  5717. case MPI2_RAID_PD_STATE_OPTIMAL:
  5718. case MPI2_RAID_PD_STATE_HOT_SPARE:
  5719. if (!ioc->is_warpdrive)
  5720. set_bit(handle, ioc->pd_handles);
  5721. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5722. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  5723. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5724. if (sas_device)
  5725. return;
  5726. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  5727. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  5728. handle))) {
  5729. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5730. ioc->name, __FILE__, __LINE__, __func__);
  5731. return;
  5732. }
  5733. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5734. MPI2_IOCSTATUS_MASK;
  5735. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  5736. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5737. ioc->name, __FILE__, __LINE__, __func__);
  5738. return;
  5739. }
  5740. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  5741. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  5742. mpt2sas_transport_update_links(ioc, sas_address, handle,
  5743. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  5744. _scsih_add_device(ioc, handle, 0, 1);
  5745. break;
  5746. case MPI2_RAID_PD_STATE_OFFLINE:
  5747. case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
  5748. case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
  5749. default:
  5750. break;
  5751. }
  5752. }
  5753. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5754. /**
  5755. * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
  5756. * @ioc: per adapter object
  5757. * @event_data: event data payload
  5758. * Context: user.
  5759. *
  5760. * Return nothing.
  5761. */
  5762. static void
  5763. _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
  5764. Mpi2EventDataIrOperationStatus_t *event_data)
  5765. {
  5766. char *reason_str = NULL;
  5767. switch (event_data->RAIDOperation) {
  5768. case MPI2_EVENT_IR_RAIDOP_RESYNC:
  5769. reason_str = "resync";
  5770. break;
  5771. case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
  5772. reason_str = "online capacity expansion";
  5773. break;
  5774. case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
  5775. reason_str = "consistency check";
  5776. break;
  5777. case MPI2_EVENT_IR_RAIDOP_BACKGROUND_INIT:
  5778. reason_str = "background init";
  5779. break;
  5780. case MPI2_EVENT_IR_RAIDOP_MAKE_DATA_CONSISTENT:
  5781. reason_str = "make data consistent";
  5782. break;
  5783. }
  5784. if (!reason_str)
  5785. return;
  5786. printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
  5787. "\thandle(0x%04x), percent complete(%d)\n",
  5788. ioc->name, reason_str,
  5789. le16_to_cpu(event_data->VolDevHandle),
  5790. event_data->PercentComplete);
  5791. }
  5792. #endif
  5793. /**
  5794. * _scsih_sas_ir_operation_status_event - handle RAID operation events
  5795. * @ioc: per adapter object
  5796. * @fw_event: The fw_event_work object
  5797. * Context: user.
  5798. *
  5799. * Return nothing.
  5800. */
  5801. static void
  5802. _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
  5803. struct fw_event_work *fw_event)
  5804. {
  5805. Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
  5806. static struct _raid_device *raid_device;
  5807. unsigned long flags;
  5808. u16 handle;
  5809. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  5810. if ((ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  5811. && !ioc->hide_ir_msg)
  5812. _scsih_sas_ir_operation_status_event_debug(ioc,
  5813. event_data);
  5814. #endif
  5815. /* code added for raid transport support */
  5816. if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC) {
  5817. handle = le16_to_cpu(event_data->VolDevHandle);
  5818. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5819. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  5820. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5821. if (!raid_device)
  5822. return;
  5823. if (event_data->RAIDOperation == MPI2_EVENT_IR_RAIDOP_RESYNC)
  5824. raid_device->percent_complete =
  5825. event_data->PercentComplete;
  5826. }
  5827. }
  5828. /**
  5829. * _scsih_prep_device_scan - initialize parameters prior to device scan
  5830. * @ioc: per adapter object
  5831. *
  5832. * Set the deleted flag prior to device scan. If the device is found during
  5833. * the scan, then we clear the deleted flag.
  5834. */
  5835. static void
  5836. _scsih_prep_device_scan(struct MPT2SAS_ADAPTER *ioc)
  5837. {
  5838. struct MPT2SAS_DEVICE *sas_device_priv_data;
  5839. struct scsi_device *sdev;
  5840. shost_for_each_device(sdev, ioc->shost) {
  5841. sas_device_priv_data = sdev->hostdata;
  5842. if (sas_device_priv_data && sas_device_priv_data->sas_target)
  5843. sas_device_priv_data->sas_target->deleted = 1;
  5844. }
  5845. }
  5846. /**
  5847. * _scsih_mark_responding_sas_device - mark a sas_devices as responding
  5848. * @ioc: per adapter object
  5849. * @sas_address: sas address
  5850. * @slot: enclosure slot id
  5851. * @handle: device handle
  5852. *
  5853. * After host reset, find out whether devices are still responding.
  5854. * Used in _scsi_remove_unresponsive_sas_devices.
  5855. *
  5856. * Return nothing.
  5857. */
  5858. static void
  5859. _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  5860. u16 slot, u16 handle)
  5861. {
  5862. struct MPT2SAS_TARGET *sas_target_priv_data = NULL;
  5863. struct scsi_target *starget;
  5864. struct _sas_device *sas_device;
  5865. unsigned long flags;
  5866. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5867. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  5868. if (sas_device->sas_address == sas_address &&
  5869. sas_device->slot == slot) {
  5870. sas_device->responding = 1;
  5871. starget = sas_device->starget;
  5872. if (starget && starget->hostdata) {
  5873. sas_target_priv_data = starget->hostdata;
  5874. sas_target_priv_data->tm_busy = 0;
  5875. sas_target_priv_data->deleted = 0;
  5876. } else
  5877. sas_target_priv_data = NULL;
  5878. if (starget)
  5879. starget_printk(KERN_INFO, starget,
  5880. "handle(0x%04x), sas_addr(0x%016llx), "
  5881. "enclosure logical id(0x%016llx), "
  5882. "slot(%d)\n", handle,
  5883. (unsigned long long)sas_device->sas_address,
  5884. (unsigned long long)
  5885. sas_device->enclosure_logical_id,
  5886. sas_device->slot);
  5887. if (sas_device->handle == handle)
  5888. goto out;
  5889. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  5890. sas_device->handle);
  5891. sas_device->handle = handle;
  5892. if (sas_target_priv_data)
  5893. sas_target_priv_data->handle = handle;
  5894. goto out;
  5895. }
  5896. }
  5897. out:
  5898. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5899. }
  5900. /**
  5901. * _scsih_search_responding_sas_devices -
  5902. * @ioc: per adapter object
  5903. *
  5904. * After host reset, find out whether devices are still responding.
  5905. * If not remove.
  5906. *
  5907. * Return nothing.
  5908. */
  5909. static void
  5910. _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
  5911. {
  5912. Mpi2SasDevicePage0_t sas_device_pg0;
  5913. Mpi2ConfigReply_t mpi_reply;
  5914. u16 ioc_status;
  5915. __le64 sas_address;
  5916. u16 handle;
  5917. u32 device_info;
  5918. u16 slot;
  5919. printk(MPT2SAS_INFO_FMT "search for end-devices: start\n", ioc->name);
  5920. if (list_empty(&ioc->sas_device_list))
  5921. goto out;
  5922. handle = 0xFFFF;
  5923. while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  5924. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  5925. handle))) {
  5926. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  5927. MPI2_IOCSTATUS_MASK;
  5928. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  5929. break;
  5930. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  5931. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  5932. if (!(_scsih_is_end_device(device_info)))
  5933. continue;
  5934. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  5935. slot = le16_to_cpu(sas_device_pg0.Slot);
  5936. _scsih_mark_responding_sas_device(ioc, sas_address, slot,
  5937. handle);
  5938. }
  5939. out:
  5940. printk(MPT2SAS_INFO_FMT "search for end-devices: complete\n",
  5941. ioc->name);
  5942. }
  5943. /**
  5944. * _scsih_mark_responding_raid_device - mark a raid_device as responding
  5945. * @ioc: per adapter object
  5946. * @wwid: world wide identifier for raid volume
  5947. * @handle: device handle
  5948. *
  5949. * After host reset, find out whether devices are still responding.
  5950. * Used in _scsi_remove_unresponsive_raid_devices.
  5951. *
  5952. * Return nothing.
  5953. */
  5954. static void
  5955. _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
  5956. u16 handle)
  5957. {
  5958. struct MPT2SAS_TARGET *sas_target_priv_data;
  5959. struct scsi_target *starget;
  5960. struct _raid_device *raid_device;
  5961. unsigned long flags;
  5962. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  5963. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  5964. if (raid_device->wwid == wwid && raid_device->starget) {
  5965. starget = raid_device->starget;
  5966. if (starget && starget->hostdata) {
  5967. sas_target_priv_data = starget->hostdata;
  5968. sas_target_priv_data->deleted = 0;
  5969. } else
  5970. sas_target_priv_data = NULL;
  5971. raid_device->responding = 1;
  5972. starget_printk(KERN_INFO, raid_device->starget,
  5973. "handle(0x%04x), wwid(0x%016llx)\n", handle,
  5974. (unsigned long long)raid_device->wwid);
  5975. /*
  5976. * WARPDRIVE: The handles of the PDs might have changed
  5977. * across the host reset so re-initialize the
  5978. * required data for Direct IO
  5979. */
  5980. _scsih_init_warpdrive_properties(ioc, raid_device);
  5981. if (raid_device->handle == handle)
  5982. goto out;
  5983. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  5984. raid_device->handle);
  5985. raid_device->handle = handle;
  5986. if (sas_target_priv_data)
  5987. sas_target_priv_data->handle = handle;
  5988. goto out;
  5989. }
  5990. }
  5991. out:
  5992. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  5993. }
  5994. /**
  5995. * _scsih_search_responding_raid_devices -
  5996. * @ioc: per adapter object
  5997. *
  5998. * After host reset, find out whether devices are still responding.
  5999. * If not remove.
  6000. *
  6001. * Return nothing.
  6002. */
  6003. static void
  6004. _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
  6005. {
  6006. Mpi2RaidVolPage1_t volume_pg1;
  6007. Mpi2RaidVolPage0_t volume_pg0;
  6008. Mpi2RaidPhysDiskPage0_t pd_pg0;
  6009. Mpi2ConfigReply_t mpi_reply;
  6010. u16 ioc_status;
  6011. u16 handle;
  6012. u8 phys_disk_num;
  6013. if (!ioc->ir_firmware)
  6014. return;
  6015. printk(MPT2SAS_INFO_FMT "search for raid volumes: start\n",
  6016. ioc->name);
  6017. if (list_empty(&ioc->raid_device_list))
  6018. goto out;
  6019. handle = 0xFFFF;
  6020. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  6021. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  6022. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6023. MPI2_IOCSTATUS_MASK;
  6024. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6025. break;
  6026. handle = le16_to_cpu(volume_pg1.DevHandle);
  6027. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
  6028. &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  6029. sizeof(Mpi2RaidVolPage0_t)))
  6030. continue;
  6031. if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
  6032. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
  6033. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED)
  6034. _scsih_mark_responding_raid_device(ioc,
  6035. le64_to_cpu(volume_pg1.WWID), handle);
  6036. }
  6037. /* refresh the pd_handles */
  6038. if (!ioc->is_warpdrive) {
  6039. phys_disk_num = 0xFF;
  6040. memset(ioc->pd_handles, 0, ioc->pd_handles_sz);
  6041. while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  6042. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
  6043. phys_disk_num))) {
  6044. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6045. MPI2_IOCSTATUS_MASK;
  6046. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6047. break;
  6048. phys_disk_num = pd_pg0.PhysDiskNum;
  6049. handle = le16_to_cpu(pd_pg0.DevHandle);
  6050. set_bit(handle, ioc->pd_handles);
  6051. }
  6052. }
  6053. out:
  6054. printk(MPT2SAS_INFO_FMT "search for responding raid volumes: "
  6055. "complete\n", ioc->name);
  6056. }
  6057. /**
  6058. * _scsih_mark_responding_expander - mark a expander as responding
  6059. * @ioc: per adapter object
  6060. * @sas_address: sas address
  6061. * @handle:
  6062. *
  6063. * After host reset, find out whether devices are still responding.
  6064. * Used in _scsi_remove_unresponsive_expanders.
  6065. *
  6066. * Return nothing.
  6067. */
  6068. static void
  6069. _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  6070. u16 handle)
  6071. {
  6072. struct _sas_node *sas_expander;
  6073. unsigned long flags;
  6074. int i;
  6075. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  6076. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  6077. if (sas_expander->sas_address != sas_address)
  6078. continue;
  6079. sas_expander->responding = 1;
  6080. if (sas_expander->handle == handle)
  6081. goto out;
  6082. printk(KERN_INFO "\texpander(0x%016llx): handle changed"
  6083. " from(0x%04x) to (0x%04x)!!!\n",
  6084. (unsigned long long)sas_expander->sas_address,
  6085. sas_expander->handle, handle);
  6086. sas_expander->handle = handle;
  6087. for (i = 0 ; i < sas_expander->num_phys ; i++)
  6088. sas_expander->phy[i].handle = handle;
  6089. goto out;
  6090. }
  6091. out:
  6092. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  6093. }
  6094. /**
  6095. * _scsih_search_responding_expanders -
  6096. * @ioc: per adapter object
  6097. *
  6098. * After host reset, find out whether devices are still responding.
  6099. * If not remove.
  6100. *
  6101. * Return nothing.
  6102. */
  6103. static void
  6104. _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
  6105. {
  6106. Mpi2ExpanderPage0_t expander_pg0;
  6107. Mpi2ConfigReply_t mpi_reply;
  6108. u16 ioc_status;
  6109. u64 sas_address;
  6110. u16 handle;
  6111. printk(MPT2SAS_INFO_FMT "search for expanders: start\n", ioc->name);
  6112. if (list_empty(&ioc->sas_expander_list))
  6113. goto out;
  6114. handle = 0xFFFF;
  6115. while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  6116. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  6117. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6118. MPI2_IOCSTATUS_MASK;
  6119. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6120. break;
  6121. handle = le16_to_cpu(expander_pg0.DevHandle);
  6122. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  6123. printk(KERN_INFO "\texpander present: handle(0x%04x), "
  6124. "sas_addr(0x%016llx)\n", handle,
  6125. (unsigned long long)sas_address);
  6126. _scsih_mark_responding_expander(ioc, sas_address, handle);
  6127. }
  6128. out:
  6129. printk(MPT2SAS_INFO_FMT "search for expanders: complete\n", ioc->name);
  6130. }
  6131. /**
  6132. * _scsih_remove_unresponding_sas_devices - removing unresponding devices
  6133. * @ioc: per adapter object
  6134. *
  6135. * Return nothing.
  6136. */
  6137. static void
  6138. _scsih_remove_unresponding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
  6139. {
  6140. struct _sas_device *sas_device, *sas_device_next;
  6141. struct _sas_node *sas_expander;
  6142. struct _raid_device *raid_device, *raid_device_next;
  6143. printk(MPT2SAS_INFO_FMT "removing unresponding devices: start\n",
  6144. ioc->name);
  6145. list_for_each_entry_safe(sas_device, sas_device_next,
  6146. &ioc->sas_device_list, list) {
  6147. if (sas_device->responding) {
  6148. sas_device->responding = 0;
  6149. continue;
  6150. }
  6151. if (sas_device->starget)
  6152. starget_printk(KERN_INFO, sas_device->starget,
  6153. "removing: handle(0x%04x), sas_addr(0x%016llx), "
  6154. "enclosure logical id(0x%016llx), slot(%d)\n",
  6155. sas_device->handle,
  6156. (unsigned long long)sas_device->sas_address,
  6157. (unsigned long long)
  6158. sas_device->enclosure_logical_id,
  6159. sas_device->slot);
  6160. _scsih_remove_device(ioc, sas_device);
  6161. }
  6162. if (!ioc->ir_firmware)
  6163. goto retry_expander_search;
  6164. list_for_each_entry_safe(raid_device, raid_device_next,
  6165. &ioc->raid_device_list, list) {
  6166. if (raid_device->responding) {
  6167. raid_device->responding = 0;
  6168. continue;
  6169. }
  6170. if (raid_device->starget) {
  6171. starget_printk(KERN_INFO, raid_device->starget,
  6172. "removing: handle(0x%04x), wwid(0x%016llx)\n",
  6173. raid_device->handle,
  6174. (unsigned long long)raid_device->wwid);
  6175. scsi_remove_target(&raid_device->starget->dev);
  6176. }
  6177. _scsih_raid_device_remove(ioc, raid_device);
  6178. }
  6179. retry_expander_search:
  6180. sas_expander = NULL;
  6181. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  6182. if (sas_expander->responding) {
  6183. sas_expander->responding = 0;
  6184. continue;
  6185. }
  6186. mpt2sas_expander_remove(ioc, sas_expander->sas_address);
  6187. goto retry_expander_search;
  6188. }
  6189. printk(MPT2SAS_INFO_FMT "removing unresponding devices: complete\n",
  6190. ioc->name);
  6191. /* unblock devices */
  6192. _scsih_ublock_io_all_device(ioc);
  6193. }
  6194. static void
  6195. _scsih_refresh_expander_links(struct MPT2SAS_ADAPTER *ioc,
  6196. struct _sas_node *sas_expander, u16 handle)
  6197. {
  6198. Mpi2ExpanderPage1_t expander_pg1;
  6199. Mpi2ConfigReply_t mpi_reply;
  6200. int i;
  6201. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  6202. if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
  6203. &expander_pg1, i, handle))) {
  6204. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  6205. ioc->name, __FILE__, __LINE__, __func__);
  6206. return;
  6207. }
  6208. mpt2sas_transport_update_links(ioc, sas_expander->sas_address,
  6209. le16_to_cpu(expander_pg1.AttachedDevHandle), i,
  6210. expander_pg1.NegotiatedLinkRate >> 4);
  6211. }
  6212. }
  6213. /**
  6214. * _scsih_scan_for_devices_after_reset - scan for devices after host reset
  6215. * @ioc: per adapter object
  6216. *
  6217. * Return nothing.
  6218. */
  6219. static void
  6220. _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
  6221. {
  6222. Mpi2ExpanderPage0_t expander_pg0;
  6223. Mpi2SasDevicePage0_t sas_device_pg0;
  6224. Mpi2RaidVolPage1_t volume_pg1;
  6225. Mpi2RaidVolPage0_t volume_pg0;
  6226. Mpi2RaidPhysDiskPage0_t pd_pg0;
  6227. Mpi2EventIrConfigElement_t element;
  6228. Mpi2ConfigReply_t mpi_reply;
  6229. u8 phys_disk_num;
  6230. u16 ioc_status;
  6231. u16 handle, parent_handle;
  6232. u64 sas_address;
  6233. struct _sas_device *sas_device;
  6234. struct _sas_node *expander_device;
  6235. static struct _raid_device *raid_device;
  6236. printk(MPT2SAS_INFO_FMT "scan devices: start\n", ioc->name);
  6237. _scsih_sas_host_refresh(ioc);
  6238. /* expanders */
  6239. handle = 0xFFFF;
  6240. while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  6241. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  6242. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6243. MPI2_IOCSTATUS_MASK;
  6244. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6245. break;
  6246. handle = le16_to_cpu(expander_pg0.DevHandle);
  6247. expander_device = mpt2sas_scsih_expander_find_by_sas_address(
  6248. ioc, le64_to_cpu(expander_pg0.SASAddress));
  6249. if (expander_device)
  6250. _scsih_refresh_expander_links(ioc, expander_device,
  6251. handle);
  6252. else
  6253. _scsih_expander_add(ioc, handle);
  6254. }
  6255. if (!ioc->ir_firmware)
  6256. goto skip_to_sas;
  6257. /* phys disk */
  6258. phys_disk_num = 0xFF;
  6259. while (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  6260. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_GET_NEXT_PHYSDISKNUM,
  6261. phys_disk_num))) {
  6262. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6263. MPI2_IOCSTATUS_MASK;
  6264. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6265. break;
  6266. phys_disk_num = pd_pg0.PhysDiskNum;
  6267. handle = le16_to_cpu(pd_pg0.DevHandle);
  6268. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  6269. if (sas_device)
  6270. continue;
  6271. if (mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  6272. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  6273. handle) != 0)
  6274. continue;
  6275. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  6276. if (!_scsih_get_sas_address(ioc, parent_handle,
  6277. &sas_address)) {
  6278. mpt2sas_transport_update_links(ioc, sas_address,
  6279. handle, sas_device_pg0.PhyNum,
  6280. MPI2_SAS_NEG_LINK_RATE_1_5);
  6281. set_bit(handle, ioc->pd_handles);
  6282. _scsih_add_device(ioc, handle, 0, 1);
  6283. }
  6284. }
  6285. /* volumes */
  6286. handle = 0xFFFF;
  6287. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  6288. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  6289. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6290. MPI2_IOCSTATUS_MASK;
  6291. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6292. break;
  6293. handle = le16_to_cpu(volume_pg1.DevHandle);
  6294. raid_device = _scsih_raid_device_find_by_wwid(ioc,
  6295. le64_to_cpu(volume_pg1.WWID));
  6296. if (raid_device)
  6297. continue;
  6298. if (mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply,
  6299. &volume_pg0, MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, handle,
  6300. sizeof(Mpi2RaidVolPage0_t)))
  6301. continue;
  6302. if (volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_OPTIMAL ||
  6303. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_ONLINE ||
  6304. volume_pg0.VolumeState == MPI2_RAID_VOL_STATE_DEGRADED) {
  6305. memset(&element, 0, sizeof(Mpi2EventIrConfigElement_t));
  6306. element.ReasonCode = MPI2_EVENT_IR_CHANGE_RC_ADDED;
  6307. element.VolDevHandle = volume_pg1.DevHandle;
  6308. _scsih_sas_volume_add(ioc, &element);
  6309. }
  6310. }
  6311. skip_to_sas:
  6312. /* sas devices */
  6313. handle = 0xFFFF;
  6314. while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  6315. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  6316. handle))) {
  6317. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  6318. MPI2_IOCSTATUS_MASK;
  6319. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  6320. break;
  6321. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  6322. if (!(_scsih_is_end_device(
  6323. le32_to_cpu(sas_device_pg0.DeviceInfo))))
  6324. continue;
  6325. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  6326. le64_to_cpu(sas_device_pg0.SASAddress));
  6327. if (sas_device)
  6328. continue;
  6329. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  6330. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address)) {
  6331. mpt2sas_transport_update_links(ioc, sas_address, handle,
  6332. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  6333. _scsih_add_device(ioc, handle, 0, 0);
  6334. }
  6335. }
  6336. printk(MPT2SAS_INFO_FMT "scan devices: complete\n", ioc->name);
  6337. }
  6338. /**
  6339. * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
  6340. * @ioc: per adapter object
  6341. * @reset_phase: phase
  6342. *
  6343. * The handler for doing any required cleanup or initialization.
  6344. *
  6345. * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
  6346. * MPT2_IOC_DONE_RESET
  6347. *
  6348. * Return nothing.
  6349. */
  6350. void
  6351. mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
  6352. {
  6353. switch (reset_phase) {
  6354. case MPT2_IOC_PRE_RESET:
  6355. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  6356. "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
  6357. break;
  6358. case MPT2_IOC_AFTER_RESET:
  6359. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  6360. "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
  6361. if (ioc->scsih_cmds.status & MPT2_CMD_PENDING) {
  6362. ioc->scsih_cmds.status |= MPT2_CMD_RESET;
  6363. mpt2sas_base_free_smid(ioc, ioc->scsih_cmds.smid);
  6364. complete(&ioc->scsih_cmds.done);
  6365. }
  6366. if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
  6367. ioc->tm_cmds.status |= MPT2_CMD_RESET;
  6368. mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
  6369. complete(&ioc->tm_cmds.done);
  6370. }
  6371. _scsih_fw_event_cleanup_queue(ioc);
  6372. _scsih_flush_running_cmds(ioc);
  6373. break;
  6374. case MPT2_IOC_DONE_RESET:
  6375. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: "
  6376. "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
  6377. _scsih_sas_host_refresh(ioc);
  6378. _scsih_prep_device_scan(ioc);
  6379. _scsih_search_responding_sas_devices(ioc);
  6380. _scsih_search_responding_raid_devices(ioc);
  6381. _scsih_search_responding_expanders(ioc);
  6382. _scsih_error_recovery_delete_devices(ioc);
  6383. break;
  6384. }
  6385. }
  6386. /**
  6387. * _firmware_event_work - delayed task for processing firmware events
  6388. * @ioc: per adapter object
  6389. * @work: equal to the fw_event_work object
  6390. * Context: user.
  6391. *
  6392. * Return nothing.
  6393. */
  6394. static void
  6395. _firmware_event_work(struct work_struct *work)
  6396. {
  6397. struct fw_event_work *fw_event = container_of(work,
  6398. struct fw_event_work, delayed_work.work);
  6399. struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
  6400. /* the queue is being flushed so ignore this event */
  6401. if (ioc->remove_host || fw_event->cancel_pending_work ||
  6402. ioc->pci_error_recovery) {
  6403. _scsih_fw_event_free(ioc, fw_event);
  6404. return;
  6405. }
  6406. switch (fw_event->event) {
  6407. case MPT2SAS_REMOVE_UNRESPONDING_DEVICES:
  6408. while (scsi_host_in_recovery(ioc->shost))
  6409. ssleep(1);
  6410. _scsih_remove_unresponding_sas_devices(ioc);
  6411. _scsih_scan_for_devices_after_reset(ioc);
  6412. break;
  6413. case MPT2SAS_PORT_ENABLE_COMPLETE:
  6414. if (!ioc->is_driver_loading && ioc->shost_recovery) {
  6415. _scsih_prep_device_scan(ioc);
  6416. _scsih_search_responding_sas_devices(ioc);
  6417. _scsih_search_responding_raid_devices(ioc);
  6418. _scsih_search_responding_expanders(ioc);
  6419. }
  6420. if (ioc->start_scan)
  6421. ioc->start_scan = 0;
  6422. else
  6423. complete(&ioc->port_enable_done);
  6424. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "port enable: complete "
  6425. "from worker thread\n", ioc->name));
  6426. break;
  6427. case MPT2SAS_TURN_ON_FAULT_LED:
  6428. _scsih_turn_on_fault_led(ioc, fw_event->device_handle);
  6429. break;
  6430. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  6431. _scsih_sas_topology_change_event(ioc, fw_event);
  6432. break;
  6433. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  6434. _scsih_sas_device_status_change_event(ioc,
  6435. fw_event);
  6436. break;
  6437. case MPI2_EVENT_SAS_DISCOVERY:
  6438. _scsih_sas_discovery_event(ioc,
  6439. fw_event);
  6440. break;
  6441. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  6442. _scsih_sas_broadcast_primative_event(ioc,
  6443. fw_event);
  6444. break;
  6445. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  6446. _scsih_sas_enclosure_dev_status_change_event(ioc,
  6447. fw_event);
  6448. break;
  6449. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  6450. _scsih_sas_ir_config_change_event(ioc, fw_event);
  6451. break;
  6452. case MPI2_EVENT_IR_VOLUME:
  6453. _scsih_sas_ir_volume_event(ioc, fw_event);
  6454. break;
  6455. case MPI2_EVENT_IR_PHYSICAL_DISK:
  6456. _scsih_sas_ir_physical_disk_event(ioc, fw_event);
  6457. break;
  6458. case MPI2_EVENT_IR_OPERATION_STATUS:
  6459. _scsih_sas_ir_operation_status_event(ioc, fw_event);
  6460. break;
  6461. }
  6462. _scsih_fw_event_free(ioc, fw_event);
  6463. }
  6464. /**
  6465. * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
  6466. * @ioc: per adapter object
  6467. * @msix_index: MSIX table index supplied by the OS
  6468. * @reply: reply message frame(lower 32bit addr)
  6469. * Context: interrupt.
  6470. *
  6471. * This function merely adds a new work task into ioc->firmware_event_thread.
  6472. * The tasks are worked from _firmware_event_work in user context.
  6473. *
  6474. * Return 1 meaning mf should be freed from _base_interrupt
  6475. * 0 means the mf is freed from this function.
  6476. */
  6477. u8
  6478. mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
  6479. u32 reply)
  6480. {
  6481. struct fw_event_work *fw_event;
  6482. Mpi2EventNotificationReply_t *mpi_reply;
  6483. u16 event;
  6484. u16 sz;
  6485. /* events turned off due to host reset or driver unloading */
  6486. if (ioc->remove_host || ioc->pci_error_recovery)
  6487. return 1;
  6488. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  6489. event = le16_to_cpu(mpi_reply->Event);
  6490. switch (event) {
  6491. /* handle these */
  6492. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  6493. {
  6494. Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
  6495. (Mpi2EventDataSasBroadcastPrimitive_t *)
  6496. mpi_reply->EventData;
  6497. if (baen_data->Primitive !=
  6498. MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT)
  6499. return 1;
  6500. if (ioc->broadcast_aen_busy) {
  6501. ioc->broadcast_aen_pending++;
  6502. return 1;
  6503. } else
  6504. ioc->broadcast_aen_busy = 1;
  6505. break;
  6506. }
  6507. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  6508. _scsih_check_topo_delete_events(ioc,
  6509. (Mpi2EventDataSasTopologyChangeList_t *)
  6510. mpi_reply->EventData);
  6511. break;
  6512. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  6513. _scsih_check_ir_config_unhide_events(ioc,
  6514. (Mpi2EventDataIrConfigChangeList_t *)
  6515. mpi_reply->EventData);
  6516. break;
  6517. case MPI2_EVENT_IR_VOLUME:
  6518. _scsih_check_volume_delete_events(ioc,
  6519. (Mpi2EventDataIrVolume_t *)
  6520. mpi_reply->EventData);
  6521. break;
  6522. case MPI2_EVENT_LOG_ENTRY_ADDED:
  6523. {
  6524. Mpi2EventDataLogEntryAdded_t *log_entry;
  6525. u32 *log_code;
  6526. if (!ioc->is_warpdrive)
  6527. break;
  6528. log_entry = (Mpi2EventDataLogEntryAdded_t *)
  6529. mpi_reply->EventData;
  6530. log_code = (u32 *)log_entry->LogData;
  6531. if (le16_to_cpu(log_entry->LogEntryQualifier)
  6532. != MPT2_WARPDRIVE_LOGENTRY)
  6533. break;
  6534. switch (le32_to_cpu(*log_code)) {
  6535. case MPT2_WARPDRIVE_LC_SSDT:
  6536. printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
  6537. "IO Throttling has occurred in the WarpDrive "
  6538. "subsystem. Check WarpDrive documentation for "
  6539. "additional details.\n", ioc->name);
  6540. break;
  6541. case MPT2_WARPDRIVE_LC_SSDLW:
  6542. printk(MPT2SAS_WARN_FMT "WarpDrive Warning: "
  6543. "Program/Erase Cycles for the WarpDrive subsystem "
  6544. "in degraded range. Check WarpDrive documentation "
  6545. "for additional details.\n", ioc->name);
  6546. break;
  6547. case MPT2_WARPDRIVE_LC_SSDLF:
  6548. printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
  6549. "There are no Program/Erase Cycles for the "
  6550. "WarpDrive subsystem. The storage device will be "
  6551. "in read-only mode. Check WarpDrive documentation "
  6552. "for additional details.\n", ioc->name);
  6553. break;
  6554. case MPT2_WARPDRIVE_LC_BRMF:
  6555. printk(MPT2SAS_ERR_FMT "WarpDrive Fatal Error: "
  6556. "The Backup Rail Monitor has failed on the "
  6557. "WarpDrive subsystem. Check WarpDrive "
  6558. "documentation for additional details.\n",
  6559. ioc->name);
  6560. break;
  6561. }
  6562. break;
  6563. }
  6564. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  6565. case MPI2_EVENT_IR_OPERATION_STATUS:
  6566. case MPI2_EVENT_SAS_DISCOVERY:
  6567. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  6568. case MPI2_EVENT_IR_PHYSICAL_DISK:
  6569. break;
  6570. default: /* ignore the rest */
  6571. return 1;
  6572. }
  6573. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  6574. if (!fw_event) {
  6575. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  6576. ioc->name, __FILE__, __LINE__, __func__);
  6577. return 1;
  6578. }
  6579. sz = le16_to_cpu(mpi_reply->EventDataLength) * 4;
  6580. fw_event->event_data = kzalloc(sz, GFP_ATOMIC);
  6581. if (!fw_event->event_data) {
  6582. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  6583. ioc->name, __FILE__, __LINE__, __func__);
  6584. kfree(fw_event);
  6585. return 1;
  6586. }
  6587. memcpy(fw_event->event_data, mpi_reply->EventData,
  6588. sz);
  6589. fw_event->ioc = ioc;
  6590. fw_event->VF_ID = mpi_reply->VF_ID;
  6591. fw_event->VP_ID = mpi_reply->VP_ID;
  6592. fw_event->event = event;
  6593. _scsih_fw_event_add(ioc, fw_event);
  6594. return 1;
  6595. }
  6596. /* shost template */
  6597. static struct scsi_host_template scsih_driver_template = {
  6598. .module = THIS_MODULE,
  6599. .name = "Fusion MPT SAS Host",
  6600. .proc_name = MPT2SAS_DRIVER_NAME,
  6601. .queuecommand = _scsih_qcmd,
  6602. .target_alloc = _scsih_target_alloc,
  6603. .slave_alloc = _scsih_slave_alloc,
  6604. .slave_configure = _scsih_slave_configure,
  6605. .target_destroy = _scsih_target_destroy,
  6606. .slave_destroy = _scsih_slave_destroy,
  6607. .scan_finished = _scsih_scan_finished,
  6608. .scan_start = _scsih_scan_start,
  6609. .change_queue_depth = _scsih_change_queue_depth,
  6610. .change_queue_type = _scsih_change_queue_type,
  6611. .eh_abort_handler = _scsih_abort,
  6612. .eh_device_reset_handler = _scsih_dev_reset,
  6613. .eh_target_reset_handler = _scsih_target_reset,
  6614. .eh_host_reset_handler = _scsih_host_reset,
  6615. .bios_param = _scsih_bios_param,
  6616. .can_queue = 1,
  6617. .this_id = -1,
  6618. .sg_tablesize = MPT2SAS_SG_DEPTH,
  6619. .max_sectors = 8192,
  6620. .cmd_per_lun = 7,
  6621. .use_clustering = ENABLE_CLUSTERING,
  6622. .shost_attrs = mpt2sas_host_attrs,
  6623. .sdev_attrs = mpt2sas_dev_attrs,
  6624. };
  6625. /**
  6626. * _scsih_expander_node_remove - removing expander device from list.
  6627. * @ioc: per adapter object
  6628. * @sas_expander: the sas_device object
  6629. * Context: Calling function should acquire ioc->sas_node_lock.
  6630. *
  6631. * Removing object and freeing associated memory from the
  6632. * ioc->sas_expander_list.
  6633. *
  6634. * Return nothing.
  6635. */
  6636. static void
  6637. _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  6638. struct _sas_node *sas_expander)
  6639. {
  6640. struct _sas_port *mpt2sas_port, *next;
  6641. /* remove sibling ports attached to this expander */
  6642. list_for_each_entry_safe(mpt2sas_port, next,
  6643. &sas_expander->sas_port_list, port_list) {
  6644. if (ioc->shost_recovery)
  6645. return;
  6646. if (mpt2sas_port->remote_identify.device_type ==
  6647. SAS_END_DEVICE)
  6648. mpt2sas_device_remove(ioc,
  6649. mpt2sas_port->remote_identify.sas_address);
  6650. else if (mpt2sas_port->remote_identify.device_type ==
  6651. SAS_EDGE_EXPANDER_DEVICE ||
  6652. mpt2sas_port->remote_identify.device_type ==
  6653. SAS_FANOUT_EXPANDER_DEVICE)
  6654. mpt2sas_expander_remove(ioc,
  6655. mpt2sas_port->remote_identify.sas_address);
  6656. }
  6657. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  6658. sas_expander->sas_address_parent);
  6659. printk(MPT2SAS_INFO_FMT "expander_remove: handle"
  6660. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  6661. sas_expander->handle, (unsigned long long)
  6662. sas_expander->sas_address);
  6663. kfree(sas_expander->phy);
  6664. kfree(sas_expander);
  6665. }
  6666. /**
  6667. * _scsih_ir_shutdown - IR shutdown notification
  6668. * @ioc: per adapter object
  6669. *
  6670. * Sending RAID Action to alert the Integrated RAID subsystem of the IOC that
  6671. * the host system is shutting down.
  6672. *
  6673. * Return nothing.
  6674. */
  6675. static void
  6676. _scsih_ir_shutdown(struct MPT2SAS_ADAPTER *ioc)
  6677. {
  6678. Mpi2RaidActionRequest_t *mpi_request;
  6679. Mpi2RaidActionReply_t *mpi_reply;
  6680. u16 smid;
  6681. /* is IR firmware build loaded ? */
  6682. if (!ioc->ir_firmware)
  6683. return;
  6684. /* are there any volumes ? */
  6685. if (list_empty(&ioc->raid_device_list))
  6686. return;
  6687. mutex_lock(&ioc->scsih_cmds.mutex);
  6688. if (ioc->scsih_cmds.status != MPT2_CMD_NOT_USED) {
  6689. printk(MPT2SAS_ERR_FMT "%s: scsih_cmd in use\n",
  6690. ioc->name, __func__);
  6691. goto out;
  6692. }
  6693. ioc->scsih_cmds.status = MPT2_CMD_PENDING;
  6694. smid = mpt2sas_base_get_smid(ioc, ioc->scsih_cb_idx);
  6695. if (!smid) {
  6696. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  6697. ioc->name, __func__);
  6698. ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
  6699. goto out;
  6700. }
  6701. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  6702. ioc->scsih_cmds.smid = smid;
  6703. memset(mpi_request, 0, sizeof(Mpi2RaidActionRequest_t));
  6704. mpi_request->Function = MPI2_FUNCTION_RAID_ACTION;
  6705. mpi_request->Action = MPI2_RAID_ACTION_SYSTEM_SHUTDOWN_INITIATED;
  6706. if (!ioc->hide_ir_msg)
  6707. printk(MPT2SAS_INFO_FMT "IR shutdown (sending)\n", ioc->name);
  6708. init_completion(&ioc->scsih_cmds.done);
  6709. mpt2sas_base_put_smid_default(ioc, smid);
  6710. wait_for_completion_timeout(&ioc->scsih_cmds.done, 10*HZ);
  6711. if (!(ioc->scsih_cmds.status & MPT2_CMD_COMPLETE)) {
  6712. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  6713. ioc->name, __func__);
  6714. goto out;
  6715. }
  6716. if (ioc->scsih_cmds.status & MPT2_CMD_REPLY_VALID) {
  6717. mpi_reply = ioc->scsih_cmds.reply;
  6718. if (!ioc->hide_ir_msg)
  6719. printk(MPT2SAS_INFO_FMT "IR shutdown (complete): "
  6720. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  6721. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  6722. le32_to_cpu(mpi_reply->IOCLogInfo));
  6723. }
  6724. out:
  6725. ioc->scsih_cmds.status = MPT2_CMD_NOT_USED;
  6726. mutex_unlock(&ioc->scsih_cmds.mutex);
  6727. }
  6728. /**
  6729. * _scsih_shutdown - routine call during system shutdown
  6730. * @pdev: PCI device struct
  6731. *
  6732. * Return nothing.
  6733. */
  6734. static void
  6735. _scsih_shutdown(struct pci_dev *pdev)
  6736. {
  6737. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6738. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6739. struct workqueue_struct *wq;
  6740. unsigned long flags;
  6741. ioc->remove_host = 1;
  6742. _scsih_fw_event_cleanup_queue(ioc);
  6743. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  6744. wq = ioc->firmware_event_thread;
  6745. ioc->firmware_event_thread = NULL;
  6746. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  6747. if (wq)
  6748. destroy_workqueue(wq);
  6749. _scsih_ir_shutdown(ioc);
  6750. mpt2sas_base_detach(ioc);
  6751. }
  6752. /**
  6753. * _scsih_remove - detach and remove add host
  6754. * @pdev: PCI device struct
  6755. *
  6756. * Routine called when unloading the driver.
  6757. * Return nothing.
  6758. */
  6759. static void __devexit
  6760. _scsih_remove(struct pci_dev *pdev)
  6761. {
  6762. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  6763. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6764. struct _sas_port *mpt2sas_port, *next_port;
  6765. struct _raid_device *raid_device, *next;
  6766. struct MPT2SAS_TARGET *sas_target_priv_data;
  6767. struct workqueue_struct *wq;
  6768. unsigned long flags;
  6769. ioc->remove_host = 1;
  6770. _scsih_fw_event_cleanup_queue(ioc);
  6771. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  6772. wq = ioc->firmware_event_thread;
  6773. ioc->firmware_event_thread = NULL;
  6774. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  6775. if (wq)
  6776. destroy_workqueue(wq);
  6777. /* release all the volumes */
  6778. _scsih_ir_shutdown(ioc);
  6779. list_for_each_entry_safe(raid_device, next, &ioc->raid_device_list,
  6780. list) {
  6781. if (raid_device->starget) {
  6782. sas_target_priv_data =
  6783. raid_device->starget->hostdata;
  6784. sas_target_priv_data->deleted = 1;
  6785. scsi_remove_target(&raid_device->starget->dev);
  6786. }
  6787. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), wwid"
  6788. "(0x%016llx)\n", ioc->name, raid_device->handle,
  6789. (unsigned long long) raid_device->wwid);
  6790. _scsih_raid_device_remove(ioc, raid_device);
  6791. }
  6792. /* free ports attached to the sas_host */
  6793. list_for_each_entry_safe(mpt2sas_port, next_port,
  6794. &ioc->sas_hba.sas_port_list, port_list) {
  6795. if (mpt2sas_port->remote_identify.device_type ==
  6796. SAS_END_DEVICE)
  6797. mpt2sas_device_remove(ioc,
  6798. mpt2sas_port->remote_identify.sas_address);
  6799. else if (mpt2sas_port->remote_identify.device_type ==
  6800. SAS_EDGE_EXPANDER_DEVICE ||
  6801. mpt2sas_port->remote_identify.device_type ==
  6802. SAS_FANOUT_EXPANDER_DEVICE)
  6803. mpt2sas_expander_remove(ioc,
  6804. mpt2sas_port->remote_identify.sas_address);
  6805. }
  6806. /* free phys attached to the sas_host */
  6807. if (ioc->sas_hba.num_phys) {
  6808. kfree(ioc->sas_hba.phy);
  6809. ioc->sas_hba.phy = NULL;
  6810. ioc->sas_hba.num_phys = 0;
  6811. }
  6812. sas_remove_host(shost);
  6813. mpt2sas_base_detach(ioc);
  6814. list_del(&ioc->list);
  6815. scsi_remove_host(shost);
  6816. scsi_host_put(shost);
  6817. }
  6818. /**
  6819. * _scsih_probe_boot_devices - reports 1st device
  6820. * @ioc: per adapter object
  6821. *
  6822. * If specified in bios page 2, this routine reports the 1st
  6823. * device scsi-ml or sas transport for persistent boot device
  6824. * purposes. Please refer to function _scsih_determine_boot_device()
  6825. */
  6826. static void
  6827. _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
  6828. {
  6829. u8 is_raid;
  6830. void *device;
  6831. struct _sas_device *sas_device;
  6832. struct _raid_device *raid_device;
  6833. u16 handle;
  6834. u64 sas_address_parent;
  6835. u64 sas_address;
  6836. unsigned long flags;
  6837. int rc;
  6838. /* no Bios, return immediately */
  6839. if (!ioc->bios_pg3.BiosVersion)
  6840. return;
  6841. device = NULL;
  6842. is_raid = 0;
  6843. if (ioc->req_boot_device.device) {
  6844. device = ioc->req_boot_device.device;
  6845. is_raid = ioc->req_boot_device.is_raid;
  6846. } else if (ioc->req_alt_boot_device.device) {
  6847. device = ioc->req_alt_boot_device.device;
  6848. is_raid = ioc->req_alt_boot_device.is_raid;
  6849. } else if (ioc->current_boot_device.device) {
  6850. device = ioc->current_boot_device.device;
  6851. is_raid = ioc->current_boot_device.is_raid;
  6852. }
  6853. if (!device)
  6854. return;
  6855. if (is_raid) {
  6856. raid_device = device;
  6857. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  6858. raid_device->id, 0);
  6859. if (rc)
  6860. _scsih_raid_device_remove(ioc, raid_device);
  6861. } else {
  6862. sas_device = device;
  6863. handle = sas_device->handle;
  6864. sas_address_parent = sas_device->sas_address_parent;
  6865. sas_address = sas_device->sas_address;
  6866. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  6867. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  6868. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  6869. if (ioc->hide_drives)
  6870. return;
  6871. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  6872. sas_device->sas_address_parent)) {
  6873. _scsih_sas_device_remove(ioc, sas_device);
  6874. } else if (!sas_device->starget) {
  6875. mpt2sas_transport_port_remove(ioc, sas_address,
  6876. sas_address_parent);
  6877. _scsih_sas_device_remove(ioc, sas_device);
  6878. }
  6879. }
  6880. }
  6881. /**
  6882. * _scsih_probe_raid - reporting raid volumes to scsi-ml
  6883. * @ioc: per adapter object
  6884. *
  6885. * Called during initial loading of the driver.
  6886. */
  6887. static void
  6888. _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
  6889. {
  6890. struct _raid_device *raid_device, *raid_next;
  6891. int rc;
  6892. list_for_each_entry_safe(raid_device, raid_next,
  6893. &ioc->raid_device_list, list) {
  6894. if (raid_device->starget)
  6895. continue;
  6896. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  6897. raid_device->id, 0);
  6898. if (rc)
  6899. _scsih_raid_device_remove(ioc, raid_device);
  6900. }
  6901. }
  6902. /**
  6903. * _scsih_probe_sas - reporting sas devices to sas transport
  6904. * @ioc: per adapter object
  6905. *
  6906. * Called during initial loading of the driver.
  6907. */
  6908. static void
  6909. _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
  6910. {
  6911. struct _sas_device *sas_device, *next;
  6912. unsigned long flags;
  6913. /* SAS Device List */
  6914. list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
  6915. list) {
  6916. if (ioc->hide_drives)
  6917. continue;
  6918. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  6919. sas_device->sas_address_parent)) {
  6920. list_del(&sas_device->list);
  6921. kfree(sas_device);
  6922. continue;
  6923. } else if (!sas_device->starget) {
  6924. mpt2sas_transport_port_remove(ioc,
  6925. sas_device->sas_address,
  6926. sas_device->sas_address_parent);
  6927. list_del(&sas_device->list);
  6928. kfree(sas_device);
  6929. continue;
  6930. }
  6931. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  6932. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  6933. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  6934. }
  6935. }
  6936. /**
  6937. * _scsih_probe_devices - probing for devices
  6938. * @ioc: per adapter object
  6939. *
  6940. * Called during initial loading of the driver.
  6941. */
  6942. static void
  6943. _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
  6944. {
  6945. u16 volume_mapping_flags;
  6946. if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
  6947. return; /* return when IOC doesn't support initiator mode */
  6948. _scsih_probe_boot_devices(ioc);
  6949. if (ioc->ir_firmware) {
  6950. volume_mapping_flags =
  6951. le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
  6952. MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
  6953. if (volume_mapping_flags ==
  6954. MPI2_IOCPAGE8_IRFLAGS_LOW_VOLUME_MAPPING) {
  6955. _scsih_probe_raid(ioc);
  6956. _scsih_probe_sas(ioc);
  6957. } else {
  6958. _scsih_probe_sas(ioc);
  6959. _scsih_probe_raid(ioc);
  6960. }
  6961. } else
  6962. _scsih_probe_sas(ioc);
  6963. }
  6964. /**
  6965. * _scsih_scan_start - scsi lld callback for .scan_start
  6966. * @shost: SCSI host pointer
  6967. *
  6968. * The shost has the ability to discover targets on its own instead
  6969. * of scanning the entire bus. In our implemention, we will kick off
  6970. * firmware discovery.
  6971. */
  6972. static void
  6973. _scsih_scan_start(struct Scsi_Host *shost)
  6974. {
  6975. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6976. int rc;
  6977. if (diag_buffer_enable != -1 && diag_buffer_enable != 0)
  6978. mpt2sas_enable_diag_buffer(ioc, diag_buffer_enable);
  6979. ioc->start_scan = 1;
  6980. rc = mpt2sas_port_enable(ioc);
  6981. if (rc != 0)
  6982. printk(MPT2SAS_INFO_FMT "port enable: FAILED\n", ioc->name);
  6983. }
  6984. /**
  6985. * _scsih_scan_finished - scsi lld callback for .scan_finished
  6986. * @shost: SCSI host pointer
  6987. * @time: elapsed time of the scan in jiffies
  6988. *
  6989. * This function will be called periodically until it returns 1 with the
  6990. * scsi_host and the elapsed time of the scan in jiffies. In our implemention,
  6991. * we wait for firmware discovery to complete, then return 1.
  6992. */
  6993. static int
  6994. _scsih_scan_finished(struct Scsi_Host *shost, unsigned long time)
  6995. {
  6996. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  6997. if (time >= (300 * HZ)) {
  6998. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  6999. printk(MPT2SAS_INFO_FMT "port enable: FAILED with timeout "
  7000. "(timeout=300s)\n", ioc->name);
  7001. ioc->is_driver_loading = 0;
  7002. return 1;
  7003. }
  7004. if (ioc->start_scan)
  7005. return 0;
  7006. if (ioc->start_scan_failed) {
  7007. printk(MPT2SAS_INFO_FMT "port enable: FAILED with "
  7008. "(ioc_status=0x%08x)\n", ioc->name, ioc->start_scan_failed);
  7009. ioc->is_driver_loading = 0;
  7010. ioc->wait_for_discovery_to_complete = 0;
  7011. ioc->remove_host = 1;
  7012. return 1;
  7013. }
  7014. printk(MPT2SAS_INFO_FMT "port enable: SUCCESS\n", ioc->name);
  7015. ioc->base_cmds.status = MPT2_CMD_NOT_USED;
  7016. if (ioc->wait_for_discovery_to_complete) {
  7017. ioc->wait_for_discovery_to_complete = 0;
  7018. _scsih_probe_devices(ioc);
  7019. }
  7020. mpt2sas_base_start_watchdog(ioc);
  7021. ioc->is_driver_loading = 0;
  7022. return 1;
  7023. }
  7024. /**
  7025. * _scsih_probe - attach and add scsi host
  7026. * @pdev: PCI device struct
  7027. * @id: pci device id
  7028. *
  7029. * Returns 0 success, anything else error.
  7030. */
  7031. static int
  7032. _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  7033. {
  7034. struct MPT2SAS_ADAPTER *ioc;
  7035. struct Scsi_Host *shost;
  7036. shost = scsi_host_alloc(&scsih_driver_template,
  7037. sizeof(struct MPT2SAS_ADAPTER));
  7038. if (!shost)
  7039. return -ENODEV;
  7040. /* init local params */
  7041. ioc = shost_priv(shost);
  7042. memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
  7043. INIT_LIST_HEAD(&ioc->list);
  7044. list_add_tail(&ioc->list, &mpt2sas_ioc_list);
  7045. ioc->shost = shost;
  7046. ioc->id = mpt_ids++;
  7047. sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
  7048. ioc->pdev = pdev;
  7049. if (id->device == MPI2_MFGPAGE_DEVID_SSS6200) {
  7050. ioc->is_warpdrive = 1;
  7051. ioc->hide_ir_msg = 1;
  7052. } else
  7053. ioc->mfg_pg10_hide_flag = MFG_PAGE10_EXPOSE_ALL_DISKS;
  7054. ioc->scsi_io_cb_idx = scsi_io_cb_idx;
  7055. ioc->tm_cb_idx = tm_cb_idx;
  7056. ioc->ctl_cb_idx = ctl_cb_idx;
  7057. ioc->base_cb_idx = base_cb_idx;
  7058. ioc->port_enable_cb_idx = port_enable_cb_idx;
  7059. ioc->transport_cb_idx = transport_cb_idx;
  7060. ioc->scsih_cb_idx = scsih_cb_idx;
  7061. ioc->config_cb_idx = config_cb_idx;
  7062. ioc->tm_tr_cb_idx = tm_tr_cb_idx;
  7063. ioc->tm_tr_volume_cb_idx = tm_tr_volume_cb_idx;
  7064. ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
  7065. ioc->logging_level = logging_level;
  7066. /* misc semaphores and spin locks */
  7067. mutex_init(&ioc->reset_in_progress_mutex);
  7068. spin_lock_init(&ioc->ioc_reset_in_progress_lock);
  7069. spin_lock_init(&ioc->scsi_lookup_lock);
  7070. spin_lock_init(&ioc->sas_device_lock);
  7071. spin_lock_init(&ioc->sas_node_lock);
  7072. spin_lock_init(&ioc->fw_event_lock);
  7073. spin_lock_init(&ioc->raid_device_lock);
  7074. INIT_LIST_HEAD(&ioc->sas_device_list);
  7075. INIT_LIST_HEAD(&ioc->sas_device_init_list);
  7076. INIT_LIST_HEAD(&ioc->sas_expander_list);
  7077. INIT_LIST_HEAD(&ioc->fw_event_list);
  7078. INIT_LIST_HEAD(&ioc->raid_device_list);
  7079. INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
  7080. INIT_LIST_HEAD(&ioc->delayed_tr_list);
  7081. INIT_LIST_HEAD(&ioc->delayed_tr_volume_list);
  7082. /* init shost parameters */
  7083. shost->max_cmd_len = 32;
  7084. shost->max_lun = max_lun;
  7085. shost->transportt = mpt2sas_transport_template;
  7086. shost->unique_id = ioc->id;
  7087. if (max_sectors != 0xFFFF) {
  7088. if (max_sectors < 64) {
  7089. shost->max_sectors = 64;
  7090. printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
  7091. "for max_sectors, range is 64 to 8192. Assigning "
  7092. "value of 64.\n", ioc->name, max_sectors);
  7093. } else if (max_sectors > 8192) {
  7094. shost->max_sectors = 8192;
  7095. printk(MPT2SAS_WARN_FMT "Invalid value %d passed "
  7096. "for max_sectors, range is 64 to 8192. Assigning "
  7097. "default value of 8192.\n", ioc->name,
  7098. max_sectors);
  7099. } else {
  7100. shost->max_sectors = max_sectors & 0xFFFE;
  7101. printk(MPT2SAS_INFO_FMT "The max_sectors value is "
  7102. "set to %d\n", ioc->name, shost->max_sectors);
  7103. }
  7104. }
  7105. if ((scsi_add_host(shost, &pdev->dev))) {
  7106. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  7107. ioc->name, __FILE__, __LINE__, __func__);
  7108. list_del(&ioc->list);
  7109. goto out_add_shost_fail;
  7110. }
  7111. scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
  7112. | SHOST_DIF_TYPE2_PROTECTION | SHOST_DIF_TYPE3_PROTECTION);
  7113. scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
  7114. /* event thread */
  7115. snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
  7116. "fw_event%d", ioc->id);
  7117. ioc->firmware_event_thread = create_singlethread_workqueue(
  7118. ioc->firmware_event_name);
  7119. if (!ioc->firmware_event_thread) {
  7120. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  7121. ioc->name, __FILE__, __LINE__, __func__);
  7122. goto out_thread_fail;
  7123. }
  7124. ioc->is_driver_loading = 1;
  7125. if ((mpt2sas_base_attach(ioc))) {
  7126. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  7127. ioc->name, __FILE__, __LINE__, __func__);
  7128. goto out_attach_fail;
  7129. }
  7130. scsi_scan_host(shost);
  7131. if (ioc->is_warpdrive) {
  7132. if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_EXPOSE_ALL_DISKS)
  7133. ioc->hide_drives = 0;
  7134. else if (ioc->mfg_pg10_hide_flag == MFG_PAGE10_HIDE_ALL_DISKS)
  7135. ioc->hide_drives = 1;
  7136. else {
  7137. if (_scsih_get_num_volumes(ioc))
  7138. ioc->hide_drives = 1;
  7139. else
  7140. ioc->hide_drives = 0;
  7141. }
  7142. } else
  7143. ioc->hide_drives = 0;
  7144. _scsih_probe_devices(ioc);
  7145. return 0;
  7146. out_attach_fail:
  7147. destroy_workqueue(ioc->firmware_event_thread);
  7148. out_thread_fail:
  7149. list_del(&ioc->list);
  7150. scsi_remove_host(shost);
  7151. scsi_host_put(shost);
  7152. out_add_shost_fail:
  7153. return -ENODEV;
  7154. }
  7155. #ifdef CONFIG_PM
  7156. /**
  7157. * _scsih_suspend - power management suspend main entry point
  7158. * @pdev: PCI device struct
  7159. * @state: PM state change to (usually PCI_D3)
  7160. *
  7161. * Returns 0 success, anything else error.
  7162. */
  7163. static int
  7164. _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
  7165. {
  7166. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7167. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  7168. pci_power_t device_state;
  7169. mpt2sas_base_stop_watchdog(ioc);
  7170. scsi_block_requests(shost);
  7171. device_state = pci_choose_state(pdev, state);
  7172. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
  7173. "operating state [D%d]\n", ioc->name, pdev,
  7174. pci_name(pdev), device_state);
  7175. mpt2sas_base_free_resources(ioc);
  7176. pci_save_state(pdev);
  7177. pci_disable_device(pdev);
  7178. pci_set_power_state(pdev, device_state);
  7179. return 0;
  7180. }
  7181. /**
  7182. * _scsih_resume - power management resume main entry point
  7183. * @pdev: PCI device struct
  7184. *
  7185. * Returns 0 success, anything else error.
  7186. */
  7187. static int
  7188. _scsih_resume(struct pci_dev *pdev)
  7189. {
  7190. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7191. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  7192. pci_power_t device_state = pdev->current_state;
  7193. int r;
  7194. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
  7195. "operating state [D%d]\n", ioc->name, pdev,
  7196. pci_name(pdev), device_state);
  7197. pci_set_power_state(pdev, PCI_D0);
  7198. pci_enable_wake(pdev, PCI_D0, 0);
  7199. pci_restore_state(pdev);
  7200. ioc->pdev = pdev;
  7201. r = mpt2sas_base_map_resources(ioc);
  7202. if (r)
  7203. return r;
  7204. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
  7205. scsi_unblock_requests(shost);
  7206. mpt2sas_base_start_watchdog(ioc);
  7207. return 0;
  7208. }
  7209. #endif /* CONFIG_PM */
  7210. /**
  7211. * _scsih_pci_error_detected - Called when a PCI error is detected.
  7212. * @pdev: PCI device struct
  7213. * @state: PCI channel state
  7214. *
  7215. * Description: Called when a PCI error is detected.
  7216. *
  7217. * Return value:
  7218. * PCI_ERS_RESULT_NEED_RESET or PCI_ERS_RESULT_DISCONNECT
  7219. */
  7220. static pci_ers_result_t
  7221. _scsih_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
  7222. {
  7223. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7224. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  7225. printk(MPT2SAS_INFO_FMT "PCI error: detected callback, state(%d)!!\n",
  7226. ioc->name, state);
  7227. switch (state) {
  7228. case pci_channel_io_normal:
  7229. return PCI_ERS_RESULT_CAN_RECOVER;
  7230. case pci_channel_io_frozen:
  7231. /* Fatal error, prepare for slot reset */
  7232. ioc->pci_error_recovery = 1;
  7233. scsi_block_requests(ioc->shost);
  7234. mpt2sas_base_stop_watchdog(ioc);
  7235. mpt2sas_base_free_resources(ioc);
  7236. return PCI_ERS_RESULT_NEED_RESET;
  7237. case pci_channel_io_perm_failure:
  7238. /* Permanent error, prepare for device removal */
  7239. ioc->pci_error_recovery = 1;
  7240. mpt2sas_base_stop_watchdog(ioc);
  7241. _scsih_flush_running_cmds(ioc);
  7242. return PCI_ERS_RESULT_DISCONNECT;
  7243. }
  7244. return PCI_ERS_RESULT_NEED_RESET;
  7245. }
  7246. /**
  7247. * _scsih_pci_slot_reset - Called when PCI slot has been reset.
  7248. * @pdev: PCI device struct
  7249. *
  7250. * Description: This routine is called by the pci error recovery
  7251. * code after the PCI slot has been reset, just before we
  7252. * should resume normal operations.
  7253. */
  7254. static pci_ers_result_t
  7255. _scsih_pci_slot_reset(struct pci_dev *pdev)
  7256. {
  7257. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7258. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  7259. int rc;
  7260. printk(MPT2SAS_INFO_FMT "PCI error: slot reset callback!!\n",
  7261. ioc->name);
  7262. ioc->pci_error_recovery = 0;
  7263. ioc->pdev = pdev;
  7264. pci_restore_state(pdev);
  7265. rc = mpt2sas_base_map_resources(ioc);
  7266. if (rc)
  7267. return PCI_ERS_RESULT_DISCONNECT;
  7268. rc = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  7269. FORCE_BIG_HAMMER);
  7270. printk(MPT2SAS_WARN_FMT "hard reset: %s\n", ioc->name,
  7271. (rc == 0) ? "success" : "failed");
  7272. if (!rc)
  7273. return PCI_ERS_RESULT_RECOVERED;
  7274. else
  7275. return PCI_ERS_RESULT_DISCONNECT;
  7276. }
  7277. /**
  7278. * _scsih_pci_resume() - resume normal ops after PCI reset
  7279. * @pdev: pointer to PCI device
  7280. *
  7281. * Called when the error recovery driver tells us that its
  7282. * OK to resume normal operation. Use completion to allow
  7283. * halted scsi ops to resume.
  7284. */
  7285. static void
  7286. _scsih_pci_resume(struct pci_dev *pdev)
  7287. {
  7288. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7289. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  7290. printk(MPT2SAS_INFO_FMT "PCI error: resume callback!!\n", ioc->name);
  7291. pci_cleanup_aer_uncorrect_error_status(pdev);
  7292. mpt2sas_base_start_watchdog(ioc);
  7293. scsi_unblock_requests(ioc->shost);
  7294. }
  7295. /**
  7296. * _scsih_pci_mmio_enabled - Enable MMIO and dump debug registers
  7297. * @pdev: pointer to PCI device
  7298. */
  7299. static pci_ers_result_t
  7300. _scsih_pci_mmio_enabled(struct pci_dev *pdev)
  7301. {
  7302. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  7303. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  7304. printk(MPT2SAS_INFO_FMT "PCI error: mmio enabled callback!!\n",
  7305. ioc->name);
  7306. /* TODO - dump whatever for debugging purposes */
  7307. /* Request a slot reset. */
  7308. return PCI_ERS_RESULT_NEED_RESET;
  7309. }
  7310. static struct pci_error_handlers _scsih_err_handler = {
  7311. .error_detected = _scsih_pci_error_detected,
  7312. .mmio_enabled = _scsih_pci_mmio_enabled,
  7313. .slot_reset = _scsih_pci_slot_reset,
  7314. .resume = _scsih_pci_resume,
  7315. };
  7316. static struct pci_driver scsih_driver = {
  7317. .name = MPT2SAS_DRIVER_NAME,
  7318. .id_table = scsih_pci_table,
  7319. .probe = _scsih_probe,
  7320. .remove = __devexit_p(_scsih_remove),
  7321. .shutdown = _scsih_shutdown,
  7322. .err_handler = &_scsih_err_handler,
  7323. #ifdef CONFIG_PM
  7324. .suspend = _scsih_suspend,
  7325. .resume = _scsih_resume,
  7326. #endif
  7327. };
  7328. /* raid transport support */
  7329. static struct raid_function_template mpt2sas_raid_functions = {
  7330. .cookie = &scsih_driver_template,
  7331. .is_raid = _scsih_is_raid,
  7332. .get_resync = _scsih_get_resync,
  7333. .get_state = _scsih_get_state,
  7334. };
  7335. /**
  7336. * _scsih_init - main entry point for this driver.
  7337. *
  7338. * Returns 0 success, anything else error.
  7339. */
  7340. static int __init
  7341. _scsih_init(void)
  7342. {
  7343. int error;
  7344. mpt_ids = 0;
  7345. printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
  7346. MPT2SAS_DRIVER_VERSION);
  7347. mpt2sas_transport_template =
  7348. sas_attach_transport(&mpt2sas_transport_functions);
  7349. if (!mpt2sas_transport_template)
  7350. return -ENODEV;
  7351. /* raid transport support */
  7352. mpt2sas_raid_template = raid_class_attach(&mpt2sas_raid_functions);
  7353. if (!mpt2sas_raid_template) {
  7354. sas_release_transport(mpt2sas_transport_template);
  7355. return -ENODEV;
  7356. }
  7357. mpt2sas_base_initialize_callback_handler();
  7358. /* queuecommand callback hander */
  7359. scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
  7360. /* task management callback handler */
  7361. tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
  7362. /* base internal commands callback handler */
  7363. base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
  7364. port_enable_cb_idx = mpt2sas_base_register_callback_handler(
  7365. mpt2sas_port_enable_done);
  7366. /* transport internal commands callback handler */
  7367. transport_cb_idx = mpt2sas_base_register_callback_handler(
  7368. mpt2sas_transport_done);
  7369. /* scsih internal commands callback handler */
  7370. scsih_cb_idx = mpt2sas_base_register_callback_handler(_scsih_done);
  7371. /* configuration page API internal commands callback handler */
  7372. config_cb_idx = mpt2sas_base_register_callback_handler(
  7373. mpt2sas_config_done);
  7374. /* ctl module callback handler */
  7375. ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
  7376. tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
  7377. _scsih_tm_tr_complete);
  7378. tm_tr_volume_cb_idx = mpt2sas_base_register_callback_handler(
  7379. _scsih_tm_volume_tr_complete);
  7380. tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
  7381. _scsih_sas_control_complete);
  7382. mpt2sas_ctl_init();
  7383. error = pci_register_driver(&scsih_driver);
  7384. if (error) {
  7385. /* raid transport support */
  7386. raid_class_release(mpt2sas_raid_template);
  7387. sas_release_transport(mpt2sas_transport_template);
  7388. }
  7389. return error;
  7390. }
  7391. /**
  7392. * _scsih_exit - exit point for this driver (when it is a module).
  7393. *
  7394. * Returns 0 success, anything else error.
  7395. */
  7396. static void __exit
  7397. _scsih_exit(void)
  7398. {
  7399. printk(KERN_INFO "mpt2sas version %s unloading\n",
  7400. MPT2SAS_DRIVER_VERSION);
  7401. pci_unregister_driver(&scsih_driver);
  7402. mpt2sas_ctl_exit();
  7403. mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
  7404. mpt2sas_base_release_callback_handler(tm_cb_idx);
  7405. mpt2sas_base_release_callback_handler(base_cb_idx);
  7406. mpt2sas_base_release_callback_handler(port_enable_cb_idx);
  7407. mpt2sas_base_release_callback_handler(transport_cb_idx);
  7408. mpt2sas_base_release_callback_handler(scsih_cb_idx);
  7409. mpt2sas_base_release_callback_handler(config_cb_idx);
  7410. mpt2sas_base_release_callback_handler(ctl_cb_idx);
  7411. mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
  7412. mpt2sas_base_release_callback_handler(tm_tr_volume_cb_idx);
  7413. mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
  7414. /* raid transport support */
  7415. raid_class_release(mpt2sas_raid_template);
  7416. sas_release_transport(mpt2sas_transport_template);
  7417. }
  7418. module_init(_scsih_init);
  7419. module_exit(_scsih_exit);