bnx2.c 184 KB

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