mpt2sas_scsih.c 178 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285
  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-2009 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 "mpt2sas_base.h"
  53. MODULE_AUTHOR(MPT2SAS_AUTHOR);
  54. MODULE_DESCRIPTION(MPT2SAS_DESCRIPTION);
  55. MODULE_LICENSE("GPL");
  56. MODULE_VERSION(MPT2SAS_DRIVER_VERSION);
  57. #define RAID_CHANNEL 1
  58. /* forward proto's */
  59. static void _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  60. struct _sas_node *sas_expander);
  61. static void _firmware_event_work(struct work_struct *work);
  62. /* global parameters */
  63. LIST_HEAD(mpt2sas_ioc_list);
  64. /* local parameters */
  65. static u8 scsi_io_cb_idx = -1;
  66. static u8 tm_cb_idx = -1;
  67. static u8 ctl_cb_idx = -1;
  68. static u8 base_cb_idx = -1;
  69. static u8 transport_cb_idx = -1;
  70. static u8 config_cb_idx = -1;
  71. static int mpt_ids;
  72. static u8 tm_tr_cb_idx = -1 ;
  73. static u8 tm_sas_control_cb_idx = -1;
  74. /* command line options */
  75. static u32 logging_level;
  76. MODULE_PARM_DESC(logging_level, " bits for enabling additional logging info "
  77. "(default=0)");
  78. /* scsi-mid layer global parmeter is max_report_luns, which is 511 */
  79. #define MPT2SAS_MAX_LUN (16895)
  80. static int max_lun = MPT2SAS_MAX_LUN;
  81. module_param(max_lun, int, 0);
  82. MODULE_PARM_DESC(max_lun, " max lun, default=16895 ");
  83. /**
  84. * struct sense_info - common structure for obtaining sense keys
  85. * @skey: sense key
  86. * @asc: additional sense code
  87. * @ascq: additional sense code qualifier
  88. */
  89. struct sense_info {
  90. u8 skey;
  91. u8 asc;
  92. u8 ascq;
  93. };
  94. /**
  95. * struct fw_event_work - firmware event struct
  96. * @list: link list framework
  97. * @work: work object (ioc->fault_reset_work_q)
  98. * @ioc: per adapter object
  99. * @VF_ID: virtual function id
  100. * @VP_ID: virtual port id
  101. * @host_reset_handling: handling events during host reset
  102. * @ignore: flag meaning this event has been marked to ignore
  103. * @event: firmware event MPI2_EVENT_XXX defined in mpt2_ioc.h
  104. * @event_data: reply event data payload follows
  105. *
  106. * This object stored on ioc->fw_event_list.
  107. */
  108. struct fw_event_work {
  109. struct list_head list;
  110. struct work_struct work;
  111. struct MPT2SAS_ADAPTER *ioc;
  112. u8 VF_ID;
  113. u8 VP_ID;
  114. u8 host_reset_handling;
  115. u8 ignore;
  116. u16 event;
  117. void *event_data;
  118. };
  119. /**
  120. * struct _scsi_io_transfer - scsi io transfer
  121. * @handle: sas device handle (assigned by firmware)
  122. * @is_raid: flag set for hidden raid components
  123. * @dir: DMA_TO_DEVICE, DMA_FROM_DEVICE,
  124. * @data_length: data transfer length
  125. * @data_dma: dma pointer to data
  126. * @sense: sense data
  127. * @lun: lun number
  128. * @cdb_length: cdb length
  129. * @cdb: cdb contents
  130. * @timeout: timeout for this command
  131. * @VF_ID: virtual function id
  132. * @VP_ID: virtual port id
  133. * @valid_reply: flag set for reply message
  134. * @sense_length: sense length
  135. * @ioc_status: ioc status
  136. * @scsi_state: scsi state
  137. * @scsi_status: scsi staus
  138. * @log_info: log information
  139. * @transfer_length: data length transfer when there is a reply message
  140. *
  141. * Used for sending internal scsi commands to devices within this module.
  142. * Refer to _scsi_send_scsi_io().
  143. */
  144. struct _scsi_io_transfer {
  145. u16 handle;
  146. u8 is_raid;
  147. enum dma_data_direction dir;
  148. u32 data_length;
  149. dma_addr_t data_dma;
  150. u8 sense[SCSI_SENSE_BUFFERSIZE];
  151. u32 lun;
  152. u8 cdb_length;
  153. u8 cdb[32];
  154. u8 timeout;
  155. u8 VF_ID;
  156. u8 VP_ID;
  157. u8 valid_reply;
  158. /* the following bits are only valid when 'valid_reply = 1' */
  159. u32 sense_length;
  160. u16 ioc_status;
  161. u8 scsi_state;
  162. u8 scsi_status;
  163. u32 log_info;
  164. u32 transfer_length;
  165. };
  166. /*
  167. * The pci device ids are defined in mpi/mpi2_cnfg.h.
  168. */
  169. static struct pci_device_id scsih_pci_table[] = {
  170. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2004,
  171. PCI_ANY_ID, PCI_ANY_ID },
  172. /* Falcon ~ 2008*/
  173. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2008,
  174. PCI_ANY_ID, PCI_ANY_ID },
  175. /* Liberator ~ 2108 */
  176. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_1,
  177. PCI_ANY_ID, PCI_ANY_ID },
  178. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_2,
  179. PCI_ANY_ID, PCI_ANY_ID },
  180. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2108_3,
  181. PCI_ANY_ID, PCI_ANY_ID },
  182. /* Meteor ~ 2116 */
  183. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_1,
  184. PCI_ANY_ID, PCI_ANY_ID },
  185. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2116_2,
  186. PCI_ANY_ID, PCI_ANY_ID },
  187. /* Thunderbolt ~ 2208 */
  188. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_1,
  189. PCI_ANY_ID, PCI_ANY_ID },
  190. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_2,
  191. PCI_ANY_ID, PCI_ANY_ID },
  192. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_3,
  193. PCI_ANY_ID, PCI_ANY_ID },
  194. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_4,
  195. PCI_ANY_ID, PCI_ANY_ID },
  196. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_5,
  197. PCI_ANY_ID, PCI_ANY_ID },
  198. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_6,
  199. PCI_ANY_ID, PCI_ANY_ID },
  200. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_7,
  201. PCI_ANY_ID, PCI_ANY_ID },
  202. { MPI2_MFGPAGE_VENDORID_LSI, MPI2_MFGPAGE_DEVID_SAS2208_8,
  203. PCI_ANY_ID, PCI_ANY_ID },
  204. {0} /* Terminating entry */
  205. };
  206. MODULE_DEVICE_TABLE(pci, scsih_pci_table);
  207. /**
  208. * _scsih_set_debug_level - global setting of ioc->logging_level.
  209. *
  210. * Note: The logging levels are defined in mpt2sas_debug.h.
  211. */
  212. static int
  213. _scsih_set_debug_level(const char *val, struct kernel_param *kp)
  214. {
  215. int ret = param_set_int(val, kp);
  216. struct MPT2SAS_ADAPTER *ioc;
  217. if (ret)
  218. return ret;
  219. printk(KERN_INFO "setting logging_level(0x%08x)\n", logging_level);
  220. list_for_each_entry(ioc, &mpt2sas_ioc_list, list)
  221. ioc->logging_level = logging_level;
  222. return 0;
  223. }
  224. module_param_call(logging_level, _scsih_set_debug_level, param_get_int,
  225. &logging_level, 0644);
  226. /**
  227. * _scsih_srch_boot_sas_address - search based on sas_address
  228. * @sas_address: sas address
  229. * @boot_device: boot device object from bios page 2
  230. *
  231. * Returns 1 when there's a match, 0 means no match.
  232. */
  233. static inline int
  234. _scsih_srch_boot_sas_address(u64 sas_address,
  235. Mpi2BootDeviceSasWwid_t *boot_device)
  236. {
  237. return (sas_address == le64_to_cpu(boot_device->SASAddress)) ? 1 : 0;
  238. }
  239. /**
  240. * _scsih_srch_boot_device_name - search based on device name
  241. * @device_name: device name specified in INDENTIFY fram
  242. * @boot_device: boot device object from bios page 2
  243. *
  244. * Returns 1 when there's a match, 0 means no match.
  245. */
  246. static inline int
  247. _scsih_srch_boot_device_name(u64 device_name,
  248. Mpi2BootDeviceDeviceName_t *boot_device)
  249. {
  250. return (device_name == le64_to_cpu(boot_device->DeviceName)) ? 1 : 0;
  251. }
  252. /**
  253. * _scsih_srch_boot_encl_slot - search based on enclosure_logical_id/slot
  254. * @enclosure_logical_id: enclosure logical id
  255. * @slot_number: slot number
  256. * @boot_device: boot device object from bios page 2
  257. *
  258. * Returns 1 when there's a match, 0 means no match.
  259. */
  260. static inline int
  261. _scsih_srch_boot_encl_slot(u64 enclosure_logical_id, u16 slot_number,
  262. Mpi2BootDeviceEnclosureSlot_t *boot_device)
  263. {
  264. return (enclosure_logical_id == le64_to_cpu(boot_device->
  265. EnclosureLogicalID) && slot_number == le16_to_cpu(boot_device->
  266. SlotNumber)) ? 1 : 0;
  267. }
  268. /**
  269. * _scsih_is_boot_device - search for matching boot device.
  270. * @sas_address: sas address
  271. * @device_name: device name specified in INDENTIFY fram
  272. * @enclosure_logical_id: enclosure logical id
  273. * @slot_number: slot number
  274. * @form: specifies boot device form
  275. * @boot_device: boot device object from bios page 2
  276. *
  277. * Returns 1 when there's a match, 0 means no match.
  278. */
  279. static int
  280. _scsih_is_boot_device(u64 sas_address, u64 device_name,
  281. u64 enclosure_logical_id, u16 slot, u8 form,
  282. Mpi2BiosPage2BootDevice_t *boot_device)
  283. {
  284. int rc = 0;
  285. switch (form) {
  286. case MPI2_BIOSPAGE2_FORM_SAS_WWID:
  287. if (!sas_address)
  288. break;
  289. rc = _scsih_srch_boot_sas_address(
  290. sas_address, &boot_device->SasWwid);
  291. break;
  292. case MPI2_BIOSPAGE2_FORM_ENCLOSURE_SLOT:
  293. if (!enclosure_logical_id)
  294. break;
  295. rc = _scsih_srch_boot_encl_slot(
  296. enclosure_logical_id,
  297. slot, &boot_device->EnclosureSlot);
  298. break;
  299. case MPI2_BIOSPAGE2_FORM_DEVICE_NAME:
  300. if (!device_name)
  301. break;
  302. rc = _scsih_srch_boot_device_name(
  303. device_name, &boot_device->DeviceName);
  304. break;
  305. case MPI2_BIOSPAGE2_FORM_NO_DEVICE_SPECIFIED:
  306. break;
  307. }
  308. return rc;
  309. }
  310. /**
  311. * _scsih_get_sas_address - set the sas_address for given device handle
  312. * @handle: device handle
  313. * @sas_address: sas address
  314. *
  315. * Returns 0 success, non-zero when failure
  316. */
  317. static int
  318. _scsih_get_sas_address(struct MPT2SAS_ADAPTER *ioc, u16 handle,
  319. u64 *sas_address)
  320. {
  321. Mpi2SasDevicePage0_t sas_device_pg0;
  322. Mpi2ConfigReply_t mpi_reply;
  323. u32 ioc_status;
  324. if (handle <= ioc->sas_hba.num_phys) {
  325. *sas_address = ioc->sas_hba.sas_address;
  326. return 0;
  327. } else
  328. *sas_address = 0;
  329. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  330. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  331. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  332. ioc->name, __FILE__, __LINE__, __func__);
  333. return -ENXIO;
  334. }
  335. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  336. MPI2_IOCSTATUS_MASK;
  337. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  338. printk(MPT2SAS_ERR_FMT "handle(0x%04x), ioc_status(0x%04x)"
  339. "\nfailure at %s:%d/%s()!\n", ioc->name, handle, ioc_status,
  340. __FILE__, __LINE__, __func__);
  341. return -EIO;
  342. }
  343. *sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  344. return 0;
  345. }
  346. /**
  347. * _scsih_determine_boot_device - determine boot device.
  348. * @ioc: per adapter object
  349. * @device: either sas_device or raid_device object
  350. * @is_raid: [flag] 1 = raid object, 0 = sas object
  351. *
  352. * Determines whether this device should be first reported device to
  353. * to scsi-ml or sas transport, this purpose is for persistant boot device.
  354. * There are primary, alternate, and current entries in bios page 2. The order
  355. * priority is primary, alternate, then current. This routine saves
  356. * the corresponding device object and is_raid flag in the ioc object.
  357. * The saved data to be used later in _scsih_probe_boot_devices().
  358. */
  359. static void
  360. _scsih_determine_boot_device(struct MPT2SAS_ADAPTER *ioc,
  361. void *device, u8 is_raid)
  362. {
  363. struct _sas_device *sas_device;
  364. struct _raid_device *raid_device;
  365. u64 sas_address;
  366. u64 device_name;
  367. u64 enclosure_logical_id;
  368. u16 slot;
  369. /* only process this function when driver loads */
  370. if (!ioc->wait_for_port_enable_to_complete)
  371. return;
  372. if (!is_raid) {
  373. sas_device = device;
  374. sas_address = sas_device->sas_address;
  375. device_name = sas_device->device_name;
  376. enclosure_logical_id = sas_device->enclosure_logical_id;
  377. slot = sas_device->slot;
  378. } else {
  379. raid_device = device;
  380. sas_address = raid_device->wwid;
  381. device_name = 0;
  382. enclosure_logical_id = 0;
  383. slot = 0;
  384. }
  385. if (!ioc->req_boot_device.device) {
  386. if (_scsih_is_boot_device(sas_address, device_name,
  387. enclosure_logical_id, slot,
  388. (ioc->bios_pg2.ReqBootDeviceForm &
  389. MPI2_BIOSPAGE2_FORM_MASK),
  390. &ioc->bios_pg2.RequestedBootDevice)) {
  391. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  392. "%s: req_boot_device(0x%016llx)\n",
  393. ioc->name, __func__,
  394. (unsigned long long)sas_address));
  395. ioc->req_boot_device.device = device;
  396. ioc->req_boot_device.is_raid = is_raid;
  397. }
  398. }
  399. if (!ioc->req_alt_boot_device.device) {
  400. if (_scsih_is_boot_device(sas_address, device_name,
  401. enclosure_logical_id, slot,
  402. (ioc->bios_pg2.ReqAltBootDeviceForm &
  403. MPI2_BIOSPAGE2_FORM_MASK),
  404. &ioc->bios_pg2.RequestedAltBootDevice)) {
  405. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  406. "%s: req_alt_boot_device(0x%016llx)\n",
  407. ioc->name, __func__,
  408. (unsigned long long)sas_address));
  409. ioc->req_alt_boot_device.device = device;
  410. ioc->req_alt_boot_device.is_raid = is_raid;
  411. }
  412. }
  413. if (!ioc->current_boot_device.device) {
  414. if (_scsih_is_boot_device(sas_address, device_name,
  415. enclosure_logical_id, slot,
  416. (ioc->bios_pg2.CurrentBootDeviceForm &
  417. MPI2_BIOSPAGE2_FORM_MASK),
  418. &ioc->bios_pg2.CurrentBootDevice)) {
  419. dinitprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  420. "%s: current_boot_device(0x%016llx)\n",
  421. ioc->name, __func__,
  422. (unsigned long long)sas_address));
  423. ioc->current_boot_device.device = device;
  424. ioc->current_boot_device.is_raid = is_raid;
  425. }
  426. }
  427. }
  428. /**
  429. * mpt2sas_scsih_sas_device_find_by_sas_address - sas device search
  430. * @ioc: per adapter object
  431. * @sas_address: sas address
  432. * Context: Calling function should acquire ioc->sas_device_lock
  433. *
  434. * This searches for sas_device based on sas_address, then return sas_device
  435. * object.
  436. */
  437. struct _sas_device *
  438. mpt2sas_scsih_sas_device_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  439. u64 sas_address)
  440. {
  441. struct _sas_device *sas_device, *r;
  442. r = NULL;
  443. /* check the sas_device_init_list */
  444. list_for_each_entry(sas_device, &ioc->sas_device_init_list,
  445. list) {
  446. if (sas_device->sas_address != sas_address)
  447. continue;
  448. r = sas_device;
  449. goto out;
  450. }
  451. /* then check the sas_device_list */
  452. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  453. if (sas_device->sas_address != sas_address)
  454. continue;
  455. r = sas_device;
  456. goto out;
  457. }
  458. out:
  459. return r;
  460. }
  461. /**
  462. * _scsih_sas_device_find_by_handle - sas device search
  463. * @ioc: per adapter object
  464. * @handle: sas device handle (assigned by firmware)
  465. * Context: Calling function should acquire ioc->sas_device_lock
  466. *
  467. * This searches for sas_device based on sas_address, then return sas_device
  468. * object.
  469. */
  470. static struct _sas_device *
  471. _scsih_sas_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  472. {
  473. struct _sas_device *sas_device, *r;
  474. r = NULL;
  475. if (ioc->wait_for_port_enable_to_complete) {
  476. list_for_each_entry(sas_device, &ioc->sas_device_init_list,
  477. list) {
  478. if (sas_device->handle != handle)
  479. continue;
  480. r = sas_device;
  481. goto out;
  482. }
  483. } else {
  484. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  485. if (sas_device->handle != handle)
  486. continue;
  487. r = sas_device;
  488. goto out;
  489. }
  490. }
  491. out:
  492. return r;
  493. }
  494. /**
  495. * _scsih_sas_device_remove - remove sas_device from list.
  496. * @ioc: per adapter object
  497. * @sas_device: the sas_device object
  498. * Context: This function will acquire ioc->sas_device_lock.
  499. *
  500. * Removing object and freeing associated memory from the ioc->sas_device_list.
  501. */
  502. static void
  503. _scsih_sas_device_remove(struct MPT2SAS_ADAPTER *ioc,
  504. struct _sas_device *sas_device)
  505. {
  506. unsigned long flags;
  507. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  508. list_del(&sas_device->list);
  509. memset(sas_device, 0, sizeof(struct _sas_device));
  510. kfree(sas_device);
  511. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  512. }
  513. /**
  514. * _scsih_sas_device_add - insert sas_device to the list.
  515. * @ioc: per adapter object
  516. * @sas_device: the sas_device object
  517. * Context: This function will acquire ioc->sas_device_lock.
  518. *
  519. * Adding new object to the ioc->sas_device_list.
  520. */
  521. static void
  522. _scsih_sas_device_add(struct MPT2SAS_ADAPTER *ioc,
  523. struct _sas_device *sas_device)
  524. {
  525. unsigned long flags;
  526. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
  527. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  528. sas_device->handle, (unsigned long long)sas_device->sas_address));
  529. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  530. list_add_tail(&sas_device->list, &ioc->sas_device_list);
  531. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  532. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  533. sas_device->sas_address_parent))
  534. _scsih_sas_device_remove(ioc, sas_device);
  535. }
  536. /**
  537. * _scsih_sas_device_init_add - insert sas_device to the list.
  538. * @ioc: per adapter object
  539. * @sas_device: the sas_device object
  540. * Context: This function will acquire ioc->sas_device_lock.
  541. *
  542. * Adding new object at driver load time to the ioc->sas_device_init_list.
  543. */
  544. static void
  545. _scsih_sas_device_init_add(struct MPT2SAS_ADAPTER *ioc,
  546. struct _sas_device *sas_device)
  547. {
  548. unsigned long flags;
  549. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
  550. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name, __func__,
  551. sas_device->handle, (unsigned long long)sas_device->sas_address));
  552. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  553. list_add_tail(&sas_device->list, &ioc->sas_device_init_list);
  554. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  555. _scsih_determine_boot_device(ioc, sas_device, 0);
  556. }
  557. /**
  558. * _scsih_raid_device_find_by_id - raid device search
  559. * @ioc: per adapter object
  560. * @id: sas device target id
  561. * @channel: sas device channel
  562. * Context: Calling function should acquire ioc->raid_device_lock
  563. *
  564. * This searches for raid_device based on target id, then return raid_device
  565. * object.
  566. */
  567. static struct _raid_device *
  568. _scsih_raid_device_find_by_id(struct MPT2SAS_ADAPTER *ioc, int id, int channel)
  569. {
  570. struct _raid_device *raid_device, *r;
  571. r = NULL;
  572. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  573. if (raid_device->id == id && raid_device->channel == channel) {
  574. r = raid_device;
  575. goto out;
  576. }
  577. }
  578. out:
  579. return r;
  580. }
  581. /**
  582. * _scsih_raid_device_find_by_handle - raid device search
  583. * @ioc: per adapter object
  584. * @handle: sas device handle (assigned by firmware)
  585. * Context: Calling function should acquire ioc->raid_device_lock
  586. *
  587. * This searches for raid_device based on handle, then return raid_device
  588. * object.
  589. */
  590. static struct _raid_device *
  591. _scsih_raid_device_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  592. {
  593. struct _raid_device *raid_device, *r;
  594. r = NULL;
  595. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  596. if (raid_device->handle != handle)
  597. continue;
  598. r = raid_device;
  599. goto out;
  600. }
  601. out:
  602. return r;
  603. }
  604. /**
  605. * _scsih_raid_device_find_by_wwid - raid device search
  606. * @ioc: per adapter object
  607. * @handle: sas device handle (assigned by firmware)
  608. * Context: Calling function should acquire ioc->raid_device_lock
  609. *
  610. * This searches for raid_device based on wwid, then return raid_device
  611. * object.
  612. */
  613. static struct _raid_device *
  614. _scsih_raid_device_find_by_wwid(struct MPT2SAS_ADAPTER *ioc, u64 wwid)
  615. {
  616. struct _raid_device *raid_device, *r;
  617. r = NULL;
  618. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  619. if (raid_device->wwid != wwid)
  620. continue;
  621. r = raid_device;
  622. goto out;
  623. }
  624. out:
  625. return r;
  626. }
  627. /**
  628. * _scsih_raid_device_add - add raid_device object
  629. * @ioc: per adapter object
  630. * @raid_device: raid_device object
  631. *
  632. * This is added to the raid_device_list link list.
  633. */
  634. static void
  635. _scsih_raid_device_add(struct MPT2SAS_ADAPTER *ioc,
  636. struct _raid_device *raid_device)
  637. {
  638. unsigned long flags;
  639. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle"
  640. "(0x%04x), wwid(0x%016llx)\n", ioc->name, __func__,
  641. raid_device->handle, (unsigned long long)raid_device->wwid));
  642. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  643. list_add_tail(&raid_device->list, &ioc->raid_device_list);
  644. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  645. }
  646. /**
  647. * _scsih_raid_device_remove - delete raid_device object
  648. * @ioc: per adapter object
  649. * @raid_device: raid_device object
  650. *
  651. * This is removed from the raid_device_list link list.
  652. */
  653. static void
  654. _scsih_raid_device_remove(struct MPT2SAS_ADAPTER *ioc,
  655. struct _raid_device *raid_device)
  656. {
  657. unsigned long flags;
  658. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  659. list_del(&raid_device->list);
  660. memset(raid_device, 0, sizeof(struct _raid_device));
  661. kfree(raid_device);
  662. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  663. }
  664. /**
  665. * mpt2sas_scsih_expander_find_by_handle - expander device search
  666. * @ioc: per adapter object
  667. * @handle: expander handle (assigned by firmware)
  668. * Context: Calling function should acquire ioc->sas_device_lock
  669. *
  670. * This searches for expander device based on handle, then returns the
  671. * sas_node object.
  672. */
  673. struct _sas_node *
  674. mpt2sas_scsih_expander_find_by_handle(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  675. {
  676. struct _sas_node *sas_expander, *r;
  677. r = NULL;
  678. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  679. if (sas_expander->handle != handle)
  680. continue;
  681. r = sas_expander;
  682. goto out;
  683. }
  684. out:
  685. return r;
  686. }
  687. /**
  688. * mpt2sas_scsih_expander_find_by_sas_address - expander device search
  689. * @ioc: per adapter object
  690. * @sas_address: sas address
  691. * Context: Calling function should acquire ioc->sas_node_lock.
  692. *
  693. * This searches for expander device based on sas_address, then returns the
  694. * sas_node object.
  695. */
  696. struct _sas_node *
  697. mpt2sas_scsih_expander_find_by_sas_address(struct MPT2SAS_ADAPTER *ioc,
  698. u64 sas_address)
  699. {
  700. struct _sas_node *sas_expander, *r;
  701. r = NULL;
  702. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  703. if (sas_expander->sas_address != sas_address)
  704. continue;
  705. r = sas_expander;
  706. goto out;
  707. }
  708. out:
  709. return r;
  710. }
  711. /**
  712. * _scsih_expander_node_add - insert expander device to the list.
  713. * @ioc: per adapter object
  714. * @sas_expander: the sas_device object
  715. * Context: This function will acquire ioc->sas_node_lock.
  716. *
  717. * Adding new object to the ioc->sas_expander_list.
  718. *
  719. * Return nothing.
  720. */
  721. static void
  722. _scsih_expander_node_add(struct MPT2SAS_ADAPTER *ioc,
  723. struct _sas_node *sas_expander)
  724. {
  725. unsigned long flags;
  726. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  727. list_add_tail(&sas_expander->list, &ioc->sas_expander_list);
  728. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  729. }
  730. /**
  731. * _scsih_is_end_device - determines if device is an end device
  732. * @device_info: bitfield providing information about the device.
  733. * Context: none
  734. *
  735. * Returns 1 if end device.
  736. */
  737. static int
  738. _scsih_is_end_device(u32 device_info)
  739. {
  740. if (device_info & MPI2_SAS_DEVICE_INFO_END_DEVICE &&
  741. ((device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) |
  742. (device_info & MPI2_SAS_DEVICE_INFO_STP_TARGET) |
  743. (device_info & MPI2_SAS_DEVICE_INFO_SATA_DEVICE)))
  744. return 1;
  745. else
  746. return 0;
  747. }
  748. /**
  749. * mptscsih_get_scsi_lookup - returns scmd entry
  750. * @ioc: per adapter object
  751. * @smid: system request message index
  752. *
  753. * Returns the smid stored scmd pointer.
  754. */
  755. static struct scsi_cmnd *
  756. _scsih_scsi_lookup_get(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  757. {
  758. return ioc->scsi_lookup[smid - 1].scmd;
  759. }
  760. /**
  761. * _scsih_scsi_lookup_find_by_scmd - scmd lookup
  762. * @ioc: per adapter object
  763. * @smid: system request message index
  764. * @scmd: pointer to scsi command object
  765. * Context: This function will acquire ioc->scsi_lookup_lock.
  766. *
  767. * This will search for a scmd pointer in the scsi_lookup array,
  768. * returning the revelent smid. A returned value of zero means invalid.
  769. */
  770. static u16
  771. _scsih_scsi_lookup_find_by_scmd(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd
  772. *scmd)
  773. {
  774. u16 smid;
  775. unsigned long flags;
  776. int i;
  777. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  778. smid = 0;
  779. for (i = 0; i < ioc->scsiio_depth; i++) {
  780. if (ioc->scsi_lookup[i].scmd == scmd) {
  781. smid = ioc->scsi_lookup[i].smid;
  782. goto out;
  783. }
  784. }
  785. out:
  786. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  787. return smid;
  788. }
  789. /**
  790. * _scsih_scsi_lookup_find_by_target - search for matching channel:id
  791. * @ioc: per adapter object
  792. * @id: target id
  793. * @channel: channel
  794. * Context: This function will acquire ioc->scsi_lookup_lock.
  795. *
  796. * This will search for a matching channel:id in the scsi_lookup array,
  797. * returning 1 if found.
  798. */
  799. static u8
  800. _scsih_scsi_lookup_find_by_target(struct MPT2SAS_ADAPTER *ioc, int id,
  801. int channel)
  802. {
  803. u8 found;
  804. unsigned long flags;
  805. int i;
  806. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  807. found = 0;
  808. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  809. if (ioc->scsi_lookup[i].scmd &&
  810. (ioc->scsi_lookup[i].scmd->device->id == id &&
  811. ioc->scsi_lookup[i].scmd->device->channel == channel)) {
  812. found = 1;
  813. goto out;
  814. }
  815. }
  816. out:
  817. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  818. return found;
  819. }
  820. /**
  821. * _scsih_scsi_lookup_find_by_lun - search for matching channel:id:lun
  822. * @ioc: per adapter object
  823. * @id: target id
  824. * @lun: lun number
  825. * @channel: channel
  826. * Context: This function will acquire ioc->scsi_lookup_lock.
  827. *
  828. * This will search for a matching channel:id:lun in the scsi_lookup array,
  829. * returning 1 if found.
  830. */
  831. static u8
  832. _scsih_scsi_lookup_find_by_lun(struct MPT2SAS_ADAPTER *ioc, int id,
  833. unsigned int lun, int channel)
  834. {
  835. u8 found;
  836. unsigned long flags;
  837. int i;
  838. spin_lock_irqsave(&ioc->scsi_lookup_lock, flags);
  839. found = 0;
  840. for (i = 0 ; i < ioc->scsiio_depth; i++) {
  841. if (ioc->scsi_lookup[i].scmd &&
  842. (ioc->scsi_lookup[i].scmd->device->id == id &&
  843. ioc->scsi_lookup[i].scmd->device->channel == channel &&
  844. ioc->scsi_lookup[i].scmd->device->lun == lun)) {
  845. found = 1;
  846. goto out;
  847. }
  848. }
  849. out:
  850. spin_unlock_irqrestore(&ioc->scsi_lookup_lock, flags);
  851. return found;
  852. }
  853. /**
  854. * _scsih_get_chain_buffer_dma - obtain block of chains (dma address)
  855. * @ioc: per adapter object
  856. * @smid: system request message index
  857. *
  858. * Returns phys pointer to chain buffer.
  859. */
  860. static dma_addr_t
  861. _scsih_get_chain_buffer_dma(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  862. {
  863. return ioc->chain_dma + ((smid - 1) * (ioc->request_sz *
  864. ioc->chains_needed_per_io));
  865. }
  866. /**
  867. * _scsih_get_chain_buffer - obtain block of chains assigned to a mf request
  868. * @ioc: per adapter object
  869. * @smid: system request message index
  870. *
  871. * Returns virt pointer to chain buffer.
  872. */
  873. static void *
  874. _scsih_get_chain_buffer(struct MPT2SAS_ADAPTER *ioc, u16 smid)
  875. {
  876. return (void *)(ioc->chain + ((smid - 1) * (ioc->request_sz *
  877. ioc->chains_needed_per_io)));
  878. }
  879. /**
  880. * _scsih_build_scatter_gather - main sg creation routine
  881. * @ioc: per adapter object
  882. * @scmd: scsi command
  883. * @smid: system request message index
  884. * Context: none.
  885. *
  886. * The main routine that builds scatter gather table from a given
  887. * scsi request sent via the .queuecommand main handler.
  888. *
  889. * Returns 0 success, anything else error
  890. */
  891. static int
  892. _scsih_build_scatter_gather(struct MPT2SAS_ADAPTER *ioc,
  893. struct scsi_cmnd *scmd, u16 smid)
  894. {
  895. Mpi2SCSIIORequest_t *mpi_request;
  896. dma_addr_t chain_dma;
  897. struct scatterlist *sg_scmd;
  898. void *sg_local, *chain;
  899. u32 chain_offset;
  900. u32 chain_length;
  901. u32 chain_flags;
  902. u32 sges_left;
  903. u32 sges_in_segment;
  904. u32 sgl_flags;
  905. u32 sgl_flags_last_element;
  906. u32 sgl_flags_end_buffer;
  907. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  908. /* init scatter gather flags */
  909. sgl_flags = MPI2_SGE_FLAGS_SIMPLE_ELEMENT;
  910. if (scmd->sc_data_direction == DMA_TO_DEVICE)
  911. sgl_flags |= MPI2_SGE_FLAGS_HOST_TO_IOC;
  912. sgl_flags_last_element = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT)
  913. << MPI2_SGE_FLAGS_SHIFT;
  914. sgl_flags_end_buffer = (sgl_flags | MPI2_SGE_FLAGS_LAST_ELEMENT |
  915. MPI2_SGE_FLAGS_END_OF_BUFFER | MPI2_SGE_FLAGS_END_OF_LIST)
  916. << MPI2_SGE_FLAGS_SHIFT;
  917. sgl_flags = sgl_flags << MPI2_SGE_FLAGS_SHIFT;
  918. sg_scmd = scsi_sglist(scmd);
  919. sges_left = scsi_dma_map(scmd);
  920. if (!sges_left) {
  921. sdev_printk(KERN_ERR, scmd->device, "pci_map_sg"
  922. " failed: request for %d bytes!\n", scsi_bufflen(scmd));
  923. return -ENOMEM;
  924. }
  925. sg_local = &mpi_request->SGL;
  926. sges_in_segment = ioc->max_sges_in_main_message;
  927. if (sges_left <= sges_in_segment)
  928. goto fill_in_last_segment;
  929. mpi_request->ChainOffset = (offsetof(Mpi2SCSIIORequest_t, SGL) +
  930. (sges_in_segment * ioc->sge_size))/4;
  931. /* fill in main message segment when there is a chain following */
  932. while (sges_in_segment) {
  933. if (sges_in_segment == 1)
  934. ioc->base_add_sg_single(sg_local,
  935. sgl_flags_last_element | sg_dma_len(sg_scmd),
  936. sg_dma_address(sg_scmd));
  937. else
  938. ioc->base_add_sg_single(sg_local, sgl_flags |
  939. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  940. sg_scmd = sg_next(sg_scmd);
  941. sg_local += ioc->sge_size;
  942. sges_left--;
  943. sges_in_segment--;
  944. }
  945. /* initializing the chain flags and pointers */
  946. chain_flags = MPI2_SGE_FLAGS_CHAIN_ELEMENT << MPI2_SGE_FLAGS_SHIFT;
  947. chain = _scsih_get_chain_buffer(ioc, smid);
  948. chain_dma = _scsih_get_chain_buffer_dma(ioc, smid);
  949. do {
  950. sges_in_segment = (sges_left <=
  951. ioc->max_sges_in_chain_message) ? sges_left :
  952. ioc->max_sges_in_chain_message;
  953. chain_offset = (sges_left == sges_in_segment) ?
  954. 0 : (sges_in_segment * ioc->sge_size)/4;
  955. chain_length = sges_in_segment * ioc->sge_size;
  956. if (chain_offset) {
  957. chain_offset = chain_offset <<
  958. MPI2_SGE_CHAIN_OFFSET_SHIFT;
  959. chain_length += ioc->sge_size;
  960. }
  961. ioc->base_add_sg_single(sg_local, chain_flags | chain_offset |
  962. chain_length, chain_dma);
  963. sg_local = chain;
  964. if (!chain_offset)
  965. goto fill_in_last_segment;
  966. /* fill in chain segments */
  967. while (sges_in_segment) {
  968. if (sges_in_segment == 1)
  969. ioc->base_add_sg_single(sg_local,
  970. sgl_flags_last_element |
  971. sg_dma_len(sg_scmd),
  972. sg_dma_address(sg_scmd));
  973. else
  974. ioc->base_add_sg_single(sg_local, sgl_flags |
  975. sg_dma_len(sg_scmd),
  976. sg_dma_address(sg_scmd));
  977. sg_scmd = sg_next(sg_scmd);
  978. sg_local += ioc->sge_size;
  979. sges_left--;
  980. sges_in_segment--;
  981. }
  982. chain_dma += ioc->request_sz;
  983. chain += ioc->request_sz;
  984. } while (1);
  985. fill_in_last_segment:
  986. /* fill the last segment */
  987. while (sges_left) {
  988. if (sges_left == 1)
  989. ioc->base_add_sg_single(sg_local, sgl_flags_end_buffer |
  990. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  991. else
  992. ioc->base_add_sg_single(sg_local, sgl_flags |
  993. sg_dma_len(sg_scmd), sg_dma_address(sg_scmd));
  994. sg_scmd = sg_next(sg_scmd);
  995. sg_local += ioc->sge_size;
  996. sges_left--;
  997. }
  998. return 0;
  999. }
  1000. /**
  1001. * _scsih_change_queue_depth - setting device queue depth
  1002. * @sdev: scsi device struct
  1003. * @qdepth: requested queue depth
  1004. *
  1005. * Returns queue depth.
  1006. */
  1007. static int
  1008. _scsih_change_queue_depth(struct scsi_device *sdev, int qdepth)
  1009. {
  1010. struct Scsi_Host *shost = sdev->host;
  1011. int max_depth;
  1012. int tag_type;
  1013. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1014. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1015. struct MPT2SAS_TARGET *sas_target_priv_data;
  1016. struct _sas_device *sas_device;
  1017. unsigned long flags;
  1018. max_depth = shost->can_queue;
  1019. /* limit max device queue for SATA to 32 */
  1020. sas_device_priv_data = sdev->hostdata;
  1021. if (!sas_device_priv_data)
  1022. goto not_sata;
  1023. sas_target_priv_data = sas_device_priv_data->sas_target;
  1024. if (!sas_target_priv_data)
  1025. goto not_sata;
  1026. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))
  1027. goto not_sata;
  1028. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1029. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1030. sas_device_priv_data->sas_target->sas_address);
  1031. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1032. if (sas_device && sas_device->device_info &
  1033. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1034. max_depth = MPT2SAS_SATA_QUEUE_DEPTH;
  1035. not_sata:
  1036. if (!sdev->tagged_supported)
  1037. max_depth = 1;
  1038. if (qdepth > max_depth)
  1039. qdepth = max_depth;
  1040. tag_type = (qdepth == 1) ? 0 : MSG_SIMPLE_TAG;
  1041. scsi_adjust_queue_depth(sdev, tag_type, qdepth);
  1042. if (sdev->inquiry_len > 7)
  1043. sdev_printk(KERN_INFO, sdev, "qdepth(%d), tagged(%d), "
  1044. "simple(%d), ordered(%d), scsi_level(%d), cmd_que(%d)\n",
  1045. sdev->queue_depth, sdev->tagged_supported, sdev->simple_tags,
  1046. sdev->ordered_tags, sdev->scsi_level,
  1047. (sdev->inquiry[7] & 2) >> 1);
  1048. return sdev->queue_depth;
  1049. }
  1050. /**
  1051. * _scsih_change_queue_type - changing device queue tag type
  1052. * @sdev: scsi device struct
  1053. * @tag_type: requested tag type
  1054. *
  1055. * Returns queue tag type.
  1056. */
  1057. static int
  1058. _scsih_change_queue_type(struct scsi_device *sdev, int tag_type)
  1059. {
  1060. if (sdev->tagged_supported) {
  1061. scsi_set_tag_type(sdev, tag_type);
  1062. if (tag_type)
  1063. scsi_activate_tcq(sdev, sdev->queue_depth);
  1064. else
  1065. scsi_deactivate_tcq(sdev, sdev->queue_depth);
  1066. } else
  1067. tag_type = 0;
  1068. return tag_type;
  1069. }
  1070. /**
  1071. * _scsih_target_alloc - target add routine
  1072. * @starget: scsi target struct
  1073. *
  1074. * Returns 0 if ok. Any other return is assumed to be an error and
  1075. * the device is ignored.
  1076. */
  1077. static int
  1078. _scsih_target_alloc(struct scsi_target *starget)
  1079. {
  1080. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1081. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1082. struct MPT2SAS_TARGET *sas_target_priv_data;
  1083. struct _sas_device *sas_device;
  1084. struct _raid_device *raid_device;
  1085. unsigned long flags;
  1086. struct sas_rphy *rphy;
  1087. sas_target_priv_data = kzalloc(sizeof(struct scsi_target), GFP_KERNEL);
  1088. if (!sas_target_priv_data)
  1089. return -ENOMEM;
  1090. starget->hostdata = sas_target_priv_data;
  1091. sas_target_priv_data->starget = starget;
  1092. sas_target_priv_data->handle = MPT2SAS_INVALID_DEVICE_HANDLE;
  1093. /* RAID volumes */
  1094. if (starget->channel == RAID_CHANNEL) {
  1095. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1096. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1097. starget->channel);
  1098. if (raid_device) {
  1099. sas_target_priv_data->handle = raid_device->handle;
  1100. sas_target_priv_data->sas_address = raid_device->wwid;
  1101. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_VOLUME;
  1102. raid_device->starget = starget;
  1103. }
  1104. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1105. return 0;
  1106. }
  1107. /* sas/sata devices */
  1108. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1109. rphy = dev_to_rphy(starget->dev.parent);
  1110. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1111. rphy->identify.sas_address);
  1112. if (sas_device) {
  1113. sas_target_priv_data->handle = sas_device->handle;
  1114. sas_target_priv_data->sas_address = sas_device->sas_address;
  1115. sas_device->starget = starget;
  1116. sas_device->id = starget->id;
  1117. sas_device->channel = starget->channel;
  1118. if (sas_device->hidden_raid_component)
  1119. sas_target_priv_data->flags |=
  1120. MPT_TARGET_FLAGS_RAID_COMPONENT;
  1121. }
  1122. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1123. return 0;
  1124. }
  1125. /**
  1126. * _scsih_target_destroy - target destroy routine
  1127. * @starget: scsi target struct
  1128. *
  1129. * Returns nothing.
  1130. */
  1131. static void
  1132. _scsih_target_destroy(struct scsi_target *starget)
  1133. {
  1134. struct Scsi_Host *shost = dev_to_shost(&starget->dev);
  1135. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1136. struct MPT2SAS_TARGET *sas_target_priv_data;
  1137. struct _sas_device *sas_device;
  1138. struct _raid_device *raid_device;
  1139. unsigned long flags;
  1140. struct sas_rphy *rphy;
  1141. sas_target_priv_data = starget->hostdata;
  1142. if (!sas_target_priv_data)
  1143. return;
  1144. if (starget->channel == RAID_CHANNEL) {
  1145. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1146. raid_device = _scsih_raid_device_find_by_id(ioc, starget->id,
  1147. starget->channel);
  1148. if (raid_device) {
  1149. raid_device->starget = NULL;
  1150. raid_device->sdev = NULL;
  1151. }
  1152. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1153. goto out;
  1154. }
  1155. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1156. rphy = dev_to_rphy(starget->dev.parent);
  1157. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1158. rphy->identify.sas_address);
  1159. if (sas_device && (sas_device->starget == starget) &&
  1160. (sas_device->id == starget->id) &&
  1161. (sas_device->channel == starget->channel))
  1162. sas_device->starget = NULL;
  1163. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1164. out:
  1165. kfree(sas_target_priv_data);
  1166. starget->hostdata = NULL;
  1167. }
  1168. /**
  1169. * _scsih_slave_alloc - device add routine
  1170. * @sdev: scsi device struct
  1171. *
  1172. * Returns 0 if ok. Any other return is assumed to be an error and
  1173. * the device is ignored.
  1174. */
  1175. static int
  1176. _scsih_slave_alloc(struct scsi_device *sdev)
  1177. {
  1178. struct Scsi_Host *shost;
  1179. struct MPT2SAS_ADAPTER *ioc;
  1180. struct MPT2SAS_TARGET *sas_target_priv_data;
  1181. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1182. struct scsi_target *starget;
  1183. struct _raid_device *raid_device;
  1184. struct _sas_device *sas_device;
  1185. unsigned long flags;
  1186. sas_device_priv_data = kzalloc(sizeof(struct scsi_device), GFP_KERNEL);
  1187. if (!sas_device_priv_data)
  1188. return -ENOMEM;
  1189. sas_device_priv_data->lun = sdev->lun;
  1190. sas_device_priv_data->flags = MPT_DEVICE_FLAGS_INIT;
  1191. starget = scsi_target(sdev);
  1192. sas_target_priv_data = starget->hostdata;
  1193. sas_target_priv_data->num_luns++;
  1194. sas_device_priv_data->sas_target = sas_target_priv_data;
  1195. sdev->hostdata = sas_device_priv_data;
  1196. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT))
  1197. sdev->no_uld_attach = 1;
  1198. shost = dev_to_shost(&starget->dev);
  1199. ioc = shost_priv(shost);
  1200. if (starget->channel == RAID_CHANNEL) {
  1201. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1202. raid_device = _scsih_raid_device_find_by_id(ioc,
  1203. starget->id, starget->channel);
  1204. if (raid_device)
  1205. raid_device->sdev = sdev; /* raid is single lun */
  1206. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1207. } else {
  1208. /* set TLR bit for SSP devices */
  1209. if (!(ioc->facts.IOCCapabilities &
  1210. MPI2_IOCFACTS_CAPABILITY_TLR))
  1211. goto out;
  1212. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1213. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1214. sas_device_priv_data->sas_target->sas_address);
  1215. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1216. if (sas_device && sas_device->device_info &
  1217. MPI2_SAS_DEVICE_INFO_SSP_TARGET)
  1218. sas_device_priv_data->flags |= MPT_DEVICE_TLR_ON;
  1219. }
  1220. out:
  1221. return 0;
  1222. }
  1223. /**
  1224. * _scsih_slave_destroy - device destroy routine
  1225. * @sdev: scsi device struct
  1226. *
  1227. * Returns nothing.
  1228. */
  1229. static void
  1230. _scsih_slave_destroy(struct scsi_device *sdev)
  1231. {
  1232. struct MPT2SAS_TARGET *sas_target_priv_data;
  1233. struct scsi_target *starget;
  1234. if (!sdev->hostdata)
  1235. return;
  1236. starget = scsi_target(sdev);
  1237. sas_target_priv_data = starget->hostdata;
  1238. sas_target_priv_data->num_luns--;
  1239. kfree(sdev->hostdata);
  1240. sdev->hostdata = NULL;
  1241. }
  1242. /**
  1243. * _scsih_display_sata_capabilities - sata capabilities
  1244. * @ioc: per adapter object
  1245. * @sas_device: the sas_device object
  1246. * @sdev: scsi device struct
  1247. */
  1248. static void
  1249. _scsih_display_sata_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1250. struct _sas_device *sas_device, struct scsi_device *sdev)
  1251. {
  1252. Mpi2ConfigReply_t mpi_reply;
  1253. Mpi2SasDevicePage0_t sas_device_pg0;
  1254. u32 ioc_status;
  1255. u16 flags;
  1256. u32 device_info;
  1257. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  1258. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, sas_device->handle))) {
  1259. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1260. ioc->name, __FILE__, __LINE__, __func__);
  1261. return;
  1262. }
  1263. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  1264. MPI2_IOCSTATUS_MASK;
  1265. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  1266. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1267. ioc->name, __FILE__, __LINE__, __func__);
  1268. return;
  1269. }
  1270. flags = le16_to_cpu(sas_device_pg0.Flags);
  1271. device_info = le16_to_cpu(sas_device_pg0.DeviceInfo);
  1272. sdev_printk(KERN_INFO, sdev,
  1273. "atapi(%s), ncq(%s), asyn_notify(%s), smart(%s), fua(%s), "
  1274. "sw_preserve(%s)\n",
  1275. (device_info & MPI2_SAS_DEVICE_INFO_ATAPI_DEVICE) ? "y" : "n",
  1276. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_NCQ_SUPPORTED) ? "y" : "n",
  1277. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_ASYNCHRONOUS_NOTIFY) ? "y" :
  1278. "n",
  1279. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SMART_SUPPORTED) ? "y" : "n",
  1280. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_FUA_SUPPORTED) ? "y" : "n",
  1281. (flags & MPI2_SAS_DEVICE0_FLAGS_SATA_SW_PRESERVE) ? "y" : "n");
  1282. }
  1283. /**
  1284. * _scsih_get_volume_capabilities - volume capabilities
  1285. * @ioc: per adapter object
  1286. * @sas_device: the raid_device object
  1287. */
  1288. static void
  1289. _scsih_get_volume_capabilities(struct MPT2SAS_ADAPTER *ioc,
  1290. struct _raid_device *raid_device)
  1291. {
  1292. Mpi2RaidVolPage0_t *vol_pg0;
  1293. Mpi2RaidPhysDiskPage0_t pd_pg0;
  1294. Mpi2SasDevicePage0_t sas_device_pg0;
  1295. Mpi2ConfigReply_t mpi_reply;
  1296. u16 sz;
  1297. u8 num_pds;
  1298. if ((mpt2sas_config_get_number_pds(ioc, raid_device->handle,
  1299. &num_pds)) || !num_pds) {
  1300. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1301. ioc->name, __FILE__, __LINE__, __func__);
  1302. return;
  1303. }
  1304. raid_device->num_pds = num_pds;
  1305. sz = offsetof(Mpi2RaidVolPage0_t, PhysDisk) + (num_pds *
  1306. sizeof(Mpi2RaidVol0PhysDisk_t));
  1307. vol_pg0 = kzalloc(sz, GFP_KERNEL);
  1308. if (!vol_pg0) {
  1309. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1310. ioc->name, __FILE__, __LINE__, __func__);
  1311. return;
  1312. }
  1313. if ((mpt2sas_config_get_raid_volume_pg0(ioc, &mpi_reply, vol_pg0,
  1314. MPI2_RAID_VOLUME_PGAD_FORM_HANDLE, raid_device->handle, sz))) {
  1315. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1316. ioc->name, __FILE__, __LINE__, __func__);
  1317. kfree(vol_pg0);
  1318. return;
  1319. }
  1320. raid_device->volume_type = vol_pg0->VolumeType;
  1321. /* figure out what the underlying devices are by
  1322. * obtaining the device_info bits for the 1st device
  1323. */
  1324. if (!(mpt2sas_config_get_phys_disk_pg0(ioc, &mpi_reply,
  1325. &pd_pg0, MPI2_PHYSDISK_PGAD_FORM_PHYSDISKNUM,
  1326. vol_pg0->PhysDisk[0].PhysDiskNum))) {
  1327. if (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  1328. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  1329. le16_to_cpu(pd_pg0.DevHandle)))) {
  1330. raid_device->device_info =
  1331. le32_to_cpu(sas_device_pg0.DeviceInfo);
  1332. }
  1333. }
  1334. kfree(vol_pg0);
  1335. }
  1336. /**
  1337. * _scsih_slave_configure - device configure routine.
  1338. * @sdev: scsi device struct
  1339. *
  1340. * Returns 0 if ok. Any other return is assumed to be an error and
  1341. * the device is ignored.
  1342. */
  1343. static int
  1344. _scsih_slave_configure(struct scsi_device *sdev)
  1345. {
  1346. struct Scsi_Host *shost = sdev->host;
  1347. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  1348. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1349. struct MPT2SAS_TARGET *sas_target_priv_data;
  1350. struct _sas_device *sas_device;
  1351. struct _raid_device *raid_device;
  1352. unsigned long flags;
  1353. int qdepth;
  1354. u8 ssp_target = 0;
  1355. char *ds = "";
  1356. char *r_level = "";
  1357. qdepth = 1;
  1358. sas_device_priv_data = sdev->hostdata;
  1359. sas_device_priv_data->configured_lun = 1;
  1360. sas_device_priv_data->flags &= ~MPT_DEVICE_FLAGS_INIT;
  1361. sas_target_priv_data = sas_device_priv_data->sas_target;
  1362. /* raid volume handling */
  1363. if (sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME) {
  1364. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  1365. raid_device = _scsih_raid_device_find_by_handle(ioc,
  1366. sas_target_priv_data->handle);
  1367. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  1368. if (!raid_device) {
  1369. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  1370. ioc->name, __FILE__, __LINE__, __func__);
  1371. return 0;
  1372. }
  1373. _scsih_get_volume_capabilities(ioc, raid_device);
  1374. /* RAID Queue Depth Support
  1375. * IS volume = underlying qdepth of drive type, either
  1376. * MPT2SAS_SAS_QUEUE_DEPTH or MPT2SAS_SATA_QUEUE_DEPTH
  1377. * IM/IME/R10 = 128 (MPT2SAS_RAID_QUEUE_DEPTH)
  1378. */
  1379. if (raid_device->device_info &
  1380. MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1381. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1382. ds = "SSP";
  1383. } else {
  1384. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1385. if (raid_device->device_info &
  1386. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1387. ds = "SATA";
  1388. else
  1389. ds = "STP";
  1390. }
  1391. switch (raid_device->volume_type) {
  1392. case MPI2_RAID_VOL_TYPE_RAID0:
  1393. r_level = "RAID0";
  1394. break;
  1395. case MPI2_RAID_VOL_TYPE_RAID1E:
  1396. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1397. if (ioc->manu_pg10.OEMIdentifier &&
  1398. (ioc->manu_pg10.GenericFlags0 &
  1399. MFG10_GF0_R10_DISPLAY) &&
  1400. !(raid_device->num_pds % 2))
  1401. r_level = "RAID10";
  1402. else
  1403. r_level = "RAID1E";
  1404. break;
  1405. case MPI2_RAID_VOL_TYPE_RAID1:
  1406. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1407. r_level = "RAID1";
  1408. break;
  1409. case MPI2_RAID_VOL_TYPE_RAID10:
  1410. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1411. r_level = "RAID10";
  1412. break;
  1413. case MPI2_RAID_VOL_TYPE_UNKNOWN:
  1414. default:
  1415. qdepth = MPT2SAS_RAID_QUEUE_DEPTH;
  1416. r_level = "RAIDX";
  1417. break;
  1418. }
  1419. sdev_printk(KERN_INFO, sdev, "%s: "
  1420. "handle(0x%04x), wwid(0x%016llx), pd_count(%d), type(%s)\n",
  1421. r_level, raid_device->handle,
  1422. (unsigned long long)raid_device->wwid,
  1423. raid_device->num_pds, ds);
  1424. _scsih_change_queue_depth(sdev, qdepth);
  1425. return 0;
  1426. }
  1427. /* non-raid handling */
  1428. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1429. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  1430. sas_device_priv_data->sas_target->sas_address);
  1431. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1432. if (sas_device) {
  1433. if (sas_target_priv_data->flags &
  1434. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1435. mpt2sas_config_get_volume_handle(ioc,
  1436. sas_device->handle, &sas_device->volume_handle);
  1437. mpt2sas_config_get_volume_wwid(ioc,
  1438. sas_device->volume_handle,
  1439. &sas_device->volume_wwid);
  1440. }
  1441. if (sas_device->device_info & MPI2_SAS_DEVICE_INFO_SSP_TARGET) {
  1442. qdepth = MPT2SAS_SAS_QUEUE_DEPTH;
  1443. ssp_target = 1;
  1444. ds = "SSP";
  1445. } else {
  1446. qdepth = MPT2SAS_SATA_QUEUE_DEPTH;
  1447. if (sas_device->device_info &
  1448. MPI2_SAS_DEVICE_INFO_STP_TARGET)
  1449. ds = "STP";
  1450. else if (sas_device->device_info &
  1451. MPI2_SAS_DEVICE_INFO_SATA_DEVICE)
  1452. ds = "SATA";
  1453. }
  1454. sdev_printk(KERN_INFO, sdev, "%s: handle(0x%04x), "
  1455. "sas_addr(0x%016llx), device_name(0x%016llx)\n",
  1456. ds, sas_device->handle,
  1457. (unsigned long long)sas_device->sas_address,
  1458. (unsigned long long)sas_device->device_name);
  1459. sdev_printk(KERN_INFO, sdev, "%s: "
  1460. "enclosure_logical_id(0x%016llx), slot(%d)\n", ds,
  1461. (unsigned long long) sas_device->enclosure_logical_id,
  1462. sas_device->slot);
  1463. if (!ssp_target)
  1464. _scsih_display_sata_capabilities(ioc, sas_device, sdev);
  1465. }
  1466. _scsih_change_queue_depth(sdev, qdepth);
  1467. if (ssp_target)
  1468. sas_read_port_mode_page(sdev);
  1469. return 0;
  1470. }
  1471. /**
  1472. * _scsih_bios_param - fetch head, sector, cylinder info for a disk
  1473. * @sdev: scsi device struct
  1474. * @bdev: pointer to block device context
  1475. * @capacity: device size (in 512 byte sectors)
  1476. * @params: three element array to place output:
  1477. * params[0] number of heads (max 255)
  1478. * params[1] number of sectors (max 63)
  1479. * params[2] number of cylinders
  1480. *
  1481. * Return nothing.
  1482. */
  1483. static int
  1484. _scsih_bios_param(struct scsi_device *sdev, struct block_device *bdev,
  1485. sector_t capacity, int params[])
  1486. {
  1487. int heads;
  1488. int sectors;
  1489. sector_t cylinders;
  1490. ulong dummy;
  1491. heads = 64;
  1492. sectors = 32;
  1493. dummy = heads * sectors;
  1494. cylinders = capacity;
  1495. sector_div(cylinders, dummy);
  1496. /*
  1497. * Handle extended translation size for logical drives
  1498. * > 1Gb
  1499. */
  1500. if ((ulong)capacity >= 0x200000) {
  1501. heads = 255;
  1502. sectors = 63;
  1503. dummy = heads * sectors;
  1504. cylinders = capacity;
  1505. sector_div(cylinders, dummy);
  1506. }
  1507. /* return result */
  1508. params[0] = heads;
  1509. params[1] = sectors;
  1510. params[2] = cylinders;
  1511. return 0;
  1512. }
  1513. /**
  1514. * _scsih_response_code - translation of device response code
  1515. * @ioc: per adapter object
  1516. * @response_code: response code returned by the device
  1517. *
  1518. * Return nothing.
  1519. */
  1520. static void
  1521. _scsih_response_code(struct MPT2SAS_ADAPTER *ioc, u8 response_code)
  1522. {
  1523. char *desc;
  1524. switch (response_code) {
  1525. case MPI2_SCSITASKMGMT_RSP_TM_COMPLETE:
  1526. desc = "task management request completed";
  1527. break;
  1528. case MPI2_SCSITASKMGMT_RSP_INVALID_FRAME:
  1529. desc = "invalid frame";
  1530. break;
  1531. case MPI2_SCSITASKMGMT_RSP_TM_NOT_SUPPORTED:
  1532. desc = "task management request not supported";
  1533. break;
  1534. case MPI2_SCSITASKMGMT_RSP_TM_FAILED:
  1535. desc = "task management request failed";
  1536. break;
  1537. case MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED:
  1538. desc = "task management request succeeded";
  1539. break;
  1540. case MPI2_SCSITASKMGMT_RSP_TM_INVALID_LUN:
  1541. desc = "invalid lun";
  1542. break;
  1543. case 0xA:
  1544. desc = "overlapped tag attempted";
  1545. break;
  1546. case MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC:
  1547. desc = "task queued, however not sent to target";
  1548. break;
  1549. default:
  1550. desc = "unknown";
  1551. break;
  1552. }
  1553. printk(MPT2SAS_WARN_FMT "response_code(0x%01x): %s\n",
  1554. ioc->name, response_code, desc);
  1555. }
  1556. /**
  1557. * _scsih_tm_done - tm completion routine
  1558. * @ioc: per adapter object
  1559. * @smid: system request message index
  1560. * @msix_index: MSIX table index supplied by the OS
  1561. * @reply: reply message frame(lower 32bit addr)
  1562. * Context: none.
  1563. *
  1564. * The callback handler when using scsih_issue_tm.
  1565. *
  1566. * Return 1 meaning mf should be freed from _base_interrupt
  1567. * 0 means the mf is freed from this function.
  1568. */
  1569. static u8
  1570. _scsih_tm_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  1571. {
  1572. MPI2DefaultReply_t *mpi_reply;
  1573. if (ioc->tm_cmds.status == MPT2_CMD_NOT_USED)
  1574. return 1;
  1575. if (ioc->tm_cmds.smid != smid)
  1576. return 1;
  1577. ioc->tm_cmds.status |= MPT2_CMD_COMPLETE;
  1578. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  1579. if (mpi_reply) {
  1580. memcpy(ioc->tm_cmds.reply, mpi_reply, mpi_reply->MsgLength*4);
  1581. ioc->tm_cmds.status |= MPT2_CMD_REPLY_VALID;
  1582. }
  1583. ioc->tm_cmds.status &= ~MPT2_CMD_PENDING;
  1584. complete(&ioc->tm_cmds.done);
  1585. return 1;
  1586. }
  1587. /**
  1588. * mpt2sas_scsih_set_tm_flag - set per target tm_busy
  1589. * @ioc: per adapter object
  1590. * @handle: device handle
  1591. *
  1592. * During taskmangement request, we need to freeze the device queue.
  1593. */
  1594. void
  1595. mpt2sas_scsih_set_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1596. {
  1597. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1598. struct scsi_device *sdev;
  1599. u8 skip = 0;
  1600. shost_for_each_device(sdev, ioc->shost) {
  1601. if (skip)
  1602. continue;
  1603. sas_device_priv_data = sdev->hostdata;
  1604. if (!sas_device_priv_data)
  1605. continue;
  1606. if (sas_device_priv_data->sas_target->handle == handle) {
  1607. sas_device_priv_data->sas_target->tm_busy = 1;
  1608. skip = 1;
  1609. ioc->ignore_loginfos = 1;
  1610. }
  1611. }
  1612. }
  1613. /**
  1614. * mpt2sas_scsih_clear_tm_flag - clear per target tm_busy
  1615. * @ioc: per adapter object
  1616. * @handle: device handle
  1617. *
  1618. * During taskmangement request, we need to freeze the device queue.
  1619. */
  1620. void
  1621. mpt2sas_scsih_clear_tm_flag(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  1622. {
  1623. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1624. struct scsi_device *sdev;
  1625. u8 skip = 0;
  1626. shost_for_each_device(sdev, ioc->shost) {
  1627. if (skip)
  1628. continue;
  1629. sas_device_priv_data = sdev->hostdata;
  1630. if (!sas_device_priv_data)
  1631. continue;
  1632. if (sas_device_priv_data->sas_target->handle == handle) {
  1633. sas_device_priv_data->sas_target->tm_busy = 0;
  1634. skip = 1;
  1635. ioc->ignore_loginfos = 0;
  1636. }
  1637. }
  1638. }
  1639. /**
  1640. * mpt2sas_scsih_issue_tm - main routine for sending tm requests
  1641. * @ioc: per adapter struct
  1642. * @device_handle: device handle
  1643. * @lun: lun number
  1644. * @type: MPI2_SCSITASKMGMT_TASKTYPE__XXX (defined in mpi2_init.h)
  1645. * @smid_task: smid assigned to the task
  1646. * @timeout: timeout in seconds
  1647. * Context: The calling function needs to acquire the tm_cmds.mutex
  1648. *
  1649. * A generic API for sending task management requests to firmware.
  1650. *
  1651. * The ioc->tm_cmds.status flag should be MPT2_CMD_NOT_USED before calling
  1652. * this API.
  1653. *
  1654. * The callback index is set inside `ioc->tm_cb_idx`.
  1655. *
  1656. * Return nothing.
  1657. */
  1658. void
  1659. mpt2sas_scsih_issue_tm(struct MPT2SAS_ADAPTER *ioc, u16 handle, uint lun,
  1660. u8 type, u16 smid_task, ulong timeout)
  1661. {
  1662. Mpi2SCSITaskManagementRequest_t *mpi_request;
  1663. Mpi2SCSITaskManagementReply_t *mpi_reply;
  1664. u16 smid = 0;
  1665. u32 ioc_state;
  1666. unsigned long timeleft;
  1667. if (ioc->tm_cmds.status != MPT2_CMD_NOT_USED) {
  1668. printk(MPT2SAS_INFO_FMT "%s: tm_cmd busy!!!\n",
  1669. __func__, ioc->name);
  1670. return;
  1671. }
  1672. if (ioc->shost_recovery) {
  1673. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  1674. __func__, ioc->name);
  1675. return;
  1676. }
  1677. ioc_state = mpt2sas_base_get_iocstate(ioc, 0);
  1678. if (ioc_state & MPI2_DOORBELL_USED) {
  1679. dhsprintk(ioc, printk(MPT2SAS_DEBUG_FMT "unexpected doorbell "
  1680. "active!\n", ioc->name));
  1681. goto issue_host_reset;
  1682. }
  1683. if ((ioc_state & MPI2_IOC_STATE_MASK) == MPI2_IOC_STATE_FAULT) {
  1684. mpt2sas_base_fault_info(ioc, ioc_state &
  1685. MPI2_DOORBELL_DATA_MASK);
  1686. goto issue_host_reset;
  1687. }
  1688. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_cb_idx);
  1689. if (!smid) {
  1690. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  1691. ioc->name, __func__);
  1692. return;
  1693. }
  1694. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "sending tm: handle(0x%04x),"
  1695. " task_type(0x%02x), smid(%d)\n", ioc->name, handle, type,
  1696. smid_task));
  1697. ioc->tm_cmds.status = MPT2_CMD_PENDING;
  1698. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  1699. ioc->tm_cmds.smid = smid;
  1700. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  1701. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  1702. mpi_request->DevHandle = cpu_to_le16(handle);
  1703. mpi_request->TaskType = type;
  1704. mpi_request->TaskMID = cpu_to_le16(smid_task);
  1705. mpi_request->VP_ID = 0; /* TODO */
  1706. mpi_request->VF_ID = 0;
  1707. int_to_scsilun(lun, (struct scsi_lun *)mpi_request->LUN);
  1708. mpt2sas_scsih_set_tm_flag(ioc, handle);
  1709. init_completion(&ioc->tm_cmds.done);
  1710. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  1711. timeleft = wait_for_completion_timeout(&ioc->tm_cmds.done, timeout*HZ);
  1712. mpt2sas_scsih_clear_tm_flag(ioc, handle);
  1713. if (!(ioc->tm_cmds.status & MPT2_CMD_COMPLETE)) {
  1714. printk(MPT2SAS_ERR_FMT "%s: timeout\n",
  1715. ioc->name, __func__);
  1716. _debug_dump_mf(mpi_request,
  1717. sizeof(Mpi2SCSITaskManagementRequest_t)/4);
  1718. if (!(ioc->tm_cmds.status & MPT2_CMD_RESET))
  1719. goto issue_host_reset;
  1720. }
  1721. if (ioc->tm_cmds.status & MPT2_CMD_REPLY_VALID) {
  1722. mpi_reply = ioc->tm_cmds.reply;
  1723. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "complete tm: "
  1724. "ioc_status(0x%04x), loginfo(0x%08x), term_count(0x%08x)\n",
  1725. ioc->name, le16_to_cpu(mpi_reply->IOCStatus),
  1726. le32_to_cpu(mpi_reply->IOCLogInfo),
  1727. le32_to_cpu(mpi_reply->TerminationCount)));
  1728. if (ioc->logging_level & MPT_DEBUG_TM)
  1729. _scsih_response_code(ioc, mpi_reply->ResponseCode);
  1730. }
  1731. return;
  1732. issue_host_reset:
  1733. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, FORCE_BIG_HAMMER);
  1734. }
  1735. /**
  1736. * _scsih_abort - eh threads main abort routine
  1737. * @sdev: scsi device struct
  1738. *
  1739. * Returns SUCCESS if command aborted else FAILED
  1740. */
  1741. static int
  1742. _scsih_abort(struct scsi_cmnd *scmd)
  1743. {
  1744. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1745. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1746. u16 smid;
  1747. u16 handle;
  1748. int r;
  1749. struct scsi_cmnd *scmd_lookup;
  1750. printk(MPT2SAS_INFO_FMT "attempting task abort! scmd(%p)\n",
  1751. ioc->name, scmd);
  1752. scsi_print_command(scmd);
  1753. sas_device_priv_data = scmd->device->hostdata;
  1754. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  1755. printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
  1756. ioc->name, scmd);
  1757. scmd->result = DID_NO_CONNECT << 16;
  1758. scmd->scsi_done(scmd);
  1759. r = SUCCESS;
  1760. goto out;
  1761. }
  1762. /* search for the command */
  1763. smid = _scsih_scsi_lookup_find_by_scmd(ioc, scmd);
  1764. if (!smid) {
  1765. scmd->result = DID_RESET << 16;
  1766. r = SUCCESS;
  1767. goto out;
  1768. }
  1769. /* for hidden raid components and volumes this is not supported */
  1770. if (sas_device_priv_data->sas_target->flags &
  1771. MPT_TARGET_FLAGS_RAID_COMPONENT ||
  1772. sas_device_priv_data->sas_target->flags & MPT_TARGET_FLAGS_VOLUME) {
  1773. scmd->result = DID_RESET << 16;
  1774. r = FAILED;
  1775. goto out;
  1776. }
  1777. mpt2sas_halt_firmware(ioc);
  1778. mutex_lock(&ioc->tm_cmds.mutex);
  1779. handle = sas_device_priv_data->sas_target->handle;
  1780. mpt2sas_scsih_issue_tm(ioc, handle, sas_device_priv_data->lun,
  1781. MPI2_SCSITASKMGMT_TASKTYPE_ABORT_TASK, smid, 30);
  1782. /* sanity check - see whether command actually completed */
  1783. scmd_lookup = _scsih_scsi_lookup_get(ioc, smid);
  1784. if (scmd_lookup && (scmd_lookup->serial_number == scmd->serial_number))
  1785. r = FAILED;
  1786. else
  1787. r = SUCCESS;
  1788. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1789. mutex_unlock(&ioc->tm_cmds.mutex);
  1790. out:
  1791. printk(MPT2SAS_INFO_FMT "task abort: %s scmd(%p)\n",
  1792. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1793. return r;
  1794. }
  1795. /**
  1796. * _scsih_dev_reset - eh threads main device reset routine
  1797. * @sdev: scsi device struct
  1798. *
  1799. * Returns SUCCESS if command aborted else FAILED
  1800. */
  1801. static int
  1802. _scsih_dev_reset(struct scsi_cmnd *scmd)
  1803. {
  1804. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1805. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1806. struct _sas_device *sas_device;
  1807. unsigned long flags;
  1808. u16 handle;
  1809. int r;
  1810. printk(MPT2SAS_INFO_FMT "attempting device reset! scmd(%p)\n",
  1811. ioc->name, scmd);
  1812. scsi_print_command(scmd);
  1813. sas_device_priv_data = scmd->device->hostdata;
  1814. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  1815. printk(MPT2SAS_INFO_FMT "device been deleted! scmd(%p)\n",
  1816. ioc->name, scmd);
  1817. scmd->result = DID_NO_CONNECT << 16;
  1818. scmd->scsi_done(scmd);
  1819. r = SUCCESS;
  1820. goto out;
  1821. }
  1822. /* for hidden raid components obtain the volume_handle */
  1823. handle = 0;
  1824. if (sas_device_priv_data->sas_target->flags &
  1825. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1826. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1827. sas_device = _scsih_sas_device_find_by_handle(ioc,
  1828. sas_device_priv_data->sas_target->handle);
  1829. if (sas_device)
  1830. handle = sas_device->volume_handle;
  1831. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1832. } else
  1833. handle = sas_device_priv_data->sas_target->handle;
  1834. if (!handle) {
  1835. scmd->result = DID_RESET << 16;
  1836. r = FAILED;
  1837. goto out;
  1838. }
  1839. mutex_lock(&ioc->tm_cmds.mutex);
  1840. mpt2sas_scsih_issue_tm(ioc, handle, 0,
  1841. MPI2_SCSITASKMGMT_TASKTYPE_LOGICAL_UNIT_RESET, scmd->device->lun,
  1842. 30);
  1843. /*
  1844. * sanity check see whether all commands to this device been
  1845. * completed
  1846. */
  1847. if (_scsih_scsi_lookup_find_by_lun(ioc, scmd->device->id,
  1848. scmd->device->lun, scmd->device->channel))
  1849. r = FAILED;
  1850. else
  1851. r = SUCCESS;
  1852. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1853. mutex_unlock(&ioc->tm_cmds.mutex);
  1854. out:
  1855. printk(MPT2SAS_INFO_FMT "device reset: %s scmd(%p)\n",
  1856. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1857. return r;
  1858. }
  1859. /**
  1860. * _scsih_target_reset - eh threads main target reset routine
  1861. * @sdev: scsi device struct
  1862. *
  1863. * Returns SUCCESS if command aborted else FAILED
  1864. */
  1865. static int
  1866. _scsih_target_reset(struct scsi_cmnd *scmd)
  1867. {
  1868. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1869. struct MPT2SAS_DEVICE *sas_device_priv_data;
  1870. struct _sas_device *sas_device;
  1871. unsigned long flags;
  1872. u16 handle;
  1873. int r;
  1874. printk(MPT2SAS_INFO_FMT "attempting target reset! scmd(%p)\n",
  1875. ioc->name, scmd);
  1876. scsi_print_command(scmd);
  1877. sas_device_priv_data = scmd->device->hostdata;
  1878. if (!sas_device_priv_data || !sas_device_priv_data->sas_target) {
  1879. printk(MPT2SAS_INFO_FMT "target been deleted! scmd(%p)\n",
  1880. ioc->name, scmd);
  1881. scmd->result = DID_NO_CONNECT << 16;
  1882. scmd->scsi_done(scmd);
  1883. r = SUCCESS;
  1884. goto out;
  1885. }
  1886. /* for hidden raid components obtain the volume_handle */
  1887. handle = 0;
  1888. if (sas_device_priv_data->sas_target->flags &
  1889. MPT_TARGET_FLAGS_RAID_COMPONENT) {
  1890. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  1891. sas_device = _scsih_sas_device_find_by_handle(ioc,
  1892. sas_device_priv_data->sas_target->handle);
  1893. if (sas_device)
  1894. handle = sas_device->volume_handle;
  1895. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  1896. } else
  1897. handle = sas_device_priv_data->sas_target->handle;
  1898. if (!handle) {
  1899. scmd->result = DID_RESET << 16;
  1900. r = FAILED;
  1901. goto out;
  1902. }
  1903. mutex_lock(&ioc->tm_cmds.mutex);
  1904. mpt2sas_scsih_issue_tm(ioc, handle, 0,
  1905. MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 30);
  1906. /*
  1907. * sanity check see whether all commands to this target been
  1908. * completed
  1909. */
  1910. if (_scsih_scsi_lookup_find_by_target(ioc, scmd->device->id,
  1911. scmd->device->channel))
  1912. r = FAILED;
  1913. else
  1914. r = SUCCESS;
  1915. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  1916. mutex_unlock(&ioc->tm_cmds.mutex);
  1917. out:
  1918. printk(MPT2SAS_INFO_FMT "target reset: %s scmd(%p)\n",
  1919. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1920. return r;
  1921. }
  1922. /**
  1923. * _scsih_host_reset - eh threads main host reset routine
  1924. * @sdev: scsi device struct
  1925. *
  1926. * Returns SUCCESS if command aborted else FAILED
  1927. */
  1928. static int
  1929. _scsih_host_reset(struct scsi_cmnd *scmd)
  1930. {
  1931. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  1932. int r, retval;
  1933. printk(MPT2SAS_INFO_FMT "attempting host reset! scmd(%p)\n",
  1934. ioc->name, scmd);
  1935. scsi_print_command(scmd);
  1936. retval = mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
  1937. FORCE_BIG_HAMMER);
  1938. r = (retval < 0) ? FAILED : SUCCESS;
  1939. printk(MPT2SAS_INFO_FMT "host reset: %s scmd(%p)\n",
  1940. ioc->name, ((r == SUCCESS) ? "SUCCESS" : "FAILED"), scmd);
  1941. return r;
  1942. }
  1943. /**
  1944. * _scsih_fw_event_add - insert and queue up fw_event
  1945. * @ioc: per adapter object
  1946. * @fw_event: object describing the event
  1947. * Context: This function will acquire ioc->fw_event_lock.
  1948. *
  1949. * This adds the firmware event object into link list, then queues it up to
  1950. * be processed from user context.
  1951. *
  1952. * Return nothing.
  1953. */
  1954. static void
  1955. _scsih_fw_event_add(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work *fw_event)
  1956. {
  1957. unsigned long flags;
  1958. if (ioc->firmware_event_thread == NULL)
  1959. return;
  1960. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1961. list_add_tail(&fw_event->list, &ioc->fw_event_list);
  1962. INIT_WORK(&fw_event->work, _firmware_event_work);
  1963. queue_work(ioc->firmware_event_thread, &fw_event->work);
  1964. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1965. }
  1966. /**
  1967. * _scsih_fw_event_free - delete fw_event
  1968. * @ioc: per adapter object
  1969. * @fw_event: object describing the event
  1970. * Context: This function will acquire ioc->fw_event_lock.
  1971. *
  1972. * This removes firmware event object from link list, frees associated memory.
  1973. *
  1974. * Return nothing.
  1975. */
  1976. static void
  1977. _scsih_fw_event_free(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  1978. *fw_event)
  1979. {
  1980. unsigned long flags;
  1981. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1982. list_del(&fw_event->list);
  1983. kfree(fw_event->event_data);
  1984. kfree(fw_event);
  1985. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1986. }
  1987. /**
  1988. * _scsih_fw_event_add - requeue an event
  1989. * @ioc: per adapter object
  1990. * @fw_event: object describing the event
  1991. * Context: This function will acquire ioc->fw_event_lock.
  1992. *
  1993. * Return nothing.
  1994. */
  1995. static void
  1996. _scsih_fw_event_requeue(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  1997. *fw_event, unsigned long delay)
  1998. {
  1999. unsigned long flags;
  2000. if (ioc->firmware_event_thread == NULL)
  2001. return;
  2002. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2003. queue_work(ioc->firmware_event_thread, &fw_event->work);
  2004. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2005. }
  2006. /**
  2007. * _scsih_fw_event_off - turn flag off preventing event handling
  2008. * @ioc: per adapter object
  2009. *
  2010. * Used to prevent handling of firmware events during adapter reset
  2011. * driver unload.
  2012. *
  2013. * Return nothing.
  2014. */
  2015. static void
  2016. _scsih_fw_event_off(struct MPT2SAS_ADAPTER *ioc)
  2017. {
  2018. unsigned long flags;
  2019. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2020. ioc->fw_events_off = 1;
  2021. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2022. }
  2023. /**
  2024. * _scsih_fw_event_on - turn flag on allowing firmware event handling
  2025. * @ioc: per adapter object
  2026. *
  2027. * Returns nothing.
  2028. */
  2029. static void
  2030. _scsih_fw_event_on(struct MPT2SAS_ADAPTER *ioc)
  2031. {
  2032. unsigned long flags;
  2033. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2034. ioc->fw_events_off = 0;
  2035. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2036. }
  2037. /**
  2038. * _scsih_ublock_io_device - set the device state to SDEV_RUNNING
  2039. * @ioc: per adapter object
  2040. * @handle: device handle
  2041. *
  2042. * During device pull we need to appropiately set the sdev state.
  2043. */
  2044. static void
  2045. _scsih_ublock_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2046. {
  2047. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2048. struct scsi_device *sdev;
  2049. shost_for_each_device(sdev, ioc->shost) {
  2050. sas_device_priv_data = sdev->hostdata;
  2051. if (!sas_device_priv_data)
  2052. continue;
  2053. if (!sas_device_priv_data->block)
  2054. continue;
  2055. if (sas_device_priv_data->sas_target->handle == handle) {
  2056. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2057. MPT2SAS_INFO_FMT "SDEV_RUNNING: "
  2058. "handle(0x%04x)\n", ioc->name, handle));
  2059. sas_device_priv_data->block = 0;
  2060. scsi_internal_device_unblock(sdev);
  2061. }
  2062. }
  2063. }
  2064. /**
  2065. * _scsih_block_io_device - set the device state to SDEV_BLOCK
  2066. * @ioc: per adapter object
  2067. * @handle: device handle
  2068. *
  2069. * During device pull we need to appropiately set the sdev state.
  2070. */
  2071. static void
  2072. _scsih_block_io_device(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2073. {
  2074. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2075. struct scsi_device *sdev;
  2076. shost_for_each_device(sdev, ioc->shost) {
  2077. sas_device_priv_data = sdev->hostdata;
  2078. if (!sas_device_priv_data)
  2079. continue;
  2080. if (sas_device_priv_data->block)
  2081. continue;
  2082. if (sas_device_priv_data->sas_target->handle == handle) {
  2083. dewtprintk(ioc, sdev_printk(KERN_INFO, sdev,
  2084. MPT2SAS_INFO_FMT "SDEV_BLOCK: "
  2085. "handle(0x%04x)\n", ioc->name, handle));
  2086. sas_device_priv_data->block = 1;
  2087. scsi_internal_device_block(sdev);
  2088. }
  2089. }
  2090. }
  2091. /**
  2092. * _scsih_block_io_to_children_attached_to_ex
  2093. * @ioc: per adapter object
  2094. * @sas_expander: the sas_device object
  2095. *
  2096. * This routine set sdev state to SDEV_BLOCK for all devices
  2097. * attached to this expander. This function called when expander is
  2098. * pulled.
  2099. */
  2100. static void
  2101. _scsih_block_io_to_children_attached_to_ex(struct MPT2SAS_ADAPTER *ioc,
  2102. struct _sas_node *sas_expander)
  2103. {
  2104. struct _sas_port *mpt2sas_port;
  2105. struct _sas_device *sas_device;
  2106. struct _sas_node *expander_sibling;
  2107. unsigned long flags;
  2108. if (!sas_expander)
  2109. return;
  2110. list_for_each_entry(mpt2sas_port,
  2111. &sas_expander->sas_port_list, port_list) {
  2112. if (mpt2sas_port->remote_identify.device_type ==
  2113. SAS_END_DEVICE) {
  2114. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2115. sas_device =
  2116. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  2117. mpt2sas_port->remote_identify.sas_address);
  2118. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2119. if (!sas_device)
  2120. continue;
  2121. _scsih_block_io_device(ioc, sas_device->handle);
  2122. }
  2123. }
  2124. list_for_each_entry(mpt2sas_port,
  2125. &sas_expander->sas_port_list, port_list) {
  2126. if (mpt2sas_port->remote_identify.device_type ==
  2127. MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  2128. mpt2sas_port->remote_identify.device_type ==
  2129. MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
  2130. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2131. expander_sibling =
  2132. mpt2sas_scsih_expander_find_by_sas_address(
  2133. ioc, mpt2sas_port->remote_identify.sas_address);
  2134. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2135. _scsih_block_io_to_children_attached_to_ex(ioc,
  2136. expander_sibling);
  2137. }
  2138. }
  2139. }
  2140. /**
  2141. * _scsih_block_io_to_children_attached_directly
  2142. * @ioc: per adapter object
  2143. * @event_data: topology change event data
  2144. *
  2145. * This routine set sdev state to SDEV_BLOCK for all devices
  2146. * direct attached during device pull.
  2147. */
  2148. static void
  2149. _scsih_block_io_to_children_attached_directly(struct MPT2SAS_ADAPTER *ioc,
  2150. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2151. {
  2152. int i;
  2153. u16 handle;
  2154. u16 reason_code;
  2155. u8 phy_number;
  2156. u8 link_rate;
  2157. for (i = 0; i < event_data->NumEntries; i++) {
  2158. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2159. if (!handle)
  2160. continue;
  2161. phy_number = event_data->StartPhyNum + i;
  2162. reason_code = event_data->PHY[i].PhyStatus &
  2163. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2164. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING)
  2165. _scsih_block_io_device(ioc, handle);
  2166. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED) {
  2167. link_rate = event_data->PHY[i].LinkRate >> 4;
  2168. if (link_rate >= MPI2_SAS_NEG_LINK_RATE_1_5)
  2169. _scsih_ublock_io_device(ioc, handle);
  2170. }
  2171. }
  2172. }
  2173. /**
  2174. * _scsih_tm_tr_send - send task management request
  2175. * @ioc: per adapter object
  2176. * @handle: device handle
  2177. * Context: interrupt time.
  2178. *
  2179. * This code is to initiate the device removal handshake protocal
  2180. * with controller firmware. This function will issue target reset
  2181. * using high priority request queue. It will send a sas iounit
  2182. * controll request (MPI2_SAS_OP_REMOVE_DEVICE) from this completion.
  2183. *
  2184. * This is designed to send muliple task management request at the same
  2185. * time to the fifo. If the fifo is full, we will append the request,
  2186. * and process it in a future completion.
  2187. */
  2188. static void
  2189. _scsih_tm_tr_send(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2190. {
  2191. Mpi2SCSITaskManagementRequest_t *mpi_request;
  2192. struct MPT2SAS_TARGET *sas_target_priv_data;
  2193. u16 smid;
  2194. struct _sas_device *sas_device;
  2195. unsigned long flags;
  2196. struct _tr_list *delayed_tr;
  2197. if (ioc->shost_recovery) {
  2198. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  2199. __func__, ioc->name);
  2200. return;
  2201. }
  2202. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2203. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2204. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2205. /* skip is hidden raid component */
  2206. if (sas_device && sas_device->hidden_raid_component)
  2207. return;
  2208. smid = mpt2sas_base_get_smid_hpr(ioc, ioc->tm_tr_cb_idx);
  2209. if (!smid) {
  2210. delayed_tr = kzalloc(sizeof(*delayed_tr), GFP_ATOMIC);
  2211. if (!delayed_tr)
  2212. return;
  2213. INIT_LIST_HEAD(&delayed_tr->list);
  2214. delayed_tr->handle = handle;
  2215. delayed_tr->state = MPT2SAS_REQ_SAS_CNTRL;
  2216. list_add_tail(&delayed_tr->list,
  2217. &ioc->delayed_tr_list);
  2218. if (sas_device && sas_device->starget) {
  2219. dewtprintk(ioc, starget_printk(KERN_INFO,
  2220. sas_device->starget, "DELAYED:tr:handle(0x%04x), "
  2221. "(open)\n", handle));
  2222. } else {
  2223. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2224. "DELAYED:tr:handle(0x%04x), (open)\n",
  2225. ioc->name, handle));
  2226. }
  2227. return;
  2228. }
  2229. if (sas_device) {
  2230. sas_device->state |= MPTSAS_STATE_TR_SEND;
  2231. sas_device->state |= MPT2SAS_REQ_SAS_CNTRL;
  2232. if (sas_device->starget && sas_device->starget->hostdata) {
  2233. sas_target_priv_data = sas_device->starget->hostdata;
  2234. sas_target_priv_data->tm_busy = 1;
  2235. dewtprintk(ioc, starget_printk(KERN_INFO,
  2236. sas_device->starget, "tr:handle(0x%04x), (open)\n",
  2237. handle));
  2238. }
  2239. } else {
  2240. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2241. "tr:handle(0x%04x), (open)\n", ioc->name, handle));
  2242. }
  2243. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2244. memset(mpi_request, 0, sizeof(Mpi2SCSITaskManagementRequest_t));
  2245. mpi_request->Function = MPI2_FUNCTION_SCSI_TASK_MGMT;
  2246. mpi_request->DevHandle = cpu_to_le16(handle);
  2247. mpi_request->TaskType = MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET;
  2248. mpt2sas_base_put_smid_hi_priority(ioc, smid);
  2249. }
  2250. /**
  2251. * _scsih_sas_control_complete - completion routine
  2252. * @ioc: per adapter object
  2253. * @smid: system request message index
  2254. * @msix_index: MSIX table index supplied by the OS
  2255. * @reply: reply message frame(lower 32bit addr)
  2256. * Context: interrupt time.
  2257. *
  2258. * This is the sas iounit controll completion routine.
  2259. * This code is part of the code to initiate the device removal
  2260. * handshake protocal with controller firmware.
  2261. *
  2262. * Return 1 meaning mf should be freed from _base_interrupt
  2263. * 0 means the mf is freed from this function.
  2264. */
  2265. static u8
  2266. _scsih_sas_control_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid,
  2267. u8 msix_index, u32 reply)
  2268. {
  2269. unsigned long flags;
  2270. u16 handle;
  2271. struct _sas_device *sas_device;
  2272. Mpi2SasIoUnitControlReply_t *mpi_reply =
  2273. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2274. handle = le16_to_cpu(mpi_reply->DevHandle);
  2275. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2276. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2277. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2278. if (sas_device) {
  2279. sas_device->state |= MPTSAS_STATE_CNTRL_COMPLETE;
  2280. if (sas_device->starget)
  2281. dewtprintk(ioc, starget_printk(KERN_INFO,
  2282. sas_device->starget,
  2283. "sc_complete:handle(0x%04x), "
  2284. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  2285. handle, le16_to_cpu(mpi_reply->IOCStatus),
  2286. le32_to_cpu(mpi_reply->IOCLogInfo)));
  2287. } else {
  2288. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2289. "sc_complete:handle(0x%04x), "
  2290. "ioc_status(0x%04x), loginfo(0x%08x)\n",
  2291. ioc->name, handle, le16_to_cpu(mpi_reply->IOCStatus),
  2292. le32_to_cpu(mpi_reply->IOCLogInfo)));
  2293. }
  2294. return 1;
  2295. }
  2296. /**
  2297. * _scsih_tm_tr_complete -
  2298. * @ioc: per adapter object
  2299. * @smid: system request message index
  2300. * @msix_index: MSIX table index supplied by the OS
  2301. * @reply: reply message frame(lower 32bit addr)
  2302. * Context: interrupt time.
  2303. *
  2304. * This is the target reset completion routine.
  2305. * This code is part of the code to initiate the device removal
  2306. * handshake protocal with controller firmware.
  2307. * It will send a sas iounit controll request (MPI2_SAS_OP_REMOVE_DEVICE)
  2308. *
  2309. * Return 1 meaning mf should be freed from _base_interrupt
  2310. * 0 means the mf is freed from this function.
  2311. */
  2312. static u8
  2313. _scsih_tm_tr_complete(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index,
  2314. u32 reply)
  2315. {
  2316. unsigned long flags;
  2317. u16 handle;
  2318. struct _sas_device *sas_device;
  2319. Mpi2SCSITaskManagementReply_t *mpi_reply =
  2320. mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2321. Mpi2SasIoUnitControlRequest_t *mpi_request;
  2322. u16 smid_sas_ctrl;
  2323. struct MPT2SAS_TARGET *sas_target_priv_data;
  2324. struct _tr_list *delayed_tr;
  2325. u8 rc;
  2326. handle = le16_to_cpu(mpi_reply->DevHandle);
  2327. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2328. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2329. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2330. if (sas_device) {
  2331. sas_device->state |= MPTSAS_STATE_TR_COMPLETE;
  2332. if (sas_device->starget) {
  2333. dewtprintk(ioc, starget_printk(KERN_INFO,
  2334. sas_device->starget, "tr_complete:handle(0x%04x), "
  2335. "(%s) ioc_status(0x%04x), loginfo(0x%08x), "
  2336. "completed(%d)\n", sas_device->handle,
  2337. (sas_device->state & MPT2SAS_REQ_SAS_CNTRL) ?
  2338. "open" : "active",
  2339. le16_to_cpu(mpi_reply->IOCStatus),
  2340. le32_to_cpu(mpi_reply->IOCLogInfo),
  2341. le32_to_cpu(mpi_reply->TerminationCount)));
  2342. if (sas_device->starget->hostdata) {
  2343. sas_target_priv_data =
  2344. sas_device->starget->hostdata;
  2345. sas_target_priv_data->tm_busy = 0;
  2346. }
  2347. }
  2348. } else {
  2349. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2350. "tr_complete:handle(0x%04x), (open) ioc_status(0x%04x), "
  2351. "loginfo(0x%08x), completed(%d)\n", ioc->name,
  2352. handle, le16_to_cpu(mpi_reply->IOCStatus),
  2353. le32_to_cpu(mpi_reply->IOCLogInfo),
  2354. le32_to_cpu(mpi_reply->TerminationCount)));
  2355. }
  2356. if (!list_empty(&ioc->delayed_tr_list)) {
  2357. delayed_tr = list_entry(ioc->delayed_tr_list.next,
  2358. struct _tr_list, list);
  2359. mpt2sas_base_free_smid(ioc, smid);
  2360. if (delayed_tr->state & MPT2SAS_REQ_SAS_CNTRL)
  2361. _scsih_tm_tr_send(ioc, delayed_tr->handle);
  2362. list_del(&delayed_tr->list);
  2363. kfree(delayed_tr);
  2364. rc = 0; /* tells base_interrupt not to free mf */
  2365. } else
  2366. rc = 1;
  2367. if (sas_device && !(sas_device->state & MPT2SAS_REQ_SAS_CNTRL))
  2368. return rc;
  2369. if (ioc->shost_recovery) {
  2370. printk(MPT2SAS_INFO_FMT "%s: host reset in progress!\n",
  2371. __func__, ioc->name);
  2372. return rc;
  2373. }
  2374. smid_sas_ctrl = mpt2sas_base_get_smid(ioc, ioc->tm_sas_control_cb_idx);
  2375. if (!smid_sas_ctrl) {
  2376. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2377. ioc->name, __func__);
  2378. return rc;
  2379. }
  2380. if (sas_device)
  2381. sas_device->state |= MPTSAS_STATE_CNTRL_SEND;
  2382. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid_sas_ctrl);
  2383. memset(mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  2384. mpi_request->Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  2385. mpi_request->Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  2386. mpi_request->DevHandle = mpi_reply->DevHandle;
  2387. mpt2sas_base_put_smid_default(ioc, smid_sas_ctrl);
  2388. return rc;
  2389. }
  2390. /**
  2391. * _scsih_check_topo_delete_events - sanity check on topo events
  2392. * @ioc: per adapter object
  2393. * @event_data: the event data payload
  2394. *
  2395. * This routine added to better handle cable breaker.
  2396. *
  2397. * This handles the case where driver recieves multiple expander
  2398. * add and delete events in a single shot. When there is a delete event
  2399. * the routine will void any pending add events waiting in the event queue.
  2400. *
  2401. * Return nothing.
  2402. */
  2403. static void
  2404. _scsih_check_topo_delete_events(struct MPT2SAS_ADAPTER *ioc,
  2405. Mpi2EventDataSasTopologyChangeList_t *event_data)
  2406. {
  2407. struct fw_event_work *fw_event;
  2408. Mpi2EventDataSasTopologyChangeList_t *local_event_data;
  2409. u16 expander_handle;
  2410. struct _sas_node *sas_expander;
  2411. unsigned long flags;
  2412. int i, reason_code;
  2413. u16 handle;
  2414. for (i = 0 ; i < event_data->NumEntries; i++) {
  2415. if (event_data->PHY[i].PhyStatus &
  2416. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT)
  2417. continue;
  2418. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  2419. if (!handle)
  2420. continue;
  2421. reason_code = event_data->PHY[i].PhyStatus &
  2422. MPI2_EVENT_SAS_TOPO_RC_MASK;
  2423. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING)
  2424. _scsih_tm_tr_send(ioc, handle);
  2425. }
  2426. expander_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  2427. if (expander_handle < ioc->sas_hba.num_phys) {
  2428. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  2429. return;
  2430. }
  2431. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING
  2432. || event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING) {
  2433. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  2434. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  2435. expander_handle);
  2436. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  2437. _scsih_block_io_to_children_attached_to_ex(ioc, sas_expander);
  2438. } else if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_RESPONDING)
  2439. _scsih_block_io_to_children_attached_directly(ioc, event_data);
  2440. if (event_data->ExpStatus != MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING)
  2441. return;
  2442. /* mark ignore flag for pending events */
  2443. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  2444. list_for_each_entry(fw_event, &ioc->fw_event_list, list) {
  2445. if (fw_event->event != MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST ||
  2446. fw_event->ignore)
  2447. continue;
  2448. local_event_data = fw_event->event_data;
  2449. if (local_event_data->ExpStatus ==
  2450. MPI2_EVENT_SAS_TOPO_ES_ADDED ||
  2451. local_event_data->ExpStatus ==
  2452. MPI2_EVENT_SAS_TOPO_ES_RESPONDING) {
  2453. if (le16_to_cpu(local_event_data->ExpanderDevHandle) ==
  2454. expander_handle) {
  2455. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  2456. "setting ignoring flag\n", ioc->name));
  2457. fw_event->ignore = 1;
  2458. }
  2459. }
  2460. }
  2461. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  2462. }
  2463. /**
  2464. * _scsih_flush_running_cmds - completing outstanding commands.
  2465. * @ioc: per adapter object
  2466. *
  2467. * The flushing out of all pending scmd commands following host reset,
  2468. * where all IO is dropped to the floor.
  2469. *
  2470. * Return nothing.
  2471. */
  2472. static void
  2473. _scsih_flush_running_cmds(struct MPT2SAS_ADAPTER *ioc)
  2474. {
  2475. struct scsi_cmnd *scmd;
  2476. u16 smid;
  2477. u16 count = 0;
  2478. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  2479. scmd = _scsih_scsi_lookup_get(ioc, smid);
  2480. if (!scmd)
  2481. continue;
  2482. count++;
  2483. mpt2sas_base_free_smid(ioc, smid);
  2484. scsi_dma_unmap(scmd);
  2485. scmd->result = DID_RESET << 16;
  2486. scmd->scsi_done(scmd);
  2487. }
  2488. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT "completing %d cmds\n",
  2489. ioc->name, count));
  2490. }
  2491. /**
  2492. * _scsih_setup_eedp - setup MPI request for EEDP transfer
  2493. * @scmd: pointer to scsi command object
  2494. * @mpi_request: pointer to the SCSI_IO reqest message frame
  2495. *
  2496. * Supporting protection 1 and 3.
  2497. *
  2498. * Returns nothing
  2499. */
  2500. static void
  2501. _scsih_setup_eedp(struct scsi_cmnd *scmd, Mpi2SCSIIORequest_t *mpi_request)
  2502. {
  2503. u16 eedp_flags;
  2504. unsigned char prot_op = scsi_get_prot_op(scmd);
  2505. unsigned char prot_type = scsi_get_prot_type(scmd);
  2506. if (prot_type == SCSI_PROT_DIF_TYPE0 ||
  2507. prot_type == SCSI_PROT_DIF_TYPE2 ||
  2508. prot_op == SCSI_PROT_NORMAL)
  2509. return;
  2510. if (prot_op == SCSI_PROT_READ_STRIP)
  2511. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_CHECK_REMOVE_OP;
  2512. else if (prot_op == SCSI_PROT_WRITE_INSERT)
  2513. eedp_flags = MPI2_SCSIIO_EEDPFLAGS_INSERT_OP;
  2514. else
  2515. return;
  2516. mpi_request->EEDPBlockSize = scmd->device->sector_size;
  2517. switch (prot_type) {
  2518. case SCSI_PROT_DIF_TYPE1:
  2519. /*
  2520. * enable ref/guard checking
  2521. * auto increment ref tag
  2522. */
  2523. mpi_request->EEDPFlags = eedp_flags |
  2524. MPI2_SCSIIO_EEDPFLAGS_INC_PRI_REFTAG |
  2525. MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
  2526. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2527. mpi_request->CDB.EEDP32.PrimaryReferenceTag =
  2528. cpu_to_be32(scsi_get_lba(scmd));
  2529. break;
  2530. case SCSI_PROT_DIF_TYPE3:
  2531. /*
  2532. * enable guard checking
  2533. */
  2534. mpi_request->EEDPFlags = eedp_flags |
  2535. MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
  2536. break;
  2537. }
  2538. }
  2539. /**
  2540. * _scsih_eedp_error_handling - return sense code for EEDP errors
  2541. * @scmd: pointer to scsi command object
  2542. * @ioc_status: ioc status
  2543. *
  2544. * Returns nothing
  2545. */
  2546. static void
  2547. _scsih_eedp_error_handling(struct scsi_cmnd *scmd, u16 ioc_status)
  2548. {
  2549. u8 ascq;
  2550. u8 sk;
  2551. u8 host_byte;
  2552. switch (ioc_status) {
  2553. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  2554. ascq = 0x01;
  2555. break;
  2556. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  2557. ascq = 0x02;
  2558. break;
  2559. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  2560. ascq = 0x03;
  2561. break;
  2562. default:
  2563. ascq = 0x00;
  2564. break;
  2565. }
  2566. if (scmd->sc_data_direction == DMA_TO_DEVICE) {
  2567. sk = ILLEGAL_REQUEST;
  2568. host_byte = DID_ABORT;
  2569. } else {
  2570. sk = ABORTED_COMMAND;
  2571. host_byte = DID_OK;
  2572. }
  2573. scsi_build_sense_buffer(0, scmd->sense_buffer, sk, 0x10, ascq);
  2574. scmd->result = DRIVER_SENSE << 24 | (host_byte << 16) |
  2575. SAM_STAT_CHECK_CONDITION;
  2576. }
  2577. /**
  2578. * _scsih_qcmd - main scsi request entry point
  2579. * @scmd: pointer to scsi command object
  2580. * @done: function pointer to be invoked on completion
  2581. *
  2582. * The callback index is set inside `ioc->scsi_io_cb_idx`.
  2583. *
  2584. * Returns 0 on success. If there's a failure, return either:
  2585. * SCSI_MLQUEUE_DEVICE_BUSY if the device queue is full, or
  2586. * SCSI_MLQUEUE_HOST_BUSY if the entire host queue is full
  2587. */
  2588. static int
  2589. _scsih_qcmd(struct scsi_cmnd *scmd, void (*done)(struct scsi_cmnd *))
  2590. {
  2591. struct MPT2SAS_ADAPTER *ioc = shost_priv(scmd->device->host);
  2592. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2593. struct MPT2SAS_TARGET *sas_target_priv_data;
  2594. Mpi2SCSIIORequest_t *mpi_request;
  2595. u32 mpi_control;
  2596. u16 smid;
  2597. scmd->scsi_done = done;
  2598. sas_device_priv_data = scmd->device->hostdata;
  2599. if (!sas_device_priv_data) {
  2600. scmd->result = DID_NO_CONNECT << 16;
  2601. scmd->scsi_done(scmd);
  2602. return 0;
  2603. }
  2604. sas_target_priv_data = sas_device_priv_data->sas_target;
  2605. if (!sas_target_priv_data || sas_target_priv_data->handle ==
  2606. MPT2SAS_INVALID_DEVICE_HANDLE || sas_target_priv_data->deleted) {
  2607. scmd->result = DID_NO_CONNECT << 16;
  2608. scmd->scsi_done(scmd);
  2609. return 0;
  2610. }
  2611. /* see if we are busy with task managment stuff */
  2612. if (sas_target_priv_data->tm_busy)
  2613. return SCSI_MLQUEUE_DEVICE_BUSY;
  2614. else if (ioc->shost_recovery || ioc->ioc_link_reset_in_progress)
  2615. return SCSI_MLQUEUE_HOST_BUSY;
  2616. if (scmd->sc_data_direction == DMA_FROM_DEVICE)
  2617. mpi_control = MPI2_SCSIIO_CONTROL_READ;
  2618. else if (scmd->sc_data_direction == DMA_TO_DEVICE)
  2619. mpi_control = MPI2_SCSIIO_CONTROL_WRITE;
  2620. else
  2621. mpi_control = MPI2_SCSIIO_CONTROL_NODATATRANSFER;
  2622. /* set tags */
  2623. if (!(sas_device_priv_data->flags & MPT_DEVICE_FLAGS_INIT)) {
  2624. if (scmd->device->tagged_supported) {
  2625. if (scmd->device->ordered_tags)
  2626. mpi_control |= MPI2_SCSIIO_CONTROL_ORDEREDQ;
  2627. else
  2628. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  2629. } else
  2630. /* MPI Revision I (UNIT = 0xA) - removed MPI2_SCSIIO_CONTROL_UNTAGGED */
  2631. /* mpi_control |= MPI2_SCSIIO_CONTROL_UNTAGGED;
  2632. */
  2633. mpi_control |= (0x500);
  2634. } else
  2635. mpi_control |= MPI2_SCSIIO_CONTROL_SIMPLEQ;
  2636. if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON))
  2637. mpi_control |= MPI2_SCSIIO_CONTROL_TLR_ON;
  2638. smid = mpt2sas_base_get_smid_scsiio(ioc, ioc->scsi_io_cb_idx, scmd);
  2639. if (!smid) {
  2640. printk(MPT2SAS_ERR_FMT "%s: failed obtaining a smid\n",
  2641. ioc->name, __func__);
  2642. goto out;
  2643. }
  2644. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2645. memset(mpi_request, 0, sizeof(Mpi2SCSIIORequest_t));
  2646. _scsih_setup_eedp(scmd, mpi_request);
  2647. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  2648. if (sas_device_priv_data->sas_target->flags &
  2649. MPT_TARGET_FLAGS_RAID_COMPONENT)
  2650. mpi_request->Function = MPI2_FUNCTION_RAID_SCSI_IO_PASSTHROUGH;
  2651. else
  2652. mpi_request->Function = MPI2_FUNCTION_SCSI_IO_REQUEST;
  2653. mpi_request->DevHandle =
  2654. cpu_to_le16(sas_device_priv_data->sas_target->handle);
  2655. mpi_request->DataLength = cpu_to_le32(scsi_bufflen(scmd));
  2656. mpi_request->Control = cpu_to_le32(mpi_control);
  2657. mpi_request->IoFlags = cpu_to_le16(scmd->cmd_len);
  2658. mpi_request->MsgFlags = MPI2_SCSIIO_MSGFLAGS_SYSTEM_SENSE_ADDR;
  2659. mpi_request->SenseBufferLength = SCSI_SENSE_BUFFERSIZE;
  2660. mpi_request->SenseBufferLowAddress =
  2661. (u32)mpt2sas_base_get_sense_buffer_dma(ioc, smid);
  2662. mpi_request->SGLOffset0 = offsetof(Mpi2SCSIIORequest_t, SGL) / 4;
  2663. mpi_request->SGLFlags = cpu_to_le16(MPI2_SCSIIO_SGLFLAGS_TYPE_MPI +
  2664. MPI2_SCSIIO_SGLFLAGS_SYSTEM_ADDR);
  2665. mpi_request->VF_ID = 0; /* TODO */
  2666. mpi_request->VP_ID = 0;
  2667. int_to_scsilun(sas_device_priv_data->lun, (struct scsi_lun *)
  2668. mpi_request->LUN);
  2669. memcpy(mpi_request->CDB.CDB32, scmd->cmnd, scmd->cmd_len);
  2670. if (!mpi_request->DataLength) {
  2671. mpt2sas_base_build_zero_len_sge(ioc, &mpi_request->SGL);
  2672. } else {
  2673. if (_scsih_build_scatter_gather(ioc, scmd, smid)) {
  2674. mpt2sas_base_free_smid(ioc, smid);
  2675. goto out;
  2676. }
  2677. }
  2678. mpt2sas_base_put_smid_scsi_io(ioc, smid,
  2679. sas_device_priv_data->sas_target->handle);
  2680. return 0;
  2681. out:
  2682. return SCSI_MLQUEUE_HOST_BUSY;
  2683. }
  2684. /**
  2685. * _scsih_normalize_sense - normalize descriptor and fixed format sense data
  2686. * @sense_buffer: sense data returned by target
  2687. * @data: normalized skey/asc/ascq
  2688. *
  2689. * Return nothing.
  2690. */
  2691. static void
  2692. _scsih_normalize_sense(char *sense_buffer, struct sense_info *data)
  2693. {
  2694. if ((sense_buffer[0] & 0x7F) >= 0x72) {
  2695. /* descriptor format */
  2696. data->skey = sense_buffer[1] & 0x0F;
  2697. data->asc = sense_buffer[2];
  2698. data->ascq = sense_buffer[3];
  2699. } else {
  2700. /* fixed format */
  2701. data->skey = sense_buffer[2] & 0x0F;
  2702. data->asc = sense_buffer[12];
  2703. data->ascq = sense_buffer[13];
  2704. }
  2705. }
  2706. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  2707. /**
  2708. * _scsih_scsi_ioc_info - translated non-succesfull SCSI_IO request
  2709. * @ioc: per adapter object
  2710. * @scmd: pointer to scsi command object
  2711. * @mpi_reply: reply mf payload returned from firmware
  2712. *
  2713. * scsi_status - SCSI Status code returned from target device
  2714. * scsi_state - state info associated with SCSI_IO determined by ioc
  2715. * ioc_status - ioc supplied status info
  2716. *
  2717. * Return nothing.
  2718. */
  2719. static void
  2720. _scsih_scsi_ioc_info(struct MPT2SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
  2721. Mpi2SCSIIOReply_t *mpi_reply, u16 smid)
  2722. {
  2723. u32 response_info;
  2724. u8 *response_bytes;
  2725. u16 ioc_status = le16_to_cpu(mpi_reply->IOCStatus) &
  2726. MPI2_IOCSTATUS_MASK;
  2727. u8 scsi_state = mpi_reply->SCSIState;
  2728. u8 scsi_status = mpi_reply->SCSIStatus;
  2729. char *desc_ioc_state = NULL;
  2730. char *desc_scsi_status = NULL;
  2731. char *desc_scsi_state = ioc->tmp_string;
  2732. u32 log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  2733. if (log_info == 0x31170000)
  2734. return;
  2735. switch (ioc_status) {
  2736. case MPI2_IOCSTATUS_SUCCESS:
  2737. desc_ioc_state = "success";
  2738. break;
  2739. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  2740. desc_ioc_state = "invalid function";
  2741. break;
  2742. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  2743. desc_ioc_state = "scsi recovered error";
  2744. break;
  2745. case MPI2_IOCSTATUS_SCSI_INVALID_DEVHANDLE:
  2746. desc_ioc_state = "scsi invalid dev handle";
  2747. break;
  2748. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  2749. desc_ioc_state = "scsi device not there";
  2750. break;
  2751. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  2752. desc_ioc_state = "scsi data overrun";
  2753. break;
  2754. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  2755. desc_ioc_state = "scsi data underrun";
  2756. break;
  2757. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  2758. desc_ioc_state = "scsi io data error";
  2759. break;
  2760. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  2761. desc_ioc_state = "scsi protocol error";
  2762. break;
  2763. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  2764. desc_ioc_state = "scsi task terminated";
  2765. break;
  2766. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  2767. desc_ioc_state = "scsi residual mismatch";
  2768. break;
  2769. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  2770. desc_ioc_state = "scsi task mgmt failed";
  2771. break;
  2772. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  2773. desc_ioc_state = "scsi ioc terminated";
  2774. break;
  2775. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  2776. desc_ioc_state = "scsi ext terminated";
  2777. break;
  2778. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  2779. desc_ioc_state = "eedp guard error";
  2780. break;
  2781. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  2782. desc_ioc_state = "eedp ref tag error";
  2783. break;
  2784. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  2785. desc_ioc_state = "eedp app tag error";
  2786. break;
  2787. default:
  2788. desc_ioc_state = "unknown";
  2789. break;
  2790. }
  2791. switch (scsi_status) {
  2792. case MPI2_SCSI_STATUS_GOOD:
  2793. desc_scsi_status = "good";
  2794. break;
  2795. case MPI2_SCSI_STATUS_CHECK_CONDITION:
  2796. desc_scsi_status = "check condition";
  2797. break;
  2798. case MPI2_SCSI_STATUS_CONDITION_MET:
  2799. desc_scsi_status = "condition met";
  2800. break;
  2801. case MPI2_SCSI_STATUS_BUSY:
  2802. desc_scsi_status = "busy";
  2803. break;
  2804. case MPI2_SCSI_STATUS_INTERMEDIATE:
  2805. desc_scsi_status = "intermediate";
  2806. break;
  2807. case MPI2_SCSI_STATUS_INTERMEDIATE_CONDMET:
  2808. desc_scsi_status = "intermediate condmet";
  2809. break;
  2810. case MPI2_SCSI_STATUS_RESERVATION_CONFLICT:
  2811. desc_scsi_status = "reservation conflict";
  2812. break;
  2813. case MPI2_SCSI_STATUS_COMMAND_TERMINATED:
  2814. desc_scsi_status = "command terminated";
  2815. break;
  2816. case MPI2_SCSI_STATUS_TASK_SET_FULL:
  2817. desc_scsi_status = "task set full";
  2818. break;
  2819. case MPI2_SCSI_STATUS_ACA_ACTIVE:
  2820. desc_scsi_status = "aca active";
  2821. break;
  2822. case MPI2_SCSI_STATUS_TASK_ABORTED:
  2823. desc_scsi_status = "task aborted";
  2824. break;
  2825. default:
  2826. desc_scsi_status = "unknown";
  2827. break;
  2828. }
  2829. desc_scsi_state[0] = '\0';
  2830. if (!scsi_state)
  2831. desc_scsi_state = " ";
  2832. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  2833. strcat(desc_scsi_state, "response info ");
  2834. if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  2835. strcat(desc_scsi_state, "state terminated ");
  2836. if (scsi_state & MPI2_SCSI_STATE_NO_SCSI_STATUS)
  2837. strcat(desc_scsi_state, "no status ");
  2838. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_FAILED)
  2839. strcat(desc_scsi_state, "autosense failed ");
  2840. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID)
  2841. strcat(desc_scsi_state, "autosense valid ");
  2842. scsi_print_command(scmd);
  2843. printk(MPT2SAS_WARN_FMT "\tdev handle(0x%04x), "
  2844. "ioc_status(%s)(0x%04x), smid(%d)\n", ioc->name,
  2845. le16_to_cpu(mpi_reply->DevHandle), desc_ioc_state,
  2846. ioc_status, smid);
  2847. printk(MPT2SAS_WARN_FMT "\trequest_len(%d), underflow(%d), "
  2848. "resid(%d)\n", ioc->name, scsi_bufflen(scmd), scmd->underflow,
  2849. scsi_get_resid(scmd));
  2850. printk(MPT2SAS_WARN_FMT "\ttag(%d), transfer_count(%d), "
  2851. "sc->result(0x%08x)\n", ioc->name, le16_to_cpu(mpi_reply->TaskTag),
  2852. le32_to_cpu(mpi_reply->TransferCount), scmd->result);
  2853. printk(MPT2SAS_WARN_FMT "\tscsi_status(%s)(0x%02x), "
  2854. "scsi_state(%s)(0x%02x)\n", ioc->name, desc_scsi_status,
  2855. scsi_status, desc_scsi_state, scsi_state);
  2856. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  2857. struct sense_info data;
  2858. _scsih_normalize_sense(scmd->sense_buffer, &data);
  2859. printk(MPT2SAS_WARN_FMT "\t[sense_key,asc,ascq]: "
  2860. "[0x%02x,0x%02x,0x%02x]\n", ioc->name, data.skey,
  2861. data.asc, data.ascq);
  2862. }
  2863. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID) {
  2864. response_info = le32_to_cpu(mpi_reply->ResponseInfo);
  2865. response_bytes = (u8 *)&response_info;
  2866. _scsih_response_code(ioc, response_bytes[0]);
  2867. }
  2868. }
  2869. #endif
  2870. /**
  2871. * _scsih_smart_predicted_fault - illuminate Fault LED
  2872. * @ioc: per adapter object
  2873. * @handle: device handle
  2874. *
  2875. * Return nothing.
  2876. */
  2877. static void
  2878. _scsih_smart_predicted_fault(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  2879. {
  2880. Mpi2SepReply_t mpi_reply;
  2881. Mpi2SepRequest_t mpi_request;
  2882. struct scsi_target *starget;
  2883. struct MPT2SAS_TARGET *sas_target_priv_data;
  2884. Mpi2EventNotificationReply_t *event_reply;
  2885. Mpi2EventDataSasDeviceStatusChange_t *event_data;
  2886. struct _sas_device *sas_device;
  2887. ssize_t sz;
  2888. unsigned long flags;
  2889. /* only handle non-raid devices */
  2890. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  2891. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  2892. if (!sas_device) {
  2893. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2894. return;
  2895. }
  2896. starget = sas_device->starget;
  2897. sas_target_priv_data = starget->hostdata;
  2898. if ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_RAID_COMPONENT) ||
  2899. ((sas_target_priv_data->flags & MPT_TARGET_FLAGS_VOLUME))) {
  2900. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2901. return;
  2902. }
  2903. starget_printk(KERN_WARNING, starget, "predicted fault\n");
  2904. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  2905. if (ioc->pdev->subsystem_vendor == PCI_VENDOR_ID_IBM) {
  2906. memset(&mpi_request, 0, sizeof(Mpi2SepRequest_t));
  2907. mpi_request.Function = MPI2_FUNCTION_SCSI_ENCLOSURE_PROCESSOR;
  2908. mpi_request.Action = MPI2_SEP_REQ_ACTION_WRITE_STATUS;
  2909. mpi_request.SlotStatus =
  2910. MPI2_SEP_REQ_SLOTSTATUS_PREDICTED_FAULT;
  2911. mpi_request.DevHandle = cpu_to_le16(handle);
  2912. mpi_request.Flags = MPI2_SEP_REQ_FLAGS_DEVHANDLE_ADDRESS;
  2913. if ((mpt2sas_base_scsi_enclosure_processor(ioc, &mpi_reply,
  2914. &mpi_request)) != 0) {
  2915. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  2916. ioc->name, __FILE__, __LINE__, __func__);
  2917. return;
  2918. }
  2919. if (mpi_reply.IOCStatus || mpi_reply.IOCLogInfo) {
  2920. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT
  2921. "enclosure_processor: ioc_status (0x%04x), "
  2922. "loginfo(0x%08x)\n", ioc->name,
  2923. le16_to_cpu(mpi_reply.IOCStatus),
  2924. le32_to_cpu(mpi_reply.IOCLogInfo)));
  2925. return;
  2926. }
  2927. }
  2928. /* insert into event log */
  2929. sz = offsetof(Mpi2EventNotificationReply_t, EventData) +
  2930. sizeof(Mpi2EventDataSasDeviceStatusChange_t);
  2931. event_reply = kzalloc(sz, GFP_KERNEL);
  2932. if (!event_reply) {
  2933. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  2934. ioc->name, __FILE__, __LINE__, __func__);
  2935. return;
  2936. }
  2937. event_reply->Function = MPI2_FUNCTION_EVENT_NOTIFICATION;
  2938. event_reply->Event =
  2939. cpu_to_le16(MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE);
  2940. event_reply->MsgLength = sz/4;
  2941. event_reply->EventDataLength =
  2942. cpu_to_le16(sizeof(Mpi2EventDataSasDeviceStatusChange_t)/4);
  2943. event_data = (Mpi2EventDataSasDeviceStatusChange_t *)
  2944. event_reply->EventData;
  2945. event_data->ReasonCode = MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA;
  2946. event_data->ASC = 0x5D;
  2947. event_data->DevHandle = cpu_to_le16(handle);
  2948. event_data->SASAddress = cpu_to_le64(sas_target_priv_data->sas_address);
  2949. mpt2sas_ctl_add_to_event_log(ioc, event_reply);
  2950. kfree(event_reply);
  2951. }
  2952. /**
  2953. * _scsih_io_done - scsi request callback
  2954. * @ioc: per adapter object
  2955. * @smid: system request message index
  2956. * @msix_index: MSIX table index supplied by the OS
  2957. * @reply: reply message frame(lower 32bit addr)
  2958. *
  2959. * Callback handler when using _scsih_qcmd.
  2960. *
  2961. * Return 1 meaning mf should be freed from _base_interrupt
  2962. * 0 means the mf is freed from this function.
  2963. */
  2964. static u8
  2965. _scsih_io_done(struct MPT2SAS_ADAPTER *ioc, u16 smid, u8 msix_index, u32 reply)
  2966. {
  2967. Mpi2SCSIIORequest_t *mpi_request;
  2968. Mpi2SCSIIOReply_t *mpi_reply;
  2969. struct scsi_cmnd *scmd;
  2970. u16 ioc_status;
  2971. u32 xfer_cnt;
  2972. u8 scsi_state;
  2973. u8 scsi_status;
  2974. u32 log_info;
  2975. struct MPT2SAS_DEVICE *sas_device_priv_data;
  2976. u32 response_code = 0;
  2977. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  2978. scmd = _scsih_scsi_lookup_get(ioc, smid);
  2979. if (scmd == NULL)
  2980. return 1;
  2981. mpi_request = mpt2sas_base_get_msg_frame(ioc, smid);
  2982. if (mpi_reply == NULL) {
  2983. scmd->result = DID_OK << 16;
  2984. goto out;
  2985. }
  2986. sas_device_priv_data = scmd->device->hostdata;
  2987. if (!sas_device_priv_data || !sas_device_priv_data->sas_target ||
  2988. sas_device_priv_data->sas_target->deleted) {
  2989. scmd->result = DID_NO_CONNECT << 16;
  2990. goto out;
  2991. }
  2992. /* turning off TLR */
  2993. scsi_state = mpi_reply->SCSIState;
  2994. if (scsi_state & MPI2_SCSI_STATE_RESPONSE_INFO_VALID)
  2995. response_code =
  2996. le32_to_cpu(mpi_reply->ResponseInfo) & 0xFF;
  2997. if (!sas_device_priv_data->tlr_snoop_check) {
  2998. sas_device_priv_data->tlr_snoop_check++;
  2999. if ((sas_device_priv_data->flags & MPT_DEVICE_TLR_ON) &&
  3000. response_code == MPI2_SCSITASKMGMT_RSP_INVALID_FRAME)
  3001. sas_device_priv_data->flags &=
  3002. ~MPT_DEVICE_TLR_ON;
  3003. }
  3004. xfer_cnt = le32_to_cpu(mpi_reply->TransferCount);
  3005. scsi_set_resid(scmd, scsi_bufflen(scmd) - xfer_cnt);
  3006. ioc_status = le16_to_cpu(mpi_reply->IOCStatus);
  3007. if (ioc_status & MPI2_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE)
  3008. log_info = le32_to_cpu(mpi_reply->IOCLogInfo);
  3009. else
  3010. log_info = 0;
  3011. ioc_status &= MPI2_IOCSTATUS_MASK;
  3012. scsi_status = mpi_reply->SCSIStatus;
  3013. if (ioc_status == MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN && xfer_cnt == 0 &&
  3014. (scsi_status == MPI2_SCSI_STATUS_BUSY ||
  3015. scsi_status == MPI2_SCSI_STATUS_RESERVATION_CONFLICT ||
  3016. scsi_status == MPI2_SCSI_STATUS_TASK_SET_FULL)) {
  3017. ioc_status = MPI2_IOCSTATUS_SUCCESS;
  3018. }
  3019. if (scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID) {
  3020. struct sense_info data;
  3021. const void *sense_data = mpt2sas_base_get_sense_buffer(ioc,
  3022. smid);
  3023. u32 sz = min_t(u32, SCSI_SENSE_BUFFERSIZE,
  3024. le32_to_cpu(mpi_reply->SenseCount));
  3025. memcpy(scmd->sense_buffer, sense_data, sz);
  3026. _scsih_normalize_sense(scmd->sense_buffer, &data);
  3027. /* failure prediction threshold exceeded */
  3028. if (data.asc == 0x5D)
  3029. _scsih_smart_predicted_fault(ioc,
  3030. le16_to_cpu(mpi_reply->DevHandle));
  3031. }
  3032. switch (ioc_status) {
  3033. case MPI2_IOCSTATUS_BUSY:
  3034. case MPI2_IOCSTATUS_INSUFFICIENT_RESOURCES:
  3035. scmd->result = SAM_STAT_BUSY;
  3036. break;
  3037. case MPI2_IOCSTATUS_SCSI_DEVICE_NOT_THERE:
  3038. scmd->result = DID_NO_CONNECT << 16;
  3039. break;
  3040. case MPI2_IOCSTATUS_SCSI_IOC_TERMINATED:
  3041. if (sas_device_priv_data->block) {
  3042. scmd->result = (DID_BUS_BUSY << 16);
  3043. break;
  3044. }
  3045. case MPI2_IOCSTATUS_SCSI_TASK_TERMINATED:
  3046. case MPI2_IOCSTATUS_SCSI_EXT_TERMINATED:
  3047. scmd->result = DID_RESET << 16;
  3048. break;
  3049. case MPI2_IOCSTATUS_SCSI_RESIDUAL_MISMATCH:
  3050. if ((xfer_cnt == 0) || (scmd->underflow > xfer_cnt))
  3051. scmd->result = DID_SOFT_ERROR << 16;
  3052. else
  3053. scmd->result = (DID_OK << 16) | scsi_status;
  3054. break;
  3055. case MPI2_IOCSTATUS_SCSI_DATA_UNDERRUN:
  3056. scmd->result = (DID_OK << 16) | scsi_status;
  3057. if ((scsi_state & MPI2_SCSI_STATE_AUTOSENSE_VALID))
  3058. break;
  3059. if (xfer_cnt < scmd->underflow) {
  3060. if (scsi_status == SAM_STAT_BUSY)
  3061. scmd->result = SAM_STAT_BUSY;
  3062. else
  3063. scmd->result = DID_SOFT_ERROR << 16;
  3064. } else if (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  3065. MPI2_SCSI_STATE_NO_SCSI_STATUS))
  3066. scmd->result = DID_SOFT_ERROR << 16;
  3067. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3068. scmd->result = DID_RESET << 16;
  3069. else if (!xfer_cnt && scmd->cmnd[0] == REPORT_LUNS) {
  3070. mpi_reply->SCSIState = MPI2_SCSI_STATE_AUTOSENSE_VALID;
  3071. mpi_reply->SCSIStatus = SAM_STAT_CHECK_CONDITION;
  3072. scmd->result = (DRIVER_SENSE << 24) |
  3073. SAM_STAT_CHECK_CONDITION;
  3074. scmd->sense_buffer[0] = 0x70;
  3075. scmd->sense_buffer[2] = ILLEGAL_REQUEST;
  3076. scmd->sense_buffer[12] = 0x20;
  3077. scmd->sense_buffer[13] = 0;
  3078. }
  3079. break;
  3080. case MPI2_IOCSTATUS_SCSI_DATA_OVERRUN:
  3081. scsi_set_resid(scmd, 0);
  3082. case MPI2_IOCSTATUS_SCSI_RECOVERED_ERROR:
  3083. case MPI2_IOCSTATUS_SUCCESS:
  3084. scmd->result = (DID_OK << 16) | scsi_status;
  3085. if (response_code ==
  3086. MPI2_SCSITASKMGMT_RSP_INVALID_FRAME ||
  3087. (scsi_state & (MPI2_SCSI_STATE_AUTOSENSE_FAILED |
  3088. MPI2_SCSI_STATE_NO_SCSI_STATUS)))
  3089. scmd->result = DID_SOFT_ERROR << 16;
  3090. else if (scsi_state & MPI2_SCSI_STATE_TERMINATED)
  3091. scmd->result = DID_RESET << 16;
  3092. break;
  3093. case MPI2_IOCSTATUS_EEDP_GUARD_ERROR:
  3094. case MPI2_IOCSTATUS_EEDP_REF_TAG_ERROR:
  3095. case MPI2_IOCSTATUS_EEDP_APP_TAG_ERROR:
  3096. _scsih_eedp_error_handling(scmd, ioc_status);
  3097. break;
  3098. case MPI2_IOCSTATUS_SCSI_PROTOCOL_ERROR:
  3099. case MPI2_IOCSTATUS_INVALID_FUNCTION:
  3100. case MPI2_IOCSTATUS_INVALID_SGL:
  3101. case MPI2_IOCSTATUS_INTERNAL_ERROR:
  3102. case MPI2_IOCSTATUS_INVALID_FIELD:
  3103. case MPI2_IOCSTATUS_INVALID_STATE:
  3104. case MPI2_IOCSTATUS_SCSI_IO_DATA_ERROR:
  3105. case MPI2_IOCSTATUS_SCSI_TASK_MGMT_FAILED:
  3106. default:
  3107. scmd->result = DID_SOFT_ERROR << 16;
  3108. break;
  3109. }
  3110. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3111. if (scmd->result && (ioc->logging_level & MPT_DEBUG_REPLY))
  3112. _scsih_scsi_ioc_info(ioc , scmd, mpi_reply, smid);
  3113. #endif
  3114. out:
  3115. scsi_dma_unmap(scmd);
  3116. scmd->scsi_done(scmd);
  3117. return 1;
  3118. }
  3119. /**
  3120. * _scsih_sas_host_refresh - refreshing sas host object contents
  3121. * @ioc: per adapter object
  3122. * Context: user
  3123. *
  3124. * During port enable, fw will send topology events for every device. Its
  3125. * possible that the handles may change from the previous setting, so this
  3126. * code keeping handles updating if changed.
  3127. *
  3128. * Return nothing.
  3129. */
  3130. static void
  3131. _scsih_sas_host_refresh(struct MPT2SAS_ADAPTER *ioc)
  3132. {
  3133. u16 sz;
  3134. u16 ioc_status;
  3135. int i;
  3136. Mpi2ConfigReply_t mpi_reply;
  3137. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  3138. u16 attached_handle;
  3139. dtmprintk(ioc, printk(MPT2SAS_INFO_FMT
  3140. "updating handles for sas_host(0x%016llx)\n",
  3141. ioc->name, (unsigned long long)ioc->sas_hba.sas_address));
  3142. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys
  3143. * sizeof(Mpi2SasIOUnit0PhyData_t));
  3144. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  3145. if (!sas_iounit_pg0) {
  3146. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3147. ioc->name, __FILE__, __LINE__, __func__);
  3148. return;
  3149. }
  3150. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  3151. sas_iounit_pg0, sz)) != 0)
  3152. goto out;
  3153. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) & MPI2_IOCSTATUS_MASK;
  3154. if (ioc_status != MPI2_IOCSTATUS_SUCCESS)
  3155. goto out;
  3156. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  3157. if (i == 0)
  3158. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  3159. PhyData[0].ControllerDevHandle);
  3160. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  3161. attached_handle = le16_to_cpu(sas_iounit_pg0->PhyData[i].
  3162. AttachedDevHandle);
  3163. mpt2sas_transport_update_links(ioc, ioc->sas_hba.sas_address,
  3164. attached_handle, i, sas_iounit_pg0->PhyData[i].
  3165. NegotiatedLinkRate >> 4);
  3166. }
  3167. out:
  3168. kfree(sas_iounit_pg0);
  3169. }
  3170. /**
  3171. * _scsih_sas_host_add - create sas host object
  3172. * @ioc: per adapter object
  3173. *
  3174. * Creating host side data object, stored in ioc->sas_hba
  3175. *
  3176. * Return nothing.
  3177. */
  3178. static void
  3179. _scsih_sas_host_add(struct MPT2SAS_ADAPTER *ioc)
  3180. {
  3181. int i;
  3182. Mpi2ConfigReply_t mpi_reply;
  3183. Mpi2SasIOUnitPage0_t *sas_iounit_pg0 = NULL;
  3184. Mpi2SasIOUnitPage1_t *sas_iounit_pg1 = NULL;
  3185. Mpi2SasPhyPage0_t phy_pg0;
  3186. Mpi2SasDevicePage0_t sas_device_pg0;
  3187. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3188. u16 ioc_status;
  3189. u16 sz;
  3190. u16 device_missing_delay;
  3191. mpt2sas_config_get_number_hba_phys(ioc, &ioc->sas_hba.num_phys);
  3192. if (!ioc->sas_hba.num_phys) {
  3193. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3194. ioc->name, __FILE__, __LINE__, __func__);
  3195. return;
  3196. }
  3197. /* sas_iounit page 0 */
  3198. sz = offsetof(Mpi2SasIOUnitPage0_t, PhyData) + (ioc->sas_hba.num_phys *
  3199. sizeof(Mpi2SasIOUnit0PhyData_t));
  3200. sas_iounit_pg0 = kzalloc(sz, GFP_KERNEL);
  3201. if (!sas_iounit_pg0) {
  3202. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3203. ioc->name, __FILE__, __LINE__, __func__);
  3204. return;
  3205. }
  3206. if ((mpt2sas_config_get_sas_iounit_pg0(ioc, &mpi_reply,
  3207. sas_iounit_pg0, sz))) {
  3208. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3209. ioc->name, __FILE__, __LINE__, __func__);
  3210. goto out;
  3211. }
  3212. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3213. MPI2_IOCSTATUS_MASK;
  3214. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3215. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3216. ioc->name, __FILE__, __LINE__, __func__);
  3217. goto out;
  3218. }
  3219. /* sas_iounit page 1 */
  3220. sz = offsetof(Mpi2SasIOUnitPage1_t, PhyData) + (ioc->sas_hba.num_phys *
  3221. sizeof(Mpi2SasIOUnit1PhyData_t));
  3222. sas_iounit_pg1 = kzalloc(sz, GFP_KERNEL);
  3223. if (!sas_iounit_pg1) {
  3224. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3225. ioc->name, __FILE__, __LINE__, __func__);
  3226. goto out;
  3227. }
  3228. if ((mpt2sas_config_get_sas_iounit_pg1(ioc, &mpi_reply,
  3229. sas_iounit_pg1, sz))) {
  3230. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3231. ioc->name, __FILE__, __LINE__, __func__);
  3232. goto out;
  3233. }
  3234. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3235. MPI2_IOCSTATUS_MASK;
  3236. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3237. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3238. ioc->name, __FILE__, __LINE__, __func__);
  3239. goto out;
  3240. }
  3241. ioc->io_missing_delay =
  3242. le16_to_cpu(sas_iounit_pg1->IODeviceMissingDelay);
  3243. device_missing_delay =
  3244. le16_to_cpu(sas_iounit_pg1->ReportDeviceMissingDelay);
  3245. if (device_missing_delay & MPI2_SASIOUNIT1_REPORT_MISSING_UNIT_16)
  3246. ioc->device_missing_delay = (device_missing_delay &
  3247. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK) * 16;
  3248. else
  3249. ioc->device_missing_delay = device_missing_delay &
  3250. MPI2_SASIOUNIT1_REPORT_MISSING_TIMEOUT_MASK;
  3251. ioc->sas_hba.parent_dev = &ioc->shost->shost_gendev;
  3252. ioc->sas_hba.phy = kcalloc(ioc->sas_hba.num_phys,
  3253. sizeof(struct _sas_phy), GFP_KERNEL);
  3254. if (!ioc->sas_hba.phy) {
  3255. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3256. ioc->name, __FILE__, __LINE__, __func__);
  3257. goto out;
  3258. }
  3259. for (i = 0; i < ioc->sas_hba.num_phys ; i++) {
  3260. if ((mpt2sas_config_get_phy_pg0(ioc, &mpi_reply, &phy_pg0,
  3261. i))) {
  3262. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3263. ioc->name, __FILE__, __LINE__, __func__);
  3264. goto out;
  3265. }
  3266. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3267. MPI2_IOCSTATUS_MASK;
  3268. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3269. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3270. ioc->name, __FILE__, __LINE__, __func__);
  3271. goto out;
  3272. }
  3273. if (i == 0)
  3274. ioc->sas_hba.handle = le16_to_cpu(sas_iounit_pg0->
  3275. PhyData[0].ControllerDevHandle);
  3276. ioc->sas_hba.phy[i].handle = ioc->sas_hba.handle;
  3277. ioc->sas_hba.phy[i].phy_id = i;
  3278. mpt2sas_transport_add_host_phy(ioc, &ioc->sas_hba.phy[i],
  3279. phy_pg0, ioc->sas_hba.parent_dev);
  3280. }
  3281. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  3282. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, ioc->sas_hba.handle))) {
  3283. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3284. ioc->name, __FILE__, __LINE__, __func__);
  3285. goto out;
  3286. }
  3287. ioc->sas_hba.enclosure_handle =
  3288. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  3289. ioc->sas_hba.sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  3290. printk(MPT2SAS_INFO_FMT "host_add: handle(0x%04x), "
  3291. "sas_addr(0x%016llx), phys(%d)\n", ioc->name, ioc->sas_hba.handle,
  3292. (unsigned long long) ioc->sas_hba.sas_address,
  3293. ioc->sas_hba.num_phys) ;
  3294. if (ioc->sas_hba.enclosure_handle) {
  3295. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  3296. &enclosure_pg0,
  3297. MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3298. ioc->sas_hba.enclosure_handle))) {
  3299. ioc->sas_hba.enclosure_logical_id =
  3300. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3301. }
  3302. }
  3303. out:
  3304. kfree(sas_iounit_pg1);
  3305. kfree(sas_iounit_pg0);
  3306. }
  3307. /**
  3308. * _scsih_expander_add - creating expander object
  3309. * @ioc: per adapter object
  3310. * @handle: expander handle
  3311. *
  3312. * Creating expander object, stored in ioc->sas_expander_list.
  3313. *
  3314. * Return 0 for success, else error.
  3315. */
  3316. static int
  3317. _scsih_expander_add(struct MPT2SAS_ADAPTER *ioc, u16 handle)
  3318. {
  3319. struct _sas_node *sas_expander;
  3320. Mpi2ConfigReply_t mpi_reply;
  3321. Mpi2ExpanderPage0_t expander_pg0;
  3322. Mpi2ExpanderPage1_t expander_pg1;
  3323. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3324. u32 ioc_status;
  3325. u16 parent_handle;
  3326. __le64 sas_address, sas_address_parent = 0;
  3327. int i;
  3328. unsigned long flags;
  3329. struct _sas_port *mpt2sas_port = NULL;
  3330. int rc = 0;
  3331. if (!handle)
  3332. return -1;
  3333. if (ioc->shost_recovery)
  3334. return -1;
  3335. if ((mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  3336. MPI2_SAS_EXPAND_PGAD_FORM_HNDL, handle))) {
  3337. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3338. ioc->name, __FILE__, __LINE__, __func__);
  3339. return -1;
  3340. }
  3341. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3342. MPI2_IOCSTATUS_MASK;
  3343. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3344. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3345. ioc->name, __FILE__, __LINE__, __func__);
  3346. return -1;
  3347. }
  3348. /* handle out of order topology events */
  3349. parent_handle = le16_to_cpu(expander_pg0.ParentDevHandle);
  3350. if (_scsih_get_sas_address(ioc, parent_handle, &sas_address_parent)
  3351. != 0) {
  3352. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3353. ioc->name, __FILE__, __LINE__, __func__);
  3354. return -1;
  3355. }
  3356. if (sas_address_parent != ioc->sas_hba.sas_address) {
  3357. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3358. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3359. sas_address_parent);
  3360. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3361. if (!sas_expander) {
  3362. rc = _scsih_expander_add(ioc, parent_handle);
  3363. if (rc != 0)
  3364. return rc;
  3365. }
  3366. }
  3367. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3368. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  3369. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3370. sas_address);
  3371. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3372. if (sas_expander)
  3373. return 0;
  3374. sas_expander = kzalloc(sizeof(struct _sas_node),
  3375. GFP_KERNEL);
  3376. if (!sas_expander) {
  3377. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3378. ioc->name, __FILE__, __LINE__, __func__);
  3379. return -1;
  3380. }
  3381. sas_expander->handle = handle;
  3382. sas_expander->num_phys = expander_pg0.NumPhys;
  3383. sas_expander->sas_address_parent = sas_address_parent;
  3384. sas_expander->sas_address = sas_address;
  3385. printk(MPT2SAS_INFO_FMT "expander_add: handle(0x%04x),"
  3386. " parent(0x%04x), sas_addr(0x%016llx), phys(%d)\n", ioc->name,
  3387. handle, parent_handle, (unsigned long long)
  3388. sas_expander->sas_address, sas_expander->num_phys);
  3389. if (!sas_expander->num_phys)
  3390. goto out_fail;
  3391. sas_expander->phy = kcalloc(sas_expander->num_phys,
  3392. sizeof(struct _sas_phy), GFP_KERNEL);
  3393. if (!sas_expander->phy) {
  3394. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3395. ioc->name, __FILE__, __LINE__, __func__);
  3396. rc = -1;
  3397. goto out_fail;
  3398. }
  3399. INIT_LIST_HEAD(&sas_expander->sas_port_list);
  3400. mpt2sas_port = mpt2sas_transport_port_add(ioc, handle,
  3401. sas_address_parent);
  3402. if (!mpt2sas_port) {
  3403. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3404. ioc->name, __FILE__, __LINE__, __func__);
  3405. rc = -1;
  3406. goto out_fail;
  3407. }
  3408. sas_expander->parent_dev = &mpt2sas_port->rphy->dev;
  3409. for (i = 0 ; i < sas_expander->num_phys ; i++) {
  3410. if ((mpt2sas_config_get_expander_pg1(ioc, &mpi_reply,
  3411. &expander_pg1, i, handle))) {
  3412. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3413. ioc->name, __FILE__, __LINE__, __func__);
  3414. rc = -1;
  3415. goto out_fail;
  3416. }
  3417. sas_expander->phy[i].handle = handle;
  3418. sas_expander->phy[i].phy_id = i;
  3419. if ((mpt2sas_transport_add_expander_phy(ioc,
  3420. &sas_expander->phy[i], expander_pg1,
  3421. sas_expander->parent_dev))) {
  3422. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3423. ioc->name, __FILE__, __LINE__, __func__);
  3424. rc = -1;
  3425. goto out_fail;
  3426. }
  3427. }
  3428. if (sas_expander->enclosure_handle) {
  3429. if (!(mpt2sas_config_get_enclosure_pg0(ioc, &mpi_reply,
  3430. &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3431. sas_expander->enclosure_handle))) {
  3432. sas_expander->enclosure_logical_id =
  3433. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3434. }
  3435. }
  3436. _scsih_expander_node_add(ioc, sas_expander);
  3437. return 0;
  3438. out_fail:
  3439. if (mpt2sas_port)
  3440. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  3441. sas_address_parent);
  3442. kfree(sas_expander);
  3443. return rc;
  3444. }
  3445. /**
  3446. * _scsih_expander_remove - removing expander object
  3447. * @ioc: per adapter object
  3448. * @sas_address: expander sas_address
  3449. *
  3450. * Return nothing.
  3451. */
  3452. static void
  3453. _scsih_expander_remove(struct MPT2SAS_ADAPTER *ioc, u64 sas_address)
  3454. {
  3455. struct _sas_node *sas_expander;
  3456. unsigned long flags;
  3457. if (ioc->shost_recovery)
  3458. return;
  3459. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3460. sas_expander = mpt2sas_scsih_expander_find_by_sas_address(ioc,
  3461. sas_address);
  3462. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3463. _scsih_expander_node_remove(ioc, sas_expander);
  3464. }
  3465. /**
  3466. * _scsih_add_device - creating sas device object
  3467. * @ioc: per adapter object
  3468. * @handle: sas device handle
  3469. * @phy_num: phy number end device attached to
  3470. * @is_pd: is this hidden raid component
  3471. *
  3472. * Creating end device object, stored in ioc->sas_device_list.
  3473. *
  3474. * Returns 0 for success, non-zero for failure.
  3475. */
  3476. static int
  3477. _scsih_add_device(struct MPT2SAS_ADAPTER *ioc, u16 handle, u8 phy_num, u8 is_pd)
  3478. {
  3479. Mpi2ConfigReply_t mpi_reply;
  3480. Mpi2SasDevicePage0_t sas_device_pg0;
  3481. Mpi2SasEnclosurePage0_t enclosure_pg0;
  3482. struct _sas_device *sas_device;
  3483. u32 ioc_status;
  3484. __le64 sas_address;
  3485. u32 device_info;
  3486. unsigned long flags;
  3487. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  3488. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  3489. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3490. ioc->name, __FILE__, __LINE__, __func__);
  3491. return -1;
  3492. }
  3493. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  3494. MPI2_IOCSTATUS_MASK;
  3495. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  3496. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3497. ioc->name, __FILE__, __LINE__, __func__);
  3498. return -1;
  3499. }
  3500. /* check if device is present */
  3501. if (!(le16_to_cpu(sas_device_pg0.Flags) &
  3502. MPI2_SAS_DEVICE0_FLAGS_DEVICE_PRESENT)) {
  3503. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3504. ioc->name, __FILE__, __LINE__, __func__);
  3505. printk(MPT2SAS_ERR_FMT "Flags = 0x%04x\n",
  3506. ioc->name, le16_to_cpu(sas_device_pg0.Flags));
  3507. return -1;
  3508. }
  3509. /* check if there were any issus with discovery */
  3510. if (sas_device_pg0.AccessStatus ==
  3511. MPI2_SAS_DEVICE0_ASTATUS_SATA_INIT_FAILED) {
  3512. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3513. ioc->name, __FILE__, __LINE__, __func__);
  3514. printk(MPT2SAS_ERR_FMT "AccessStatus = 0x%02x\n",
  3515. ioc->name, sas_device_pg0.AccessStatus);
  3516. return -1;
  3517. }
  3518. /* check if this is end device */
  3519. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  3520. if (!(_scsih_is_end_device(device_info))) {
  3521. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3522. ioc->name, __FILE__, __LINE__, __func__);
  3523. return -1;
  3524. }
  3525. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  3526. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3527. sas_device = mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  3528. sas_address);
  3529. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3530. if (sas_device) {
  3531. _scsih_ublock_io_device(ioc, handle);
  3532. return 0;
  3533. }
  3534. sas_device = kzalloc(sizeof(struct _sas_device),
  3535. GFP_KERNEL);
  3536. if (!sas_device) {
  3537. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3538. ioc->name, __FILE__, __LINE__, __func__);
  3539. return -1;
  3540. }
  3541. sas_device->handle = handle;
  3542. if (_scsih_get_sas_address(ioc, le16_to_cpu
  3543. (sas_device_pg0.ParentDevHandle),
  3544. &sas_device->sas_address_parent) != 0)
  3545. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3546. ioc->name, __FILE__, __LINE__, __func__);
  3547. sas_device->enclosure_handle =
  3548. le16_to_cpu(sas_device_pg0.EnclosureHandle);
  3549. sas_device->slot =
  3550. le16_to_cpu(sas_device_pg0.Slot);
  3551. sas_device->device_info = device_info;
  3552. sas_device->sas_address = sas_address;
  3553. sas_device->hidden_raid_component = is_pd;
  3554. /* get enclosure_logical_id */
  3555. if (sas_device->enclosure_handle && !(mpt2sas_config_get_enclosure_pg0(
  3556. ioc, &mpi_reply, &enclosure_pg0, MPI2_SAS_ENCLOS_PGAD_FORM_HANDLE,
  3557. sas_device->enclosure_handle)))
  3558. sas_device->enclosure_logical_id =
  3559. le64_to_cpu(enclosure_pg0.EnclosureLogicalID);
  3560. /* get device name */
  3561. sas_device->device_name = le64_to_cpu(sas_device_pg0.DeviceName);
  3562. if (ioc->wait_for_port_enable_to_complete)
  3563. _scsih_sas_device_init_add(ioc, sas_device);
  3564. else
  3565. _scsih_sas_device_add(ioc, sas_device);
  3566. return 0;
  3567. }
  3568. /**
  3569. * _scsih_remove_device - removing sas device object
  3570. * @ioc: per adapter object
  3571. * @sas_device: the sas_device object
  3572. *
  3573. * Return nothing.
  3574. */
  3575. static void
  3576. _scsih_remove_device(struct MPT2SAS_ADAPTER *ioc, struct _sas_device
  3577. *sas_device)
  3578. {
  3579. struct MPT2SAS_TARGET *sas_target_priv_data;
  3580. Mpi2SasIoUnitControlReply_t mpi_reply;
  3581. Mpi2SasIoUnitControlRequest_t mpi_request;
  3582. u16 device_handle, handle;
  3583. if (!sas_device)
  3584. return;
  3585. handle = sas_device->handle;
  3586. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: enter: handle(0x%04x),"
  3587. " sas_addr(0x%016llx)\n", ioc->name, __func__, handle,
  3588. (unsigned long long) sas_device->sas_address));
  3589. if (sas_device->starget && sas_device->starget->hostdata) {
  3590. sas_target_priv_data = sas_device->starget->hostdata;
  3591. sas_target_priv_data->deleted = 1;
  3592. }
  3593. if (ioc->remove_host || ioc->shost_recovery || !handle)
  3594. goto out;
  3595. if ((sas_device->state & MPTSAS_STATE_TR_COMPLETE)) {
  3596. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "\tskip "
  3597. "target_reset handle(0x%04x)\n", ioc->name,
  3598. handle));
  3599. goto skip_tr;
  3600. }
  3601. /* Target Reset to flush out all the outstanding IO */
  3602. device_handle = (sas_device->hidden_raid_component) ?
  3603. sas_device->volume_handle : handle;
  3604. if (device_handle) {
  3605. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset: "
  3606. "handle(0x%04x)\n", ioc->name, device_handle));
  3607. mutex_lock(&ioc->tm_cmds.mutex);
  3608. mpt2sas_scsih_issue_tm(ioc, device_handle, 0,
  3609. MPI2_SCSITASKMGMT_TASKTYPE_TARGET_RESET, 0, 10);
  3610. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  3611. mutex_unlock(&ioc->tm_cmds.mutex);
  3612. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "issue target reset "
  3613. "done: handle(0x%04x)\n", ioc->name, device_handle));
  3614. if (ioc->shost_recovery)
  3615. goto out;
  3616. }
  3617. skip_tr:
  3618. if ((sas_device->state & MPTSAS_STATE_CNTRL_COMPLETE)) {
  3619. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "\tskip "
  3620. "sas_cntrl handle(0x%04x)\n", ioc->name, handle));
  3621. goto out;
  3622. }
  3623. /* SAS_IO_UNIT_CNTR - send REMOVE_DEVICE */
  3624. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: handle"
  3625. "(0x%04x)\n", ioc->name, handle));
  3626. memset(&mpi_request, 0, sizeof(Mpi2SasIoUnitControlRequest_t));
  3627. mpi_request.Function = MPI2_FUNCTION_SAS_IO_UNIT_CONTROL;
  3628. mpi_request.Operation = MPI2_SAS_OP_REMOVE_DEVICE;
  3629. mpi_request.DevHandle = handle;
  3630. mpi_request.VF_ID = 0; /* TODO */
  3631. mpi_request.VP_ID = 0;
  3632. if ((mpt2sas_base_sas_iounit_control(ioc, &mpi_reply,
  3633. &mpi_request)) != 0) {
  3634. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  3635. ioc->name, __FILE__, __LINE__, __func__);
  3636. }
  3637. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "sas_iounit: ioc_status"
  3638. "(0x%04x), loginfo(0x%08x)\n", ioc->name,
  3639. le16_to_cpu(mpi_reply.IOCStatus),
  3640. le32_to_cpu(mpi_reply.IOCLogInfo)));
  3641. out:
  3642. _scsih_ublock_io_device(ioc, handle);
  3643. mpt2sas_transport_port_remove(ioc, sas_device->sas_address,
  3644. sas_device->sas_address_parent);
  3645. printk(MPT2SAS_INFO_FMT "removing handle(0x%04x), sas_addr"
  3646. "(0x%016llx)\n", ioc->name, handle,
  3647. (unsigned long long) sas_device->sas_address);
  3648. _scsih_sas_device_remove(ioc, sas_device);
  3649. dewtprintk(ioc, printk(MPT2SAS_INFO_FMT "%s: exit: handle"
  3650. "(0x%04x)\n", ioc->name, __func__, handle));
  3651. }
  3652. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3653. /**
  3654. * _scsih_sas_topology_change_event_debug - debug for topology event
  3655. * @ioc: per adapter object
  3656. * @event_data: event data payload
  3657. * Context: user.
  3658. */
  3659. static void
  3660. _scsih_sas_topology_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  3661. Mpi2EventDataSasTopologyChangeList_t *event_data)
  3662. {
  3663. int i;
  3664. u16 handle;
  3665. u16 reason_code;
  3666. u8 phy_number;
  3667. char *status_str = NULL;
  3668. char link_rate[25];
  3669. switch (event_data->ExpStatus) {
  3670. case MPI2_EVENT_SAS_TOPO_ES_ADDED:
  3671. status_str = "add";
  3672. break;
  3673. case MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING:
  3674. status_str = "remove";
  3675. break;
  3676. case MPI2_EVENT_SAS_TOPO_ES_RESPONDING:
  3677. status_str = "responding";
  3678. break;
  3679. case MPI2_EVENT_SAS_TOPO_ES_DELAY_NOT_RESPONDING:
  3680. status_str = "remove delay";
  3681. break;
  3682. default:
  3683. status_str = "unknown status";
  3684. break;
  3685. }
  3686. printk(MPT2SAS_DEBUG_FMT "sas topology change: (%s)\n",
  3687. ioc->name, status_str);
  3688. printk(KERN_DEBUG "\thandle(0x%04x), enclosure_handle(0x%04x) "
  3689. "start_phy(%02d), count(%d)\n",
  3690. le16_to_cpu(event_data->ExpanderDevHandle),
  3691. le16_to_cpu(event_data->EnclosureHandle),
  3692. event_data->StartPhyNum, event_data->NumEntries);
  3693. for (i = 0; i < event_data->NumEntries; i++) {
  3694. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3695. if (!handle)
  3696. continue;
  3697. phy_number = event_data->StartPhyNum + i;
  3698. reason_code = event_data->PHY[i].PhyStatus &
  3699. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3700. switch (reason_code) {
  3701. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  3702. snprintf(link_rate, 25, ": add, link(0x%02x)",
  3703. (event_data->PHY[i].LinkRate >> 4));
  3704. status_str = link_rate;
  3705. break;
  3706. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  3707. status_str = ": remove";
  3708. break;
  3709. case MPI2_EVENT_SAS_TOPO_RC_DELAY_NOT_RESPONDING:
  3710. status_str = ": remove_delay";
  3711. break;
  3712. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  3713. snprintf(link_rate, 25, ": link(0x%02x)",
  3714. (event_data->PHY[i].LinkRate >> 4));
  3715. status_str = link_rate;
  3716. break;
  3717. case MPI2_EVENT_SAS_TOPO_RC_NO_CHANGE:
  3718. status_str = ": responding";
  3719. break;
  3720. default:
  3721. status_str = ": unknown";
  3722. break;
  3723. }
  3724. printk(KERN_DEBUG "\tphy(%02d), attached_handle(0x%04x)%s\n",
  3725. phy_number, handle, status_str);
  3726. }
  3727. }
  3728. #endif
  3729. /**
  3730. * _scsih_sas_topology_change_event - handle topology changes
  3731. * @ioc: per adapter object
  3732. * @fw_event: The fw_event_work object
  3733. * Context: user.
  3734. *
  3735. */
  3736. static void
  3737. _scsih_sas_topology_change_event(struct MPT2SAS_ADAPTER *ioc,
  3738. struct fw_event_work *fw_event)
  3739. {
  3740. int i;
  3741. u16 parent_handle, handle;
  3742. u16 reason_code;
  3743. u8 phy_number;
  3744. struct _sas_node *sas_expander;
  3745. struct _sas_device *sas_device;
  3746. u64 sas_address;
  3747. unsigned long flags;
  3748. u8 link_rate;
  3749. Mpi2EventDataSasTopologyChangeList_t *event_data = fw_event->event_data;
  3750. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3751. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  3752. _scsih_sas_topology_change_event_debug(ioc, event_data);
  3753. #endif
  3754. if (ioc->shost_recovery)
  3755. return;
  3756. if (!ioc->sas_hba.num_phys)
  3757. _scsih_sas_host_add(ioc);
  3758. else
  3759. _scsih_sas_host_refresh(ioc);
  3760. if (fw_event->ignore) {
  3761. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring expander "
  3762. "event\n", ioc->name));
  3763. return;
  3764. }
  3765. parent_handle = le16_to_cpu(event_data->ExpanderDevHandle);
  3766. /* handle expander add */
  3767. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_ADDED)
  3768. if (_scsih_expander_add(ioc, parent_handle) != 0)
  3769. return;
  3770. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  3771. sas_expander = mpt2sas_scsih_expander_find_by_handle(ioc,
  3772. parent_handle);
  3773. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  3774. if (sas_expander)
  3775. sas_address = sas_expander->sas_address;
  3776. else if (parent_handle < ioc->sas_hba.num_phys)
  3777. sas_address = ioc->sas_hba.sas_address;
  3778. else
  3779. return;
  3780. /* handle siblings events */
  3781. for (i = 0; i < event_data->NumEntries; i++) {
  3782. if (fw_event->ignore) {
  3783. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "ignoring "
  3784. "expander event\n", ioc->name));
  3785. return;
  3786. }
  3787. if (ioc->shost_recovery)
  3788. return;
  3789. phy_number = event_data->StartPhyNum + i;
  3790. reason_code = event_data->PHY[i].PhyStatus &
  3791. MPI2_EVENT_SAS_TOPO_RC_MASK;
  3792. if ((event_data->PHY[i].PhyStatus &
  3793. MPI2_EVENT_SAS_TOPO_PHYSTATUS_VACANT) && (reason_code !=
  3794. MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING))
  3795. continue;
  3796. handle = le16_to_cpu(event_data->PHY[i].AttachedDevHandle);
  3797. if (!handle)
  3798. continue;
  3799. link_rate = event_data->PHY[i].LinkRate >> 4;
  3800. switch (reason_code) {
  3801. case MPI2_EVENT_SAS_TOPO_RC_PHY_CHANGED:
  3802. case MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED:
  3803. mpt2sas_transport_update_links(ioc, sas_address,
  3804. handle, phy_number, link_rate);
  3805. if (link_rate < MPI2_SAS_NEG_LINK_RATE_1_5)
  3806. break;
  3807. if (reason_code == MPI2_EVENT_SAS_TOPO_RC_TARG_ADDED) {
  3808. _scsih_add_device(ioc, handle, phy_number, 0);
  3809. }
  3810. break;
  3811. case MPI2_EVENT_SAS_TOPO_RC_TARG_NOT_RESPONDING:
  3812. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  3813. sas_device = _scsih_sas_device_find_by_handle(ioc,
  3814. handle);
  3815. if (!sas_device) {
  3816. spin_unlock_irqrestore(&ioc->sas_device_lock,
  3817. flags);
  3818. break;
  3819. }
  3820. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  3821. _scsih_remove_device(ioc, sas_device);
  3822. break;
  3823. }
  3824. }
  3825. /* handle expander removal */
  3826. if (event_data->ExpStatus == MPI2_EVENT_SAS_TOPO_ES_NOT_RESPONDING &&
  3827. sas_expander)
  3828. _scsih_expander_remove(ioc, sas_address);
  3829. }
  3830. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3831. /**
  3832. * _scsih_sas_device_status_change_event_debug - debug for device event
  3833. * @event_data: event data payload
  3834. * Context: user.
  3835. *
  3836. * Return nothing.
  3837. */
  3838. static void
  3839. _scsih_sas_device_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  3840. Mpi2EventDataSasDeviceStatusChange_t *event_data)
  3841. {
  3842. char *reason_str = NULL;
  3843. switch (event_data->ReasonCode) {
  3844. case MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  3845. reason_str = "smart data";
  3846. break;
  3847. case MPI2_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  3848. reason_str = "unsupported device discovered";
  3849. break;
  3850. case MPI2_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  3851. reason_str = "internal device reset";
  3852. break;
  3853. case MPI2_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  3854. reason_str = "internal task abort";
  3855. break;
  3856. case MPI2_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  3857. reason_str = "internal task abort set";
  3858. break;
  3859. case MPI2_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  3860. reason_str = "internal clear task set";
  3861. break;
  3862. case MPI2_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  3863. reason_str = "internal query task";
  3864. break;
  3865. case MPI2_EVENT_SAS_DEV_STAT_RC_SATA_INIT_FAILURE:
  3866. reason_str = "sata init failure";
  3867. break;
  3868. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_INTERNAL_DEV_RESET:
  3869. reason_str = "internal device reset complete";
  3870. break;
  3871. case MPI2_EVENT_SAS_DEV_STAT_RC_CMP_TASK_ABORT_INTERNAL:
  3872. reason_str = "internal task abort complete";
  3873. break;
  3874. case MPI2_EVENT_SAS_DEV_STAT_RC_ASYNC_NOTIFICATION:
  3875. reason_str = "internal async notification";
  3876. break;
  3877. default:
  3878. reason_str = "unknown reason";
  3879. break;
  3880. }
  3881. printk(MPT2SAS_DEBUG_FMT "device status change: (%s)\n"
  3882. "\thandle(0x%04x), sas address(0x%016llx)", ioc->name,
  3883. reason_str, le16_to_cpu(event_data->DevHandle),
  3884. (unsigned long long)le64_to_cpu(event_data->SASAddress));
  3885. if (event_data->ReasonCode == MPI2_EVENT_SAS_DEV_STAT_RC_SMART_DATA)
  3886. printk(MPT2SAS_DEBUG_FMT ", ASC(0x%x), ASCQ(0x%x)\n", ioc->name,
  3887. event_data->ASC, event_data->ASCQ);
  3888. printk(KERN_INFO "\n");
  3889. }
  3890. #endif
  3891. /**
  3892. * _scsih_sas_device_status_change_event - handle device status change
  3893. * @ioc: per adapter object
  3894. * @fw_event: The fw_event_work object
  3895. * Context: user.
  3896. *
  3897. * Return nothing.
  3898. */
  3899. static void
  3900. _scsih_sas_device_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  3901. struct fw_event_work *fw_event)
  3902. {
  3903. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3904. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  3905. _scsih_sas_device_status_change_event_debug(ioc,
  3906. fw_event->event_data);
  3907. #endif
  3908. }
  3909. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3910. /**
  3911. * _scsih_sas_enclosure_dev_status_change_event_debug - debug for enclosure event
  3912. * @ioc: per adapter object
  3913. * @event_data: event data payload
  3914. * Context: user.
  3915. *
  3916. * Return nothing.
  3917. */
  3918. static void
  3919. _scsih_sas_enclosure_dev_status_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  3920. Mpi2EventDataSasEnclDevStatusChange_t *event_data)
  3921. {
  3922. char *reason_str = NULL;
  3923. switch (event_data->ReasonCode) {
  3924. case MPI2_EVENT_SAS_ENCL_RC_ADDED:
  3925. reason_str = "enclosure add";
  3926. break;
  3927. case MPI2_EVENT_SAS_ENCL_RC_NOT_RESPONDING:
  3928. reason_str = "enclosure remove";
  3929. break;
  3930. default:
  3931. reason_str = "unknown reason";
  3932. break;
  3933. }
  3934. printk(MPT2SAS_DEBUG_FMT "enclosure status change: (%s)\n"
  3935. "\thandle(0x%04x), enclosure logical id(0x%016llx)"
  3936. " number slots(%d)\n", ioc->name, reason_str,
  3937. le16_to_cpu(event_data->EnclosureHandle),
  3938. (unsigned long long)le64_to_cpu(event_data->EnclosureLogicalID),
  3939. le16_to_cpu(event_data->StartSlot));
  3940. }
  3941. #endif
  3942. /**
  3943. * _scsih_sas_enclosure_dev_status_change_event - handle enclosure events
  3944. * @ioc: per adapter object
  3945. * @fw_event: The fw_event_work object
  3946. * Context: user.
  3947. *
  3948. * Return nothing.
  3949. */
  3950. static void
  3951. _scsih_sas_enclosure_dev_status_change_event(struct MPT2SAS_ADAPTER *ioc,
  3952. struct fw_event_work *fw_event)
  3953. {
  3954. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3955. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  3956. _scsih_sas_enclosure_dev_status_change_event_debug(ioc,
  3957. fw_event->event_data);
  3958. #endif
  3959. }
  3960. /**
  3961. * _scsih_sas_broadcast_primative_event - handle broadcast events
  3962. * @ioc: per adapter object
  3963. * @fw_event: The fw_event_work object
  3964. * Context: user.
  3965. *
  3966. * Return nothing.
  3967. */
  3968. static void
  3969. _scsih_sas_broadcast_primative_event(struct MPT2SAS_ADAPTER *ioc,
  3970. struct fw_event_work *fw_event)
  3971. {
  3972. struct scsi_cmnd *scmd;
  3973. u16 smid, handle;
  3974. u32 lun;
  3975. struct MPT2SAS_DEVICE *sas_device_priv_data;
  3976. u32 termination_count;
  3977. u32 query_count;
  3978. Mpi2SCSITaskManagementReply_t *mpi_reply;
  3979. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  3980. Mpi2EventDataSasBroadcastPrimitive_t *event_data = fw_event->event_data;
  3981. #endif
  3982. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "broadcast primative: "
  3983. "phy number(%d), width(%d)\n", ioc->name, event_data->PhyNum,
  3984. event_data->PortWidth));
  3985. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: enter\n", ioc->name,
  3986. __func__));
  3987. mutex_lock(&ioc->tm_cmds.mutex);
  3988. termination_count = 0;
  3989. query_count = 0;
  3990. mpi_reply = ioc->tm_cmds.reply;
  3991. for (smid = 1; smid <= ioc->scsiio_depth; smid++) {
  3992. scmd = _scsih_scsi_lookup_get(ioc, smid);
  3993. if (!scmd)
  3994. continue;
  3995. sas_device_priv_data = scmd->device->hostdata;
  3996. if (!sas_device_priv_data || !sas_device_priv_data->sas_target)
  3997. continue;
  3998. /* skip hidden raid components */
  3999. if (sas_device_priv_data->sas_target->flags &
  4000. MPT_TARGET_FLAGS_RAID_COMPONENT)
  4001. continue;
  4002. /* skip volumes */
  4003. if (sas_device_priv_data->sas_target->flags &
  4004. MPT_TARGET_FLAGS_VOLUME)
  4005. continue;
  4006. handle = sas_device_priv_data->sas_target->handle;
  4007. lun = sas_device_priv_data->lun;
  4008. query_count++;
  4009. mpt2sas_scsih_issue_tm(ioc, handle, lun,
  4010. MPI2_SCSITASKMGMT_TASKTYPE_QUERY_TASK, smid, 30);
  4011. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  4012. if ((mpi_reply->IOCStatus == MPI2_IOCSTATUS_SUCCESS) &&
  4013. (mpi_reply->ResponseCode ==
  4014. MPI2_SCSITASKMGMT_RSP_TM_SUCCEEDED ||
  4015. mpi_reply->ResponseCode ==
  4016. MPI2_SCSITASKMGMT_RSP_IO_QUEUED_ON_IOC))
  4017. continue;
  4018. mpt2sas_scsih_issue_tm(ioc, handle, lun,
  4019. MPI2_SCSITASKMGMT_TASKTYPE_ABRT_TASK_SET, 0, 30);
  4020. ioc->tm_cmds.status = MPT2_CMD_NOT_USED;
  4021. termination_count += le32_to_cpu(mpi_reply->TerminationCount);
  4022. }
  4023. ioc->broadcast_aen_busy = 0;
  4024. mutex_unlock(&ioc->tm_cmds.mutex);
  4025. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT
  4026. "%s - exit, query_count = %d termination_count = %d\n",
  4027. ioc->name, __func__, query_count, termination_count));
  4028. }
  4029. /**
  4030. * _scsih_sas_discovery_event - handle discovery events
  4031. * @ioc: per adapter object
  4032. * @fw_event: The fw_event_work object
  4033. * Context: user.
  4034. *
  4035. * Return nothing.
  4036. */
  4037. static void
  4038. _scsih_sas_discovery_event(struct MPT2SAS_ADAPTER *ioc,
  4039. struct fw_event_work *fw_event)
  4040. {
  4041. Mpi2EventDataSasDiscovery_t *event_data = fw_event->event_data;
  4042. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4043. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK) {
  4044. printk(MPT2SAS_DEBUG_FMT "discovery event: (%s)", ioc->name,
  4045. (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED) ?
  4046. "start" : "stop");
  4047. if (event_data->DiscoveryStatus)
  4048. printk("discovery_status(0x%08x)",
  4049. le32_to_cpu(event_data->DiscoveryStatus));
  4050. printk("\n");
  4051. }
  4052. #endif
  4053. if (event_data->ReasonCode == MPI2_EVENT_SAS_DISC_RC_STARTED &&
  4054. !ioc->sas_hba.num_phys)
  4055. _scsih_sas_host_add(ioc);
  4056. }
  4057. /**
  4058. * _scsih_reprobe_lun - reprobing lun
  4059. * @sdev: scsi device struct
  4060. * @no_uld_attach: sdev->no_uld_attach flag setting
  4061. *
  4062. **/
  4063. static void
  4064. _scsih_reprobe_lun(struct scsi_device *sdev, void *no_uld_attach)
  4065. {
  4066. int rc;
  4067. sdev->no_uld_attach = no_uld_attach ? 1 : 0;
  4068. sdev_printk(KERN_INFO, sdev, "%s raid component\n",
  4069. sdev->no_uld_attach ? "hidding" : "exposing");
  4070. rc = scsi_device_reprobe(sdev);
  4071. }
  4072. /**
  4073. * _scsih_reprobe_target - reprobing target
  4074. * @starget: scsi target struct
  4075. * @no_uld_attach: sdev->no_uld_attach flag setting
  4076. *
  4077. * Note: no_uld_attach flag determines whether the disk device is attached
  4078. * to block layer. A value of `1` means to not attach.
  4079. **/
  4080. static void
  4081. _scsih_reprobe_target(struct scsi_target *starget, int no_uld_attach)
  4082. {
  4083. struct MPT2SAS_TARGET *sas_target_priv_data = starget->hostdata;
  4084. if (no_uld_attach)
  4085. sas_target_priv_data->flags |= MPT_TARGET_FLAGS_RAID_COMPONENT;
  4086. else
  4087. sas_target_priv_data->flags &= ~MPT_TARGET_FLAGS_RAID_COMPONENT;
  4088. starget_for_each_device(starget, no_uld_attach ? (void *)1 : NULL,
  4089. _scsih_reprobe_lun);
  4090. }
  4091. /**
  4092. * _scsih_sas_volume_add - add new volume
  4093. * @ioc: per adapter object
  4094. * @element: IR config element data
  4095. * Context: user.
  4096. *
  4097. * Return nothing.
  4098. */
  4099. static void
  4100. _scsih_sas_volume_add(struct MPT2SAS_ADAPTER *ioc,
  4101. Mpi2EventIrConfigElement_t *element)
  4102. {
  4103. struct _raid_device *raid_device;
  4104. unsigned long flags;
  4105. u64 wwid;
  4106. u16 handle = le16_to_cpu(element->VolDevHandle);
  4107. int rc;
  4108. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  4109. if (!wwid) {
  4110. printk(MPT2SAS_ERR_FMT
  4111. "failure at %s:%d/%s()!\n", ioc->name,
  4112. __FILE__, __LINE__, __func__);
  4113. return;
  4114. }
  4115. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4116. raid_device = _scsih_raid_device_find_by_wwid(ioc, wwid);
  4117. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4118. if (raid_device)
  4119. return;
  4120. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  4121. if (!raid_device) {
  4122. printk(MPT2SAS_ERR_FMT
  4123. "failure at %s:%d/%s()!\n", ioc->name,
  4124. __FILE__, __LINE__, __func__);
  4125. return;
  4126. }
  4127. raid_device->id = ioc->sas_id++;
  4128. raid_device->channel = RAID_CHANNEL;
  4129. raid_device->handle = handle;
  4130. raid_device->wwid = wwid;
  4131. _scsih_raid_device_add(ioc, raid_device);
  4132. if (!ioc->wait_for_port_enable_to_complete) {
  4133. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  4134. raid_device->id, 0);
  4135. if (rc)
  4136. _scsih_raid_device_remove(ioc, raid_device);
  4137. } else
  4138. _scsih_determine_boot_device(ioc, raid_device, 1);
  4139. }
  4140. /**
  4141. * _scsih_sas_volume_delete - delete volume
  4142. * @ioc: per adapter object
  4143. * @element: IR config element data
  4144. * Context: user.
  4145. *
  4146. * Return nothing.
  4147. */
  4148. static void
  4149. _scsih_sas_volume_delete(struct MPT2SAS_ADAPTER *ioc,
  4150. Mpi2EventIrConfigElement_t *element)
  4151. {
  4152. struct _raid_device *raid_device;
  4153. u16 handle = le16_to_cpu(element->VolDevHandle);
  4154. unsigned long flags;
  4155. struct MPT2SAS_TARGET *sas_target_priv_data;
  4156. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4157. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  4158. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4159. if (!raid_device)
  4160. return;
  4161. if (raid_device->starget) {
  4162. sas_target_priv_data = raid_device->starget->hostdata;
  4163. sas_target_priv_data->deleted = 1;
  4164. scsi_remove_target(&raid_device->starget->dev);
  4165. }
  4166. _scsih_raid_device_remove(ioc, raid_device);
  4167. }
  4168. /**
  4169. * _scsih_sas_pd_expose - expose pd component to /dev/sdX
  4170. * @ioc: per adapter object
  4171. * @element: IR config element data
  4172. * Context: user.
  4173. *
  4174. * Return nothing.
  4175. */
  4176. static void
  4177. _scsih_sas_pd_expose(struct MPT2SAS_ADAPTER *ioc,
  4178. Mpi2EventIrConfigElement_t *element)
  4179. {
  4180. struct _sas_device *sas_device;
  4181. unsigned long flags;
  4182. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4183. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4184. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4185. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4186. if (!sas_device)
  4187. return;
  4188. /* exposing raid component */
  4189. sas_device->volume_handle = 0;
  4190. sas_device->volume_wwid = 0;
  4191. sas_device->hidden_raid_component = 0;
  4192. _scsih_reprobe_target(sas_device->starget, 0);
  4193. }
  4194. /**
  4195. * _scsih_sas_pd_hide - hide pd component from /dev/sdX
  4196. * @ioc: per adapter object
  4197. * @element: IR config element data
  4198. * Context: user.
  4199. *
  4200. * Return nothing.
  4201. */
  4202. static void
  4203. _scsih_sas_pd_hide(struct MPT2SAS_ADAPTER *ioc,
  4204. Mpi2EventIrConfigElement_t *element)
  4205. {
  4206. struct _sas_device *sas_device;
  4207. unsigned long flags;
  4208. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4209. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4210. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4211. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4212. if (!sas_device)
  4213. return;
  4214. /* hiding raid component */
  4215. mpt2sas_config_get_volume_handle(ioc, handle,
  4216. &sas_device->volume_handle);
  4217. mpt2sas_config_get_volume_wwid(ioc, sas_device->volume_handle,
  4218. &sas_device->volume_wwid);
  4219. sas_device->hidden_raid_component = 1;
  4220. _scsih_reprobe_target(sas_device->starget, 1);
  4221. }
  4222. /**
  4223. * _scsih_sas_pd_delete - delete pd component
  4224. * @ioc: per adapter object
  4225. * @element: IR config element data
  4226. * Context: user.
  4227. *
  4228. * Return nothing.
  4229. */
  4230. static void
  4231. _scsih_sas_pd_delete(struct MPT2SAS_ADAPTER *ioc,
  4232. Mpi2EventIrConfigElement_t *element)
  4233. {
  4234. struct _sas_device *sas_device;
  4235. unsigned long flags;
  4236. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4237. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4238. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4239. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4240. if (!sas_device)
  4241. return;
  4242. _scsih_remove_device(ioc, sas_device);
  4243. }
  4244. /**
  4245. * _scsih_sas_pd_add - remove pd component
  4246. * @ioc: per adapter object
  4247. * @element: IR config element data
  4248. * Context: user.
  4249. *
  4250. * Return nothing.
  4251. */
  4252. static void
  4253. _scsih_sas_pd_add(struct MPT2SAS_ADAPTER *ioc,
  4254. Mpi2EventIrConfigElement_t *element)
  4255. {
  4256. struct _sas_device *sas_device;
  4257. unsigned long flags;
  4258. u16 handle = le16_to_cpu(element->PhysDiskDevHandle);
  4259. Mpi2ConfigReply_t mpi_reply;
  4260. Mpi2SasDevicePage0_t sas_device_pg0;
  4261. u32 ioc_status;
  4262. u64 sas_address;
  4263. u16 parent_handle;
  4264. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4265. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4266. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4267. if (sas_device) {
  4268. sas_device->hidden_raid_component = 1;
  4269. return;
  4270. }
  4271. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply, &sas_device_pg0,
  4272. MPI2_SAS_DEVICE_PGAD_FORM_HANDLE, handle))) {
  4273. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4274. ioc->name, __FILE__, __LINE__, __func__);
  4275. return;
  4276. }
  4277. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4278. MPI2_IOCSTATUS_MASK;
  4279. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4280. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4281. ioc->name, __FILE__, __LINE__, __func__);
  4282. return;
  4283. }
  4284. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  4285. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  4286. mpt2sas_transport_update_links(ioc, sas_address, handle,
  4287. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  4288. _scsih_add_device(ioc, handle, 0, 1);
  4289. }
  4290. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4291. /**
  4292. * _scsih_sas_ir_config_change_event_debug - debug for IR Config Change events
  4293. * @ioc: per adapter object
  4294. * @event_data: event data payload
  4295. * Context: user.
  4296. *
  4297. * Return nothing.
  4298. */
  4299. static void
  4300. _scsih_sas_ir_config_change_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4301. Mpi2EventDataIrConfigChangeList_t *event_data)
  4302. {
  4303. Mpi2EventIrConfigElement_t *element;
  4304. u8 element_type;
  4305. int i;
  4306. char *reason_str = NULL, *element_str = NULL;
  4307. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  4308. printk(MPT2SAS_DEBUG_FMT "raid config change: (%s), elements(%d)\n",
  4309. ioc->name, (le32_to_cpu(event_data->Flags) &
  4310. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ?
  4311. "foreign" : "native", event_data->NumElements);
  4312. for (i = 0; i < event_data->NumElements; i++, element++) {
  4313. switch (element->ReasonCode) {
  4314. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  4315. reason_str = "add";
  4316. break;
  4317. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  4318. reason_str = "remove";
  4319. break;
  4320. case MPI2_EVENT_IR_CHANGE_RC_NO_CHANGE:
  4321. reason_str = "no change";
  4322. break;
  4323. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  4324. reason_str = "hide";
  4325. break;
  4326. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  4327. reason_str = "unhide";
  4328. break;
  4329. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  4330. reason_str = "volume_created";
  4331. break;
  4332. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  4333. reason_str = "volume_deleted";
  4334. break;
  4335. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  4336. reason_str = "pd_created";
  4337. break;
  4338. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  4339. reason_str = "pd_deleted";
  4340. break;
  4341. default:
  4342. reason_str = "unknown reason";
  4343. break;
  4344. }
  4345. element_type = le16_to_cpu(element->ElementFlags) &
  4346. MPI2_EVENT_IR_CHANGE_EFLAGS_ELEMENT_TYPE_MASK;
  4347. switch (element_type) {
  4348. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLUME_ELEMENT:
  4349. element_str = "volume";
  4350. break;
  4351. case MPI2_EVENT_IR_CHANGE_EFLAGS_VOLPHYSDISK_ELEMENT:
  4352. element_str = "phys disk";
  4353. break;
  4354. case MPI2_EVENT_IR_CHANGE_EFLAGS_HOTSPARE_ELEMENT:
  4355. element_str = "hot spare";
  4356. break;
  4357. default:
  4358. element_str = "unknown element";
  4359. break;
  4360. }
  4361. printk(KERN_DEBUG "\t(%s:%s), vol handle(0x%04x), "
  4362. "pd handle(0x%04x), pd num(0x%02x)\n", element_str,
  4363. reason_str, le16_to_cpu(element->VolDevHandle),
  4364. le16_to_cpu(element->PhysDiskDevHandle),
  4365. element->PhysDiskNum);
  4366. }
  4367. }
  4368. #endif
  4369. /**
  4370. * _scsih_sas_ir_config_change_event - handle ir configuration change events
  4371. * @ioc: per adapter object
  4372. * @fw_event: The fw_event_work object
  4373. * Context: user.
  4374. *
  4375. * Return nothing.
  4376. */
  4377. static void
  4378. _scsih_sas_ir_config_change_event(struct MPT2SAS_ADAPTER *ioc,
  4379. struct fw_event_work *fw_event)
  4380. {
  4381. Mpi2EventIrConfigElement_t *element;
  4382. int i;
  4383. u8 foreign_config;
  4384. Mpi2EventDataIrConfigChangeList_t *event_data = fw_event->event_data;
  4385. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4386. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4387. _scsih_sas_ir_config_change_event_debug(ioc, event_data);
  4388. #endif
  4389. foreign_config = (le32_to_cpu(event_data->Flags) &
  4390. MPI2_EVENT_IR_CHANGE_FLAGS_FOREIGN_CONFIG) ? 1 : 0;
  4391. element = (Mpi2EventIrConfigElement_t *)&event_data->ConfigElement[0];
  4392. for (i = 0; i < event_data->NumElements; i++, element++) {
  4393. switch (element->ReasonCode) {
  4394. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_CREATED:
  4395. case MPI2_EVENT_IR_CHANGE_RC_ADDED:
  4396. if (!foreign_config)
  4397. _scsih_sas_volume_add(ioc, element);
  4398. break;
  4399. case MPI2_EVENT_IR_CHANGE_RC_VOLUME_DELETED:
  4400. case MPI2_EVENT_IR_CHANGE_RC_REMOVED:
  4401. if (!foreign_config)
  4402. _scsih_sas_volume_delete(ioc, element);
  4403. break;
  4404. case MPI2_EVENT_IR_CHANGE_RC_PD_CREATED:
  4405. _scsih_sas_pd_hide(ioc, element);
  4406. break;
  4407. case MPI2_EVENT_IR_CHANGE_RC_PD_DELETED:
  4408. _scsih_sas_pd_expose(ioc, element);
  4409. break;
  4410. case MPI2_EVENT_IR_CHANGE_RC_HIDE:
  4411. _scsih_sas_pd_add(ioc, element);
  4412. break;
  4413. case MPI2_EVENT_IR_CHANGE_RC_UNHIDE:
  4414. _scsih_sas_pd_delete(ioc, element);
  4415. break;
  4416. }
  4417. }
  4418. }
  4419. /**
  4420. * _scsih_sas_ir_volume_event - IR volume event
  4421. * @ioc: per adapter object
  4422. * @fw_event: The fw_event_work object
  4423. * Context: user.
  4424. *
  4425. * Return nothing.
  4426. */
  4427. static void
  4428. _scsih_sas_ir_volume_event(struct MPT2SAS_ADAPTER *ioc,
  4429. struct fw_event_work *fw_event)
  4430. {
  4431. u64 wwid;
  4432. unsigned long flags;
  4433. struct _raid_device *raid_device;
  4434. u16 handle;
  4435. u32 state;
  4436. int rc;
  4437. struct MPT2SAS_TARGET *sas_target_priv_data;
  4438. Mpi2EventDataIrVolume_t *event_data = fw_event->event_data;
  4439. if (event_data->ReasonCode != MPI2_EVENT_IR_VOLUME_RC_STATE_CHANGED)
  4440. return;
  4441. handle = le16_to_cpu(event_data->VolDevHandle);
  4442. state = le32_to_cpu(event_data->NewValue);
  4443. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
  4444. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  4445. le32_to_cpu(event_data->PreviousValue), state));
  4446. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4447. raid_device = _scsih_raid_device_find_by_handle(ioc, handle);
  4448. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4449. switch (state) {
  4450. case MPI2_RAID_VOL_STATE_MISSING:
  4451. case MPI2_RAID_VOL_STATE_FAILED:
  4452. if (!raid_device)
  4453. break;
  4454. if (raid_device->starget) {
  4455. sas_target_priv_data = raid_device->starget->hostdata;
  4456. sas_target_priv_data->deleted = 1;
  4457. scsi_remove_target(&raid_device->starget->dev);
  4458. }
  4459. _scsih_raid_device_remove(ioc, raid_device);
  4460. break;
  4461. case MPI2_RAID_VOL_STATE_ONLINE:
  4462. case MPI2_RAID_VOL_STATE_DEGRADED:
  4463. case MPI2_RAID_VOL_STATE_OPTIMAL:
  4464. if (raid_device)
  4465. break;
  4466. mpt2sas_config_get_volume_wwid(ioc, handle, &wwid);
  4467. if (!wwid) {
  4468. printk(MPT2SAS_ERR_FMT
  4469. "failure at %s:%d/%s()!\n", ioc->name,
  4470. __FILE__, __LINE__, __func__);
  4471. break;
  4472. }
  4473. raid_device = kzalloc(sizeof(struct _raid_device), GFP_KERNEL);
  4474. if (!raid_device) {
  4475. printk(MPT2SAS_ERR_FMT
  4476. "failure at %s:%d/%s()!\n", ioc->name,
  4477. __FILE__, __LINE__, __func__);
  4478. break;
  4479. }
  4480. raid_device->id = ioc->sas_id++;
  4481. raid_device->channel = RAID_CHANNEL;
  4482. raid_device->handle = handle;
  4483. raid_device->wwid = wwid;
  4484. _scsih_raid_device_add(ioc, raid_device);
  4485. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  4486. raid_device->id, 0);
  4487. if (rc)
  4488. _scsih_raid_device_remove(ioc, raid_device);
  4489. break;
  4490. case MPI2_RAID_VOL_STATE_INITIALIZING:
  4491. default:
  4492. break;
  4493. }
  4494. }
  4495. /**
  4496. * _scsih_sas_ir_physical_disk_event - PD event
  4497. * @ioc: per adapter object
  4498. * @fw_event: The fw_event_work object
  4499. * Context: user.
  4500. *
  4501. * Return nothing.
  4502. */
  4503. static void
  4504. _scsih_sas_ir_physical_disk_event(struct MPT2SAS_ADAPTER *ioc,
  4505. struct fw_event_work *fw_event)
  4506. {
  4507. u16 handle, parent_handle;
  4508. u32 state;
  4509. struct _sas_device *sas_device;
  4510. unsigned long flags;
  4511. Mpi2ConfigReply_t mpi_reply;
  4512. Mpi2SasDevicePage0_t sas_device_pg0;
  4513. u32 ioc_status;
  4514. Mpi2EventDataIrPhysicalDisk_t *event_data = fw_event->event_data;
  4515. u64 sas_address;
  4516. if (event_data->ReasonCode != MPI2_EVENT_IR_PHYSDISK_RC_STATE_CHANGED)
  4517. return;
  4518. handle = le16_to_cpu(event_data->PhysDiskDevHandle);
  4519. state = le32_to_cpu(event_data->NewValue);
  4520. dewtprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: handle(0x%04x), "
  4521. "old(0x%08x), new(0x%08x)\n", ioc->name, __func__, handle,
  4522. le32_to_cpu(event_data->PreviousValue), state));
  4523. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4524. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4525. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4526. switch (state) {
  4527. case MPI2_RAID_PD_STATE_ONLINE:
  4528. case MPI2_RAID_PD_STATE_DEGRADED:
  4529. case MPI2_RAID_PD_STATE_REBUILDING:
  4530. case MPI2_RAID_PD_STATE_OPTIMAL:
  4531. if (sas_device) {
  4532. sas_device->hidden_raid_component = 1;
  4533. return;
  4534. }
  4535. if ((mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  4536. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_HANDLE,
  4537. handle))) {
  4538. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4539. ioc->name, __FILE__, __LINE__, __func__);
  4540. return;
  4541. }
  4542. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4543. MPI2_IOCSTATUS_MASK;
  4544. if (ioc_status != MPI2_IOCSTATUS_SUCCESS) {
  4545. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  4546. ioc->name, __FILE__, __LINE__, __func__);
  4547. return;
  4548. }
  4549. parent_handle = le16_to_cpu(sas_device_pg0.ParentDevHandle);
  4550. if (!_scsih_get_sas_address(ioc, parent_handle, &sas_address))
  4551. mpt2sas_transport_update_links(ioc, sas_address, handle,
  4552. sas_device_pg0.PhyNum, MPI2_SAS_NEG_LINK_RATE_1_5);
  4553. _scsih_add_device(ioc, handle, 0, 1);
  4554. break;
  4555. case MPI2_RAID_PD_STATE_OFFLINE:
  4556. case MPI2_RAID_PD_STATE_NOT_CONFIGURED:
  4557. case MPI2_RAID_PD_STATE_NOT_COMPATIBLE:
  4558. case MPI2_RAID_PD_STATE_HOT_SPARE:
  4559. default:
  4560. break;
  4561. }
  4562. }
  4563. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4564. /**
  4565. * _scsih_sas_ir_operation_status_event_debug - debug for IR op event
  4566. * @ioc: per adapter object
  4567. * @event_data: event data payload
  4568. * Context: user.
  4569. *
  4570. * Return nothing.
  4571. */
  4572. static void
  4573. _scsih_sas_ir_operation_status_event_debug(struct MPT2SAS_ADAPTER *ioc,
  4574. Mpi2EventDataIrOperationStatus_t *event_data)
  4575. {
  4576. char *reason_str = NULL;
  4577. switch (event_data->RAIDOperation) {
  4578. case MPI2_EVENT_IR_RAIDOP_RESYNC:
  4579. reason_str = "resync";
  4580. break;
  4581. case MPI2_EVENT_IR_RAIDOP_ONLINE_CAP_EXPANSION:
  4582. reason_str = "online capacity expansion";
  4583. break;
  4584. case MPI2_EVENT_IR_RAIDOP_CONSISTENCY_CHECK:
  4585. reason_str = "consistency check";
  4586. break;
  4587. default:
  4588. reason_str = "unknown reason";
  4589. break;
  4590. }
  4591. printk(MPT2SAS_INFO_FMT "raid operational status: (%s)"
  4592. "\thandle(0x%04x), percent complete(%d)\n",
  4593. ioc->name, reason_str,
  4594. le16_to_cpu(event_data->VolDevHandle),
  4595. event_data->PercentComplete);
  4596. }
  4597. #endif
  4598. /**
  4599. * _scsih_sas_ir_operation_status_event - handle RAID operation events
  4600. * @ioc: per adapter object
  4601. * @fw_event: The fw_event_work object
  4602. * Context: user.
  4603. *
  4604. * Return nothing.
  4605. */
  4606. static void
  4607. _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
  4608. struct fw_event_work *fw_event)
  4609. {
  4610. #ifdef CONFIG_SCSI_MPT2SAS_LOGGING
  4611. if (ioc->logging_level & MPT_DEBUG_EVENT_WORK_TASK)
  4612. _scsih_sas_ir_operation_status_event_debug(ioc,
  4613. fw_event->event_data);
  4614. #endif
  4615. }
  4616. /**
  4617. * _scsih_task_set_full - handle task set full
  4618. * @ioc: per adapter object
  4619. * @fw_event: The fw_event_work object
  4620. * Context: user.
  4621. *
  4622. * Throttle back qdepth.
  4623. */
  4624. static void
  4625. _scsih_task_set_full(struct MPT2SAS_ADAPTER *ioc, struct fw_event_work
  4626. *fw_event)
  4627. {
  4628. unsigned long flags;
  4629. struct _sas_device *sas_device;
  4630. static struct _raid_device *raid_device;
  4631. struct scsi_device *sdev;
  4632. int depth;
  4633. u16 current_depth;
  4634. u16 handle;
  4635. int id, channel;
  4636. u64 sas_address;
  4637. Mpi2EventDataTaskSetFull_t *event_data = fw_event->event_data;
  4638. current_depth = le16_to_cpu(event_data->CurrentDepth);
  4639. handle = le16_to_cpu(event_data->DevHandle);
  4640. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4641. sas_device = _scsih_sas_device_find_by_handle(ioc, handle);
  4642. if (!sas_device) {
  4643. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4644. return;
  4645. }
  4646. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4647. id = sas_device->id;
  4648. channel = sas_device->channel;
  4649. sas_address = sas_device->sas_address;
  4650. /* if hidden raid component, then change to volume characteristics */
  4651. if (sas_device->hidden_raid_component && sas_device->volume_handle) {
  4652. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4653. raid_device = _scsih_raid_device_find_by_handle(
  4654. ioc, sas_device->volume_handle);
  4655. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4656. if (raid_device) {
  4657. id = raid_device->id;
  4658. channel = raid_device->channel;
  4659. handle = raid_device->handle;
  4660. sas_address = raid_device->wwid;
  4661. }
  4662. }
  4663. if (ioc->logging_level & MPT_DEBUG_TASK_SET_FULL)
  4664. starget_printk(KERN_DEBUG, sas_device->starget, "task set "
  4665. "full: handle(0x%04x), sas_addr(0x%016llx), depth(%d)\n",
  4666. handle, (unsigned long long)sas_address, current_depth);
  4667. shost_for_each_device(sdev, ioc->shost) {
  4668. if (sdev->id == id && sdev->channel == channel) {
  4669. if (current_depth > sdev->queue_depth) {
  4670. if (ioc->logging_level &
  4671. MPT_DEBUG_TASK_SET_FULL)
  4672. sdev_printk(KERN_INFO, sdev, "strange "
  4673. "observation, the queue depth is"
  4674. " (%d) meanwhile fw queue depth "
  4675. "is (%d)\n", sdev->queue_depth,
  4676. current_depth);
  4677. continue;
  4678. }
  4679. depth = scsi_track_queue_full(sdev,
  4680. current_depth - 1);
  4681. if (depth > 0)
  4682. sdev_printk(KERN_INFO, sdev, "Queue depth "
  4683. "reduced to (%d)\n", depth);
  4684. else if (depth < 0)
  4685. sdev_printk(KERN_INFO, sdev, "Tagged Command "
  4686. "Queueing is being disabled\n");
  4687. else if (depth == 0)
  4688. if (ioc->logging_level &
  4689. MPT_DEBUG_TASK_SET_FULL)
  4690. sdev_printk(KERN_INFO, sdev,
  4691. "Queue depth not changed yet\n");
  4692. }
  4693. }
  4694. }
  4695. /**
  4696. * _scsih_mark_responding_sas_device - mark a sas_devices as responding
  4697. * @ioc: per adapter object
  4698. * @sas_address: sas address
  4699. * @slot: enclosure slot id
  4700. * @handle: device handle
  4701. *
  4702. * After host reset, find out whether devices are still responding.
  4703. * Used in _scsi_remove_unresponsive_sas_devices.
  4704. *
  4705. * Return nothing.
  4706. */
  4707. static void
  4708. _scsih_mark_responding_sas_device(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  4709. u16 slot, u16 handle)
  4710. {
  4711. struct MPT2SAS_TARGET *sas_target_priv_data;
  4712. struct scsi_target *starget;
  4713. struct _sas_device *sas_device;
  4714. unsigned long flags;
  4715. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  4716. list_for_each_entry(sas_device, &ioc->sas_device_list, list) {
  4717. if (sas_device->sas_address == sas_address &&
  4718. sas_device->slot == slot && sas_device->starget) {
  4719. sas_device->responding = 1;
  4720. sas_device->state = 0;
  4721. starget = sas_device->starget;
  4722. sas_target_priv_data = starget->hostdata;
  4723. sas_target_priv_data->tm_busy = 0;
  4724. starget_printk(KERN_INFO, sas_device->starget,
  4725. "handle(0x%04x), sas_addr(0x%016llx), enclosure "
  4726. "logical id(0x%016llx), slot(%d)\n", handle,
  4727. (unsigned long long)sas_device->sas_address,
  4728. (unsigned long long)
  4729. sas_device->enclosure_logical_id,
  4730. sas_device->slot);
  4731. if (sas_device->handle == handle)
  4732. goto out;
  4733. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  4734. sas_device->handle);
  4735. sas_device->handle = handle;
  4736. sas_target_priv_data->handle = handle;
  4737. goto out;
  4738. }
  4739. }
  4740. out:
  4741. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  4742. }
  4743. /**
  4744. * _scsih_search_responding_sas_devices -
  4745. * @ioc: per adapter object
  4746. *
  4747. * After host reset, find out whether devices are still responding.
  4748. * If not remove.
  4749. *
  4750. * Return nothing.
  4751. */
  4752. static void
  4753. _scsih_search_responding_sas_devices(struct MPT2SAS_ADAPTER *ioc)
  4754. {
  4755. Mpi2SasDevicePage0_t sas_device_pg0;
  4756. Mpi2ConfigReply_t mpi_reply;
  4757. u16 ioc_status;
  4758. __le64 sas_address;
  4759. u16 handle;
  4760. u32 device_info;
  4761. u16 slot;
  4762. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  4763. if (list_empty(&ioc->sas_device_list))
  4764. return;
  4765. handle = 0xFFFF;
  4766. while (!(mpt2sas_config_get_sas_device_pg0(ioc, &mpi_reply,
  4767. &sas_device_pg0, MPI2_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE,
  4768. handle))) {
  4769. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4770. MPI2_IOCSTATUS_MASK;
  4771. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  4772. break;
  4773. handle = le16_to_cpu(sas_device_pg0.DevHandle);
  4774. device_info = le32_to_cpu(sas_device_pg0.DeviceInfo);
  4775. if (!(_scsih_is_end_device(device_info)))
  4776. continue;
  4777. sas_address = le64_to_cpu(sas_device_pg0.SASAddress);
  4778. slot = le16_to_cpu(sas_device_pg0.Slot);
  4779. _scsih_mark_responding_sas_device(ioc, sas_address, slot,
  4780. handle);
  4781. }
  4782. }
  4783. /**
  4784. * _scsih_mark_responding_raid_device - mark a raid_device as responding
  4785. * @ioc: per adapter object
  4786. * @wwid: world wide identifier for raid volume
  4787. * @handle: device handle
  4788. *
  4789. * After host reset, find out whether devices are still responding.
  4790. * Used in _scsi_remove_unresponsive_raid_devices.
  4791. *
  4792. * Return nothing.
  4793. */
  4794. static void
  4795. _scsih_mark_responding_raid_device(struct MPT2SAS_ADAPTER *ioc, u64 wwid,
  4796. u16 handle)
  4797. {
  4798. struct MPT2SAS_TARGET *sas_target_priv_data;
  4799. struct scsi_target *starget;
  4800. struct _raid_device *raid_device;
  4801. unsigned long flags;
  4802. spin_lock_irqsave(&ioc->raid_device_lock, flags);
  4803. list_for_each_entry(raid_device, &ioc->raid_device_list, list) {
  4804. if (raid_device->wwid == wwid && raid_device->starget) {
  4805. raid_device->responding = 1;
  4806. starget_printk(KERN_INFO, raid_device->starget,
  4807. "handle(0x%04x), wwid(0x%016llx)\n", handle,
  4808. (unsigned long long)raid_device->wwid);
  4809. if (raid_device->handle == handle)
  4810. goto out;
  4811. printk(KERN_INFO "\thandle changed from(0x%04x)!!!\n",
  4812. raid_device->handle);
  4813. raid_device->handle = handle;
  4814. starget = raid_device->starget;
  4815. sas_target_priv_data = starget->hostdata;
  4816. sas_target_priv_data->handle = handle;
  4817. goto out;
  4818. }
  4819. }
  4820. out:
  4821. spin_unlock_irqrestore(&ioc->raid_device_lock, flags);
  4822. }
  4823. /**
  4824. * _scsih_search_responding_raid_devices -
  4825. * @ioc: per adapter object
  4826. *
  4827. * After host reset, find out whether devices are still responding.
  4828. * If not remove.
  4829. *
  4830. * Return nothing.
  4831. */
  4832. static void
  4833. _scsih_search_responding_raid_devices(struct MPT2SAS_ADAPTER *ioc)
  4834. {
  4835. Mpi2RaidVolPage1_t volume_pg1;
  4836. Mpi2ConfigReply_t mpi_reply;
  4837. u16 ioc_status;
  4838. u16 handle;
  4839. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  4840. if (list_empty(&ioc->raid_device_list))
  4841. return;
  4842. handle = 0xFFFF;
  4843. while (!(mpt2sas_config_get_raid_volume_pg1(ioc, &mpi_reply,
  4844. &volume_pg1, MPI2_RAID_VOLUME_PGAD_FORM_GET_NEXT_HANDLE, handle))) {
  4845. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4846. MPI2_IOCSTATUS_MASK;
  4847. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  4848. break;
  4849. handle = le16_to_cpu(volume_pg1.DevHandle);
  4850. _scsih_mark_responding_raid_device(ioc,
  4851. le64_to_cpu(volume_pg1.WWID), handle);
  4852. }
  4853. }
  4854. /**
  4855. * _scsih_mark_responding_expander - mark a expander as responding
  4856. * @ioc: per adapter object
  4857. * @sas_address: sas address
  4858. * @handle:
  4859. *
  4860. * After host reset, find out whether devices are still responding.
  4861. * Used in _scsi_remove_unresponsive_expanders.
  4862. *
  4863. * Return nothing.
  4864. */
  4865. static void
  4866. _scsih_mark_responding_expander(struct MPT2SAS_ADAPTER *ioc, u64 sas_address,
  4867. u16 handle)
  4868. {
  4869. struct _sas_node *sas_expander;
  4870. unsigned long flags;
  4871. int i;
  4872. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  4873. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  4874. if (sas_expander->sas_address != sas_address)
  4875. continue;
  4876. sas_expander->responding = 1;
  4877. if (sas_expander->handle == handle)
  4878. goto out;
  4879. printk(KERN_INFO "\texpander(0x%016llx): handle changed"
  4880. " from(0x%04x) to (0x%04x)!!!\n",
  4881. (unsigned long long)sas_expander->sas_address,
  4882. sas_expander->handle, handle);
  4883. sas_expander->handle = handle;
  4884. for (i = 0 ; i < sas_expander->num_phys ; i++)
  4885. sas_expander->phy[i].handle = handle;
  4886. goto out;
  4887. }
  4888. out:
  4889. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  4890. }
  4891. /**
  4892. * _scsih_search_responding_expanders -
  4893. * @ioc: per adapter object
  4894. *
  4895. * After host reset, find out whether devices are still responding.
  4896. * If not remove.
  4897. *
  4898. * Return nothing.
  4899. */
  4900. static void
  4901. _scsih_search_responding_expanders(struct MPT2SAS_ADAPTER *ioc)
  4902. {
  4903. Mpi2ExpanderPage0_t expander_pg0;
  4904. Mpi2ConfigReply_t mpi_reply;
  4905. u16 ioc_status;
  4906. __le64 sas_address;
  4907. u16 handle;
  4908. printk(MPT2SAS_INFO_FMT "%s\n", ioc->name, __func__);
  4909. if (list_empty(&ioc->sas_expander_list))
  4910. return;
  4911. handle = 0xFFFF;
  4912. while (!(mpt2sas_config_get_expander_pg0(ioc, &mpi_reply, &expander_pg0,
  4913. MPI2_SAS_EXPAND_PGAD_FORM_GET_NEXT_HNDL, handle))) {
  4914. ioc_status = le16_to_cpu(mpi_reply.IOCStatus) &
  4915. MPI2_IOCSTATUS_MASK;
  4916. if (ioc_status == MPI2_IOCSTATUS_CONFIG_INVALID_PAGE)
  4917. break;
  4918. handle = le16_to_cpu(expander_pg0.DevHandle);
  4919. sas_address = le64_to_cpu(expander_pg0.SASAddress);
  4920. printk(KERN_INFO "\texpander present: handle(0x%04x), "
  4921. "sas_addr(0x%016llx)\n", handle,
  4922. (unsigned long long)sas_address);
  4923. _scsih_mark_responding_expander(ioc, sas_address, handle);
  4924. }
  4925. }
  4926. /**
  4927. * _scsih_remove_unresponding_devices - removing unresponding devices
  4928. * @ioc: per adapter object
  4929. *
  4930. * Return nothing.
  4931. */
  4932. static void
  4933. _scsih_remove_unresponding_devices(struct MPT2SAS_ADAPTER *ioc)
  4934. {
  4935. struct _sas_device *sas_device, *sas_device_next;
  4936. struct _sas_node *sas_expander;
  4937. struct _raid_device *raid_device, *raid_device_next;
  4938. list_for_each_entry_safe(sas_device, sas_device_next,
  4939. &ioc->sas_device_list, list) {
  4940. if (sas_device->responding) {
  4941. sas_device->responding = 0;
  4942. continue;
  4943. }
  4944. if (sas_device->starget)
  4945. starget_printk(KERN_INFO, sas_device->starget,
  4946. "removing: handle(0x%04x), sas_addr(0x%016llx), "
  4947. "enclosure logical id(0x%016llx), slot(%d)\n",
  4948. sas_device->handle,
  4949. (unsigned long long)sas_device->sas_address,
  4950. (unsigned long long)
  4951. sas_device->enclosure_logical_id,
  4952. sas_device->slot);
  4953. /* invalidate the device handle */
  4954. sas_device->handle = 0;
  4955. _scsih_remove_device(ioc, sas_device);
  4956. }
  4957. list_for_each_entry_safe(raid_device, raid_device_next,
  4958. &ioc->raid_device_list, list) {
  4959. if (raid_device->responding) {
  4960. raid_device->responding = 0;
  4961. continue;
  4962. }
  4963. if (raid_device->starget) {
  4964. starget_printk(KERN_INFO, raid_device->starget,
  4965. "removing: handle(0x%04x), wwid(0x%016llx)\n",
  4966. raid_device->handle,
  4967. (unsigned long long)raid_device->wwid);
  4968. scsi_remove_target(&raid_device->starget->dev);
  4969. }
  4970. _scsih_raid_device_remove(ioc, raid_device);
  4971. }
  4972. retry_expander_search:
  4973. sas_expander = NULL;
  4974. list_for_each_entry(sas_expander, &ioc->sas_expander_list, list) {
  4975. if (sas_expander->responding) {
  4976. sas_expander->responding = 0;
  4977. continue;
  4978. }
  4979. _scsih_expander_remove(ioc, sas_expander->sas_address);
  4980. goto retry_expander_search;
  4981. }
  4982. }
  4983. /**
  4984. * mpt2sas_scsih_reset_handler - reset callback handler (for scsih)
  4985. * @ioc: per adapter object
  4986. * @reset_phase: phase
  4987. *
  4988. * The handler for doing any required cleanup or initialization.
  4989. *
  4990. * The reset phase can be MPT2_IOC_PRE_RESET, MPT2_IOC_AFTER_RESET,
  4991. * MPT2_IOC_DONE_RESET
  4992. *
  4993. * Return nothing.
  4994. */
  4995. void
  4996. mpt2sas_scsih_reset_handler(struct MPT2SAS_ADAPTER *ioc, int reset_phase)
  4997. {
  4998. switch (reset_phase) {
  4999. case MPT2_IOC_PRE_RESET:
  5000. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  5001. "MPT2_IOC_PRE_RESET\n", ioc->name, __func__));
  5002. _scsih_fw_event_off(ioc);
  5003. break;
  5004. case MPT2_IOC_AFTER_RESET:
  5005. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  5006. "MPT2_IOC_AFTER_RESET\n", ioc->name, __func__));
  5007. if (ioc->tm_cmds.status & MPT2_CMD_PENDING) {
  5008. ioc->tm_cmds.status |= MPT2_CMD_RESET;
  5009. mpt2sas_base_free_smid(ioc, ioc->tm_cmds.smid);
  5010. complete(&ioc->tm_cmds.done);
  5011. }
  5012. _scsih_fw_event_on(ioc);
  5013. _scsih_flush_running_cmds(ioc);
  5014. break;
  5015. case MPT2_IOC_DONE_RESET:
  5016. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  5017. "MPT2_IOC_DONE_RESET\n", ioc->name, __func__));
  5018. _scsih_sas_host_refresh(ioc);
  5019. _scsih_search_responding_sas_devices(ioc);
  5020. _scsih_search_responding_raid_devices(ioc);
  5021. _scsih_search_responding_expanders(ioc);
  5022. break;
  5023. case MPT2_IOC_RUNNING:
  5024. dtmprintk(ioc, printk(MPT2SAS_DEBUG_FMT "%s: "
  5025. "MPT2_IOC_RUNNING\n", ioc->name, __func__));
  5026. _scsih_remove_unresponding_devices(ioc);
  5027. break;
  5028. }
  5029. }
  5030. /**
  5031. * _firmware_event_work - delayed task for processing firmware events
  5032. * @ioc: per adapter object
  5033. * @work: equal to the fw_event_work object
  5034. * Context: user.
  5035. *
  5036. * Return nothing.
  5037. */
  5038. static void
  5039. _firmware_event_work(struct work_struct *work)
  5040. {
  5041. struct fw_event_work *fw_event = container_of(work,
  5042. struct fw_event_work, work);
  5043. unsigned long flags;
  5044. struct MPT2SAS_ADAPTER *ioc = fw_event->ioc;
  5045. /* the queue is being flushed so ignore this event */
  5046. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5047. if (ioc->fw_events_off || ioc->remove_host) {
  5048. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5049. _scsih_fw_event_free(ioc, fw_event);
  5050. return;
  5051. }
  5052. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5053. if (ioc->shost_recovery) {
  5054. _scsih_fw_event_requeue(ioc, fw_event, 1000);
  5055. return;
  5056. }
  5057. switch (fw_event->event) {
  5058. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  5059. _scsih_sas_topology_change_event(ioc, fw_event);
  5060. break;
  5061. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5062. _scsih_sas_device_status_change_event(ioc,
  5063. fw_event);
  5064. break;
  5065. case MPI2_EVENT_SAS_DISCOVERY:
  5066. _scsih_sas_discovery_event(ioc,
  5067. fw_event);
  5068. break;
  5069. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  5070. _scsih_sas_broadcast_primative_event(ioc,
  5071. fw_event);
  5072. break;
  5073. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  5074. _scsih_sas_enclosure_dev_status_change_event(ioc,
  5075. fw_event);
  5076. break;
  5077. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  5078. _scsih_sas_ir_config_change_event(ioc, fw_event);
  5079. break;
  5080. case MPI2_EVENT_IR_VOLUME:
  5081. _scsih_sas_ir_volume_event(ioc, fw_event);
  5082. break;
  5083. case MPI2_EVENT_IR_PHYSICAL_DISK:
  5084. _scsih_sas_ir_physical_disk_event(ioc, fw_event);
  5085. break;
  5086. case MPI2_EVENT_IR_OPERATION_STATUS:
  5087. _scsih_sas_ir_operation_status_event(ioc, fw_event);
  5088. break;
  5089. case MPI2_EVENT_TASK_SET_FULL:
  5090. _scsih_task_set_full(ioc, fw_event);
  5091. break;
  5092. }
  5093. _scsih_fw_event_free(ioc, fw_event);
  5094. }
  5095. /**
  5096. * mpt2sas_scsih_event_callback - firmware event handler (called at ISR time)
  5097. * @ioc: per adapter object
  5098. * @msix_index: MSIX table index supplied by the OS
  5099. * @reply: reply message frame(lower 32bit addr)
  5100. * Context: interrupt.
  5101. *
  5102. * This function merely adds a new work task into ioc->firmware_event_thread.
  5103. * The tasks are worked from _firmware_event_work in user context.
  5104. *
  5105. * Return 1 meaning mf should be freed from _base_interrupt
  5106. * 0 means the mf is freed from this function.
  5107. */
  5108. u8
  5109. mpt2sas_scsih_event_callback(struct MPT2SAS_ADAPTER *ioc, u8 msix_index,
  5110. u32 reply)
  5111. {
  5112. struct fw_event_work *fw_event;
  5113. Mpi2EventNotificationReply_t *mpi_reply;
  5114. unsigned long flags;
  5115. u16 event;
  5116. /* events turned off due to host reset or driver unloading */
  5117. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5118. if (ioc->fw_events_off || ioc->remove_host) {
  5119. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5120. return 1;
  5121. }
  5122. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5123. mpi_reply = mpt2sas_base_get_reply_virt_addr(ioc, reply);
  5124. event = le16_to_cpu(mpi_reply->Event);
  5125. switch (event) {
  5126. /* handle these */
  5127. case MPI2_EVENT_SAS_BROADCAST_PRIMITIVE:
  5128. {
  5129. Mpi2EventDataSasBroadcastPrimitive_t *baen_data =
  5130. (Mpi2EventDataSasBroadcastPrimitive_t *)
  5131. mpi_reply->EventData;
  5132. if (baen_data->Primitive !=
  5133. MPI2_EVENT_PRIMITIVE_ASYNCHRONOUS_EVENT ||
  5134. ioc->broadcast_aen_busy)
  5135. return 1;
  5136. ioc->broadcast_aen_busy = 1;
  5137. break;
  5138. }
  5139. case MPI2_EVENT_SAS_TOPOLOGY_CHANGE_LIST:
  5140. _scsih_check_topo_delete_events(ioc,
  5141. (Mpi2EventDataSasTopologyChangeList_t *)
  5142. mpi_reply->EventData);
  5143. break;
  5144. case MPI2_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5145. case MPI2_EVENT_IR_OPERATION_STATUS:
  5146. case MPI2_EVENT_SAS_DISCOVERY:
  5147. case MPI2_EVENT_SAS_ENCL_DEVICE_STATUS_CHANGE:
  5148. case MPI2_EVENT_IR_VOLUME:
  5149. case MPI2_EVENT_IR_PHYSICAL_DISK:
  5150. case MPI2_EVENT_IR_CONFIGURATION_CHANGE_LIST:
  5151. case MPI2_EVENT_TASK_SET_FULL:
  5152. break;
  5153. default: /* ignore the rest */
  5154. return 1;
  5155. }
  5156. fw_event = kzalloc(sizeof(struct fw_event_work), GFP_ATOMIC);
  5157. if (!fw_event) {
  5158. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5159. ioc->name, __FILE__, __LINE__, __func__);
  5160. return 1;
  5161. }
  5162. fw_event->event_data =
  5163. kzalloc(mpi_reply->EventDataLength*4, GFP_ATOMIC);
  5164. if (!fw_event->event_data) {
  5165. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5166. ioc->name, __FILE__, __LINE__, __func__);
  5167. kfree(fw_event);
  5168. return 1;
  5169. }
  5170. memcpy(fw_event->event_data, mpi_reply->EventData,
  5171. mpi_reply->EventDataLength*4);
  5172. fw_event->ioc = ioc;
  5173. fw_event->VF_ID = mpi_reply->VF_ID;
  5174. fw_event->VP_ID = mpi_reply->VP_ID;
  5175. fw_event->event = event;
  5176. _scsih_fw_event_add(ioc, fw_event);
  5177. return 1;
  5178. }
  5179. /* shost template */
  5180. static struct scsi_host_template scsih_driver_template = {
  5181. .module = THIS_MODULE,
  5182. .name = "Fusion MPT SAS Host",
  5183. .proc_name = MPT2SAS_DRIVER_NAME,
  5184. .queuecommand = _scsih_qcmd,
  5185. .target_alloc = _scsih_target_alloc,
  5186. .slave_alloc = _scsih_slave_alloc,
  5187. .slave_configure = _scsih_slave_configure,
  5188. .target_destroy = _scsih_target_destroy,
  5189. .slave_destroy = _scsih_slave_destroy,
  5190. .change_queue_depth = _scsih_change_queue_depth,
  5191. .change_queue_type = _scsih_change_queue_type,
  5192. .eh_abort_handler = _scsih_abort,
  5193. .eh_device_reset_handler = _scsih_dev_reset,
  5194. .eh_target_reset_handler = _scsih_target_reset,
  5195. .eh_host_reset_handler = _scsih_host_reset,
  5196. .bios_param = _scsih_bios_param,
  5197. .can_queue = 1,
  5198. .this_id = -1,
  5199. .sg_tablesize = MPT2SAS_SG_DEPTH,
  5200. .max_sectors = 8192,
  5201. .cmd_per_lun = 7,
  5202. .use_clustering = ENABLE_CLUSTERING,
  5203. .shost_attrs = mpt2sas_host_attrs,
  5204. .sdev_attrs = mpt2sas_dev_attrs,
  5205. };
  5206. /**
  5207. * _scsih_expander_node_remove - removing expander device from list.
  5208. * @ioc: per adapter object
  5209. * @sas_expander: the sas_device object
  5210. * Context: Calling function should acquire ioc->sas_node_lock.
  5211. *
  5212. * Removing object and freeing associated memory from the
  5213. * ioc->sas_expander_list.
  5214. *
  5215. * Return nothing.
  5216. */
  5217. static void
  5218. _scsih_expander_node_remove(struct MPT2SAS_ADAPTER *ioc,
  5219. struct _sas_node *sas_expander)
  5220. {
  5221. struct _sas_port *mpt2sas_port;
  5222. struct _sas_device *sas_device;
  5223. struct _sas_node *expander_sibling;
  5224. unsigned long flags;
  5225. if (!sas_expander)
  5226. return;
  5227. /* remove sibling ports attached to this expander */
  5228. retry_device_search:
  5229. list_for_each_entry(mpt2sas_port,
  5230. &sas_expander->sas_port_list, port_list) {
  5231. if (mpt2sas_port->remote_identify.device_type ==
  5232. SAS_END_DEVICE) {
  5233. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5234. sas_device =
  5235. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  5236. mpt2sas_port->remote_identify.sas_address);
  5237. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5238. if (!sas_device)
  5239. continue;
  5240. _scsih_remove_device(ioc, sas_device);
  5241. if (ioc->shost_recovery)
  5242. return;
  5243. goto retry_device_search;
  5244. }
  5245. }
  5246. retry_expander_search:
  5247. list_for_each_entry(mpt2sas_port,
  5248. &sas_expander->sas_port_list, port_list) {
  5249. if (mpt2sas_port->remote_identify.device_type ==
  5250. MPI2_SAS_DEVICE_INFO_EDGE_EXPANDER ||
  5251. mpt2sas_port->remote_identify.device_type ==
  5252. MPI2_SAS_DEVICE_INFO_FANOUT_EXPANDER) {
  5253. spin_lock_irqsave(&ioc->sas_node_lock, flags);
  5254. expander_sibling =
  5255. mpt2sas_scsih_expander_find_by_sas_address(
  5256. ioc, mpt2sas_port->remote_identify.sas_address);
  5257. spin_unlock_irqrestore(&ioc->sas_node_lock, flags);
  5258. if (!expander_sibling)
  5259. continue;
  5260. _scsih_expander_remove(ioc,
  5261. expander_sibling->sas_address);
  5262. if (ioc->shost_recovery)
  5263. return;
  5264. goto retry_expander_search;
  5265. }
  5266. }
  5267. mpt2sas_transport_port_remove(ioc, sas_expander->sas_address,
  5268. sas_expander->sas_address_parent);
  5269. printk(MPT2SAS_INFO_FMT "expander_remove: handle"
  5270. "(0x%04x), sas_addr(0x%016llx)\n", ioc->name,
  5271. sas_expander->handle, (unsigned long long)
  5272. sas_expander->sas_address);
  5273. list_del(&sas_expander->list);
  5274. kfree(sas_expander->phy);
  5275. kfree(sas_expander);
  5276. }
  5277. /**
  5278. * _scsih_remove - detach and remove add host
  5279. * @pdev: PCI device struct
  5280. *
  5281. * Return nothing.
  5282. */
  5283. static void __devexit
  5284. _scsih_remove(struct pci_dev *pdev)
  5285. {
  5286. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5287. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5288. struct _sas_port *mpt2sas_port;
  5289. struct _sas_device *sas_device;
  5290. struct _sas_node *expander_sibling;
  5291. struct workqueue_struct *wq;
  5292. unsigned long flags;
  5293. ioc->remove_host = 1;
  5294. _scsih_fw_event_off(ioc);
  5295. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  5296. wq = ioc->firmware_event_thread;
  5297. ioc->firmware_event_thread = NULL;
  5298. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  5299. if (wq)
  5300. destroy_workqueue(wq);
  5301. /* free ports attached to the sas_host */
  5302. retry_again:
  5303. list_for_each_entry(mpt2sas_port,
  5304. &ioc->sas_hba.sas_port_list, port_list) {
  5305. if (mpt2sas_port->remote_identify.device_type ==
  5306. SAS_END_DEVICE) {
  5307. sas_device =
  5308. mpt2sas_scsih_sas_device_find_by_sas_address(ioc,
  5309. mpt2sas_port->remote_identify.sas_address);
  5310. if (sas_device) {
  5311. _scsih_remove_device(ioc, sas_device);
  5312. goto retry_again;
  5313. }
  5314. } else {
  5315. expander_sibling =
  5316. mpt2sas_scsih_expander_find_by_sas_address(ioc,
  5317. mpt2sas_port->remote_identify.sas_address);
  5318. if (expander_sibling) {
  5319. _scsih_expander_remove(ioc,
  5320. expander_sibling->sas_address);
  5321. goto retry_again;
  5322. }
  5323. }
  5324. }
  5325. /* free phys attached to the sas_host */
  5326. if (ioc->sas_hba.num_phys) {
  5327. kfree(ioc->sas_hba.phy);
  5328. ioc->sas_hba.phy = NULL;
  5329. ioc->sas_hba.num_phys = 0;
  5330. }
  5331. sas_remove_host(shost);
  5332. mpt2sas_base_detach(ioc);
  5333. list_del(&ioc->list);
  5334. scsi_remove_host(shost);
  5335. scsi_host_put(shost);
  5336. }
  5337. /**
  5338. * _scsih_probe_boot_devices - reports 1st device
  5339. * @ioc: per adapter object
  5340. *
  5341. * If specified in bios page 2, this routine reports the 1st
  5342. * device scsi-ml or sas transport for persistent boot device
  5343. * purposes. Please refer to function _scsih_determine_boot_device()
  5344. */
  5345. static void
  5346. _scsih_probe_boot_devices(struct MPT2SAS_ADAPTER *ioc)
  5347. {
  5348. u8 is_raid;
  5349. void *device;
  5350. struct _sas_device *sas_device;
  5351. struct _raid_device *raid_device;
  5352. u16 handle;
  5353. u64 sas_address_parent;
  5354. u64 sas_address;
  5355. unsigned long flags;
  5356. int rc;
  5357. device = NULL;
  5358. if (ioc->req_boot_device.device) {
  5359. device = ioc->req_boot_device.device;
  5360. is_raid = ioc->req_boot_device.is_raid;
  5361. } else if (ioc->req_alt_boot_device.device) {
  5362. device = ioc->req_alt_boot_device.device;
  5363. is_raid = ioc->req_alt_boot_device.is_raid;
  5364. } else if (ioc->current_boot_device.device) {
  5365. device = ioc->current_boot_device.device;
  5366. is_raid = ioc->current_boot_device.is_raid;
  5367. }
  5368. if (!device)
  5369. return;
  5370. if (is_raid) {
  5371. raid_device = device;
  5372. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5373. raid_device->id, 0);
  5374. if (rc)
  5375. _scsih_raid_device_remove(ioc, raid_device);
  5376. } else {
  5377. sas_device = device;
  5378. handle = sas_device->handle;
  5379. sas_address_parent = sas_device->sas_address_parent;
  5380. sas_address = sas_device->sas_address;
  5381. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5382. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  5383. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5384. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  5385. sas_device->sas_address_parent)) {
  5386. _scsih_sas_device_remove(ioc, sas_device);
  5387. } else if (!sas_device->starget) {
  5388. mpt2sas_transport_port_remove(ioc, sas_address,
  5389. sas_address_parent);
  5390. _scsih_sas_device_remove(ioc, sas_device);
  5391. }
  5392. }
  5393. }
  5394. /**
  5395. * _scsih_probe_raid - reporting raid volumes to scsi-ml
  5396. * @ioc: per adapter object
  5397. *
  5398. * Called during initial loading of the driver.
  5399. */
  5400. static void
  5401. _scsih_probe_raid(struct MPT2SAS_ADAPTER *ioc)
  5402. {
  5403. struct _raid_device *raid_device, *raid_next;
  5404. int rc;
  5405. list_for_each_entry_safe(raid_device, raid_next,
  5406. &ioc->raid_device_list, list) {
  5407. if (raid_device->starget)
  5408. continue;
  5409. rc = scsi_add_device(ioc->shost, RAID_CHANNEL,
  5410. raid_device->id, 0);
  5411. if (rc)
  5412. _scsih_raid_device_remove(ioc, raid_device);
  5413. }
  5414. }
  5415. /**
  5416. * _scsih_probe_sas - reporting sas devices to sas transport
  5417. * @ioc: per adapter object
  5418. *
  5419. * Called during initial loading of the driver.
  5420. */
  5421. static void
  5422. _scsih_probe_sas(struct MPT2SAS_ADAPTER *ioc)
  5423. {
  5424. struct _sas_device *sas_device, *next;
  5425. unsigned long flags;
  5426. /* SAS Device List */
  5427. list_for_each_entry_safe(sas_device, next, &ioc->sas_device_init_list,
  5428. list) {
  5429. spin_lock_irqsave(&ioc->sas_device_lock, flags);
  5430. list_move_tail(&sas_device->list, &ioc->sas_device_list);
  5431. spin_unlock_irqrestore(&ioc->sas_device_lock, flags);
  5432. if (!mpt2sas_transport_port_add(ioc, sas_device->handle,
  5433. sas_device->sas_address_parent)) {
  5434. _scsih_sas_device_remove(ioc, sas_device);
  5435. } else if (!sas_device->starget) {
  5436. mpt2sas_transport_port_remove(ioc,
  5437. sas_device->sas_address,
  5438. sas_device->sas_address_parent);
  5439. _scsih_sas_device_remove(ioc, sas_device);
  5440. }
  5441. }
  5442. }
  5443. /**
  5444. * _scsih_probe_devices - probing for devices
  5445. * @ioc: per adapter object
  5446. *
  5447. * Called during initial loading of the driver.
  5448. */
  5449. static void
  5450. _scsih_probe_devices(struct MPT2SAS_ADAPTER *ioc)
  5451. {
  5452. u16 volume_mapping_flags =
  5453. le16_to_cpu(ioc->ioc_pg8.IRVolumeMappingFlags) &
  5454. MPI2_IOCPAGE8_IRFLAGS_MASK_VOLUME_MAPPING_MODE;
  5455. if (!(ioc->facts.ProtocolFlags & MPI2_IOCFACTS_PROTOCOL_SCSI_INITIATOR))
  5456. return; /* return when IOC doesn't support initiator mode */
  5457. _scsih_probe_boot_devices(ioc);
  5458. if (ioc->ir_firmware) {
  5459. if ((volume_mapping_flags &
  5460. MPI2_IOCPAGE8_IRFLAGS_HIGH_VOLUME_MAPPING)) {
  5461. _scsih_probe_sas(ioc);
  5462. _scsih_probe_raid(ioc);
  5463. } else {
  5464. _scsih_probe_raid(ioc);
  5465. _scsih_probe_sas(ioc);
  5466. }
  5467. } else
  5468. _scsih_probe_sas(ioc);
  5469. }
  5470. /**
  5471. * _scsih_probe - attach and add scsi host
  5472. * @pdev: PCI device struct
  5473. * @id: pci device id
  5474. *
  5475. * Returns 0 success, anything else error.
  5476. */
  5477. static int
  5478. _scsih_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  5479. {
  5480. struct MPT2SAS_ADAPTER *ioc;
  5481. struct Scsi_Host *shost;
  5482. shost = scsi_host_alloc(&scsih_driver_template,
  5483. sizeof(struct MPT2SAS_ADAPTER));
  5484. if (!shost)
  5485. return -ENODEV;
  5486. /* init local params */
  5487. ioc = shost_priv(shost);
  5488. memset(ioc, 0, sizeof(struct MPT2SAS_ADAPTER));
  5489. INIT_LIST_HEAD(&ioc->list);
  5490. list_add_tail(&ioc->list, &mpt2sas_ioc_list);
  5491. ioc->shost = shost;
  5492. ioc->id = mpt_ids++;
  5493. sprintf(ioc->name, "%s%d", MPT2SAS_DRIVER_NAME, ioc->id);
  5494. ioc->pdev = pdev;
  5495. ioc->scsi_io_cb_idx = scsi_io_cb_idx;
  5496. ioc->tm_cb_idx = tm_cb_idx;
  5497. ioc->ctl_cb_idx = ctl_cb_idx;
  5498. ioc->base_cb_idx = base_cb_idx;
  5499. ioc->transport_cb_idx = transport_cb_idx;
  5500. ioc->config_cb_idx = config_cb_idx;
  5501. ioc->tm_tr_cb_idx = tm_tr_cb_idx;
  5502. ioc->tm_sas_control_cb_idx = tm_sas_control_cb_idx;
  5503. ioc->logging_level = logging_level;
  5504. /* misc semaphores and spin locks */
  5505. spin_lock_init(&ioc->ioc_reset_in_progress_lock);
  5506. spin_lock_init(&ioc->scsi_lookup_lock);
  5507. spin_lock_init(&ioc->sas_device_lock);
  5508. spin_lock_init(&ioc->sas_node_lock);
  5509. spin_lock_init(&ioc->fw_event_lock);
  5510. spin_lock_init(&ioc->raid_device_lock);
  5511. INIT_LIST_HEAD(&ioc->sas_device_list);
  5512. INIT_LIST_HEAD(&ioc->sas_device_init_list);
  5513. INIT_LIST_HEAD(&ioc->sas_expander_list);
  5514. INIT_LIST_HEAD(&ioc->fw_event_list);
  5515. INIT_LIST_HEAD(&ioc->raid_device_list);
  5516. INIT_LIST_HEAD(&ioc->sas_hba.sas_port_list);
  5517. INIT_LIST_HEAD(&ioc->delayed_tr_list);
  5518. /* init shost parameters */
  5519. shost->max_cmd_len = 16;
  5520. shost->max_lun = max_lun;
  5521. shost->transportt = mpt2sas_transport_template;
  5522. shost->unique_id = ioc->id;
  5523. if ((scsi_add_host(shost, &pdev->dev))) {
  5524. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5525. ioc->name, __FILE__, __LINE__, __func__);
  5526. list_del(&ioc->list);
  5527. goto out_add_shost_fail;
  5528. }
  5529. scsi_host_set_prot(shost, SHOST_DIF_TYPE1_PROTECTION
  5530. | SHOST_DIF_TYPE3_PROTECTION);
  5531. scsi_host_set_guard(shost, SHOST_DIX_GUARD_CRC);
  5532. /* event thread */
  5533. snprintf(ioc->firmware_event_name, sizeof(ioc->firmware_event_name),
  5534. "fw_event%d", ioc->id);
  5535. ioc->firmware_event_thread = create_singlethread_workqueue(
  5536. ioc->firmware_event_name);
  5537. if (!ioc->firmware_event_thread) {
  5538. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5539. ioc->name, __FILE__, __LINE__, __func__);
  5540. goto out_thread_fail;
  5541. }
  5542. ioc->wait_for_port_enable_to_complete = 1;
  5543. if ((mpt2sas_base_attach(ioc))) {
  5544. printk(MPT2SAS_ERR_FMT "failure at %s:%d/%s()!\n",
  5545. ioc->name, __FILE__, __LINE__, __func__);
  5546. goto out_attach_fail;
  5547. }
  5548. ioc->wait_for_port_enable_to_complete = 0;
  5549. _scsih_probe_devices(ioc);
  5550. return 0;
  5551. out_attach_fail:
  5552. destroy_workqueue(ioc->firmware_event_thread);
  5553. out_thread_fail:
  5554. list_del(&ioc->list);
  5555. scsi_remove_host(shost);
  5556. out_add_shost_fail:
  5557. return -ENODEV;
  5558. }
  5559. #ifdef CONFIG_PM
  5560. /**
  5561. * _scsih_suspend - power management suspend main entry point
  5562. * @pdev: PCI device struct
  5563. * @state: PM state change to (usually PCI_D3)
  5564. *
  5565. * Returns 0 success, anything else error.
  5566. */
  5567. static int
  5568. _scsih_suspend(struct pci_dev *pdev, pm_message_t state)
  5569. {
  5570. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5571. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5572. u32 device_state;
  5573. mpt2sas_base_stop_watchdog(ioc);
  5574. flush_scheduled_work();
  5575. scsi_block_requests(shost);
  5576. device_state = pci_choose_state(pdev, state);
  5577. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, entering "
  5578. "operating state [D%d]\n", ioc->name, pdev,
  5579. pci_name(pdev), device_state);
  5580. mpt2sas_base_free_resources(ioc);
  5581. pci_save_state(pdev);
  5582. pci_disable_device(pdev);
  5583. pci_set_power_state(pdev, device_state);
  5584. return 0;
  5585. }
  5586. /**
  5587. * _scsih_resume - power management resume main entry point
  5588. * @pdev: PCI device struct
  5589. *
  5590. * Returns 0 success, anything else error.
  5591. */
  5592. static int
  5593. _scsih_resume(struct pci_dev *pdev)
  5594. {
  5595. struct Scsi_Host *shost = pci_get_drvdata(pdev);
  5596. struct MPT2SAS_ADAPTER *ioc = shost_priv(shost);
  5597. u32 device_state = pdev->current_state;
  5598. int r;
  5599. printk(MPT2SAS_INFO_FMT "pdev=0x%p, slot=%s, previous "
  5600. "operating state [D%d]\n", ioc->name, pdev,
  5601. pci_name(pdev), device_state);
  5602. pci_set_power_state(pdev, PCI_D0);
  5603. pci_enable_wake(pdev, PCI_D0, 0);
  5604. pci_restore_state(pdev);
  5605. ioc->pdev = pdev;
  5606. r = mpt2sas_base_map_resources(ioc);
  5607. if (r)
  5608. return r;
  5609. mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP, SOFT_RESET);
  5610. scsi_unblock_requests(shost);
  5611. mpt2sas_base_start_watchdog(ioc);
  5612. return 0;
  5613. }
  5614. #endif /* CONFIG_PM */
  5615. static struct pci_driver scsih_driver = {
  5616. .name = MPT2SAS_DRIVER_NAME,
  5617. .id_table = scsih_pci_table,
  5618. .probe = _scsih_probe,
  5619. .remove = __devexit_p(_scsih_remove),
  5620. #ifdef CONFIG_PM
  5621. .suspend = _scsih_suspend,
  5622. .resume = _scsih_resume,
  5623. #endif
  5624. };
  5625. /**
  5626. * _scsih_init - main entry point for this driver.
  5627. *
  5628. * Returns 0 success, anything else error.
  5629. */
  5630. static int __init
  5631. _scsih_init(void)
  5632. {
  5633. int error;
  5634. mpt_ids = 0;
  5635. printk(KERN_INFO "%s version %s loaded\n", MPT2SAS_DRIVER_NAME,
  5636. MPT2SAS_DRIVER_VERSION);
  5637. mpt2sas_transport_template =
  5638. sas_attach_transport(&mpt2sas_transport_functions);
  5639. if (!mpt2sas_transport_template)
  5640. return -ENODEV;
  5641. mpt2sas_base_initialize_callback_handler();
  5642. /* queuecommand callback hander */
  5643. scsi_io_cb_idx = mpt2sas_base_register_callback_handler(_scsih_io_done);
  5644. /* task managment callback handler */
  5645. tm_cb_idx = mpt2sas_base_register_callback_handler(_scsih_tm_done);
  5646. /* base internal commands callback handler */
  5647. base_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_base_done);
  5648. /* transport internal commands callback handler */
  5649. transport_cb_idx = mpt2sas_base_register_callback_handler(
  5650. mpt2sas_transport_done);
  5651. /* configuration page API internal commands callback handler */
  5652. config_cb_idx = mpt2sas_base_register_callback_handler(
  5653. mpt2sas_config_done);
  5654. /* ctl module callback handler */
  5655. ctl_cb_idx = mpt2sas_base_register_callback_handler(mpt2sas_ctl_done);
  5656. tm_tr_cb_idx = mpt2sas_base_register_callback_handler(
  5657. _scsih_tm_tr_complete);
  5658. tm_sas_control_cb_idx = mpt2sas_base_register_callback_handler(
  5659. _scsih_sas_control_complete);
  5660. mpt2sas_ctl_init();
  5661. error = pci_register_driver(&scsih_driver);
  5662. if (error)
  5663. sas_release_transport(mpt2sas_transport_template);
  5664. return error;
  5665. }
  5666. /**
  5667. * _scsih_exit - exit point for this driver (when it is a module).
  5668. *
  5669. * Returns 0 success, anything else error.
  5670. */
  5671. static void __exit
  5672. _scsih_exit(void)
  5673. {
  5674. printk(KERN_INFO "mpt2sas version %s unloading\n",
  5675. MPT2SAS_DRIVER_VERSION);
  5676. pci_unregister_driver(&scsih_driver);
  5677. sas_release_transport(mpt2sas_transport_template);
  5678. mpt2sas_base_release_callback_handler(scsi_io_cb_idx);
  5679. mpt2sas_base_release_callback_handler(tm_cb_idx);
  5680. mpt2sas_base_release_callback_handler(base_cb_idx);
  5681. mpt2sas_base_release_callback_handler(transport_cb_idx);
  5682. mpt2sas_base_release_callback_handler(config_cb_idx);
  5683. mpt2sas_base_release_callback_handler(ctl_cb_idx);
  5684. mpt2sas_base_release_callback_handler(tm_tr_cb_idx);
  5685. mpt2sas_base_release_callback_handler(tm_sas_control_cb_idx);
  5686. mpt2sas_ctl_exit();
  5687. }
  5688. module_init(_scsih_init);
  5689. module_exit(_scsih_exit);