bnx2.c 145 KB

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