bnx2.c 214 KB

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