bnx2.c 141 KB

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