mpt2sas_scsih.c 223 KB

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