mptbase.c 185 KB

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