bnx2.c 186 KB

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