bnx2.c 181 KB

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