mptbase.c 185 KB

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