bnx2.c 190 KB

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