bnx2.c 146 KB

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