bnx2.c 142 KB

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