bnx2.c 192 KB

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