bnx2.c 166 KB

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