mpt2sas_scsih.c 206 KB

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