bnx2.c 139 KB

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