bnx2.c 146 KB

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