bnx2.c 168 KB

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