mpt2sas_scsih.c 234 KB

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