bnx2.c 185 KB

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