bnx2.c 146 KB

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