mpt2sas_scsih.c 176 KB

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