bnx2.c 175 KB

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