bnx2.c 191 KB

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