bnx2.c 144 KB

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