bnx2.c 143 KB

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