mpt2sas_scsih.c 177 KB

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