mpt3sas_scsih.c 264 KB

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