bnx2.c 145 KB

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