bnx2.c 193 KB

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