bnx2.c 156 KB

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