mpt2sas_scsih.c 235 KB

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