mptbase.c 181 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479
  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 Logic PCI chip/adapter(s)
  6. * running LSI Logic Fusion MPT (Message Passing Technology) firmware.
  7. *
  8. * Copyright (c) 1999-2005 LSI Logic Corporation
  9. * (mailto:mpt_linux_developer@lsil.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/slab.h>
  49. #include <linux/types.h>
  50. #include <linux/pci.h>
  51. #include <linux/kdev_t.h>
  52. #include <linux/blkdev.h>
  53. #include <linux/delay.h>
  54. #include <linux/interrupt.h> /* needed for in_interrupt() proto */
  55. #include <linux/dma-mapping.h>
  56. #include <asm/io.h>
  57. #ifdef CONFIG_MTRR
  58. #include <asm/mtrr.h>
  59. #endif
  60. #include "mptbase.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. /*
  69. * cmd line parameters
  70. */
  71. static int mpt_msi_enable;
  72. module_param(mpt_msi_enable, int, 0);
  73. MODULE_PARM_DESC(mpt_msi_enable, " MSI Support Enable (default=0)");
  74. #ifdef MFCNT
  75. static int mfcounter = 0;
  76. #define PRINT_MF_COUNT 20000
  77. #endif
  78. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  79. /*
  80. * Public data...
  81. */
  82. int mpt_lan_index = -1;
  83. int mpt_stm_index = -1;
  84. struct proc_dir_entry *mpt_proc_root_dir;
  85. #define WHOINIT_UNKNOWN 0xAA
  86. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  87. /*
  88. * Private data...
  89. */
  90. /* Adapter link list */
  91. LIST_HEAD(ioc_list);
  92. /* Callback lookup table */
  93. static MPT_CALLBACK MptCallbacks[MPT_MAX_PROTOCOL_DRIVERS];
  94. /* Protocol driver class lookup table */
  95. static int MptDriverClass[MPT_MAX_PROTOCOL_DRIVERS];
  96. /* Event handler lookup table */
  97. static MPT_EVHANDLER MptEvHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  98. /* Reset handler lookup table */
  99. static MPT_RESETHANDLER MptResetHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  100. static struct mpt_pci_driver *MptDeviceDriverHandlers[MPT_MAX_PROTOCOL_DRIVERS];
  101. static int mpt_base_index = -1;
  102. static int last_drv_idx = -1;
  103. static DECLARE_WAIT_QUEUE_HEAD(mpt_waitq);
  104. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  105. /*
  106. * Forward protos...
  107. */
  108. static irqreturn_t mpt_interrupt(int irq, void *bus_id);
  109. static int mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *req, MPT_FRAME_HDR *reply);
  110. static int mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes,
  111. u32 *req, int replyBytes, u16 *u16reply, int maxwait,
  112. int sleepFlag);
  113. static int mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag);
  114. static void mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev);
  115. static void mpt_adapter_disable(MPT_ADAPTER *ioc);
  116. static void mpt_adapter_dispose(MPT_ADAPTER *ioc);
  117. static void MptDisplayIocCapabilities(MPT_ADAPTER *ioc);
  118. static int MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag);
  119. static int GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason);
  120. static int GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  121. static int SendIocInit(MPT_ADAPTER *ioc, int sleepFlag);
  122. static int SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag);
  123. static int mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag);
  124. static int mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag);
  125. static int mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  126. static int KickStart(MPT_ADAPTER *ioc, int ignore, int sleepFlag);
  127. static int SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag);
  128. static int PrimeIocFifos(MPT_ADAPTER *ioc);
  129. static int WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  130. static int WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  131. static int WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag);
  132. static int GetLanConfigPages(MPT_ADAPTER *ioc);
  133. static int GetIoUnitPage2(MPT_ADAPTER *ioc);
  134. int mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode);
  135. static int mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum);
  136. static int mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum);
  137. static void mpt_read_ioc_pg_1(MPT_ADAPTER *ioc);
  138. static void mpt_read_ioc_pg_4(MPT_ADAPTER *ioc);
  139. static void mpt_timer_expired(unsigned long data);
  140. static int SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch);
  141. static int SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp);
  142. static int mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag);
  143. static int mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init);
  144. #ifdef CONFIG_PROC_FS
  145. static int procmpt_summary_read(char *buf, char **start, off_t offset,
  146. int request, int *eof, void *data);
  147. static int procmpt_version_read(char *buf, char **start, off_t offset,
  148. int request, int *eof, void *data);
  149. static int procmpt_iocinfo_read(char *buf, char **start, off_t offset,
  150. int request, int *eof, void *data);
  151. #endif
  152. static void mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc);
  153. //int mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag);
  154. static int ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *evReply, int *evHandlers);
  155. static void mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf);
  156. static void mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info);
  157. static void mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info);
  158. static void mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info);
  159. static int mpt_read_ioc_pg_3(MPT_ADAPTER *ioc);
  160. /* module entry point */
  161. static int __init fusion_init (void);
  162. static void __exit fusion_exit (void);
  163. #define CHIPREG_READ32(addr) readl_relaxed(addr)
  164. #define CHIPREG_READ32_dmasync(addr) readl(addr)
  165. #define CHIPREG_WRITE32(addr,val) writel(val, addr)
  166. #define CHIPREG_PIO_WRITE32(addr,val) outl(val, (unsigned long)addr)
  167. #define CHIPREG_PIO_READ32(addr) inl((unsigned long)addr)
  168. static void
  169. pci_disable_io_access(struct pci_dev *pdev)
  170. {
  171. u16 command_reg;
  172. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  173. command_reg &= ~1;
  174. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  175. }
  176. static void
  177. pci_enable_io_access(struct pci_dev *pdev)
  178. {
  179. u16 command_reg;
  180. pci_read_config_word(pdev, PCI_COMMAND, &command_reg);
  181. command_reg |= 1;
  182. pci_write_config_word(pdev, PCI_COMMAND, command_reg);
  183. }
  184. /*
  185. * Process turbo (context) reply...
  186. */
  187. static void
  188. mpt_turbo_reply(MPT_ADAPTER *ioc, u32 pa)
  189. {
  190. MPT_FRAME_HDR *mf = NULL;
  191. MPT_FRAME_HDR *mr = NULL;
  192. int req_idx = 0;
  193. int cb_idx;
  194. dmfprintk((MYIOC_s_INFO_FMT "Got TURBO reply req_idx=%08x\n",
  195. ioc->name, pa));
  196. switch (pa >> MPI_CONTEXT_REPLY_TYPE_SHIFT) {
  197. case MPI_CONTEXT_REPLY_TYPE_SCSI_INIT:
  198. req_idx = pa & 0x0000FFFF;
  199. cb_idx = (pa & 0x00FF0000) >> 16;
  200. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  201. break;
  202. case MPI_CONTEXT_REPLY_TYPE_LAN:
  203. cb_idx = mpt_lan_index;
  204. /*
  205. * Blind set of mf to NULL here was fatal
  206. * after lan_reply says "freeme"
  207. * Fix sort of combined with an optimization here;
  208. * added explicit check for case where lan_reply
  209. * was just returning 1 and doing nothing else.
  210. * For this case skip the callback, but set up
  211. * proper mf value first here:-)
  212. */
  213. if ((pa & 0x58000000) == 0x58000000) {
  214. req_idx = pa & 0x0000FFFF;
  215. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  216. mpt_free_msg_frame(ioc, mf);
  217. mb();
  218. return;
  219. break;
  220. }
  221. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  222. break;
  223. case MPI_CONTEXT_REPLY_TYPE_SCSI_TARGET:
  224. cb_idx = mpt_stm_index;
  225. mr = (MPT_FRAME_HDR *) CAST_U32_TO_PTR(pa);
  226. break;
  227. default:
  228. cb_idx = 0;
  229. BUG();
  230. }
  231. /* Check for (valid) IO callback! */
  232. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
  233. MptCallbacks[cb_idx] == NULL) {
  234. printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
  235. __FUNCTION__, ioc->name, cb_idx);
  236. goto out;
  237. }
  238. if (MptCallbacks[cb_idx](ioc, mf, mr))
  239. mpt_free_msg_frame(ioc, mf);
  240. out:
  241. mb();
  242. }
  243. static void
  244. mpt_reply(MPT_ADAPTER *ioc, u32 pa)
  245. {
  246. MPT_FRAME_HDR *mf;
  247. MPT_FRAME_HDR *mr;
  248. int req_idx;
  249. int cb_idx;
  250. int freeme;
  251. u32 reply_dma_low;
  252. u16 ioc_stat;
  253. /* non-TURBO reply! Hmmm, something may be up...
  254. * Newest turbo reply mechanism; get address
  255. * via left shift 1 (get rid of MPI_ADDRESS_REPLY_A_BIT)!
  256. */
  257. /* Map DMA address of reply header to cpu address.
  258. * pa is 32 bits - but the dma address may be 32 or 64 bits
  259. * get offset based only only the low addresses
  260. */
  261. reply_dma_low = (pa <<= 1);
  262. mr = (MPT_FRAME_HDR *)((u8 *)ioc->reply_frames +
  263. (reply_dma_low - ioc->reply_frames_low_dma));
  264. req_idx = le16_to_cpu(mr->u.frame.hwhdr.msgctxu.fld.req_idx);
  265. cb_idx = mr->u.frame.hwhdr.msgctxu.fld.cb_idx;
  266. mf = MPT_INDEX_2_MFPTR(ioc, req_idx);
  267. dmfprintk((MYIOC_s_INFO_FMT "Got non-TURBO reply=%p req_idx=%x cb_idx=%x Function=%x\n",
  268. ioc->name, mr, req_idx, cb_idx, mr->u.hdr.Function));
  269. DBG_DUMP_REPLY_FRAME(mr)
  270. /* Check/log IOC log info
  271. */
  272. ioc_stat = le16_to_cpu(mr->u.reply.IOCStatus);
  273. if (ioc_stat & MPI_IOCSTATUS_FLAG_LOG_INFO_AVAILABLE) {
  274. u32 log_info = le32_to_cpu(mr->u.reply.IOCLogInfo);
  275. if (ioc->bus_type == FC)
  276. mpt_fc_log_info(ioc, log_info);
  277. else if (ioc->bus_type == SPI)
  278. mpt_spi_log_info(ioc, log_info);
  279. else if (ioc->bus_type == SAS)
  280. mpt_sas_log_info(ioc, log_info);
  281. }
  282. if (ioc_stat & MPI_IOCSTATUS_MASK) {
  283. if (ioc->bus_type == SPI &&
  284. cb_idx != mpt_stm_index &&
  285. cb_idx != mpt_lan_index)
  286. mpt_sp_ioc_info(ioc, (u32)ioc_stat, mf);
  287. }
  288. /* Check for (valid) IO callback! */
  289. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS ||
  290. MptCallbacks[cb_idx] == NULL) {
  291. printk(MYIOC_s_WARN_FMT "%s: Invalid cb_idx (%d)!\n",
  292. __FUNCTION__, ioc->name, cb_idx);
  293. freeme = 0;
  294. goto out;
  295. }
  296. freeme = MptCallbacks[cb_idx](ioc, mf, mr);
  297. out:
  298. /* Flush (non-TURBO) reply with a WRITE! */
  299. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, pa);
  300. if (freeme)
  301. mpt_free_msg_frame(ioc, mf);
  302. mb();
  303. }
  304. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  305. /*
  306. * mpt_interrupt - MPT adapter (IOC) specific interrupt handler.
  307. * @irq: irq number (not used)
  308. * @bus_id: bus identifier cookie == pointer to MPT_ADAPTER structure
  309. *
  310. * This routine is registered via the request_irq() kernel API call,
  311. * and handles all interrupts generated from a specific MPT adapter
  312. * (also referred to as a IO Controller or IOC).
  313. * This routine must clear the interrupt from the adapter and does
  314. * so by reading the reply FIFO. Multiple replies may be processed
  315. * per single call to this routine.
  316. *
  317. * This routine handles register-level access of the adapter but
  318. * dispatches (calls) a protocol-specific callback routine to handle
  319. * the protocol-specific details of the MPT request completion.
  320. */
  321. static irqreturn_t
  322. mpt_interrupt(int irq, void *bus_id)
  323. {
  324. MPT_ADAPTER *ioc = bus_id;
  325. u32 pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
  326. if (pa == 0xFFFFFFFF)
  327. return IRQ_NONE;
  328. /*
  329. * Drain the reply FIFO!
  330. */
  331. do {
  332. if (pa & MPI_ADDRESS_REPLY_A_BIT)
  333. mpt_reply(ioc, pa);
  334. else
  335. mpt_turbo_reply(ioc, pa);
  336. pa = CHIPREG_READ32_dmasync(&ioc->chip->ReplyFifo);
  337. } while (pa != 0xFFFFFFFF);
  338. return IRQ_HANDLED;
  339. }
  340. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  341. /*
  342. * mpt_base_reply - MPT base driver's callback routine; all base driver
  343. * "internal" request/reply processing is routed here.
  344. * Currently used for EventNotification and EventAck handling.
  345. * @ioc: Pointer to MPT_ADAPTER structure
  346. * @mf: Pointer to original MPT request frame
  347. * @reply: Pointer to MPT reply frame (NULL if TurboReply)
  348. *
  349. * Returns 1 indicating original alloc'd request frame ptr
  350. * should be freed, or 0 if it shouldn't.
  351. */
  352. static int
  353. mpt_base_reply(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *reply)
  354. {
  355. int freereq = 1;
  356. u8 func;
  357. dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply() called\n", ioc->name));
  358. #if defined(MPT_DEBUG_MSG_FRAME)
  359. if (!(reply->u.hdr.MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY)) {
  360. dmfprintk((KERN_INFO MYNAM ": Original request frame (@%p) header\n", mf));
  361. DBG_DUMP_REQUEST_FRAME_HDR(mf)
  362. }
  363. #endif
  364. func = reply->u.hdr.Function;
  365. dmfprintk((MYIOC_s_INFO_FMT "mpt_base_reply, Function=%02Xh\n",
  366. ioc->name, func));
  367. if (func == MPI_FUNCTION_EVENT_NOTIFICATION) {
  368. EventNotificationReply_t *pEvReply = (EventNotificationReply_t *) reply;
  369. int evHandlers = 0;
  370. int results;
  371. results = ProcessEventNotification(ioc, pEvReply, &evHandlers);
  372. if (results != evHandlers) {
  373. /* CHECKME! Any special handling needed here? */
  374. devtverboseprintk((MYIOC_s_WARN_FMT "Called %d event handlers, sum results = %d\n",
  375. ioc->name, evHandlers, results));
  376. }
  377. /*
  378. * Hmmm... It seems that EventNotificationReply is an exception
  379. * to the rule of one reply per request.
  380. */
  381. if (pEvReply->MsgFlags & MPI_MSGFLAGS_CONTINUATION_REPLY) {
  382. freereq = 0;
  383. } else {
  384. devtverboseprintk((MYIOC_s_WARN_FMT "EVENT_NOTIFICATION reply %p returns Request frame\n",
  385. ioc->name, pEvReply));
  386. }
  387. #ifdef CONFIG_PROC_FS
  388. // LogEvent(ioc, pEvReply);
  389. #endif
  390. } else if (func == MPI_FUNCTION_EVENT_ACK) {
  391. dprintk((MYIOC_s_INFO_FMT "mpt_base_reply, EventAck reply received\n",
  392. ioc->name));
  393. } else if (func == MPI_FUNCTION_CONFIG) {
  394. CONFIGPARMS *pCfg;
  395. unsigned long flags;
  396. dcprintk((MYIOC_s_INFO_FMT "config_complete (mf=%p,mr=%p)\n",
  397. ioc->name, mf, reply));
  398. pCfg = * ((CONFIGPARMS **)((u8 *) mf + ioc->req_sz - sizeof(void *)));
  399. if (pCfg) {
  400. /* disable timer and remove from linked list */
  401. del_timer(&pCfg->timer);
  402. spin_lock_irqsave(&ioc->FreeQlock, flags);
  403. list_del(&pCfg->linkage);
  404. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  405. /*
  406. * If IOC Status is SUCCESS, save the header
  407. * and set the status code to GOOD.
  408. */
  409. pCfg->status = MPT_CONFIG_ERROR;
  410. if (reply) {
  411. ConfigReply_t *pReply = (ConfigReply_t *)reply;
  412. u16 status;
  413. status = le16_to_cpu(pReply->IOCStatus) & MPI_IOCSTATUS_MASK;
  414. dcprintk((KERN_NOTICE " IOCStatus=%04xh, IOCLogInfo=%08xh\n",
  415. status, le32_to_cpu(pReply->IOCLogInfo)));
  416. pCfg->status = status;
  417. if (status == MPI_IOCSTATUS_SUCCESS) {
  418. if ((pReply->Header.PageType &
  419. MPI_CONFIG_PAGETYPE_MASK) ==
  420. MPI_CONFIG_PAGETYPE_EXTENDED) {
  421. pCfg->cfghdr.ehdr->ExtPageLength =
  422. le16_to_cpu(pReply->ExtPageLength);
  423. pCfg->cfghdr.ehdr->ExtPageType =
  424. pReply->ExtPageType;
  425. }
  426. pCfg->cfghdr.hdr->PageVersion = pReply->Header.PageVersion;
  427. /* If this is a regular header, save PageLength. */
  428. /* LMP Do this better so not using a reserved field! */
  429. pCfg->cfghdr.hdr->PageLength = pReply->Header.PageLength;
  430. pCfg->cfghdr.hdr->PageNumber = pReply->Header.PageNumber;
  431. pCfg->cfghdr.hdr->PageType = pReply->Header.PageType;
  432. }
  433. }
  434. /*
  435. * Wake up the original calling thread
  436. */
  437. pCfg->wait_done = 1;
  438. wake_up(&mpt_waitq);
  439. }
  440. } else if (func == MPI_FUNCTION_SAS_IO_UNIT_CONTROL) {
  441. /* we should be always getting a reply frame */
  442. memcpy(ioc->persist_reply_frame, reply,
  443. min(MPT_DEFAULT_FRAME_SIZE,
  444. 4*reply->u.reply.MsgLength));
  445. del_timer(&ioc->persist_timer);
  446. ioc->persist_wait_done = 1;
  447. wake_up(&mpt_waitq);
  448. } else {
  449. printk(MYIOC_s_ERR_FMT "Unexpected msg function (=%02Xh) reply received!\n",
  450. ioc->name, func);
  451. }
  452. /*
  453. * Conditionally tell caller to free the original
  454. * EventNotification/EventAck/unexpected request frame!
  455. */
  456. return freereq;
  457. }
  458. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  459. /**
  460. * mpt_register - Register protocol-specific main callback handler.
  461. * @cbfunc: callback function pointer
  462. * @dclass: Protocol driver's class (%MPT_DRIVER_CLASS enum value)
  463. *
  464. * This routine is called by a protocol-specific driver (SCSI host,
  465. * LAN, SCSI target) to register it's reply callback routine. Each
  466. * protocol-specific driver must do this before it will be able to
  467. * use any IOC resources, such as obtaining request frames.
  468. *
  469. * NOTES: The SCSI protocol driver currently calls this routine thrice
  470. * in order to register separate callbacks; one for "normal" SCSI IO;
  471. * one for MptScsiTaskMgmt requests; one for Scan/DV requests.
  472. *
  473. * Returns a positive integer valued "handle" in the
  474. * range (and S.O.D. order) {N,...,7,6,5,...,1} if successful.
  475. * Any non-positive return value (including zero!) should be considered
  476. * an error by the caller.
  477. */
  478. int
  479. mpt_register(MPT_CALLBACK cbfunc, MPT_DRIVER_CLASS dclass)
  480. {
  481. int i;
  482. last_drv_idx = -1;
  483. /*
  484. * Search for empty callback slot in this order: {N,...,7,6,5,...,1}
  485. * (slot/handle 0 is reserved!)
  486. */
  487. for (i = MPT_MAX_PROTOCOL_DRIVERS-1; i; i--) {
  488. if (MptCallbacks[i] == NULL) {
  489. MptCallbacks[i] = cbfunc;
  490. MptDriverClass[i] = dclass;
  491. MptEvHandlers[i] = NULL;
  492. last_drv_idx = i;
  493. break;
  494. }
  495. }
  496. return last_drv_idx;
  497. }
  498. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  499. /**
  500. * mpt_deregister - Deregister a protocol drivers resources.
  501. * @cb_idx: previously registered callback handle
  502. *
  503. * Each protocol-specific driver should call this routine when it's
  504. * module is unloaded.
  505. */
  506. void
  507. mpt_deregister(int cb_idx)
  508. {
  509. if ((cb_idx >= 0) && (cb_idx < MPT_MAX_PROTOCOL_DRIVERS)) {
  510. MptCallbacks[cb_idx] = NULL;
  511. MptDriverClass[cb_idx] = MPTUNKNOWN_DRIVER;
  512. MptEvHandlers[cb_idx] = NULL;
  513. last_drv_idx++;
  514. }
  515. }
  516. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  517. /**
  518. * mpt_event_register - Register protocol-specific event callback
  519. * handler.
  520. * @cb_idx: previously registered (via mpt_register) callback handle
  521. * @ev_cbfunc: callback function
  522. *
  523. * This routine can be called by one or more protocol-specific drivers
  524. * if/when they choose to be notified of MPT events.
  525. *
  526. * Returns 0 for success.
  527. */
  528. int
  529. mpt_event_register(int cb_idx, MPT_EVHANDLER ev_cbfunc)
  530. {
  531. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  532. return -1;
  533. MptEvHandlers[cb_idx] = ev_cbfunc;
  534. return 0;
  535. }
  536. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  537. /**
  538. * mpt_event_deregister - Deregister protocol-specific event callback
  539. * handler.
  540. * @cb_idx: previously registered callback handle
  541. *
  542. * Each protocol-specific driver should call this routine
  543. * when it does not (or can no longer) handle events,
  544. * or when it's module is unloaded.
  545. */
  546. void
  547. mpt_event_deregister(int cb_idx)
  548. {
  549. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  550. return;
  551. MptEvHandlers[cb_idx] = NULL;
  552. }
  553. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  554. /**
  555. * mpt_reset_register - Register protocol-specific IOC reset handler.
  556. * @cb_idx: previously registered (via mpt_register) callback handle
  557. * @reset_func: reset function
  558. *
  559. * This routine can be called by one or more protocol-specific drivers
  560. * if/when they choose to be notified of IOC resets.
  561. *
  562. * Returns 0 for success.
  563. */
  564. int
  565. mpt_reset_register(int cb_idx, MPT_RESETHANDLER reset_func)
  566. {
  567. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  568. return -1;
  569. MptResetHandlers[cb_idx] = reset_func;
  570. return 0;
  571. }
  572. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  573. /**
  574. * mpt_reset_deregister - Deregister protocol-specific IOC reset handler.
  575. * @cb_idx: previously registered callback handle
  576. *
  577. * Each protocol-specific driver should call this routine
  578. * when it does not (or can no longer) handle IOC reset handling,
  579. * or when it's module is unloaded.
  580. */
  581. void
  582. mpt_reset_deregister(int cb_idx)
  583. {
  584. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  585. return;
  586. MptResetHandlers[cb_idx] = NULL;
  587. }
  588. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  589. /**
  590. * mpt_device_driver_register - Register device driver hooks
  591. */
  592. int
  593. mpt_device_driver_register(struct mpt_pci_driver * dd_cbfunc, int cb_idx)
  594. {
  595. MPT_ADAPTER *ioc;
  596. const struct pci_device_id *id;
  597. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  598. return -EINVAL;
  599. MptDeviceDriverHandlers[cb_idx] = dd_cbfunc;
  600. /* call per pci device probe entry point */
  601. list_for_each_entry(ioc, &ioc_list, list) {
  602. id = ioc->pcidev->driver ?
  603. ioc->pcidev->driver->id_table : NULL;
  604. if (dd_cbfunc->probe)
  605. dd_cbfunc->probe(ioc->pcidev, id);
  606. }
  607. return 0;
  608. }
  609. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  610. /**
  611. * mpt_device_driver_deregister - DeRegister device driver hooks
  612. */
  613. void
  614. mpt_device_driver_deregister(int cb_idx)
  615. {
  616. struct mpt_pci_driver *dd_cbfunc;
  617. MPT_ADAPTER *ioc;
  618. if (cb_idx < 1 || cb_idx >= MPT_MAX_PROTOCOL_DRIVERS)
  619. return;
  620. dd_cbfunc = MptDeviceDriverHandlers[cb_idx];
  621. list_for_each_entry(ioc, &ioc_list, list) {
  622. if (dd_cbfunc->remove)
  623. dd_cbfunc->remove(ioc->pcidev);
  624. }
  625. MptDeviceDriverHandlers[cb_idx] = NULL;
  626. }
  627. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  628. /**
  629. * mpt_get_msg_frame - Obtain a MPT request frame from the pool (of 1024)
  630. * allocated per MPT adapter.
  631. * @handle: Handle of registered MPT protocol driver
  632. * @ioc: Pointer to MPT adapter structure
  633. *
  634. * Returns pointer to a MPT request frame or %NULL if none are available
  635. * or IOC is not active.
  636. */
  637. MPT_FRAME_HDR*
  638. mpt_get_msg_frame(int handle, MPT_ADAPTER *ioc)
  639. {
  640. MPT_FRAME_HDR *mf;
  641. unsigned long flags;
  642. u16 req_idx; /* Request index */
  643. /* validate handle and ioc identifier */
  644. #ifdef MFCNT
  645. if (!ioc->active)
  646. printk(KERN_WARNING "IOC Not Active! mpt_get_msg_frame returning NULL!\n");
  647. #endif
  648. /* If interrupts are not attached, do not return a request frame */
  649. if (!ioc->active)
  650. return NULL;
  651. spin_lock_irqsave(&ioc->FreeQlock, flags);
  652. if (!list_empty(&ioc->FreeQ)) {
  653. int req_offset;
  654. mf = list_entry(ioc->FreeQ.next, MPT_FRAME_HDR,
  655. u.frame.linkage.list);
  656. list_del(&mf->u.frame.linkage.list);
  657. mf->u.frame.linkage.arg1 = 0;
  658. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
  659. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  660. /* u16! */
  661. req_idx = req_offset / ioc->req_sz;
  662. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  663. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  664. ioc->RequestNB[req_idx] = ioc->NB_for_64_byte_frame; /* Default, will be changed if necessary in SG generation */
  665. #ifdef MFCNT
  666. ioc->mfcnt++;
  667. #endif
  668. }
  669. else
  670. mf = NULL;
  671. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  672. #ifdef MFCNT
  673. if (mf == NULL)
  674. printk(KERN_WARNING "IOC Active. No free Msg Frames! Count 0x%x Max 0x%x\n", ioc->mfcnt, ioc->req_depth);
  675. mfcounter++;
  676. if (mfcounter == PRINT_MF_COUNT)
  677. printk(KERN_INFO "MF Count 0x%x Max 0x%x \n", ioc->mfcnt, ioc->req_depth);
  678. #endif
  679. dmfprintk((KERN_INFO MYNAM ": %s: mpt_get_msg_frame(%d,%d), got mf=%p\n",
  680. ioc->name, handle, ioc->id, mf));
  681. return mf;
  682. }
  683. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  684. /**
  685. * mpt_put_msg_frame - Send a protocol specific MPT request frame
  686. * to a IOC.
  687. * @handle: Handle of registered MPT protocol driver
  688. * @ioc: Pointer to MPT adapter structure
  689. * @mf: Pointer to MPT request frame
  690. *
  691. * This routine posts a MPT request frame to the request post FIFO of a
  692. * specific MPT adapter.
  693. */
  694. void
  695. mpt_put_msg_frame(int handle, MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  696. {
  697. u32 mf_dma_addr;
  698. int req_offset;
  699. u16 req_idx; /* Request index */
  700. /* ensure values are reset properly! */
  701. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle; /* byte */
  702. req_offset = (u8 *)mf - (u8 *)ioc->req_frames;
  703. /* u16! */
  704. req_idx = req_offset / ioc->req_sz;
  705. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(req_idx);
  706. mf->u.frame.hwhdr.msgctxu.fld.rsvd = 0;
  707. #ifdef MPT_DEBUG_MSG_FRAME
  708. {
  709. u32 *m = mf->u.frame.hwhdr.__hdr;
  710. int ii, n;
  711. printk(KERN_INFO MYNAM ": %s: About to Put msg frame @ %p:\n" KERN_INFO " ",
  712. ioc->name, m);
  713. n = ioc->req_sz/4 - 1;
  714. while (m[n] == 0)
  715. n--;
  716. for (ii=0; ii<=n; ii++) {
  717. if (ii && ((ii%8)==0))
  718. printk("\n" KERN_INFO " ");
  719. printk(" %08x", le32_to_cpu(m[ii]));
  720. }
  721. printk("\n");
  722. }
  723. #endif
  724. mf_dma_addr = (ioc->req_frames_low_dma + req_offset) | ioc->RequestNB[req_idx];
  725. dsgprintk((MYIOC_s_INFO_FMT "mf_dma_addr=%x req_idx=%d RequestNB=%x\n", ioc->name, mf_dma_addr, req_idx, ioc->RequestNB[req_idx]));
  726. CHIPREG_WRITE32(&ioc->chip->RequestFifo, mf_dma_addr);
  727. }
  728. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  729. /**
  730. * mpt_free_msg_frame - Place MPT request frame back on FreeQ.
  731. * @handle: Handle of registered MPT protocol driver
  732. * @ioc: Pointer to MPT adapter structure
  733. * @mf: Pointer to MPT request frame
  734. *
  735. * This routine places a MPT request frame back on the MPT adapter's
  736. * FreeQ.
  737. */
  738. void
  739. mpt_free_msg_frame(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf)
  740. {
  741. unsigned long flags;
  742. /* Put Request back on FreeQ! */
  743. spin_lock_irqsave(&ioc->FreeQlock, flags);
  744. mf->u.frame.linkage.arg1 = 0xdeadbeaf; /* signature to know if this mf is freed */
  745. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  746. #ifdef MFCNT
  747. ioc->mfcnt--;
  748. #endif
  749. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  750. }
  751. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  752. /**
  753. * mpt_add_sge - Place a simple SGE at address pAddr.
  754. * @pAddr: virtual address for SGE
  755. * @flagslength: SGE flags and data transfer length
  756. * @dma_addr: Physical address
  757. *
  758. * This routine places a MPT request frame back on the MPT adapter's
  759. * FreeQ.
  760. */
  761. void
  762. mpt_add_sge(char *pAddr, u32 flagslength, dma_addr_t dma_addr)
  763. {
  764. if (sizeof(dma_addr_t) == sizeof(u64)) {
  765. SGESimple64_t *pSge = (SGESimple64_t *) pAddr;
  766. u32 tmp = dma_addr & 0xFFFFFFFF;
  767. pSge->FlagsLength = cpu_to_le32(flagslength);
  768. pSge->Address.Low = cpu_to_le32(tmp);
  769. tmp = (u32) ((u64)dma_addr >> 32);
  770. pSge->Address.High = cpu_to_le32(tmp);
  771. } else {
  772. SGESimple32_t *pSge = (SGESimple32_t *) pAddr;
  773. pSge->FlagsLength = cpu_to_le32(flagslength);
  774. pSge->Address = cpu_to_le32(dma_addr);
  775. }
  776. }
  777. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  778. /**
  779. * mpt_send_handshake_request - Send MPT request via doorbell
  780. * handshake method.
  781. * @handle: Handle of registered MPT protocol driver
  782. * @ioc: Pointer to MPT adapter structure
  783. * @reqBytes: Size of the request in bytes
  784. * @req: Pointer to MPT request frame
  785. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  786. *
  787. * This routine is used exclusively to send MptScsiTaskMgmt
  788. * requests since they are required to be sent via doorbell handshake.
  789. *
  790. * NOTE: It is the callers responsibility to byte-swap fields in the
  791. * request which are greater than 1 byte in size.
  792. *
  793. * Returns 0 for success, non-zero for failure.
  794. */
  795. int
  796. mpt_send_handshake_request(int handle, MPT_ADAPTER *ioc, int reqBytes, u32 *req, int sleepFlag)
  797. {
  798. int r = 0;
  799. u8 *req_as_bytes;
  800. int ii;
  801. /* State is known to be good upon entering
  802. * this function so issue the bus reset
  803. * request.
  804. */
  805. /*
  806. * Emulate what mpt_put_msg_frame() does /wrt to sanity
  807. * setting cb_idx/req_idx. But ONLY if this request
  808. * is in proper (pre-alloc'd) request buffer range...
  809. */
  810. ii = MFPTR_2_MPT_INDEX(ioc,(MPT_FRAME_HDR*)req);
  811. if (reqBytes >= 12 && ii >= 0 && ii < ioc->req_depth) {
  812. MPT_FRAME_HDR *mf = (MPT_FRAME_HDR*)req;
  813. mf->u.frame.hwhdr.msgctxu.fld.req_idx = cpu_to_le16(ii);
  814. mf->u.frame.hwhdr.msgctxu.fld.cb_idx = handle;
  815. }
  816. /* Make sure there are no doorbells */
  817. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  818. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  819. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  820. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  821. /* Wait for IOC doorbell int */
  822. if ((ii = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0) {
  823. return ii;
  824. }
  825. /* Read doorbell and check for active bit */
  826. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  827. return -5;
  828. dhsprintk((KERN_INFO MYNAM ": %s: mpt_send_handshake_request start, WaitCnt=%d\n",
  829. ioc->name, ii));
  830. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  831. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  832. return -2;
  833. }
  834. /* Send request via doorbell handshake */
  835. req_as_bytes = (u8 *) req;
  836. for (ii = 0; ii < reqBytes/4; ii++) {
  837. u32 word;
  838. word = ((req_as_bytes[(ii*4) + 0] << 0) |
  839. (req_as_bytes[(ii*4) + 1] << 8) |
  840. (req_as_bytes[(ii*4) + 2] << 16) |
  841. (req_as_bytes[(ii*4) + 3] << 24));
  842. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  843. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  844. r = -3;
  845. break;
  846. }
  847. }
  848. if (r >= 0 && WaitForDoorbellInt(ioc, 10, sleepFlag) >= 0)
  849. r = 0;
  850. else
  851. r = -4;
  852. /* Make sure there are no doorbells */
  853. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  854. return r;
  855. }
  856. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  857. /**
  858. * mpt_host_page_access_control - provides mechanism for the host
  859. * driver to control the IOC's Host Page Buffer access.
  860. * @ioc: Pointer to MPT adapter structure
  861. * @access_control_value: define bits below
  862. *
  863. * Access Control Value - bits[15:12]
  864. * 0h Reserved
  865. * 1h Enable Access { MPI_DB_HPBAC_ENABLE_ACCESS }
  866. * 2h Disable Access { MPI_DB_HPBAC_DISABLE_ACCESS }
  867. * 3h Free Buffer { MPI_DB_HPBAC_FREE_BUFFER }
  868. *
  869. * Returns 0 for success, non-zero for failure.
  870. */
  871. static int
  872. mpt_host_page_access_control(MPT_ADAPTER *ioc, u8 access_control_value, int sleepFlag)
  873. {
  874. int r = 0;
  875. /* return if in use */
  876. if (CHIPREG_READ32(&ioc->chip->Doorbell)
  877. & MPI_DOORBELL_ACTIVE)
  878. return -1;
  879. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  880. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  881. ((MPI_FUNCTION_HOST_PAGEBUF_ACCESS_CONTROL
  882. <<MPI_DOORBELL_FUNCTION_SHIFT) |
  883. (access_control_value<<12)));
  884. /* Wait for IOC to clear Doorbell Status bit */
  885. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0) {
  886. return -2;
  887. }else
  888. return 0;
  889. }
  890. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  891. /**
  892. * mpt_host_page_alloc - allocate system memory for the fw
  893. * If we already allocated memory in past, then resend the same pointer.
  894. * ioc@: Pointer to pointer to IOC adapter
  895. * ioc_init@: Pointer to ioc init config page
  896. *
  897. * Returns 0 for success, non-zero for failure.
  898. */
  899. static int
  900. mpt_host_page_alloc(MPT_ADAPTER *ioc, pIOCInit_t ioc_init)
  901. {
  902. char *psge;
  903. int flags_length;
  904. u32 host_page_buffer_sz=0;
  905. if(!ioc->HostPageBuffer) {
  906. host_page_buffer_sz =
  907. le32_to_cpu(ioc->facts.HostPageBufferSGE.FlagsLength) & 0xFFFFFF;
  908. if(!host_page_buffer_sz)
  909. return 0; /* fw doesn't need any host buffers */
  910. /* spin till we get enough memory */
  911. while(host_page_buffer_sz > 0) {
  912. if((ioc->HostPageBuffer = pci_alloc_consistent(
  913. ioc->pcidev,
  914. host_page_buffer_sz,
  915. &ioc->HostPageBuffer_dma)) != NULL) {
  916. dinitprintk((MYIOC_s_INFO_FMT
  917. "host_page_buffer @ %p, dma @ %x, sz=%d bytes\n",
  918. ioc->name, ioc->HostPageBuffer,
  919. (u32)ioc->HostPageBuffer_dma,
  920. host_page_buffer_sz));
  921. ioc->alloc_total += host_page_buffer_sz;
  922. ioc->HostPageBuffer_sz = host_page_buffer_sz;
  923. break;
  924. }
  925. host_page_buffer_sz -= (4*1024);
  926. }
  927. }
  928. if(!ioc->HostPageBuffer) {
  929. printk(MYIOC_s_ERR_FMT
  930. "Failed to alloc memory for host_page_buffer!\n",
  931. ioc->name);
  932. return -999;
  933. }
  934. psge = (char *)&ioc_init->HostPageBufferSGE;
  935. flags_length = MPI_SGE_FLAGS_SIMPLE_ELEMENT |
  936. MPI_SGE_FLAGS_SYSTEM_ADDRESS |
  937. MPI_SGE_FLAGS_32_BIT_ADDRESSING |
  938. MPI_SGE_FLAGS_HOST_TO_IOC |
  939. MPI_SGE_FLAGS_END_OF_BUFFER;
  940. if (sizeof(dma_addr_t) == sizeof(u64)) {
  941. flags_length |= MPI_SGE_FLAGS_64_BIT_ADDRESSING;
  942. }
  943. flags_length = flags_length << MPI_SGE_FLAGS_SHIFT;
  944. flags_length |= ioc->HostPageBuffer_sz;
  945. mpt_add_sge(psge, flags_length, ioc->HostPageBuffer_dma);
  946. ioc->facts.HostPageBufferSGE = ioc_init->HostPageBufferSGE;
  947. return 0;
  948. }
  949. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  950. /**
  951. * mpt_verify_adapter - Given a unique IOC identifier, set pointer to
  952. * the associated MPT adapter structure.
  953. * @iocid: IOC unique identifier (integer)
  954. * @iocpp: Pointer to pointer to IOC adapter
  955. *
  956. * Returns iocid and sets iocpp.
  957. */
  958. int
  959. mpt_verify_adapter(int iocid, MPT_ADAPTER **iocpp)
  960. {
  961. MPT_ADAPTER *ioc;
  962. list_for_each_entry(ioc,&ioc_list,list) {
  963. if (ioc->id == iocid) {
  964. *iocpp =ioc;
  965. return iocid;
  966. }
  967. }
  968. *iocpp = NULL;
  969. return -1;
  970. }
  971. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  972. /*
  973. * mpt_attach - Install a PCI intelligent MPT adapter.
  974. * @pdev: Pointer to pci_dev structure
  975. *
  976. * This routine performs all the steps necessary to bring the IOC of
  977. * a MPT adapter to a OPERATIONAL state. This includes registering
  978. * memory regions, registering the interrupt, and allocating request
  979. * and reply memory pools.
  980. *
  981. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  982. * MPT adapter.
  983. *
  984. * Returns 0 for success, non-zero for failure.
  985. *
  986. * TODO: Add support for polled controllers
  987. */
  988. int
  989. mpt_attach(struct pci_dev *pdev, const struct pci_device_id *id)
  990. {
  991. MPT_ADAPTER *ioc;
  992. u8 __iomem *mem;
  993. unsigned long mem_phys;
  994. unsigned long port;
  995. u32 msize;
  996. u32 psize;
  997. int ii;
  998. int r = -ENODEV;
  999. u8 revision;
  1000. u8 pcixcmd;
  1001. static int mpt_ids = 0;
  1002. #ifdef CONFIG_PROC_FS
  1003. struct proc_dir_entry *dent, *ent;
  1004. #endif
  1005. if (pci_enable_device(pdev))
  1006. return r;
  1007. dinitprintk((KERN_WARNING MYNAM ": mpt_adapter_install\n"));
  1008. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  1009. dprintk((KERN_INFO MYNAM
  1010. ": 64 BIT PCI BUS DMA ADDRESSING SUPPORTED\n"));
  1011. } else if (pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  1012. printk(KERN_WARNING MYNAM ": 32 BIT PCI BUS DMA ADDRESSING NOT SUPPORTED\n");
  1013. return r;
  1014. }
  1015. if (!pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK))
  1016. dprintk((KERN_INFO MYNAM
  1017. ": Using 64 bit consistent mask\n"));
  1018. else
  1019. dprintk((KERN_INFO MYNAM
  1020. ": Not using 64 bit consistent mask\n"));
  1021. ioc = kzalloc(sizeof(MPT_ADAPTER), GFP_ATOMIC);
  1022. if (ioc == NULL) {
  1023. printk(KERN_ERR MYNAM ": ERROR - Insufficient memory to add adapter!\n");
  1024. return -ENOMEM;
  1025. }
  1026. ioc->alloc_total = sizeof(MPT_ADAPTER);
  1027. ioc->req_sz = MPT_DEFAULT_FRAME_SIZE; /* avoid div by zero! */
  1028. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  1029. ioc->pcidev = pdev;
  1030. ioc->diagPending = 0;
  1031. spin_lock_init(&ioc->diagLock);
  1032. spin_lock_init(&ioc->initializing_hba_lock);
  1033. /* Initialize the event logging.
  1034. */
  1035. ioc->eventTypes = 0; /* None */
  1036. ioc->eventContext = 0;
  1037. ioc->eventLogSize = 0;
  1038. ioc->events = NULL;
  1039. #ifdef MFCNT
  1040. ioc->mfcnt = 0;
  1041. #endif
  1042. ioc->cached_fw = NULL;
  1043. /* Initilize SCSI Config Data structure
  1044. */
  1045. memset(&ioc->spi_data, 0, sizeof(SpiCfgData));
  1046. /* Initialize the running configQ head.
  1047. */
  1048. INIT_LIST_HEAD(&ioc->configQ);
  1049. /* Initialize the fc rport list head.
  1050. */
  1051. INIT_LIST_HEAD(&ioc->fc_rports);
  1052. /* Find lookup slot. */
  1053. INIT_LIST_HEAD(&ioc->list);
  1054. ioc->id = mpt_ids++;
  1055. mem_phys = msize = 0;
  1056. port = psize = 0;
  1057. for (ii=0; ii < DEVICE_COUNT_RESOURCE; ii++) {
  1058. if (pci_resource_flags(pdev, ii) & PCI_BASE_ADDRESS_SPACE_IO) {
  1059. if (psize)
  1060. continue;
  1061. /* Get I/O space! */
  1062. port = pci_resource_start(pdev, ii);
  1063. psize = pci_resource_len(pdev,ii);
  1064. } else {
  1065. if (msize)
  1066. continue;
  1067. /* Get memmap */
  1068. mem_phys = pci_resource_start(pdev, ii);
  1069. msize = pci_resource_len(pdev,ii);
  1070. }
  1071. }
  1072. ioc->mem_size = msize;
  1073. mem = NULL;
  1074. /* Get logical ptr for PciMem0 space */
  1075. /*mem = ioremap(mem_phys, msize);*/
  1076. mem = ioremap(mem_phys, msize);
  1077. if (mem == NULL) {
  1078. printk(KERN_ERR MYNAM ": ERROR - Unable to map adapter memory!\n");
  1079. kfree(ioc);
  1080. return -EINVAL;
  1081. }
  1082. ioc->memmap = mem;
  1083. dinitprintk((KERN_INFO MYNAM ": mem = %p, mem_phys = %lx\n", mem, mem_phys));
  1084. dinitprintk((KERN_INFO MYNAM ": facts @ %p, pfacts[0] @ %p\n",
  1085. &ioc->facts, &ioc->pfacts[0]));
  1086. ioc->mem_phys = mem_phys;
  1087. ioc->chip = (SYSIF_REGS __iomem *)mem;
  1088. /* Save Port IO values in case we need to do downloadboot */
  1089. {
  1090. u8 *pmem = (u8*)port;
  1091. ioc->pio_mem_phys = port;
  1092. ioc->pio_chip = (SYSIF_REGS __iomem *)pmem;
  1093. }
  1094. if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC909) {
  1095. ioc->prod_name = "LSIFC909";
  1096. ioc->bus_type = FC;
  1097. }
  1098. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929) {
  1099. ioc->prod_name = "LSIFC929";
  1100. ioc->bus_type = FC;
  1101. }
  1102. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919) {
  1103. ioc->prod_name = "LSIFC919";
  1104. ioc->bus_type = FC;
  1105. }
  1106. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC929X) {
  1107. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1108. ioc->bus_type = FC;
  1109. if (revision < XL_929) {
  1110. ioc->prod_name = "LSIFC929X";
  1111. /* 929X Chip Fix. Set Split transactions level
  1112. * for PCIX. Set MOST bits to zero.
  1113. */
  1114. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1115. pcixcmd &= 0x8F;
  1116. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1117. } else {
  1118. ioc->prod_name = "LSIFC929XL";
  1119. /* 929XL Chip Fix. Set MMRBC to 0x08.
  1120. */
  1121. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1122. pcixcmd |= 0x08;
  1123. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1124. }
  1125. }
  1126. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC919X) {
  1127. ioc->prod_name = "LSIFC919X";
  1128. ioc->bus_type = FC;
  1129. /* 919X Chip Fix. Set Split transactions level
  1130. * for PCIX. Set MOST bits to zero.
  1131. */
  1132. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1133. pcixcmd &= 0x8F;
  1134. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1135. }
  1136. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC939X) {
  1137. ioc->prod_name = "LSIFC939X";
  1138. ioc->bus_type = FC;
  1139. ioc->errata_flag_1064 = 1;
  1140. }
  1141. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949X) {
  1142. ioc->prod_name = "LSIFC949X";
  1143. ioc->bus_type = FC;
  1144. ioc->errata_flag_1064 = 1;
  1145. }
  1146. else if (pdev->device == MPI_MANUFACTPAGE_DEVICEID_FC949E) {
  1147. ioc->prod_name = "LSIFC949E";
  1148. ioc->bus_type = FC;
  1149. }
  1150. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_53C1030) {
  1151. ioc->prod_name = "LSI53C1030";
  1152. ioc->bus_type = SPI;
  1153. /* 1030 Chip Fix. Disable Split transactions
  1154. * for PCIX. Set MOST bits to zero if Rev < C0( = 8).
  1155. */
  1156. pci_read_config_byte(pdev, PCI_CLASS_REVISION, &revision);
  1157. if (revision < C0_1030) {
  1158. pci_read_config_byte(pdev, 0x6a, &pcixcmd);
  1159. pcixcmd &= 0x8F;
  1160. pci_write_config_byte(pdev, 0x6a, pcixcmd);
  1161. }
  1162. }
  1163. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_1030_53C1035) {
  1164. ioc->prod_name = "LSI53C1035";
  1165. ioc->bus_type = SPI;
  1166. }
  1167. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064) {
  1168. ioc->prod_name = "LSISAS1064";
  1169. ioc->bus_type = SAS;
  1170. ioc->errata_flag_1064 = 1;
  1171. }
  1172. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068) {
  1173. ioc->prod_name = "LSISAS1068";
  1174. ioc->bus_type = SAS;
  1175. ioc->errata_flag_1064 = 1;
  1176. }
  1177. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1064E) {
  1178. ioc->prod_name = "LSISAS1064E";
  1179. ioc->bus_type = SAS;
  1180. }
  1181. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1068E) {
  1182. ioc->prod_name = "LSISAS1068E";
  1183. ioc->bus_type = SAS;
  1184. }
  1185. else if (pdev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
  1186. ioc->prod_name = "LSISAS1078";
  1187. ioc->bus_type = SAS;
  1188. }
  1189. if (ioc->errata_flag_1064)
  1190. pci_disable_io_access(pdev);
  1191. sprintf(ioc->name, "ioc%d", ioc->id);
  1192. spin_lock_init(&ioc->FreeQlock);
  1193. /* Disable all! */
  1194. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1195. ioc->active = 0;
  1196. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1197. /* Set lookup ptr. */
  1198. list_add_tail(&ioc->list, &ioc_list);
  1199. /* Check for "bound ports" (929, 929X, 1030, 1035) to reduce redundant resets.
  1200. */
  1201. mpt_detect_bound_ports(ioc, pdev);
  1202. if ((r = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_BRINGUP,
  1203. CAN_SLEEP)) != 0){
  1204. printk(KERN_WARNING MYNAM
  1205. ": WARNING - %s did not initialize properly! (%d)\n",
  1206. ioc->name, r);
  1207. list_del(&ioc->list);
  1208. if (ioc->alt_ioc)
  1209. ioc->alt_ioc->alt_ioc = NULL;
  1210. iounmap(mem);
  1211. kfree(ioc);
  1212. pci_set_drvdata(pdev, NULL);
  1213. return r;
  1214. }
  1215. /* call per device driver probe entry point */
  1216. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1217. if(MptDeviceDriverHandlers[ii] &&
  1218. MptDeviceDriverHandlers[ii]->probe) {
  1219. MptDeviceDriverHandlers[ii]->probe(pdev,id);
  1220. }
  1221. }
  1222. #ifdef CONFIG_PROC_FS
  1223. /*
  1224. * Create "/proc/mpt/iocN" subdirectory entry for each MPT adapter.
  1225. */
  1226. dent = proc_mkdir(ioc->name, mpt_proc_root_dir);
  1227. if (dent) {
  1228. ent = create_proc_entry("info", S_IFREG|S_IRUGO, dent);
  1229. if (ent) {
  1230. ent->read_proc = procmpt_iocinfo_read;
  1231. ent->data = ioc;
  1232. }
  1233. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, dent);
  1234. if (ent) {
  1235. ent->read_proc = procmpt_summary_read;
  1236. ent->data = ioc;
  1237. }
  1238. }
  1239. #endif
  1240. return 0;
  1241. }
  1242. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1243. /*
  1244. * mpt_detach - Remove a PCI intelligent MPT adapter.
  1245. * @pdev: Pointer to pci_dev structure
  1246. *
  1247. */
  1248. void
  1249. mpt_detach(struct pci_dev *pdev)
  1250. {
  1251. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1252. char pname[32];
  1253. int ii;
  1254. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/summary", ioc->name);
  1255. remove_proc_entry(pname, NULL);
  1256. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s/info", ioc->name);
  1257. remove_proc_entry(pname, NULL);
  1258. sprintf(pname, MPT_PROCFS_MPTBASEDIR "/%s", ioc->name);
  1259. remove_proc_entry(pname, NULL);
  1260. /* call per device driver remove entry point */
  1261. for(ii=0; ii<MPT_MAX_PROTOCOL_DRIVERS; ii++) {
  1262. if(MptDeviceDriverHandlers[ii] &&
  1263. MptDeviceDriverHandlers[ii]->remove) {
  1264. MptDeviceDriverHandlers[ii]->remove(pdev);
  1265. }
  1266. }
  1267. /* Disable interrupts! */
  1268. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1269. ioc->active = 0;
  1270. synchronize_irq(pdev->irq);
  1271. /* Clear any lingering interrupt */
  1272. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1273. CHIPREG_READ32(&ioc->chip->IntStatus);
  1274. mpt_adapter_dispose(ioc);
  1275. pci_set_drvdata(pdev, NULL);
  1276. }
  1277. /**************************************************************************
  1278. * Power Management
  1279. */
  1280. #ifdef CONFIG_PM
  1281. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1282. /*
  1283. * mpt_suspend - Fusion MPT base driver suspend routine.
  1284. *
  1285. *
  1286. */
  1287. int
  1288. mpt_suspend(struct pci_dev *pdev, pm_message_t state)
  1289. {
  1290. u32 device_state;
  1291. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1292. device_state=pci_choose_state(pdev, state);
  1293. printk(MYIOC_s_INFO_FMT
  1294. "pci-suspend: pdev=0x%p, slot=%s, Entering operating state [D%d]\n",
  1295. ioc->name, pdev, pci_name(pdev), device_state);
  1296. pci_save_state(pdev);
  1297. /* put ioc into READY_STATE */
  1298. if(SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, CAN_SLEEP)) {
  1299. printk(MYIOC_s_ERR_FMT
  1300. "pci-suspend: IOC msg unit reset failed!\n", ioc->name);
  1301. }
  1302. /* disable interrupts */
  1303. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1304. ioc->active = 0;
  1305. /* Clear any lingering interrupt */
  1306. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1307. pci_disable_device(pdev);
  1308. pci_set_power_state(pdev, device_state);
  1309. return 0;
  1310. }
  1311. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1312. /*
  1313. * mpt_resume - Fusion MPT base driver resume routine.
  1314. *
  1315. *
  1316. */
  1317. int
  1318. mpt_resume(struct pci_dev *pdev)
  1319. {
  1320. MPT_ADAPTER *ioc = pci_get_drvdata(pdev);
  1321. u32 device_state = pdev->current_state;
  1322. int recovery_state;
  1323. printk(MYIOC_s_INFO_FMT
  1324. "pci-resume: pdev=0x%p, slot=%s, Previous operating state [D%d]\n",
  1325. ioc->name, pdev, pci_name(pdev), device_state);
  1326. pci_set_power_state(pdev, 0);
  1327. pci_restore_state(pdev);
  1328. pci_enable_device(pdev);
  1329. /* enable interrupts */
  1330. CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
  1331. ioc->active = 1;
  1332. printk(MYIOC_s_INFO_FMT
  1333. "pci-resume: ioc-state=0x%x,doorbell=0x%x\n",
  1334. ioc->name,
  1335. (mpt_GetIocState(ioc, 1) >> MPI_IOC_STATE_SHIFT),
  1336. CHIPREG_READ32(&ioc->chip->Doorbell));
  1337. /* bring ioc to operational state */
  1338. if ((recovery_state = mpt_do_ioc_recovery(ioc,
  1339. MPT_HOSTEVENT_IOC_RECOVER, CAN_SLEEP)) != 0) {
  1340. printk(MYIOC_s_INFO_FMT
  1341. "pci-resume: Cannot recover, error:[%x]\n",
  1342. ioc->name, recovery_state);
  1343. } else {
  1344. printk(MYIOC_s_INFO_FMT
  1345. "pci-resume: success\n", ioc->name);
  1346. }
  1347. return 0;
  1348. }
  1349. #endif
  1350. static int
  1351. mpt_signal_reset(int index, MPT_ADAPTER *ioc, int reset_phase)
  1352. {
  1353. if ((MptDriverClass[index] == MPTSPI_DRIVER &&
  1354. ioc->bus_type != SPI) ||
  1355. (MptDriverClass[index] == MPTFC_DRIVER &&
  1356. ioc->bus_type != FC) ||
  1357. (MptDriverClass[index] == MPTSAS_DRIVER &&
  1358. ioc->bus_type != SAS))
  1359. /* make sure we only call the relevant reset handler
  1360. * for the bus */
  1361. return 0;
  1362. return (MptResetHandlers[index])(ioc, reset_phase);
  1363. }
  1364. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1365. /*
  1366. * mpt_do_ioc_recovery - Initialize or recover MPT adapter.
  1367. * @ioc: Pointer to MPT adapter structure
  1368. * @reason: Event word / reason
  1369. * @sleepFlag: Use schedule if CAN_SLEEP else use udelay.
  1370. *
  1371. * This routine performs all the steps necessary to bring the IOC
  1372. * to a OPERATIONAL state.
  1373. *
  1374. * This routine also pre-fetches the LAN MAC address of a Fibre Channel
  1375. * MPT adapter.
  1376. *
  1377. * Returns:
  1378. * 0 for success
  1379. * -1 if failed to get board READY
  1380. * -2 if READY but IOCFacts Failed
  1381. * -3 if READY but PrimeIOCFifos Failed
  1382. * -4 if READY but IOCInit Failed
  1383. */
  1384. static int
  1385. mpt_do_ioc_recovery(MPT_ADAPTER *ioc, u32 reason, int sleepFlag)
  1386. {
  1387. int hard_reset_done = 0;
  1388. int alt_ioc_ready = 0;
  1389. int hard;
  1390. int rc=0;
  1391. int ii;
  1392. int handlers;
  1393. int ret = 0;
  1394. int reset_alt_ioc_active = 0;
  1395. int irq_allocated = 0;
  1396. printk(KERN_INFO MYNAM ": Initiating %s %s\n",
  1397. ioc->name, reason==MPT_HOSTEVENT_IOC_BRINGUP ? "bringup" : "recovery");
  1398. /* Disable reply interrupts (also blocks FreeQ) */
  1399. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1400. ioc->active = 0;
  1401. if (ioc->alt_ioc) {
  1402. if (ioc->alt_ioc->active)
  1403. reset_alt_ioc_active = 1;
  1404. /* Disable alt-IOC's reply interrupts (and FreeQ) for a bit ... */
  1405. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, 0xFFFFFFFF);
  1406. ioc->alt_ioc->active = 0;
  1407. }
  1408. hard = 1;
  1409. if (reason == MPT_HOSTEVENT_IOC_BRINGUP)
  1410. hard = 0;
  1411. if ((hard_reset_done = MakeIocReady(ioc, hard, sleepFlag)) < 0) {
  1412. if (hard_reset_done == -4) {
  1413. printk(KERN_WARNING MYNAM ": %s Owned by PEER..skipping!\n",
  1414. ioc->name);
  1415. if (reset_alt_ioc_active && ioc->alt_ioc) {
  1416. /* (re)Enable alt-IOC! (reply interrupt, FreeQ) */
  1417. dprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
  1418. ioc->alt_ioc->name));
  1419. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
  1420. ioc->alt_ioc->active = 1;
  1421. }
  1422. } else {
  1423. printk(KERN_WARNING MYNAM ": %s NOT READY WARNING!\n",
  1424. ioc->name);
  1425. }
  1426. return -1;
  1427. }
  1428. /* hard_reset_done = 0 if a soft reset was performed
  1429. * and 1 if a hard reset was performed.
  1430. */
  1431. if (hard_reset_done && reset_alt_ioc_active && ioc->alt_ioc) {
  1432. if ((rc = MakeIocReady(ioc->alt_ioc, 0, sleepFlag)) == 0)
  1433. alt_ioc_ready = 1;
  1434. else
  1435. printk(KERN_WARNING MYNAM
  1436. ": alt-%s: Not ready WARNING!\n",
  1437. ioc->alt_ioc->name);
  1438. }
  1439. for (ii=0; ii<5; ii++) {
  1440. /* Get IOC facts! Allow 5 retries */
  1441. if ((rc = GetIocFacts(ioc, sleepFlag, reason)) == 0)
  1442. break;
  1443. }
  1444. if (ii == 5) {
  1445. dinitprintk((MYIOC_s_INFO_FMT "Retry IocFacts failed rc=%x\n", ioc->name, rc));
  1446. ret = -2;
  1447. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1448. MptDisplayIocCapabilities(ioc);
  1449. }
  1450. if (alt_ioc_ready) {
  1451. if ((rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason)) != 0) {
  1452. dinitprintk((MYIOC_s_INFO_FMT "Initial Alt IocFacts failed rc=%x\n", ioc->name, rc));
  1453. /* Retry - alt IOC was initialized once
  1454. */
  1455. rc = GetIocFacts(ioc->alt_ioc, sleepFlag, reason);
  1456. }
  1457. if (rc) {
  1458. dinitprintk((MYIOC_s_INFO_FMT "Retry Alt IocFacts failed rc=%x\n", ioc->name, rc));
  1459. alt_ioc_ready = 0;
  1460. reset_alt_ioc_active = 0;
  1461. } else if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  1462. MptDisplayIocCapabilities(ioc->alt_ioc);
  1463. }
  1464. }
  1465. /*
  1466. * Device is reset now. It must have de-asserted the interrupt line
  1467. * (if it was asserted) and it should be safe to register for the
  1468. * interrupt now.
  1469. */
  1470. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  1471. ioc->pci_irq = -1;
  1472. if (ioc->pcidev->irq) {
  1473. if (mpt_msi_enable && !pci_enable_msi(ioc->pcidev))
  1474. printk(MYIOC_s_INFO_FMT "PCI-MSI enabled\n",
  1475. ioc->name);
  1476. rc = request_irq(ioc->pcidev->irq, mpt_interrupt,
  1477. IRQF_SHARED, ioc->name, ioc);
  1478. if (rc < 0) {
  1479. printk(MYIOC_s_ERR_FMT "Unable to allocate "
  1480. "interrupt %d!\n", ioc->name,
  1481. ioc->pcidev->irq);
  1482. if (mpt_msi_enable)
  1483. pci_disable_msi(ioc->pcidev);
  1484. return -EBUSY;
  1485. }
  1486. irq_allocated = 1;
  1487. ioc->pci_irq = ioc->pcidev->irq;
  1488. pci_set_master(ioc->pcidev); /* ?? */
  1489. pci_set_drvdata(ioc->pcidev, ioc);
  1490. dprintk((KERN_INFO MYNAM ": %s installed at interrupt "
  1491. "%d\n", ioc->name, ioc->pcidev->irq));
  1492. }
  1493. }
  1494. /* Prime reply & request queues!
  1495. * (mucho alloc's) Must be done prior to
  1496. * init as upper addresses are needed for init.
  1497. * If fails, continue with alt-ioc processing
  1498. */
  1499. if ((ret == 0) && ((rc = PrimeIocFifos(ioc)) != 0))
  1500. ret = -3;
  1501. /* May need to check/upload firmware & data here!
  1502. * If fails, continue with alt-ioc processing
  1503. */
  1504. if ((ret == 0) && ((rc = SendIocInit(ioc, sleepFlag)) != 0))
  1505. ret = -4;
  1506. // NEW!
  1507. if (alt_ioc_ready && ((rc = PrimeIocFifos(ioc->alt_ioc)) != 0)) {
  1508. printk(KERN_WARNING MYNAM ": alt-%s: (%d) FIFO mgmt alloc WARNING!\n",
  1509. ioc->alt_ioc->name, rc);
  1510. alt_ioc_ready = 0;
  1511. reset_alt_ioc_active = 0;
  1512. }
  1513. if (alt_ioc_ready) {
  1514. if ((rc = SendIocInit(ioc->alt_ioc, sleepFlag)) != 0) {
  1515. alt_ioc_ready = 0;
  1516. reset_alt_ioc_active = 0;
  1517. printk(KERN_WARNING MYNAM
  1518. ": alt-%s: (%d) init failure WARNING!\n",
  1519. ioc->alt_ioc->name, rc);
  1520. }
  1521. }
  1522. if (reason == MPT_HOSTEVENT_IOC_BRINGUP){
  1523. if (ioc->upload_fw) {
  1524. ddlprintk((MYIOC_s_INFO_FMT
  1525. "firmware upload required!\n", ioc->name));
  1526. /* Controller is not operational, cannot do upload
  1527. */
  1528. if (ret == 0) {
  1529. rc = mpt_do_upload(ioc, sleepFlag);
  1530. if (rc == 0) {
  1531. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  1532. /*
  1533. * Maintain only one pointer to FW memory
  1534. * so there will not be two attempt to
  1535. * downloadboot onboard dual function
  1536. * chips (mpt_adapter_disable,
  1537. * mpt_diag_reset)
  1538. */
  1539. ddlprintk((MYIOC_s_INFO_FMT ": mpt_upload: alt_%s has cached_fw=%p \n",
  1540. ioc->name, ioc->alt_ioc->name, ioc->alt_ioc->cached_fw));
  1541. ioc->alt_ioc->cached_fw = NULL;
  1542. }
  1543. } else {
  1544. printk(KERN_WARNING MYNAM ": firmware upload failure!\n");
  1545. ret = -5;
  1546. }
  1547. }
  1548. }
  1549. }
  1550. if (ret == 0) {
  1551. /* Enable! (reply interrupt) */
  1552. CHIPREG_WRITE32(&ioc->chip->IntMask, MPI_HIM_DIM);
  1553. ioc->active = 1;
  1554. }
  1555. if (reset_alt_ioc_active && ioc->alt_ioc) {
  1556. /* (re)Enable alt-IOC! (reply interrupt) */
  1557. dinitprintk((KERN_INFO MYNAM ": alt-%s reply irq re-enabled\n",
  1558. ioc->alt_ioc->name));
  1559. CHIPREG_WRITE32(&ioc->alt_ioc->chip->IntMask, MPI_HIM_DIM);
  1560. ioc->alt_ioc->active = 1;
  1561. }
  1562. /* Enable MPT base driver management of EventNotification
  1563. * and EventAck handling.
  1564. */
  1565. if ((ret == 0) && (!ioc->facts.EventState))
  1566. (void) SendEventNotification(ioc, 1); /* 1=Enable EventNotification */
  1567. if (ioc->alt_ioc && alt_ioc_ready && !ioc->alt_ioc->facts.EventState)
  1568. (void) SendEventNotification(ioc->alt_ioc, 1); /* 1=Enable EventNotification */
  1569. /* Add additional "reason" check before call to GetLanConfigPages
  1570. * (combined with GetIoUnitPage2 call). This prevents a somewhat
  1571. * recursive scenario; GetLanConfigPages times out, timer expired
  1572. * routine calls HardResetHandler, which calls into here again,
  1573. * and we try GetLanConfigPages again...
  1574. */
  1575. if ((ret == 0) && (reason == MPT_HOSTEVENT_IOC_BRINGUP)) {
  1576. if (ioc->bus_type == SAS) {
  1577. /* clear persistency table */
  1578. if(ioc->facts.IOCExceptions &
  1579. MPI_IOCFACTS_EXCEPT_PERSISTENT_TABLE_FULL) {
  1580. ret = mptbase_sas_persist_operation(ioc,
  1581. MPI_SAS_OP_CLEAR_NOT_PRESENT);
  1582. if(ret != 0)
  1583. goto out;
  1584. }
  1585. /* Find IM volumes
  1586. */
  1587. mpt_findImVolumes(ioc);
  1588. } else if (ioc->bus_type == FC) {
  1589. if ((ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) &&
  1590. (ioc->lan_cnfg_page0.Header.PageLength == 0)) {
  1591. /*
  1592. * Pre-fetch the ports LAN MAC address!
  1593. * (LANPage1_t stuff)
  1594. */
  1595. (void) GetLanConfigPages(ioc);
  1596. #ifdef MPT_DEBUG
  1597. {
  1598. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  1599. dprintk((MYIOC_s_INFO_FMT "LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  1600. ioc->name, a[5], a[4], a[3], a[2], a[1], a[0] ));
  1601. }
  1602. #endif
  1603. }
  1604. } else {
  1605. /* Get NVRAM and adapter maximums from SPP 0 and 2
  1606. */
  1607. mpt_GetScsiPortSettings(ioc, 0);
  1608. /* Get version and length of SDP 1
  1609. */
  1610. mpt_readScsiDevicePageHeaders(ioc, 0);
  1611. /* Find IM volumes
  1612. */
  1613. if (ioc->facts.MsgVersion >= MPI_VERSION_01_02)
  1614. mpt_findImVolumes(ioc);
  1615. /* Check, and possibly reset, the coalescing value
  1616. */
  1617. mpt_read_ioc_pg_1(ioc);
  1618. mpt_read_ioc_pg_4(ioc);
  1619. }
  1620. GetIoUnitPage2(ioc);
  1621. }
  1622. /*
  1623. * Call each currently registered protocol IOC reset handler
  1624. * with post-reset indication.
  1625. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  1626. * MptResetHandlers[] registered yet.
  1627. */
  1628. if (hard_reset_done) {
  1629. rc = handlers = 0;
  1630. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  1631. if ((ret == 0) && MptResetHandlers[ii]) {
  1632. dprintk((MYIOC_s_INFO_FMT "Calling IOC post_reset handler #%d\n",
  1633. ioc->name, ii));
  1634. rc += mpt_signal_reset(ii, ioc, MPT_IOC_POST_RESET);
  1635. handlers++;
  1636. }
  1637. if (alt_ioc_ready && MptResetHandlers[ii]) {
  1638. drsprintk((MYIOC_s_INFO_FMT "Calling alt-%s post_reset handler #%d\n",
  1639. ioc->name, ioc->alt_ioc->name, ii));
  1640. rc += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_POST_RESET);
  1641. handlers++;
  1642. }
  1643. }
  1644. /* FIXME? Examine results here? */
  1645. }
  1646. out:
  1647. if ((ret != 0) && irq_allocated) {
  1648. free_irq(ioc->pci_irq, ioc);
  1649. if (mpt_msi_enable)
  1650. pci_disable_msi(ioc->pcidev);
  1651. }
  1652. return ret;
  1653. }
  1654. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1655. /*
  1656. * mpt_detect_bound_ports - Search for PCI bus/dev_function
  1657. * which matches PCI bus/dev_function (+/-1) for newly discovered 929,
  1658. * 929X, 1030 or 1035.
  1659. * @ioc: Pointer to MPT adapter structure
  1660. * @pdev: Pointer to (struct pci_dev) structure
  1661. *
  1662. * If match on PCI dev_function +/-1 is found, bind the two MPT adapters
  1663. * using alt_ioc pointer fields in their %MPT_ADAPTER structures.
  1664. */
  1665. static void
  1666. mpt_detect_bound_ports(MPT_ADAPTER *ioc, struct pci_dev *pdev)
  1667. {
  1668. struct pci_dev *peer=NULL;
  1669. unsigned int slot = PCI_SLOT(pdev->devfn);
  1670. unsigned int func = PCI_FUNC(pdev->devfn);
  1671. MPT_ADAPTER *ioc_srch;
  1672. dprintk((MYIOC_s_INFO_FMT "PCI device %s devfn=%x/%x,"
  1673. " searching for devfn match on %x or %x\n",
  1674. ioc->name, pci_name(pdev), pdev->bus->number,
  1675. pdev->devfn, func-1, func+1));
  1676. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func-1));
  1677. if (!peer) {
  1678. peer = pci_get_slot(pdev->bus, PCI_DEVFN(slot,func+1));
  1679. if (!peer)
  1680. return;
  1681. }
  1682. list_for_each_entry(ioc_srch, &ioc_list, list) {
  1683. struct pci_dev *_pcidev = ioc_srch->pcidev;
  1684. if (_pcidev == peer) {
  1685. /* Paranoia checks */
  1686. if (ioc->alt_ioc != NULL) {
  1687. printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
  1688. ioc->name, ioc->alt_ioc->name);
  1689. break;
  1690. } else if (ioc_srch->alt_ioc != NULL) {
  1691. printk(KERN_WARNING MYNAM ": Oops, already bound (%s <==> %s)!\n",
  1692. ioc_srch->name, ioc_srch->alt_ioc->name);
  1693. break;
  1694. }
  1695. dprintk((KERN_INFO MYNAM ": FOUND! binding %s <==> %s\n",
  1696. ioc->name, ioc_srch->name));
  1697. ioc_srch->alt_ioc = ioc;
  1698. ioc->alt_ioc = ioc_srch;
  1699. }
  1700. }
  1701. pci_dev_put(peer);
  1702. }
  1703. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1704. /*
  1705. * mpt_adapter_disable - Disable misbehaving MPT adapter.
  1706. * @this: Pointer to MPT adapter structure
  1707. */
  1708. static void
  1709. mpt_adapter_disable(MPT_ADAPTER *ioc)
  1710. {
  1711. int sz;
  1712. int ret;
  1713. if (ioc->cached_fw != NULL) {
  1714. ddlprintk((KERN_INFO MYNAM ": mpt_adapter_disable: Pushing FW onto adapter\n"));
  1715. if ((ret = mpt_downloadboot(ioc, (MpiFwHeader_t *)ioc->cached_fw, NO_SLEEP)) < 0) {
  1716. printk(KERN_WARNING MYNAM
  1717. ": firmware downloadboot failure (%d)!\n", ret);
  1718. }
  1719. }
  1720. /* Disable adapter interrupts! */
  1721. CHIPREG_WRITE32(&ioc->chip->IntMask, 0xFFFFFFFF);
  1722. ioc->active = 0;
  1723. /* Clear any lingering interrupt */
  1724. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  1725. if (ioc->alloc != NULL) {
  1726. sz = ioc->alloc_sz;
  1727. dexitprintk((KERN_INFO MYNAM ": %s.free @ %p, sz=%d bytes\n",
  1728. ioc->name, ioc->alloc, ioc->alloc_sz));
  1729. pci_free_consistent(ioc->pcidev, sz,
  1730. ioc->alloc, ioc->alloc_dma);
  1731. ioc->reply_frames = NULL;
  1732. ioc->req_frames = NULL;
  1733. ioc->alloc = NULL;
  1734. ioc->alloc_total -= sz;
  1735. }
  1736. if (ioc->sense_buf_pool != NULL) {
  1737. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  1738. pci_free_consistent(ioc->pcidev, sz,
  1739. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  1740. ioc->sense_buf_pool = NULL;
  1741. ioc->alloc_total -= sz;
  1742. }
  1743. if (ioc->events != NULL){
  1744. sz = MPTCTL_EVENT_LOG_SIZE * sizeof(MPT_IOCTL_EVENTS);
  1745. kfree(ioc->events);
  1746. ioc->events = NULL;
  1747. ioc->alloc_total -= sz;
  1748. }
  1749. if (ioc->cached_fw != NULL) {
  1750. sz = ioc->facts.FWImageSize;
  1751. pci_free_consistent(ioc->pcidev, sz,
  1752. ioc->cached_fw, ioc->cached_fw_dma);
  1753. ioc->cached_fw = NULL;
  1754. ioc->alloc_total -= sz;
  1755. }
  1756. kfree(ioc->spi_data.nvram);
  1757. kfree(ioc->raid_data.pIocPg3);
  1758. ioc->spi_data.nvram = NULL;
  1759. ioc->raid_data.pIocPg3 = NULL;
  1760. if (ioc->spi_data.pIocPg4 != NULL) {
  1761. sz = ioc->spi_data.IocPg4Sz;
  1762. pci_free_consistent(ioc->pcidev, sz,
  1763. ioc->spi_data.pIocPg4,
  1764. ioc->spi_data.IocPg4_dma);
  1765. ioc->spi_data.pIocPg4 = NULL;
  1766. ioc->alloc_total -= sz;
  1767. }
  1768. if (ioc->ReqToChain != NULL) {
  1769. kfree(ioc->ReqToChain);
  1770. kfree(ioc->RequestNB);
  1771. ioc->ReqToChain = NULL;
  1772. }
  1773. kfree(ioc->ChainToChain);
  1774. ioc->ChainToChain = NULL;
  1775. if (ioc->HostPageBuffer != NULL) {
  1776. if((ret = mpt_host_page_access_control(ioc,
  1777. MPI_DB_HPBAC_FREE_BUFFER, NO_SLEEP)) != 0) {
  1778. printk(KERN_ERR MYNAM
  1779. ": %s: host page buffers free failed (%d)!\n",
  1780. __FUNCTION__, ret);
  1781. }
  1782. dexitprintk((KERN_INFO MYNAM ": %s HostPageBuffer free @ %p, sz=%d bytes\n",
  1783. ioc->name, ioc->HostPageBuffer, ioc->HostPageBuffer_sz));
  1784. pci_free_consistent(ioc->pcidev, ioc->HostPageBuffer_sz,
  1785. ioc->HostPageBuffer,
  1786. ioc->HostPageBuffer_dma);
  1787. ioc->HostPageBuffer = NULL;
  1788. ioc->HostPageBuffer_sz = 0;
  1789. ioc->alloc_total -= ioc->HostPageBuffer_sz;
  1790. }
  1791. }
  1792. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1793. /*
  1794. * mpt_adapter_dispose - Free all resources associated with a MPT
  1795. * adapter.
  1796. * @ioc: Pointer to MPT adapter structure
  1797. *
  1798. * This routine unregisters h/w resources and frees all alloc'd memory
  1799. * associated with a MPT adapter structure.
  1800. */
  1801. static void
  1802. mpt_adapter_dispose(MPT_ADAPTER *ioc)
  1803. {
  1804. int sz_first, sz_last;
  1805. if (ioc == NULL)
  1806. return;
  1807. sz_first = ioc->alloc_total;
  1808. mpt_adapter_disable(ioc);
  1809. if (ioc->pci_irq != -1) {
  1810. free_irq(ioc->pci_irq, ioc);
  1811. if (mpt_msi_enable)
  1812. pci_disable_msi(ioc->pcidev);
  1813. ioc->pci_irq = -1;
  1814. }
  1815. if (ioc->memmap != NULL) {
  1816. iounmap(ioc->memmap);
  1817. ioc->memmap = NULL;
  1818. }
  1819. #if defined(CONFIG_MTRR) && 0
  1820. if (ioc->mtrr_reg > 0) {
  1821. mtrr_del(ioc->mtrr_reg, 0, 0);
  1822. dprintk((KERN_INFO MYNAM ": %s: MTRR region de-registered\n", ioc->name));
  1823. }
  1824. #endif
  1825. /* Zap the adapter lookup ptr! */
  1826. list_del(&ioc->list);
  1827. sz_last = ioc->alloc_total;
  1828. dprintk((KERN_INFO MYNAM ": %s: free'd %d of %d bytes\n",
  1829. ioc->name, sz_first-sz_last+(int)sizeof(*ioc), sz_first));
  1830. if (ioc->alt_ioc)
  1831. ioc->alt_ioc->alt_ioc = NULL;
  1832. kfree(ioc);
  1833. }
  1834. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1835. /*
  1836. * MptDisplayIocCapabilities - Disply IOC's capacilities.
  1837. * @ioc: Pointer to MPT adapter structure
  1838. */
  1839. static void
  1840. MptDisplayIocCapabilities(MPT_ADAPTER *ioc)
  1841. {
  1842. int i = 0;
  1843. printk(KERN_INFO "%s: ", ioc->name);
  1844. if (ioc->prod_name && strlen(ioc->prod_name) > 3)
  1845. printk("%s: ", ioc->prod_name+3);
  1846. printk("Capabilities={");
  1847. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_INITIATOR) {
  1848. printk("Initiator");
  1849. i++;
  1850. }
  1851. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1852. printk("%sTarget", i ? "," : "");
  1853. i++;
  1854. }
  1855. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  1856. printk("%sLAN", i ? "," : "");
  1857. i++;
  1858. }
  1859. #if 0
  1860. /*
  1861. * This would probably evoke more questions than it's worth
  1862. */
  1863. if (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_TARGET) {
  1864. printk("%sLogBusAddr", i ? "," : "");
  1865. i++;
  1866. }
  1867. #endif
  1868. printk("}\n");
  1869. }
  1870. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1871. /*
  1872. * MakeIocReady - Get IOC to a READY state, using KickStart if needed.
  1873. * @ioc: Pointer to MPT_ADAPTER structure
  1874. * @force: Force hard KickStart of IOC
  1875. * @sleepFlag: Specifies whether the process can sleep
  1876. *
  1877. * Returns:
  1878. * 1 - DIAG reset and READY
  1879. * 0 - READY initially OR soft reset and READY
  1880. * -1 - Any failure on KickStart
  1881. * -2 - Msg Unit Reset Failed
  1882. * -3 - IO Unit Reset Failed
  1883. * -4 - IOC owned by a PEER
  1884. */
  1885. static int
  1886. MakeIocReady(MPT_ADAPTER *ioc, int force, int sleepFlag)
  1887. {
  1888. u32 ioc_state;
  1889. int statefault = 0;
  1890. int cntdn;
  1891. int hard_reset_done = 0;
  1892. int r;
  1893. int ii;
  1894. int whoinit;
  1895. /* Get current [raw] IOC state */
  1896. ioc_state = mpt_GetIocState(ioc, 0);
  1897. dhsprintk((KERN_INFO MYNAM "::MakeIocReady, %s [raw] state=%08x\n", ioc->name, ioc_state));
  1898. /*
  1899. * Check to see if IOC got left/stuck in doorbell handshake
  1900. * grip of death. If so, hard reset the IOC.
  1901. */
  1902. if (ioc_state & MPI_DOORBELL_ACTIVE) {
  1903. statefault = 1;
  1904. printk(MYIOC_s_WARN_FMT "Unexpected doorbell active!\n",
  1905. ioc->name);
  1906. }
  1907. /* Is it already READY? */
  1908. if (!statefault && (ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_READY)
  1909. return 0;
  1910. /*
  1911. * Check to see if IOC is in FAULT state.
  1912. */
  1913. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_FAULT) {
  1914. statefault = 2;
  1915. printk(MYIOC_s_WARN_FMT "IOC is in FAULT state!!!\n",
  1916. ioc->name);
  1917. printk(KERN_WARNING " FAULT code = %04xh\n",
  1918. ioc_state & MPI_DOORBELL_DATA_MASK);
  1919. }
  1920. /*
  1921. * Hmmm... Did it get left operational?
  1922. */
  1923. if ((ioc_state & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_OPERATIONAL) {
  1924. dinitprintk((MYIOC_s_INFO_FMT "IOC operational unexpected\n",
  1925. ioc->name));
  1926. /* Check WhoInit.
  1927. * If PCI Peer, exit.
  1928. * Else, if no fault conditions are present, issue a MessageUnitReset
  1929. * Else, fall through to KickStart case
  1930. */
  1931. whoinit = (ioc_state & MPI_DOORBELL_WHO_INIT_MASK) >> MPI_DOORBELL_WHO_INIT_SHIFT;
  1932. dinitprintk((KERN_INFO MYNAM
  1933. ": whoinit 0x%x statefault %d force %d\n",
  1934. whoinit, statefault, force));
  1935. if (whoinit == MPI_WHOINIT_PCI_PEER)
  1936. return -4;
  1937. else {
  1938. if ((statefault == 0 ) && (force == 0)) {
  1939. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) == 0)
  1940. return 0;
  1941. }
  1942. statefault = 3;
  1943. }
  1944. }
  1945. hard_reset_done = KickStart(ioc, statefault||force, sleepFlag);
  1946. if (hard_reset_done < 0)
  1947. return -1;
  1948. /*
  1949. * Loop here waiting for IOC to come READY.
  1950. */
  1951. ii = 0;
  1952. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 5; /* 5 seconds */
  1953. while ((ioc_state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  1954. if (ioc_state == MPI_IOC_STATE_OPERATIONAL) {
  1955. /*
  1956. * BIOS or previous driver load left IOC in OP state.
  1957. * Reset messaging FIFOs.
  1958. */
  1959. if ((r = SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag)) != 0) {
  1960. printk(MYIOC_s_ERR_FMT "IOC msg unit reset failed!\n", ioc->name);
  1961. return -2;
  1962. }
  1963. } else if (ioc_state == MPI_IOC_STATE_RESET) {
  1964. /*
  1965. * Something is wrong. Try to get IOC back
  1966. * to a known state.
  1967. */
  1968. if ((r = SendIocReset(ioc, MPI_FUNCTION_IO_UNIT_RESET, sleepFlag)) != 0) {
  1969. printk(MYIOC_s_ERR_FMT "IO unit reset failed!\n", ioc->name);
  1970. return -3;
  1971. }
  1972. }
  1973. ii++; cntdn--;
  1974. if (!cntdn) {
  1975. printk(MYIOC_s_ERR_FMT "Wait IOC_READY state timeout(%d)!\n",
  1976. ioc->name, (int)((ii+5)/HZ));
  1977. return -ETIME;
  1978. }
  1979. if (sleepFlag == CAN_SLEEP) {
  1980. msleep(1);
  1981. } else {
  1982. mdelay (1); /* 1 msec delay */
  1983. }
  1984. }
  1985. if (statefault < 3) {
  1986. printk(MYIOC_s_INFO_FMT "Recovered from %s\n",
  1987. ioc->name,
  1988. statefault==1 ? "stuck handshake" : "IOC FAULT");
  1989. }
  1990. return hard_reset_done;
  1991. }
  1992. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  1993. /*
  1994. * mpt_GetIocState - Get the current state of a MPT adapter.
  1995. * @ioc: Pointer to MPT_ADAPTER structure
  1996. * @cooked: Request raw or cooked IOC state
  1997. *
  1998. * Returns all IOC Doorbell register bits if cooked==0, else just the
  1999. * Doorbell bits in MPI_IOC_STATE_MASK.
  2000. */
  2001. u32
  2002. mpt_GetIocState(MPT_ADAPTER *ioc, int cooked)
  2003. {
  2004. u32 s, sc;
  2005. /* Get! */
  2006. s = CHIPREG_READ32(&ioc->chip->Doorbell);
  2007. // dprintk((MYIOC_s_INFO_FMT "raw state = %08x\n", ioc->name, s));
  2008. sc = s & MPI_IOC_STATE_MASK;
  2009. /* Save! */
  2010. ioc->last_state = sc;
  2011. return cooked ? sc : s;
  2012. }
  2013. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2014. /*
  2015. * GetIocFacts - Send IOCFacts request to MPT adapter.
  2016. * @ioc: Pointer to MPT_ADAPTER structure
  2017. * @sleepFlag: Specifies whether the process can sleep
  2018. * @reason: If recovery, only update facts.
  2019. *
  2020. * Returns 0 for success, non-zero for failure.
  2021. */
  2022. static int
  2023. GetIocFacts(MPT_ADAPTER *ioc, int sleepFlag, int reason)
  2024. {
  2025. IOCFacts_t get_facts;
  2026. IOCFactsReply_t *facts;
  2027. int r;
  2028. int req_sz;
  2029. int reply_sz;
  2030. int sz;
  2031. u32 status, vv;
  2032. u8 shiftFactor=1;
  2033. /* IOC *must* NOT be in RESET state! */
  2034. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2035. printk(KERN_ERR MYNAM ": ERROR - Can't get IOCFacts, %s NOT READY! (%08x)\n",
  2036. ioc->name,
  2037. ioc->last_state );
  2038. return -44;
  2039. }
  2040. facts = &ioc->facts;
  2041. /* Destination (reply area)... */
  2042. reply_sz = sizeof(*facts);
  2043. memset(facts, 0, reply_sz);
  2044. /* Request area (get_facts on the stack right now!) */
  2045. req_sz = sizeof(get_facts);
  2046. memset(&get_facts, 0, req_sz);
  2047. get_facts.Function = MPI_FUNCTION_IOC_FACTS;
  2048. /* Assert: All other get_facts fields are zero! */
  2049. dinitprintk((MYIOC_s_INFO_FMT
  2050. "Sending get IocFacts request req_sz=%d reply_sz=%d\n",
  2051. ioc->name, req_sz, reply_sz));
  2052. /* No non-zero fields in the get_facts request are greater than
  2053. * 1 byte in size, so we can just fire it off as is.
  2054. */
  2055. r = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_facts,
  2056. reply_sz, (u16*)facts, 5 /*seconds*/, sleepFlag);
  2057. if (r != 0)
  2058. return r;
  2059. /*
  2060. * Now byte swap (GRRR) the necessary fields before any further
  2061. * inspection of reply contents.
  2062. *
  2063. * But need to do some sanity checks on MsgLength (byte) field
  2064. * to make sure we don't zero IOC's req_sz!
  2065. */
  2066. /* Did we get a valid reply? */
  2067. if (facts->MsgLength > offsetof(IOCFactsReply_t, RequestFrameSize)/sizeof(u32)) {
  2068. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2069. /*
  2070. * If not been here, done that, save off first WhoInit value
  2071. */
  2072. if (ioc->FirstWhoInit == WHOINIT_UNKNOWN)
  2073. ioc->FirstWhoInit = facts->WhoInit;
  2074. }
  2075. facts->MsgVersion = le16_to_cpu(facts->MsgVersion);
  2076. facts->MsgContext = le32_to_cpu(facts->MsgContext);
  2077. facts->IOCExceptions = le16_to_cpu(facts->IOCExceptions);
  2078. facts->IOCStatus = le16_to_cpu(facts->IOCStatus);
  2079. facts->IOCLogInfo = le32_to_cpu(facts->IOCLogInfo);
  2080. status = le16_to_cpu(facts->IOCStatus) & MPI_IOCSTATUS_MASK;
  2081. /* CHECKME! IOCStatus, IOCLogInfo */
  2082. facts->ReplyQueueDepth = le16_to_cpu(facts->ReplyQueueDepth);
  2083. facts->RequestFrameSize = le16_to_cpu(facts->RequestFrameSize);
  2084. /*
  2085. * FC f/w version changed between 1.1 and 1.2
  2086. * Old: u16{Major(4),Minor(4),SubMinor(8)}
  2087. * New: u32{Major(8),Minor(8),Unit(8),Dev(8)}
  2088. */
  2089. if (facts->MsgVersion < 0x0102) {
  2090. /*
  2091. * Handle old FC f/w style, convert to new...
  2092. */
  2093. u16 oldv = le16_to_cpu(facts->Reserved_0101_FWVersion);
  2094. facts->FWVersion.Word =
  2095. ((oldv<<12) & 0xFF000000) |
  2096. ((oldv<<8) & 0x000FFF00);
  2097. } else
  2098. facts->FWVersion.Word = le32_to_cpu(facts->FWVersion.Word);
  2099. facts->ProductID = le16_to_cpu(facts->ProductID);
  2100. facts->CurrentHostMfaHighAddr =
  2101. le32_to_cpu(facts->CurrentHostMfaHighAddr);
  2102. facts->GlobalCredits = le16_to_cpu(facts->GlobalCredits);
  2103. facts->CurrentSenseBufferHighAddr =
  2104. le32_to_cpu(facts->CurrentSenseBufferHighAddr);
  2105. facts->CurReplyFrameSize =
  2106. le16_to_cpu(facts->CurReplyFrameSize);
  2107. facts->IOCCapabilities = le32_to_cpu(facts->IOCCapabilities);
  2108. /*
  2109. * Handle NEW (!) IOCFactsReply fields in MPI-1.01.xx
  2110. * Older MPI-1.00.xx struct had 13 dwords, and enlarged
  2111. * to 14 in MPI-1.01.0x.
  2112. */
  2113. if (facts->MsgLength >= (offsetof(IOCFactsReply_t,FWImageSize) + 7)/4 &&
  2114. facts->MsgVersion > 0x0100) {
  2115. facts->FWImageSize = le32_to_cpu(facts->FWImageSize);
  2116. }
  2117. sz = facts->FWImageSize;
  2118. if ( sz & 0x01 )
  2119. sz += 1;
  2120. if ( sz & 0x02 )
  2121. sz += 2;
  2122. facts->FWImageSize = sz;
  2123. if (!facts->RequestFrameSize) {
  2124. /* Something is wrong! */
  2125. printk(MYIOC_s_ERR_FMT "IOC reported invalid 0 request size!\n",
  2126. ioc->name);
  2127. return -55;
  2128. }
  2129. r = sz = facts->BlockSize;
  2130. vv = ((63 / (sz * 4)) + 1) & 0x03;
  2131. ioc->NB_for_64_byte_frame = vv;
  2132. while ( sz )
  2133. {
  2134. shiftFactor++;
  2135. sz = sz >> 1;
  2136. }
  2137. ioc->NBShiftFactor = shiftFactor;
  2138. dinitprintk((MYIOC_s_INFO_FMT "NB_for_64_byte_frame=%x NBShiftFactor=%x BlockSize=%x\n",
  2139. ioc->name, vv, shiftFactor, r));
  2140. if (reason == MPT_HOSTEVENT_IOC_BRINGUP) {
  2141. /*
  2142. * Set values for this IOC's request & reply frame sizes,
  2143. * and request & reply queue depths...
  2144. */
  2145. ioc->req_sz = min(MPT_DEFAULT_FRAME_SIZE, facts->RequestFrameSize * 4);
  2146. ioc->req_depth = min_t(int, MPT_MAX_REQ_DEPTH, facts->GlobalCredits);
  2147. ioc->reply_sz = MPT_REPLY_FRAME_SIZE;
  2148. ioc->reply_depth = min_t(int, MPT_DEFAULT_REPLY_DEPTH, facts->ReplyQueueDepth);
  2149. dinitprintk((MYIOC_s_INFO_FMT "reply_sz=%3d, reply_depth=%4d\n",
  2150. ioc->name, ioc->reply_sz, ioc->reply_depth));
  2151. dinitprintk((MYIOC_s_INFO_FMT "req_sz =%3d, req_depth =%4d\n",
  2152. ioc->name, ioc->req_sz, ioc->req_depth));
  2153. /* Get port facts! */
  2154. if ( (r = GetPortFacts(ioc, 0, sleepFlag)) != 0 )
  2155. return r;
  2156. }
  2157. } else {
  2158. printk(MYIOC_s_ERR_FMT
  2159. "Invalid IOC facts reply, msgLength=%d offsetof=%zd!\n",
  2160. ioc->name, facts->MsgLength, (offsetof(IOCFactsReply_t,
  2161. RequestFrameSize)/sizeof(u32)));
  2162. return -66;
  2163. }
  2164. return 0;
  2165. }
  2166. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2167. /*
  2168. * GetPortFacts - Send PortFacts request to MPT adapter.
  2169. * @ioc: Pointer to MPT_ADAPTER structure
  2170. * @portnum: Port number
  2171. * @sleepFlag: Specifies whether the process can sleep
  2172. *
  2173. * Returns 0 for success, non-zero for failure.
  2174. */
  2175. static int
  2176. GetPortFacts(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2177. {
  2178. PortFacts_t get_pfacts;
  2179. PortFactsReply_t *pfacts;
  2180. int ii;
  2181. int req_sz;
  2182. int reply_sz;
  2183. /* IOC *must* NOT be in RESET state! */
  2184. if (ioc->last_state == MPI_IOC_STATE_RESET) {
  2185. printk(KERN_ERR MYNAM ": ERROR - Can't get PortFacts, %s NOT READY! (%08x)\n",
  2186. ioc->name,
  2187. ioc->last_state );
  2188. return -4;
  2189. }
  2190. pfacts = &ioc->pfacts[portnum];
  2191. /* Destination (reply area)... */
  2192. reply_sz = sizeof(*pfacts);
  2193. memset(pfacts, 0, reply_sz);
  2194. /* Request area (get_pfacts on the stack right now!) */
  2195. req_sz = sizeof(get_pfacts);
  2196. memset(&get_pfacts, 0, req_sz);
  2197. get_pfacts.Function = MPI_FUNCTION_PORT_FACTS;
  2198. get_pfacts.PortNumber = portnum;
  2199. /* Assert: All other get_pfacts fields are zero! */
  2200. dinitprintk((MYIOC_s_INFO_FMT "Sending get PortFacts(%d) request\n",
  2201. ioc->name, portnum));
  2202. /* No non-zero fields in the get_pfacts request are greater than
  2203. * 1 byte in size, so we can just fire it off as is.
  2204. */
  2205. ii = mpt_handshake_req_reply_wait(ioc, req_sz, (u32*)&get_pfacts,
  2206. reply_sz, (u16*)pfacts, 5 /*seconds*/, sleepFlag);
  2207. if (ii != 0)
  2208. return ii;
  2209. /* Did we get a valid reply? */
  2210. /* Now byte swap the necessary fields in the response. */
  2211. pfacts->MsgContext = le32_to_cpu(pfacts->MsgContext);
  2212. pfacts->IOCStatus = le16_to_cpu(pfacts->IOCStatus);
  2213. pfacts->IOCLogInfo = le32_to_cpu(pfacts->IOCLogInfo);
  2214. pfacts->MaxDevices = le16_to_cpu(pfacts->MaxDevices);
  2215. pfacts->PortSCSIID = le16_to_cpu(pfacts->PortSCSIID);
  2216. pfacts->ProtocolFlags = le16_to_cpu(pfacts->ProtocolFlags);
  2217. pfacts->MaxPostedCmdBuffers = le16_to_cpu(pfacts->MaxPostedCmdBuffers);
  2218. pfacts->MaxPersistentIDs = le16_to_cpu(pfacts->MaxPersistentIDs);
  2219. pfacts->MaxLanBuckets = le16_to_cpu(pfacts->MaxLanBuckets);
  2220. return 0;
  2221. }
  2222. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2223. /*
  2224. * SendIocInit - Send IOCInit request to MPT adapter.
  2225. * @ioc: Pointer to MPT_ADAPTER structure
  2226. * @sleepFlag: Specifies whether the process can sleep
  2227. *
  2228. * Send IOCInit followed by PortEnable to bring IOC to OPERATIONAL state.
  2229. *
  2230. * Returns 0 for success, non-zero for failure.
  2231. */
  2232. static int
  2233. SendIocInit(MPT_ADAPTER *ioc, int sleepFlag)
  2234. {
  2235. IOCInit_t ioc_init;
  2236. MPIDefaultReply_t init_reply;
  2237. u32 state;
  2238. int r;
  2239. int count;
  2240. int cntdn;
  2241. memset(&ioc_init, 0, sizeof(ioc_init));
  2242. memset(&init_reply, 0, sizeof(init_reply));
  2243. ioc_init.WhoInit = MPI_WHOINIT_HOST_DRIVER;
  2244. ioc_init.Function = MPI_FUNCTION_IOC_INIT;
  2245. /* If we are in a recovery mode and we uploaded the FW image,
  2246. * then this pointer is not NULL. Skip the upload a second time.
  2247. * Set this flag if cached_fw set for either IOC.
  2248. */
  2249. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  2250. ioc->upload_fw = 1;
  2251. else
  2252. ioc->upload_fw = 0;
  2253. ddlprintk((MYIOC_s_INFO_FMT "upload_fw %d facts.Flags=%x\n",
  2254. ioc->name, ioc->upload_fw, ioc->facts.Flags));
  2255. if(ioc->bus_type == SAS)
  2256. ioc_init.MaxDevices = ioc->facts.MaxDevices;
  2257. else if(ioc->bus_type == FC)
  2258. ioc_init.MaxDevices = MPT_MAX_FC_DEVICES;
  2259. else
  2260. ioc_init.MaxDevices = MPT_MAX_SCSI_DEVICES;
  2261. ioc_init.MaxBuses = MPT_MAX_BUS;
  2262. dinitprintk((MYIOC_s_INFO_FMT "facts.MsgVersion=%x\n",
  2263. ioc->name, ioc->facts.MsgVersion));
  2264. if (ioc->facts.MsgVersion >= MPI_VERSION_01_05) {
  2265. // set MsgVersion and HeaderVersion host driver was built with
  2266. ioc_init.MsgVersion = cpu_to_le16(MPI_VERSION);
  2267. ioc_init.HeaderVersion = cpu_to_le16(MPI_HEADER_VERSION);
  2268. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_HOST_PAGE_BUFFER_PERSISTENT) {
  2269. ioc_init.HostPageBufferSGE = ioc->facts.HostPageBufferSGE;
  2270. } else if(mpt_host_page_alloc(ioc, &ioc_init))
  2271. return -99;
  2272. }
  2273. ioc_init.ReplyFrameSize = cpu_to_le16(ioc->reply_sz); /* in BYTES */
  2274. if (sizeof(dma_addr_t) == sizeof(u64)) {
  2275. /* Save the upper 32-bits of the request
  2276. * (reply) and sense buffers.
  2277. */
  2278. ioc_init.HostMfaHighAddr = cpu_to_le32((u32)((u64)ioc->alloc_dma >> 32));
  2279. ioc_init.SenseBufferHighAddr = cpu_to_le32((u32)((u64)ioc->sense_buf_pool_dma >> 32));
  2280. } else {
  2281. /* Force 32-bit addressing */
  2282. ioc_init.HostMfaHighAddr = cpu_to_le32(0);
  2283. ioc_init.SenseBufferHighAddr = cpu_to_le32(0);
  2284. }
  2285. ioc->facts.CurrentHostMfaHighAddr = ioc_init.HostMfaHighAddr;
  2286. ioc->facts.CurrentSenseBufferHighAddr = ioc_init.SenseBufferHighAddr;
  2287. ioc->facts.MaxDevices = ioc_init.MaxDevices;
  2288. ioc->facts.MaxBuses = ioc_init.MaxBuses;
  2289. dhsprintk((MYIOC_s_INFO_FMT "Sending IOCInit (req @ %p)\n",
  2290. ioc->name, &ioc_init));
  2291. r = mpt_handshake_req_reply_wait(ioc, sizeof(IOCInit_t), (u32*)&ioc_init,
  2292. sizeof(MPIDefaultReply_t), (u16*)&init_reply, 10 /*seconds*/, sleepFlag);
  2293. if (r != 0) {
  2294. printk(MYIOC_s_ERR_FMT "Sending IOCInit failed(%d)!\n",ioc->name, r);
  2295. return r;
  2296. }
  2297. /* No need to byte swap the multibyte fields in the reply
  2298. * since we don't even look at it's contents.
  2299. */
  2300. dhsprintk((MYIOC_s_INFO_FMT "Sending PortEnable (req @ %p)\n",
  2301. ioc->name, &ioc_init));
  2302. if ((r = SendPortEnable(ioc, 0, sleepFlag)) != 0) {
  2303. printk(MYIOC_s_ERR_FMT "Sending PortEnable failed(%d)!\n",ioc->name, r);
  2304. return r;
  2305. }
  2306. /* YIKES! SUPER IMPORTANT!!!
  2307. * Poll IocState until _OPERATIONAL while IOC is doing
  2308. * LoopInit and TargetDiscovery!
  2309. */
  2310. count = 0;
  2311. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 60; /* 60 seconds */
  2312. state = mpt_GetIocState(ioc, 1);
  2313. while (state != MPI_IOC_STATE_OPERATIONAL && --cntdn) {
  2314. if (sleepFlag == CAN_SLEEP) {
  2315. msleep(1);
  2316. } else {
  2317. mdelay(1);
  2318. }
  2319. if (!cntdn) {
  2320. printk(MYIOC_s_ERR_FMT "Wait IOC_OP state timeout(%d)!\n",
  2321. ioc->name, (int)((count+5)/HZ));
  2322. return -9;
  2323. }
  2324. state = mpt_GetIocState(ioc, 1);
  2325. count++;
  2326. }
  2327. dinitprintk((MYIOC_s_INFO_FMT "INFO - Wait IOC_OPERATIONAL state (cnt=%d)\n",
  2328. ioc->name, count));
  2329. ioc->aen_event_read_flag=0;
  2330. return r;
  2331. }
  2332. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2333. /*
  2334. * SendPortEnable - Send PortEnable request to MPT adapter port.
  2335. * @ioc: Pointer to MPT_ADAPTER structure
  2336. * @portnum: Port number to enable
  2337. * @sleepFlag: Specifies whether the process can sleep
  2338. *
  2339. * Send PortEnable to bring IOC to OPERATIONAL state.
  2340. *
  2341. * Returns 0 for success, non-zero for failure.
  2342. */
  2343. static int
  2344. SendPortEnable(MPT_ADAPTER *ioc, int portnum, int sleepFlag)
  2345. {
  2346. PortEnable_t port_enable;
  2347. MPIDefaultReply_t reply_buf;
  2348. int rc;
  2349. int req_sz;
  2350. int reply_sz;
  2351. /* Destination... */
  2352. reply_sz = sizeof(MPIDefaultReply_t);
  2353. memset(&reply_buf, 0, reply_sz);
  2354. req_sz = sizeof(PortEnable_t);
  2355. memset(&port_enable, 0, req_sz);
  2356. port_enable.Function = MPI_FUNCTION_PORT_ENABLE;
  2357. port_enable.PortNumber = portnum;
  2358. /* port_enable.ChainOffset = 0; */
  2359. /* port_enable.MsgFlags = 0; */
  2360. /* port_enable.MsgContext = 0; */
  2361. dinitprintk((MYIOC_s_INFO_FMT "Sending Port(%d)Enable (req @ %p)\n",
  2362. ioc->name, portnum, &port_enable));
  2363. /* RAID FW may take a long time to enable
  2364. */
  2365. if (((ioc->facts.ProductID & MPI_FW_HEADER_PID_PROD_MASK)
  2366. > MPI_FW_HEADER_PID_PROD_TARGET_SCSI) ||
  2367. (ioc->bus_type == SAS)) {
  2368. rc = mpt_handshake_req_reply_wait(ioc, req_sz,
  2369. (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
  2370. 300 /*seconds*/, sleepFlag);
  2371. } else {
  2372. rc = mpt_handshake_req_reply_wait(ioc, req_sz,
  2373. (u32*)&port_enable, reply_sz, (u16*)&reply_buf,
  2374. 30 /*seconds*/, sleepFlag);
  2375. }
  2376. return rc;
  2377. }
  2378. /*
  2379. * ioc: Pointer to MPT_ADAPTER structure
  2380. * size - total FW bytes
  2381. */
  2382. void
  2383. mpt_alloc_fw_memory(MPT_ADAPTER *ioc, int size)
  2384. {
  2385. if (ioc->cached_fw)
  2386. return; /* use already allocated memory */
  2387. if (ioc->alt_ioc && ioc->alt_ioc->cached_fw) {
  2388. ioc->cached_fw = ioc->alt_ioc->cached_fw; /* use alt_ioc's memory */
  2389. ioc->cached_fw_dma = ioc->alt_ioc->cached_fw_dma;
  2390. ioc->alloc_total += size;
  2391. ioc->alt_ioc->alloc_total -= size;
  2392. } else {
  2393. if ( (ioc->cached_fw = pci_alloc_consistent(ioc->pcidev, size, &ioc->cached_fw_dma) ) )
  2394. ioc->alloc_total += size;
  2395. }
  2396. }
  2397. /*
  2398. * If alt_img is NULL, delete from ioc structure.
  2399. * Else, delete a secondary image in same format.
  2400. */
  2401. void
  2402. mpt_free_fw_memory(MPT_ADAPTER *ioc)
  2403. {
  2404. int sz;
  2405. sz = ioc->facts.FWImageSize;
  2406. dinitprintk((KERN_INFO MYNAM "free_fw_memory: FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2407. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2408. pci_free_consistent(ioc->pcidev, sz,
  2409. ioc->cached_fw, ioc->cached_fw_dma);
  2410. ioc->cached_fw = NULL;
  2411. return;
  2412. }
  2413. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2414. /*
  2415. * mpt_do_upload - Construct and Send FWUpload request to MPT adapter port.
  2416. * @ioc: Pointer to MPT_ADAPTER structure
  2417. * @sleepFlag: Specifies whether the process can sleep
  2418. *
  2419. * Returns 0 for success, >0 for handshake failure
  2420. * <0 for fw upload failure.
  2421. *
  2422. * Remark: If bound IOC and a successful FWUpload was performed
  2423. * on the bound IOC, the second image is discarded
  2424. * and memory is free'd. Both channels must upload to prevent
  2425. * IOC from running in degraded mode.
  2426. */
  2427. static int
  2428. mpt_do_upload(MPT_ADAPTER *ioc, int sleepFlag)
  2429. {
  2430. u8 request[ioc->req_sz];
  2431. u8 reply[sizeof(FWUploadReply_t)];
  2432. FWUpload_t *prequest;
  2433. FWUploadReply_t *preply;
  2434. FWUploadTCSGE_t *ptcsge;
  2435. int sgeoffset;
  2436. u32 flagsLength;
  2437. int ii, sz, reply_sz;
  2438. int cmdStatus;
  2439. /* If the image size is 0, we are done.
  2440. */
  2441. if ((sz = ioc->facts.FWImageSize) == 0)
  2442. return 0;
  2443. mpt_alloc_fw_memory(ioc, sz);
  2444. dinitprintk((KERN_INFO MYNAM ": FW Image @ %p[%p], sz=%d[%x] bytes\n",
  2445. ioc->cached_fw, (void *)(ulong)ioc->cached_fw_dma, sz, sz));
  2446. if (ioc->cached_fw == NULL) {
  2447. /* Major Failure.
  2448. */
  2449. return -ENOMEM;
  2450. }
  2451. prequest = (FWUpload_t *)&request;
  2452. preply = (FWUploadReply_t *)&reply;
  2453. /* Destination... */
  2454. memset(prequest, 0, ioc->req_sz);
  2455. reply_sz = sizeof(reply);
  2456. memset(preply, 0, reply_sz);
  2457. prequest->ImageType = MPI_FW_UPLOAD_ITYPE_FW_IOC_MEM;
  2458. prequest->Function = MPI_FUNCTION_FW_UPLOAD;
  2459. ptcsge = (FWUploadTCSGE_t *) &prequest->SGL;
  2460. ptcsge->DetailsLength = 12;
  2461. ptcsge->Flags = MPI_SGE_FLAGS_TRANSACTION_ELEMENT;
  2462. ptcsge->ImageSize = cpu_to_le32(sz);
  2463. sgeoffset = sizeof(FWUpload_t) - sizeof(SGE_MPI_UNION) + sizeof(FWUploadTCSGE_t);
  2464. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ | sz;
  2465. mpt_add_sge(&request[sgeoffset], flagsLength, ioc->cached_fw_dma);
  2466. sgeoffset += sizeof(u32) + sizeof(dma_addr_t);
  2467. dinitprintk((KERN_INFO MYNAM ": Sending FW Upload (req @ %p) sgeoffset=%d \n",
  2468. prequest, sgeoffset));
  2469. DBG_DUMP_FW_REQUEST_FRAME(prequest)
  2470. ii = mpt_handshake_req_reply_wait(ioc, sgeoffset, (u32*)prequest,
  2471. reply_sz, (u16*)preply, 65 /*seconds*/, sleepFlag);
  2472. dinitprintk((KERN_INFO MYNAM ": FW Upload completed rc=%x \n", ii));
  2473. cmdStatus = -EFAULT;
  2474. if (ii == 0) {
  2475. /* Handshake transfer was complete and successful.
  2476. * Check the Reply Frame.
  2477. */
  2478. int status, transfer_sz;
  2479. status = le16_to_cpu(preply->IOCStatus);
  2480. if (status == MPI_IOCSTATUS_SUCCESS) {
  2481. transfer_sz = le32_to_cpu(preply->ActualImageSize);
  2482. if (transfer_sz == sz)
  2483. cmdStatus = 0;
  2484. }
  2485. }
  2486. dinitprintk((MYIOC_s_INFO_FMT ": do_upload cmdStatus=%d \n",
  2487. ioc->name, cmdStatus));
  2488. if (cmdStatus) {
  2489. ddlprintk((MYIOC_s_INFO_FMT ": fw upload failed, freeing image \n",
  2490. ioc->name));
  2491. mpt_free_fw_memory(ioc);
  2492. }
  2493. return cmdStatus;
  2494. }
  2495. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2496. /*
  2497. * mpt_downloadboot - DownloadBoot code
  2498. * @ioc: Pointer to MPT_ADAPTER structure
  2499. * @flag: Specify which part of IOC memory is to be uploaded.
  2500. * @sleepFlag: Specifies whether the process can sleep
  2501. *
  2502. * FwDownloadBoot requires Programmed IO access.
  2503. *
  2504. * Returns 0 for success
  2505. * -1 FW Image size is 0
  2506. * -2 No valid cached_fw Pointer
  2507. * <0 for fw upload failure.
  2508. */
  2509. static int
  2510. mpt_downloadboot(MPT_ADAPTER *ioc, MpiFwHeader_t *pFwHeader, int sleepFlag)
  2511. {
  2512. MpiExtImageHeader_t *pExtImage;
  2513. u32 fwSize;
  2514. u32 diag0val;
  2515. int count;
  2516. u32 *ptrFw;
  2517. u32 diagRwData;
  2518. u32 nextImage;
  2519. u32 load_addr;
  2520. u32 ioc_state=0;
  2521. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: fw size 0x%x (%d), FW Ptr %p\n",
  2522. ioc->name, pFwHeader->ImageSize, pFwHeader->ImageSize, pFwHeader));
  2523. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2524. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2525. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2526. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2527. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2528. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2529. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM));
  2530. /* wait 1 msec */
  2531. if (sleepFlag == CAN_SLEEP) {
  2532. msleep(1);
  2533. } else {
  2534. mdelay (1);
  2535. }
  2536. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2537. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2538. for (count = 0; count < 30; count ++) {
  2539. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2540. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2541. ddlprintk((MYIOC_s_INFO_FMT "RESET_ADAPTER cleared, count=%d\n",
  2542. ioc->name, count));
  2543. break;
  2544. }
  2545. /* wait .1 sec */
  2546. if (sleepFlag == CAN_SLEEP) {
  2547. msleep (100);
  2548. } else {
  2549. mdelay (100);
  2550. }
  2551. }
  2552. if ( count == 30 ) {
  2553. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! "
  2554. "Unable to get MPI_DIAG_DRWE mode, diag0val=%x\n",
  2555. ioc->name, diag0val));
  2556. return -3;
  2557. }
  2558. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2559. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2560. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2561. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2562. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2563. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2564. /* Set the DiagRwEn and Disable ARM bits */
  2565. CHIPREG_WRITE32(&ioc->chip->Diagnostic, (MPI_DIAG_RW_ENABLE | MPI_DIAG_DISABLE_ARM));
  2566. fwSize = (pFwHeader->ImageSize + 3)/4;
  2567. ptrFw = (u32 *) pFwHeader;
  2568. /* Write the LoadStartAddress to the DiagRw Address Register
  2569. * using Programmed IO
  2570. */
  2571. if (ioc->errata_flag_1064)
  2572. pci_enable_io_access(ioc->pcidev);
  2573. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->LoadStartAddress);
  2574. ddlprintk((MYIOC_s_INFO_FMT "LoadStart addr written 0x%x \n",
  2575. ioc->name, pFwHeader->LoadStartAddress));
  2576. ddlprintk((MYIOC_s_INFO_FMT "Write FW Image: 0x%x bytes @ %p\n",
  2577. ioc->name, fwSize*4, ptrFw));
  2578. while (fwSize--) {
  2579. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2580. }
  2581. nextImage = pFwHeader->NextImageHeaderOffset;
  2582. while (nextImage) {
  2583. pExtImage = (MpiExtImageHeader_t *) ((char *)pFwHeader + nextImage);
  2584. load_addr = pExtImage->LoadStartAddress;
  2585. fwSize = (pExtImage->ImageSize + 3) >> 2;
  2586. ptrFw = (u32 *)pExtImage;
  2587. ddlprintk((MYIOC_s_INFO_FMT "Write Ext Image: 0x%x (%d) bytes @ %p load_addr=%x\n",
  2588. ioc->name, fwSize*4, fwSize*4, ptrFw, load_addr));
  2589. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, load_addr);
  2590. while (fwSize--) {
  2591. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, *ptrFw++);
  2592. }
  2593. nextImage = pExtImage->NextImageHeaderOffset;
  2594. }
  2595. /* Write the IopResetVectorRegAddr */
  2596. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Addr=%x! \n", ioc->name, pFwHeader->IopResetRegAddr));
  2597. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, pFwHeader->IopResetRegAddr);
  2598. /* Write the IopResetVectorValue */
  2599. ddlprintk((MYIOC_s_INFO_FMT "Write IopResetVector Value=%x! \n", ioc->name, pFwHeader->IopResetVectorValue));
  2600. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, pFwHeader->IopResetVectorValue);
  2601. /* Clear the internal flash bad bit - autoincrementing register,
  2602. * so must do two writes.
  2603. */
  2604. if (ioc->bus_type == SPI) {
  2605. /*
  2606. * 1030 and 1035 H/W errata, workaround to access
  2607. * the ClearFlashBadSignatureBit
  2608. */
  2609. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2610. diagRwData = CHIPREG_PIO_READ32(&ioc->pio_chip->DiagRwData);
  2611. diagRwData |= 0x40000000;
  2612. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwAddress, 0x3F000000);
  2613. CHIPREG_PIO_WRITE32(&ioc->pio_chip->DiagRwData, diagRwData);
  2614. } else /* if((ioc->bus_type == SAS) || (ioc->bus_type == FC)) */ {
  2615. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2616. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val |
  2617. MPI_DIAG_CLEAR_FLASH_BAD_SIG);
  2618. /* wait 1 msec */
  2619. if (sleepFlag == CAN_SLEEP) {
  2620. msleep (1);
  2621. } else {
  2622. mdelay (1);
  2623. }
  2624. }
  2625. if (ioc->errata_flag_1064)
  2626. pci_disable_io_access(ioc->pcidev);
  2627. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2628. ddlprintk((MYIOC_s_INFO_FMT "downloadboot diag0val=%x, "
  2629. "turning off PREVENT_IOC_BOOT, DISABLE_ARM, RW_ENABLE\n",
  2630. ioc->name, diag0val));
  2631. diag0val &= ~(MPI_DIAG_PREVENT_IOC_BOOT | MPI_DIAG_DISABLE_ARM | MPI_DIAG_RW_ENABLE);
  2632. ddlprintk((MYIOC_s_INFO_FMT "downloadboot now diag0val=%x\n",
  2633. ioc->name, diag0val));
  2634. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2635. /* Write 0xFF to reset the sequencer */
  2636. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2637. if (ioc->bus_type == SAS) {
  2638. ioc_state = mpt_GetIocState(ioc, 0);
  2639. if ( (GetIocFacts(ioc, sleepFlag,
  2640. MPT_HOSTEVENT_IOC_BRINGUP)) != 0 ) {
  2641. ddlprintk((MYIOC_s_INFO_FMT "GetIocFacts failed: IocState=%x\n",
  2642. ioc->name, ioc_state));
  2643. return -EFAULT;
  2644. }
  2645. }
  2646. for (count=0; count<HZ*20; count++) {
  2647. if ((ioc_state = mpt_GetIocState(ioc, 0)) & MPI_IOC_STATE_READY) {
  2648. ddlprintk((MYIOC_s_INFO_FMT "downloadboot successful! (count=%d) IocState=%x\n",
  2649. ioc->name, count, ioc_state));
  2650. if (ioc->bus_type == SAS) {
  2651. return 0;
  2652. }
  2653. if ((SendIocInit(ioc, sleepFlag)) != 0) {
  2654. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit failed\n",
  2655. ioc->name));
  2656. return -EFAULT;
  2657. }
  2658. ddlprintk((MYIOC_s_INFO_FMT "downloadboot: SendIocInit successful\n",
  2659. ioc->name));
  2660. return 0;
  2661. }
  2662. if (sleepFlag == CAN_SLEEP) {
  2663. msleep (10);
  2664. } else {
  2665. mdelay (10);
  2666. }
  2667. }
  2668. ddlprintk((MYIOC_s_INFO_FMT "downloadboot failed! IocState=%x\n",
  2669. ioc->name, ioc_state));
  2670. return -EFAULT;
  2671. }
  2672. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2673. /*
  2674. * KickStart - Perform hard reset of MPT adapter.
  2675. * @ioc: Pointer to MPT_ADAPTER structure
  2676. * @force: Force hard reset
  2677. * @sleepFlag: Specifies whether the process can sleep
  2678. *
  2679. * This routine places MPT adapter in diagnostic mode via the
  2680. * WriteSequence register, and then performs a hard reset of adapter
  2681. * via the Diagnostic register.
  2682. *
  2683. * Inputs: sleepflag - CAN_SLEEP (non-interrupt thread)
  2684. * or NO_SLEEP (interrupt thread, use mdelay)
  2685. * force - 1 if doorbell active, board fault state
  2686. * board operational, IOC_RECOVERY or
  2687. * IOC_BRINGUP and there is an alt_ioc.
  2688. * 0 else
  2689. *
  2690. * Returns:
  2691. * 1 - hard reset, READY
  2692. * 0 - no reset due to History bit, READY
  2693. * -1 - no reset due to History bit but not READY
  2694. * OR reset but failed to come READY
  2695. * -2 - no reset, could not enter DIAG mode
  2696. * -3 - reset but bad FW bit
  2697. */
  2698. static int
  2699. KickStart(MPT_ADAPTER *ioc, int force, int sleepFlag)
  2700. {
  2701. int hard_reset_done = 0;
  2702. u32 ioc_state=0;
  2703. int cnt,cntdn;
  2704. dinitprintk((KERN_WARNING MYNAM ": KickStarting %s!\n", ioc->name));
  2705. if (ioc->bus_type == SPI) {
  2706. /* Always issue a Msg Unit Reset first. This will clear some
  2707. * SCSI bus hang conditions.
  2708. */
  2709. SendIocReset(ioc, MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET, sleepFlag);
  2710. if (sleepFlag == CAN_SLEEP) {
  2711. msleep (1000);
  2712. } else {
  2713. mdelay (1000);
  2714. }
  2715. }
  2716. hard_reset_done = mpt_diag_reset(ioc, force, sleepFlag);
  2717. if (hard_reset_done < 0)
  2718. return hard_reset_done;
  2719. dinitprintk((MYIOC_s_INFO_FMT "Diagnostic reset successful!\n",
  2720. ioc->name));
  2721. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 2; /* 2 seconds */
  2722. for (cnt=0; cnt<cntdn; cnt++) {
  2723. ioc_state = mpt_GetIocState(ioc, 1);
  2724. if ((ioc_state == MPI_IOC_STATE_READY) || (ioc_state == MPI_IOC_STATE_OPERATIONAL)) {
  2725. dinitprintk((MYIOC_s_INFO_FMT "KickStart successful! (cnt=%d)\n",
  2726. ioc->name, cnt));
  2727. return hard_reset_done;
  2728. }
  2729. if (sleepFlag == CAN_SLEEP) {
  2730. msleep (10);
  2731. } else {
  2732. mdelay (10);
  2733. }
  2734. }
  2735. printk(MYIOC_s_ERR_FMT "Failed to come READY after reset! IocState=%x\n",
  2736. ioc->name, ioc_state);
  2737. return -1;
  2738. }
  2739. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2740. /*
  2741. * mpt_diag_reset - Perform hard reset of the adapter.
  2742. * @ioc: Pointer to MPT_ADAPTER structure
  2743. * @ignore: Set if to honor and clear to ignore
  2744. * the reset history bit
  2745. * @sleepflag: CAN_SLEEP if called in a non-interrupt thread,
  2746. * else set to NO_SLEEP (use mdelay instead)
  2747. *
  2748. * This routine places the adapter in diagnostic mode via the
  2749. * WriteSequence register and then performs a hard reset of adapter
  2750. * via the Diagnostic register. Adapter should be in ready state
  2751. * upon successful completion.
  2752. *
  2753. * Returns: 1 hard reset successful
  2754. * 0 no reset performed because reset history bit set
  2755. * -2 enabling diagnostic mode failed
  2756. * -3 diagnostic reset failed
  2757. */
  2758. static int
  2759. mpt_diag_reset(MPT_ADAPTER *ioc, int ignore, int sleepFlag)
  2760. {
  2761. MPT_ADAPTER *iocp=NULL;
  2762. u32 diag0val;
  2763. u32 doorbell;
  2764. int hard_reset_done = 0;
  2765. int count = 0;
  2766. #ifdef MPT_DEBUG
  2767. u32 diag1val = 0;
  2768. #endif
  2769. if (ioc->pcidev->device == MPI_MANUFACTPAGE_DEVID_SAS1078) {
  2770. drsprintk((MYIOC_s_WARN_FMT "%s: Doorbell=%p; 1078 reset "
  2771. "address=%p\n", ioc->name, __FUNCTION__,
  2772. &ioc->chip->Doorbell, &ioc->chip->Reset_1078));
  2773. CHIPREG_WRITE32(&ioc->chip->Reset_1078, 0x07);
  2774. if (sleepFlag == CAN_SLEEP)
  2775. msleep(1);
  2776. else
  2777. mdelay(1);
  2778. for (count = 0; count < 60; count ++) {
  2779. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  2780. doorbell &= MPI_IOC_STATE_MASK;
  2781. drsprintk((MYIOC_s_INFO_FMT
  2782. "looking for READY STATE: doorbell=%x"
  2783. " count=%d\n",
  2784. ioc->name, doorbell, count));
  2785. if (doorbell == MPI_IOC_STATE_READY) {
  2786. return 0;
  2787. }
  2788. /* wait 1 sec */
  2789. if (sleepFlag == CAN_SLEEP)
  2790. msleep(1000);
  2791. else
  2792. mdelay(1000);
  2793. }
  2794. return -1;
  2795. }
  2796. /* Clear any existing interrupts */
  2797. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  2798. /* Use "Diagnostic reset" method! (only thing available!) */
  2799. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2800. #ifdef MPT_DEBUG
  2801. if (ioc->alt_ioc)
  2802. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2803. dprintk((MYIOC_s_INFO_FMT "DbG1: diag0=%08x, diag1=%08x\n",
  2804. ioc->name, diag0val, diag1val));
  2805. #endif
  2806. /* Do the reset if we are told to ignore the reset history
  2807. * or if the reset history is 0
  2808. */
  2809. if (ignore || !(diag0val & MPI_DIAG_RESET_HISTORY)) {
  2810. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2811. /* Write magic sequence to WriteSequence register
  2812. * Loop until in diagnostic mode
  2813. */
  2814. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2815. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2816. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2817. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2818. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2819. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2820. /* wait 100 msec */
  2821. if (sleepFlag == CAN_SLEEP) {
  2822. msleep (100);
  2823. } else {
  2824. mdelay (100);
  2825. }
  2826. count++;
  2827. if (count > 20) {
  2828. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2829. ioc->name, diag0val);
  2830. return -2;
  2831. }
  2832. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2833. dprintk((MYIOC_s_INFO_FMT "Wrote magic DiagWriteEn sequence (%x)\n",
  2834. ioc->name, diag0val));
  2835. }
  2836. #ifdef MPT_DEBUG
  2837. if (ioc->alt_ioc)
  2838. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2839. dprintk((MYIOC_s_INFO_FMT "DbG2: diag0=%08x, diag1=%08x\n",
  2840. ioc->name, diag0val, diag1val));
  2841. #endif
  2842. /*
  2843. * Disable the ARM (Bug fix)
  2844. *
  2845. */
  2846. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_DISABLE_ARM);
  2847. mdelay(1);
  2848. /*
  2849. * Now hit the reset bit in the Diagnostic register
  2850. * (THE BIG HAMMER!) (Clears DRWE bit).
  2851. */
  2852. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val | MPI_DIAG_RESET_ADAPTER);
  2853. hard_reset_done = 1;
  2854. dprintk((MYIOC_s_INFO_FMT "Diagnostic reset performed\n",
  2855. ioc->name));
  2856. /*
  2857. * Call each currently registered protocol IOC reset handler
  2858. * with pre-reset indication.
  2859. * NOTE: If we're doing _IOC_BRINGUP, there can be no
  2860. * MptResetHandlers[] registered yet.
  2861. */
  2862. {
  2863. int ii;
  2864. int r = 0;
  2865. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  2866. if (MptResetHandlers[ii]) {
  2867. dprintk((MYIOC_s_INFO_FMT "Calling IOC pre_reset handler #%d\n",
  2868. ioc->name, ii));
  2869. r += mpt_signal_reset(ii, ioc, MPT_IOC_PRE_RESET);
  2870. if (ioc->alt_ioc) {
  2871. dprintk((MYIOC_s_INFO_FMT "Calling alt-%s pre_reset handler #%d\n",
  2872. ioc->name, ioc->alt_ioc->name, ii));
  2873. r += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_PRE_RESET);
  2874. }
  2875. }
  2876. }
  2877. /* FIXME? Examine results here? */
  2878. }
  2879. if (ioc->cached_fw)
  2880. iocp = ioc;
  2881. else if (ioc->alt_ioc && ioc->alt_ioc->cached_fw)
  2882. iocp = ioc->alt_ioc;
  2883. if (iocp) {
  2884. /* If the DownloadBoot operation fails, the
  2885. * IOC will be left unusable. This is a fatal error
  2886. * case. _diag_reset will return < 0
  2887. */
  2888. for (count = 0; count < 30; count ++) {
  2889. diag0val = CHIPREG_READ32(&iocp->chip->Diagnostic);
  2890. if (!(diag0val & MPI_DIAG_RESET_ADAPTER)) {
  2891. break;
  2892. }
  2893. dprintk((MYIOC_s_INFO_FMT "cached_fw: diag0val=%x count=%d\n",
  2894. iocp->name, diag0val, count));
  2895. /* wait 1 sec */
  2896. if (sleepFlag == CAN_SLEEP) {
  2897. msleep (1000);
  2898. } else {
  2899. mdelay (1000);
  2900. }
  2901. }
  2902. if ((count = mpt_downloadboot(ioc,
  2903. (MpiFwHeader_t *)iocp->cached_fw, sleepFlag)) < 0) {
  2904. printk(KERN_WARNING MYNAM
  2905. ": firmware downloadboot failure (%d)!\n", count);
  2906. }
  2907. } else {
  2908. /* Wait for FW to reload and for board
  2909. * to go to the READY state.
  2910. * Maximum wait is 60 seconds.
  2911. * If fail, no error will check again
  2912. * with calling program.
  2913. */
  2914. for (count = 0; count < 60; count ++) {
  2915. doorbell = CHIPREG_READ32(&ioc->chip->Doorbell);
  2916. doorbell &= MPI_IOC_STATE_MASK;
  2917. if (doorbell == MPI_IOC_STATE_READY) {
  2918. break;
  2919. }
  2920. /* wait 1 sec */
  2921. if (sleepFlag == CAN_SLEEP) {
  2922. msleep (1000);
  2923. } else {
  2924. mdelay (1000);
  2925. }
  2926. }
  2927. }
  2928. }
  2929. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2930. #ifdef MPT_DEBUG
  2931. if (ioc->alt_ioc)
  2932. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2933. dprintk((MYIOC_s_INFO_FMT "DbG3: diag0=%08x, diag1=%08x\n",
  2934. ioc->name, diag0val, diag1val));
  2935. #endif
  2936. /* Clear RESET_HISTORY bit! Place board in the
  2937. * diagnostic mode to update the diag register.
  2938. */
  2939. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2940. count = 0;
  2941. while ((diag0val & MPI_DIAG_DRWE) == 0) {
  2942. /* Write magic sequence to WriteSequence register
  2943. * Loop until in diagnostic mode
  2944. */
  2945. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFF);
  2946. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_1ST_KEY_VALUE);
  2947. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_2ND_KEY_VALUE);
  2948. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_3RD_KEY_VALUE);
  2949. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_4TH_KEY_VALUE);
  2950. CHIPREG_WRITE32(&ioc->chip->WriteSequence, MPI_WRSEQ_5TH_KEY_VALUE);
  2951. /* wait 100 msec */
  2952. if (sleepFlag == CAN_SLEEP) {
  2953. msleep (100);
  2954. } else {
  2955. mdelay (100);
  2956. }
  2957. count++;
  2958. if (count > 20) {
  2959. printk(MYIOC_s_ERR_FMT "Enable Diagnostic mode FAILED! (%02xh)\n",
  2960. ioc->name, diag0val);
  2961. break;
  2962. }
  2963. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2964. }
  2965. diag0val &= ~MPI_DIAG_RESET_HISTORY;
  2966. CHIPREG_WRITE32(&ioc->chip->Diagnostic, diag0val);
  2967. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2968. if (diag0val & MPI_DIAG_RESET_HISTORY) {
  2969. printk(MYIOC_s_WARN_FMT "ResetHistory bit failed to clear!\n",
  2970. ioc->name);
  2971. }
  2972. /* Disable Diagnostic Mode
  2973. */
  2974. CHIPREG_WRITE32(&ioc->chip->WriteSequence, 0xFFFFFFFF);
  2975. /* Check FW reload status flags.
  2976. */
  2977. diag0val = CHIPREG_READ32(&ioc->chip->Diagnostic);
  2978. if (diag0val & (MPI_DIAG_FLASH_BAD_SIG | MPI_DIAG_RESET_ADAPTER | MPI_DIAG_DISABLE_ARM)) {
  2979. printk(MYIOC_s_ERR_FMT "Diagnostic reset FAILED! (%02xh)\n",
  2980. ioc->name, diag0val);
  2981. return -3;
  2982. }
  2983. #ifdef MPT_DEBUG
  2984. if (ioc->alt_ioc)
  2985. diag1val = CHIPREG_READ32(&ioc->alt_ioc->chip->Diagnostic);
  2986. dprintk((MYIOC_s_INFO_FMT "DbG4: diag0=%08x, diag1=%08x\n",
  2987. ioc->name, diag0val, diag1val));
  2988. #endif
  2989. /*
  2990. * Reset flag that says we've enabled event notification
  2991. */
  2992. ioc->facts.EventState = 0;
  2993. if (ioc->alt_ioc)
  2994. ioc->alt_ioc->facts.EventState = 0;
  2995. return hard_reset_done;
  2996. }
  2997. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  2998. /*
  2999. * SendIocReset - Send IOCReset request to MPT adapter.
  3000. * @ioc: Pointer to MPT_ADAPTER structure
  3001. * @reset_type: reset type, expected values are
  3002. * %MPI_FUNCTION_IOC_MESSAGE_UNIT_RESET or %MPI_FUNCTION_IO_UNIT_RESET
  3003. *
  3004. * Send IOCReset request to the MPT adapter.
  3005. *
  3006. * Returns 0 for success, non-zero for failure.
  3007. */
  3008. static int
  3009. SendIocReset(MPT_ADAPTER *ioc, u8 reset_type, int sleepFlag)
  3010. {
  3011. int r;
  3012. u32 state;
  3013. int cntdn, count;
  3014. drsprintk((KERN_INFO MYNAM ": %s: Sending IOC reset(0x%02x)!\n",
  3015. ioc->name, reset_type));
  3016. CHIPREG_WRITE32(&ioc->chip->Doorbell, reset_type<<MPI_DOORBELL_FUNCTION_SHIFT);
  3017. if ((r = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3018. return r;
  3019. /* FW ACK'd request, wait for READY state
  3020. */
  3021. count = 0;
  3022. cntdn = ((sleepFlag == CAN_SLEEP) ? HZ : 1000) * 15; /* 15 seconds */
  3023. while ((state = mpt_GetIocState(ioc, 1)) != MPI_IOC_STATE_READY) {
  3024. cntdn--;
  3025. count++;
  3026. if (!cntdn) {
  3027. if (sleepFlag != CAN_SLEEP)
  3028. count *= 10;
  3029. printk(KERN_ERR MYNAM ": %s: ERROR - Wait IOC_READY state timeout(%d)!\n",
  3030. ioc->name, (int)((count+5)/HZ));
  3031. return -ETIME;
  3032. }
  3033. if (sleepFlag == CAN_SLEEP) {
  3034. msleep(1);
  3035. } else {
  3036. mdelay (1); /* 1 msec delay */
  3037. }
  3038. }
  3039. /* TODO!
  3040. * Cleanup all event stuff for this IOC; re-issue EventNotification
  3041. * request if needed.
  3042. */
  3043. if (ioc->facts.Function)
  3044. ioc->facts.EventState = 0;
  3045. return 0;
  3046. }
  3047. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3048. /*
  3049. * initChainBuffers - Allocate memory for and initialize
  3050. * chain buffers, chain buffer control arrays and spinlock.
  3051. * @hd: Pointer to MPT_SCSI_HOST structure
  3052. * @init: If set, initialize the spin lock.
  3053. */
  3054. static int
  3055. initChainBuffers(MPT_ADAPTER *ioc)
  3056. {
  3057. u8 *mem;
  3058. int sz, ii, num_chain;
  3059. int scale, num_sge, numSGE;
  3060. /* ReqToChain size must equal the req_depth
  3061. * index = req_idx
  3062. */
  3063. if (ioc->ReqToChain == NULL) {
  3064. sz = ioc->req_depth * sizeof(int);
  3065. mem = kmalloc(sz, GFP_ATOMIC);
  3066. if (mem == NULL)
  3067. return -1;
  3068. ioc->ReqToChain = (int *) mem;
  3069. dinitprintk((KERN_INFO MYNAM ": %s ReqToChain alloc @ %p, sz=%d bytes\n",
  3070. ioc->name, mem, sz));
  3071. mem = kmalloc(sz, GFP_ATOMIC);
  3072. if (mem == NULL)
  3073. return -1;
  3074. ioc->RequestNB = (int *) mem;
  3075. dinitprintk((KERN_INFO MYNAM ": %s RequestNB alloc @ %p, sz=%d bytes\n",
  3076. ioc->name, mem, sz));
  3077. }
  3078. for (ii = 0; ii < ioc->req_depth; ii++) {
  3079. ioc->ReqToChain[ii] = MPT_HOST_NO_CHAIN;
  3080. }
  3081. /* ChainToChain size must equal the total number
  3082. * of chain buffers to be allocated.
  3083. * index = chain_idx
  3084. *
  3085. * Calculate the number of chain buffers needed(plus 1) per I/O
  3086. * then multiply the the maximum number of simultaneous cmds
  3087. *
  3088. * num_sge = num sge in request frame + last chain buffer
  3089. * scale = num sge per chain buffer if no chain element
  3090. */
  3091. scale = ioc->req_sz/(sizeof(dma_addr_t) + sizeof(u32));
  3092. if (sizeof(dma_addr_t) == sizeof(u64))
  3093. num_sge = scale + (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  3094. else
  3095. num_sge = 1+ scale + (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  3096. if (sizeof(dma_addr_t) == sizeof(u64)) {
  3097. numSGE = (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  3098. (ioc->req_sz - 60) / (sizeof(dma_addr_t) + sizeof(u32));
  3099. } else {
  3100. numSGE = 1 + (scale - 1) * (ioc->facts.MaxChainDepth-1) + scale +
  3101. (ioc->req_sz - 64) / (sizeof(dma_addr_t) + sizeof(u32));
  3102. }
  3103. dinitprintk((KERN_INFO MYNAM ": %s num_sge=%d numSGE=%d\n",
  3104. ioc->name, num_sge, numSGE));
  3105. if ( numSGE > MPT_SCSI_SG_DEPTH )
  3106. numSGE = MPT_SCSI_SG_DEPTH;
  3107. num_chain = 1;
  3108. while (numSGE - num_sge > 0) {
  3109. num_chain++;
  3110. num_sge += (scale - 1);
  3111. }
  3112. num_chain++;
  3113. dinitprintk((KERN_INFO MYNAM ": %s Now numSGE=%d num_sge=%d num_chain=%d\n",
  3114. ioc->name, numSGE, num_sge, num_chain));
  3115. if (ioc->bus_type == SPI)
  3116. num_chain *= MPT_SCSI_CAN_QUEUE;
  3117. else
  3118. num_chain *= MPT_FC_CAN_QUEUE;
  3119. ioc->num_chain = num_chain;
  3120. sz = num_chain * sizeof(int);
  3121. if (ioc->ChainToChain == NULL) {
  3122. mem = kmalloc(sz, GFP_ATOMIC);
  3123. if (mem == NULL)
  3124. return -1;
  3125. ioc->ChainToChain = (int *) mem;
  3126. dinitprintk((KERN_INFO MYNAM ": %s ChainToChain alloc @ %p, sz=%d bytes\n",
  3127. ioc->name, mem, sz));
  3128. } else {
  3129. mem = (u8 *) ioc->ChainToChain;
  3130. }
  3131. memset(mem, 0xFF, sz);
  3132. return num_chain;
  3133. }
  3134. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3135. /*
  3136. * PrimeIocFifos - Initialize IOC request and reply FIFOs.
  3137. * @ioc: Pointer to MPT_ADAPTER structure
  3138. *
  3139. * This routine allocates memory for the MPT reply and request frame
  3140. * pools (if necessary), and primes the IOC reply FIFO with
  3141. * reply frames.
  3142. *
  3143. * Returns 0 for success, non-zero for failure.
  3144. */
  3145. static int
  3146. PrimeIocFifos(MPT_ADAPTER *ioc)
  3147. {
  3148. MPT_FRAME_HDR *mf;
  3149. unsigned long flags;
  3150. dma_addr_t alloc_dma;
  3151. u8 *mem;
  3152. int i, reply_sz, sz, total_size, num_chain;
  3153. /* Prime reply FIFO... */
  3154. if (ioc->reply_frames == NULL) {
  3155. if ( (num_chain = initChainBuffers(ioc)) < 0)
  3156. return -1;
  3157. total_size = reply_sz = (ioc->reply_sz * ioc->reply_depth);
  3158. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d bytes, ReplyDepth=%d\n",
  3159. ioc->name, ioc->reply_sz, ioc->reply_depth));
  3160. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffer sz=%d[%x] bytes\n",
  3161. ioc->name, reply_sz, reply_sz));
  3162. sz = (ioc->req_sz * ioc->req_depth);
  3163. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d bytes, RequestDepth=%d\n",
  3164. ioc->name, ioc->req_sz, ioc->req_depth));
  3165. dinitprintk((KERN_INFO MYNAM ": %s.RequestBuffer sz=%d[%x] bytes\n",
  3166. ioc->name, sz, sz));
  3167. total_size += sz;
  3168. sz = num_chain * ioc->req_sz; /* chain buffer pool size */
  3169. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d bytes, ChainDepth=%d\n",
  3170. ioc->name, ioc->req_sz, num_chain));
  3171. dinitprintk((KERN_INFO MYNAM ": %s.ChainBuffer sz=%d[%x] bytes num_chain=%d\n",
  3172. ioc->name, sz, sz, num_chain));
  3173. total_size += sz;
  3174. mem = pci_alloc_consistent(ioc->pcidev, total_size, &alloc_dma);
  3175. if (mem == NULL) {
  3176. printk(MYIOC_s_ERR_FMT "Unable to allocate Reply, Request, Chain Buffers!\n",
  3177. ioc->name);
  3178. goto out_fail;
  3179. }
  3180. dinitprintk((KERN_INFO MYNAM ": %s.Total alloc @ %p[%p], sz=%d[%x] bytes\n",
  3181. ioc->name, mem, (void *)(ulong)alloc_dma, total_size, total_size));
  3182. memset(mem, 0, total_size);
  3183. ioc->alloc_total += total_size;
  3184. ioc->alloc = mem;
  3185. ioc->alloc_dma = alloc_dma;
  3186. ioc->alloc_sz = total_size;
  3187. ioc->reply_frames = (MPT_FRAME_HDR *) mem;
  3188. ioc->reply_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3189. dinitprintk((KERN_INFO MYNAM ": %s ReplyBuffers @ %p[%p]\n",
  3190. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3191. alloc_dma += reply_sz;
  3192. mem += reply_sz;
  3193. /* Request FIFO - WE manage this! */
  3194. ioc->req_frames = (MPT_FRAME_HDR *) mem;
  3195. ioc->req_frames_dma = alloc_dma;
  3196. dinitprintk((KERN_INFO MYNAM ": %s RequestBuffers @ %p[%p]\n",
  3197. ioc->name, mem, (void *)(ulong)alloc_dma));
  3198. ioc->req_frames_low_dma = (u32) (alloc_dma & 0xFFFFFFFF);
  3199. #if defined(CONFIG_MTRR) && 0
  3200. /*
  3201. * Enable Write Combining MTRR for IOC's memory region.
  3202. * (at least as much as we can; "size and base must be
  3203. * multiples of 4 kiB"
  3204. */
  3205. ioc->mtrr_reg = mtrr_add(ioc->req_frames_dma,
  3206. sz,
  3207. MTRR_TYPE_WRCOMB, 1);
  3208. dprintk((MYIOC_s_INFO_FMT "MTRR region registered (base:size=%08x:%x)\n",
  3209. ioc->name, ioc->req_frames_dma, sz));
  3210. #endif
  3211. for (i = 0; i < ioc->req_depth; i++) {
  3212. alloc_dma += ioc->req_sz;
  3213. mem += ioc->req_sz;
  3214. }
  3215. ioc->ChainBuffer = mem;
  3216. ioc->ChainBufferDMA = alloc_dma;
  3217. dinitprintk((KERN_INFO MYNAM " :%s ChainBuffers @ %p(%p)\n",
  3218. ioc->name, ioc->ChainBuffer, (void *)(ulong)ioc->ChainBufferDMA));
  3219. /* Initialize the free chain Q.
  3220. */
  3221. INIT_LIST_HEAD(&ioc->FreeChainQ);
  3222. /* Post the chain buffers to the FreeChainQ.
  3223. */
  3224. mem = (u8 *)ioc->ChainBuffer;
  3225. for (i=0; i < num_chain; i++) {
  3226. mf = (MPT_FRAME_HDR *) mem;
  3227. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeChainQ);
  3228. mem += ioc->req_sz;
  3229. }
  3230. /* Initialize Request frames linked list
  3231. */
  3232. alloc_dma = ioc->req_frames_dma;
  3233. mem = (u8 *) ioc->req_frames;
  3234. spin_lock_irqsave(&ioc->FreeQlock, flags);
  3235. INIT_LIST_HEAD(&ioc->FreeQ);
  3236. for (i = 0; i < ioc->req_depth; i++) {
  3237. mf = (MPT_FRAME_HDR *) mem;
  3238. /* Queue REQUESTs *internally*! */
  3239. list_add_tail(&mf->u.frame.linkage.list, &ioc->FreeQ);
  3240. mem += ioc->req_sz;
  3241. }
  3242. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  3243. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3244. ioc->sense_buf_pool =
  3245. pci_alloc_consistent(ioc->pcidev, sz, &ioc->sense_buf_pool_dma);
  3246. if (ioc->sense_buf_pool == NULL) {
  3247. printk(MYIOC_s_ERR_FMT "Unable to allocate Sense Buffers!\n",
  3248. ioc->name);
  3249. goto out_fail;
  3250. }
  3251. ioc->sense_buf_low_dma = (u32) (ioc->sense_buf_pool_dma & 0xFFFFFFFF);
  3252. ioc->alloc_total += sz;
  3253. dinitprintk((KERN_INFO MYNAM ": %s.SenseBuffers @ %p[%p]\n",
  3254. ioc->name, ioc->sense_buf_pool, (void *)(ulong)ioc->sense_buf_pool_dma));
  3255. }
  3256. /* Post Reply frames to FIFO
  3257. */
  3258. alloc_dma = ioc->alloc_dma;
  3259. dinitprintk((KERN_INFO MYNAM ": %s.ReplyBuffers @ %p[%p]\n",
  3260. ioc->name, ioc->reply_frames, (void *)(ulong)alloc_dma));
  3261. for (i = 0; i < ioc->reply_depth; i++) {
  3262. /* Write each address to the IOC! */
  3263. CHIPREG_WRITE32(&ioc->chip->ReplyFifo, alloc_dma);
  3264. alloc_dma += ioc->reply_sz;
  3265. }
  3266. return 0;
  3267. out_fail:
  3268. if (ioc->alloc != NULL) {
  3269. sz = ioc->alloc_sz;
  3270. pci_free_consistent(ioc->pcidev,
  3271. sz,
  3272. ioc->alloc, ioc->alloc_dma);
  3273. ioc->reply_frames = NULL;
  3274. ioc->req_frames = NULL;
  3275. ioc->alloc_total -= sz;
  3276. }
  3277. if (ioc->sense_buf_pool != NULL) {
  3278. sz = (ioc->req_depth * MPT_SENSE_BUFFER_ALLOC);
  3279. pci_free_consistent(ioc->pcidev,
  3280. sz,
  3281. ioc->sense_buf_pool, ioc->sense_buf_pool_dma);
  3282. ioc->sense_buf_pool = NULL;
  3283. }
  3284. return -1;
  3285. }
  3286. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3287. /**
  3288. * mpt_handshake_req_reply_wait - Send MPT request to and receive reply
  3289. * from IOC via doorbell handshake method.
  3290. * @ioc: Pointer to MPT_ADAPTER structure
  3291. * @reqBytes: Size of the request in bytes
  3292. * @req: Pointer to MPT request frame
  3293. * @replyBytes: Expected size of the reply in bytes
  3294. * @u16reply: Pointer to area where reply should be written
  3295. * @maxwait: Max wait time for a reply (in seconds)
  3296. * @sleepFlag: Specifies whether the process can sleep
  3297. *
  3298. * NOTES: It is the callers responsibility to byte-swap fields in the
  3299. * request which are greater than 1 byte in size. It is also the
  3300. * callers responsibility to byte-swap response fields which are
  3301. * greater than 1 byte in size.
  3302. *
  3303. * Returns 0 for success, non-zero for failure.
  3304. */
  3305. static int
  3306. mpt_handshake_req_reply_wait(MPT_ADAPTER *ioc, int reqBytes, u32 *req,
  3307. int replyBytes, u16 *u16reply, int maxwait, int sleepFlag)
  3308. {
  3309. MPIDefaultReply_t *mptReply;
  3310. int failcnt = 0;
  3311. int t;
  3312. /*
  3313. * Get ready to cache a handshake reply
  3314. */
  3315. ioc->hs_reply_idx = 0;
  3316. mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3317. mptReply->MsgLength = 0;
  3318. /*
  3319. * Make sure there are no doorbells (WRITE 0 to IntStatus reg),
  3320. * then tell IOC that we want to handshake a request of N words.
  3321. * (WRITE u32val to Doorbell reg).
  3322. */
  3323. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3324. CHIPREG_WRITE32(&ioc->chip->Doorbell,
  3325. ((MPI_FUNCTION_HANDSHAKE<<MPI_DOORBELL_FUNCTION_SHIFT) |
  3326. ((reqBytes/4)<<MPI_DOORBELL_ADD_DWORDS_SHIFT)));
  3327. /*
  3328. * Wait for IOC's doorbell handshake int
  3329. */
  3330. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3331. failcnt++;
  3332. dhsprintk((MYIOC_s_INFO_FMT "HandShake request start reqBytes=%d, WaitCnt=%d%s\n",
  3333. ioc->name, reqBytes, t, failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3334. /* Read doorbell and check for active bit */
  3335. if (!(CHIPREG_READ32(&ioc->chip->Doorbell) & MPI_DOORBELL_ACTIVE))
  3336. return -1;
  3337. /*
  3338. * Clear doorbell int (WRITE 0 to IntStatus reg),
  3339. * then wait for IOC to ACKnowledge that it's ready for
  3340. * our handshake request.
  3341. */
  3342. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3343. if (!failcnt && (t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3344. failcnt++;
  3345. if (!failcnt) {
  3346. int ii;
  3347. u8 *req_as_bytes = (u8 *) req;
  3348. /*
  3349. * Stuff request words via doorbell handshake,
  3350. * with ACK from IOC for each.
  3351. */
  3352. for (ii = 0; !failcnt && ii < reqBytes/4; ii++) {
  3353. u32 word = ((req_as_bytes[(ii*4) + 0] << 0) |
  3354. (req_as_bytes[(ii*4) + 1] << 8) |
  3355. (req_as_bytes[(ii*4) + 2] << 16) |
  3356. (req_as_bytes[(ii*4) + 3] << 24));
  3357. CHIPREG_WRITE32(&ioc->chip->Doorbell, word);
  3358. if ((t = WaitForDoorbellAck(ioc, 5, sleepFlag)) < 0)
  3359. failcnt++;
  3360. }
  3361. dhsprintk((KERN_INFO MYNAM ": Handshake request frame (@%p) header\n", req));
  3362. DBG_DUMP_REQUEST_FRAME_HDR(req)
  3363. dhsprintk((MYIOC_s_INFO_FMT "HandShake request post done, WaitCnt=%d%s\n",
  3364. ioc->name, t, failcnt ? " - MISSING DOORBELL ACK!" : ""));
  3365. /*
  3366. * Wait for completion of doorbell handshake reply from the IOC
  3367. */
  3368. if (!failcnt && (t = WaitForDoorbellReply(ioc, maxwait, sleepFlag)) < 0)
  3369. failcnt++;
  3370. dhsprintk((MYIOC_s_INFO_FMT "HandShake reply count=%d%s\n",
  3371. ioc->name, t, failcnt ? " - MISSING DOORBELL REPLY!" : ""));
  3372. /*
  3373. * Copy out the cached reply...
  3374. */
  3375. for (ii=0; ii < min(replyBytes/2,mptReply->MsgLength*2); ii++)
  3376. u16reply[ii] = ioc->hs_reply[ii];
  3377. } else {
  3378. return -99;
  3379. }
  3380. return -failcnt;
  3381. }
  3382. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3383. /*
  3384. * WaitForDoorbellAck - Wait for IOC to clear the IOP_DOORBELL_STATUS bit
  3385. * in it's IntStatus register.
  3386. * @ioc: Pointer to MPT_ADAPTER structure
  3387. * @howlong: How long to wait (in seconds)
  3388. * @sleepFlag: Specifies whether the process can sleep
  3389. *
  3390. * This routine waits (up to ~2 seconds max) for IOC doorbell
  3391. * handshake ACKnowledge.
  3392. *
  3393. * Returns a negative value on failure, else wait loop count.
  3394. */
  3395. static int
  3396. WaitForDoorbellAck(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3397. {
  3398. int cntdn;
  3399. int count = 0;
  3400. u32 intstat=0;
  3401. cntdn = 1000 * howlong;
  3402. if (sleepFlag == CAN_SLEEP) {
  3403. while (--cntdn) {
  3404. msleep (1);
  3405. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3406. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3407. break;
  3408. count++;
  3409. }
  3410. } else {
  3411. while (--cntdn) {
  3412. mdelay (1);
  3413. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3414. if (! (intstat & MPI_HIS_IOP_DOORBELL_STATUS))
  3415. break;
  3416. count++;
  3417. }
  3418. }
  3419. if (cntdn) {
  3420. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell ACK (count=%d)\n",
  3421. ioc->name, count));
  3422. return count;
  3423. }
  3424. printk(MYIOC_s_ERR_FMT "Doorbell ACK timeout (count=%d), IntStatus=%x!\n",
  3425. ioc->name, count, intstat);
  3426. return -1;
  3427. }
  3428. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3429. /*
  3430. * WaitForDoorbellInt - Wait for IOC to set the HIS_DOORBELL_INTERRUPT bit
  3431. * in it's IntStatus register.
  3432. * @ioc: Pointer to MPT_ADAPTER structure
  3433. * @howlong: How long to wait (in seconds)
  3434. * @sleepFlag: Specifies whether the process can sleep
  3435. *
  3436. * This routine waits (up to ~2 seconds max) for IOC doorbell interrupt.
  3437. *
  3438. * Returns a negative value on failure, else wait loop count.
  3439. */
  3440. static int
  3441. WaitForDoorbellInt(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3442. {
  3443. int cntdn;
  3444. int count = 0;
  3445. u32 intstat=0;
  3446. cntdn = 1000 * howlong;
  3447. if (sleepFlag == CAN_SLEEP) {
  3448. while (--cntdn) {
  3449. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3450. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3451. break;
  3452. msleep(1);
  3453. count++;
  3454. }
  3455. } else {
  3456. while (--cntdn) {
  3457. intstat = CHIPREG_READ32(&ioc->chip->IntStatus);
  3458. if (intstat & MPI_HIS_DOORBELL_INTERRUPT)
  3459. break;
  3460. mdelay(1);
  3461. count++;
  3462. }
  3463. }
  3464. if (cntdn) {
  3465. dprintk((MYIOC_s_INFO_FMT "WaitForDoorbell INT (cnt=%d) howlong=%d\n",
  3466. ioc->name, count, howlong));
  3467. return count;
  3468. }
  3469. printk(MYIOC_s_ERR_FMT "Doorbell INT timeout (count=%d), IntStatus=%x!\n",
  3470. ioc->name, count, intstat);
  3471. return -1;
  3472. }
  3473. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3474. /*
  3475. * WaitForDoorbellReply - Wait for and capture a IOC handshake reply.
  3476. * @ioc: Pointer to MPT_ADAPTER structure
  3477. * @howlong: How long to wait (in seconds)
  3478. * @sleepFlag: Specifies whether the process can sleep
  3479. *
  3480. * This routine polls the IOC for a handshake reply, 16 bits at a time.
  3481. * Reply is cached to IOC private area large enough to hold a maximum
  3482. * of 128 bytes of reply data.
  3483. *
  3484. * Returns a negative value on failure, else size of reply in WORDS.
  3485. */
  3486. static int
  3487. WaitForDoorbellReply(MPT_ADAPTER *ioc, int howlong, int sleepFlag)
  3488. {
  3489. int u16cnt = 0;
  3490. int failcnt = 0;
  3491. int t;
  3492. u16 *hs_reply = ioc->hs_reply;
  3493. volatile MPIDefaultReply_t *mptReply = (MPIDefaultReply_t *) ioc->hs_reply;
  3494. u16 hword;
  3495. hs_reply[0] = hs_reply[1] = hs_reply[7] = 0;
  3496. /*
  3497. * Get first two u16's so we can look at IOC's intended reply MsgLength
  3498. */
  3499. u16cnt=0;
  3500. if ((t = WaitForDoorbellInt(ioc, howlong, sleepFlag)) < 0) {
  3501. failcnt++;
  3502. } else {
  3503. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3504. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3505. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3506. failcnt++;
  3507. else {
  3508. hs_reply[u16cnt++] = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3509. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3510. }
  3511. }
  3512. dhsprintk((MYIOC_s_INFO_FMT "WaitCnt=%d First handshake reply word=%08x%s\n",
  3513. ioc->name, t, le32_to_cpu(*(u32 *)hs_reply),
  3514. failcnt ? " - MISSING DOORBELL HANDSHAKE!" : ""));
  3515. /*
  3516. * If no error (and IOC said MsgLength is > 0), piece together
  3517. * reply 16 bits at a time.
  3518. */
  3519. for (u16cnt=2; !failcnt && u16cnt < (2 * mptReply->MsgLength); u16cnt++) {
  3520. if ((t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3521. failcnt++;
  3522. hword = le16_to_cpu(CHIPREG_READ32(&ioc->chip->Doorbell) & 0x0000FFFF);
  3523. /* don't overflow our IOC hs_reply[] buffer! */
  3524. if (u16cnt < sizeof(ioc->hs_reply) / sizeof(ioc->hs_reply[0]))
  3525. hs_reply[u16cnt] = hword;
  3526. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3527. }
  3528. if (!failcnt && (t = WaitForDoorbellInt(ioc, 5, sleepFlag)) < 0)
  3529. failcnt++;
  3530. CHIPREG_WRITE32(&ioc->chip->IntStatus, 0);
  3531. if (failcnt) {
  3532. printk(MYIOC_s_ERR_FMT "Handshake reply failure!\n",
  3533. ioc->name);
  3534. return -failcnt;
  3535. }
  3536. #if 0
  3537. else if (u16cnt != (2 * mptReply->MsgLength)) {
  3538. return -101;
  3539. }
  3540. else if ((mptReply->IOCStatus & MPI_IOCSTATUS_MASK) != MPI_IOCSTATUS_SUCCESS) {
  3541. return -102;
  3542. }
  3543. #endif
  3544. dhsprintk((MYIOC_s_INFO_FMT "Got Handshake reply:\n", ioc->name));
  3545. DBG_DUMP_REPLY_FRAME(mptReply)
  3546. dhsprintk((MYIOC_s_INFO_FMT "WaitForDoorbell REPLY WaitCnt=%d (sz=%d)\n",
  3547. ioc->name, t, u16cnt/2));
  3548. return u16cnt/2;
  3549. }
  3550. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3551. /*
  3552. * GetLanConfigPages - Fetch LANConfig pages.
  3553. * @ioc: Pointer to MPT_ADAPTER structure
  3554. *
  3555. * Return: 0 for success
  3556. * -ENOMEM if no memory available
  3557. * -EPERM if not allowed due to ISR context
  3558. * -EAGAIN if no msg frames currently available
  3559. * -EFAULT for non-successful reply or no reply (timeout)
  3560. */
  3561. static int
  3562. GetLanConfigPages(MPT_ADAPTER *ioc)
  3563. {
  3564. ConfigPageHeader_t hdr;
  3565. CONFIGPARMS cfg;
  3566. LANPage0_t *ppage0_alloc;
  3567. dma_addr_t page0_dma;
  3568. LANPage1_t *ppage1_alloc;
  3569. dma_addr_t page1_dma;
  3570. int rc = 0;
  3571. int data_sz;
  3572. int copy_sz;
  3573. /* Get LAN Page 0 header */
  3574. hdr.PageVersion = 0;
  3575. hdr.PageLength = 0;
  3576. hdr.PageNumber = 0;
  3577. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3578. cfg.cfghdr.hdr = &hdr;
  3579. cfg.physAddr = -1;
  3580. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3581. cfg.dir = 0;
  3582. cfg.pageAddr = 0;
  3583. cfg.timeout = 0;
  3584. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3585. return rc;
  3586. if (hdr.PageLength > 0) {
  3587. data_sz = hdr.PageLength * 4;
  3588. ppage0_alloc = (LANPage0_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page0_dma);
  3589. rc = -ENOMEM;
  3590. if (ppage0_alloc) {
  3591. memset((u8 *)ppage0_alloc, 0, data_sz);
  3592. cfg.physAddr = page0_dma;
  3593. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3594. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3595. /* save the data */
  3596. copy_sz = min_t(int, sizeof(LANPage0_t), data_sz);
  3597. memcpy(&ioc->lan_cnfg_page0, ppage0_alloc, copy_sz);
  3598. }
  3599. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage0_alloc, page0_dma);
  3600. /* FIXME!
  3601. * Normalize endianness of structure data,
  3602. * by byte-swapping all > 1 byte fields!
  3603. */
  3604. }
  3605. if (rc)
  3606. return rc;
  3607. }
  3608. /* Get LAN Page 1 header */
  3609. hdr.PageVersion = 0;
  3610. hdr.PageLength = 0;
  3611. hdr.PageNumber = 1;
  3612. hdr.PageType = MPI_CONFIG_PAGETYPE_LAN;
  3613. cfg.cfghdr.hdr = &hdr;
  3614. cfg.physAddr = -1;
  3615. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3616. cfg.dir = 0;
  3617. cfg.pageAddr = 0;
  3618. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3619. return rc;
  3620. if (hdr.PageLength == 0)
  3621. return 0;
  3622. data_sz = hdr.PageLength * 4;
  3623. rc = -ENOMEM;
  3624. ppage1_alloc = (LANPage1_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page1_dma);
  3625. if (ppage1_alloc) {
  3626. memset((u8 *)ppage1_alloc, 0, data_sz);
  3627. cfg.physAddr = page1_dma;
  3628. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3629. if ((rc = mpt_config(ioc, &cfg)) == 0) {
  3630. /* save the data */
  3631. copy_sz = min_t(int, sizeof(LANPage1_t), data_sz);
  3632. memcpy(&ioc->lan_cnfg_page1, ppage1_alloc, copy_sz);
  3633. }
  3634. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage1_alloc, page1_dma);
  3635. /* FIXME!
  3636. * Normalize endianness of structure data,
  3637. * by byte-swapping all > 1 byte fields!
  3638. */
  3639. }
  3640. return rc;
  3641. }
  3642. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3643. /*
  3644. * mptbase_sas_persist_operation - Perform operation on SAS Persitent Table
  3645. * @ioc: Pointer to MPT_ADAPTER structure
  3646. * @sas_address: 64bit SAS Address for operation.
  3647. * @target_id: specified target for operation
  3648. * @bus: specified bus for operation
  3649. * @persist_opcode: see below
  3650. *
  3651. * MPI_SAS_OP_CLEAR_NOT_PRESENT - Free all persist TargetID mappings for
  3652. * devices not currently present.
  3653. * MPI_SAS_OP_CLEAR_ALL_PERSISTENT - Clear al persist TargetID mappings
  3654. *
  3655. * NOTE: Don't use not this function during interrupt time.
  3656. *
  3657. * Returns: 0 for success, non-zero error
  3658. */
  3659. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3660. int
  3661. mptbase_sas_persist_operation(MPT_ADAPTER *ioc, u8 persist_opcode)
  3662. {
  3663. SasIoUnitControlRequest_t *sasIoUnitCntrReq;
  3664. SasIoUnitControlReply_t *sasIoUnitCntrReply;
  3665. MPT_FRAME_HDR *mf = NULL;
  3666. MPIHeader_t *mpi_hdr;
  3667. /* insure garbage is not sent to fw */
  3668. switch(persist_opcode) {
  3669. case MPI_SAS_OP_CLEAR_NOT_PRESENT:
  3670. case MPI_SAS_OP_CLEAR_ALL_PERSISTENT:
  3671. break;
  3672. default:
  3673. return -1;
  3674. break;
  3675. }
  3676. printk("%s: persist_opcode=%x\n",__FUNCTION__, persist_opcode);
  3677. /* Get a MF for this command.
  3678. */
  3679. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  3680. printk("%s: no msg frames!\n",__FUNCTION__);
  3681. return -1;
  3682. }
  3683. mpi_hdr = (MPIHeader_t *) mf;
  3684. sasIoUnitCntrReq = (SasIoUnitControlRequest_t *)mf;
  3685. memset(sasIoUnitCntrReq,0,sizeof(SasIoUnitControlRequest_t));
  3686. sasIoUnitCntrReq->Function = MPI_FUNCTION_SAS_IO_UNIT_CONTROL;
  3687. sasIoUnitCntrReq->MsgContext = mpi_hdr->MsgContext;
  3688. sasIoUnitCntrReq->Operation = persist_opcode;
  3689. init_timer(&ioc->persist_timer);
  3690. ioc->persist_timer.data = (unsigned long) ioc;
  3691. ioc->persist_timer.function = mpt_timer_expired;
  3692. ioc->persist_timer.expires = jiffies + HZ*10 /* 10 sec */;
  3693. ioc->persist_wait_done=0;
  3694. add_timer(&ioc->persist_timer);
  3695. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  3696. wait_event(mpt_waitq, ioc->persist_wait_done);
  3697. sasIoUnitCntrReply =
  3698. (SasIoUnitControlReply_t *)ioc->persist_reply_frame;
  3699. if (le16_to_cpu(sasIoUnitCntrReply->IOCStatus) != MPI_IOCSTATUS_SUCCESS) {
  3700. printk("%s: IOCStatus=0x%X IOCLogInfo=0x%X\n",
  3701. __FUNCTION__,
  3702. sasIoUnitCntrReply->IOCStatus,
  3703. sasIoUnitCntrReply->IOCLogInfo);
  3704. return -1;
  3705. }
  3706. printk("%s: success\n",__FUNCTION__);
  3707. return 0;
  3708. }
  3709. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3710. static void
  3711. mptbase_raid_process_event_data(MPT_ADAPTER *ioc,
  3712. MpiEventDataRaid_t * pRaidEventData)
  3713. {
  3714. int volume;
  3715. int reason;
  3716. int disk;
  3717. int status;
  3718. int flags;
  3719. int state;
  3720. volume = pRaidEventData->VolumeID;
  3721. reason = pRaidEventData->ReasonCode;
  3722. disk = pRaidEventData->PhysDiskNum;
  3723. status = le32_to_cpu(pRaidEventData->SettingsStatus);
  3724. flags = (status >> 0) & 0xff;
  3725. state = (status >> 8) & 0xff;
  3726. if (reason == MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED) {
  3727. return;
  3728. }
  3729. if ((reason >= MPI_EVENT_RAID_RC_PHYSDISK_CREATED &&
  3730. reason <= MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED) ||
  3731. (reason == MPI_EVENT_RAID_RC_SMART_DATA)) {
  3732. printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for PhysDisk %d\n",
  3733. ioc->name, disk);
  3734. } else {
  3735. printk(MYIOC_s_INFO_FMT "RAID STATUS CHANGE for VolumeID %d\n",
  3736. ioc->name, volume);
  3737. }
  3738. switch(reason) {
  3739. case MPI_EVENT_RAID_RC_VOLUME_CREATED:
  3740. printk(MYIOC_s_INFO_FMT " volume has been created\n",
  3741. ioc->name);
  3742. break;
  3743. case MPI_EVENT_RAID_RC_VOLUME_DELETED:
  3744. printk(MYIOC_s_INFO_FMT " volume has been deleted\n",
  3745. ioc->name);
  3746. break;
  3747. case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED:
  3748. printk(MYIOC_s_INFO_FMT " volume settings have been changed\n",
  3749. ioc->name);
  3750. break;
  3751. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED:
  3752. printk(MYIOC_s_INFO_FMT " volume is now %s%s%s%s\n",
  3753. ioc->name,
  3754. state == MPI_RAIDVOL0_STATUS_STATE_OPTIMAL
  3755. ? "optimal"
  3756. : state == MPI_RAIDVOL0_STATUS_STATE_DEGRADED
  3757. ? "degraded"
  3758. : state == MPI_RAIDVOL0_STATUS_STATE_FAILED
  3759. ? "failed"
  3760. : "state unknown",
  3761. flags & MPI_RAIDVOL0_STATUS_FLAG_ENABLED
  3762. ? ", enabled" : "",
  3763. flags & MPI_RAIDVOL0_STATUS_FLAG_QUIESCED
  3764. ? ", quiesced" : "",
  3765. flags & MPI_RAIDVOL0_STATUS_FLAG_RESYNC_IN_PROGRESS
  3766. ? ", resync in progress" : "" );
  3767. break;
  3768. case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED:
  3769. printk(MYIOC_s_INFO_FMT " volume membership of PhysDisk %d has changed\n",
  3770. ioc->name, disk);
  3771. break;
  3772. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED:
  3773. printk(MYIOC_s_INFO_FMT " PhysDisk has been created\n",
  3774. ioc->name);
  3775. break;
  3776. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED:
  3777. printk(MYIOC_s_INFO_FMT " PhysDisk has been deleted\n",
  3778. ioc->name);
  3779. break;
  3780. case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED:
  3781. printk(MYIOC_s_INFO_FMT " PhysDisk settings have been changed\n",
  3782. ioc->name);
  3783. break;
  3784. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED:
  3785. printk(MYIOC_s_INFO_FMT " PhysDisk is now %s%s%s\n",
  3786. ioc->name,
  3787. state == MPI_PHYSDISK0_STATUS_ONLINE
  3788. ? "online"
  3789. : state == MPI_PHYSDISK0_STATUS_MISSING
  3790. ? "missing"
  3791. : state == MPI_PHYSDISK0_STATUS_NOT_COMPATIBLE
  3792. ? "not compatible"
  3793. : state == MPI_PHYSDISK0_STATUS_FAILED
  3794. ? "failed"
  3795. : state == MPI_PHYSDISK0_STATUS_INITIALIZING
  3796. ? "initializing"
  3797. : state == MPI_PHYSDISK0_STATUS_OFFLINE_REQUESTED
  3798. ? "offline requested"
  3799. : state == MPI_PHYSDISK0_STATUS_FAILED_REQUESTED
  3800. ? "failed requested"
  3801. : state == MPI_PHYSDISK0_STATUS_OTHER_OFFLINE
  3802. ? "offline"
  3803. : "state unknown",
  3804. flags & MPI_PHYSDISK0_STATUS_FLAG_OUT_OF_SYNC
  3805. ? ", out of sync" : "",
  3806. flags & MPI_PHYSDISK0_STATUS_FLAG_QUIESCED
  3807. ? ", quiesced" : "" );
  3808. break;
  3809. case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED:
  3810. printk(MYIOC_s_INFO_FMT " Domain Validation needed for PhysDisk %d\n",
  3811. ioc->name, disk);
  3812. break;
  3813. case MPI_EVENT_RAID_RC_SMART_DATA:
  3814. printk(MYIOC_s_INFO_FMT " SMART data received, ASC/ASCQ = %02xh/%02xh\n",
  3815. ioc->name, pRaidEventData->ASC, pRaidEventData->ASCQ);
  3816. break;
  3817. case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED:
  3818. printk(MYIOC_s_INFO_FMT " replacement of PhysDisk %d has started\n",
  3819. ioc->name, disk);
  3820. break;
  3821. }
  3822. }
  3823. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3824. /*
  3825. * GetIoUnitPage2 - Retrieve BIOS version and boot order information.
  3826. * @ioc: Pointer to MPT_ADAPTER structure
  3827. *
  3828. * Returns: 0 for success
  3829. * -ENOMEM if no memory available
  3830. * -EPERM if not allowed due to ISR context
  3831. * -EAGAIN if no msg frames currently available
  3832. * -EFAULT for non-successful reply or no reply (timeout)
  3833. */
  3834. static int
  3835. GetIoUnitPage2(MPT_ADAPTER *ioc)
  3836. {
  3837. ConfigPageHeader_t hdr;
  3838. CONFIGPARMS cfg;
  3839. IOUnitPage2_t *ppage_alloc;
  3840. dma_addr_t page_dma;
  3841. int data_sz;
  3842. int rc;
  3843. /* Get the page header */
  3844. hdr.PageVersion = 0;
  3845. hdr.PageLength = 0;
  3846. hdr.PageNumber = 2;
  3847. hdr.PageType = MPI_CONFIG_PAGETYPE_IO_UNIT;
  3848. cfg.cfghdr.hdr = &hdr;
  3849. cfg.physAddr = -1;
  3850. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3851. cfg.dir = 0;
  3852. cfg.pageAddr = 0;
  3853. cfg.timeout = 0;
  3854. if ((rc = mpt_config(ioc, &cfg)) != 0)
  3855. return rc;
  3856. if (hdr.PageLength == 0)
  3857. return 0;
  3858. /* Read the config page */
  3859. data_sz = hdr.PageLength * 4;
  3860. rc = -ENOMEM;
  3861. ppage_alloc = (IOUnitPage2_t *) pci_alloc_consistent(ioc->pcidev, data_sz, &page_dma);
  3862. if (ppage_alloc) {
  3863. memset((u8 *)ppage_alloc, 0, data_sz);
  3864. cfg.physAddr = page_dma;
  3865. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3866. /* If Good, save data */
  3867. if ((rc = mpt_config(ioc, &cfg)) == 0)
  3868. ioc->biosVersion = le32_to_cpu(ppage_alloc->BiosVersion);
  3869. pci_free_consistent(ioc->pcidev, data_sz, (u8 *) ppage_alloc, page_dma);
  3870. }
  3871. return rc;
  3872. }
  3873. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  3874. /* mpt_GetScsiPortSettings - read SCSI Port Page 0 and 2
  3875. * @ioc: Pointer to a Adapter Strucutre
  3876. * @portnum: IOC port number
  3877. *
  3878. * Return: -EFAULT if read of config page header fails
  3879. * or if no nvram
  3880. * If read of SCSI Port Page 0 fails,
  3881. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3882. * Adapter settings: async, narrow
  3883. * Return 1
  3884. * If read of SCSI Port Page 2 fails,
  3885. * Adapter settings valid
  3886. * NVRAM = MPT_HOST_NVRAM_INVALID (0xFFFFFFFF)
  3887. * Return 1
  3888. * Else
  3889. * Both valid
  3890. * Return 0
  3891. * CHECK - what type of locking mechanisms should be used????
  3892. */
  3893. static int
  3894. mpt_GetScsiPortSettings(MPT_ADAPTER *ioc, int portnum)
  3895. {
  3896. u8 *pbuf;
  3897. dma_addr_t buf_dma;
  3898. CONFIGPARMS cfg;
  3899. ConfigPageHeader_t header;
  3900. int ii;
  3901. int data, rc = 0;
  3902. /* Allocate memory
  3903. */
  3904. if (!ioc->spi_data.nvram) {
  3905. int sz;
  3906. u8 *mem;
  3907. sz = MPT_MAX_SCSI_DEVICES * sizeof(int);
  3908. mem = kmalloc(sz, GFP_ATOMIC);
  3909. if (mem == NULL)
  3910. return -EFAULT;
  3911. ioc->spi_data.nvram = (int *) mem;
  3912. dprintk((MYIOC_s_INFO_FMT "SCSI device NVRAM settings @ %p, sz=%d\n",
  3913. ioc->name, ioc->spi_data.nvram, sz));
  3914. }
  3915. /* Invalidate NVRAM information
  3916. */
  3917. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  3918. ioc->spi_data.nvram[ii] = MPT_HOST_NVRAM_INVALID;
  3919. }
  3920. /* Read SPP0 header, allocate memory, then read page.
  3921. */
  3922. header.PageVersion = 0;
  3923. header.PageLength = 0;
  3924. header.PageNumber = 0;
  3925. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3926. cfg.cfghdr.hdr = &header;
  3927. cfg.physAddr = -1;
  3928. cfg.pageAddr = portnum;
  3929. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3930. cfg.dir = 0;
  3931. cfg.timeout = 0; /* use default */
  3932. if (mpt_config(ioc, &cfg) != 0)
  3933. return -EFAULT;
  3934. if (header.PageLength > 0) {
  3935. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  3936. if (pbuf) {
  3937. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  3938. cfg.physAddr = buf_dma;
  3939. if (mpt_config(ioc, &cfg) != 0) {
  3940. ioc->spi_data.maxBusWidth = MPT_NARROW;
  3941. ioc->spi_data.maxSyncOffset = 0;
  3942. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3943. ioc->spi_data.busType = MPT_HOST_BUS_UNKNOWN;
  3944. rc = 1;
  3945. ddvprintk((MYIOC_s_INFO_FMT "Unable to read PortPage0 minSyncFactor=%x\n",
  3946. ioc->name, ioc->spi_data.minSyncFactor));
  3947. } else {
  3948. /* Save the Port Page 0 data
  3949. */
  3950. SCSIPortPage0_t *pPP0 = (SCSIPortPage0_t *) pbuf;
  3951. pPP0->Capabilities = le32_to_cpu(pPP0->Capabilities);
  3952. pPP0->PhysicalInterface = le32_to_cpu(pPP0->PhysicalInterface);
  3953. if ( (pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_QAS) == 0 ) {
  3954. ioc->spi_data.noQas |= MPT_TARGET_NO_NEGO_QAS;
  3955. ddvprintk((KERN_INFO MYNAM " :%s noQas due to Capabilities=%x\n",
  3956. ioc->name, pPP0->Capabilities));
  3957. }
  3958. ioc->spi_data.maxBusWidth = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_WIDE ? 1 : 0;
  3959. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MAX_SYNC_OFFSET_MASK;
  3960. if (data) {
  3961. ioc->spi_data.maxSyncOffset = (u8) (data >> 16);
  3962. data = pPP0->Capabilities & MPI_SCSIPORTPAGE0_CAP_MIN_SYNC_PERIOD_MASK;
  3963. ioc->spi_data.minSyncFactor = (u8) (data >> 8);
  3964. ddvprintk((MYIOC_s_INFO_FMT "PortPage0 minSyncFactor=%x\n",
  3965. ioc->name, ioc->spi_data.minSyncFactor));
  3966. } else {
  3967. ioc->spi_data.maxSyncOffset = 0;
  3968. ioc->spi_data.minSyncFactor = MPT_ASYNC;
  3969. }
  3970. ioc->spi_data.busType = pPP0->PhysicalInterface & MPI_SCSIPORTPAGE0_PHY_SIGNAL_TYPE_MASK;
  3971. /* Update the minSyncFactor based on bus type.
  3972. */
  3973. if ((ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_HVD) ||
  3974. (ioc->spi_data.busType == MPI_SCSIPORTPAGE0_PHY_SIGNAL_SE)) {
  3975. if (ioc->spi_data.minSyncFactor < MPT_ULTRA) {
  3976. ioc->spi_data.minSyncFactor = MPT_ULTRA;
  3977. ddvprintk((MYIOC_s_INFO_FMT "HVD or SE detected, minSyncFactor=%x\n",
  3978. ioc->name, ioc->spi_data.minSyncFactor));
  3979. }
  3980. }
  3981. }
  3982. if (pbuf) {
  3983. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  3984. }
  3985. }
  3986. }
  3987. /* SCSI Port Page 2 - Read the header then the page.
  3988. */
  3989. header.PageVersion = 0;
  3990. header.PageLength = 0;
  3991. header.PageNumber = 2;
  3992. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_PORT;
  3993. cfg.cfghdr.hdr = &header;
  3994. cfg.physAddr = -1;
  3995. cfg.pageAddr = portnum;
  3996. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  3997. cfg.dir = 0;
  3998. if (mpt_config(ioc, &cfg) != 0)
  3999. return -EFAULT;
  4000. if (header.PageLength > 0) {
  4001. /* Allocate memory and read SCSI Port Page 2
  4002. */
  4003. pbuf = pci_alloc_consistent(ioc->pcidev, header.PageLength * 4, &buf_dma);
  4004. if (pbuf) {
  4005. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_NVRAM;
  4006. cfg.physAddr = buf_dma;
  4007. if (mpt_config(ioc, &cfg) != 0) {
  4008. /* Nvram data is left with INVALID mark
  4009. */
  4010. rc = 1;
  4011. } else {
  4012. SCSIPortPage2_t *pPP2 = (SCSIPortPage2_t *) pbuf;
  4013. MpiDeviceInfo_t *pdevice = NULL;
  4014. /*
  4015. * Save "Set to Avoid SCSI Bus Resets" flag
  4016. */
  4017. ioc->spi_data.bus_reset =
  4018. (le32_to_cpu(pPP2->PortFlags) &
  4019. MPI_SCSIPORTPAGE2_PORT_FLAGS_AVOID_SCSI_RESET) ?
  4020. 0 : 1 ;
  4021. /* Save the Port Page 2 data
  4022. * (reformat into a 32bit quantity)
  4023. */
  4024. data = le32_to_cpu(pPP2->PortFlags) & MPI_SCSIPORTPAGE2_PORT_FLAGS_DV_MASK;
  4025. ioc->spi_data.PortFlags = data;
  4026. for (ii=0; ii < MPT_MAX_SCSI_DEVICES; ii++) {
  4027. pdevice = &pPP2->DeviceSettings[ii];
  4028. data = (le16_to_cpu(pdevice->DeviceFlags) << 16) |
  4029. (pdevice->SyncFactor << 8) | pdevice->Timeout;
  4030. ioc->spi_data.nvram[ii] = data;
  4031. }
  4032. }
  4033. pci_free_consistent(ioc->pcidev, header.PageLength * 4, pbuf, buf_dma);
  4034. }
  4035. }
  4036. /* Update Adapter limits with those from NVRAM
  4037. * Comment: Don't need to do this. Target performance
  4038. * parameters will never exceed the adapters limits.
  4039. */
  4040. return rc;
  4041. }
  4042. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4043. /* mpt_readScsiDevicePageHeaders - save version and length of SDP1
  4044. * @ioc: Pointer to a Adapter Strucutre
  4045. * @portnum: IOC port number
  4046. *
  4047. * Return: -EFAULT if read of config page header fails
  4048. * or 0 if success.
  4049. */
  4050. static int
  4051. mpt_readScsiDevicePageHeaders(MPT_ADAPTER *ioc, int portnum)
  4052. {
  4053. CONFIGPARMS cfg;
  4054. ConfigPageHeader_t header;
  4055. /* Read the SCSI Device Page 1 header
  4056. */
  4057. header.PageVersion = 0;
  4058. header.PageLength = 0;
  4059. header.PageNumber = 1;
  4060. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  4061. cfg.cfghdr.hdr = &header;
  4062. cfg.physAddr = -1;
  4063. cfg.pageAddr = portnum;
  4064. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4065. cfg.dir = 0;
  4066. cfg.timeout = 0;
  4067. if (mpt_config(ioc, &cfg) != 0)
  4068. return -EFAULT;
  4069. ioc->spi_data.sdp1version = cfg.cfghdr.hdr->PageVersion;
  4070. ioc->spi_data.sdp1length = cfg.cfghdr.hdr->PageLength;
  4071. header.PageVersion = 0;
  4072. header.PageLength = 0;
  4073. header.PageNumber = 0;
  4074. header.PageType = MPI_CONFIG_PAGETYPE_SCSI_DEVICE;
  4075. if (mpt_config(ioc, &cfg) != 0)
  4076. return -EFAULT;
  4077. ioc->spi_data.sdp0version = cfg.cfghdr.hdr->PageVersion;
  4078. ioc->spi_data.sdp0length = cfg.cfghdr.hdr->PageLength;
  4079. dcprintk((MYIOC_s_INFO_FMT "Headers: 0: version %d length %d\n",
  4080. ioc->name, ioc->spi_data.sdp0version, ioc->spi_data.sdp0length));
  4081. dcprintk((MYIOC_s_INFO_FMT "Headers: 1: version %d length %d\n",
  4082. ioc->name, ioc->spi_data.sdp1version, ioc->spi_data.sdp1length));
  4083. return 0;
  4084. }
  4085. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4086. /**
  4087. * mpt_findImVolumes - Identify IDs of hidden disks and RAID Volumes
  4088. * @ioc: Pointer to a Adapter Strucutre
  4089. * @portnum: IOC port number
  4090. *
  4091. * Return:
  4092. * 0 on success
  4093. * -EFAULT if read of config page header fails or data pointer not NULL
  4094. * -ENOMEM if pci_alloc failed
  4095. */
  4096. int
  4097. mpt_findImVolumes(MPT_ADAPTER *ioc)
  4098. {
  4099. IOCPage2_t *pIoc2;
  4100. u8 *mem;
  4101. ConfigPageIoc2RaidVol_t *pIocRv;
  4102. dma_addr_t ioc2_dma;
  4103. CONFIGPARMS cfg;
  4104. ConfigPageHeader_t header;
  4105. int jj;
  4106. int rc = 0;
  4107. int iocpage2sz;
  4108. u8 nVols, nPhys;
  4109. u8 vid, vbus, vioc;
  4110. /* Read IOCP2 header then the page.
  4111. */
  4112. header.PageVersion = 0;
  4113. header.PageLength = 0;
  4114. header.PageNumber = 2;
  4115. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  4116. cfg.cfghdr.hdr = &header;
  4117. cfg.physAddr = -1;
  4118. cfg.pageAddr = 0;
  4119. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4120. cfg.dir = 0;
  4121. cfg.timeout = 0;
  4122. if (mpt_config(ioc, &cfg) != 0)
  4123. return -EFAULT;
  4124. if (header.PageLength == 0)
  4125. return -EFAULT;
  4126. iocpage2sz = header.PageLength * 4;
  4127. pIoc2 = pci_alloc_consistent(ioc->pcidev, iocpage2sz, &ioc2_dma);
  4128. if (!pIoc2)
  4129. return -ENOMEM;
  4130. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4131. cfg.physAddr = ioc2_dma;
  4132. if (mpt_config(ioc, &cfg) != 0)
  4133. goto done_and_free;
  4134. if ( (mem = (u8 *)ioc->raid_data.pIocPg2) == NULL ) {
  4135. mem = kmalloc(iocpage2sz, GFP_ATOMIC);
  4136. if (mem) {
  4137. ioc->raid_data.pIocPg2 = (IOCPage2_t *) mem;
  4138. } else {
  4139. goto done_and_free;
  4140. }
  4141. }
  4142. memcpy(mem, (u8 *)pIoc2, iocpage2sz);
  4143. /* Identify RAID Volume Id's */
  4144. nVols = pIoc2->NumActiveVolumes;
  4145. if ( nVols == 0) {
  4146. /* No RAID Volume.
  4147. */
  4148. goto done_and_free;
  4149. } else {
  4150. /* At least 1 RAID Volume
  4151. */
  4152. pIocRv = pIoc2->RaidVolume;
  4153. ioc->raid_data.isRaid = 0;
  4154. for (jj = 0; jj < nVols; jj++, pIocRv++) {
  4155. vid = pIocRv->VolumeID;
  4156. vbus = pIocRv->VolumeBus;
  4157. vioc = pIocRv->VolumeIOC;
  4158. /* find the match
  4159. */
  4160. if (vbus == 0) {
  4161. ioc->raid_data.isRaid |= (1 << vid);
  4162. } else {
  4163. /* Error! Always bus 0
  4164. */
  4165. }
  4166. }
  4167. }
  4168. /* Identify Hidden Physical Disk Id's */
  4169. nPhys = pIoc2->NumActivePhysDisks;
  4170. if (nPhys == 0) {
  4171. /* No physical disks.
  4172. */
  4173. } else {
  4174. mpt_read_ioc_pg_3(ioc);
  4175. }
  4176. done_and_free:
  4177. pci_free_consistent(ioc->pcidev, iocpage2sz, pIoc2, ioc2_dma);
  4178. return rc;
  4179. }
  4180. static int
  4181. mpt_read_ioc_pg_3(MPT_ADAPTER *ioc)
  4182. {
  4183. IOCPage3_t *pIoc3;
  4184. u8 *mem;
  4185. CONFIGPARMS cfg;
  4186. ConfigPageHeader_t header;
  4187. dma_addr_t ioc3_dma;
  4188. int iocpage3sz = 0;
  4189. /* Free the old page
  4190. */
  4191. kfree(ioc->raid_data.pIocPg3);
  4192. ioc->raid_data.pIocPg3 = NULL;
  4193. /* There is at least one physical disk.
  4194. * Read and save IOC Page 3
  4195. */
  4196. header.PageVersion = 0;
  4197. header.PageLength = 0;
  4198. header.PageNumber = 3;
  4199. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  4200. cfg.cfghdr.hdr = &header;
  4201. cfg.physAddr = -1;
  4202. cfg.pageAddr = 0;
  4203. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4204. cfg.dir = 0;
  4205. cfg.timeout = 0;
  4206. if (mpt_config(ioc, &cfg) != 0)
  4207. return 0;
  4208. if (header.PageLength == 0)
  4209. return 0;
  4210. /* Read Header good, alloc memory
  4211. */
  4212. iocpage3sz = header.PageLength * 4;
  4213. pIoc3 = pci_alloc_consistent(ioc->pcidev, iocpage3sz, &ioc3_dma);
  4214. if (!pIoc3)
  4215. return 0;
  4216. /* Read the Page and save the data
  4217. * into malloc'd memory.
  4218. */
  4219. cfg.physAddr = ioc3_dma;
  4220. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4221. if (mpt_config(ioc, &cfg) == 0) {
  4222. mem = kmalloc(iocpage3sz, GFP_ATOMIC);
  4223. if (mem) {
  4224. memcpy(mem, (u8 *)pIoc3, iocpage3sz);
  4225. ioc->raid_data.pIocPg3 = (IOCPage3_t *) mem;
  4226. }
  4227. }
  4228. pci_free_consistent(ioc->pcidev, iocpage3sz, pIoc3, ioc3_dma);
  4229. return 0;
  4230. }
  4231. static void
  4232. mpt_read_ioc_pg_4(MPT_ADAPTER *ioc)
  4233. {
  4234. IOCPage4_t *pIoc4;
  4235. CONFIGPARMS cfg;
  4236. ConfigPageHeader_t header;
  4237. dma_addr_t ioc4_dma;
  4238. int iocpage4sz;
  4239. /* Read and save IOC Page 4
  4240. */
  4241. header.PageVersion = 0;
  4242. header.PageLength = 0;
  4243. header.PageNumber = 4;
  4244. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  4245. cfg.cfghdr.hdr = &header;
  4246. cfg.physAddr = -1;
  4247. cfg.pageAddr = 0;
  4248. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4249. cfg.dir = 0;
  4250. cfg.timeout = 0;
  4251. if (mpt_config(ioc, &cfg) != 0)
  4252. return;
  4253. if (header.PageLength == 0)
  4254. return;
  4255. if ( (pIoc4 = ioc->spi_data.pIocPg4) == NULL ) {
  4256. iocpage4sz = (header.PageLength + 4) * 4; /* Allow 4 additional SEP's */
  4257. pIoc4 = pci_alloc_consistent(ioc->pcidev, iocpage4sz, &ioc4_dma);
  4258. if (!pIoc4)
  4259. return;
  4260. ioc->alloc_total += iocpage4sz;
  4261. } else {
  4262. ioc4_dma = ioc->spi_data.IocPg4_dma;
  4263. iocpage4sz = ioc->spi_data.IocPg4Sz;
  4264. }
  4265. /* Read the Page into dma memory.
  4266. */
  4267. cfg.physAddr = ioc4_dma;
  4268. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4269. if (mpt_config(ioc, &cfg) == 0) {
  4270. ioc->spi_data.pIocPg4 = (IOCPage4_t *) pIoc4;
  4271. ioc->spi_data.IocPg4_dma = ioc4_dma;
  4272. ioc->spi_data.IocPg4Sz = iocpage4sz;
  4273. } else {
  4274. pci_free_consistent(ioc->pcidev, iocpage4sz, pIoc4, ioc4_dma);
  4275. ioc->spi_data.pIocPg4 = NULL;
  4276. ioc->alloc_total -= iocpage4sz;
  4277. }
  4278. }
  4279. static void
  4280. mpt_read_ioc_pg_1(MPT_ADAPTER *ioc)
  4281. {
  4282. IOCPage1_t *pIoc1;
  4283. CONFIGPARMS cfg;
  4284. ConfigPageHeader_t header;
  4285. dma_addr_t ioc1_dma;
  4286. int iocpage1sz = 0;
  4287. u32 tmp;
  4288. /* Check the Coalescing Timeout in IOC Page 1
  4289. */
  4290. header.PageVersion = 0;
  4291. header.PageLength = 0;
  4292. header.PageNumber = 1;
  4293. header.PageType = MPI_CONFIG_PAGETYPE_IOC;
  4294. cfg.cfghdr.hdr = &header;
  4295. cfg.physAddr = -1;
  4296. cfg.pageAddr = 0;
  4297. cfg.action = MPI_CONFIG_ACTION_PAGE_HEADER;
  4298. cfg.dir = 0;
  4299. cfg.timeout = 0;
  4300. if (mpt_config(ioc, &cfg) != 0)
  4301. return;
  4302. if (header.PageLength == 0)
  4303. return;
  4304. /* Read Header good, alloc memory
  4305. */
  4306. iocpage1sz = header.PageLength * 4;
  4307. pIoc1 = pci_alloc_consistent(ioc->pcidev, iocpage1sz, &ioc1_dma);
  4308. if (!pIoc1)
  4309. return;
  4310. /* Read the Page and check coalescing timeout
  4311. */
  4312. cfg.physAddr = ioc1_dma;
  4313. cfg.action = MPI_CONFIG_ACTION_PAGE_READ_CURRENT;
  4314. if (mpt_config(ioc, &cfg) == 0) {
  4315. tmp = le32_to_cpu(pIoc1->Flags) & MPI_IOCPAGE1_REPLY_COALESCING;
  4316. if (tmp == MPI_IOCPAGE1_REPLY_COALESCING) {
  4317. tmp = le32_to_cpu(pIoc1->CoalescingTimeout);
  4318. dprintk((MYIOC_s_INFO_FMT "Coalescing Enabled Timeout = %d\n",
  4319. ioc->name, tmp));
  4320. if (tmp > MPT_COALESCING_TIMEOUT) {
  4321. pIoc1->CoalescingTimeout = cpu_to_le32(MPT_COALESCING_TIMEOUT);
  4322. /* Write NVRAM and current
  4323. */
  4324. cfg.dir = 1;
  4325. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_CURRENT;
  4326. if (mpt_config(ioc, &cfg) == 0) {
  4327. dprintk((MYIOC_s_INFO_FMT "Reset Current Coalescing Timeout to = %d\n",
  4328. ioc->name, MPT_COALESCING_TIMEOUT));
  4329. cfg.action = MPI_CONFIG_ACTION_PAGE_WRITE_NVRAM;
  4330. if (mpt_config(ioc, &cfg) == 0) {
  4331. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout to = %d\n",
  4332. ioc->name, MPT_COALESCING_TIMEOUT));
  4333. } else {
  4334. dprintk((MYIOC_s_INFO_FMT "Reset NVRAM Coalescing Timeout Failed\n",
  4335. ioc->name));
  4336. }
  4337. } else {
  4338. dprintk((MYIOC_s_WARN_FMT "Reset of Current Coalescing Timeout Failed!\n",
  4339. ioc->name));
  4340. }
  4341. }
  4342. } else {
  4343. dprintk((MYIOC_s_WARN_FMT "Coalescing Disabled\n", ioc->name));
  4344. }
  4345. }
  4346. pci_free_consistent(ioc->pcidev, iocpage1sz, pIoc1, ioc1_dma);
  4347. return;
  4348. }
  4349. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4350. /*
  4351. * SendEventNotification - Send EventNotification (on or off) request
  4352. * to MPT adapter.
  4353. * @ioc: Pointer to MPT_ADAPTER structure
  4354. * @EvSwitch: Event switch flags
  4355. */
  4356. static int
  4357. SendEventNotification(MPT_ADAPTER *ioc, u8 EvSwitch)
  4358. {
  4359. EventNotification_t *evnp;
  4360. evnp = (EventNotification_t *) mpt_get_msg_frame(mpt_base_index, ioc);
  4361. if (evnp == NULL) {
  4362. devtverboseprintk((MYIOC_s_WARN_FMT "Unable to allocate event request frame!\n",
  4363. ioc->name));
  4364. return 0;
  4365. }
  4366. memset(evnp, 0, sizeof(*evnp));
  4367. devtverboseprintk((MYIOC_s_INFO_FMT "Sending EventNotification (%d) request %p\n", ioc->name, EvSwitch, evnp));
  4368. evnp->Function = MPI_FUNCTION_EVENT_NOTIFICATION;
  4369. evnp->ChainOffset = 0;
  4370. evnp->MsgFlags = 0;
  4371. evnp->Switch = EvSwitch;
  4372. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)evnp);
  4373. return 0;
  4374. }
  4375. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4376. /**
  4377. * SendEventAck - Send EventAck request to MPT adapter.
  4378. * @ioc: Pointer to MPT_ADAPTER structure
  4379. * @evnp: Pointer to original EventNotification request
  4380. */
  4381. static int
  4382. SendEventAck(MPT_ADAPTER *ioc, EventNotificationReply_t *evnp)
  4383. {
  4384. EventAck_t *pAck;
  4385. if ((pAck = (EventAck_t *) mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4386. dfailprintk((MYIOC_s_WARN_FMT "%s, no msg frames!!\n",
  4387. ioc->name,__FUNCTION__));
  4388. return -1;
  4389. }
  4390. devtverboseprintk((MYIOC_s_INFO_FMT "Sending EventAck\n", ioc->name));
  4391. pAck->Function = MPI_FUNCTION_EVENT_ACK;
  4392. pAck->ChainOffset = 0;
  4393. pAck->Reserved[0] = pAck->Reserved[1] = 0;
  4394. pAck->MsgFlags = 0;
  4395. pAck->Reserved1[0] = pAck->Reserved1[1] = pAck->Reserved1[2] = 0;
  4396. pAck->Event = evnp->Event;
  4397. pAck->EventContext = evnp->EventContext;
  4398. mpt_put_msg_frame(mpt_base_index, ioc, (MPT_FRAME_HDR *)pAck);
  4399. return 0;
  4400. }
  4401. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4402. /**
  4403. * mpt_config - Generic function to issue config message
  4404. * @ioc - Pointer to an adapter structure
  4405. * @cfg - Pointer to a configuration structure. Struct contains
  4406. * action, page address, direction, physical address
  4407. * and pointer to a configuration page header
  4408. * Page header is updated.
  4409. *
  4410. * Returns 0 for success
  4411. * -EPERM if not allowed due to ISR context
  4412. * -EAGAIN if no msg frames currently available
  4413. * -EFAULT for non-successful reply or no reply (timeout)
  4414. */
  4415. int
  4416. mpt_config(MPT_ADAPTER *ioc, CONFIGPARMS *pCfg)
  4417. {
  4418. Config_t *pReq;
  4419. ConfigExtendedPageHeader_t *pExtHdr = NULL;
  4420. MPT_FRAME_HDR *mf;
  4421. unsigned long flags;
  4422. int ii, rc;
  4423. int flagsLength;
  4424. int in_isr;
  4425. /* Prevent calling wait_event() (below), if caller happens
  4426. * to be in ISR context, because that is fatal!
  4427. */
  4428. in_isr = in_interrupt();
  4429. if (in_isr) {
  4430. dcprintk((MYIOC_s_WARN_FMT "Config request not allowed in ISR context!\n",
  4431. ioc->name));
  4432. return -EPERM;
  4433. }
  4434. /* Get and Populate a free Frame
  4435. */
  4436. if ((mf = mpt_get_msg_frame(mpt_base_index, ioc)) == NULL) {
  4437. dcprintk((MYIOC_s_WARN_FMT "mpt_config: no msg frames!\n",
  4438. ioc->name));
  4439. return -EAGAIN;
  4440. }
  4441. pReq = (Config_t *)mf;
  4442. pReq->Action = pCfg->action;
  4443. pReq->Reserved = 0;
  4444. pReq->ChainOffset = 0;
  4445. pReq->Function = MPI_FUNCTION_CONFIG;
  4446. /* Assume page type is not extended and clear "reserved" fields. */
  4447. pReq->ExtPageLength = 0;
  4448. pReq->ExtPageType = 0;
  4449. pReq->MsgFlags = 0;
  4450. for (ii=0; ii < 8; ii++)
  4451. pReq->Reserved2[ii] = 0;
  4452. pReq->Header.PageVersion = pCfg->cfghdr.hdr->PageVersion;
  4453. pReq->Header.PageLength = pCfg->cfghdr.hdr->PageLength;
  4454. pReq->Header.PageNumber = pCfg->cfghdr.hdr->PageNumber;
  4455. pReq->Header.PageType = (pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK);
  4456. if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
  4457. pExtHdr = (ConfigExtendedPageHeader_t *)pCfg->cfghdr.ehdr;
  4458. pReq->ExtPageLength = cpu_to_le16(pExtHdr->ExtPageLength);
  4459. pReq->ExtPageType = pExtHdr->ExtPageType;
  4460. pReq->Header.PageType = MPI_CONFIG_PAGETYPE_EXTENDED;
  4461. /* Page Length must be treated as a reserved field for the extended header. */
  4462. pReq->Header.PageLength = 0;
  4463. }
  4464. pReq->PageAddress = cpu_to_le32(pCfg->pageAddr);
  4465. /* Add a SGE to the config request.
  4466. */
  4467. if (pCfg->dir)
  4468. flagsLength = MPT_SGE_FLAGS_SSIMPLE_WRITE;
  4469. else
  4470. flagsLength = MPT_SGE_FLAGS_SSIMPLE_READ;
  4471. if ((pCfg->cfghdr.hdr->PageType & MPI_CONFIG_PAGETYPE_MASK) == MPI_CONFIG_PAGETYPE_EXTENDED) {
  4472. flagsLength |= pExtHdr->ExtPageLength * 4;
  4473. dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
  4474. ioc->name, pReq->ExtPageType, pReq->Header.PageNumber, pReq->Action));
  4475. }
  4476. else {
  4477. flagsLength |= pCfg->cfghdr.hdr->PageLength * 4;
  4478. dcprintk((MYIOC_s_INFO_FMT "Sending Config request type %d, page %d and action %d\n",
  4479. ioc->name, pReq->Header.PageType, pReq->Header.PageNumber, pReq->Action));
  4480. }
  4481. mpt_add_sge((char *)&pReq->PageBufferSGE, flagsLength, pCfg->physAddr);
  4482. /* Append pCfg pointer to end of mf
  4483. */
  4484. *((void **) (((u8 *) mf) + (ioc->req_sz - sizeof(void *)))) = (void *) pCfg;
  4485. /* Initalize the timer
  4486. */
  4487. init_timer(&pCfg->timer);
  4488. pCfg->timer.data = (unsigned long) ioc;
  4489. pCfg->timer.function = mpt_timer_expired;
  4490. pCfg->wait_done = 0;
  4491. /* Set the timer; ensure 10 second minimum */
  4492. if (pCfg->timeout < 10)
  4493. pCfg->timer.expires = jiffies + HZ*10;
  4494. else
  4495. pCfg->timer.expires = jiffies + HZ*pCfg->timeout;
  4496. /* Add to end of Q, set timer and then issue this command */
  4497. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4498. list_add_tail(&pCfg->linkage, &ioc->configQ);
  4499. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4500. add_timer(&pCfg->timer);
  4501. mpt_put_msg_frame(mpt_base_index, ioc, mf);
  4502. wait_event(mpt_waitq, pCfg->wait_done);
  4503. /* mf has been freed - do not access */
  4504. rc = pCfg->status;
  4505. return rc;
  4506. }
  4507. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4508. /*
  4509. * mpt_timer_expired - Call back for timer process.
  4510. * Used only internal config functionality.
  4511. * @data: Pointer to MPT_SCSI_HOST recast as an unsigned long
  4512. */
  4513. static void
  4514. mpt_timer_expired(unsigned long data)
  4515. {
  4516. MPT_ADAPTER *ioc = (MPT_ADAPTER *) data;
  4517. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired! \n", ioc->name));
  4518. /* Perform a FW reload */
  4519. if (mpt_HardResetHandler(ioc, NO_SLEEP) < 0)
  4520. printk(MYIOC_s_WARN_FMT "Firmware Reload FAILED!\n", ioc->name);
  4521. /* No more processing.
  4522. * Hard reset clean-up will wake up
  4523. * process and free all resources.
  4524. */
  4525. dcprintk((MYIOC_s_WARN_FMT "mpt_timer_expired complete!\n", ioc->name));
  4526. return;
  4527. }
  4528. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4529. /*
  4530. * mpt_ioc_reset - Base cleanup for hard reset
  4531. * @ioc: Pointer to the adapter structure
  4532. * @reset_phase: Indicates pre- or post-reset functionality
  4533. *
  4534. * Remark: Free's resources with internally generated commands.
  4535. */
  4536. static int
  4537. mpt_ioc_reset(MPT_ADAPTER *ioc, int reset_phase)
  4538. {
  4539. CONFIGPARMS *pCfg;
  4540. unsigned long flags;
  4541. dprintk((KERN_WARNING MYNAM
  4542. ": IOC %s_reset routed to MPT base driver!\n",
  4543. reset_phase==MPT_IOC_SETUP_RESET ? "setup" : (
  4544. reset_phase==MPT_IOC_PRE_RESET ? "pre" : "post")));
  4545. if (reset_phase == MPT_IOC_SETUP_RESET) {
  4546. ;
  4547. } else if (reset_phase == MPT_IOC_PRE_RESET) {
  4548. /* If the internal config Q is not empty -
  4549. * delete timer. MF resources will be freed when
  4550. * the FIFO's are primed.
  4551. */
  4552. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4553. list_for_each_entry(pCfg, &ioc->configQ, linkage)
  4554. del_timer(&pCfg->timer);
  4555. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4556. } else {
  4557. CONFIGPARMS *pNext;
  4558. /* Search the configQ for internal commands.
  4559. * Flush the Q, and wake up all suspended threads.
  4560. */
  4561. spin_lock_irqsave(&ioc->FreeQlock, flags);
  4562. list_for_each_entry_safe(pCfg, pNext, &ioc->configQ, linkage) {
  4563. list_del(&pCfg->linkage);
  4564. pCfg->status = MPT_CONFIG_ERROR;
  4565. pCfg->wait_done = 1;
  4566. wake_up(&mpt_waitq);
  4567. }
  4568. spin_unlock_irqrestore(&ioc->FreeQlock, flags);
  4569. }
  4570. return 1; /* currently means nothing really */
  4571. }
  4572. #ifdef CONFIG_PROC_FS /* { */
  4573. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4574. /*
  4575. * procfs (%MPT_PROCFS_MPTBASEDIR/...) support stuff...
  4576. */
  4577. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4578. /*
  4579. * procmpt_create - Create %MPT_PROCFS_MPTBASEDIR entries.
  4580. *
  4581. * Returns 0 for success, non-zero for failure.
  4582. */
  4583. static int
  4584. procmpt_create(void)
  4585. {
  4586. struct proc_dir_entry *ent;
  4587. mpt_proc_root_dir = proc_mkdir(MPT_PROCFS_MPTBASEDIR, NULL);
  4588. if (mpt_proc_root_dir == NULL)
  4589. return -ENOTDIR;
  4590. ent = create_proc_entry("summary", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4591. if (ent)
  4592. ent->read_proc = procmpt_summary_read;
  4593. ent = create_proc_entry("version", S_IFREG|S_IRUGO, mpt_proc_root_dir);
  4594. if (ent)
  4595. ent->read_proc = procmpt_version_read;
  4596. return 0;
  4597. }
  4598. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4599. /*
  4600. * procmpt_destroy - Tear down %MPT_PROCFS_MPTBASEDIR entries.
  4601. *
  4602. * Returns 0 for success, non-zero for failure.
  4603. */
  4604. static void
  4605. procmpt_destroy(void)
  4606. {
  4607. remove_proc_entry("version", mpt_proc_root_dir);
  4608. remove_proc_entry("summary", mpt_proc_root_dir);
  4609. remove_proc_entry(MPT_PROCFS_MPTBASEDIR, NULL);
  4610. }
  4611. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4612. /*
  4613. * procmpt_summary_read - Handle read request from /proc/mpt/summary
  4614. * or from /proc/mpt/iocN/summary.
  4615. * @buf: Pointer to area to write information
  4616. * @start: Pointer to start pointer
  4617. * @offset: Offset to start writing
  4618. * @request:
  4619. * @eof: Pointer to EOF integer
  4620. * @data: Pointer
  4621. *
  4622. * Returns number of characters written to process performing the read.
  4623. */
  4624. static int
  4625. procmpt_summary_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4626. {
  4627. MPT_ADAPTER *ioc;
  4628. char *out = buf;
  4629. int len;
  4630. if (data) {
  4631. int more = 0;
  4632. ioc = data;
  4633. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4634. out += more;
  4635. } else {
  4636. list_for_each_entry(ioc, &ioc_list, list) {
  4637. int more = 0;
  4638. mpt_print_ioc_summary(ioc, out, &more, 0, 1);
  4639. out += more;
  4640. if ((out-buf) >= request)
  4641. break;
  4642. }
  4643. }
  4644. len = out - buf;
  4645. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4646. }
  4647. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4648. /*
  4649. * procmpt_version_read - Handle read request from /proc/mpt/version.
  4650. * @buf: Pointer to area to write information
  4651. * @start: Pointer to start pointer
  4652. * @offset: Offset to start writing
  4653. * @request:
  4654. * @eof: Pointer to EOF integer
  4655. * @data: Pointer
  4656. *
  4657. * Returns number of characters written to process performing the read.
  4658. */
  4659. static int
  4660. procmpt_version_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4661. {
  4662. int ii;
  4663. int scsi, fc, sas, lan, ctl, targ, dmp;
  4664. char *drvname;
  4665. int len;
  4666. len = sprintf(buf, "%s-%s\n", "mptlinux", MPT_LINUX_VERSION_COMMON);
  4667. len += sprintf(buf+len, " Fusion MPT base driver\n");
  4668. scsi = fc = sas = lan = ctl = targ = dmp = 0;
  4669. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4670. drvname = NULL;
  4671. if (MptCallbacks[ii]) {
  4672. switch (MptDriverClass[ii]) {
  4673. case MPTSPI_DRIVER:
  4674. if (!scsi++) drvname = "SPI host";
  4675. break;
  4676. case MPTFC_DRIVER:
  4677. if (!fc++) drvname = "FC host";
  4678. break;
  4679. case MPTSAS_DRIVER:
  4680. if (!sas++) drvname = "SAS host";
  4681. break;
  4682. case MPTLAN_DRIVER:
  4683. if (!lan++) drvname = "LAN";
  4684. break;
  4685. case MPTSTM_DRIVER:
  4686. if (!targ++) drvname = "SCSI target";
  4687. break;
  4688. case MPTCTL_DRIVER:
  4689. if (!ctl++) drvname = "ioctl";
  4690. break;
  4691. }
  4692. if (drvname)
  4693. len += sprintf(buf+len, " Fusion MPT %s driver\n", drvname);
  4694. }
  4695. }
  4696. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4697. }
  4698. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4699. /*
  4700. * procmpt_iocinfo_read - Handle read request from /proc/mpt/iocN/info.
  4701. * @buf: Pointer to area to write information
  4702. * @start: Pointer to start pointer
  4703. * @offset: Offset to start writing
  4704. * @request:
  4705. * @eof: Pointer to EOF integer
  4706. * @data: Pointer
  4707. *
  4708. * Returns number of characters written to process performing the read.
  4709. */
  4710. static int
  4711. procmpt_iocinfo_read(char *buf, char **start, off_t offset, int request, int *eof, void *data)
  4712. {
  4713. MPT_ADAPTER *ioc = data;
  4714. int len;
  4715. char expVer[32];
  4716. int sz;
  4717. int p;
  4718. mpt_get_fw_exp_ver(expVer, ioc);
  4719. len = sprintf(buf, "%s:", ioc->name);
  4720. if (ioc->facts.Flags & MPI_IOCFACTS_FLAGS_FW_DOWNLOAD_BOOT)
  4721. len += sprintf(buf+len, " (f/w download boot flag set)");
  4722. // if (ioc->facts.IOCExceptions & MPI_IOCFACTS_EXCEPT_CONFIG_CHECKSUM_FAIL)
  4723. // len += sprintf(buf+len, " CONFIG_CHECKSUM_FAIL!");
  4724. len += sprintf(buf+len, "\n ProductID = 0x%04x (%s)\n",
  4725. ioc->facts.ProductID,
  4726. ioc->prod_name);
  4727. len += sprintf(buf+len, " FWVersion = 0x%08x%s", ioc->facts.FWVersion.Word, expVer);
  4728. if (ioc->facts.FWImageSize)
  4729. len += sprintf(buf+len, " (fw_size=%d)", ioc->facts.FWImageSize);
  4730. len += sprintf(buf+len, "\n MsgVersion = 0x%04x\n", ioc->facts.MsgVersion);
  4731. len += sprintf(buf+len, " FirstWhoInit = 0x%02x\n", ioc->FirstWhoInit);
  4732. len += sprintf(buf+len, " EventState = 0x%02x\n", ioc->facts.EventState);
  4733. len += sprintf(buf+len, " CurrentHostMfaHighAddr = 0x%08x\n",
  4734. ioc->facts.CurrentHostMfaHighAddr);
  4735. len += sprintf(buf+len, " CurrentSenseBufferHighAddr = 0x%08x\n",
  4736. ioc->facts.CurrentSenseBufferHighAddr);
  4737. len += sprintf(buf+len, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
  4738. len += sprintf(buf+len, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
  4739. len += sprintf(buf+len, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
  4740. (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
  4741. /*
  4742. * Rounding UP to nearest 4-kB boundary here...
  4743. */
  4744. sz = (ioc->req_sz * ioc->req_depth) + 128;
  4745. sz = ((sz + 0x1000UL - 1UL) / 0x1000) * 0x1000;
  4746. len += sprintf(buf+len, " {CurReqSz=%d} x {CurReqDepth=%d} = %d bytes ^= 0x%x\n",
  4747. ioc->req_sz, ioc->req_depth, ioc->req_sz*ioc->req_depth, sz);
  4748. len += sprintf(buf+len, " {MaxReqSz=%d} {MaxReqDepth=%d}\n",
  4749. 4*ioc->facts.RequestFrameSize,
  4750. ioc->facts.GlobalCredits);
  4751. len += sprintf(buf+len, " Frames @ 0x%p (Dma @ 0x%p)\n",
  4752. (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
  4753. sz = (ioc->reply_sz * ioc->reply_depth) + 128;
  4754. len += sprintf(buf+len, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
  4755. ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
  4756. len += sprintf(buf+len, " {MaxRepSz=%d} {MaxRepDepth=%d}\n",
  4757. ioc->facts.CurReplyFrameSize,
  4758. ioc->facts.ReplyQueueDepth);
  4759. len += sprintf(buf+len, " MaxDevices = %d\n",
  4760. (ioc->facts.MaxDevices==0) ? 255 : ioc->facts.MaxDevices);
  4761. len += sprintf(buf+len, " MaxBuses = %d\n", ioc->facts.MaxBuses);
  4762. /* per-port info */
  4763. for (p=0; p < ioc->facts.NumberOfPorts; p++) {
  4764. len += sprintf(buf+len, " PortNumber = %d (of %d)\n",
  4765. p+1,
  4766. ioc->facts.NumberOfPorts);
  4767. if (ioc->bus_type == FC) {
  4768. if (ioc->pfacts[p].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN) {
  4769. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4770. len += sprintf(buf+len, " LanAddr = %02X:%02X:%02X:%02X:%02X:%02X\n",
  4771. a[5], a[4], a[3], a[2], a[1], a[0]);
  4772. }
  4773. len += sprintf(buf+len, " WWN = %08X%08X:%08X%08X\n",
  4774. ioc->fc_port_page0[p].WWNN.High,
  4775. ioc->fc_port_page0[p].WWNN.Low,
  4776. ioc->fc_port_page0[p].WWPN.High,
  4777. ioc->fc_port_page0[p].WWPN.Low);
  4778. }
  4779. }
  4780. MPT_PROC_READ_RETURN(buf,start,offset,request,eof,len);
  4781. }
  4782. #endif /* CONFIG_PROC_FS } */
  4783. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4784. static void
  4785. mpt_get_fw_exp_ver(char *buf, MPT_ADAPTER *ioc)
  4786. {
  4787. buf[0] ='\0';
  4788. if ((ioc->facts.FWVersion.Word >> 24) == 0x0E) {
  4789. sprintf(buf, " (Exp %02d%02d)",
  4790. (ioc->facts.FWVersion.Word >> 16) & 0x00FF, /* Month */
  4791. (ioc->facts.FWVersion.Word >> 8) & 0x1F); /* Day */
  4792. /* insider hack! */
  4793. if ((ioc->facts.FWVersion.Word >> 8) & 0x80)
  4794. strcat(buf, " [MDBG]");
  4795. }
  4796. }
  4797. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4798. /**
  4799. * mpt_print_ioc_summary - Write ASCII summary of IOC to a buffer.
  4800. * @ioc: Pointer to MPT_ADAPTER structure
  4801. * @buffer: Pointer to buffer where IOC summary info should be written
  4802. * @size: Pointer to number of bytes we wrote (set by this routine)
  4803. * @len: Offset at which to start writing in buffer
  4804. * @showlan: Display LAN stuff?
  4805. *
  4806. * This routine writes (english readable) ASCII text, which represents
  4807. * a summary of IOC information, to a buffer.
  4808. */
  4809. void
  4810. mpt_print_ioc_summary(MPT_ADAPTER *ioc, char *buffer, int *size, int len, int showlan)
  4811. {
  4812. char expVer[32];
  4813. int y;
  4814. mpt_get_fw_exp_ver(expVer, ioc);
  4815. /*
  4816. * Shorter summary of attached ioc's...
  4817. */
  4818. y = sprintf(buffer+len, "%s: %s, %s%08xh%s, Ports=%d, MaxQ=%d",
  4819. ioc->name,
  4820. ioc->prod_name,
  4821. MPT_FW_REV_MAGIC_ID_STRING, /* "FwRev=" or somesuch */
  4822. ioc->facts.FWVersion.Word,
  4823. expVer,
  4824. ioc->facts.NumberOfPorts,
  4825. ioc->req_depth);
  4826. if (showlan && (ioc->pfacts[0].ProtocolFlags & MPI_PORTFACTS_PROTOCOL_LAN)) {
  4827. u8 *a = (u8*)&ioc->lan_cnfg_page1.HardwareAddressLow;
  4828. y += sprintf(buffer+len+y, ", LanAddr=%02X:%02X:%02X:%02X:%02X:%02X",
  4829. a[5], a[4], a[3], a[2], a[1], a[0]);
  4830. }
  4831. y += sprintf(buffer+len+y, ", IRQ=%d", ioc->pci_irq);
  4832. if (!ioc->active)
  4833. y += sprintf(buffer+len+y, " (disabled)");
  4834. y += sprintf(buffer+len+y, "\n");
  4835. *size = y;
  4836. }
  4837. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4838. /*
  4839. * Reset Handling
  4840. */
  4841. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4842. /**
  4843. * mpt_HardResetHandler - Generic reset handler, issue SCSI Task
  4844. * Management call based on input arg values. If TaskMgmt fails,
  4845. * return associated SCSI request.
  4846. * @ioc: Pointer to MPT_ADAPTER structure
  4847. * @sleepFlag: Indicates if sleep or schedule must be called.
  4848. *
  4849. * Remark: _HardResetHandler can be invoked from an interrupt thread (timer)
  4850. * or a non-interrupt thread. In the former, must not call schedule().
  4851. *
  4852. * Remark: A return of -1 is a FATAL error case, as it means a
  4853. * FW reload/initialization failed.
  4854. *
  4855. * Returns 0 for SUCCESS or -1 if FAILED.
  4856. */
  4857. int
  4858. mpt_HardResetHandler(MPT_ADAPTER *ioc, int sleepFlag)
  4859. {
  4860. int rc;
  4861. unsigned long flags;
  4862. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name));
  4863. #ifdef MFCNT
  4864. printk(MYIOC_s_INFO_FMT "HardResetHandler Entered!\n", ioc->name);
  4865. printk("MF count 0x%x !\n", ioc->mfcnt);
  4866. #endif
  4867. /* Reset the adapter. Prevent more than 1 call to
  4868. * mpt_do_ioc_recovery at any instant in time.
  4869. */
  4870. spin_lock_irqsave(&ioc->diagLock, flags);
  4871. if ((ioc->diagPending) || (ioc->alt_ioc && ioc->alt_ioc->diagPending)){
  4872. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4873. return 0;
  4874. } else {
  4875. ioc->diagPending = 1;
  4876. }
  4877. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4878. /* FIXME: If do_ioc_recovery fails, repeat....
  4879. */
  4880. /* The SCSI driver needs to adjust timeouts on all current
  4881. * commands prior to the diagnostic reset being issued.
  4882. * Prevents timeouts occurring during a diagnostic reset...very bad.
  4883. * For all other protocol drivers, this is a no-op.
  4884. */
  4885. {
  4886. int ii;
  4887. int r = 0;
  4888. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  4889. if (MptResetHandlers[ii]) {
  4890. dtmprintk((MYIOC_s_INFO_FMT "Calling IOC reset_setup handler #%d\n",
  4891. ioc->name, ii));
  4892. r += mpt_signal_reset(ii, ioc, MPT_IOC_SETUP_RESET);
  4893. if (ioc->alt_ioc) {
  4894. dtmprintk((MYIOC_s_INFO_FMT "Calling alt-%s setup reset handler #%d\n",
  4895. ioc->name, ioc->alt_ioc->name, ii));
  4896. r += mpt_signal_reset(ii, ioc->alt_ioc, MPT_IOC_SETUP_RESET);
  4897. }
  4898. }
  4899. }
  4900. }
  4901. if ((rc = mpt_do_ioc_recovery(ioc, MPT_HOSTEVENT_IOC_RECOVER, sleepFlag)) != 0) {
  4902. printk(KERN_WARNING MYNAM ": WARNING - (%d) Cannot recover %s\n",
  4903. rc, ioc->name);
  4904. }
  4905. ioc->reload_fw = 0;
  4906. if (ioc->alt_ioc)
  4907. ioc->alt_ioc->reload_fw = 0;
  4908. spin_lock_irqsave(&ioc->diagLock, flags);
  4909. ioc->diagPending = 0;
  4910. if (ioc->alt_ioc)
  4911. ioc->alt_ioc->diagPending = 0;
  4912. spin_unlock_irqrestore(&ioc->diagLock, flags);
  4913. dtmprintk((MYIOC_s_INFO_FMT "HardResetHandler rc = %d!\n", ioc->name, rc));
  4914. return rc;
  4915. }
  4916. # define EVENT_DESCR_STR_SZ 100
  4917. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  4918. static void
  4919. EventDescriptionStr(u8 event, u32 evData0, char *evStr)
  4920. {
  4921. char *ds = NULL;
  4922. switch(event) {
  4923. case MPI_EVENT_NONE:
  4924. ds = "None";
  4925. break;
  4926. case MPI_EVENT_LOG_DATA:
  4927. ds = "Log Data";
  4928. break;
  4929. case MPI_EVENT_STATE_CHANGE:
  4930. ds = "State Change";
  4931. break;
  4932. case MPI_EVENT_UNIT_ATTENTION:
  4933. ds = "Unit Attention";
  4934. break;
  4935. case MPI_EVENT_IOC_BUS_RESET:
  4936. ds = "IOC Bus Reset";
  4937. break;
  4938. case MPI_EVENT_EXT_BUS_RESET:
  4939. ds = "External Bus Reset";
  4940. break;
  4941. case MPI_EVENT_RESCAN:
  4942. ds = "Bus Rescan Event";
  4943. /* Ok, do we need to do anything here? As far as
  4944. I can tell, this is when a new device gets added
  4945. to the loop. */
  4946. break;
  4947. case MPI_EVENT_LINK_STATUS_CHANGE:
  4948. if (evData0 == MPI_EVENT_LINK_STATUS_FAILURE)
  4949. ds = "Link Status(FAILURE) Change";
  4950. else
  4951. ds = "Link Status(ACTIVE) Change";
  4952. break;
  4953. case MPI_EVENT_LOOP_STATE_CHANGE:
  4954. if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LIP)
  4955. ds = "Loop State(LIP) Change";
  4956. else if (evData0 == MPI_EVENT_LOOP_STATE_CHANGE_LPE)
  4957. ds = "Loop State(LPE) Change"; /* ??? */
  4958. else
  4959. ds = "Loop State(LPB) Change"; /* ??? */
  4960. break;
  4961. case MPI_EVENT_LOGOUT:
  4962. ds = "Logout";
  4963. break;
  4964. case MPI_EVENT_EVENT_CHANGE:
  4965. if (evData0)
  4966. ds = "Events ON";
  4967. else
  4968. ds = "Events OFF";
  4969. break;
  4970. case MPI_EVENT_INTEGRATED_RAID:
  4971. {
  4972. u8 ReasonCode = (u8)(evData0 >> 16);
  4973. switch (ReasonCode) {
  4974. case MPI_EVENT_RAID_RC_VOLUME_CREATED :
  4975. ds = "Integrated Raid: Volume Created";
  4976. break;
  4977. case MPI_EVENT_RAID_RC_VOLUME_DELETED :
  4978. ds = "Integrated Raid: Volume Deleted";
  4979. break;
  4980. case MPI_EVENT_RAID_RC_VOLUME_SETTINGS_CHANGED :
  4981. ds = "Integrated Raid: Volume Settings Changed";
  4982. break;
  4983. case MPI_EVENT_RAID_RC_VOLUME_STATUS_CHANGED :
  4984. ds = "Integrated Raid: Volume Status Changed";
  4985. break;
  4986. case MPI_EVENT_RAID_RC_VOLUME_PHYSDISK_CHANGED :
  4987. ds = "Integrated Raid: Volume Physdisk Changed";
  4988. break;
  4989. case MPI_EVENT_RAID_RC_PHYSDISK_CREATED :
  4990. ds = "Integrated Raid: Physdisk Created";
  4991. break;
  4992. case MPI_EVENT_RAID_RC_PHYSDISK_DELETED :
  4993. ds = "Integrated Raid: Physdisk Deleted";
  4994. break;
  4995. case MPI_EVENT_RAID_RC_PHYSDISK_SETTINGS_CHANGED :
  4996. ds = "Integrated Raid: Physdisk Settings Changed";
  4997. break;
  4998. case MPI_EVENT_RAID_RC_PHYSDISK_STATUS_CHANGED :
  4999. ds = "Integrated Raid: Physdisk Status Changed";
  5000. break;
  5001. case MPI_EVENT_RAID_RC_DOMAIN_VAL_NEEDED :
  5002. ds = "Integrated Raid: Domain Validation Needed";
  5003. break;
  5004. case MPI_EVENT_RAID_RC_SMART_DATA :
  5005. ds = "Integrated Raid; Smart Data";
  5006. break;
  5007. case MPI_EVENT_RAID_RC_REPLACE_ACTION_STARTED :
  5008. ds = "Integrated Raid: Replace Action Started";
  5009. break;
  5010. default:
  5011. ds = "Integrated Raid";
  5012. break;
  5013. }
  5014. break;
  5015. }
  5016. case MPI_EVENT_SCSI_DEVICE_STATUS_CHANGE:
  5017. ds = "SCSI Device Status Change";
  5018. break;
  5019. case MPI_EVENT_SAS_DEVICE_STATUS_CHANGE:
  5020. {
  5021. u8 id = (u8)(evData0);
  5022. u8 ReasonCode = (u8)(evData0 >> 16);
  5023. switch (ReasonCode) {
  5024. case MPI_EVENT_SAS_DEV_STAT_RC_ADDED:
  5025. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5026. "SAS Device Status Change: Added: id=%d", id);
  5027. break;
  5028. case MPI_EVENT_SAS_DEV_STAT_RC_NOT_RESPONDING:
  5029. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5030. "SAS Device Status Change: Deleted: id=%d", id);
  5031. break;
  5032. case MPI_EVENT_SAS_DEV_STAT_RC_SMART_DATA:
  5033. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5034. "SAS Device Status Change: SMART Data: id=%d",
  5035. id);
  5036. break;
  5037. case MPI_EVENT_SAS_DEV_STAT_RC_NO_PERSIST_ADDED:
  5038. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5039. "SAS Device Status Change: No Persistancy: id=%d", id);
  5040. break;
  5041. case MPI_EVENT_SAS_DEV_STAT_RC_INTERNAL_DEVICE_RESET:
  5042. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5043. "SAS Device Status Change: Internal Device Reset : id=%d", id);
  5044. break;
  5045. case MPI_EVENT_SAS_DEV_STAT_RC_TASK_ABORT_INTERNAL:
  5046. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5047. "SAS Device Status Change: Internal Task Abort : id=%d", id);
  5048. break;
  5049. case MPI_EVENT_SAS_DEV_STAT_RC_ABORT_TASK_SET_INTERNAL:
  5050. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5051. "SAS Device Status Change: Internal Abort Task Set : id=%d", id);
  5052. break;
  5053. case MPI_EVENT_SAS_DEV_STAT_RC_CLEAR_TASK_SET_INTERNAL:
  5054. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5055. "SAS Device Status Change: Internal Clear Task Set : id=%d", id);
  5056. break;
  5057. case MPI_EVENT_SAS_DEV_STAT_RC_QUERY_TASK_INTERNAL:
  5058. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5059. "SAS Device Status Change: Internal Query Task : id=%d", id);
  5060. break;
  5061. default:
  5062. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5063. "SAS Device Status Change: Unknown: id=%d", id);
  5064. break;
  5065. }
  5066. break;
  5067. }
  5068. case MPI_EVENT_ON_BUS_TIMER_EXPIRED:
  5069. ds = "Bus Timer Expired";
  5070. break;
  5071. case MPI_EVENT_QUEUE_FULL:
  5072. ds = "Queue Full";
  5073. break;
  5074. case MPI_EVENT_SAS_SES:
  5075. ds = "SAS SES Event";
  5076. break;
  5077. case MPI_EVENT_PERSISTENT_TABLE_FULL:
  5078. ds = "Persistent Table Full";
  5079. break;
  5080. case MPI_EVENT_SAS_PHY_LINK_STATUS:
  5081. {
  5082. u8 LinkRates = (u8)(evData0 >> 8);
  5083. u8 PhyNumber = (u8)(evData0);
  5084. LinkRates = (LinkRates & MPI_EVENT_SAS_PLS_LR_CURRENT_MASK) >>
  5085. MPI_EVENT_SAS_PLS_LR_CURRENT_SHIFT;
  5086. switch (LinkRates) {
  5087. case MPI_EVENT_SAS_PLS_LR_RATE_UNKNOWN:
  5088. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5089. "SAS PHY Link Status: Phy=%d:"
  5090. " Rate Unknown",PhyNumber);
  5091. break;
  5092. case MPI_EVENT_SAS_PLS_LR_RATE_PHY_DISABLED:
  5093. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5094. "SAS PHY Link Status: Phy=%d:"
  5095. " Phy Disabled",PhyNumber);
  5096. break;
  5097. case MPI_EVENT_SAS_PLS_LR_RATE_FAILED_SPEED_NEGOTIATION:
  5098. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5099. "SAS PHY Link Status: Phy=%d:"
  5100. " Failed Speed Nego",PhyNumber);
  5101. break;
  5102. case MPI_EVENT_SAS_PLS_LR_RATE_SATA_OOB_COMPLETE:
  5103. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5104. "SAS PHY Link Status: Phy=%d:"
  5105. " Sata OOB Completed",PhyNumber);
  5106. break;
  5107. case MPI_EVENT_SAS_PLS_LR_RATE_1_5:
  5108. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5109. "SAS PHY Link Status: Phy=%d:"
  5110. " Rate 1.5 Gbps",PhyNumber);
  5111. break;
  5112. case MPI_EVENT_SAS_PLS_LR_RATE_3_0:
  5113. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5114. "SAS PHY Link Status: Phy=%d:"
  5115. " Rate 3.0 Gpbs",PhyNumber);
  5116. break;
  5117. default:
  5118. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5119. "SAS PHY Link Status: Phy=%d", PhyNumber);
  5120. break;
  5121. }
  5122. break;
  5123. }
  5124. case MPI_EVENT_SAS_DISCOVERY_ERROR:
  5125. ds = "SAS Discovery Error";
  5126. break;
  5127. case MPI_EVENT_IR_RESYNC_UPDATE:
  5128. {
  5129. u8 resync_complete = (u8)(evData0 >> 16);
  5130. snprintf(evStr, EVENT_DESCR_STR_SZ,
  5131. "IR Resync Update: Complete = %d:",resync_complete);
  5132. break;
  5133. }
  5134. case MPI_EVENT_IR2:
  5135. {
  5136. u8 ReasonCode = (u8)(evData0 >> 16);
  5137. switch (ReasonCode) {
  5138. case MPI_EVENT_IR2_RC_LD_STATE_CHANGED:
  5139. ds = "IR2: LD State Changed";
  5140. break;
  5141. case MPI_EVENT_IR2_RC_PD_STATE_CHANGED:
  5142. ds = "IR2: PD State Changed";
  5143. break;
  5144. case MPI_EVENT_IR2_RC_BAD_BLOCK_TABLE_FULL:
  5145. ds = "IR2: Bad Block Table Full";
  5146. break;
  5147. case MPI_EVENT_IR2_RC_PD_INSERTED:
  5148. ds = "IR2: PD Inserted";
  5149. break;
  5150. case MPI_EVENT_IR2_RC_PD_REMOVED:
  5151. ds = "IR2: PD Removed";
  5152. break;
  5153. case MPI_EVENT_IR2_RC_FOREIGN_CFG_DETECTED:
  5154. ds = "IR2: Foreign CFG Detected";
  5155. break;
  5156. case MPI_EVENT_IR2_RC_REBUILD_MEDIUM_ERROR:
  5157. ds = "IR2: Rebuild Medium Error";
  5158. break;
  5159. default:
  5160. ds = "IR2";
  5161. break;
  5162. }
  5163. break;
  5164. }
  5165. case MPI_EVENT_SAS_DISCOVERY:
  5166. {
  5167. if (evData0)
  5168. ds = "SAS Discovery: Start";
  5169. else
  5170. ds = "SAS Discovery: Stop";
  5171. break;
  5172. }
  5173. case MPI_EVENT_LOG_ENTRY_ADDED:
  5174. ds = "SAS Log Entry Added";
  5175. break;
  5176. /*
  5177. * MPT base "custom" events may be added here...
  5178. */
  5179. default:
  5180. ds = "Unknown";
  5181. break;
  5182. }
  5183. if (ds)
  5184. strncpy(evStr, ds, EVENT_DESCR_STR_SZ);
  5185. }
  5186. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5187. /*
  5188. * ProcessEventNotification - Route a received EventNotificationReply to
  5189. * all currently regeistered event handlers.
  5190. * @ioc: Pointer to MPT_ADAPTER structure
  5191. * @pEventReply: Pointer to EventNotification reply frame
  5192. * @evHandlers: Pointer to integer, number of event handlers
  5193. *
  5194. * Returns sum of event handlers return values.
  5195. */
  5196. static int
  5197. ProcessEventNotification(MPT_ADAPTER *ioc, EventNotificationReply_t *pEventReply, int *evHandlers)
  5198. {
  5199. u16 evDataLen;
  5200. u32 evData0 = 0;
  5201. // u32 evCtx;
  5202. int ii;
  5203. int r = 0;
  5204. int handlers = 0;
  5205. char evStr[EVENT_DESCR_STR_SZ];
  5206. u8 event;
  5207. /*
  5208. * Do platform normalization of values
  5209. */
  5210. event = le32_to_cpu(pEventReply->Event) & 0xFF;
  5211. // evCtx = le32_to_cpu(pEventReply->EventContext);
  5212. evDataLen = le16_to_cpu(pEventReply->EventDataLength);
  5213. if (evDataLen) {
  5214. evData0 = le32_to_cpu(pEventReply->Data[0]);
  5215. }
  5216. EventDescriptionStr(event, evData0, evStr);
  5217. devtprintk((MYIOC_s_INFO_FMT "MPT event:(%02Xh) : %s\n",
  5218. ioc->name,
  5219. event,
  5220. evStr));
  5221. #if defined(MPT_DEBUG) || defined(MPT_DEBUG_VERBOSE_EVENTS)
  5222. printk(KERN_INFO MYNAM ": Event data:\n" KERN_INFO);
  5223. for (ii = 0; ii < evDataLen; ii++)
  5224. printk(" %08x", le32_to_cpu(pEventReply->Data[ii]));
  5225. printk("\n");
  5226. #endif
  5227. /*
  5228. * Do general / base driver event processing
  5229. */
  5230. switch(event) {
  5231. case MPI_EVENT_EVENT_CHANGE: /* 0A */
  5232. if (evDataLen) {
  5233. u8 evState = evData0 & 0xFF;
  5234. /* CHECKME! What if evState unexpectedly says OFF (0)? */
  5235. /* Update EventState field in cached IocFacts */
  5236. if (ioc->facts.Function) {
  5237. ioc->facts.EventState = evState;
  5238. }
  5239. }
  5240. break;
  5241. case MPI_EVENT_INTEGRATED_RAID:
  5242. mptbase_raid_process_event_data(ioc,
  5243. (MpiEventDataRaid_t *)pEventReply->Data);
  5244. break;
  5245. default:
  5246. break;
  5247. }
  5248. /*
  5249. * Should this event be logged? Events are written sequentially.
  5250. * When buffer is full, start again at the top.
  5251. */
  5252. if (ioc->events && (ioc->eventTypes & ( 1 << event))) {
  5253. int idx;
  5254. idx = ioc->eventContext % MPTCTL_EVENT_LOG_SIZE;
  5255. ioc->events[idx].event = event;
  5256. ioc->events[idx].eventContext = ioc->eventContext;
  5257. for (ii = 0; ii < 2; ii++) {
  5258. if (ii < evDataLen)
  5259. ioc->events[idx].data[ii] = le32_to_cpu(pEventReply->Data[ii]);
  5260. else
  5261. ioc->events[idx].data[ii] = 0;
  5262. }
  5263. ioc->eventContext++;
  5264. }
  5265. /*
  5266. * Call each currently registered protocol event handler.
  5267. */
  5268. for (ii=MPT_MAX_PROTOCOL_DRIVERS-1; ii; ii--) {
  5269. if (MptEvHandlers[ii]) {
  5270. devtverboseprintk((MYIOC_s_INFO_FMT "Routing Event to event handler #%d\n",
  5271. ioc->name, ii));
  5272. r += (*(MptEvHandlers[ii]))(ioc, pEventReply);
  5273. handlers++;
  5274. }
  5275. }
  5276. /* FIXME? Examine results here? */
  5277. /*
  5278. * If needed, send (a single) EventAck.
  5279. */
  5280. if (pEventReply->AckRequired == MPI_EVENT_NOTIFICATION_ACK_REQUIRED) {
  5281. devtverboseprintk((MYIOC_s_WARN_FMT
  5282. "EventAck required\n",ioc->name));
  5283. if ((ii = SendEventAck(ioc, pEventReply)) != 0) {
  5284. devtverboseprintk((MYIOC_s_WARN_FMT "SendEventAck returned %d\n",
  5285. ioc->name, ii));
  5286. }
  5287. }
  5288. *evHandlers = handlers;
  5289. return r;
  5290. }
  5291. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5292. /*
  5293. * mpt_fc_log_info - Log information returned from Fibre Channel IOC.
  5294. * @ioc: Pointer to MPT_ADAPTER structure
  5295. * @log_info: U32 LogInfo reply word from the IOC
  5296. *
  5297. * Refer to lsi/mpi_log_fc.h.
  5298. */
  5299. static void
  5300. mpt_fc_log_info(MPT_ADAPTER *ioc, u32 log_info)
  5301. {
  5302. static char *subcl_str[8] = {
  5303. "FCP Initiator", "FCP Target", "LAN", "MPI Message Layer",
  5304. "FC Link", "Context Manager", "Invalid Field Offset", "State Change Info"
  5305. };
  5306. u8 subcl = (log_info >> 24) & 0x7;
  5307. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): SubCl={%s}\n",
  5308. ioc->name, log_info, subcl_str[subcl]);
  5309. }
  5310. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5311. /*
  5312. * mpt_spi_log_info - Log information returned from SCSI Parallel IOC.
  5313. * @ioc: Pointer to MPT_ADAPTER structure
  5314. * @mr: Pointer to MPT reply frame
  5315. * @log_info: U32 LogInfo word from the IOC
  5316. *
  5317. * Refer to lsi/sp_log.h.
  5318. */
  5319. static void
  5320. mpt_spi_log_info(MPT_ADAPTER *ioc, u32 log_info)
  5321. {
  5322. u32 info = log_info & 0x00FF0000;
  5323. char *desc = "unknown";
  5324. switch (info) {
  5325. case 0x00010000:
  5326. desc = "bug! MID not found";
  5327. if (ioc->reload_fw == 0)
  5328. ioc->reload_fw++;
  5329. break;
  5330. case 0x00020000:
  5331. desc = "Parity Error";
  5332. break;
  5333. case 0x00030000:
  5334. desc = "ASYNC Outbound Overrun";
  5335. break;
  5336. case 0x00040000:
  5337. desc = "SYNC Offset Error";
  5338. break;
  5339. case 0x00050000:
  5340. desc = "BM Change";
  5341. break;
  5342. case 0x00060000:
  5343. desc = "Msg In Overflow";
  5344. break;
  5345. case 0x00070000:
  5346. desc = "DMA Error";
  5347. break;
  5348. case 0x00080000:
  5349. desc = "Outbound DMA Overrun";
  5350. break;
  5351. case 0x00090000:
  5352. desc = "Task Management";
  5353. break;
  5354. case 0x000A0000:
  5355. desc = "Device Problem";
  5356. break;
  5357. case 0x000B0000:
  5358. desc = "Invalid Phase Change";
  5359. break;
  5360. case 0x000C0000:
  5361. desc = "Untagged Table Size";
  5362. break;
  5363. }
  5364. printk(MYIOC_s_INFO_FMT "LogInfo(0x%08x): F/W: %s\n", ioc->name, log_info, desc);
  5365. }
  5366. /* strings for sas loginfo */
  5367. static char *originator_str[] = {
  5368. "IOP", /* 00h */
  5369. "PL", /* 01h */
  5370. "IR" /* 02h */
  5371. };
  5372. static char *iop_code_str[] = {
  5373. NULL, /* 00h */
  5374. "Invalid SAS Address", /* 01h */
  5375. NULL, /* 02h */
  5376. "Invalid Page", /* 03h */
  5377. "Diag Message Error", /* 04h */
  5378. "Task Terminated", /* 05h */
  5379. "Enclosure Management", /* 06h */
  5380. "Target Mode" /* 07h */
  5381. };
  5382. static char *pl_code_str[] = {
  5383. NULL, /* 00h */
  5384. "Open Failure", /* 01h */
  5385. "Invalid Scatter Gather List", /* 02h */
  5386. "Wrong Relative Offset or Frame Length", /* 03h */
  5387. "Frame Transfer Error", /* 04h */
  5388. "Transmit Frame Connected Low", /* 05h */
  5389. "SATA Non-NCQ RW Error Bit Set", /* 06h */
  5390. "SATA Read Log Receive Data Error", /* 07h */
  5391. "SATA NCQ Fail All Commands After Error", /* 08h */
  5392. "SATA Error in Receive Set Device Bit FIS", /* 09h */
  5393. "Receive Frame Invalid Message", /* 0Ah */
  5394. "Receive Context Message Valid Error", /* 0Bh */
  5395. "Receive Frame Current Frame Error", /* 0Ch */
  5396. "SATA Link Down", /* 0Dh */
  5397. "Discovery SATA Init W IOS", /* 0Eh */
  5398. "Config Invalid Page", /* 0Fh */
  5399. "Discovery SATA Init Timeout", /* 10h */
  5400. "Reset", /* 11h */
  5401. "Abort", /* 12h */
  5402. "IO Not Yet Executed", /* 13h */
  5403. "IO Executed", /* 14h */
  5404. "Persistant Reservation Out Not Affiliation Owner", /* 15h */
  5405. "Open Transmit DMA Abort", /* 16h */
  5406. "IO Device Missing Delay Retry", /* 17h */
  5407. NULL, /* 18h */
  5408. NULL, /* 19h */
  5409. NULL, /* 1Ah */
  5410. NULL, /* 1Bh */
  5411. NULL, /* 1Ch */
  5412. NULL, /* 1Dh */
  5413. NULL, /* 1Eh */
  5414. NULL, /* 1Fh */
  5415. "Enclosure Management" /* 20h */
  5416. };
  5417. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5418. /*
  5419. * mpt_sas_log_info - Log information returned from SAS IOC.
  5420. * @ioc: Pointer to MPT_ADAPTER structure
  5421. * @log_info: U32 LogInfo reply word from the IOC
  5422. *
  5423. * Refer to lsi/mpi_log_sas.h.
  5424. */
  5425. static void
  5426. mpt_sas_log_info(MPT_ADAPTER *ioc, u32 log_info)
  5427. {
  5428. union loginfo_type {
  5429. u32 loginfo;
  5430. struct {
  5431. u32 subcode:16;
  5432. u32 code:8;
  5433. u32 originator:4;
  5434. u32 bus_type:4;
  5435. }dw;
  5436. };
  5437. union loginfo_type sas_loginfo;
  5438. char *code_desc = NULL;
  5439. sas_loginfo.loginfo = log_info;
  5440. if ((sas_loginfo.dw.bus_type != 3 /*SAS*/) &&
  5441. (sas_loginfo.dw.originator < sizeof(originator_str)/sizeof(char*)))
  5442. return;
  5443. if ((sas_loginfo.dw.originator == 0 /*IOP*/) &&
  5444. (sas_loginfo.dw.code < sizeof(iop_code_str)/sizeof(char*))) {
  5445. code_desc = iop_code_str[sas_loginfo.dw.code];
  5446. }else if ((sas_loginfo.dw.originator == 1 /*PL*/) &&
  5447. (sas_loginfo.dw.code < sizeof(pl_code_str)/sizeof(char*) )) {
  5448. code_desc = pl_code_str[sas_loginfo.dw.code];
  5449. }
  5450. if (code_desc != NULL)
  5451. printk(MYIOC_s_INFO_FMT
  5452. "LogInfo(0x%08x): Originator={%s}, Code={%s},"
  5453. " SubCode(0x%04x)\n",
  5454. ioc->name,
  5455. log_info,
  5456. originator_str[sas_loginfo.dw.originator],
  5457. code_desc,
  5458. sas_loginfo.dw.subcode);
  5459. else
  5460. printk(MYIOC_s_INFO_FMT
  5461. "LogInfo(0x%08x): Originator={%s}, Code=(0x%02x),"
  5462. " SubCode(0x%04x)\n",
  5463. ioc->name,
  5464. log_info,
  5465. originator_str[sas_loginfo.dw.originator],
  5466. sas_loginfo.dw.code,
  5467. sas_loginfo.dw.subcode);
  5468. }
  5469. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5470. /*
  5471. * mpt_sp_ioc_info - IOC information returned from SCSI Parallel IOC.
  5472. * @ioc: Pointer to MPT_ADAPTER structure
  5473. * @ioc_status: U32 IOCStatus word from IOC
  5474. * @mf: Pointer to MPT request frame
  5475. *
  5476. * Refer to lsi/mpi.h.
  5477. */
  5478. static void
  5479. mpt_sp_ioc_info(MPT_ADAPTER *ioc, u32 ioc_status, MPT_FRAME_HDR *mf)
  5480. {
  5481. u32 status = ioc_status & MPI_IOCSTATUS_MASK;
  5482. char *desc = NULL;
  5483. switch (status) {
  5484. case MPI_IOCSTATUS_INVALID_FUNCTION: /* 0x0001 */
  5485. desc = "Invalid Function";
  5486. break;
  5487. case MPI_IOCSTATUS_BUSY: /* 0x0002 */
  5488. desc = "Busy";
  5489. break;
  5490. case MPI_IOCSTATUS_INVALID_SGL: /* 0x0003 */
  5491. desc = "Invalid SGL";
  5492. break;
  5493. case MPI_IOCSTATUS_INTERNAL_ERROR: /* 0x0004 */
  5494. desc = "Internal Error";
  5495. break;
  5496. case MPI_IOCSTATUS_RESERVED: /* 0x0005 */
  5497. desc = "Reserved";
  5498. break;
  5499. case MPI_IOCSTATUS_INSUFFICIENT_RESOURCES: /* 0x0006 */
  5500. desc = "Insufficient Resources";
  5501. break;
  5502. case MPI_IOCSTATUS_INVALID_FIELD: /* 0x0007 */
  5503. desc = "Invalid Field";
  5504. break;
  5505. case MPI_IOCSTATUS_INVALID_STATE: /* 0x0008 */
  5506. desc = "Invalid State";
  5507. break;
  5508. case MPI_IOCSTATUS_CONFIG_INVALID_ACTION: /* 0x0020 */
  5509. case MPI_IOCSTATUS_CONFIG_INVALID_TYPE: /* 0x0021 */
  5510. case MPI_IOCSTATUS_CONFIG_INVALID_PAGE: /* 0x0022 */
  5511. case MPI_IOCSTATUS_CONFIG_INVALID_DATA: /* 0x0023 */
  5512. case MPI_IOCSTATUS_CONFIG_NO_DEFAULTS: /* 0x0024 */
  5513. case MPI_IOCSTATUS_CONFIG_CANT_COMMIT: /* 0x0025 */
  5514. /* No message for Config IOCStatus values */
  5515. break;
  5516. case MPI_IOCSTATUS_SCSI_RECOVERED_ERROR: /* 0x0040 */
  5517. /* No message for recovered error
  5518. desc = "SCSI Recovered Error";
  5519. */
  5520. break;
  5521. case MPI_IOCSTATUS_SCSI_INVALID_BUS: /* 0x0041 */
  5522. desc = "SCSI Invalid Bus";
  5523. break;
  5524. case MPI_IOCSTATUS_SCSI_INVALID_TARGETID: /* 0x0042 */
  5525. desc = "SCSI Invalid TargetID";
  5526. break;
  5527. case MPI_IOCSTATUS_SCSI_DEVICE_NOT_THERE: /* 0x0043 */
  5528. {
  5529. SCSIIORequest_t *pScsiReq = (SCSIIORequest_t *) mf;
  5530. U8 cdb = pScsiReq->CDB[0];
  5531. if (cdb != 0x12) { /* Inquiry is issued for device scanning */
  5532. desc = "SCSI Device Not There";
  5533. }
  5534. break;
  5535. }
  5536. case MPI_IOCSTATUS_SCSI_DATA_OVERRUN: /* 0x0044 */
  5537. desc = "SCSI Data Overrun";
  5538. break;
  5539. case MPI_IOCSTATUS_SCSI_DATA_UNDERRUN: /* 0x0045 */
  5540. /* This error is checked in scsi_io_done(). Skip.
  5541. desc = "SCSI Data Underrun";
  5542. */
  5543. break;
  5544. case MPI_IOCSTATUS_SCSI_IO_DATA_ERROR: /* 0x0046 */
  5545. desc = "SCSI I/O Data Error";
  5546. break;
  5547. case MPI_IOCSTATUS_SCSI_PROTOCOL_ERROR: /* 0x0047 */
  5548. desc = "SCSI Protocol Error";
  5549. break;
  5550. case MPI_IOCSTATUS_SCSI_TASK_TERMINATED: /* 0x0048 */
  5551. desc = "SCSI Task Terminated";
  5552. break;
  5553. case MPI_IOCSTATUS_SCSI_RESIDUAL_MISMATCH: /* 0x0049 */
  5554. desc = "SCSI Residual Mismatch";
  5555. break;
  5556. case MPI_IOCSTATUS_SCSI_TASK_MGMT_FAILED: /* 0x004A */
  5557. desc = "SCSI Task Management Failed";
  5558. break;
  5559. case MPI_IOCSTATUS_SCSI_IOC_TERMINATED: /* 0x004B */
  5560. desc = "SCSI IOC Terminated";
  5561. break;
  5562. case MPI_IOCSTATUS_SCSI_EXT_TERMINATED: /* 0x004C */
  5563. desc = "SCSI Ext Terminated";
  5564. break;
  5565. default:
  5566. desc = "Others";
  5567. break;
  5568. }
  5569. if (desc != NULL)
  5570. printk(MYIOC_s_INFO_FMT "IOCStatus(0x%04x): %s\n", ioc->name, status, desc);
  5571. }
  5572. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5573. EXPORT_SYMBOL(mpt_attach);
  5574. EXPORT_SYMBOL(mpt_detach);
  5575. #ifdef CONFIG_PM
  5576. EXPORT_SYMBOL(mpt_resume);
  5577. EXPORT_SYMBOL(mpt_suspend);
  5578. #endif
  5579. EXPORT_SYMBOL(ioc_list);
  5580. EXPORT_SYMBOL(mpt_proc_root_dir);
  5581. EXPORT_SYMBOL(mpt_register);
  5582. EXPORT_SYMBOL(mpt_deregister);
  5583. EXPORT_SYMBOL(mpt_event_register);
  5584. EXPORT_SYMBOL(mpt_event_deregister);
  5585. EXPORT_SYMBOL(mpt_reset_register);
  5586. EXPORT_SYMBOL(mpt_reset_deregister);
  5587. EXPORT_SYMBOL(mpt_device_driver_register);
  5588. EXPORT_SYMBOL(mpt_device_driver_deregister);
  5589. EXPORT_SYMBOL(mpt_get_msg_frame);
  5590. EXPORT_SYMBOL(mpt_put_msg_frame);
  5591. EXPORT_SYMBOL(mpt_free_msg_frame);
  5592. EXPORT_SYMBOL(mpt_add_sge);
  5593. EXPORT_SYMBOL(mpt_send_handshake_request);
  5594. EXPORT_SYMBOL(mpt_verify_adapter);
  5595. EXPORT_SYMBOL(mpt_GetIocState);
  5596. EXPORT_SYMBOL(mpt_print_ioc_summary);
  5597. EXPORT_SYMBOL(mpt_lan_index);
  5598. EXPORT_SYMBOL(mpt_stm_index);
  5599. EXPORT_SYMBOL(mpt_HardResetHandler);
  5600. EXPORT_SYMBOL(mpt_config);
  5601. EXPORT_SYMBOL(mpt_findImVolumes);
  5602. EXPORT_SYMBOL(mpt_alloc_fw_memory);
  5603. EXPORT_SYMBOL(mpt_free_fw_memory);
  5604. EXPORT_SYMBOL(mptbase_sas_persist_operation);
  5605. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5606. /*
  5607. * fusion_init - Fusion MPT base driver initialization routine.
  5608. *
  5609. * Returns 0 for success, non-zero for failure.
  5610. */
  5611. static int __init
  5612. fusion_init(void)
  5613. {
  5614. int i;
  5615. show_mptmod_ver(my_NAME, my_VERSION);
  5616. printk(KERN_INFO COPYRIGHT "\n");
  5617. for (i = 0; i < MPT_MAX_PROTOCOL_DRIVERS; i++) {
  5618. MptCallbacks[i] = NULL;
  5619. MptDriverClass[i] = MPTUNKNOWN_DRIVER;
  5620. MptEvHandlers[i] = NULL;
  5621. MptResetHandlers[i] = NULL;
  5622. }
  5623. /* Register ourselves (mptbase) in order to facilitate
  5624. * EventNotification handling.
  5625. */
  5626. mpt_base_index = mpt_register(mpt_base_reply, MPTBASE_DRIVER);
  5627. /* Register for hard reset handling callbacks.
  5628. */
  5629. if (mpt_reset_register(mpt_base_index, mpt_ioc_reset) == 0) {
  5630. dprintk((KERN_INFO MYNAM ": Register for IOC reset notification\n"));
  5631. } else {
  5632. /* FIXME! */
  5633. }
  5634. #ifdef CONFIG_PROC_FS
  5635. (void) procmpt_create();
  5636. #endif
  5637. return 0;
  5638. }
  5639. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5640. /*
  5641. * fusion_exit - Perform driver unload cleanup.
  5642. *
  5643. * This routine frees all resources associated with each MPT adapter
  5644. * and removes all %MPT_PROCFS_MPTBASEDIR entries.
  5645. */
  5646. static void __exit
  5647. fusion_exit(void)
  5648. {
  5649. dexitprintk((KERN_INFO MYNAM ": fusion_exit() called!\n"));
  5650. mpt_reset_deregister(mpt_base_index);
  5651. #ifdef CONFIG_PROC_FS
  5652. procmpt_destroy();
  5653. #endif
  5654. }
  5655. module_init(fusion_init);
  5656. module_exit(fusion_exit);