mptbase.c 236 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528
  1. /*
  2. * linux/drivers/message/fusion/mptbase.c
  3. * This is the Fusion MPT base driver which supports multiple
  4. * (SCSI + LAN) specialized protocol drivers.
  5. * For use with LSI PCI chip/adapter(s)
  6. * running LSI Fusion MPT (Message Passing Technology) firmware.
  7. *
  8. * Copyright (c) 1999-2008 LSI Corporation
  9. * (mailto:DL-MPTFusionLinux@lsi.com)
  10. *
  11. */
  12. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  13. /*
  14. This program is free software; you can redistribute it and/or modify
  15. it under the terms of the GNU General Public License as published by
  16. the Free Software Foundation; version 2 of the License.
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. GNU General Public License for more details.
  21. NO WARRANTY
  22. THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR
  23. CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT
  24. LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT,
  25. MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is
  26. solely responsible for determining the appropriateness of using and
  27. distributing the Program and assumes all risks associated with its
  28. exercise of rights under this Agreement, including but not limited to
  29. the risks and costs of program errors, damage to or loss of data,
  30. programs or equipment, and unavailability or interruption of operations.
  31. DISCLAIMER OF LIABILITY
  32. NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY
  33. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34. DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND
  35. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  36. TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  37. USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
  38. HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES
  39. You should have received a copy of the GNU General Public License
  40. along with this program; if not, write to the Free Software
  41. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  42. */
  43. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  44. #include <linux/kernel.h>
  45. #include <linux/module.h>
  46. #include <linux/errno.h>
  47. #include <linux/init.h>
  48. #include <linux/seq_file.h>
  49. #include <linux/slab.h>
  50. #include <linux/types.h>
  51. #include <linux/pci.h>
  52. #include <linux/kdev_t.h>
  53. #include <linux/blkdev.h>
  54. #include <linux/delay.h>
  55. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  56. #include <linux/dma-mapping.h>
  57. #include <linux/kthread.h>
  58. #include <scsi/scsi_host.h>
  59. #include "mptbase.h"
  60. #include "lsi/mpi_log_fc.h"
  61. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  62. #define my_NAME "Fusion MPT base driver"
  63. #define my_VERSION MPT_LINUX_VERSION_COMMON
  64. #define MYNAM "mptbase"
  65. MODULE_AUTHOR(MODULEAUTHOR);
  66. MODULE_DESCRIPTION(my_NAME);
  67. MODULE_LICENSE("GPL");
  68. MODULE_VERSION(my_VERSION);
  69. /*
  70. * cmd line parameters
  71. */
  72. static int mpt_msi_enable_spi;
  73. module_param(mpt_msi_enable_spi, int, 0);
  74. MODULE_PARM_DESC(mpt_msi_enable_spi,
  75. " Enable MSI Support for SPI controllers (default=0)");
  76. static int mpt_msi_enable_fc;
  77. module_param(mpt_msi_enable_fc, int, 0);
  78. MODULE_PARM_DESC(mpt_msi_enable_fc,
  79. " Enable MSI Support for FC controllers (default=0)");
  80. static int mpt_msi_enable_sas;
  81. module_param(mpt_msi_enable_sas, int, 0);
  82. MODULE_PARM_DESC(mpt_msi_enable_sas,
  83. " Enable MSI Support for SAS controllers (default=0)");
  84. static int mpt_channel_mapping;
  85. module_param(mpt_channel_mapping, int, 0);
  86. MODULE_PARM_DESC(mpt_channel_mapping, " Mapping id's to channels (default=0)");
  87. static int mpt_debug_level;
  88. static int mpt_set_debug_level(const char *val, const struct kernel_param *kp);
  89. module_param_call(mpt_debug_level, mpt_set_debug_level, param_get_int,
  90. &mpt_debug_level, 0600);
  91. MODULE_PARM_DESC(mpt_debug_level,
  92. " debug level - refer to mptdebug.h - (default=0)");
  93. int mpt_fwfault_debug;
  94. EXPORT_SYMBOL(mpt_fwfault_debug);
  95. module_param(mpt_fwfault_debug, int, 0600);
  96. MODULE_PARM_DESC(mpt_fwfault_debug,
  97. "Enable detection of Firmware fault and halt Firmware on fault - (default=0)");
  98. static char MptCallbacksName[MPT_MAX_PROTOCOL_DRIVERS]
  99. [MPT_MAX_CALLBACKNAME_LEN+1];
  100. #ifdef MFCNT
  101. static int mfcounter = 0;
  102. #define PRINT_MF_COUNT 20000
  103. #endif
  104. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  105. /*
  106. * Public data...
  107. */
  108. #define WHOINIT_UNKNOWN 0xAA
  109. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  110. /*
  111. * Private data...
  112. */
  113. /* Adapter link list */
  114. LIST_HEAD(ioc_list);
  115. /* Callback lookup table */
  116. static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
  117. /* Protocol driver class lookup table */
  118. static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
  119. /* Event handler lookup table */
  120. static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  121. /* Reset handler lookup table */
  122. static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  123. static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  124. #ifdef CONFIG_PROC_FS
  125. static struct proc_dir_entry *mpt_proc_root_dir;
  126. #endif
  127. /*
  128. * Driver Callback Index's
  129. */
  130. static u8 mpt_base_index = MPT_MAX_PROTOCOL_DRIVERS;
  131. static u8 last_drv_idx;
  132. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  133. /*
  134. * Forward protos...
  135. */
  136. static irqreturn_t mpt_interrupt(int irq, void *bus_id);
  137. static int mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req,
  138. MPT_FRAME_HDR *reply);
  139. static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
  140. u32 *req, int replyBytes, u16 *u16reply, int maxwait,
  141. int sleepFlag);
  142. static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
  143. static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
  144. static void mpt_adapter_disable(MPT_ADAPTER *ioc);
  145. static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
  146. static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
  147. static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
  148. static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
  149. static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  150. static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
  151. static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  152. static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
  153. static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
  154. static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  155. static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  156. static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
  157. static int PrimeIocFifos(MPT_ADAPTER *ioc);
  158. static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  159. static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  160. static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  161. static int GetLanConfigPages(MPT_ADAPTER *ioc);
  162. static int GetIoUnitPage2(MPT_ADAPTER *ioc);
  163. int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
  164. static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
  165. static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
  166. static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
  167. static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
  168. static void mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc);
  169. static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch,
  170. int sleepFlag);
  171. static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
  172. static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
  173. static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
  174. #ifdef CONFIG_PROC_FS
  175. static int mpt_summary_proc_show(struct seq_file *m, void *v);
  176. static int mpt_version_proc_show(struct seq_file *m, void *v);
  177. static int mpt_iocinfo_proc_show(struct seq_file *m, void *v);
  178. #endif
  179. static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
  180. static int ProcessEventNotification(MPT_ADAPTER *ioc,
  181. EventNotificationReply_t *evReply, int *evHandlers);
  182. static void mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
  183. static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
  184. static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
  185. static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info , u8 cb_idx);
  186. static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
  187. static void mpt_inactive_raid_list_free(MPT_ADAPTER *ioc);
  188. /* module entry point */
  189. static int __init fusion_init (void);
  190. static void __exit fusion_exit (void);
  191. #define CHIPREG_READ32(addr) readl_relaxed(addr)
  192. #define CHIPREG_READ32_dmasync(addr) readl(addr)
  193. #define CHIPREG_WRITE32(addr,val) writel(val, addr)
  194. #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
  195. #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
  196. static void
  197. pci_disable_io_access(struct pci_dev *pdev)
  198. {
  199. u16 command_reg;
  200. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  201. command_reg &= ~1;
  202. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  203. }
  204. static void
  205. pci_enable_io_access(struct pci_dev *pdev)
  206. {
  207. u16 command_reg;
  208. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  209. command_reg |= 1;
  210. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  211. }
  212. static int mpt_set_debug_level(const char *val, const struct kernel_param *kp)
  213. {
  214. int ret = param_set_int(val, kp);
  215. MPT_ADAPTER *ioc;
  216. if (ret)
  217. return ret;
  218. list_for_each_entry(ioc, &ioc_list, list)
  219. ioc->debug_level = mpt_debug_level;
  220. return 0;
  221. }
  222. /**
  223. * mpt_get_cb_idx - obtain cb_idx for registered driver
  224. * @dclass: class driver enum
  225. *
  226. * Returns cb_idx, or zero means it wasn't found
  227. **/
  228. static u8
  229. mpt_get_cb_idx(MPT_DRIVER_CLASS dclass)
  230. {
  231. u8 cb_idx;
  232. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--)
  233. if (MptDriverClass[cb_idx] == dclass)
  234. return cb_idx;
  235. return 0;
  236. }
  237. /**
  238. * mpt_is_discovery_complete - determine if discovery has completed
  239. * @ioc: per adatper instance
  240. *
  241. * Returns 1 when discovery completed, else zero.
  242. */
  243. static int
  244. mpt_is_discovery_complete(MPT_ADAPTER *ioc)
  245. {
  246. ConfigExtendedPageHeader_t hdr;
  247. CONFIGPARMS cfg;
  248. SasIOUnitPage0_t *buffer;
  249. dma_addr_t dma_handle;
  250. int rc = 0;
  251. memset(&hdr, 0, sizeof(ConfigExtendedPageHeader_t));
  252. memset(&cfg, 0, sizeof(CONFIGPARMS));
  253. hdr.PageVersion = MPI_SASIOUNITPAGE0_PAGEVERSION;
  254. hdr.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  255. hdr.ExtPageType = MPI_CONFIG_EXTPAGETYPE_SAS_IO_UNIT;
  256. cfg.cfghdr.ehdr = &hdr;
  257. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  258. if ((mpt_config(ioc, &cfg)))
  259. goto out;
  260. if (!hdr.ExtPageLength)
  261. goto out;
  262. buffer = pci_alloc_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  263. &dma_handle);
  264. if (!buffer)
  265. goto out;
  266. cfg.physAddr = dma_handle;
  267. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  268. if ((mpt_config(ioc, &cfg)))
  269. goto out_free_consistent;
  270. if (!(buffer->PhyData[0].PortFlags &
  271. MPI_SAS_IOUNIT0_PORT_FLAGS_DISCOVERY_IN_PROGRESS))
  272. rc = 1;
  273. out_free_consistent:
  274. pci_free_consistent(ioc->pcidev, hdr.ExtPageLength * 4,
  275. buffer, dma_handle);
  276. out:
  277. return rc;
  278. }
  279. /**
  280. * mpt_remove_dead_ioc_func - kthread context to remove dead ioc
  281. * @arg: input argument, used to derive ioc
  282. *
  283. * Return 0 if controller is removed from pci subsystem.
  284. * Return -1 for other case.
  285. */
  286. static int mpt_remove_dead_ioc_func(void *arg)
  287. {
  288. MPT_ADAPTER *ioc = (MPT_ADAPTER *)arg;
  289. struct pci_dev *pdev;
  290. if (!ioc)
  291. return -1;
  292. pdev = ioc->pcidev;
  293. if (!pdev)
  294. return -1;
  295. pci_stop_and_remove_bus_device_locked(pdev);
  296. return 0;
  297. }
  298. /**
  299. * mpt_fault_reset_work - work performed on workq after ioc fault
  300. * @work: input argument, used to derive ioc
  301. *
  302. **/
  303. static void
  304. mpt_fault_reset_work(struct work_struct *work)
  305. {
  306. MPT_ADAPTER *ioc =
  307. container_of(work, MPT_ADAPTER, fault_reset_work.work);
  308. u32 ioc_raw_state;
  309. int rc;
  310. unsigned long flags;
  311. MPT_SCSI_HOST *hd;
  312. struct task_struct *p;
  313. if (ioc->ioc_reset_in_progress || !ioc->active)
  314. goto out;
  315. ioc_raw_state = mpt_GetIocState(ioc, 0);
  316. if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_MASK) {
  317. printk(MYIOC_s_INFO_FMT "%s: IOC is non-operational !!!!\n",
  318. ioc->name, __func__);
  319. /*
  320. * Call mptscsih_flush_pending_cmds callback so that we
  321. * flush all pending commands back to OS.
  322. * This call is required to aovid deadlock at block layer.
  323. * Dead IOC will fail to do diag reset,and this call is safe
  324. * since dead ioc will never return any command back from HW.
  325. */
  326. hd = shost_priv(ioc->sh);
  327. ioc->schedule_dead_ioc_flush_running_cmds(hd);
  328. /*Remove the Dead Host */
  329. p = kthread_run(mpt_remove_dead_ioc_func, ioc,
  330. "mpt_dead_ioc_%d", ioc->id);
  331. if (IS_ERR(p)) {
  332. printk(MYIOC_s_ERR_FMT
  333. "%s: Running mpt_dead_ioc thread failed !\n",
  334. ioc->name, __func__);
  335. } else {
  336. printk(MYIOC_s_WARN_FMT
  337. "%s: Running mpt_dead_ioc thread success !\n",
  338. ioc->name, __func__);
  339. }
  340. return; /* don't rearm timer */
  341. }
  342. if ((ioc_raw_state & MPI_IOC_STATE_MASK)
  343. == MPI_IOC_STATE_FAULT) {
  344. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state (%04xh)!!!\n",
  345. ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
  346. printk(MYIOC_s_WARN_FMT "Issuing HardReset from %s!!\n",
  347. ioc->name, __func__);
  348. rc = mpt_HardResetHandler(ioc, CAN_SLEEP);
  349. printk(MYIOC_s_WARN_FMT "%s: HardReset: %s\n", ioc->name,
  350. __func__, (rc == 0) ? "success" : "failed");
  351. ioc_raw_state = mpt_GetIocState(ioc, 0);
  352. if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT)
  353. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state after "
  354. "reset (%04xh)\n", ioc->name, ioc_raw_state &
  355. MPI_DOORBELL_DATA_MASK);
  356. } else if (ioc->bus_type == SAS && ioc->sas_discovery_quiesce_io) {
  357. if ((mpt_is_discovery_complete(ioc))) {
  358. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT "clearing "
  359. "discovery_quiesce_io flag\n", ioc->name));
  360. ioc->sas_discovery_quiesce_io = 0;
  361. }
  362. }
  363. out:
  364. /*
  365. * Take turns polling alternate controller
  366. */
  367. if (ioc->alt_ioc)
  368. ioc = ioc->alt_ioc;
  369. /* rearm the timer */
  370. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  371. if (ioc->reset_work_q)
  372. queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
  373. msecs_to_jiffies(MPT_POLLING_INTERVAL));
  374. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  375. }
  376. /*
  377. * Process turbo (context) reply...
  378. */
  379. static void
  380. mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
  381. {
  382. MPT_FRAME_HDR *mf = NULL;
  383. MPT_FRAME_HDR *mr = NULL;
  384. u16 req_idx = 0;
  385. u8 cb_idx;
  386. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got TURBO reply req_idx=%08x\n",
  387. ioc->name, pa));
  388. switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
  389. case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
  390. req_idx = pa & 0x0000FFFF;
  391. cb_idx = (pa & 0x00FF0000) >> 16;
  392. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  393. break;
  394. case MPI_CONTEXT_REPLY_TYPE_LAN:
  395. cb_idx = mpt_get_cb_idx(MPTLAN_DRIVER);
  396. /*
  397. * Blind set of mf to NULL here was fatal
  398. * after lan_reply says "freeme"
  399. * Fix sort of combined with an optimization here;
  400. * added explicit check for case where lan_reply
  401. * was just returning 1 and doing nothing else.
  402. * For this case skip the callback, but set up
  403. * proper mf value first here:-)
  404. */
  405. if ((pa & 0x58000000) == 0x58000000) {
  406. req_idx = pa & 0x0000FFFF;
  407. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  408. mpt_free_msg_frame(ioc, mf);
  409. mb();
  410. return;
  411. break;
  412. }
  413. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  414. break;
  415. case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
  416. cb_idx = mpt_get_cb_idx(MPTSTM_DRIVER);
  417. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  418. break;
  419. default:
  420. cb_idx = 0;
  421. BUG();
  422. }
  423. /* Check for (valid) IO callback! */
  424. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
  425. MptCallbacks[cb_idx] == NULL) {
  426. printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
  427. __func__, ioc->name, cb_idx);
  428. goto out;
  429. }
  430. if (MptCallbacks[cb_idx](ioc, mf, mr))
  431. mpt_free_msg_frame(ioc, mf);
  432. out:
  433. mb();
  434. }
  435. static void
  436. mpt_reply(MPT_ADAPTER *ioc, u32 pa)
  437. {
  438. MPT_FRAME_HDR *mf;
  439. MPT_FRAME_HDR *mr;
  440. u16 req_idx;
  441. u8 cb_idx;
  442. int freeme;
  443. u32 reply_dma_low;
  444. u16 ioc_stat;
  445. /* non-TURBO reply! Hmmm, something may be up...
  446. * Newest turbo reply mechanism; get address
  447. * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
  448. */
  449. /* Map DMA address of reply header to cpu address.
  450. * pa is 32 bits - but the dma address may be 32 or 64 bits
  451. * get offset based only only the low addresses
  452. */
  453. reply_dma_low = (pa <<= 1);
  454. mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
  455. (reply_dma_low - ioc->reply_frames_low_dma));
  456. req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
  457. cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
  458. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  459. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
  460. ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
  461. DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mr);
  462. /* Check/log IOC log info
  463. */
  464. ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
  465. if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
  466. u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
  467. if (ioc->bus_type == FC)
  468. mpt_fc_log_info(ioc, log_info);
  469. else if (ioc->bus_type == SPI)
  470. mpt_spi_log_info(ioc, log_info);
  471. else if (ioc->bus_type == SAS)
  472. mpt_sas_log_info(ioc, log_info, cb_idx);
  473. }
  474. if (ioc_stat & MPI_IOCSTATUS_MASK)
  475. mpt_iocstatus_info(ioc, (u32)ioc_stat, mf);
  476. /* Check for (valid) IO callback! */
  477. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
  478. MptCallbacks[cb_idx] == NULL) {
  479. printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
  480. __func__, ioc->name, cb_idx);
  481. freeme = 0;
  482. goto out;
  483. }
  484. freeme = MptCallbacks[cb_idx](ioc, mf, mr);
  485. out:
  486. /* Flush (non-TURBO) reply with a WRITE! */
  487. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
  488. if (freeme)
  489. mpt_free_msg_frame(ioc, mf);
  490. mb();
  491. }
  492. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  493. /**
  494. * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
  495. * @irq: irq number (not used)
  496. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  497. *
  498. * This routine is registered via the request_irq() kernel API call,
  499. * and handles all interrupts generated from a specific MPT adapter
  500. * (also referred to as a IO Controller or IOC).
  501. * This routine must clear the interrupt from the adapter and does
  502. * so by reading the reply FIFO. Multiple replies may be processed
  503. * per single call to this routine.
  504. *
  505. * This routine handles register-level access of the adapter but
  506. * dispatches (calls) a protocol-specific callback routine to handle
  507. * the protocol-specific details of the MPT request completion.
  508. */
  509. static irqreturn_t
  510. mpt_interrupt(int irq, void *bus_id)
  511. {
  512. MPT_ADAPTER *ioc = bus_id;
  513. u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
  514. if (pa == 0xFFFFFFFF)
  515. return IRQ_NONE;
  516. /*
  517. * Drain the reply FIFO!
  518. */
  519. do {
  520. if (pa & MPI_ADDRESS_REPLY_A_BIT)
  521. mpt_reply(ioc, pa);
  522. else
  523. mpt_turbo_reply(ioc, pa);
  524. pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
  525. } while (pa != 0xFFFFFFFF);
  526. return IRQ_HANDLED;
  527. }
  528. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  529. /**
  530. * mptbase_reply - MPT base driver's callback routine
  531. * @ioc: Pointer to MPT_ADAPTER structure
  532. * @req: Pointer to original MPT request frame
  533. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  534. *
  535. * MPT base driver's callback routine; all base driver
  536. * "internal" request/reply processing is routed here.
  537. * Currently used for EventNotification and EventAck handling.
  538. *
  539. * Returns 1 indicating original alloc'd request frame ptr
  540. * should be freed, or 0 if it shouldn't.
  541. */
  542. static int
  543. mptbase_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply)
  544. {
  545. EventNotificationReply_t *pEventReply;
  546. u8 event;
  547. int evHandlers;
  548. int freereq = 1;
  549. switch (reply->u.hdr.Function) {
  550. case MPI_FUNCTION_EVENT_NOTIFICATION:
  551. pEventReply = (EventNotificationReply_t *)reply;
  552. evHandlers = 0;
  553. ProcessEventNotification(ioc, pEventReply, &evHandlers);
  554. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  555. if (pEventReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)
  556. freereq = 0;
  557. if (event != MPI_EVENT_EVENT_CHANGE)
  558. break;
  559. /* fall through */
  560. case MPI_FUNCTION_CONFIG:
  561. case MPI_FUNCTION_SAS_IO_UNIT_CONTROL:
  562. ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_COMMAND_GOOD;
  563. ioc->mptbase_cmds.status |= MPT_MGMT_STATUS_RF_VALID;
  564. memcpy(ioc->mptbase_cmds.reply, reply,
  565. min(MPT_DEFAULT_FRAME_SIZE,
  566. 4 * reply->u.reply.MsgLength));
  567. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
  568. ioc->mptbase_cmds.status &= ~MPT_MGMT_STATUS_PENDING;
  569. complete(&ioc->mptbase_cmds.done);
  570. } else
  571. freereq = 0;
  572. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_FREE_MF)
  573. freereq = 1;
  574. break;
  575. case MPI_FUNCTION_EVENT_ACK:
  576. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  577. "EventAck reply received\n", ioc->name));
  578. break;
  579. default:
  580. printk(MYIOC_s_ERR_FMT
  581. "Unexpected msg function (=%02Xh) reply received!\n",
  582. ioc->name, reply->u.hdr.Function);
  583. break;
  584. }
  585. /*
  586. * Conditionally tell caller to free the original
  587. * EventNotification/EventAck/unexpected request frame!
  588. */
  589. return freereq;
  590. }
  591. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  592. /**
  593. * mpt_register - Register protocol-specific main callback handler.
  594. * @cbfunc: callback function pointer
  595. * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
  596. * @func_name: call function's name
  597. *
  598. * This routine is called by a protocol-specific driver (SCSI host,
  599. * LAN, SCSI target) to register its reply callback routine. Each
  600. * protocol-specific driver must do this before it will be able to
  601. * use any IOC resources, such as obtaining request frames.
  602. *
  603. * NOTES: The SCSI protocol driver currently calls this routine thrice
  604. * in order to register separate callbacks; one for "normal" SCSI IO;
  605. * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
  606. *
  607. * Returns u8 valued "handle" in the range (and S.O.D. order)
  608. * {N,...,7,6,5,...,1} if successful.
  609. * A return value of MPT_MAX_PROTOCOL_DRIVERS (including zero!) should be
  610. * considered an error by the caller.
  611. */
  612. u8
  613. mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass, char *func_name)
  614. {
  615. u8 cb_idx;
  616. last_drv_idx = MPT_MAX_PROTOCOL_DRIVERS;
  617. /*
  618. * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
  619. * (slot/handle 0 is reserved!)
  620. */
  621. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  622. if (MptCallbacks[cb_idx] == NULL) {
  623. MptCallbacks[cb_idx] = cbfunc;
  624. MptDriverClass[cb_idx] = dclass;
  625. MptEvHandlers[cb_idx] = NULL;
  626. last_drv_idx = cb_idx;
  627. strlcpy(MptCallbacksName[cb_idx], func_name,
  628. MPT_MAX_CALLBACKNAME_LEN+1);
  629. break;
  630. }
  631. }
  632. return last_drv_idx;
  633. }
  634. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  635. /**
  636. * mpt_deregister - Deregister a protocol drivers resources.
  637. * @cb_idx: previously registered callback handle
  638. *
  639. * Each protocol-specific driver should call this routine when its
  640. * module is unloaded.
  641. */
  642. void
  643. mpt_deregister(u8 cb_idx)
  644. {
  645. if (cb_idx && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
  646. MptCallbacks[cb_idx] = NULL;
  647. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  648. MptEvHandlers[cb_idx] = NULL;
  649. last_drv_idx++;
  650. }
  651. }
  652. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  653. /**
  654. * mpt_event_register - Register protocol-specific event callback handler.
  655. * @cb_idx: previously registered (via mpt_register) callback handle
  656. * @ev_cbfunc: callback function
  657. *
  658. * This routine can be called by one or more protocol-specific drivers
  659. * if/when they choose to be notified of MPT events.
  660. *
  661. * Returns 0 for success.
  662. */
  663. int
  664. mpt_event_register(u8 cb_idx, MPT_EVHANDLER ev_cbfunc)
  665. {
  666. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  667. return -1;
  668. MptEvHandlers[cb_idx] = ev_cbfunc;
  669. return 0;
  670. }
  671. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  672. /**
  673. * mpt_event_deregister - Deregister protocol-specific event callback handler
  674. * @cb_idx: previously registered callback handle
  675. *
  676. * Each protocol-specific driver should call this routine
  677. * when it does not (or can no longer) handle events,
  678. * or when its module is unloaded.
  679. */
  680. void
  681. mpt_event_deregister(u8 cb_idx)
  682. {
  683. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  684. return;
  685. MptEvHandlers[cb_idx] = NULL;
  686. }
  687. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  688. /**
  689. * mpt_reset_register - Register protocol-specific IOC reset handler.
  690. * @cb_idx: previously registered (via mpt_register) callback handle
  691. * @reset_func: reset function
  692. *
  693. * This routine can be called by one or more protocol-specific drivers
  694. * if/when they choose to be notified of IOC resets.
  695. *
  696. * Returns 0 for success.
  697. */
  698. int
  699. mpt_reset_register(u8 cb_idx, MPT_RESETHANDLER reset_func)
  700. {
  701. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  702. return -1;
  703. MptResetHandlers[cb_idx] = reset_func;
  704. return 0;
  705. }
  706. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  707. /**
  708. * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
  709. * @cb_idx: previously registered callback handle
  710. *
  711. * Each protocol-specific driver should call this routine
  712. * when it does not (or can no longer) handle IOC reset handling,
  713. * or when its module is unloaded.
  714. */
  715. void
  716. mpt_reset_deregister(u8 cb_idx)
  717. {
  718. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  719. return;
  720. MptResetHandlers[cb_idx] = NULL;
  721. }
  722. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  723. /**
  724. * mpt_device_driver_register - Register device driver hooks
  725. * @dd_cbfunc: driver callbacks struct
  726. * @cb_idx: MPT protocol driver index
  727. */
  728. int
  729. mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, u8 cb_idx)
  730. {
  731. MPT_ADAPTER *ioc;
  732. const struct pci_device_id *id;
  733. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  734. return -EINVAL;
  735. MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
  736. /* call per pci device probe entry point */
  737. list_for_each_entry(ioc, &ioc_list, list) {
  738. id = ioc->pcidev->driver ?
  739. ioc->pcidev->driver->id_table : NULL;
  740. if (dd_cbfunc->probe)
  741. dd_cbfunc->probe(ioc->pcidev, id);
  742. }
  743. return 0;
  744. }
  745. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  746. /**
  747. * mpt_device_driver_deregister - DeRegister device driver hooks
  748. * @cb_idx: MPT protocol driver index
  749. */
  750. void
  751. mpt_device_driver_deregister(u8 cb_idx)
  752. {
  753. struct mpt_pci_driver *dd_cbfunc;
  754. MPT_ADAPTER *ioc;
  755. if (!cb_idx || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  756. return;
  757. dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
  758. list_for_each_entry(ioc, &ioc_list, list) {
  759. if (dd_cbfunc->remove)
  760. dd_cbfunc->remove(ioc->pcidev);
  761. }
  762. MptDeviceDriverHandlers[cb_idx] = NULL;
  763. }
  764. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  765. /**
  766. * mpt_get_msg_frame - Obtain an MPT request frame from the pool
  767. * @cb_idx: Handle of registered MPT protocol driver
  768. * @ioc: Pointer to MPT adapter structure
  769. *
  770. * Obtain an MPT request frame from the pool (of 1024) that are
  771. * allocated per MPT adapter.
  772. *
  773. * Returns pointer to a MPT request frame or %NULL if none are available
  774. * or IOC is not active.
  775. */
  776. MPT_FRAME_HDR*
  777. mpt_get_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc)
  778. {
  779. MPT_FRAME_HDR *mf;
  780. unsigned long flags;
  781. u16 req_idx; /* Request index */
  782. /* validate handle and ioc identifier */
  783. #ifdef MFCNT
  784. if (!ioc->active)
  785. printk(MYIOC_s_WARN_FMT "IOC Not Active! mpt_get_msg_frame "
  786. "returning NULL!\n", ioc->name);
  787. #endif
  788. /* If interrupts are not attached, do not return a request frame */
  789. if (!ioc->active)
  790. return NULL;
  791. spin_lock_irqsave(&ioc->FreeQlock, flags);
  792. if (!list_empty(&ioc->FreeQ)) {
  793. int req_offset;
  794. mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
  795. u.frame.linkage.list);
  796. list_del(&mf->u.frame.linkage.list);
  797. mf->u.frame.linkage.arg1 = 0;
  798. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx; /* byte */
  799. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  800. /* u16! */
  801. req_idx = req_offset / ioc->req_sz;
  802. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  803. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  804. /* Default, will be changed if necessary in SG generation */
  805. ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame;
  806. #ifdef MFCNT
  807. ioc->mfcnt++;
  808. #endif
  809. }
  810. else
  811. mf = NULL;
  812. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  813. #ifdef MFCNT
  814. if (mf == NULL)
  815. printk(MYIOC_s_WARN_FMT "IOC Active. No free Msg Frames! "
  816. "Count 0x%x Max 0x%x\n", ioc->name, ioc->mfcnt,
  817. ioc->req_depth);
  818. mfcounter++;
  819. if (mfcounter == PRINT_MF_COUNT)
  820. printk(MYIOC_s_INFO_FMT "MF Count 0x%x Max 0x%x \n", ioc->name,
  821. ioc->mfcnt, ioc->req_depth);
  822. #endif
  823. dmfprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_get_msg_frame(%d,%d), got mf=%p\n",
  824. ioc->name, cb_idx, ioc->id, mf));
  825. return mf;
  826. }
  827. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  828. /**
  829. * mpt_put_msg_frame - Send a protocol-specific MPT request frame to an IOC
  830. * @cb_idx: Handle of registered MPT protocol driver
  831. * @ioc: Pointer to MPT adapter structure
  832. * @mf: Pointer to MPT request frame
  833. *
  834. * This routine posts an MPT request frame to the request post FIFO of a
  835. * specific MPT adapter.
  836. */
  837. void
  838. mpt_put_msg_frame(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  839. {
  840. u32 mf_dma_addr;
  841. int req_offset;
  842. u16 req_idx; /* Request index */
  843. /* ensure values are reset properly! */
  844. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx; /* byte */
  845. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  846. /* u16! */
  847. req_idx = req_offset / ioc->req_sz;
  848. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  849. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  850. DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
  851. mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
  852. dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d "
  853. "RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx,
  854. ioc->RequestNB[req_idx]));
  855. CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
  856. }
  857. /**
  858. * mpt_put_msg_frame_hi_pri - Send a hi-pri protocol-specific MPT request frame
  859. * @cb_idx: Handle of registered MPT protocol driver
  860. * @ioc: Pointer to MPT adapter structure
  861. * @mf: Pointer to MPT request frame
  862. *
  863. * Send a protocol-specific MPT request frame to an IOC using
  864. * hi-priority request queue.
  865. *
  866. * This routine posts an MPT request frame to the request post FIFO of a
  867. * specific MPT adapter.
  868. **/
  869. void
  870. mpt_put_msg_frame_hi_pri(u8 cb_idx, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  871. {
  872. u32 mf_dma_addr;
  873. int req_offset;
  874. u16 req_idx; /* Request index */
  875. /* ensure values are reset properly! */
  876. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
  877. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  878. req_idx = req_offset / ioc->req_sz;
  879. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  880. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  881. DBG_DUMP_PUT_MSG_FRAME(ioc, (u32 *)mf);
  882. mf_dma_addr = (ioc->req_frames_low_dma + req_offset);
  883. dsgprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mf_dma_addr=%x req_idx=%d\n",
  884. ioc->name, mf_dma_addr, req_idx));
  885. CHIPREG_WRITE32(&ioc->chip->RequestHiPriFifo, mf_dma_addr);
  886. }
  887. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  888. /**
  889. * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
  890. * @ioc: Pointer to MPT adapter structure
  891. * @mf: Pointer to MPT request frame
  892. *
  893. * This routine places a MPT request frame back on the MPT adapter's
  894. * FreeQ.
  895. */
  896. void
  897. mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  898. {
  899. unsigned long flags;
  900. /* Put Request back on FreeQ! */
  901. spin_lock_irqsave(&ioc->FreeQlock, flags);
  902. if (cpu_to_le32(mf->u.frame.linkage.arg1) == 0xdeadbeaf)
  903. goto out;
  904. /* signature to know if this mf is freed */
  905. mf->u.frame.linkage.arg1 = cpu_to_le32(0xdeadbeaf);
  906. list_add(&mf->u.frame.linkage.list, &ioc->FreeQ);
  907. #ifdef MFCNT
  908. ioc->mfcnt--;
  909. #endif
  910. out:
  911. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  912. }
  913. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  914. /**
  915. * mpt_add_sge - Place a simple 32 bit SGE at address pAddr.
  916. * @pAddr: virtual address for SGE
  917. * @flagslength: SGE flags and data transfer length
  918. * @dma_addr: Physical address
  919. *
  920. * This routine places a MPT request frame back on the MPT adapter's
  921. * FreeQ.
  922. */
  923. static void
  924. mpt_add_sge(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
  925. {
  926. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  927. pSge->FlagsLength = cpu_to_le32(flagslength);
  928. pSge->Address = cpu_to_le32(dma_addr);
  929. }
  930. /**
  931. * mpt_add_sge_64bit - Place a simple 64 bit SGE at address pAddr.
  932. * @pAddr: virtual address for SGE
  933. * @flagslength: SGE flags and data transfer length
  934. * @dma_addr: Physical address
  935. *
  936. * This routine places a MPT request frame back on the MPT adapter's
  937. * FreeQ.
  938. **/
  939. static void
  940. mpt_add_sge_64bit(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
  941. {
  942. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  943. pSge->Address.Low = cpu_to_le32
  944. (lower_32_bits(dma_addr));
  945. pSge->Address.High = cpu_to_le32
  946. (upper_32_bits(dma_addr));
  947. pSge->FlagsLength = cpu_to_le32
  948. ((flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
  949. }
  950. /**
  951. * mpt_add_sge_64bit_1078 - Place a simple 64 bit SGE at address pAddr (1078 workaround).
  952. * @pAddr: virtual address for SGE
  953. * @flagslength: SGE flags and data transfer length
  954. * @dma_addr: Physical address
  955. *
  956. * This routine places a MPT request frame back on the MPT adapter's
  957. * FreeQ.
  958. **/
  959. static void
  960. mpt_add_sge_64bit_1078(void *pAddr, u32 flagslength, dma_addr_t dma_addr)
  961. {
  962. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  963. u32 tmp;
  964. pSge->Address.Low = cpu_to_le32
  965. (lower_32_bits(dma_addr));
  966. tmp = (u32)(upper_32_bits(dma_addr));
  967. /*
  968. * 1078 errata workaround for the 36GB limitation
  969. */
  970. if ((((u64)dma_addr + MPI_SGE_LENGTH(flagslength)) >> 32) == 9) {
  971. flagslength |=
  972. MPI_SGE_SET_FLAGS(MPI_SGE_FLAGS_LOCAL_ADDRESS);
  973. tmp |= (1<<31);
  974. if (mpt_debug_level & MPT_DEBUG_36GB_MEM)
  975. printk(KERN_DEBUG "1078 P0M2 addressing for "
  976. "addr = 0x%llx len = %d\n",
  977. (unsigned long long)dma_addr,
  978. MPI_SGE_LENGTH(flagslength));
  979. }
  980. pSge->Address.High = cpu_to_le32(tmp);
  981. pSge->FlagsLength = cpu_to_le32(
  982. (flagslength | MPT_SGE_FLAGS_64_BIT_ADDRESSING));
  983. }
  984. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  985. /**
  986. * mpt_add_chain - Place a 32 bit chain SGE at address pAddr.
  987. * @pAddr: virtual address for SGE
  988. * @next: nextChainOffset value (u32's)
  989. * @length: length of next SGL segment
  990. * @dma_addr: Physical address
  991. *
  992. */
  993. static void
  994. mpt_add_chain(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  995. {
  996. SGEChain32_t *pChain = (SGEChain32_t *) pAddr;
  997. pChain->Length = cpu_to_le16(length);
  998. pChain->Flags = MPI_SGE_FLAGS_CHAIN_ELEMENT;
  999. pChain->NextChainOffset = next;
  1000. pChain->Address = cpu_to_le32(dma_addr);
  1001. }
  1002. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1003. /**
  1004. * mpt_add_chain_64bit - Place a 64 bit chain SGE at address pAddr.
  1005. * @pAddr: virtual address for SGE
  1006. * @next: nextChainOffset value (u32's)
  1007. * @length: length of next SGL segment
  1008. * @dma_addr: Physical address
  1009. *
  1010. */
  1011. static void
  1012. mpt_add_chain_64bit(void *pAddr, u8 next, u16 length, dma_addr_t dma_addr)
  1013. {
  1014. SGEChain64_t *pChain = (SGEChain64_t *) pAddr;
  1015. u32 tmp = dma_addr & 0xFFFFFFFF;
  1016. pChain->Length = cpu_to_le16(length);
  1017. pChain->Flags = (MPI_SGE_FLAGS_CHAIN_ELEMENT |
  1018. MPI_SGE_FLAGS_64_BIT_ADDRESSING);
  1019. pChain->NextChainOffset = next;
  1020. pChain->Address.Low = cpu_to_le32(tmp);
  1021. tmp = (u32)(upper_32_bits(dma_addr));
  1022. pChain->Address.High = cpu_to_le32(tmp);
  1023. }
  1024. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1025. /**
  1026. * mpt_send_handshake_request - Send MPT request via doorbell handshake method.
  1027. * @cb_idx: Handle of registered MPT protocol driver
  1028. * @ioc: Pointer to MPT adapter structure
  1029. * @reqBytes: Size of the request in bytes
  1030. * @req: Pointer to MPT request frame
  1031. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  1032. *
  1033. * This routine is used exclusively to send MptScsiTaskMgmt
  1034. * requests since they are required to be sent via doorbell handshake.
  1035. *
  1036. * NOTE: It is the callers responsibility to byte-swap fields in the
  1037. * request which are greater than 1 byte in size.
  1038. *
  1039. * Returns 0 for success, non-zero for failure.
  1040. */
  1041. int
  1042. mpt_send_handshake_request(u8 cb_idx, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
  1043. {
  1044. int r = 0;
  1045. u8 *req_as_bytes;
  1046. int ii;
  1047. /* State is known to be good upon entering
  1048. * this function so issue the bus reset
  1049. * request.
  1050. */
  1051. /*
  1052. * Emulate what mpt_put_msg_frame() does /wrt to sanity
  1053. * setting cb_idx/req_idx. But ONLY if this request
  1054. * is in proper (pre-alloc'd) request buffer range...
  1055. */
  1056. ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
  1057. if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
  1058. MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
  1059. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
  1060. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = cb_idx;
  1061. }
  1062. /* Make sure there are no doorbells */
  1063. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1064. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  1065. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  1066. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  1067. /* Wait for IOC doorbell int */
  1068. if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
  1069. return ii;
  1070. }
  1071. /* Read doorbell and check for active bit */
  1072. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  1073. return -5;
  1074. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "mpt_send_handshake_request start, WaitCnt=%d\n",
  1075. ioc->name, ii));
  1076. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1077. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  1078. return -2;
  1079. }
  1080. /* Send request via doorbell handshake */
  1081. req_as_bytes = (u8 *) req;
  1082. for (ii = 0; ii < reqBytes/4; ii++) {
  1083. u32 word;
  1084. word = ((req_as_bytes[(ii*4) + 0] << 0) |
  1085. (req_as_bytes[(ii*4) + 1] << 8) |
  1086. (req_as_bytes[(ii*4) + 2] << 16) |
  1087. (req_as_bytes[(ii*4) + 3] << 24));
  1088. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  1089. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  1090. r = -3;
  1091. break;
  1092. }
  1093. }
  1094. if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
  1095. r = 0;
  1096. else
  1097. r = -4;
  1098. /* Make sure there are no doorbells */
  1099. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1100. return r;
  1101. }
  1102. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1103. /**
  1104. * mpt_host_page_access_control - control the IOC's Host Page Buffer access
  1105. * @ioc: Pointer to MPT adapter structure
  1106. * @access_control_value: define bits below
  1107. * @sleepFlag: Specifies whether the process can sleep
  1108. *
  1109. * Provides mechanism for the host driver to control the IOC's
  1110. * Host Page Buffer access.
  1111. *
  1112. * Access Control Value - bits[15:12]
  1113. * 0h Reserved
  1114. * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
  1115. * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
  1116. * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
  1117. *
  1118. * Returns 0 for success, non-zero for failure.
  1119. */
  1120. static int
  1121. mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
  1122. {
  1123. int r = 0;
  1124. /* return if in use */
  1125. if (CHIPREG_READ32(&ioc->chip->Doorbell)
  1126. & MPI_DOORBELL_ACTIVE)
  1127. return -1;
  1128. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1129. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  1130. ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
  1131. <<MPI_DOORBELL_FUNCTION_SHIFT) |
  1132. (access_control_value<<12)));
  1133. /* Wait for IOC to clear Doorbell Status bit */
  1134. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  1135. return -2;
  1136. }else
  1137. return 0;
  1138. }
  1139. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1140. /**
  1141. * mpt_host_page_alloc - allocate system memory for the fw
  1142. * @ioc: Pointer to pointer to IOC adapter
  1143. * @ioc_init: Pointer to ioc init config page
  1144. *
  1145. * If we already allocated memory in past, then resend the same pointer.
  1146. * Returns 0 for success, non-zero for failure.
  1147. */
  1148. static int
  1149. mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
  1150. {
  1151. char *psge;
  1152. int flags_length;
  1153. u32 host_page_buffer_sz=0;
  1154. if(!ioc->HostPageBuffer) {
  1155. host_page_buffer_sz =
  1156. le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
  1157. if(!host_page_buffer_sz)
  1158. return 0; /* fw doesn't need any host buffers */
  1159. /* spin till we get enough memory */
  1160. while(host_page_buffer_sz > 0) {
  1161. if((ioc->HostPageBuffer = pci_alloc_consistent(
  1162. ioc->pcidev,
  1163. host_page_buffer_sz,
  1164. &ioc->HostPageBuffer_dma)) != NULL) {
  1165. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  1166. "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
  1167. ioc->name, ioc->HostPageBuffer,
  1168. (u32)ioc->HostPageBuffer_dma,
  1169. host_page_buffer_sz));
  1170. ioc->alloc_total += host_page_buffer_sz;
  1171. ioc->HostPageBuffer_sz = host_page_buffer_sz;
  1172. break;
  1173. }
  1174. host_page_buffer_sz -= (4*1024);
  1175. }
  1176. }
  1177. if(!ioc->HostPageBuffer) {
  1178. printk(MYIOC_s_ERR_FMT
  1179. "Failed to alloc memory for host_page_buffer!\n",
  1180. ioc->name);
  1181. return -999;
  1182. }
  1183. psge = (char *)&ioc_init->HostPageBufferSGE;
  1184. flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
  1185. MPI_SGE_FLAGS_SYSTEM_ADDRESS |
  1186. MPI_SGE_FLAGS_HOST_TO_IOC |
  1187. MPI_SGE_FLAGS_END_OF_BUFFER;
  1188. flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
  1189. flags_length |= ioc->HostPageBuffer_sz;
  1190. ioc->add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
  1191. ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
  1192. return 0;
  1193. }
  1194. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1195. /**
  1196. * mpt_verify_adapter - Given IOC identifier, set pointer to its adapter structure.
  1197. * @iocid: IOC unique identifier (integer)
  1198. * @iocpp: Pointer to pointer to IOC adapter
  1199. *
  1200. * Given a unique IOC identifier, set pointer to the associated MPT
  1201. * adapter structure.
  1202. *
  1203. * Returns iocid and sets iocpp if iocid is found.
  1204. * Returns -1 if iocid is not found.
  1205. */
  1206. int
  1207. mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
  1208. {
  1209. MPT_ADAPTER *ioc;
  1210. list_for_each_entry(ioc,&ioc_list,list) {
  1211. if (ioc->id == iocid) {
  1212. *iocpp =ioc;
  1213. return iocid;
  1214. }
  1215. }
  1216. *iocpp = NULL;
  1217. return -1;
  1218. }
  1219. /**
  1220. * mpt_get_product_name - returns product string
  1221. * @vendor: pci vendor id
  1222. * @device: pci device id
  1223. * @revision: pci revision id
  1224. *
  1225. * Returns product string displayed when driver loads,
  1226. * in /proc/mpt/summary and /sysfs/class/scsi_host/host<X>/version_product
  1227. *
  1228. **/
  1229. static const char*
  1230. mpt_get_product_name(u16 vendor, u16 device, u8 revision)
  1231. {
  1232. char *product_str = NULL;
  1233. if (vendor == PCI_VENDOR_ID_BROCADE) {
  1234. switch (device)
  1235. {
  1236. case MPI_MANUFACTPAGE_DEVICEID_FC949E:
  1237. switch (revision)
  1238. {
  1239. case 0x00:
  1240. product_str = "BRE040 A0";
  1241. break;
  1242. case 0x01:
  1243. product_str = "BRE040 A1";
  1244. break;
  1245. default:
  1246. product_str = "BRE040";
  1247. break;
  1248. }
  1249. break;
  1250. }
  1251. goto out;
  1252. }
  1253. switch (device)
  1254. {
  1255. case MPI_MANUFACTPAGE_DEVICEID_FC909:
  1256. product_str = "LSIFC909 B1";
  1257. break;
  1258. case MPI_MANUFACTPAGE_DEVICEID_FC919:
  1259. product_str = "LSIFC919 B0";
  1260. break;
  1261. case MPI_MANUFACTPAGE_DEVICEID_FC929:
  1262. product_str = "LSIFC929 B0";
  1263. break;
  1264. case MPI_MANUFACTPAGE_DEVICEID_FC919X:
  1265. if (revision < 0x80)
  1266. product_str = "LSIFC919X A0";
  1267. else
  1268. product_str = "LSIFC919XL A1";
  1269. break;
  1270. case MPI_MANUFACTPAGE_DEVICEID_FC929X:
  1271. if (revision < 0x80)
  1272. product_str = "LSIFC929X A0";
  1273. else
  1274. product_str = "LSIFC929XL A1";
  1275. break;
  1276. case MPI_MANUFACTPAGE_DEVICEID_FC939X:
  1277. product_str = "LSIFC939X A1";
  1278. break;
  1279. case MPI_MANUFACTPAGE_DEVICEID_FC949X:
  1280. product_str = "LSIFC949X A1";
  1281. break;
  1282. case MPI_MANUFACTPAGE_DEVICEID_FC949E:
  1283. switch (revision)
  1284. {
  1285. case 0x00:
  1286. product_str = "LSIFC949E A0";
  1287. break;
  1288. case 0x01:
  1289. product_str = "LSIFC949E A1";
  1290. break;
  1291. default:
  1292. product_str = "LSIFC949E";
  1293. break;
  1294. }
  1295. break;
  1296. case MPI_MANUFACTPAGE_DEVID_53C1030:
  1297. switch (revision)
  1298. {
  1299. case 0x00:
  1300. product_str = "LSI53C1030 A0";
  1301. break;
  1302. case 0x01:
  1303. product_str = "LSI53C1030 B0";
  1304. break;
  1305. case 0x03:
  1306. product_str = "LSI53C1030 B1";
  1307. break;
  1308. case 0x07:
  1309. product_str = "LSI53C1030 B2";
  1310. break;
  1311. case 0x08:
  1312. product_str = "LSI53C1030 C0";
  1313. break;
  1314. case 0x80:
  1315. product_str = "LSI53C1030T A0";
  1316. break;
  1317. case 0x83:
  1318. product_str = "LSI53C1030T A2";
  1319. break;
  1320. case 0x87:
  1321. product_str = "LSI53C1030T A3";
  1322. break;
  1323. case 0xc1:
  1324. product_str = "LSI53C1020A A1";
  1325. break;
  1326. default:
  1327. product_str = "LSI53C1030";
  1328. break;
  1329. }
  1330. break;
  1331. case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
  1332. switch (revision)
  1333. {
  1334. case 0x03:
  1335. product_str = "LSI53C1035 A2";
  1336. break;
  1337. case 0x04:
  1338. product_str = "LSI53C1035 B0";
  1339. break;
  1340. default:
  1341. product_str = "LSI53C1035";
  1342. break;
  1343. }
  1344. break;
  1345. case MPI_MANUFACTPAGE_DEVID_SAS1064:
  1346. switch (revision)
  1347. {
  1348. case 0x00:
  1349. product_str = "LSISAS1064 A1";
  1350. break;
  1351. case 0x01:
  1352. product_str = "LSISAS1064 A2";
  1353. break;
  1354. case 0x02:
  1355. product_str = "LSISAS1064 A3";
  1356. break;
  1357. case 0x03:
  1358. product_str = "LSISAS1064 A4";
  1359. break;
  1360. default:
  1361. product_str = "LSISAS1064";
  1362. break;
  1363. }
  1364. break;
  1365. case MPI_MANUFACTPAGE_DEVID_SAS1064E:
  1366. switch (revision)
  1367. {
  1368. case 0x00:
  1369. product_str = "LSISAS1064E A0";
  1370. break;
  1371. case 0x01:
  1372. product_str = "LSISAS1064E B0";
  1373. break;
  1374. case 0x02:
  1375. product_str = "LSISAS1064E B1";
  1376. break;
  1377. case 0x04:
  1378. product_str = "LSISAS1064E B2";
  1379. break;
  1380. case 0x08:
  1381. product_str = "LSISAS1064E B3";
  1382. break;
  1383. default:
  1384. product_str = "LSISAS1064E";
  1385. break;
  1386. }
  1387. break;
  1388. case MPI_MANUFACTPAGE_DEVID_SAS1068:
  1389. switch (revision)
  1390. {
  1391. case 0x00:
  1392. product_str = "LSISAS1068 A0";
  1393. break;
  1394. case 0x01:
  1395. product_str = "LSISAS1068 B0";
  1396. break;
  1397. case 0x02:
  1398. product_str = "LSISAS1068 B1";
  1399. break;
  1400. default:
  1401. product_str = "LSISAS1068";
  1402. break;
  1403. }
  1404. break;
  1405. case MPI_MANUFACTPAGE_DEVID_SAS1068E:
  1406. switch (revision)
  1407. {
  1408. case 0x00:
  1409. product_str = "LSISAS1068E A0";
  1410. break;
  1411. case 0x01:
  1412. product_str = "LSISAS1068E B0";
  1413. break;
  1414. case 0x02:
  1415. product_str = "LSISAS1068E B1";
  1416. break;
  1417. case 0x04:
  1418. product_str = "LSISAS1068E B2";
  1419. break;
  1420. case 0x08:
  1421. product_str = "LSISAS1068E B3";
  1422. break;
  1423. default:
  1424. product_str = "LSISAS1068E";
  1425. break;
  1426. }
  1427. break;
  1428. case MPI_MANUFACTPAGE_DEVID_SAS1078:
  1429. switch (revision)
  1430. {
  1431. case 0x00:
  1432. product_str = "LSISAS1078 A0";
  1433. break;
  1434. case 0x01:
  1435. product_str = "LSISAS1078 B0";
  1436. break;
  1437. case 0x02:
  1438. product_str = "LSISAS1078 C0";
  1439. break;
  1440. case 0x03:
  1441. product_str = "LSISAS1078 C1";
  1442. break;
  1443. case 0x04:
  1444. product_str = "LSISAS1078 C2";
  1445. break;
  1446. default:
  1447. product_str = "LSISAS1078";
  1448. break;
  1449. }
  1450. break;
  1451. }
  1452. out:
  1453. return product_str;
  1454. }
  1455. /**
  1456. * mpt_mapresources - map in memory mapped io
  1457. * @ioc: Pointer to pointer to IOC adapter
  1458. *
  1459. **/
  1460. static int
  1461. mpt_mapresources(MPT_ADAPTER *ioc)
  1462. {
  1463. u8 __iomem *mem;
  1464. int ii;
  1465. resource_size_t mem_phys;
  1466. unsigned long port;
  1467. u32 msize;
  1468. u32 psize;
  1469. int r = -ENODEV;
  1470. struct pci_dev *pdev;
  1471. pdev = ioc->pcidev;
  1472. ioc->bars = pci_select_bars(pdev, IORESOURCE_MEM);
  1473. if (pci_enable_device_mem(pdev)) {
  1474. printk(MYIOC_s_ERR_FMT "pci_enable_device_mem() "
  1475. "failed\n", ioc->name);
  1476. return r;
  1477. }
  1478. if (pci_request_selected_regions(pdev, ioc->bars, "mpt")) {
  1479. printk(MYIOC_s_ERR_FMT "pci_request_selected_regions() with "
  1480. "MEM failed\n", ioc->name);
  1481. goto out_pci_disable_device;
  1482. }
  1483. if (sizeof(dma_addr_t) > 4) {
  1484. const uint64_t required_mask = dma_get_required_mask
  1485. (&pdev->dev);
  1486. if (required_mask > DMA_BIT_MASK(32)
  1487. && !pci_set_dma_mask(pdev, DMA_BIT_MASK(64))
  1488. && !pci_set_consistent_dma_mask(pdev,
  1489. DMA_BIT_MASK(64))) {
  1490. ioc->dma_mask = DMA_BIT_MASK(64);
  1491. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  1492. ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
  1493. ioc->name));
  1494. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
  1495. && !pci_set_consistent_dma_mask(pdev,
  1496. DMA_BIT_MASK(32))) {
  1497. ioc->dma_mask = DMA_BIT_MASK(32);
  1498. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  1499. ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
  1500. ioc->name));
  1501. } else {
  1502. printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
  1503. ioc->name, pci_name(pdev));
  1504. goto out_pci_release_region;
  1505. }
  1506. } else {
  1507. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))
  1508. && !pci_set_consistent_dma_mask(pdev,
  1509. DMA_BIT_MASK(32))) {
  1510. ioc->dma_mask = DMA_BIT_MASK(32);
  1511. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  1512. ": 32 BIT PCI BUS DMA ADDRESSING SUPPORTED\n",
  1513. ioc->name));
  1514. } else {
  1515. printk(MYIOC_s_WARN_FMT "no suitable DMA mask for %s\n",
  1516. ioc->name, pci_name(pdev));
  1517. goto out_pci_release_region;
  1518. }
  1519. }
  1520. mem_phys = msize = 0;
  1521. port = psize = 0;
  1522. for (ii = 0; ii < DEVICE_COUNT_RESOURCE; ii++) {
  1523. if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
  1524. if (psize)
  1525. continue;
  1526. /* Get I/O space! */
  1527. port = pci_resource_start(pdev, ii);
  1528. psize = pci_resource_len(pdev, ii);
  1529. } else {
  1530. if (msize)
  1531. continue;
  1532. /* Get memmap */
  1533. mem_phys = pci_resource_start(pdev, ii);
  1534. msize = pci_resource_len(pdev, ii);
  1535. }
  1536. }
  1537. ioc->mem_size = msize;
  1538. mem = NULL;
  1539. /* Get logical ptr for PciMem0 space */
  1540. /*mem = ioremap(mem_phys, msize);*/
  1541. mem = ioremap(mem_phys, msize);
  1542. if (mem == NULL) {
  1543. printk(MYIOC_s_ERR_FMT ": ERROR - Unable to map adapter"
  1544. " memory!\n", ioc->name);
  1545. r = -EINVAL;
  1546. goto out_pci_release_region;
  1547. }
  1548. ioc->memmap = mem;
  1549. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "mem = %p, mem_phys = %llx\n",
  1550. ioc->name, mem, (unsigned long long)mem_phys));
  1551. ioc->mem_phys = mem_phys;
  1552. ioc->chip = (SYSIF_REGS __iomem *)mem;
  1553. /* Save Port IO values in case we need to do downloadboot */
  1554. ioc->pio_mem_phys = port;
  1555. ioc->pio_chip = (SYSIF_REGS __iomem *)port;
  1556. return 0;
  1557. out_pci_release_region:
  1558. pci_release_selected_regions(pdev, ioc->bars);
  1559. out_pci_disable_device:
  1560. pci_disable_device(pdev);
  1561. return r;
  1562. }
  1563. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1564. /**
  1565. * mpt_attach - Install a PCI intelligent MPT adapter.
  1566. * @pdev: Pointer to pci_dev structure
  1567. * @id: PCI device ID information
  1568. *
  1569. * This routine performs all the steps necessary to bring the IOC of
  1570. * a MPT adapter to a OPERATIONAL state. This includes registering
  1571. * memory regions, registering the interrupt, and allocating request
  1572. * and reply memory pools.
  1573. *
  1574. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  1575. * MPT adapter.
  1576. *
  1577. * Returns 0 for success, non-zero for failure.
  1578. *
  1579. * TODO: Add support for polled controllers
  1580. */
  1581. int
  1582. mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  1583. {
  1584. MPT_ADAPTER *ioc;
  1585. u8 cb_idx;
  1586. int r = -ENODEV;
  1587. u8 pcixcmd;
  1588. static int mpt_ids = 0;
  1589. #ifdef CONFIG_PROC_FS
  1590. struct proc_dir_entry *dent;
  1591. #endif
  1592. ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_KERNEL);
  1593. if (ioc == NULL) {
  1594. printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
  1595. return -ENOMEM;
  1596. }
  1597. ioc->id = mpt_ids++;
  1598. sprintf(ioc->name, "ioc%d", ioc->id);
  1599. dinitprintk(ioc, printk(KERN_WARNING MYNAM ": mpt_adapter_install\n"));
  1600. /*
  1601. * set initial debug level
  1602. * (refer to mptdebug.h)
  1603. *
  1604. */
  1605. ioc->debug_level = mpt_debug_level;
  1606. if (mpt_debug_level)
  1607. printk(KERN_INFO "mpt_debug_level=%xh\n", mpt_debug_level);
  1608. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": mpt_adapter_install\n", ioc->name));
  1609. ioc->pcidev = pdev;
  1610. if (mpt_mapresources(ioc)) {
  1611. goto out_free_ioc;
  1612. }
  1613. /*
  1614. * Setting up proper handlers for scatter gather handling
  1615. */
  1616. if (ioc->dma_mask == DMA_BIT_MASK(64)) {
  1617. if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
  1618. ioc->add_sge = &mpt_add_sge_64bit_1078;
  1619. else
  1620. ioc->add_sge = &mpt_add_sge_64bit;
  1621. ioc->add_chain = &mpt_add_chain_64bit;
  1622. ioc->sg_addr_size = 8;
  1623. } else {
  1624. ioc->add_sge = &mpt_add_sge;
  1625. ioc->add_chain = &mpt_add_chain;
  1626. ioc->sg_addr_size = 4;
  1627. }
  1628. ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
  1629. ioc->alloc_total = sizeof(MPT_ADAPTER);
  1630. ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
  1631. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  1632. spin_lock_init(&ioc->taskmgmt_lock);
  1633. mutex_init(&ioc->internal_cmds.mutex);
  1634. init_completion(&ioc->internal_cmds.done);
  1635. mutex_init(&ioc->mptbase_cmds.mutex);
  1636. init_completion(&ioc->mptbase_cmds.done);
  1637. mutex_init(&ioc->taskmgmt_cmds.mutex);
  1638. init_completion(&ioc->taskmgmt_cmds.done);
  1639. /* Initialize the event logging.
  1640. */
  1641. ioc->eventTypes = 0; /* None */
  1642. ioc->eventContext = 0;
  1643. ioc->eventLogSize = 0;
  1644. ioc->events = NULL;
  1645. #ifdef MFCNT
  1646. ioc->mfcnt = 0;
  1647. #endif
  1648. ioc->sh = NULL;
  1649. ioc->cached_fw = NULL;
  1650. /* Initialize SCSI Config Data structure
  1651. */
  1652. memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
  1653. /* Initialize the fc rport list head.
  1654. */
  1655. INIT_LIST_HEAD(&ioc->fc_rports);
  1656. /* Find lookup slot. */
  1657. INIT_LIST_HEAD(&ioc->list);
  1658. /* Initialize workqueue */
  1659. INIT_DELAYED_WORK(&ioc->fault_reset_work, mpt_fault_reset_work);
  1660. snprintf(ioc->reset_work_q_name, MPT_KOBJ_NAME_LEN,
  1661. "mpt_poll_%d", ioc->id);
  1662. ioc->reset_work_q = alloc_workqueue(ioc->reset_work_q_name,
  1663. WQ_MEM_RECLAIM, 0);
  1664. if (!ioc->reset_work_q) {
  1665. printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
  1666. ioc->name);
  1667. r = -ENOMEM;
  1668. goto out_unmap_resources;
  1669. }
  1670. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "facts @ %p, pfacts[0] @ %p\n",
  1671. ioc->name, &ioc->facts, &ioc->pfacts[0]));
  1672. ioc->prod_name = mpt_get_product_name(pdev->vendor, pdev->device,
  1673. pdev->revision);
  1674. switch (pdev->device)
  1675. {
  1676. case MPI_MANUFACTPAGE_DEVICEID_FC939X:
  1677. case MPI_MANUFACTPAGE_DEVICEID_FC949X:
  1678. ioc->errata_flag_1064 = 1;
  1679. /* fall through */
  1680. case MPI_MANUFACTPAGE_DEVICEID_FC909:
  1681. case MPI_MANUFACTPAGE_DEVICEID_FC929:
  1682. case MPI_MANUFACTPAGE_DEVICEID_FC919:
  1683. case MPI_MANUFACTPAGE_DEVICEID_FC949E:
  1684. ioc->bus_type = FC;
  1685. break;
  1686. case MPI_MANUFACTPAGE_DEVICEID_FC929X:
  1687. if (pdev->revision < XL_929) {
  1688. /* 929X Chip Fix. Set Split transactions level
  1689. * for PCIX. Set MOST bits to zero.
  1690. */
  1691. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1692. pcixcmd &= 0x8F;
  1693. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1694. } else {
  1695. /* 929XL Chip Fix. Set MMRBC to 0x08.
  1696. */
  1697. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1698. pcixcmd |= 0x08;
  1699. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1700. }
  1701. ioc->bus_type = FC;
  1702. break;
  1703. case MPI_MANUFACTPAGE_DEVICEID_FC919X:
  1704. /* 919X Chip Fix. Set Split transactions level
  1705. * for PCIX. Set MOST bits to zero.
  1706. */
  1707. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1708. pcixcmd &= 0x8F;
  1709. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1710. ioc->bus_type = FC;
  1711. break;
  1712. case MPI_MANUFACTPAGE_DEVID_53C1030:
  1713. /* 1030 Chip Fix. Disable Split transactions
  1714. * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
  1715. */
  1716. if (pdev->revision < C0_1030) {
  1717. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1718. pcixcmd &= 0x8F;
  1719. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1720. }
  1721. /* fall through */
  1722. case MPI_MANUFACTPAGE_DEVID_1030_53C1035:
  1723. ioc->bus_type = SPI;
  1724. break;
  1725. case MPI_MANUFACTPAGE_DEVID_SAS1064:
  1726. case MPI_MANUFACTPAGE_DEVID_SAS1068:
  1727. ioc->errata_flag_1064 = 1;
  1728. ioc->bus_type = SAS;
  1729. break;
  1730. case MPI_MANUFACTPAGE_DEVID_SAS1064E:
  1731. case MPI_MANUFACTPAGE_DEVID_SAS1068E:
  1732. case MPI_MANUFACTPAGE_DEVID_SAS1078:
  1733. ioc->bus_type = SAS;
  1734. break;
  1735. }
  1736. switch (ioc->bus_type) {
  1737. case SAS:
  1738. ioc->msi_enable = mpt_msi_enable_sas;
  1739. break;
  1740. case SPI:
  1741. ioc->msi_enable = mpt_msi_enable_spi;
  1742. break;
  1743. case FC:
  1744. ioc->msi_enable = mpt_msi_enable_fc;
  1745. break;
  1746. default:
  1747. ioc->msi_enable = 0;
  1748. break;
  1749. }
  1750. ioc->fw_events_off = 1;
  1751. if (ioc->errata_flag_1064)
  1752. pci_disable_io_access(pdev);
  1753. spin_lock_init(&ioc->FreeQlock);
  1754. /* Disable all! */
  1755. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1756. ioc->active = 0;
  1757. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1758. /* Set IOC ptr in the pcidev's driver data. */
  1759. pci_set_drvdata(ioc->pcidev, ioc);
  1760. /* Set lookup ptr. */
  1761. list_add_tail(&ioc->list, &ioc_list);
  1762. /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
  1763. */
  1764. mpt_detect_bound_ports(ioc, pdev);
  1765. INIT_LIST_HEAD(&ioc->fw_event_list);
  1766. spin_lock_init(&ioc->fw_event_lock);
  1767. snprintf(ioc->fw_event_q_name, MPT_KOBJ_NAME_LEN, "mpt/%d", ioc->id);
  1768. ioc->fw_event_q = alloc_workqueue(ioc->fw_event_q_name,
  1769. WQ_MEM_RECLAIM, 0);
  1770. if (!ioc->fw_event_q) {
  1771. printk(MYIOC_s_ERR_FMT "Insufficient memory to add adapter!\n",
  1772. ioc->name);
  1773. r = -ENOMEM;
  1774. goto out_remove_ioc;
  1775. }
  1776. if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
  1777. CAN_SLEEP)) != 0){
  1778. printk(MYIOC_s_ERR_FMT "didn't initialize properly! (%d)\n",
  1779. ioc->name, r);
  1780. destroy_workqueue(ioc->fw_event_q);
  1781. ioc->fw_event_q = NULL;
  1782. list_del(&ioc->list);
  1783. if (ioc->alt_ioc)
  1784. ioc->alt_ioc->alt_ioc = NULL;
  1785. iounmap(ioc->memmap);
  1786. if (pci_is_enabled(pdev))
  1787. pci_disable_device(pdev);
  1788. if (r != -5)
  1789. pci_release_selected_regions(pdev, ioc->bars);
  1790. destroy_workqueue(ioc->reset_work_q);
  1791. ioc->reset_work_q = NULL;
  1792. kfree(ioc);
  1793. return r;
  1794. }
  1795. /* call per device driver probe entry point */
  1796. for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
  1797. if(MptDeviceDriverHandlers[cb_idx] &&
  1798. MptDeviceDriverHandlers[cb_idx]->probe) {
  1799. MptDeviceDriverHandlers[cb_idx]->probe(pdev,id);
  1800. }
  1801. }
  1802. #ifdef CONFIG_PROC_FS
  1803. /*
  1804. * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
  1805. */
  1806. dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
  1807. if (dent) {
  1808. proc_create_single_data("info", S_IRUGO, dent,
  1809. mpt_iocinfo_proc_show, ioc);
  1810. proc_create_single_data("summary", S_IRUGO, dent,
  1811. mpt_summary_proc_show, ioc);
  1812. }
  1813. #endif
  1814. if (!ioc->alt_ioc)
  1815. queue_delayed_work(ioc->reset_work_q, &ioc->fault_reset_work,
  1816. msecs_to_jiffies(MPT_POLLING_INTERVAL));
  1817. return 0;
  1818. out_remove_ioc:
  1819. list_del(&ioc->list);
  1820. if (ioc->alt_ioc)
  1821. ioc->alt_ioc->alt_ioc = NULL;
  1822. destroy_workqueue(ioc->reset_work_q);
  1823. ioc->reset_work_q = NULL;
  1824. out_unmap_resources:
  1825. iounmap(ioc->memmap);
  1826. pci_disable_device(pdev);
  1827. pci_release_selected_regions(pdev, ioc->bars);
  1828. out_free_ioc:
  1829. kfree(ioc);
  1830. return r;
  1831. }
  1832. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1833. /**
  1834. * mpt_detach - Remove a PCI intelligent MPT adapter.
  1835. * @pdev: Pointer to pci_dev structure
  1836. */
  1837. void
  1838. mpt_detach(struct pci_dev *pdev)
  1839. {
  1840. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1841. char pname[64];
  1842. u8 cb_idx;
  1843. unsigned long flags;
  1844. struct workqueue_struct *wq;
  1845. /*
  1846. * Stop polling ioc for fault condition
  1847. */
  1848. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  1849. wq = ioc->reset_work_q;
  1850. ioc->reset_work_q = NULL;
  1851. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  1852. cancel_delayed_work(&ioc->fault_reset_work);
  1853. destroy_workqueue(wq);
  1854. spin_lock_irqsave(&ioc->fw_event_lock, flags);
  1855. wq = ioc->fw_event_q;
  1856. ioc->fw_event_q = NULL;
  1857. spin_unlock_irqrestore(&ioc->fw_event_lock, flags);
  1858. destroy_workqueue(wq);
  1859. snprintf(pname, sizeof(pname), MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
  1860. remove_proc_entry(pname, NULL);
  1861. snprintf(pname, sizeof(pname), MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
  1862. remove_proc_entry(pname, NULL);
  1863. snprintf(pname, sizeof(pname), MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
  1864. remove_proc_entry(pname, NULL);
  1865. /* call per device driver remove entry point */
  1866. for(cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
  1867. if(MptDeviceDriverHandlers[cb_idx] &&
  1868. MptDeviceDriverHandlers[cb_idx]->remove) {
  1869. MptDeviceDriverHandlers[cb_idx]->remove(pdev);
  1870. }
  1871. }
  1872. /* Disable interrupts! */
  1873. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1874. ioc->active = 0;
  1875. synchronize_irq(pdev->irq);
  1876. /* Clear any lingering interrupt */
  1877. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1878. CHIPREG_READ32(&ioc->chip->IntStatus);
  1879. mpt_adapter_dispose(ioc);
  1880. }
  1881. /**************************************************************************
  1882. * Power Management
  1883. */
  1884. #ifdef CONFIG_PM
  1885. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1886. /**
  1887. * mpt_suspend - Fusion MPT base driver suspend routine.
  1888. * @pdev: Pointer to pci_dev structure
  1889. * @state: new state to enter
  1890. */
  1891. int
  1892. mpt_suspend(struct pci_dev *pdev, pm_message_t state)
  1893. {
  1894. u32 device_state;
  1895. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1896. device_state = pci_choose_state(pdev, state);
  1897. printk(MYIOC_s_INFO_FMT "pci-suspend: pdev=0x%p, slot=%s, Entering "
  1898. "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
  1899. device_state);
  1900. /* put ioc into READY_STATE */
  1901. if (SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
  1902. printk(MYIOC_s_ERR_FMT
  1903. "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
  1904. }
  1905. /* disable interrupts */
  1906. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1907. ioc->active = 0;
  1908. /* Clear any lingering interrupt */
  1909. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1910. free_irq(ioc->pci_irq, ioc);
  1911. if (ioc->msi_enable)
  1912. pci_disable_msi(ioc->pcidev);
  1913. ioc->pci_irq = -1;
  1914. pci_save_state(pdev);
  1915. pci_disable_device(pdev);
  1916. pci_release_selected_regions(pdev, ioc->bars);
  1917. pci_set_power_state(pdev, device_state);
  1918. return 0;
  1919. }
  1920. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1921. /**
  1922. * mpt_resume - Fusion MPT base driver resume routine.
  1923. * @pdev: Pointer to pci_dev structure
  1924. */
  1925. int
  1926. mpt_resume(struct pci_dev *pdev)
  1927. {
  1928. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1929. u32 device_state = pdev->current_state;
  1930. int recovery_state;
  1931. int err;
  1932. printk(MYIOC_s_INFO_FMT "pci-resume: pdev=0x%p, slot=%s, Previous "
  1933. "operating state [D%d]\n", ioc->name, pdev, pci_name(pdev),
  1934. device_state);
  1935. pci_set_power_state(pdev, PCI_D0);
  1936. pci_enable_wake(pdev, PCI_D0, 0);
  1937. pci_restore_state(pdev);
  1938. ioc->pcidev = pdev;
  1939. err = mpt_mapresources(ioc);
  1940. if (err)
  1941. return err;
  1942. if (ioc->dma_mask == DMA_BIT_MASK(64)) {
  1943. if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078)
  1944. ioc->add_sge = &mpt_add_sge_64bit_1078;
  1945. else
  1946. ioc->add_sge = &mpt_add_sge_64bit;
  1947. ioc->add_chain = &mpt_add_chain_64bit;
  1948. ioc->sg_addr_size = 8;
  1949. } else {
  1950. ioc->add_sge = &mpt_add_sge;
  1951. ioc->add_chain = &mpt_add_chain;
  1952. ioc->sg_addr_size = 4;
  1953. }
  1954. ioc->SGE_size = sizeof(u32) + ioc->sg_addr_size;
  1955. printk(MYIOC_s_INFO_FMT "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
  1956. ioc->name, (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
  1957. CHIPREG_READ32(&ioc->chip->Doorbell));
  1958. /*
  1959. * Errata workaround for SAS pci express:
  1960. * Upon returning to the D0 state, the contents of the doorbell will be
  1961. * stale data, and this will incorrectly signal to the host driver that
  1962. * the firmware is ready to process mpt commands. The workaround is
  1963. * to issue a diagnostic reset.
  1964. */
  1965. if (ioc->bus_type == SAS && (pdev->device ==
  1966. MPI_MANUFACTPAGE_DEVID_SAS1068E || pdev->device ==
  1967. MPI_MANUFACTPAGE_DEVID_SAS1064E)) {
  1968. if (KickStart(ioc, 1, CAN_SLEEP) < 0) {
  1969. printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover\n",
  1970. ioc->name);
  1971. goto out;
  1972. }
  1973. }
  1974. /* bring ioc to operational state */
  1975. printk(MYIOC_s_INFO_FMT "Sending mpt_do_ioc_recovery\n", ioc->name);
  1976. recovery_state = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
  1977. CAN_SLEEP);
  1978. if (recovery_state != 0)
  1979. printk(MYIOC_s_WARN_FMT "pci-resume: Cannot recover, "
  1980. "error:[%x]\n", ioc->name, recovery_state);
  1981. else
  1982. printk(MYIOC_s_INFO_FMT
  1983. "pci-resume: success\n", ioc->name);
  1984. out:
  1985. return 0;
  1986. }
  1987. #endif
  1988. static int
  1989. mpt_signal_reset(u8 index, MPT_ADAPTER *ioc, int reset_phase)
  1990. {
  1991. if ((MptDriverClass[index] == MPTSPI_DRIVER &&
  1992. ioc->bus_type != SPI) ||
  1993. (MptDriverClass[index] == MPTFC_DRIVER &&
  1994. ioc->bus_type != FC) ||
  1995. (MptDriverClass[index] == MPTSAS_DRIVER &&
  1996. ioc->bus_type != SAS))
  1997. /* make sure we only call the relevant reset handler
  1998. * for the bus */
  1999. return 0;
  2000. return (MptResetHandlers[index])(ioc, reset_phase);
  2001. }
  2002. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2003. /**
  2004. * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
  2005. * @ioc: Pointer to MPT adapter structure
  2006. * @reason: Event word / reason
  2007. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  2008. *
  2009. * This routine performs all the steps necessary to bring the IOC
  2010. * to a OPERATIONAL state.
  2011. *
  2012. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  2013. * MPT adapter.
  2014. *
  2015. * Returns:
  2016. * 0 for success
  2017. * -1 if failed to get board READY
  2018. * -2 if READY but IOCFacts Failed
  2019. * -3 if READY but PrimeIOCFifos Failed
  2020. * -4 if READY but IOCInit Failed
  2021. * -5 if failed to enable_device and/or request_selected_regions
  2022. * -6 if failed to upload firmware
  2023. */
  2024. static int
  2025. mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
  2026. {
  2027. int hard_reset_done = 0;
  2028. int alt_ioc_ready = 0;
  2029. int hard;
  2030. int rc=0;
  2031. int ii;
  2032. int ret = 0;
  2033. int reset_alt_ioc_active = 0;
  2034. int irq_allocated = 0;
  2035. u8 *a;
  2036. printk(MYIOC_s_INFO_FMT "Initiating %s\n", ioc->name,
  2037. reason == MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
  2038. /* Disable reply interrupts (also blocks FreeQ) */
  2039. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  2040. ioc->active = 0;
  2041. if (ioc->alt_ioc) {
  2042. if (ioc->alt_ioc->active ||
  2043. reason == MPT_HOSTEVENT_IOC_RECOVER) {
  2044. reset_alt_ioc_active = 1;
  2045. /* Disable alt-IOC's reply interrupts
  2046. * (and FreeQ) for a bit
  2047. **/
  2048. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
  2049. 0xFFFFFFFF);
  2050. ioc->alt_ioc->active = 0;
  2051. }
  2052. }
  2053. hard = 1;
  2054. if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
  2055. hard = 0;
  2056. if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
  2057. if (hard_reset_done == -4) {
  2058. printk(MYIOC_s_WARN_FMT "Owned by PEER..skipping!\n",
  2059. ioc->name);
  2060. if (reset_alt_ioc_active && ioc->alt_ioc) {
  2061. /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
  2062. dprintk(ioc, printk(MYIOC_s_INFO_FMT
  2063. "alt_ioc reply irq re-enabled\n", ioc->alt_ioc->name));
  2064. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
  2065. ioc->alt_ioc->active = 1;
  2066. }
  2067. } else {
  2068. printk(MYIOC_s_WARN_FMT
  2069. "NOT READY WARNING!\n", ioc->name);
  2070. }
  2071. ret = -1;
  2072. goto out;
  2073. }
  2074. /* hard_reset_done = 0 if a soft reset was performed
  2075. * and 1 if a hard reset was performed.
  2076. */
  2077. if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
  2078. if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
  2079. alt_ioc_ready = 1;
  2080. else
  2081. printk(MYIOC_s_WARN_FMT
  2082. ": alt-ioc Not ready WARNING!\n",
  2083. ioc->alt_ioc->name);
  2084. }
  2085. for (ii=0; ii<5; ii++) {
  2086. /* Get IOC facts! Allow 5 retries */
  2087. if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
  2088. break;
  2089. }
  2090. if (ii == 5) {
  2091. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2092. "Retry IocFacts failed rc=%x\n", ioc->name, rc));
  2093. ret = -2;
  2094. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2095. MptDisplayIocCapabilities(ioc);
  2096. }
  2097. if (alt_ioc_ready) {
  2098. if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
  2099. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2100. "Initial Alt IocFacts failed rc=%x\n",
  2101. ioc->name, rc));
  2102. /* Retry - alt IOC was initialized once
  2103. */
  2104. rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
  2105. }
  2106. if (rc) {
  2107. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2108. "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
  2109. alt_ioc_ready = 0;
  2110. reset_alt_ioc_active = 0;
  2111. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2112. MptDisplayIocCapabilities(ioc->alt_ioc);
  2113. }
  2114. }
  2115. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP) &&
  2116. (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)) {
  2117. pci_release_selected_regions(ioc->pcidev, ioc->bars);
  2118. ioc->bars = pci_select_bars(ioc->pcidev, IORESOURCE_MEM |
  2119. IORESOURCE_IO);
  2120. if (pci_enable_device(ioc->pcidev))
  2121. return -5;
  2122. if (pci_request_selected_regions(ioc->pcidev, ioc->bars,
  2123. "mpt"))
  2124. return -5;
  2125. }
  2126. /*
  2127. * Device is reset now. It must have de-asserted the interrupt line
  2128. * (if it was asserted) and it should be safe to register for the
  2129. * interrupt now.
  2130. */
  2131. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  2132. ioc->pci_irq = -1;
  2133. if (ioc->pcidev->irq) {
  2134. if (ioc->msi_enable && !pci_enable_msi(ioc->pcidev))
  2135. printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
  2136. ioc->name);
  2137. else
  2138. ioc->msi_enable = 0;
  2139. rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
  2140. IRQF_SHARED, ioc->name, ioc);
  2141. if (rc < 0) {
  2142. printk(MYIOC_s_ERR_FMT "Unable to allocate "
  2143. "interrupt %d!\n",
  2144. ioc->name, ioc->pcidev->irq);
  2145. if (ioc->msi_enable)
  2146. pci_disable_msi(ioc->pcidev);
  2147. ret = -EBUSY;
  2148. goto out;
  2149. }
  2150. irq_allocated = 1;
  2151. ioc->pci_irq = ioc->pcidev->irq;
  2152. pci_set_master(ioc->pcidev); /* ?? */
  2153. pci_set_drvdata(ioc->pcidev, ioc);
  2154. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2155. "installed at interrupt %d\n", ioc->name,
  2156. ioc->pcidev->irq));
  2157. }
  2158. }
  2159. /* Prime reply & request queues!
  2160. * (mucho alloc's) Must be done prior to
  2161. * init as upper addresses are needed for init.
  2162. * If fails, continue with alt-ioc processing
  2163. */
  2164. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "PrimeIocFifos\n",
  2165. ioc->name));
  2166. if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
  2167. ret = -3;
  2168. /* May need to check/upload firmware & data here!
  2169. * If fails, continue with alt-ioc processing
  2170. */
  2171. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT "SendIocInit\n",
  2172. ioc->name));
  2173. if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
  2174. ret = -4;
  2175. // NEW!
  2176. if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
  2177. printk(MYIOC_s_WARN_FMT
  2178. ": alt-ioc (%d) FIFO mgmt alloc WARNING!\n",
  2179. ioc->alt_ioc->name, rc);
  2180. alt_ioc_ready = 0;
  2181. reset_alt_ioc_active = 0;
  2182. }
  2183. if (alt_ioc_ready) {
  2184. if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
  2185. alt_ioc_ready = 0;
  2186. reset_alt_ioc_active = 0;
  2187. printk(MYIOC_s_WARN_FMT
  2188. ": alt-ioc: (%d) init failure WARNING!\n",
  2189. ioc->alt_ioc->name, rc);
  2190. }
  2191. }
  2192. if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
  2193. if (ioc->upload_fw) {
  2194. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2195. "firmware upload required!\n", ioc->name));
  2196. /* Controller is not operational, cannot do upload
  2197. */
  2198. if (ret == 0) {
  2199. rc = mpt_do_upload(ioc, sleepFlag);
  2200. if (rc == 0) {
  2201. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  2202. /*
  2203. * Maintain only one pointer to FW memory
  2204. * so there will not be two attempt to
  2205. * downloadboot onboard dual function
  2206. * chips (mpt_adapter_disable,
  2207. * mpt_diag_reset)
  2208. */
  2209. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2210. "mpt_upload: alt_%s has cached_fw=%p \n",
  2211. ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
  2212. ioc->cached_fw = NULL;
  2213. }
  2214. } else {
  2215. printk(MYIOC_s_WARN_FMT
  2216. "firmware upload failure!\n", ioc->name);
  2217. ret = -6;
  2218. }
  2219. }
  2220. }
  2221. }
  2222. /* Enable MPT base driver management of EventNotification
  2223. * and EventAck handling.
  2224. */
  2225. if ((ret == 0) && (!ioc->facts.EventState)) {
  2226. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2227. "SendEventNotification\n",
  2228. ioc->name));
  2229. ret = SendEventNotification(ioc, 1, sleepFlag); /* 1=Enable */
  2230. }
  2231. if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
  2232. rc = SendEventNotification(ioc->alt_ioc, 1, sleepFlag);
  2233. if (ret == 0) {
  2234. /* Enable! (reply interrupt) */
  2235. CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
  2236. ioc->active = 1;
  2237. }
  2238. if (rc == 0) { /* alt ioc */
  2239. if (reset_alt_ioc_active && ioc->alt_ioc) {
  2240. /* (re)Enable alt-IOC! (reply interrupt) */
  2241. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "alt-ioc"
  2242. "reply irq re-enabled\n",
  2243. ioc->alt_ioc->name));
  2244. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask,
  2245. MPI_HIM_DIM);
  2246. ioc->alt_ioc->active = 1;
  2247. }
  2248. }
  2249. /* Add additional "reason" check before call to GetLanConfigPages
  2250. * (combined with GetIoUnitPage2 call). This prevents a somewhat
  2251. * recursive scenario; GetLanConfigPages times out, timer expired
  2252. * routine calls HardResetHandler, which calls into here again,
  2253. * and we try GetLanConfigPages again...
  2254. */
  2255. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  2256. /*
  2257. * Initialize link list for inactive raid volumes.
  2258. */
  2259. mutex_init(&ioc->raid_data.inactive_list_mutex);
  2260. INIT_LIST_HEAD(&ioc->raid_data.inactive_list);
  2261. switch (ioc->bus_type) {
  2262. case SAS:
  2263. /* clear persistency table */
  2264. if(ioc->facts.IOCExceptions &
  2265. MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
  2266. ret = mptbase_sas_persist_operation(ioc,
  2267. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  2268. if(ret != 0)
  2269. goto out;
  2270. }
  2271. /* Find IM volumes
  2272. */
  2273. mpt_findImVolumes(ioc);
  2274. /* Check, and possibly reset, the coalescing value
  2275. */
  2276. mpt_read_ioc_pg_1(ioc);
  2277. break;
  2278. case FC:
  2279. if ((ioc->pfacts[0].ProtocolFlags &
  2280. MPI_PORTFACTS_PROTOCOL_LAN) &&
  2281. (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
  2282. /*
  2283. * Pre-fetch the ports LAN MAC address!
  2284. * (LANPage1_t stuff)
  2285. */
  2286. (void) GetLanConfigPages(ioc);
  2287. a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  2288. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2289. "LanAddr = %pMR\n", ioc->name, a));
  2290. }
  2291. break;
  2292. case SPI:
  2293. /* Get NVRAM and adapter maximums from SPP 0 and 2
  2294. */
  2295. mpt_GetScsiPortSettings(ioc, 0);
  2296. /* Get version and length of SDP 1
  2297. */
  2298. mpt_readScsiDevicePageHeaders(ioc, 0);
  2299. /* Find IM volumes
  2300. */
  2301. if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
  2302. mpt_findImVolumes(ioc);
  2303. /* Check, and possibly reset, the coalescing value
  2304. */
  2305. mpt_read_ioc_pg_1(ioc);
  2306. mpt_read_ioc_pg_4(ioc);
  2307. break;
  2308. }
  2309. GetIoUnitPage2(ioc);
  2310. mpt_get_manufacturing_pg_0(ioc);
  2311. }
  2312. out:
  2313. if ((ret != 0) && irq_allocated) {
  2314. free_irq(ioc->pci_irq, ioc);
  2315. if (ioc->msi_enable)
  2316. pci_disable_msi(ioc->pcidev);
  2317. }
  2318. return ret;
  2319. }
  2320. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2321. /**
  2322. * mpt_detect_bound_ports - Search for matching PCI bus/dev_function
  2323. * @ioc: Pointer to MPT adapter structure
  2324. * @pdev: Pointer to (struct pci_dev) structure
  2325. *
  2326. * Search for PCI bus/dev_function which matches
  2327. * PCI bus/dev_function (+/-1) for newly discovered 929,
  2328. * 929X, 1030 or 1035.
  2329. *
  2330. * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
  2331. * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
  2332. */
  2333. static void
  2334. mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
  2335. {
  2336. struct pci_dev *peer=NULL;
  2337. unsigned int slot = PCI_SLOT(pdev->devfn);
  2338. unsigned int func = PCI_FUNC(pdev->devfn);
  2339. MPT_ADAPTER *ioc_srch;
  2340. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "PCI device %s devfn=%x/%x,"
  2341. " searching for devfn match on %x or %x\n",
  2342. ioc->name, pci_name(pdev), pdev->bus->number,
  2343. pdev->devfn, func-1, func+1));
  2344. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
  2345. if (!peer) {
  2346. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
  2347. if (!peer)
  2348. return;
  2349. }
  2350. list_for_each_entry(ioc_srch, &ioc_list, list) {
  2351. struct pci_dev *_pcidev = ioc_srch->pcidev;
  2352. if (_pcidev == peer) {
  2353. /* Paranoia checks */
  2354. if (ioc->alt_ioc != NULL) {
  2355. printk(MYIOC_s_WARN_FMT
  2356. "Oops, already bound (%s <==> %s)!\n",
  2357. ioc->name, ioc->name, ioc->alt_ioc->name);
  2358. break;
  2359. } else if (ioc_srch->alt_ioc != NULL) {
  2360. printk(MYIOC_s_WARN_FMT
  2361. "Oops, already bound (%s <==> %s)!\n",
  2362. ioc_srch->name, ioc_srch->name,
  2363. ioc_srch->alt_ioc->name);
  2364. break;
  2365. }
  2366. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2367. "FOUND! binding %s <==> %s\n",
  2368. ioc->name, ioc->name, ioc_srch->name));
  2369. ioc_srch->alt_ioc = ioc;
  2370. ioc->alt_ioc = ioc_srch;
  2371. }
  2372. }
  2373. pci_dev_put(peer);
  2374. }
  2375. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2376. /**
  2377. * mpt_adapter_disable - Disable misbehaving MPT adapter.
  2378. * @ioc: Pointer to MPT adapter structure
  2379. */
  2380. static void
  2381. mpt_adapter_disable(MPT_ADAPTER *ioc)
  2382. {
  2383. int sz;
  2384. int ret;
  2385. if (ioc->cached_fw != NULL) {
  2386. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2387. "%s: Pushing FW onto adapter\n", __func__, ioc->name));
  2388. if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)
  2389. ioc->cached_fw, CAN_SLEEP)) < 0) {
  2390. printk(MYIOC_s_WARN_FMT
  2391. ": firmware downloadboot failure (%d)!\n",
  2392. ioc->name, ret);
  2393. }
  2394. }
  2395. /*
  2396. * Put the controller into ready state (if its not already)
  2397. */
  2398. if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY) {
  2399. if (!SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET,
  2400. CAN_SLEEP)) {
  2401. if (mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_READY)
  2402. printk(MYIOC_s_ERR_FMT "%s: IOC msg unit "
  2403. "reset failed to put ioc in ready state!\n",
  2404. ioc->name, __func__);
  2405. } else
  2406. printk(MYIOC_s_ERR_FMT "%s: IOC msg unit reset "
  2407. "failed!\n", ioc->name, __func__);
  2408. }
  2409. /* Disable adapter interrupts! */
  2410. synchronize_irq(ioc->pcidev->irq);
  2411. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  2412. ioc->active = 0;
  2413. /* Clear any lingering interrupt */
  2414. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  2415. CHIPREG_READ32(&ioc->chip->IntStatus);
  2416. if (ioc->alloc != NULL) {
  2417. sz = ioc->alloc_sz;
  2418. dexitprintk(ioc, printk(MYIOC_s_INFO_FMT "free @ %p, sz=%d bytes\n",
  2419. ioc->name, ioc->alloc, ioc->alloc_sz));
  2420. pci_free_consistent(ioc->pcidev, sz,
  2421. ioc->alloc, ioc->alloc_dma);
  2422. ioc->reply_frames = NULL;
  2423. ioc->req_frames = NULL;
  2424. ioc->alloc = NULL;
  2425. ioc->alloc_total -= sz;
  2426. }
  2427. if (ioc->sense_buf_pool != NULL) {
  2428. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  2429. pci_free_consistent(ioc->pcidev, sz,
  2430. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  2431. ioc->sense_buf_pool = NULL;
  2432. ioc->alloc_total -= sz;
  2433. }
  2434. if (ioc->events != NULL){
  2435. sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  2436. kfree(ioc->events);
  2437. ioc->events = NULL;
  2438. ioc->alloc_total -= sz;
  2439. }
  2440. mpt_free_fw_memory(ioc);
  2441. kfree(ioc->spi_data.nvram);
  2442. mpt_inactive_raid_list_free(ioc);
  2443. kfree(ioc->raid_data.pIocPg2);
  2444. kfree(ioc->raid_data.pIocPg3);
  2445. ioc->spi_data.nvram = NULL;
  2446. ioc->raid_data.pIocPg3 = NULL;
  2447. if (ioc->spi_data.pIocPg4 != NULL) {
  2448. sz = ioc->spi_data.IocPg4Sz;
  2449. pci_free_consistent(ioc->pcidev, sz,
  2450. ioc->spi_data.pIocPg4,
  2451. ioc->spi_data.IocPg4_dma);
  2452. ioc->spi_data.pIocPg4 = NULL;
  2453. ioc->alloc_total -= sz;
  2454. }
  2455. if (ioc->ReqToChain != NULL) {
  2456. kfree(ioc->ReqToChain);
  2457. kfree(ioc->RequestNB);
  2458. ioc->ReqToChain = NULL;
  2459. }
  2460. kfree(ioc->ChainToChain);
  2461. ioc->ChainToChain = NULL;
  2462. if (ioc->HostPageBuffer != NULL) {
  2463. if((ret = mpt_host_page_access_control(ioc,
  2464. MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
  2465. printk(MYIOC_s_ERR_FMT
  2466. ": %s: host page buffers free failed (%d)!\n",
  2467. ioc->name, __func__, ret);
  2468. }
  2469. dexitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2470. "HostPageBuffer free @ %p, sz=%d bytes\n",
  2471. ioc->name, ioc->HostPageBuffer,
  2472. ioc->HostPageBuffer_sz));
  2473. pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
  2474. ioc->HostPageBuffer, ioc->HostPageBuffer_dma);
  2475. ioc->HostPageBuffer = NULL;
  2476. ioc->HostPageBuffer_sz = 0;
  2477. ioc->alloc_total -= ioc->HostPageBuffer_sz;
  2478. }
  2479. pci_set_drvdata(ioc->pcidev, NULL);
  2480. }
  2481. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2482. /**
  2483. * mpt_adapter_dispose - Free all resources associated with an MPT adapter
  2484. * @ioc: Pointer to MPT adapter structure
  2485. *
  2486. * This routine unregisters h/w resources and frees all alloc'd memory
  2487. * associated with a MPT adapter structure.
  2488. */
  2489. static void
  2490. mpt_adapter_dispose(MPT_ADAPTER *ioc)
  2491. {
  2492. int sz_first, sz_last;
  2493. if (ioc == NULL)
  2494. return;
  2495. sz_first = ioc->alloc_total;
  2496. mpt_adapter_disable(ioc);
  2497. if (ioc->pci_irq != -1) {
  2498. free_irq(ioc->pci_irq, ioc);
  2499. if (ioc->msi_enable)
  2500. pci_disable_msi(ioc->pcidev);
  2501. ioc->pci_irq = -1;
  2502. }
  2503. if (ioc->memmap != NULL) {
  2504. iounmap(ioc->memmap);
  2505. ioc->memmap = NULL;
  2506. }
  2507. pci_disable_device(ioc->pcidev);
  2508. pci_release_selected_regions(ioc->pcidev, ioc->bars);
  2509. /* Zap the adapter lookup ptr! */
  2510. list_del(&ioc->list);
  2511. sz_last = ioc->alloc_total;
  2512. dprintk(ioc, printk(MYIOC_s_INFO_FMT "free'd %d of %d bytes\n",
  2513. ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
  2514. if (ioc->alt_ioc)
  2515. ioc->alt_ioc->alt_ioc = NULL;
  2516. kfree(ioc);
  2517. }
  2518. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2519. /**
  2520. * MptDisplayIocCapabilities - Disply IOC's capabilities.
  2521. * @ioc: Pointer to MPT adapter structure
  2522. */
  2523. static void
  2524. MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  2525. {
  2526. int i = 0;
  2527. printk(KERN_INFO "%s: ", ioc->name);
  2528. if (ioc->prod_name)
  2529. pr_cont("%s: ", ioc->prod_name);
  2530. pr_cont("Capabilities={");
  2531. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
  2532. pr_cont("Initiator");
  2533. i++;
  2534. }
  2535. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  2536. pr_cont("%sTarget", i ? "," : "");
  2537. i++;
  2538. }
  2539. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  2540. pr_cont("%sLAN", i ? "," : "");
  2541. i++;
  2542. }
  2543. #if 0
  2544. /*
  2545. * This would probably evoke more questions than it's worth
  2546. */
  2547. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  2548. pr_cont("%sLogBusAddr", i ? "," : "");
  2549. i++;
  2550. }
  2551. #endif
  2552. pr_cont("}\n");
  2553. }
  2554. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2555. /**
  2556. * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
  2557. * @ioc: Pointer to MPT_ADAPTER structure
  2558. * @force: Force hard KickStart of IOC
  2559. * @sleepFlag: Specifies whether the process can sleep
  2560. *
  2561. * Returns:
  2562. * 1 - DIAG reset and READY
  2563. * 0 - READY initially OR soft reset and READY
  2564. * -1 - Any failure on KickStart
  2565. * -2 - Msg Unit Reset Failed
  2566. * -3 - IO Unit Reset Failed
  2567. * -4 - IOC owned by a PEER
  2568. */
  2569. static int
  2570. MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
  2571. {
  2572. u32 ioc_state;
  2573. int statefault = 0;
  2574. int cntdn;
  2575. int hard_reset_done = 0;
  2576. int r;
  2577. int ii;
  2578. int whoinit;
  2579. /* Get current [raw] IOC state */
  2580. ioc_state = mpt_GetIocState(ioc, 0);
  2581. dhsprintk(ioc, printk(MYIOC_s_INFO_FMT "MakeIocReady [raw] state=%08x\n", ioc->name, ioc_state));
  2582. /*
  2583. * Check to see if IOC got left/stuck in doorbell handshake
  2584. * grip of death. If so, hard reset the IOC.
  2585. */
  2586. if (ioc_state & MPI_DOORBELL_ACTIVE) {
  2587. statefault = 1;
  2588. printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
  2589. ioc->name);
  2590. }
  2591. /* Is it already READY? */
  2592. if (!statefault &&
  2593. ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)) {
  2594. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2595. "IOC is in READY state\n", ioc->name));
  2596. return 0;
  2597. }
  2598. /*
  2599. * Check to see if IOC is in FAULT state.
  2600. */
  2601. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  2602. statefault = 2;
  2603. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
  2604. ioc->name);
  2605. printk(MYIOC_s_WARN_FMT " FAULT code = %04xh\n",
  2606. ioc->name, ioc_state & MPI_DOORBELL_DATA_MASK);
  2607. }
  2608. /*
  2609. * Hmmm... Did it get left operational?
  2610. */
  2611. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
  2612. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOC operational unexpected\n",
  2613. ioc->name));
  2614. /* Check WhoInit.
  2615. * If PCI Peer, exit.
  2616. * Else, if no fault conditions are present, issue a MessageUnitReset
  2617. * Else, fall through to KickStart case
  2618. */
  2619. whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
  2620. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT
  2621. "whoinit 0x%x statefault %d force %d\n",
  2622. ioc->name, whoinit, statefault, force));
  2623. if (whoinit == MPI_WHOINIT_PCI_PEER)
  2624. return -4;
  2625. else {
  2626. if ((statefault == 0 ) && (force == 0)) {
  2627. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
  2628. return 0;
  2629. }
  2630. statefault = 3;
  2631. }
  2632. }
  2633. hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
  2634. if (hard_reset_done < 0)
  2635. return -1;
  2636. /*
  2637. * Loop here waiting for IOC to come READY.
  2638. */
  2639. ii = 0;
  2640. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
  2641. while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  2642. if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
  2643. /*
  2644. * BIOS or previous driver load left IOC in OP state.
  2645. * Reset messaging FIFOs.
  2646. */
  2647. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
  2648. printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
  2649. return -2;
  2650. }
  2651. } else if (ioc_state == MPI_IOC_STATE_RESET) {
  2652. /*
  2653. * Something is wrong. Try to get IOC back
  2654. * to a known state.
  2655. */
  2656. if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
  2657. printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
  2658. return -3;
  2659. }
  2660. }
  2661. ii++; cntdn--;
  2662. if (!cntdn) {
  2663. printk(MYIOC_s_ERR_FMT
  2664. "Wait IOC_READY state (0x%x) timeout(%d)!\n",
  2665. ioc->name, ioc_state, (int)((ii+5)/HZ));
  2666. return -ETIME;
  2667. }
  2668. if (sleepFlag == CAN_SLEEP) {
  2669. msleep(1);
  2670. } else {
  2671. mdelay (1); /* 1 msec delay */
  2672. }
  2673. }
  2674. if (statefault < 3) {
  2675. printk(MYIOC_s_INFO_FMT "Recovered from %s\n", ioc->name,
  2676. statefault == 1 ? "stuck handshake" : "IOC FAULT");
  2677. }
  2678. return hard_reset_done;
  2679. }
  2680. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2681. /**
  2682. * mpt_GetIocState - Get the current state of a MPT adapter.
  2683. * @ioc: Pointer to MPT_ADAPTER structure
  2684. * @cooked: Request raw or cooked IOC state
  2685. *
  2686. * Returns all IOC Doorbell register bits if cooked==0, else just the
  2687. * Doorbell bits in MPI_IOC_STATE_MASK.
  2688. */
  2689. u32
  2690. mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
  2691. {
  2692. u32 s, sc;
  2693. /* Get! */
  2694. s = CHIPREG_READ32(&ioc->chip->Doorbell);
  2695. sc = s & MPI_IOC_STATE_MASK;
  2696. /* Save! */
  2697. ioc->last_state = sc;
  2698. return cooked ? sc : s;
  2699. }
  2700. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2701. /**
  2702. * GetIocFacts - Send IOCFacts request to MPT adapter.
  2703. * @ioc: Pointer to MPT_ADAPTER structure
  2704. * @sleepFlag: Specifies whether the process can sleep
  2705. * @reason: If recovery, only update facts.
  2706. *
  2707. * Returns 0 for success, non-zero for failure.
  2708. */
  2709. static int
  2710. GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  2711. {
  2712. IOCFacts_t get_facts;
  2713. IOCFactsReply_t *facts;
  2714. int r;
  2715. int req_sz;
  2716. int reply_sz;
  2717. int sz;
  2718. u32 status, vv;
  2719. u8 shiftFactor=1;
  2720. /* IOC *must* NOT be in RESET state! */
  2721. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2722. printk(KERN_ERR MYNAM
  2723. ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
  2724. ioc->name, ioc->last_state);
  2725. return -44;
  2726. }
  2727. facts = &ioc->facts;
  2728. /* Destination (reply area)... */
  2729. reply_sz = sizeof(*facts);
  2730. memset(facts, 0, reply_sz);
  2731. /* Request area (get_facts on the stack right now!) */
  2732. req_sz = sizeof(get_facts);
  2733. memset(&get_facts, 0, req_sz);
  2734. get_facts.Function = MPI_FUNCTION_IOC_FACTS;
  2735. /* Assert: All other get_facts fields are zero! */
  2736. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2737. "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
  2738. ioc->name, req_sz, reply_sz));
  2739. /* No non-zero fields in the get_facts request are greater than
  2740. * 1 byte in size, so we can just fire it off as is.
  2741. */
  2742. r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
  2743. reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
  2744. if (r != 0)
  2745. return r;
  2746. /*
  2747. * Now byte swap (GRRR) the necessary fields before any further
  2748. * inspection of reply contents.
  2749. *
  2750. * But need to do some sanity checks on MsgLength (byte) field
  2751. * to make sure we don't zero IOC's req_sz!
  2752. */
  2753. /* Did we get a valid reply? */
  2754. if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
  2755. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2756. /*
  2757. * If not been here, done that, save off first WhoInit value
  2758. */
  2759. if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
  2760. ioc->FirstWhoInit = facts->WhoInit;
  2761. }
  2762. facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
  2763. facts->MsgContext = le32_to_cpu(facts->MsgContext);
  2764. facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
  2765. facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
  2766. facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
  2767. status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
  2768. /* CHECKME! IOCStatus, IOCLogInfo */
  2769. facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
  2770. facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
  2771. /*
  2772. * FC f/w version changed between 1.1 and 1.2
  2773. * Old: u16{Major(4),Minor(4),SubMinor(8)}
  2774. * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
  2775. */
  2776. if (facts->MsgVersion < MPI_VERSION_01_02) {
  2777. /*
  2778. * Handle old FC f/w style, convert to new...
  2779. */
  2780. u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
  2781. facts->FWVersion.Word =
  2782. ((oldv<<12) & 0xFF000000) |
  2783. ((oldv<<8) & 0x000FFF00);
  2784. } else
  2785. facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
  2786. facts->ProductID = le16_to_cpu(facts->ProductID);
  2787. if ((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
  2788. > MPI_FW_HEADER_PID_PROD_TARGET_SCSI)
  2789. ioc->ir_firmware = 1;
  2790. facts->CurrentHostMfaHighAddr =
  2791. le32_to_cpu(facts->CurrentHostMfaHighAddr);
  2792. facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
  2793. facts->CurrentSenseBufferHighAddr =
  2794. le32_to_cpu(facts->CurrentSenseBufferHighAddr);
  2795. facts->CurReplyFrameSize =
  2796. le16_to_cpu(facts->CurReplyFrameSize);
  2797. facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
  2798. /*
  2799. * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
  2800. * Older MPI-1.00.xx struct had 13 dwords, and enlarged
  2801. * to 14 in MPI-1.01.0x.
  2802. */
  2803. if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
  2804. facts->MsgVersion > MPI_VERSION_01_00) {
  2805. facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
  2806. }
  2807. facts->FWImageSize = ALIGN(facts->FWImageSize, 4);
  2808. if (!facts->RequestFrameSize) {
  2809. /* Something is wrong! */
  2810. printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
  2811. ioc->name);
  2812. return -55;
  2813. }
  2814. r = sz = facts->BlockSize;
  2815. vv = ((63 / (sz * 4)) + 1) & 0x03;
  2816. ioc->NB_for_64_byte_frame = vv;
  2817. while ( sz )
  2818. {
  2819. shiftFactor++;
  2820. sz = sz >> 1;
  2821. }
  2822. ioc->NBShiftFactor = shiftFactor;
  2823. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  2824. "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
  2825. ioc->name, vv, shiftFactor, r));
  2826. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2827. /*
  2828. * Set values for this IOC's request & reply frame sizes,
  2829. * and request & reply queue depths...
  2830. */
  2831. ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
  2832. ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
  2833. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  2834. ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
  2835. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "reply_sz=%3d, reply_depth=%4d\n",
  2836. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2837. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "req_sz =%3d, req_depth =%4d\n",
  2838. ioc->name, ioc->req_sz, ioc->req_depth));
  2839. /* Get port facts! */
  2840. if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
  2841. return r;
  2842. }
  2843. } else {
  2844. printk(MYIOC_s_ERR_FMT
  2845. "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
  2846. ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
  2847. RequestFrameSize)/sizeof(u32)));
  2848. return -66;
  2849. }
  2850. return 0;
  2851. }
  2852. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2853. /**
  2854. * GetPortFacts - Send PortFacts request to MPT adapter.
  2855. * @ioc: Pointer to MPT_ADAPTER structure
  2856. * @portnum: Port number
  2857. * @sleepFlag: Specifies whether the process can sleep
  2858. *
  2859. * Returns 0 for success, non-zero for failure.
  2860. */
  2861. static int
  2862. GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2863. {
  2864. PortFacts_t get_pfacts;
  2865. PortFactsReply_t *pfacts;
  2866. int ii;
  2867. int req_sz;
  2868. int reply_sz;
  2869. int max_id;
  2870. /* IOC *must* NOT be in RESET state! */
  2871. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2872. printk(MYIOC_s_ERR_FMT "Can't get PortFacts NOT READY! (%08x)\n",
  2873. ioc->name, ioc->last_state );
  2874. return -4;
  2875. }
  2876. pfacts = &ioc->pfacts[portnum];
  2877. /* Destination (reply area)... */
  2878. reply_sz = sizeof(*pfacts);
  2879. memset(pfacts, 0, reply_sz);
  2880. /* Request area (get_pfacts on the stack right now!) */
  2881. req_sz = sizeof(get_pfacts);
  2882. memset(&get_pfacts, 0, req_sz);
  2883. get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
  2884. get_pfacts.PortNumber = portnum;
  2885. /* Assert: All other get_pfacts fields are zero! */
  2886. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending get PortFacts(%d) request\n",
  2887. ioc->name, portnum));
  2888. /* No non-zero fields in the get_pfacts request are greater than
  2889. * 1 byte in size, so we can just fire it off as is.
  2890. */
  2891. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
  2892. reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
  2893. if (ii != 0)
  2894. return ii;
  2895. /* Did we get a valid reply? */
  2896. /* Now byte swap the necessary fields in the response. */
  2897. pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
  2898. pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
  2899. pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
  2900. pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
  2901. pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
  2902. pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
  2903. pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
  2904. pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
  2905. pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
  2906. max_id = (ioc->bus_type == SAS) ? pfacts->PortSCSIID :
  2907. pfacts->MaxDevices;
  2908. ioc->devices_per_bus = (max_id > 255) ? 256 : max_id;
  2909. ioc->number_of_buses = (ioc->devices_per_bus < 256) ? 1 : max_id/256;
  2910. /*
  2911. * Place all the devices on channels
  2912. *
  2913. * (for debuging)
  2914. */
  2915. if (mpt_channel_mapping) {
  2916. ioc->devices_per_bus = 1;
  2917. ioc->number_of_buses = (max_id > 255) ? 255 : max_id;
  2918. }
  2919. return 0;
  2920. }
  2921. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2922. /**
  2923. * SendIocInit - Send IOCInit request to MPT adapter.
  2924. * @ioc: Pointer to MPT_ADAPTER structure
  2925. * @sleepFlag: Specifies whether the process can sleep
  2926. *
  2927. * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
  2928. *
  2929. * Returns 0 for success, non-zero for failure.
  2930. */
  2931. static int
  2932. SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
  2933. {
  2934. IOCInit_t ioc_init;
  2935. MPIDefaultReply_t init_reply;
  2936. u32 state;
  2937. int r;
  2938. int count;
  2939. int cntdn;
  2940. memset(&ioc_init, 0, sizeof(ioc_init));
  2941. memset(&init_reply, 0, sizeof(init_reply));
  2942. ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
  2943. ioc_init.Function = MPI_FUNCTION_IOC_INIT;
  2944. /* If we are in a recovery mode and we uploaded the FW image,
  2945. * then this pointer is not NULL. Skip the upload a second time.
  2946. * Set this flag if cached_fw set for either IOC.
  2947. */
  2948. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  2949. ioc->upload_fw = 1;
  2950. else
  2951. ioc->upload_fw = 0;
  2952. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "upload_fw %d facts.Flags=%x\n",
  2953. ioc->name, ioc->upload_fw, ioc->facts.Flags));
  2954. ioc_init.MaxDevices = (U8)ioc->devices_per_bus;
  2955. ioc_init.MaxBuses = (U8)ioc->number_of_buses;
  2956. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "facts.MsgVersion=%x\n",
  2957. ioc->name, ioc->facts.MsgVersion));
  2958. if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
  2959. // set MsgVersion and HeaderVersion host driver was built with
  2960. ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
  2961. ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
  2962. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
  2963. ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
  2964. } else if(mpt_host_page_alloc(ioc, &ioc_init))
  2965. return -99;
  2966. }
  2967. ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
  2968. if (ioc->sg_addr_size == sizeof(u64)) {
  2969. /* Save the upper 32-bits of the request
  2970. * (reply) and sense buffers.
  2971. */
  2972. ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
  2973. ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  2974. } else {
  2975. /* Force 32-bit addressing */
  2976. ioc_init.HostMfaHighAddr = cpu_to_le32(0);
  2977. ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
  2978. }
  2979. ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
  2980. ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
  2981. ioc->facts.MaxDevices = ioc_init.MaxDevices;
  2982. ioc->facts.MaxBuses = ioc_init.MaxBuses;
  2983. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOCInit (req @ %p)\n",
  2984. ioc->name, &ioc_init));
  2985. r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
  2986. sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
  2987. if (r != 0) {
  2988. printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
  2989. return r;
  2990. }
  2991. /* No need to byte swap the multibyte fields in the reply
  2992. * since we don't even look at its contents.
  2993. */
  2994. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending PortEnable (req @ %p)\n",
  2995. ioc->name, &ioc_init));
  2996. if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
  2997. printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
  2998. return r;
  2999. }
  3000. /* YIKES! SUPER IMPORTANT!!!
  3001. * Poll IocState until _OPERATIONAL while IOC is doing
  3002. * LoopInit and TargetDiscovery!
  3003. */
  3004. count = 0;
  3005. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
  3006. state = mpt_GetIocState(ioc, 1);
  3007. while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
  3008. if (sleepFlag == CAN_SLEEP) {
  3009. msleep(1);
  3010. } else {
  3011. mdelay(1);
  3012. }
  3013. if (!cntdn) {
  3014. printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
  3015. ioc->name, (int)((count+5)/HZ));
  3016. return -9;
  3017. }
  3018. state = mpt_GetIocState(ioc, 1);
  3019. count++;
  3020. }
  3021. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wait IOC_OPERATIONAL state (cnt=%d)\n",
  3022. ioc->name, count));
  3023. ioc->aen_event_read_flag=0;
  3024. return r;
  3025. }
  3026. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3027. /**
  3028. * SendPortEnable - Send PortEnable request to MPT adapter port.
  3029. * @ioc: Pointer to MPT_ADAPTER structure
  3030. * @portnum: Port number to enable
  3031. * @sleepFlag: Specifies whether the process can sleep
  3032. *
  3033. * Send PortEnable to bring IOC to OPERATIONAL state.
  3034. *
  3035. * Returns 0 for success, non-zero for failure.
  3036. */
  3037. static int
  3038. SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  3039. {
  3040. PortEnable_t port_enable;
  3041. MPIDefaultReply_t reply_buf;
  3042. int rc;
  3043. int req_sz;
  3044. int reply_sz;
  3045. /* Destination... */
  3046. reply_sz = sizeof(MPIDefaultReply_t);
  3047. memset(&reply_buf, 0, reply_sz);
  3048. req_sz = sizeof(PortEnable_t);
  3049. memset(&port_enable, 0, req_sz);
  3050. port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
  3051. port_enable.PortNumber = portnum;
  3052. /* port_enable.ChainOffset = 0; */
  3053. /* port_enable.MsgFlags = 0; */
  3054. /* port_enable.MsgContext = 0; */
  3055. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending Port(%d)Enable (req @ %p)\n",
  3056. ioc->name, portnum, &port_enable));
  3057. /* RAID FW may take a long time to enable
  3058. */
  3059. if (ioc->ir_firmware || ioc->bus_type == SAS) {
  3060. rc = mpt_handshake_req_reply_wait(ioc, req_sz,
  3061. (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
  3062. 300 /*seconds*/, sleepFlag);
  3063. } else {
  3064. rc = mpt_handshake_req_reply_wait(ioc, req_sz,
  3065. (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
  3066. 30 /*seconds*/, sleepFlag);
  3067. }
  3068. return rc;
  3069. }
  3070. /**
  3071. * mpt_alloc_fw_memory - allocate firmware memory
  3072. * @ioc: Pointer to MPT_ADAPTER structure
  3073. * @size: total FW bytes
  3074. *
  3075. * If memory has already been allocated, the same (cached) value
  3076. * is returned.
  3077. *
  3078. * Return 0 if successful, or non-zero for failure
  3079. **/
  3080. int
  3081. mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
  3082. {
  3083. int rc;
  3084. if (ioc->cached_fw) {
  3085. rc = 0; /* use already allocated memory */
  3086. goto out;
  3087. }
  3088. else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  3089. ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
  3090. ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
  3091. rc = 0;
  3092. goto out;
  3093. }
  3094. ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma);
  3095. if (!ioc->cached_fw) {
  3096. printk(MYIOC_s_ERR_FMT "Unable to allocate memory for the cached firmware image!\n",
  3097. ioc->name);
  3098. rc = -1;
  3099. } else {
  3100. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Image @ %p[%p], sz=%d[%x] bytes\n",
  3101. ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, size, size));
  3102. ioc->alloc_total += size;
  3103. rc = 0;
  3104. }
  3105. out:
  3106. return rc;
  3107. }
  3108. /**
  3109. * mpt_free_fw_memory - free firmware memory
  3110. * @ioc: Pointer to MPT_ADAPTER structure
  3111. *
  3112. * If alt_img is NULL, delete from ioc structure.
  3113. * Else, delete a secondary image in same format.
  3114. **/
  3115. void
  3116. mpt_free_fw_memory(MPT_ADAPTER *ioc)
  3117. {
  3118. int sz;
  3119. if (!ioc->cached_fw)
  3120. return;
  3121. sz = ioc->facts.FWImageSize;
  3122. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
  3123. ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  3124. pci_free_consistent(ioc->pcidev, sz, ioc->cached_fw, ioc->cached_fw_dma);
  3125. ioc->alloc_total -= sz;
  3126. ioc->cached_fw = NULL;
  3127. }
  3128. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3129. /**
  3130. * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
  3131. * @ioc: Pointer to MPT_ADAPTER structure
  3132. * @sleepFlag: Specifies whether the process can sleep
  3133. *
  3134. * Returns 0 for success, >0 for handshake failure
  3135. * <0 for fw upload failure.
  3136. *
  3137. * Remark: If bound IOC and a successful FWUpload was performed
  3138. * on the bound IOC, the second image is discarded
  3139. * and memory is free'd. Both channels must upload to prevent
  3140. * IOC from running in degraded mode.
  3141. */
  3142. static int
  3143. mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
  3144. {
  3145. u8 reply[sizeof(FWUploadReply_t)];
  3146. FWUpload_t *prequest;
  3147. FWUploadReply_t *preply;
  3148. FWUploadTCSGE_t *ptcsge;
  3149. u32 flagsLength;
  3150. int ii, sz, reply_sz;
  3151. int cmdStatus;
  3152. int request_size;
  3153. /* If the image size is 0, we are done.
  3154. */
  3155. if ((sz = ioc->facts.FWImageSize) == 0)
  3156. return 0;
  3157. if (mpt_alloc_fw_memory(ioc, ioc->facts.FWImageSize) != 0)
  3158. return -ENOMEM;
  3159. dinitprintk(ioc, printk(MYIOC_s_INFO_FMT ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
  3160. ioc->name, ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  3161. prequest = (sleepFlag == NO_SLEEP) ? kzalloc(ioc->req_sz, GFP_ATOMIC) :
  3162. kzalloc(ioc->req_sz, GFP_KERNEL);
  3163. if (!prequest) {
  3164. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed "
  3165. "while allocating memory \n", ioc->name));
  3166. mpt_free_fw_memory(ioc);
  3167. return -ENOMEM;
  3168. }
  3169. preply = (FWUploadReply_t *)&reply;
  3170. reply_sz = sizeof(reply);
  3171. memset(preply, 0, reply_sz);
  3172. prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
  3173. prequest->Function = MPI_FUNCTION_FW_UPLOAD;
  3174. ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
  3175. ptcsge->DetailsLength = 12;
  3176. ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  3177. ptcsge->ImageSize = cpu_to_le32(sz);
  3178. ptcsge++;
  3179. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
  3180. ioc->add_sge((char *)ptcsge, flagsLength, ioc->cached_fw_dma);
  3181. request_size = offsetof(FWUpload_t, SGL) + sizeof(FWUploadTCSGE_t) +
  3182. ioc->SGE_size;
  3183. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending FW Upload "
  3184. " (req @ %p) fw_size=%d mf_request_size=%d\n", ioc->name, prequest,
  3185. ioc->facts.FWImageSize, request_size));
  3186. DBG_DUMP_FW_REQUEST_FRAME(ioc, (u32 *)prequest);
  3187. ii = mpt_handshake_req_reply_wait(ioc, request_size, (u32 *)prequest,
  3188. reply_sz, (u16 *)preply, 65 /*seconds*/, sleepFlag);
  3189. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "FW Upload completed "
  3190. "rc=%x \n", ioc->name, ii));
  3191. cmdStatus = -EFAULT;
  3192. if (ii == 0) {
  3193. /* Handshake transfer was complete and successful.
  3194. * Check the Reply Frame.
  3195. */
  3196. int status;
  3197. status = le16_to_cpu(preply->IOCStatus) &
  3198. MPI_IOCSTATUS_MASK;
  3199. if (status == MPI_IOCSTATUS_SUCCESS &&
  3200. ioc->facts.FWImageSize ==
  3201. le32_to_cpu(preply->ActualImageSize))
  3202. cmdStatus = 0;
  3203. }
  3204. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT ": do_upload cmdStatus=%d \n",
  3205. ioc->name, cmdStatus));
  3206. if (cmdStatus) {
  3207. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "fw upload failed, "
  3208. "freeing image \n", ioc->name));
  3209. mpt_free_fw_memory(ioc);
  3210. }
  3211. kfree(prequest);
  3212. return cmdStatus;
  3213. }
  3214. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3215. /**
  3216. * mpt_downloadboot - DownloadBoot code
  3217. * @ioc: Pointer to MPT_ADAPTER structure
  3218. * @pFwHeader: Pointer to firmware header info
  3219. * @sleepFlag: Specifies whether the process can sleep
  3220. *
  3221. * FwDownloadBoot requires Programmed IO access.
  3222. *
  3223. * Returns 0 for success
  3224. * -1 FW Image size is 0
  3225. * -2 No valid cached_fw Pointer
  3226. * <0 for fw upload failure.
  3227. */
  3228. static int
  3229. mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
  3230. {
  3231. MpiExtImageHeader_t *pExtImage;
  3232. u32 fwSize;
  3233. u32 diag0val;
  3234. int count;
  3235. u32 *ptrFw;
  3236. u32 diagRwData;
  3237. u32 nextImage;
  3238. u32 load_addr;
  3239. u32 ioc_state=0;
  3240. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
  3241. ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
  3242. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3243. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3244. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3245. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3246. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3247. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3248. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
  3249. /* wait 1 msec */
  3250. if (sleepFlag == CAN_SLEEP) {
  3251. msleep(1);
  3252. } else {
  3253. mdelay (1);
  3254. }
  3255. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3256. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  3257. for (count = 0; count < 30; count ++) {
  3258. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3259. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  3260. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RESET_ADAPTER cleared, count=%d\n",
  3261. ioc->name, count));
  3262. break;
  3263. }
  3264. /* wait .1 sec */
  3265. if (sleepFlag == CAN_SLEEP) {
  3266. msleep (100);
  3267. } else {
  3268. mdelay (100);
  3269. }
  3270. }
  3271. if ( count == 30 ) {
  3272. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot failed! "
  3273. "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
  3274. ioc->name, diag0val));
  3275. return -3;
  3276. }
  3277. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3278. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3279. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3280. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3281. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3282. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3283. /* Set the DiagRwEn and Disable ARM bits */
  3284. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
  3285. fwSize = (pFwHeader->ImageSize + 3)/4;
  3286. ptrFw = (u32 *) pFwHeader;
  3287. /* Write the LoadStartAddress to the DiagRw Address Register
  3288. * using Programmed IO
  3289. */
  3290. if (ioc->errata_flag_1064)
  3291. pci_enable_io_access(ioc->pcidev);
  3292. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
  3293. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "LoadStart addr written 0x%x \n",
  3294. ioc->name, pFwHeader->LoadStartAddress));
  3295. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write FW Image: 0x%x bytes @ %p\n",
  3296. ioc->name, fwSize*4, ptrFw));
  3297. while (fwSize--) {
  3298. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  3299. }
  3300. nextImage = pFwHeader->NextImageHeaderOffset;
  3301. while (nextImage) {
  3302. pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
  3303. load_addr = pExtImage->LoadStartAddress;
  3304. fwSize = (pExtImage->ImageSize + 3) >> 2;
  3305. ptrFw = (u32 *)pExtImage;
  3306. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
  3307. ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
  3308. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
  3309. while (fwSize--) {
  3310. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  3311. }
  3312. nextImage = pExtImage->NextImageHeaderOffset;
  3313. }
  3314. /* Write the IopResetVectorRegAddr */
  3315. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
  3316. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
  3317. /* Write the IopResetVectorValue */
  3318. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
  3319. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
  3320. /* Clear the internal flash bad bit - autoincrementing register,
  3321. * so must do two writes.
  3322. */
  3323. if (ioc->bus_type == SPI) {
  3324. /*
  3325. * 1030 and 1035 H/W errata, workaround to access
  3326. * the ClearFlashBadSignatureBit
  3327. */
  3328. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  3329. diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
  3330. diagRwData |= 0x40000000;
  3331. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  3332. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
  3333. } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
  3334. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3335. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
  3336. MPI_DIAG_CLEAR_FLASH_BAD_SIG);
  3337. /* wait 1 msec */
  3338. if (sleepFlag == CAN_SLEEP) {
  3339. msleep (1);
  3340. } else {
  3341. mdelay (1);
  3342. }
  3343. }
  3344. if (ioc->errata_flag_1064)
  3345. pci_disable_io_access(ioc->pcidev);
  3346. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3347. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot diag0val=%x, "
  3348. "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
  3349. ioc->name, diag0val));
  3350. diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
  3351. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "downloadboot now diag0val=%x\n",
  3352. ioc->name, diag0val));
  3353. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  3354. /* Write 0xFF to reset the sequencer */
  3355. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3356. if (ioc->bus_type == SAS) {
  3357. ioc_state = mpt_GetIocState(ioc, 0);
  3358. if ( (GetIocFacts(ioc, sleepFlag,
  3359. MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
  3360. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT "GetIocFacts failed: IocState=%x\n",
  3361. ioc->name, ioc_state));
  3362. return -EFAULT;
  3363. }
  3364. }
  3365. for (count=0; count<HZ*20; count++) {
  3366. if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
  3367. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3368. "downloadboot successful! (count=%d) IocState=%x\n",
  3369. ioc->name, count, ioc_state));
  3370. if (ioc->bus_type == SAS) {
  3371. return 0;
  3372. }
  3373. if ((SendIocInit(ioc, sleepFlag)) != 0) {
  3374. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3375. "downloadboot: SendIocInit failed\n",
  3376. ioc->name));
  3377. return -EFAULT;
  3378. }
  3379. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3380. "downloadboot: SendIocInit successful\n",
  3381. ioc->name));
  3382. return 0;
  3383. }
  3384. if (sleepFlag == CAN_SLEEP) {
  3385. msleep (10);
  3386. } else {
  3387. mdelay (10);
  3388. }
  3389. }
  3390. ddlprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3391. "downloadboot failed! IocState=%x\n",ioc->name, ioc_state));
  3392. return -EFAULT;
  3393. }
  3394. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3395. /**
  3396. * KickStart - Perform hard reset of MPT adapter.
  3397. * @ioc: Pointer to MPT_ADAPTER structure
  3398. * @force: Force hard reset
  3399. * @sleepFlag: Specifies whether the process can sleep
  3400. *
  3401. * This routine places MPT adapter in diagnostic mode via the
  3402. * WriteSequence register, and then performs a hard reset of adapter
  3403. * via the Diagnostic register.
  3404. *
  3405. * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
  3406. * or NO_SLEEP (interrupt thread, use mdelay)
  3407. * force - 1 if doorbell active, board fault state
  3408. * board operational, IOC_RECOVERY or
  3409. * IOC_BRINGUP and there is an alt_ioc.
  3410. * 0 else
  3411. *
  3412. * Returns:
  3413. * 1 - hard reset, READY
  3414. * 0 - no reset due to History bit, READY
  3415. * -1 - no reset due to History bit but not READY
  3416. * OR reset but failed to come READY
  3417. * -2 - no reset, could not enter DIAG mode
  3418. * -3 - reset but bad FW bit
  3419. */
  3420. static int
  3421. KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
  3422. {
  3423. int hard_reset_done = 0;
  3424. u32 ioc_state=0;
  3425. int cnt,cntdn;
  3426. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStarting!\n", ioc->name));
  3427. if (ioc->bus_type == SPI) {
  3428. /* Always issue a Msg Unit Reset first. This will clear some
  3429. * SCSI bus hang conditions.
  3430. */
  3431. SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  3432. if (sleepFlag == CAN_SLEEP) {
  3433. msleep (1000);
  3434. } else {
  3435. mdelay (1000);
  3436. }
  3437. }
  3438. hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
  3439. if (hard_reset_done < 0)
  3440. return hard_reset_done;
  3441. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset successful!\n",
  3442. ioc->name));
  3443. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
  3444. for (cnt=0; cnt<cntdn; cnt++) {
  3445. ioc_state = mpt_GetIocState(ioc, 1);
  3446. if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
  3447. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "KickStart successful! (cnt=%d)\n",
  3448. ioc->name, cnt));
  3449. return hard_reset_done;
  3450. }
  3451. if (sleepFlag == CAN_SLEEP) {
  3452. msleep (10);
  3453. } else {
  3454. mdelay (10);
  3455. }
  3456. }
  3457. dinitprintk(ioc, printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
  3458. ioc->name, mpt_GetIocState(ioc, 0)));
  3459. return -1;
  3460. }
  3461. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3462. /**
  3463. * mpt_diag_reset - Perform hard reset of the adapter.
  3464. * @ioc: Pointer to MPT_ADAPTER structure
  3465. * @ignore: Set if to honor and clear to ignore
  3466. * the reset history bit
  3467. * @sleepFlag: CAN_SLEEP if called in a non-interrupt thread,
  3468. * else set to NO_SLEEP (use mdelay instead)
  3469. *
  3470. * This routine places the adapter in diagnostic mode via the
  3471. * WriteSequence register and then performs a hard reset of adapter
  3472. * via the Diagnostic register. Adapter should be in ready state
  3473. * upon successful completion.
  3474. *
  3475. * Returns: 1 hard reset successful
  3476. * 0 no reset performed because reset history bit set
  3477. * -2 enabling diagnostic mode failed
  3478. * -3 diagnostic reset failed
  3479. */
  3480. static int
  3481. mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
  3482. {
  3483. u32 diag0val;
  3484. u32 doorbell;
  3485. int hard_reset_done = 0;
  3486. int count = 0;
  3487. u32 diag1val = 0;
  3488. MpiFwHeader_t *cached_fw; /* Pointer to FW */
  3489. u8 cb_idx;
  3490. /* Clear any existing interrupts */
  3491. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3492. if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
  3493. if (!ignore)
  3494. return 0;
  3495. drsprintk(ioc, printk(MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
  3496. "address=%p\n", ioc->name, __func__,
  3497. &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
  3498. CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
  3499. if (sleepFlag == CAN_SLEEP)
  3500. msleep(1);
  3501. else
  3502. mdelay(1);
  3503. /*
  3504. * Call each currently registered protocol IOC reset handler
  3505. * with pre-reset indication.
  3506. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  3507. * MptResetHandlers[] registered yet.
  3508. */
  3509. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  3510. if (MptResetHandlers[cb_idx])
  3511. (*(MptResetHandlers[cb_idx]))(ioc,
  3512. MPT_IOC_PRE_RESET);
  3513. }
  3514. for (count = 0; count < 60; count ++) {
  3515. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  3516. doorbell &= MPI_IOC_STATE_MASK;
  3517. drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3518. "looking for READY STATE: doorbell=%x"
  3519. " count=%d\n",
  3520. ioc->name, doorbell, count));
  3521. if (doorbell == MPI_IOC_STATE_READY) {
  3522. return 1;
  3523. }
  3524. /* wait 1 sec */
  3525. if (sleepFlag == CAN_SLEEP)
  3526. msleep(1000);
  3527. else
  3528. mdelay(1000);
  3529. }
  3530. return -1;
  3531. }
  3532. /* Use "Diagnostic reset" method! (only thing available!) */
  3533. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3534. if (ioc->debug_level & MPT_DEBUG) {
  3535. if (ioc->alt_ioc)
  3536. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3537. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG1: diag0=%08x, diag1=%08x\n",
  3538. ioc->name, diag0val, diag1val));
  3539. }
  3540. /* Do the reset if we are told to ignore the reset history
  3541. * or if the reset history is 0
  3542. */
  3543. if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
  3544. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  3545. /* Write magic sequence to WriteSequence register
  3546. * Loop until in diagnostic mode
  3547. */
  3548. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3549. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3550. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3551. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3552. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3553. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3554. /* wait 100 msec */
  3555. if (sleepFlag == CAN_SLEEP) {
  3556. msleep (100);
  3557. } else {
  3558. mdelay (100);
  3559. }
  3560. count++;
  3561. if (count > 20) {
  3562. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  3563. ioc->name, diag0val);
  3564. return -2;
  3565. }
  3566. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3567. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
  3568. ioc->name, diag0val));
  3569. }
  3570. if (ioc->debug_level & MPT_DEBUG) {
  3571. if (ioc->alt_ioc)
  3572. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3573. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG2: diag0=%08x, diag1=%08x\n",
  3574. ioc->name, diag0val, diag1val));
  3575. }
  3576. /*
  3577. * Disable the ARM (Bug fix)
  3578. *
  3579. */
  3580. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
  3581. mdelay(1);
  3582. /*
  3583. * Now hit the reset bit in the Diagnostic register
  3584. * (THE BIG HAMMER!) (Clears DRWE bit).
  3585. */
  3586. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  3587. hard_reset_done = 1;
  3588. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Diagnostic reset performed\n",
  3589. ioc->name));
  3590. /*
  3591. * Call each currently registered protocol IOC reset handler
  3592. * with pre-reset indication.
  3593. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  3594. * MptResetHandlers[] registered yet.
  3595. */
  3596. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  3597. if (MptResetHandlers[cb_idx]) {
  3598. mpt_signal_reset(cb_idx,
  3599. ioc, MPT_IOC_PRE_RESET);
  3600. if (ioc->alt_ioc) {
  3601. mpt_signal_reset(cb_idx,
  3602. ioc->alt_ioc, MPT_IOC_PRE_RESET);
  3603. }
  3604. }
  3605. }
  3606. if (ioc->cached_fw)
  3607. cached_fw = (MpiFwHeader_t *)ioc->cached_fw;
  3608. else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
  3609. cached_fw = (MpiFwHeader_t *)ioc->alt_ioc->cached_fw;
  3610. else
  3611. cached_fw = NULL;
  3612. if (cached_fw) {
  3613. /* If the DownloadBoot operation fails, the
  3614. * IOC will be left unusable. This is a fatal error
  3615. * case. _diag_reset will return < 0
  3616. */
  3617. for (count = 0; count < 30; count ++) {
  3618. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3619. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  3620. break;
  3621. }
  3622. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "cached_fw: diag0val=%x count=%d\n",
  3623. ioc->name, diag0val, count));
  3624. /* wait 1 sec */
  3625. if (sleepFlag == CAN_SLEEP) {
  3626. msleep (1000);
  3627. } else {
  3628. mdelay (1000);
  3629. }
  3630. }
  3631. if ((count = mpt_downloadboot(ioc, cached_fw, sleepFlag)) < 0) {
  3632. printk(MYIOC_s_WARN_FMT
  3633. "firmware downloadboot failure (%d)!\n", ioc->name, count);
  3634. }
  3635. } else {
  3636. /* Wait for FW to reload and for board
  3637. * to go to the READY state.
  3638. * Maximum wait is 60 seconds.
  3639. * If fail, no error will check again
  3640. * with calling program.
  3641. */
  3642. for (count = 0; count < 60; count ++) {
  3643. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  3644. doorbell &= MPI_IOC_STATE_MASK;
  3645. drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3646. "looking for READY STATE: doorbell=%x"
  3647. " count=%d\n", ioc->name, doorbell, count));
  3648. if (doorbell == MPI_IOC_STATE_READY) {
  3649. break;
  3650. }
  3651. /* wait 1 sec */
  3652. if (sleepFlag == CAN_SLEEP) {
  3653. msleep (1000);
  3654. } else {
  3655. mdelay (1000);
  3656. }
  3657. }
  3658. if (doorbell != MPI_IOC_STATE_READY)
  3659. printk(MYIOC_s_ERR_FMT "Failed to come READY "
  3660. "after reset! IocState=%x", ioc->name,
  3661. doorbell);
  3662. }
  3663. }
  3664. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3665. if (ioc->debug_level & MPT_DEBUG) {
  3666. if (ioc->alt_ioc)
  3667. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3668. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG3: diag0=%08x, diag1=%08x\n",
  3669. ioc->name, diag0val, diag1val));
  3670. }
  3671. /* Clear RESET_HISTORY bit! Place board in the
  3672. * diagnostic mode to update the diag register.
  3673. */
  3674. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3675. count = 0;
  3676. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  3677. /* Write magic sequence to WriteSequence register
  3678. * Loop until in diagnostic mode
  3679. */
  3680. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  3681. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  3682. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  3683. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  3684. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  3685. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  3686. /* wait 100 msec */
  3687. if (sleepFlag == CAN_SLEEP) {
  3688. msleep (100);
  3689. } else {
  3690. mdelay (100);
  3691. }
  3692. count++;
  3693. if (count > 20) {
  3694. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  3695. ioc->name, diag0val);
  3696. break;
  3697. }
  3698. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3699. }
  3700. diag0val &= ~MPI_DIAG_RESET_HISTORY;
  3701. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  3702. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3703. if (diag0val & MPI_DIAG_RESET_HISTORY) {
  3704. printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
  3705. ioc->name);
  3706. }
  3707. /* Disable Diagnostic Mode
  3708. */
  3709. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
  3710. /* Check FW reload status flags.
  3711. */
  3712. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  3713. if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
  3714. printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
  3715. ioc->name, diag0val);
  3716. return -3;
  3717. }
  3718. if (ioc->debug_level & MPT_DEBUG) {
  3719. if (ioc->alt_ioc)
  3720. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  3721. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "DbG4: diag0=%08x, diag1=%08x\n",
  3722. ioc->name, diag0val, diag1val));
  3723. }
  3724. /*
  3725. * Reset flag that says we've enabled event notification
  3726. */
  3727. ioc->facts.EventState = 0;
  3728. if (ioc->alt_ioc)
  3729. ioc->alt_ioc->facts.EventState = 0;
  3730. return hard_reset_done;
  3731. }
  3732. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3733. /**
  3734. * SendIocReset - Send IOCReset request to MPT adapter.
  3735. * @ioc: Pointer to MPT_ADAPTER structure
  3736. * @reset_type: reset type, expected values are
  3737. * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
  3738. * @sleepFlag: Specifies whether the process can sleep
  3739. *
  3740. * Send IOCReset request to the MPT adapter.
  3741. *
  3742. * Returns 0 for success, non-zero for failure.
  3743. */
  3744. static int
  3745. SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
  3746. {
  3747. int r;
  3748. u32 state;
  3749. int cntdn, count;
  3750. drsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending IOC reset(0x%02x)!\n",
  3751. ioc->name, reset_type));
  3752. CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
  3753. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3754. return r;
  3755. /* FW ACK'd request, wait for READY state
  3756. */
  3757. count = 0;
  3758. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  3759. while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  3760. cntdn--;
  3761. count++;
  3762. if (!cntdn) {
  3763. if (sleepFlag != CAN_SLEEP)
  3764. count *= 10;
  3765. printk(MYIOC_s_ERR_FMT
  3766. "Wait IOC_READY state (0x%x) timeout(%d)!\n",
  3767. ioc->name, state, (int)((count+5)/HZ));
  3768. return -ETIME;
  3769. }
  3770. if (sleepFlag == CAN_SLEEP) {
  3771. msleep(1);
  3772. } else {
  3773. mdelay (1); /* 1 msec delay */
  3774. }
  3775. }
  3776. /* TODO!
  3777. * Cleanup all event stuff for this IOC; re-issue EventNotification
  3778. * request if needed.
  3779. */
  3780. if (ioc->facts.Function)
  3781. ioc->facts.EventState = 0;
  3782. return 0;
  3783. }
  3784. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3785. /**
  3786. * initChainBuffers - Allocate memory for and initialize chain buffers
  3787. * @ioc: Pointer to MPT_ADAPTER structure
  3788. *
  3789. * Allocates memory for and initializes chain buffers,
  3790. * chain buffer control arrays and spinlock.
  3791. */
  3792. static int
  3793. initChainBuffers(MPT_ADAPTER *ioc)
  3794. {
  3795. u8 *mem;
  3796. int sz, ii, num_chain;
  3797. int scale, num_sge, numSGE;
  3798. /* ReqToChain size must equal the req_depth
  3799. * index = req_idx
  3800. */
  3801. if (ioc->ReqToChain == NULL) {
  3802. sz = ioc->req_depth * sizeof(int);
  3803. mem = kmalloc(sz, GFP_ATOMIC);
  3804. if (mem == NULL)
  3805. return -1;
  3806. ioc->ReqToChain = (int *) mem;
  3807. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReqToChain alloc @ %p, sz=%d bytes\n",
  3808. ioc->name, mem, sz));
  3809. mem = kmalloc(sz, GFP_ATOMIC);
  3810. if (mem == NULL)
  3811. return -1;
  3812. ioc->RequestNB = (int *) mem;
  3813. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestNB alloc @ %p, sz=%d bytes\n",
  3814. ioc->name, mem, sz));
  3815. }
  3816. for (ii = 0; ii < ioc->req_depth; ii++) {
  3817. ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
  3818. }
  3819. /* ChainToChain size must equal the total number
  3820. * of chain buffers to be allocated.
  3821. * index = chain_idx
  3822. *
  3823. * Calculate the number of chain buffers needed(plus 1) per I/O
  3824. * then multiply the maximum number of simultaneous cmds
  3825. *
  3826. * num_sge = num sge in request frame + last chain buffer
  3827. * scale = num sge per chain buffer if no chain element
  3828. */
  3829. scale = ioc->req_sz / ioc->SGE_size;
  3830. if (ioc->sg_addr_size == sizeof(u64))
  3831. num_sge = scale + (ioc->req_sz - 60) / ioc->SGE_size;
  3832. else
  3833. num_sge = 1 + scale + (ioc->req_sz - 64) / ioc->SGE_size;
  3834. if (ioc->sg_addr_size == sizeof(u64)) {
  3835. numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  3836. (ioc->req_sz - 60) / ioc->SGE_size;
  3837. } else {
  3838. numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) +
  3839. scale + (ioc->req_sz - 64) / ioc->SGE_size;
  3840. }
  3841. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "num_sge=%d numSGE=%d\n",
  3842. ioc->name, num_sge, numSGE));
  3843. if (ioc->bus_type == FC) {
  3844. if (numSGE > MPT_SCSI_FC_SG_DEPTH)
  3845. numSGE = MPT_SCSI_FC_SG_DEPTH;
  3846. } else {
  3847. if (numSGE > MPT_SCSI_SG_DEPTH)
  3848. numSGE = MPT_SCSI_SG_DEPTH;
  3849. }
  3850. num_chain = 1;
  3851. while (numSGE - num_sge > 0) {
  3852. num_chain++;
  3853. num_sge += (scale - 1);
  3854. }
  3855. num_chain++;
  3856. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Now numSGE=%d num_sge=%d num_chain=%d\n",
  3857. ioc->name, numSGE, num_sge, num_chain));
  3858. if (ioc->bus_type == SPI)
  3859. num_chain *= MPT_SCSI_CAN_QUEUE;
  3860. else if (ioc->bus_type == SAS)
  3861. num_chain *= MPT_SAS_CAN_QUEUE;
  3862. else
  3863. num_chain *= MPT_FC_CAN_QUEUE;
  3864. ioc->num_chain = num_chain;
  3865. sz = num_chain * sizeof(int);
  3866. if (ioc->ChainToChain == NULL) {
  3867. mem = kmalloc(sz, GFP_ATOMIC);
  3868. if (mem == NULL)
  3869. return -1;
  3870. ioc->ChainToChain = (int *) mem;
  3871. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainToChain alloc @ %p, sz=%d bytes\n",
  3872. ioc->name, mem, sz));
  3873. } else {
  3874. mem = (u8 *) ioc->ChainToChain;
  3875. }
  3876. memset(mem, 0xFF, sz);
  3877. return num_chain;
  3878. }
  3879. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3880. /**
  3881. * PrimeIocFifos - Initialize IOC request and reply FIFOs.
  3882. * @ioc: Pointer to MPT_ADAPTER structure
  3883. *
  3884. * This routine allocates memory for the MPT reply and request frame
  3885. * pools (if necessary), and primes the IOC reply FIFO with
  3886. * reply frames.
  3887. *
  3888. * Returns 0 for success, non-zero for failure.
  3889. */
  3890. static int
  3891. PrimeIocFifos(MPT_ADAPTER *ioc)
  3892. {
  3893. MPT_FRAME_HDR *mf;
  3894. unsigned long flags;
  3895. dma_addr_t alloc_dma;
  3896. u8 *mem;
  3897. int i, reply_sz, sz, total_size, num_chain;
  3898. u64 dma_mask;
  3899. dma_mask = 0;
  3900. /* Prime reply FIFO... */
  3901. if (ioc->reply_frames == NULL) {
  3902. if ( (num_chain = initChainBuffers(ioc)) < 0)
  3903. return -1;
  3904. /*
  3905. * 1078 errata workaround for the 36GB limitation
  3906. */
  3907. if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078 &&
  3908. ioc->dma_mask > DMA_BIT_MASK(35)) {
  3909. if (!pci_set_dma_mask(ioc->pcidev, DMA_BIT_MASK(32))
  3910. && !pci_set_consistent_dma_mask(ioc->pcidev,
  3911. DMA_BIT_MASK(32))) {
  3912. dma_mask = DMA_BIT_MASK(35);
  3913. d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  3914. "setting 35 bit addressing for "
  3915. "Request/Reply/Chain and Sense Buffers\n",
  3916. ioc->name));
  3917. } else {
  3918. /*Reseting DMA mask to 64 bit*/
  3919. pci_set_dma_mask(ioc->pcidev,
  3920. DMA_BIT_MASK(64));
  3921. pci_set_consistent_dma_mask(ioc->pcidev,
  3922. DMA_BIT_MASK(64));
  3923. printk(MYIOC_s_ERR_FMT
  3924. "failed setting 35 bit addressing for "
  3925. "Request/Reply/Chain and Sense Buffers\n",
  3926. ioc->name);
  3927. return -1;
  3928. }
  3929. }
  3930. total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
  3931. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
  3932. ioc->name, ioc->reply_sz, ioc->reply_depth));
  3933. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffer sz=%d[%x] bytes\n",
  3934. ioc->name, reply_sz, reply_sz));
  3935. sz = (ioc->req_sz * ioc->req_depth);
  3936. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffer sz=%d bytes, RequestDepth=%d\n",
  3937. ioc->name, ioc->req_sz, ioc->req_depth));
  3938. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffer sz=%d[%x] bytes\n",
  3939. ioc->name, sz, sz));
  3940. total_size += sz;
  3941. sz = num_chain * ioc->req_sz; /* chain buffer pool size */
  3942. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffer sz=%d bytes, ChainDepth=%d\n",
  3943. ioc->name, ioc->req_sz, num_chain));
  3944. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
  3945. ioc->name, sz, sz, num_chain));
  3946. total_size += sz;
  3947. mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
  3948. if (mem == NULL) {
  3949. printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
  3950. ioc->name);
  3951. goto out_fail;
  3952. }
  3953. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Total alloc @ %p[%p], sz=%d[%x] bytes\n",
  3954. ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
  3955. memset(mem, 0, total_size);
  3956. ioc->alloc_total += total_size;
  3957. ioc->alloc = mem;
  3958. ioc->alloc_dma = alloc_dma;
  3959. ioc->alloc_sz = total_size;
  3960. ioc->reply_frames = (MPT_FRAME_HDR *) mem;
  3961. ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3962. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffers @ %p[%p]\n",
  3963. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3964. alloc_dma += reply_sz;
  3965. mem += reply_sz;
  3966. /* Request FIFO - WE manage this! */
  3967. ioc->req_frames = (MPT_FRAME_HDR *) mem;
  3968. ioc->req_frames_dma = alloc_dma;
  3969. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "RequestBuffers @ %p[%p]\n",
  3970. ioc->name, mem, (void *)(ulong)alloc_dma));
  3971. ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3972. for (i = 0; i < ioc->req_depth; i++) {
  3973. alloc_dma += ioc->req_sz;
  3974. mem += ioc->req_sz;
  3975. }
  3976. ioc->ChainBuffer = mem;
  3977. ioc->ChainBufferDMA = alloc_dma;
  3978. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ChainBuffers @ %p(%p)\n",
  3979. ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
  3980. /* Initialize the free chain Q.
  3981. */
  3982. INIT_LIST_HEAD(&ioc->FreeChainQ);
  3983. /* Post the chain buffers to the FreeChainQ.
  3984. */
  3985. mem = (u8 *)ioc->ChainBuffer;
  3986. for (i=0; i < num_chain; i++) {
  3987. mf = (MPT_FRAME_HDR *) mem;
  3988. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
  3989. mem += ioc->req_sz;
  3990. }
  3991. /* Initialize Request frames linked list
  3992. */
  3993. alloc_dma = ioc->req_frames_dma;
  3994. mem = (u8 *) ioc->req_frames;
  3995. spin_lock_irqsave(&ioc->FreeQlock, flags);
  3996. INIT_LIST_HEAD(&ioc->FreeQ);
  3997. for (i = 0; i < ioc->req_depth; i++) {
  3998. mf = (MPT_FRAME_HDR *) mem;
  3999. /* Queue REQUESTs *internally*! */
  4000. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  4001. mem += ioc->req_sz;
  4002. }
  4003. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4004. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  4005. ioc->sense_buf_pool =
  4006. pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
  4007. if (ioc->sense_buf_pool == NULL) {
  4008. printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
  4009. ioc->name);
  4010. goto out_fail;
  4011. }
  4012. ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
  4013. ioc->alloc_total += sz;
  4014. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SenseBuffers @ %p[%p]\n",
  4015. ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
  4016. }
  4017. /* Post Reply frames to FIFO
  4018. */
  4019. alloc_dma = ioc->alloc_dma;
  4020. dinitprintk(ioc, printk(MYIOC_s_DEBUG_FMT "ReplyBuffers @ %p[%p]\n",
  4021. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  4022. for (i = 0; i < ioc->reply_depth; i++) {
  4023. /* Write each address to the IOC! */
  4024. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
  4025. alloc_dma += ioc->reply_sz;
  4026. }
  4027. if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
  4028. ioc->dma_mask) && !pci_set_consistent_dma_mask(ioc->pcidev,
  4029. ioc->dma_mask))
  4030. d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4031. "restoring 64 bit addressing\n", ioc->name));
  4032. return 0;
  4033. out_fail:
  4034. if (ioc->alloc != NULL) {
  4035. sz = ioc->alloc_sz;
  4036. pci_free_consistent(ioc->pcidev,
  4037. sz,
  4038. ioc->alloc, ioc->alloc_dma);
  4039. ioc->reply_frames = NULL;
  4040. ioc->req_frames = NULL;
  4041. ioc->alloc_total -= sz;
  4042. }
  4043. if (ioc->sense_buf_pool != NULL) {
  4044. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  4045. pci_free_consistent(ioc->pcidev,
  4046. sz,
  4047. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  4048. ioc->sense_buf_pool = NULL;
  4049. }
  4050. if (dma_mask == DMA_BIT_MASK(35) && !pci_set_dma_mask(ioc->pcidev,
  4051. DMA_BIT_MASK(64)) && !pci_set_consistent_dma_mask(ioc->pcidev,
  4052. DMA_BIT_MASK(64)))
  4053. d36memprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4054. "restoring 64 bit addressing\n", ioc->name));
  4055. return -1;
  4056. }
  4057. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4058. /**
  4059. * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
  4060. * from IOC via doorbell handshake method.
  4061. * @ioc: Pointer to MPT_ADAPTER structure
  4062. * @reqBytes: Size of the request in bytes
  4063. * @req: Pointer to MPT request frame
  4064. * @replyBytes: Expected size of the reply in bytes
  4065. * @u16reply: Pointer to area where reply should be written
  4066. * @maxwait: Max wait time for a reply (in seconds)
  4067. * @sleepFlag: Specifies whether the process can sleep
  4068. *
  4069. * NOTES: It is the callers responsibility to byte-swap fields in the
  4070. * request which are greater than 1 byte in size. It is also the
  4071. * callers responsibility to byte-swap response fields which are
  4072. * greater than 1 byte in size.
  4073. *
  4074. * Returns 0 for success, non-zero for failure.
  4075. */
  4076. static int
  4077. mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
  4078. int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
  4079. {
  4080. MPIDefaultReply_t *mptReply;
  4081. int failcnt = 0;
  4082. int t;
  4083. /*
  4084. * Get ready to cache a handshake reply
  4085. */
  4086. ioc->hs_reply_idx = 0;
  4087. mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  4088. mptReply->MsgLength = 0;
  4089. /*
  4090. * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
  4091. * then tell IOC that we want to handshake a request of N words.
  4092. * (WRITE u32val to Doorbell reg).
  4093. */
  4094. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4095. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  4096. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  4097. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  4098. /*
  4099. * Wait for IOC's doorbell handshake int
  4100. */
  4101. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4102. failcnt++;
  4103. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
  4104. ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  4105. /* Read doorbell and check for active bit */
  4106. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  4107. return -1;
  4108. /*
  4109. * Clear doorbell int (WRITE 0 to IntStatus reg),
  4110. * then wait for IOC to ACKnowledge that it's ready for
  4111. * our handshake request.
  4112. */
  4113. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4114. if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  4115. failcnt++;
  4116. if (!failcnt) {
  4117. int ii;
  4118. u8 *req_as_bytes = (u8 *) req;
  4119. /*
  4120. * Stuff request words via doorbell handshake,
  4121. * with ACK from IOC for each.
  4122. */
  4123. for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
  4124. u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
  4125. (req_as_bytes[(ii*4) + 1] << 8) |
  4126. (req_as_bytes[(ii*4) + 2] << 16) |
  4127. (req_as_bytes[(ii*4) + 3] << 24));
  4128. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  4129. if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  4130. failcnt++;
  4131. }
  4132. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Handshake request frame (@%p) header\n", ioc->name, req));
  4133. DBG_DUMP_REQUEST_FRAME_HDR(ioc, (u32 *)req);
  4134. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake request post done, WaitCnt=%d%s\n",
  4135. ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
  4136. /*
  4137. * Wait for completion of doorbell handshake reply from the IOC
  4138. */
  4139. if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
  4140. failcnt++;
  4141. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HandShake reply count=%d%s\n",
  4142. ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
  4143. /*
  4144. * Copy out the cached reply...
  4145. */
  4146. for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
  4147. u16reply[ii] = ioc->hs_reply[ii];
  4148. } else {
  4149. return -99;
  4150. }
  4151. return -failcnt;
  4152. }
  4153. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4154. /**
  4155. * WaitForDoorbellAck - Wait for IOC doorbell handshake acknowledge
  4156. * @ioc: Pointer to MPT_ADAPTER structure
  4157. * @howlong: How long to wait (in seconds)
  4158. * @sleepFlag: Specifies whether the process can sleep
  4159. *
  4160. * This routine waits (up to ~2 seconds max) for IOC doorbell
  4161. * handshake ACKnowledge, indicated by the IOP_DOORBELL_STATUS
  4162. * bit in its IntStatus register being clear.
  4163. *
  4164. * Returns a negative value on failure, else wait loop count.
  4165. */
  4166. static int
  4167. WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  4168. {
  4169. int cntdn;
  4170. int count = 0;
  4171. u32 intstat=0;
  4172. cntdn = 1000 * howlong;
  4173. if (sleepFlag == CAN_SLEEP) {
  4174. while (--cntdn) {
  4175. msleep (1);
  4176. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4177. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  4178. break;
  4179. count++;
  4180. }
  4181. } else {
  4182. while (--cntdn) {
  4183. udelay (1000);
  4184. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4185. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  4186. break;
  4187. count++;
  4188. }
  4189. }
  4190. if (cntdn) {
  4191. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell ACK (count=%d)\n",
  4192. ioc->name, count));
  4193. return count;
  4194. }
  4195. printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
  4196. ioc->name, count, intstat);
  4197. return -1;
  4198. }
  4199. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4200. /**
  4201. * WaitForDoorbellInt - Wait for IOC to set its doorbell interrupt bit
  4202. * @ioc: Pointer to MPT_ADAPTER structure
  4203. * @howlong: How long to wait (in seconds)
  4204. * @sleepFlag: Specifies whether the process can sleep
  4205. *
  4206. * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt
  4207. * (MPI_HIS_DOORBELL_INTERRUPT) to be set in the IntStatus register.
  4208. *
  4209. * Returns a negative value on failure, else wait loop count.
  4210. */
  4211. static int
  4212. WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  4213. {
  4214. int cntdn;
  4215. int count = 0;
  4216. u32 intstat=0;
  4217. cntdn = 1000 * howlong;
  4218. if (sleepFlag == CAN_SLEEP) {
  4219. while (--cntdn) {
  4220. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4221. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  4222. break;
  4223. msleep(1);
  4224. count++;
  4225. }
  4226. } else {
  4227. while (--cntdn) {
  4228. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  4229. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  4230. break;
  4231. udelay (1000);
  4232. count++;
  4233. }
  4234. }
  4235. if (cntdn) {
  4236. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
  4237. ioc->name, count, howlong));
  4238. return count;
  4239. }
  4240. printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
  4241. ioc->name, count, intstat);
  4242. return -1;
  4243. }
  4244. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4245. /**
  4246. * WaitForDoorbellReply - Wait for and capture an IOC handshake reply.
  4247. * @ioc: Pointer to MPT_ADAPTER structure
  4248. * @howlong: How long to wait (in seconds)
  4249. * @sleepFlag: Specifies whether the process can sleep
  4250. *
  4251. * This routine polls the IOC for a handshake reply, 16 bits at a time.
  4252. * Reply is cached to IOC private area large enough to hold a maximum
  4253. * of 128 bytes of reply data.
  4254. *
  4255. * Returns a negative value on failure, else size of reply in WORDS.
  4256. */
  4257. static int
  4258. WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  4259. {
  4260. int u16cnt = 0;
  4261. int failcnt = 0;
  4262. int t;
  4263. u16 *hs_reply = ioc->hs_reply;
  4264. volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  4265. u16 hword;
  4266. hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
  4267. /*
  4268. * Get first two u16's so we can look at IOC's intended reply MsgLength
  4269. */
  4270. u16cnt=0;
  4271. if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
  4272. failcnt++;
  4273. } else {
  4274. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  4275. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4276. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4277. failcnt++;
  4278. else {
  4279. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  4280. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4281. }
  4282. }
  4283. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
  4284. ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
  4285. failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  4286. /*
  4287. * If no error (and IOC said MsgLength is > 0), piece together
  4288. * reply 16 bits at a time.
  4289. */
  4290. for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
  4291. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4292. failcnt++;
  4293. hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  4294. /* don't overflow our IOC hs_reply[] buffer! */
  4295. if (u16cnt < ARRAY_SIZE(ioc->hs_reply))
  4296. hs_reply[u16cnt] = hword;
  4297. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4298. }
  4299. if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  4300. failcnt++;
  4301. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  4302. if (failcnt) {
  4303. printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
  4304. ioc->name);
  4305. return -failcnt;
  4306. }
  4307. #if 0
  4308. else if (u16cnt != (2 * mptReply->MsgLength)) {
  4309. return -101;
  4310. }
  4311. else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
  4312. return -102;
  4313. }
  4314. #endif
  4315. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Got Handshake reply:\n", ioc->name));
  4316. DBG_DUMP_REPLY_FRAME(ioc, (u32 *)mptReply);
  4317. dhsprintk(ioc, printk(MYIOC_s_DEBUG_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
  4318. ioc->name, t, u16cnt/2));
  4319. return u16cnt/2;
  4320. }
  4321. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4322. /**
  4323. * GetLanConfigPages - Fetch LANConfig pages.
  4324. * @ioc: Pointer to MPT_ADAPTER structure
  4325. *
  4326. * Return: 0 for success
  4327. * -ENOMEM if no memory available
  4328. * -EPERM if not allowed due to ISR context
  4329. * -EAGAIN if no msg frames currently available
  4330. * -EFAULT for non-successful reply or no reply (timeout)
  4331. */
  4332. static int
  4333. GetLanConfigPages(MPT_ADAPTER *ioc)
  4334. {
  4335. ConfigPageHeader_t hdr;
  4336. CONFIGPARMS cfg;
  4337. LANPage0_t *ppage0_alloc;
  4338. dma_addr_t page0_dma;
  4339. LANPage1_t *ppage1_alloc;
  4340. dma_addr_t page1_dma;
  4341. int rc = 0;
  4342. int data_sz;
  4343. int copy_sz;
  4344. /* Get LAN Page 0 header */
  4345. hdr.PageVersion = 0;
  4346. hdr.PageLength = 0;
  4347. hdr.PageNumber = 0;
  4348. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  4349. cfg.cfghdr.hdr = &hdr;
  4350. cfg.physAddr = -1;
  4351. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4352. cfg.dir = 0;
  4353. cfg.pageAddr = 0;
  4354. cfg.timeout = 0;
  4355. if ((rc = mpt_config(ioc, &cfg)) != 0)
  4356. return rc;
  4357. if (hdr.PageLength > 0) {
  4358. data_sz = hdr.PageLength * 4;
  4359. ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  4360. rc = -ENOMEM;
  4361. if (ppage0_alloc) {
  4362. memset((u8 *)ppage0_alloc, 0, data_sz);
  4363. cfg.physAddr = page0_dma;
  4364. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4365. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  4366. /* save the data */
  4367. copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
  4368. memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
  4369. }
  4370. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  4371. /* FIXME!
  4372. * Normalize endianness of structure data,
  4373. * by byte-swapping all > 1 byte fields!
  4374. */
  4375. }
  4376. if (rc)
  4377. return rc;
  4378. }
  4379. /* Get LAN Page 1 header */
  4380. hdr.PageVersion = 0;
  4381. hdr.PageLength = 0;
  4382. hdr.PageNumber = 1;
  4383. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  4384. cfg.cfghdr.hdr = &hdr;
  4385. cfg.physAddr = -1;
  4386. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4387. cfg.dir = 0;
  4388. cfg.pageAddr = 0;
  4389. if ((rc = mpt_config(ioc, &cfg)) != 0)
  4390. return rc;
  4391. if (hdr.PageLength == 0)
  4392. return 0;
  4393. data_sz = hdr.PageLength * 4;
  4394. rc = -ENOMEM;
  4395. ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
  4396. if (ppage1_alloc) {
  4397. memset((u8 *)ppage1_alloc, 0, data_sz);
  4398. cfg.physAddr = page1_dma;
  4399. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4400. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  4401. /* save the data */
  4402. copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
  4403. memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
  4404. }
  4405. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
  4406. /* FIXME!
  4407. * Normalize endianness of structure data,
  4408. * by byte-swapping all > 1 byte fields!
  4409. */
  4410. }
  4411. return rc;
  4412. }
  4413. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4414. /**
  4415. * mptbase_sas_persist_operation - Perform operation on SAS Persistent Table
  4416. * @ioc: Pointer to MPT_ADAPTER structure
  4417. * @persist_opcode: see below
  4418. *
  4419. * MPI_SAS_OP_CLEAR_NOT_PRESENT - Free all persist TargetID mappings for
  4420. * devices not currently present.
  4421. * MPI_SAS_OP_CLEAR_ALL_PERSISTENT - Clear al persist TargetID mappings
  4422. *
  4423. * NOTE: Don't use not this function during interrupt time.
  4424. *
  4425. * Returns 0 for success, non-zero error
  4426. */
  4427. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4428. int
  4429. mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
  4430. {
  4431. SasIoUnitControlRequest_t *sasIoUnitCntrReq;
  4432. SasIoUnitControlReply_t *sasIoUnitCntrReply;
  4433. MPT_FRAME_HDR *mf = NULL;
  4434. MPIHeader_t *mpi_hdr;
  4435. int ret = 0;
  4436. unsigned long timeleft;
  4437. mutex_lock(&ioc->mptbase_cmds.mutex);
  4438. /* init the internal cmd struct */
  4439. memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
  4440. INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
  4441. /* insure garbage is not sent to fw */
  4442. switch(persist_opcode) {
  4443. case MPI_SAS_OP_CLEAR_NOT_PRESENT:
  4444. case MPI_SAS_OP_CLEAR_ALL_PERSISTENT:
  4445. break;
  4446. default:
  4447. ret = -1;
  4448. goto out;
  4449. }
  4450. printk(KERN_DEBUG "%s: persist_opcode=%x\n",
  4451. __func__, persist_opcode);
  4452. /* Get a MF for this command.
  4453. */
  4454. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4455. printk(KERN_DEBUG "%s: no msg frames!\n", __func__);
  4456. ret = -1;
  4457. goto out;
  4458. }
  4459. mpi_hdr = (MPIHeader_t *) mf;
  4460. sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
  4461. memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
  4462. sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
  4463. sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
  4464. sasIoUnitCntrReq->Operation = persist_opcode;
  4465. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4466. timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done, 10*HZ);
  4467. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  4468. ret = -ETIME;
  4469. printk(KERN_DEBUG "%s: failed\n", __func__);
  4470. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  4471. goto out;
  4472. if (!timeleft) {
  4473. printk(MYIOC_s_WARN_FMT
  4474. "Issuing Reset from %s!!, doorbell=0x%08x\n",
  4475. ioc->name, __func__, mpt_GetIocState(ioc, 0));
  4476. mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP);
  4477. mpt_free_msg_frame(ioc, mf);
  4478. }
  4479. goto out;
  4480. }
  4481. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  4482. ret = -1;
  4483. goto out;
  4484. }
  4485. sasIoUnitCntrReply =
  4486. (SasIoUnitControlReply_t *)ioc->mptbase_cmds.reply;
  4487. if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
  4488. printk(KERN_DEBUG "%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
  4489. __func__, sasIoUnitCntrReply->IOCStatus,
  4490. sasIoUnitCntrReply->IOCLogInfo);
  4491. printk(KERN_DEBUG "%s: failed\n", __func__);
  4492. ret = -1;
  4493. } else
  4494. printk(KERN_DEBUG "%s: success\n", __func__);
  4495. out:
  4496. CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
  4497. mutex_unlock(&ioc->mptbase_cmds.mutex);
  4498. return ret;
  4499. }
  4500. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4501. static void
  4502. mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
  4503. MpiEventDataRaid_t * pRaidEventData)
  4504. {
  4505. int volume;
  4506. int reason;
  4507. int disk;
  4508. int status;
  4509. int flags;
  4510. int state;
  4511. volume = pRaidEventData->VolumeID;
  4512. reason = pRaidEventData->ReasonCode;
  4513. disk = pRaidEventData->PhysDiskNum;
  4514. status = le32_to_cpu(pRaidEventData->SettingsStatus);
  4515. flags = (status >> 0) & 0xff;
  4516. state = (status >> 8) & 0xff;
  4517. if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
  4518. return;
  4519. }
  4520. if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED &&
  4521. reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) ||
  4522. (reason == MPI_EVENT_RAID_RC_SMART_DATA)) {
  4523. printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d id=%d\n",
  4524. ioc->name, disk, volume);
  4525. } else {
  4526. printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n",
  4527. ioc->name, volume);
  4528. }
  4529. switch(reason) {
  4530. case MPI_EVENT_RAID_RC_VOLUME_CREATED:
  4531. printk(MYIOC_s_INFO_FMT " volume has been created\n",
  4532. ioc->name);
  4533. break;
  4534. case MPI_EVENT_RAID_RC_VOLUME_DELETED:
  4535. printk(MYIOC_s_INFO_FMT " volume has been deleted\n",
  4536. ioc->name);
  4537. break;
  4538. case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED:
  4539. printk(MYIOC_s_INFO_FMT " volume settings have been changed\n",
  4540. ioc->name);
  4541. break;
  4542. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
  4543. printk(MYIOC_s_INFO_FMT " volume is now %s%s%s%s\n",
  4544. ioc->name,
  4545. state == MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
  4546. ? "optimal"
  4547. : state == MPI_RAIDVOL0_STATUS_STATE_DEGRADED
  4548. ? "degraded"
  4549. : state == MPI_RAIDVOL0_STATUS_STATE_FAILED
  4550. ? "failed"
  4551. : "state unknown",
  4552. flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED
  4553. ? ", enabled" : "",
  4554. flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
  4555. ? ", quiesced" : "",
  4556. flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
  4557. ? ", resync in progress" : "" );
  4558. break;
  4559. case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED:
  4560. printk(MYIOC_s_INFO_FMT " volume membership of PhysDisk %d has changed\n",
  4561. ioc->name, disk);
  4562. break;
  4563. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
  4564. printk(MYIOC_s_INFO_FMT " PhysDisk has been created\n",
  4565. ioc->name);
  4566. break;
  4567. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
  4568. printk(MYIOC_s_INFO_FMT " PhysDisk has been deleted\n",
  4569. ioc->name);
  4570. break;
  4571. case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED:
  4572. printk(MYIOC_s_INFO_FMT " PhysDisk settings have been changed\n",
  4573. ioc->name);
  4574. break;
  4575. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
  4576. printk(MYIOC_s_INFO_FMT " PhysDisk is now %s%s%s\n",
  4577. ioc->name,
  4578. state == MPI_PHYSDISK0_STATUS_ONLINE
  4579. ? "online"
  4580. : state == MPI_PHYSDISK0_STATUS_MISSING
  4581. ? "missing"
  4582. : state == MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE
  4583. ? "not compatible"
  4584. : state == MPI_PHYSDISK0_STATUS_FAILED
  4585. ? "failed"
  4586. : state == MPI_PHYSDISK0_STATUS_INITIALIZING
  4587. ? "initializing"
  4588. : state == MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED
  4589. ? "offline requested"
  4590. : state == MPI_PHYSDISK0_STATUS_FAILED_REQUESTED
  4591. ? "failed requested"
  4592. : state == MPI_PHYSDISK0_STATUS_OTHER_OFFLINE
  4593. ? "offline"
  4594. : "state unknown",
  4595. flags & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC
  4596. ? ", out of sync" : "",
  4597. flags & MPI_PHYSDISK0_STATUS_FLAG_QUIESCED
  4598. ? ", quiesced" : "" );
  4599. break;
  4600. case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED:
  4601. printk(MYIOC_s_INFO_FMT " Domain Validation needed for PhysDisk %d\n",
  4602. ioc->name, disk);
  4603. break;
  4604. case MPI_EVENT_RAID_RC_SMART_DATA:
  4605. printk(MYIOC_s_INFO_FMT " SMART data received, ASC/ASCQ = %02xh/%02xh\n",
  4606. ioc->name, pRaidEventData->ASC, pRaidEventData->ASCQ);
  4607. break;
  4608. case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED:
  4609. printk(MYIOC_s_INFO_FMT " replacement of PhysDisk %d has started\n",
  4610. ioc->name, disk);
  4611. break;
  4612. }
  4613. }
  4614. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4615. /**
  4616. * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
  4617. * @ioc: Pointer to MPT_ADAPTER structure
  4618. *
  4619. * Returns: 0 for success
  4620. * -ENOMEM if no memory available
  4621. * -EPERM if not allowed due to ISR context
  4622. * -EAGAIN if no msg frames currently available
  4623. * -EFAULT for non-successful reply or no reply (timeout)
  4624. */
  4625. static int
  4626. GetIoUnitPage2(MPT_ADAPTER *ioc)
  4627. {
  4628. ConfigPageHeader_t hdr;
  4629. CONFIGPARMS cfg;
  4630. IOUnitPage2_t *ppage_alloc;
  4631. dma_addr_t page_dma;
  4632. int data_sz;
  4633. int rc;
  4634. /* Get the page header */
  4635. hdr.PageVersion = 0;
  4636. hdr.PageLength = 0;
  4637. hdr.PageNumber = 2;
  4638. hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
  4639. cfg.cfghdr.hdr = &hdr;
  4640. cfg.physAddr = -1;
  4641. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4642. cfg.dir = 0;
  4643. cfg.pageAddr = 0;
  4644. cfg.timeout = 0;
  4645. if ((rc = mpt_config(ioc, &cfg)) != 0)
  4646. return rc;
  4647. if (hdr.PageLength == 0)
  4648. return 0;
  4649. /* Read the config page */
  4650. data_sz = hdr.PageLength * 4;
  4651. rc = -ENOMEM;
  4652. ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  4653. if (ppage_alloc) {
  4654. memset((u8 *)ppage_alloc, 0, data_sz);
  4655. cfg.physAddr = page_dma;
  4656. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4657. /* If Good, save data */
  4658. if ((rc = mpt_config(ioc, &cfg)) == 0)
  4659. ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
  4660. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
  4661. }
  4662. return rc;
  4663. }
  4664. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4665. /**
  4666. * mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
  4667. * @ioc: Pointer to a Adapter Strucutre
  4668. * @portnum: IOC port number
  4669. *
  4670. * Return: -EFAULT if read of config page header fails
  4671. * or if no nvram
  4672. * If read of SCSI Port Page 0 fails,
  4673. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  4674. * Adapter settings: async, narrow
  4675. * Return 1
  4676. * If read of SCSI Port Page 2 fails,
  4677. * Adapter settings valid
  4678. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  4679. * Return 1
  4680. * Else
  4681. * Both valid
  4682. * Return 0
  4683. * CHECK - what type of locking mechanisms should be used????
  4684. */
  4685. static int
  4686. mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
  4687. {
  4688. u8 *pbuf;
  4689. dma_addr_t buf_dma;
  4690. CONFIGPARMS cfg;
  4691. ConfigPageHeader_t header;
  4692. int ii;
  4693. int data, rc = 0;
  4694. /* Allocate memory
  4695. */
  4696. if (!ioc->spi_data.nvram) {
  4697. int sz;
  4698. u8 *mem;
  4699. sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
  4700. mem = kmalloc(sz, GFP_ATOMIC);
  4701. if (mem == NULL)
  4702. return -EFAULT;
  4703. ioc->spi_data.nvram = (int *) mem;
  4704. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
  4705. ioc->name, ioc->spi_data.nvram, sz));
  4706. }
  4707. /* Invalidate NVRAM information
  4708. */
  4709. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4710. ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
  4711. }
  4712. /* Read SPP0 header, allocate memory, then read page.
  4713. */
  4714. header.PageVersion = 0;
  4715. header.PageLength = 0;
  4716. header.PageNumber = 0;
  4717. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  4718. cfg.cfghdr.hdr = &header;
  4719. cfg.physAddr = -1;
  4720. cfg.pageAddr = portnum;
  4721. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4722. cfg.dir = 0;
  4723. cfg.timeout = 0; /* use default */
  4724. if (mpt_config(ioc, &cfg) != 0)
  4725. return -EFAULT;
  4726. if (header.PageLength > 0) {
  4727. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  4728. if (pbuf) {
  4729. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4730. cfg.physAddr = buf_dma;
  4731. if (mpt_config(ioc, &cfg) != 0) {
  4732. ioc->spi_data.maxBusWidth = MPT_NARROW;
  4733. ioc->spi_data.maxSyncOffset = 0;
  4734. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  4735. ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
  4736. rc = 1;
  4737. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4738. "Unable to read PortPage0 minSyncFactor=%x\n",
  4739. ioc->name, ioc->spi_data.minSyncFactor));
  4740. } else {
  4741. /* Save the Port Page 0 data
  4742. */
  4743. SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
  4744. pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
  4745. pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
  4746. if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
  4747. ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
  4748. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4749. "noQas due to Capabilities=%x\n",
  4750. ioc->name, pPP0->Capabilities));
  4751. }
  4752. ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
  4753. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
  4754. if (data) {
  4755. ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
  4756. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
  4757. ioc->spi_data.minSyncFactor = (u8) (data >> 8);
  4758. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4759. "PortPage0 minSyncFactor=%x\n",
  4760. ioc->name, ioc->spi_data.minSyncFactor));
  4761. } else {
  4762. ioc->spi_data.maxSyncOffset = 0;
  4763. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  4764. }
  4765. ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
  4766. /* Update the minSyncFactor based on bus type.
  4767. */
  4768. if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
  4769. (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
  4770. if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
  4771. ioc->spi_data.minSyncFactor = MPT_ULTRA;
  4772. ddvprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  4773. "HVD or SE detected, minSyncFactor=%x\n",
  4774. ioc->name, ioc->spi_data.minSyncFactor));
  4775. }
  4776. }
  4777. }
  4778. if (pbuf) {
  4779. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  4780. }
  4781. }
  4782. }
  4783. /* SCSI Port Page 2 - Read the header then the page.
  4784. */
  4785. header.PageVersion = 0;
  4786. header.PageLength = 0;
  4787. header.PageNumber = 2;
  4788. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  4789. cfg.cfghdr.hdr = &header;
  4790. cfg.physAddr = -1;
  4791. cfg.pageAddr = portnum;
  4792. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4793. cfg.dir = 0;
  4794. if (mpt_config(ioc, &cfg) != 0)
  4795. return -EFAULT;
  4796. if (header.PageLength > 0) {
  4797. /* Allocate memory and read SCSI Port Page 2
  4798. */
  4799. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  4800. if (pbuf) {
  4801. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
  4802. cfg.physAddr = buf_dma;
  4803. if (mpt_config(ioc, &cfg) != 0) {
  4804. /* Nvram data is left with INVALID mark
  4805. */
  4806. rc = 1;
  4807. } else if (ioc->pcidev->vendor == PCI_VENDOR_ID_ATTO) {
  4808. /* This is an ATTO adapter, read Page2 accordingly
  4809. */
  4810. ATTO_SCSIPortPage2_t *pPP2 = (ATTO_SCSIPortPage2_t *) pbuf;
  4811. ATTODeviceInfo_t *pdevice = NULL;
  4812. u16 ATTOFlags;
  4813. /* Save the Port Page 2 data
  4814. * (reformat into a 32bit quantity)
  4815. */
  4816. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4817. pdevice = &pPP2->DeviceSettings[ii];
  4818. ATTOFlags = le16_to_cpu(pdevice->ATTOFlags);
  4819. data = 0;
  4820. /* Translate ATTO device flags to LSI format
  4821. */
  4822. if (ATTOFlags & ATTOFLAG_DISC)
  4823. data |= (MPI_SCSIPORTPAGE2_DEVICE_DISCONNECT_ENABLE);
  4824. if (ATTOFlags & ATTOFLAG_ID_ENB)
  4825. data |= (MPI_SCSIPORTPAGE2_DEVICE_ID_SCAN_ENABLE);
  4826. if (ATTOFlags & ATTOFLAG_LUN_ENB)
  4827. data |= (MPI_SCSIPORTPAGE2_DEVICE_LUN_SCAN_ENABLE);
  4828. if (ATTOFlags & ATTOFLAG_TAGGED)
  4829. data |= (MPI_SCSIPORTPAGE2_DEVICE_TAG_QUEUE_ENABLE);
  4830. if (!(ATTOFlags & ATTOFLAG_WIDE_ENB))
  4831. data |= (MPI_SCSIPORTPAGE2_DEVICE_WIDE_DISABLE);
  4832. data = (data << 16) | (pdevice->Period << 8) | 10;
  4833. ioc->spi_data.nvram[ii] = data;
  4834. }
  4835. } else {
  4836. SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
  4837. MpiDeviceInfo_t *pdevice = NULL;
  4838. /*
  4839. * Save "Set to Avoid SCSI Bus Resets" flag
  4840. */
  4841. ioc->spi_data.bus_reset =
  4842. (le32_to_cpu(pPP2->PortFlags) &
  4843. MPI_SCSIPORTPAGE2_PORT_FLAGS_AVOID_SCSI_RESET) ?
  4844. 0 : 1 ;
  4845. /* Save the Port Page 2 data
  4846. * (reformat into a 32bit quantity)
  4847. */
  4848. data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
  4849. ioc->spi_data.PortFlags = data;
  4850. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4851. pdevice = &pPP2->DeviceSettings[ii];
  4852. data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
  4853. (pdevice->SyncFactor << 8) | pdevice->Timeout;
  4854. ioc->spi_data.nvram[ii] = data;
  4855. }
  4856. }
  4857. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  4858. }
  4859. }
  4860. /* Update Adapter limits with those from NVRAM
  4861. * Comment: Don't need to do this. Target performance
  4862. * parameters will never exceed the adapters limits.
  4863. */
  4864. return rc;
  4865. }
  4866. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4867. /**
  4868. * mpt_readScsiDevicePageHeaders - save version and length of SDP1
  4869. * @ioc: Pointer to a Adapter Strucutre
  4870. * @portnum: IOC port number
  4871. *
  4872. * Return: -EFAULT if read of config page header fails
  4873. * or 0 if success.
  4874. */
  4875. static int
  4876. mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
  4877. {
  4878. CONFIGPARMS cfg;
  4879. ConfigPageHeader_t header;
  4880. /* Read the SCSI Device Page 1 header
  4881. */
  4882. header.PageVersion = 0;
  4883. header.PageLength = 0;
  4884. header.PageNumber = 1;
  4885. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  4886. cfg.cfghdr.hdr = &header;
  4887. cfg.physAddr = -1;
  4888. cfg.pageAddr = portnum;
  4889. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4890. cfg.dir = 0;
  4891. cfg.timeout = 0;
  4892. if (mpt_config(ioc, &cfg) != 0)
  4893. return -EFAULT;
  4894. ioc->spi_data.sdp1version = cfg.cfghdr.hdr->PageVersion;
  4895. ioc->spi_data.sdp1length = cfg.cfghdr.hdr->PageLength;
  4896. header.PageVersion = 0;
  4897. header.PageLength = 0;
  4898. header.PageNumber = 0;
  4899. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  4900. if (mpt_config(ioc, &cfg) != 0)
  4901. return -EFAULT;
  4902. ioc->spi_data.sdp0version = cfg.cfghdr.hdr->PageVersion;
  4903. ioc->spi_data.sdp0length = cfg.cfghdr.hdr->PageLength;
  4904. dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Headers: 0: version %d length %d\n",
  4905. ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
  4906. dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Headers: 1: version %d length %d\n",
  4907. ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
  4908. return 0;
  4909. }
  4910. /**
  4911. * mpt_inactive_raid_list_free - This clears this link list.
  4912. * @ioc : pointer to per adapter structure
  4913. **/
  4914. static void
  4915. mpt_inactive_raid_list_free(MPT_ADAPTER *ioc)
  4916. {
  4917. struct inactive_raid_component_info *component_info, *pNext;
  4918. if (list_empty(&ioc->raid_data.inactive_list))
  4919. return;
  4920. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  4921. list_for_each_entry_safe(component_info, pNext,
  4922. &ioc->raid_data.inactive_list, list) {
  4923. list_del(&component_info->list);
  4924. kfree(component_info);
  4925. }
  4926. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  4927. }
  4928. /**
  4929. * mpt_inactive_raid_volumes - sets up link list of phy_disk_nums for devices belonging in an inactive volume
  4930. *
  4931. * @ioc : pointer to per adapter structure
  4932. * @channel : volume channel
  4933. * @id : volume target id
  4934. **/
  4935. static void
  4936. mpt_inactive_raid_volumes(MPT_ADAPTER *ioc, u8 channel, u8 id)
  4937. {
  4938. CONFIGPARMS cfg;
  4939. ConfigPageHeader_t hdr;
  4940. dma_addr_t dma_handle;
  4941. pRaidVolumePage0_t buffer = NULL;
  4942. int i;
  4943. RaidPhysDiskPage0_t phys_disk;
  4944. struct inactive_raid_component_info *component_info;
  4945. int handle_inactive_volumes;
  4946. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  4947. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  4948. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_VOLUME;
  4949. cfg.pageAddr = (channel << 8) + id;
  4950. cfg.cfghdr.hdr = &hdr;
  4951. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4952. if (mpt_config(ioc, &cfg) != 0)
  4953. goto out;
  4954. if (!hdr.PageLength)
  4955. goto out;
  4956. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  4957. &dma_handle);
  4958. if (!buffer)
  4959. goto out;
  4960. cfg.physAddr = dma_handle;
  4961. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4962. if (mpt_config(ioc, &cfg) != 0)
  4963. goto out;
  4964. if (!buffer->NumPhysDisks)
  4965. goto out;
  4966. handle_inactive_volumes =
  4967. (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_VOLUME_INACTIVE ||
  4968. (buffer->VolumeStatus.Flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED) == 0 ||
  4969. buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_FAILED ||
  4970. buffer->VolumeStatus.State == MPI_RAIDVOL0_STATUS_STATE_MISSING) ? 1 : 0;
  4971. if (!handle_inactive_volumes)
  4972. goto out;
  4973. mutex_lock(&ioc->raid_data.inactive_list_mutex);
  4974. for (i = 0; i < buffer->NumPhysDisks; i++) {
  4975. if(mpt_raid_phys_disk_pg0(ioc,
  4976. buffer->PhysDisk[i].PhysDiskNum, &phys_disk) != 0)
  4977. continue;
  4978. if ((component_info = kmalloc(sizeof (*component_info),
  4979. GFP_KERNEL)) == NULL)
  4980. continue;
  4981. component_info->volumeID = id;
  4982. component_info->volumeBus = channel;
  4983. component_info->d.PhysDiskNum = phys_disk.PhysDiskNum;
  4984. component_info->d.PhysDiskBus = phys_disk.PhysDiskBus;
  4985. component_info->d.PhysDiskID = phys_disk.PhysDiskID;
  4986. component_info->d.PhysDiskIOC = phys_disk.PhysDiskIOC;
  4987. list_add_tail(&component_info->list,
  4988. &ioc->raid_data.inactive_list);
  4989. }
  4990. mutex_unlock(&ioc->raid_data.inactive_list_mutex);
  4991. out:
  4992. if (buffer)
  4993. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  4994. dma_handle);
  4995. }
  4996. /**
  4997. * mpt_raid_phys_disk_pg0 - returns phys disk page zero
  4998. * @ioc: Pointer to a Adapter Structure
  4999. * @phys_disk_num: io unit unique phys disk num generated by the ioc
  5000. * @phys_disk: requested payload data returned
  5001. *
  5002. * Return:
  5003. * 0 on success
  5004. * -EFAULT if read of config page header fails or data pointer not NULL
  5005. * -ENOMEM if pci_alloc failed
  5006. **/
  5007. int
  5008. mpt_raid_phys_disk_pg0(MPT_ADAPTER *ioc, u8 phys_disk_num,
  5009. RaidPhysDiskPage0_t *phys_disk)
  5010. {
  5011. CONFIGPARMS cfg;
  5012. ConfigPageHeader_t hdr;
  5013. dma_addr_t dma_handle;
  5014. pRaidPhysDiskPage0_t buffer = NULL;
  5015. int rc;
  5016. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5017. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5018. memset(phys_disk, 0, sizeof(RaidPhysDiskPage0_t));
  5019. hdr.PageVersion = MPI_RAIDPHYSDISKPAGE0_PAGEVERSION;
  5020. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
  5021. cfg.cfghdr.hdr = &hdr;
  5022. cfg.physAddr = -1;
  5023. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5024. if (mpt_config(ioc, &cfg) != 0) {
  5025. rc = -EFAULT;
  5026. goto out;
  5027. }
  5028. if (!hdr.PageLength) {
  5029. rc = -EFAULT;
  5030. goto out;
  5031. }
  5032. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  5033. &dma_handle);
  5034. if (!buffer) {
  5035. rc = -ENOMEM;
  5036. goto out;
  5037. }
  5038. cfg.physAddr = dma_handle;
  5039. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5040. cfg.pageAddr = phys_disk_num;
  5041. if (mpt_config(ioc, &cfg) != 0) {
  5042. rc = -EFAULT;
  5043. goto out;
  5044. }
  5045. rc = 0;
  5046. memcpy(phys_disk, buffer, sizeof(*buffer));
  5047. phys_disk->MaxLBA = le32_to_cpu(buffer->MaxLBA);
  5048. out:
  5049. if (buffer)
  5050. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5051. dma_handle);
  5052. return rc;
  5053. }
  5054. /**
  5055. * mpt_raid_phys_disk_get_num_paths - returns number paths associated to this phys_num
  5056. * @ioc: Pointer to a Adapter Structure
  5057. * @phys_disk_num: io unit unique phys disk num generated by the ioc
  5058. *
  5059. * Return:
  5060. * returns number paths
  5061. **/
  5062. int
  5063. mpt_raid_phys_disk_get_num_paths(MPT_ADAPTER *ioc, u8 phys_disk_num)
  5064. {
  5065. CONFIGPARMS cfg;
  5066. ConfigPageHeader_t hdr;
  5067. dma_addr_t dma_handle;
  5068. pRaidPhysDiskPage1_t buffer = NULL;
  5069. int rc;
  5070. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5071. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5072. hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
  5073. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
  5074. hdr.PageNumber = 1;
  5075. cfg.cfghdr.hdr = &hdr;
  5076. cfg.physAddr = -1;
  5077. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5078. if (mpt_config(ioc, &cfg) != 0) {
  5079. rc = 0;
  5080. goto out;
  5081. }
  5082. if (!hdr.PageLength) {
  5083. rc = 0;
  5084. goto out;
  5085. }
  5086. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  5087. &dma_handle);
  5088. if (!buffer) {
  5089. rc = 0;
  5090. goto out;
  5091. }
  5092. cfg.physAddr = dma_handle;
  5093. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5094. cfg.pageAddr = phys_disk_num;
  5095. if (mpt_config(ioc, &cfg) != 0) {
  5096. rc = 0;
  5097. goto out;
  5098. }
  5099. rc = buffer->NumPhysDiskPaths;
  5100. out:
  5101. if (buffer)
  5102. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5103. dma_handle);
  5104. return rc;
  5105. }
  5106. EXPORT_SYMBOL(mpt_raid_phys_disk_get_num_paths);
  5107. /**
  5108. * mpt_raid_phys_disk_pg1 - returns phys disk page 1
  5109. * @ioc: Pointer to a Adapter Structure
  5110. * @phys_disk_num: io unit unique phys disk num generated by the ioc
  5111. * @phys_disk: requested payload data returned
  5112. *
  5113. * Return:
  5114. * 0 on success
  5115. * -EFAULT if read of config page header fails or data pointer not NULL
  5116. * -ENOMEM if pci_alloc failed
  5117. **/
  5118. int
  5119. mpt_raid_phys_disk_pg1(MPT_ADAPTER *ioc, u8 phys_disk_num,
  5120. RaidPhysDiskPage1_t *phys_disk)
  5121. {
  5122. CONFIGPARMS cfg;
  5123. ConfigPageHeader_t hdr;
  5124. dma_addr_t dma_handle;
  5125. pRaidPhysDiskPage1_t buffer = NULL;
  5126. int rc;
  5127. int i;
  5128. __le64 sas_address;
  5129. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5130. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5131. rc = 0;
  5132. hdr.PageVersion = MPI_RAIDPHYSDISKPAGE1_PAGEVERSION;
  5133. hdr.PageType = MPI_CONFIG_PAGETYPE_RAID_PHYSDISK;
  5134. hdr.PageNumber = 1;
  5135. cfg.cfghdr.hdr = &hdr;
  5136. cfg.physAddr = -1;
  5137. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5138. if (mpt_config(ioc, &cfg) != 0) {
  5139. rc = -EFAULT;
  5140. goto out;
  5141. }
  5142. if (!hdr.PageLength) {
  5143. rc = -EFAULT;
  5144. goto out;
  5145. }
  5146. buffer = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4,
  5147. &dma_handle);
  5148. if (!buffer) {
  5149. rc = -ENOMEM;
  5150. goto out;
  5151. }
  5152. cfg.physAddr = dma_handle;
  5153. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5154. cfg.pageAddr = phys_disk_num;
  5155. if (mpt_config(ioc, &cfg) != 0) {
  5156. rc = -EFAULT;
  5157. goto out;
  5158. }
  5159. phys_disk->NumPhysDiskPaths = buffer->NumPhysDiskPaths;
  5160. phys_disk->PhysDiskNum = phys_disk_num;
  5161. for (i = 0; i < phys_disk->NumPhysDiskPaths; i++) {
  5162. phys_disk->Path[i].PhysDiskID = buffer->Path[i].PhysDiskID;
  5163. phys_disk->Path[i].PhysDiskBus = buffer->Path[i].PhysDiskBus;
  5164. phys_disk->Path[i].OwnerIdentifier =
  5165. buffer->Path[i].OwnerIdentifier;
  5166. phys_disk->Path[i].Flags = le16_to_cpu(buffer->Path[i].Flags);
  5167. memcpy(&sas_address, &buffer->Path[i].WWID, sizeof(__le64));
  5168. sas_address = le64_to_cpu(sas_address);
  5169. memcpy(&phys_disk->Path[i].WWID, &sas_address, sizeof(__le64));
  5170. memcpy(&sas_address,
  5171. &buffer->Path[i].OwnerWWID, sizeof(__le64));
  5172. sas_address = le64_to_cpu(sas_address);
  5173. memcpy(&phys_disk->Path[i].OwnerWWID,
  5174. &sas_address, sizeof(__le64));
  5175. }
  5176. out:
  5177. if (buffer)
  5178. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, buffer,
  5179. dma_handle);
  5180. return rc;
  5181. }
  5182. EXPORT_SYMBOL(mpt_raid_phys_disk_pg1);
  5183. /**
  5184. * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  5185. * @ioc: Pointer to a Adapter Strucutre
  5186. *
  5187. * Return:
  5188. * 0 on success
  5189. * -EFAULT if read of config page header fails or data pointer not NULL
  5190. * -ENOMEM if pci_alloc failed
  5191. **/
  5192. int
  5193. mpt_findImVolumes(MPT_ADAPTER *ioc)
  5194. {
  5195. IOCPage2_t *pIoc2;
  5196. u8 *mem;
  5197. dma_addr_t ioc2_dma;
  5198. CONFIGPARMS cfg;
  5199. ConfigPageHeader_t header;
  5200. int rc = 0;
  5201. int iocpage2sz;
  5202. int i;
  5203. if (!ioc->ir_firmware)
  5204. return 0;
  5205. /* Free the old page
  5206. */
  5207. kfree(ioc->raid_data.pIocPg2);
  5208. ioc->raid_data.pIocPg2 = NULL;
  5209. mpt_inactive_raid_list_free(ioc);
  5210. /* Read IOCP2 header then the page.
  5211. */
  5212. header.PageVersion = 0;
  5213. header.PageLength = 0;
  5214. header.PageNumber = 2;
  5215. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5216. cfg.cfghdr.hdr = &header;
  5217. cfg.physAddr = -1;
  5218. cfg.pageAddr = 0;
  5219. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5220. cfg.dir = 0;
  5221. cfg.timeout = 0;
  5222. if (mpt_config(ioc, &cfg) != 0)
  5223. return -EFAULT;
  5224. if (header.PageLength == 0)
  5225. return -EFAULT;
  5226. iocpage2sz = header.PageLength * 4;
  5227. pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
  5228. if (!pIoc2)
  5229. return -ENOMEM;
  5230. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5231. cfg.physAddr = ioc2_dma;
  5232. if (mpt_config(ioc, &cfg) != 0)
  5233. goto out;
  5234. mem = kmemdup(pIoc2, iocpage2sz, GFP_KERNEL);
  5235. if (!mem) {
  5236. rc = -ENOMEM;
  5237. goto out;
  5238. }
  5239. ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
  5240. mpt_read_ioc_pg_3(ioc);
  5241. for (i = 0; i < pIoc2->NumActiveVolumes ; i++)
  5242. mpt_inactive_raid_volumes(ioc,
  5243. pIoc2->RaidVolume[i].VolumeBus,
  5244. pIoc2->RaidVolume[i].VolumeID);
  5245. out:
  5246. pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
  5247. return rc;
  5248. }
  5249. static int
  5250. mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
  5251. {
  5252. IOCPage3_t *pIoc3;
  5253. u8 *mem;
  5254. CONFIGPARMS cfg;
  5255. ConfigPageHeader_t header;
  5256. dma_addr_t ioc3_dma;
  5257. int iocpage3sz = 0;
  5258. /* Free the old page
  5259. */
  5260. kfree(ioc->raid_data.pIocPg3);
  5261. ioc->raid_data.pIocPg3 = NULL;
  5262. /* There is at least one physical disk.
  5263. * Read and save IOC Page 3
  5264. */
  5265. header.PageVersion = 0;
  5266. header.PageLength = 0;
  5267. header.PageNumber = 3;
  5268. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5269. cfg.cfghdr.hdr = &header;
  5270. cfg.physAddr = -1;
  5271. cfg.pageAddr = 0;
  5272. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5273. cfg.dir = 0;
  5274. cfg.timeout = 0;
  5275. if (mpt_config(ioc, &cfg) != 0)
  5276. return 0;
  5277. if (header.PageLength == 0)
  5278. return 0;
  5279. /* Read Header good, alloc memory
  5280. */
  5281. iocpage3sz = header.PageLength * 4;
  5282. pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
  5283. if (!pIoc3)
  5284. return 0;
  5285. /* Read the Page and save the data
  5286. * into malloc'd memory.
  5287. */
  5288. cfg.physAddr = ioc3_dma;
  5289. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5290. if (mpt_config(ioc, &cfg) == 0) {
  5291. mem = kmalloc(iocpage3sz, GFP_KERNEL);
  5292. if (mem) {
  5293. memcpy(mem, (u8 *)pIoc3, iocpage3sz);
  5294. ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
  5295. }
  5296. }
  5297. pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
  5298. return 0;
  5299. }
  5300. static void
  5301. mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
  5302. {
  5303. IOCPage4_t *pIoc4;
  5304. CONFIGPARMS cfg;
  5305. ConfigPageHeader_t header;
  5306. dma_addr_t ioc4_dma;
  5307. int iocpage4sz;
  5308. /* Read and save IOC Page 4
  5309. */
  5310. header.PageVersion = 0;
  5311. header.PageLength = 0;
  5312. header.PageNumber = 4;
  5313. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5314. cfg.cfghdr.hdr = &header;
  5315. cfg.physAddr = -1;
  5316. cfg.pageAddr = 0;
  5317. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5318. cfg.dir = 0;
  5319. cfg.timeout = 0;
  5320. if (mpt_config(ioc, &cfg) != 0)
  5321. return;
  5322. if (header.PageLength == 0)
  5323. return;
  5324. if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
  5325. iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
  5326. pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
  5327. if (!pIoc4)
  5328. return;
  5329. ioc->alloc_total += iocpage4sz;
  5330. } else {
  5331. ioc4_dma = ioc->spi_data.IocPg4_dma;
  5332. iocpage4sz = ioc->spi_data.IocPg4Sz;
  5333. }
  5334. /* Read the Page into dma memory.
  5335. */
  5336. cfg.physAddr = ioc4_dma;
  5337. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5338. if (mpt_config(ioc, &cfg) == 0) {
  5339. ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
  5340. ioc->spi_data.IocPg4_dma = ioc4_dma;
  5341. ioc->spi_data.IocPg4Sz = iocpage4sz;
  5342. } else {
  5343. pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
  5344. ioc->spi_data.pIocPg4 = NULL;
  5345. ioc->alloc_total -= iocpage4sz;
  5346. }
  5347. }
  5348. static void
  5349. mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
  5350. {
  5351. IOCPage1_t *pIoc1;
  5352. CONFIGPARMS cfg;
  5353. ConfigPageHeader_t header;
  5354. dma_addr_t ioc1_dma;
  5355. int iocpage1sz = 0;
  5356. u32 tmp;
  5357. /* Check the Coalescing Timeout in IOC Page 1
  5358. */
  5359. header.PageVersion = 0;
  5360. header.PageLength = 0;
  5361. header.PageNumber = 1;
  5362. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  5363. cfg.cfghdr.hdr = &header;
  5364. cfg.physAddr = -1;
  5365. cfg.pageAddr = 0;
  5366. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5367. cfg.dir = 0;
  5368. cfg.timeout = 0;
  5369. if (mpt_config(ioc, &cfg) != 0)
  5370. return;
  5371. if (header.PageLength == 0)
  5372. return;
  5373. /* Read Header good, alloc memory
  5374. */
  5375. iocpage1sz = header.PageLength * 4;
  5376. pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
  5377. if (!pIoc1)
  5378. return;
  5379. /* Read the Page and check coalescing timeout
  5380. */
  5381. cfg.physAddr = ioc1_dma;
  5382. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5383. if (mpt_config(ioc, &cfg) == 0) {
  5384. tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
  5385. if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
  5386. tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
  5387. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Coalescing Enabled Timeout = %d\n",
  5388. ioc->name, tmp));
  5389. if (tmp > MPT_COALESCING_TIMEOUT) {
  5390. pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
  5391. /* Write NVRAM and current
  5392. */
  5393. cfg.dir = 1;
  5394. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  5395. if (mpt_config(ioc, &cfg) == 0) {
  5396. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Reset Current Coalescing Timeout to = %d\n",
  5397. ioc->name, MPT_COALESCING_TIMEOUT));
  5398. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  5399. if (mpt_config(ioc, &cfg) == 0) {
  5400. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5401. "Reset NVRAM Coalescing Timeout to = %d\n",
  5402. ioc->name, MPT_COALESCING_TIMEOUT));
  5403. } else {
  5404. dprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5405. "Reset NVRAM Coalescing Timeout Failed\n",
  5406. ioc->name));
  5407. }
  5408. } else {
  5409. dprintk(ioc, printk(MYIOC_s_WARN_FMT
  5410. "Reset of Current Coalescing Timeout Failed!\n",
  5411. ioc->name));
  5412. }
  5413. }
  5414. } else {
  5415. dprintk(ioc, printk(MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
  5416. }
  5417. }
  5418. pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
  5419. return;
  5420. }
  5421. static void
  5422. mpt_get_manufacturing_pg_0(MPT_ADAPTER *ioc)
  5423. {
  5424. CONFIGPARMS cfg;
  5425. ConfigPageHeader_t hdr;
  5426. dma_addr_t buf_dma;
  5427. ManufacturingPage0_t *pbuf = NULL;
  5428. memset(&cfg, 0 , sizeof(CONFIGPARMS));
  5429. memset(&hdr, 0 , sizeof(ConfigPageHeader_t));
  5430. hdr.PageType = MPI_CONFIG_PAGETYPE_MANUFACTURING;
  5431. cfg.cfghdr.hdr = &hdr;
  5432. cfg.physAddr = -1;
  5433. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  5434. cfg.timeout = 10;
  5435. if (mpt_config(ioc, &cfg) != 0)
  5436. goto out;
  5437. if (!cfg.cfghdr.hdr->PageLength)
  5438. goto out;
  5439. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  5440. pbuf = pci_alloc_consistent(ioc->pcidev, hdr.PageLength * 4, &buf_dma);
  5441. if (!pbuf)
  5442. goto out;
  5443. cfg.physAddr = buf_dma;
  5444. if (mpt_config(ioc, &cfg) != 0)
  5445. goto out;
  5446. memcpy(ioc->board_name, pbuf->BoardName, sizeof(ioc->board_name));
  5447. memcpy(ioc->board_assembly, pbuf->BoardAssembly, sizeof(ioc->board_assembly));
  5448. memcpy(ioc->board_tracer, pbuf->BoardTracerNumber, sizeof(ioc->board_tracer));
  5449. out:
  5450. if (pbuf)
  5451. pci_free_consistent(ioc->pcidev, hdr.PageLength * 4, pbuf, buf_dma);
  5452. }
  5453. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5454. /**
  5455. * SendEventNotification - Send EventNotification (on or off) request to adapter
  5456. * @ioc: Pointer to MPT_ADAPTER structure
  5457. * @EvSwitch: Event switch flags
  5458. * @sleepFlag: Specifies whether the process can sleep
  5459. */
  5460. static int
  5461. SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch, int sleepFlag)
  5462. {
  5463. EventNotification_t evn;
  5464. MPIDefaultReply_t reply_buf;
  5465. memset(&evn, 0, sizeof(EventNotification_t));
  5466. memset(&reply_buf, 0, sizeof(MPIDefaultReply_t));
  5467. evn.Function = MPI_FUNCTION_EVENT_NOTIFICATION;
  5468. evn.Switch = EvSwitch;
  5469. evn.MsgContext = cpu_to_le32(mpt_base_index << 16);
  5470. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5471. "Sending EventNotification (%d) request %p\n",
  5472. ioc->name, EvSwitch, &evn));
  5473. return mpt_handshake_req_reply_wait(ioc, sizeof(EventNotification_t),
  5474. (u32 *)&evn, sizeof(MPIDefaultReply_t), (u16 *)&reply_buf, 30,
  5475. sleepFlag);
  5476. }
  5477. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5478. /**
  5479. * SendEventAck - Send EventAck request to MPT adapter.
  5480. * @ioc: Pointer to MPT_ADAPTER structure
  5481. * @evnp: Pointer to original EventNotification request
  5482. */
  5483. static int
  5484. SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
  5485. {
  5486. EventAck_t *pAck;
  5487. if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  5488. dfailprintk(ioc, printk(MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
  5489. ioc->name, __func__));
  5490. return -1;
  5491. }
  5492. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "Sending EventAck\n", ioc->name));
  5493. pAck->Function = MPI_FUNCTION_EVENT_ACK;
  5494. pAck->ChainOffset = 0;
  5495. pAck->Reserved[0] = pAck->Reserved[1] = 0;
  5496. pAck->MsgFlags = 0;
  5497. pAck->Reserved1[0] = pAck->Reserved1[1] = pAck->Reserved1[2] = 0;
  5498. pAck->Event = evnp->Event;
  5499. pAck->EventContext = evnp->EventContext;
  5500. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
  5501. return 0;
  5502. }
  5503. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5504. /**
  5505. * mpt_config - Generic function to issue config message
  5506. * @ioc: Pointer to an adapter structure
  5507. * @pCfg: Pointer to a configuration structure. Struct contains
  5508. * action, page address, direction, physical address
  5509. * and pointer to a configuration page header
  5510. * Page header is updated.
  5511. *
  5512. * Returns 0 for success
  5513. * -EPERM if not allowed due to ISR context
  5514. * -EAGAIN if no msg frames currently available
  5515. * -EFAULT for non-successful reply or no reply (timeout)
  5516. */
  5517. int
  5518. mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  5519. {
  5520. Config_t *pReq;
  5521. ConfigReply_t *pReply;
  5522. ConfigExtendedPageHeader_t *pExtHdr = NULL;
  5523. MPT_FRAME_HDR *mf;
  5524. int ii;
  5525. int flagsLength;
  5526. long timeout;
  5527. int ret;
  5528. u8 page_type = 0, extend_page;
  5529. unsigned long timeleft;
  5530. unsigned long flags;
  5531. int in_isr;
  5532. u8 issue_hard_reset = 0;
  5533. u8 retry_count = 0;
  5534. /* Prevent calling wait_event() (below), if caller happens
  5535. * to be in ISR context, because that is fatal!
  5536. */
  5537. in_isr = in_interrupt();
  5538. if (in_isr) {
  5539. dcprintk(ioc, printk(MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
  5540. ioc->name));
  5541. return -EPERM;
  5542. }
  5543. /* don't send a config page during diag reset */
  5544. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  5545. if (ioc->ioc_reset_in_progress) {
  5546. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5547. "%s: busy with host reset\n", ioc->name, __func__));
  5548. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  5549. return -EBUSY;
  5550. }
  5551. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  5552. /* don't send if no chance of success */
  5553. if (!ioc->active ||
  5554. mpt_GetIocState(ioc, 1) != MPI_IOC_STATE_OPERATIONAL) {
  5555. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5556. "%s: ioc not operational, %d, %xh\n",
  5557. ioc->name, __func__, ioc->active,
  5558. mpt_GetIocState(ioc, 0)));
  5559. return -EFAULT;
  5560. }
  5561. retry_config:
  5562. mutex_lock(&ioc->mptbase_cmds.mutex);
  5563. /* init the internal cmd struct */
  5564. memset(ioc->mptbase_cmds.reply, 0 , MPT_DEFAULT_FRAME_SIZE);
  5565. INITIALIZE_MGMT_STATUS(ioc->mptbase_cmds.status)
  5566. /* Get and Populate a free Frame
  5567. */
  5568. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  5569. dcprintk(ioc, printk(MYIOC_s_WARN_FMT
  5570. "mpt_config: no msg frames!\n", ioc->name));
  5571. ret = -EAGAIN;
  5572. goto out;
  5573. }
  5574. pReq = (Config_t *)mf;
  5575. pReq->Action = pCfg->action;
  5576. pReq->Reserved = 0;
  5577. pReq->ChainOffset = 0;
  5578. pReq->Function = MPI_FUNCTION_CONFIG;
  5579. /* Assume page type is not extended and clear "reserved" fields. */
  5580. pReq->ExtPageLength = 0;
  5581. pReq->ExtPageType = 0;
  5582. pReq->MsgFlags = 0;
  5583. for (ii=0; ii < 8; ii++)
  5584. pReq->Reserved2[ii] = 0;
  5585. pReq->Header.PageVersion = pCfg->cfghdr.hdr->PageVersion;
  5586. pReq->Header.PageLength = pCfg->cfghdr.hdr->PageLength;
  5587. pReq->Header.PageNumber = pCfg->cfghdr.hdr->PageNumber;
  5588. pReq->Header.PageType = (pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
  5589. if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
  5590. pExtHdr = (ConfigExtendedPageHeader_t *)pCfg->cfghdr.ehdr;
  5591. pReq->ExtPageLength = cpu_to_le16(pExtHdr->ExtPageLength);
  5592. pReq->ExtPageType = pExtHdr->ExtPageType;
  5593. pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  5594. /* Page Length must be treated as a reserved field for the
  5595. * extended header.
  5596. */
  5597. pReq->Header.PageLength = 0;
  5598. }
  5599. pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
  5600. /* Add a SGE to the config request.
  5601. */
  5602. if (pCfg->dir)
  5603. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  5604. else
  5605. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  5606. if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) ==
  5607. MPI_CONFIG_PAGETYPE_EXTENDED) {
  5608. flagsLength |= pExtHdr->ExtPageLength * 4;
  5609. page_type = pReq->ExtPageType;
  5610. extend_page = 1;
  5611. } else {
  5612. flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
  5613. page_type = pReq->Header.PageType;
  5614. extend_page = 0;
  5615. }
  5616. dcprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5617. "Sending Config request type 0x%x, page 0x%x and action %d\n",
  5618. ioc->name, page_type, pReq->Header.PageNumber, pReq->Action));
  5619. ioc->add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
  5620. timeout = (pCfg->timeout < 15) ? HZ*15 : HZ*pCfg->timeout;
  5621. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  5622. timeleft = wait_for_completion_timeout(&ioc->mptbase_cmds.done,
  5623. timeout);
  5624. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_COMMAND_GOOD)) {
  5625. ret = -ETIME;
  5626. dfailprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5627. "Failed Sending Config request type 0x%x, page 0x%x,"
  5628. " action %d, status %xh, time left %ld\n\n",
  5629. ioc->name, page_type, pReq->Header.PageNumber,
  5630. pReq->Action, ioc->mptbase_cmds.status, timeleft));
  5631. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_DID_IOCRESET)
  5632. goto out;
  5633. if (!timeleft) {
  5634. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  5635. if (ioc->ioc_reset_in_progress) {
  5636. spin_unlock_irqrestore(&ioc->taskmgmt_lock,
  5637. flags);
  5638. printk(MYIOC_s_INFO_FMT "%s: host reset in"
  5639. " progress mpt_config timed out.!!\n",
  5640. __func__, ioc->name);
  5641. mutex_unlock(&ioc->mptbase_cmds.mutex);
  5642. return -EFAULT;
  5643. }
  5644. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  5645. issue_hard_reset = 1;
  5646. }
  5647. goto out;
  5648. }
  5649. if (!(ioc->mptbase_cmds.status & MPT_MGMT_STATUS_RF_VALID)) {
  5650. ret = -1;
  5651. goto out;
  5652. }
  5653. pReply = (ConfigReply_t *)ioc->mptbase_cmds.reply;
  5654. ret = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  5655. if (ret == MPI_IOCSTATUS_SUCCESS) {
  5656. if (extend_page) {
  5657. pCfg->cfghdr.ehdr->ExtPageLength =
  5658. le16_to_cpu(pReply->ExtPageLength);
  5659. pCfg->cfghdr.ehdr->ExtPageType =
  5660. pReply->ExtPageType;
  5661. }
  5662. pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
  5663. pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
  5664. pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
  5665. pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
  5666. }
  5667. if (retry_count)
  5668. printk(MYIOC_s_INFO_FMT "Retry completed "
  5669. "ret=0x%x timeleft=%ld\n",
  5670. ioc->name, ret, timeleft);
  5671. dcprintk(ioc, printk(KERN_DEBUG "IOCStatus=%04xh, IOCLogInfo=%08xh\n",
  5672. ret, le32_to_cpu(pReply->IOCLogInfo)));
  5673. out:
  5674. CLEAR_MGMT_STATUS(ioc->mptbase_cmds.status)
  5675. mutex_unlock(&ioc->mptbase_cmds.mutex);
  5676. if (issue_hard_reset) {
  5677. issue_hard_reset = 0;
  5678. printk(MYIOC_s_WARN_FMT
  5679. "Issuing Reset from %s!!, doorbell=0x%08x\n",
  5680. ioc->name, __func__, mpt_GetIocState(ioc, 0));
  5681. if (retry_count == 0) {
  5682. if (mpt_Soft_Hard_ResetHandler(ioc, CAN_SLEEP) != 0)
  5683. retry_count++;
  5684. } else
  5685. mpt_HardResetHandler(ioc, CAN_SLEEP);
  5686. mpt_free_msg_frame(ioc, mf);
  5687. /* attempt one retry for a timed out command */
  5688. if (retry_count < 2) {
  5689. printk(MYIOC_s_INFO_FMT
  5690. "Attempting Retry Config request"
  5691. " type 0x%x, page 0x%x,"
  5692. " action %d\n", ioc->name, page_type,
  5693. pCfg->cfghdr.hdr->PageNumber, pCfg->action);
  5694. retry_count++;
  5695. goto retry_config;
  5696. }
  5697. }
  5698. return ret;
  5699. }
  5700. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5701. /**
  5702. * mpt_ioc_reset - Base cleanup for hard reset
  5703. * @ioc: Pointer to the adapter structure
  5704. * @reset_phase: Indicates pre- or post-reset functionality
  5705. *
  5706. * Remark: Frees resources with internally generated commands.
  5707. */
  5708. static int
  5709. mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  5710. {
  5711. switch (reset_phase) {
  5712. case MPT_IOC_SETUP_RESET:
  5713. ioc->taskmgmt_quiesce_io = 1;
  5714. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5715. "%s: MPT_IOC_SETUP_RESET\n", ioc->name, __func__));
  5716. break;
  5717. case MPT_IOC_PRE_RESET:
  5718. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5719. "%s: MPT_IOC_PRE_RESET\n", ioc->name, __func__));
  5720. break;
  5721. case MPT_IOC_POST_RESET:
  5722. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  5723. "%s: MPT_IOC_POST_RESET\n", ioc->name, __func__));
  5724. /* wake up mptbase_cmds */
  5725. if (ioc->mptbase_cmds.status & MPT_MGMT_STATUS_PENDING) {
  5726. ioc->mptbase_cmds.status |=
  5727. MPT_MGMT_STATUS_DID_IOCRESET;
  5728. complete(&ioc->mptbase_cmds.done);
  5729. }
  5730. /* wake up taskmgmt_cmds */
  5731. if (ioc->taskmgmt_cmds.status & MPT_MGMT_STATUS_PENDING) {
  5732. ioc->taskmgmt_cmds.status |=
  5733. MPT_MGMT_STATUS_DID_IOCRESET;
  5734. complete(&ioc->taskmgmt_cmds.done);
  5735. }
  5736. break;
  5737. default:
  5738. break;
  5739. }
  5740. return 1; /* currently means nothing really */
  5741. }
  5742. #ifdef CONFIG_PROC_FS /* { */
  5743. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5744. /*
  5745. * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
  5746. */
  5747. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5748. /**
  5749. * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
  5750. *
  5751. * Returns 0 for success, non-zero for failure.
  5752. */
  5753. static int
  5754. procmpt_create(void)
  5755. {
  5756. mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
  5757. if (mpt_proc_root_dir == NULL)
  5758. return -ENOTDIR;
  5759. proc_create_single("summary", S_IRUGO, mpt_proc_root_dir,
  5760. mpt_summary_proc_show);
  5761. proc_create_single("version", S_IRUGO, mpt_proc_root_dir,
  5762. mpt_version_proc_show);
  5763. return 0;
  5764. }
  5765. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5766. /**
  5767. * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
  5768. *
  5769. * Returns 0 for success, non-zero for failure.
  5770. */
  5771. static void
  5772. procmpt_destroy(void)
  5773. {
  5774. remove_proc_entry("version", mpt_proc_root_dir);
  5775. remove_proc_entry("summary", mpt_proc_root_dir);
  5776. remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
  5777. }
  5778. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5779. /*
  5780. * Handles read request from /proc/mpt/summary or /proc/mpt/iocN/summary.
  5781. */
  5782. static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan);
  5783. static int mpt_summary_proc_show(struct seq_file *m, void *v)
  5784. {
  5785. MPT_ADAPTER *ioc = m->private;
  5786. if (ioc) {
  5787. seq_mpt_print_ioc_summary(ioc, m, 1);
  5788. } else {
  5789. list_for_each_entry(ioc, &ioc_list, list) {
  5790. seq_mpt_print_ioc_summary(ioc, m, 1);
  5791. }
  5792. }
  5793. return 0;
  5794. }
  5795. static int mpt_version_proc_show(struct seq_file *m, void *v)
  5796. {
  5797. u8 cb_idx;
  5798. int scsi, fc, sas, lan, ctl, targ, dmp;
  5799. char *drvname;
  5800. seq_printf(m, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
  5801. seq_printf(m, " Fusion MPT base driver\n");
  5802. scsi = fc = sas = lan = ctl = targ = dmp = 0;
  5803. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  5804. drvname = NULL;
  5805. if (MptCallbacks[cb_idx]) {
  5806. switch (MptDriverClass[cb_idx]) {
  5807. case MPTSPI_DRIVER:
  5808. if (!scsi++) drvname = "SPI host";
  5809. break;
  5810. case MPTFC_DRIVER:
  5811. if (!fc++) drvname = "FC host";
  5812. break;
  5813. case MPTSAS_DRIVER:
  5814. if (!sas++) drvname = "SAS host";
  5815. break;
  5816. case MPTLAN_DRIVER:
  5817. if (!lan++) drvname = "LAN";
  5818. break;
  5819. case MPTSTM_DRIVER:
  5820. if (!targ++) drvname = "SCSI target";
  5821. break;
  5822. case MPTCTL_DRIVER:
  5823. if (!ctl++) drvname = "ioctl";
  5824. break;
  5825. }
  5826. if (drvname)
  5827. seq_printf(m, " Fusion MPT %s driver\n", drvname);
  5828. }
  5829. }
  5830. return 0;
  5831. }
  5832. static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
  5833. {
  5834. MPT_ADAPTER *ioc = m->private;
  5835. char expVer[32];
  5836. int sz;
  5837. int p;
  5838. mpt_get_fw_exp_ver(expVer, ioc);
  5839. seq_printf(m, "%s:", ioc->name);
  5840. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  5841. seq_printf(m, " (f/w download boot flag set)");
  5842. // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
  5843. // seq_printf(m, " CONFIG_CHECKSUM_FAIL!");
  5844. seq_printf(m, "\n ProductID = 0x%04x (%s)\n",
  5845. ioc->facts.ProductID,
  5846. ioc->prod_name);
  5847. seq_printf(m, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
  5848. if (ioc->facts.FWImageSize)
  5849. seq_printf(m, " (fw_size=%d)", ioc->facts.FWImageSize);
  5850. seq_printf(m, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
  5851. seq_printf(m, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
  5852. seq_printf(m, " EventState = 0x%02x\n", ioc->facts.EventState);
  5853. seq_printf(m, " CurrentHostMfaHighAddr = 0x%08x\n",
  5854. ioc->facts.CurrentHostMfaHighAddr);
  5855. seq_printf(m, " CurrentSenseBufferHighAddr = 0x%08x\n",
  5856. ioc->facts.CurrentSenseBufferHighAddr);
  5857. seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  5858. seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  5859. seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  5860. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  5861. /*
  5862. * Rounding UP to nearest 4-kB boundary here...
  5863. */
  5864. sz = (ioc->req_sz * ioc->req_depth) + 128;
  5865. sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
  5866. seq_printf(m, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
  5867. ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
  5868. seq_printf(m, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
  5869. 4*ioc->facts.RequestFrameSize,
  5870. ioc->facts.GlobalCredits);
  5871. seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
  5872. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  5873. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  5874. seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  5875. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  5876. seq_printf(m, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
  5877. ioc->facts.CurReplyFrameSize,
  5878. ioc->facts.ReplyQueueDepth);
  5879. seq_printf(m, " MaxDevices = %d\n",
  5880. (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
  5881. seq_printf(m, " MaxBuses = %d\n", ioc->facts.MaxBuses);
  5882. /* per-port info */
  5883. for (p=0; p < ioc->facts.NumberOfPorts; p++) {
  5884. seq_printf(m, " PortNumber = %d (of %d)\n",
  5885. p+1,
  5886. ioc->facts.NumberOfPorts);
  5887. if (ioc->bus_type == FC) {
  5888. if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  5889. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  5890. seq_printf(m, " LanAddr = %pMR\n", a);
  5891. }
  5892. seq_printf(m, " WWN = %08X%08X:%08X%08X\n",
  5893. ioc->fc_port_page0[p].WWNN.High,
  5894. ioc->fc_port_page0[p].WWNN.Low,
  5895. ioc->fc_port_page0[p].WWPN.High,
  5896. ioc->fc_port_page0[p].WWPN.Low);
  5897. }
  5898. }
  5899. return 0;
  5900. }
  5901. #endif /* CONFIG_PROC_FS } */
  5902. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5903. static void
  5904. mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
  5905. {
  5906. buf[0] ='\0';
  5907. if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
  5908. sprintf(buf, " (Exp %02d%02d)",
  5909. (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
  5910. (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
  5911. /* insider hack! */
  5912. if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
  5913. strcat(buf, " [MDBG]");
  5914. }
  5915. }
  5916. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5917. /**
  5918. * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
  5919. * @ioc: Pointer to MPT_ADAPTER structure
  5920. * @buffer: Pointer to buffer where IOC summary info should be written
  5921. * @size: Pointer to number of bytes we wrote (set by this routine)
  5922. * @len: Offset at which to start writing in buffer
  5923. * @showlan: Display LAN stuff?
  5924. *
  5925. * This routine writes (english readable) ASCII text, which represents
  5926. * a summary of IOC information, to a buffer.
  5927. */
  5928. void
  5929. mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  5930. {
  5931. char expVer[32];
  5932. int y;
  5933. mpt_get_fw_exp_ver(expVer, ioc);
  5934. /*
  5935. * Shorter summary of attached ioc's...
  5936. */
  5937. y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  5938. ioc->name,
  5939. ioc->prod_name,
  5940. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  5941. ioc->facts.FWVersion.Word,
  5942. expVer,
  5943. ioc->facts.NumberOfPorts,
  5944. ioc->req_depth);
  5945. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  5946. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  5947. y += sprintf(buffer+len+y, ", LanAddr=%pMR", a);
  5948. }
  5949. y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
  5950. if (!ioc->active)
  5951. y += sprintf(buffer+len+y, " (disabled)");
  5952. y += sprintf(buffer+len+y, "\n");
  5953. *size = y;
  5954. }
  5955. #ifdef CONFIG_PROC_FS
  5956. static void seq_mpt_print_ioc_summary(MPT_ADAPTER *ioc, struct seq_file *m, int showlan)
  5957. {
  5958. char expVer[32];
  5959. mpt_get_fw_exp_ver(expVer, ioc);
  5960. /*
  5961. * Shorter summary of attached ioc's...
  5962. */
  5963. seq_printf(m, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  5964. ioc->name,
  5965. ioc->prod_name,
  5966. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  5967. ioc->facts.FWVersion.Word,
  5968. expVer,
  5969. ioc->facts.NumberOfPorts,
  5970. ioc->req_depth);
  5971. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  5972. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  5973. seq_printf(m, ", LanAddr=%pMR", a);
  5974. }
  5975. seq_printf(m, ", IRQ=%d", ioc->pci_irq);
  5976. if (!ioc->active)
  5977. seq_printf(m, " (disabled)");
  5978. seq_putc(m, '\n');
  5979. }
  5980. #endif
  5981. /**
  5982. * mpt_set_taskmgmt_in_progress_flag - set flags associated with task management
  5983. * @ioc: Pointer to MPT_ADAPTER structure
  5984. *
  5985. * Returns 0 for SUCCESS or -1 if FAILED.
  5986. *
  5987. * If -1 is return, then it was not possible to set the flags
  5988. **/
  5989. int
  5990. mpt_set_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
  5991. {
  5992. unsigned long flags;
  5993. int retval;
  5994. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  5995. if (ioc->ioc_reset_in_progress || ioc->taskmgmt_in_progress ||
  5996. (ioc->alt_ioc && ioc->alt_ioc->taskmgmt_in_progress)) {
  5997. retval = -1;
  5998. goto out;
  5999. }
  6000. retval = 0;
  6001. ioc->taskmgmt_in_progress = 1;
  6002. ioc->taskmgmt_quiesce_io = 1;
  6003. if (ioc->alt_ioc) {
  6004. ioc->alt_ioc->taskmgmt_in_progress = 1;
  6005. ioc->alt_ioc->taskmgmt_quiesce_io = 1;
  6006. }
  6007. out:
  6008. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6009. return retval;
  6010. }
  6011. EXPORT_SYMBOL(mpt_set_taskmgmt_in_progress_flag);
  6012. /**
  6013. * mpt_clear_taskmgmt_in_progress_flag - clear flags associated with task management
  6014. * @ioc: Pointer to MPT_ADAPTER structure
  6015. *
  6016. **/
  6017. void
  6018. mpt_clear_taskmgmt_in_progress_flag(MPT_ADAPTER *ioc)
  6019. {
  6020. unsigned long flags;
  6021. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6022. ioc->taskmgmt_in_progress = 0;
  6023. ioc->taskmgmt_quiesce_io = 0;
  6024. if (ioc->alt_ioc) {
  6025. ioc->alt_ioc->taskmgmt_in_progress = 0;
  6026. ioc->alt_ioc->taskmgmt_quiesce_io = 0;
  6027. }
  6028. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6029. }
  6030. EXPORT_SYMBOL(mpt_clear_taskmgmt_in_progress_flag);
  6031. /**
  6032. * mpt_halt_firmware - Halts the firmware if it is operational and panic
  6033. * the kernel
  6034. * @ioc: Pointer to MPT_ADAPTER structure
  6035. *
  6036. **/
  6037. void
  6038. mpt_halt_firmware(MPT_ADAPTER *ioc)
  6039. {
  6040. u32 ioc_raw_state;
  6041. ioc_raw_state = mpt_GetIocState(ioc, 0);
  6042. if ((ioc_raw_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  6043. printk(MYIOC_s_ERR_FMT "IOC is in FAULT state (%04xh)!!!\n",
  6044. ioc->name, ioc_raw_state & MPI_DOORBELL_DATA_MASK);
  6045. panic("%s: IOC Fault (%04xh)!!!\n", ioc->name,
  6046. ioc_raw_state & MPI_DOORBELL_DATA_MASK);
  6047. } else {
  6048. CHIPREG_WRITE32(&ioc->chip->Doorbell, 0xC0FFEE00);
  6049. panic("%s: Firmware is halted due to command timeout\n",
  6050. ioc->name);
  6051. }
  6052. }
  6053. EXPORT_SYMBOL(mpt_halt_firmware);
  6054. /**
  6055. * mpt_SoftResetHandler - Issues a less expensive reset
  6056. * @ioc: Pointer to MPT_ADAPTER structure
  6057. * @sleepFlag: Indicates if sleep or schedule must be called.
  6058. *
  6059. * Returns 0 for SUCCESS or -1 if FAILED.
  6060. *
  6061. * Message Unit Reset - instructs the IOC to reset the Reply Post and
  6062. * Free FIFO's. All the Message Frames on Reply Free FIFO are discarded.
  6063. * All posted buffers are freed, and event notification is turned off.
  6064. * IOC doesn't reply to any outstanding request. This will transfer IOC
  6065. * to READY state.
  6066. **/
  6067. static int
  6068. mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  6069. {
  6070. int rc;
  6071. int ii;
  6072. u8 cb_idx;
  6073. unsigned long flags;
  6074. u32 ioc_state;
  6075. unsigned long time_count;
  6076. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SoftResetHandler Entered!\n",
  6077. ioc->name));
  6078. ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
  6079. if (mpt_fwfault_debug)
  6080. mpt_halt_firmware(ioc);
  6081. if (ioc_state == MPI_IOC_STATE_FAULT ||
  6082. ioc_state == MPI_IOC_STATE_RESET) {
  6083. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6084. "skipping, either in FAULT or RESET state!\n", ioc->name));
  6085. return -1;
  6086. }
  6087. if (ioc->bus_type == FC) {
  6088. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6089. "skipping, because the bus type is FC!\n", ioc->name));
  6090. return -1;
  6091. }
  6092. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6093. if (ioc->ioc_reset_in_progress) {
  6094. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6095. return -1;
  6096. }
  6097. ioc->ioc_reset_in_progress = 1;
  6098. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6099. rc = -1;
  6100. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6101. if (MptResetHandlers[cb_idx])
  6102. mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
  6103. }
  6104. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6105. if (ioc->taskmgmt_in_progress) {
  6106. ioc->ioc_reset_in_progress = 0;
  6107. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6108. return -1;
  6109. }
  6110. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6111. /* Disable reply interrupts (also blocks FreeQ) */
  6112. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  6113. ioc->active = 0;
  6114. time_count = jiffies;
  6115. rc = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  6116. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6117. if (MptResetHandlers[cb_idx])
  6118. mpt_signal_reset(cb_idx, ioc, MPT_IOC_PRE_RESET);
  6119. }
  6120. if (rc)
  6121. goto out;
  6122. ioc_state = mpt_GetIocState(ioc, 0) & MPI_IOC_STATE_MASK;
  6123. if (ioc_state != MPI_IOC_STATE_READY)
  6124. goto out;
  6125. for (ii = 0; ii < 5; ii++) {
  6126. /* Get IOC facts! Allow 5 retries */
  6127. rc = GetIocFacts(ioc, sleepFlag,
  6128. MPT_HOSTEVENT_IOC_RECOVER);
  6129. if (rc == 0)
  6130. break;
  6131. if (sleepFlag == CAN_SLEEP)
  6132. msleep(100);
  6133. else
  6134. mdelay(100);
  6135. }
  6136. if (ii == 5)
  6137. goto out;
  6138. rc = PrimeIocFifos(ioc);
  6139. if (rc != 0)
  6140. goto out;
  6141. rc = SendIocInit(ioc, sleepFlag);
  6142. if (rc != 0)
  6143. goto out;
  6144. rc = SendEventNotification(ioc, 1, sleepFlag);
  6145. if (rc != 0)
  6146. goto out;
  6147. if (ioc->hard_resets < -1)
  6148. ioc->hard_resets++;
  6149. /*
  6150. * At this point, we know soft reset succeeded.
  6151. */
  6152. ioc->active = 1;
  6153. CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
  6154. out:
  6155. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6156. ioc->ioc_reset_in_progress = 0;
  6157. ioc->taskmgmt_quiesce_io = 0;
  6158. ioc->taskmgmt_in_progress = 0;
  6159. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6160. if (ioc->active) { /* otherwise, hard reset coming */
  6161. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6162. if (MptResetHandlers[cb_idx])
  6163. mpt_signal_reset(cb_idx, ioc,
  6164. MPT_IOC_POST_RESET);
  6165. }
  6166. }
  6167. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6168. "SoftResetHandler: completed (%d seconds): %s\n",
  6169. ioc->name, jiffies_to_msecs(jiffies - time_count)/1000,
  6170. ((rc == 0) ? "SUCCESS" : "FAILED")));
  6171. return rc;
  6172. }
  6173. /**
  6174. * mpt_Soft_Hard_ResetHandler - Try less expensive reset
  6175. * @ioc: Pointer to MPT_ADAPTER structure
  6176. * @sleepFlag: Indicates if sleep or schedule must be called.
  6177. *
  6178. * Returns 0 for SUCCESS or -1 if FAILED.
  6179. * Try for softreset first, only if it fails go for expensive
  6180. * HardReset.
  6181. **/
  6182. int
  6183. mpt_Soft_Hard_ResetHandler(MPT_ADAPTER *ioc, int sleepFlag) {
  6184. int ret = -1;
  6185. ret = mpt_SoftResetHandler(ioc, sleepFlag);
  6186. if (ret == 0)
  6187. return ret;
  6188. ret = mpt_HardResetHandler(ioc, sleepFlag);
  6189. return ret;
  6190. }
  6191. EXPORT_SYMBOL(mpt_Soft_Hard_ResetHandler);
  6192. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6193. /*
  6194. * Reset Handling
  6195. */
  6196. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6197. /**
  6198. * mpt_HardResetHandler - Generic reset handler
  6199. * @ioc: Pointer to MPT_ADAPTER structure
  6200. * @sleepFlag: Indicates if sleep or schedule must be called.
  6201. *
  6202. * Issues SCSI Task Management call based on input arg values.
  6203. * If TaskMgmt fails, returns associated SCSI request.
  6204. *
  6205. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  6206. * or a non-interrupt thread. In the former, must not call schedule().
  6207. *
  6208. * Note: A return of -1 is a FATAL error case, as it means a
  6209. * FW reload/initialization failed.
  6210. *
  6211. * Returns 0 for SUCCESS or -1 if FAILED.
  6212. */
  6213. int
  6214. mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  6215. {
  6216. int rc;
  6217. u8 cb_idx;
  6218. unsigned long flags;
  6219. unsigned long time_count;
  6220. dtmprintk(ioc, printk(MYIOC_s_DEBUG_FMT "HardResetHandler Entered!\n", ioc->name));
  6221. #ifdef MFCNT
  6222. printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
  6223. printk("MF count 0x%x !\n", ioc->mfcnt);
  6224. #endif
  6225. if (mpt_fwfault_debug)
  6226. mpt_halt_firmware(ioc);
  6227. /* Reset the adapter. Prevent more than 1 call to
  6228. * mpt_do_ioc_recovery at any instant in time.
  6229. */
  6230. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6231. if (ioc->ioc_reset_in_progress) {
  6232. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6233. ioc->wait_on_reset_completion = 1;
  6234. do {
  6235. ssleep(1);
  6236. } while (ioc->ioc_reset_in_progress == 1);
  6237. ioc->wait_on_reset_completion = 0;
  6238. return ioc->reset_status;
  6239. }
  6240. if (ioc->wait_on_reset_completion) {
  6241. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6242. rc = 0;
  6243. time_count = jiffies;
  6244. goto exit;
  6245. }
  6246. ioc->ioc_reset_in_progress = 1;
  6247. if (ioc->alt_ioc)
  6248. ioc->alt_ioc->ioc_reset_in_progress = 1;
  6249. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6250. /* The SCSI driver needs to adjust timeouts on all current
  6251. * commands prior to the diagnostic reset being issued.
  6252. * Prevents timeouts occurring during a diagnostic reset...very bad.
  6253. * For all other protocol drivers, this is a no-op.
  6254. */
  6255. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6256. if (MptResetHandlers[cb_idx]) {
  6257. mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET);
  6258. if (ioc->alt_ioc)
  6259. mpt_signal_reset(cb_idx, ioc->alt_ioc,
  6260. MPT_IOC_SETUP_RESET);
  6261. }
  6262. }
  6263. time_count = jiffies;
  6264. rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag);
  6265. if (rc != 0) {
  6266. printk(KERN_WARNING MYNAM
  6267. ": WARNING - (%d) Cannot recover %s, doorbell=0x%08x\n",
  6268. rc, ioc->name, mpt_GetIocState(ioc, 0));
  6269. } else {
  6270. if (ioc->hard_resets < -1)
  6271. ioc->hard_resets++;
  6272. }
  6273. spin_lock_irqsave(&ioc->taskmgmt_lock, flags);
  6274. ioc->ioc_reset_in_progress = 0;
  6275. ioc->taskmgmt_quiesce_io = 0;
  6276. ioc->taskmgmt_in_progress = 0;
  6277. ioc->reset_status = rc;
  6278. if (ioc->alt_ioc) {
  6279. ioc->alt_ioc->ioc_reset_in_progress = 0;
  6280. ioc->alt_ioc->taskmgmt_quiesce_io = 0;
  6281. ioc->alt_ioc->taskmgmt_in_progress = 0;
  6282. }
  6283. spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags);
  6284. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6285. if (MptResetHandlers[cb_idx]) {
  6286. mpt_signal_reset(cb_idx, ioc, MPT_IOC_POST_RESET);
  6287. if (ioc->alt_ioc)
  6288. mpt_signal_reset(cb_idx,
  6289. ioc->alt_ioc, MPT_IOC_POST_RESET);
  6290. }
  6291. }
  6292. exit:
  6293. dtmprintk(ioc,
  6294. printk(MYIOC_s_DEBUG_FMT
  6295. "HardResetHandler: completed (%d seconds): %s\n", ioc->name,
  6296. jiffies_to_msecs(jiffies - time_count)/1000, ((rc == 0) ?
  6297. "SUCCESS" : "FAILED")));
  6298. return rc;
  6299. }
  6300. #ifdef CONFIG_FUSION_LOGGING
  6301. static void
  6302. mpt_display_event_info(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply)
  6303. {
  6304. char *ds = NULL;
  6305. u32 evData0;
  6306. int ii;
  6307. u8 event;
  6308. char *evStr = ioc->evStr;
  6309. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  6310. evData0 = le32_to_cpu(pEventReply->Data[0]);
  6311. switch(event) {
  6312. case MPI_EVENT_NONE:
  6313. ds = "None";
  6314. break;
  6315. case MPI_EVENT_LOG_DATA:
  6316. ds = "Log Data";
  6317. break;
  6318. case MPI_EVENT_STATE_CHANGE:
  6319. ds = "State Change";
  6320. break;
  6321. case MPI_EVENT_UNIT_ATTENTION:
  6322. ds = "Unit Attention";
  6323. break;
  6324. case MPI_EVENT_IOC_BUS_RESET:
  6325. ds = "IOC Bus Reset";
  6326. break;
  6327. case MPI_EVENT_EXT_BUS_RESET:
  6328. ds = "External Bus Reset";
  6329. break;
  6330. case MPI_EVENT_RESCAN:
  6331. ds = "Bus Rescan Event";
  6332. break;
  6333. case MPI_EVENT_LINK_STATUS_CHANGE:
  6334. if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
  6335. ds = "Link Status(FAILURE) Change";
  6336. else
  6337. ds = "Link Status(ACTIVE) Change";
  6338. break;
  6339. case MPI_EVENT_LOOP_STATE_CHANGE:
  6340. if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
  6341. ds = "Loop State(LIP) Change";
  6342. else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
  6343. ds = "Loop State(LPE) Change";
  6344. else
  6345. ds = "Loop State(LPB) Change";
  6346. break;
  6347. case MPI_EVENT_LOGOUT:
  6348. ds = "Logout";
  6349. break;
  6350. case MPI_EVENT_EVENT_CHANGE:
  6351. if (evData0)
  6352. ds = "Events ON";
  6353. else
  6354. ds = "Events OFF";
  6355. break;
  6356. case MPI_EVENT_INTEGRATED_RAID:
  6357. {
  6358. u8 ReasonCode = (u8)(evData0 >> 16);
  6359. switch (ReasonCode) {
  6360. case MPI_EVENT_RAID_RC_VOLUME_CREATED :
  6361. ds = "Integrated Raid: Volume Created";
  6362. break;
  6363. case MPI_EVENT_RAID_RC_VOLUME_DELETED :
  6364. ds = "Integrated Raid: Volume Deleted";
  6365. break;
  6366. case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED :
  6367. ds = "Integrated Raid: Volume Settings Changed";
  6368. break;
  6369. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED :
  6370. ds = "Integrated Raid: Volume Status Changed";
  6371. break;
  6372. case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED :
  6373. ds = "Integrated Raid: Volume Physdisk Changed";
  6374. break;
  6375. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED :
  6376. ds = "Integrated Raid: Physdisk Created";
  6377. break;
  6378. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED :
  6379. ds = "Integrated Raid: Physdisk Deleted";
  6380. break;
  6381. case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED :
  6382. ds = "Integrated Raid: Physdisk Settings Changed";
  6383. break;
  6384. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED :
  6385. ds = "Integrated Raid: Physdisk Status Changed";
  6386. break;
  6387. case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED :
  6388. ds = "Integrated Raid: Domain Validation Needed";
  6389. break;
  6390. case MPI_EVENT_RAID_RC_SMART_DATA :
  6391. ds = "Integrated Raid; Smart Data";
  6392. break;
  6393. case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED :
  6394. ds = "Integrated Raid: Replace Action Started";
  6395. break;
  6396. default:
  6397. ds = "Integrated Raid";
  6398. break;
  6399. }
  6400. break;
  6401. }
  6402. case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE:
  6403. ds = "SCSI Device Status Change";
  6404. break;
  6405. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  6406. {
  6407. u8 id = (u8)(evData0);
  6408. u8 channel = (u8)(evData0 >> 8);
  6409. u8 ReasonCode = (u8)(evData0 >> 16);
  6410. switch (ReasonCode) {
  6411. case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
  6412. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6413. "SAS Device Status Change: Added: "
  6414. "id=%d channel=%d", id, channel);
  6415. break;
  6416. case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
  6417. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6418. "SAS Device Status Change: Deleted: "
  6419. "id=%d channel=%d", id, channel);
  6420. break;
  6421. case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  6422. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6423. "SAS Device Status Change: SMART Data: "
  6424. "id=%d channel=%d", id, channel);
  6425. break;
  6426. case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
  6427. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6428. "SAS Device Status Change: No Persistency: "
  6429. "id=%d channel=%d", id, channel);
  6430. break;
  6431. case MPI_EVENT_SAS_DEV_STAT_RC_UNSUPPORTED:
  6432. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6433. "SAS Device Status Change: Unsupported Device "
  6434. "Discovered : id=%d channel=%d", id, channel);
  6435. break;
  6436. case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  6437. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6438. "SAS Device Status Change: Internal Device "
  6439. "Reset : id=%d channel=%d", id, channel);
  6440. break;
  6441. case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  6442. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6443. "SAS Device Status Change: Internal Task "
  6444. "Abort : id=%d channel=%d", id, channel);
  6445. break;
  6446. case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  6447. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6448. "SAS Device Status Change: Internal Abort "
  6449. "Task Set : id=%d channel=%d", id, channel);
  6450. break;
  6451. case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  6452. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6453. "SAS Device Status Change: Internal Clear "
  6454. "Task Set : id=%d channel=%d", id, channel);
  6455. break;
  6456. case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  6457. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6458. "SAS Device Status Change: Internal Query "
  6459. "Task : id=%d channel=%d", id, channel);
  6460. break;
  6461. default:
  6462. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6463. "SAS Device Status Change: Unknown: "
  6464. "id=%d channel=%d", id, channel);
  6465. break;
  6466. }
  6467. break;
  6468. }
  6469. case MPI_EVENT_ON_BUS_TIMER_EXPIRED:
  6470. ds = "Bus Timer Expired";
  6471. break;
  6472. case MPI_EVENT_QUEUE_FULL:
  6473. {
  6474. u16 curr_depth = (u16)(evData0 >> 16);
  6475. u8 channel = (u8)(evData0 >> 8);
  6476. u8 id = (u8)(evData0);
  6477. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6478. "Queue Full: channel=%d id=%d depth=%d",
  6479. channel, id, curr_depth);
  6480. break;
  6481. }
  6482. case MPI_EVENT_SAS_SES:
  6483. ds = "SAS SES Event";
  6484. break;
  6485. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  6486. ds = "Persistent Table Full";
  6487. break;
  6488. case MPI_EVENT_SAS_PHY_LINK_STATUS:
  6489. {
  6490. u8 LinkRates = (u8)(evData0 >> 8);
  6491. u8 PhyNumber = (u8)(evData0);
  6492. LinkRates = (LinkRates & MPI_EVENT_SAS_PLS_LR_CURRENT_MASK) >>
  6493. MPI_EVENT_SAS_PLS_LR_CURRENT_SHIFT;
  6494. switch (LinkRates) {
  6495. case MPI_EVENT_SAS_PLS_LR_RATE_UNKNOWN:
  6496. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6497. "SAS PHY Link Status: Phy=%d:"
  6498. " Rate Unknown",PhyNumber);
  6499. break;
  6500. case MPI_EVENT_SAS_PLS_LR_RATE_PHY_DISABLED:
  6501. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6502. "SAS PHY Link Status: Phy=%d:"
  6503. " Phy Disabled",PhyNumber);
  6504. break;
  6505. case MPI_EVENT_SAS_PLS_LR_RATE_FAILED_SPEED_NEGOTIATION:
  6506. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6507. "SAS PHY Link Status: Phy=%d:"
  6508. " Failed Speed Nego",PhyNumber);
  6509. break;
  6510. case MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE:
  6511. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6512. "SAS PHY Link Status: Phy=%d:"
  6513. " Sata OOB Completed",PhyNumber);
  6514. break;
  6515. case MPI_EVENT_SAS_PLS_LR_RATE_1_5:
  6516. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6517. "SAS PHY Link Status: Phy=%d:"
  6518. " Rate 1.5 Gbps",PhyNumber);
  6519. break;
  6520. case MPI_EVENT_SAS_PLS_LR_RATE_3_0:
  6521. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6522. "SAS PHY Link Status: Phy=%d:"
  6523. " Rate 3.0 Gbps", PhyNumber);
  6524. break;
  6525. case MPI_EVENT_SAS_PLS_LR_RATE_6_0:
  6526. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6527. "SAS PHY Link Status: Phy=%d:"
  6528. " Rate 6.0 Gbps", PhyNumber);
  6529. break;
  6530. default:
  6531. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6532. "SAS PHY Link Status: Phy=%d", PhyNumber);
  6533. break;
  6534. }
  6535. break;
  6536. }
  6537. case MPI_EVENT_SAS_DISCOVERY_ERROR:
  6538. ds = "SAS Discovery Error";
  6539. break;
  6540. case MPI_EVENT_IR_RESYNC_UPDATE:
  6541. {
  6542. u8 resync_complete = (u8)(evData0 >> 16);
  6543. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6544. "IR Resync Update: Complete = %d:",resync_complete);
  6545. break;
  6546. }
  6547. case MPI_EVENT_IR2:
  6548. {
  6549. u8 id = (u8)(evData0);
  6550. u8 channel = (u8)(evData0 >> 8);
  6551. u8 phys_num = (u8)(evData0 >> 24);
  6552. u8 ReasonCode = (u8)(evData0 >> 16);
  6553. switch (ReasonCode) {
  6554. case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
  6555. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6556. "IR2: LD State Changed: "
  6557. "id=%d channel=%d phys_num=%d",
  6558. id, channel, phys_num);
  6559. break;
  6560. case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
  6561. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6562. "IR2: PD State Changed "
  6563. "id=%d channel=%d phys_num=%d",
  6564. id, channel, phys_num);
  6565. break;
  6566. case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
  6567. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6568. "IR2: Bad Block Table Full: "
  6569. "id=%d channel=%d phys_num=%d",
  6570. id, channel, phys_num);
  6571. break;
  6572. case MPI_EVENT_IR2_RC_PD_INSERTED:
  6573. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6574. "IR2: PD Inserted: "
  6575. "id=%d channel=%d phys_num=%d",
  6576. id, channel, phys_num);
  6577. break;
  6578. case MPI_EVENT_IR2_RC_PD_REMOVED:
  6579. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6580. "IR2: PD Removed: "
  6581. "id=%d channel=%d phys_num=%d",
  6582. id, channel, phys_num);
  6583. break;
  6584. case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
  6585. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6586. "IR2: Foreign CFG Detected: "
  6587. "id=%d channel=%d phys_num=%d",
  6588. id, channel, phys_num);
  6589. break;
  6590. case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
  6591. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6592. "IR2: Rebuild Medium Error: "
  6593. "id=%d channel=%d phys_num=%d",
  6594. id, channel, phys_num);
  6595. break;
  6596. case MPI_EVENT_IR2_RC_DUAL_PORT_ADDED:
  6597. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6598. "IR2: Dual Port Added: "
  6599. "id=%d channel=%d phys_num=%d",
  6600. id, channel, phys_num);
  6601. break;
  6602. case MPI_EVENT_IR2_RC_DUAL_PORT_REMOVED:
  6603. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6604. "IR2: Dual Port Removed: "
  6605. "id=%d channel=%d phys_num=%d",
  6606. id, channel, phys_num);
  6607. break;
  6608. default:
  6609. ds = "IR2";
  6610. break;
  6611. }
  6612. break;
  6613. }
  6614. case MPI_EVENT_SAS_DISCOVERY:
  6615. {
  6616. if (evData0)
  6617. ds = "SAS Discovery: Start";
  6618. else
  6619. ds = "SAS Discovery: Stop";
  6620. break;
  6621. }
  6622. case MPI_EVENT_LOG_ENTRY_ADDED:
  6623. ds = "SAS Log Entry Added";
  6624. break;
  6625. case MPI_EVENT_SAS_BROADCAST_PRIMITIVE:
  6626. {
  6627. u8 phy_num = (u8)(evData0);
  6628. u8 port_num = (u8)(evData0 >> 8);
  6629. u8 port_width = (u8)(evData0 >> 16);
  6630. u8 primitive = (u8)(evData0 >> 24);
  6631. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6632. "SAS Broadcast Primitive: phy=%d port=%d "
  6633. "width=%d primitive=0x%02x",
  6634. phy_num, port_num, port_width, primitive);
  6635. break;
  6636. }
  6637. case MPI_EVENT_SAS_INIT_DEVICE_STATUS_CHANGE:
  6638. {
  6639. u8 reason = (u8)(evData0);
  6640. switch (reason) {
  6641. case MPI_EVENT_SAS_INIT_RC_ADDED:
  6642. ds = "SAS Initiator Status Change: Added";
  6643. break;
  6644. case MPI_EVENT_SAS_INIT_RC_REMOVED:
  6645. ds = "SAS Initiator Status Change: Deleted";
  6646. break;
  6647. default:
  6648. ds = "SAS Initiator Status Change";
  6649. break;
  6650. }
  6651. break;
  6652. }
  6653. case MPI_EVENT_SAS_INIT_TABLE_OVERFLOW:
  6654. {
  6655. u8 max_init = (u8)(evData0);
  6656. u8 current_init = (u8)(evData0 >> 8);
  6657. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6658. "SAS Initiator Device Table Overflow: max initiators=%02d "
  6659. "current initiators=%02d",
  6660. max_init, current_init);
  6661. break;
  6662. }
  6663. case MPI_EVENT_SAS_SMP_ERROR:
  6664. {
  6665. u8 status = (u8)(evData0);
  6666. u8 port_num = (u8)(evData0 >> 8);
  6667. u8 result = (u8)(evData0 >> 16);
  6668. if (status == MPI_EVENT_SAS_SMP_FUNCTION_RESULT_VALID)
  6669. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6670. "SAS SMP Error: port=%d result=0x%02x",
  6671. port_num, result);
  6672. else if (status == MPI_EVENT_SAS_SMP_CRC_ERROR)
  6673. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6674. "SAS SMP Error: port=%d : CRC Error",
  6675. port_num);
  6676. else if (status == MPI_EVENT_SAS_SMP_TIMEOUT)
  6677. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6678. "SAS SMP Error: port=%d : Timeout",
  6679. port_num);
  6680. else if (status == MPI_EVENT_SAS_SMP_NO_DESTINATION)
  6681. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6682. "SAS SMP Error: port=%d : No Destination",
  6683. port_num);
  6684. else if (status == MPI_EVENT_SAS_SMP_BAD_DESTINATION)
  6685. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6686. "SAS SMP Error: port=%d : Bad Destination",
  6687. port_num);
  6688. else
  6689. snprintf(evStr, EVENT_DESCR_STR_SZ,
  6690. "SAS SMP Error: port=%d : status=0x%02x",
  6691. port_num, status);
  6692. break;
  6693. }
  6694. case MPI_EVENT_SAS_EXPANDER_STATUS_CHANGE:
  6695. {
  6696. u8 reason = (u8)(evData0);
  6697. switch (reason) {
  6698. case MPI_EVENT_SAS_EXP_RC_ADDED:
  6699. ds = "Expander Status Change: Added";
  6700. break;
  6701. case MPI_EVENT_SAS_EXP_RC_NOT_RESPONDING:
  6702. ds = "Expander Status Change: Deleted";
  6703. break;
  6704. default:
  6705. ds = "Expander Status Change";
  6706. break;
  6707. }
  6708. break;
  6709. }
  6710. /*
  6711. * MPT base "custom" events may be added here...
  6712. */
  6713. default:
  6714. ds = "Unknown";
  6715. break;
  6716. }
  6717. if (ds)
  6718. strlcpy(evStr, ds, EVENT_DESCR_STR_SZ);
  6719. devtprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6720. "MPT event:(%02Xh) : %s\n",
  6721. ioc->name, event, evStr));
  6722. devtverboseprintk(ioc, printk(KERN_DEBUG MYNAM
  6723. ": Event data:\n"));
  6724. for (ii = 0; ii < le16_to_cpu(pEventReply->EventDataLength); ii++)
  6725. devtverboseprintk(ioc, printk(" %08x",
  6726. le32_to_cpu(pEventReply->Data[ii])));
  6727. devtverboseprintk(ioc, printk(KERN_DEBUG "\n"));
  6728. }
  6729. #endif
  6730. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6731. /**
  6732. * ProcessEventNotification - Route EventNotificationReply to all event handlers
  6733. * @ioc: Pointer to MPT_ADAPTER structure
  6734. * @pEventReply: Pointer to EventNotification reply frame
  6735. * @evHandlers: Pointer to integer, number of event handlers
  6736. *
  6737. * Routes a received EventNotificationReply to all currently registered
  6738. * event handlers.
  6739. * Returns sum of event handlers return values.
  6740. */
  6741. static int
  6742. ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  6743. {
  6744. u16 evDataLen;
  6745. u32 evData0 = 0;
  6746. int ii;
  6747. u8 cb_idx;
  6748. int r = 0;
  6749. int handlers = 0;
  6750. u8 event;
  6751. /*
  6752. * Do platform normalization of values
  6753. */
  6754. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  6755. evDataLen = le16_to_cpu(pEventReply->EventDataLength);
  6756. if (evDataLen) {
  6757. evData0 = le32_to_cpu(pEventReply->Data[0]);
  6758. }
  6759. #ifdef CONFIG_FUSION_LOGGING
  6760. if (evDataLen)
  6761. mpt_display_event_info(ioc, pEventReply);
  6762. #endif
  6763. /*
  6764. * Do general / base driver event processing
  6765. */
  6766. switch(event) {
  6767. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  6768. if (evDataLen) {
  6769. u8 evState = evData0 & 0xFF;
  6770. /* CHECKME! What if evState unexpectedly says OFF (0)? */
  6771. /* Update EventState field in cached IocFacts */
  6772. if (ioc->facts.Function) {
  6773. ioc->facts.EventState = evState;
  6774. }
  6775. }
  6776. break;
  6777. case MPI_EVENT_INTEGRATED_RAID:
  6778. mptbase_raid_process_event_data(ioc,
  6779. (MpiEventDataRaid_t *)pEventReply->Data);
  6780. break;
  6781. default:
  6782. break;
  6783. }
  6784. /*
  6785. * Should this event be logged? Events are written sequentially.
  6786. * When buffer is full, start again at the top.
  6787. */
  6788. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  6789. int idx;
  6790. idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
  6791. ioc->events[idx].event = event;
  6792. ioc->events[idx].eventContext = ioc->eventContext;
  6793. for (ii = 0; ii < 2; ii++) {
  6794. if (ii < evDataLen)
  6795. ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
  6796. else
  6797. ioc->events[idx].data[ii] = 0;
  6798. }
  6799. ioc->eventContext++;
  6800. }
  6801. /*
  6802. * Call each currently registered protocol event handler.
  6803. */
  6804. for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) {
  6805. if (MptEvHandlers[cb_idx]) {
  6806. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6807. "Routing Event to event handler #%d\n",
  6808. ioc->name, cb_idx));
  6809. r += (*(MptEvHandlers[cb_idx]))(ioc, pEventReply);
  6810. handlers++;
  6811. }
  6812. }
  6813. /* FIXME? Examine results here? */
  6814. /*
  6815. * If needed, send (a single) EventAck.
  6816. */
  6817. if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
  6818. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT
  6819. "EventAck required\n",ioc->name));
  6820. if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
  6821. devtverboseprintk(ioc, printk(MYIOC_s_DEBUG_FMT "SendEventAck returned %d\n",
  6822. ioc->name, ii));
  6823. }
  6824. }
  6825. *evHandlers = handlers;
  6826. return r;
  6827. }
  6828. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6829. /**
  6830. * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
  6831. * @ioc: Pointer to MPT_ADAPTER structure
  6832. * @log_info: U32 LogInfo reply word from the IOC
  6833. *
  6834. * Refer to lsi/mpi_log_fc.h.
  6835. */
  6836. static void
  6837. mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
  6838. {
  6839. char *desc = "unknown";
  6840. switch (log_info & 0xFF000000) {
  6841. case MPI_IOCLOGINFO_FC_INIT_BASE:
  6842. desc = "FCP Initiator";
  6843. break;
  6844. case MPI_IOCLOGINFO_FC_TARGET_BASE:
  6845. desc = "FCP Target";
  6846. break;
  6847. case MPI_IOCLOGINFO_FC_LAN_BASE:
  6848. desc = "LAN";
  6849. break;
  6850. case MPI_IOCLOGINFO_FC_MSG_BASE:
  6851. desc = "MPI Message Layer";
  6852. break;
  6853. case MPI_IOCLOGINFO_FC_LINK_BASE:
  6854. desc = "FC Link";
  6855. break;
  6856. case MPI_IOCLOGINFO_FC_CTX_BASE:
  6857. desc = "Context Manager";
  6858. break;
  6859. case MPI_IOCLOGINFO_FC_INVALID_FIELD_BYTE_OFFSET:
  6860. desc = "Invalid Field Offset";
  6861. break;
  6862. case MPI_IOCLOGINFO_FC_STATE_CHANGE:
  6863. desc = "State Change Info";
  6864. break;
  6865. }
  6866. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubClass={%s}, Value=(0x%06x)\n",
  6867. ioc->name, log_info, desc, (log_info & 0xFFFFFF));
  6868. }
  6869. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  6870. /**
  6871. * mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
  6872. * @ioc: Pointer to MPT_ADAPTER structure
  6873. * @log_info: U32 LogInfo word from the IOC
  6874. *
  6875. * Refer to lsi/sp_log.h.
  6876. */
  6877. static void
  6878. mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
  6879. {
  6880. u32 info = log_info & 0x00FF0000;
  6881. char *desc = "unknown";
  6882. switch (info) {
  6883. case 0x00010000:
  6884. desc = "bug! MID not found";
  6885. break;
  6886. case 0x00020000:
  6887. desc = "Parity Error";
  6888. break;
  6889. case 0x00030000:
  6890. desc = "ASYNC Outbound Overrun";
  6891. break;
  6892. case 0x00040000:
  6893. desc = "SYNC Offset Error";
  6894. break;
  6895. case 0x00050000:
  6896. desc = "BM Change";
  6897. break;
  6898. case 0x00060000:
  6899. desc = "Msg In Overflow";
  6900. break;
  6901. case 0x00070000:
  6902. desc = "DMA Error";
  6903. break;
  6904. case 0x00080000:
  6905. desc = "Outbound DMA Overrun";
  6906. break;
  6907. case 0x00090000:
  6908. desc = "Task Management";
  6909. break;
  6910. case 0x000A0000:
  6911. desc = "Device Problem";
  6912. break;
  6913. case 0x000B0000:
  6914. desc = "Invalid Phase Change";
  6915. break;
  6916. case 0x000C0000:
  6917. desc = "Untagged Table Size";
  6918. break;
  6919. }
  6920. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
  6921. }
  6922. /* strings for sas loginfo */
  6923. static char *originator_str[] = {
  6924. "IOP", /* 00h */
  6925. "PL", /* 01h */
  6926. "IR" /* 02h */
  6927. };
  6928. static char *iop_code_str[] = {
  6929. NULL, /* 00h */
  6930. "Invalid SAS Address", /* 01h */
  6931. NULL, /* 02h */
  6932. "Invalid Page", /* 03h */
  6933. "Diag Message Error", /* 04h */
  6934. "Task Terminated", /* 05h */
  6935. "Enclosure Management", /* 06h */
  6936. "Target Mode" /* 07h */
  6937. };
  6938. static char *pl_code_str[] = {
  6939. NULL, /* 00h */
  6940. "Open Failure", /* 01h */
  6941. "Invalid Scatter Gather List", /* 02h */
  6942. "Wrong Relative Offset or Frame Length", /* 03h */
  6943. "Frame Transfer Error", /* 04h */
  6944. "Transmit Frame Connected Low", /* 05h */
  6945. "SATA Non-NCQ RW Error Bit Set", /* 06h */
  6946. "SATA Read Log Receive Data Error", /* 07h */
  6947. "SATA NCQ Fail All Commands After Error", /* 08h */
  6948. "SATA Error in Receive Set Device Bit FIS", /* 09h */
  6949. "Receive Frame Invalid Message", /* 0Ah */
  6950. "Receive Context Message Valid Error", /* 0Bh */
  6951. "Receive Frame Current Frame Error", /* 0Ch */
  6952. "SATA Link Down", /* 0Dh */
  6953. "Discovery SATA Init W IOS", /* 0Eh */
  6954. "Config Invalid Page", /* 0Fh */
  6955. "Discovery SATA Init Timeout", /* 10h */
  6956. "Reset", /* 11h */
  6957. "Abort", /* 12h */
  6958. "IO Not Yet Executed", /* 13h */
  6959. "IO Executed", /* 14h */
  6960. "Persistent Reservation Out Not Affiliation "
  6961. "Owner", /* 15h */
  6962. "Open Transmit DMA Abort", /* 16h */
  6963. "IO Device Missing Delay Retry", /* 17h */
  6964. "IO Cancelled Due to Receive Error", /* 18h */
  6965. NULL, /* 19h */
  6966. NULL, /* 1Ah */
  6967. NULL, /* 1Bh */
  6968. NULL, /* 1Ch */
  6969. NULL, /* 1Dh */
  6970. NULL, /* 1Eh */
  6971. NULL, /* 1Fh */
  6972. "Enclosure Management" /* 20h */
  6973. };
  6974. static char *ir_code_str[] = {
  6975. "Raid Action Error", /* 00h */
  6976. NULL, /* 00h */
  6977. NULL, /* 01h */
  6978. NULL, /* 02h */
  6979. NULL, /* 03h */
  6980. NULL, /* 04h */
  6981. NULL, /* 05h */
  6982. NULL, /* 06h */
  6983. NULL /* 07h */
  6984. };
  6985. static char *raid_sub_code_str[] = {
  6986. NULL, /* 00h */
  6987. "Volume Creation Failed: Data Passed too "
  6988. "Large", /* 01h */
  6989. "Volume Creation Failed: Duplicate Volumes "
  6990. "Attempted", /* 02h */
  6991. "Volume Creation Failed: Max Number "
  6992. "Supported Volumes Exceeded", /* 03h */
  6993. "Volume Creation Failed: DMA Error", /* 04h */
  6994. "Volume Creation Failed: Invalid Volume Type", /* 05h */
  6995. "Volume Creation Failed: Error Reading "
  6996. "MFG Page 4", /* 06h */
  6997. "Volume Creation Failed: Creating Internal "
  6998. "Structures", /* 07h */
  6999. NULL, /* 08h */
  7000. NULL, /* 09h */
  7001. NULL, /* 0Ah */
  7002. NULL, /* 0Bh */
  7003. NULL, /* 0Ch */
  7004. NULL, /* 0Dh */
  7005. NULL, /* 0Eh */
  7006. NULL, /* 0Fh */
  7007. "Activation failed: Already Active Volume", /* 10h */
  7008. "Activation failed: Unsupported Volume Type", /* 11h */
  7009. "Activation failed: Too Many Active Volumes", /* 12h */
  7010. "Activation failed: Volume ID in Use", /* 13h */
  7011. "Activation failed: Reported Failure", /* 14h */
  7012. "Activation failed: Importing a Volume", /* 15h */
  7013. NULL, /* 16h */
  7014. NULL, /* 17h */
  7015. NULL, /* 18h */
  7016. NULL, /* 19h */
  7017. NULL, /* 1Ah */
  7018. NULL, /* 1Bh */
  7019. NULL, /* 1Ch */
  7020. NULL, /* 1Dh */
  7021. NULL, /* 1Eh */
  7022. NULL, /* 1Fh */
  7023. "Phys Disk failed: Too Many Phys Disks", /* 20h */
  7024. "Phys Disk failed: Data Passed too Large", /* 21h */
  7025. "Phys Disk failed: DMA Error", /* 22h */
  7026. "Phys Disk failed: Invalid <channel:id>", /* 23h */
  7027. "Phys Disk failed: Creating Phys Disk Config "
  7028. "Page", /* 24h */
  7029. NULL, /* 25h */
  7030. NULL, /* 26h */
  7031. NULL, /* 27h */
  7032. NULL, /* 28h */
  7033. NULL, /* 29h */
  7034. NULL, /* 2Ah */
  7035. NULL, /* 2Bh */
  7036. NULL, /* 2Ch */
  7037. NULL, /* 2Dh */
  7038. NULL, /* 2Eh */
  7039. NULL, /* 2Fh */
  7040. "Compatibility Error: IR Disabled", /* 30h */
  7041. "Compatibility Error: Inquiry Command Failed", /* 31h */
  7042. "Compatibility Error: Device not Direct Access "
  7043. "Device ", /* 32h */
  7044. "Compatibility Error: Removable Device Found", /* 33h */
  7045. "Compatibility Error: Device SCSI Version not "
  7046. "2 or Higher", /* 34h */
  7047. "Compatibility Error: SATA Device, 48 BIT LBA "
  7048. "not Supported", /* 35h */
  7049. "Compatibility Error: Device doesn't have "
  7050. "512 Byte Block Sizes", /* 36h */
  7051. "Compatibility Error: Volume Type Check Failed", /* 37h */
  7052. "Compatibility Error: Volume Type is "
  7053. "Unsupported by FW", /* 38h */
  7054. "Compatibility Error: Disk Drive too Small for "
  7055. "use in Volume", /* 39h */
  7056. "Compatibility Error: Phys Disk for Create "
  7057. "Volume not Found", /* 3Ah */
  7058. "Compatibility Error: Too Many or too Few "
  7059. "Disks for Volume Type", /* 3Bh */
  7060. "Compatibility Error: Disk stripe Sizes "
  7061. "Must be 64KB", /* 3Ch */
  7062. "Compatibility Error: IME Size Limited to < 2TB", /* 3Dh */
  7063. };
  7064. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7065. /**
  7066. * mpt_sas_log_info - Log information returned from SAS IOC.
  7067. * @ioc: Pointer to MPT_ADAPTER structure
  7068. * @log_info: U32 LogInfo reply word from the IOC
  7069. * @cb_idx: callback function's handle
  7070. *
  7071. * Refer to lsi/mpi_log_sas.h.
  7072. **/
  7073. static void
  7074. mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info, u8 cb_idx)
  7075. {
  7076. union loginfo_type {
  7077. u32 loginfo;
  7078. struct {
  7079. u32 subcode:16;
  7080. u32 code:8;
  7081. u32 originator:4;
  7082. u32 bus_type:4;
  7083. } dw;
  7084. };
  7085. union loginfo_type sas_loginfo;
  7086. char *originator_desc = NULL;
  7087. char *code_desc = NULL;
  7088. char *sub_code_desc = NULL;
  7089. sas_loginfo.loginfo = log_info;
  7090. if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
  7091. (sas_loginfo.dw.originator < ARRAY_SIZE(originator_str)))
  7092. return;
  7093. originator_desc = originator_str[sas_loginfo.dw.originator];
  7094. switch (sas_loginfo.dw.originator) {
  7095. case 0: /* IOP */
  7096. if (sas_loginfo.dw.code <
  7097. ARRAY_SIZE(iop_code_str))
  7098. code_desc = iop_code_str[sas_loginfo.dw.code];
  7099. break;
  7100. case 1: /* PL */
  7101. if (sas_loginfo.dw.code <
  7102. ARRAY_SIZE(pl_code_str))
  7103. code_desc = pl_code_str[sas_loginfo.dw.code];
  7104. break;
  7105. case 2: /* IR */
  7106. if (sas_loginfo.dw.code >=
  7107. ARRAY_SIZE(ir_code_str))
  7108. break;
  7109. code_desc = ir_code_str[sas_loginfo.dw.code];
  7110. if (sas_loginfo.dw.subcode >=
  7111. ARRAY_SIZE(raid_sub_code_str))
  7112. break;
  7113. if (sas_loginfo.dw.code == 0)
  7114. sub_code_desc =
  7115. raid_sub_code_str[sas_loginfo.dw.subcode];
  7116. break;
  7117. default:
  7118. return;
  7119. }
  7120. if (sub_code_desc != NULL)
  7121. printk(MYIOC_s_INFO_FMT
  7122. "LogInfo(0x%08x): Originator={%s}, Code={%s},"
  7123. " SubCode={%s} cb_idx %s\n",
  7124. ioc->name, log_info, originator_desc, code_desc,
  7125. sub_code_desc, MptCallbacksName[cb_idx]);
  7126. else if (code_desc != NULL)
  7127. printk(MYIOC_s_INFO_FMT
  7128. "LogInfo(0x%08x): Originator={%s}, Code={%s},"
  7129. " SubCode(0x%04x) cb_idx %s\n",
  7130. ioc->name, log_info, originator_desc, code_desc,
  7131. sas_loginfo.dw.subcode, MptCallbacksName[cb_idx]);
  7132. else
  7133. printk(MYIOC_s_INFO_FMT
  7134. "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
  7135. " SubCode(0x%04x) cb_idx %s\n",
  7136. ioc->name, log_info, originator_desc,
  7137. sas_loginfo.dw.code, sas_loginfo.dw.subcode,
  7138. MptCallbacksName[cb_idx]);
  7139. }
  7140. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7141. /**
  7142. * mpt_iocstatus_info_config - IOCSTATUS information for config pages
  7143. * @ioc: Pointer to MPT_ADAPTER structure
  7144. * @ioc_status: U32 IOCStatus word from IOC
  7145. * @mf: Pointer to MPT request frame
  7146. *
  7147. * Refer to lsi/mpi.h.
  7148. **/
  7149. static void
  7150. mpt_iocstatus_info_config(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  7151. {
  7152. Config_t *pReq = (Config_t *)mf;
  7153. char extend_desc[EVENT_DESCR_STR_SZ];
  7154. char *desc = NULL;
  7155. u32 form;
  7156. u8 page_type;
  7157. if (pReq->Header.PageType == MPI_CONFIG_PAGETYPE_EXTENDED)
  7158. page_type = pReq->ExtPageType;
  7159. else
  7160. page_type = pReq->Header.PageType;
  7161. /*
  7162. * ignore invalid page messages for GET_NEXT_HANDLE
  7163. */
  7164. form = le32_to_cpu(pReq->PageAddress);
  7165. if (ioc_status == MPI_IOCSTATUS_CONFIG_INVALID_PAGE) {
  7166. if (page_type == MPI_CONFIG_EXTPAGETYPE_SAS_DEVICE ||
  7167. page_type == MPI_CONFIG_EXTPAGETYPE_SAS_EXPANDER ||
  7168. page_type == MPI_CONFIG_EXTPAGETYPE_ENCLOSURE) {
  7169. if ((form >> MPI_SAS_DEVICE_PGAD_FORM_SHIFT) ==
  7170. MPI_SAS_DEVICE_PGAD_FORM_GET_NEXT_HANDLE)
  7171. return;
  7172. }
  7173. if (page_type == MPI_CONFIG_PAGETYPE_FC_DEVICE)
  7174. if ((form & MPI_FC_DEVICE_PGAD_FORM_MASK) ==
  7175. MPI_FC_DEVICE_PGAD_FORM_NEXT_DID)
  7176. return;
  7177. }
  7178. snprintf(extend_desc, EVENT_DESCR_STR_SZ,
  7179. "type=%02Xh, page=%02Xh, action=%02Xh, form=%08Xh",
  7180. page_type, pReq->Header.PageNumber, pReq->Action, form);
  7181. switch (ioc_status) {
  7182. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  7183. desc = "Config Page Invalid Action";
  7184. break;
  7185. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  7186. desc = "Config Page Invalid Type";
  7187. break;
  7188. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  7189. desc = "Config Page Invalid Page";
  7190. break;
  7191. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  7192. desc = "Config Page Invalid Data";
  7193. break;
  7194. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  7195. desc = "Config Page No Defaults";
  7196. break;
  7197. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  7198. desc = "Config Page Can't Commit";
  7199. break;
  7200. }
  7201. if (!desc)
  7202. return;
  7203. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s: %s\n",
  7204. ioc->name, ioc_status, desc, extend_desc));
  7205. }
  7206. /**
  7207. * mpt_iocstatus_info - IOCSTATUS information returned from IOC.
  7208. * @ioc: Pointer to MPT_ADAPTER structure
  7209. * @ioc_status: U32 IOCStatus word from IOC
  7210. * @mf: Pointer to MPT request frame
  7211. *
  7212. * Refer to lsi/mpi.h.
  7213. **/
  7214. static void
  7215. mpt_iocstatus_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  7216. {
  7217. u32 status = ioc_status & MPI_IOCSTATUS_MASK;
  7218. char *desc = NULL;
  7219. switch (status) {
  7220. /****************************************************************************/
  7221. /* Common IOCStatus values for all replies */
  7222. /****************************************************************************/
  7223. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  7224. desc = "Invalid Function";
  7225. break;
  7226. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  7227. desc = "Busy";
  7228. break;
  7229. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  7230. desc = "Invalid SGL";
  7231. break;
  7232. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  7233. desc = "Internal Error";
  7234. break;
  7235. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  7236. desc = "Reserved";
  7237. break;
  7238. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  7239. desc = "Insufficient Resources";
  7240. break;
  7241. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  7242. desc = "Invalid Field";
  7243. break;
  7244. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  7245. desc = "Invalid State";
  7246. break;
  7247. /****************************************************************************/
  7248. /* Config IOCStatus values */
  7249. /****************************************************************************/
  7250. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  7251. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  7252. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  7253. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  7254. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  7255. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  7256. mpt_iocstatus_info_config(ioc, status, mf);
  7257. break;
  7258. /****************************************************************************/
  7259. /* SCSIIO Reply (SPI, FCP, SAS) initiator values */
  7260. /* */
  7261. /* Look at mptscsih_iocstatus_info_scsiio in mptscsih.c */
  7262. /* */
  7263. /****************************************************************************/
  7264. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  7265. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  7266. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  7267. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  7268. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  7269. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  7270. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  7271. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  7272. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  7273. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  7274. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  7275. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  7276. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  7277. break;
  7278. /****************************************************************************/
  7279. /* SCSI Target values */
  7280. /****************************************************************************/
  7281. case MPI_IOCSTATUS_TARGET_PRIORITY_IO: /* 0x0060 */
  7282. desc = "Target: Priority IO";
  7283. break;
  7284. case MPI_IOCSTATUS_TARGET_INVALID_PORT: /* 0x0061 */
  7285. desc = "Target: Invalid Port";
  7286. break;
  7287. case MPI_IOCSTATUS_TARGET_INVALID_IO_INDEX: /* 0x0062 */
  7288. desc = "Target Invalid IO Index:";
  7289. break;
  7290. case MPI_IOCSTATUS_TARGET_ABORTED: /* 0x0063 */
  7291. desc = "Target: Aborted";
  7292. break;
  7293. case MPI_IOCSTATUS_TARGET_NO_CONN_RETRYABLE: /* 0x0064 */
  7294. desc = "Target: No Conn Retryable";
  7295. break;
  7296. case MPI_IOCSTATUS_TARGET_NO_CONNECTION: /* 0x0065 */
  7297. desc = "Target: No Connection";
  7298. break;
  7299. case MPI_IOCSTATUS_TARGET_XFER_COUNT_MISMATCH: /* 0x006A */
  7300. desc = "Target: Transfer Count Mismatch";
  7301. break;
  7302. case MPI_IOCSTATUS_TARGET_STS_DATA_NOT_SENT: /* 0x006B */
  7303. desc = "Target: STS Data not Sent";
  7304. break;
  7305. case MPI_IOCSTATUS_TARGET_DATA_OFFSET_ERROR: /* 0x006D */
  7306. desc = "Target: Data Offset Error";
  7307. break;
  7308. case MPI_IOCSTATUS_TARGET_TOO_MUCH_WRITE_DATA: /* 0x006E */
  7309. desc = "Target: Too Much Write Data";
  7310. break;
  7311. case MPI_IOCSTATUS_TARGET_IU_TOO_SHORT: /* 0x006F */
  7312. desc = "Target: IU Too Short";
  7313. break;
  7314. case MPI_IOCSTATUS_TARGET_ACK_NAK_TIMEOUT: /* 0x0070 */
  7315. desc = "Target: ACK NAK Timeout";
  7316. break;
  7317. case MPI_IOCSTATUS_TARGET_NAK_RECEIVED: /* 0x0071 */
  7318. desc = "Target: Nak Received";
  7319. break;
  7320. /****************************************************************************/
  7321. /* Fibre Channel Direct Access values */
  7322. /****************************************************************************/
  7323. case MPI_IOCSTATUS_FC_ABORTED: /* 0x0066 */
  7324. desc = "FC: Aborted";
  7325. break;
  7326. case MPI_IOCSTATUS_FC_RX_ID_INVALID: /* 0x0067 */
  7327. desc = "FC: RX ID Invalid";
  7328. break;
  7329. case MPI_IOCSTATUS_FC_DID_INVALID: /* 0x0068 */
  7330. desc = "FC: DID Invalid";
  7331. break;
  7332. case MPI_IOCSTATUS_FC_NODE_LOGGED_OUT: /* 0x0069 */
  7333. desc = "FC: Node Logged Out";
  7334. break;
  7335. case MPI_IOCSTATUS_FC_EXCHANGE_CANCELED: /* 0x006C */
  7336. desc = "FC: Exchange Canceled";
  7337. break;
  7338. /****************************************************************************/
  7339. /* LAN values */
  7340. /****************************************************************************/
  7341. case MPI_IOCSTATUS_LAN_DEVICE_NOT_FOUND: /* 0x0080 */
  7342. desc = "LAN: Device not Found";
  7343. break;
  7344. case MPI_IOCSTATUS_LAN_DEVICE_FAILURE: /* 0x0081 */
  7345. desc = "LAN: Device Failure";
  7346. break;
  7347. case MPI_IOCSTATUS_LAN_TRANSMIT_ERROR: /* 0x0082 */
  7348. desc = "LAN: Transmit Error";
  7349. break;
  7350. case MPI_IOCSTATUS_LAN_TRANSMIT_ABORTED: /* 0x0083 */
  7351. desc = "LAN: Transmit Aborted";
  7352. break;
  7353. case MPI_IOCSTATUS_LAN_RECEIVE_ERROR: /* 0x0084 */
  7354. desc = "LAN: Receive Error";
  7355. break;
  7356. case MPI_IOCSTATUS_LAN_RECEIVE_ABORTED: /* 0x0085 */
  7357. desc = "LAN: Receive Aborted";
  7358. break;
  7359. case MPI_IOCSTATUS_LAN_PARTIAL_PACKET: /* 0x0086 */
  7360. desc = "LAN: Partial Packet";
  7361. break;
  7362. case MPI_IOCSTATUS_LAN_CANCELED: /* 0x0087 */
  7363. desc = "LAN: Canceled";
  7364. break;
  7365. /****************************************************************************/
  7366. /* Serial Attached SCSI values */
  7367. /****************************************************************************/
  7368. case MPI_IOCSTATUS_SAS_SMP_REQUEST_FAILED: /* 0x0090 */
  7369. desc = "SAS: SMP Request Failed";
  7370. break;
  7371. case MPI_IOCSTATUS_SAS_SMP_DATA_OVERRUN: /* 0x0090 */
  7372. desc = "SAS: SMP Data Overrun";
  7373. break;
  7374. default:
  7375. desc = "Others";
  7376. break;
  7377. }
  7378. if (!desc)
  7379. return;
  7380. dreplyprintk(ioc, printk(MYIOC_s_DEBUG_FMT "IOCStatus(0x%04X): %s\n",
  7381. ioc->name, status, desc));
  7382. }
  7383. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7384. EXPORT_SYMBOL(mpt_attach);
  7385. EXPORT_SYMBOL(mpt_detach);
  7386. #ifdef CONFIG_PM
  7387. EXPORT_SYMBOL(mpt_resume);
  7388. EXPORT_SYMBOL(mpt_suspend);
  7389. #endif
  7390. EXPORT_SYMBOL(ioc_list);
  7391. EXPORT_SYMBOL(mpt_register);
  7392. EXPORT_SYMBOL(mpt_deregister);
  7393. EXPORT_SYMBOL(mpt_event_register);
  7394. EXPORT_SYMBOL(mpt_event_deregister);
  7395. EXPORT_SYMBOL(mpt_reset_register);
  7396. EXPORT_SYMBOL(mpt_reset_deregister);
  7397. EXPORT_SYMBOL(mpt_device_driver_register);
  7398. EXPORT_SYMBOL(mpt_device_driver_deregister);
  7399. EXPORT_SYMBOL(mpt_get_msg_frame);
  7400. EXPORT_SYMBOL(mpt_put_msg_frame);
  7401. EXPORT_SYMBOL(mpt_put_msg_frame_hi_pri);
  7402. EXPORT_SYMBOL(mpt_free_msg_frame);
  7403. EXPORT_SYMBOL(mpt_send_handshake_request);
  7404. EXPORT_SYMBOL(mpt_verify_adapter);
  7405. EXPORT_SYMBOL(mpt_GetIocState);
  7406. EXPORT_SYMBOL(mpt_print_ioc_summary);
  7407. EXPORT_SYMBOL(mpt_HardResetHandler);
  7408. EXPORT_SYMBOL(mpt_config);
  7409. EXPORT_SYMBOL(mpt_findImVolumes);
  7410. EXPORT_SYMBOL(mpt_alloc_fw_memory);
  7411. EXPORT_SYMBOL(mpt_free_fw_memory);
  7412. EXPORT_SYMBOL(mptbase_sas_persist_operation);
  7413. EXPORT_SYMBOL(mpt_raid_phys_disk_pg0);
  7414. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7415. /**
  7416. * fusion_init - Fusion MPT base driver initialization routine.
  7417. *
  7418. * Returns 0 for success, non-zero for failure.
  7419. */
  7420. static int __init
  7421. fusion_init(void)
  7422. {
  7423. u8 cb_idx;
  7424. show_mptmod_ver(my_NAME, my_VERSION);
  7425. printk(KERN_INFO COPYRIGHT "\n");
  7426. for (cb_idx = 0; cb_idx < MPT_MAX_PROTOCOL_DRIVERS; cb_idx++) {
  7427. MptCallbacks[cb_idx] = NULL;
  7428. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  7429. MptEvHandlers[cb_idx] = NULL;
  7430. MptResetHandlers[cb_idx] = NULL;
  7431. }
  7432. /* Register ourselves (mptbase) in order to facilitate
  7433. * EventNotification handling.
  7434. */
  7435. mpt_base_index = mpt_register(mptbase_reply, MPTBASE_DRIVER,
  7436. "mptbase_reply");
  7437. /* Register for hard reset handling callbacks.
  7438. */
  7439. mpt_reset_register(mpt_base_index, mpt_ioc_reset);
  7440. #ifdef CONFIG_PROC_FS
  7441. (void) procmpt_create();
  7442. #endif
  7443. return 0;
  7444. }
  7445. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  7446. /**
  7447. * fusion_exit - Perform driver unload cleanup.
  7448. *
  7449. * This routine frees all resources associated with each MPT adapter
  7450. * and removes all %MPT_PROCFS_MPTBASEDIR entries.
  7451. */
  7452. static void __exit
  7453. fusion_exit(void)
  7454. {
  7455. mpt_reset_deregister(mpt_base_index);
  7456. #ifdef CONFIG_PROC_FS
  7457. procmpt_destroy();
  7458. #endif
  7459. }
  7460. module_init(fusion_init);
  7461. module_exit(fusion_exit);