bnx2.c 149 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329
  1. /* bnx2.c: Broadcom NX2 network driver.
  2. *
  3. * Copyright (c) 2004, 2005, 2006 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Written by: Michael Chan (mchan@broadcom.com)
  10. */
  11. #include <linux/module.h>
  12. #include <linux/moduleparam.h>
  13. #include <linux/kernel.h>
  14. #include <linux/timer.h>
  15. #include <linux/errno.h>
  16. #include <linux/ioport.h>
  17. #include <linux/slab.h>
  18. #include <linux/vmalloc.h>
  19. #include <linux/interrupt.h>
  20. #include <linux/pci.h>
  21. #include <linux/init.h>
  22. #include <linux/netdevice.h>
  23. #include <linux/etherdevice.h>
  24. #include <linux/skbuff.h>
  25. #include <linux/dma-mapping.h>
  26. #include <asm/bitops.h>
  27. #include <asm/io.h>
  28. #include <asm/irq.h>
  29. #include <linux/delay.h>
  30. #include <asm/byteorder.h>
  31. #include <asm/page.h>
  32. #include <linux/time.h>
  33. #include <linux/ethtool.h>
  34. #include <linux/mii.h>
  35. #ifdef NETIF_F_HW_VLAN_TX
  36. #include <linux/if_vlan.h>
  37. #define BCM_VLAN 1
  38. #endif
  39. #include <net/ip.h>
  40. #include <net/tcp.h>
  41. #include <net/checksum.h>
  42. #include <linux/workqueue.h>
  43. #include <linux/crc32.h>
  44. #include <linux/prefetch.h>
  45. #include <linux/cache.h>
  46. #include <linux/zlib.h>
  47. #include "bnx2.h"
  48. #include "bnx2_fw.h"
  49. #include "bnx2_fw2.h"
  50. #define DRV_MODULE_NAME "bnx2"
  51. #define PFX DRV_MODULE_NAME ": "
  52. #define DRV_MODULE_VERSION "1.5.8"
  53. #define DRV_MODULE_RELDATE "April 24, 2007"
  54. #define RUN_AT(x) (jiffies + (x))
  55. /* Time in jiffies before concluding the transmitter is hung. */
  56. #define TX_TIMEOUT (5*HZ)
  57. static const char version[] __devinitdata =
  58. "Broadcom NetXtreme II Gigabit Ethernet Driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  59. MODULE_AUTHOR("Michael Chan <mchan@broadcom.com>");
  60. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM5706/5708 Driver");
  61. MODULE_LICENSE("GPL");
  62. MODULE_VERSION(DRV_MODULE_VERSION);
  63. static int disable_msi = 0;
  64. module_param(disable_msi, int, 0);
  65. MODULE_PARM_DESC(disable_msi, "Disable Message Signaled Interrupt (MSI)");
  66. typedef enum {
  67. BCM5706 = 0,
  68. NC370T,
  69. NC370I,
  70. BCM5706S,
  71. NC370F,
  72. BCM5708,
  73. BCM5708S,
  74. BCM5709,
  75. } board_t;
  76. /* indexed by board_t, above */
  77. static const struct {
  78. char *name;
  79. } board_info[] __devinitdata = {
  80. { "Broadcom NetXtreme II BCM5706 1000Base-T" },
  81. { "HP NC370T Multifunction Gigabit Server Adapter" },
  82. { "HP NC370i Multifunction Gigabit Server Adapter" },
  83. { "Broadcom NetXtreme II BCM5706 1000Base-SX" },
  84. { "HP NC370F Multifunction Gigabit Server Adapter" },
  85. { "Broadcom NetXtreme II BCM5708 1000Base-T" },
  86. { "Broadcom NetXtreme II BCM5708 1000Base-SX" },
  87. { "Broadcom NetXtreme II BCM5709 1000Base-T" },
  88. };
  89. static struct pci_device_id bnx2_pci_tbl[] = {
  90. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  91. PCI_VENDOR_ID_HP, 0x3101, 0, 0, NC370T },
  92. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  93. PCI_VENDOR_ID_HP, 0x3106, 0, 0, NC370I },
  94. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706,
  95. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706 },
  96. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708,
  97. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708 },
  98. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  99. PCI_VENDOR_ID_HP, 0x3102, 0, 0, NC370F },
  100. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5706S,
  101. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5706S },
  102. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5708S,
  103. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5708S },
  104. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_5709,
  105. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM5709 },
  106. { 0, }
  107. };
  108. static struct flash_spec flash_table[] =
  109. {
  110. /* Slow EEPROM */
  111. {0x00000000, 0x40830380, 0x009f0081, 0xa184a053, 0xaf000400,
  112. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  113. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  114. "EEPROM - slow"},
  115. /* Expansion entry 0001 */
  116. {0x08000002, 0x4b808201, 0x00050081, 0x03840253, 0xaf020406,
  117. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  118. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  119. "Entry 0001"},
  120. /* Saifun SA25F010 (non-buffered flash) */
  121. /* strap, cfg1, & write1 need updates */
  122. {0x04000001, 0x47808201, 0x00050081, 0x03840253, 0xaf020406,
  123. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  124. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*2,
  125. "Non-buffered flash (128kB)"},
  126. /* Saifun SA25F020 (non-buffered flash) */
  127. /* strap, cfg1, & write1 need updates */
  128. {0x0c000003, 0x4f808201, 0x00050081, 0x03840253, 0xaf020406,
  129. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  130. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE*4,
  131. "Non-buffered flash (256kB)"},
  132. /* Expansion entry 0100 */
  133. {0x11000000, 0x53808201, 0x00050081, 0x03840253, 0xaf020406,
  134. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  135. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  136. "Entry 0100"},
  137. /* Entry 0101: ST M45PE10 (non-buffered flash, TetonII B0) */
  138. {0x19000002, 0x5b808201, 0x000500db, 0x03840253, 0xaf020406,
  139. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  140. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*2,
  141. "Entry 0101: ST M45PE10 (128kB non-bufferred)"},
  142. /* Entry 0110: ST M45PE20 (non-buffered flash)*/
  143. {0x15000001, 0x57808201, 0x000500db, 0x03840253, 0xaf020406,
  144. 0, ST_MICRO_FLASH_PAGE_BITS, ST_MICRO_FLASH_PAGE_SIZE,
  145. ST_MICRO_FLASH_BYTE_ADDR_MASK, ST_MICRO_FLASH_BASE_TOTAL_SIZE*4,
  146. "Entry 0110: ST M45PE20 (256kB non-bufferred)"},
  147. /* Saifun SA25F005 (non-buffered flash) */
  148. /* strap, cfg1, & write1 need updates */
  149. {0x1d000003, 0x5f808201, 0x00050081, 0x03840253, 0xaf020406,
  150. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  151. SAIFUN_FLASH_BYTE_ADDR_MASK, SAIFUN_FLASH_BASE_TOTAL_SIZE,
  152. "Non-buffered flash (64kB)"},
  153. /* Fast EEPROM */
  154. {0x22000000, 0x62808380, 0x009f0081, 0xa184a053, 0xaf000400,
  155. 1, SEEPROM_PAGE_BITS, SEEPROM_PAGE_SIZE,
  156. SEEPROM_BYTE_ADDR_MASK, SEEPROM_TOTAL_SIZE,
  157. "EEPROM - fast"},
  158. /* Expansion entry 1001 */
  159. {0x2a000002, 0x6b808201, 0x00050081, 0x03840253, 0xaf020406,
  160. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  161. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  162. "Entry 1001"},
  163. /* Expansion entry 1010 */
  164. {0x26000001, 0x67808201, 0x00050081, 0x03840253, 0xaf020406,
  165. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  166. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  167. "Entry 1010"},
  168. /* ATMEL AT45DB011B (buffered flash) */
  169. {0x2e000003, 0x6e808273, 0x00570081, 0x68848353, 0xaf000400,
  170. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  171. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE,
  172. "Buffered flash (128kB)"},
  173. /* Expansion entry 1100 */
  174. {0x33000000, 0x73808201, 0x00050081, 0x03840253, 0xaf020406,
  175. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  176. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  177. "Entry 1100"},
  178. /* Expansion entry 1101 */
  179. {0x3b000002, 0x7b808201, 0x00050081, 0x03840253, 0xaf020406,
  180. 0, SAIFUN_FLASH_PAGE_BITS, SAIFUN_FLASH_PAGE_SIZE,
  181. SAIFUN_FLASH_BYTE_ADDR_MASK, 0,
  182. "Entry 1101"},
  183. /* Ateml Expansion entry 1110 */
  184. {0x37000001, 0x76808273, 0x00570081, 0x68848353, 0xaf000400,
  185. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  186. BUFFERED_FLASH_BYTE_ADDR_MASK, 0,
  187. "Entry 1110 (Atmel)"},
  188. /* ATMEL AT45DB021B (buffered flash) */
  189. {0x3f000003, 0x7e808273, 0x00570081, 0x68848353, 0xaf000400,
  190. 1, BUFFERED_FLASH_PAGE_BITS, BUFFERED_FLASH_PAGE_SIZE,
  191. BUFFERED_FLASH_BYTE_ADDR_MASK, BUFFERED_FLASH_TOTAL_SIZE*2,
  192. "Buffered flash (256kB)"},
  193. };
  194. MODULE_DEVICE_TABLE(pci, bnx2_pci_tbl);
  195. static inline u32 bnx2_tx_avail(struct bnx2 *bp)
  196. {
  197. u32 diff;
  198. smp_mb();
  199. /* The ring uses 256 indices for 255 entries, one of them
  200. * needs to be skipped.
  201. */
  202. diff = bp->tx_prod - bp->tx_cons;
  203. if (unlikely(diff >= TX_DESC_CNT)) {
  204. diff &= 0xffff;
  205. if (diff == TX_DESC_CNT)
  206. diff = MAX_TX_DESC_CNT;
  207. }
  208. return (bp->tx_ring_size - diff);
  209. }
  210. static u32
  211. bnx2_reg_rd_ind(struct bnx2 *bp, u32 offset)
  212. {
  213. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  214. return (REG_RD(bp, BNX2_PCICFG_REG_WINDOW));
  215. }
  216. static void
  217. bnx2_reg_wr_ind(struct bnx2 *bp, u32 offset, u32 val)
  218. {
  219. REG_WR(bp, BNX2_PCICFG_REG_WINDOW_ADDRESS, offset);
  220. REG_WR(bp, BNX2_PCICFG_REG_WINDOW, val);
  221. }
  222. static void
  223. bnx2_ctx_wr(struct bnx2 *bp, u32 cid_addr, u32 offset, u32 val)
  224. {
  225. offset += cid_addr;
  226. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  227. int i;
  228. REG_WR(bp, BNX2_CTX_CTX_DATA, val);
  229. REG_WR(bp, BNX2_CTX_CTX_CTRL,
  230. offset | BNX2_CTX_CTX_CTRL_WRITE_REQ);
  231. for (i = 0; i < 5; i++) {
  232. u32 val;
  233. val = REG_RD(bp, BNX2_CTX_CTX_CTRL);
  234. if ((val & BNX2_CTX_CTX_CTRL_WRITE_REQ) == 0)
  235. break;
  236. udelay(5);
  237. }
  238. } else {
  239. REG_WR(bp, BNX2_CTX_DATA_ADR, offset);
  240. REG_WR(bp, BNX2_CTX_DATA, val);
  241. }
  242. }
  243. static int
  244. bnx2_read_phy(struct bnx2 *bp, u32 reg, u32 *val)
  245. {
  246. u32 val1;
  247. int i, ret;
  248. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  249. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  250. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  251. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  252. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  253. udelay(40);
  254. }
  255. val1 = (bp->phy_addr << 21) | (reg << 16) |
  256. BNX2_EMAC_MDIO_COMM_COMMAND_READ | BNX2_EMAC_MDIO_COMM_DISEXT |
  257. BNX2_EMAC_MDIO_COMM_START_BUSY;
  258. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  259. for (i = 0; i < 50; i++) {
  260. udelay(10);
  261. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  262. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  263. udelay(5);
  264. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  265. val1 &= BNX2_EMAC_MDIO_COMM_DATA;
  266. break;
  267. }
  268. }
  269. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY) {
  270. *val = 0x0;
  271. ret = -EBUSY;
  272. }
  273. else {
  274. *val = val1;
  275. ret = 0;
  276. }
  277. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  278. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  279. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  280. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  281. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  282. udelay(40);
  283. }
  284. return ret;
  285. }
  286. static int
  287. bnx2_write_phy(struct bnx2 *bp, u32 reg, u32 val)
  288. {
  289. u32 val1;
  290. int i, ret;
  291. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  292. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  293. val1 &= ~BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  294. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  295. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  296. udelay(40);
  297. }
  298. val1 = (bp->phy_addr << 21) | (reg << 16) | val |
  299. BNX2_EMAC_MDIO_COMM_COMMAND_WRITE |
  300. BNX2_EMAC_MDIO_COMM_START_BUSY | BNX2_EMAC_MDIO_COMM_DISEXT;
  301. REG_WR(bp, BNX2_EMAC_MDIO_COMM, val1);
  302. for (i = 0; i < 50; i++) {
  303. udelay(10);
  304. val1 = REG_RD(bp, BNX2_EMAC_MDIO_COMM);
  305. if (!(val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)) {
  306. udelay(5);
  307. break;
  308. }
  309. }
  310. if (val1 & BNX2_EMAC_MDIO_COMM_START_BUSY)
  311. ret = -EBUSY;
  312. else
  313. ret = 0;
  314. if (bp->phy_flags & PHY_INT_MODE_AUTO_POLLING_FLAG) {
  315. val1 = REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  316. val1 |= BNX2_EMAC_MDIO_MODE_AUTO_POLL;
  317. REG_WR(bp, BNX2_EMAC_MDIO_MODE, val1);
  318. REG_RD(bp, BNX2_EMAC_MDIO_MODE);
  319. udelay(40);
  320. }
  321. return ret;
  322. }
  323. static void
  324. bnx2_disable_int(struct bnx2 *bp)
  325. {
  326. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  327. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  328. REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD);
  329. }
  330. static void
  331. bnx2_enable_int(struct bnx2 *bp)
  332. {
  333. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  334. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  335. BNX2_PCICFG_INT_ACK_CMD_MASK_INT | bp->last_status_idx);
  336. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  337. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID | bp->last_status_idx);
  338. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  339. }
  340. static void
  341. bnx2_disable_int_sync(struct bnx2 *bp)
  342. {
  343. atomic_inc(&bp->intr_sem);
  344. bnx2_disable_int(bp);
  345. synchronize_irq(bp->pdev->irq);
  346. }
  347. static void
  348. bnx2_netif_stop(struct bnx2 *bp)
  349. {
  350. bnx2_disable_int_sync(bp);
  351. if (netif_running(bp->dev)) {
  352. netif_poll_disable(bp->dev);
  353. netif_tx_disable(bp->dev);
  354. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  355. }
  356. }
  357. static void
  358. bnx2_netif_start(struct bnx2 *bp)
  359. {
  360. if (atomic_dec_and_test(&bp->intr_sem)) {
  361. if (netif_running(bp->dev)) {
  362. netif_wake_queue(bp->dev);
  363. netif_poll_enable(bp->dev);
  364. bnx2_enable_int(bp);
  365. }
  366. }
  367. }
  368. static void
  369. bnx2_free_mem(struct bnx2 *bp)
  370. {
  371. int i;
  372. for (i = 0; i < bp->ctx_pages; i++) {
  373. if (bp->ctx_blk[i]) {
  374. pci_free_consistent(bp->pdev, BCM_PAGE_SIZE,
  375. bp->ctx_blk[i],
  376. bp->ctx_blk_mapping[i]);
  377. bp->ctx_blk[i] = NULL;
  378. }
  379. }
  380. if (bp->status_blk) {
  381. pci_free_consistent(bp->pdev, bp->status_stats_size,
  382. bp->status_blk, bp->status_blk_mapping);
  383. bp->status_blk = NULL;
  384. bp->stats_blk = NULL;
  385. }
  386. if (bp->tx_desc_ring) {
  387. pci_free_consistent(bp->pdev,
  388. sizeof(struct tx_bd) * TX_DESC_CNT,
  389. bp->tx_desc_ring, bp->tx_desc_mapping);
  390. bp->tx_desc_ring = NULL;
  391. }
  392. kfree(bp->tx_buf_ring);
  393. bp->tx_buf_ring = NULL;
  394. for (i = 0; i < bp->rx_max_ring; i++) {
  395. if (bp->rx_desc_ring[i])
  396. pci_free_consistent(bp->pdev,
  397. sizeof(struct rx_bd) * RX_DESC_CNT,
  398. bp->rx_desc_ring[i],
  399. bp->rx_desc_mapping[i]);
  400. bp->rx_desc_ring[i] = NULL;
  401. }
  402. vfree(bp->rx_buf_ring);
  403. bp->rx_buf_ring = NULL;
  404. }
  405. static int
  406. bnx2_alloc_mem(struct bnx2 *bp)
  407. {
  408. int i, status_blk_size;
  409. bp->tx_buf_ring = kzalloc(sizeof(struct sw_bd) * TX_DESC_CNT,
  410. GFP_KERNEL);
  411. if (bp->tx_buf_ring == NULL)
  412. return -ENOMEM;
  413. bp->tx_desc_ring = pci_alloc_consistent(bp->pdev,
  414. sizeof(struct tx_bd) *
  415. TX_DESC_CNT,
  416. &bp->tx_desc_mapping);
  417. if (bp->tx_desc_ring == NULL)
  418. goto alloc_mem_err;
  419. bp->rx_buf_ring = vmalloc(sizeof(struct sw_bd) * RX_DESC_CNT *
  420. bp->rx_max_ring);
  421. if (bp->rx_buf_ring == NULL)
  422. goto alloc_mem_err;
  423. memset(bp->rx_buf_ring, 0, sizeof(struct sw_bd) * RX_DESC_CNT *
  424. bp->rx_max_ring);
  425. for (i = 0; i < bp->rx_max_ring; i++) {
  426. bp->rx_desc_ring[i] =
  427. pci_alloc_consistent(bp->pdev,
  428. sizeof(struct rx_bd) * RX_DESC_CNT,
  429. &bp->rx_desc_mapping[i]);
  430. if (bp->rx_desc_ring[i] == NULL)
  431. goto alloc_mem_err;
  432. }
  433. /* Combine status and statistics blocks into one allocation. */
  434. status_blk_size = L1_CACHE_ALIGN(sizeof(struct status_block));
  435. bp->status_stats_size = status_blk_size +
  436. sizeof(struct statistics_block);
  437. bp->status_blk = pci_alloc_consistent(bp->pdev, bp->status_stats_size,
  438. &bp->status_blk_mapping);
  439. if (bp->status_blk == NULL)
  440. goto alloc_mem_err;
  441. memset(bp->status_blk, 0, bp->status_stats_size);
  442. bp->stats_blk = (void *) ((unsigned long) bp->status_blk +
  443. status_blk_size);
  444. bp->stats_blk_mapping = bp->status_blk_mapping + status_blk_size;
  445. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  446. bp->ctx_pages = 0x2000 / BCM_PAGE_SIZE;
  447. if (bp->ctx_pages == 0)
  448. bp->ctx_pages = 1;
  449. for (i = 0; i < bp->ctx_pages; i++) {
  450. bp->ctx_blk[i] = pci_alloc_consistent(bp->pdev,
  451. BCM_PAGE_SIZE,
  452. &bp->ctx_blk_mapping[i]);
  453. if (bp->ctx_blk[i] == NULL)
  454. goto alloc_mem_err;
  455. }
  456. }
  457. return 0;
  458. alloc_mem_err:
  459. bnx2_free_mem(bp);
  460. return -ENOMEM;
  461. }
  462. static void
  463. bnx2_report_fw_link(struct bnx2 *bp)
  464. {
  465. u32 fw_link_status = 0;
  466. if (bp->link_up) {
  467. u32 bmsr;
  468. switch (bp->line_speed) {
  469. case SPEED_10:
  470. if (bp->duplex == DUPLEX_HALF)
  471. fw_link_status = BNX2_LINK_STATUS_10HALF;
  472. else
  473. fw_link_status = BNX2_LINK_STATUS_10FULL;
  474. break;
  475. case SPEED_100:
  476. if (bp->duplex == DUPLEX_HALF)
  477. fw_link_status = BNX2_LINK_STATUS_100HALF;
  478. else
  479. fw_link_status = BNX2_LINK_STATUS_100FULL;
  480. break;
  481. case SPEED_1000:
  482. if (bp->duplex == DUPLEX_HALF)
  483. fw_link_status = BNX2_LINK_STATUS_1000HALF;
  484. else
  485. fw_link_status = BNX2_LINK_STATUS_1000FULL;
  486. break;
  487. case SPEED_2500:
  488. if (bp->duplex == DUPLEX_HALF)
  489. fw_link_status = BNX2_LINK_STATUS_2500HALF;
  490. else
  491. fw_link_status = BNX2_LINK_STATUS_2500FULL;
  492. break;
  493. }
  494. fw_link_status |= BNX2_LINK_STATUS_LINK_UP;
  495. if (bp->autoneg) {
  496. fw_link_status |= BNX2_LINK_STATUS_AN_ENABLED;
  497. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  498. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  499. if (!(bmsr & BMSR_ANEGCOMPLETE) ||
  500. bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)
  501. fw_link_status |= BNX2_LINK_STATUS_PARALLEL_DET;
  502. else
  503. fw_link_status |= BNX2_LINK_STATUS_AN_COMPLETE;
  504. }
  505. }
  506. else
  507. fw_link_status = BNX2_LINK_STATUS_LINK_DOWN;
  508. REG_WR_IND(bp, bp->shmem_base + BNX2_LINK_STATUS, fw_link_status);
  509. }
  510. static void
  511. bnx2_report_link(struct bnx2 *bp)
  512. {
  513. if (bp->link_up) {
  514. netif_carrier_on(bp->dev);
  515. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  516. printk("%d Mbps ", bp->line_speed);
  517. if (bp->duplex == DUPLEX_FULL)
  518. printk("full duplex");
  519. else
  520. printk("half duplex");
  521. if (bp->flow_ctrl) {
  522. if (bp->flow_ctrl & FLOW_CTRL_RX) {
  523. printk(", receive ");
  524. if (bp->flow_ctrl & FLOW_CTRL_TX)
  525. printk("& transmit ");
  526. }
  527. else {
  528. printk(", transmit ");
  529. }
  530. printk("flow control ON");
  531. }
  532. printk("\n");
  533. }
  534. else {
  535. netif_carrier_off(bp->dev);
  536. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  537. }
  538. bnx2_report_fw_link(bp);
  539. }
  540. static void
  541. bnx2_resolve_flow_ctrl(struct bnx2 *bp)
  542. {
  543. u32 local_adv, remote_adv;
  544. bp->flow_ctrl = 0;
  545. if ((bp->autoneg & (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) !=
  546. (AUTONEG_SPEED | AUTONEG_FLOW_CTRL)) {
  547. if (bp->duplex == DUPLEX_FULL) {
  548. bp->flow_ctrl = bp->req_flow_ctrl;
  549. }
  550. return;
  551. }
  552. if (bp->duplex != DUPLEX_FULL) {
  553. return;
  554. }
  555. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  556. (CHIP_NUM(bp) == CHIP_NUM_5708)) {
  557. u32 val;
  558. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  559. if (val & BCM5708S_1000X_STAT1_TX_PAUSE)
  560. bp->flow_ctrl |= FLOW_CTRL_TX;
  561. if (val & BCM5708S_1000X_STAT1_RX_PAUSE)
  562. bp->flow_ctrl |= FLOW_CTRL_RX;
  563. return;
  564. }
  565. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  566. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  567. if (bp->phy_flags & PHY_SERDES_FLAG) {
  568. u32 new_local_adv = 0;
  569. u32 new_remote_adv = 0;
  570. if (local_adv & ADVERTISE_1000XPAUSE)
  571. new_local_adv |= ADVERTISE_PAUSE_CAP;
  572. if (local_adv & ADVERTISE_1000XPSE_ASYM)
  573. new_local_adv |= ADVERTISE_PAUSE_ASYM;
  574. if (remote_adv & ADVERTISE_1000XPAUSE)
  575. new_remote_adv |= ADVERTISE_PAUSE_CAP;
  576. if (remote_adv & ADVERTISE_1000XPSE_ASYM)
  577. new_remote_adv |= ADVERTISE_PAUSE_ASYM;
  578. local_adv = new_local_adv;
  579. remote_adv = new_remote_adv;
  580. }
  581. /* See Table 28B-3 of 802.3ab-1999 spec. */
  582. if (local_adv & ADVERTISE_PAUSE_CAP) {
  583. if(local_adv & ADVERTISE_PAUSE_ASYM) {
  584. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  585. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  586. }
  587. else if (remote_adv & ADVERTISE_PAUSE_ASYM) {
  588. bp->flow_ctrl = FLOW_CTRL_RX;
  589. }
  590. }
  591. else {
  592. if (remote_adv & ADVERTISE_PAUSE_CAP) {
  593. bp->flow_ctrl = FLOW_CTRL_TX | FLOW_CTRL_RX;
  594. }
  595. }
  596. }
  597. else if (local_adv & ADVERTISE_PAUSE_ASYM) {
  598. if ((remote_adv & ADVERTISE_PAUSE_CAP) &&
  599. (remote_adv & ADVERTISE_PAUSE_ASYM)) {
  600. bp->flow_ctrl = FLOW_CTRL_TX;
  601. }
  602. }
  603. }
  604. static int
  605. bnx2_5708s_linkup(struct bnx2 *bp)
  606. {
  607. u32 val;
  608. bp->link_up = 1;
  609. bnx2_read_phy(bp, BCM5708S_1000X_STAT1, &val);
  610. switch (val & BCM5708S_1000X_STAT1_SPEED_MASK) {
  611. case BCM5708S_1000X_STAT1_SPEED_10:
  612. bp->line_speed = SPEED_10;
  613. break;
  614. case BCM5708S_1000X_STAT1_SPEED_100:
  615. bp->line_speed = SPEED_100;
  616. break;
  617. case BCM5708S_1000X_STAT1_SPEED_1G:
  618. bp->line_speed = SPEED_1000;
  619. break;
  620. case BCM5708S_1000X_STAT1_SPEED_2G5:
  621. bp->line_speed = SPEED_2500;
  622. break;
  623. }
  624. if (val & BCM5708S_1000X_STAT1_FD)
  625. bp->duplex = DUPLEX_FULL;
  626. else
  627. bp->duplex = DUPLEX_HALF;
  628. return 0;
  629. }
  630. static int
  631. bnx2_5706s_linkup(struct bnx2 *bp)
  632. {
  633. u32 bmcr, local_adv, remote_adv, common;
  634. bp->link_up = 1;
  635. bp->line_speed = SPEED_1000;
  636. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  637. if (bmcr & BMCR_FULLDPLX) {
  638. bp->duplex = DUPLEX_FULL;
  639. }
  640. else {
  641. bp->duplex = DUPLEX_HALF;
  642. }
  643. if (!(bmcr & BMCR_ANENABLE)) {
  644. return 0;
  645. }
  646. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  647. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  648. common = local_adv & remote_adv;
  649. if (common & (ADVERTISE_1000XHALF | ADVERTISE_1000XFULL)) {
  650. if (common & ADVERTISE_1000XFULL) {
  651. bp->duplex = DUPLEX_FULL;
  652. }
  653. else {
  654. bp->duplex = DUPLEX_HALF;
  655. }
  656. }
  657. return 0;
  658. }
  659. static int
  660. bnx2_copper_linkup(struct bnx2 *bp)
  661. {
  662. u32 bmcr;
  663. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  664. if (bmcr & BMCR_ANENABLE) {
  665. u32 local_adv, remote_adv, common;
  666. bnx2_read_phy(bp, MII_CTRL1000, &local_adv);
  667. bnx2_read_phy(bp, MII_STAT1000, &remote_adv);
  668. common = local_adv & (remote_adv >> 2);
  669. if (common & ADVERTISE_1000FULL) {
  670. bp->line_speed = SPEED_1000;
  671. bp->duplex = DUPLEX_FULL;
  672. }
  673. else if (common & ADVERTISE_1000HALF) {
  674. bp->line_speed = SPEED_1000;
  675. bp->duplex = DUPLEX_HALF;
  676. }
  677. else {
  678. bnx2_read_phy(bp, bp->mii_adv, &local_adv);
  679. bnx2_read_phy(bp, bp->mii_lpa, &remote_adv);
  680. common = local_adv & remote_adv;
  681. if (common & ADVERTISE_100FULL) {
  682. bp->line_speed = SPEED_100;
  683. bp->duplex = DUPLEX_FULL;
  684. }
  685. else if (common & ADVERTISE_100HALF) {
  686. bp->line_speed = SPEED_100;
  687. bp->duplex = DUPLEX_HALF;
  688. }
  689. else if (common & ADVERTISE_10FULL) {
  690. bp->line_speed = SPEED_10;
  691. bp->duplex = DUPLEX_FULL;
  692. }
  693. else if (common & ADVERTISE_10HALF) {
  694. bp->line_speed = SPEED_10;
  695. bp->duplex = DUPLEX_HALF;
  696. }
  697. else {
  698. bp->line_speed = 0;
  699. bp->link_up = 0;
  700. }
  701. }
  702. }
  703. else {
  704. if (bmcr & BMCR_SPEED100) {
  705. bp->line_speed = SPEED_100;
  706. }
  707. else {
  708. bp->line_speed = SPEED_10;
  709. }
  710. if (bmcr & BMCR_FULLDPLX) {
  711. bp->duplex = DUPLEX_FULL;
  712. }
  713. else {
  714. bp->duplex = DUPLEX_HALF;
  715. }
  716. }
  717. return 0;
  718. }
  719. static int
  720. bnx2_set_mac_link(struct bnx2 *bp)
  721. {
  722. u32 val;
  723. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x2620);
  724. if (bp->link_up && (bp->line_speed == SPEED_1000) &&
  725. (bp->duplex == DUPLEX_HALF)) {
  726. REG_WR(bp, BNX2_EMAC_TX_LENGTHS, 0x26ff);
  727. }
  728. /* Configure the EMAC mode register. */
  729. val = REG_RD(bp, BNX2_EMAC_MODE);
  730. val &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  731. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  732. BNX2_EMAC_MODE_25G_MODE);
  733. if (bp->link_up) {
  734. switch (bp->line_speed) {
  735. case SPEED_10:
  736. if (CHIP_NUM(bp) != CHIP_NUM_5706) {
  737. val |= BNX2_EMAC_MODE_PORT_MII_10M;
  738. break;
  739. }
  740. /* fall through */
  741. case SPEED_100:
  742. val |= BNX2_EMAC_MODE_PORT_MII;
  743. break;
  744. case SPEED_2500:
  745. val |= BNX2_EMAC_MODE_25G_MODE;
  746. /* fall through */
  747. case SPEED_1000:
  748. val |= BNX2_EMAC_MODE_PORT_GMII;
  749. break;
  750. }
  751. }
  752. else {
  753. val |= BNX2_EMAC_MODE_PORT_GMII;
  754. }
  755. /* Set the MAC to operate in the appropriate duplex mode. */
  756. if (bp->duplex == DUPLEX_HALF)
  757. val |= BNX2_EMAC_MODE_HALF_DUPLEX;
  758. REG_WR(bp, BNX2_EMAC_MODE, val);
  759. /* Enable/disable rx PAUSE. */
  760. bp->rx_mode &= ~BNX2_EMAC_RX_MODE_FLOW_EN;
  761. if (bp->flow_ctrl & FLOW_CTRL_RX)
  762. bp->rx_mode |= BNX2_EMAC_RX_MODE_FLOW_EN;
  763. REG_WR(bp, BNX2_EMAC_RX_MODE, bp->rx_mode);
  764. /* Enable/disable tx PAUSE. */
  765. val = REG_RD(bp, BNX2_EMAC_TX_MODE);
  766. val &= ~BNX2_EMAC_TX_MODE_FLOW_EN;
  767. if (bp->flow_ctrl & FLOW_CTRL_TX)
  768. val |= BNX2_EMAC_TX_MODE_FLOW_EN;
  769. REG_WR(bp, BNX2_EMAC_TX_MODE, val);
  770. /* Acknowledge the interrupt. */
  771. REG_WR(bp, BNX2_EMAC_STATUS, BNX2_EMAC_STATUS_LINK_CHANGE);
  772. return 0;
  773. }
  774. static int
  775. bnx2_test_and_enable_2g5(struct bnx2 *bp)
  776. {
  777. u32 up1;
  778. int ret = 1;
  779. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  780. return 0;
  781. if (bp->autoneg & AUTONEG_SPEED)
  782. bp->advertising |= ADVERTISED_2500baseX_Full;
  783. bnx2_read_phy(bp, bp->mii_up1, &up1);
  784. if (!(up1 & BCM5708S_UP1_2G5)) {
  785. up1 |= BCM5708S_UP1_2G5;
  786. bnx2_write_phy(bp, bp->mii_up1, up1);
  787. ret = 0;
  788. }
  789. return ret;
  790. }
  791. static int
  792. bnx2_test_and_disable_2g5(struct bnx2 *bp)
  793. {
  794. u32 up1;
  795. int ret = 0;
  796. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  797. return 0;
  798. bnx2_read_phy(bp, bp->mii_up1, &up1);
  799. if (up1 & BCM5708S_UP1_2G5) {
  800. up1 &= ~BCM5708S_UP1_2G5;
  801. bnx2_write_phy(bp, bp->mii_up1, up1);
  802. ret = 1;
  803. }
  804. return ret;
  805. }
  806. static void
  807. bnx2_enable_forced_2g5(struct bnx2 *bp)
  808. {
  809. u32 bmcr;
  810. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  811. return;
  812. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  813. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  814. bmcr |= BCM5708S_BMCR_FORCE_2500;
  815. }
  816. if (bp->autoneg & AUTONEG_SPEED) {
  817. bmcr &= ~BMCR_ANENABLE;
  818. if (bp->req_duplex == DUPLEX_FULL)
  819. bmcr |= BMCR_FULLDPLX;
  820. }
  821. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  822. }
  823. static void
  824. bnx2_disable_forced_2g5(struct bnx2 *bp)
  825. {
  826. u32 bmcr;
  827. if (!(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  828. return;
  829. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  830. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  831. bmcr &= ~BCM5708S_BMCR_FORCE_2500;
  832. }
  833. if (bp->autoneg & AUTONEG_SPEED)
  834. bmcr |= BMCR_SPEED1000 | BMCR_ANENABLE | BMCR_ANRESTART;
  835. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  836. }
  837. static int
  838. bnx2_set_link(struct bnx2 *bp)
  839. {
  840. u32 bmsr;
  841. u8 link_up;
  842. if (bp->loopback == MAC_LOOPBACK || bp->loopback == PHY_LOOPBACK) {
  843. bp->link_up = 1;
  844. return 0;
  845. }
  846. link_up = bp->link_up;
  847. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  848. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  849. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  850. (CHIP_NUM(bp) == CHIP_NUM_5706)) {
  851. u32 val;
  852. val = REG_RD(bp, BNX2_EMAC_STATUS);
  853. if (val & BNX2_EMAC_STATUS_LINK)
  854. bmsr |= BMSR_LSTATUS;
  855. else
  856. bmsr &= ~BMSR_LSTATUS;
  857. }
  858. if (bmsr & BMSR_LSTATUS) {
  859. bp->link_up = 1;
  860. if (bp->phy_flags & PHY_SERDES_FLAG) {
  861. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  862. bnx2_5706s_linkup(bp);
  863. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  864. bnx2_5708s_linkup(bp);
  865. }
  866. else {
  867. bnx2_copper_linkup(bp);
  868. }
  869. bnx2_resolve_flow_ctrl(bp);
  870. }
  871. else {
  872. if ((bp->phy_flags & PHY_SERDES_FLAG) &&
  873. (bp->autoneg & AUTONEG_SPEED))
  874. bnx2_disable_forced_2g5(bp);
  875. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  876. bp->link_up = 0;
  877. }
  878. if (bp->link_up != link_up) {
  879. bnx2_report_link(bp);
  880. }
  881. bnx2_set_mac_link(bp);
  882. return 0;
  883. }
  884. static int
  885. bnx2_reset_phy(struct bnx2 *bp)
  886. {
  887. int i;
  888. u32 reg;
  889. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_RESET);
  890. #define PHY_RESET_MAX_WAIT 100
  891. for (i = 0; i < PHY_RESET_MAX_WAIT; i++) {
  892. udelay(10);
  893. bnx2_read_phy(bp, bp->mii_bmcr, &reg);
  894. if (!(reg & BMCR_RESET)) {
  895. udelay(20);
  896. break;
  897. }
  898. }
  899. if (i == PHY_RESET_MAX_WAIT) {
  900. return -EBUSY;
  901. }
  902. return 0;
  903. }
  904. static u32
  905. bnx2_phy_get_pause_adv(struct bnx2 *bp)
  906. {
  907. u32 adv = 0;
  908. if ((bp->req_flow_ctrl & (FLOW_CTRL_RX | FLOW_CTRL_TX)) ==
  909. (FLOW_CTRL_RX | FLOW_CTRL_TX)) {
  910. if (bp->phy_flags & PHY_SERDES_FLAG) {
  911. adv = ADVERTISE_1000XPAUSE;
  912. }
  913. else {
  914. adv = ADVERTISE_PAUSE_CAP;
  915. }
  916. }
  917. else if (bp->req_flow_ctrl & FLOW_CTRL_TX) {
  918. if (bp->phy_flags & PHY_SERDES_FLAG) {
  919. adv = ADVERTISE_1000XPSE_ASYM;
  920. }
  921. else {
  922. adv = ADVERTISE_PAUSE_ASYM;
  923. }
  924. }
  925. else if (bp->req_flow_ctrl & FLOW_CTRL_RX) {
  926. if (bp->phy_flags & PHY_SERDES_FLAG) {
  927. adv = ADVERTISE_1000XPAUSE | ADVERTISE_1000XPSE_ASYM;
  928. }
  929. else {
  930. adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  931. }
  932. }
  933. return adv;
  934. }
  935. static int
  936. bnx2_setup_serdes_phy(struct bnx2 *bp)
  937. {
  938. u32 adv, bmcr;
  939. u32 new_adv = 0;
  940. if (!(bp->autoneg & AUTONEG_SPEED)) {
  941. u32 new_bmcr;
  942. int force_link_down = 0;
  943. if (bp->req_line_speed == SPEED_2500) {
  944. if (!bnx2_test_and_enable_2g5(bp))
  945. force_link_down = 1;
  946. } else if (bp->req_line_speed == SPEED_1000) {
  947. if (bnx2_test_and_disable_2g5(bp))
  948. force_link_down = 1;
  949. }
  950. bnx2_read_phy(bp, bp->mii_adv, &adv);
  951. adv &= ~(ADVERTISE_1000XFULL | ADVERTISE_1000XHALF);
  952. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  953. new_bmcr = bmcr & ~BMCR_ANENABLE;
  954. new_bmcr |= BMCR_SPEED1000;
  955. if (CHIP_NUM(bp) == CHIP_NUM_5708) {
  956. if (bp->req_line_speed == SPEED_2500)
  957. new_bmcr |= BCM5708S_BMCR_FORCE_2500;
  958. else
  959. new_bmcr = bmcr & ~BCM5708S_BMCR_FORCE_2500;
  960. }
  961. if (bp->req_duplex == DUPLEX_FULL) {
  962. adv |= ADVERTISE_1000XFULL;
  963. new_bmcr |= BMCR_FULLDPLX;
  964. }
  965. else {
  966. adv |= ADVERTISE_1000XHALF;
  967. new_bmcr &= ~BMCR_FULLDPLX;
  968. }
  969. if ((new_bmcr != bmcr) || (force_link_down)) {
  970. /* Force a link down visible on the other side */
  971. if (bp->link_up) {
  972. bnx2_write_phy(bp, bp->mii_adv, adv &
  973. ~(ADVERTISE_1000XFULL |
  974. ADVERTISE_1000XHALF));
  975. bnx2_write_phy(bp, bp->mii_bmcr, bmcr |
  976. BMCR_ANRESTART | BMCR_ANENABLE);
  977. bp->link_up = 0;
  978. netif_carrier_off(bp->dev);
  979. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  980. bnx2_report_link(bp);
  981. }
  982. bnx2_write_phy(bp, bp->mii_adv, adv);
  983. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  984. } else {
  985. bnx2_resolve_flow_ctrl(bp);
  986. bnx2_set_mac_link(bp);
  987. }
  988. return 0;
  989. }
  990. bnx2_test_and_enable_2g5(bp);
  991. if (bp->advertising & ADVERTISED_1000baseT_Full)
  992. new_adv |= ADVERTISE_1000XFULL;
  993. new_adv |= bnx2_phy_get_pause_adv(bp);
  994. bnx2_read_phy(bp, bp->mii_adv, &adv);
  995. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  996. bp->serdes_an_pending = 0;
  997. if ((adv != new_adv) || ((bmcr & BMCR_ANENABLE) == 0)) {
  998. /* Force a link down visible on the other side */
  999. if (bp->link_up) {
  1000. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1001. spin_unlock_bh(&bp->phy_lock);
  1002. msleep(20);
  1003. spin_lock_bh(&bp->phy_lock);
  1004. }
  1005. bnx2_write_phy(bp, bp->mii_adv, new_adv);
  1006. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART |
  1007. BMCR_ANENABLE);
  1008. /* Speed up link-up time when the link partner
  1009. * does not autonegotiate which is very common
  1010. * in blade servers. Some blade servers use
  1011. * IPMI for kerboard input and it's important
  1012. * to minimize link disruptions. Autoneg. involves
  1013. * exchanging base pages plus 3 next pages and
  1014. * normally completes in about 120 msec.
  1015. */
  1016. bp->current_interval = SERDES_AN_TIMEOUT;
  1017. bp->serdes_an_pending = 1;
  1018. mod_timer(&bp->timer, jiffies + bp->current_interval);
  1019. } else {
  1020. bnx2_resolve_flow_ctrl(bp);
  1021. bnx2_set_mac_link(bp);
  1022. }
  1023. return 0;
  1024. }
  1025. #define ETHTOOL_ALL_FIBRE_SPEED \
  1026. (ADVERTISED_1000baseT_Full)
  1027. #define ETHTOOL_ALL_COPPER_SPEED \
  1028. (ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | \
  1029. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | \
  1030. ADVERTISED_1000baseT_Full)
  1031. #define PHY_ALL_10_100_SPEED (ADVERTISE_10HALF | ADVERTISE_10FULL | \
  1032. ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_CSMA)
  1033. #define PHY_ALL_1000_SPEED (ADVERTISE_1000HALF | ADVERTISE_1000FULL)
  1034. static int
  1035. bnx2_setup_copper_phy(struct bnx2 *bp)
  1036. {
  1037. u32 bmcr;
  1038. u32 new_bmcr;
  1039. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  1040. if (bp->autoneg & AUTONEG_SPEED) {
  1041. u32 adv_reg, adv1000_reg;
  1042. u32 new_adv_reg = 0;
  1043. u32 new_adv1000_reg = 0;
  1044. bnx2_read_phy(bp, bp->mii_adv, &adv_reg);
  1045. adv_reg &= (PHY_ALL_10_100_SPEED | ADVERTISE_PAUSE_CAP |
  1046. ADVERTISE_PAUSE_ASYM);
  1047. bnx2_read_phy(bp, MII_CTRL1000, &adv1000_reg);
  1048. adv1000_reg &= PHY_ALL_1000_SPEED;
  1049. if (bp->advertising & ADVERTISED_10baseT_Half)
  1050. new_adv_reg |= ADVERTISE_10HALF;
  1051. if (bp->advertising & ADVERTISED_10baseT_Full)
  1052. new_adv_reg |= ADVERTISE_10FULL;
  1053. if (bp->advertising & ADVERTISED_100baseT_Half)
  1054. new_adv_reg |= ADVERTISE_100HALF;
  1055. if (bp->advertising & ADVERTISED_100baseT_Full)
  1056. new_adv_reg |= ADVERTISE_100FULL;
  1057. if (bp->advertising & ADVERTISED_1000baseT_Full)
  1058. new_adv1000_reg |= ADVERTISE_1000FULL;
  1059. new_adv_reg |= ADVERTISE_CSMA;
  1060. new_adv_reg |= bnx2_phy_get_pause_adv(bp);
  1061. if ((adv1000_reg != new_adv1000_reg) ||
  1062. (adv_reg != new_adv_reg) ||
  1063. ((bmcr & BMCR_ANENABLE) == 0)) {
  1064. bnx2_write_phy(bp, bp->mii_adv, new_adv_reg);
  1065. bnx2_write_phy(bp, MII_CTRL1000, new_adv1000_reg);
  1066. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_ANRESTART |
  1067. BMCR_ANENABLE);
  1068. }
  1069. else if (bp->link_up) {
  1070. /* Flow ctrl may have changed from auto to forced */
  1071. /* or vice-versa. */
  1072. bnx2_resolve_flow_ctrl(bp);
  1073. bnx2_set_mac_link(bp);
  1074. }
  1075. return 0;
  1076. }
  1077. new_bmcr = 0;
  1078. if (bp->req_line_speed == SPEED_100) {
  1079. new_bmcr |= BMCR_SPEED100;
  1080. }
  1081. if (bp->req_duplex == DUPLEX_FULL) {
  1082. new_bmcr |= BMCR_FULLDPLX;
  1083. }
  1084. if (new_bmcr != bmcr) {
  1085. u32 bmsr;
  1086. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1087. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1088. if (bmsr & BMSR_LSTATUS) {
  1089. /* Force link down */
  1090. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  1091. spin_unlock_bh(&bp->phy_lock);
  1092. msleep(50);
  1093. spin_lock_bh(&bp->phy_lock);
  1094. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1095. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  1096. }
  1097. bnx2_write_phy(bp, bp->mii_bmcr, new_bmcr);
  1098. /* Normally, the new speed is setup after the link has
  1099. * gone down and up again. In some cases, link will not go
  1100. * down so we need to set up the new speed here.
  1101. */
  1102. if (bmsr & BMSR_LSTATUS) {
  1103. bp->line_speed = bp->req_line_speed;
  1104. bp->duplex = bp->req_duplex;
  1105. bnx2_resolve_flow_ctrl(bp);
  1106. bnx2_set_mac_link(bp);
  1107. }
  1108. }
  1109. return 0;
  1110. }
  1111. static int
  1112. bnx2_setup_phy(struct bnx2 *bp)
  1113. {
  1114. if (bp->loopback == MAC_LOOPBACK)
  1115. return 0;
  1116. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1117. return (bnx2_setup_serdes_phy(bp));
  1118. }
  1119. else {
  1120. return (bnx2_setup_copper_phy(bp));
  1121. }
  1122. }
  1123. static int
  1124. bnx2_init_5708s_phy(struct bnx2 *bp)
  1125. {
  1126. u32 val;
  1127. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG3);
  1128. bnx2_write_phy(bp, BCM5708S_DIG_3_0, BCM5708S_DIG_3_0_USE_IEEE);
  1129. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1130. bnx2_read_phy(bp, BCM5708S_1000X_CTL1, &val);
  1131. val |= BCM5708S_1000X_CTL1_FIBER_MODE | BCM5708S_1000X_CTL1_AUTODET_EN;
  1132. bnx2_write_phy(bp, BCM5708S_1000X_CTL1, val);
  1133. bnx2_read_phy(bp, BCM5708S_1000X_CTL2, &val);
  1134. val |= BCM5708S_1000X_CTL2_PLLEL_DET_EN;
  1135. bnx2_write_phy(bp, BCM5708S_1000X_CTL2, val);
  1136. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) {
  1137. bnx2_read_phy(bp, BCM5708S_UP1, &val);
  1138. val |= BCM5708S_UP1_2G5;
  1139. bnx2_write_phy(bp, BCM5708S_UP1, val);
  1140. }
  1141. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  1142. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  1143. (CHIP_ID(bp) == CHIP_ID_5708_B1)) {
  1144. /* increase tx signal amplitude */
  1145. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1146. BCM5708S_BLK_ADDR_TX_MISC);
  1147. bnx2_read_phy(bp, BCM5708S_TX_ACTL1, &val);
  1148. val &= ~BCM5708S_TX_ACTL1_DRIVER_VCM;
  1149. bnx2_write_phy(bp, BCM5708S_TX_ACTL1, val);
  1150. bnx2_write_phy(bp, BCM5708S_BLK_ADDR, BCM5708S_BLK_ADDR_DIG);
  1151. }
  1152. val = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG) &
  1153. BNX2_PORT_HW_CFG_CFG_TXCTL3_MASK;
  1154. if (val) {
  1155. u32 is_backplane;
  1156. is_backplane = REG_RD_IND(bp, bp->shmem_base +
  1157. BNX2_SHARED_HW_CFG_CONFIG);
  1158. if (is_backplane & BNX2_SHARED_HW_CFG_PHY_BACKPLANE) {
  1159. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1160. BCM5708S_BLK_ADDR_TX_MISC);
  1161. bnx2_write_phy(bp, BCM5708S_TX_ACTL3, val);
  1162. bnx2_write_phy(bp, BCM5708S_BLK_ADDR,
  1163. BCM5708S_BLK_ADDR_DIG);
  1164. }
  1165. }
  1166. return 0;
  1167. }
  1168. static int
  1169. bnx2_init_5706s_phy(struct bnx2 *bp)
  1170. {
  1171. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  1172. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1173. REG_WR(bp, BNX2_MISC_GP_HW_CTL0, 0x300);
  1174. if (bp->dev->mtu > 1500) {
  1175. u32 val;
  1176. /* Set extended packet length bit */
  1177. bnx2_write_phy(bp, 0x18, 0x7);
  1178. bnx2_read_phy(bp, 0x18, &val);
  1179. bnx2_write_phy(bp, 0x18, (val & 0xfff8) | 0x4000);
  1180. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1181. bnx2_read_phy(bp, 0x1c, &val);
  1182. bnx2_write_phy(bp, 0x1c, (val & 0x3ff) | 0xec02);
  1183. }
  1184. else {
  1185. u32 val;
  1186. bnx2_write_phy(bp, 0x18, 0x7);
  1187. bnx2_read_phy(bp, 0x18, &val);
  1188. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1189. bnx2_write_phy(bp, 0x1c, 0x6c00);
  1190. bnx2_read_phy(bp, 0x1c, &val);
  1191. bnx2_write_phy(bp, 0x1c, (val & 0x3fd) | 0xec00);
  1192. }
  1193. return 0;
  1194. }
  1195. static int
  1196. bnx2_init_copper_phy(struct bnx2 *bp)
  1197. {
  1198. u32 val;
  1199. if (bp->phy_flags & PHY_CRC_FIX_FLAG) {
  1200. bnx2_write_phy(bp, 0x18, 0x0c00);
  1201. bnx2_write_phy(bp, 0x17, 0x000a);
  1202. bnx2_write_phy(bp, 0x15, 0x310b);
  1203. bnx2_write_phy(bp, 0x17, 0x201f);
  1204. bnx2_write_phy(bp, 0x15, 0x9506);
  1205. bnx2_write_phy(bp, 0x17, 0x401f);
  1206. bnx2_write_phy(bp, 0x15, 0x14e2);
  1207. bnx2_write_phy(bp, 0x18, 0x0400);
  1208. }
  1209. if (bp->phy_flags & PHY_DIS_EARLY_DAC_FLAG) {
  1210. bnx2_write_phy(bp, MII_BNX2_DSP_ADDRESS,
  1211. MII_BNX2_DSP_EXPAND_REG | 0x8);
  1212. bnx2_read_phy(bp, MII_BNX2_DSP_RW_PORT, &val);
  1213. val &= ~(1 << 8);
  1214. bnx2_write_phy(bp, MII_BNX2_DSP_RW_PORT, val);
  1215. }
  1216. if (bp->dev->mtu > 1500) {
  1217. /* Set extended packet length bit */
  1218. bnx2_write_phy(bp, 0x18, 0x7);
  1219. bnx2_read_phy(bp, 0x18, &val);
  1220. bnx2_write_phy(bp, 0x18, val | 0x4000);
  1221. bnx2_read_phy(bp, 0x10, &val);
  1222. bnx2_write_phy(bp, 0x10, val | 0x1);
  1223. }
  1224. else {
  1225. bnx2_write_phy(bp, 0x18, 0x7);
  1226. bnx2_read_phy(bp, 0x18, &val);
  1227. bnx2_write_phy(bp, 0x18, val & ~0x4007);
  1228. bnx2_read_phy(bp, 0x10, &val);
  1229. bnx2_write_phy(bp, 0x10, val & ~0x1);
  1230. }
  1231. /* ethernet@wirespeed */
  1232. bnx2_write_phy(bp, 0x18, 0x7007);
  1233. bnx2_read_phy(bp, 0x18, &val);
  1234. bnx2_write_phy(bp, 0x18, val | (1 << 15) | (1 << 4));
  1235. return 0;
  1236. }
  1237. static int
  1238. bnx2_init_phy(struct bnx2 *bp)
  1239. {
  1240. u32 val;
  1241. int rc = 0;
  1242. bp->phy_flags &= ~PHY_INT_MODE_MASK_FLAG;
  1243. bp->phy_flags |= PHY_INT_MODE_LINK_READY_FLAG;
  1244. bp->mii_bmcr = MII_BMCR;
  1245. bp->mii_bmsr = MII_BMSR;
  1246. bp->mii_adv = MII_ADVERTISE;
  1247. bp->mii_lpa = MII_LPA;
  1248. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  1249. bnx2_reset_phy(bp);
  1250. bnx2_read_phy(bp, MII_PHYSID1, &val);
  1251. bp->phy_id = val << 16;
  1252. bnx2_read_phy(bp, MII_PHYSID2, &val);
  1253. bp->phy_id |= val & 0xffff;
  1254. if (bp->phy_flags & PHY_SERDES_FLAG) {
  1255. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  1256. rc = bnx2_init_5706s_phy(bp);
  1257. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  1258. rc = bnx2_init_5708s_phy(bp);
  1259. }
  1260. else {
  1261. rc = bnx2_init_copper_phy(bp);
  1262. }
  1263. bnx2_setup_phy(bp);
  1264. return rc;
  1265. }
  1266. static int
  1267. bnx2_set_mac_loopback(struct bnx2 *bp)
  1268. {
  1269. u32 mac_mode;
  1270. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1271. mac_mode &= ~BNX2_EMAC_MODE_PORT;
  1272. mac_mode |= BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK;
  1273. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1274. bp->link_up = 1;
  1275. return 0;
  1276. }
  1277. static int bnx2_test_link(struct bnx2 *);
  1278. static int
  1279. bnx2_set_phy_loopback(struct bnx2 *bp)
  1280. {
  1281. u32 mac_mode;
  1282. int rc, i;
  1283. spin_lock_bh(&bp->phy_lock);
  1284. rc = bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK | BMCR_FULLDPLX |
  1285. BMCR_SPEED1000);
  1286. spin_unlock_bh(&bp->phy_lock);
  1287. if (rc)
  1288. return rc;
  1289. for (i = 0; i < 10; i++) {
  1290. if (bnx2_test_link(bp) == 0)
  1291. break;
  1292. msleep(100);
  1293. }
  1294. mac_mode = REG_RD(bp, BNX2_EMAC_MODE);
  1295. mac_mode &= ~(BNX2_EMAC_MODE_PORT | BNX2_EMAC_MODE_HALF_DUPLEX |
  1296. BNX2_EMAC_MODE_MAC_LOOP | BNX2_EMAC_MODE_FORCE_LINK |
  1297. BNX2_EMAC_MODE_25G_MODE);
  1298. mac_mode |= BNX2_EMAC_MODE_PORT_GMII;
  1299. REG_WR(bp, BNX2_EMAC_MODE, mac_mode);
  1300. bp->link_up = 1;
  1301. return 0;
  1302. }
  1303. static int
  1304. bnx2_fw_sync(struct bnx2 *bp, u32 msg_data, int silent)
  1305. {
  1306. int i;
  1307. u32 val;
  1308. bp->fw_wr_seq++;
  1309. msg_data |= bp->fw_wr_seq;
  1310. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1311. /* wait for an acknowledgement. */
  1312. for (i = 0; i < (FW_ACK_TIME_OUT_MS / 10); i++) {
  1313. msleep(10);
  1314. val = REG_RD_IND(bp, bp->shmem_base + BNX2_FW_MB);
  1315. if ((val & BNX2_FW_MSG_ACK) == (msg_data & BNX2_DRV_MSG_SEQ))
  1316. break;
  1317. }
  1318. if ((msg_data & BNX2_DRV_MSG_DATA) == BNX2_DRV_MSG_DATA_WAIT0)
  1319. return 0;
  1320. /* If we timed out, inform the firmware that this is the case. */
  1321. if ((val & BNX2_FW_MSG_ACK) != (msg_data & BNX2_DRV_MSG_SEQ)) {
  1322. if (!silent)
  1323. printk(KERN_ERR PFX "fw sync timeout, reset code = "
  1324. "%x\n", msg_data);
  1325. msg_data &= ~BNX2_DRV_MSG_CODE;
  1326. msg_data |= BNX2_DRV_MSG_CODE_FW_TIMEOUT;
  1327. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_MB, msg_data);
  1328. return -EBUSY;
  1329. }
  1330. if ((val & BNX2_FW_MSG_STATUS_MASK) != BNX2_FW_MSG_STATUS_OK)
  1331. return -EIO;
  1332. return 0;
  1333. }
  1334. static int
  1335. bnx2_init_5709_context(struct bnx2 *bp)
  1336. {
  1337. int i, ret = 0;
  1338. u32 val;
  1339. val = BNX2_CTX_COMMAND_ENABLED | BNX2_CTX_COMMAND_MEM_INIT | (1 << 12);
  1340. val |= (BCM_PAGE_BITS - 8) << 16;
  1341. REG_WR(bp, BNX2_CTX_COMMAND, val);
  1342. for (i = 0; i < bp->ctx_pages; i++) {
  1343. int j;
  1344. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA0,
  1345. (bp->ctx_blk_mapping[i] & 0xffffffff) |
  1346. BNX2_CTX_HOST_PAGE_TBL_DATA0_VALID);
  1347. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_DATA1,
  1348. (u64) bp->ctx_blk_mapping[i] >> 32);
  1349. REG_WR(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL, i |
  1350. BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ);
  1351. for (j = 0; j < 10; j++) {
  1352. val = REG_RD(bp, BNX2_CTX_HOST_PAGE_TBL_CTRL);
  1353. if (!(val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ))
  1354. break;
  1355. udelay(5);
  1356. }
  1357. if (val & BNX2_CTX_HOST_PAGE_TBL_CTRL_WRITE_REQ) {
  1358. ret = -EBUSY;
  1359. break;
  1360. }
  1361. }
  1362. return ret;
  1363. }
  1364. static void
  1365. bnx2_init_context(struct bnx2 *bp)
  1366. {
  1367. u32 vcid;
  1368. vcid = 96;
  1369. while (vcid) {
  1370. u32 vcid_addr, pcid_addr, offset;
  1371. vcid--;
  1372. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  1373. u32 new_vcid;
  1374. vcid_addr = GET_PCID_ADDR(vcid);
  1375. if (vcid & 0x8) {
  1376. new_vcid = 0x60 + (vcid & 0xf0) + (vcid & 0x7);
  1377. }
  1378. else {
  1379. new_vcid = vcid;
  1380. }
  1381. pcid_addr = GET_PCID_ADDR(new_vcid);
  1382. }
  1383. else {
  1384. vcid_addr = GET_CID_ADDR(vcid);
  1385. pcid_addr = vcid_addr;
  1386. }
  1387. REG_WR(bp, BNX2_CTX_VIRT_ADDR, 0x00);
  1388. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1389. /* Zero out the context. */
  1390. for (offset = 0; offset < PHY_CTX_SIZE; offset += 4) {
  1391. CTX_WR(bp, 0x00, offset, 0);
  1392. }
  1393. REG_WR(bp, BNX2_CTX_VIRT_ADDR, vcid_addr);
  1394. REG_WR(bp, BNX2_CTX_PAGE_TBL, pcid_addr);
  1395. }
  1396. }
  1397. static int
  1398. bnx2_alloc_bad_rbuf(struct bnx2 *bp)
  1399. {
  1400. u16 *good_mbuf;
  1401. u32 good_mbuf_cnt;
  1402. u32 val;
  1403. good_mbuf = kmalloc(512 * sizeof(u16), GFP_KERNEL);
  1404. if (good_mbuf == NULL) {
  1405. printk(KERN_ERR PFX "Failed to allocate memory in "
  1406. "bnx2_alloc_bad_rbuf\n");
  1407. return -ENOMEM;
  1408. }
  1409. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  1410. BNX2_MISC_ENABLE_SET_BITS_RX_MBUF_ENABLE);
  1411. good_mbuf_cnt = 0;
  1412. /* Allocate a bunch of mbufs and save the good ones in an array. */
  1413. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1414. while (val & BNX2_RBUF_STATUS1_FREE_COUNT) {
  1415. REG_WR_IND(bp, BNX2_RBUF_COMMAND, BNX2_RBUF_COMMAND_ALLOC_REQ);
  1416. val = REG_RD_IND(bp, BNX2_RBUF_FW_BUF_ALLOC);
  1417. val &= BNX2_RBUF_FW_BUF_ALLOC_VALUE;
  1418. /* The addresses with Bit 9 set are bad memory blocks. */
  1419. if (!(val & (1 << 9))) {
  1420. good_mbuf[good_mbuf_cnt] = (u16) val;
  1421. good_mbuf_cnt++;
  1422. }
  1423. val = REG_RD_IND(bp, BNX2_RBUF_STATUS1);
  1424. }
  1425. /* Free the good ones back to the mbuf pool thus discarding
  1426. * all the bad ones. */
  1427. while (good_mbuf_cnt) {
  1428. good_mbuf_cnt--;
  1429. val = good_mbuf[good_mbuf_cnt];
  1430. val = (val << 9) | val | 1;
  1431. REG_WR_IND(bp, BNX2_RBUF_FW_BUF_FREE, val);
  1432. }
  1433. kfree(good_mbuf);
  1434. return 0;
  1435. }
  1436. static void
  1437. bnx2_set_mac_addr(struct bnx2 *bp)
  1438. {
  1439. u32 val;
  1440. u8 *mac_addr = bp->dev->dev_addr;
  1441. val = (mac_addr[0] << 8) | mac_addr[1];
  1442. REG_WR(bp, BNX2_EMAC_MAC_MATCH0, val);
  1443. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  1444. (mac_addr[4] << 8) | mac_addr[5];
  1445. REG_WR(bp, BNX2_EMAC_MAC_MATCH1, val);
  1446. }
  1447. static inline int
  1448. bnx2_alloc_rx_skb(struct bnx2 *bp, u16 index)
  1449. {
  1450. struct sk_buff *skb;
  1451. struct sw_bd *rx_buf = &bp->rx_buf_ring[index];
  1452. dma_addr_t mapping;
  1453. struct rx_bd *rxbd = &bp->rx_desc_ring[RX_RING(index)][RX_IDX(index)];
  1454. unsigned long align;
  1455. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  1456. if (skb == NULL) {
  1457. return -ENOMEM;
  1458. }
  1459. if (unlikely((align = (unsigned long) skb->data & (BNX2_RX_ALIGN - 1))))
  1460. skb_reserve(skb, BNX2_RX_ALIGN - align);
  1461. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_use_size,
  1462. PCI_DMA_FROMDEVICE);
  1463. rx_buf->skb = skb;
  1464. pci_unmap_addr_set(rx_buf, mapping, mapping);
  1465. rxbd->rx_bd_haddr_hi = (u64) mapping >> 32;
  1466. rxbd->rx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  1467. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1468. return 0;
  1469. }
  1470. static void
  1471. bnx2_phy_int(struct bnx2 *bp)
  1472. {
  1473. u32 new_link_state, old_link_state;
  1474. new_link_state = bp->status_blk->status_attn_bits &
  1475. STATUS_ATTN_BITS_LINK_STATE;
  1476. old_link_state = bp->status_blk->status_attn_bits_ack &
  1477. STATUS_ATTN_BITS_LINK_STATE;
  1478. if (new_link_state != old_link_state) {
  1479. if (new_link_state) {
  1480. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_SET_CMD,
  1481. STATUS_ATTN_BITS_LINK_STATE);
  1482. }
  1483. else {
  1484. REG_WR(bp, BNX2_PCICFG_STATUS_BIT_CLEAR_CMD,
  1485. STATUS_ATTN_BITS_LINK_STATE);
  1486. }
  1487. bnx2_set_link(bp);
  1488. }
  1489. }
  1490. static void
  1491. bnx2_tx_int(struct bnx2 *bp)
  1492. {
  1493. struct status_block *sblk = bp->status_blk;
  1494. u16 hw_cons, sw_cons, sw_ring_cons;
  1495. int tx_free_bd = 0;
  1496. hw_cons = bp->hw_tx_cons = sblk->status_tx_quick_consumer_index0;
  1497. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1498. hw_cons++;
  1499. }
  1500. sw_cons = bp->tx_cons;
  1501. while (sw_cons != hw_cons) {
  1502. struct sw_bd *tx_buf;
  1503. struct sk_buff *skb;
  1504. int i, last;
  1505. sw_ring_cons = TX_RING_IDX(sw_cons);
  1506. tx_buf = &bp->tx_buf_ring[sw_ring_cons];
  1507. skb = tx_buf->skb;
  1508. /* partial BD completions possible with TSO packets */
  1509. if (skb_is_gso(skb)) {
  1510. u16 last_idx, last_ring_idx;
  1511. last_idx = sw_cons +
  1512. skb_shinfo(skb)->nr_frags + 1;
  1513. last_ring_idx = sw_ring_cons +
  1514. skb_shinfo(skb)->nr_frags + 1;
  1515. if (unlikely(last_ring_idx >= MAX_TX_DESC_CNT)) {
  1516. last_idx++;
  1517. }
  1518. if (((s16) ((s16) last_idx - (s16) hw_cons)) > 0) {
  1519. break;
  1520. }
  1521. }
  1522. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  1523. skb_headlen(skb), PCI_DMA_TODEVICE);
  1524. tx_buf->skb = NULL;
  1525. last = skb_shinfo(skb)->nr_frags;
  1526. for (i = 0; i < last; i++) {
  1527. sw_cons = NEXT_TX_BD(sw_cons);
  1528. pci_unmap_page(bp->pdev,
  1529. pci_unmap_addr(
  1530. &bp->tx_buf_ring[TX_RING_IDX(sw_cons)],
  1531. mapping),
  1532. skb_shinfo(skb)->frags[i].size,
  1533. PCI_DMA_TODEVICE);
  1534. }
  1535. sw_cons = NEXT_TX_BD(sw_cons);
  1536. tx_free_bd += last + 1;
  1537. dev_kfree_skb(skb);
  1538. hw_cons = bp->hw_tx_cons =
  1539. sblk->status_tx_quick_consumer_index0;
  1540. if ((hw_cons & MAX_TX_DESC_CNT) == MAX_TX_DESC_CNT) {
  1541. hw_cons++;
  1542. }
  1543. }
  1544. bp->tx_cons = sw_cons;
  1545. /* Need to make the tx_cons update visible to bnx2_start_xmit()
  1546. * before checking for netif_queue_stopped(). Without the
  1547. * memory barrier, there is a small possibility that bnx2_start_xmit()
  1548. * will miss it and cause the queue to be stopped forever.
  1549. */
  1550. smp_mb();
  1551. if (unlikely(netif_queue_stopped(bp->dev)) &&
  1552. (bnx2_tx_avail(bp) > bp->tx_wake_thresh)) {
  1553. netif_tx_lock(bp->dev);
  1554. if ((netif_queue_stopped(bp->dev)) &&
  1555. (bnx2_tx_avail(bp) > bp->tx_wake_thresh))
  1556. netif_wake_queue(bp->dev);
  1557. netif_tx_unlock(bp->dev);
  1558. }
  1559. }
  1560. static inline void
  1561. bnx2_reuse_rx_skb(struct bnx2 *bp, struct sk_buff *skb,
  1562. u16 cons, u16 prod)
  1563. {
  1564. struct sw_bd *cons_rx_buf, *prod_rx_buf;
  1565. struct rx_bd *cons_bd, *prod_bd;
  1566. cons_rx_buf = &bp->rx_buf_ring[cons];
  1567. prod_rx_buf = &bp->rx_buf_ring[prod];
  1568. pci_dma_sync_single_for_device(bp->pdev,
  1569. pci_unmap_addr(cons_rx_buf, mapping),
  1570. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1571. bp->rx_prod_bseq += bp->rx_buf_use_size;
  1572. prod_rx_buf->skb = skb;
  1573. if (cons == prod)
  1574. return;
  1575. pci_unmap_addr_set(prod_rx_buf, mapping,
  1576. pci_unmap_addr(cons_rx_buf, mapping));
  1577. cons_bd = &bp->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)];
  1578. prod_bd = &bp->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)];
  1579. prod_bd->rx_bd_haddr_hi = cons_bd->rx_bd_haddr_hi;
  1580. prod_bd->rx_bd_haddr_lo = cons_bd->rx_bd_haddr_lo;
  1581. }
  1582. static int
  1583. bnx2_rx_int(struct bnx2 *bp, int budget)
  1584. {
  1585. struct status_block *sblk = bp->status_blk;
  1586. u16 hw_cons, sw_cons, sw_ring_cons, sw_prod, sw_ring_prod;
  1587. struct l2_fhdr *rx_hdr;
  1588. int rx_pkt = 0;
  1589. hw_cons = bp->hw_rx_cons = sblk->status_rx_quick_consumer_index0;
  1590. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT) {
  1591. hw_cons++;
  1592. }
  1593. sw_cons = bp->rx_cons;
  1594. sw_prod = bp->rx_prod;
  1595. /* Memory barrier necessary as speculative reads of the rx
  1596. * buffer can be ahead of the index in the status block
  1597. */
  1598. rmb();
  1599. while (sw_cons != hw_cons) {
  1600. unsigned int len;
  1601. u32 status;
  1602. struct sw_bd *rx_buf;
  1603. struct sk_buff *skb;
  1604. dma_addr_t dma_addr;
  1605. sw_ring_cons = RX_RING_IDX(sw_cons);
  1606. sw_ring_prod = RX_RING_IDX(sw_prod);
  1607. rx_buf = &bp->rx_buf_ring[sw_ring_cons];
  1608. skb = rx_buf->skb;
  1609. rx_buf->skb = NULL;
  1610. dma_addr = pci_unmap_addr(rx_buf, mapping);
  1611. pci_dma_sync_single_for_cpu(bp->pdev, dma_addr,
  1612. bp->rx_offset + RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  1613. rx_hdr = (struct l2_fhdr *) skb->data;
  1614. len = rx_hdr->l2_fhdr_pkt_len - 4;
  1615. if ((status = rx_hdr->l2_fhdr_status) &
  1616. (L2_FHDR_ERRORS_BAD_CRC |
  1617. L2_FHDR_ERRORS_PHY_DECODE |
  1618. L2_FHDR_ERRORS_ALIGNMENT |
  1619. L2_FHDR_ERRORS_TOO_SHORT |
  1620. L2_FHDR_ERRORS_GIANT_FRAME)) {
  1621. goto reuse_rx;
  1622. }
  1623. /* Since we don't have a jumbo ring, copy small packets
  1624. * if mtu > 1500
  1625. */
  1626. if ((bp->dev->mtu > 1500) && (len <= RX_COPY_THRESH)) {
  1627. struct sk_buff *new_skb;
  1628. new_skb = netdev_alloc_skb(bp->dev, len + 2);
  1629. if (new_skb == NULL)
  1630. goto reuse_rx;
  1631. /* aligned copy */
  1632. skb_copy_from_linear_data_offset(skb, bp->rx_offset - 2,
  1633. new_skb->data, len + 2);
  1634. skb_reserve(new_skb, 2);
  1635. skb_put(new_skb, len);
  1636. bnx2_reuse_rx_skb(bp, skb,
  1637. sw_ring_cons, sw_ring_prod);
  1638. skb = new_skb;
  1639. }
  1640. else if (bnx2_alloc_rx_skb(bp, sw_ring_prod) == 0) {
  1641. pci_unmap_single(bp->pdev, dma_addr,
  1642. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  1643. skb_reserve(skb, bp->rx_offset);
  1644. skb_put(skb, len);
  1645. }
  1646. else {
  1647. reuse_rx:
  1648. bnx2_reuse_rx_skb(bp, skb,
  1649. sw_ring_cons, sw_ring_prod);
  1650. goto next_rx;
  1651. }
  1652. skb->protocol = eth_type_trans(skb, bp->dev);
  1653. if ((len > (bp->dev->mtu + ETH_HLEN)) &&
  1654. (ntohs(skb->protocol) != 0x8100)) {
  1655. dev_kfree_skb(skb);
  1656. goto next_rx;
  1657. }
  1658. skb->ip_summed = CHECKSUM_NONE;
  1659. if (bp->rx_csum &&
  1660. (status & (L2_FHDR_STATUS_TCP_SEGMENT |
  1661. L2_FHDR_STATUS_UDP_DATAGRAM))) {
  1662. if (likely((status & (L2_FHDR_ERRORS_TCP_XSUM |
  1663. L2_FHDR_ERRORS_UDP_XSUM)) == 0))
  1664. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1665. }
  1666. #ifdef BCM_VLAN
  1667. if ((status & L2_FHDR_STATUS_L2_VLAN_TAG) && (bp->vlgrp != 0)) {
  1668. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1669. rx_hdr->l2_fhdr_vlan_tag);
  1670. }
  1671. else
  1672. #endif
  1673. netif_receive_skb(skb);
  1674. bp->dev->last_rx = jiffies;
  1675. rx_pkt++;
  1676. next_rx:
  1677. sw_cons = NEXT_RX_BD(sw_cons);
  1678. sw_prod = NEXT_RX_BD(sw_prod);
  1679. if ((rx_pkt == budget))
  1680. break;
  1681. /* Refresh hw_cons to see if there is new work */
  1682. if (sw_cons == hw_cons) {
  1683. hw_cons = bp->hw_rx_cons =
  1684. sblk->status_rx_quick_consumer_index0;
  1685. if ((hw_cons & MAX_RX_DESC_CNT) == MAX_RX_DESC_CNT)
  1686. hw_cons++;
  1687. rmb();
  1688. }
  1689. }
  1690. bp->rx_cons = sw_cons;
  1691. bp->rx_prod = sw_prod;
  1692. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, sw_prod);
  1693. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  1694. mmiowb();
  1695. return rx_pkt;
  1696. }
  1697. /* MSI ISR - The only difference between this and the INTx ISR
  1698. * is that the MSI interrupt is always serviced.
  1699. */
  1700. static irqreturn_t
  1701. bnx2_msi(int irq, void *dev_instance)
  1702. {
  1703. struct net_device *dev = dev_instance;
  1704. struct bnx2 *bp = netdev_priv(dev);
  1705. prefetch(bp->status_blk);
  1706. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1707. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1708. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1709. /* Return here if interrupt is disabled. */
  1710. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1711. return IRQ_HANDLED;
  1712. netif_rx_schedule(dev);
  1713. return IRQ_HANDLED;
  1714. }
  1715. static irqreturn_t
  1716. bnx2_interrupt(int irq, void *dev_instance)
  1717. {
  1718. struct net_device *dev = dev_instance;
  1719. struct bnx2 *bp = netdev_priv(dev);
  1720. /* When using INTx, it is possible for the interrupt to arrive
  1721. * at the CPU before the status block posted prior to the
  1722. * interrupt. Reading a register will flush the status block.
  1723. * When using MSI, the MSI message will always complete after
  1724. * the status block write.
  1725. */
  1726. if ((bp->status_blk->status_idx == bp->last_status_idx) &&
  1727. (REG_RD(bp, BNX2_PCICFG_MISC_STATUS) &
  1728. BNX2_PCICFG_MISC_STATUS_INTA_VALUE))
  1729. return IRQ_NONE;
  1730. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1731. BNX2_PCICFG_INT_ACK_CMD_USE_INT_HC_PARAM |
  1732. BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  1733. /* Return here if interrupt is shared and is disabled. */
  1734. if (unlikely(atomic_read(&bp->intr_sem) != 0))
  1735. return IRQ_HANDLED;
  1736. netif_rx_schedule(dev);
  1737. return IRQ_HANDLED;
  1738. }
  1739. static inline int
  1740. bnx2_has_work(struct bnx2 *bp)
  1741. {
  1742. struct status_block *sblk = bp->status_blk;
  1743. if ((sblk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) ||
  1744. (sblk->status_tx_quick_consumer_index0 != bp->hw_tx_cons))
  1745. return 1;
  1746. if ((sblk->status_attn_bits & STATUS_ATTN_BITS_LINK_STATE) !=
  1747. (sblk->status_attn_bits_ack & STATUS_ATTN_BITS_LINK_STATE))
  1748. return 1;
  1749. return 0;
  1750. }
  1751. static int
  1752. bnx2_poll(struct net_device *dev, int *budget)
  1753. {
  1754. struct bnx2 *bp = netdev_priv(dev);
  1755. if ((bp->status_blk->status_attn_bits &
  1756. STATUS_ATTN_BITS_LINK_STATE) !=
  1757. (bp->status_blk->status_attn_bits_ack &
  1758. STATUS_ATTN_BITS_LINK_STATE)) {
  1759. spin_lock(&bp->phy_lock);
  1760. bnx2_phy_int(bp);
  1761. spin_unlock(&bp->phy_lock);
  1762. /* This is needed to take care of transient status
  1763. * during link changes.
  1764. */
  1765. REG_WR(bp, BNX2_HC_COMMAND,
  1766. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  1767. REG_RD(bp, BNX2_HC_COMMAND);
  1768. }
  1769. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->hw_tx_cons)
  1770. bnx2_tx_int(bp);
  1771. if (bp->status_blk->status_rx_quick_consumer_index0 != bp->hw_rx_cons) {
  1772. int orig_budget = *budget;
  1773. int work_done;
  1774. if (orig_budget > dev->quota)
  1775. orig_budget = dev->quota;
  1776. work_done = bnx2_rx_int(bp, orig_budget);
  1777. *budget -= work_done;
  1778. dev->quota -= work_done;
  1779. }
  1780. bp->last_status_idx = bp->status_blk->status_idx;
  1781. rmb();
  1782. if (!bnx2_has_work(bp)) {
  1783. netif_rx_complete(dev);
  1784. if (likely(bp->flags & USING_MSI_FLAG)) {
  1785. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1786. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1787. bp->last_status_idx);
  1788. return 0;
  1789. }
  1790. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1791. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1792. BNX2_PCICFG_INT_ACK_CMD_MASK_INT |
  1793. bp->last_status_idx);
  1794. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD,
  1795. BNX2_PCICFG_INT_ACK_CMD_INDEX_VALID |
  1796. bp->last_status_idx);
  1797. return 0;
  1798. }
  1799. return 1;
  1800. }
  1801. /* Called with rtnl_lock from vlan functions and also netif_tx_lock
  1802. * from set_multicast.
  1803. */
  1804. static void
  1805. bnx2_set_rx_mode(struct net_device *dev)
  1806. {
  1807. struct bnx2 *bp = netdev_priv(dev);
  1808. u32 rx_mode, sort_mode;
  1809. int i;
  1810. spin_lock_bh(&bp->phy_lock);
  1811. rx_mode = bp->rx_mode & ~(BNX2_EMAC_RX_MODE_PROMISCUOUS |
  1812. BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG);
  1813. sort_mode = 1 | BNX2_RPM_SORT_USER0_BC_EN;
  1814. #ifdef BCM_VLAN
  1815. if (!bp->vlgrp && !(bp->flags & ASF_ENABLE_FLAG))
  1816. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1817. #else
  1818. if (!(bp->flags & ASF_ENABLE_FLAG))
  1819. rx_mode |= BNX2_EMAC_RX_MODE_KEEP_VLAN_TAG;
  1820. #endif
  1821. if (dev->flags & IFF_PROMISC) {
  1822. /* Promiscuous mode. */
  1823. rx_mode |= BNX2_EMAC_RX_MODE_PROMISCUOUS;
  1824. sort_mode |= BNX2_RPM_SORT_USER0_PROM_EN |
  1825. BNX2_RPM_SORT_USER0_PROM_VLAN;
  1826. }
  1827. else if (dev->flags & IFF_ALLMULTI) {
  1828. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1829. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1830. 0xffffffff);
  1831. }
  1832. sort_mode |= BNX2_RPM_SORT_USER0_MC_EN;
  1833. }
  1834. else {
  1835. /* Accept one or more multicast(s). */
  1836. struct dev_mc_list *mclist;
  1837. u32 mc_filter[NUM_MC_HASH_REGISTERS];
  1838. u32 regidx;
  1839. u32 bit;
  1840. u32 crc;
  1841. memset(mc_filter, 0, 4 * NUM_MC_HASH_REGISTERS);
  1842. for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
  1843. i++, mclist = mclist->next) {
  1844. crc = ether_crc_le(ETH_ALEN, mclist->dmi_addr);
  1845. bit = crc & 0xff;
  1846. regidx = (bit & 0xe0) >> 5;
  1847. bit &= 0x1f;
  1848. mc_filter[regidx] |= (1 << bit);
  1849. }
  1850. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  1851. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  1852. mc_filter[i]);
  1853. }
  1854. sort_mode |= BNX2_RPM_SORT_USER0_MC_HSH_EN;
  1855. }
  1856. if (rx_mode != bp->rx_mode) {
  1857. bp->rx_mode = rx_mode;
  1858. REG_WR(bp, BNX2_EMAC_RX_MODE, rx_mode);
  1859. }
  1860. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  1861. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode);
  1862. REG_WR(bp, BNX2_RPM_SORT_USER0, sort_mode | BNX2_RPM_SORT_USER0_ENA);
  1863. spin_unlock_bh(&bp->phy_lock);
  1864. }
  1865. #define FW_BUF_SIZE 0x8000
  1866. static int
  1867. bnx2_gunzip_init(struct bnx2 *bp)
  1868. {
  1869. if ((bp->gunzip_buf = vmalloc(FW_BUF_SIZE)) == NULL)
  1870. goto gunzip_nomem1;
  1871. if ((bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL)) == NULL)
  1872. goto gunzip_nomem2;
  1873. bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(), GFP_KERNEL);
  1874. if (bp->strm->workspace == NULL)
  1875. goto gunzip_nomem3;
  1876. return 0;
  1877. gunzip_nomem3:
  1878. kfree(bp->strm);
  1879. bp->strm = NULL;
  1880. gunzip_nomem2:
  1881. vfree(bp->gunzip_buf);
  1882. bp->gunzip_buf = NULL;
  1883. gunzip_nomem1:
  1884. printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for "
  1885. "uncompression.\n", bp->dev->name);
  1886. return -ENOMEM;
  1887. }
  1888. static void
  1889. bnx2_gunzip_end(struct bnx2 *bp)
  1890. {
  1891. kfree(bp->strm->workspace);
  1892. kfree(bp->strm);
  1893. bp->strm = NULL;
  1894. if (bp->gunzip_buf) {
  1895. vfree(bp->gunzip_buf);
  1896. bp->gunzip_buf = NULL;
  1897. }
  1898. }
  1899. static int
  1900. bnx2_gunzip(struct bnx2 *bp, u8 *zbuf, int len, void **outbuf, int *outlen)
  1901. {
  1902. int n, rc;
  1903. /* check gzip header */
  1904. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
  1905. return -EINVAL;
  1906. n = 10;
  1907. #define FNAME 0x8
  1908. if (zbuf[3] & FNAME)
  1909. while ((zbuf[n++] != 0) && (n < len));
  1910. bp->strm->next_in = zbuf + n;
  1911. bp->strm->avail_in = len - n;
  1912. bp->strm->next_out = bp->gunzip_buf;
  1913. bp->strm->avail_out = FW_BUF_SIZE;
  1914. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  1915. if (rc != Z_OK)
  1916. return rc;
  1917. rc = zlib_inflate(bp->strm, Z_FINISH);
  1918. *outlen = FW_BUF_SIZE - bp->strm->avail_out;
  1919. *outbuf = bp->gunzip_buf;
  1920. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  1921. printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
  1922. bp->dev->name, bp->strm->msg);
  1923. zlib_inflateEnd(bp->strm);
  1924. if (rc == Z_STREAM_END)
  1925. return 0;
  1926. return rc;
  1927. }
  1928. static void
  1929. load_rv2p_fw(struct bnx2 *bp, u32 *rv2p_code, u32 rv2p_code_len,
  1930. u32 rv2p_proc)
  1931. {
  1932. int i;
  1933. u32 val;
  1934. for (i = 0; i < rv2p_code_len; i += 8) {
  1935. REG_WR(bp, BNX2_RV2P_INSTR_HIGH, cpu_to_le32(*rv2p_code));
  1936. rv2p_code++;
  1937. REG_WR(bp, BNX2_RV2P_INSTR_LOW, cpu_to_le32(*rv2p_code));
  1938. rv2p_code++;
  1939. if (rv2p_proc == RV2P_PROC1) {
  1940. val = (i / 8) | BNX2_RV2P_PROC1_ADDR_CMD_RDWR;
  1941. REG_WR(bp, BNX2_RV2P_PROC1_ADDR_CMD, val);
  1942. }
  1943. else {
  1944. val = (i / 8) | BNX2_RV2P_PROC2_ADDR_CMD_RDWR;
  1945. REG_WR(bp, BNX2_RV2P_PROC2_ADDR_CMD, val);
  1946. }
  1947. }
  1948. /* Reset the processor, un-stall is done later. */
  1949. if (rv2p_proc == RV2P_PROC1) {
  1950. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC1_RESET);
  1951. }
  1952. else {
  1953. REG_WR(bp, BNX2_RV2P_COMMAND, BNX2_RV2P_COMMAND_PROC2_RESET);
  1954. }
  1955. }
  1956. static int
  1957. load_cpu_fw(struct bnx2 *bp, struct cpu_reg *cpu_reg, struct fw_info *fw)
  1958. {
  1959. u32 offset;
  1960. u32 val;
  1961. int rc;
  1962. /* Halt the CPU. */
  1963. val = REG_RD_IND(bp, cpu_reg->mode);
  1964. val |= cpu_reg->mode_value_halt;
  1965. REG_WR_IND(bp, cpu_reg->mode, val);
  1966. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  1967. /* Load the Text area. */
  1968. offset = cpu_reg->spad_base + (fw->text_addr - cpu_reg->mips_view_base);
  1969. if (fw->gz_text) {
  1970. u32 text_len;
  1971. void *text;
  1972. rc = bnx2_gunzip(bp, fw->gz_text, fw->gz_text_len, &text,
  1973. &text_len);
  1974. if (rc)
  1975. return rc;
  1976. fw->text = text;
  1977. }
  1978. if (fw->gz_text) {
  1979. int j;
  1980. for (j = 0; j < (fw->text_len / 4); j++, offset += 4) {
  1981. REG_WR_IND(bp, offset, cpu_to_le32(fw->text[j]));
  1982. }
  1983. }
  1984. /* Load the Data area. */
  1985. offset = cpu_reg->spad_base + (fw->data_addr - cpu_reg->mips_view_base);
  1986. if (fw->data) {
  1987. int j;
  1988. for (j = 0; j < (fw->data_len / 4); j++, offset += 4) {
  1989. REG_WR_IND(bp, offset, fw->data[j]);
  1990. }
  1991. }
  1992. /* Load the SBSS area. */
  1993. offset = cpu_reg->spad_base + (fw->sbss_addr - cpu_reg->mips_view_base);
  1994. if (fw->sbss) {
  1995. int j;
  1996. for (j = 0; j < (fw->sbss_len / 4); j++, offset += 4) {
  1997. REG_WR_IND(bp, offset, fw->sbss[j]);
  1998. }
  1999. }
  2000. /* Load the BSS area. */
  2001. offset = cpu_reg->spad_base + (fw->bss_addr - cpu_reg->mips_view_base);
  2002. if (fw->bss) {
  2003. int j;
  2004. for (j = 0; j < (fw->bss_len/4); j++, offset += 4) {
  2005. REG_WR_IND(bp, offset, fw->bss[j]);
  2006. }
  2007. }
  2008. /* Load the Read-Only area. */
  2009. offset = cpu_reg->spad_base +
  2010. (fw->rodata_addr - cpu_reg->mips_view_base);
  2011. if (fw->rodata) {
  2012. int j;
  2013. for (j = 0; j < (fw->rodata_len / 4); j++, offset += 4) {
  2014. REG_WR_IND(bp, offset, fw->rodata[j]);
  2015. }
  2016. }
  2017. /* Clear the pre-fetch instruction. */
  2018. REG_WR_IND(bp, cpu_reg->inst, 0);
  2019. REG_WR_IND(bp, cpu_reg->pc, fw->start_addr);
  2020. /* Start the CPU. */
  2021. val = REG_RD_IND(bp, cpu_reg->mode);
  2022. val &= ~cpu_reg->mode_value_halt;
  2023. REG_WR_IND(bp, cpu_reg->state, cpu_reg->state_value_clear);
  2024. REG_WR_IND(bp, cpu_reg->mode, val);
  2025. return 0;
  2026. }
  2027. static int
  2028. bnx2_init_cpus(struct bnx2 *bp)
  2029. {
  2030. struct cpu_reg cpu_reg;
  2031. struct fw_info *fw;
  2032. int rc = 0;
  2033. void *text;
  2034. u32 text_len;
  2035. if ((rc = bnx2_gunzip_init(bp)) != 0)
  2036. return rc;
  2037. /* Initialize the RV2P processor. */
  2038. rc = bnx2_gunzip(bp, bnx2_rv2p_proc1, sizeof(bnx2_rv2p_proc1), &text,
  2039. &text_len);
  2040. if (rc)
  2041. goto init_cpu_err;
  2042. load_rv2p_fw(bp, text, text_len, RV2P_PROC1);
  2043. rc = bnx2_gunzip(bp, bnx2_rv2p_proc2, sizeof(bnx2_rv2p_proc2), &text,
  2044. &text_len);
  2045. if (rc)
  2046. goto init_cpu_err;
  2047. load_rv2p_fw(bp, text, text_len, RV2P_PROC2);
  2048. /* Initialize the RX Processor. */
  2049. cpu_reg.mode = BNX2_RXP_CPU_MODE;
  2050. cpu_reg.mode_value_halt = BNX2_RXP_CPU_MODE_SOFT_HALT;
  2051. cpu_reg.mode_value_sstep = BNX2_RXP_CPU_MODE_STEP_ENA;
  2052. cpu_reg.state = BNX2_RXP_CPU_STATE;
  2053. cpu_reg.state_value_clear = 0xffffff;
  2054. cpu_reg.gpr0 = BNX2_RXP_CPU_REG_FILE;
  2055. cpu_reg.evmask = BNX2_RXP_CPU_EVENT_MASK;
  2056. cpu_reg.pc = BNX2_RXP_CPU_PROGRAM_COUNTER;
  2057. cpu_reg.inst = BNX2_RXP_CPU_INSTRUCTION;
  2058. cpu_reg.bp = BNX2_RXP_CPU_HW_BREAKPOINT;
  2059. cpu_reg.spad_base = BNX2_RXP_SCRATCH;
  2060. cpu_reg.mips_view_base = 0x8000000;
  2061. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2062. fw = &bnx2_rxp_fw_09;
  2063. else
  2064. fw = &bnx2_rxp_fw_06;
  2065. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2066. if (rc)
  2067. goto init_cpu_err;
  2068. /* Initialize the TX Processor. */
  2069. cpu_reg.mode = BNX2_TXP_CPU_MODE;
  2070. cpu_reg.mode_value_halt = BNX2_TXP_CPU_MODE_SOFT_HALT;
  2071. cpu_reg.mode_value_sstep = BNX2_TXP_CPU_MODE_STEP_ENA;
  2072. cpu_reg.state = BNX2_TXP_CPU_STATE;
  2073. cpu_reg.state_value_clear = 0xffffff;
  2074. cpu_reg.gpr0 = BNX2_TXP_CPU_REG_FILE;
  2075. cpu_reg.evmask = BNX2_TXP_CPU_EVENT_MASK;
  2076. cpu_reg.pc = BNX2_TXP_CPU_PROGRAM_COUNTER;
  2077. cpu_reg.inst = BNX2_TXP_CPU_INSTRUCTION;
  2078. cpu_reg.bp = BNX2_TXP_CPU_HW_BREAKPOINT;
  2079. cpu_reg.spad_base = BNX2_TXP_SCRATCH;
  2080. cpu_reg.mips_view_base = 0x8000000;
  2081. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2082. fw = &bnx2_txp_fw_09;
  2083. else
  2084. fw = &bnx2_txp_fw_06;
  2085. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2086. if (rc)
  2087. goto init_cpu_err;
  2088. /* Initialize the TX Patch-up Processor. */
  2089. cpu_reg.mode = BNX2_TPAT_CPU_MODE;
  2090. cpu_reg.mode_value_halt = BNX2_TPAT_CPU_MODE_SOFT_HALT;
  2091. cpu_reg.mode_value_sstep = BNX2_TPAT_CPU_MODE_STEP_ENA;
  2092. cpu_reg.state = BNX2_TPAT_CPU_STATE;
  2093. cpu_reg.state_value_clear = 0xffffff;
  2094. cpu_reg.gpr0 = BNX2_TPAT_CPU_REG_FILE;
  2095. cpu_reg.evmask = BNX2_TPAT_CPU_EVENT_MASK;
  2096. cpu_reg.pc = BNX2_TPAT_CPU_PROGRAM_COUNTER;
  2097. cpu_reg.inst = BNX2_TPAT_CPU_INSTRUCTION;
  2098. cpu_reg.bp = BNX2_TPAT_CPU_HW_BREAKPOINT;
  2099. cpu_reg.spad_base = BNX2_TPAT_SCRATCH;
  2100. cpu_reg.mips_view_base = 0x8000000;
  2101. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2102. fw = &bnx2_tpat_fw_09;
  2103. else
  2104. fw = &bnx2_tpat_fw_06;
  2105. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2106. if (rc)
  2107. goto init_cpu_err;
  2108. /* Initialize the Completion Processor. */
  2109. cpu_reg.mode = BNX2_COM_CPU_MODE;
  2110. cpu_reg.mode_value_halt = BNX2_COM_CPU_MODE_SOFT_HALT;
  2111. cpu_reg.mode_value_sstep = BNX2_COM_CPU_MODE_STEP_ENA;
  2112. cpu_reg.state = BNX2_COM_CPU_STATE;
  2113. cpu_reg.state_value_clear = 0xffffff;
  2114. cpu_reg.gpr0 = BNX2_COM_CPU_REG_FILE;
  2115. cpu_reg.evmask = BNX2_COM_CPU_EVENT_MASK;
  2116. cpu_reg.pc = BNX2_COM_CPU_PROGRAM_COUNTER;
  2117. cpu_reg.inst = BNX2_COM_CPU_INSTRUCTION;
  2118. cpu_reg.bp = BNX2_COM_CPU_HW_BREAKPOINT;
  2119. cpu_reg.spad_base = BNX2_COM_SCRATCH;
  2120. cpu_reg.mips_view_base = 0x8000000;
  2121. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2122. fw = &bnx2_com_fw_09;
  2123. else
  2124. fw = &bnx2_com_fw_06;
  2125. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2126. if (rc)
  2127. goto init_cpu_err;
  2128. /* Initialize the Command Processor. */
  2129. cpu_reg.mode = BNX2_CP_CPU_MODE;
  2130. cpu_reg.mode_value_halt = BNX2_CP_CPU_MODE_SOFT_HALT;
  2131. cpu_reg.mode_value_sstep = BNX2_CP_CPU_MODE_STEP_ENA;
  2132. cpu_reg.state = BNX2_CP_CPU_STATE;
  2133. cpu_reg.state_value_clear = 0xffffff;
  2134. cpu_reg.gpr0 = BNX2_CP_CPU_REG_FILE;
  2135. cpu_reg.evmask = BNX2_CP_CPU_EVENT_MASK;
  2136. cpu_reg.pc = BNX2_CP_CPU_PROGRAM_COUNTER;
  2137. cpu_reg.inst = BNX2_CP_CPU_INSTRUCTION;
  2138. cpu_reg.bp = BNX2_CP_CPU_HW_BREAKPOINT;
  2139. cpu_reg.spad_base = BNX2_CP_SCRATCH;
  2140. cpu_reg.mips_view_base = 0x8000000;
  2141. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2142. fw = &bnx2_cp_fw_09;
  2143. rc = load_cpu_fw(bp, &cpu_reg, fw);
  2144. if (rc)
  2145. goto init_cpu_err;
  2146. }
  2147. init_cpu_err:
  2148. bnx2_gunzip_end(bp);
  2149. return rc;
  2150. }
  2151. static int
  2152. bnx2_set_power_state(struct bnx2 *bp, pci_power_t state)
  2153. {
  2154. u16 pmcsr;
  2155. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  2156. switch (state) {
  2157. case PCI_D0: {
  2158. u32 val;
  2159. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2160. (pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  2161. PCI_PM_CTRL_PME_STATUS);
  2162. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  2163. /* delay required during transition out of D3hot */
  2164. msleep(20);
  2165. val = REG_RD(bp, BNX2_EMAC_MODE);
  2166. val |= BNX2_EMAC_MODE_MPKT_RCVD | BNX2_EMAC_MODE_ACPI_RCVD;
  2167. val &= ~BNX2_EMAC_MODE_MPKT;
  2168. REG_WR(bp, BNX2_EMAC_MODE, val);
  2169. val = REG_RD(bp, BNX2_RPM_CONFIG);
  2170. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  2171. REG_WR(bp, BNX2_RPM_CONFIG, val);
  2172. break;
  2173. }
  2174. case PCI_D3hot: {
  2175. int i;
  2176. u32 val, wol_msg;
  2177. if (bp->wol) {
  2178. u32 advertising;
  2179. u8 autoneg;
  2180. autoneg = bp->autoneg;
  2181. advertising = bp->advertising;
  2182. bp->autoneg = AUTONEG_SPEED;
  2183. bp->advertising = ADVERTISED_10baseT_Half |
  2184. ADVERTISED_10baseT_Full |
  2185. ADVERTISED_100baseT_Half |
  2186. ADVERTISED_100baseT_Full |
  2187. ADVERTISED_Autoneg;
  2188. bnx2_setup_copper_phy(bp);
  2189. bp->autoneg = autoneg;
  2190. bp->advertising = advertising;
  2191. bnx2_set_mac_addr(bp);
  2192. val = REG_RD(bp, BNX2_EMAC_MODE);
  2193. /* Enable port mode. */
  2194. val &= ~BNX2_EMAC_MODE_PORT;
  2195. val |= BNX2_EMAC_MODE_PORT_MII |
  2196. BNX2_EMAC_MODE_MPKT_RCVD |
  2197. BNX2_EMAC_MODE_ACPI_RCVD |
  2198. BNX2_EMAC_MODE_MPKT;
  2199. REG_WR(bp, BNX2_EMAC_MODE, val);
  2200. /* receive all multicast */
  2201. for (i = 0; i < NUM_MC_HASH_REGISTERS; i++) {
  2202. REG_WR(bp, BNX2_EMAC_MULTICAST_HASH0 + (i * 4),
  2203. 0xffffffff);
  2204. }
  2205. REG_WR(bp, BNX2_EMAC_RX_MODE,
  2206. BNX2_EMAC_RX_MODE_SORT_MODE);
  2207. val = 1 | BNX2_RPM_SORT_USER0_BC_EN |
  2208. BNX2_RPM_SORT_USER0_MC_EN;
  2209. REG_WR(bp, BNX2_RPM_SORT_USER0, 0x0);
  2210. REG_WR(bp, BNX2_RPM_SORT_USER0, val);
  2211. REG_WR(bp, BNX2_RPM_SORT_USER0, val |
  2212. BNX2_RPM_SORT_USER0_ENA);
  2213. /* Need to enable EMAC and RPM for WOL. */
  2214. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2215. BNX2_MISC_ENABLE_SET_BITS_RX_PARSER_MAC_ENABLE |
  2216. BNX2_MISC_ENABLE_SET_BITS_TX_HEADER_Q_ENABLE |
  2217. BNX2_MISC_ENABLE_SET_BITS_EMAC_ENABLE);
  2218. val = REG_RD(bp, BNX2_RPM_CONFIG);
  2219. val &= ~BNX2_RPM_CONFIG_ACPI_ENA;
  2220. REG_WR(bp, BNX2_RPM_CONFIG, val);
  2221. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  2222. }
  2223. else {
  2224. wol_msg = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  2225. }
  2226. if (!(bp->flags & NO_WOL_FLAG))
  2227. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT3 | wol_msg, 0);
  2228. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  2229. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2230. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  2231. if (bp->wol)
  2232. pmcsr |= 3;
  2233. }
  2234. else {
  2235. pmcsr |= 3;
  2236. }
  2237. if (bp->wol) {
  2238. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  2239. }
  2240. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  2241. pmcsr);
  2242. /* No more memory access after this point until
  2243. * device is brought back to D0.
  2244. */
  2245. udelay(50);
  2246. break;
  2247. }
  2248. default:
  2249. return -EINVAL;
  2250. }
  2251. return 0;
  2252. }
  2253. static int
  2254. bnx2_acquire_nvram_lock(struct bnx2 *bp)
  2255. {
  2256. u32 val;
  2257. int j;
  2258. /* Request access to the flash interface. */
  2259. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_SET2);
  2260. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2261. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2262. if (val & BNX2_NVM_SW_ARB_ARB_ARB2)
  2263. break;
  2264. udelay(5);
  2265. }
  2266. if (j >= NVRAM_TIMEOUT_COUNT)
  2267. return -EBUSY;
  2268. return 0;
  2269. }
  2270. static int
  2271. bnx2_release_nvram_lock(struct bnx2 *bp)
  2272. {
  2273. int j;
  2274. u32 val;
  2275. /* Relinquish nvram interface. */
  2276. REG_WR(bp, BNX2_NVM_SW_ARB, BNX2_NVM_SW_ARB_ARB_REQ_CLR2);
  2277. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2278. val = REG_RD(bp, BNX2_NVM_SW_ARB);
  2279. if (!(val & BNX2_NVM_SW_ARB_ARB_ARB2))
  2280. break;
  2281. udelay(5);
  2282. }
  2283. if (j >= NVRAM_TIMEOUT_COUNT)
  2284. return -EBUSY;
  2285. return 0;
  2286. }
  2287. static int
  2288. bnx2_enable_nvram_write(struct bnx2 *bp)
  2289. {
  2290. u32 val;
  2291. val = REG_RD(bp, BNX2_MISC_CFG);
  2292. REG_WR(bp, BNX2_MISC_CFG, val | BNX2_MISC_CFG_NVM_WR_EN_PCI);
  2293. if (!bp->flash_info->buffered) {
  2294. int j;
  2295. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2296. REG_WR(bp, BNX2_NVM_COMMAND,
  2297. BNX2_NVM_COMMAND_WREN | BNX2_NVM_COMMAND_DOIT);
  2298. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2299. udelay(5);
  2300. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2301. if (val & BNX2_NVM_COMMAND_DONE)
  2302. break;
  2303. }
  2304. if (j >= NVRAM_TIMEOUT_COUNT)
  2305. return -EBUSY;
  2306. }
  2307. return 0;
  2308. }
  2309. static void
  2310. bnx2_disable_nvram_write(struct bnx2 *bp)
  2311. {
  2312. u32 val;
  2313. val = REG_RD(bp, BNX2_MISC_CFG);
  2314. REG_WR(bp, BNX2_MISC_CFG, val & ~BNX2_MISC_CFG_NVM_WR_EN);
  2315. }
  2316. static void
  2317. bnx2_enable_nvram_access(struct bnx2 *bp)
  2318. {
  2319. u32 val;
  2320. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2321. /* Enable both bits, even on read. */
  2322. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2323. val | BNX2_NVM_ACCESS_ENABLE_EN | BNX2_NVM_ACCESS_ENABLE_WR_EN);
  2324. }
  2325. static void
  2326. bnx2_disable_nvram_access(struct bnx2 *bp)
  2327. {
  2328. u32 val;
  2329. val = REG_RD(bp, BNX2_NVM_ACCESS_ENABLE);
  2330. /* Disable both bits, even after read. */
  2331. REG_WR(bp, BNX2_NVM_ACCESS_ENABLE,
  2332. val & ~(BNX2_NVM_ACCESS_ENABLE_EN |
  2333. BNX2_NVM_ACCESS_ENABLE_WR_EN));
  2334. }
  2335. static int
  2336. bnx2_nvram_erase_page(struct bnx2 *bp, u32 offset)
  2337. {
  2338. u32 cmd;
  2339. int j;
  2340. if (bp->flash_info->buffered)
  2341. /* Buffered flash, no erase needed */
  2342. return 0;
  2343. /* Build an erase command */
  2344. cmd = BNX2_NVM_COMMAND_ERASE | BNX2_NVM_COMMAND_WR |
  2345. BNX2_NVM_COMMAND_DOIT;
  2346. /* Need to clear DONE bit separately. */
  2347. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2348. /* Address of the NVRAM to read from. */
  2349. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2350. /* Issue an erase command. */
  2351. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2352. /* Wait for completion. */
  2353. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2354. u32 val;
  2355. udelay(5);
  2356. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2357. if (val & BNX2_NVM_COMMAND_DONE)
  2358. break;
  2359. }
  2360. if (j >= NVRAM_TIMEOUT_COUNT)
  2361. return -EBUSY;
  2362. return 0;
  2363. }
  2364. static int
  2365. bnx2_nvram_read_dword(struct bnx2 *bp, u32 offset, u8 *ret_val, u32 cmd_flags)
  2366. {
  2367. u32 cmd;
  2368. int j;
  2369. /* Build the command word. */
  2370. cmd = BNX2_NVM_COMMAND_DOIT | cmd_flags;
  2371. /* Calculate an offset of a buffered flash. */
  2372. if (bp->flash_info->buffered) {
  2373. offset = ((offset / bp->flash_info->page_size) <<
  2374. bp->flash_info->page_bits) +
  2375. (offset % bp->flash_info->page_size);
  2376. }
  2377. /* Need to clear DONE bit separately. */
  2378. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2379. /* Address of the NVRAM to read from. */
  2380. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2381. /* Issue a read command. */
  2382. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2383. /* Wait for completion. */
  2384. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2385. u32 val;
  2386. udelay(5);
  2387. val = REG_RD(bp, BNX2_NVM_COMMAND);
  2388. if (val & BNX2_NVM_COMMAND_DONE) {
  2389. val = REG_RD(bp, BNX2_NVM_READ);
  2390. val = be32_to_cpu(val);
  2391. memcpy(ret_val, &val, 4);
  2392. break;
  2393. }
  2394. }
  2395. if (j >= NVRAM_TIMEOUT_COUNT)
  2396. return -EBUSY;
  2397. return 0;
  2398. }
  2399. static int
  2400. bnx2_nvram_write_dword(struct bnx2 *bp, u32 offset, u8 *val, u32 cmd_flags)
  2401. {
  2402. u32 cmd, val32;
  2403. int j;
  2404. /* Build the command word. */
  2405. cmd = BNX2_NVM_COMMAND_DOIT | BNX2_NVM_COMMAND_WR | cmd_flags;
  2406. /* Calculate an offset of a buffered flash. */
  2407. if (bp->flash_info->buffered) {
  2408. offset = ((offset / bp->flash_info->page_size) <<
  2409. bp->flash_info->page_bits) +
  2410. (offset % bp->flash_info->page_size);
  2411. }
  2412. /* Need to clear DONE bit separately. */
  2413. REG_WR(bp, BNX2_NVM_COMMAND, BNX2_NVM_COMMAND_DONE);
  2414. memcpy(&val32, val, 4);
  2415. val32 = cpu_to_be32(val32);
  2416. /* Write the data. */
  2417. REG_WR(bp, BNX2_NVM_WRITE, val32);
  2418. /* Address of the NVRAM to write to. */
  2419. REG_WR(bp, BNX2_NVM_ADDR, offset & BNX2_NVM_ADDR_NVM_ADDR_VALUE);
  2420. /* Issue the write command. */
  2421. REG_WR(bp, BNX2_NVM_COMMAND, cmd);
  2422. /* Wait for completion. */
  2423. for (j = 0; j < NVRAM_TIMEOUT_COUNT; j++) {
  2424. udelay(5);
  2425. if (REG_RD(bp, BNX2_NVM_COMMAND) & BNX2_NVM_COMMAND_DONE)
  2426. break;
  2427. }
  2428. if (j >= NVRAM_TIMEOUT_COUNT)
  2429. return -EBUSY;
  2430. return 0;
  2431. }
  2432. static int
  2433. bnx2_init_nvram(struct bnx2 *bp)
  2434. {
  2435. u32 val;
  2436. int j, entry_count, rc;
  2437. struct flash_spec *flash;
  2438. /* Determine the selected interface. */
  2439. val = REG_RD(bp, BNX2_NVM_CFG1);
  2440. entry_count = sizeof(flash_table) / sizeof(struct flash_spec);
  2441. rc = 0;
  2442. if (val & 0x40000000) {
  2443. /* Flash interface has been reconfigured */
  2444. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2445. j++, flash++) {
  2446. if ((val & FLASH_BACKUP_STRAP_MASK) ==
  2447. (flash->config1 & FLASH_BACKUP_STRAP_MASK)) {
  2448. bp->flash_info = flash;
  2449. break;
  2450. }
  2451. }
  2452. }
  2453. else {
  2454. u32 mask;
  2455. /* Not yet been reconfigured */
  2456. if (val & (1 << 23))
  2457. mask = FLASH_BACKUP_STRAP_MASK;
  2458. else
  2459. mask = FLASH_STRAP_MASK;
  2460. for (j = 0, flash = &flash_table[0]; j < entry_count;
  2461. j++, flash++) {
  2462. if ((val & mask) == (flash->strapping & mask)) {
  2463. bp->flash_info = flash;
  2464. /* Request access to the flash interface. */
  2465. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2466. return rc;
  2467. /* Enable access to flash interface */
  2468. bnx2_enable_nvram_access(bp);
  2469. /* Reconfigure the flash interface */
  2470. REG_WR(bp, BNX2_NVM_CFG1, flash->config1);
  2471. REG_WR(bp, BNX2_NVM_CFG2, flash->config2);
  2472. REG_WR(bp, BNX2_NVM_CFG3, flash->config3);
  2473. REG_WR(bp, BNX2_NVM_WRITE1, flash->write1);
  2474. /* Disable access to flash interface */
  2475. bnx2_disable_nvram_access(bp);
  2476. bnx2_release_nvram_lock(bp);
  2477. break;
  2478. }
  2479. }
  2480. } /* if (val & 0x40000000) */
  2481. if (j == entry_count) {
  2482. bp->flash_info = NULL;
  2483. printk(KERN_ALERT PFX "Unknown flash/EEPROM type.\n");
  2484. return -ENODEV;
  2485. }
  2486. val = REG_RD_IND(bp, bp->shmem_base + BNX2_SHARED_HW_CFG_CONFIG2);
  2487. val &= BNX2_SHARED_HW_CFG2_NVM_SIZE_MASK;
  2488. if (val)
  2489. bp->flash_size = val;
  2490. else
  2491. bp->flash_size = bp->flash_info->total_size;
  2492. return rc;
  2493. }
  2494. static int
  2495. bnx2_nvram_read(struct bnx2 *bp, u32 offset, u8 *ret_buf,
  2496. int buf_size)
  2497. {
  2498. int rc = 0;
  2499. u32 cmd_flags, offset32, len32, extra;
  2500. if (buf_size == 0)
  2501. return 0;
  2502. /* Request access to the flash interface. */
  2503. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2504. return rc;
  2505. /* Enable access to flash interface */
  2506. bnx2_enable_nvram_access(bp);
  2507. len32 = buf_size;
  2508. offset32 = offset;
  2509. extra = 0;
  2510. cmd_flags = 0;
  2511. if (offset32 & 3) {
  2512. u8 buf[4];
  2513. u32 pre_len;
  2514. offset32 &= ~3;
  2515. pre_len = 4 - (offset & 3);
  2516. if (pre_len >= len32) {
  2517. pre_len = len32;
  2518. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2519. BNX2_NVM_COMMAND_LAST;
  2520. }
  2521. else {
  2522. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2523. }
  2524. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2525. if (rc)
  2526. return rc;
  2527. memcpy(ret_buf, buf + (offset & 3), pre_len);
  2528. offset32 += 4;
  2529. ret_buf += pre_len;
  2530. len32 -= pre_len;
  2531. }
  2532. if (len32 & 3) {
  2533. extra = 4 - (len32 & 3);
  2534. len32 = (len32 + 4) & ~3;
  2535. }
  2536. if (len32 == 4) {
  2537. u8 buf[4];
  2538. if (cmd_flags)
  2539. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2540. else
  2541. cmd_flags = BNX2_NVM_COMMAND_FIRST |
  2542. BNX2_NVM_COMMAND_LAST;
  2543. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2544. memcpy(ret_buf, buf, 4 - extra);
  2545. }
  2546. else if (len32 > 0) {
  2547. u8 buf[4];
  2548. /* Read the first word. */
  2549. if (cmd_flags)
  2550. cmd_flags = 0;
  2551. else
  2552. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2553. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, cmd_flags);
  2554. /* Advance to the next dword. */
  2555. offset32 += 4;
  2556. ret_buf += 4;
  2557. len32 -= 4;
  2558. while (len32 > 4 && rc == 0) {
  2559. rc = bnx2_nvram_read_dword(bp, offset32, ret_buf, 0);
  2560. /* Advance to the next dword. */
  2561. offset32 += 4;
  2562. ret_buf += 4;
  2563. len32 -= 4;
  2564. }
  2565. if (rc)
  2566. return rc;
  2567. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2568. rc = bnx2_nvram_read_dword(bp, offset32, buf, cmd_flags);
  2569. memcpy(ret_buf, buf, 4 - extra);
  2570. }
  2571. /* Disable access to flash interface */
  2572. bnx2_disable_nvram_access(bp);
  2573. bnx2_release_nvram_lock(bp);
  2574. return rc;
  2575. }
  2576. static int
  2577. bnx2_nvram_write(struct bnx2 *bp, u32 offset, u8 *data_buf,
  2578. int buf_size)
  2579. {
  2580. u32 written, offset32, len32;
  2581. u8 *buf, start[4], end[4], *align_buf = NULL, *flash_buffer = NULL;
  2582. int rc = 0;
  2583. int align_start, align_end;
  2584. buf = data_buf;
  2585. offset32 = offset;
  2586. len32 = buf_size;
  2587. align_start = align_end = 0;
  2588. if ((align_start = (offset32 & 3))) {
  2589. offset32 &= ~3;
  2590. len32 += align_start;
  2591. if (len32 < 4)
  2592. len32 = 4;
  2593. if ((rc = bnx2_nvram_read(bp, offset32, start, 4)))
  2594. return rc;
  2595. }
  2596. if (len32 & 3) {
  2597. align_end = 4 - (len32 & 3);
  2598. len32 += align_end;
  2599. if ((rc = bnx2_nvram_read(bp, offset32 + len32 - 4, end, 4)))
  2600. return rc;
  2601. }
  2602. if (align_start || align_end) {
  2603. align_buf = kmalloc(len32, GFP_KERNEL);
  2604. if (align_buf == NULL)
  2605. return -ENOMEM;
  2606. if (align_start) {
  2607. memcpy(align_buf, start, 4);
  2608. }
  2609. if (align_end) {
  2610. memcpy(align_buf + len32 - 4, end, 4);
  2611. }
  2612. memcpy(align_buf + align_start, data_buf, buf_size);
  2613. buf = align_buf;
  2614. }
  2615. if (bp->flash_info->buffered == 0) {
  2616. flash_buffer = kmalloc(264, GFP_KERNEL);
  2617. if (flash_buffer == NULL) {
  2618. rc = -ENOMEM;
  2619. goto nvram_write_end;
  2620. }
  2621. }
  2622. written = 0;
  2623. while ((written < len32) && (rc == 0)) {
  2624. u32 page_start, page_end, data_start, data_end;
  2625. u32 addr, cmd_flags;
  2626. int i;
  2627. /* Find the page_start addr */
  2628. page_start = offset32 + written;
  2629. page_start -= (page_start % bp->flash_info->page_size);
  2630. /* Find the page_end addr */
  2631. page_end = page_start + bp->flash_info->page_size;
  2632. /* Find the data_start addr */
  2633. data_start = (written == 0) ? offset32 : page_start;
  2634. /* Find the data_end addr */
  2635. data_end = (page_end > offset32 + len32) ?
  2636. (offset32 + len32) : page_end;
  2637. /* Request access to the flash interface. */
  2638. if ((rc = bnx2_acquire_nvram_lock(bp)) != 0)
  2639. goto nvram_write_end;
  2640. /* Enable access to flash interface */
  2641. bnx2_enable_nvram_access(bp);
  2642. cmd_flags = BNX2_NVM_COMMAND_FIRST;
  2643. if (bp->flash_info->buffered == 0) {
  2644. int j;
  2645. /* Read the whole page into the buffer
  2646. * (non-buffer flash only) */
  2647. for (j = 0; j < bp->flash_info->page_size; j += 4) {
  2648. if (j == (bp->flash_info->page_size - 4)) {
  2649. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2650. }
  2651. rc = bnx2_nvram_read_dword(bp,
  2652. page_start + j,
  2653. &flash_buffer[j],
  2654. cmd_flags);
  2655. if (rc)
  2656. goto nvram_write_end;
  2657. cmd_flags = 0;
  2658. }
  2659. }
  2660. /* Enable writes to flash interface (unlock write-protect) */
  2661. if ((rc = bnx2_enable_nvram_write(bp)) != 0)
  2662. goto nvram_write_end;
  2663. /* Loop to write back the buffer data from page_start to
  2664. * data_start */
  2665. i = 0;
  2666. if (bp->flash_info->buffered == 0) {
  2667. /* Erase the page */
  2668. if ((rc = bnx2_nvram_erase_page(bp, page_start)) != 0)
  2669. goto nvram_write_end;
  2670. /* Re-enable the write again for the actual write */
  2671. bnx2_enable_nvram_write(bp);
  2672. for (addr = page_start; addr < data_start;
  2673. addr += 4, i += 4) {
  2674. rc = bnx2_nvram_write_dword(bp, addr,
  2675. &flash_buffer[i], cmd_flags);
  2676. if (rc != 0)
  2677. goto nvram_write_end;
  2678. cmd_flags = 0;
  2679. }
  2680. }
  2681. /* Loop to write the new data from data_start to data_end */
  2682. for (addr = data_start; addr < data_end; addr += 4, i += 4) {
  2683. if ((addr == page_end - 4) ||
  2684. ((bp->flash_info->buffered) &&
  2685. (addr == data_end - 4))) {
  2686. cmd_flags |= BNX2_NVM_COMMAND_LAST;
  2687. }
  2688. rc = bnx2_nvram_write_dword(bp, addr, buf,
  2689. cmd_flags);
  2690. if (rc != 0)
  2691. goto nvram_write_end;
  2692. cmd_flags = 0;
  2693. buf += 4;
  2694. }
  2695. /* Loop to write back the buffer data from data_end
  2696. * to page_end */
  2697. if (bp->flash_info->buffered == 0) {
  2698. for (addr = data_end; addr < page_end;
  2699. addr += 4, i += 4) {
  2700. if (addr == page_end-4) {
  2701. cmd_flags = BNX2_NVM_COMMAND_LAST;
  2702. }
  2703. rc = bnx2_nvram_write_dword(bp, addr,
  2704. &flash_buffer[i], cmd_flags);
  2705. if (rc != 0)
  2706. goto nvram_write_end;
  2707. cmd_flags = 0;
  2708. }
  2709. }
  2710. /* Disable writes to flash interface (lock write-protect) */
  2711. bnx2_disable_nvram_write(bp);
  2712. /* Disable access to flash interface */
  2713. bnx2_disable_nvram_access(bp);
  2714. bnx2_release_nvram_lock(bp);
  2715. /* Increment written */
  2716. written += data_end - data_start;
  2717. }
  2718. nvram_write_end:
  2719. kfree(flash_buffer);
  2720. kfree(align_buf);
  2721. return rc;
  2722. }
  2723. static int
  2724. bnx2_reset_chip(struct bnx2 *bp, u32 reset_code)
  2725. {
  2726. u32 val;
  2727. int i, rc = 0;
  2728. /* Wait for the current PCI transaction to complete before
  2729. * issuing a reset. */
  2730. REG_WR(bp, BNX2_MISC_ENABLE_CLR_BITS,
  2731. BNX2_MISC_ENABLE_CLR_BITS_TX_DMA_ENABLE |
  2732. BNX2_MISC_ENABLE_CLR_BITS_DMA_ENGINE_ENABLE |
  2733. BNX2_MISC_ENABLE_CLR_BITS_RX_DMA_ENABLE |
  2734. BNX2_MISC_ENABLE_CLR_BITS_HOST_COALESCE_ENABLE);
  2735. val = REG_RD(bp, BNX2_MISC_ENABLE_CLR_BITS);
  2736. udelay(5);
  2737. /* Wait for the firmware to tell us it is ok to issue a reset. */
  2738. bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT0 | reset_code, 1);
  2739. /* Deposit a driver reset signature so the firmware knows that
  2740. * this is a soft reset. */
  2741. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_RESET_SIGNATURE,
  2742. BNX2_DRV_RESET_SIGNATURE_MAGIC);
  2743. /* Do a dummy read to force the chip to complete all current transaction
  2744. * before we issue a reset. */
  2745. val = REG_RD(bp, BNX2_MISC_ID);
  2746. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2747. REG_WR(bp, BNX2_MISC_COMMAND, BNX2_MISC_COMMAND_SW_RESET);
  2748. REG_RD(bp, BNX2_MISC_COMMAND);
  2749. udelay(5);
  2750. val = BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2751. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2752. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG, val);
  2753. } else {
  2754. val = BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2755. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  2756. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP;
  2757. /* Chip reset. */
  2758. REG_WR(bp, BNX2_PCICFG_MISC_CONFIG, val);
  2759. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  2760. (CHIP_ID(bp) == CHIP_ID_5706_A1)) {
  2761. current->state = TASK_UNINTERRUPTIBLE;
  2762. schedule_timeout(HZ / 50);
  2763. }
  2764. /* Reset takes approximate 30 usec */
  2765. for (i = 0; i < 10; i++) {
  2766. val = REG_RD(bp, BNX2_PCICFG_MISC_CONFIG);
  2767. if ((val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2768. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) == 0)
  2769. break;
  2770. udelay(10);
  2771. }
  2772. if (val & (BNX2_PCICFG_MISC_CONFIG_CORE_RST_REQ |
  2773. BNX2_PCICFG_MISC_CONFIG_CORE_RST_BSY)) {
  2774. printk(KERN_ERR PFX "Chip reset did not complete\n");
  2775. return -EBUSY;
  2776. }
  2777. }
  2778. /* Make sure byte swapping is properly configured. */
  2779. val = REG_RD(bp, BNX2_PCI_SWAP_DIAG0);
  2780. if (val != 0x01020304) {
  2781. printk(KERN_ERR PFX "Chip not in correct endian mode\n");
  2782. return -ENODEV;
  2783. }
  2784. /* Wait for the firmware to finish its initialization. */
  2785. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT1 | reset_code, 0);
  2786. if (rc)
  2787. return rc;
  2788. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2789. /* Adjust the voltage regular to two steps lower. The default
  2790. * of this register is 0x0000000e. */
  2791. REG_WR(bp, BNX2_MISC_VREG_CONTROL, 0x000000fa);
  2792. /* Remove bad rbuf memory from the free pool. */
  2793. rc = bnx2_alloc_bad_rbuf(bp);
  2794. }
  2795. return rc;
  2796. }
  2797. static int
  2798. bnx2_init_chip(struct bnx2 *bp)
  2799. {
  2800. u32 val;
  2801. int rc;
  2802. /* Make sure the interrupt is not active. */
  2803. REG_WR(bp, BNX2_PCICFG_INT_ACK_CMD, BNX2_PCICFG_INT_ACK_CMD_MASK_INT);
  2804. val = BNX2_DMA_CONFIG_DATA_BYTE_SWAP |
  2805. BNX2_DMA_CONFIG_DATA_WORD_SWAP |
  2806. #ifdef __BIG_ENDIAN
  2807. BNX2_DMA_CONFIG_CNTL_BYTE_SWAP |
  2808. #endif
  2809. BNX2_DMA_CONFIG_CNTL_WORD_SWAP |
  2810. DMA_READ_CHANS << 12 |
  2811. DMA_WRITE_CHANS << 16;
  2812. val |= (0x2 << 20) | (1 << 11);
  2813. if ((bp->flags & PCIX_FLAG) && (bp->bus_speed_mhz == 133))
  2814. val |= (1 << 23);
  2815. if ((CHIP_NUM(bp) == CHIP_NUM_5706) &&
  2816. (CHIP_ID(bp) != CHIP_ID_5706_A0) && !(bp->flags & PCIX_FLAG))
  2817. val |= BNX2_DMA_CONFIG_CNTL_PING_PONG_DMA;
  2818. REG_WR(bp, BNX2_DMA_CONFIG, val);
  2819. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  2820. val = REG_RD(bp, BNX2_TDMA_CONFIG);
  2821. val |= BNX2_TDMA_CONFIG_ONE_DMA;
  2822. REG_WR(bp, BNX2_TDMA_CONFIG, val);
  2823. }
  2824. if (bp->flags & PCIX_FLAG) {
  2825. u16 val16;
  2826. pci_read_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2827. &val16);
  2828. pci_write_config_word(bp->pdev, bp->pcix_cap + PCI_X_CMD,
  2829. val16 & ~PCI_X_CMD_ERO);
  2830. }
  2831. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS,
  2832. BNX2_MISC_ENABLE_SET_BITS_HOST_COALESCE_ENABLE |
  2833. BNX2_MISC_ENABLE_STATUS_BITS_RX_V2P_ENABLE |
  2834. BNX2_MISC_ENABLE_STATUS_BITS_CONTEXT_ENABLE);
  2835. /* Initialize context mapping and zero out the quick contexts. The
  2836. * context block must have already been enabled. */
  2837. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  2838. bnx2_init_5709_context(bp);
  2839. else
  2840. bnx2_init_context(bp);
  2841. if ((rc = bnx2_init_cpus(bp)) != 0)
  2842. return rc;
  2843. bnx2_init_nvram(bp);
  2844. bnx2_set_mac_addr(bp);
  2845. val = REG_RD(bp, BNX2_MQ_CONFIG);
  2846. val &= ~BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE;
  2847. val |= BNX2_MQ_CONFIG_KNL_BYP_BLK_SIZE_256;
  2848. if (CHIP_ID(bp) == CHIP_ID_5709_A0 || CHIP_ID(bp) == CHIP_ID_5709_A1)
  2849. val |= BNX2_MQ_CONFIG_HALT_DIS;
  2850. REG_WR(bp, BNX2_MQ_CONFIG, val);
  2851. val = 0x10000 + (MAX_CID_CNT * MB_KERNEL_CTX_SIZE);
  2852. REG_WR(bp, BNX2_MQ_KNL_BYP_WIND_START, val);
  2853. REG_WR(bp, BNX2_MQ_KNL_WIND_END, val);
  2854. val = (BCM_PAGE_BITS - 8) << 24;
  2855. REG_WR(bp, BNX2_RV2P_CONFIG, val);
  2856. /* Configure page size. */
  2857. val = REG_RD(bp, BNX2_TBDR_CONFIG);
  2858. val &= ~BNX2_TBDR_CONFIG_PAGE_SIZE;
  2859. val |= (BCM_PAGE_BITS - 8) << 24 | 0x40;
  2860. REG_WR(bp, BNX2_TBDR_CONFIG, val);
  2861. val = bp->mac_addr[0] +
  2862. (bp->mac_addr[1] << 8) +
  2863. (bp->mac_addr[2] << 16) +
  2864. bp->mac_addr[3] +
  2865. (bp->mac_addr[4] << 8) +
  2866. (bp->mac_addr[5] << 16);
  2867. REG_WR(bp, BNX2_EMAC_BACKOFF_SEED, val);
  2868. /* Program the MTU. Also include 4 bytes for CRC32. */
  2869. val = bp->dev->mtu + ETH_HLEN + 4;
  2870. if (val > (MAX_ETHERNET_PACKET_SIZE + 4))
  2871. val |= BNX2_EMAC_RX_MTU_SIZE_JUMBO_ENA;
  2872. REG_WR(bp, BNX2_EMAC_RX_MTU_SIZE, val);
  2873. bp->last_status_idx = 0;
  2874. bp->rx_mode = BNX2_EMAC_RX_MODE_SORT_MODE;
  2875. /* Set up how to generate a link change interrupt. */
  2876. REG_WR(bp, BNX2_EMAC_ATTENTION_ENA, BNX2_EMAC_ATTENTION_ENA_LINK);
  2877. REG_WR(bp, BNX2_HC_STATUS_ADDR_L,
  2878. (u64) bp->status_blk_mapping & 0xffffffff);
  2879. REG_WR(bp, BNX2_HC_STATUS_ADDR_H, (u64) bp->status_blk_mapping >> 32);
  2880. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_L,
  2881. (u64) bp->stats_blk_mapping & 0xffffffff);
  2882. REG_WR(bp, BNX2_HC_STATISTICS_ADDR_H,
  2883. (u64) bp->stats_blk_mapping >> 32);
  2884. REG_WR(bp, BNX2_HC_TX_QUICK_CONS_TRIP,
  2885. (bp->tx_quick_cons_trip_int << 16) | bp->tx_quick_cons_trip);
  2886. REG_WR(bp, BNX2_HC_RX_QUICK_CONS_TRIP,
  2887. (bp->rx_quick_cons_trip_int << 16) | bp->rx_quick_cons_trip);
  2888. REG_WR(bp, BNX2_HC_COMP_PROD_TRIP,
  2889. (bp->comp_prod_trip_int << 16) | bp->comp_prod_trip);
  2890. REG_WR(bp, BNX2_HC_TX_TICKS, (bp->tx_ticks_int << 16) | bp->tx_ticks);
  2891. REG_WR(bp, BNX2_HC_RX_TICKS, (bp->rx_ticks_int << 16) | bp->rx_ticks);
  2892. REG_WR(bp, BNX2_HC_COM_TICKS,
  2893. (bp->com_ticks_int << 16) | bp->com_ticks);
  2894. REG_WR(bp, BNX2_HC_CMD_TICKS,
  2895. (bp->cmd_ticks_int << 16) | bp->cmd_ticks);
  2896. REG_WR(bp, BNX2_HC_STATS_TICKS, bp->stats_ticks & 0xffff00);
  2897. REG_WR(bp, BNX2_HC_STAT_COLLECT_TICKS, 0xbb8); /* 3ms */
  2898. if (CHIP_ID(bp) == CHIP_ID_5706_A1)
  2899. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_COLLECT_STATS);
  2900. else {
  2901. REG_WR(bp, BNX2_HC_CONFIG, BNX2_HC_CONFIG_RX_TMR_MODE |
  2902. BNX2_HC_CONFIG_TX_TMR_MODE |
  2903. BNX2_HC_CONFIG_COLLECT_STATS);
  2904. }
  2905. /* Clear internal stats counters. */
  2906. REG_WR(bp, BNX2_HC_COMMAND, BNX2_HC_COMMAND_CLR_STAT_NOW);
  2907. REG_WR(bp, BNX2_HC_ATTN_BITS_ENABLE, STATUS_ATTN_BITS_LINK_STATE);
  2908. if (REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_FEATURE) &
  2909. BNX2_PORT_FEATURE_ASF_ENABLED)
  2910. bp->flags |= ASF_ENABLE_FLAG;
  2911. /* Initialize the receive filter. */
  2912. bnx2_set_rx_mode(bp->dev);
  2913. rc = bnx2_fw_sync(bp, BNX2_DRV_MSG_DATA_WAIT2 | BNX2_DRV_MSG_CODE_RESET,
  2914. 0);
  2915. REG_WR(bp, BNX2_MISC_ENABLE_SET_BITS, 0x5ffffff);
  2916. REG_RD(bp, BNX2_MISC_ENABLE_SET_BITS);
  2917. udelay(20);
  2918. bp->hc_cmd = REG_RD(bp, BNX2_HC_COMMAND);
  2919. return rc;
  2920. }
  2921. static void
  2922. bnx2_init_tx_context(struct bnx2 *bp, u32 cid)
  2923. {
  2924. u32 val, offset0, offset1, offset2, offset3;
  2925. if (CHIP_NUM(bp) == CHIP_NUM_5709) {
  2926. offset0 = BNX2_L2CTX_TYPE_XI;
  2927. offset1 = BNX2_L2CTX_CMD_TYPE_XI;
  2928. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI_XI;
  2929. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO_XI;
  2930. } else {
  2931. offset0 = BNX2_L2CTX_TYPE;
  2932. offset1 = BNX2_L2CTX_CMD_TYPE;
  2933. offset2 = BNX2_L2CTX_TBDR_BHADDR_HI;
  2934. offset3 = BNX2_L2CTX_TBDR_BHADDR_LO;
  2935. }
  2936. val = BNX2_L2CTX_TYPE_TYPE_L2 | BNX2_L2CTX_TYPE_SIZE_L2;
  2937. CTX_WR(bp, GET_CID_ADDR(cid), offset0, val);
  2938. val = BNX2_L2CTX_CMD_TYPE_TYPE_L2 | (8 << 16);
  2939. CTX_WR(bp, GET_CID_ADDR(cid), offset1, val);
  2940. val = (u64) bp->tx_desc_mapping >> 32;
  2941. CTX_WR(bp, GET_CID_ADDR(cid), offset2, val);
  2942. val = (u64) bp->tx_desc_mapping & 0xffffffff;
  2943. CTX_WR(bp, GET_CID_ADDR(cid), offset3, val);
  2944. }
  2945. static void
  2946. bnx2_init_tx_ring(struct bnx2 *bp)
  2947. {
  2948. struct tx_bd *txbd;
  2949. u32 cid;
  2950. bp->tx_wake_thresh = bp->tx_ring_size / 2;
  2951. txbd = &bp->tx_desc_ring[MAX_TX_DESC_CNT];
  2952. txbd->tx_bd_haddr_hi = (u64) bp->tx_desc_mapping >> 32;
  2953. txbd->tx_bd_haddr_lo = (u64) bp->tx_desc_mapping & 0xffffffff;
  2954. bp->tx_prod = 0;
  2955. bp->tx_cons = 0;
  2956. bp->hw_tx_cons = 0;
  2957. bp->tx_prod_bseq = 0;
  2958. cid = TX_CID;
  2959. bp->tx_bidx_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BIDX;
  2960. bp->tx_bseq_addr = MB_GET_CID_ADDR(cid) + BNX2_L2CTX_TX_HOST_BSEQ;
  2961. bnx2_init_tx_context(bp, cid);
  2962. }
  2963. static void
  2964. bnx2_init_rx_ring(struct bnx2 *bp)
  2965. {
  2966. struct rx_bd *rxbd;
  2967. int i;
  2968. u16 prod, ring_prod;
  2969. u32 val;
  2970. /* 8 for CRC and VLAN */
  2971. bp->rx_buf_use_size = bp->dev->mtu + ETH_HLEN + bp->rx_offset + 8;
  2972. /* hw alignment */
  2973. bp->rx_buf_size = bp->rx_buf_use_size + BNX2_RX_ALIGN;
  2974. ring_prod = prod = bp->rx_prod = 0;
  2975. bp->rx_cons = 0;
  2976. bp->hw_rx_cons = 0;
  2977. bp->rx_prod_bseq = 0;
  2978. for (i = 0; i < bp->rx_max_ring; i++) {
  2979. int j;
  2980. rxbd = &bp->rx_desc_ring[i][0];
  2981. for (j = 0; j < MAX_RX_DESC_CNT; j++, rxbd++) {
  2982. rxbd->rx_bd_len = bp->rx_buf_use_size;
  2983. rxbd->rx_bd_flags = RX_BD_FLAGS_START | RX_BD_FLAGS_END;
  2984. }
  2985. if (i == (bp->rx_max_ring - 1))
  2986. j = 0;
  2987. else
  2988. j = i + 1;
  2989. rxbd->rx_bd_haddr_hi = (u64) bp->rx_desc_mapping[j] >> 32;
  2990. rxbd->rx_bd_haddr_lo = (u64) bp->rx_desc_mapping[j] &
  2991. 0xffffffff;
  2992. }
  2993. val = BNX2_L2CTX_CTX_TYPE_CTX_BD_CHN_TYPE_VALUE;
  2994. val |= BNX2_L2CTX_CTX_TYPE_SIZE_L2;
  2995. val |= 0x02 << 8;
  2996. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_CTX_TYPE, val);
  2997. val = (u64) bp->rx_desc_mapping[0] >> 32;
  2998. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_HI, val);
  2999. val = (u64) bp->rx_desc_mapping[0] & 0xffffffff;
  3000. CTX_WR(bp, GET_CID_ADDR(RX_CID), BNX2_L2CTX_NX_BDHADDR_LO, val);
  3001. for (i = 0; i < bp->rx_ring_size; i++) {
  3002. if (bnx2_alloc_rx_skb(bp, ring_prod) < 0) {
  3003. break;
  3004. }
  3005. prod = NEXT_RX_BD(prod);
  3006. ring_prod = RX_RING_IDX(prod);
  3007. }
  3008. bp->rx_prod = prod;
  3009. REG_WR16(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BDIDX, prod);
  3010. REG_WR(bp, MB_RX_CID_ADDR + BNX2_L2CTX_HOST_BSEQ, bp->rx_prod_bseq);
  3011. }
  3012. static void
  3013. bnx2_set_rx_ring_size(struct bnx2 *bp, u32 size)
  3014. {
  3015. u32 num_rings, max;
  3016. bp->rx_ring_size = size;
  3017. num_rings = 1;
  3018. while (size > MAX_RX_DESC_CNT) {
  3019. size -= MAX_RX_DESC_CNT;
  3020. num_rings++;
  3021. }
  3022. /* round to next power of 2 */
  3023. max = MAX_RX_RINGS;
  3024. while ((max & num_rings) == 0)
  3025. max >>= 1;
  3026. if (num_rings != max)
  3027. max <<= 1;
  3028. bp->rx_max_ring = max;
  3029. bp->rx_max_ring_idx = (bp->rx_max_ring * RX_DESC_CNT) - 1;
  3030. }
  3031. static void
  3032. bnx2_free_tx_skbs(struct bnx2 *bp)
  3033. {
  3034. int i;
  3035. if (bp->tx_buf_ring == NULL)
  3036. return;
  3037. for (i = 0; i < TX_DESC_CNT; ) {
  3038. struct sw_bd *tx_buf = &bp->tx_buf_ring[i];
  3039. struct sk_buff *skb = tx_buf->skb;
  3040. int j, last;
  3041. if (skb == NULL) {
  3042. i++;
  3043. continue;
  3044. }
  3045. pci_unmap_single(bp->pdev, pci_unmap_addr(tx_buf, mapping),
  3046. skb_headlen(skb), PCI_DMA_TODEVICE);
  3047. tx_buf->skb = NULL;
  3048. last = skb_shinfo(skb)->nr_frags;
  3049. for (j = 0; j < last; j++) {
  3050. tx_buf = &bp->tx_buf_ring[i + j + 1];
  3051. pci_unmap_page(bp->pdev,
  3052. pci_unmap_addr(tx_buf, mapping),
  3053. skb_shinfo(skb)->frags[j].size,
  3054. PCI_DMA_TODEVICE);
  3055. }
  3056. dev_kfree_skb(skb);
  3057. i += j + 1;
  3058. }
  3059. }
  3060. static void
  3061. bnx2_free_rx_skbs(struct bnx2 *bp)
  3062. {
  3063. int i;
  3064. if (bp->rx_buf_ring == NULL)
  3065. return;
  3066. for (i = 0; i < bp->rx_max_ring_idx; i++) {
  3067. struct sw_bd *rx_buf = &bp->rx_buf_ring[i];
  3068. struct sk_buff *skb = rx_buf->skb;
  3069. if (skb == NULL)
  3070. continue;
  3071. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  3072. bp->rx_buf_use_size, PCI_DMA_FROMDEVICE);
  3073. rx_buf->skb = NULL;
  3074. dev_kfree_skb(skb);
  3075. }
  3076. }
  3077. static void
  3078. bnx2_free_skbs(struct bnx2 *bp)
  3079. {
  3080. bnx2_free_tx_skbs(bp);
  3081. bnx2_free_rx_skbs(bp);
  3082. }
  3083. static int
  3084. bnx2_reset_nic(struct bnx2 *bp, u32 reset_code)
  3085. {
  3086. int rc;
  3087. rc = bnx2_reset_chip(bp, reset_code);
  3088. bnx2_free_skbs(bp);
  3089. if (rc)
  3090. return rc;
  3091. if ((rc = bnx2_init_chip(bp)) != 0)
  3092. return rc;
  3093. bnx2_init_tx_ring(bp);
  3094. bnx2_init_rx_ring(bp);
  3095. return 0;
  3096. }
  3097. static int
  3098. bnx2_init_nic(struct bnx2 *bp)
  3099. {
  3100. int rc;
  3101. if ((rc = bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET)) != 0)
  3102. return rc;
  3103. spin_lock_bh(&bp->phy_lock);
  3104. bnx2_init_phy(bp);
  3105. spin_unlock_bh(&bp->phy_lock);
  3106. bnx2_set_link(bp);
  3107. return 0;
  3108. }
  3109. static int
  3110. bnx2_test_registers(struct bnx2 *bp)
  3111. {
  3112. int ret;
  3113. int i, is_5709;
  3114. static const struct {
  3115. u16 offset;
  3116. u16 flags;
  3117. #define BNX2_FL_NOT_5709 1
  3118. u32 rw_mask;
  3119. u32 ro_mask;
  3120. } reg_tbl[] = {
  3121. { 0x006c, 0, 0x00000000, 0x0000003f },
  3122. { 0x0090, 0, 0xffffffff, 0x00000000 },
  3123. { 0x0094, 0, 0x00000000, 0x00000000 },
  3124. { 0x0404, BNX2_FL_NOT_5709, 0x00003f00, 0x00000000 },
  3125. { 0x0418, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3126. { 0x041c, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3127. { 0x0420, BNX2_FL_NOT_5709, 0x00000000, 0x80ffffff },
  3128. { 0x0424, BNX2_FL_NOT_5709, 0x00000000, 0x00000000 },
  3129. { 0x0428, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  3130. { 0x0450, BNX2_FL_NOT_5709, 0x00000000, 0x0000ffff },
  3131. { 0x0454, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3132. { 0x0458, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3133. { 0x0808, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3134. { 0x0854, BNX2_FL_NOT_5709, 0x00000000, 0xffffffff },
  3135. { 0x0868, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3136. { 0x086c, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3137. { 0x0870, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3138. { 0x0874, BNX2_FL_NOT_5709, 0x00000000, 0x77777777 },
  3139. { 0x0c00, BNX2_FL_NOT_5709, 0x00000000, 0x00000001 },
  3140. { 0x0c04, BNX2_FL_NOT_5709, 0x00000000, 0x03ff0001 },
  3141. { 0x0c08, BNX2_FL_NOT_5709, 0x0f0ff073, 0x00000000 },
  3142. { 0x1000, 0, 0x00000000, 0x00000001 },
  3143. { 0x1004, 0, 0x00000000, 0x000f0001 },
  3144. { 0x1408, 0, 0x01c00800, 0x00000000 },
  3145. { 0x149c, 0, 0x8000ffff, 0x00000000 },
  3146. { 0x14a8, 0, 0x00000000, 0x000001ff },
  3147. { 0x14ac, 0, 0x0fffffff, 0x10000000 },
  3148. { 0x14b0, 0, 0x00000002, 0x00000001 },
  3149. { 0x14b8, 0, 0x00000000, 0x00000000 },
  3150. { 0x14c0, 0, 0x00000000, 0x00000009 },
  3151. { 0x14c4, 0, 0x00003fff, 0x00000000 },
  3152. { 0x14cc, 0, 0x00000000, 0x00000001 },
  3153. { 0x14d0, 0, 0xffffffff, 0x00000000 },
  3154. { 0x1800, 0, 0x00000000, 0x00000001 },
  3155. { 0x1804, 0, 0x00000000, 0x00000003 },
  3156. { 0x2800, 0, 0x00000000, 0x00000001 },
  3157. { 0x2804, 0, 0x00000000, 0x00003f01 },
  3158. { 0x2808, 0, 0x0f3f3f03, 0x00000000 },
  3159. { 0x2810, 0, 0xffff0000, 0x00000000 },
  3160. { 0x2814, 0, 0xffff0000, 0x00000000 },
  3161. { 0x2818, 0, 0xffff0000, 0x00000000 },
  3162. { 0x281c, 0, 0xffff0000, 0x00000000 },
  3163. { 0x2834, 0, 0xffffffff, 0x00000000 },
  3164. { 0x2840, 0, 0x00000000, 0xffffffff },
  3165. { 0x2844, 0, 0x00000000, 0xffffffff },
  3166. { 0x2848, 0, 0xffffffff, 0x00000000 },
  3167. { 0x284c, 0, 0xf800f800, 0x07ff07ff },
  3168. { 0x2c00, 0, 0x00000000, 0x00000011 },
  3169. { 0x2c04, 0, 0x00000000, 0x00030007 },
  3170. { 0x3c00, 0, 0x00000000, 0x00000001 },
  3171. { 0x3c04, 0, 0x00000000, 0x00070000 },
  3172. { 0x3c08, 0, 0x00007f71, 0x07f00000 },
  3173. { 0x3c0c, 0, 0x1f3ffffc, 0x00000000 },
  3174. { 0x3c10, 0, 0xffffffff, 0x00000000 },
  3175. { 0x3c14, 0, 0x00000000, 0xffffffff },
  3176. { 0x3c18, 0, 0x00000000, 0xffffffff },
  3177. { 0x3c1c, 0, 0xfffff000, 0x00000000 },
  3178. { 0x3c20, 0, 0xffffff00, 0x00000000 },
  3179. { 0x5004, 0, 0x00000000, 0x0000007f },
  3180. { 0x5008, 0, 0x0f0007ff, 0x00000000 },
  3181. { 0x5c00, 0, 0x00000000, 0x00000001 },
  3182. { 0x5c04, 0, 0x00000000, 0x0003000f },
  3183. { 0x5c08, 0, 0x00000003, 0x00000000 },
  3184. { 0x5c0c, 0, 0x0000fff8, 0x00000000 },
  3185. { 0x5c10, 0, 0x00000000, 0xffffffff },
  3186. { 0x5c80, 0, 0x00000000, 0x0f7113f1 },
  3187. { 0x5c84, 0, 0x00000000, 0x0000f333 },
  3188. { 0x5c88, 0, 0x00000000, 0x00077373 },
  3189. { 0x5c8c, 0, 0x00000000, 0x0007f737 },
  3190. { 0x6808, 0, 0x0000ff7f, 0x00000000 },
  3191. { 0x680c, 0, 0xffffffff, 0x00000000 },
  3192. { 0x6810, 0, 0xffffffff, 0x00000000 },
  3193. { 0x6814, 0, 0xffffffff, 0x00000000 },
  3194. { 0x6818, 0, 0xffffffff, 0x00000000 },
  3195. { 0x681c, 0, 0xffffffff, 0x00000000 },
  3196. { 0x6820, 0, 0x00ff00ff, 0x00000000 },
  3197. { 0x6824, 0, 0x00ff00ff, 0x00000000 },
  3198. { 0x6828, 0, 0x00ff00ff, 0x00000000 },
  3199. { 0x682c, 0, 0x03ff03ff, 0x00000000 },
  3200. { 0x6830, 0, 0x03ff03ff, 0x00000000 },
  3201. { 0x6834, 0, 0x03ff03ff, 0x00000000 },
  3202. { 0x6838, 0, 0x03ff03ff, 0x00000000 },
  3203. { 0x683c, 0, 0x0000ffff, 0x00000000 },
  3204. { 0x6840, 0, 0x00000ff0, 0x00000000 },
  3205. { 0x6844, 0, 0x00ffff00, 0x00000000 },
  3206. { 0x684c, 0, 0xffffffff, 0x00000000 },
  3207. { 0x6850, 0, 0x7f7f7f7f, 0x00000000 },
  3208. { 0x6854, 0, 0x7f7f7f7f, 0x00000000 },
  3209. { 0x6858, 0, 0x7f7f7f7f, 0x00000000 },
  3210. { 0x685c, 0, 0x7f7f7f7f, 0x00000000 },
  3211. { 0x6908, 0, 0x00000000, 0x0001ff0f },
  3212. { 0x690c, 0, 0x00000000, 0x0ffe00f0 },
  3213. { 0xffff, 0, 0x00000000, 0x00000000 },
  3214. };
  3215. ret = 0;
  3216. is_5709 = 0;
  3217. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  3218. is_5709 = 1;
  3219. for (i = 0; reg_tbl[i].offset != 0xffff; i++) {
  3220. u32 offset, rw_mask, ro_mask, save_val, val;
  3221. u16 flags = reg_tbl[i].flags;
  3222. if (is_5709 && (flags & BNX2_FL_NOT_5709))
  3223. continue;
  3224. offset = (u32) reg_tbl[i].offset;
  3225. rw_mask = reg_tbl[i].rw_mask;
  3226. ro_mask = reg_tbl[i].ro_mask;
  3227. save_val = readl(bp->regview + offset);
  3228. writel(0, bp->regview + offset);
  3229. val = readl(bp->regview + offset);
  3230. if ((val & rw_mask) != 0) {
  3231. goto reg_test_err;
  3232. }
  3233. if ((val & ro_mask) != (save_val & ro_mask)) {
  3234. goto reg_test_err;
  3235. }
  3236. writel(0xffffffff, bp->regview + offset);
  3237. val = readl(bp->regview + offset);
  3238. if ((val & rw_mask) != rw_mask) {
  3239. goto reg_test_err;
  3240. }
  3241. if ((val & ro_mask) != (save_val & ro_mask)) {
  3242. goto reg_test_err;
  3243. }
  3244. writel(save_val, bp->regview + offset);
  3245. continue;
  3246. reg_test_err:
  3247. writel(save_val, bp->regview + offset);
  3248. ret = -ENODEV;
  3249. break;
  3250. }
  3251. return ret;
  3252. }
  3253. static int
  3254. bnx2_do_mem_test(struct bnx2 *bp, u32 start, u32 size)
  3255. {
  3256. static const u32 test_pattern[] = { 0x00000000, 0xffffffff, 0x55555555,
  3257. 0xaaaaaaaa , 0xaa55aa55, 0x55aa55aa };
  3258. int i;
  3259. for (i = 0; i < sizeof(test_pattern) / 4; i++) {
  3260. u32 offset;
  3261. for (offset = 0; offset < size; offset += 4) {
  3262. REG_WR_IND(bp, start + offset, test_pattern[i]);
  3263. if (REG_RD_IND(bp, start + offset) !=
  3264. test_pattern[i]) {
  3265. return -ENODEV;
  3266. }
  3267. }
  3268. }
  3269. return 0;
  3270. }
  3271. static int
  3272. bnx2_test_memory(struct bnx2 *bp)
  3273. {
  3274. int ret = 0;
  3275. int i;
  3276. static struct mem_entry {
  3277. u32 offset;
  3278. u32 len;
  3279. } mem_tbl_5706[] = {
  3280. { 0x60000, 0x4000 },
  3281. { 0xa0000, 0x3000 },
  3282. { 0xe0000, 0x4000 },
  3283. { 0x120000, 0x4000 },
  3284. { 0x1a0000, 0x4000 },
  3285. { 0x160000, 0x4000 },
  3286. { 0xffffffff, 0 },
  3287. },
  3288. mem_tbl_5709[] = {
  3289. { 0x60000, 0x4000 },
  3290. { 0xa0000, 0x3000 },
  3291. { 0xe0000, 0x4000 },
  3292. { 0x120000, 0x4000 },
  3293. { 0x1a0000, 0x4000 },
  3294. { 0xffffffff, 0 },
  3295. };
  3296. struct mem_entry *mem_tbl;
  3297. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  3298. mem_tbl = mem_tbl_5709;
  3299. else
  3300. mem_tbl = mem_tbl_5706;
  3301. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++) {
  3302. if ((ret = bnx2_do_mem_test(bp, mem_tbl[i].offset,
  3303. mem_tbl[i].len)) != 0) {
  3304. return ret;
  3305. }
  3306. }
  3307. return ret;
  3308. }
  3309. #define BNX2_MAC_LOOPBACK 0
  3310. #define BNX2_PHY_LOOPBACK 1
  3311. static int
  3312. bnx2_run_loopback(struct bnx2 *bp, int loopback_mode)
  3313. {
  3314. unsigned int pkt_size, num_pkts, i;
  3315. struct sk_buff *skb, *rx_skb;
  3316. unsigned char *packet;
  3317. u16 rx_start_idx, rx_idx;
  3318. dma_addr_t map;
  3319. struct tx_bd *txbd;
  3320. struct sw_bd *rx_buf;
  3321. struct l2_fhdr *rx_hdr;
  3322. int ret = -ENODEV;
  3323. if (loopback_mode == BNX2_MAC_LOOPBACK) {
  3324. bp->loopback = MAC_LOOPBACK;
  3325. bnx2_set_mac_loopback(bp);
  3326. }
  3327. else if (loopback_mode == BNX2_PHY_LOOPBACK) {
  3328. bp->loopback = PHY_LOOPBACK;
  3329. bnx2_set_phy_loopback(bp);
  3330. }
  3331. else
  3332. return -EINVAL;
  3333. pkt_size = 1514;
  3334. skb = netdev_alloc_skb(bp->dev, pkt_size);
  3335. if (!skb)
  3336. return -ENOMEM;
  3337. packet = skb_put(skb, pkt_size);
  3338. memcpy(packet, bp->dev->dev_addr, 6);
  3339. memset(packet + 6, 0x0, 8);
  3340. for (i = 14; i < pkt_size; i++)
  3341. packet[i] = (unsigned char) (i & 0xff);
  3342. map = pci_map_single(bp->pdev, skb->data, pkt_size,
  3343. PCI_DMA_TODEVICE);
  3344. REG_WR(bp, BNX2_HC_COMMAND,
  3345. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3346. REG_RD(bp, BNX2_HC_COMMAND);
  3347. udelay(5);
  3348. rx_start_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3349. num_pkts = 0;
  3350. txbd = &bp->tx_desc_ring[TX_RING_IDX(bp->tx_prod)];
  3351. txbd->tx_bd_haddr_hi = (u64) map >> 32;
  3352. txbd->tx_bd_haddr_lo = (u64) map & 0xffffffff;
  3353. txbd->tx_bd_mss_nbytes = pkt_size;
  3354. txbd->tx_bd_vlan_tag_flags = TX_BD_FLAGS_START | TX_BD_FLAGS_END;
  3355. num_pkts++;
  3356. bp->tx_prod = NEXT_TX_BD(bp->tx_prod);
  3357. bp->tx_prod_bseq += pkt_size;
  3358. REG_WR16(bp, bp->tx_bidx_addr, bp->tx_prod);
  3359. REG_WR(bp, bp->tx_bseq_addr, bp->tx_prod_bseq);
  3360. udelay(100);
  3361. REG_WR(bp, BNX2_HC_COMMAND,
  3362. bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW_WO_INT);
  3363. REG_RD(bp, BNX2_HC_COMMAND);
  3364. udelay(5);
  3365. pci_unmap_single(bp->pdev, map, pkt_size, PCI_DMA_TODEVICE);
  3366. dev_kfree_skb(skb);
  3367. if (bp->status_blk->status_tx_quick_consumer_index0 != bp->tx_prod) {
  3368. goto loopback_test_done;
  3369. }
  3370. rx_idx = bp->status_blk->status_rx_quick_consumer_index0;
  3371. if (rx_idx != rx_start_idx + num_pkts) {
  3372. goto loopback_test_done;
  3373. }
  3374. rx_buf = &bp->rx_buf_ring[rx_start_idx];
  3375. rx_skb = rx_buf->skb;
  3376. rx_hdr = (struct l2_fhdr *) rx_skb->data;
  3377. skb_reserve(rx_skb, bp->rx_offset);
  3378. pci_dma_sync_single_for_cpu(bp->pdev,
  3379. pci_unmap_addr(rx_buf, mapping),
  3380. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  3381. if (rx_hdr->l2_fhdr_status &
  3382. (L2_FHDR_ERRORS_BAD_CRC |
  3383. L2_FHDR_ERRORS_PHY_DECODE |
  3384. L2_FHDR_ERRORS_ALIGNMENT |
  3385. L2_FHDR_ERRORS_TOO_SHORT |
  3386. L2_FHDR_ERRORS_GIANT_FRAME)) {
  3387. goto loopback_test_done;
  3388. }
  3389. if ((rx_hdr->l2_fhdr_pkt_len - 4) != pkt_size) {
  3390. goto loopback_test_done;
  3391. }
  3392. for (i = 14; i < pkt_size; i++) {
  3393. if (*(rx_skb->data + i) != (unsigned char) (i & 0xff)) {
  3394. goto loopback_test_done;
  3395. }
  3396. }
  3397. ret = 0;
  3398. loopback_test_done:
  3399. bp->loopback = 0;
  3400. return ret;
  3401. }
  3402. #define BNX2_MAC_LOOPBACK_FAILED 1
  3403. #define BNX2_PHY_LOOPBACK_FAILED 2
  3404. #define BNX2_LOOPBACK_FAILED (BNX2_MAC_LOOPBACK_FAILED | \
  3405. BNX2_PHY_LOOPBACK_FAILED)
  3406. static int
  3407. bnx2_test_loopback(struct bnx2 *bp)
  3408. {
  3409. int rc = 0;
  3410. if (!netif_running(bp->dev))
  3411. return BNX2_LOOPBACK_FAILED;
  3412. bnx2_reset_nic(bp, BNX2_DRV_MSG_CODE_RESET);
  3413. spin_lock_bh(&bp->phy_lock);
  3414. bnx2_init_phy(bp);
  3415. spin_unlock_bh(&bp->phy_lock);
  3416. if (bnx2_run_loopback(bp, BNX2_MAC_LOOPBACK))
  3417. rc |= BNX2_MAC_LOOPBACK_FAILED;
  3418. if (bnx2_run_loopback(bp, BNX2_PHY_LOOPBACK))
  3419. rc |= BNX2_PHY_LOOPBACK_FAILED;
  3420. return rc;
  3421. }
  3422. #define NVRAM_SIZE 0x200
  3423. #define CRC32_RESIDUAL 0xdebb20e3
  3424. static int
  3425. bnx2_test_nvram(struct bnx2 *bp)
  3426. {
  3427. u32 buf[NVRAM_SIZE / 4];
  3428. u8 *data = (u8 *) buf;
  3429. int rc = 0;
  3430. u32 magic, csum;
  3431. if ((rc = bnx2_nvram_read(bp, 0, data, 4)) != 0)
  3432. goto test_nvram_done;
  3433. magic = be32_to_cpu(buf[0]);
  3434. if (magic != 0x669955aa) {
  3435. rc = -ENODEV;
  3436. goto test_nvram_done;
  3437. }
  3438. if ((rc = bnx2_nvram_read(bp, 0x100, data, NVRAM_SIZE)) != 0)
  3439. goto test_nvram_done;
  3440. csum = ether_crc_le(0x100, data);
  3441. if (csum != CRC32_RESIDUAL) {
  3442. rc = -ENODEV;
  3443. goto test_nvram_done;
  3444. }
  3445. csum = ether_crc_le(0x100, data + 0x100);
  3446. if (csum != CRC32_RESIDUAL) {
  3447. rc = -ENODEV;
  3448. }
  3449. test_nvram_done:
  3450. return rc;
  3451. }
  3452. static int
  3453. bnx2_test_link(struct bnx2 *bp)
  3454. {
  3455. u32 bmsr;
  3456. spin_lock_bh(&bp->phy_lock);
  3457. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  3458. bnx2_read_phy(bp, bp->mii_bmsr, &bmsr);
  3459. spin_unlock_bh(&bp->phy_lock);
  3460. if (bmsr & BMSR_LSTATUS) {
  3461. return 0;
  3462. }
  3463. return -ENODEV;
  3464. }
  3465. static int
  3466. bnx2_test_intr(struct bnx2 *bp)
  3467. {
  3468. int i;
  3469. u16 status_idx;
  3470. if (!netif_running(bp->dev))
  3471. return -ENODEV;
  3472. status_idx = REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff;
  3473. /* This register is not touched during run-time. */
  3474. REG_WR(bp, BNX2_HC_COMMAND, bp->hc_cmd | BNX2_HC_COMMAND_COAL_NOW);
  3475. REG_RD(bp, BNX2_HC_COMMAND);
  3476. for (i = 0; i < 10; i++) {
  3477. if ((REG_RD(bp, BNX2_PCICFG_INT_ACK_CMD) & 0xffff) !=
  3478. status_idx) {
  3479. break;
  3480. }
  3481. msleep_interruptible(10);
  3482. }
  3483. if (i < 10)
  3484. return 0;
  3485. return -ENODEV;
  3486. }
  3487. static void
  3488. bnx2_5706_serdes_timer(struct bnx2 *bp)
  3489. {
  3490. spin_lock(&bp->phy_lock);
  3491. if (bp->serdes_an_pending)
  3492. bp->serdes_an_pending--;
  3493. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3494. u32 bmcr;
  3495. bp->current_interval = bp->timer_interval;
  3496. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  3497. if (bmcr & BMCR_ANENABLE) {
  3498. u32 phy1, phy2;
  3499. bnx2_write_phy(bp, 0x1c, 0x7c00);
  3500. bnx2_read_phy(bp, 0x1c, &phy1);
  3501. bnx2_write_phy(bp, 0x17, 0x0f01);
  3502. bnx2_read_phy(bp, 0x15, &phy2);
  3503. bnx2_write_phy(bp, 0x17, 0x0f01);
  3504. bnx2_read_phy(bp, 0x15, &phy2);
  3505. if ((phy1 & 0x10) && /* SIGNAL DETECT */
  3506. !(phy2 & 0x20)) { /* no CONFIG */
  3507. bmcr &= ~BMCR_ANENABLE;
  3508. bmcr |= BMCR_SPEED1000 | BMCR_FULLDPLX;
  3509. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  3510. bp->phy_flags |= PHY_PARALLEL_DETECT_FLAG;
  3511. }
  3512. }
  3513. }
  3514. else if ((bp->link_up) && (bp->autoneg & AUTONEG_SPEED) &&
  3515. (bp->phy_flags & PHY_PARALLEL_DETECT_FLAG)) {
  3516. u32 phy2;
  3517. bnx2_write_phy(bp, 0x17, 0x0f01);
  3518. bnx2_read_phy(bp, 0x15, &phy2);
  3519. if (phy2 & 0x20) {
  3520. u32 bmcr;
  3521. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  3522. bmcr |= BMCR_ANENABLE;
  3523. bnx2_write_phy(bp, bp->mii_bmcr, bmcr);
  3524. bp->phy_flags &= ~PHY_PARALLEL_DETECT_FLAG;
  3525. }
  3526. } else
  3527. bp->current_interval = bp->timer_interval;
  3528. spin_unlock(&bp->phy_lock);
  3529. }
  3530. static void
  3531. bnx2_5708_serdes_timer(struct bnx2 *bp)
  3532. {
  3533. if ((bp->phy_flags & PHY_2_5G_CAPABLE_FLAG) == 0) {
  3534. bp->serdes_an_pending = 0;
  3535. return;
  3536. }
  3537. spin_lock(&bp->phy_lock);
  3538. if (bp->serdes_an_pending)
  3539. bp->serdes_an_pending--;
  3540. else if ((bp->link_up == 0) && (bp->autoneg & AUTONEG_SPEED)) {
  3541. u32 bmcr;
  3542. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  3543. if (bmcr & BMCR_ANENABLE) {
  3544. bnx2_enable_forced_2g5(bp);
  3545. bp->current_interval = SERDES_FORCED_TIMEOUT;
  3546. } else {
  3547. bnx2_disable_forced_2g5(bp);
  3548. bp->serdes_an_pending = 2;
  3549. bp->current_interval = bp->timer_interval;
  3550. }
  3551. } else
  3552. bp->current_interval = bp->timer_interval;
  3553. spin_unlock(&bp->phy_lock);
  3554. }
  3555. static void
  3556. bnx2_timer(unsigned long data)
  3557. {
  3558. struct bnx2 *bp = (struct bnx2 *) data;
  3559. u32 msg;
  3560. if (!netif_running(bp->dev))
  3561. return;
  3562. if (atomic_read(&bp->intr_sem) != 0)
  3563. goto bnx2_restart_timer;
  3564. msg = (u32) ++bp->fw_drv_pulse_wr_seq;
  3565. REG_WR_IND(bp, bp->shmem_base + BNX2_DRV_PULSE_MB, msg);
  3566. bp->stats_blk->stat_FwRxDrop = REG_RD_IND(bp, BNX2_FW_RX_DROP_COUNT);
  3567. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3568. if (CHIP_NUM(bp) == CHIP_NUM_5706)
  3569. bnx2_5706_serdes_timer(bp);
  3570. else if (CHIP_NUM(bp) == CHIP_NUM_5708)
  3571. bnx2_5708_serdes_timer(bp);
  3572. }
  3573. bnx2_restart_timer:
  3574. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3575. }
  3576. /* Called with rtnl_lock */
  3577. static int
  3578. bnx2_open(struct net_device *dev)
  3579. {
  3580. struct bnx2 *bp = netdev_priv(dev);
  3581. int rc;
  3582. netif_carrier_off(dev);
  3583. bnx2_set_power_state(bp, PCI_D0);
  3584. bnx2_disable_int(bp);
  3585. rc = bnx2_alloc_mem(bp);
  3586. if (rc)
  3587. return rc;
  3588. if ((CHIP_ID(bp) != CHIP_ID_5706_A0) &&
  3589. (CHIP_ID(bp) != CHIP_ID_5706_A1) &&
  3590. !disable_msi) {
  3591. if (pci_enable_msi(bp->pdev) == 0) {
  3592. bp->flags |= USING_MSI_FLAG;
  3593. rc = request_irq(bp->pdev->irq, bnx2_msi, 0, dev->name,
  3594. dev);
  3595. }
  3596. else {
  3597. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3598. IRQF_SHARED, dev->name, dev);
  3599. }
  3600. }
  3601. else {
  3602. rc = request_irq(bp->pdev->irq, bnx2_interrupt, IRQF_SHARED,
  3603. dev->name, dev);
  3604. }
  3605. if (rc) {
  3606. bnx2_free_mem(bp);
  3607. return rc;
  3608. }
  3609. rc = bnx2_init_nic(bp);
  3610. if (rc) {
  3611. free_irq(bp->pdev->irq, dev);
  3612. if (bp->flags & USING_MSI_FLAG) {
  3613. pci_disable_msi(bp->pdev);
  3614. bp->flags &= ~USING_MSI_FLAG;
  3615. }
  3616. bnx2_free_skbs(bp);
  3617. bnx2_free_mem(bp);
  3618. return rc;
  3619. }
  3620. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3621. atomic_set(&bp->intr_sem, 0);
  3622. bnx2_enable_int(bp);
  3623. if (bp->flags & USING_MSI_FLAG) {
  3624. /* Test MSI to make sure it is working
  3625. * If MSI test fails, go back to INTx mode
  3626. */
  3627. if (bnx2_test_intr(bp) != 0) {
  3628. printk(KERN_WARNING PFX "%s: No interrupt was generated"
  3629. " using MSI, switching to INTx mode. Please"
  3630. " report this failure to the PCI maintainer"
  3631. " and include system chipset information.\n",
  3632. bp->dev->name);
  3633. bnx2_disable_int(bp);
  3634. free_irq(bp->pdev->irq, dev);
  3635. pci_disable_msi(bp->pdev);
  3636. bp->flags &= ~USING_MSI_FLAG;
  3637. rc = bnx2_init_nic(bp);
  3638. if (!rc) {
  3639. rc = request_irq(bp->pdev->irq, bnx2_interrupt,
  3640. IRQF_SHARED, dev->name, dev);
  3641. }
  3642. if (rc) {
  3643. bnx2_free_skbs(bp);
  3644. bnx2_free_mem(bp);
  3645. del_timer_sync(&bp->timer);
  3646. return rc;
  3647. }
  3648. bnx2_enable_int(bp);
  3649. }
  3650. }
  3651. if (bp->flags & USING_MSI_FLAG) {
  3652. printk(KERN_INFO PFX "%s: using MSI\n", dev->name);
  3653. }
  3654. netif_start_queue(dev);
  3655. return 0;
  3656. }
  3657. static void
  3658. bnx2_reset_task(struct work_struct *work)
  3659. {
  3660. struct bnx2 *bp = container_of(work, struct bnx2, reset_task);
  3661. if (!netif_running(bp->dev))
  3662. return;
  3663. bp->in_reset_task = 1;
  3664. bnx2_netif_stop(bp);
  3665. bnx2_init_nic(bp);
  3666. atomic_set(&bp->intr_sem, 1);
  3667. bnx2_netif_start(bp);
  3668. bp->in_reset_task = 0;
  3669. }
  3670. static void
  3671. bnx2_tx_timeout(struct net_device *dev)
  3672. {
  3673. struct bnx2 *bp = netdev_priv(dev);
  3674. /* This allows the netif to be shutdown gracefully before resetting */
  3675. schedule_work(&bp->reset_task);
  3676. }
  3677. #ifdef BCM_VLAN
  3678. /* Called with rtnl_lock */
  3679. static void
  3680. bnx2_vlan_rx_register(struct net_device *dev, struct vlan_group *vlgrp)
  3681. {
  3682. struct bnx2 *bp = netdev_priv(dev);
  3683. bnx2_netif_stop(bp);
  3684. bp->vlgrp = vlgrp;
  3685. bnx2_set_rx_mode(dev);
  3686. bnx2_netif_start(bp);
  3687. }
  3688. /* Called with rtnl_lock */
  3689. static void
  3690. bnx2_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)
  3691. {
  3692. struct bnx2 *bp = netdev_priv(dev);
  3693. bnx2_netif_stop(bp);
  3694. vlan_group_set_device(bp->vlgrp, vid, NULL);
  3695. bnx2_set_rx_mode(dev);
  3696. bnx2_netif_start(bp);
  3697. }
  3698. #endif
  3699. /* Called with netif_tx_lock.
  3700. * bnx2_tx_int() runs without netif_tx_lock unless it needs to call
  3701. * netif_wake_queue().
  3702. */
  3703. static int
  3704. bnx2_start_xmit(struct sk_buff *skb, struct net_device *dev)
  3705. {
  3706. struct bnx2 *bp = netdev_priv(dev);
  3707. dma_addr_t mapping;
  3708. struct tx_bd *txbd;
  3709. struct sw_bd *tx_buf;
  3710. u32 len, vlan_tag_flags, last_frag, mss;
  3711. u16 prod, ring_prod;
  3712. int i;
  3713. if (unlikely(bnx2_tx_avail(bp) < (skb_shinfo(skb)->nr_frags + 1))) {
  3714. netif_stop_queue(dev);
  3715. printk(KERN_ERR PFX "%s: BUG! Tx ring full when queue awake!\n",
  3716. dev->name);
  3717. return NETDEV_TX_BUSY;
  3718. }
  3719. len = skb_headlen(skb);
  3720. prod = bp->tx_prod;
  3721. ring_prod = TX_RING_IDX(prod);
  3722. vlan_tag_flags = 0;
  3723. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3724. vlan_tag_flags |= TX_BD_FLAGS_TCP_UDP_CKSUM;
  3725. }
  3726. if (bp->vlgrp != 0 && vlan_tx_tag_present(skb)) {
  3727. vlan_tag_flags |=
  3728. (TX_BD_FLAGS_VLAN_TAG | (vlan_tx_tag_get(skb) << 16));
  3729. }
  3730. if ((mss = skb_shinfo(skb)->gso_size) &&
  3731. (skb->len > (bp->dev->mtu + ETH_HLEN))) {
  3732. u32 tcp_opt_len, ip_tcp_len;
  3733. struct iphdr *iph;
  3734. vlan_tag_flags |= TX_BD_FLAGS_SW_LSO;
  3735. tcp_opt_len = tcp_optlen(skb);
  3736. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6) {
  3737. u32 tcp_off = skb_transport_offset(skb) -
  3738. sizeof(struct ipv6hdr) - ETH_HLEN;
  3739. vlan_tag_flags |= ((tcp_opt_len >> 2) << 8) |
  3740. TX_BD_FLAGS_SW_FLAGS;
  3741. if (likely(tcp_off == 0))
  3742. vlan_tag_flags &= ~TX_BD_FLAGS_TCP6_OFF0_MSK;
  3743. else {
  3744. tcp_off >>= 3;
  3745. vlan_tag_flags |= ((tcp_off & 0x3) <<
  3746. TX_BD_FLAGS_TCP6_OFF0_SHL) |
  3747. ((tcp_off & 0x10) <<
  3748. TX_BD_FLAGS_TCP6_OFF4_SHL);
  3749. mss |= (tcp_off & 0xc) << TX_BD_TCP6_OFF2_SHL;
  3750. }
  3751. } else {
  3752. if (skb_header_cloned(skb) &&
  3753. pskb_expand_head(skb, 0, 0, GFP_ATOMIC)) {
  3754. dev_kfree_skb(skb);
  3755. return NETDEV_TX_OK;
  3756. }
  3757. ip_tcp_len = ip_hdrlen(skb) + sizeof(struct tcphdr);
  3758. iph = ip_hdr(skb);
  3759. iph->check = 0;
  3760. iph->tot_len = htons(mss + ip_tcp_len + tcp_opt_len);
  3761. tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
  3762. iph->daddr, 0,
  3763. IPPROTO_TCP,
  3764. 0);
  3765. if (tcp_opt_len || (iph->ihl > 5)) {
  3766. vlan_tag_flags |= ((iph->ihl - 5) +
  3767. (tcp_opt_len >> 2)) << 8;
  3768. }
  3769. }
  3770. } else
  3771. mss = 0;
  3772. mapping = pci_map_single(bp->pdev, skb->data, len, PCI_DMA_TODEVICE);
  3773. tx_buf = &bp->tx_buf_ring[ring_prod];
  3774. tx_buf->skb = skb;
  3775. pci_unmap_addr_set(tx_buf, mapping, mapping);
  3776. txbd = &bp->tx_desc_ring[ring_prod];
  3777. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3778. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3779. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3780. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags | TX_BD_FLAGS_START;
  3781. last_frag = skb_shinfo(skb)->nr_frags;
  3782. for (i = 0; i < last_frag; i++) {
  3783. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3784. prod = NEXT_TX_BD(prod);
  3785. ring_prod = TX_RING_IDX(prod);
  3786. txbd = &bp->tx_desc_ring[ring_prod];
  3787. len = frag->size;
  3788. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  3789. len, PCI_DMA_TODEVICE);
  3790. pci_unmap_addr_set(&bp->tx_buf_ring[ring_prod],
  3791. mapping, mapping);
  3792. txbd->tx_bd_haddr_hi = (u64) mapping >> 32;
  3793. txbd->tx_bd_haddr_lo = (u64) mapping & 0xffffffff;
  3794. txbd->tx_bd_mss_nbytes = len | (mss << 16);
  3795. txbd->tx_bd_vlan_tag_flags = vlan_tag_flags;
  3796. }
  3797. txbd->tx_bd_vlan_tag_flags |= TX_BD_FLAGS_END;
  3798. prod = NEXT_TX_BD(prod);
  3799. bp->tx_prod_bseq += skb->len;
  3800. REG_WR16(bp, bp->tx_bidx_addr, prod);
  3801. REG_WR(bp, bp->tx_bseq_addr, bp->tx_prod_bseq);
  3802. mmiowb();
  3803. bp->tx_prod = prod;
  3804. dev->trans_start = jiffies;
  3805. if (unlikely(bnx2_tx_avail(bp) <= MAX_SKB_FRAGS)) {
  3806. netif_stop_queue(dev);
  3807. if (bnx2_tx_avail(bp) > bp->tx_wake_thresh)
  3808. netif_wake_queue(dev);
  3809. }
  3810. return NETDEV_TX_OK;
  3811. }
  3812. /* Called with rtnl_lock */
  3813. static int
  3814. bnx2_close(struct net_device *dev)
  3815. {
  3816. struct bnx2 *bp = netdev_priv(dev);
  3817. u32 reset_code;
  3818. /* Calling flush_scheduled_work() may deadlock because
  3819. * linkwatch_event() may be on the workqueue and it will try to get
  3820. * the rtnl_lock which we are holding.
  3821. */
  3822. while (bp->in_reset_task)
  3823. msleep(1);
  3824. bnx2_netif_stop(bp);
  3825. del_timer_sync(&bp->timer);
  3826. if (bp->flags & NO_WOL_FLAG)
  3827. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  3828. else if (bp->wol)
  3829. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  3830. else
  3831. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  3832. bnx2_reset_chip(bp, reset_code);
  3833. free_irq(bp->pdev->irq, dev);
  3834. if (bp->flags & USING_MSI_FLAG) {
  3835. pci_disable_msi(bp->pdev);
  3836. bp->flags &= ~USING_MSI_FLAG;
  3837. }
  3838. bnx2_free_skbs(bp);
  3839. bnx2_free_mem(bp);
  3840. bp->link_up = 0;
  3841. netif_carrier_off(bp->dev);
  3842. bnx2_set_power_state(bp, PCI_D3hot);
  3843. return 0;
  3844. }
  3845. #define GET_NET_STATS64(ctr) \
  3846. (unsigned long) ((unsigned long) (ctr##_hi) << 32) + \
  3847. (unsigned long) (ctr##_lo)
  3848. #define GET_NET_STATS32(ctr) \
  3849. (ctr##_lo)
  3850. #if (BITS_PER_LONG == 64)
  3851. #define GET_NET_STATS GET_NET_STATS64
  3852. #else
  3853. #define GET_NET_STATS GET_NET_STATS32
  3854. #endif
  3855. static struct net_device_stats *
  3856. bnx2_get_stats(struct net_device *dev)
  3857. {
  3858. struct bnx2 *bp = netdev_priv(dev);
  3859. struct statistics_block *stats_blk = bp->stats_blk;
  3860. struct net_device_stats *net_stats = &bp->net_stats;
  3861. if (bp->stats_blk == NULL) {
  3862. return net_stats;
  3863. }
  3864. net_stats->rx_packets =
  3865. GET_NET_STATS(stats_blk->stat_IfHCInUcastPkts) +
  3866. GET_NET_STATS(stats_blk->stat_IfHCInMulticastPkts) +
  3867. GET_NET_STATS(stats_blk->stat_IfHCInBroadcastPkts);
  3868. net_stats->tx_packets =
  3869. GET_NET_STATS(stats_blk->stat_IfHCOutUcastPkts) +
  3870. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts) +
  3871. GET_NET_STATS(stats_blk->stat_IfHCOutBroadcastPkts);
  3872. net_stats->rx_bytes =
  3873. GET_NET_STATS(stats_blk->stat_IfHCInOctets);
  3874. net_stats->tx_bytes =
  3875. GET_NET_STATS(stats_blk->stat_IfHCOutOctets);
  3876. net_stats->multicast =
  3877. GET_NET_STATS(stats_blk->stat_IfHCOutMulticastPkts);
  3878. net_stats->collisions =
  3879. (unsigned long) stats_blk->stat_EtherStatsCollisions;
  3880. net_stats->rx_length_errors =
  3881. (unsigned long) (stats_blk->stat_EtherStatsUndersizePkts +
  3882. stats_blk->stat_EtherStatsOverrsizePkts);
  3883. net_stats->rx_over_errors =
  3884. (unsigned long) stats_blk->stat_IfInMBUFDiscards;
  3885. net_stats->rx_frame_errors =
  3886. (unsigned long) stats_blk->stat_Dot3StatsAlignmentErrors;
  3887. net_stats->rx_crc_errors =
  3888. (unsigned long) stats_blk->stat_Dot3StatsFCSErrors;
  3889. net_stats->rx_errors = net_stats->rx_length_errors +
  3890. net_stats->rx_over_errors + net_stats->rx_frame_errors +
  3891. net_stats->rx_crc_errors;
  3892. net_stats->tx_aborted_errors =
  3893. (unsigned long) (stats_blk->stat_Dot3StatsExcessiveCollisions +
  3894. stats_blk->stat_Dot3StatsLateCollisions);
  3895. if ((CHIP_NUM(bp) == CHIP_NUM_5706) ||
  3896. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  3897. net_stats->tx_carrier_errors = 0;
  3898. else {
  3899. net_stats->tx_carrier_errors =
  3900. (unsigned long)
  3901. stats_blk->stat_Dot3StatsCarrierSenseErrors;
  3902. }
  3903. net_stats->tx_errors =
  3904. (unsigned long)
  3905. stats_blk->stat_emac_tx_stat_dot3statsinternalmactransmiterrors
  3906. +
  3907. net_stats->tx_aborted_errors +
  3908. net_stats->tx_carrier_errors;
  3909. net_stats->rx_missed_errors =
  3910. (unsigned long) (stats_blk->stat_IfInMBUFDiscards +
  3911. stats_blk->stat_FwRxDrop);
  3912. return net_stats;
  3913. }
  3914. /* All ethtool functions called with rtnl_lock */
  3915. static int
  3916. bnx2_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3917. {
  3918. struct bnx2 *bp = netdev_priv(dev);
  3919. cmd->supported = SUPPORTED_Autoneg;
  3920. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3921. cmd->supported |= SUPPORTED_1000baseT_Full |
  3922. SUPPORTED_FIBRE;
  3923. if (bp->phy_flags & PHY_2_5G_CAPABLE_FLAG)
  3924. cmd->supported |= SUPPORTED_2500baseX_Full;
  3925. cmd->port = PORT_FIBRE;
  3926. }
  3927. else {
  3928. cmd->supported |= SUPPORTED_10baseT_Half |
  3929. SUPPORTED_10baseT_Full |
  3930. SUPPORTED_100baseT_Half |
  3931. SUPPORTED_100baseT_Full |
  3932. SUPPORTED_1000baseT_Full |
  3933. SUPPORTED_TP;
  3934. cmd->port = PORT_TP;
  3935. }
  3936. cmd->advertising = bp->advertising;
  3937. if (bp->autoneg & AUTONEG_SPEED) {
  3938. cmd->autoneg = AUTONEG_ENABLE;
  3939. }
  3940. else {
  3941. cmd->autoneg = AUTONEG_DISABLE;
  3942. }
  3943. if (netif_carrier_ok(dev)) {
  3944. cmd->speed = bp->line_speed;
  3945. cmd->duplex = bp->duplex;
  3946. }
  3947. else {
  3948. cmd->speed = -1;
  3949. cmd->duplex = -1;
  3950. }
  3951. cmd->transceiver = XCVR_INTERNAL;
  3952. cmd->phy_address = bp->phy_addr;
  3953. return 0;
  3954. }
  3955. static int
  3956. bnx2_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  3957. {
  3958. struct bnx2 *bp = netdev_priv(dev);
  3959. u8 autoneg = bp->autoneg;
  3960. u8 req_duplex = bp->req_duplex;
  3961. u16 req_line_speed = bp->req_line_speed;
  3962. u32 advertising = bp->advertising;
  3963. if (cmd->autoneg == AUTONEG_ENABLE) {
  3964. autoneg |= AUTONEG_SPEED;
  3965. cmd->advertising &= ETHTOOL_ALL_COPPER_SPEED;
  3966. /* allow advertising 1 speed */
  3967. if ((cmd->advertising == ADVERTISED_10baseT_Half) ||
  3968. (cmd->advertising == ADVERTISED_10baseT_Full) ||
  3969. (cmd->advertising == ADVERTISED_100baseT_Half) ||
  3970. (cmd->advertising == ADVERTISED_100baseT_Full)) {
  3971. if (bp->phy_flags & PHY_SERDES_FLAG)
  3972. return -EINVAL;
  3973. advertising = cmd->advertising;
  3974. }
  3975. else if (cmd->advertising == ADVERTISED_1000baseT_Full) {
  3976. advertising = cmd->advertising;
  3977. }
  3978. else if (cmd->advertising == ADVERTISED_1000baseT_Half) {
  3979. return -EINVAL;
  3980. }
  3981. else {
  3982. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3983. advertising = ETHTOOL_ALL_FIBRE_SPEED;
  3984. }
  3985. else {
  3986. advertising = ETHTOOL_ALL_COPPER_SPEED;
  3987. }
  3988. }
  3989. advertising |= ADVERTISED_Autoneg;
  3990. }
  3991. else {
  3992. if (bp->phy_flags & PHY_SERDES_FLAG) {
  3993. if ((cmd->speed != SPEED_1000 &&
  3994. cmd->speed != SPEED_2500) ||
  3995. (cmd->duplex != DUPLEX_FULL))
  3996. return -EINVAL;
  3997. if (cmd->speed == SPEED_2500 &&
  3998. !(bp->phy_flags & PHY_2_5G_CAPABLE_FLAG))
  3999. return -EINVAL;
  4000. }
  4001. else if (cmd->speed == SPEED_1000) {
  4002. return -EINVAL;
  4003. }
  4004. autoneg &= ~AUTONEG_SPEED;
  4005. req_line_speed = cmd->speed;
  4006. req_duplex = cmd->duplex;
  4007. advertising = 0;
  4008. }
  4009. bp->autoneg = autoneg;
  4010. bp->advertising = advertising;
  4011. bp->req_line_speed = req_line_speed;
  4012. bp->req_duplex = req_duplex;
  4013. spin_lock_bh(&bp->phy_lock);
  4014. bnx2_setup_phy(bp);
  4015. spin_unlock_bh(&bp->phy_lock);
  4016. return 0;
  4017. }
  4018. static void
  4019. bnx2_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  4020. {
  4021. struct bnx2 *bp = netdev_priv(dev);
  4022. strcpy(info->driver, DRV_MODULE_NAME);
  4023. strcpy(info->version, DRV_MODULE_VERSION);
  4024. strcpy(info->bus_info, pci_name(bp->pdev));
  4025. info->fw_version[0] = ((bp->fw_ver & 0xff000000) >> 24) + '0';
  4026. info->fw_version[2] = ((bp->fw_ver & 0xff0000) >> 16) + '0';
  4027. info->fw_version[4] = ((bp->fw_ver & 0xff00) >> 8) + '0';
  4028. info->fw_version[1] = info->fw_version[3] = '.';
  4029. info->fw_version[5] = 0;
  4030. }
  4031. #define BNX2_REGDUMP_LEN (32 * 1024)
  4032. static int
  4033. bnx2_get_regs_len(struct net_device *dev)
  4034. {
  4035. return BNX2_REGDUMP_LEN;
  4036. }
  4037. static void
  4038. bnx2_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *_p)
  4039. {
  4040. u32 *p = _p, i, offset;
  4041. u8 *orig_p = _p;
  4042. struct bnx2 *bp = netdev_priv(dev);
  4043. u32 reg_boundaries[] = { 0x0000, 0x0098, 0x0400, 0x045c,
  4044. 0x0800, 0x0880, 0x0c00, 0x0c10,
  4045. 0x0c30, 0x0d08, 0x1000, 0x101c,
  4046. 0x1040, 0x1048, 0x1080, 0x10a4,
  4047. 0x1400, 0x1490, 0x1498, 0x14f0,
  4048. 0x1500, 0x155c, 0x1580, 0x15dc,
  4049. 0x1600, 0x1658, 0x1680, 0x16d8,
  4050. 0x1800, 0x1820, 0x1840, 0x1854,
  4051. 0x1880, 0x1894, 0x1900, 0x1984,
  4052. 0x1c00, 0x1c0c, 0x1c40, 0x1c54,
  4053. 0x1c80, 0x1c94, 0x1d00, 0x1d84,
  4054. 0x2000, 0x2030, 0x23c0, 0x2400,
  4055. 0x2800, 0x2820, 0x2830, 0x2850,
  4056. 0x2b40, 0x2c10, 0x2fc0, 0x3058,
  4057. 0x3c00, 0x3c94, 0x4000, 0x4010,
  4058. 0x4080, 0x4090, 0x43c0, 0x4458,
  4059. 0x4c00, 0x4c18, 0x4c40, 0x4c54,
  4060. 0x4fc0, 0x5010, 0x53c0, 0x5444,
  4061. 0x5c00, 0x5c18, 0x5c80, 0x5c90,
  4062. 0x5fc0, 0x6000, 0x6400, 0x6428,
  4063. 0x6800, 0x6848, 0x684c, 0x6860,
  4064. 0x6888, 0x6910, 0x8000 };
  4065. regs->version = 0;
  4066. memset(p, 0, BNX2_REGDUMP_LEN);
  4067. if (!netif_running(bp->dev))
  4068. return;
  4069. i = 0;
  4070. offset = reg_boundaries[0];
  4071. p += offset;
  4072. while (offset < BNX2_REGDUMP_LEN) {
  4073. *p++ = REG_RD(bp, offset);
  4074. offset += 4;
  4075. if (offset == reg_boundaries[i + 1]) {
  4076. offset = reg_boundaries[i + 2];
  4077. p = (u32 *) (orig_p + offset);
  4078. i += 2;
  4079. }
  4080. }
  4081. }
  4082. static void
  4083. bnx2_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  4084. {
  4085. struct bnx2 *bp = netdev_priv(dev);
  4086. if (bp->flags & NO_WOL_FLAG) {
  4087. wol->supported = 0;
  4088. wol->wolopts = 0;
  4089. }
  4090. else {
  4091. wol->supported = WAKE_MAGIC;
  4092. if (bp->wol)
  4093. wol->wolopts = WAKE_MAGIC;
  4094. else
  4095. wol->wolopts = 0;
  4096. }
  4097. memset(&wol->sopass, 0, sizeof(wol->sopass));
  4098. }
  4099. static int
  4100. bnx2_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  4101. {
  4102. struct bnx2 *bp = netdev_priv(dev);
  4103. if (wol->wolopts & ~WAKE_MAGIC)
  4104. return -EINVAL;
  4105. if (wol->wolopts & WAKE_MAGIC) {
  4106. if (bp->flags & NO_WOL_FLAG)
  4107. return -EINVAL;
  4108. bp->wol = 1;
  4109. }
  4110. else {
  4111. bp->wol = 0;
  4112. }
  4113. return 0;
  4114. }
  4115. static int
  4116. bnx2_nway_reset(struct net_device *dev)
  4117. {
  4118. struct bnx2 *bp = netdev_priv(dev);
  4119. u32 bmcr;
  4120. if (!(bp->autoneg & AUTONEG_SPEED)) {
  4121. return -EINVAL;
  4122. }
  4123. spin_lock_bh(&bp->phy_lock);
  4124. /* Force a link down visible on the other side */
  4125. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4126. bnx2_write_phy(bp, bp->mii_bmcr, BMCR_LOOPBACK);
  4127. spin_unlock_bh(&bp->phy_lock);
  4128. msleep(20);
  4129. spin_lock_bh(&bp->phy_lock);
  4130. bp->current_interval = SERDES_AN_TIMEOUT;
  4131. bp->serdes_an_pending = 1;
  4132. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4133. }
  4134. bnx2_read_phy(bp, bp->mii_bmcr, &bmcr);
  4135. bmcr &= ~BMCR_LOOPBACK;
  4136. bnx2_write_phy(bp, bp->mii_bmcr, bmcr | BMCR_ANRESTART | BMCR_ANENABLE);
  4137. spin_unlock_bh(&bp->phy_lock);
  4138. return 0;
  4139. }
  4140. static int
  4141. bnx2_get_eeprom_len(struct net_device *dev)
  4142. {
  4143. struct bnx2 *bp = netdev_priv(dev);
  4144. if (bp->flash_info == NULL)
  4145. return 0;
  4146. return (int) bp->flash_size;
  4147. }
  4148. static int
  4149. bnx2_get_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  4150. u8 *eebuf)
  4151. {
  4152. struct bnx2 *bp = netdev_priv(dev);
  4153. int rc;
  4154. /* parameters already validated in ethtool_get_eeprom */
  4155. rc = bnx2_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  4156. return rc;
  4157. }
  4158. static int
  4159. bnx2_set_eeprom(struct net_device *dev, struct ethtool_eeprom *eeprom,
  4160. u8 *eebuf)
  4161. {
  4162. struct bnx2 *bp = netdev_priv(dev);
  4163. int rc;
  4164. /* parameters already validated in ethtool_set_eeprom */
  4165. rc = bnx2_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  4166. return rc;
  4167. }
  4168. static int
  4169. bnx2_get_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4170. {
  4171. struct bnx2 *bp = netdev_priv(dev);
  4172. memset(coal, 0, sizeof(struct ethtool_coalesce));
  4173. coal->rx_coalesce_usecs = bp->rx_ticks;
  4174. coal->rx_max_coalesced_frames = bp->rx_quick_cons_trip;
  4175. coal->rx_coalesce_usecs_irq = bp->rx_ticks_int;
  4176. coal->rx_max_coalesced_frames_irq = bp->rx_quick_cons_trip_int;
  4177. coal->tx_coalesce_usecs = bp->tx_ticks;
  4178. coal->tx_max_coalesced_frames = bp->tx_quick_cons_trip;
  4179. coal->tx_coalesce_usecs_irq = bp->tx_ticks_int;
  4180. coal->tx_max_coalesced_frames_irq = bp->tx_quick_cons_trip_int;
  4181. coal->stats_block_coalesce_usecs = bp->stats_ticks;
  4182. return 0;
  4183. }
  4184. static int
  4185. bnx2_set_coalesce(struct net_device *dev, struct ethtool_coalesce *coal)
  4186. {
  4187. struct bnx2 *bp = netdev_priv(dev);
  4188. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  4189. if (bp->rx_ticks > 0x3ff) bp->rx_ticks = 0x3ff;
  4190. bp->rx_quick_cons_trip = (u16) coal->rx_max_coalesced_frames;
  4191. if (bp->rx_quick_cons_trip > 0xff) bp->rx_quick_cons_trip = 0xff;
  4192. bp->rx_ticks_int = (u16) coal->rx_coalesce_usecs_irq;
  4193. if (bp->rx_ticks_int > 0x3ff) bp->rx_ticks_int = 0x3ff;
  4194. bp->rx_quick_cons_trip_int = (u16) coal->rx_max_coalesced_frames_irq;
  4195. if (bp->rx_quick_cons_trip_int > 0xff)
  4196. bp->rx_quick_cons_trip_int = 0xff;
  4197. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  4198. if (bp->tx_ticks > 0x3ff) bp->tx_ticks = 0x3ff;
  4199. bp->tx_quick_cons_trip = (u16) coal->tx_max_coalesced_frames;
  4200. if (bp->tx_quick_cons_trip > 0xff) bp->tx_quick_cons_trip = 0xff;
  4201. bp->tx_ticks_int = (u16) coal->tx_coalesce_usecs_irq;
  4202. if (bp->tx_ticks_int > 0x3ff) bp->tx_ticks_int = 0x3ff;
  4203. bp->tx_quick_cons_trip_int = (u16) coal->tx_max_coalesced_frames_irq;
  4204. if (bp->tx_quick_cons_trip_int > 0xff) bp->tx_quick_cons_trip_int =
  4205. 0xff;
  4206. bp->stats_ticks = coal->stats_block_coalesce_usecs;
  4207. if (bp->stats_ticks > 0xffff00) bp->stats_ticks = 0xffff00;
  4208. bp->stats_ticks &= 0xffff00;
  4209. if (netif_running(bp->dev)) {
  4210. bnx2_netif_stop(bp);
  4211. bnx2_init_nic(bp);
  4212. bnx2_netif_start(bp);
  4213. }
  4214. return 0;
  4215. }
  4216. static void
  4217. bnx2_get_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4218. {
  4219. struct bnx2 *bp = netdev_priv(dev);
  4220. ering->rx_max_pending = MAX_TOTAL_RX_DESC_CNT;
  4221. ering->rx_mini_max_pending = 0;
  4222. ering->rx_jumbo_max_pending = 0;
  4223. ering->rx_pending = bp->rx_ring_size;
  4224. ering->rx_mini_pending = 0;
  4225. ering->rx_jumbo_pending = 0;
  4226. ering->tx_max_pending = MAX_TX_DESC_CNT;
  4227. ering->tx_pending = bp->tx_ring_size;
  4228. }
  4229. static int
  4230. bnx2_set_ringparam(struct net_device *dev, struct ethtool_ringparam *ering)
  4231. {
  4232. struct bnx2 *bp = netdev_priv(dev);
  4233. if ((ering->rx_pending > MAX_TOTAL_RX_DESC_CNT) ||
  4234. (ering->tx_pending > MAX_TX_DESC_CNT) ||
  4235. (ering->tx_pending <= MAX_SKB_FRAGS)) {
  4236. return -EINVAL;
  4237. }
  4238. if (netif_running(bp->dev)) {
  4239. bnx2_netif_stop(bp);
  4240. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4241. bnx2_free_skbs(bp);
  4242. bnx2_free_mem(bp);
  4243. }
  4244. bnx2_set_rx_ring_size(bp, ering->rx_pending);
  4245. bp->tx_ring_size = ering->tx_pending;
  4246. if (netif_running(bp->dev)) {
  4247. int rc;
  4248. rc = bnx2_alloc_mem(bp);
  4249. if (rc)
  4250. return rc;
  4251. bnx2_init_nic(bp);
  4252. bnx2_netif_start(bp);
  4253. }
  4254. return 0;
  4255. }
  4256. static void
  4257. bnx2_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4258. {
  4259. struct bnx2 *bp = netdev_priv(dev);
  4260. epause->autoneg = ((bp->autoneg & AUTONEG_FLOW_CTRL) != 0);
  4261. epause->rx_pause = ((bp->flow_ctrl & FLOW_CTRL_RX) != 0);
  4262. epause->tx_pause = ((bp->flow_ctrl & FLOW_CTRL_TX) != 0);
  4263. }
  4264. static int
  4265. bnx2_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam *epause)
  4266. {
  4267. struct bnx2 *bp = netdev_priv(dev);
  4268. bp->req_flow_ctrl = 0;
  4269. if (epause->rx_pause)
  4270. bp->req_flow_ctrl |= FLOW_CTRL_RX;
  4271. if (epause->tx_pause)
  4272. bp->req_flow_ctrl |= FLOW_CTRL_TX;
  4273. if (epause->autoneg) {
  4274. bp->autoneg |= AUTONEG_FLOW_CTRL;
  4275. }
  4276. else {
  4277. bp->autoneg &= ~AUTONEG_FLOW_CTRL;
  4278. }
  4279. spin_lock_bh(&bp->phy_lock);
  4280. bnx2_setup_phy(bp);
  4281. spin_unlock_bh(&bp->phy_lock);
  4282. return 0;
  4283. }
  4284. static u32
  4285. bnx2_get_rx_csum(struct net_device *dev)
  4286. {
  4287. struct bnx2 *bp = netdev_priv(dev);
  4288. return bp->rx_csum;
  4289. }
  4290. static int
  4291. bnx2_set_rx_csum(struct net_device *dev, u32 data)
  4292. {
  4293. struct bnx2 *bp = netdev_priv(dev);
  4294. bp->rx_csum = data;
  4295. return 0;
  4296. }
  4297. static int
  4298. bnx2_set_tso(struct net_device *dev, u32 data)
  4299. {
  4300. struct bnx2 *bp = netdev_priv(dev);
  4301. if (data) {
  4302. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  4303. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4304. dev->features |= NETIF_F_TSO6;
  4305. } else
  4306. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6 |
  4307. NETIF_F_TSO_ECN);
  4308. return 0;
  4309. }
  4310. #define BNX2_NUM_STATS 46
  4311. static struct {
  4312. char string[ETH_GSTRING_LEN];
  4313. } bnx2_stats_str_arr[BNX2_NUM_STATS] = {
  4314. { "rx_bytes" },
  4315. { "rx_error_bytes" },
  4316. { "tx_bytes" },
  4317. { "tx_error_bytes" },
  4318. { "rx_ucast_packets" },
  4319. { "rx_mcast_packets" },
  4320. { "rx_bcast_packets" },
  4321. { "tx_ucast_packets" },
  4322. { "tx_mcast_packets" },
  4323. { "tx_bcast_packets" },
  4324. { "tx_mac_errors" },
  4325. { "tx_carrier_errors" },
  4326. { "rx_crc_errors" },
  4327. { "rx_align_errors" },
  4328. { "tx_single_collisions" },
  4329. { "tx_multi_collisions" },
  4330. { "tx_deferred" },
  4331. { "tx_excess_collisions" },
  4332. { "tx_late_collisions" },
  4333. { "tx_total_collisions" },
  4334. { "rx_fragments" },
  4335. { "rx_jabbers" },
  4336. { "rx_undersize_packets" },
  4337. { "rx_oversize_packets" },
  4338. { "rx_64_byte_packets" },
  4339. { "rx_65_to_127_byte_packets" },
  4340. { "rx_128_to_255_byte_packets" },
  4341. { "rx_256_to_511_byte_packets" },
  4342. { "rx_512_to_1023_byte_packets" },
  4343. { "rx_1024_to_1522_byte_packets" },
  4344. { "rx_1523_to_9022_byte_packets" },
  4345. { "tx_64_byte_packets" },
  4346. { "tx_65_to_127_byte_packets" },
  4347. { "tx_128_to_255_byte_packets" },
  4348. { "tx_256_to_511_byte_packets" },
  4349. { "tx_512_to_1023_byte_packets" },
  4350. { "tx_1024_to_1522_byte_packets" },
  4351. { "tx_1523_to_9022_byte_packets" },
  4352. { "rx_xon_frames" },
  4353. { "rx_xoff_frames" },
  4354. { "tx_xon_frames" },
  4355. { "tx_xoff_frames" },
  4356. { "rx_mac_ctrl_frames" },
  4357. { "rx_filtered_packets" },
  4358. { "rx_discards" },
  4359. { "rx_fw_discards" },
  4360. };
  4361. #define STATS_OFFSET32(offset_name) (offsetof(struct statistics_block, offset_name) / 4)
  4362. static const unsigned long bnx2_stats_offset_arr[BNX2_NUM_STATS] = {
  4363. STATS_OFFSET32(stat_IfHCInOctets_hi),
  4364. STATS_OFFSET32(stat_IfHCInBadOctets_hi),
  4365. STATS_OFFSET32(stat_IfHCOutOctets_hi),
  4366. STATS_OFFSET32(stat_IfHCOutBadOctets_hi),
  4367. STATS_OFFSET32(stat_IfHCInUcastPkts_hi),
  4368. STATS_OFFSET32(stat_IfHCInMulticastPkts_hi),
  4369. STATS_OFFSET32(stat_IfHCInBroadcastPkts_hi),
  4370. STATS_OFFSET32(stat_IfHCOutUcastPkts_hi),
  4371. STATS_OFFSET32(stat_IfHCOutMulticastPkts_hi),
  4372. STATS_OFFSET32(stat_IfHCOutBroadcastPkts_hi),
  4373. STATS_OFFSET32(stat_emac_tx_stat_dot3statsinternalmactransmiterrors),
  4374. STATS_OFFSET32(stat_Dot3StatsCarrierSenseErrors),
  4375. STATS_OFFSET32(stat_Dot3StatsFCSErrors),
  4376. STATS_OFFSET32(stat_Dot3StatsAlignmentErrors),
  4377. STATS_OFFSET32(stat_Dot3StatsSingleCollisionFrames),
  4378. STATS_OFFSET32(stat_Dot3StatsMultipleCollisionFrames),
  4379. STATS_OFFSET32(stat_Dot3StatsDeferredTransmissions),
  4380. STATS_OFFSET32(stat_Dot3StatsExcessiveCollisions),
  4381. STATS_OFFSET32(stat_Dot3StatsLateCollisions),
  4382. STATS_OFFSET32(stat_EtherStatsCollisions),
  4383. STATS_OFFSET32(stat_EtherStatsFragments),
  4384. STATS_OFFSET32(stat_EtherStatsJabbers),
  4385. STATS_OFFSET32(stat_EtherStatsUndersizePkts),
  4386. STATS_OFFSET32(stat_EtherStatsOverrsizePkts),
  4387. STATS_OFFSET32(stat_EtherStatsPktsRx64Octets),
  4388. STATS_OFFSET32(stat_EtherStatsPktsRx65Octetsto127Octets),
  4389. STATS_OFFSET32(stat_EtherStatsPktsRx128Octetsto255Octets),
  4390. STATS_OFFSET32(stat_EtherStatsPktsRx256Octetsto511Octets),
  4391. STATS_OFFSET32(stat_EtherStatsPktsRx512Octetsto1023Octets),
  4392. STATS_OFFSET32(stat_EtherStatsPktsRx1024Octetsto1522Octets),
  4393. STATS_OFFSET32(stat_EtherStatsPktsRx1523Octetsto9022Octets),
  4394. STATS_OFFSET32(stat_EtherStatsPktsTx64Octets),
  4395. STATS_OFFSET32(stat_EtherStatsPktsTx65Octetsto127Octets),
  4396. STATS_OFFSET32(stat_EtherStatsPktsTx128Octetsto255Octets),
  4397. STATS_OFFSET32(stat_EtherStatsPktsTx256Octetsto511Octets),
  4398. STATS_OFFSET32(stat_EtherStatsPktsTx512Octetsto1023Octets),
  4399. STATS_OFFSET32(stat_EtherStatsPktsTx1024Octetsto1522Octets),
  4400. STATS_OFFSET32(stat_EtherStatsPktsTx1523Octetsto9022Octets),
  4401. STATS_OFFSET32(stat_XonPauseFramesReceived),
  4402. STATS_OFFSET32(stat_XoffPauseFramesReceived),
  4403. STATS_OFFSET32(stat_OutXonSent),
  4404. STATS_OFFSET32(stat_OutXoffSent),
  4405. STATS_OFFSET32(stat_MacControlFramesReceived),
  4406. STATS_OFFSET32(stat_IfInFramesL2FilterDiscards),
  4407. STATS_OFFSET32(stat_IfInMBUFDiscards),
  4408. STATS_OFFSET32(stat_FwRxDrop),
  4409. };
  4410. /* stat_IfHCInBadOctets and stat_Dot3StatsCarrierSenseErrors are
  4411. * skipped because of errata.
  4412. */
  4413. static u8 bnx2_5706_stats_len_arr[BNX2_NUM_STATS] = {
  4414. 8,0,8,8,8,8,8,8,8,8,
  4415. 4,0,4,4,4,4,4,4,4,4,
  4416. 4,4,4,4,4,4,4,4,4,4,
  4417. 4,4,4,4,4,4,4,4,4,4,
  4418. 4,4,4,4,4,4,
  4419. };
  4420. static u8 bnx2_5708_stats_len_arr[BNX2_NUM_STATS] = {
  4421. 8,0,8,8,8,8,8,8,8,8,
  4422. 4,4,4,4,4,4,4,4,4,4,
  4423. 4,4,4,4,4,4,4,4,4,4,
  4424. 4,4,4,4,4,4,4,4,4,4,
  4425. 4,4,4,4,4,4,
  4426. };
  4427. #define BNX2_NUM_TESTS 6
  4428. static struct {
  4429. char string[ETH_GSTRING_LEN];
  4430. } bnx2_tests_str_arr[BNX2_NUM_TESTS] = {
  4431. { "register_test (offline)" },
  4432. { "memory_test (offline)" },
  4433. { "loopback_test (offline)" },
  4434. { "nvram_test (online)" },
  4435. { "interrupt_test (online)" },
  4436. { "link_test (online)" },
  4437. };
  4438. static int
  4439. bnx2_self_test_count(struct net_device *dev)
  4440. {
  4441. return BNX2_NUM_TESTS;
  4442. }
  4443. static void
  4444. bnx2_self_test(struct net_device *dev, struct ethtool_test *etest, u64 *buf)
  4445. {
  4446. struct bnx2 *bp = netdev_priv(dev);
  4447. memset(buf, 0, sizeof(u64) * BNX2_NUM_TESTS);
  4448. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  4449. int i;
  4450. bnx2_netif_stop(bp);
  4451. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_DIAG);
  4452. bnx2_free_skbs(bp);
  4453. if (bnx2_test_registers(bp) != 0) {
  4454. buf[0] = 1;
  4455. etest->flags |= ETH_TEST_FL_FAILED;
  4456. }
  4457. if (bnx2_test_memory(bp) != 0) {
  4458. buf[1] = 1;
  4459. etest->flags |= ETH_TEST_FL_FAILED;
  4460. }
  4461. if ((buf[2] = bnx2_test_loopback(bp)) != 0)
  4462. etest->flags |= ETH_TEST_FL_FAILED;
  4463. if (!netif_running(bp->dev)) {
  4464. bnx2_reset_chip(bp, BNX2_DRV_MSG_CODE_RESET);
  4465. }
  4466. else {
  4467. bnx2_init_nic(bp);
  4468. bnx2_netif_start(bp);
  4469. }
  4470. /* wait for link up */
  4471. for (i = 0; i < 7; i++) {
  4472. if (bp->link_up)
  4473. break;
  4474. msleep_interruptible(1000);
  4475. }
  4476. }
  4477. if (bnx2_test_nvram(bp) != 0) {
  4478. buf[3] = 1;
  4479. etest->flags |= ETH_TEST_FL_FAILED;
  4480. }
  4481. if (bnx2_test_intr(bp) != 0) {
  4482. buf[4] = 1;
  4483. etest->flags |= ETH_TEST_FL_FAILED;
  4484. }
  4485. if (bnx2_test_link(bp) != 0) {
  4486. buf[5] = 1;
  4487. etest->flags |= ETH_TEST_FL_FAILED;
  4488. }
  4489. }
  4490. static void
  4491. bnx2_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  4492. {
  4493. switch (stringset) {
  4494. case ETH_SS_STATS:
  4495. memcpy(buf, bnx2_stats_str_arr,
  4496. sizeof(bnx2_stats_str_arr));
  4497. break;
  4498. case ETH_SS_TEST:
  4499. memcpy(buf, bnx2_tests_str_arr,
  4500. sizeof(bnx2_tests_str_arr));
  4501. break;
  4502. }
  4503. }
  4504. static int
  4505. bnx2_get_stats_count(struct net_device *dev)
  4506. {
  4507. return BNX2_NUM_STATS;
  4508. }
  4509. static void
  4510. bnx2_get_ethtool_stats(struct net_device *dev,
  4511. struct ethtool_stats *stats, u64 *buf)
  4512. {
  4513. struct bnx2 *bp = netdev_priv(dev);
  4514. int i;
  4515. u32 *hw_stats = (u32 *) bp->stats_blk;
  4516. u8 *stats_len_arr = NULL;
  4517. if (hw_stats == NULL) {
  4518. memset(buf, 0, sizeof(u64) * BNX2_NUM_STATS);
  4519. return;
  4520. }
  4521. if ((CHIP_ID(bp) == CHIP_ID_5706_A0) ||
  4522. (CHIP_ID(bp) == CHIP_ID_5706_A1) ||
  4523. (CHIP_ID(bp) == CHIP_ID_5706_A2) ||
  4524. (CHIP_ID(bp) == CHIP_ID_5708_A0))
  4525. stats_len_arr = bnx2_5706_stats_len_arr;
  4526. else
  4527. stats_len_arr = bnx2_5708_stats_len_arr;
  4528. for (i = 0; i < BNX2_NUM_STATS; i++) {
  4529. if (stats_len_arr[i] == 0) {
  4530. /* skip this counter */
  4531. buf[i] = 0;
  4532. continue;
  4533. }
  4534. if (stats_len_arr[i] == 4) {
  4535. /* 4-byte counter */
  4536. buf[i] = (u64)
  4537. *(hw_stats + bnx2_stats_offset_arr[i]);
  4538. continue;
  4539. }
  4540. /* 8-byte counter */
  4541. buf[i] = (((u64) *(hw_stats +
  4542. bnx2_stats_offset_arr[i])) << 32) +
  4543. *(hw_stats + bnx2_stats_offset_arr[i] + 1);
  4544. }
  4545. }
  4546. static int
  4547. bnx2_phys_id(struct net_device *dev, u32 data)
  4548. {
  4549. struct bnx2 *bp = netdev_priv(dev);
  4550. int i;
  4551. u32 save;
  4552. if (data == 0)
  4553. data = 2;
  4554. save = REG_RD(bp, BNX2_MISC_CFG);
  4555. REG_WR(bp, BNX2_MISC_CFG, BNX2_MISC_CFG_LEDMODE_MAC);
  4556. for (i = 0; i < (data * 2); i++) {
  4557. if ((i % 2) == 0) {
  4558. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE);
  4559. }
  4560. else {
  4561. REG_WR(bp, BNX2_EMAC_LED, BNX2_EMAC_LED_OVERRIDE |
  4562. BNX2_EMAC_LED_1000MB_OVERRIDE |
  4563. BNX2_EMAC_LED_100MB_OVERRIDE |
  4564. BNX2_EMAC_LED_10MB_OVERRIDE |
  4565. BNX2_EMAC_LED_TRAFFIC_OVERRIDE |
  4566. BNX2_EMAC_LED_TRAFFIC);
  4567. }
  4568. msleep_interruptible(500);
  4569. if (signal_pending(current))
  4570. break;
  4571. }
  4572. REG_WR(bp, BNX2_EMAC_LED, 0);
  4573. REG_WR(bp, BNX2_MISC_CFG, save);
  4574. return 0;
  4575. }
  4576. static int
  4577. bnx2_set_tx_csum(struct net_device *dev, u32 data)
  4578. {
  4579. struct bnx2 *bp = netdev_priv(dev);
  4580. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4581. return (ethtool_op_set_tx_hw_csum(dev, data));
  4582. else
  4583. return (ethtool_op_set_tx_csum(dev, data));
  4584. }
  4585. static const struct ethtool_ops bnx2_ethtool_ops = {
  4586. .get_settings = bnx2_get_settings,
  4587. .set_settings = bnx2_set_settings,
  4588. .get_drvinfo = bnx2_get_drvinfo,
  4589. .get_regs_len = bnx2_get_regs_len,
  4590. .get_regs = bnx2_get_regs,
  4591. .get_wol = bnx2_get_wol,
  4592. .set_wol = bnx2_set_wol,
  4593. .nway_reset = bnx2_nway_reset,
  4594. .get_link = ethtool_op_get_link,
  4595. .get_eeprom_len = bnx2_get_eeprom_len,
  4596. .get_eeprom = bnx2_get_eeprom,
  4597. .set_eeprom = bnx2_set_eeprom,
  4598. .get_coalesce = bnx2_get_coalesce,
  4599. .set_coalesce = bnx2_set_coalesce,
  4600. .get_ringparam = bnx2_get_ringparam,
  4601. .set_ringparam = bnx2_set_ringparam,
  4602. .get_pauseparam = bnx2_get_pauseparam,
  4603. .set_pauseparam = bnx2_set_pauseparam,
  4604. .get_rx_csum = bnx2_get_rx_csum,
  4605. .set_rx_csum = bnx2_set_rx_csum,
  4606. .get_tx_csum = ethtool_op_get_tx_csum,
  4607. .set_tx_csum = bnx2_set_tx_csum,
  4608. .get_sg = ethtool_op_get_sg,
  4609. .set_sg = ethtool_op_set_sg,
  4610. .get_tso = ethtool_op_get_tso,
  4611. .set_tso = bnx2_set_tso,
  4612. .self_test_count = bnx2_self_test_count,
  4613. .self_test = bnx2_self_test,
  4614. .get_strings = bnx2_get_strings,
  4615. .phys_id = bnx2_phys_id,
  4616. .get_stats_count = bnx2_get_stats_count,
  4617. .get_ethtool_stats = bnx2_get_ethtool_stats,
  4618. .get_perm_addr = ethtool_op_get_perm_addr,
  4619. };
  4620. /* Called with rtnl_lock */
  4621. static int
  4622. bnx2_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  4623. {
  4624. struct mii_ioctl_data *data = if_mii(ifr);
  4625. struct bnx2 *bp = netdev_priv(dev);
  4626. int err;
  4627. switch(cmd) {
  4628. case SIOCGMIIPHY:
  4629. data->phy_id = bp->phy_addr;
  4630. /* fallthru */
  4631. case SIOCGMIIREG: {
  4632. u32 mii_regval;
  4633. if (!netif_running(dev))
  4634. return -EAGAIN;
  4635. spin_lock_bh(&bp->phy_lock);
  4636. err = bnx2_read_phy(bp, data->reg_num & 0x1f, &mii_regval);
  4637. spin_unlock_bh(&bp->phy_lock);
  4638. data->val_out = mii_regval;
  4639. return err;
  4640. }
  4641. case SIOCSMIIREG:
  4642. if (!capable(CAP_NET_ADMIN))
  4643. return -EPERM;
  4644. if (!netif_running(dev))
  4645. return -EAGAIN;
  4646. spin_lock_bh(&bp->phy_lock);
  4647. err = bnx2_write_phy(bp, data->reg_num & 0x1f, data->val_in);
  4648. spin_unlock_bh(&bp->phy_lock);
  4649. return err;
  4650. default:
  4651. /* do nothing */
  4652. break;
  4653. }
  4654. return -EOPNOTSUPP;
  4655. }
  4656. /* Called with rtnl_lock */
  4657. static int
  4658. bnx2_change_mac_addr(struct net_device *dev, void *p)
  4659. {
  4660. struct sockaddr *addr = p;
  4661. struct bnx2 *bp = netdev_priv(dev);
  4662. if (!is_valid_ether_addr(addr->sa_data))
  4663. return -EINVAL;
  4664. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4665. if (netif_running(dev))
  4666. bnx2_set_mac_addr(bp);
  4667. return 0;
  4668. }
  4669. /* Called with rtnl_lock */
  4670. static int
  4671. bnx2_change_mtu(struct net_device *dev, int new_mtu)
  4672. {
  4673. struct bnx2 *bp = netdev_priv(dev);
  4674. if (((new_mtu + ETH_HLEN) > MAX_ETHERNET_JUMBO_PACKET_SIZE) ||
  4675. ((new_mtu + ETH_HLEN) < MIN_ETHERNET_PACKET_SIZE))
  4676. return -EINVAL;
  4677. dev->mtu = new_mtu;
  4678. if (netif_running(dev)) {
  4679. bnx2_netif_stop(bp);
  4680. bnx2_init_nic(bp);
  4681. bnx2_netif_start(bp);
  4682. }
  4683. return 0;
  4684. }
  4685. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  4686. static void
  4687. poll_bnx2(struct net_device *dev)
  4688. {
  4689. struct bnx2 *bp = netdev_priv(dev);
  4690. disable_irq(bp->pdev->irq);
  4691. bnx2_interrupt(bp->pdev->irq, dev);
  4692. enable_irq(bp->pdev->irq);
  4693. }
  4694. #endif
  4695. static void __devinit
  4696. bnx2_get_5709_media(struct bnx2 *bp)
  4697. {
  4698. u32 val = REG_RD(bp, BNX2_MISC_DUAL_MEDIA_CTRL);
  4699. u32 bond_id = val & BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID;
  4700. u32 strap;
  4701. if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_C)
  4702. return;
  4703. else if (bond_id == BNX2_MISC_DUAL_MEDIA_CTRL_BOND_ID_S) {
  4704. bp->phy_flags |= PHY_SERDES_FLAG;
  4705. return;
  4706. }
  4707. if (val & BNX2_MISC_DUAL_MEDIA_CTRL_STRAP_OVERRIDE)
  4708. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL) >> 21;
  4709. else
  4710. strap = (val & BNX2_MISC_DUAL_MEDIA_CTRL_PHY_CTRL_STRAP) >> 8;
  4711. if (PCI_FUNC(bp->pdev->devfn) == 0) {
  4712. switch (strap) {
  4713. case 0x4:
  4714. case 0x5:
  4715. case 0x6:
  4716. bp->phy_flags |= PHY_SERDES_FLAG;
  4717. return;
  4718. }
  4719. } else {
  4720. switch (strap) {
  4721. case 0x1:
  4722. case 0x2:
  4723. case 0x4:
  4724. bp->phy_flags |= PHY_SERDES_FLAG;
  4725. return;
  4726. }
  4727. }
  4728. }
  4729. static int __devinit
  4730. bnx2_init_board(struct pci_dev *pdev, struct net_device *dev)
  4731. {
  4732. struct bnx2 *bp;
  4733. unsigned long mem_len;
  4734. int rc;
  4735. u32 reg;
  4736. u64 dma_mask, persist_dma_mask;
  4737. SET_MODULE_OWNER(dev);
  4738. SET_NETDEV_DEV(dev, &pdev->dev);
  4739. bp = netdev_priv(dev);
  4740. bp->flags = 0;
  4741. bp->phy_flags = 0;
  4742. /* enable device (incl. PCI PM wakeup), and bus-mastering */
  4743. rc = pci_enable_device(pdev);
  4744. if (rc) {
  4745. dev_err(&pdev->dev, "Cannot enable PCI device, aborting.");
  4746. goto err_out;
  4747. }
  4748. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  4749. dev_err(&pdev->dev,
  4750. "Cannot find PCI device base address, aborting.\n");
  4751. rc = -ENODEV;
  4752. goto err_out_disable;
  4753. }
  4754. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  4755. if (rc) {
  4756. dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting.\n");
  4757. goto err_out_disable;
  4758. }
  4759. pci_set_master(pdev);
  4760. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  4761. if (bp->pm_cap == 0) {
  4762. dev_err(&pdev->dev,
  4763. "Cannot find power management capability, aborting.\n");
  4764. rc = -EIO;
  4765. goto err_out_release;
  4766. }
  4767. bp->dev = dev;
  4768. bp->pdev = pdev;
  4769. spin_lock_init(&bp->phy_lock);
  4770. INIT_WORK(&bp->reset_task, bnx2_reset_task);
  4771. dev->base_addr = dev->mem_start = pci_resource_start(pdev, 0);
  4772. mem_len = MB_GET_CID_ADDR(TX_TSS_CID + 1);
  4773. dev->mem_end = dev->mem_start + mem_len;
  4774. dev->irq = pdev->irq;
  4775. bp->regview = ioremap_nocache(dev->base_addr, mem_len);
  4776. if (!bp->regview) {
  4777. dev_err(&pdev->dev, "Cannot map register space, aborting.\n");
  4778. rc = -ENOMEM;
  4779. goto err_out_release;
  4780. }
  4781. /* Configure byte swap and enable write to the reg_window registers.
  4782. * Rely on CPU to do target byte swapping on big endian systems
  4783. * The chip's target access swapping will not swap all accesses
  4784. */
  4785. pci_write_config_dword(bp->pdev, BNX2_PCICFG_MISC_CONFIG,
  4786. BNX2_PCICFG_MISC_CONFIG_REG_WINDOW_ENA |
  4787. BNX2_PCICFG_MISC_CONFIG_TARGET_MB_WORD_SWAP);
  4788. bnx2_set_power_state(bp, PCI_D0);
  4789. bp->chip_id = REG_RD(bp, BNX2_MISC_ID);
  4790. if (CHIP_NUM(bp) != CHIP_NUM_5709) {
  4791. bp->pcix_cap = pci_find_capability(pdev, PCI_CAP_ID_PCIX);
  4792. if (bp->pcix_cap == 0) {
  4793. dev_err(&pdev->dev,
  4794. "Cannot find PCIX capability, aborting.\n");
  4795. rc = -EIO;
  4796. goto err_out_unmap;
  4797. }
  4798. }
  4799. /* 5708 cannot support DMA addresses > 40-bit. */
  4800. if (CHIP_NUM(bp) == CHIP_NUM_5708)
  4801. persist_dma_mask = dma_mask = DMA_40BIT_MASK;
  4802. else
  4803. persist_dma_mask = dma_mask = DMA_64BIT_MASK;
  4804. /* Configure DMA attributes. */
  4805. if (pci_set_dma_mask(pdev, dma_mask) == 0) {
  4806. dev->features |= NETIF_F_HIGHDMA;
  4807. rc = pci_set_consistent_dma_mask(pdev, persist_dma_mask);
  4808. if (rc) {
  4809. dev_err(&pdev->dev,
  4810. "pci_set_consistent_dma_mask failed, aborting.\n");
  4811. goto err_out_unmap;
  4812. }
  4813. } else if ((rc = pci_set_dma_mask(pdev, DMA_32BIT_MASK)) != 0) {
  4814. dev_err(&pdev->dev, "System does not support DMA, aborting.\n");
  4815. goto err_out_unmap;
  4816. }
  4817. /* Get bus information. */
  4818. reg = REG_RD(bp, BNX2_PCICFG_MISC_STATUS);
  4819. if (reg & BNX2_PCICFG_MISC_STATUS_PCIX_DET) {
  4820. u32 clkreg;
  4821. bp->flags |= PCIX_FLAG;
  4822. clkreg = REG_RD(bp, BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS);
  4823. clkreg &= BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET;
  4824. switch (clkreg) {
  4825. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_133MHZ:
  4826. bp->bus_speed_mhz = 133;
  4827. break;
  4828. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_95MHZ:
  4829. bp->bus_speed_mhz = 100;
  4830. break;
  4831. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_66MHZ:
  4832. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_80MHZ:
  4833. bp->bus_speed_mhz = 66;
  4834. break;
  4835. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_48MHZ:
  4836. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_55MHZ:
  4837. bp->bus_speed_mhz = 50;
  4838. break;
  4839. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_LOW:
  4840. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_32MHZ:
  4841. case BNX2_PCICFG_PCI_CLOCK_CONTROL_BITS_PCI_CLK_SPD_DET_38MHZ:
  4842. bp->bus_speed_mhz = 33;
  4843. break;
  4844. }
  4845. }
  4846. else {
  4847. if (reg & BNX2_PCICFG_MISC_STATUS_M66EN)
  4848. bp->bus_speed_mhz = 66;
  4849. else
  4850. bp->bus_speed_mhz = 33;
  4851. }
  4852. if (reg & BNX2_PCICFG_MISC_STATUS_32BIT_DET)
  4853. bp->flags |= PCI_32BIT_FLAG;
  4854. /* 5706A0 may falsely detect SERR and PERR. */
  4855. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4856. reg = REG_RD(bp, PCI_COMMAND);
  4857. reg &= ~(PCI_COMMAND_SERR | PCI_COMMAND_PARITY);
  4858. REG_WR(bp, PCI_COMMAND, reg);
  4859. }
  4860. else if ((CHIP_ID(bp) == CHIP_ID_5706_A1) &&
  4861. !(bp->flags & PCIX_FLAG)) {
  4862. dev_err(&pdev->dev,
  4863. "5706 A1 can only be used in a PCIX bus, aborting.\n");
  4864. goto err_out_unmap;
  4865. }
  4866. bnx2_init_nvram(bp);
  4867. reg = REG_RD_IND(bp, BNX2_SHM_HDR_SIGNATURE);
  4868. if ((reg & BNX2_SHM_HDR_SIGNATURE_SIG_MASK) ==
  4869. BNX2_SHM_HDR_SIGNATURE_SIG) {
  4870. u32 off = PCI_FUNC(pdev->devfn) << 2;
  4871. bp->shmem_base = REG_RD_IND(bp, BNX2_SHM_HDR_ADDR_0 + off);
  4872. } else
  4873. bp->shmem_base = HOST_VIEW_SHMEM_BASE;
  4874. /* Get the permanent MAC address. First we need to make sure the
  4875. * firmware is actually running.
  4876. */
  4877. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_SIGNATURE);
  4878. if ((reg & BNX2_DEV_INFO_SIGNATURE_MAGIC_MASK) !=
  4879. BNX2_DEV_INFO_SIGNATURE_MAGIC) {
  4880. dev_err(&pdev->dev, "Firmware not running, aborting.\n");
  4881. rc = -ENODEV;
  4882. goto err_out_unmap;
  4883. }
  4884. bp->fw_ver = REG_RD_IND(bp, bp->shmem_base + BNX2_DEV_INFO_BC_REV);
  4885. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_UPPER);
  4886. bp->mac_addr[0] = (u8) (reg >> 8);
  4887. bp->mac_addr[1] = (u8) reg;
  4888. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_MAC_LOWER);
  4889. bp->mac_addr[2] = (u8) (reg >> 24);
  4890. bp->mac_addr[3] = (u8) (reg >> 16);
  4891. bp->mac_addr[4] = (u8) (reg >> 8);
  4892. bp->mac_addr[5] = (u8) reg;
  4893. bp->tx_ring_size = MAX_TX_DESC_CNT;
  4894. bnx2_set_rx_ring_size(bp, 255);
  4895. bp->rx_csum = 1;
  4896. bp->rx_offset = sizeof(struct l2_fhdr) + 2;
  4897. bp->tx_quick_cons_trip_int = 20;
  4898. bp->tx_quick_cons_trip = 20;
  4899. bp->tx_ticks_int = 80;
  4900. bp->tx_ticks = 80;
  4901. bp->rx_quick_cons_trip_int = 6;
  4902. bp->rx_quick_cons_trip = 6;
  4903. bp->rx_ticks_int = 18;
  4904. bp->rx_ticks = 18;
  4905. bp->stats_ticks = 1000000 & 0xffff00;
  4906. bp->timer_interval = HZ;
  4907. bp->current_interval = HZ;
  4908. bp->phy_addr = 1;
  4909. /* Disable WOL support if we are running on a SERDES chip. */
  4910. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  4911. bnx2_get_5709_media(bp);
  4912. else if (CHIP_BOND_ID(bp) & CHIP_BOND_ID_SERDES_BIT)
  4913. bp->phy_flags |= PHY_SERDES_FLAG;
  4914. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4915. bp->flags |= NO_WOL_FLAG;
  4916. if (CHIP_NUM(bp) != CHIP_NUM_5706) {
  4917. bp->phy_addr = 2;
  4918. reg = REG_RD_IND(bp, bp->shmem_base +
  4919. BNX2_SHARED_HW_CFG_CONFIG);
  4920. if (reg & BNX2_SHARED_HW_CFG_PHY_2_5G)
  4921. bp->phy_flags |= PHY_2_5G_CAPABLE_FLAG;
  4922. }
  4923. } else if (CHIP_NUM(bp) == CHIP_NUM_5706 ||
  4924. CHIP_NUM(bp) == CHIP_NUM_5708)
  4925. bp->phy_flags |= PHY_CRC_FIX_FLAG;
  4926. else if (CHIP_ID(bp) == CHIP_ID_5709_A0)
  4927. bp->phy_flags |= PHY_DIS_EARLY_DAC_FLAG;
  4928. if ((CHIP_ID(bp) == CHIP_ID_5708_A0) ||
  4929. (CHIP_ID(bp) == CHIP_ID_5708_B0) ||
  4930. (CHIP_ID(bp) == CHIP_ID_5708_B1))
  4931. bp->flags |= NO_WOL_FLAG;
  4932. if (CHIP_ID(bp) == CHIP_ID_5706_A0) {
  4933. bp->tx_quick_cons_trip_int =
  4934. bp->tx_quick_cons_trip;
  4935. bp->tx_ticks_int = bp->tx_ticks;
  4936. bp->rx_quick_cons_trip_int =
  4937. bp->rx_quick_cons_trip;
  4938. bp->rx_ticks_int = bp->rx_ticks;
  4939. bp->comp_prod_trip_int = bp->comp_prod_trip;
  4940. bp->com_ticks_int = bp->com_ticks;
  4941. bp->cmd_ticks_int = bp->cmd_ticks;
  4942. }
  4943. /* Disable MSI on 5706 if AMD 8132 bridge is found.
  4944. *
  4945. * MSI is defined to be 32-bit write. The 5706 does 64-bit MSI writes
  4946. * with byte enables disabled on the unused 32-bit word. This is legal
  4947. * but causes problems on the AMD 8132 which will eventually stop
  4948. * responding after a while.
  4949. *
  4950. * AMD believes this incompatibility is unique to the 5706, and
  4951. * prefers to locally disable MSI rather than globally disabling it.
  4952. */
  4953. if (CHIP_NUM(bp) == CHIP_NUM_5706 && disable_msi == 0) {
  4954. struct pci_dev *amd_8132 = NULL;
  4955. while ((amd_8132 = pci_get_device(PCI_VENDOR_ID_AMD,
  4956. PCI_DEVICE_ID_AMD_8132_BRIDGE,
  4957. amd_8132))) {
  4958. u8 rev;
  4959. pci_read_config_byte(amd_8132, PCI_REVISION_ID, &rev);
  4960. if (rev >= 0x10 && rev <= 0x13) {
  4961. disable_msi = 1;
  4962. pci_dev_put(amd_8132);
  4963. break;
  4964. }
  4965. }
  4966. }
  4967. bp->autoneg = AUTONEG_SPEED | AUTONEG_FLOW_CTRL;
  4968. bp->req_line_speed = 0;
  4969. if (bp->phy_flags & PHY_SERDES_FLAG) {
  4970. bp->advertising = ETHTOOL_ALL_FIBRE_SPEED | ADVERTISED_Autoneg;
  4971. reg = REG_RD_IND(bp, bp->shmem_base + BNX2_PORT_HW_CFG_CONFIG);
  4972. reg &= BNX2_PORT_HW_CFG_CFG_DFLT_LINK_MASK;
  4973. if (reg == BNX2_PORT_HW_CFG_CFG_DFLT_LINK_1G) {
  4974. bp->autoneg = 0;
  4975. bp->req_line_speed = bp->line_speed = SPEED_1000;
  4976. bp->req_duplex = DUPLEX_FULL;
  4977. }
  4978. }
  4979. else {
  4980. bp->advertising = ETHTOOL_ALL_COPPER_SPEED | ADVERTISED_Autoneg;
  4981. }
  4982. bp->req_flow_ctrl = FLOW_CTRL_RX | FLOW_CTRL_TX;
  4983. init_timer(&bp->timer);
  4984. bp->timer.expires = RUN_AT(bp->timer_interval);
  4985. bp->timer.data = (unsigned long) bp;
  4986. bp->timer.function = bnx2_timer;
  4987. return 0;
  4988. err_out_unmap:
  4989. if (bp->regview) {
  4990. iounmap(bp->regview);
  4991. bp->regview = NULL;
  4992. }
  4993. err_out_release:
  4994. pci_release_regions(pdev);
  4995. err_out_disable:
  4996. pci_disable_device(pdev);
  4997. pci_set_drvdata(pdev, NULL);
  4998. err_out:
  4999. return rc;
  5000. }
  5001. static int __devinit
  5002. bnx2_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  5003. {
  5004. static int version_printed = 0;
  5005. struct net_device *dev = NULL;
  5006. struct bnx2 *bp;
  5007. int rc, i;
  5008. if (version_printed++ == 0)
  5009. printk(KERN_INFO "%s", version);
  5010. /* dev zeroed in init_etherdev */
  5011. dev = alloc_etherdev(sizeof(*bp));
  5012. if (!dev)
  5013. return -ENOMEM;
  5014. rc = bnx2_init_board(pdev, dev);
  5015. if (rc < 0) {
  5016. free_netdev(dev);
  5017. return rc;
  5018. }
  5019. dev->open = bnx2_open;
  5020. dev->hard_start_xmit = bnx2_start_xmit;
  5021. dev->stop = bnx2_close;
  5022. dev->get_stats = bnx2_get_stats;
  5023. dev->set_multicast_list = bnx2_set_rx_mode;
  5024. dev->do_ioctl = bnx2_ioctl;
  5025. dev->set_mac_address = bnx2_change_mac_addr;
  5026. dev->change_mtu = bnx2_change_mtu;
  5027. dev->tx_timeout = bnx2_tx_timeout;
  5028. dev->watchdog_timeo = TX_TIMEOUT;
  5029. #ifdef BCM_VLAN
  5030. dev->vlan_rx_register = bnx2_vlan_rx_register;
  5031. dev->vlan_rx_kill_vid = bnx2_vlan_rx_kill_vid;
  5032. #endif
  5033. dev->poll = bnx2_poll;
  5034. dev->ethtool_ops = &bnx2_ethtool_ops;
  5035. dev->weight = 64;
  5036. bp = netdev_priv(dev);
  5037. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  5038. dev->poll_controller = poll_bnx2;
  5039. #endif
  5040. pci_set_drvdata(pdev, dev);
  5041. memcpy(dev->dev_addr, bp->mac_addr, 6);
  5042. memcpy(dev->perm_addr, bp->mac_addr, 6);
  5043. bp->name = board_info[ent->driver_data].name;
  5044. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5045. dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
  5046. else
  5047. dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
  5048. #ifdef BCM_VLAN
  5049. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  5050. #endif
  5051. dev->features |= NETIF_F_TSO | NETIF_F_TSO_ECN;
  5052. if (CHIP_NUM(bp) == CHIP_NUM_5709)
  5053. dev->features |= NETIF_F_TSO6;
  5054. if ((rc = register_netdev(dev))) {
  5055. dev_err(&pdev->dev, "Cannot register net device\n");
  5056. if (bp->regview)
  5057. iounmap(bp->regview);
  5058. pci_release_regions(pdev);
  5059. pci_disable_device(pdev);
  5060. pci_set_drvdata(pdev, NULL);
  5061. free_netdev(dev);
  5062. return rc;
  5063. }
  5064. printk(KERN_INFO "%s: %s (%c%d) PCI%s %s %dMHz found at mem %lx, "
  5065. "IRQ %d, ",
  5066. dev->name,
  5067. bp->name,
  5068. ((CHIP_ID(bp) & 0xf000) >> 12) + 'A',
  5069. ((CHIP_ID(bp) & 0x0ff0) >> 4),
  5070. ((bp->flags & PCIX_FLAG) ? "-X" : ""),
  5071. ((bp->flags & PCI_32BIT_FLAG) ? "32-bit" : "64-bit"),
  5072. bp->bus_speed_mhz,
  5073. dev->base_addr,
  5074. bp->pdev->irq);
  5075. printk("node addr ");
  5076. for (i = 0; i < 6; i++)
  5077. printk("%2.2x", dev->dev_addr[i]);
  5078. printk("\n");
  5079. return 0;
  5080. }
  5081. static void __devexit
  5082. bnx2_remove_one(struct pci_dev *pdev)
  5083. {
  5084. struct net_device *dev = pci_get_drvdata(pdev);
  5085. struct bnx2 *bp = netdev_priv(dev);
  5086. flush_scheduled_work();
  5087. unregister_netdev(dev);
  5088. if (bp->regview)
  5089. iounmap(bp->regview);
  5090. free_netdev(dev);
  5091. pci_release_regions(pdev);
  5092. pci_disable_device(pdev);
  5093. pci_set_drvdata(pdev, NULL);
  5094. }
  5095. static int
  5096. bnx2_suspend(struct pci_dev *pdev, pm_message_t state)
  5097. {
  5098. struct net_device *dev = pci_get_drvdata(pdev);
  5099. struct bnx2 *bp = netdev_priv(dev);
  5100. u32 reset_code;
  5101. if (!netif_running(dev))
  5102. return 0;
  5103. flush_scheduled_work();
  5104. bnx2_netif_stop(bp);
  5105. netif_device_detach(dev);
  5106. del_timer_sync(&bp->timer);
  5107. if (bp->flags & NO_WOL_FLAG)
  5108. reset_code = BNX2_DRV_MSG_CODE_UNLOAD_LNK_DN;
  5109. else if (bp->wol)
  5110. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_WOL;
  5111. else
  5112. reset_code = BNX2_DRV_MSG_CODE_SUSPEND_NO_WOL;
  5113. bnx2_reset_chip(bp, reset_code);
  5114. bnx2_free_skbs(bp);
  5115. pci_save_state(pdev);
  5116. bnx2_set_power_state(bp, pci_choose_state(pdev, state));
  5117. return 0;
  5118. }
  5119. static int
  5120. bnx2_resume(struct pci_dev *pdev)
  5121. {
  5122. struct net_device *dev = pci_get_drvdata(pdev);
  5123. struct bnx2 *bp = netdev_priv(dev);
  5124. if (!netif_running(dev))
  5125. return 0;
  5126. pci_restore_state(pdev);
  5127. bnx2_set_power_state(bp, PCI_D0);
  5128. netif_device_attach(dev);
  5129. bnx2_init_nic(bp);
  5130. bnx2_netif_start(bp);
  5131. return 0;
  5132. }
  5133. static struct pci_driver bnx2_pci_driver = {
  5134. .name = DRV_MODULE_NAME,
  5135. .id_table = bnx2_pci_tbl,
  5136. .probe = bnx2_init_one,
  5137. .remove = __devexit_p(bnx2_remove_one),
  5138. .suspend = bnx2_suspend,
  5139. .resume = bnx2_resume,
  5140. };
  5141. static int __init bnx2_init(void)
  5142. {
  5143. return pci_register_driver(&bnx2_pci_driver);
  5144. }
  5145. static void __exit bnx2_cleanup(void)
  5146. {
  5147. pci_unregister_driver(&bnx2_pci_driver);
  5148. }
  5149. module_init(bnx2_init);
  5150. module_exit(bnx2_cleanup);