mpt2sas_scsih.c 178 KB

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