bnx2.c 167 KB

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