bnx2x_main.c 308 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2009 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. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #include <linux/module.h>
  18. #include <linux/moduleparam.h>
  19. #include <linux/kernel.h>
  20. #include <linux/device.h> /* for dev_info() */
  21. #include <linux/timer.h>
  22. #include <linux/errno.h>
  23. #include <linux/ioport.h>
  24. #include <linux/slab.h>
  25. #include <linux/vmalloc.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/pci.h>
  28. #include <linux/init.h>
  29. #include <linux/netdevice.h>
  30. #include <linux/etherdevice.h>
  31. #include <linux/skbuff.h>
  32. #include <linux/dma-mapping.h>
  33. #include <linux/bitops.h>
  34. #include <linux/irq.h>
  35. #include <linux/delay.h>
  36. #include <asm/byteorder.h>
  37. #include <linux/time.h>
  38. #include <linux/ethtool.h>
  39. #include <linux/mii.h>
  40. #include <linux/if_vlan.h>
  41. #include <net/ip.h>
  42. #include <net/tcp.h>
  43. #include <net/checksum.h>
  44. #include <net/ip6_checksum.h>
  45. #include <linux/workqueue.h>
  46. #include <linux/crc32.h>
  47. #include <linux/crc32c.h>
  48. #include <linux/prefetch.h>
  49. #include <linux/zlib.h>
  50. #include <linux/io.h>
  51. #include "bnx2x.h"
  52. #include "bnx2x_init.h"
  53. #include "bnx2x_dump.h"
  54. #define DRV_MODULE_VERSION "1.48.105"
  55. #define DRV_MODULE_RELDATE "2009/03/02"
  56. #define BNX2X_BC_VER 0x040200
  57. /* Time in jiffies before concluding the transmitter is hung */
  58. #define TX_TIMEOUT (5*HZ)
  59. static char version[] __devinitdata =
  60. "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver "
  61. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  62. MODULE_AUTHOR("Eliezer Tamir");
  63. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver");
  64. MODULE_LICENSE("GPL");
  65. MODULE_VERSION(DRV_MODULE_VERSION);
  66. static int multi_mode = 1;
  67. module_param(multi_mode, int, 0);
  68. MODULE_PARM_DESC(multi_mode, " Use per-CPU queues");
  69. static int disable_tpa;
  70. module_param(disable_tpa, int, 0);
  71. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  72. static int int_mode;
  73. module_param(int_mode, int, 0);
  74. MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)");
  75. static int poll;
  76. module_param(poll, int, 0);
  77. MODULE_PARM_DESC(poll, " Use polling (for debug)");
  78. static int mrrs = -1;
  79. module_param(mrrs, int, 0);
  80. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  81. static int debug;
  82. module_param(debug, int, 0);
  83. MODULE_PARM_DESC(debug, " Default debug msglevel");
  84. static int load_count[3]; /* 0-common, 1-port0, 2-port1 */
  85. static struct workqueue_struct *bnx2x_wq;
  86. enum bnx2x_board_type {
  87. BCM57710 = 0,
  88. BCM57711 = 1,
  89. BCM57711E = 2,
  90. };
  91. /* indexed by board_type, above */
  92. static struct {
  93. char *name;
  94. } board_info[] __devinitdata = {
  95. { "Broadcom NetXtreme II BCM57710 XGb" },
  96. { "Broadcom NetXtreme II BCM57711 XGb" },
  97. { "Broadcom NetXtreme II BCM57711E XGb" }
  98. };
  99. static const struct pci_device_id bnx2x_pci_tbl[] = {
  100. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57710,
  101. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57710 },
  102. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711,
  103. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711 },
  104. { PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711E,
  105. PCI_ANY_ID, PCI_ANY_ID, 0, 0, BCM57711E },
  106. { 0 }
  107. };
  108. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  109. /****************************************************************************
  110. * General service functions
  111. ****************************************************************************/
  112. /* used only at init
  113. * locking is done by mcp
  114. */
  115. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  116. {
  117. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  118. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  119. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  120. PCICFG_VENDOR_ID_OFFSET);
  121. }
  122. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  123. {
  124. u32 val;
  125. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  126. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  127. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  128. PCICFG_VENDOR_ID_OFFSET);
  129. return val;
  130. }
  131. static const u32 dmae_reg_go_c[] = {
  132. DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
  133. DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
  134. DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
  135. DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
  136. };
  137. /* copy command into DMAE command memory and set DMAE command go */
  138. static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae,
  139. int idx)
  140. {
  141. u32 cmd_offset;
  142. int i;
  143. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  144. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  145. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  146. DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
  147. idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
  148. }
  149. REG_WR(bp, dmae_reg_go_c[idx], 1);
  150. }
  151. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  152. u32 len32)
  153. {
  154. struct dmae_command *dmae = &bp->init_dmae;
  155. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  156. int cnt = 200;
  157. if (!bp->dmae_ready) {
  158. u32 *data = bnx2x_sp(bp, wb_data[0]);
  159. DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
  160. " using indirect\n", dst_addr, len32);
  161. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  162. return;
  163. }
  164. mutex_lock(&bp->dmae_mutex);
  165. memset(dmae, 0, sizeof(struct dmae_command));
  166. dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  167. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  168. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  169. #ifdef __BIG_ENDIAN
  170. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  171. #else
  172. DMAE_CMD_ENDIANITY_DW_SWAP |
  173. #endif
  174. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  175. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  176. dmae->src_addr_lo = U64_LO(dma_addr);
  177. dmae->src_addr_hi = U64_HI(dma_addr);
  178. dmae->dst_addr_lo = dst_addr >> 2;
  179. dmae->dst_addr_hi = 0;
  180. dmae->len = len32;
  181. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  182. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  183. dmae->comp_val = DMAE_COMP_VAL;
  184. DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
  185. DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
  186. "dst_addr [%x:%08x (%08x)]\n"
  187. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  188. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  189. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, dst_addr,
  190. dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
  191. DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  192. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  193. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  194. *wb_comp = 0;
  195. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  196. udelay(5);
  197. while (*wb_comp != DMAE_COMP_VAL) {
  198. DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
  199. if (!cnt) {
  200. BNX2X_ERR("DMAE timeout!\n");
  201. break;
  202. }
  203. cnt--;
  204. /* adjust delay for emulation/FPGA */
  205. if (CHIP_REV_IS_SLOW(bp))
  206. msleep(100);
  207. else
  208. udelay(5);
  209. }
  210. mutex_unlock(&bp->dmae_mutex);
  211. }
  212. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  213. {
  214. struct dmae_command *dmae = &bp->init_dmae;
  215. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  216. int cnt = 200;
  217. if (!bp->dmae_ready) {
  218. u32 *data = bnx2x_sp(bp, wb_data[0]);
  219. int i;
  220. DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
  221. " using indirect\n", src_addr, len32);
  222. for (i = 0; i < len32; i++)
  223. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  224. return;
  225. }
  226. mutex_lock(&bp->dmae_mutex);
  227. memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4);
  228. memset(dmae, 0, sizeof(struct dmae_command));
  229. dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  230. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  231. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  232. #ifdef __BIG_ENDIAN
  233. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  234. #else
  235. DMAE_CMD_ENDIANITY_DW_SWAP |
  236. #endif
  237. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  238. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  239. dmae->src_addr_lo = src_addr >> 2;
  240. dmae->src_addr_hi = 0;
  241. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  242. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  243. dmae->len = len32;
  244. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  245. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  246. dmae->comp_val = DMAE_COMP_VAL;
  247. DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
  248. DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
  249. "dst_addr [%x:%08x (%08x)]\n"
  250. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  251. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  252. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo, src_addr,
  253. dmae->comp_addr_hi, dmae->comp_addr_lo, dmae->comp_val);
  254. *wb_comp = 0;
  255. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  256. udelay(5);
  257. while (*wb_comp != DMAE_COMP_VAL) {
  258. if (!cnt) {
  259. BNX2X_ERR("DMAE timeout!\n");
  260. break;
  261. }
  262. cnt--;
  263. /* adjust delay for emulation/FPGA */
  264. if (CHIP_REV_IS_SLOW(bp))
  265. msleep(100);
  266. else
  267. udelay(5);
  268. }
  269. DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  270. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  271. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  272. mutex_unlock(&bp->dmae_mutex);
  273. }
  274. /* used only for slowpath so not inlined */
  275. static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
  276. {
  277. u32 wb_write[2];
  278. wb_write[0] = val_hi;
  279. wb_write[1] = val_lo;
  280. REG_WR_DMAE(bp, reg, wb_write, 2);
  281. }
  282. #ifdef USE_WB_RD
  283. static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
  284. {
  285. u32 wb_data[2];
  286. REG_RD_DMAE(bp, reg, wb_data, 2);
  287. return HILO_U64(wb_data[0], wb_data[1]);
  288. }
  289. #endif
  290. static int bnx2x_mc_assert(struct bnx2x *bp)
  291. {
  292. char last_idx;
  293. int i, rc = 0;
  294. u32 row0, row1, row2, row3;
  295. /* XSTORM */
  296. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  297. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  298. if (last_idx)
  299. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  300. /* print the asserts */
  301. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  302. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  303. XSTORM_ASSERT_LIST_OFFSET(i));
  304. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  305. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  306. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  307. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  308. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  309. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  310. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  311. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  312. " 0x%08x 0x%08x 0x%08x\n",
  313. i, row3, row2, row1, row0);
  314. rc++;
  315. } else {
  316. break;
  317. }
  318. }
  319. /* TSTORM */
  320. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  321. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  322. if (last_idx)
  323. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  324. /* print the asserts */
  325. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  326. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  327. TSTORM_ASSERT_LIST_OFFSET(i));
  328. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  329. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  330. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  331. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  332. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  333. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  334. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  335. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  336. " 0x%08x 0x%08x 0x%08x\n",
  337. i, row3, row2, row1, row0);
  338. rc++;
  339. } else {
  340. break;
  341. }
  342. }
  343. /* CSTORM */
  344. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  345. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  346. if (last_idx)
  347. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  348. /* print the asserts */
  349. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  350. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  351. CSTORM_ASSERT_LIST_OFFSET(i));
  352. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  353. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  354. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  355. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  356. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  357. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  358. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  359. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  360. " 0x%08x 0x%08x 0x%08x\n",
  361. i, row3, row2, row1, row0);
  362. rc++;
  363. } else {
  364. break;
  365. }
  366. }
  367. /* USTORM */
  368. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  369. USTORM_ASSERT_LIST_INDEX_OFFSET);
  370. if (last_idx)
  371. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  372. /* print the asserts */
  373. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  374. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  375. USTORM_ASSERT_LIST_OFFSET(i));
  376. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  377. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  378. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  379. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  380. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  381. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  382. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  383. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
  384. " 0x%08x 0x%08x 0x%08x\n",
  385. i, row3, row2, row1, row0);
  386. rc++;
  387. } else {
  388. break;
  389. }
  390. }
  391. return rc;
  392. }
  393. static void bnx2x_fw_dump(struct bnx2x *bp)
  394. {
  395. u32 mark, offset;
  396. __be32 data[9];
  397. int word;
  398. mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104);
  399. mark = ((mark + 0x3) & ~0x3);
  400. printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n" KERN_ERR, mark);
  401. for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) {
  402. for (word = 0; word < 8; word++)
  403. data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
  404. offset + 4*word));
  405. data[8] = 0x0;
  406. printk(KERN_CONT "%s", (char *)data);
  407. }
  408. for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) {
  409. for (word = 0; word < 8; word++)
  410. data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
  411. offset + 4*word));
  412. data[8] = 0x0;
  413. printk(KERN_CONT "%s", (char *)data);
  414. }
  415. printk("\n" KERN_ERR PFX "end of fw dump\n");
  416. }
  417. static void bnx2x_panic_dump(struct bnx2x *bp)
  418. {
  419. int i;
  420. u16 j, start, end;
  421. bp->stats_state = STATS_STATE_DISABLED;
  422. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  423. BNX2X_ERR("begin crash dump -----------------\n");
  424. /* Indices */
  425. /* Common */
  426. BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)"
  427. " def_t_idx(%u) def_att_idx(%u) attn_state(%u)"
  428. " spq_prod_idx(%u)\n",
  429. bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx,
  430. bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
  431. /* Rx */
  432. for_each_rx_queue(bp, i) {
  433. struct bnx2x_fastpath *fp = &bp->fp[i];
  434. BNX2X_ERR("fp%d: rx_bd_prod(%x) rx_bd_cons(%x)"
  435. " *rx_bd_cons_sb(%x) rx_comp_prod(%x)"
  436. " rx_comp_cons(%x) *rx_cons_sb(%x)\n",
  437. i, fp->rx_bd_prod, fp->rx_bd_cons,
  438. le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod,
  439. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  440. BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)"
  441. " fp_u_idx(%x) *sb_u_idx(%x)\n",
  442. fp->rx_sge_prod, fp->last_max_sge,
  443. le16_to_cpu(fp->fp_u_idx),
  444. fp->status_blk->u_status_block.status_block_index);
  445. }
  446. /* Tx */
  447. for_each_tx_queue(bp, i) {
  448. struct bnx2x_fastpath *fp = &bp->fp[i];
  449. struct eth_tx_db_data *hw_prods = fp->hw_tx_prods;
  450. BNX2X_ERR("fp%d: tx_pkt_prod(%x) tx_pkt_cons(%x)"
  451. " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n",
  452. i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
  453. fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
  454. BNX2X_ERR(" fp_c_idx(%x) *sb_c_idx(%x)"
  455. " bd data(%x,%x)\n", le16_to_cpu(fp->fp_c_idx),
  456. fp->status_blk->c_status_block.status_block_index,
  457. hw_prods->packets_prod, hw_prods->bds_prod);
  458. }
  459. /* Rings */
  460. /* Rx */
  461. for_each_rx_queue(bp, i) {
  462. struct bnx2x_fastpath *fp = &bp->fp[i];
  463. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  464. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  465. for (j = start; j != end; j = RX_BD(j + 1)) {
  466. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  467. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  468. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  469. i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
  470. }
  471. start = RX_SGE(fp->rx_sge_prod);
  472. end = RX_SGE(fp->last_max_sge);
  473. for (j = start; j != end; j = RX_SGE(j + 1)) {
  474. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  475. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  476. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  477. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  478. }
  479. start = RCQ_BD(fp->rx_comp_cons - 10);
  480. end = RCQ_BD(fp->rx_comp_cons + 503);
  481. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  482. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  483. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  484. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  485. }
  486. }
  487. /* Tx */
  488. for_each_tx_queue(bp, i) {
  489. struct bnx2x_fastpath *fp = &bp->fp[i];
  490. start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
  491. end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
  492. for (j = start; j != end; j = TX_BD(j + 1)) {
  493. struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
  494. BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
  495. i, j, sw_bd->skb, sw_bd->first_bd);
  496. }
  497. start = TX_BD(fp->tx_bd_cons - 10);
  498. end = TX_BD(fp->tx_bd_cons + 254);
  499. for (j = start; j != end; j = TX_BD(j + 1)) {
  500. u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
  501. BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
  502. i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
  503. }
  504. }
  505. bnx2x_fw_dump(bp);
  506. bnx2x_mc_assert(bp);
  507. BNX2X_ERR("end crash dump -----------------\n");
  508. }
  509. static void bnx2x_int_enable(struct bnx2x *bp)
  510. {
  511. int port = BP_PORT(bp);
  512. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  513. u32 val = REG_RD(bp, addr);
  514. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  515. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  516. if (msix) {
  517. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  518. HC_CONFIG_0_REG_INT_LINE_EN_0);
  519. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  520. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  521. } else if (msi) {
  522. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  523. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  524. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  525. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  526. } else {
  527. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  528. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  529. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  530. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  531. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  532. val, port, addr);
  533. REG_WR(bp, addr, val);
  534. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  535. }
  536. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
  537. val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  538. REG_WR(bp, addr, val);
  539. if (CHIP_IS_E1H(bp)) {
  540. /* init leading/trailing edge */
  541. if (IS_E1HMF(bp)) {
  542. val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
  543. if (bp->port.pmf)
  544. /* enable nig and gpio3 attention */
  545. val |= 0x1100;
  546. } else
  547. val = 0xffff;
  548. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  549. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  550. }
  551. }
  552. static void bnx2x_int_disable(struct bnx2x *bp)
  553. {
  554. int port = BP_PORT(bp);
  555. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  556. u32 val = REG_RD(bp, addr);
  557. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  558. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  559. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  560. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  561. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  562. val, port, addr);
  563. /* flush all outstanding writes */
  564. mmiowb();
  565. REG_WR(bp, addr, val);
  566. if (REG_RD(bp, addr) != val)
  567. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  568. }
  569. static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  570. {
  571. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  572. int i, offset;
  573. /* disable interrupt handling */
  574. atomic_inc(&bp->intr_sem);
  575. if (disable_hw)
  576. /* prevent the HW from sending interrupts */
  577. bnx2x_int_disable(bp);
  578. /* make sure all ISRs are done */
  579. if (msix) {
  580. synchronize_irq(bp->msix_table[0].vector);
  581. offset = 1;
  582. for_each_queue(bp, i)
  583. synchronize_irq(bp->msix_table[i + offset].vector);
  584. } else
  585. synchronize_irq(bp->pdev->irq);
  586. /* make sure sp_task is not running */
  587. cancel_delayed_work(&bp->sp_task);
  588. flush_workqueue(bnx2x_wq);
  589. }
  590. /* fast path */
  591. /*
  592. * General service functions
  593. */
  594. static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id,
  595. u8 storm, u16 index, u8 op, u8 update)
  596. {
  597. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  598. COMMAND_REG_INT_ACK);
  599. struct igu_ack_register igu_ack;
  600. igu_ack.status_block_index = index;
  601. igu_ack.sb_id_and_flags =
  602. ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  603. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  604. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  605. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  606. DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
  607. (*(u32 *)&igu_ack), hc_addr);
  608. REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
  609. }
  610. static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
  611. {
  612. struct host_status_block *fpsb = fp->status_blk;
  613. u16 rc = 0;
  614. barrier(); /* status block is written to by the chip */
  615. if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) {
  616. fp->fp_c_idx = fpsb->c_status_block.status_block_index;
  617. rc |= 1;
  618. }
  619. if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) {
  620. fp->fp_u_idx = fpsb->u_status_block.status_block_index;
  621. rc |= 2;
  622. }
  623. return rc;
  624. }
  625. static u16 bnx2x_ack_int(struct bnx2x *bp)
  626. {
  627. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  628. COMMAND_REG_SIMD_MASK);
  629. u32 result = REG_RD(bp, hc_addr);
  630. DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
  631. result, hc_addr);
  632. return result;
  633. }
  634. /*
  635. * fast path service functions
  636. */
  637. static inline int bnx2x_has_tx_work(struct bnx2x_fastpath *fp)
  638. {
  639. u16 tx_cons_sb;
  640. /* Tell compiler that status block fields can change */
  641. barrier();
  642. tx_cons_sb = le16_to_cpu(*fp->tx_cons_sb);
  643. return (fp->tx_pkt_cons != tx_cons_sb);
  644. }
  645. static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
  646. {
  647. /* Tell compiler that consumer and producer can change */
  648. barrier();
  649. return (fp->tx_pkt_prod != fp->tx_pkt_cons);
  650. }
  651. /* free skb in the packet ring at pos idx
  652. * return idx of last bd freed
  653. */
  654. static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  655. u16 idx)
  656. {
  657. struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx];
  658. struct eth_tx_bd *tx_bd;
  659. struct sk_buff *skb = tx_buf->skb;
  660. u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
  661. int nbd;
  662. DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
  663. idx, tx_buf, skb);
  664. /* unmap first bd */
  665. DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
  666. tx_bd = &fp->tx_desc_ring[bd_idx];
  667. pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_bd),
  668. BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE);
  669. nbd = le16_to_cpu(tx_bd->nbd) - 1;
  670. new_cons = nbd + tx_buf->first_bd;
  671. #ifdef BNX2X_STOP_ON_ERROR
  672. if (nbd > (MAX_SKB_FRAGS + 2)) {
  673. BNX2X_ERR("BAD nbd!\n");
  674. bnx2x_panic();
  675. }
  676. #endif
  677. /* Skip a parse bd and the TSO split header bd
  678. since they have no mapping */
  679. if (nbd)
  680. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  681. if (tx_bd->bd_flags.as_bitfield & (ETH_TX_BD_FLAGS_IP_CSUM |
  682. ETH_TX_BD_FLAGS_TCP_CSUM |
  683. ETH_TX_BD_FLAGS_SW_LSO)) {
  684. if (--nbd)
  685. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  686. tx_bd = &fp->tx_desc_ring[bd_idx];
  687. /* is this a TSO split header bd? */
  688. if (tx_bd->bd_flags.as_bitfield & ETH_TX_BD_FLAGS_SW_LSO) {
  689. if (--nbd)
  690. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  691. }
  692. }
  693. /* now free frags */
  694. while (nbd > 0) {
  695. DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
  696. tx_bd = &fp->tx_desc_ring[bd_idx];
  697. pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_bd),
  698. BD_UNMAP_LEN(tx_bd), PCI_DMA_TODEVICE);
  699. if (--nbd)
  700. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  701. }
  702. /* release skb */
  703. WARN_ON(!skb);
  704. dev_kfree_skb(skb);
  705. tx_buf->first_bd = 0;
  706. tx_buf->skb = NULL;
  707. return new_cons;
  708. }
  709. static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
  710. {
  711. s16 used;
  712. u16 prod;
  713. u16 cons;
  714. barrier(); /* Tell compiler that prod and cons can change */
  715. prod = fp->tx_bd_prod;
  716. cons = fp->tx_bd_cons;
  717. /* NUM_TX_RINGS = number of "next-page" entries
  718. It will be used as a threshold */
  719. used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
  720. #ifdef BNX2X_STOP_ON_ERROR
  721. WARN_ON(used < 0);
  722. WARN_ON(used > fp->bp->tx_ring_size);
  723. WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
  724. #endif
  725. return (s16)(fp->bp->tx_ring_size) - used;
  726. }
  727. static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
  728. {
  729. struct bnx2x *bp = fp->bp;
  730. struct netdev_queue *txq;
  731. u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
  732. int done = 0;
  733. #ifdef BNX2X_STOP_ON_ERROR
  734. if (unlikely(bp->panic))
  735. return;
  736. #endif
  737. txq = netdev_get_tx_queue(bp->dev, fp->index);
  738. hw_cons = le16_to_cpu(*fp->tx_cons_sb);
  739. sw_cons = fp->tx_pkt_cons;
  740. while (sw_cons != hw_cons) {
  741. u16 pkt_cons;
  742. pkt_cons = TX_BD(sw_cons);
  743. /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */
  744. DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n",
  745. hw_cons, sw_cons, pkt_cons);
  746. /* if (NEXT_TX_IDX(sw_cons) != hw_cons) {
  747. rmb();
  748. prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb);
  749. }
  750. */
  751. bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
  752. sw_cons++;
  753. done++;
  754. }
  755. fp->tx_pkt_cons = sw_cons;
  756. fp->tx_bd_cons = bd_cons;
  757. /* TBD need a thresh? */
  758. if (unlikely(netif_tx_queue_stopped(txq))) {
  759. __netif_tx_lock(txq, smp_processor_id());
  760. /* Need to make the tx_bd_cons update visible to start_xmit()
  761. * before checking for netif_tx_queue_stopped(). Without the
  762. * memory barrier, there is a small possibility that
  763. * start_xmit() will miss it and cause the queue to be stopped
  764. * forever.
  765. */
  766. smp_mb();
  767. if ((netif_tx_queue_stopped(txq)) &&
  768. (bp->state == BNX2X_STATE_OPEN) &&
  769. (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
  770. netif_tx_wake_queue(txq);
  771. __netif_tx_unlock(txq);
  772. }
  773. }
  774. static void bnx2x_sp_event(struct bnx2x_fastpath *fp,
  775. union eth_rx_cqe *rr_cqe)
  776. {
  777. struct bnx2x *bp = fp->bp;
  778. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  779. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  780. DP(BNX2X_MSG_SP,
  781. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  782. fp->index, cid, command, bp->state,
  783. rr_cqe->ramrod_cqe.ramrod_type);
  784. bp->spq_left++;
  785. if (fp->index) {
  786. switch (command | fp->state) {
  787. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP |
  788. BNX2X_FP_STATE_OPENING):
  789. DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n",
  790. cid);
  791. fp->state = BNX2X_FP_STATE_OPEN;
  792. break;
  793. case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING):
  794. DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n",
  795. cid);
  796. fp->state = BNX2X_FP_STATE_HALTED;
  797. break;
  798. default:
  799. BNX2X_ERR("unexpected MC reply (%d) "
  800. "fp->state is %x\n", command, fp->state);
  801. break;
  802. }
  803. mb(); /* force bnx2x_wait_ramrod() to see the change */
  804. return;
  805. }
  806. switch (command | bp->state) {
  807. case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT):
  808. DP(NETIF_MSG_IFUP, "got setup ramrod\n");
  809. bp->state = BNX2X_STATE_OPEN;
  810. break;
  811. case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT):
  812. DP(NETIF_MSG_IFDOWN, "got halt ramrod\n");
  813. bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE;
  814. fp->state = BNX2X_FP_STATE_HALTED;
  815. break;
  816. case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT):
  817. DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid);
  818. bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED;
  819. break;
  820. case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN):
  821. case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG):
  822. DP(NETIF_MSG_IFUP, "got set mac ramrod\n");
  823. bp->set_mac_pending = 0;
  824. break;
  825. case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT):
  826. DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n");
  827. break;
  828. default:
  829. BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n",
  830. command, bp->state);
  831. break;
  832. }
  833. mb(); /* force bnx2x_wait_ramrod() to see the change */
  834. }
  835. static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
  836. struct bnx2x_fastpath *fp, u16 index)
  837. {
  838. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  839. struct page *page = sw_buf->page;
  840. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  841. /* Skip "next page" elements */
  842. if (!page)
  843. return;
  844. pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping),
  845. SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
  846. __free_pages(page, PAGES_PER_SGE_SHIFT);
  847. sw_buf->page = NULL;
  848. sge->addr_hi = 0;
  849. sge->addr_lo = 0;
  850. }
  851. static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
  852. struct bnx2x_fastpath *fp, int last)
  853. {
  854. int i;
  855. for (i = 0; i < last; i++)
  856. bnx2x_free_rx_sge(bp, fp, i);
  857. }
  858. static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
  859. struct bnx2x_fastpath *fp, u16 index)
  860. {
  861. struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
  862. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  863. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  864. dma_addr_t mapping;
  865. if (unlikely(page == NULL))
  866. return -ENOMEM;
  867. mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE,
  868. PCI_DMA_FROMDEVICE);
  869. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  870. __free_pages(page, PAGES_PER_SGE_SHIFT);
  871. return -ENOMEM;
  872. }
  873. sw_buf->page = page;
  874. pci_unmap_addr_set(sw_buf, mapping, mapping);
  875. sge->addr_hi = cpu_to_le32(U64_HI(mapping));
  876. sge->addr_lo = cpu_to_le32(U64_LO(mapping));
  877. return 0;
  878. }
  879. static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
  880. struct bnx2x_fastpath *fp, u16 index)
  881. {
  882. struct sk_buff *skb;
  883. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
  884. struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
  885. dma_addr_t mapping;
  886. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  887. if (unlikely(skb == NULL))
  888. return -ENOMEM;
  889. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size,
  890. PCI_DMA_FROMDEVICE);
  891. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  892. dev_kfree_skb(skb);
  893. return -ENOMEM;
  894. }
  895. rx_buf->skb = skb;
  896. pci_unmap_addr_set(rx_buf, mapping, mapping);
  897. rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  898. rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  899. return 0;
  900. }
  901. /* note that we are not allocating a new skb,
  902. * we are just moving one from cons to prod
  903. * we are not creating a new mapping,
  904. * so there is no need to check for dma_mapping_error().
  905. */
  906. static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
  907. struct sk_buff *skb, u16 cons, u16 prod)
  908. {
  909. struct bnx2x *bp = fp->bp;
  910. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  911. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  912. struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
  913. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  914. pci_dma_sync_single_for_device(bp->pdev,
  915. pci_unmap_addr(cons_rx_buf, mapping),
  916. RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  917. prod_rx_buf->skb = cons_rx_buf->skb;
  918. pci_unmap_addr_set(prod_rx_buf, mapping,
  919. pci_unmap_addr(cons_rx_buf, mapping));
  920. *prod_bd = *cons_bd;
  921. }
  922. static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
  923. u16 idx)
  924. {
  925. u16 last_max = fp->last_max_sge;
  926. if (SUB_S16(idx, last_max) > 0)
  927. fp->last_max_sge = idx;
  928. }
  929. static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
  930. {
  931. int i, j;
  932. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  933. int idx = RX_SGE_CNT * i - 1;
  934. for (j = 0; j < 2; j++) {
  935. SGE_MASK_CLEAR_BIT(fp, idx);
  936. idx--;
  937. }
  938. }
  939. }
  940. static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
  941. struct eth_fast_path_rx_cqe *fp_cqe)
  942. {
  943. struct bnx2x *bp = fp->bp;
  944. u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
  945. le16_to_cpu(fp_cqe->len_on_bd)) >>
  946. SGE_PAGE_SHIFT;
  947. u16 last_max, last_elem, first_elem;
  948. u16 delta = 0;
  949. u16 i;
  950. if (!sge_len)
  951. return;
  952. /* First mark all used pages */
  953. for (i = 0; i < sge_len; i++)
  954. SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i])));
  955. DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
  956. sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
  957. /* Here we assume that the last SGE index is the biggest */
  958. prefetch((void *)(fp->sge_mask));
  959. bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
  960. last_max = RX_SGE(fp->last_max_sge);
  961. last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT;
  962. first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT;
  963. /* If ring is not full */
  964. if (last_elem + 1 != first_elem)
  965. last_elem++;
  966. /* Now update the prod */
  967. for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
  968. if (likely(fp->sge_mask[i]))
  969. break;
  970. fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK;
  971. delta += RX_SGE_MASK_ELEM_SZ;
  972. }
  973. if (delta > 0) {
  974. fp->rx_sge_prod += delta;
  975. /* clear page-end entries */
  976. bnx2x_clear_sge_mask_next_elems(fp);
  977. }
  978. DP(NETIF_MSG_RX_STATUS,
  979. "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
  980. fp->last_max_sge, fp->rx_sge_prod);
  981. }
  982. static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
  983. {
  984. /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
  985. memset(fp->sge_mask, 0xff,
  986. (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
  987. /* Clear the two last indices in the page to 1:
  988. these are the indices that correspond to the "next" element,
  989. hence will never be indicated and should be removed from
  990. the calculations. */
  991. bnx2x_clear_sge_mask_next_elems(fp);
  992. }
  993. static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
  994. struct sk_buff *skb, u16 cons, u16 prod)
  995. {
  996. struct bnx2x *bp = fp->bp;
  997. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  998. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  999. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  1000. dma_addr_t mapping;
  1001. /* move empty skb from pool to prod and map it */
  1002. prod_rx_buf->skb = fp->tpa_pool[queue].skb;
  1003. mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data,
  1004. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  1005. pci_unmap_addr_set(prod_rx_buf, mapping, mapping);
  1006. /* move partial skb from cons to pool (don't unmap yet) */
  1007. fp->tpa_pool[queue] = *cons_rx_buf;
  1008. /* mark bin state as start - print error if current state != stop */
  1009. if (fp->tpa_state[queue] != BNX2X_TPA_STOP)
  1010. BNX2X_ERR("start of bin not in stop [%d]\n", queue);
  1011. fp->tpa_state[queue] = BNX2X_TPA_START;
  1012. /* point prod_bd to new skb */
  1013. prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1014. prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1015. #ifdef BNX2X_STOP_ON_ERROR
  1016. fp->tpa_queue_used |= (1 << queue);
  1017. #ifdef __powerpc64__
  1018. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
  1019. #else
  1020. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
  1021. #endif
  1022. fp->tpa_queue_used);
  1023. #endif
  1024. }
  1025. static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1026. struct sk_buff *skb,
  1027. struct eth_fast_path_rx_cqe *fp_cqe,
  1028. u16 cqe_idx)
  1029. {
  1030. struct sw_rx_page *rx_pg, old_rx_pg;
  1031. u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd);
  1032. u32 i, frag_len, frag_size, pages;
  1033. int err;
  1034. int j;
  1035. frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd;
  1036. pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
  1037. /* This is needed in order to enable forwarding support */
  1038. if (frag_size)
  1039. skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE,
  1040. max(frag_size, (u32)len_on_bd));
  1041. #ifdef BNX2X_STOP_ON_ERROR
  1042. if (pages >
  1043. min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) {
  1044. BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
  1045. pages, cqe_idx);
  1046. BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n",
  1047. fp_cqe->pkt_len, len_on_bd);
  1048. bnx2x_panic();
  1049. return -EINVAL;
  1050. }
  1051. #endif
  1052. /* Run through the SGL and compose the fragmented skb */
  1053. for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
  1054. u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j]));
  1055. /* FW gives the indices of the SGE as if the ring is an array
  1056. (meaning that "next" element will consume 2 indices) */
  1057. frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
  1058. rx_pg = &fp->rx_page_ring[sge_idx];
  1059. old_rx_pg = *rx_pg;
  1060. /* If we fail to allocate a substitute page, we simply stop
  1061. where we are and drop the whole packet */
  1062. err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
  1063. if (unlikely(err)) {
  1064. fp->eth_q_stats.rx_skb_alloc_failed++;
  1065. return err;
  1066. }
  1067. /* Unmap the page as we r going to pass it to the stack */
  1068. pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping),
  1069. SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
  1070. /* Add one frag and update the appropriate fields in the skb */
  1071. skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
  1072. skb->data_len += frag_len;
  1073. skb->truesize += frag_len;
  1074. skb->len += frag_len;
  1075. frag_size -= frag_len;
  1076. }
  1077. return 0;
  1078. }
  1079. static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1080. u16 queue, int pad, int len, union eth_rx_cqe *cqe,
  1081. u16 cqe_idx)
  1082. {
  1083. struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue];
  1084. struct sk_buff *skb = rx_buf->skb;
  1085. /* alloc new skb */
  1086. struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  1087. /* Unmap skb in the pool anyway, as we are going to change
  1088. pool entry status to BNX2X_TPA_STOP even if new skb allocation
  1089. fails. */
  1090. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  1091. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  1092. if (likely(new_skb)) {
  1093. /* fix ip xsum and give it to the stack */
  1094. /* (no need to map the new skb) */
  1095. #ifdef BCM_VLAN
  1096. int is_vlan_cqe =
  1097. (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
  1098. PARSING_FLAGS_VLAN);
  1099. int is_not_hwaccel_vlan_cqe =
  1100. (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG)));
  1101. #endif
  1102. prefetch(skb);
  1103. prefetch(((char *)(skb)) + 128);
  1104. #ifdef BNX2X_STOP_ON_ERROR
  1105. if (pad + len > bp->rx_buf_size) {
  1106. BNX2X_ERR("skb_put is about to fail... "
  1107. "pad %d len %d rx_buf_size %d\n",
  1108. pad, len, bp->rx_buf_size);
  1109. bnx2x_panic();
  1110. return;
  1111. }
  1112. #endif
  1113. skb_reserve(skb, pad);
  1114. skb_put(skb, len);
  1115. skb->protocol = eth_type_trans(skb, bp->dev);
  1116. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1117. {
  1118. struct iphdr *iph;
  1119. iph = (struct iphdr *)skb->data;
  1120. #ifdef BCM_VLAN
  1121. /* If there is no Rx VLAN offloading -
  1122. take VLAN tag into an account */
  1123. if (unlikely(is_not_hwaccel_vlan_cqe))
  1124. iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN);
  1125. #endif
  1126. iph->check = 0;
  1127. iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
  1128. }
  1129. if (!bnx2x_fill_frag_skb(bp, fp, skb,
  1130. &cqe->fast_path_cqe, cqe_idx)) {
  1131. #ifdef BCM_VLAN
  1132. if ((bp->vlgrp != NULL) && is_vlan_cqe &&
  1133. (!is_not_hwaccel_vlan_cqe))
  1134. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1135. le16_to_cpu(cqe->fast_path_cqe.
  1136. vlan_tag));
  1137. else
  1138. #endif
  1139. netif_receive_skb(skb);
  1140. } else {
  1141. DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
  1142. " - dropping packet!\n");
  1143. dev_kfree_skb(skb);
  1144. }
  1145. /* put new skb in bin */
  1146. fp->tpa_pool[queue].skb = new_skb;
  1147. } else {
  1148. /* else drop the packet and keep the buffer in the bin */
  1149. DP(NETIF_MSG_RX_STATUS,
  1150. "Failed to allocate new skb - dropping packet!\n");
  1151. fp->eth_q_stats.rx_skb_alloc_failed++;
  1152. }
  1153. fp->tpa_state[queue] = BNX2X_TPA_STOP;
  1154. }
  1155. static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
  1156. struct bnx2x_fastpath *fp,
  1157. u16 bd_prod, u16 rx_comp_prod,
  1158. u16 rx_sge_prod)
  1159. {
  1160. struct ustorm_eth_rx_producers rx_prods = {0};
  1161. int i;
  1162. /* Update producers */
  1163. rx_prods.bd_prod = bd_prod;
  1164. rx_prods.cqe_prod = rx_comp_prod;
  1165. rx_prods.sge_prod = rx_sge_prod;
  1166. /*
  1167. * Make sure that the BD and SGE data is updated before updating the
  1168. * producers since FW might read the BD/SGE right after the producer
  1169. * is updated.
  1170. * This is only applicable for weak-ordered memory model archs such
  1171. * as IA-64. The following barrier is also mandatory since FW will
  1172. * assumes BDs must have buffers.
  1173. */
  1174. wmb();
  1175. for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
  1176. REG_WR(bp, BAR_USTRORM_INTMEM +
  1177. USTORM_RX_PRODS_OFFSET(BP_PORT(bp), fp->cl_id) + i*4,
  1178. ((u32 *)&rx_prods)[i]);
  1179. mmiowb(); /* keep prod updates ordered */
  1180. DP(NETIF_MSG_RX_STATUS,
  1181. "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
  1182. fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
  1183. }
  1184. static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
  1185. {
  1186. struct bnx2x *bp = fp->bp;
  1187. u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
  1188. u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
  1189. int rx_pkt = 0;
  1190. #ifdef BNX2X_STOP_ON_ERROR
  1191. if (unlikely(bp->panic))
  1192. return 0;
  1193. #endif
  1194. /* CQ "next element" is of the size of the regular element,
  1195. that's why it's ok here */
  1196. hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
  1197. if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  1198. hw_comp_cons++;
  1199. bd_cons = fp->rx_bd_cons;
  1200. bd_prod = fp->rx_bd_prod;
  1201. bd_prod_fw = bd_prod;
  1202. sw_comp_cons = fp->rx_comp_cons;
  1203. sw_comp_prod = fp->rx_comp_prod;
  1204. /* Memory barrier necessary as speculative reads of the rx
  1205. * buffer can be ahead of the index in the status block
  1206. */
  1207. rmb();
  1208. DP(NETIF_MSG_RX_STATUS,
  1209. "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
  1210. fp->index, hw_comp_cons, sw_comp_cons);
  1211. while (sw_comp_cons != hw_comp_cons) {
  1212. struct sw_rx_bd *rx_buf = NULL;
  1213. struct sk_buff *skb;
  1214. union eth_rx_cqe *cqe;
  1215. u8 cqe_fp_flags;
  1216. u16 len, pad;
  1217. comp_ring_cons = RCQ_BD(sw_comp_cons);
  1218. bd_prod = RX_BD(bd_prod);
  1219. bd_cons = RX_BD(bd_cons);
  1220. cqe = &fp->rx_comp_ring[comp_ring_cons];
  1221. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1222. DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
  1223. " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
  1224. cqe_fp_flags, cqe->fast_path_cqe.status_flags,
  1225. le32_to_cpu(cqe->fast_path_cqe.rss_hash_result),
  1226. le16_to_cpu(cqe->fast_path_cqe.vlan_tag),
  1227. le16_to_cpu(cqe->fast_path_cqe.pkt_len));
  1228. /* is this a slowpath msg? */
  1229. if (unlikely(CQE_TYPE(cqe_fp_flags))) {
  1230. bnx2x_sp_event(fp, cqe);
  1231. goto next_cqe;
  1232. /* this is an rx packet */
  1233. } else {
  1234. rx_buf = &fp->rx_buf_ring[bd_cons];
  1235. skb = rx_buf->skb;
  1236. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1237. pad = cqe->fast_path_cqe.placement_offset;
  1238. /* If CQE is marked both TPA_START and TPA_END
  1239. it is a non-TPA CQE */
  1240. if ((!fp->disable_tpa) &&
  1241. (TPA_TYPE(cqe_fp_flags) !=
  1242. (TPA_TYPE_START | TPA_TYPE_END))) {
  1243. u16 queue = cqe->fast_path_cqe.queue_index;
  1244. if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) {
  1245. DP(NETIF_MSG_RX_STATUS,
  1246. "calling tpa_start on queue %d\n",
  1247. queue);
  1248. bnx2x_tpa_start(fp, queue, skb,
  1249. bd_cons, bd_prod);
  1250. goto next_rx;
  1251. }
  1252. if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) {
  1253. DP(NETIF_MSG_RX_STATUS,
  1254. "calling tpa_stop on queue %d\n",
  1255. queue);
  1256. if (!BNX2X_RX_SUM_FIX(cqe))
  1257. BNX2X_ERR("STOP on none TCP "
  1258. "data\n");
  1259. /* This is a size of the linear data
  1260. on this skb */
  1261. len = le16_to_cpu(cqe->fast_path_cqe.
  1262. len_on_bd);
  1263. bnx2x_tpa_stop(bp, fp, queue, pad,
  1264. len, cqe, comp_ring_cons);
  1265. #ifdef BNX2X_STOP_ON_ERROR
  1266. if (bp->panic)
  1267. return -EINVAL;
  1268. #endif
  1269. bnx2x_update_sge_prod(fp,
  1270. &cqe->fast_path_cqe);
  1271. goto next_cqe;
  1272. }
  1273. }
  1274. pci_dma_sync_single_for_device(bp->pdev,
  1275. pci_unmap_addr(rx_buf, mapping),
  1276. pad + RX_COPY_THRESH,
  1277. PCI_DMA_FROMDEVICE);
  1278. prefetch(skb);
  1279. prefetch(((char *)(skb)) + 128);
  1280. /* is this an error packet? */
  1281. if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
  1282. DP(NETIF_MSG_RX_ERR,
  1283. "ERROR flags %x rx packet %u\n",
  1284. cqe_fp_flags, sw_comp_cons);
  1285. fp->eth_q_stats.rx_err_discard_pkt++;
  1286. goto reuse_rx;
  1287. }
  1288. /* Since we don't have a jumbo ring
  1289. * copy small packets if mtu > 1500
  1290. */
  1291. if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
  1292. (len <= RX_COPY_THRESH)) {
  1293. struct sk_buff *new_skb;
  1294. new_skb = netdev_alloc_skb(bp->dev,
  1295. len + pad);
  1296. if (new_skb == NULL) {
  1297. DP(NETIF_MSG_RX_ERR,
  1298. "ERROR packet dropped "
  1299. "because of alloc failure\n");
  1300. fp->eth_q_stats.rx_skb_alloc_failed++;
  1301. goto reuse_rx;
  1302. }
  1303. /* aligned copy */
  1304. skb_copy_from_linear_data_offset(skb, pad,
  1305. new_skb->data + pad, len);
  1306. skb_reserve(new_skb, pad);
  1307. skb_put(new_skb, len);
  1308. bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
  1309. skb = new_skb;
  1310. } else if (bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0) {
  1311. pci_unmap_single(bp->pdev,
  1312. pci_unmap_addr(rx_buf, mapping),
  1313. bp->rx_buf_size,
  1314. PCI_DMA_FROMDEVICE);
  1315. skb_reserve(skb, pad);
  1316. skb_put(skb, len);
  1317. } else {
  1318. DP(NETIF_MSG_RX_ERR,
  1319. "ERROR packet dropped because "
  1320. "of alloc failure\n");
  1321. fp->eth_q_stats.rx_skb_alloc_failed++;
  1322. reuse_rx:
  1323. bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
  1324. goto next_rx;
  1325. }
  1326. skb->protocol = eth_type_trans(skb, bp->dev);
  1327. skb->ip_summed = CHECKSUM_NONE;
  1328. if (bp->rx_csum) {
  1329. if (likely(BNX2X_RX_CSUM_OK(cqe)))
  1330. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1331. else
  1332. fp->eth_q_stats.hw_csum_err++;
  1333. }
  1334. }
  1335. skb_record_rx_queue(skb, fp->index);
  1336. #ifdef BCM_VLAN
  1337. if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) &&
  1338. (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
  1339. PARSING_FLAGS_VLAN))
  1340. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1341. le16_to_cpu(cqe->fast_path_cqe.vlan_tag));
  1342. else
  1343. #endif
  1344. netif_receive_skb(skb);
  1345. next_rx:
  1346. rx_buf->skb = NULL;
  1347. bd_cons = NEXT_RX_IDX(bd_cons);
  1348. bd_prod = NEXT_RX_IDX(bd_prod);
  1349. bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
  1350. rx_pkt++;
  1351. next_cqe:
  1352. sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
  1353. sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
  1354. if (rx_pkt == budget)
  1355. break;
  1356. } /* while */
  1357. fp->rx_bd_cons = bd_cons;
  1358. fp->rx_bd_prod = bd_prod_fw;
  1359. fp->rx_comp_cons = sw_comp_cons;
  1360. fp->rx_comp_prod = sw_comp_prod;
  1361. /* Update producers */
  1362. bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
  1363. fp->rx_sge_prod);
  1364. fp->rx_pkt += rx_pkt;
  1365. fp->rx_calls++;
  1366. return rx_pkt;
  1367. }
  1368. static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
  1369. {
  1370. struct bnx2x_fastpath *fp = fp_cookie;
  1371. struct bnx2x *bp = fp->bp;
  1372. int index = fp->index;
  1373. /* Return here if interrupt is disabled */
  1374. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1375. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  1376. return IRQ_HANDLED;
  1377. }
  1378. DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n",
  1379. index, fp->sb_id);
  1380. bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
  1381. #ifdef BNX2X_STOP_ON_ERROR
  1382. if (unlikely(bp->panic))
  1383. return IRQ_HANDLED;
  1384. #endif
  1385. prefetch(fp->rx_cons_sb);
  1386. prefetch(fp->tx_cons_sb);
  1387. prefetch(&fp->status_blk->c_status_block.status_block_index);
  1388. prefetch(&fp->status_blk->u_status_block.status_block_index);
  1389. napi_schedule(&bnx2x_fp(bp, index, napi));
  1390. return IRQ_HANDLED;
  1391. }
  1392. static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1393. {
  1394. struct bnx2x *bp = netdev_priv(dev_instance);
  1395. u16 status = bnx2x_ack_int(bp);
  1396. u16 mask;
  1397. /* Return here if interrupt is shared and it's not for us */
  1398. if (unlikely(status == 0)) {
  1399. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1400. return IRQ_NONE;
  1401. }
  1402. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1403. /* Return here if interrupt is disabled */
  1404. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1405. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  1406. return IRQ_HANDLED;
  1407. }
  1408. #ifdef BNX2X_STOP_ON_ERROR
  1409. if (unlikely(bp->panic))
  1410. return IRQ_HANDLED;
  1411. #endif
  1412. mask = 0x2 << bp->fp[0].sb_id;
  1413. if (status & mask) {
  1414. struct bnx2x_fastpath *fp = &bp->fp[0];
  1415. prefetch(fp->rx_cons_sb);
  1416. prefetch(fp->tx_cons_sb);
  1417. prefetch(&fp->status_blk->c_status_block.status_block_index);
  1418. prefetch(&fp->status_blk->u_status_block.status_block_index);
  1419. napi_schedule(&bnx2x_fp(bp, 0, napi));
  1420. status &= ~mask;
  1421. }
  1422. if (unlikely(status & 0x1)) {
  1423. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1424. status &= ~0x1;
  1425. if (!status)
  1426. return IRQ_HANDLED;
  1427. }
  1428. if (status)
  1429. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n",
  1430. status);
  1431. return IRQ_HANDLED;
  1432. }
  1433. /* end of fast path */
  1434. static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
  1435. /* Link */
  1436. /*
  1437. * General service functions
  1438. */
  1439. static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1440. {
  1441. u32 lock_status;
  1442. u32 resource_bit = (1 << resource);
  1443. int func = BP_FUNC(bp);
  1444. u32 hw_lock_control_reg;
  1445. int cnt;
  1446. /* Validating that the resource is within range */
  1447. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1448. DP(NETIF_MSG_HW,
  1449. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1450. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1451. return -EINVAL;
  1452. }
  1453. if (func <= 5) {
  1454. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1455. } else {
  1456. hw_lock_control_reg =
  1457. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1458. }
  1459. /* Validating that the resource is not already taken */
  1460. lock_status = REG_RD(bp, hw_lock_control_reg);
  1461. if (lock_status & resource_bit) {
  1462. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1463. lock_status, resource_bit);
  1464. return -EEXIST;
  1465. }
  1466. /* Try for 5 second every 5ms */
  1467. for (cnt = 0; cnt < 1000; cnt++) {
  1468. /* Try to acquire the lock */
  1469. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1470. lock_status = REG_RD(bp, hw_lock_control_reg);
  1471. if (lock_status & resource_bit)
  1472. return 0;
  1473. msleep(5);
  1474. }
  1475. DP(NETIF_MSG_HW, "Timeout\n");
  1476. return -EAGAIN;
  1477. }
  1478. static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1479. {
  1480. u32 lock_status;
  1481. u32 resource_bit = (1 << resource);
  1482. int func = BP_FUNC(bp);
  1483. u32 hw_lock_control_reg;
  1484. /* Validating that the resource is within range */
  1485. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1486. DP(NETIF_MSG_HW,
  1487. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1488. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1489. return -EINVAL;
  1490. }
  1491. if (func <= 5) {
  1492. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1493. } else {
  1494. hw_lock_control_reg =
  1495. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1496. }
  1497. /* Validating that the resource is currently taken */
  1498. lock_status = REG_RD(bp, hw_lock_control_reg);
  1499. if (!(lock_status & resource_bit)) {
  1500. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1501. lock_status, resource_bit);
  1502. return -EFAULT;
  1503. }
  1504. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1505. return 0;
  1506. }
  1507. /* HW Lock for shared dual port PHYs */
  1508. static void bnx2x_acquire_phy_lock(struct bnx2x *bp)
  1509. {
  1510. mutex_lock(&bp->port.phy_mutex);
  1511. if (bp->port.need_hw_lock)
  1512. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  1513. }
  1514. static void bnx2x_release_phy_lock(struct bnx2x *bp)
  1515. {
  1516. if (bp->port.need_hw_lock)
  1517. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  1518. mutex_unlock(&bp->port.phy_mutex);
  1519. }
  1520. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1521. {
  1522. /* The GPIO should be swapped if swap register is set and active */
  1523. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1524. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1525. int gpio_shift = gpio_num +
  1526. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1527. u32 gpio_mask = (1 << gpio_shift);
  1528. u32 gpio_reg;
  1529. int value;
  1530. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1531. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1532. return -EINVAL;
  1533. }
  1534. /* read GPIO value */
  1535. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1536. /* get the requested pin value */
  1537. if ((gpio_reg & gpio_mask) == gpio_mask)
  1538. value = 1;
  1539. else
  1540. value = 0;
  1541. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1542. return value;
  1543. }
  1544. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1545. {
  1546. /* The GPIO should be swapped if swap register is set and active */
  1547. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1548. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1549. int gpio_shift = gpio_num +
  1550. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1551. u32 gpio_mask = (1 << gpio_shift);
  1552. u32 gpio_reg;
  1553. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1554. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1555. return -EINVAL;
  1556. }
  1557. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1558. /* read GPIO and mask except the float bits */
  1559. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1560. switch (mode) {
  1561. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1562. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
  1563. gpio_num, gpio_shift);
  1564. /* clear FLOAT and set CLR */
  1565. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1566. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1567. break;
  1568. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1569. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
  1570. gpio_num, gpio_shift);
  1571. /* clear FLOAT and set SET */
  1572. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1573. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1574. break;
  1575. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1576. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
  1577. gpio_num, gpio_shift);
  1578. /* set FLOAT */
  1579. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1580. break;
  1581. default:
  1582. break;
  1583. }
  1584. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1585. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1586. return 0;
  1587. }
  1588. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1589. {
  1590. /* The GPIO should be swapped if swap register is set and active */
  1591. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1592. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1593. int gpio_shift = gpio_num +
  1594. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1595. u32 gpio_mask = (1 << gpio_shift);
  1596. u32 gpio_reg;
  1597. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1598. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1599. return -EINVAL;
  1600. }
  1601. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1602. /* read GPIO int */
  1603. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1604. switch (mode) {
  1605. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1606. DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
  1607. "output low\n", gpio_num, gpio_shift);
  1608. /* clear SET and set CLR */
  1609. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1610. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1611. break;
  1612. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1613. DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
  1614. "output high\n", gpio_num, gpio_shift);
  1615. /* clear CLR and set SET */
  1616. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1617. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1618. break;
  1619. default:
  1620. break;
  1621. }
  1622. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1623. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1624. return 0;
  1625. }
  1626. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1627. {
  1628. u32 spio_mask = (1 << spio_num);
  1629. u32 spio_reg;
  1630. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1631. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1632. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1633. return -EINVAL;
  1634. }
  1635. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1636. /* read SPIO and mask except the float bits */
  1637. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1638. switch (mode) {
  1639. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1640. DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
  1641. /* clear FLOAT and set CLR */
  1642. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1643. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1644. break;
  1645. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1646. DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
  1647. /* clear FLOAT and set SET */
  1648. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1649. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1650. break;
  1651. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1652. DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
  1653. /* set FLOAT */
  1654. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1655. break;
  1656. default:
  1657. break;
  1658. }
  1659. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1660. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1661. return 0;
  1662. }
  1663. static void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1664. {
  1665. switch (bp->link_vars.ieee_fc &
  1666. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1667. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1668. bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
  1669. ADVERTISED_Pause);
  1670. break;
  1671. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1672. bp->port.advertising |= (ADVERTISED_Asym_Pause |
  1673. ADVERTISED_Pause);
  1674. break;
  1675. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1676. bp->port.advertising |= ADVERTISED_Asym_Pause;
  1677. break;
  1678. default:
  1679. bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
  1680. ADVERTISED_Pause);
  1681. break;
  1682. }
  1683. }
  1684. static void bnx2x_link_report(struct bnx2x *bp)
  1685. {
  1686. if (bp->link_vars.link_up) {
  1687. if (bp->state == BNX2X_STATE_OPEN)
  1688. netif_carrier_on(bp->dev);
  1689. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  1690. printk("%d Mbps ", bp->link_vars.line_speed);
  1691. if (bp->link_vars.duplex == DUPLEX_FULL)
  1692. printk("full duplex");
  1693. else
  1694. printk("half duplex");
  1695. if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) {
  1696. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) {
  1697. printk(", receive ");
  1698. if (bp->link_vars.flow_ctrl &
  1699. BNX2X_FLOW_CTRL_TX)
  1700. printk("& transmit ");
  1701. } else {
  1702. printk(", transmit ");
  1703. }
  1704. printk("flow control ON");
  1705. }
  1706. printk("\n");
  1707. } else { /* link_down */
  1708. netif_carrier_off(bp->dev);
  1709. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  1710. }
  1711. }
  1712. static u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1713. {
  1714. if (!BP_NOMCP(bp)) {
  1715. u8 rc;
  1716. /* Initialize link parameters structure variables */
  1717. /* It is recommended to turn off RX FC for jumbo frames
  1718. for better performance */
  1719. if (IS_E1HMF(bp))
  1720. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1721. else if (bp->dev->mtu > 5000)
  1722. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1723. else
  1724. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1725. bnx2x_acquire_phy_lock(bp);
  1726. if (load_mode == LOAD_DIAG)
  1727. bp->link_params.loopback_mode = LOOPBACK_XGXS_10;
  1728. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1729. bnx2x_release_phy_lock(bp);
  1730. bnx2x_calc_fc_adv(bp);
  1731. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1732. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1733. bnx2x_link_report(bp);
  1734. }
  1735. return rc;
  1736. }
  1737. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1738. return -EINVAL;
  1739. }
  1740. static void bnx2x_link_set(struct bnx2x *bp)
  1741. {
  1742. if (!BP_NOMCP(bp)) {
  1743. bnx2x_acquire_phy_lock(bp);
  1744. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1745. bnx2x_release_phy_lock(bp);
  1746. bnx2x_calc_fc_adv(bp);
  1747. } else
  1748. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1749. }
  1750. static void bnx2x__link_reset(struct bnx2x *bp)
  1751. {
  1752. if (!BP_NOMCP(bp)) {
  1753. bnx2x_acquire_phy_lock(bp);
  1754. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1755. bnx2x_release_phy_lock(bp);
  1756. } else
  1757. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1758. }
  1759. static u8 bnx2x_link_test(struct bnx2x *bp)
  1760. {
  1761. u8 rc;
  1762. bnx2x_acquire_phy_lock(bp);
  1763. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars);
  1764. bnx2x_release_phy_lock(bp);
  1765. return rc;
  1766. }
  1767. static void bnx2x_init_port_minmax(struct bnx2x *bp)
  1768. {
  1769. u32 r_param = bp->link_vars.line_speed / 8;
  1770. u32 fair_periodic_timeout_usec;
  1771. u32 t_fair;
  1772. memset(&(bp->cmng.rs_vars), 0,
  1773. sizeof(struct rate_shaping_vars_per_port));
  1774. memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
  1775. /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
  1776. bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
  1777. /* this is the threshold below which no timer arming will occur
  1778. 1.25 coefficient is for the threshold to be a little bigger
  1779. than the real time, to compensate for timer in-accuracy */
  1780. bp->cmng.rs_vars.rs_threshold =
  1781. (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
  1782. /* resolution of fairness timer */
  1783. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  1784. /* for 10G it is 1000usec. for 1G it is 10000usec. */
  1785. t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
  1786. /* this is the threshold below which we won't arm the timer anymore */
  1787. bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
  1788. /* we multiply by 1e3/8 to get bytes/msec.
  1789. We don't want the credits to pass a credit
  1790. of the t_fair*FAIR_MEM (algorithm resolution) */
  1791. bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
  1792. /* since each tick is 4 usec */
  1793. bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
  1794. }
  1795. static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func)
  1796. {
  1797. struct rate_shaping_vars_per_vn m_rs_vn;
  1798. struct fairness_vars_per_vn m_fair_vn;
  1799. u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  1800. u16 vn_min_rate, vn_max_rate;
  1801. int i;
  1802. /* If function is hidden - set min and max to zeroes */
  1803. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
  1804. vn_min_rate = 0;
  1805. vn_max_rate = 0;
  1806. } else {
  1807. vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1808. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1809. /* If fairness is enabled (not all min rates are zeroes) and
  1810. if current min rate is zero - set it to 1.
  1811. This is a requirement of the algorithm. */
  1812. if (bp->vn_weight_sum && (vn_min_rate == 0))
  1813. vn_min_rate = DEF_MIN_RATE;
  1814. vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
  1815. FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
  1816. }
  1817. DP(NETIF_MSG_IFUP,
  1818. "func %d: vn_min_rate=%d vn_max_rate=%d vn_weight_sum=%d\n",
  1819. func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
  1820. memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
  1821. memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
  1822. /* global vn counter - maximal Mbps for this vn */
  1823. m_rs_vn.vn_counter.rate = vn_max_rate;
  1824. /* quota - number of bytes transmitted in this period */
  1825. m_rs_vn.vn_counter.quota =
  1826. (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
  1827. if (bp->vn_weight_sum) {
  1828. /* credit for each period of the fairness algorithm:
  1829. number of bytes in T_FAIR (the vn share the port rate).
  1830. vn_weight_sum should not be larger than 10000, thus
  1831. T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
  1832. than zero */
  1833. m_fair_vn.vn_credit_delta =
  1834. max((u32)(vn_min_rate * (T_FAIR_COEF /
  1835. (8 * bp->vn_weight_sum))),
  1836. (u32)(bp->cmng.fair_vars.fair_threshold * 2));
  1837. DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n",
  1838. m_fair_vn.vn_credit_delta);
  1839. }
  1840. /* Store it to internal memory */
  1841. for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
  1842. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1843. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
  1844. ((u32 *)(&m_rs_vn))[i]);
  1845. for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
  1846. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1847. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
  1848. ((u32 *)(&m_fair_vn))[i]);
  1849. }
  1850. /* This function is called upon link interrupt */
  1851. static void bnx2x_link_attn(struct bnx2x *bp)
  1852. {
  1853. /* Make sure that we are synced with the current statistics */
  1854. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1855. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  1856. if (bp->link_vars.link_up) {
  1857. /* dropless flow control */
  1858. if (CHIP_IS_E1H(bp)) {
  1859. int port = BP_PORT(bp);
  1860. u32 pause_enabled = 0;
  1861. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  1862. pause_enabled = 1;
  1863. REG_WR(bp, BAR_USTRORM_INTMEM +
  1864. USTORM_PAUSE_ENABLED_OFFSET(port),
  1865. pause_enabled);
  1866. }
  1867. if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
  1868. struct host_port_stats *pstats;
  1869. pstats = bnx2x_sp(bp, port_stats);
  1870. /* reset old bmac stats */
  1871. memset(&(pstats->mac_stx[0]), 0,
  1872. sizeof(struct mac_stx));
  1873. }
  1874. if ((bp->state == BNX2X_STATE_OPEN) ||
  1875. (bp->state == BNX2X_STATE_DISABLED))
  1876. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1877. }
  1878. /* indicate link status */
  1879. bnx2x_link_report(bp);
  1880. if (IS_E1HMF(bp)) {
  1881. int port = BP_PORT(bp);
  1882. int func;
  1883. int vn;
  1884. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  1885. if (vn == BP_E1HVN(bp))
  1886. continue;
  1887. func = ((vn << 1) | port);
  1888. /* Set the attention towards other drivers
  1889. on the same port */
  1890. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  1891. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  1892. }
  1893. if (bp->link_vars.link_up) {
  1894. int i;
  1895. /* Init rate shaping and fairness contexts */
  1896. bnx2x_init_port_minmax(bp);
  1897. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  1898. bnx2x_init_vn_minmax(bp, 2*vn + port);
  1899. /* Store it to internal memory */
  1900. for (i = 0;
  1901. i < sizeof(struct cmng_struct_per_port) / 4; i++)
  1902. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1903. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
  1904. ((u32 *)(&bp->cmng))[i]);
  1905. }
  1906. }
  1907. }
  1908. static void bnx2x__link_status_update(struct bnx2x *bp)
  1909. {
  1910. if (bp->state != BNX2X_STATE_OPEN)
  1911. return;
  1912. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  1913. if (bp->link_vars.link_up)
  1914. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1915. else
  1916. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  1917. /* indicate link status */
  1918. bnx2x_link_report(bp);
  1919. }
  1920. static void bnx2x_pmf_update(struct bnx2x *bp)
  1921. {
  1922. int port = BP_PORT(bp);
  1923. u32 val;
  1924. bp->port.pmf = 1;
  1925. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  1926. /* enable nig attention */
  1927. val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
  1928. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1929. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1930. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  1931. }
  1932. /* end of Link */
  1933. /* slow path */
  1934. /*
  1935. * General service functions
  1936. */
  1937. /* the slow path queue is odd since completions arrive on the fastpath ring */
  1938. static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  1939. u32 data_hi, u32 data_lo, int common)
  1940. {
  1941. int func = BP_FUNC(bp);
  1942. DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
  1943. "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n",
  1944. (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) +
  1945. (void *)bp->spq_prod_bd - (void *)bp->spq), command,
  1946. HW_CID(bp, cid), data_hi, data_lo, bp->spq_left);
  1947. #ifdef BNX2X_STOP_ON_ERROR
  1948. if (unlikely(bp->panic))
  1949. return -EIO;
  1950. #endif
  1951. spin_lock_bh(&bp->spq_lock);
  1952. if (!bp->spq_left) {
  1953. BNX2X_ERR("BUG! SPQ ring full!\n");
  1954. spin_unlock_bh(&bp->spq_lock);
  1955. bnx2x_panic();
  1956. return -EBUSY;
  1957. }
  1958. /* CID needs port number to be encoded int it */
  1959. bp->spq_prod_bd->hdr.conn_and_cmd_data =
  1960. cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) |
  1961. HW_CID(bp, cid)));
  1962. bp->spq_prod_bd->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE);
  1963. if (common)
  1964. bp->spq_prod_bd->hdr.type |=
  1965. cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT));
  1966. bp->spq_prod_bd->data.mac_config_addr.hi = cpu_to_le32(data_hi);
  1967. bp->spq_prod_bd->data.mac_config_addr.lo = cpu_to_le32(data_lo);
  1968. bp->spq_left--;
  1969. if (bp->spq_prod_bd == bp->spq_last_bd) {
  1970. bp->spq_prod_bd = bp->spq;
  1971. bp->spq_prod_idx = 0;
  1972. DP(NETIF_MSG_TIMER, "end of spq\n");
  1973. } else {
  1974. bp->spq_prod_bd++;
  1975. bp->spq_prod_idx++;
  1976. }
  1977. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  1978. bp->spq_prod_idx);
  1979. spin_unlock_bh(&bp->spq_lock);
  1980. return 0;
  1981. }
  1982. /* acquire split MCP access lock register */
  1983. static int bnx2x_acquire_alr(struct bnx2x *bp)
  1984. {
  1985. u32 i, j, val;
  1986. int rc = 0;
  1987. might_sleep();
  1988. i = 100;
  1989. for (j = 0; j < i*10; j++) {
  1990. val = (1UL << 31);
  1991. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  1992. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  1993. if (val & (1L << 31))
  1994. break;
  1995. msleep(5);
  1996. }
  1997. if (!(val & (1L << 31))) {
  1998. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  1999. rc = -EBUSY;
  2000. }
  2001. return rc;
  2002. }
  2003. /* release split MCP access lock register */
  2004. static void bnx2x_release_alr(struct bnx2x *bp)
  2005. {
  2006. u32 val = 0;
  2007. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2008. }
  2009. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2010. {
  2011. struct host_def_status_block *def_sb = bp->def_status_blk;
  2012. u16 rc = 0;
  2013. barrier(); /* status block is written to by the chip */
  2014. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2015. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2016. rc |= 1;
  2017. }
  2018. if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) {
  2019. bp->def_c_idx = def_sb->c_def_status_block.status_block_index;
  2020. rc |= 2;
  2021. }
  2022. if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) {
  2023. bp->def_u_idx = def_sb->u_def_status_block.status_block_index;
  2024. rc |= 4;
  2025. }
  2026. if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) {
  2027. bp->def_x_idx = def_sb->x_def_status_block.status_block_index;
  2028. rc |= 8;
  2029. }
  2030. if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) {
  2031. bp->def_t_idx = def_sb->t_def_status_block.status_block_index;
  2032. rc |= 16;
  2033. }
  2034. return rc;
  2035. }
  2036. /*
  2037. * slow path service functions
  2038. */
  2039. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2040. {
  2041. int port = BP_PORT(bp);
  2042. u32 hc_addr = (HC_REG_COMMAND_REG + port*32 +
  2043. COMMAND_REG_ATTN_BITS_SET);
  2044. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2045. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2046. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2047. NIG_REG_MASK_INTERRUPT_PORT0;
  2048. u32 aeu_mask;
  2049. u32 nig_mask = 0;
  2050. if (bp->attn_state & asserted)
  2051. BNX2X_ERR("IGU ERROR\n");
  2052. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2053. aeu_mask = REG_RD(bp, aeu_addr);
  2054. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2055. aeu_mask, asserted);
  2056. aeu_mask &= ~(asserted & 0xff);
  2057. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2058. REG_WR(bp, aeu_addr, aeu_mask);
  2059. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2060. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2061. bp->attn_state |= asserted;
  2062. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2063. if (asserted & ATTN_HARD_WIRED_MASK) {
  2064. if (asserted & ATTN_NIG_FOR_FUNC) {
  2065. bnx2x_acquire_phy_lock(bp);
  2066. /* save nig interrupt mask */
  2067. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2068. REG_WR(bp, nig_int_mask_addr, 0);
  2069. bnx2x_link_attn(bp);
  2070. /* handle unicore attn? */
  2071. }
  2072. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2073. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2074. if (asserted & GPIO_2_FUNC)
  2075. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2076. if (asserted & GPIO_3_FUNC)
  2077. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2078. if (asserted & GPIO_4_FUNC)
  2079. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2080. if (port == 0) {
  2081. if (asserted & ATTN_GENERAL_ATTN_1) {
  2082. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2083. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2084. }
  2085. if (asserted & ATTN_GENERAL_ATTN_2) {
  2086. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2087. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2088. }
  2089. if (asserted & ATTN_GENERAL_ATTN_3) {
  2090. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2091. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2092. }
  2093. } else {
  2094. if (asserted & ATTN_GENERAL_ATTN_4) {
  2095. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2096. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2097. }
  2098. if (asserted & ATTN_GENERAL_ATTN_5) {
  2099. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2100. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2101. }
  2102. if (asserted & ATTN_GENERAL_ATTN_6) {
  2103. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2104. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2105. }
  2106. }
  2107. } /* if hardwired */
  2108. DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
  2109. asserted, hc_addr);
  2110. REG_WR(bp, hc_addr, asserted);
  2111. /* now set back the mask */
  2112. if (asserted & ATTN_NIG_FOR_FUNC) {
  2113. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2114. bnx2x_release_phy_lock(bp);
  2115. }
  2116. }
  2117. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2118. {
  2119. int port = BP_PORT(bp);
  2120. int reg_offset;
  2121. u32 val;
  2122. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2123. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2124. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2125. val = REG_RD(bp, reg_offset);
  2126. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2127. REG_WR(bp, reg_offset, val);
  2128. BNX2X_ERR("SPIO5 hw attention\n");
  2129. switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
  2130. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  2131. /* Fan failure attention */
  2132. /* The PHY reset is controlled by GPIO 1 */
  2133. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  2134. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  2135. /* Low power mode is controlled by GPIO 2 */
  2136. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  2137. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  2138. /* mark the failure */
  2139. bp->link_params.ext_phy_config &=
  2140. ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2141. bp->link_params.ext_phy_config |=
  2142. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2143. SHMEM_WR(bp,
  2144. dev_info.port_hw_config[port].
  2145. external_phy_config,
  2146. bp->link_params.ext_phy_config);
  2147. /* log the failure */
  2148. printk(KERN_ERR PFX "Fan Failure on Network"
  2149. " Controller %s has caused the driver to"
  2150. " shutdown the card to prevent permanent"
  2151. " damage. Please contact Dell Support for"
  2152. " assistance\n", bp->dev->name);
  2153. break;
  2154. default:
  2155. break;
  2156. }
  2157. }
  2158. if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
  2159. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
  2160. bnx2x_acquire_phy_lock(bp);
  2161. bnx2x_handle_module_detect_int(&bp->link_params);
  2162. bnx2x_release_phy_lock(bp);
  2163. }
  2164. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2165. val = REG_RD(bp, reg_offset);
  2166. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2167. REG_WR(bp, reg_offset, val);
  2168. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2169. (attn & HW_INTERRUT_ASSERT_SET_0));
  2170. bnx2x_panic();
  2171. }
  2172. }
  2173. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2174. {
  2175. u32 val;
  2176. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2177. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2178. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2179. /* DORQ discard attention */
  2180. if (val & 0x2)
  2181. BNX2X_ERR("FATAL error from DORQ\n");
  2182. }
  2183. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2184. int port = BP_PORT(bp);
  2185. int reg_offset;
  2186. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2187. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2188. val = REG_RD(bp, reg_offset);
  2189. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2190. REG_WR(bp, reg_offset, val);
  2191. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2192. (attn & HW_INTERRUT_ASSERT_SET_1));
  2193. bnx2x_panic();
  2194. }
  2195. }
  2196. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2197. {
  2198. u32 val;
  2199. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2200. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2201. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2202. /* CFC error attention */
  2203. if (val & 0x2)
  2204. BNX2X_ERR("FATAL error from CFC\n");
  2205. }
  2206. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2207. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2208. BNX2X_ERR("PXP hw attention 0x%x\n", val);
  2209. /* RQ_USDMDP_FIFO_OVERFLOW */
  2210. if (val & 0x18000)
  2211. BNX2X_ERR("FATAL error from PXP\n");
  2212. }
  2213. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2214. int port = BP_PORT(bp);
  2215. int reg_offset;
  2216. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2217. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2218. val = REG_RD(bp, reg_offset);
  2219. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2220. REG_WR(bp, reg_offset, val);
  2221. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2222. (attn & HW_INTERRUT_ASSERT_SET_2));
  2223. bnx2x_panic();
  2224. }
  2225. }
  2226. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2227. {
  2228. u32 val;
  2229. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2230. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2231. int func = BP_FUNC(bp);
  2232. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2233. bnx2x__link_status_update(bp);
  2234. if (SHMEM_RD(bp, func_mb[func].drv_status) &
  2235. DRV_STATUS_PMF)
  2236. bnx2x_pmf_update(bp);
  2237. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  2238. BNX2X_ERR("MC assert!\n");
  2239. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  2240. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  2241. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  2242. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  2243. bnx2x_panic();
  2244. } else if (attn & BNX2X_MCP_ASSERT) {
  2245. BNX2X_ERR("MCP assert!\n");
  2246. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  2247. bnx2x_fw_dump(bp);
  2248. } else
  2249. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  2250. }
  2251. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  2252. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  2253. if (attn & BNX2X_GRC_TIMEOUT) {
  2254. val = CHIP_IS_E1H(bp) ?
  2255. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0;
  2256. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  2257. }
  2258. if (attn & BNX2X_GRC_RSV) {
  2259. val = CHIP_IS_E1H(bp) ?
  2260. REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0;
  2261. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  2262. }
  2263. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  2264. }
  2265. }
  2266. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  2267. {
  2268. struct attn_route attn;
  2269. struct attn_route group_mask;
  2270. int port = BP_PORT(bp);
  2271. int index;
  2272. u32 reg_addr;
  2273. u32 val;
  2274. u32 aeu_mask;
  2275. /* need to take HW lock because MCP or other port might also
  2276. try to handle this event */
  2277. bnx2x_acquire_alr(bp);
  2278. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  2279. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  2280. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  2281. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  2282. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n",
  2283. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]);
  2284. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  2285. if (deasserted & (1 << index)) {
  2286. group_mask = bp->attn_group[index];
  2287. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n",
  2288. index, group_mask.sig[0], group_mask.sig[1],
  2289. group_mask.sig[2], group_mask.sig[3]);
  2290. bnx2x_attn_int_deasserted3(bp,
  2291. attn.sig[3] & group_mask.sig[3]);
  2292. bnx2x_attn_int_deasserted1(bp,
  2293. attn.sig[1] & group_mask.sig[1]);
  2294. bnx2x_attn_int_deasserted2(bp,
  2295. attn.sig[2] & group_mask.sig[2]);
  2296. bnx2x_attn_int_deasserted0(bp,
  2297. attn.sig[0] & group_mask.sig[0]);
  2298. if ((attn.sig[0] & group_mask.sig[0] &
  2299. HW_PRTY_ASSERT_SET_0) ||
  2300. (attn.sig[1] & group_mask.sig[1] &
  2301. HW_PRTY_ASSERT_SET_1) ||
  2302. (attn.sig[2] & group_mask.sig[2] &
  2303. HW_PRTY_ASSERT_SET_2))
  2304. BNX2X_ERR("FATAL HW block parity attention\n");
  2305. }
  2306. }
  2307. bnx2x_release_alr(bp);
  2308. reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR);
  2309. val = ~deasserted;
  2310. DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
  2311. val, reg_addr);
  2312. REG_WR(bp, reg_addr, val);
  2313. if (~bp->attn_state & deasserted)
  2314. BNX2X_ERR("IGU ERROR\n");
  2315. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2316. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2317. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2318. aeu_mask = REG_RD(bp, reg_addr);
  2319. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  2320. aeu_mask, deasserted);
  2321. aeu_mask |= (deasserted & 0xff);
  2322. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2323. REG_WR(bp, reg_addr, aeu_mask);
  2324. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2325. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2326. bp->attn_state &= ~deasserted;
  2327. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2328. }
  2329. static void bnx2x_attn_int(struct bnx2x *bp)
  2330. {
  2331. /* read local copy of bits */
  2332. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  2333. attn_bits);
  2334. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  2335. attn_bits_ack);
  2336. u32 attn_state = bp->attn_state;
  2337. /* look for changed bits */
  2338. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  2339. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  2340. DP(NETIF_MSG_HW,
  2341. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  2342. attn_bits, attn_ack, asserted, deasserted);
  2343. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  2344. BNX2X_ERR("BAD attention state\n");
  2345. /* handle bits that were raised */
  2346. if (asserted)
  2347. bnx2x_attn_int_asserted(bp, asserted);
  2348. if (deasserted)
  2349. bnx2x_attn_int_deasserted(bp, deasserted);
  2350. }
  2351. static void bnx2x_sp_task(struct work_struct *work)
  2352. {
  2353. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  2354. u16 status;
  2355. /* Return here if interrupt is disabled */
  2356. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  2357. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  2358. return;
  2359. }
  2360. status = bnx2x_update_dsb_idx(bp);
  2361. /* if (status == 0) */
  2362. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  2363. DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status);
  2364. /* HW attentions */
  2365. if (status & 0x1)
  2366. bnx2x_attn_int(bp);
  2367. bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx),
  2368. IGU_INT_NOP, 1);
  2369. bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx),
  2370. IGU_INT_NOP, 1);
  2371. bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx),
  2372. IGU_INT_NOP, 1);
  2373. bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx),
  2374. IGU_INT_NOP, 1);
  2375. bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx),
  2376. IGU_INT_ENABLE, 1);
  2377. }
  2378. static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  2379. {
  2380. struct net_device *dev = dev_instance;
  2381. struct bnx2x *bp = netdev_priv(dev);
  2382. /* Return here if interrupt is disabled */
  2383. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  2384. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  2385. return IRQ_HANDLED;
  2386. }
  2387. bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0);
  2388. #ifdef BNX2X_STOP_ON_ERROR
  2389. if (unlikely(bp->panic))
  2390. return IRQ_HANDLED;
  2391. #endif
  2392. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  2393. return IRQ_HANDLED;
  2394. }
  2395. /* end of slow path */
  2396. /* Statistics */
  2397. /****************************************************************************
  2398. * Macros
  2399. ****************************************************************************/
  2400. /* sum[hi:lo] += add[hi:lo] */
  2401. #define ADD_64(s_hi, a_hi, s_lo, a_lo) \
  2402. do { \
  2403. s_lo += a_lo; \
  2404. s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
  2405. } while (0)
  2406. /* difference = minuend - subtrahend */
  2407. #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
  2408. do { \
  2409. if (m_lo < s_lo) { \
  2410. /* underflow */ \
  2411. d_hi = m_hi - s_hi; \
  2412. if (d_hi > 0) { \
  2413. /* we can 'loan' 1 */ \
  2414. d_hi--; \
  2415. d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
  2416. } else { \
  2417. /* m_hi <= s_hi */ \
  2418. d_hi = 0; \
  2419. d_lo = 0; \
  2420. } \
  2421. } else { \
  2422. /* m_lo >= s_lo */ \
  2423. if (m_hi < s_hi) { \
  2424. d_hi = 0; \
  2425. d_lo = 0; \
  2426. } else { \
  2427. /* m_hi >= s_hi */ \
  2428. d_hi = m_hi - s_hi; \
  2429. d_lo = m_lo - s_lo; \
  2430. } \
  2431. } \
  2432. } while (0)
  2433. #define UPDATE_STAT64(s, t) \
  2434. do { \
  2435. DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
  2436. diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
  2437. pstats->mac_stx[0].t##_hi = new->s##_hi; \
  2438. pstats->mac_stx[0].t##_lo = new->s##_lo; \
  2439. ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
  2440. pstats->mac_stx[1].t##_lo, diff.lo); \
  2441. } while (0)
  2442. #define UPDATE_STAT64_NIG(s, t) \
  2443. do { \
  2444. DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
  2445. diff.lo, new->s##_lo, old->s##_lo); \
  2446. ADD_64(estats->t##_hi, diff.hi, \
  2447. estats->t##_lo, diff.lo); \
  2448. } while (0)
  2449. /* sum[hi:lo] += add */
  2450. #define ADD_EXTEND_64(s_hi, s_lo, a) \
  2451. do { \
  2452. s_lo += a; \
  2453. s_hi += (s_lo < a) ? 1 : 0; \
  2454. } while (0)
  2455. #define UPDATE_EXTEND_STAT(s) \
  2456. do { \
  2457. ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
  2458. pstats->mac_stx[1].s##_lo, \
  2459. new->s); \
  2460. } while (0)
  2461. #define UPDATE_EXTEND_TSTAT(s, t) \
  2462. do { \
  2463. diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
  2464. old_tclient->s = tclient->s; \
  2465. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2466. } while (0)
  2467. #define UPDATE_EXTEND_USTAT(s, t) \
  2468. do { \
  2469. diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
  2470. old_uclient->s = uclient->s; \
  2471. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2472. } while (0)
  2473. #define UPDATE_EXTEND_XSTAT(s, t) \
  2474. do { \
  2475. diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
  2476. old_xclient->s = xclient->s; \
  2477. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2478. } while (0)
  2479. /* minuend -= subtrahend */
  2480. #define SUB_64(m_hi, s_hi, m_lo, s_lo) \
  2481. do { \
  2482. DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
  2483. } while (0)
  2484. /* minuend[hi:lo] -= subtrahend */
  2485. #define SUB_EXTEND_64(m_hi, m_lo, s) \
  2486. do { \
  2487. SUB_64(m_hi, 0, m_lo, s); \
  2488. } while (0)
  2489. #define SUB_EXTEND_USTAT(s, t) \
  2490. do { \
  2491. diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
  2492. SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2493. } while (0)
  2494. /*
  2495. * General service functions
  2496. */
  2497. static inline long bnx2x_hilo(u32 *hiref)
  2498. {
  2499. u32 lo = *(hiref + 1);
  2500. #if (BITS_PER_LONG == 64)
  2501. u32 hi = *hiref;
  2502. return HILO_U64(hi, lo);
  2503. #else
  2504. return lo;
  2505. #endif
  2506. }
  2507. /*
  2508. * Init service functions
  2509. */
  2510. static void bnx2x_storm_stats_post(struct bnx2x *bp)
  2511. {
  2512. if (!bp->stats_pending) {
  2513. struct eth_query_ramrod_data ramrod_data = {0};
  2514. int i, rc;
  2515. ramrod_data.drv_counter = bp->stats_counter++;
  2516. ramrod_data.collect_port = bp->port.pmf ? 1 : 0;
  2517. for_each_queue(bp, i)
  2518. ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id);
  2519. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0,
  2520. ((u32 *)&ramrod_data)[1],
  2521. ((u32 *)&ramrod_data)[0], 0);
  2522. if (rc == 0) {
  2523. /* stats ramrod has it's own slot on the spq */
  2524. bp->spq_left++;
  2525. bp->stats_pending = 1;
  2526. }
  2527. }
  2528. }
  2529. static void bnx2x_stats_init(struct bnx2x *bp)
  2530. {
  2531. int port = BP_PORT(bp);
  2532. int i;
  2533. bp->stats_pending = 0;
  2534. bp->executer_idx = 0;
  2535. bp->stats_counter = 0;
  2536. /* port stats */
  2537. if (!BP_NOMCP(bp))
  2538. bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
  2539. else
  2540. bp->port.port_stx = 0;
  2541. DP(BNX2X_MSG_STATS, "port_stx 0x%x\n", bp->port.port_stx);
  2542. memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
  2543. bp->port.old_nig_stats.brb_discard =
  2544. REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
  2545. bp->port.old_nig_stats.brb_truncate =
  2546. REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
  2547. REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
  2548. &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2);
  2549. REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
  2550. &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2);
  2551. /* function stats */
  2552. for_each_queue(bp, i) {
  2553. struct bnx2x_fastpath *fp = &bp->fp[i];
  2554. memset(&fp->old_tclient, 0,
  2555. sizeof(struct tstorm_per_client_stats));
  2556. memset(&fp->old_uclient, 0,
  2557. sizeof(struct ustorm_per_client_stats));
  2558. memset(&fp->old_xclient, 0,
  2559. sizeof(struct xstorm_per_client_stats));
  2560. memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats));
  2561. }
  2562. memset(&bp->dev->stats, 0, sizeof(struct net_device_stats));
  2563. memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats));
  2564. bp->stats_state = STATS_STATE_DISABLED;
  2565. if (IS_E1HMF(bp) && bp->port.pmf && bp->port.port_stx)
  2566. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2567. }
  2568. static void bnx2x_hw_stats_post(struct bnx2x *bp)
  2569. {
  2570. struct dmae_command *dmae = &bp->stats_dmae;
  2571. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2572. *stats_comp = DMAE_COMP_VAL;
  2573. if (CHIP_REV_IS_SLOW(bp))
  2574. return;
  2575. /* loader */
  2576. if (bp->executer_idx) {
  2577. int loader_idx = PMF_DMAE_C(bp);
  2578. memset(dmae, 0, sizeof(struct dmae_command));
  2579. dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  2580. DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
  2581. DMAE_CMD_DST_RESET |
  2582. #ifdef __BIG_ENDIAN
  2583. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2584. #else
  2585. DMAE_CMD_ENDIANITY_DW_SWAP |
  2586. #endif
  2587. (BP_PORT(bp) ? DMAE_CMD_PORT_1 :
  2588. DMAE_CMD_PORT_0) |
  2589. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  2590. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
  2591. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
  2592. dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
  2593. sizeof(struct dmae_command) *
  2594. (loader_idx + 1)) >> 2;
  2595. dmae->dst_addr_hi = 0;
  2596. dmae->len = sizeof(struct dmae_command) >> 2;
  2597. if (CHIP_IS_E1(bp))
  2598. dmae->len--;
  2599. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
  2600. dmae->comp_addr_hi = 0;
  2601. dmae->comp_val = 1;
  2602. *stats_comp = 0;
  2603. bnx2x_post_dmae(bp, dmae, loader_idx);
  2604. } else if (bp->func_stx) {
  2605. *stats_comp = 0;
  2606. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  2607. }
  2608. }
  2609. static int bnx2x_stats_comp(struct bnx2x *bp)
  2610. {
  2611. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2612. int cnt = 10;
  2613. might_sleep();
  2614. while (*stats_comp != DMAE_COMP_VAL) {
  2615. if (!cnt) {
  2616. BNX2X_ERR("timeout waiting for stats finished\n");
  2617. break;
  2618. }
  2619. cnt--;
  2620. msleep(1);
  2621. }
  2622. return 1;
  2623. }
  2624. /*
  2625. * Statistics service functions
  2626. */
  2627. static void bnx2x_stats_pmf_update(struct bnx2x *bp)
  2628. {
  2629. struct dmae_command *dmae;
  2630. u32 opcode;
  2631. int loader_idx = PMF_DMAE_C(bp);
  2632. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2633. /* sanity */
  2634. if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) {
  2635. BNX2X_ERR("BUG!\n");
  2636. return;
  2637. }
  2638. bp->executer_idx = 0;
  2639. opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  2640. DMAE_CMD_C_ENABLE |
  2641. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2642. #ifdef __BIG_ENDIAN
  2643. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2644. #else
  2645. DMAE_CMD_ENDIANITY_DW_SWAP |
  2646. #endif
  2647. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2648. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  2649. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2650. dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
  2651. dmae->src_addr_lo = bp->port.port_stx >> 2;
  2652. dmae->src_addr_hi = 0;
  2653. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  2654. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  2655. dmae->len = DMAE_LEN32_RD_MAX;
  2656. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2657. dmae->comp_addr_hi = 0;
  2658. dmae->comp_val = 1;
  2659. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2660. dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
  2661. dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
  2662. dmae->src_addr_hi = 0;
  2663. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
  2664. DMAE_LEN32_RD_MAX * 4);
  2665. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
  2666. DMAE_LEN32_RD_MAX * 4);
  2667. dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX;
  2668. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  2669. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  2670. dmae->comp_val = DMAE_COMP_VAL;
  2671. *stats_comp = 0;
  2672. bnx2x_hw_stats_post(bp);
  2673. bnx2x_stats_comp(bp);
  2674. }
  2675. static void bnx2x_port_stats_init(struct bnx2x *bp)
  2676. {
  2677. struct dmae_command *dmae;
  2678. int port = BP_PORT(bp);
  2679. int vn = BP_E1HVN(bp);
  2680. u32 opcode;
  2681. int loader_idx = PMF_DMAE_C(bp);
  2682. u32 mac_addr;
  2683. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2684. /* sanity */
  2685. if (!bp->link_vars.link_up || !bp->port.pmf) {
  2686. BNX2X_ERR("BUG!\n");
  2687. return;
  2688. }
  2689. bp->executer_idx = 0;
  2690. /* MCP */
  2691. opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  2692. DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
  2693. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2694. #ifdef __BIG_ENDIAN
  2695. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2696. #else
  2697. DMAE_CMD_ENDIANITY_DW_SWAP |
  2698. #endif
  2699. (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2700. (vn << DMAE_CMD_E1HVN_SHIFT));
  2701. if (bp->port.port_stx) {
  2702. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2703. dmae->opcode = opcode;
  2704. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  2705. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  2706. dmae->dst_addr_lo = bp->port.port_stx >> 2;
  2707. dmae->dst_addr_hi = 0;
  2708. dmae->len = sizeof(struct host_port_stats) >> 2;
  2709. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2710. dmae->comp_addr_hi = 0;
  2711. dmae->comp_val = 1;
  2712. }
  2713. if (bp->func_stx) {
  2714. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2715. dmae->opcode = opcode;
  2716. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
  2717. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
  2718. dmae->dst_addr_lo = bp->func_stx >> 2;
  2719. dmae->dst_addr_hi = 0;
  2720. dmae->len = sizeof(struct host_func_stats) >> 2;
  2721. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2722. dmae->comp_addr_hi = 0;
  2723. dmae->comp_val = 1;
  2724. }
  2725. /* MAC */
  2726. opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  2727. DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
  2728. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2729. #ifdef __BIG_ENDIAN
  2730. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2731. #else
  2732. DMAE_CMD_ENDIANITY_DW_SWAP |
  2733. #endif
  2734. (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2735. (vn << DMAE_CMD_E1HVN_SHIFT));
  2736. if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
  2737. mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
  2738. NIG_REG_INGRESS_BMAC0_MEM);
  2739. /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
  2740. BIGMAC_REGISTER_TX_STAT_GTBYT */
  2741. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2742. dmae->opcode = opcode;
  2743. dmae->src_addr_lo = (mac_addr +
  2744. BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
  2745. dmae->src_addr_hi = 0;
  2746. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
  2747. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
  2748. dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
  2749. BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
  2750. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2751. dmae->comp_addr_hi = 0;
  2752. dmae->comp_val = 1;
  2753. /* BIGMAC_REGISTER_RX_STAT_GR64 ..
  2754. BIGMAC_REGISTER_RX_STAT_GRIPJ */
  2755. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2756. dmae->opcode = opcode;
  2757. dmae->src_addr_lo = (mac_addr +
  2758. BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
  2759. dmae->src_addr_hi = 0;
  2760. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
  2761. offsetof(struct bmac_stats, rx_stat_gr64_lo));
  2762. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
  2763. offsetof(struct bmac_stats, rx_stat_gr64_lo));
  2764. dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
  2765. BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
  2766. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2767. dmae->comp_addr_hi = 0;
  2768. dmae->comp_val = 1;
  2769. } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
  2770. mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
  2771. /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
  2772. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2773. dmae->opcode = opcode;
  2774. dmae->src_addr_lo = (mac_addr +
  2775. EMAC_REG_EMAC_RX_STAT_AC) >> 2;
  2776. dmae->src_addr_hi = 0;
  2777. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
  2778. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
  2779. dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
  2780. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2781. dmae->comp_addr_hi = 0;
  2782. dmae->comp_val = 1;
  2783. /* EMAC_REG_EMAC_RX_STAT_AC_28 */
  2784. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2785. dmae->opcode = opcode;
  2786. dmae->src_addr_lo = (mac_addr +
  2787. EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
  2788. dmae->src_addr_hi = 0;
  2789. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
  2790. offsetof(struct emac_stats, rx_stat_falsecarriererrors));
  2791. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
  2792. offsetof(struct emac_stats, rx_stat_falsecarriererrors));
  2793. dmae->len = 1;
  2794. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2795. dmae->comp_addr_hi = 0;
  2796. dmae->comp_val = 1;
  2797. /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
  2798. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2799. dmae->opcode = opcode;
  2800. dmae->src_addr_lo = (mac_addr +
  2801. EMAC_REG_EMAC_TX_STAT_AC) >> 2;
  2802. dmae->src_addr_hi = 0;
  2803. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
  2804. offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
  2805. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
  2806. offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
  2807. dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
  2808. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2809. dmae->comp_addr_hi = 0;
  2810. dmae->comp_val = 1;
  2811. }
  2812. /* NIG */
  2813. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2814. dmae->opcode = opcode;
  2815. dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
  2816. NIG_REG_STAT0_BRB_DISCARD) >> 2;
  2817. dmae->src_addr_hi = 0;
  2818. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
  2819. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
  2820. dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
  2821. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2822. dmae->comp_addr_hi = 0;
  2823. dmae->comp_val = 1;
  2824. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2825. dmae->opcode = opcode;
  2826. dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
  2827. NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
  2828. dmae->src_addr_hi = 0;
  2829. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
  2830. offsetof(struct nig_stats, egress_mac_pkt0_lo));
  2831. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
  2832. offsetof(struct nig_stats, egress_mac_pkt0_lo));
  2833. dmae->len = (2*sizeof(u32)) >> 2;
  2834. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2835. dmae->comp_addr_hi = 0;
  2836. dmae->comp_val = 1;
  2837. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2838. dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  2839. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  2840. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2841. #ifdef __BIG_ENDIAN
  2842. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2843. #else
  2844. DMAE_CMD_ENDIANITY_DW_SWAP |
  2845. #endif
  2846. (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2847. (vn << DMAE_CMD_E1HVN_SHIFT));
  2848. dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
  2849. NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
  2850. dmae->src_addr_hi = 0;
  2851. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
  2852. offsetof(struct nig_stats, egress_mac_pkt1_lo));
  2853. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
  2854. offsetof(struct nig_stats, egress_mac_pkt1_lo));
  2855. dmae->len = (2*sizeof(u32)) >> 2;
  2856. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  2857. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  2858. dmae->comp_val = DMAE_COMP_VAL;
  2859. *stats_comp = 0;
  2860. }
  2861. static void bnx2x_func_stats_init(struct bnx2x *bp)
  2862. {
  2863. struct dmae_command *dmae = &bp->stats_dmae;
  2864. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2865. /* sanity */
  2866. if (!bp->func_stx) {
  2867. BNX2X_ERR("BUG!\n");
  2868. return;
  2869. }
  2870. bp->executer_idx = 0;
  2871. memset(dmae, 0, sizeof(struct dmae_command));
  2872. dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  2873. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  2874. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2875. #ifdef __BIG_ENDIAN
  2876. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2877. #else
  2878. DMAE_CMD_ENDIANITY_DW_SWAP |
  2879. #endif
  2880. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2881. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  2882. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
  2883. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
  2884. dmae->dst_addr_lo = bp->func_stx >> 2;
  2885. dmae->dst_addr_hi = 0;
  2886. dmae->len = sizeof(struct host_func_stats) >> 2;
  2887. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  2888. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  2889. dmae->comp_val = DMAE_COMP_VAL;
  2890. *stats_comp = 0;
  2891. }
  2892. static void bnx2x_stats_start(struct bnx2x *bp)
  2893. {
  2894. if (bp->port.pmf)
  2895. bnx2x_port_stats_init(bp);
  2896. else if (bp->func_stx)
  2897. bnx2x_func_stats_init(bp);
  2898. bnx2x_hw_stats_post(bp);
  2899. bnx2x_storm_stats_post(bp);
  2900. }
  2901. static void bnx2x_stats_pmf_start(struct bnx2x *bp)
  2902. {
  2903. bnx2x_stats_comp(bp);
  2904. bnx2x_stats_pmf_update(bp);
  2905. bnx2x_stats_start(bp);
  2906. }
  2907. static void bnx2x_stats_restart(struct bnx2x *bp)
  2908. {
  2909. bnx2x_stats_comp(bp);
  2910. bnx2x_stats_start(bp);
  2911. }
  2912. static void bnx2x_bmac_stats_update(struct bnx2x *bp)
  2913. {
  2914. struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats);
  2915. struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
  2916. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  2917. struct {
  2918. u32 lo;
  2919. u32 hi;
  2920. } diff;
  2921. UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
  2922. UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
  2923. UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
  2924. UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
  2925. UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
  2926. UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
  2927. UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
  2928. UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
  2929. UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf);
  2930. UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
  2931. UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
  2932. UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
  2933. UPDATE_STAT64(tx_stat_gt127,
  2934. tx_stat_etherstatspkts65octetsto127octets);
  2935. UPDATE_STAT64(tx_stat_gt255,
  2936. tx_stat_etherstatspkts128octetsto255octets);
  2937. UPDATE_STAT64(tx_stat_gt511,
  2938. tx_stat_etherstatspkts256octetsto511octets);
  2939. UPDATE_STAT64(tx_stat_gt1023,
  2940. tx_stat_etherstatspkts512octetsto1023octets);
  2941. UPDATE_STAT64(tx_stat_gt1518,
  2942. tx_stat_etherstatspkts1024octetsto1522octets);
  2943. UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047);
  2944. UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095);
  2945. UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216);
  2946. UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383);
  2947. UPDATE_STAT64(tx_stat_gterr,
  2948. tx_stat_dot3statsinternalmactransmiterrors);
  2949. UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl);
  2950. estats->pause_frames_received_hi =
  2951. pstats->mac_stx[1].rx_stat_bmac_xpf_hi;
  2952. estats->pause_frames_received_lo =
  2953. pstats->mac_stx[1].rx_stat_bmac_xpf_lo;
  2954. estats->pause_frames_sent_hi =
  2955. pstats->mac_stx[1].tx_stat_outxoffsent_hi;
  2956. estats->pause_frames_sent_lo =
  2957. pstats->mac_stx[1].tx_stat_outxoffsent_lo;
  2958. }
  2959. static void bnx2x_emac_stats_update(struct bnx2x *bp)
  2960. {
  2961. struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
  2962. struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
  2963. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  2964. UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
  2965. UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
  2966. UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
  2967. UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
  2968. UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
  2969. UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
  2970. UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
  2971. UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
  2972. UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
  2973. UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
  2974. UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
  2975. UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
  2976. UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
  2977. UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
  2978. UPDATE_EXTEND_STAT(tx_stat_outxonsent);
  2979. UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
  2980. UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
  2981. UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
  2982. UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
  2983. UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
  2984. UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
  2985. UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
  2986. UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
  2987. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
  2988. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
  2989. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
  2990. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
  2991. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
  2992. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
  2993. UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
  2994. UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
  2995. estats->pause_frames_received_hi =
  2996. pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
  2997. estats->pause_frames_received_lo =
  2998. pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
  2999. ADD_64(estats->pause_frames_received_hi,
  3000. pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
  3001. estats->pause_frames_received_lo,
  3002. pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
  3003. estats->pause_frames_sent_hi =
  3004. pstats->mac_stx[1].tx_stat_outxonsent_hi;
  3005. estats->pause_frames_sent_lo =
  3006. pstats->mac_stx[1].tx_stat_outxonsent_lo;
  3007. ADD_64(estats->pause_frames_sent_hi,
  3008. pstats->mac_stx[1].tx_stat_outxoffsent_hi,
  3009. estats->pause_frames_sent_lo,
  3010. pstats->mac_stx[1].tx_stat_outxoffsent_lo);
  3011. }
  3012. static int bnx2x_hw_stats_update(struct bnx2x *bp)
  3013. {
  3014. struct nig_stats *new = bnx2x_sp(bp, nig_stats);
  3015. struct nig_stats *old = &(bp->port.old_nig_stats);
  3016. struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
  3017. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3018. struct {
  3019. u32 lo;
  3020. u32 hi;
  3021. } diff;
  3022. u32 nig_timer_max;
  3023. if (bp->link_vars.mac_type == MAC_TYPE_BMAC)
  3024. bnx2x_bmac_stats_update(bp);
  3025. else if (bp->link_vars.mac_type == MAC_TYPE_EMAC)
  3026. bnx2x_emac_stats_update(bp);
  3027. else { /* unreached */
  3028. BNX2X_ERR("stats updated by DMAE but no MAC active\n");
  3029. return -1;
  3030. }
  3031. ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
  3032. new->brb_discard - old->brb_discard);
  3033. ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
  3034. new->brb_truncate - old->brb_truncate);
  3035. UPDATE_STAT64_NIG(egress_mac_pkt0,
  3036. etherstatspkts1024octetsto1522octets);
  3037. UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets);
  3038. memcpy(old, new, sizeof(struct nig_stats));
  3039. memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
  3040. sizeof(struct mac_stx));
  3041. estats->brb_drop_hi = pstats->brb_drop_hi;
  3042. estats->brb_drop_lo = pstats->brb_drop_lo;
  3043. pstats->host_port_stats_start = ++pstats->host_port_stats_end;
  3044. nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
  3045. if (nig_timer_max != estats->nig_timer_max) {
  3046. estats->nig_timer_max = nig_timer_max;
  3047. BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max);
  3048. }
  3049. return 0;
  3050. }
  3051. static int bnx2x_storm_stats_update(struct bnx2x *bp)
  3052. {
  3053. struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats);
  3054. struct tstorm_per_port_stats *tport =
  3055. &stats->tstorm_common.port_statistics;
  3056. struct host_func_stats *fstats = bnx2x_sp(bp, func_stats);
  3057. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3058. int i;
  3059. memset(&(fstats->total_bytes_received_hi), 0,
  3060. sizeof(struct host_func_stats) - 2*sizeof(u32));
  3061. estats->error_bytes_received_hi = 0;
  3062. estats->error_bytes_received_lo = 0;
  3063. estats->etherstatsoverrsizepkts_hi = 0;
  3064. estats->etherstatsoverrsizepkts_lo = 0;
  3065. estats->no_buff_discard_hi = 0;
  3066. estats->no_buff_discard_lo = 0;
  3067. for_each_queue(bp, i) {
  3068. struct bnx2x_fastpath *fp = &bp->fp[i];
  3069. int cl_id = fp->cl_id;
  3070. struct tstorm_per_client_stats *tclient =
  3071. &stats->tstorm_common.client_statistics[cl_id];
  3072. struct tstorm_per_client_stats *old_tclient = &fp->old_tclient;
  3073. struct ustorm_per_client_stats *uclient =
  3074. &stats->ustorm_common.client_statistics[cl_id];
  3075. struct ustorm_per_client_stats *old_uclient = &fp->old_uclient;
  3076. struct xstorm_per_client_stats *xclient =
  3077. &stats->xstorm_common.client_statistics[cl_id];
  3078. struct xstorm_per_client_stats *old_xclient = &fp->old_xclient;
  3079. struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
  3080. u32 diff;
  3081. /* are storm stats valid? */
  3082. if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) !=
  3083. bp->stats_counter) {
  3084. DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm"
  3085. " xstorm counter (%d) != stats_counter (%d)\n",
  3086. i, xclient->stats_counter, bp->stats_counter);
  3087. return -1;
  3088. }
  3089. if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) !=
  3090. bp->stats_counter) {
  3091. DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm"
  3092. " tstorm counter (%d) != stats_counter (%d)\n",
  3093. i, tclient->stats_counter, bp->stats_counter);
  3094. return -2;
  3095. }
  3096. if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) !=
  3097. bp->stats_counter) {
  3098. DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm"
  3099. " ustorm counter (%d) != stats_counter (%d)\n",
  3100. i, uclient->stats_counter, bp->stats_counter);
  3101. return -4;
  3102. }
  3103. qstats->total_bytes_received_hi =
  3104. qstats->valid_bytes_received_hi =
  3105. le32_to_cpu(tclient->total_rcv_bytes.hi);
  3106. qstats->total_bytes_received_lo =
  3107. qstats->valid_bytes_received_lo =
  3108. le32_to_cpu(tclient->total_rcv_bytes.lo);
  3109. qstats->error_bytes_received_hi =
  3110. le32_to_cpu(tclient->rcv_error_bytes.hi);
  3111. qstats->error_bytes_received_lo =
  3112. le32_to_cpu(tclient->rcv_error_bytes.lo);
  3113. ADD_64(qstats->total_bytes_received_hi,
  3114. qstats->error_bytes_received_hi,
  3115. qstats->total_bytes_received_lo,
  3116. qstats->error_bytes_received_lo);
  3117. UPDATE_EXTEND_TSTAT(rcv_unicast_pkts,
  3118. total_unicast_packets_received);
  3119. UPDATE_EXTEND_TSTAT(rcv_multicast_pkts,
  3120. total_multicast_packets_received);
  3121. UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts,
  3122. total_broadcast_packets_received);
  3123. UPDATE_EXTEND_TSTAT(packets_too_big_discard,
  3124. etherstatsoverrsizepkts);
  3125. UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard);
  3126. SUB_EXTEND_USTAT(ucast_no_buff_pkts,
  3127. total_unicast_packets_received);
  3128. SUB_EXTEND_USTAT(mcast_no_buff_pkts,
  3129. total_multicast_packets_received);
  3130. SUB_EXTEND_USTAT(bcast_no_buff_pkts,
  3131. total_broadcast_packets_received);
  3132. UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard);
  3133. UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard);
  3134. UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard);
  3135. qstats->total_bytes_transmitted_hi =
  3136. le32_to_cpu(xclient->total_sent_bytes.hi);
  3137. qstats->total_bytes_transmitted_lo =
  3138. le32_to_cpu(xclient->total_sent_bytes.lo);
  3139. UPDATE_EXTEND_XSTAT(unicast_pkts_sent,
  3140. total_unicast_packets_transmitted);
  3141. UPDATE_EXTEND_XSTAT(multicast_pkts_sent,
  3142. total_multicast_packets_transmitted);
  3143. UPDATE_EXTEND_XSTAT(broadcast_pkts_sent,
  3144. total_broadcast_packets_transmitted);
  3145. old_tclient->checksum_discard = tclient->checksum_discard;
  3146. old_tclient->ttl0_discard = tclient->ttl0_discard;
  3147. ADD_64(fstats->total_bytes_received_hi,
  3148. qstats->total_bytes_received_hi,
  3149. fstats->total_bytes_received_lo,
  3150. qstats->total_bytes_received_lo);
  3151. ADD_64(fstats->total_bytes_transmitted_hi,
  3152. qstats->total_bytes_transmitted_hi,
  3153. fstats->total_bytes_transmitted_lo,
  3154. qstats->total_bytes_transmitted_lo);
  3155. ADD_64(fstats->total_unicast_packets_received_hi,
  3156. qstats->total_unicast_packets_received_hi,
  3157. fstats->total_unicast_packets_received_lo,
  3158. qstats->total_unicast_packets_received_lo);
  3159. ADD_64(fstats->total_multicast_packets_received_hi,
  3160. qstats->total_multicast_packets_received_hi,
  3161. fstats->total_multicast_packets_received_lo,
  3162. qstats->total_multicast_packets_received_lo);
  3163. ADD_64(fstats->total_broadcast_packets_received_hi,
  3164. qstats->total_broadcast_packets_received_hi,
  3165. fstats->total_broadcast_packets_received_lo,
  3166. qstats->total_broadcast_packets_received_lo);
  3167. ADD_64(fstats->total_unicast_packets_transmitted_hi,
  3168. qstats->total_unicast_packets_transmitted_hi,
  3169. fstats->total_unicast_packets_transmitted_lo,
  3170. qstats->total_unicast_packets_transmitted_lo);
  3171. ADD_64(fstats->total_multicast_packets_transmitted_hi,
  3172. qstats->total_multicast_packets_transmitted_hi,
  3173. fstats->total_multicast_packets_transmitted_lo,
  3174. qstats->total_multicast_packets_transmitted_lo);
  3175. ADD_64(fstats->total_broadcast_packets_transmitted_hi,
  3176. qstats->total_broadcast_packets_transmitted_hi,
  3177. fstats->total_broadcast_packets_transmitted_lo,
  3178. qstats->total_broadcast_packets_transmitted_lo);
  3179. ADD_64(fstats->valid_bytes_received_hi,
  3180. qstats->valid_bytes_received_hi,
  3181. fstats->valid_bytes_received_lo,
  3182. qstats->valid_bytes_received_lo);
  3183. ADD_64(estats->error_bytes_received_hi,
  3184. qstats->error_bytes_received_hi,
  3185. estats->error_bytes_received_lo,
  3186. qstats->error_bytes_received_lo);
  3187. ADD_64(estats->etherstatsoverrsizepkts_hi,
  3188. qstats->etherstatsoverrsizepkts_hi,
  3189. estats->etherstatsoverrsizepkts_lo,
  3190. qstats->etherstatsoverrsizepkts_lo);
  3191. ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi,
  3192. estats->no_buff_discard_lo, qstats->no_buff_discard_lo);
  3193. }
  3194. ADD_64(fstats->total_bytes_received_hi,
  3195. estats->rx_stat_ifhcinbadoctets_hi,
  3196. fstats->total_bytes_received_lo,
  3197. estats->rx_stat_ifhcinbadoctets_lo);
  3198. memcpy(estats, &(fstats->total_bytes_received_hi),
  3199. sizeof(struct host_func_stats) - 2*sizeof(u32));
  3200. ADD_64(estats->etherstatsoverrsizepkts_hi,
  3201. estats->rx_stat_dot3statsframestoolong_hi,
  3202. estats->etherstatsoverrsizepkts_lo,
  3203. estats->rx_stat_dot3statsframestoolong_lo);
  3204. ADD_64(estats->error_bytes_received_hi,
  3205. estats->rx_stat_ifhcinbadoctets_hi,
  3206. estats->error_bytes_received_lo,
  3207. estats->rx_stat_ifhcinbadoctets_lo);
  3208. if (bp->port.pmf) {
  3209. estats->mac_filter_discard =
  3210. le32_to_cpu(tport->mac_filter_discard);
  3211. estats->xxoverflow_discard =
  3212. le32_to_cpu(tport->xxoverflow_discard);
  3213. estats->brb_truncate_discard =
  3214. le32_to_cpu(tport->brb_truncate_discard);
  3215. estats->mac_discard = le32_to_cpu(tport->mac_discard);
  3216. }
  3217. fstats->host_func_stats_start = ++fstats->host_func_stats_end;
  3218. bp->stats_pending = 0;
  3219. return 0;
  3220. }
  3221. static void bnx2x_net_stats_update(struct bnx2x *bp)
  3222. {
  3223. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3224. struct net_device_stats *nstats = &bp->dev->stats;
  3225. int i;
  3226. nstats->rx_packets =
  3227. bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
  3228. bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
  3229. bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
  3230. nstats->tx_packets =
  3231. bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
  3232. bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
  3233. bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
  3234. nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
  3235. nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
  3236. nstats->rx_dropped = estats->mac_discard;
  3237. for_each_queue(bp, i)
  3238. nstats->rx_dropped +=
  3239. le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
  3240. nstats->tx_dropped = 0;
  3241. nstats->multicast =
  3242. bnx2x_hilo(&estats->total_multicast_packets_received_hi);
  3243. nstats->collisions =
  3244. bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
  3245. nstats->rx_length_errors =
  3246. bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
  3247. bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
  3248. nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
  3249. bnx2x_hilo(&estats->brb_truncate_hi);
  3250. nstats->rx_crc_errors =
  3251. bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
  3252. nstats->rx_frame_errors =
  3253. bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
  3254. nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
  3255. nstats->rx_missed_errors = estats->xxoverflow_discard;
  3256. nstats->rx_errors = nstats->rx_length_errors +
  3257. nstats->rx_over_errors +
  3258. nstats->rx_crc_errors +
  3259. nstats->rx_frame_errors +
  3260. nstats->rx_fifo_errors +
  3261. nstats->rx_missed_errors;
  3262. nstats->tx_aborted_errors =
  3263. bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
  3264. bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
  3265. nstats->tx_carrier_errors =
  3266. bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
  3267. nstats->tx_fifo_errors = 0;
  3268. nstats->tx_heartbeat_errors = 0;
  3269. nstats->tx_window_errors = 0;
  3270. nstats->tx_errors = nstats->tx_aborted_errors +
  3271. nstats->tx_carrier_errors +
  3272. bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
  3273. }
  3274. static void bnx2x_drv_stats_update(struct bnx2x *bp)
  3275. {
  3276. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3277. int i;
  3278. estats->driver_xoff = 0;
  3279. estats->rx_err_discard_pkt = 0;
  3280. estats->rx_skb_alloc_failed = 0;
  3281. estats->hw_csum_err = 0;
  3282. for_each_queue(bp, i) {
  3283. struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
  3284. estats->driver_xoff += qstats->driver_xoff;
  3285. estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt;
  3286. estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed;
  3287. estats->hw_csum_err += qstats->hw_csum_err;
  3288. }
  3289. }
  3290. static void bnx2x_stats_update(struct bnx2x *bp)
  3291. {
  3292. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3293. if (*stats_comp != DMAE_COMP_VAL)
  3294. return;
  3295. if (bp->port.pmf)
  3296. bnx2x_hw_stats_update(bp);
  3297. if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) {
  3298. BNX2X_ERR("storm stats were not updated for 3 times\n");
  3299. bnx2x_panic();
  3300. return;
  3301. }
  3302. bnx2x_net_stats_update(bp);
  3303. bnx2x_drv_stats_update(bp);
  3304. if (bp->msglevel & NETIF_MSG_TIMER) {
  3305. struct tstorm_per_client_stats *old_tclient =
  3306. &bp->fp->old_tclient;
  3307. struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats;
  3308. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3309. struct net_device_stats *nstats = &bp->dev->stats;
  3310. int i;
  3311. printk(KERN_DEBUG "%s:\n", bp->dev->name);
  3312. printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)"
  3313. " tx pkt (%lx)\n",
  3314. bnx2x_tx_avail(bp->fp),
  3315. le16_to_cpu(*bp->fp->tx_cons_sb), nstats->tx_packets);
  3316. printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)"
  3317. " rx pkt (%lx)\n",
  3318. (u16)(le16_to_cpu(*bp->fp->rx_cons_sb) -
  3319. bp->fp->rx_comp_cons),
  3320. le16_to_cpu(*bp->fp->rx_cons_sb), nstats->rx_packets);
  3321. printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u "
  3322. "brb truncate %u\n",
  3323. (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"),
  3324. qstats->driver_xoff,
  3325. estats->brb_drop_lo, estats->brb_truncate_lo);
  3326. printk(KERN_DEBUG "tstats: checksum_discard %u "
  3327. "packets_too_big_discard %lu no_buff_discard %lu "
  3328. "mac_discard %u mac_filter_discard %u "
  3329. "xxovrflow_discard %u brb_truncate_discard %u "
  3330. "ttl0_discard %u\n",
  3331. le32_to_cpu(old_tclient->checksum_discard),
  3332. bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi),
  3333. bnx2x_hilo(&qstats->no_buff_discard_hi),
  3334. estats->mac_discard, estats->mac_filter_discard,
  3335. estats->xxoverflow_discard, estats->brb_truncate_discard,
  3336. le32_to_cpu(old_tclient->ttl0_discard));
  3337. for_each_queue(bp, i) {
  3338. printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i,
  3339. bnx2x_fp(bp, i, tx_pkt),
  3340. bnx2x_fp(bp, i, rx_pkt),
  3341. bnx2x_fp(bp, i, rx_calls));
  3342. }
  3343. }
  3344. bnx2x_hw_stats_post(bp);
  3345. bnx2x_storm_stats_post(bp);
  3346. }
  3347. static void bnx2x_port_stats_stop(struct bnx2x *bp)
  3348. {
  3349. struct dmae_command *dmae;
  3350. u32 opcode;
  3351. int loader_idx = PMF_DMAE_C(bp);
  3352. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3353. bp->executer_idx = 0;
  3354. opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  3355. DMAE_CMD_C_ENABLE |
  3356. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  3357. #ifdef __BIG_ENDIAN
  3358. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  3359. #else
  3360. DMAE_CMD_ENDIANITY_DW_SWAP |
  3361. #endif
  3362. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  3363. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  3364. if (bp->port.port_stx) {
  3365. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3366. if (bp->func_stx)
  3367. dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
  3368. else
  3369. dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
  3370. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  3371. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  3372. dmae->dst_addr_lo = bp->port.port_stx >> 2;
  3373. dmae->dst_addr_hi = 0;
  3374. dmae->len = sizeof(struct host_port_stats) >> 2;
  3375. if (bp->func_stx) {
  3376. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3377. dmae->comp_addr_hi = 0;
  3378. dmae->comp_val = 1;
  3379. } else {
  3380. dmae->comp_addr_lo =
  3381. U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3382. dmae->comp_addr_hi =
  3383. U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3384. dmae->comp_val = DMAE_COMP_VAL;
  3385. *stats_comp = 0;
  3386. }
  3387. }
  3388. if (bp->func_stx) {
  3389. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3390. dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
  3391. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
  3392. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
  3393. dmae->dst_addr_lo = bp->func_stx >> 2;
  3394. dmae->dst_addr_hi = 0;
  3395. dmae->len = sizeof(struct host_func_stats) >> 2;
  3396. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3397. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3398. dmae->comp_val = DMAE_COMP_VAL;
  3399. *stats_comp = 0;
  3400. }
  3401. }
  3402. static void bnx2x_stats_stop(struct bnx2x *bp)
  3403. {
  3404. int update = 0;
  3405. bnx2x_stats_comp(bp);
  3406. if (bp->port.pmf)
  3407. update = (bnx2x_hw_stats_update(bp) == 0);
  3408. update |= (bnx2x_storm_stats_update(bp) == 0);
  3409. if (update) {
  3410. bnx2x_net_stats_update(bp);
  3411. if (bp->port.pmf)
  3412. bnx2x_port_stats_stop(bp);
  3413. bnx2x_hw_stats_post(bp);
  3414. bnx2x_stats_comp(bp);
  3415. }
  3416. }
  3417. static void bnx2x_stats_do_nothing(struct bnx2x *bp)
  3418. {
  3419. }
  3420. static const struct {
  3421. void (*action)(struct bnx2x *bp);
  3422. enum bnx2x_stats_state next_state;
  3423. } bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
  3424. /* state event */
  3425. {
  3426. /* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
  3427. /* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
  3428. /* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
  3429. /* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
  3430. },
  3431. {
  3432. /* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
  3433. /* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
  3434. /* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
  3435. /* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
  3436. }
  3437. };
  3438. static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
  3439. {
  3440. enum bnx2x_stats_state state = bp->stats_state;
  3441. bnx2x_stats_stm[state][event].action(bp);
  3442. bp->stats_state = bnx2x_stats_stm[state][event].next_state;
  3443. if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER))
  3444. DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
  3445. state, event, bp->stats_state);
  3446. }
  3447. static void bnx2x_timer(unsigned long data)
  3448. {
  3449. struct bnx2x *bp = (struct bnx2x *) data;
  3450. if (!netif_running(bp->dev))
  3451. return;
  3452. if (atomic_read(&bp->intr_sem) != 0)
  3453. goto timer_restart;
  3454. if (poll) {
  3455. struct bnx2x_fastpath *fp = &bp->fp[0];
  3456. int rc;
  3457. bnx2x_tx_int(fp);
  3458. rc = bnx2x_rx_int(fp, 1000);
  3459. }
  3460. if (!BP_NOMCP(bp)) {
  3461. int func = BP_FUNC(bp);
  3462. u32 drv_pulse;
  3463. u32 mcp_pulse;
  3464. ++bp->fw_drv_pulse_wr_seq;
  3465. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  3466. /* TBD - add SYSTEM_TIME */
  3467. drv_pulse = bp->fw_drv_pulse_wr_seq;
  3468. SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse);
  3469. mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) &
  3470. MCP_PULSE_SEQ_MASK);
  3471. /* The delta between driver pulse and mcp response
  3472. * should be 1 (before mcp response) or 0 (after mcp response)
  3473. */
  3474. if ((drv_pulse != mcp_pulse) &&
  3475. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  3476. /* someone lost a heartbeat... */
  3477. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  3478. drv_pulse, mcp_pulse);
  3479. }
  3480. }
  3481. if ((bp->state == BNX2X_STATE_OPEN) ||
  3482. (bp->state == BNX2X_STATE_DISABLED))
  3483. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  3484. timer_restart:
  3485. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3486. }
  3487. /* end of Statistics */
  3488. /* nic init */
  3489. /*
  3490. * nic init service functions
  3491. */
  3492. static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id)
  3493. {
  3494. int port = BP_PORT(bp);
  3495. bnx2x_init_fill(bp, USTORM_INTMEM_ADDR +
  3496. USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0,
  3497. sizeof(struct ustorm_status_block)/4);
  3498. bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR +
  3499. CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), 0,
  3500. sizeof(struct cstorm_status_block)/4);
  3501. }
  3502. static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb,
  3503. dma_addr_t mapping, int sb_id)
  3504. {
  3505. int port = BP_PORT(bp);
  3506. int func = BP_FUNC(bp);
  3507. int index;
  3508. u64 section;
  3509. /* USTORM */
  3510. section = ((u64)mapping) + offsetof(struct host_status_block,
  3511. u_status_block);
  3512. sb->u_status_block.status_block_id = sb_id;
  3513. REG_WR(bp, BAR_USTRORM_INTMEM +
  3514. USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section));
  3515. REG_WR(bp, BAR_USTRORM_INTMEM +
  3516. ((USTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4),
  3517. U64_HI(section));
  3518. REG_WR8(bp, BAR_USTRORM_INTMEM + FP_USB_FUNC_OFF +
  3519. USTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func);
  3520. for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++)
  3521. REG_WR16(bp, BAR_USTRORM_INTMEM +
  3522. USTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1);
  3523. /* CSTORM */
  3524. section = ((u64)mapping) + offsetof(struct host_status_block,
  3525. c_status_block);
  3526. sb->c_status_block.status_block_id = sb_id;
  3527. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3528. CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id), U64_LO(section));
  3529. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3530. ((CSTORM_SB_HOST_SB_ADDR_OFFSET(port, sb_id)) + 4),
  3531. U64_HI(section));
  3532. REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF +
  3533. CSTORM_SB_HOST_STATUS_BLOCK_OFFSET(port, sb_id), func);
  3534. for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++)
  3535. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  3536. CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id, index), 1);
  3537. bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  3538. }
  3539. static void bnx2x_zero_def_sb(struct bnx2x *bp)
  3540. {
  3541. int func = BP_FUNC(bp);
  3542. bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR +
  3543. TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
  3544. sizeof(struct tstorm_def_status_block)/4);
  3545. bnx2x_init_fill(bp, USTORM_INTMEM_ADDR +
  3546. USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
  3547. sizeof(struct ustorm_def_status_block)/4);
  3548. bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR +
  3549. CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
  3550. sizeof(struct cstorm_def_status_block)/4);
  3551. bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR +
  3552. XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
  3553. sizeof(struct xstorm_def_status_block)/4);
  3554. }
  3555. static void bnx2x_init_def_sb(struct bnx2x *bp,
  3556. struct host_def_status_block *def_sb,
  3557. dma_addr_t mapping, int sb_id)
  3558. {
  3559. int port = BP_PORT(bp);
  3560. int func = BP_FUNC(bp);
  3561. int index, val, reg_offset;
  3562. u64 section;
  3563. /* ATTN */
  3564. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  3565. atten_status_block);
  3566. def_sb->atten_status_block.status_block_id = sb_id;
  3567. bp->attn_state = 0;
  3568. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3569. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3570. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3571. bp->attn_group[index].sig[0] = REG_RD(bp,
  3572. reg_offset + 0x10*index);
  3573. bp->attn_group[index].sig[1] = REG_RD(bp,
  3574. reg_offset + 0x4 + 0x10*index);
  3575. bp->attn_group[index].sig[2] = REG_RD(bp,
  3576. reg_offset + 0x8 + 0x10*index);
  3577. bp->attn_group[index].sig[3] = REG_RD(bp,
  3578. reg_offset + 0xc + 0x10*index);
  3579. }
  3580. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  3581. HC_REG_ATTN_MSG0_ADDR_L);
  3582. REG_WR(bp, reg_offset, U64_LO(section));
  3583. REG_WR(bp, reg_offset + 4, U64_HI(section));
  3584. reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0);
  3585. val = REG_RD(bp, reg_offset);
  3586. val |= sb_id;
  3587. REG_WR(bp, reg_offset, val);
  3588. /* USTORM */
  3589. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  3590. u_def_status_block);
  3591. def_sb->u_def_status_block.status_block_id = sb_id;
  3592. REG_WR(bp, BAR_USTRORM_INTMEM +
  3593. USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
  3594. REG_WR(bp, BAR_USTRORM_INTMEM +
  3595. ((USTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
  3596. U64_HI(section));
  3597. REG_WR8(bp, BAR_USTRORM_INTMEM + DEF_USB_FUNC_OFF +
  3598. USTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
  3599. for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++)
  3600. REG_WR16(bp, BAR_USTRORM_INTMEM +
  3601. USTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
  3602. /* CSTORM */
  3603. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  3604. c_def_status_block);
  3605. def_sb->c_def_status_block.status_block_id = sb_id;
  3606. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3607. CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
  3608. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3609. ((CSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
  3610. U64_HI(section));
  3611. REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF +
  3612. CSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
  3613. for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++)
  3614. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  3615. CSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
  3616. /* TSTORM */
  3617. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  3618. t_def_status_block);
  3619. def_sb->t_def_status_block.status_block_id = sb_id;
  3620. REG_WR(bp, BAR_TSTRORM_INTMEM +
  3621. TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
  3622. REG_WR(bp, BAR_TSTRORM_INTMEM +
  3623. ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
  3624. U64_HI(section));
  3625. REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF +
  3626. TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
  3627. for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++)
  3628. REG_WR16(bp, BAR_TSTRORM_INTMEM +
  3629. TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
  3630. /* XSTORM */
  3631. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  3632. x_def_status_block);
  3633. def_sb->x_def_status_block.status_block_id = sb_id;
  3634. REG_WR(bp, BAR_XSTRORM_INTMEM +
  3635. XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
  3636. REG_WR(bp, BAR_XSTRORM_INTMEM +
  3637. ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
  3638. U64_HI(section));
  3639. REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF +
  3640. XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
  3641. for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++)
  3642. REG_WR16(bp, BAR_XSTRORM_INTMEM +
  3643. XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
  3644. bp->stats_pending = 0;
  3645. bp->set_mac_pending = 0;
  3646. bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  3647. }
  3648. static void bnx2x_update_coalesce(struct bnx2x *bp)
  3649. {
  3650. int port = BP_PORT(bp);
  3651. int i;
  3652. for_each_queue(bp, i) {
  3653. int sb_id = bp->fp[i].sb_id;
  3654. /* HC_INDEX_U_ETH_RX_CQ_CONS */
  3655. REG_WR8(bp, BAR_USTRORM_INTMEM +
  3656. USTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id,
  3657. U_SB_ETH_RX_CQ_INDEX),
  3658. bp->rx_ticks/12);
  3659. REG_WR16(bp, BAR_USTRORM_INTMEM +
  3660. USTORM_SB_HC_DISABLE_OFFSET(port, sb_id,
  3661. U_SB_ETH_RX_CQ_INDEX),
  3662. bp->rx_ticks ? 0 : 1);
  3663. /* HC_INDEX_C_ETH_TX_CQ_CONS */
  3664. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  3665. CSTORM_SB_HC_TIMEOUT_OFFSET(port, sb_id,
  3666. C_SB_ETH_TX_CQ_INDEX),
  3667. bp->tx_ticks/12);
  3668. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  3669. CSTORM_SB_HC_DISABLE_OFFSET(port, sb_id,
  3670. C_SB_ETH_TX_CQ_INDEX),
  3671. bp->tx_ticks ? 0 : 1);
  3672. }
  3673. }
  3674. static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
  3675. struct bnx2x_fastpath *fp, int last)
  3676. {
  3677. int i;
  3678. for (i = 0; i < last; i++) {
  3679. struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
  3680. struct sk_buff *skb = rx_buf->skb;
  3681. if (skb == NULL) {
  3682. DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
  3683. continue;
  3684. }
  3685. if (fp->tpa_state[i] == BNX2X_TPA_START)
  3686. pci_unmap_single(bp->pdev,
  3687. pci_unmap_addr(rx_buf, mapping),
  3688. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  3689. dev_kfree_skb(skb);
  3690. rx_buf->skb = NULL;
  3691. }
  3692. }
  3693. static void bnx2x_init_rx_rings(struct bnx2x *bp)
  3694. {
  3695. int func = BP_FUNC(bp);
  3696. int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
  3697. ETH_MAX_AGGREGATION_QUEUES_E1H;
  3698. u16 ring_prod, cqe_ring_prod;
  3699. int i, j;
  3700. bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN;
  3701. DP(NETIF_MSG_IFUP,
  3702. "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size);
  3703. if (bp->flags & TPA_ENABLE_FLAG) {
  3704. for_each_rx_queue(bp, j) {
  3705. struct bnx2x_fastpath *fp = &bp->fp[j];
  3706. for (i = 0; i < max_agg_queues; i++) {
  3707. fp->tpa_pool[i].skb =
  3708. netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  3709. if (!fp->tpa_pool[i].skb) {
  3710. BNX2X_ERR("Failed to allocate TPA "
  3711. "skb pool for queue[%d] - "
  3712. "disabling TPA on this "
  3713. "queue!\n", j);
  3714. bnx2x_free_tpa_pool(bp, fp, i);
  3715. fp->disable_tpa = 1;
  3716. break;
  3717. }
  3718. pci_unmap_addr_set((struct sw_rx_bd *)
  3719. &bp->fp->tpa_pool[i],
  3720. mapping, 0);
  3721. fp->tpa_state[i] = BNX2X_TPA_STOP;
  3722. }
  3723. }
  3724. }
  3725. for_each_rx_queue(bp, j) {
  3726. struct bnx2x_fastpath *fp = &bp->fp[j];
  3727. fp->rx_bd_cons = 0;
  3728. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  3729. fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX;
  3730. /* "next page" elements initialization */
  3731. /* SGE ring */
  3732. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  3733. struct eth_rx_sge *sge;
  3734. sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
  3735. sge->addr_hi =
  3736. cpu_to_le32(U64_HI(fp->rx_sge_mapping +
  3737. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  3738. sge->addr_lo =
  3739. cpu_to_le32(U64_LO(fp->rx_sge_mapping +
  3740. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  3741. }
  3742. bnx2x_init_sge_ring_bit_mask(fp);
  3743. /* RX BD ring */
  3744. for (i = 1; i <= NUM_RX_RINGS; i++) {
  3745. struct eth_rx_bd *rx_bd;
  3746. rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
  3747. rx_bd->addr_hi =
  3748. cpu_to_le32(U64_HI(fp->rx_desc_mapping +
  3749. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  3750. rx_bd->addr_lo =
  3751. cpu_to_le32(U64_LO(fp->rx_desc_mapping +
  3752. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  3753. }
  3754. /* CQ ring */
  3755. for (i = 1; i <= NUM_RCQ_RINGS; i++) {
  3756. struct eth_rx_cqe_next_page *nextpg;
  3757. nextpg = (struct eth_rx_cqe_next_page *)
  3758. &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
  3759. nextpg->addr_hi =
  3760. cpu_to_le32(U64_HI(fp->rx_comp_mapping +
  3761. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  3762. nextpg->addr_lo =
  3763. cpu_to_le32(U64_LO(fp->rx_comp_mapping +
  3764. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  3765. }
  3766. /* Allocate SGEs and initialize the ring elements */
  3767. for (i = 0, ring_prod = 0;
  3768. i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
  3769. if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
  3770. BNX2X_ERR("was only able to allocate "
  3771. "%d rx sges\n", i);
  3772. BNX2X_ERR("disabling TPA for queue[%d]\n", j);
  3773. /* Cleanup already allocated elements */
  3774. bnx2x_free_rx_sge_range(bp, fp, ring_prod);
  3775. bnx2x_free_tpa_pool(bp, fp, max_agg_queues);
  3776. fp->disable_tpa = 1;
  3777. ring_prod = 0;
  3778. break;
  3779. }
  3780. ring_prod = NEXT_SGE_IDX(ring_prod);
  3781. }
  3782. fp->rx_sge_prod = ring_prod;
  3783. /* Allocate BDs and initialize BD ring */
  3784. fp->rx_comp_cons = 0;
  3785. cqe_ring_prod = ring_prod = 0;
  3786. for (i = 0; i < bp->rx_ring_size; i++) {
  3787. if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) {
  3788. BNX2X_ERR("was only able to allocate "
  3789. "%d rx skbs on queue[%d]\n", i, j);
  3790. fp->eth_q_stats.rx_skb_alloc_failed++;
  3791. break;
  3792. }
  3793. ring_prod = NEXT_RX_IDX(ring_prod);
  3794. cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod);
  3795. WARN_ON(ring_prod <= i);
  3796. }
  3797. fp->rx_bd_prod = ring_prod;
  3798. /* must not have more available CQEs than BDs */
  3799. fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT),
  3800. cqe_ring_prod);
  3801. fp->rx_pkt = fp->rx_calls = 0;
  3802. /* Warning!
  3803. * this will generate an interrupt (to the TSTORM)
  3804. * must only be done after chip is initialized
  3805. */
  3806. bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod,
  3807. fp->rx_sge_prod);
  3808. if (j != 0)
  3809. continue;
  3810. REG_WR(bp, BAR_USTRORM_INTMEM +
  3811. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
  3812. U64_LO(fp->rx_comp_mapping));
  3813. REG_WR(bp, BAR_USTRORM_INTMEM +
  3814. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
  3815. U64_HI(fp->rx_comp_mapping));
  3816. }
  3817. }
  3818. static void bnx2x_init_tx_ring(struct bnx2x *bp)
  3819. {
  3820. int i, j;
  3821. for_each_tx_queue(bp, j) {
  3822. struct bnx2x_fastpath *fp = &bp->fp[j];
  3823. for (i = 1; i <= NUM_TX_RINGS; i++) {
  3824. struct eth_tx_bd *tx_bd =
  3825. &fp->tx_desc_ring[TX_DESC_CNT * i - 1];
  3826. tx_bd->addr_hi =
  3827. cpu_to_le32(U64_HI(fp->tx_desc_mapping +
  3828. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  3829. tx_bd->addr_lo =
  3830. cpu_to_le32(U64_LO(fp->tx_desc_mapping +
  3831. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  3832. }
  3833. fp->tx_pkt_prod = 0;
  3834. fp->tx_pkt_cons = 0;
  3835. fp->tx_bd_prod = 0;
  3836. fp->tx_bd_cons = 0;
  3837. fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
  3838. fp->tx_pkt = 0;
  3839. }
  3840. }
  3841. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  3842. {
  3843. int func = BP_FUNC(bp);
  3844. spin_lock_init(&bp->spq_lock);
  3845. bp->spq_left = MAX_SPQ_PENDING;
  3846. bp->spq_prod_idx = 0;
  3847. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  3848. bp->spq_prod_bd = bp->spq;
  3849. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  3850. REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func),
  3851. U64_LO(bp->spq_mapping));
  3852. REG_WR(bp,
  3853. XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4,
  3854. U64_HI(bp->spq_mapping));
  3855. REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func),
  3856. bp->spq_prod_idx);
  3857. }
  3858. static void bnx2x_init_context(struct bnx2x *bp)
  3859. {
  3860. int i;
  3861. for_each_queue(bp, i) {
  3862. struct eth_context *context = bnx2x_sp(bp, context[i].eth);
  3863. struct bnx2x_fastpath *fp = &bp->fp[i];
  3864. u8 cl_id = fp->cl_id;
  3865. u8 sb_id = fp->sb_id;
  3866. context->ustorm_st_context.common.sb_index_numbers =
  3867. BNX2X_RX_SB_INDEX_NUM;
  3868. context->ustorm_st_context.common.clientId = cl_id;
  3869. context->ustorm_st_context.common.status_block_id = sb_id;
  3870. context->ustorm_st_context.common.flags =
  3871. (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT |
  3872. USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS);
  3873. context->ustorm_st_context.common.statistics_counter_id =
  3874. cl_id;
  3875. context->ustorm_st_context.common.mc_alignment_log_size =
  3876. BNX2X_RX_ALIGN_SHIFT;
  3877. context->ustorm_st_context.common.bd_buff_size =
  3878. bp->rx_buf_size;
  3879. context->ustorm_st_context.common.bd_page_base_hi =
  3880. U64_HI(fp->rx_desc_mapping);
  3881. context->ustorm_st_context.common.bd_page_base_lo =
  3882. U64_LO(fp->rx_desc_mapping);
  3883. if (!fp->disable_tpa) {
  3884. context->ustorm_st_context.common.flags |=
  3885. (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA |
  3886. USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_SGE_RING);
  3887. context->ustorm_st_context.common.sge_buff_size =
  3888. (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE,
  3889. (u32)0xffff);
  3890. context->ustorm_st_context.common.sge_page_base_hi =
  3891. U64_HI(fp->rx_sge_mapping);
  3892. context->ustorm_st_context.common.sge_page_base_lo =
  3893. U64_LO(fp->rx_sge_mapping);
  3894. }
  3895. context->ustorm_ag_context.cdu_usage =
  3896. CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
  3897. CDU_REGION_NUMBER_UCM_AG,
  3898. ETH_CONNECTION_TYPE);
  3899. context->xstorm_st_context.tx_bd_page_base_hi =
  3900. U64_HI(fp->tx_desc_mapping);
  3901. context->xstorm_st_context.tx_bd_page_base_lo =
  3902. U64_LO(fp->tx_desc_mapping);
  3903. context->xstorm_st_context.db_data_addr_hi =
  3904. U64_HI(fp->tx_prods_mapping);
  3905. context->xstorm_st_context.db_data_addr_lo =
  3906. U64_LO(fp->tx_prods_mapping);
  3907. context->xstorm_st_context.statistics_data = (cl_id |
  3908. XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE);
  3909. context->cstorm_st_context.sb_index_number =
  3910. C_SB_ETH_TX_CQ_INDEX;
  3911. context->cstorm_st_context.status_block_id = sb_id;
  3912. context->xstorm_ag_context.cdu_reserved =
  3913. CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
  3914. CDU_REGION_NUMBER_XCM_AG,
  3915. ETH_CONNECTION_TYPE);
  3916. }
  3917. }
  3918. static void bnx2x_init_ind_table(struct bnx2x *bp)
  3919. {
  3920. int func = BP_FUNC(bp);
  3921. int i;
  3922. if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
  3923. return;
  3924. DP(NETIF_MSG_IFUP,
  3925. "Initializing indirection table multi_mode %d\n", bp->multi_mode);
  3926. for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
  3927. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  3928. TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
  3929. bp->fp->cl_id + (i % bp->num_rx_queues));
  3930. }
  3931. static void bnx2x_set_client_config(struct bnx2x *bp)
  3932. {
  3933. struct tstorm_eth_client_config tstorm_client = {0};
  3934. int port = BP_PORT(bp);
  3935. int i;
  3936. tstorm_client.mtu = bp->dev->mtu;
  3937. tstorm_client.config_flags =
  3938. (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE |
  3939. TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE);
  3940. #ifdef BCM_VLAN
  3941. if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) {
  3942. tstorm_client.config_flags |=
  3943. TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE;
  3944. DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
  3945. }
  3946. #endif
  3947. if (bp->flags & TPA_ENABLE_FLAG) {
  3948. tstorm_client.max_sges_for_packet =
  3949. SGE_PAGE_ALIGN(tstorm_client.mtu) >> SGE_PAGE_SHIFT;
  3950. tstorm_client.max_sges_for_packet =
  3951. ((tstorm_client.max_sges_for_packet +
  3952. PAGES_PER_SGE - 1) & (~(PAGES_PER_SGE - 1))) >>
  3953. PAGES_PER_SGE_SHIFT;
  3954. tstorm_client.config_flags |=
  3955. TSTORM_ETH_CLIENT_CONFIG_ENABLE_SGE_RING;
  3956. }
  3957. for_each_queue(bp, i) {
  3958. tstorm_client.statistics_counter_id = bp->fp[i].cl_id;
  3959. REG_WR(bp, BAR_TSTRORM_INTMEM +
  3960. TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id),
  3961. ((u32 *)&tstorm_client)[0]);
  3962. REG_WR(bp, BAR_TSTRORM_INTMEM +
  3963. TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4,
  3964. ((u32 *)&tstorm_client)[1]);
  3965. }
  3966. DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n",
  3967. ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]);
  3968. }
  3969. static void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  3970. {
  3971. struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0};
  3972. int mode = bp->rx_mode;
  3973. int mask = (1 << BP_L_ID(bp));
  3974. int func = BP_FUNC(bp);
  3975. int i;
  3976. DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask);
  3977. switch (mode) {
  3978. case BNX2X_RX_MODE_NONE: /* no Rx */
  3979. tstorm_mac_filter.ucast_drop_all = mask;
  3980. tstorm_mac_filter.mcast_drop_all = mask;
  3981. tstorm_mac_filter.bcast_drop_all = mask;
  3982. break;
  3983. case BNX2X_RX_MODE_NORMAL:
  3984. tstorm_mac_filter.bcast_accept_all = mask;
  3985. break;
  3986. case BNX2X_RX_MODE_ALLMULTI:
  3987. tstorm_mac_filter.mcast_accept_all = mask;
  3988. tstorm_mac_filter.bcast_accept_all = mask;
  3989. break;
  3990. case BNX2X_RX_MODE_PROMISC:
  3991. tstorm_mac_filter.ucast_accept_all = mask;
  3992. tstorm_mac_filter.mcast_accept_all = mask;
  3993. tstorm_mac_filter.bcast_accept_all = mask;
  3994. break;
  3995. default:
  3996. BNX2X_ERR("BAD rx mode (%d)\n", mode);
  3997. break;
  3998. }
  3999. for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) {
  4000. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4001. TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4,
  4002. ((u32 *)&tstorm_mac_filter)[i]);
  4003. /* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
  4004. ((u32 *)&tstorm_mac_filter)[i]); */
  4005. }
  4006. if (mode != BNX2X_RX_MODE_NONE)
  4007. bnx2x_set_client_config(bp);
  4008. }
  4009. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4010. {
  4011. int i;
  4012. if (bp->flags & TPA_ENABLE_FLAG) {
  4013. struct tstorm_eth_tpa_exist tpa = {0};
  4014. tpa.tpa_exist = 1;
  4015. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET,
  4016. ((u32 *)&tpa)[0]);
  4017. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_TPA_EXIST_OFFSET + 4,
  4018. ((u32 *)&tpa)[1]);
  4019. }
  4020. /* Zero this manually as its initialization is
  4021. currently missing in the initTool */
  4022. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4023. REG_WR(bp, BAR_USTRORM_INTMEM +
  4024. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4025. }
  4026. static void bnx2x_init_internal_port(struct bnx2x *bp)
  4027. {
  4028. int port = BP_PORT(bp);
  4029. REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
  4030. REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
  4031. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
  4032. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
  4033. }
  4034. /* Calculates the sum of vn_min_rates.
  4035. It's needed for further normalizing of the min_rates.
  4036. Returns:
  4037. sum of vn_min_rates.
  4038. or
  4039. 0 - if all the min_rates are 0.
  4040. In the later case fainess algorithm should be deactivated.
  4041. If not all min_rates are zero then those that are zeroes will be set to 1.
  4042. */
  4043. static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
  4044. {
  4045. int all_zero = 1;
  4046. int port = BP_PORT(bp);
  4047. int vn;
  4048. bp->vn_weight_sum = 0;
  4049. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  4050. int func = 2*vn + port;
  4051. u32 vn_cfg =
  4052. SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  4053. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  4054. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  4055. /* Skip hidden vns */
  4056. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  4057. continue;
  4058. /* If min rate is zero - set it to 1 */
  4059. if (!vn_min_rate)
  4060. vn_min_rate = DEF_MIN_RATE;
  4061. else
  4062. all_zero = 0;
  4063. bp->vn_weight_sum += vn_min_rate;
  4064. }
  4065. /* ... only if all min rates are zeros - disable fairness */
  4066. if (all_zero)
  4067. bp->vn_weight_sum = 0;
  4068. }
  4069. static void bnx2x_init_internal_func(struct bnx2x *bp)
  4070. {
  4071. struct tstorm_eth_function_common_config tstorm_config = {0};
  4072. struct stats_indication_flags stats_flags = {0};
  4073. int port = BP_PORT(bp);
  4074. int func = BP_FUNC(bp);
  4075. int i, j;
  4076. u32 offset;
  4077. u16 max_agg_size;
  4078. if (is_multi(bp)) {
  4079. tstorm_config.config_flags = MULTI_FLAGS(bp);
  4080. tstorm_config.rss_result_mask = MULTI_MASK;
  4081. }
  4082. if (IS_E1HMF(bp))
  4083. tstorm_config.config_flags |=
  4084. TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM;
  4085. tstorm_config.leading_client_id = BP_L_ID(bp);
  4086. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4087. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func),
  4088. (*(u32 *)&tstorm_config));
  4089. bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */
  4090. bnx2x_set_storm_rx_mode(bp);
  4091. for_each_queue(bp, i) {
  4092. u8 cl_id = bp->fp[i].cl_id;
  4093. /* reset xstorm per client statistics */
  4094. offset = BAR_XSTRORM_INTMEM +
  4095. XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
  4096. for (j = 0;
  4097. j < sizeof(struct xstorm_per_client_stats) / 4; j++)
  4098. REG_WR(bp, offset + j*4, 0);
  4099. /* reset tstorm per client statistics */
  4100. offset = BAR_TSTRORM_INTMEM +
  4101. TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
  4102. for (j = 0;
  4103. j < sizeof(struct tstorm_per_client_stats) / 4; j++)
  4104. REG_WR(bp, offset + j*4, 0);
  4105. /* reset ustorm per client statistics */
  4106. offset = BAR_USTRORM_INTMEM +
  4107. USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
  4108. for (j = 0;
  4109. j < sizeof(struct ustorm_per_client_stats) / 4; j++)
  4110. REG_WR(bp, offset + j*4, 0);
  4111. }
  4112. /* Init statistics related context */
  4113. stats_flags.collect_eth = 1;
  4114. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func),
  4115. ((u32 *)&stats_flags)[0]);
  4116. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4,
  4117. ((u32 *)&stats_flags)[1]);
  4118. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func),
  4119. ((u32 *)&stats_flags)[0]);
  4120. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4,
  4121. ((u32 *)&stats_flags)[1]);
  4122. REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func),
  4123. ((u32 *)&stats_flags)[0]);
  4124. REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4,
  4125. ((u32 *)&stats_flags)[1]);
  4126. REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func),
  4127. ((u32 *)&stats_flags)[0]);
  4128. REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4,
  4129. ((u32 *)&stats_flags)[1]);
  4130. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4131. XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
  4132. U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
  4133. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4134. XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
  4135. U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
  4136. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4137. TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
  4138. U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
  4139. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4140. TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
  4141. U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
  4142. REG_WR(bp, BAR_USTRORM_INTMEM +
  4143. USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
  4144. U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
  4145. REG_WR(bp, BAR_USTRORM_INTMEM +
  4146. USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
  4147. U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
  4148. if (CHIP_IS_E1H(bp)) {
  4149. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET,
  4150. IS_E1HMF(bp));
  4151. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET,
  4152. IS_E1HMF(bp));
  4153. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET,
  4154. IS_E1HMF(bp));
  4155. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET,
  4156. IS_E1HMF(bp));
  4157. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func),
  4158. bp->e1hov);
  4159. }
  4160. /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */
  4161. max_agg_size =
  4162. min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) *
  4163. SGE_PAGE_SIZE * PAGES_PER_SGE),
  4164. (u32)0xffff);
  4165. for_each_rx_queue(bp, i) {
  4166. struct bnx2x_fastpath *fp = &bp->fp[i];
  4167. REG_WR(bp, BAR_USTRORM_INTMEM +
  4168. USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id),
  4169. U64_LO(fp->rx_comp_mapping));
  4170. REG_WR(bp, BAR_USTRORM_INTMEM +
  4171. USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4,
  4172. U64_HI(fp->rx_comp_mapping));
  4173. REG_WR16(bp, BAR_USTRORM_INTMEM +
  4174. USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id),
  4175. max_agg_size);
  4176. }
  4177. /* dropless flow control */
  4178. if (CHIP_IS_E1H(bp)) {
  4179. struct ustorm_eth_rx_pause_data_e1h rx_pause = {0};
  4180. rx_pause.bd_thr_low = 250;
  4181. rx_pause.cqe_thr_low = 250;
  4182. rx_pause.cos = 1;
  4183. rx_pause.sge_thr_low = 0;
  4184. rx_pause.bd_thr_high = 350;
  4185. rx_pause.cqe_thr_high = 350;
  4186. rx_pause.sge_thr_high = 0;
  4187. for_each_rx_queue(bp, i) {
  4188. struct bnx2x_fastpath *fp = &bp->fp[i];
  4189. if (!fp->disable_tpa) {
  4190. rx_pause.sge_thr_low = 150;
  4191. rx_pause.sge_thr_high = 250;
  4192. }
  4193. offset = BAR_USTRORM_INTMEM +
  4194. USTORM_ETH_RING_PAUSE_DATA_OFFSET(port,
  4195. fp->cl_id);
  4196. for (j = 0;
  4197. j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4;
  4198. j++)
  4199. REG_WR(bp, offset + j*4,
  4200. ((u32 *)&rx_pause)[j]);
  4201. }
  4202. }
  4203. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  4204. /* Init rate shaping and fairness contexts */
  4205. if (IS_E1HMF(bp)) {
  4206. int vn;
  4207. /* During init there is no active link
  4208. Until link is up, set link rate to 10Gbps */
  4209. bp->link_vars.line_speed = SPEED_10000;
  4210. bnx2x_init_port_minmax(bp);
  4211. bnx2x_calc_vn_weight_sum(bp);
  4212. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  4213. bnx2x_init_vn_minmax(bp, 2*vn + port);
  4214. /* Enable rate shaping and fairness */
  4215. bp->cmng.flags.cmng_enables =
  4216. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  4217. if (bp->vn_weight_sum)
  4218. bp->cmng.flags.cmng_enables |=
  4219. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  4220. else
  4221. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  4222. " fairness will be disabled\n");
  4223. } else {
  4224. /* rate shaping and fairness are disabled */
  4225. DP(NETIF_MSG_IFUP,
  4226. "single function mode minmax will be disabled\n");
  4227. }
  4228. /* Store it to internal memory */
  4229. if (bp->port.pmf)
  4230. for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
  4231. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4232. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4,
  4233. ((u32 *)(&bp->cmng))[i]);
  4234. }
  4235. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4236. {
  4237. switch (load_code) {
  4238. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4239. bnx2x_init_internal_common(bp);
  4240. /* no break */
  4241. case FW_MSG_CODE_DRV_LOAD_PORT:
  4242. bnx2x_init_internal_port(bp);
  4243. /* no break */
  4244. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4245. bnx2x_init_internal_func(bp);
  4246. break;
  4247. default:
  4248. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4249. break;
  4250. }
  4251. }
  4252. static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4253. {
  4254. int i;
  4255. for_each_queue(bp, i) {
  4256. struct bnx2x_fastpath *fp = &bp->fp[i];
  4257. fp->bp = bp;
  4258. fp->state = BNX2X_FP_STATE_CLOSED;
  4259. fp->index = i;
  4260. fp->cl_id = BP_L_ID(bp) + i;
  4261. fp->sb_id = fp->cl_id;
  4262. DP(NETIF_MSG_IFUP,
  4263. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n",
  4264. i, bp, fp->status_blk, fp->cl_id, fp->sb_id);
  4265. bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping,
  4266. fp->sb_id);
  4267. bnx2x_update_fpsb_idx(fp);
  4268. }
  4269. /* ensure status block indices were read */
  4270. rmb();
  4271. bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping,
  4272. DEF_SB_ID);
  4273. bnx2x_update_dsb_idx(bp);
  4274. bnx2x_update_coalesce(bp);
  4275. bnx2x_init_rx_rings(bp);
  4276. bnx2x_init_tx_ring(bp);
  4277. bnx2x_init_sp_ring(bp);
  4278. bnx2x_init_context(bp);
  4279. bnx2x_init_internal(bp, load_code);
  4280. bnx2x_init_ind_table(bp);
  4281. bnx2x_stats_init(bp);
  4282. /* At this point, we are ready for interrupts */
  4283. atomic_set(&bp->intr_sem, 0);
  4284. /* flush all before enabling interrupts */
  4285. mb();
  4286. mmiowb();
  4287. bnx2x_int_enable(bp);
  4288. }
  4289. /* end of nic init */
  4290. /*
  4291. * gzip service functions
  4292. */
  4293. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4294. {
  4295. bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE,
  4296. &bp->gunzip_mapping);
  4297. if (bp->gunzip_buf == NULL)
  4298. goto gunzip_nomem1;
  4299. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4300. if (bp->strm == NULL)
  4301. goto gunzip_nomem2;
  4302. bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
  4303. GFP_KERNEL);
  4304. if (bp->strm->workspace == NULL)
  4305. goto gunzip_nomem3;
  4306. return 0;
  4307. gunzip_nomem3:
  4308. kfree(bp->strm);
  4309. bp->strm = NULL;
  4310. gunzip_nomem2:
  4311. pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
  4312. bp->gunzip_mapping);
  4313. bp->gunzip_buf = NULL;
  4314. gunzip_nomem1:
  4315. printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for"
  4316. " un-compression\n", bp->dev->name);
  4317. return -ENOMEM;
  4318. }
  4319. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4320. {
  4321. kfree(bp->strm->workspace);
  4322. kfree(bp->strm);
  4323. bp->strm = NULL;
  4324. if (bp->gunzip_buf) {
  4325. pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
  4326. bp->gunzip_mapping);
  4327. bp->gunzip_buf = NULL;
  4328. }
  4329. }
  4330. static int bnx2x_gunzip(struct bnx2x *bp, u8 *zbuf, int len)
  4331. {
  4332. int n, rc;
  4333. /* check gzip header */
  4334. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED))
  4335. return -EINVAL;
  4336. n = 10;
  4337. #define FNAME 0x8
  4338. if (zbuf[3] & FNAME)
  4339. while ((zbuf[n++] != 0) && (n < len));
  4340. bp->strm->next_in = zbuf + n;
  4341. bp->strm->avail_in = len - n;
  4342. bp->strm->next_out = bp->gunzip_buf;
  4343. bp->strm->avail_out = FW_BUF_SIZE;
  4344. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4345. if (rc != Z_OK)
  4346. return rc;
  4347. rc = zlib_inflate(bp->strm, Z_FINISH);
  4348. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4349. printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
  4350. bp->dev->name, bp->strm->msg);
  4351. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4352. if (bp->gunzip_outlen & 0x3)
  4353. printk(KERN_ERR PFX "%s: Firmware decompression error:"
  4354. " gunzip_outlen (%d) not aligned\n",
  4355. bp->dev->name, bp->gunzip_outlen);
  4356. bp->gunzip_outlen >>= 2;
  4357. zlib_inflateEnd(bp->strm);
  4358. if (rc == Z_STREAM_END)
  4359. return 0;
  4360. return rc;
  4361. }
  4362. /* nic load/unload */
  4363. /*
  4364. * General service functions
  4365. */
  4366. /* send a NIG loopback debug packet */
  4367. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4368. {
  4369. u32 wb_write[3];
  4370. /* Ethernet source and destination addresses */
  4371. wb_write[0] = 0x55555555;
  4372. wb_write[1] = 0x55555555;
  4373. wb_write[2] = 0x20; /* SOP */
  4374. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4375. /* NON-IP protocol */
  4376. wb_write[0] = 0x09000000;
  4377. wb_write[1] = 0x55555555;
  4378. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4379. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4380. }
  4381. /* some of the internal memories
  4382. * are not directly readable from the driver
  4383. * to test them we send debug packets
  4384. */
  4385. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4386. {
  4387. int factor;
  4388. int count, i;
  4389. u32 val = 0;
  4390. if (CHIP_REV_IS_FPGA(bp))
  4391. factor = 120;
  4392. else if (CHIP_REV_IS_EMUL(bp))
  4393. factor = 200;
  4394. else
  4395. factor = 1;
  4396. DP(NETIF_MSG_HW, "start part1\n");
  4397. /* Disable inputs of parser neighbor blocks */
  4398. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4399. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4400. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4401. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4402. /* Write 0 to parser credits for CFC search request */
  4403. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4404. /* send Ethernet packet */
  4405. bnx2x_lb_pckt(bp);
  4406. /* TODO do i reset NIG statistic? */
  4407. /* Wait until NIG register shows 1 packet of size 0x10 */
  4408. count = 1000 * factor;
  4409. while (count) {
  4410. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4411. val = *bnx2x_sp(bp, wb_data[0]);
  4412. if (val == 0x10)
  4413. break;
  4414. msleep(10);
  4415. count--;
  4416. }
  4417. if (val != 0x10) {
  4418. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4419. return -1;
  4420. }
  4421. /* Wait until PRS register shows 1 packet */
  4422. count = 1000 * factor;
  4423. while (count) {
  4424. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4425. if (val == 1)
  4426. break;
  4427. msleep(10);
  4428. count--;
  4429. }
  4430. if (val != 0x1) {
  4431. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4432. return -2;
  4433. }
  4434. /* Reset and init BRB, PRS */
  4435. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4436. msleep(50);
  4437. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4438. msleep(50);
  4439. bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
  4440. bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
  4441. DP(NETIF_MSG_HW, "part2\n");
  4442. /* Disable inputs of parser neighbor blocks */
  4443. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4444. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4445. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4446. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4447. /* Write 0 to parser credits for CFC search request */
  4448. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4449. /* send 10 Ethernet packets */
  4450. for (i = 0; i < 10; i++)
  4451. bnx2x_lb_pckt(bp);
  4452. /* Wait until NIG register shows 10 + 1
  4453. packets of size 11*0x10 = 0xb0 */
  4454. count = 1000 * factor;
  4455. while (count) {
  4456. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4457. val = *bnx2x_sp(bp, wb_data[0]);
  4458. if (val == 0xb0)
  4459. break;
  4460. msleep(10);
  4461. count--;
  4462. }
  4463. if (val != 0xb0) {
  4464. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4465. return -3;
  4466. }
  4467. /* Wait until PRS register shows 2 packets */
  4468. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4469. if (val != 2)
  4470. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4471. /* Write 1 to parser credits for CFC search request */
  4472. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4473. /* Wait until PRS register shows 3 packets */
  4474. msleep(10 * factor);
  4475. /* Wait until NIG register shows 1 packet of size 0x10 */
  4476. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4477. if (val != 3)
  4478. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4479. /* clear NIG EOP FIFO */
  4480. for (i = 0; i < 11; i++)
  4481. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4482. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4483. if (val != 1) {
  4484. BNX2X_ERR("clear of NIG failed\n");
  4485. return -4;
  4486. }
  4487. /* Reset and init BRB, PRS, NIG */
  4488. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4489. msleep(50);
  4490. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4491. msleep(50);
  4492. bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
  4493. bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
  4494. #ifndef BCM_ISCSI
  4495. /* set NIC mode */
  4496. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4497. #endif
  4498. /* Enable inputs of parser neighbor blocks */
  4499. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4500. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4501. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4502. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4503. DP(NETIF_MSG_HW, "done\n");
  4504. return 0; /* OK */
  4505. }
  4506. static void enable_blocks_attention(struct bnx2x *bp)
  4507. {
  4508. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4509. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4510. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4511. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4512. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4513. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4514. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4515. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4516. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4517. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4518. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4519. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4520. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4521. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4522. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4523. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4524. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4525. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4526. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4527. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4528. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4529. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4530. if (CHIP_REV_IS_FPGA(bp))
  4531. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4532. else
  4533. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4534. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4535. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4536. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4537. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4538. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
  4539. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4540. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4541. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4542. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */
  4543. }
  4544. static void bnx2x_reset_common(struct bnx2x *bp)
  4545. {
  4546. /* reset_common */
  4547. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4548. 0xd3ffff7f);
  4549. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403);
  4550. }
  4551. static int bnx2x_init_common(struct bnx2x *bp)
  4552. {
  4553. u32 val, i;
  4554. DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp));
  4555. bnx2x_reset_common(bp);
  4556. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  4557. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc);
  4558. bnx2x_init_block(bp, MISC_COMMON_START, MISC_COMMON_END);
  4559. if (CHIP_IS_E1H(bp))
  4560. REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp));
  4561. REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100);
  4562. msleep(30);
  4563. REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0);
  4564. bnx2x_init_block(bp, PXP_COMMON_START, PXP_COMMON_END);
  4565. if (CHIP_IS_E1(bp)) {
  4566. /* enable HW interrupt from PXP on USDM overflow
  4567. bit 16 on INT_MASK_0 */
  4568. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4569. }
  4570. bnx2x_init_block(bp, PXP2_COMMON_START, PXP2_COMMON_END);
  4571. bnx2x_init_pxp(bp);
  4572. #ifdef __BIG_ENDIAN
  4573. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  4574. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  4575. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  4576. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  4577. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  4578. /* make sure this value is 0 */
  4579. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  4580. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  4581. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  4582. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  4583. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  4584. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  4585. #endif
  4586. REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2);
  4587. #ifdef BCM_ISCSI
  4588. REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5);
  4589. REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5);
  4590. REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5);
  4591. #endif
  4592. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  4593. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  4594. /* let the HW do it's magic ... */
  4595. msleep(100);
  4596. /* finish PXP init */
  4597. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  4598. if (val != 1) {
  4599. BNX2X_ERR("PXP2 CFG failed\n");
  4600. return -EBUSY;
  4601. }
  4602. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  4603. if (val != 1) {
  4604. BNX2X_ERR("PXP2 RD_INIT failed\n");
  4605. return -EBUSY;
  4606. }
  4607. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  4608. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  4609. bnx2x_init_block(bp, DMAE_COMMON_START, DMAE_COMMON_END);
  4610. /* clean the DMAE memory */
  4611. bp->dmae_ready = 1;
  4612. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8);
  4613. bnx2x_init_block(bp, TCM_COMMON_START, TCM_COMMON_END);
  4614. bnx2x_init_block(bp, UCM_COMMON_START, UCM_COMMON_END);
  4615. bnx2x_init_block(bp, CCM_COMMON_START, CCM_COMMON_END);
  4616. bnx2x_init_block(bp, XCM_COMMON_START, XCM_COMMON_END);
  4617. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  4618. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  4619. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  4620. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  4621. bnx2x_init_block(bp, QM_COMMON_START, QM_COMMON_END);
  4622. /* soft reset pulse */
  4623. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  4624. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  4625. #ifdef BCM_ISCSI
  4626. bnx2x_init_block(bp, TIMERS_COMMON_START, TIMERS_COMMON_END);
  4627. #endif
  4628. bnx2x_init_block(bp, DQ_COMMON_START, DQ_COMMON_END);
  4629. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT);
  4630. if (!CHIP_REV_IS_SLOW(bp)) {
  4631. /* enable hw interrupt from doorbell Q */
  4632. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4633. }
  4634. bnx2x_init_block(bp, BRB1_COMMON_START, BRB1_COMMON_END);
  4635. bnx2x_init_block(bp, PRS_COMMON_START, PRS_COMMON_END);
  4636. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  4637. /* set NIC mode */
  4638. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4639. if (CHIP_IS_E1H(bp))
  4640. REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp));
  4641. bnx2x_init_block(bp, TSDM_COMMON_START, TSDM_COMMON_END);
  4642. bnx2x_init_block(bp, CSDM_COMMON_START, CSDM_COMMON_END);
  4643. bnx2x_init_block(bp, USDM_COMMON_START, USDM_COMMON_END);
  4644. bnx2x_init_block(bp, XSDM_COMMON_START, XSDM_COMMON_END);
  4645. bnx2x_init_fill(bp, TSTORM_INTMEM_ADDR, 0, STORM_INTMEM_SIZE(bp));
  4646. bnx2x_init_fill(bp, USTORM_INTMEM_ADDR, 0, STORM_INTMEM_SIZE(bp));
  4647. bnx2x_init_fill(bp, CSTORM_INTMEM_ADDR, 0, STORM_INTMEM_SIZE(bp));
  4648. bnx2x_init_fill(bp, XSTORM_INTMEM_ADDR, 0, STORM_INTMEM_SIZE(bp));
  4649. bnx2x_init_block(bp, TSEM_COMMON_START, TSEM_COMMON_END);
  4650. bnx2x_init_block(bp, USEM_COMMON_START, USEM_COMMON_END);
  4651. bnx2x_init_block(bp, CSEM_COMMON_START, CSEM_COMMON_END);
  4652. bnx2x_init_block(bp, XSEM_COMMON_START, XSEM_COMMON_END);
  4653. /* sync semi rtc */
  4654. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4655. 0x80000000);
  4656. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  4657. 0x80000000);
  4658. bnx2x_init_block(bp, UPB_COMMON_START, UPB_COMMON_END);
  4659. bnx2x_init_block(bp, XPB_COMMON_START, XPB_COMMON_END);
  4660. bnx2x_init_block(bp, PBF_COMMON_START, PBF_COMMON_END);
  4661. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  4662. for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) {
  4663. REG_WR(bp, i, 0xc0cac01a);
  4664. /* TODO: replace with something meaningful */
  4665. }
  4666. bnx2x_init_block(bp, SRCH_COMMON_START, SRCH_COMMON_END);
  4667. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  4668. if (sizeof(union cdu_context) != 1024)
  4669. /* we currently assume that a context is 1024 bytes */
  4670. printk(KERN_ALERT PFX "please adjust the size of"
  4671. " cdu_context(%ld)\n", (long)sizeof(union cdu_context));
  4672. bnx2x_init_block(bp, CDU_COMMON_START, CDU_COMMON_END);
  4673. val = (4 << 24) + (0 << 12) + 1024;
  4674. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  4675. if (CHIP_IS_E1(bp)) {
  4676. /* !!! fix pxp client crdit until excel update */
  4677. REG_WR(bp, CDU_REG_CDU_DEBUG, 0x264);
  4678. REG_WR(bp, CDU_REG_CDU_DEBUG, 0);
  4679. }
  4680. bnx2x_init_block(bp, CFC_COMMON_START, CFC_COMMON_END);
  4681. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  4682. /* enable context validation interrupt from CFC */
  4683. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4684. /* set the thresholds to prevent CFC/CDU race */
  4685. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  4686. bnx2x_init_block(bp, HC_COMMON_START, HC_COMMON_END);
  4687. bnx2x_init_block(bp, MISC_AEU_COMMON_START, MISC_AEU_COMMON_END);
  4688. /* PXPCS COMMON comes here */
  4689. /* Reset PCIE errors for debug */
  4690. REG_WR(bp, 0x2814, 0xffffffff);
  4691. REG_WR(bp, 0x3820, 0xffffffff);
  4692. /* EMAC0 COMMON comes here */
  4693. /* EMAC1 COMMON comes here */
  4694. /* DBU COMMON comes here */
  4695. /* DBG COMMON comes here */
  4696. bnx2x_init_block(bp, NIG_COMMON_START, NIG_COMMON_END);
  4697. if (CHIP_IS_E1H(bp)) {
  4698. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp));
  4699. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp));
  4700. }
  4701. if (CHIP_REV_IS_SLOW(bp))
  4702. msleep(200);
  4703. /* finish CFC init */
  4704. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  4705. if (val != 1) {
  4706. BNX2X_ERR("CFC LL_INIT failed\n");
  4707. return -EBUSY;
  4708. }
  4709. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  4710. if (val != 1) {
  4711. BNX2X_ERR("CFC AC_INIT failed\n");
  4712. return -EBUSY;
  4713. }
  4714. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  4715. if (val != 1) {
  4716. BNX2X_ERR("CFC CAM_INIT failed\n");
  4717. return -EBUSY;
  4718. }
  4719. REG_WR(bp, CFC_REG_DEBUG0, 0);
  4720. /* read NIG statistic
  4721. to see if this is our first up since powerup */
  4722. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4723. val = *bnx2x_sp(bp, wb_data[0]);
  4724. /* do internal memory self test */
  4725. if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) {
  4726. BNX2X_ERR("internal mem self test failed\n");
  4727. return -EBUSY;
  4728. }
  4729. switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
  4730. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
  4731. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  4732. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  4733. bp->port.need_hw_lock = 1;
  4734. break;
  4735. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  4736. /* Fan failure is indicated by SPIO 5 */
  4737. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  4738. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  4739. /* set to active low mode */
  4740. val = REG_RD(bp, MISC_REG_SPIO_INT);
  4741. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  4742. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  4743. REG_WR(bp, MISC_REG_SPIO_INT, val);
  4744. /* enable interrupt to signal the IGU */
  4745. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  4746. val |= (1 << MISC_REGISTERS_SPIO_5);
  4747. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  4748. break;
  4749. default:
  4750. break;
  4751. }
  4752. /* clear PXP2 attentions */
  4753. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  4754. enable_blocks_attention(bp);
  4755. if (!BP_NOMCP(bp)) {
  4756. bnx2x_acquire_phy_lock(bp);
  4757. bnx2x_common_init_phy(bp, bp->common.shmem_base);
  4758. bnx2x_release_phy_lock(bp);
  4759. } else
  4760. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  4761. return 0;
  4762. }
  4763. static int bnx2x_init_port(struct bnx2x *bp)
  4764. {
  4765. int port = BP_PORT(bp);
  4766. u32 low, high;
  4767. u32 val;
  4768. DP(BNX2X_MSG_MCP, "starting port init port %x\n", port);
  4769. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  4770. /* Port PXP comes here */
  4771. /* Port PXP2 comes here */
  4772. #ifdef BCM_ISCSI
  4773. /* Port0 1
  4774. * Port1 385 */
  4775. i++;
  4776. wb_write[0] = ONCHIP_ADDR1(bp->timers_mapping);
  4777. wb_write[1] = ONCHIP_ADDR2(bp->timers_mapping);
  4778. REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
  4779. REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i));
  4780. /* Port0 2
  4781. * Port1 386 */
  4782. i++;
  4783. wb_write[0] = ONCHIP_ADDR1(bp->qm_mapping);
  4784. wb_write[1] = ONCHIP_ADDR2(bp->qm_mapping);
  4785. REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
  4786. REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i));
  4787. /* Port0 3
  4788. * Port1 387 */
  4789. i++;
  4790. wb_write[0] = ONCHIP_ADDR1(bp->t1_mapping);
  4791. wb_write[1] = ONCHIP_ADDR2(bp->t1_mapping);
  4792. REG_WR_DMAE(bp, PXP2_REG_RQ_ONCHIP_AT + i*8, wb_write, 2);
  4793. REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i));
  4794. #endif
  4795. /* Port CMs come here */
  4796. bnx2x_init_block(bp, (port ? XCM_PORT1_START : XCM_PORT0_START),
  4797. (port ? XCM_PORT1_END : XCM_PORT0_END));
  4798. /* Port QM comes here */
  4799. #ifdef BCM_ISCSI
  4800. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + func*4, 1024/64*20);
  4801. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + func*4, 31);
  4802. bnx2x_init_block(bp, func ? TIMERS_PORT1_START : TIMERS_PORT0_START,
  4803. func ? TIMERS_PORT1_END : TIMERS_PORT0_END);
  4804. #endif
  4805. /* Port DQ comes here */
  4806. bnx2x_init_block(bp, (port ? BRB1_PORT1_START : BRB1_PORT0_START),
  4807. (port ? BRB1_PORT1_END : BRB1_PORT0_END));
  4808. if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) {
  4809. /* no pause for emulation and FPGA */
  4810. low = 0;
  4811. high = 513;
  4812. } else {
  4813. if (IS_E1HMF(bp))
  4814. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  4815. else if (bp->dev->mtu > 4096) {
  4816. if (bp->flags & ONE_PORT_FLAG)
  4817. low = 160;
  4818. else {
  4819. val = bp->dev->mtu;
  4820. /* (24*1024 + val*4)/256 */
  4821. low = 96 + (val/64) + ((val % 64) ? 1 : 0);
  4822. }
  4823. } else
  4824. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  4825. high = low + 56; /* 14*1024/256 */
  4826. }
  4827. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  4828. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  4829. /* Port PRS comes here */
  4830. /* Port TSDM comes here */
  4831. /* Port CSDM comes here */
  4832. /* Port USDM comes here */
  4833. /* Port XSDM comes here */
  4834. bnx2x_init_block(bp, port ? TSEM_PORT1_START : TSEM_PORT0_START,
  4835. port ? TSEM_PORT1_END : TSEM_PORT0_END);
  4836. bnx2x_init_block(bp, port ? USEM_PORT1_START : USEM_PORT0_START,
  4837. port ? USEM_PORT1_END : USEM_PORT0_END);
  4838. bnx2x_init_block(bp, port ? CSEM_PORT1_START : CSEM_PORT0_START,
  4839. port ? CSEM_PORT1_END : CSEM_PORT0_END);
  4840. bnx2x_init_block(bp, port ? XSEM_PORT1_START : XSEM_PORT0_START,
  4841. port ? XSEM_PORT1_END : XSEM_PORT0_END);
  4842. /* Port UPB comes here */
  4843. /* Port XPB comes here */
  4844. bnx2x_init_block(bp, port ? PBF_PORT1_START : PBF_PORT0_START,
  4845. port ? PBF_PORT1_END : PBF_PORT0_END);
  4846. /* configure PBF to work without PAUSE mtu 9000 */
  4847. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  4848. /* update threshold */
  4849. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  4850. /* update init credit */
  4851. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  4852. /* probe changes */
  4853. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  4854. msleep(5);
  4855. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  4856. #ifdef BCM_ISCSI
  4857. /* tell the searcher where the T2 table is */
  4858. REG_WR(bp, SRC_REG_COUNTFREE0 + func*4, 16*1024/64);
  4859. wb_write[0] = U64_LO(bp->t2_mapping);
  4860. wb_write[1] = U64_HI(bp->t2_mapping);
  4861. REG_WR_DMAE(bp, SRC_REG_FIRSTFREE0 + func*4, wb_write, 2);
  4862. wb_write[0] = U64_LO((u64)bp->t2_mapping + 16*1024 - 64);
  4863. wb_write[1] = U64_HI((u64)bp->t2_mapping + 16*1024 - 64);
  4864. REG_WR_DMAE(bp, SRC_REG_LASTFREE0 + func*4, wb_write, 2);
  4865. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + func*4, 10);
  4866. /* Port SRCH comes here */
  4867. #endif
  4868. /* Port CDU comes here */
  4869. /* Port CFC comes here */
  4870. if (CHIP_IS_E1(bp)) {
  4871. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  4872. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  4873. }
  4874. bnx2x_init_block(bp, port ? HC_PORT1_START : HC_PORT0_START,
  4875. port ? HC_PORT1_END : HC_PORT0_END);
  4876. bnx2x_init_block(bp, port ? MISC_AEU_PORT1_START :
  4877. MISC_AEU_PORT0_START,
  4878. port ? MISC_AEU_PORT1_END : MISC_AEU_PORT0_END);
  4879. /* init aeu_mask_attn_func_0/1:
  4880. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  4881. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  4882. * bits 4-7 are used for "per vn group attention" */
  4883. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4,
  4884. (IS_E1HMF(bp) ? 0xF7 : 0x7));
  4885. /* Port PXPCS comes here */
  4886. /* Port EMAC0 comes here */
  4887. /* Port EMAC1 comes here */
  4888. /* Port DBU comes here */
  4889. /* Port DBG comes here */
  4890. bnx2x_init_block(bp, port ? NIG_PORT1_START : NIG_PORT0_START,
  4891. port ? NIG_PORT1_END : NIG_PORT0_END);
  4892. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  4893. if (CHIP_IS_E1H(bp)) {
  4894. /* 0x2 disable e1hov, 0x1 enable */
  4895. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  4896. (IS_E1HMF(bp) ? 0x1 : 0x2));
  4897. /* support pause requests from USDM, TSDM and BRB */
  4898. REG_WR(bp, NIG_REG_LLFC_EGRESS_SRC_ENABLE_0 + port*4, 0x7);
  4899. {
  4900. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  4901. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  4902. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  4903. }
  4904. }
  4905. /* Port MCP comes here */
  4906. /* Port DMAE comes here */
  4907. switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
  4908. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  4909. {
  4910. u32 swap_val, swap_override, aeu_gpio_mask, offset;
  4911. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  4912. MISC_REGISTERS_GPIO_INPUT_HI_Z, port);
  4913. /* The GPIO should be swapped if the swap register is
  4914. set and active */
  4915. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  4916. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  4917. /* Select function upon port-swap configuration */
  4918. if (port == 0) {
  4919. offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
  4920. aeu_gpio_mask = (swap_val && swap_override) ?
  4921. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
  4922. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
  4923. } else {
  4924. offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
  4925. aeu_gpio_mask = (swap_val && swap_override) ?
  4926. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
  4927. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
  4928. }
  4929. val = REG_RD(bp, offset);
  4930. /* add GPIO3 to group */
  4931. val |= aeu_gpio_mask;
  4932. REG_WR(bp, offset, val);
  4933. }
  4934. break;
  4935. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  4936. /* add SPIO 5 to group 0 */
  4937. val = REG_RD(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4938. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  4939. REG_WR(bp, MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0, val);
  4940. break;
  4941. default:
  4942. break;
  4943. }
  4944. bnx2x__link_reset(bp);
  4945. return 0;
  4946. }
  4947. #define ILT_PER_FUNC (768/2)
  4948. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  4949. /* the phys address is shifted right 12 bits and has an added
  4950. 1=valid bit added to the 53rd bit
  4951. then since this is a wide register(TM)
  4952. we split it into two 32 bit writes
  4953. */
  4954. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  4955. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  4956. #define PXP_ONE_ILT(x) (((x) << 10) | x)
  4957. #define PXP_ILT_RANGE(f, l) (((l) << 10) | f)
  4958. #define CNIC_ILT_LINES 0
  4959. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  4960. {
  4961. int reg;
  4962. if (CHIP_IS_E1H(bp))
  4963. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  4964. else /* E1 */
  4965. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  4966. bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
  4967. }
  4968. static int bnx2x_init_func(struct bnx2x *bp)
  4969. {
  4970. int port = BP_PORT(bp);
  4971. int func = BP_FUNC(bp);
  4972. u32 addr, val;
  4973. int i;
  4974. DP(BNX2X_MSG_MCP, "starting func init func %x\n", func);
  4975. /* set MSI reconfigure capability */
  4976. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  4977. val = REG_RD(bp, addr);
  4978. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  4979. REG_WR(bp, addr, val);
  4980. i = FUNC_ILT_BASE(func);
  4981. bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context));
  4982. if (CHIP_IS_E1H(bp)) {
  4983. REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i);
  4984. REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES);
  4985. } else /* E1 */
  4986. REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4,
  4987. PXP_ILT_RANGE(i, i + CNIC_ILT_LINES));
  4988. if (CHIP_IS_E1H(bp)) {
  4989. for (i = 0; i < 9; i++)
  4990. bnx2x_init_block(bp,
  4991. cm_start[func][i], cm_end[func][i]);
  4992. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  4993. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov);
  4994. }
  4995. /* HC init per function */
  4996. if (CHIP_IS_E1H(bp)) {
  4997. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  4998. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  4999. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5000. }
  5001. bnx2x_init_block(bp, hc_limits[func][0], hc_limits[func][1]);
  5002. /* Reset PCIE errors for debug */
  5003. REG_WR(bp, 0x2114, 0xffffffff);
  5004. REG_WR(bp, 0x2120, 0xffffffff);
  5005. return 0;
  5006. }
  5007. static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
  5008. {
  5009. int i, rc = 0;
  5010. DP(BNX2X_MSG_MCP, "function %d load_code %x\n",
  5011. BP_FUNC(bp), load_code);
  5012. bp->dmae_ready = 0;
  5013. mutex_init(&bp->dmae_mutex);
  5014. bnx2x_gunzip_init(bp);
  5015. switch (load_code) {
  5016. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5017. rc = bnx2x_init_common(bp);
  5018. if (rc)
  5019. goto init_hw_err;
  5020. /* no break */
  5021. case FW_MSG_CODE_DRV_LOAD_PORT:
  5022. bp->dmae_ready = 1;
  5023. rc = bnx2x_init_port(bp);
  5024. if (rc)
  5025. goto init_hw_err;
  5026. /* no break */
  5027. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5028. bp->dmae_ready = 1;
  5029. rc = bnx2x_init_func(bp);
  5030. if (rc)
  5031. goto init_hw_err;
  5032. break;
  5033. default:
  5034. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5035. break;
  5036. }
  5037. if (!BP_NOMCP(bp)) {
  5038. int func = BP_FUNC(bp);
  5039. bp->fw_drv_pulse_wr_seq =
  5040. (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) &
  5041. DRV_PULSE_SEQ_MASK);
  5042. bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
  5043. DP(BNX2X_MSG_MCP, "drv_pulse 0x%x func_stx 0x%x\n",
  5044. bp->fw_drv_pulse_wr_seq, bp->func_stx);
  5045. } else
  5046. bp->func_stx = 0;
  5047. /* this needs to be done before gunzip end */
  5048. bnx2x_zero_def_sb(bp);
  5049. for_each_queue(bp, i)
  5050. bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
  5051. init_hw_err:
  5052. bnx2x_gunzip_end(bp);
  5053. return rc;
  5054. }
  5055. /* send the MCP a request, block until there is a reply */
  5056. static u32 bnx2x_fw_command(struct bnx2x *bp, u32 command)
  5057. {
  5058. int func = BP_FUNC(bp);
  5059. u32 seq = ++bp->fw_seq;
  5060. u32 rc = 0;
  5061. u32 cnt = 1;
  5062. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  5063. SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq));
  5064. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
  5065. do {
  5066. /* let the FW do it's magic ... */
  5067. msleep(delay);
  5068. rc = SHMEM_RD(bp, func_mb[func].fw_mb_header);
  5069. /* Give the FW up to 2 second (200*10ms) */
  5070. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 200));
  5071. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  5072. cnt*delay, rc, seq);
  5073. /* is this a reply to our command? */
  5074. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK)) {
  5075. rc &= FW_MSG_CODE_MASK;
  5076. } else {
  5077. /* FW BUG! */
  5078. BNX2X_ERR("FW failed to respond!\n");
  5079. bnx2x_fw_dump(bp);
  5080. rc = 0;
  5081. }
  5082. return rc;
  5083. }
  5084. static void bnx2x_free_mem(struct bnx2x *bp)
  5085. {
  5086. #define BNX2X_PCI_FREE(x, y, size) \
  5087. do { \
  5088. if (x) { \
  5089. pci_free_consistent(bp->pdev, size, x, y); \
  5090. x = NULL; \
  5091. y = 0; \
  5092. } \
  5093. } while (0)
  5094. #define BNX2X_FREE(x) \
  5095. do { \
  5096. if (x) { \
  5097. vfree(x); \
  5098. x = NULL; \
  5099. } \
  5100. } while (0)
  5101. int i;
  5102. /* fastpath */
  5103. /* Common */
  5104. for_each_queue(bp, i) {
  5105. /* status blocks */
  5106. BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk),
  5107. bnx2x_fp(bp, i, status_blk_mapping),
  5108. sizeof(struct host_status_block) +
  5109. sizeof(struct eth_tx_db_data));
  5110. }
  5111. /* Rx */
  5112. for_each_rx_queue(bp, i) {
  5113. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  5114. BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
  5115. BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring),
  5116. bnx2x_fp(bp, i, rx_desc_mapping),
  5117. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  5118. BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring),
  5119. bnx2x_fp(bp, i, rx_comp_mapping),
  5120. sizeof(struct eth_fast_path_rx_cqe) *
  5121. NUM_RCQ_BD);
  5122. /* SGE ring */
  5123. BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring));
  5124. BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring),
  5125. bnx2x_fp(bp, i, rx_sge_mapping),
  5126. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  5127. }
  5128. /* Tx */
  5129. for_each_tx_queue(bp, i) {
  5130. /* fastpath tx rings: tx_buf tx_desc */
  5131. BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
  5132. BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring),
  5133. bnx2x_fp(bp, i, tx_desc_mapping),
  5134. sizeof(struct eth_tx_bd) * NUM_TX_BD);
  5135. }
  5136. /* end of fastpath */
  5137. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5138. sizeof(struct host_def_status_block));
  5139. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5140. sizeof(struct bnx2x_slowpath));
  5141. #ifdef BCM_ISCSI
  5142. BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024);
  5143. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024);
  5144. BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024);
  5145. BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024);
  5146. #endif
  5147. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5148. #undef BNX2X_PCI_FREE
  5149. #undef BNX2X_KFREE
  5150. }
  5151. static int bnx2x_alloc_mem(struct bnx2x *bp)
  5152. {
  5153. #define BNX2X_PCI_ALLOC(x, y, size) \
  5154. do { \
  5155. x = pci_alloc_consistent(bp->pdev, size, y); \
  5156. if (x == NULL) \
  5157. goto alloc_mem_err; \
  5158. memset(x, 0, size); \
  5159. } while (0)
  5160. #define BNX2X_ALLOC(x, size) \
  5161. do { \
  5162. x = vmalloc(size); \
  5163. if (x == NULL) \
  5164. goto alloc_mem_err; \
  5165. memset(x, 0, size); \
  5166. } while (0)
  5167. int i;
  5168. /* fastpath */
  5169. /* Common */
  5170. for_each_queue(bp, i) {
  5171. bnx2x_fp(bp, i, bp) = bp;
  5172. /* status blocks */
  5173. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk),
  5174. &bnx2x_fp(bp, i, status_blk_mapping),
  5175. sizeof(struct host_status_block) +
  5176. sizeof(struct eth_tx_db_data));
  5177. }
  5178. /* Rx */
  5179. for_each_rx_queue(bp, i) {
  5180. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  5181. BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
  5182. sizeof(struct sw_rx_bd) * NUM_RX_BD);
  5183. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring),
  5184. &bnx2x_fp(bp, i, rx_desc_mapping),
  5185. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  5186. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring),
  5187. &bnx2x_fp(bp, i, rx_comp_mapping),
  5188. sizeof(struct eth_fast_path_rx_cqe) *
  5189. NUM_RCQ_BD);
  5190. /* SGE ring */
  5191. BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring),
  5192. sizeof(struct sw_rx_page) * NUM_RX_SGE);
  5193. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring),
  5194. &bnx2x_fp(bp, i, rx_sge_mapping),
  5195. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  5196. }
  5197. /* Tx */
  5198. for_each_tx_queue(bp, i) {
  5199. bnx2x_fp(bp, i, hw_tx_prods) =
  5200. (void *)(bnx2x_fp(bp, i, status_blk) + 1);
  5201. bnx2x_fp(bp, i, tx_prods_mapping) =
  5202. bnx2x_fp(bp, i, status_blk_mapping) +
  5203. sizeof(struct host_status_block);
  5204. /* fastpath tx rings: tx_buf tx_desc */
  5205. BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
  5206. sizeof(struct sw_tx_bd) * NUM_TX_BD);
  5207. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring),
  5208. &bnx2x_fp(bp, i, tx_desc_mapping),
  5209. sizeof(struct eth_tx_bd) * NUM_TX_BD);
  5210. }
  5211. /* end of fastpath */
  5212. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5213. sizeof(struct host_def_status_block));
  5214. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5215. sizeof(struct bnx2x_slowpath));
  5216. #ifdef BCM_ISCSI
  5217. BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024);
  5218. /* Initialize T1 */
  5219. for (i = 0; i < 64*1024; i += 64) {
  5220. *(u64 *)((char *)bp->t1 + i + 56) = 0x0UL;
  5221. *(u64 *)((char *)bp->t1 + i + 3) = 0x0UL;
  5222. }
  5223. /* allocate searcher T2 table
  5224. we allocate 1/4 of alloc num for T2
  5225. (which is not entered into the ILT) */
  5226. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024);
  5227. /* Initialize T2 */
  5228. for (i = 0; i < 16*1024; i += 64)
  5229. * (u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64;
  5230. /* now fixup the last line in the block to point to the next block */
  5231. *(u64 *)((char *)bp->t2 + 1024*16-8) = bp->t2_mapping;
  5232. /* Timer block array (MAX_CONN*8) phys uncached for now 1024 conns */
  5233. BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024);
  5234. /* QM queues (128*MAX_CONN) */
  5235. BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024);
  5236. #endif
  5237. /* Slow path ring */
  5238. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5239. return 0;
  5240. alloc_mem_err:
  5241. bnx2x_free_mem(bp);
  5242. return -ENOMEM;
  5243. #undef BNX2X_PCI_ALLOC
  5244. #undef BNX2X_ALLOC
  5245. }
  5246. static void bnx2x_free_tx_skbs(struct bnx2x *bp)
  5247. {
  5248. int i;
  5249. for_each_tx_queue(bp, i) {
  5250. struct bnx2x_fastpath *fp = &bp->fp[i];
  5251. u16 bd_cons = fp->tx_bd_cons;
  5252. u16 sw_prod = fp->tx_pkt_prod;
  5253. u16 sw_cons = fp->tx_pkt_cons;
  5254. while (sw_cons != sw_prod) {
  5255. bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons));
  5256. sw_cons++;
  5257. }
  5258. }
  5259. }
  5260. static void bnx2x_free_rx_skbs(struct bnx2x *bp)
  5261. {
  5262. int i, j;
  5263. for_each_rx_queue(bp, j) {
  5264. struct bnx2x_fastpath *fp = &bp->fp[j];
  5265. for (i = 0; i < NUM_RX_BD; i++) {
  5266. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
  5267. struct sk_buff *skb = rx_buf->skb;
  5268. if (skb == NULL)
  5269. continue;
  5270. pci_unmap_single(bp->pdev,
  5271. pci_unmap_addr(rx_buf, mapping),
  5272. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  5273. rx_buf->skb = NULL;
  5274. dev_kfree_skb(skb);
  5275. }
  5276. if (!fp->disable_tpa)
  5277. bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ?
  5278. ETH_MAX_AGGREGATION_QUEUES_E1 :
  5279. ETH_MAX_AGGREGATION_QUEUES_E1H);
  5280. }
  5281. }
  5282. static void bnx2x_free_skbs(struct bnx2x *bp)
  5283. {
  5284. bnx2x_free_tx_skbs(bp);
  5285. bnx2x_free_rx_skbs(bp);
  5286. }
  5287. static void bnx2x_free_msix_irqs(struct bnx2x *bp)
  5288. {
  5289. int i, offset = 1;
  5290. free_irq(bp->msix_table[0].vector, bp->dev);
  5291. DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
  5292. bp->msix_table[0].vector);
  5293. for_each_queue(bp, i) {
  5294. DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq "
  5295. "state %x\n", i, bp->msix_table[i + offset].vector,
  5296. bnx2x_fp(bp, i, state));
  5297. free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]);
  5298. }
  5299. }
  5300. static void bnx2x_free_irq(struct bnx2x *bp)
  5301. {
  5302. if (bp->flags & USING_MSIX_FLAG) {
  5303. bnx2x_free_msix_irqs(bp);
  5304. pci_disable_msix(bp->pdev);
  5305. bp->flags &= ~USING_MSIX_FLAG;
  5306. } else if (bp->flags & USING_MSI_FLAG) {
  5307. free_irq(bp->pdev->irq, bp->dev);
  5308. pci_disable_msi(bp->pdev);
  5309. bp->flags &= ~USING_MSI_FLAG;
  5310. } else
  5311. free_irq(bp->pdev->irq, bp->dev);
  5312. }
  5313. static int bnx2x_enable_msix(struct bnx2x *bp)
  5314. {
  5315. int i, rc, offset = 1;
  5316. int igu_vec = 0;
  5317. bp->msix_table[0].entry = igu_vec;
  5318. DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec);
  5319. for_each_queue(bp, i) {
  5320. igu_vec = BP_L_ID(bp) + offset + i;
  5321. bp->msix_table[i + offset].entry = igu_vec;
  5322. DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
  5323. "(fastpath #%u)\n", i + offset, igu_vec, i);
  5324. }
  5325. rc = pci_enable_msix(bp->pdev, &bp->msix_table[0],
  5326. BNX2X_NUM_QUEUES(bp) + offset);
  5327. if (rc) {
  5328. DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
  5329. return rc;
  5330. }
  5331. bp->flags |= USING_MSIX_FLAG;
  5332. return 0;
  5333. }
  5334. static int bnx2x_req_msix_irqs(struct bnx2x *bp)
  5335. {
  5336. int i, rc, offset = 1;
  5337. rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0,
  5338. bp->dev->name, bp->dev);
  5339. if (rc) {
  5340. BNX2X_ERR("request sp irq failed\n");
  5341. return -EBUSY;
  5342. }
  5343. for_each_queue(bp, i) {
  5344. struct bnx2x_fastpath *fp = &bp->fp[i];
  5345. sprintf(fp->name, "%s.fp%d", bp->dev->name, i);
  5346. rc = request_irq(bp->msix_table[i + offset].vector,
  5347. bnx2x_msix_fp_int, 0, fp->name, fp);
  5348. if (rc) {
  5349. BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc);
  5350. bnx2x_free_msix_irqs(bp);
  5351. return -EBUSY;
  5352. }
  5353. fp->state = BNX2X_FP_STATE_IRQ;
  5354. }
  5355. i = BNX2X_NUM_QUEUES(bp);
  5356. if (is_multi(bp))
  5357. printk(KERN_INFO PFX
  5358. "%s: using MSI-X IRQs: sp %d fp %d - %d\n",
  5359. bp->dev->name, bp->msix_table[0].vector,
  5360. bp->msix_table[offset].vector,
  5361. bp->msix_table[offset + i - 1].vector);
  5362. else
  5363. printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp %d\n",
  5364. bp->dev->name, bp->msix_table[0].vector,
  5365. bp->msix_table[offset + i - 1].vector);
  5366. return 0;
  5367. }
  5368. static int bnx2x_enable_msi(struct bnx2x *bp)
  5369. {
  5370. int rc;
  5371. rc = pci_enable_msi(bp->pdev);
  5372. if (rc) {
  5373. DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
  5374. return -1;
  5375. }
  5376. bp->flags |= USING_MSI_FLAG;
  5377. return 0;
  5378. }
  5379. static int bnx2x_req_irq(struct bnx2x *bp)
  5380. {
  5381. unsigned long flags;
  5382. int rc;
  5383. if (bp->flags & USING_MSI_FLAG)
  5384. flags = 0;
  5385. else
  5386. flags = IRQF_SHARED;
  5387. rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
  5388. bp->dev->name, bp->dev);
  5389. if (!rc)
  5390. bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ;
  5391. return rc;
  5392. }
  5393. static void bnx2x_napi_enable(struct bnx2x *bp)
  5394. {
  5395. int i;
  5396. for_each_rx_queue(bp, i)
  5397. napi_enable(&bnx2x_fp(bp, i, napi));
  5398. }
  5399. static void bnx2x_napi_disable(struct bnx2x *bp)
  5400. {
  5401. int i;
  5402. for_each_rx_queue(bp, i)
  5403. napi_disable(&bnx2x_fp(bp, i, napi));
  5404. }
  5405. static void bnx2x_netif_start(struct bnx2x *bp)
  5406. {
  5407. if (atomic_dec_and_test(&bp->intr_sem)) {
  5408. if (netif_running(bp->dev)) {
  5409. bnx2x_napi_enable(bp);
  5410. bnx2x_int_enable(bp);
  5411. if (bp->state == BNX2X_STATE_OPEN)
  5412. netif_tx_wake_all_queues(bp->dev);
  5413. }
  5414. }
  5415. }
  5416. static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
  5417. {
  5418. bnx2x_int_disable_sync(bp, disable_hw);
  5419. bnx2x_napi_disable(bp);
  5420. netif_tx_disable(bp->dev);
  5421. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  5422. }
  5423. /*
  5424. * Init service functions
  5425. */
  5426. static void bnx2x_set_mac_addr_e1(struct bnx2x *bp, int set)
  5427. {
  5428. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  5429. int port = BP_PORT(bp);
  5430. /* CAM allocation
  5431. * unicasts 0-31:port0 32-63:port1
  5432. * multicast 64-127:port0 128-191:port1
  5433. */
  5434. config->hdr.length = 2;
  5435. config->hdr.offset = port ? 32 : 0;
  5436. config->hdr.client_id = bp->fp->cl_id;
  5437. config->hdr.reserved1 = 0;
  5438. /* primary MAC */
  5439. config->config_table[0].cam_entry.msb_mac_addr =
  5440. swab16(*(u16 *)&bp->dev->dev_addr[0]);
  5441. config->config_table[0].cam_entry.middle_mac_addr =
  5442. swab16(*(u16 *)&bp->dev->dev_addr[2]);
  5443. config->config_table[0].cam_entry.lsb_mac_addr =
  5444. swab16(*(u16 *)&bp->dev->dev_addr[4]);
  5445. config->config_table[0].cam_entry.flags = cpu_to_le16(port);
  5446. if (set)
  5447. config->config_table[0].target_table_entry.flags = 0;
  5448. else
  5449. CAM_INVALIDATE(config->config_table[0]);
  5450. config->config_table[0].target_table_entry.client_id = 0;
  5451. config->config_table[0].target_table_entry.vlan_id = 0;
  5452. DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n",
  5453. (set ? "setting" : "clearing"),
  5454. config->config_table[0].cam_entry.msb_mac_addr,
  5455. config->config_table[0].cam_entry.middle_mac_addr,
  5456. config->config_table[0].cam_entry.lsb_mac_addr);
  5457. /* broadcast */
  5458. config->config_table[1].cam_entry.msb_mac_addr = cpu_to_le16(0xffff);
  5459. config->config_table[1].cam_entry.middle_mac_addr = cpu_to_le16(0xffff);
  5460. config->config_table[1].cam_entry.lsb_mac_addr = cpu_to_le16(0xffff);
  5461. config->config_table[1].cam_entry.flags = cpu_to_le16(port);
  5462. if (set)
  5463. config->config_table[1].target_table_entry.flags =
  5464. TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST;
  5465. else
  5466. CAM_INVALIDATE(config->config_table[1]);
  5467. config->config_table[1].target_table_entry.client_id = 0;
  5468. config->config_table[1].target_table_entry.vlan_id = 0;
  5469. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  5470. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  5471. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  5472. }
  5473. static void bnx2x_set_mac_addr_e1h(struct bnx2x *bp, int set)
  5474. {
  5475. struct mac_configuration_cmd_e1h *config =
  5476. (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config);
  5477. if (set && (bp->state != BNX2X_STATE_OPEN)) {
  5478. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  5479. return;
  5480. }
  5481. /* CAM allocation for E1H
  5482. * unicasts: by func number
  5483. * multicast: 20+FUNC*20, 20 each
  5484. */
  5485. config->hdr.length = 1;
  5486. config->hdr.offset = BP_FUNC(bp);
  5487. config->hdr.client_id = bp->fp->cl_id;
  5488. config->hdr.reserved1 = 0;
  5489. /* primary MAC */
  5490. config->config_table[0].msb_mac_addr =
  5491. swab16(*(u16 *)&bp->dev->dev_addr[0]);
  5492. config->config_table[0].middle_mac_addr =
  5493. swab16(*(u16 *)&bp->dev->dev_addr[2]);
  5494. config->config_table[0].lsb_mac_addr =
  5495. swab16(*(u16 *)&bp->dev->dev_addr[4]);
  5496. config->config_table[0].client_id = BP_L_ID(bp);
  5497. config->config_table[0].vlan_id = 0;
  5498. config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov);
  5499. if (set)
  5500. config->config_table[0].flags = BP_PORT(bp);
  5501. else
  5502. config->config_table[0].flags =
  5503. MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE;
  5504. DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID %d\n",
  5505. (set ? "setting" : "clearing"),
  5506. config->config_table[0].msb_mac_addr,
  5507. config->config_table[0].middle_mac_addr,
  5508. config->config_table[0].lsb_mac_addr, bp->e1hov, BP_L_ID(bp));
  5509. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  5510. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  5511. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  5512. }
  5513. static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
  5514. int *state_p, int poll)
  5515. {
  5516. /* can take a while if any port is running */
  5517. int cnt = 5000;
  5518. DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n",
  5519. poll ? "polling" : "waiting", state, idx);
  5520. might_sleep();
  5521. while (cnt--) {
  5522. if (poll) {
  5523. bnx2x_rx_int(bp->fp, 10);
  5524. /* if index is different from 0
  5525. * the reply for some commands will
  5526. * be on the non default queue
  5527. */
  5528. if (idx)
  5529. bnx2x_rx_int(&bp->fp[idx], 10);
  5530. }
  5531. mb(); /* state is changed by bnx2x_sp_event() */
  5532. if (*state_p == state) {
  5533. #ifdef BNX2X_STOP_ON_ERROR
  5534. DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt);
  5535. #endif
  5536. return 0;
  5537. }
  5538. msleep(1);
  5539. }
  5540. /* timeout! */
  5541. BNX2X_ERR("timeout %s for state %x on IDX [%d]\n",
  5542. poll ? "polling" : "waiting", state, idx);
  5543. #ifdef BNX2X_STOP_ON_ERROR
  5544. bnx2x_panic();
  5545. #endif
  5546. return -EBUSY;
  5547. }
  5548. static int bnx2x_setup_leading(struct bnx2x *bp)
  5549. {
  5550. int rc;
  5551. /* reset IGU state */
  5552. bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  5553. /* SETUP ramrod */
  5554. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0);
  5555. /* Wait for completion */
  5556. rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0);
  5557. return rc;
  5558. }
  5559. static int bnx2x_setup_multi(struct bnx2x *bp, int index)
  5560. {
  5561. struct bnx2x_fastpath *fp = &bp->fp[index];
  5562. /* reset IGU state */
  5563. bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  5564. /* SETUP ramrod */
  5565. fp->state = BNX2X_FP_STATE_OPENING;
  5566. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0,
  5567. fp->cl_id, 0);
  5568. /* Wait for completion */
  5569. return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index,
  5570. &(fp->state), 0);
  5571. }
  5572. static int bnx2x_poll(struct napi_struct *napi, int budget);
  5573. static void bnx2x_set_int_mode(struct bnx2x *bp)
  5574. {
  5575. int num_queues;
  5576. switch (int_mode) {
  5577. case INT_MODE_INTx:
  5578. case INT_MODE_MSI:
  5579. num_queues = 1;
  5580. bp->num_rx_queues = num_queues;
  5581. bp->num_tx_queues = num_queues;
  5582. DP(NETIF_MSG_IFUP,
  5583. "set number of queues to %d\n", num_queues);
  5584. break;
  5585. case INT_MODE_MSIX:
  5586. default:
  5587. if (bp->multi_mode == ETH_RSS_MODE_REGULAR)
  5588. num_queues = min_t(u32, num_online_cpus(),
  5589. BNX2X_MAX_QUEUES(bp));
  5590. else
  5591. num_queues = 1;
  5592. bp->num_rx_queues = num_queues;
  5593. bp->num_tx_queues = num_queues;
  5594. DP(NETIF_MSG_IFUP, "set number of rx queues to %d"
  5595. " number of tx queues to %d\n",
  5596. bp->num_rx_queues, bp->num_tx_queues);
  5597. /* if we can't use MSI-X we only need one fp,
  5598. * so try to enable MSI-X with the requested number of fp's
  5599. * and fallback to MSI or legacy INTx with one fp
  5600. */
  5601. if (bnx2x_enable_msix(bp)) {
  5602. /* failed to enable MSI-X */
  5603. num_queues = 1;
  5604. bp->num_rx_queues = num_queues;
  5605. bp->num_tx_queues = num_queues;
  5606. if (bp->multi_mode)
  5607. BNX2X_ERR("Multi requested but failed to "
  5608. "enable MSI-X set number of "
  5609. "queues to %d\n", num_queues);
  5610. }
  5611. break;
  5612. }
  5613. bp->dev->real_num_tx_queues = bp->num_tx_queues;
  5614. }
  5615. static void bnx2x_set_rx_mode(struct net_device *dev);
  5616. /* must be called with rtnl_lock */
  5617. static int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
  5618. {
  5619. u32 load_code;
  5620. int i, rc = 0;
  5621. #ifdef BNX2X_STOP_ON_ERROR
  5622. DP(NETIF_MSG_IFUP, "enter load_mode %d\n", load_mode);
  5623. if (unlikely(bp->panic))
  5624. return -EPERM;
  5625. #endif
  5626. bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
  5627. bnx2x_set_int_mode(bp);
  5628. if (bnx2x_alloc_mem(bp))
  5629. return -ENOMEM;
  5630. for_each_rx_queue(bp, i)
  5631. bnx2x_fp(bp, i, disable_tpa) =
  5632. ((bp->flags & TPA_ENABLE_FLAG) == 0);
  5633. for_each_rx_queue(bp, i)
  5634. netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
  5635. bnx2x_poll, 128);
  5636. #ifdef BNX2X_STOP_ON_ERROR
  5637. for_each_rx_queue(bp, i) {
  5638. struct bnx2x_fastpath *fp = &bp->fp[i];
  5639. fp->poll_no_work = 0;
  5640. fp->poll_calls = 0;
  5641. fp->poll_max_calls = 0;
  5642. fp->poll_complete = 0;
  5643. fp->poll_exit = 0;
  5644. }
  5645. #endif
  5646. bnx2x_napi_enable(bp);
  5647. if (bp->flags & USING_MSIX_FLAG) {
  5648. rc = bnx2x_req_msix_irqs(bp);
  5649. if (rc) {
  5650. pci_disable_msix(bp->pdev);
  5651. goto load_error1;
  5652. }
  5653. } else {
  5654. if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx))
  5655. bnx2x_enable_msi(bp);
  5656. bnx2x_ack_int(bp);
  5657. rc = bnx2x_req_irq(bp);
  5658. if (rc) {
  5659. BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
  5660. if (bp->flags & USING_MSI_FLAG)
  5661. pci_disable_msi(bp->pdev);
  5662. goto load_error1;
  5663. }
  5664. if (bp->flags & USING_MSI_FLAG) {
  5665. bp->dev->irq = bp->pdev->irq;
  5666. printk(KERN_INFO PFX "%s: using MSI IRQ %d\n",
  5667. bp->dev->name, bp->pdev->irq);
  5668. }
  5669. }
  5670. /* Send LOAD_REQUEST command to MCP
  5671. Returns the type of LOAD command:
  5672. if it is the first port to be initialized
  5673. common blocks should be initialized, otherwise - not
  5674. */
  5675. if (!BP_NOMCP(bp)) {
  5676. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ);
  5677. if (!load_code) {
  5678. BNX2X_ERR("MCP response failure, aborting\n");
  5679. rc = -EBUSY;
  5680. goto load_error2;
  5681. }
  5682. if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
  5683. rc = -EBUSY; /* other port in diagnostic mode */
  5684. goto load_error2;
  5685. }
  5686. } else {
  5687. int port = BP_PORT(bp);
  5688. DP(NETIF_MSG_IFUP, "NO MCP - load counts %d, %d, %d\n",
  5689. load_count[0], load_count[1], load_count[2]);
  5690. load_count[0]++;
  5691. load_count[1 + port]++;
  5692. DP(NETIF_MSG_IFUP, "NO MCP - new load counts %d, %d, %d\n",
  5693. load_count[0], load_count[1], load_count[2]);
  5694. if (load_count[0] == 1)
  5695. load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
  5696. else if (load_count[1 + port] == 1)
  5697. load_code = FW_MSG_CODE_DRV_LOAD_PORT;
  5698. else
  5699. load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
  5700. }
  5701. if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
  5702. (load_code == FW_MSG_CODE_DRV_LOAD_PORT))
  5703. bp->port.pmf = 1;
  5704. else
  5705. bp->port.pmf = 0;
  5706. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  5707. /* Initialize HW */
  5708. rc = bnx2x_init_hw(bp, load_code);
  5709. if (rc) {
  5710. BNX2X_ERR("HW init failed, aborting\n");
  5711. goto load_error2;
  5712. }
  5713. /* Setup NIC internals and enable interrupts */
  5714. bnx2x_nic_init(bp, load_code);
  5715. /* Send LOAD_DONE command to MCP */
  5716. if (!BP_NOMCP(bp)) {
  5717. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE);
  5718. if (!load_code) {
  5719. BNX2X_ERR("MCP response failure, aborting\n");
  5720. rc = -EBUSY;
  5721. goto load_error3;
  5722. }
  5723. }
  5724. bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
  5725. rc = bnx2x_setup_leading(bp);
  5726. if (rc) {
  5727. BNX2X_ERR("Setup leading failed!\n");
  5728. goto load_error3;
  5729. }
  5730. if (CHIP_IS_E1H(bp))
  5731. if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
  5732. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  5733. bp->state = BNX2X_STATE_DISABLED;
  5734. }
  5735. if (bp->state == BNX2X_STATE_OPEN)
  5736. for_each_nondefault_queue(bp, i) {
  5737. rc = bnx2x_setup_multi(bp, i);
  5738. if (rc)
  5739. goto load_error3;
  5740. }
  5741. if (CHIP_IS_E1(bp))
  5742. bnx2x_set_mac_addr_e1(bp, 1);
  5743. else
  5744. bnx2x_set_mac_addr_e1h(bp, 1);
  5745. if (bp->port.pmf)
  5746. bnx2x_initial_phy_init(bp, load_mode);
  5747. /* Start fast path */
  5748. switch (load_mode) {
  5749. case LOAD_NORMAL:
  5750. /* Tx queue should be only reenabled */
  5751. netif_tx_wake_all_queues(bp->dev);
  5752. /* Initialize the receive filter. */
  5753. bnx2x_set_rx_mode(bp->dev);
  5754. break;
  5755. case LOAD_OPEN:
  5756. netif_tx_start_all_queues(bp->dev);
  5757. /* Initialize the receive filter. */
  5758. bnx2x_set_rx_mode(bp->dev);
  5759. break;
  5760. case LOAD_DIAG:
  5761. /* Initialize the receive filter. */
  5762. bnx2x_set_rx_mode(bp->dev);
  5763. bp->state = BNX2X_STATE_DIAG;
  5764. break;
  5765. default:
  5766. break;
  5767. }
  5768. if (!bp->port.pmf)
  5769. bnx2x__link_status_update(bp);
  5770. /* start the timer */
  5771. mod_timer(&bp->timer, jiffies + bp->current_interval);
  5772. return 0;
  5773. load_error3:
  5774. bnx2x_int_disable_sync(bp, 1);
  5775. if (!BP_NOMCP(bp)) {
  5776. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP);
  5777. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  5778. }
  5779. bp->port.pmf = 0;
  5780. /* Free SKBs, SGEs, TPA pool and driver internals */
  5781. bnx2x_free_skbs(bp);
  5782. for_each_rx_queue(bp, i)
  5783. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  5784. load_error2:
  5785. /* Release IRQs */
  5786. bnx2x_free_irq(bp);
  5787. load_error1:
  5788. bnx2x_napi_disable(bp);
  5789. for_each_rx_queue(bp, i)
  5790. netif_napi_del(&bnx2x_fp(bp, i, napi));
  5791. bnx2x_free_mem(bp);
  5792. return rc;
  5793. }
  5794. static int bnx2x_stop_multi(struct bnx2x *bp, int index)
  5795. {
  5796. struct bnx2x_fastpath *fp = &bp->fp[index];
  5797. int rc;
  5798. /* halt the connection */
  5799. fp->state = BNX2X_FP_STATE_HALTING;
  5800. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0);
  5801. /* Wait for completion */
  5802. rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index,
  5803. &(fp->state), 1);
  5804. if (rc) /* timeout */
  5805. return rc;
  5806. /* delete cfc entry */
  5807. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1);
  5808. /* Wait for completion */
  5809. rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index,
  5810. &(fp->state), 1);
  5811. return rc;
  5812. }
  5813. static int bnx2x_stop_leading(struct bnx2x *bp)
  5814. {
  5815. __le16 dsb_sp_prod_idx;
  5816. /* if the other port is handling traffic,
  5817. this can take a lot of time */
  5818. int cnt = 500;
  5819. int rc;
  5820. might_sleep();
  5821. /* Send HALT ramrod */
  5822. bp->fp[0].state = BNX2X_FP_STATE_HALTING;
  5823. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0);
  5824. /* Wait for completion */
  5825. rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0,
  5826. &(bp->fp[0].state), 1);
  5827. if (rc) /* timeout */
  5828. return rc;
  5829. dsb_sp_prod_idx = *bp->dsb_sp_prod;
  5830. /* Send PORT_DELETE ramrod */
  5831. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1);
  5832. /* Wait for completion to arrive on default status block
  5833. we are going to reset the chip anyway
  5834. so there is not much to do if this times out
  5835. */
  5836. while (dsb_sp_prod_idx == *bp->dsb_sp_prod) {
  5837. if (!cnt) {
  5838. DP(NETIF_MSG_IFDOWN, "timeout waiting for port del "
  5839. "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n",
  5840. *bp->dsb_sp_prod, dsb_sp_prod_idx);
  5841. #ifdef BNX2X_STOP_ON_ERROR
  5842. bnx2x_panic();
  5843. #endif
  5844. rc = -EBUSY;
  5845. break;
  5846. }
  5847. cnt--;
  5848. msleep(1);
  5849. rmb(); /* Refresh the dsb_sp_prod */
  5850. }
  5851. bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD;
  5852. bp->fp[0].state = BNX2X_FP_STATE_CLOSED;
  5853. return rc;
  5854. }
  5855. static void bnx2x_reset_func(struct bnx2x *bp)
  5856. {
  5857. int port = BP_PORT(bp);
  5858. int func = BP_FUNC(bp);
  5859. int base, i;
  5860. /* Configure IGU */
  5861. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5862. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5863. /* Clear ILT */
  5864. base = FUNC_ILT_BASE(func);
  5865. for (i = base; i < base + ILT_PER_FUNC; i++)
  5866. bnx2x_ilt_wr(bp, i, 0);
  5867. }
  5868. static void bnx2x_reset_port(struct bnx2x *bp)
  5869. {
  5870. int port = BP_PORT(bp);
  5871. u32 val;
  5872. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5873. /* Do not rcv packets to BRB */
  5874. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  5875. /* Do not direct rcv packets that are not for MCP to the BRB */
  5876. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  5877. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  5878. /* Configure AEU */
  5879. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  5880. msleep(100);
  5881. /* Check for BRB port occupancy */
  5882. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  5883. if (val)
  5884. DP(NETIF_MSG_IFDOWN,
  5885. "BRB1 is not empty %d blocks are occupied\n", val);
  5886. /* TODO: Close Doorbell port? */
  5887. }
  5888. static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code)
  5889. {
  5890. DP(BNX2X_MSG_MCP, "function %d reset_code %x\n",
  5891. BP_FUNC(bp), reset_code);
  5892. switch (reset_code) {
  5893. case FW_MSG_CODE_DRV_UNLOAD_COMMON:
  5894. bnx2x_reset_port(bp);
  5895. bnx2x_reset_func(bp);
  5896. bnx2x_reset_common(bp);
  5897. break;
  5898. case FW_MSG_CODE_DRV_UNLOAD_PORT:
  5899. bnx2x_reset_port(bp);
  5900. bnx2x_reset_func(bp);
  5901. break;
  5902. case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
  5903. bnx2x_reset_func(bp);
  5904. break;
  5905. default:
  5906. BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code);
  5907. break;
  5908. }
  5909. }
  5910. /* must be called with rtnl_lock */
  5911. static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
  5912. {
  5913. int port = BP_PORT(bp);
  5914. u32 reset_code = 0;
  5915. int i, cnt, rc;
  5916. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  5917. bp->rx_mode = BNX2X_RX_MODE_NONE;
  5918. bnx2x_set_storm_rx_mode(bp);
  5919. bnx2x_netif_stop(bp, 1);
  5920. del_timer_sync(&bp->timer);
  5921. SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb,
  5922. (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq));
  5923. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  5924. /* Release IRQs */
  5925. bnx2x_free_irq(bp);
  5926. /* Wait until tx fastpath tasks complete */
  5927. for_each_tx_queue(bp, i) {
  5928. struct bnx2x_fastpath *fp = &bp->fp[i];
  5929. cnt = 1000;
  5930. while (bnx2x_has_tx_work_unload(fp)) {
  5931. bnx2x_tx_int(fp);
  5932. if (!cnt) {
  5933. BNX2X_ERR("timeout waiting for queue[%d]\n",
  5934. i);
  5935. #ifdef BNX2X_STOP_ON_ERROR
  5936. bnx2x_panic();
  5937. return -EBUSY;
  5938. #else
  5939. break;
  5940. #endif
  5941. }
  5942. cnt--;
  5943. msleep(1);
  5944. }
  5945. }
  5946. /* Give HW time to discard old tx messages */
  5947. msleep(1);
  5948. if (CHIP_IS_E1(bp)) {
  5949. struct mac_configuration_cmd *config =
  5950. bnx2x_sp(bp, mcast_config);
  5951. bnx2x_set_mac_addr_e1(bp, 0);
  5952. for (i = 0; i < config->hdr.length; i++)
  5953. CAM_INVALIDATE(config->config_table[i]);
  5954. config->hdr.length = i;
  5955. if (CHIP_REV_IS_SLOW(bp))
  5956. config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
  5957. else
  5958. config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port);
  5959. config->hdr.client_id = bp->fp->cl_id;
  5960. config->hdr.reserved1 = 0;
  5961. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  5962. U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
  5963. U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0);
  5964. } else { /* E1H */
  5965. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  5966. bnx2x_set_mac_addr_e1h(bp, 0);
  5967. for (i = 0; i < MC_HASH_SIZE; i++)
  5968. REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
  5969. }
  5970. if (unload_mode == UNLOAD_NORMAL)
  5971. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  5972. else if (bp->flags & NO_WOL_FLAG) {
  5973. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  5974. if (CHIP_IS_E1H(bp))
  5975. REG_WR(bp, MISC_REG_E1HMF_MODE, 0);
  5976. } else if (bp->wol) {
  5977. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  5978. u8 *mac_addr = bp->dev->dev_addr;
  5979. u32 val;
  5980. /* The mac address is written to entries 1-4 to
  5981. preserve entry 0 which is used by the PMF */
  5982. u8 entry = (BP_E1HVN(bp) + 1)*8;
  5983. val = (mac_addr[0] << 8) | mac_addr[1];
  5984. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  5985. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  5986. (mac_addr[4] << 8) | mac_addr[5];
  5987. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  5988. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  5989. } else
  5990. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  5991. /* Close multi and leading connections
  5992. Completions for ramrods are collected in a synchronous way */
  5993. for_each_nondefault_queue(bp, i)
  5994. if (bnx2x_stop_multi(bp, i))
  5995. goto unload_error;
  5996. rc = bnx2x_stop_leading(bp);
  5997. if (rc) {
  5998. BNX2X_ERR("Stop leading failed!\n");
  5999. #ifdef BNX2X_STOP_ON_ERROR
  6000. return -EBUSY;
  6001. #else
  6002. goto unload_error;
  6003. #endif
  6004. }
  6005. unload_error:
  6006. if (!BP_NOMCP(bp))
  6007. reset_code = bnx2x_fw_command(bp, reset_code);
  6008. else {
  6009. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts %d, %d, %d\n",
  6010. load_count[0], load_count[1], load_count[2]);
  6011. load_count[0]--;
  6012. load_count[1 + port]--;
  6013. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts %d, %d, %d\n",
  6014. load_count[0], load_count[1], load_count[2]);
  6015. if (load_count[0] == 0)
  6016. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6017. else if (load_count[1 + port] == 0)
  6018. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6019. else
  6020. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6021. }
  6022. if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) ||
  6023. (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT))
  6024. bnx2x__link_reset(bp);
  6025. /* Reset the chip */
  6026. bnx2x_reset_chip(bp, reset_code);
  6027. /* Report UNLOAD_DONE to MCP */
  6028. if (!BP_NOMCP(bp))
  6029. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6030. bp->port.pmf = 0;
  6031. /* Free SKBs, SGEs, TPA pool and driver internals */
  6032. bnx2x_free_skbs(bp);
  6033. for_each_rx_queue(bp, i)
  6034. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  6035. for_each_rx_queue(bp, i)
  6036. netif_napi_del(&bnx2x_fp(bp, i, napi));
  6037. bnx2x_free_mem(bp);
  6038. bp->state = BNX2X_STATE_CLOSED;
  6039. netif_carrier_off(bp->dev);
  6040. return 0;
  6041. }
  6042. static void bnx2x_reset_task(struct work_struct *work)
  6043. {
  6044. struct bnx2x *bp = container_of(work, struct bnx2x, reset_task);
  6045. #ifdef BNX2X_STOP_ON_ERROR
  6046. BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
  6047. " so reset not done to allow debug dump,\n"
  6048. KERN_ERR " you will need to reboot when done\n");
  6049. return;
  6050. #endif
  6051. rtnl_lock();
  6052. if (!netif_running(bp->dev))
  6053. goto reset_task_exit;
  6054. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  6055. bnx2x_nic_load(bp, LOAD_NORMAL);
  6056. reset_task_exit:
  6057. rtnl_unlock();
  6058. }
  6059. /* end of nic load/unload */
  6060. /* ethtool_ops */
  6061. /*
  6062. * Init service functions
  6063. */
  6064. static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func)
  6065. {
  6066. switch (func) {
  6067. case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0;
  6068. case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1;
  6069. case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2;
  6070. case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3;
  6071. case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4;
  6072. case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5;
  6073. case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6;
  6074. case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7;
  6075. default:
  6076. BNX2X_ERR("Unsupported function index: %d\n", func);
  6077. return (u32)(-1);
  6078. }
  6079. }
  6080. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func)
  6081. {
  6082. u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val;
  6083. /* Flush all outstanding writes */
  6084. mmiowb();
  6085. /* Pretend to be function 0 */
  6086. REG_WR(bp, reg, 0);
  6087. /* Flush the GRC transaction (in the chip) */
  6088. new_val = REG_RD(bp, reg);
  6089. if (new_val != 0) {
  6090. BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n",
  6091. new_val);
  6092. BUG();
  6093. }
  6094. /* From now we are in the "like-E1" mode */
  6095. bnx2x_int_disable(bp);
  6096. /* Flush all outstanding writes */
  6097. mmiowb();
  6098. /* Restore the original funtion settings */
  6099. REG_WR(bp, reg, orig_func);
  6100. new_val = REG_RD(bp, reg);
  6101. if (new_val != orig_func) {
  6102. BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n",
  6103. orig_func, new_val);
  6104. BUG();
  6105. }
  6106. }
  6107. static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func)
  6108. {
  6109. if (CHIP_IS_E1H(bp))
  6110. bnx2x_undi_int_disable_e1h(bp, func);
  6111. else
  6112. bnx2x_int_disable(bp);
  6113. }
  6114. static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
  6115. {
  6116. u32 val;
  6117. /* Check if there is any driver already loaded */
  6118. val = REG_RD(bp, MISC_REG_UNPREPARED);
  6119. if (val == 0x1) {
  6120. /* Check if it is the UNDI driver
  6121. * UNDI driver initializes CID offset for normal bell to 0x7
  6122. */
  6123. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6124. val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  6125. if (val == 0x7) {
  6126. u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6127. /* save our func */
  6128. int func = BP_FUNC(bp);
  6129. u32 swap_en;
  6130. u32 swap_val;
  6131. /* clear the UNDI indication */
  6132. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  6133. BNX2X_DEV_INFO("UNDI is active! reset device\n");
  6134. /* try unload UNDI on port 0 */
  6135. bp->func = 0;
  6136. bp->fw_seq =
  6137. (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
  6138. DRV_MSG_SEQ_NUMBER_MASK);
  6139. reset_code = bnx2x_fw_command(bp, reset_code);
  6140. /* if UNDI is loaded on the other port */
  6141. if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  6142. /* send "DONE" for previous unload */
  6143. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6144. /* unload UNDI on port 1 */
  6145. bp->func = 1;
  6146. bp->fw_seq =
  6147. (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
  6148. DRV_MSG_SEQ_NUMBER_MASK);
  6149. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6150. bnx2x_fw_command(bp, reset_code);
  6151. }
  6152. /* now it's safe to release the lock */
  6153. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6154. bnx2x_undi_int_disable(bp, func);
  6155. /* close input traffic and wait for it */
  6156. /* Do not rcv packets to BRB */
  6157. REG_WR(bp,
  6158. (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK :
  6159. NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
  6160. /* Do not direct rcv packets that are not for MCP to
  6161. * the BRB */
  6162. REG_WR(bp,
  6163. (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6164. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6165. /* clear AEU */
  6166. REG_WR(bp,
  6167. (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6168. MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
  6169. msleep(10);
  6170. /* save NIG port swap info */
  6171. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  6172. swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  6173. /* reset device */
  6174. REG_WR(bp,
  6175. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6176. 0xd3ffffff);
  6177. REG_WR(bp,
  6178. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6179. 0x1403);
  6180. /* take the NIG out of reset and restore swap values */
  6181. REG_WR(bp,
  6182. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6183. MISC_REGISTERS_RESET_REG_1_RST_NIG);
  6184. REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
  6185. REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
  6186. /* send unload done to the MCP */
  6187. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6188. /* restore our func and fw_seq */
  6189. bp->func = func;
  6190. bp->fw_seq =
  6191. (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
  6192. DRV_MSG_SEQ_NUMBER_MASK);
  6193. } else
  6194. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6195. }
  6196. }
  6197. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  6198. {
  6199. u32 val, val2, val3, val4, id;
  6200. u16 pmc;
  6201. /* Get the chip revision id and number. */
  6202. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  6203. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  6204. id = ((val & 0xffff) << 16);
  6205. val = REG_RD(bp, MISC_REG_CHIP_REV);
  6206. id |= ((val & 0xf) << 12);
  6207. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  6208. id |= ((val & 0xff) << 4);
  6209. val = REG_RD(bp, MISC_REG_BOND_ID);
  6210. id |= (val & 0xf);
  6211. bp->common.chip_id = id;
  6212. bp->link_params.chip_id = bp->common.chip_id;
  6213. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  6214. val = (REG_RD(bp, 0x2874) & 0x55);
  6215. if ((bp->common.chip_id & 0x1) ||
  6216. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  6217. bp->flags |= ONE_PORT_FLAG;
  6218. BNX2X_DEV_INFO("single port device\n");
  6219. }
  6220. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  6221. bp->common.flash_size = (NVRAM_1MB_SIZE <<
  6222. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  6223. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  6224. bp->common.flash_size, bp->common.flash_size);
  6225. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6226. bp->link_params.shmem_base = bp->common.shmem_base;
  6227. BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
  6228. if (!bp->common.shmem_base ||
  6229. (bp->common.shmem_base < 0xA0000) ||
  6230. (bp->common.shmem_base >= 0xC0000)) {
  6231. BNX2X_DEV_INFO("MCP not active\n");
  6232. bp->flags |= NO_MCP_FLAG;
  6233. return;
  6234. }
  6235. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6236. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  6237. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  6238. BNX2X_ERR("BAD MCP validity signature\n");
  6239. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  6240. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  6241. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  6242. SHARED_HW_CFG_LED_MODE_MASK) >>
  6243. SHARED_HW_CFG_LED_MODE_SHIFT);
  6244. bp->link_params.feature_config_flags = 0;
  6245. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  6246. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  6247. bp->link_params.feature_config_flags |=
  6248. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  6249. else
  6250. bp->link_params.feature_config_flags &=
  6251. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  6252. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  6253. bp->common.bc_ver = val;
  6254. BNX2X_DEV_INFO("bc_ver %X\n", val);
  6255. if (val < BNX2X_BC_VER) {
  6256. /* for now only warn
  6257. * later we might need to enforce this */
  6258. BNX2X_ERR("This driver needs bc_ver %X but found %X,"
  6259. " please upgrade BC\n", BNX2X_BC_VER, val);
  6260. }
  6261. if (BP_E1HVN(bp) == 0) {
  6262. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  6263. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  6264. } else {
  6265. /* no WOL capability for E1HVN != 0 */
  6266. bp->flags |= NO_WOL_FLAG;
  6267. }
  6268. BNX2X_DEV_INFO("%sWoL capable\n",
  6269. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  6270. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  6271. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  6272. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  6273. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  6274. printk(KERN_INFO PFX "part number %X-%X-%X-%X\n",
  6275. val, val2, val3, val4);
  6276. }
  6277. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  6278. u32 switch_cfg)
  6279. {
  6280. int port = BP_PORT(bp);
  6281. u32 ext_phy_type;
  6282. switch (switch_cfg) {
  6283. case SWITCH_CFG_1G:
  6284. BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg);
  6285. ext_phy_type =
  6286. SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  6287. switch (ext_phy_type) {
  6288. case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
  6289. BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
  6290. ext_phy_type);
  6291. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6292. SUPPORTED_10baseT_Full |
  6293. SUPPORTED_100baseT_Half |
  6294. SUPPORTED_100baseT_Full |
  6295. SUPPORTED_1000baseT_Full |
  6296. SUPPORTED_2500baseX_Full |
  6297. SUPPORTED_TP |
  6298. SUPPORTED_FIBRE |
  6299. SUPPORTED_Autoneg |
  6300. SUPPORTED_Pause |
  6301. SUPPORTED_Asym_Pause);
  6302. break;
  6303. case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
  6304. BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
  6305. ext_phy_type);
  6306. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6307. SUPPORTED_10baseT_Full |
  6308. SUPPORTED_100baseT_Half |
  6309. SUPPORTED_100baseT_Full |
  6310. SUPPORTED_1000baseT_Full |
  6311. SUPPORTED_TP |
  6312. SUPPORTED_FIBRE |
  6313. SUPPORTED_Autoneg |
  6314. SUPPORTED_Pause |
  6315. SUPPORTED_Asym_Pause);
  6316. break;
  6317. default:
  6318. BNX2X_ERR("NVRAM config error. "
  6319. "BAD SerDes ext_phy_config 0x%x\n",
  6320. bp->link_params.ext_phy_config);
  6321. return;
  6322. }
  6323. bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR +
  6324. port*0x10);
  6325. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  6326. break;
  6327. case SWITCH_CFG_10G:
  6328. BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg);
  6329. ext_phy_type =
  6330. XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  6331. switch (ext_phy_type) {
  6332. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  6333. BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
  6334. ext_phy_type);
  6335. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6336. SUPPORTED_10baseT_Full |
  6337. SUPPORTED_100baseT_Half |
  6338. SUPPORTED_100baseT_Full |
  6339. SUPPORTED_1000baseT_Full |
  6340. SUPPORTED_2500baseX_Full |
  6341. SUPPORTED_10000baseT_Full |
  6342. SUPPORTED_TP |
  6343. SUPPORTED_FIBRE |
  6344. SUPPORTED_Autoneg |
  6345. SUPPORTED_Pause |
  6346. SUPPORTED_Asym_Pause);
  6347. break;
  6348. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
  6349. BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n",
  6350. ext_phy_type);
  6351. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6352. SUPPORTED_1000baseT_Full |
  6353. SUPPORTED_FIBRE |
  6354. SUPPORTED_Autoneg |
  6355. SUPPORTED_Pause |
  6356. SUPPORTED_Asym_Pause);
  6357. break;
  6358. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  6359. BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n",
  6360. ext_phy_type);
  6361. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6362. SUPPORTED_2500baseX_Full |
  6363. SUPPORTED_1000baseT_Full |
  6364. SUPPORTED_FIBRE |
  6365. SUPPORTED_Autoneg |
  6366. SUPPORTED_Pause |
  6367. SUPPORTED_Asym_Pause);
  6368. break;
  6369. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
  6370. BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n",
  6371. ext_phy_type);
  6372. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6373. SUPPORTED_FIBRE |
  6374. SUPPORTED_Pause |
  6375. SUPPORTED_Asym_Pause);
  6376. break;
  6377. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
  6378. BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n",
  6379. ext_phy_type);
  6380. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6381. SUPPORTED_1000baseT_Full |
  6382. SUPPORTED_FIBRE |
  6383. SUPPORTED_Pause |
  6384. SUPPORTED_Asym_Pause);
  6385. break;
  6386. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  6387. BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n",
  6388. ext_phy_type);
  6389. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6390. SUPPORTED_1000baseT_Full |
  6391. SUPPORTED_Autoneg |
  6392. SUPPORTED_FIBRE |
  6393. SUPPORTED_Pause |
  6394. SUPPORTED_Asym_Pause);
  6395. break;
  6396. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  6397. BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n",
  6398. ext_phy_type);
  6399. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6400. SUPPORTED_TP |
  6401. SUPPORTED_Autoneg |
  6402. SUPPORTED_Pause |
  6403. SUPPORTED_Asym_Pause);
  6404. break;
  6405. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
  6406. BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n",
  6407. ext_phy_type);
  6408. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6409. SUPPORTED_10baseT_Full |
  6410. SUPPORTED_100baseT_Half |
  6411. SUPPORTED_100baseT_Full |
  6412. SUPPORTED_1000baseT_Full |
  6413. SUPPORTED_10000baseT_Full |
  6414. SUPPORTED_TP |
  6415. SUPPORTED_Autoneg |
  6416. SUPPORTED_Pause |
  6417. SUPPORTED_Asym_Pause);
  6418. break;
  6419. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  6420. BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
  6421. bp->link_params.ext_phy_config);
  6422. break;
  6423. default:
  6424. BNX2X_ERR("NVRAM config error. "
  6425. "BAD XGXS ext_phy_config 0x%x\n",
  6426. bp->link_params.ext_phy_config);
  6427. return;
  6428. }
  6429. bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR +
  6430. port*0x18);
  6431. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  6432. break;
  6433. default:
  6434. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  6435. bp->port.link_config);
  6436. return;
  6437. }
  6438. bp->link_params.phy_addr = bp->port.phy_addr;
  6439. /* mask what we support according to speed_cap_mask */
  6440. if (!(bp->link_params.speed_cap_mask &
  6441. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  6442. bp->port.supported &= ~SUPPORTED_10baseT_Half;
  6443. if (!(bp->link_params.speed_cap_mask &
  6444. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  6445. bp->port.supported &= ~SUPPORTED_10baseT_Full;
  6446. if (!(bp->link_params.speed_cap_mask &
  6447. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  6448. bp->port.supported &= ~SUPPORTED_100baseT_Half;
  6449. if (!(bp->link_params.speed_cap_mask &
  6450. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  6451. bp->port.supported &= ~SUPPORTED_100baseT_Full;
  6452. if (!(bp->link_params.speed_cap_mask &
  6453. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  6454. bp->port.supported &= ~(SUPPORTED_1000baseT_Half |
  6455. SUPPORTED_1000baseT_Full);
  6456. if (!(bp->link_params.speed_cap_mask &
  6457. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  6458. bp->port.supported &= ~SUPPORTED_2500baseX_Full;
  6459. if (!(bp->link_params.speed_cap_mask &
  6460. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  6461. bp->port.supported &= ~SUPPORTED_10000baseT_Full;
  6462. BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported);
  6463. }
  6464. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  6465. {
  6466. bp->link_params.req_duplex = DUPLEX_FULL;
  6467. switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  6468. case PORT_FEATURE_LINK_SPEED_AUTO:
  6469. if (bp->port.supported & SUPPORTED_Autoneg) {
  6470. bp->link_params.req_line_speed = SPEED_AUTO_NEG;
  6471. bp->port.advertising = bp->port.supported;
  6472. } else {
  6473. u32 ext_phy_type =
  6474. XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  6475. if ((ext_phy_type ==
  6476. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
  6477. (ext_phy_type ==
  6478. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) {
  6479. /* force 10G, no AN */
  6480. bp->link_params.req_line_speed = SPEED_10000;
  6481. bp->port.advertising =
  6482. (ADVERTISED_10000baseT_Full |
  6483. ADVERTISED_FIBRE);
  6484. break;
  6485. }
  6486. BNX2X_ERR("NVRAM config error. "
  6487. "Invalid link_config 0x%x"
  6488. " Autoneg not supported\n",
  6489. bp->port.link_config);
  6490. return;
  6491. }
  6492. break;
  6493. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  6494. if (bp->port.supported & SUPPORTED_10baseT_Full) {
  6495. bp->link_params.req_line_speed = SPEED_10;
  6496. bp->port.advertising = (ADVERTISED_10baseT_Full |
  6497. ADVERTISED_TP);
  6498. } else {
  6499. BNX2X_ERR("NVRAM config error. "
  6500. "Invalid link_config 0x%x"
  6501. " speed_cap_mask 0x%x\n",
  6502. bp->port.link_config,
  6503. bp->link_params.speed_cap_mask);
  6504. return;
  6505. }
  6506. break;
  6507. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  6508. if (bp->port.supported & SUPPORTED_10baseT_Half) {
  6509. bp->link_params.req_line_speed = SPEED_10;
  6510. bp->link_params.req_duplex = DUPLEX_HALF;
  6511. bp->port.advertising = (ADVERTISED_10baseT_Half |
  6512. ADVERTISED_TP);
  6513. } else {
  6514. BNX2X_ERR("NVRAM config error. "
  6515. "Invalid link_config 0x%x"
  6516. " speed_cap_mask 0x%x\n",
  6517. bp->port.link_config,
  6518. bp->link_params.speed_cap_mask);
  6519. return;
  6520. }
  6521. break;
  6522. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  6523. if (bp->port.supported & SUPPORTED_100baseT_Full) {
  6524. bp->link_params.req_line_speed = SPEED_100;
  6525. bp->port.advertising = (ADVERTISED_100baseT_Full |
  6526. ADVERTISED_TP);
  6527. } else {
  6528. BNX2X_ERR("NVRAM config error. "
  6529. "Invalid link_config 0x%x"
  6530. " speed_cap_mask 0x%x\n",
  6531. bp->port.link_config,
  6532. bp->link_params.speed_cap_mask);
  6533. return;
  6534. }
  6535. break;
  6536. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  6537. if (bp->port.supported & SUPPORTED_100baseT_Half) {
  6538. bp->link_params.req_line_speed = SPEED_100;
  6539. bp->link_params.req_duplex = DUPLEX_HALF;
  6540. bp->port.advertising = (ADVERTISED_100baseT_Half |
  6541. ADVERTISED_TP);
  6542. } else {
  6543. BNX2X_ERR("NVRAM config error. "
  6544. "Invalid link_config 0x%x"
  6545. " speed_cap_mask 0x%x\n",
  6546. bp->port.link_config,
  6547. bp->link_params.speed_cap_mask);
  6548. return;
  6549. }
  6550. break;
  6551. case PORT_FEATURE_LINK_SPEED_1G:
  6552. if (bp->port.supported & SUPPORTED_1000baseT_Full) {
  6553. bp->link_params.req_line_speed = SPEED_1000;
  6554. bp->port.advertising = (ADVERTISED_1000baseT_Full |
  6555. ADVERTISED_TP);
  6556. } else {
  6557. BNX2X_ERR("NVRAM config error. "
  6558. "Invalid link_config 0x%x"
  6559. " speed_cap_mask 0x%x\n",
  6560. bp->port.link_config,
  6561. bp->link_params.speed_cap_mask);
  6562. return;
  6563. }
  6564. break;
  6565. case PORT_FEATURE_LINK_SPEED_2_5G:
  6566. if (bp->port.supported & SUPPORTED_2500baseX_Full) {
  6567. bp->link_params.req_line_speed = SPEED_2500;
  6568. bp->port.advertising = (ADVERTISED_2500baseX_Full |
  6569. ADVERTISED_TP);
  6570. } else {
  6571. BNX2X_ERR("NVRAM config error. "
  6572. "Invalid link_config 0x%x"
  6573. " speed_cap_mask 0x%x\n",
  6574. bp->port.link_config,
  6575. bp->link_params.speed_cap_mask);
  6576. return;
  6577. }
  6578. break;
  6579. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  6580. case PORT_FEATURE_LINK_SPEED_10G_KX4:
  6581. case PORT_FEATURE_LINK_SPEED_10G_KR:
  6582. if (bp->port.supported & SUPPORTED_10000baseT_Full) {
  6583. bp->link_params.req_line_speed = SPEED_10000;
  6584. bp->port.advertising = (ADVERTISED_10000baseT_Full |
  6585. ADVERTISED_FIBRE);
  6586. } else {
  6587. BNX2X_ERR("NVRAM config error. "
  6588. "Invalid link_config 0x%x"
  6589. " speed_cap_mask 0x%x\n",
  6590. bp->port.link_config,
  6591. bp->link_params.speed_cap_mask);
  6592. return;
  6593. }
  6594. break;
  6595. default:
  6596. BNX2X_ERR("NVRAM config error. "
  6597. "BAD link speed link_config 0x%x\n",
  6598. bp->port.link_config);
  6599. bp->link_params.req_line_speed = SPEED_AUTO_NEG;
  6600. bp->port.advertising = bp->port.supported;
  6601. break;
  6602. }
  6603. bp->link_params.req_flow_ctrl = (bp->port.link_config &
  6604. PORT_FEATURE_FLOW_CONTROL_MASK);
  6605. if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
  6606. !(bp->port.supported & SUPPORTED_Autoneg))
  6607. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  6608. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x"
  6609. " advertising 0x%x\n",
  6610. bp->link_params.req_line_speed,
  6611. bp->link_params.req_duplex,
  6612. bp->link_params.req_flow_ctrl, bp->port.advertising);
  6613. }
  6614. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  6615. {
  6616. int port = BP_PORT(bp);
  6617. u32 val, val2;
  6618. u32 config;
  6619. u16 i;
  6620. bp->link_params.bp = bp;
  6621. bp->link_params.port = port;
  6622. bp->link_params.lane_config =
  6623. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  6624. bp->link_params.ext_phy_config =
  6625. SHMEM_RD(bp,
  6626. dev_info.port_hw_config[port].external_phy_config);
  6627. bp->link_params.speed_cap_mask =
  6628. SHMEM_RD(bp,
  6629. dev_info.port_hw_config[port].speed_capability_mask);
  6630. bp->port.link_config =
  6631. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  6632. /* Get the 4 lanes xgxs config rx and tx */
  6633. for (i = 0; i < 2; i++) {
  6634. val = SHMEM_RD(bp,
  6635. dev_info.port_hw_config[port].xgxs_config_rx[i<<1]);
  6636. bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff);
  6637. bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff);
  6638. val = SHMEM_RD(bp,
  6639. dev_info.port_hw_config[port].xgxs_config_tx[i<<1]);
  6640. bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff);
  6641. bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff);
  6642. }
  6643. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  6644. if (config & PORT_FEAT_CFG_OPT_MDL_ENFRCMNT_ENABLED)
  6645. bp->link_params.feature_config_flags |=
  6646. FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED;
  6647. else
  6648. bp->link_params.feature_config_flags &=
  6649. ~FEATURE_CONFIG_MODULE_ENFORCMENT_ENABLED;
  6650. /* If the device is capable of WoL, set the default state according
  6651. * to the HW
  6652. */
  6653. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  6654. (config & PORT_FEATURE_WOL_ENABLED));
  6655. BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x"
  6656. " speed_cap_mask 0x%08x link_config 0x%08x\n",
  6657. bp->link_params.lane_config,
  6658. bp->link_params.ext_phy_config,
  6659. bp->link_params.speed_cap_mask, bp->port.link_config);
  6660. bp->link_params.switch_cfg = (bp->port.link_config &
  6661. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  6662. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  6663. bnx2x_link_settings_requested(bp);
  6664. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  6665. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  6666. bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
  6667. bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
  6668. bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
  6669. bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
  6670. bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
  6671. bp->dev->dev_addr[5] = (u8)(val & 0xff);
  6672. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  6673. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  6674. }
  6675. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  6676. {
  6677. int func = BP_FUNC(bp);
  6678. u32 val, val2;
  6679. int rc = 0;
  6680. bnx2x_get_common_hwinfo(bp);
  6681. bp->e1hov = 0;
  6682. bp->e1hmf = 0;
  6683. if (CHIP_IS_E1H(bp)) {
  6684. bp->mf_config =
  6685. SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  6686. val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].e1hov_tag) &
  6687. FUNC_MF_CFG_E1HOV_TAG_MASK);
  6688. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  6689. bp->e1hov = val;
  6690. bp->e1hmf = 1;
  6691. BNX2X_DEV_INFO("MF mode E1HOV for func %d is %d "
  6692. "(0x%04x)\n",
  6693. func, bp->e1hov, bp->e1hov);
  6694. } else {
  6695. BNX2X_DEV_INFO("single function mode\n");
  6696. if (BP_E1HVN(bp)) {
  6697. BNX2X_ERR("!!! No valid E1HOV for func %d,"
  6698. " aborting\n", func);
  6699. rc = -EPERM;
  6700. }
  6701. }
  6702. }
  6703. if (!BP_NOMCP(bp)) {
  6704. bnx2x_get_port_hwinfo(bp);
  6705. bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) &
  6706. DRV_MSG_SEQ_NUMBER_MASK);
  6707. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  6708. }
  6709. if (IS_E1HMF(bp)) {
  6710. val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper);
  6711. val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower);
  6712. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  6713. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
  6714. bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
  6715. bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
  6716. bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
  6717. bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
  6718. bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
  6719. bp->dev->dev_addr[5] = (u8)(val & 0xff);
  6720. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr,
  6721. ETH_ALEN);
  6722. memcpy(bp->dev->perm_addr, bp->dev->dev_addr,
  6723. ETH_ALEN);
  6724. }
  6725. return rc;
  6726. }
  6727. if (BP_NOMCP(bp)) {
  6728. /* only supposed to happen on emulation/FPGA */
  6729. BNX2X_ERR("warning random MAC workaround active\n");
  6730. random_ether_addr(bp->dev->dev_addr);
  6731. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  6732. }
  6733. return rc;
  6734. }
  6735. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  6736. {
  6737. int func = BP_FUNC(bp);
  6738. int timer_interval;
  6739. int rc;
  6740. /* Disable interrupt handling until HW is initialized */
  6741. atomic_set(&bp->intr_sem, 1);
  6742. mutex_init(&bp->port.phy_mutex);
  6743. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  6744. INIT_WORK(&bp->reset_task, bnx2x_reset_task);
  6745. rc = bnx2x_get_hwinfo(bp);
  6746. /* need to reset chip if undi was active */
  6747. if (!BP_NOMCP(bp))
  6748. bnx2x_undi_unload(bp);
  6749. if (CHIP_REV_IS_FPGA(bp))
  6750. printk(KERN_ERR PFX "FPGA detected\n");
  6751. if (BP_NOMCP(bp) && (func == 0))
  6752. printk(KERN_ERR PFX
  6753. "MCP disabled, must load devices in order!\n");
  6754. /* Set multi queue mode */
  6755. if ((multi_mode != ETH_RSS_MODE_DISABLED) &&
  6756. ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) {
  6757. printk(KERN_ERR PFX
  6758. "Multi disabled since int_mode requested is not MSI-X\n");
  6759. multi_mode = ETH_RSS_MODE_DISABLED;
  6760. }
  6761. bp->multi_mode = multi_mode;
  6762. /* Set TPA flags */
  6763. if (disable_tpa) {
  6764. bp->flags &= ~TPA_ENABLE_FLAG;
  6765. bp->dev->features &= ~NETIF_F_LRO;
  6766. } else {
  6767. bp->flags |= TPA_ENABLE_FLAG;
  6768. bp->dev->features |= NETIF_F_LRO;
  6769. }
  6770. bp->mrrs = mrrs;
  6771. bp->tx_ring_size = MAX_TX_AVAIL;
  6772. bp->rx_ring_size = MAX_RX_AVAIL;
  6773. bp->rx_csum = 1;
  6774. bp->tx_ticks = 50;
  6775. bp->rx_ticks = 25;
  6776. timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
  6777. bp->current_interval = (poll ? poll : timer_interval);
  6778. init_timer(&bp->timer);
  6779. bp->timer.expires = jiffies + bp->current_interval;
  6780. bp->timer.data = (unsigned long) bp;
  6781. bp->timer.function = bnx2x_timer;
  6782. return rc;
  6783. }
  6784. /*
  6785. * ethtool service functions
  6786. */
  6787. /* All ethtool functions called with rtnl_lock */
  6788. static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6789. {
  6790. struct bnx2x *bp = netdev_priv(dev);
  6791. cmd->supported = bp->port.supported;
  6792. cmd->advertising = bp->port.advertising;
  6793. if (netif_carrier_ok(dev)) {
  6794. cmd->speed = bp->link_vars.line_speed;
  6795. cmd->duplex = bp->link_vars.duplex;
  6796. } else {
  6797. cmd->speed = bp->link_params.req_line_speed;
  6798. cmd->duplex = bp->link_params.req_duplex;
  6799. }
  6800. if (IS_E1HMF(bp)) {
  6801. u16 vn_max_rate;
  6802. vn_max_rate = ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
  6803. FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
  6804. if (vn_max_rate < cmd->speed)
  6805. cmd->speed = vn_max_rate;
  6806. }
  6807. if (bp->link_params.switch_cfg == SWITCH_CFG_10G) {
  6808. u32 ext_phy_type =
  6809. XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  6810. switch (ext_phy_type) {
  6811. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  6812. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
  6813. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  6814. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
  6815. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
  6816. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  6817. cmd->port = PORT_FIBRE;
  6818. break;
  6819. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  6820. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
  6821. cmd->port = PORT_TP;
  6822. break;
  6823. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  6824. BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
  6825. bp->link_params.ext_phy_config);
  6826. break;
  6827. default:
  6828. DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
  6829. bp->link_params.ext_phy_config);
  6830. break;
  6831. }
  6832. } else
  6833. cmd->port = PORT_TP;
  6834. cmd->phy_address = bp->port.phy_addr;
  6835. cmd->transceiver = XCVR_INTERNAL;
  6836. if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
  6837. cmd->autoneg = AUTONEG_ENABLE;
  6838. else
  6839. cmd->autoneg = AUTONEG_DISABLE;
  6840. cmd->maxtxpkt = 0;
  6841. cmd->maxrxpkt = 0;
  6842. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  6843. DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
  6844. DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
  6845. DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  6846. cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
  6847. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  6848. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  6849. return 0;
  6850. }
  6851. static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  6852. {
  6853. struct bnx2x *bp = netdev_priv(dev);
  6854. u32 advertising;
  6855. if (IS_E1HMF(bp))
  6856. return 0;
  6857. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  6858. DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
  6859. DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
  6860. DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  6861. cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
  6862. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  6863. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  6864. if (cmd->autoneg == AUTONEG_ENABLE) {
  6865. if (!(bp->port.supported & SUPPORTED_Autoneg)) {
  6866. DP(NETIF_MSG_LINK, "Autoneg not supported\n");
  6867. return -EINVAL;
  6868. }
  6869. /* advertise the requested speed and duplex if supported */
  6870. cmd->advertising &= bp->port.supported;
  6871. bp->link_params.req_line_speed = SPEED_AUTO_NEG;
  6872. bp->link_params.req_duplex = DUPLEX_FULL;
  6873. bp->port.advertising |= (ADVERTISED_Autoneg |
  6874. cmd->advertising);
  6875. } else { /* forced speed */
  6876. /* advertise the requested speed and duplex if supported */
  6877. switch (cmd->speed) {
  6878. case SPEED_10:
  6879. if (cmd->duplex == DUPLEX_FULL) {
  6880. if (!(bp->port.supported &
  6881. SUPPORTED_10baseT_Full)) {
  6882. DP(NETIF_MSG_LINK,
  6883. "10M full not supported\n");
  6884. return -EINVAL;
  6885. }
  6886. advertising = (ADVERTISED_10baseT_Full |
  6887. ADVERTISED_TP);
  6888. } else {
  6889. if (!(bp->port.supported &
  6890. SUPPORTED_10baseT_Half)) {
  6891. DP(NETIF_MSG_LINK,
  6892. "10M half not supported\n");
  6893. return -EINVAL;
  6894. }
  6895. advertising = (ADVERTISED_10baseT_Half |
  6896. ADVERTISED_TP);
  6897. }
  6898. break;
  6899. case SPEED_100:
  6900. if (cmd->duplex == DUPLEX_FULL) {
  6901. if (!(bp->port.supported &
  6902. SUPPORTED_100baseT_Full)) {
  6903. DP(NETIF_MSG_LINK,
  6904. "100M full not supported\n");
  6905. return -EINVAL;
  6906. }
  6907. advertising = (ADVERTISED_100baseT_Full |
  6908. ADVERTISED_TP);
  6909. } else {
  6910. if (!(bp->port.supported &
  6911. SUPPORTED_100baseT_Half)) {
  6912. DP(NETIF_MSG_LINK,
  6913. "100M half not supported\n");
  6914. return -EINVAL;
  6915. }
  6916. advertising = (ADVERTISED_100baseT_Half |
  6917. ADVERTISED_TP);
  6918. }
  6919. break;
  6920. case SPEED_1000:
  6921. if (cmd->duplex != DUPLEX_FULL) {
  6922. DP(NETIF_MSG_LINK, "1G half not supported\n");
  6923. return -EINVAL;
  6924. }
  6925. if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
  6926. DP(NETIF_MSG_LINK, "1G full not supported\n");
  6927. return -EINVAL;
  6928. }
  6929. advertising = (ADVERTISED_1000baseT_Full |
  6930. ADVERTISED_TP);
  6931. break;
  6932. case SPEED_2500:
  6933. if (cmd->duplex != DUPLEX_FULL) {
  6934. DP(NETIF_MSG_LINK,
  6935. "2.5G half not supported\n");
  6936. return -EINVAL;
  6937. }
  6938. if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
  6939. DP(NETIF_MSG_LINK,
  6940. "2.5G full not supported\n");
  6941. return -EINVAL;
  6942. }
  6943. advertising = (ADVERTISED_2500baseX_Full |
  6944. ADVERTISED_TP);
  6945. break;
  6946. case SPEED_10000:
  6947. if (cmd->duplex != DUPLEX_FULL) {
  6948. DP(NETIF_MSG_LINK, "10G half not supported\n");
  6949. return -EINVAL;
  6950. }
  6951. if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
  6952. DP(NETIF_MSG_LINK, "10G full not supported\n");
  6953. return -EINVAL;
  6954. }
  6955. advertising = (ADVERTISED_10000baseT_Full |
  6956. ADVERTISED_FIBRE);
  6957. break;
  6958. default:
  6959. DP(NETIF_MSG_LINK, "Unsupported speed\n");
  6960. return -EINVAL;
  6961. }
  6962. bp->link_params.req_line_speed = cmd->speed;
  6963. bp->link_params.req_duplex = cmd->duplex;
  6964. bp->port.advertising = advertising;
  6965. }
  6966. DP(NETIF_MSG_LINK, "req_line_speed %d\n"
  6967. DP_LEVEL " req_duplex %d advertising 0x%x\n",
  6968. bp->link_params.req_line_speed, bp->link_params.req_duplex,
  6969. bp->port.advertising);
  6970. if (netif_running(dev)) {
  6971. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  6972. bnx2x_link_set(bp);
  6973. }
  6974. return 0;
  6975. }
  6976. #define PHY_FW_VER_LEN 10
  6977. static void bnx2x_get_drvinfo(struct net_device *dev,
  6978. struct ethtool_drvinfo *info)
  6979. {
  6980. struct bnx2x *bp = netdev_priv(dev);
  6981. u8 phy_fw_ver[PHY_FW_VER_LEN];
  6982. strcpy(info->driver, DRV_MODULE_NAME);
  6983. strcpy(info->version, DRV_MODULE_VERSION);
  6984. phy_fw_ver[0] = '\0';
  6985. if (bp->port.pmf) {
  6986. bnx2x_acquire_phy_lock(bp);
  6987. bnx2x_get_ext_phy_fw_version(&bp->link_params,
  6988. (bp->state != BNX2X_STATE_CLOSED),
  6989. phy_fw_ver, PHY_FW_VER_LEN);
  6990. bnx2x_release_phy_lock(bp);
  6991. }
  6992. snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s",
  6993. (bp->common.bc_ver & 0xff0000) >> 16,
  6994. (bp->common.bc_ver & 0xff00) >> 8,
  6995. (bp->common.bc_ver & 0xff),
  6996. ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver);
  6997. strcpy(info->bus_info, pci_name(bp->pdev));
  6998. info->n_stats = BNX2X_NUM_STATS;
  6999. info->testinfo_len = BNX2X_NUM_TESTS;
  7000. info->eedump_len = bp->common.flash_size;
  7001. info->regdump_len = 0;
  7002. }
  7003. #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
  7004. #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
  7005. static int bnx2x_get_regs_len(struct net_device *dev)
  7006. {
  7007. static u32 regdump_len;
  7008. struct bnx2x *bp = netdev_priv(dev);
  7009. int i;
  7010. if (regdump_len)
  7011. return regdump_len;
  7012. if (CHIP_IS_E1(bp)) {
  7013. for (i = 0; i < REGS_COUNT; i++)
  7014. if (IS_E1_ONLINE(reg_addrs[i].info))
  7015. regdump_len += reg_addrs[i].size;
  7016. for (i = 0; i < WREGS_COUNT_E1; i++)
  7017. if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
  7018. regdump_len += wreg_addrs_e1[i].size *
  7019. (1 + wreg_addrs_e1[i].read_regs_count);
  7020. } else { /* E1H */
  7021. for (i = 0; i < REGS_COUNT; i++)
  7022. if (IS_E1H_ONLINE(reg_addrs[i].info))
  7023. regdump_len += reg_addrs[i].size;
  7024. for (i = 0; i < WREGS_COUNT_E1H; i++)
  7025. if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
  7026. regdump_len += wreg_addrs_e1h[i].size *
  7027. (1 + wreg_addrs_e1h[i].read_regs_count);
  7028. }
  7029. regdump_len *= 4;
  7030. regdump_len += sizeof(struct dump_hdr);
  7031. return regdump_len;
  7032. }
  7033. static void bnx2x_get_regs(struct net_device *dev,
  7034. struct ethtool_regs *regs, void *_p)
  7035. {
  7036. u32 *p = _p, i, j;
  7037. struct bnx2x *bp = netdev_priv(dev);
  7038. struct dump_hdr dump_hdr = {0};
  7039. regs->version = 0;
  7040. memset(p, 0, regs->len);
  7041. if (!netif_running(bp->dev))
  7042. return;
  7043. dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
  7044. dump_hdr.dump_sign = dump_sign_all;
  7045. dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
  7046. dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
  7047. dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
  7048. dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
  7049. dump_hdr.info = CHIP_IS_E1(bp) ? RI_E1_ONLINE : RI_E1H_ONLINE;
  7050. memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
  7051. p += dump_hdr.hdr_size + 1;
  7052. if (CHIP_IS_E1(bp)) {
  7053. for (i = 0; i < REGS_COUNT; i++)
  7054. if (IS_E1_ONLINE(reg_addrs[i].info))
  7055. for (j = 0; j < reg_addrs[i].size; j++)
  7056. *p++ = REG_RD(bp,
  7057. reg_addrs[i].addr + j*4);
  7058. } else { /* E1H */
  7059. for (i = 0; i < REGS_COUNT; i++)
  7060. if (IS_E1H_ONLINE(reg_addrs[i].info))
  7061. for (j = 0; j < reg_addrs[i].size; j++)
  7062. *p++ = REG_RD(bp,
  7063. reg_addrs[i].addr + j*4);
  7064. }
  7065. }
  7066. static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7067. {
  7068. struct bnx2x *bp = netdev_priv(dev);
  7069. if (bp->flags & NO_WOL_FLAG) {
  7070. wol->supported = 0;
  7071. wol->wolopts = 0;
  7072. } else {
  7073. wol->supported = WAKE_MAGIC;
  7074. if (bp->wol)
  7075. wol->wolopts = WAKE_MAGIC;
  7076. else
  7077. wol->wolopts = 0;
  7078. }
  7079. memset(&wol->sopass, 0, sizeof(wol->sopass));
  7080. }
  7081. static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7082. {
  7083. struct bnx2x *bp = netdev_priv(dev);
  7084. if (wol->wolopts & ~WAKE_MAGIC)
  7085. return -EINVAL;
  7086. if (wol->wolopts & WAKE_MAGIC) {
  7087. if (bp->flags & NO_WOL_FLAG)
  7088. return -EINVAL;
  7089. bp->wol = 1;
  7090. } else
  7091. bp->wol = 0;
  7092. return 0;
  7093. }
  7094. static u32 bnx2x_get_msglevel(struct net_device *dev)
  7095. {
  7096. struct bnx2x *bp = netdev_priv(dev);
  7097. return bp->msglevel;
  7098. }
  7099. static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
  7100. {
  7101. struct bnx2x *bp = netdev_priv(dev);
  7102. if (capable(CAP_NET_ADMIN))
  7103. bp->msglevel = level;
  7104. }
  7105. static int bnx2x_nway_reset(struct net_device *dev)
  7106. {
  7107. struct bnx2x *bp = netdev_priv(dev);
  7108. if (!bp->port.pmf)
  7109. return 0;
  7110. if (netif_running(dev)) {
  7111. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  7112. bnx2x_link_set(bp);
  7113. }
  7114. return 0;
  7115. }
  7116. static int bnx2x_get_eeprom_len(struct net_device *dev)
  7117. {
  7118. struct bnx2x *bp = netdev_priv(dev);
  7119. return bp->common.flash_size;
  7120. }
  7121. static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
  7122. {
  7123. int port = BP_PORT(bp);
  7124. int count, i;
  7125. u32 val = 0;
  7126. /* adjust timeout for emulation/FPGA */
  7127. count = NVRAM_TIMEOUT_COUNT;
  7128. if (CHIP_REV_IS_SLOW(bp))
  7129. count *= 100;
  7130. /* request access to nvram interface */
  7131. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7132. (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
  7133. for (i = 0; i < count*10; i++) {
  7134. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  7135. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
  7136. break;
  7137. udelay(5);
  7138. }
  7139. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
  7140. DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
  7141. return -EBUSY;
  7142. }
  7143. return 0;
  7144. }
  7145. static int bnx2x_release_nvram_lock(struct bnx2x *bp)
  7146. {
  7147. int port = BP_PORT(bp);
  7148. int count, i;
  7149. u32 val = 0;
  7150. /* adjust timeout for emulation/FPGA */
  7151. count = NVRAM_TIMEOUT_COUNT;
  7152. if (CHIP_REV_IS_SLOW(bp))
  7153. count *= 100;
  7154. /* relinquish nvram interface */
  7155. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7156. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
  7157. for (i = 0; i < count*10; i++) {
  7158. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  7159. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
  7160. break;
  7161. udelay(5);
  7162. }
  7163. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
  7164. DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
  7165. return -EBUSY;
  7166. }
  7167. return 0;
  7168. }
  7169. static void bnx2x_enable_nvram_access(struct bnx2x *bp)
  7170. {
  7171. u32 val;
  7172. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  7173. /* enable both bits, even on read */
  7174. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  7175. (val | MCPR_NVM_ACCESS_ENABLE_EN |
  7176. MCPR_NVM_ACCESS_ENABLE_WR_EN));
  7177. }
  7178. static void bnx2x_disable_nvram_access(struct bnx2x *bp)
  7179. {
  7180. u32 val;
  7181. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  7182. /* disable both bits, even after read */
  7183. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  7184. (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
  7185. MCPR_NVM_ACCESS_ENABLE_WR_EN)));
  7186. }
  7187. static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
  7188. u32 cmd_flags)
  7189. {
  7190. int count, i, rc;
  7191. u32 val;
  7192. /* build the command word */
  7193. cmd_flags |= MCPR_NVM_COMMAND_DOIT;
  7194. /* need to clear DONE bit separately */
  7195. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  7196. /* address of the NVRAM to read from */
  7197. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  7198. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  7199. /* issue a read command */
  7200. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  7201. /* adjust timeout for emulation/FPGA */
  7202. count = NVRAM_TIMEOUT_COUNT;
  7203. if (CHIP_REV_IS_SLOW(bp))
  7204. count *= 100;
  7205. /* wait for completion */
  7206. *ret_val = 0;
  7207. rc = -EBUSY;
  7208. for (i = 0; i < count; i++) {
  7209. udelay(5);
  7210. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  7211. if (val & MCPR_NVM_COMMAND_DONE) {
  7212. val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
  7213. /* we read nvram data in cpu order
  7214. * but ethtool sees it as an array of bytes
  7215. * converting to big-endian will do the work */
  7216. *ret_val = cpu_to_be32(val);
  7217. rc = 0;
  7218. break;
  7219. }
  7220. }
  7221. return rc;
  7222. }
  7223. static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  7224. int buf_size)
  7225. {
  7226. int rc;
  7227. u32 cmd_flags;
  7228. __be32 val;
  7229. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  7230. DP(BNX2X_MSG_NVM,
  7231. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  7232. offset, buf_size);
  7233. return -EINVAL;
  7234. }
  7235. if (offset + buf_size > bp->common.flash_size) {
  7236. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  7237. " buf_size (0x%x) > flash_size (0x%x)\n",
  7238. offset, buf_size, bp->common.flash_size);
  7239. return -EINVAL;
  7240. }
  7241. /* request access to nvram interface */
  7242. rc = bnx2x_acquire_nvram_lock(bp);
  7243. if (rc)
  7244. return rc;
  7245. /* enable access to nvram interface */
  7246. bnx2x_enable_nvram_access(bp);
  7247. /* read the first word(s) */
  7248. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  7249. while ((buf_size > sizeof(u32)) && (rc == 0)) {
  7250. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  7251. memcpy(ret_buf, &val, 4);
  7252. /* advance to the next dword */
  7253. offset += sizeof(u32);
  7254. ret_buf += sizeof(u32);
  7255. buf_size -= sizeof(u32);
  7256. cmd_flags = 0;
  7257. }
  7258. if (rc == 0) {
  7259. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  7260. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  7261. memcpy(ret_buf, &val, 4);
  7262. }
  7263. /* disable access to nvram interface */
  7264. bnx2x_disable_nvram_access(bp);
  7265. bnx2x_release_nvram_lock(bp);
  7266. return rc;
  7267. }
  7268. static int bnx2x_get_eeprom(struct net_device *dev,
  7269. struct ethtool_eeprom *eeprom, u8 *eebuf)
  7270. {
  7271. struct bnx2x *bp = netdev_priv(dev);
  7272. int rc;
  7273. if (!netif_running(dev))
  7274. return -EAGAIN;
  7275. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  7276. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  7277. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  7278. eeprom->len, eeprom->len);
  7279. /* parameters already validated in ethtool_get_eeprom */
  7280. rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  7281. return rc;
  7282. }
  7283. static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
  7284. u32 cmd_flags)
  7285. {
  7286. int count, i, rc;
  7287. /* build the command word */
  7288. cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
  7289. /* need to clear DONE bit separately */
  7290. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  7291. /* write the data */
  7292. REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
  7293. /* address of the NVRAM to write to */
  7294. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  7295. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  7296. /* issue the write command */
  7297. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  7298. /* adjust timeout for emulation/FPGA */
  7299. count = NVRAM_TIMEOUT_COUNT;
  7300. if (CHIP_REV_IS_SLOW(bp))
  7301. count *= 100;
  7302. /* wait for completion */
  7303. rc = -EBUSY;
  7304. for (i = 0; i < count; i++) {
  7305. udelay(5);
  7306. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  7307. if (val & MCPR_NVM_COMMAND_DONE) {
  7308. rc = 0;
  7309. break;
  7310. }
  7311. }
  7312. return rc;
  7313. }
  7314. #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
  7315. static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
  7316. int buf_size)
  7317. {
  7318. int rc;
  7319. u32 cmd_flags;
  7320. u32 align_offset;
  7321. __be32 val;
  7322. if (offset + buf_size > bp->common.flash_size) {
  7323. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  7324. " buf_size (0x%x) > flash_size (0x%x)\n",
  7325. offset, buf_size, bp->common.flash_size);
  7326. return -EINVAL;
  7327. }
  7328. /* request access to nvram interface */
  7329. rc = bnx2x_acquire_nvram_lock(bp);
  7330. if (rc)
  7331. return rc;
  7332. /* enable access to nvram interface */
  7333. bnx2x_enable_nvram_access(bp);
  7334. cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
  7335. align_offset = (offset & ~0x03);
  7336. rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
  7337. if (rc == 0) {
  7338. val &= ~(0xff << BYTE_OFFSET(offset));
  7339. val |= (*data_buf << BYTE_OFFSET(offset));
  7340. /* nvram data is returned as an array of bytes
  7341. * convert it back to cpu order */
  7342. val = be32_to_cpu(val);
  7343. rc = bnx2x_nvram_write_dword(bp, align_offset, val,
  7344. cmd_flags);
  7345. }
  7346. /* disable access to nvram interface */
  7347. bnx2x_disable_nvram_access(bp);
  7348. bnx2x_release_nvram_lock(bp);
  7349. return rc;
  7350. }
  7351. static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
  7352. int buf_size)
  7353. {
  7354. int rc;
  7355. u32 cmd_flags;
  7356. u32 val;
  7357. u32 written_so_far;
  7358. if (buf_size == 1) /* ethtool */
  7359. return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
  7360. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  7361. DP(BNX2X_MSG_NVM,
  7362. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  7363. offset, buf_size);
  7364. return -EINVAL;
  7365. }
  7366. if (offset + buf_size > bp->common.flash_size) {
  7367. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  7368. " buf_size (0x%x) > flash_size (0x%x)\n",
  7369. offset, buf_size, bp->common.flash_size);
  7370. return -EINVAL;
  7371. }
  7372. /* request access to nvram interface */
  7373. rc = bnx2x_acquire_nvram_lock(bp);
  7374. if (rc)
  7375. return rc;
  7376. /* enable access to nvram interface */
  7377. bnx2x_enable_nvram_access(bp);
  7378. written_so_far = 0;
  7379. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  7380. while ((written_so_far < buf_size) && (rc == 0)) {
  7381. if (written_so_far == (buf_size - sizeof(u32)))
  7382. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  7383. else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
  7384. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  7385. else if ((offset % NVRAM_PAGE_SIZE) == 0)
  7386. cmd_flags |= MCPR_NVM_COMMAND_FIRST;
  7387. memcpy(&val, data_buf, 4);
  7388. rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
  7389. /* advance to the next dword */
  7390. offset += sizeof(u32);
  7391. data_buf += sizeof(u32);
  7392. written_so_far += sizeof(u32);
  7393. cmd_flags = 0;
  7394. }
  7395. /* disable access to nvram interface */
  7396. bnx2x_disable_nvram_access(bp);
  7397. bnx2x_release_nvram_lock(bp);
  7398. return rc;
  7399. }
  7400. static int bnx2x_set_eeprom(struct net_device *dev,
  7401. struct ethtool_eeprom *eeprom, u8 *eebuf)
  7402. {
  7403. struct bnx2x *bp = netdev_priv(dev);
  7404. int rc;
  7405. if (!netif_running(dev))
  7406. return -EAGAIN;
  7407. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  7408. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  7409. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  7410. eeprom->len, eeprom->len);
  7411. /* parameters already validated in ethtool_set_eeprom */
  7412. /* If the magic number is PHY (0x00504859) upgrade the PHY FW */
  7413. if (eeprom->magic == 0x00504859)
  7414. if (bp->port.pmf) {
  7415. bnx2x_acquire_phy_lock(bp);
  7416. rc = bnx2x_flash_download(bp, BP_PORT(bp),
  7417. bp->link_params.ext_phy_config,
  7418. (bp->state != BNX2X_STATE_CLOSED),
  7419. eebuf, eeprom->len);
  7420. if ((bp->state == BNX2X_STATE_OPEN) ||
  7421. (bp->state == BNX2X_STATE_DISABLED)) {
  7422. rc |= bnx2x_link_reset(&bp->link_params,
  7423. &bp->link_vars, 1);
  7424. rc |= bnx2x_phy_init(&bp->link_params,
  7425. &bp->link_vars);
  7426. }
  7427. bnx2x_release_phy_lock(bp);
  7428. } else /* Only the PMF can access the PHY */
  7429. return -EINVAL;
  7430. else
  7431. rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  7432. return rc;
  7433. }
  7434. static int bnx2x_get_coalesce(struct net_device *dev,
  7435. struct ethtool_coalesce *coal)
  7436. {
  7437. struct bnx2x *bp = netdev_priv(dev);
  7438. memset(coal, 0, sizeof(struct ethtool_coalesce));
  7439. coal->rx_coalesce_usecs = bp->rx_ticks;
  7440. coal->tx_coalesce_usecs = bp->tx_ticks;
  7441. return 0;
  7442. }
  7443. static int bnx2x_set_coalesce(struct net_device *dev,
  7444. struct ethtool_coalesce *coal)
  7445. {
  7446. struct bnx2x *bp = netdev_priv(dev);
  7447. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  7448. if (bp->rx_ticks > 3000)
  7449. bp->rx_ticks = 3000;
  7450. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  7451. if (bp->tx_ticks > 0x3000)
  7452. bp->tx_ticks = 0x3000;
  7453. if (netif_running(dev))
  7454. bnx2x_update_coalesce(bp);
  7455. return 0;
  7456. }
  7457. static void bnx2x_get_ringparam(struct net_device *dev,
  7458. struct ethtool_ringparam *ering)
  7459. {
  7460. struct bnx2x *bp = netdev_priv(dev);
  7461. ering->rx_max_pending = MAX_RX_AVAIL;
  7462. ering->rx_mini_max_pending = 0;
  7463. ering->rx_jumbo_max_pending = 0;
  7464. ering->rx_pending = bp->rx_ring_size;
  7465. ering->rx_mini_pending = 0;
  7466. ering->rx_jumbo_pending = 0;
  7467. ering->tx_max_pending = MAX_TX_AVAIL;
  7468. ering->tx_pending = bp->tx_ring_size;
  7469. }
  7470. static int bnx2x_set_ringparam(struct net_device *dev,
  7471. struct ethtool_ringparam *ering)
  7472. {
  7473. struct bnx2x *bp = netdev_priv(dev);
  7474. int rc = 0;
  7475. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  7476. (ering->tx_pending > MAX_TX_AVAIL) ||
  7477. (ering->tx_pending <= MAX_SKB_FRAGS + 4))
  7478. return -EINVAL;
  7479. bp->rx_ring_size = ering->rx_pending;
  7480. bp->tx_ring_size = ering->tx_pending;
  7481. if (netif_running(dev)) {
  7482. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7483. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  7484. }
  7485. return rc;
  7486. }
  7487. static void bnx2x_get_pauseparam(struct net_device *dev,
  7488. struct ethtool_pauseparam *epause)
  7489. {
  7490. struct bnx2x *bp = netdev_priv(dev);
  7491. epause->autoneg = (bp->link_params.req_flow_ctrl ==
  7492. BNX2X_FLOW_CTRL_AUTO) &&
  7493. (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
  7494. epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
  7495. BNX2X_FLOW_CTRL_RX);
  7496. epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
  7497. BNX2X_FLOW_CTRL_TX);
  7498. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  7499. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  7500. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  7501. }
  7502. static int bnx2x_set_pauseparam(struct net_device *dev,
  7503. struct ethtool_pauseparam *epause)
  7504. {
  7505. struct bnx2x *bp = netdev_priv(dev);
  7506. if (IS_E1HMF(bp))
  7507. return 0;
  7508. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  7509. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  7510. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  7511. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
  7512. if (epause->rx_pause)
  7513. bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
  7514. if (epause->tx_pause)
  7515. bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
  7516. if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
  7517. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  7518. if (epause->autoneg) {
  7519. if (!(bp->port.supported & SUPPORTED_Autoneg)) {
  7520. DP(NETIF_MSG_LINK, "autoneg not supported\n");
  7521. return -EINVAL;
  7522. }
  7523. if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
  7524. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
  7525. }
  7526. DP(NETIF_MSG_LINK,
  7527. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
  7528. if (netif_running(dev)) {
  7529. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  7530. bnx2x_link_set(bp);
  7531. }
  7532. return 0;
  7533. }
  7534. static int bnx2x_set_flags(struct net_device *dev, u32 data)
  7535. {
  7536. struct bnx2x *bp = netdev_priv(dev);
  7537. int changed = 0;
  7538. int rc = 0;
  7539. /* TPA requires Rx CSUM offloading */
  7540. if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
  7541. if (!(dev->features & NETIF_F_LRO)) {
  7542. dev->features |= NETIF_F_LRO;
  7543. bp->flags |= TPA_ENABLE_FLAG;
  7544. changed = 1;
  7545. }
  7546. } else if (dev->features & NETIF_F_LRO) {
  7547. dev->features &= ~NETIF_F_LRO;
  7548. bp->flags &= ~TPA_ENABLE_FLAG;
  7549. changed = 1;
  7550. }
  7551. if (changed && netif_running(dev)) {
  7552. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7553. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  7554. }
  7555. return rc;
  7556. }
  7557. static u32 bnx2x_get_rx_csum(struct net_device *dev)
  7558. {
  7559. struct bnx2x *bp = netdev_priv(dev);
  7560. return bp->rx_csum;
  7561. }
  7562. static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
  7563. {
  7564. struct bnx2x *bp = netdev_priv(dev);
  7565. int rc = 0;
  7566. bp->rx_csum = data;
  7567. /* Disable TPA, when Rx CSUM is disabled. Otherwise all
  7568. TPA'ed packets will be discarded due to wrong TCP CSUM */
  7569. if (!data) {
  7570. u32 flags = ethtool_op_get_flags(dev);
  7571. rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
  7572. }
  7573. return rc;
  7574. }
  7575. static int bnx2x_set_tso(struct net_device *dev, u32 data)
  7576. {
  7577. if (data) {
  7578. dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
  7579. dev->features |= NETIF_F_TSO6;
  7580. } else {
  7581. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
  7582. dev->features &= ~NETIF_F_TSO6;
  7583. }
  7584. return 0;
  7585. }
  7586. static const struct {
  7587. char string[ETH_GSTRING_LEN];
  7588. } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
  7589. { "register_test (offline)" },
  7590. { "memory_test (offline)" },
  7591. { "loopback_test (offline)" },
  7592. { "nvram_test (online)" },
  7593. { "interrupt_test (online)" },
  7594. { "link_test (online)" },
  7595. { "idle check (online)" }
  7596. };
  7597. static int bnx2x_self_test_count(struct net_device *dev)
  7598. {
  7599. return BNX2X_NUM_TESTS;
  7600. }
  7601. static int bnx2x_test_registers(struct bnx2x *bp)
  7602. {
  7603. int idx, i, rc = -ENODEV;
  7604. u32 wr_val = 0;
  7605. int port = BP_PORT(bp);
  7606. static const struct {
  7607. u32 offset0;
  7608. u32 offset1;
  7609. u32 mask;
  7610. } reg_tbl[] = {
  7611. /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  7612. { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  7613. { HC_REG_AGG_INT_0, 4, 0x000003ff },
  7614. { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  7615. { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  7616. { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  7617. { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  7618. { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  7619. { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  7620. { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  7621. /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  7622. { QM_REG_CONNNUM_0, 4, 0x000fffff },
  7623. { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  7624. { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  7625. { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  7626. { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  7627. { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  7628. { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  7629. { NIG_REG_EGRESS_MNG0_FIFO, 20, 0xffffffff },
  7630. { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  7631. /* 20 */ { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  7632. { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  7633. { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  7634. { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  7635. { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  7636. { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  7637. { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  7638. { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  7639. { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  7640. { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  7641. /* 30 */ { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  7642. { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  7643. { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  7644. { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  7645. { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
  7646. { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  7647. { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  7648. { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  7649. { 0xffffffff, 0, 0x00000000 }
  7650. };
  7651. if (!netif_running(bp->dev))
  7652. return rc;
  7653. /* Repeat the test twice:
  7654. First by writing 0x00000000, second by writing 0xffffffff */
  7655. for (idx = 0; idx < 2; idx++) {
  7656. switch (idx) {
  7657. case 0:
  7658. wr_val = 0;
  7659. break;
  7660. case 1:
  7661. wr_val = 0xffffffff;
  7662. break;
  7663. }
  7664. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  7665. u32 offset, mask, save_val, val;
  7666. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  7667. mask = reg_tbl[i].mask;
  7668. save_val = REG_RD(bp, offset);
  7669. REG_WR(bp, offset, wr_val);
  7670. val = REG_RD(bp, offset);
  7671. /* Restore the original register's value */
  7672. REG_WR(bp, offset, save_val);
  7673. /* verify that value is as expected value */
  7674. if ((val & mask) != (wr_val & mask))
  7675. goto test_reg_exit;
  7676. }
  7677. }
  7678. rc = 0;
  7679. test_reg_exit:
  7680. return rc;
  7681. }
  7682. static int bnx2x_test_memory(struct bnx2x *bp)
  7683. {
  7684. int i, j, rc = -ENODEV;
  7685. u32 val;
  7686. static const struct {
  7687. u32 offset;
  7688. int size;
  7689. } mem_tbl[] = {
  7690. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  7691. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  7692. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  7693. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  7694. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  7695. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  7696. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  7697. { 0xffffffff, 0 }
  7698. };
  7699. static const struct {
  7700. char *name;
  7701. u32 offset;
  7702. u32 e1_mask;
  7703. u32 e1h_mask;
  7704. } prty_tbl[] = {
  7705. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
  7706. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
  7707. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
  7708. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
  7709. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
  7710. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
  7711. { NULL, 0xffffffff, 0, 0 }
  7712. };
  7713. if (!netif_running(bp->dev))
  7714. return rc;
  7715. /* Go through all the memories */
  7716. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  7717. for (j = 0; j < mem_tbl[i].size; j++)
  7718. REG_RD(bp, mem_tbl[i].offset + j*4);
  7719. /* Check the parity status */
  7720. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  7721. val = REG_RD(bp, prty_tbl[i].offset);
  7722. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  7723. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
  7724. DP(NETIF_MSG_HW,
  7725. "%s is 0x%x\n", prty_tbl[i].name, val);
  7726. goto test_mem_exit;
  7727. }
  7728. }
  7729. rc = 0;
  7730. test_mem_exit:
  7731. return rc;
  7732. }
  7733. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
  7734. {
  7735. int cnt = 1000;
  7736. if (link_up)
  7737. while (bnx2x_link_test(bp) && cnt--)
  7738. msleep(10);
  7739. }
  7740. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
  7741. {
  7742. unsigned int pkt_size, num_pkts, i;
  7743. struct sk_buff *skb;
  7744. unsigned char *packet;
  7745. struct bnx2x_fastpath *fp = &bp->fp[0];
  7746. u16 tx_start_idx, tx_idx;
  7747. u16 rx_start_idx, rx_idx;
  7748. u16 pkt_prod;
  7749. struct sw_tx_bd *tx_buf;
  7750. struct eth_tx_bd *tx_bd;
  7751. dma_addr_t mapping;
  7752. union eth_rx_cqe *cqe;
  7753. u8 cqe_fp_flags;
  7754. struct sw_rx_bd *rx_buf;
  7755. u16 len;
  7756. int rc = -ENODEV;
  7757. /* check the loopback mode */
  7758. switch (loopback_mode) {
  7759. case BNX2X_PHY_LOOPBACK:
  7760. if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10)
  7761. return -EINVAL;
  7762. break;
  7763. case BNX2X_MAC_LOOPBACK:
  7764. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  7765. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  7766. break;
  7767. default:
  7768. return -EINVAL;
  7769. }
  7770. /* prepare the loopback packet */
  7771. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  7772. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  7773. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  7774. if (!skb) {
  7775. rc = -ENOMEM;
  7776. goto test_loopback_exit;
  7777. }
  7778. packet = skb_put(skb, pkt_size);
  7779. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  7780. memset(packet + ETH_ALEN, 0, (ETH_HLEN - ETH_ALEN));
  7781. for (i = ETH_HLEN; i < pkt_size; i++)
  7782. packet[i] = (unsigned char) (i & 0xff);
  7783. /* send the loopback packet */
  7784. num_pkts = 0;
  7785. tx_start_idx = le16_to_cpu(*fp->tx_cons_sb);
  7786. rx_start_idx = le16_to_cpu(*fp->rx_cons_sb);
  7787. pkt_prod = fp->tx_pkt_prod++;
  7788. tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
  7789. tx_buf->first_bd = fp->tx_bd_prod;
  7790. tx_buf->skb = skb;
  7791. tx_bd = &fp->tx_desc_ring[TX_BD(fp->tx_bd_prod)];
  7792. mapping = pci_map_single(bp->pdev, skb->data,
  7793. skb_headlen(skb), PCI_DMA_TODEVICE);
  7794. tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  7795. tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  7796. tx_bd->nbd = cpu_to_le16(1);
  7797. tx_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  7798. tx_bd->vlan = cpu_to_le16(pkt_prod);
  7799. tx_bd->bd_flags.as_bitfield = (ETH_TX_BD_FLAGS_START_BD |
  7800. ETH_TX_BD_FLAGS_END_BD);
  7801. tx_bd->general_data = ((UNICAST_ADDRESS <<
  7802. ETH_TX_BD_ETH_ADDR_TYPE_SHIFT) | 1);
  7803. wmb();
  7804. le16_add_cpu(&fp->hw_tx_prods->bds_prod, 1);
  7805. mb(); /* FW restriction: must not reorder writing nbd and packets */
  7806. le32_add_cpu(&fp->hw_tx_prods->packets_prod, 1);
  7807. DOORBELL(bp, fp->index, 0);
  7808. mmiowb();
  7809. num_pkts++;
  7810. fp->tx_bd_prod++;
  7811. bp->dev->trans_start = jiffies;
  7812. udelay(100);
  7813. tx_idx = le16_to_cpu(*fp->tx_cons_sb);
  7814. if (tx_idx != tx_start_idx + num_pkts)
  7815. goto test_loopback_exit;
  7816. rx_idx = le16_to_cpu(*fp->rx_cons_sb);
  7817. if (rx_idx != rx_start_idx + num_pkts)
  7818. goto test_loopback_exit;
  7819. cqe = &fp->rx_comp_ring[RCQ_BD(fp->rx_comp_cons)];
  7820. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  7821. if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  7822. goto test_loopback_rx_exit;
  7823. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  7824. if (len != pkt_size)
  7825. goto test_loopback_rx_exit;
  7826. rx_buf = &fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)];
  7827. skb = rx_buf->skb;
  7828. skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
  7829. for (i = ETH_HLEN; i < pkt_size; i++)
  7830. if (*(skb->data + i) != (unsigned char) (i & 0xff))
  7831. goto test_loopback_rx_exit;
  7832. rc = 0;
  7833. test_loopback_rx_exit:
  7834. fp->rx_bd_cons = NEXT_RX_IDX(fp->rx_bd_cons);
  7835. fp->rx_bd_prod = NEXT_RX_IDX(fp->rx_bd_prod);
  7836. fp->rx_comp_cons = NEXT_RCQ_IDX(fp->rx_comp_cons);
  7837. fp->rx_comp_prod = NEXT_RCQ_IDX(fp->rx_comp_prod);
  7838. /* Update producers */
  7839. bnx2x_update_rx_prod(bp, fp, fp->rx_bd_prod, fp->rx_comp_prod,
  7840. fp->rx_sge_prod);
  7841. test_loopback_exit:
  7842. bp->link_params.loopback_mode = LOOPBACK_NONE;
  7843. return rc;
  7844. }
  7845. static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
  7846. {
  7847. int rc = 0, res;
  7848. if (!netif_running(bp->dev))
  7849. return BNX2X_LOOPBACK_FAILED;
  7850. bnx2x_netif_stop(bp, 1);
  7851. bnx2x_acquire_phy_lock(bp);
  7852. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
  7853. if (res) {
  7854. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  7855. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  7856. }
  7857. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
  7858. if (res) {
  7859. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  7860. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  7861. }
  7862. bnx2x_release_phy_lock(bp);
  7863. bnx2x_netif_start(bp);
  7864. return rc;
  7865. }
  7866. #define CRC32_RESIDUAL 0xdebb20e3
  7867. static int bnx2x_test_nvram(struct bnx2x *bp)
  7868. {
  7869. static const struct {
  7870. int offset;
  7871. int size;
  7872. } nvram_tbl[] = {
  7873. { 0, 0x14 }, /* bootstrap */
  7874. { 0x14, 0xec }, /* dir */
  7875. { 0x100, 0x350 }, /* manuf_info */
  7876. { 0x450, 0xf0 }, /* feature_info */
  7877. { 0x640, 0x64 }, /* upgrade_key_info */
  7878. { 0x6a4, 0x64 },
  7879. { 0x708, 0x70 }, /* manuf_key_info */
  7880. { 0x778, 0x70 },
  7881. { 0, 0 }
  7882. };
  7883. __be32 buf[0x350 / 4];
  7884. u8 *data = (u8 *)buf;
  7885. int i, rc;
  7886. u32 magic, csum;
  7887. rc = bnx2x_nvram_read(bp, 0, data, 4);
  7888. if (rc) {
  7889. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  7890. goto test_nvram_exit;
  7891. }
  7892. magic = be32_to_cpu(buf[0]);
  7893. if (magic != 0x669955aa) {
  7894. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  7895. rc = -ENODEV;
  7896. goto test_nvram_exit;
  7897. }
  7898. for (i = 0; nvram_tbl[i].size; i++) {
  7899. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  7900. nvram_tbl[i].size);
  7901. if (rc) {
  7902. DP(NETIF_MSG_PROBE,
  7903. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  7904. goto test_nvram_exit;
  7905. }
  7906. csum = ether_crc_le(nvram_tbl[i].size, data);
  7907. if (csum != CRC32_RESIDUAL) {
  7908. DP(NETIF_MSG_PROBE,
  7909. "nvram_tbl[%d] csum value (0x%08x)\n", i, csum);
  7910. rc = -ENODEV;
  7911. goto test_nvram_exit;
  7912. }
  7913. }
  7914. test_nvram_exit:
  7915. return rc;
  7916. }
  7917. static int bnx2x_test_intr(struct bnx2x *bp)
  7918. {
  7919. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  7920. int i, rc;
  7921. if (!netif_running(bp->dev))
  7922. return -ENODEV;
  7923. config->hdr.length = 0;
  7924. if (CHIP_IS_E1(bp))
  7925. config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
  7926. else
  7927. config->hdr.offset = BP_FUNC(bp);
  7928. config->hdr.client_id = bp->fp->cl_id;
  7929. config->hdr.reserved1 = 0;
  7930. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  7931. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  7932. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  7933. if (rc == 0) {
  7934. bp->set_mac_pending++;
  7935. for (i = 0; i < 10; i++) {
  7936. if (!bp->set_mac_pending)
  7937. break;
  7938. msleep_interruptible(10);
  7939. }
  7940. if (i == 10)
  7941. rc = -ENODEV;
  7942. }
  7943. return rc;
  7944. }
  7945. static void bnx2x_self_test(struct net_device *dev,
  7946. struct ethtool_test *etest, u64 *buf)
  7947. {
  7948. struct bnx2x *bp = netdev_priv(dev);
  7949. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  7950. if (!netif_running(dev))
  7951. return;
  7952. /* offline tests are not supported in MF mode */
  7953. if (IS_E1HMF(bp))
  7954. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  7955. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  7956. u8 link_up;
  7957. link_up = bp->link_vars.link_up;
  7958. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7959. bnx2x_nic_load(bp, LOAD_DIAG);
  7960. /* wait until link state is restored */
  7961. bnx2x_wait_for_link(bp, link_up);
  7962. if (bnx2x_test_registers(bp) != 0) {
  7963. buf[0] = 1;
  7964. etest->flags |= ETH_TEST_FL_FAILED;
  7965. }
  7966. if (bnx2x_test_memory(bp) != 0) {
  7967. buf[1] = 1;
  7968. etest->flags |= ETH_TEST_FL_FAILED;
  7969. }
  7970. buf[2] = bnx2x_test_loopback(bp, link_up);
  7971. if (buf[2] != 0)
  7972. etest->flags |= ETH_TEST_FL_FAILED;
  7973. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7974. bnx2x_nic_load(bp, LOAD_NORMAL);
  7975. /* wait until link state is restored */
  7976. bnx2x_wait_for_link(bp, link_up);
  7977. }
  7978. if (bnx2x_test_nvram(bp) != 0) {
  7979. buf[3] = 1;
  7980. etest->flags |= ETH_TEST_FL_FAILED;
  7981. }
  7982. if (bnx2x_test_intr(bp) != 0) {
  7983. buf[4] = 1;
  7984. etest->flags |= ETH_TEST_FL_FAILED;
  7985. }
  7986. if (bp->port.pmf)
  7987. if (bnx2x_link_test(bp) != 0) {
  7988. buf[5] = 1;
  7989. etest->flags |= ETH_TEST_FL_FAILED;
  7990. }
  7991. #ifdef BNX2X_EXTRA_DEBUG
  7992. bnx2x_panic_dump(bp);
  7993. #endif
  7994. }
  7995. static const struct {
  7996. long offset;
  7997. int size;
  7998. u8 string[ETH_GSTRING_LEN];
  7999. } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
  8000. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
  8001. { Q_STATS_OFFSET32(error_bytes_received_hi),
  8002. 8, "[%d]: rx_error_bytes" },
  8003. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  8004. 8, "[%d]: rx_ucast_packets" },
  8005. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  8006. 8, "[%d]: rx_mcast_packets" },
  8007. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  8008. 8, "[%d]: rx_bcast_packets" },
  8009. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
  8010. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  8011. 4, "[%d]: rx_phy_ip_err_discards"},
  8012. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  8013. 4, "[%d]: rx_skb_alloc_discard" },
  8014. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
  8015. /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
  8016. { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  8017. 8, "[%d]: tx_packets" }
  8018. };
  8019. static const struct {
  8020. long offset;
  8021. int size;
  8022. u32 flags;
  8023. #define STATS_FLAGS_PORT 1
  8024. #define STATS_FLAGS_FUNC 2
  8025. #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
  8026. u8 string[ETH_GSTRING_LEN];
  8027. } bnx2x_stats_arr[BNX2X_NUM_STATS] = {
  8028. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  8029. 8, STATS_FLAGS_BOTH, "rx_bytes" },
  8030. { STATS_OFFSET32(error_bytes_received_hi),
  8031. 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
  8032. { STATS_OFFSET32(total_unicast_packets_received_hi),
  8033. 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
  8034. { STATS_OFFSET32(total_multicast_packets_received_hi),
  8035. 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
  8036. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  8037. 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
  8038. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  8039. 8, STATS_FLAGS_PORT, "rx_crc_errors" },
  8040. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  8041. 8, STATS_FLAGS_PORT, "rx_align_errors" },
  8042. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  8043. 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
  8044. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  8045. 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
  8046. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  8047. 8, STATS_FLAGS_PORT, "rx_fragments" },
  8048. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  8049. 8, STATS_FLAGS_PORT, "rx_jabbers" },
  8050. { STATS_OFFSET32(no_buff_discard_hi),
  8051. 8, STATS_FLAGS_BOTH, "rx_discards" },
  8052. { STATS_OFFSET32(mac_filter_discard),
  8053. 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
  8054. { STATS_OFFSET32(xxoverflow_discard),
  8055. 4, STATS_FLAGS_PORT, "rx_fw_discards" },
  8056. { STATS_OFFSET32(brb_drop_hi),
  8057. 8, STATS_FLAGS_PORT, "rx_brb_discard" },
  8058. { STATS_OFFSET32(brb_truncate_hi),
  8059. 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
  8060. { STATS_OFFSET32(pause_frames_received_hi),
  8061. 8, STATS_FLAGS_PORT, "rx_pause_frames" },
  8062. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  8063. 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
  8064. { STATS_OFFSET32(nig_timer_max),
  8065. 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
  8066. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  8067. 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
  8068. { STATS_OFFSET32(rx_skb_alloc_failed),
  8069. 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
  8070. { STATS_OFFSET32(hw_csum_err),
  8071. 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
  8072. { STATS_OFFSET32(total_bytes_transmitted_hi),
  8073. 8, STATS_FLAGS_BOTH, "tx_bytes" },
  8074. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  8075. 8, STATS_FLAGS_PORT, "tx_error_bytes" },
  8076. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  8077. 8, STATS_FLAGS_BOTH, "tx_packets" },
  8078. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  8079. 8, STATS_FLAGS_PORT, "tx_mac_errors" },
  8080. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  8081. 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
  8082. { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  8083. 8, STATS_FLAGS_PORT, "tx_single_collisions" },
  8084. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  8085. 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
  8086. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  8087. 8, STATS_FLAGS_PORT, "tx_deferred" },
  8088. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  8089. 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
  8090. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  8091. 8, STATS_FLAGS_PORT, "tx_late_collisions" },
  8092. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  8093. 8, STATS_FLAGS_PORT, "tx_total_collisions" },
  8094. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  8095. 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
  8096. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  8097. 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
  8098. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  8099. 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
  8100. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  8101. 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
  8102. { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  8103. 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
  8104. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  8105. 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
  8106. /* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
  8107. 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
  8108. { STATS_OFFSET32(pause_frames_sent_hi),
  8109. 8, STATS_FLAGS_PORT, "tx_pause_frames" }
  8110. };
  8111. #define IS_PORT_STAT(i) \
  8112. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  8113. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  8114. #define IS_E1HMF_MODE_STAT(bp) \
  8115. (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS))
  8116. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  8117. {
  8118. struct bnx2x *bp = netdev_priv(dev);
  8119. int i, j, k;
  8120. switch (stringset) {
  8121. case ETH_SS_STATS:
  8122. if (is_multi(bp)) {
  8123. k = 0;
  8124. for_each_queue(bp, i) {
  8125. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  8126. sprintf(buf + (k + j)*ETH_GSTRING_LEN,
  8127. bnx2x_q_stats_arr[j].string, i);
  8128. k += BNX2X_NUM_Q_STATS;
  8129. }
  8130. if (IS_E1HMF_MODE_STAT(bp))
  8131. break;
  8132. for (j = 0; j < BNX2X_NUM_STATS; j++)
  8133. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  8134. bnx2x_stats_arr[j].string);
  8135. } else {
  8136. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  8137. if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
  8138. continue;
  8139. strcpy(buf + j*ETH_GSTRING_LEN,
  8140. bnx2x_stats_arr[i].string);
  8141. j++;
  8142. }
  8143. }
  8144. break;
  8145. case ETH_SS_TEST:
  8146. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  8147. break;
  8148. }
  8149. }
  8150. static int bnx2x_get_stats_count(struct net_device *dev)
  8151. {
  8152. struct bnx2x *bp = netdev_priv(dev);
  8153. int i, num_stats;
  8154. if (is_multi(bp)) {
  8155. num_stats = BNX2X_NUM_Q_STATS * BNX2X_NUM_QUEUES(bp);
  8156. if (!IS_E1HMF_MODE_STAT(bp))
  8157. num_stats += BNX2X_NUM_STATS;
  8158. } else {
  8159. if (IS_E1HMF_MODE_STAT(bp)) {
  8160. num_stats = 0;
  8161. for (i = 0; i < BNX2X_NUM_STATS; i++)
  8162. if (IS_FUNC_STAT(i))
  8163. num_stats++;
  8164. } else
  8165. num_stats = BNX2X_NUM_STATS;
  8166. }
  8167. return num_stats;
  8168. }
  8169. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  8170. struct ethtool_stats *stats, u64 *buf)
  8171. {
  8172. struct bnx2x *bp = netdev_priv(dev);
  8173. u32 *hw_stats, *offset;
  8174. int i, j, k;
  8175. if (is_multi(bp)) {
  8176. k = 0;
  8177. for_each_queue(bp, i) {
  8178. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  8179. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  8180. if (bnx2x_q_stats_arr[j].size == 0) {
  8181. /* skip this counter */
  8182. buf[k + j] = 0;
  8183. continue;
  8184. }
  8185. offset = (hw_stats +
  8186. bnx2x_q_stats_arr[j].offset);
  8187. if (bnx2x_q_stats_arr[j].size == 4) {
  8188. /* 4-byte counter */
  8189. buf[k + j] = (u64) *offset;
  8190. continue;
  8191. }
  8192. /* 8-byte counter */
  8193. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  8194. }
  8195. k += BNX2X_NUM_Q_STATS;
  8196. }
  8197. if (IS_E1HMF_MODE_STAT(bp))
  8198. return;
  8199. hw_stats = (u32 *)&bp->eth_stats;
  8200. for (j = 0; j < BNX2X_NUM_STATS; j++) {
  8201. if (bnx2x_stats_arr[j].size == 0) {
  8202. /* skip this counter */
  8203. buf[k + j] = 0;
  8204. continue;
  8205. }
  8206. offset = (hw_stats + bnx2x_stats_arr[j].offset);
  8207. if (bnx2x_stats_arr[j].size == 4) {
  8208. /* 4-byte counter */
  8209. buf[k + j] = (u64) *offset;
  8210. continue;
  8211. }
  8212. /* 8-byte counter */
  8213. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  8214. }
  8215. } else {
  8216. hw_stats = (u32 *)&bp->eth_stats;
  8217. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  8218. if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
  8219. continue;
  8220. if (bnx2x_stats_arr[i].size == 0) {
  8221. /* skip this counter */
  8222. buf[j] = 0;
  8223. j++;
  8224. continue;
  8225. }
  8226. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  8227. if (bnx2x_stats_arr[i].size == 4) {
  8228. /* 4-byte counter */
  8229. buf[j] = (u64) *offset;
  8230. j++;
  8231. continue;
  8232. }
  8233. /* 8-byte counter */
  8234. buf[j] = HILO_U64(*offset, *(offset + 1));
  8235. j++;
  8236. }
  8237. }
  8238. }
  8239. static int bnx2x_phys_id(struct net_device *dev, u32 data)
  8240. {
  8241. struct bnx2x *bp = netdev_priv(dev);
  8242. int port = BP_PORT(bp);
  8243. int i;
  8244. if (!netif_running(dev))
  8245. return 0;
  8246. if (!bp->port.pmf)
  8247. return 0;
  8248. if (data == 0)
  8249. data = 2;
  8250. for (i = 0; i < (data * 2); i++) {
  8251. if ((i % 2) == 0)
  8252. bnx2x_set_led(bp, port, LED_MODE_OPER, SPEED_1000,
  8253. bp->link_params.hw_led_mode,
  8254. bp->link_params.chip_id);
  8255. else
  8256. bnx2x_set_led(bp, port, LED_MODE_OFF, 0,
  8257. bp->link_params.hw_led_mode,
  8258. bp->link_params.chip_id);
  8259. msleep_interruptible(500);
  8260. if (signal_pending(current))
  8261. break;
  8262. }
  8263. if (bp->link_vars.link_up)
  8264. bnx2x_set_led(bp, port, LED_MODE_OPER,
  8265. bp->link_vars.line_speed,
  8266. bp->link_params.hw_led_mode,
  8267. bp->link_params.chip_id);
  8268. return 0;
  8269. }
  8270. static struct ethtool_ops bnx2x_ethtool_ops = {
  8271. .get_settings = bnx2x_get_settings,
  8272. .set_settings = bnx2x_set_settings,
  8273. .get_drvinfo = bnx2x_get_drvinfo,
  8274. .get_regs_len = bnx2x_get_regs_len,
  8275. .get_regs = bnx2x_get_regs,
  8276. .get_wol = bnx2x_get_wol,
  8277. .set_wol = bnx2x_set_wol,
  8278. .get_msglevel = bnx2x_get_msglevel,
  8279. .set_msglevel = bnx2x_set_msglevel,
  8280. .nway_reset = bnx2x_nway_reset,
  8281. .get_link = ethtool_op_get_link,
  8282. .get_eeprom_len = bnx2x_get_eeprom_len,
  8283. .get_eeprom = bnx2x_get_eeprom,
  8284. .set_eeprom = bnx2x_set_eeprom,
  8285. .get_coalesce = bnx2x_get_coalesce,
  8286. .set_coalesce = bnx2x_set_coalesce,
  8287. .get_ringparam = bnx2x_get_ringparam,
  8288. .set_ringparam = bnx2x_set_ringparam,
  8289. .get_pauseparam = bnx2x_get_pauseparam,
  8290. .set_pauseparam = bnx2x_set_pauseparam,
  8291. .get_rx_csum = bnx2x_get_rx_csum,
  8292. .set_rx_csum = bnx2x_set_rx_csum,
  8293. .get_tx_csum = ethtool_op_get_tx_csum,
  8294. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  8295. .set_flags = bnx2x_set_flags,
  8296. .get_flags = ethtool_op_get_flags,
  8297. .get_sg = ethtool_op_get_sg,
  8298. .set_sg = ethtool_op_set_sg,
  8299. .get_tso = ethtool_op_get_tso,
  8300. .set_tso = bnx2x_set_tso,
  8301. .self_test_count = bnx2x_self_test_count,
  8302. .self_test = bnx2x_self_test,
  8303. .get_strings = bnx2x_get_strings,
  8304. .phys_id = bnx2x_phys_id,
  8305. .get_stats_count = bnx2x_get_stats_count,
  8306. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  8307. };
  8308. /* end of ethtool_ops */
  8309. /****************************************************************************
  8310. * General service functions
  8311. ****************************************************************************/
  8312. static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
  8313. {
  8314. u16 pmcsr;
  8315. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  8316. switch (state) {
  8317. case PCI_D0:
  8318. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  8319. ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  8320. PCI_PM_CTRL_PME_STATUS));
  8321. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  8322. /* delay required during transition out of D3hot */
  8323. msleep(20);
  8324. break;
  8325. case PCI_D3hot:
  8326. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  8327. pmcsr |= 3;
  8328. if (bp->wol)
  8329. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  8330. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  8331. pmcsr);
  8332. /* No more memory access after this point until
  8333. * device is brought back to D0.
  8334. */
  8335. break;
  8336. default:
  8337. return -EINVAL;
  8338. }
  8339. return 0;
  8340. }
  8341. static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
  8342. {
  8343. u16 rx_cons_sb;
  8344. /* Tell compiler that status block fields can change */
  8345. barrier();
  8346. rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
  8347. if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  8348. rx_cons_sb++;
  8349. return (fp->rx_comp_cons != rx_cons_sb);
  8350. }
  8351. /*
  8352. * net_device service functions
  8353. */
  8354. static int bnx2x_poll(struct napi_struct *napi, int budget)
  8355. {
  8356. struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
  8357. napi);
  8358. struct bnx2x *bp = fp->bp;
  8359. int work_done = 0;
  8360. #ifdef BNX2X_STOP_ON_ERROR
  8361. if (unlikely(bp->panic))
  8362. goto poll_panic;
  8363. #endif
  8364. prefetch(fp->tx_buf_ring[TX_BD(fp->tx_pkt_cons)].skb);
  8365. prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb);
  8366. prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256);
  8367. bnx2x_update_fpsb_idx(fp);
  8368. if (bnx2x_has_tx_work(fp))
  8369. bnx2x_tx_int(fp);
  8370. if (bnx2x_has_rx_work(fp)) {
  8371. work_done = bnx2x_rx_int(fp, budget);
  8372. /* must not complete if we consumed full budget */
  8373. if (work_done >= budget)
  8374. goto poll_again;
  8375. }
  8376. /* BNX2X_HAS_WORK() reads the status block, thus we need to
  8377. * ensure that status block indices have been actually read
  8378. * (bnx2x_update_fpsb_idx) prior to this check (BNX2X_HAS_WORK)
  8379. * so that we won't write the "newer" value of the status block to IGU
  8380. * (if there was a DMA right after BNX2X_HAS_WORK and
  8381. * if there is no rmb, the memory reading (bnx2x_update_fpsb_idx)
  8382. * may be postponed to right before bnx2x_ack_sb). In this case
  8383. * there will never be another interrupt until there is another update
  8384. * of the status block, while there is still unhandled work.
  8385. */
  8386. rmb();
  8387. if (!BNX2X_HAS_WORK(fp)) {
  8388. #ifdef BNX2X_STOP_ON_ERROR
  8389. poll_panic:
  8390. #endif
  8391. napi_complete(napi);
  8392. bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
  8393. le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
  8394. bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
  8395. le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
  8396. }
  8397. poll_again:
  8398. return work_done;
  8399. }
  8400. /* we split the first BD into headers and data BDs
  8401. * to ease the pain of our fellow microcode engineers
  8402. * we use one mapping for both BDs
  8403. * So far this has only been observed to happen
  8404. * in Other Operating Systems(TM)
  8405. */
  8406. static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
  8407. struct bnx2x_fastpath *fp,
  8408. struct eth_tx_bd **tx_bd, u16 hlen,
  8409. u16 bd_prod, int nbd)
  8410. {
  8411. struct eth_tx_bd *h_tx_bd = *tx_bd;
  8412. struct eth_tx_bd *d_tx_bd;
  8413. dma_addr_t mapping;
  8414. int old_len = le16_to_cpu(h_tx_bd->nbytes);
  8415. /* first fix first BD */
  8416. h_tx_bd->nbd = cpu_to_le16(nbd);
  8417. h_tx_bd->nbytes = cpu_to_le16(hlen);
  8418. DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
  8419. "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
  8420. h_tx_bd->addr_lo, h_tx_bd->nbd);
  8421. /* now get a new data BD
  8422. * (after the pbd) and fill it */
  8423. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  8424. d_tx_bd = &fp->tx_desc_ring[bd_prod];
  8425. mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
  8426. le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
  8427. d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  8428. d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  8429. d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
  8430. d_tx_bd->vlan = 0;
  8431. /* this marks the BD as one that has no individual mapping
  8432. * the FW ignores this flag in a BD not marked start
  8433. */
  8434. d_tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_SW_LSO;
  8435. DP(NETIF_MSG_TX_QUEUED,
  8436. "TSO split data size is %d (%x:%x)\n",
  8437. d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
  8438. /* update tx_bd for marking the last BD flag */
  8439. *tx_bd = d_tx_bd;
  8440. return bd_prod;
  8441. }
  8442. static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
  8443. {
  8444. if (fix > 0)
  8445. csum = (u16) ~csum_fold(csum_sub(csum,
  8446. csum_partial(t_header - fix, fix, 0)));
  8447. else if (fix < 0)
  8448. csum = (u16) ~csum_fold(csum_add(csum,
  8449. csum_partial(t_header, -fix, 0)));
  8450. return swab16(csum);
  8451. }
  8452. static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
  8453. {
  8454. u32 rc;
  8455. if (skb->ip_summed != CHECKSUM_PARTIAL)
  8456. rc = XMIT_PLAIN;
  8457. else {
  8458. if (skb->protocol == htons(ETH_P_IPV6)) {
  8459. rc = XMIT_CSUM_V6;
  8460. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  8461. rc |= XMIT_CSUM_TCP;
  8462. } else {
  8463. rc = XMIT_CSUM_V4;
  8464. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  8465. rc |= XMIT_CSUM_TCP;
  8466. }
  8467. }
  8468. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
  8469. rc |= XMIT_GSO_V4;
  8470. else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  8471. rc |= XMIT_GSO_V6;
  8472. return rc;
  8473. }
  8474. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  8475. /* check if packet requires linearization (packet is too fragmented)
  8476. no need to check fragmentation if page size > 8K (there will be no
  8477. violation to FW restrictions) */
  8478. static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
  8479. u32 xmit_type)
  8480. {
  8481. int to_copy = 0;
  8482. int hlen = 0;
  8483. int first_bd_sz = 0;
  8484. /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
  8485. if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
  8486. if (xmit_type & XMIT_GSO) {
  8487. unsigned short lso_mss = skb_shinfo(skb)->gso_size;
  8488. /* Check if LSO packet needs to be copied:
  8489. 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
  8490. int wnd_size = MAX_FETCH_BD - 3;
  8491. /* Number of windows to check */
  8492. int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
  8493. int wnd_idx = 0;
  8494. int frag_idx = 0;
  8495. u32 wnd_sum = 0;
  8496. /* Headers length */
  8497. hlen = (int)(skb_transport_header(skb) - skb->data) +
  8498. tcp_hdrlen(skb);
  8499. /* Amount of data (w/o headers) on linear part of SKB*/
  8500. first_bd_sz = skb_headlen(skb) - hlen;
  8501. wnd_sum = first_bd_sz;
  8502. /* Calculate the first sum - it's special */
  8503. for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
  8504. wnd_sum +=
  8505. skb_shinfo(skb)->frags[frag_idx].size;
  8506. /* If there was data on linear skb data - check it */
  8507. if (first_bd_sz > 0) {
  8508. if (unlikely(wnd_sum < lso_mss)) {
  8509. to_copy = 1;
  8510. goto exit_lbl;
  8511. }
  8512. wnd_sum -= first_bd_sz;
  8513. }
  8514. /* Others are easier: run through the frag list and
  8515. check all windows */
  8516. for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
  8517. wnd_sum +=
  8518. skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
  8519. if (unlikely(wnd_sum < lso_mss)) {
  8520. to_copy = 1;
  8521. break;
  8522. }
  8523. wnd_sum -=
  8524. skb_shinfo(skb)->frags[wnd_idx].size;
  8525. }
  8526. } else {
  8527. /* in non-LSO too fragmented packet should always
  8528. be linearized */
  8529. to_copy = 1;
  8530. }
  8531. }
  8532. exit_lbl:
  8533. if (unlikely(to_copy))
  8534. DP(NETIF_MSG_TX_QUEUED,
  8535. "Linearization IS REQUIRED for %s packet. "
  8536. "num_frags %d hlen %d first_bd_sz %d\n",
  8537. (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
  8538. skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
  8539. return to_copy;
  8540. }
  8541. #endif
  8542. /* called with netif_tx_lock
  8543. * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
  8544. * netif_wake_queue()
  8545. */
  8546. static int bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
  8547. {
  8548. struct bnx2x *bp = netdev_priv(dev);
  8549. struct bnx2x_fastpath *fp;
  8550. struct netdev_queue *txq;
  8551. struct sw_tx_bd *tx_buf;
  8552. struct eth_tx_bd *tx_bd;
  8553. struct eth_tx_parse_bd *pbd = NULL;
  8554. u16 pkt_prod, bd_prod;
  8555. int nbd, fp_index;
  8556. dma_addr_t mapping;
  8557. u32 xmit_type = bnx2x_xmit_type(bp, skb);
  8558. int vlan_off = (bp->e1hov ? 4 : 0);
  8559. int i;
  8560. u8 hlen = 0;
  8561. #ifdef BNX2X_STOP_ON_ERROR
  8562. if (unlikely(bp->panic))
  8563. return NETDEV_TX_BUSY;
  8564. #endif
  8565. fp_index = skb_get_queue_mapping(skb);
  8566. txq = netdev_get_tx_queue(dev, fp_index);
  8567. fp = &bp->fp[fp_index];
  8568. if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
  8569. fp->eth_q_stats.driver_xoff++,
  8570. netif_tx_stop_queue(txq);
  8571. BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
  8572. return NETDEV_TX_BUSY;
  8573. }
  8574. DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)"
  8575. " gso type %x xmit_type %x\n",
  8576. skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
  8577. ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
  8578. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  8579. /* First, check if we need to linearize the skb (due to FW
  8580. restrictions). No need to check fragmentation if page size > 8K
  8581. (there will be no violation to FW restrictions) */
  8582. if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
  8583. /* Statistics of linearization */
  8584. bp->lin_cnt++;
  8585. if (skb_linearize(skb) != 0) {
  8586. DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
  8587. "silently dropping this SKB\n");
  8588. dev_kfree_skb_any(skb);
  8589. return NETDEV_TX_OK;
  8590. }
  8591. }
  8592. #endif
  8593. /*
  8594. Please read carefully. First we use one BD which we mark as start,
  8595. then for TSO or xsum we have a parsing info BD,
  8596. and only then we have the rest of the TSO BDs.
  8597. (don't forget to mark the last one as last,
  8598. and to unmap only AFTER you write to the BD ...)
  8599. And above all, all pdb sizes are in words - NOT DWORDS!
  8600. */
  8601. pkt_prod = fp->tx_pkt_prod++;
  8602. bd_prod = TX_BD(fp->tx_bd_prod);
  8603. /* get a tx_buf and first BD */
  8604. tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
  8605. tx_bd = &fp->tx_desc_ring[bd_prod];
  8606. tx_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  8607. tx_bd->general_data = (UNICAST_ADDRESS <<
  8608. ETH_TX_BD_ETH_ADDR_TYPE_SHIFT);
  8609. /* header nbd */
  8610. tx_bd->general_data |= (1 << ETH_TX_BD_HDR_NBDS_SHIFT);
  8611. /* remember the first BD of the packet */
  8612. tx_buf->first_bd = fp->tx_bd_prod;
  8613. tx_buf->skb = skb;
  8614. DP(NETIF_MSG_TX_QUEUED,
  8615. "sending pkt %u @%p next_idx %u bd %u @%p\n",
  8616. pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_bd);
  8617. #ifdef BCM_VLAN
  8618. if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) &&
  8619. (bp->flags & HW_VLAN_TX_FLAG)) {
  8620. tx_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb));
  8621. tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG;
  8622. vlan_off += 4;
  8623. } else
  8624. #endif
  8625. tx_bd->vlan = cpu_to_le16(pkt_prod);
  8626. if (xmit_type) {
  8627. /* turn on parsing and get a BD */
  8628. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  8629. pbd = (void *)&fp->tx_desc_ring[bd_prod];
  8630. memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
  8631. }
  8632. if (xmit_type & XMIT_CSUM) {
  8633. hlen = (skb_network_header(skb) - skb->data + vlan_off) / 2;
  8634. /* for now NS flag is not used in Linux */
  8635. pbd->global_data =
  8636. (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
  8637. ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT));
  8638. pbd->ip_hlen = (skb_transport_header(skb) -
  8639. skb_network_header(skb)) / 2;
  8640. hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2;
  8641. pbd->total_hlen = cpu_to_le16(hlen);
  8642. hlen = hlen*2 - vlan_off;
  8643. tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_TCP_CSUM;
  8644. if (xmit_type & XMIT_CSUM_V4)
  8645. tx_bd->bd_flags.as_bitfield |=
  8646. ETH_TX_BD_FLAGS_IP_CSUM;
  8647. else
  8648. tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_IPV6;
  8649. if (xmit_type & XMIT_CSUM_TCP) {
  8650. pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
  8651. } else {
  8652. s8 fix = SKB_CS_OFF(skb); /* signed! */
  8653. pbd->global_data |= ETH_TX_PARSE_BD_CS_ANY_FLG;
  8654. pbd->cs_offset = fix / 2;
  8655. DP(NETIF_MSG_TX_QUEUED,
  8656. "hlen %d offset %d fix %d csum before fix %x\n",
  8657. le16_to_cpu(pbd->total_hlen), pbd->cs_offset, fix,
  8658. SKB_CS(skb));
  8659. /* HW bug: fixup the CSUM */
  8660. pbd->tcp_pseudo_csum =
  8661. bnx2x_csum_fix(skb_transport_header(skb),
  8662. SKB_CS(skb), fix);
  8663. DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
  8664. pbd->tcp_pseudo_csum);
  8665. }
  8666. }
  8667. mapping = pci_map_single(bp->pdev, skb->data,
  8668. skb_headlen(skb), PCI_DMA_TODEVICE);
  8669. tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  8670. tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  8671. nbd = skb_shinfo(skb)->nr_frags + ((pbd == NULL) ? 1 : 2);
  8672. tx_bd->nbd = cpu_to_le16(nbd);
  8673. tx_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  8674. DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
  8675. " nbytes %d flags %x vlan %x\n",
  8676. tx_bd, tx_bd->addr_hi, tx_bd->addr_lo, le16_to_cpu(tx_bd->nbd),
  8677. le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield,
  8678. le16_to_cpu(tx_bd->vlan));
  8679. if (xmit_type & XMIT_GSO) {
  8680. DP(NETIF_MSG_TX_QUEUED,
  8681. "TSO packet len %d hlen %d total len %d tso size %d\n",
  8682. skb->len, hlen, skb_headlen(skb),
  8683. skb_shinfo(skb)->gso_size);
  8684. tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
  8685. if (unlikely(skb_headlen(skb) > hlen))
  8686. bd_prod = bnx2x_tx_split(bp, fp, &tx_bd, hlen,
  8687. bd_prod, ++nbd);
  8688. pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
  8689. pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
  8690. pbd->tcp_flags = pbd_tcp_flags(skb);
  8691. if (xmit_type & XMIT_GSO_V4) {
  8692. pbd->ip_id = swab16(ip_hdr(skb)->id);
  8693. pbd->tcp_pseudo_csum =
  8694. swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  8695. ip_hdr(skb)->daddr,
  8696. 0, IPPROTO_TCP, 0));
  8697. } else
  8698. pbd->tcp_pseudo_csum =
  8699. swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  8700. &ipv6_hdr(skb)->daddr,
  8701. 0, IPPROTO_TCP, 0));
  8702. pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN;
  8703. }
  8704. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  8705. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  8706. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  8707. tx_bd = &fp->tx_desc_ring[bd_prod];
  8708. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  8709. frag->size, PCI_DMA_TODEVICE);
  8710. tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  8711. tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  8712. tx_bd->nbytes = cpu_to_le16(frag->size);
  8713. tx_bd->vlan = cpu_to_le16(pkt_prod);
  8714. tx_bd->bd_flags.as_bitfield = 0;
  8715. DP(NETIF_MSG_TX_QUEUED,
  8716. "frag %d bd @%p addr (%x:%x) nbytes %d flags %x\n",
  8717. i, tx_bd, tx_bd->addr_hi, tx_bd->addr_lo,
  8718. le16_to_cpu(tx_bd->nbytes), tx_bd->bd_flags.as_bitfield);
  8719. }
  8720. /* now at last mark the BD as the last BD */
  8721. tx_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_END_BD;
  8722. DP(NETIF_MSG_TX_QUEUED, "last bd @%p flags %x\n",
  8723. tx_bd, tx_bd->bd_flags.as_bitfield);
  8724. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  8725. /* now send a tx doorbell, counting the next BD
  8726. * if the packet contains or ends with it
  8727. */
  8728. if (TX_BD_POFF(bd_prod) < nbd)
  8729. nbd++;
  8730. if (pbd)
  8731. DP(NETIF_MSG_TX_QUEUED,
  8732. "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
  8733. " tcp_flags %x xsum %x seq %u hlen %u\n",
  8734. pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id,
  8735. pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum,
  8736. pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen));
  8737. DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
  8738. /*
  8739. * Make sure that the BD data is updated before updating the producer
  8740. * since FW might read the BD right after the producer is updated.
  8741. * This is only applicable for weak-ordered memory model archs such
  8742. * as IA-64. The following barrier is also mandatory since FW will
  8743. * assumes packets must have BDs.
  8744. */
  8745. wmb();
  8746. le16_add_cpu(&fp->hw_tx_prods->bds_prod, nbd);
  8747. mb(); /* FW restriction: must not reorder writing nbd and packets */
  8748. le32_add_cpu(&fp->hw_tx_prods->packets_prod, 1);
  8749. DOORBELL(bp, fp->index, 0);
  8750. mmiowb();
  8751. fp->tx_bd_prod += nbd;
  8752. dev->trans_start = jiffies;
  8753. if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) {
  8754. /* We want bnx2x_tx_int to "see" the updated tx_bd_prod
  8755. if we put Tx into XOFF state. */
  8756. smp_mb();
  8757. netif_tx_stop_queue(txq);
  8758. fp->eth_q_stats.driver_xoff++;
  8759. if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
  8760. netif_tx_wake_queue(txq);
  8761. }
  8762. fp->tx_pkt++;
  8763. return NETDEV_TX_OK;
  8764. }
  8765. /* called with rtnl_lock */
  8766. static int bnx2x_open(struct net_device *dev)
  8767. {
  8768. struct bnx2x *bp = netdev_priv(dev);
  8769. netif_carrier_off(dev);
  8770. bnx2x_set_power_state(bp, PCI_D0);
  8771. return bnx2x_nic_load(bp, LOAD_OPEN);
  8772. }
  8773. /* called with rtnl_lock */
  8774. static int bnx2x_close(struct net_device *dev)
  8775. {
  8776. struct bnx2x *bp = netdev_priv(dev);
  8777. /* Unload the driver, release IRQs */
  8778. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  8779. if (atomic_read(&bp->pdev->enable_cnt) == 1)
  8780. if (!CHIP_REV_IS_SLOW(bp))
  8781. bnx2x_set_power_state(bp, PCI_D3hot);
  8782. return 0;
  8783. }
  8784. /* called with netif_tx_lock from dev_mcast.c */
  8785. static void bnx2x_set_rx_mode(struct net_device *dev)
  8786. {
  8787. struct bnx2x *bp = netdev_priv(dev);
  8788. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  8789. int port = BP_PORT(bp);
  8790. if (bp->state != BNX2X_STATE_OPEN) {
  8791. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  8792. return;
  8793. }
  8794. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
  8795. if (dev->flags & IFF_PROMISC)
  8796. rx_mode = BNX2X_RX_MODE_PROMISC;
  8797. else if ((dev->flags & IFF_ALLMULTI) ||
  8798. ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp)))
  8799. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8800. else { /* some multicasts */
  8801. if (CHIP_IS_E1(bp)) {
  8802. int i, old, offset;
  8803. struct dev_mc_list *mclist;
  8804. struct mac_configuration_cmd *config =
  8805. bnx2x_sp(bp, mcast_config);
  8806. for (i = 0, mclist = dev->mc_list;
  8807. mclist && (i < dev->mc_count);
  8808. i++, mclist = mclist->next) {
  8809. config->config_table[i].
  8810. cam_entry.msb_mac_addr =
  8811. swab16(*(u16 *)&mclist->dmi_addr[0]);
  8812. config->config_table[i].
  8813. cam_entry.middle_mac_addr =
  8814. swab16(*(u16 *)&mclist->dmi_addr[2]);
  8815. config->config_table[i].
  8816. cam_entry.lsb_mac_addr =
  8817. swab16(*(u16 *)&mclist->dmi_addr[4]);
  8818. config->config_table[i].cam_entry.flags =
  8819. cpu_to_le16(port);
  8820. config->config_table[i].
  8821. target_table_entry.flags = 0;
  8822. config->config_table[i].
  8823. target_table_entry.client_id = 0;
  8824. config->config_table[i].
  8825. target_table_entry.vlan_id = 0;
  8826. DP(NETIF_MSG_IFUP,
  8827. "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
  8828. config->config_table[i].
  8829. cam_entry.msb_mac_addr,
  8830. config->config_table[i].
  8831. cam_entry.middle_mac_addr,
  8832. config->config_table[i].
  8833. cam_entry.lsb_mac_addr);
  8834. }
  8835. old = config->hdr.length;
  8836. if (old > i) {
  8837. for (; i < old; i++) {
  8838. if (CAM_IS_INVALID(config->
  8839. config_table[i])) {
  8840. /* already invalidated */
  8841. break;
  8842. }
  8843. /* invalidate */
  8844. CAM_INVALIDATE(config->
  8845. config_table[i]);
  8846. }
  8847. }
  8848. if (CHIP_REV_IS_SLOW(bp))
  8849. offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
  8850. else
  8851. offset = BNX2X_MAX_MULTICAST*(1 + port);
  8852. config->hdr.length = i;
  8853. config->hdr.offset = offset;
  8854. config->hdr.client_id = bp->fp->cl_id;
  8855. config->hdr.reserved1 = 0;
  8856. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  8857. U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
  8858. U64_LO(bnx2x_sp_mapping(bp, mcast_config)),
  8859. 0);
  8860. } else { /* E1H */
  8861. /* Accept one or more multicasts */
  8862. struct dev_mc_list *mclist;
  8863. u32 mc_filter[MC_HASH_SIZE];
  8864. u32 crc, bit, regidx;
  8865. int i;
  8866. memset(mc_filter, 0, 4 * MC_HASH_SIZE);
  8867. for (i = 0, mclist = dev->mc_list;
  8868. mclist && (i < dev->mc_count);
  8869. i++, mclist = mclist->next) {
  8870. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  8871. mclist->dmi_addr);
  8872. crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN);
  8873. bit = (crc >> 24) & 0xff;
  8874. regidx = bit >> 5;
  8875. bit &= 0x1f;
  8876. mc_filter[regidx] |= (1 << bit);
  8877. }
  8878. for (i = 0; i < MC_HASH_SIZE; i++)
  8879. REG_WR(bp, MC_HASH_OFFSET(bp, i),
  8880. mc_filter[i]);
  8881. }
  8882. }
  8883. bp->rx_mode = rx_mode;
  8884. bnx2x_set_storm_rx_mode(bp);
  8885. }
  8886. /* called with rtnl_lock */
  8887. static int bnx2x_change_mac_addr(struct net_device *dev, void *p)
  8888. {
  8889. struct sockaddr *addr = p;
  8890. struct bnx2x *bp = netdev_priv(dev);
  8891. if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
  8892. return -EINVAL;
  8893. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  8894. if (netif_running(dev)) {
  8895. if (CHIP_IS_E1(bp))
  8896. bnx2x_set_mac_addr_e1(bp, 1);
  8897. else
  8898. bnx2x_set_mac_addr_e1h(bp, 1);
  8899. }
  8900. return 0;
  8901. }
  8902. /* called with rtnl_lock */
  8903. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8904. {
  8905. struct mii_ioctl_data *data = if_mii(ifr);
  8906. struct bnx2x *bp = netdev_priv(dev);
  8907. int port = BP_PORT(bp);
  8908. int err;
  8909. switch (cmd) {
  8910. case SIOCGMIIPHY:
  8911. data->phy_id = bp->port.phy_addr;
  8912. /* fallthrough */
  8913. case SIOCGMIIREG: {
  8914. u16 mii_regval;
  8915. if (!netif_running(dev))
  8916. return -EAGAIN;
  8917. mutex_lock(&bp->port.phy_mutex);
  8918. err = bnx2x_cl45_read(bp, port, 0, bp->port.phy_addr,
  8919. DEFAULT_PHY_DEV_ADDR,
  8920. (data->reg_num & 0x1f), &mii_regval);
  8921. data->val_out = mii_regval;
  8922. mutex_unlock(&bp->port.phy_mutex);
  8923. return err;
  8924. }
  8925. case SIOCSMIIREG:
  8926. if (!capable(CAP_NET_ADMIN))
  8927. return -EPERM;
  8928. if (!netif_running(dev))
  8929. return -EAGAIN;
  8930. mutex_lock(&bp->port.phy_mutex);
  8931. err = bnx2x_cl45_write(bp, port, 0, bp->port.phy_addr,
  8932. DEFAULT_PHY_DEV_ADDR,
  8933. (data->reg_num & 0x1f), data->val_in);
  8934. mutex_unlock(&bp->port.phy_mutex);
  8935. return err;
  8936. default:
  8937. /* do nothing */
  8938. break;
  8939. }
  8940. return -EOPNOTSUPP;
  8941. }
  8942. /* called with rtnl_lock */
  8943. static int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
  8944. {
  8945. struct bnx2x *bp = netdev_priv(dev);
  8946. int rc = 0;
  8947. if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
  8948. ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
  8949. return -EINVAL;
  8950. /* This does not race with packet allocation
  8951. * because the actual alloc size is
  8952. * only updated as part of load
  8953. */
  8954. dev->mtu = new_mtu;
  8955. if (netif_running(dev)) {
  8956. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  8957. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  8958. }
  8959. return rc;
  8960. }
  8961. static void bnx2x_tx_timeout(struct net_device *dev)
  8962. {
  8963. struct bnx2x *bp = netdev_priv(dev);
  8964. #ifdef BNX2X_STOP_ON_ERROR
  8965. if (!bp->panic)
  8966. bnx2x_panic();
  8967. #endif
  8968. /* This allows the netif to be shutdown gracefully before resetting */
  8969. schedule_work(&bp->reset_task);
  8970. }
  8971. #ifdef BCM_VLAN
  8972. /* called with rtnl_lock */
  8973. static void bnx2x_vlan_rx_register(struct net_device *dev,
  8974. struct vlan_group *vlgrp)
  8975. {
  8976. struct bnx2x *bp = netdev_priv(dev);
  8977. bp->vlgrp = vlgrp;
  8978. /* Set flags according to the required capabilities */
  8979. bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
  8980. if (dev->features & NETIF_F_HW_VLAN_TX)
  8981. bp->flags |= HW_VLAN_TX_FLAG;
  8982. if (dev->features & NETIF_F_HW_VLAN_RX)
  8983. bp->flags |= HW_VLAN_RX_FLAG;
  8984. if (netif_running(dev))
  8985. bnx2x_set_client_config(bp);
  8986. }
  8987. #endif
  8988. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  8989. static void poll_bnx2x(struct net_device *dev)
  8990. {
  8991. struct bnx2x *bp = netdev_priv(dev);
  8992. disable_irq(bp->pdev->irq);
  8993. bnx2x_interrupt(bp->pdev->irq, dev);
  8994. enable_irq(bp->pdev->irq);
  8995. }
  8996. #endif
  8997. static const struct net_device_ops bnx2x_netdev_ops = {
  8998. .ndo_open = bnx2x_open,
  8999. .ndo_stop = bnx2x_close,
  9000. .ndo_start_xmit = bnx2x_start_xmit,
  9001. .ndo_set_multicast_list = bnx2x_set_rx_mode,
  9002. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9003. .ndo_validate_addr = eth_validate_addr,
  9004. .ndo_do_ioctl = bnx2x_ioctl,
  9005. .ndo_change_mtu = bnx2x_change_mtu,
  9006. .ndo_tx_timeout = bnx2x_tx_timeout,
  9007. #ifdef BCM_VLAN
  9008. .ndo_vlan_rx_register = bnx2x_vlan_rx_register,
  9009. #endif
  9010. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  9011. .ndo_poll_controller = poll_bnx2x,
  9012. #endif
  9013. };
  9014. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9015. struct net_device *dev)
  9016. {
  9017. struct bnx2x *bp;
  9018. int rc;
  9019. SET_NETDEV_DEV(dev, &pdev->dev);
  9020. bp = netdev_priv(dev);
  9021. bp->dev = dev;
  9022. bp->pdev = pdev;
  9023. bp->flags = 0;
  9024. bp->func = PCI_FUNC(pdev->devfn);
  9025. rc = pci_enable_device(pdev);
  9026. if (rc) {
  9027. printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n");
  9028. goto err_out;
  9029. }
  9030. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9031. printk(KERN_ERR PFX "Cannot find PCI device base address,"
  9032. " aborting\n");
  9033. rc = -ENODEV;
  9034. goto err_out_disable;
  9035. }
  9036. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9037. printk(KERN_ERR PFX "Cannot find second PCI device"
  9038. " base address, aborting\n");
  9039. rc = -ENODEV;
  9040. goto err_out_disable;
  9041. }
  9042. if (atomic_read(&pdev->enable_cnt) == 1) {
  9043. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9044. if (rc) {
  9045. printk(KERN_ERR PFX "Cannot obtain PCI resources,"
  9046. " aborting\n");
  9047. goto err_out_disable;
  9048. }
  9049. pci_set_master(pdev);
  9050. pci_save_state(pdev);
  9051. }
  9052. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9053. if (bp->pm_cap == 0) {
  9054. printk(KERN_ERR PFX "Cannot find power management"
  9055. " capability, aborting\n");
  9056. rc = -EIO;
  9057. goto err_out_release;
  9058. }
  9059. bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  9060. if (bp->pcie_cap == 0) {
  9061. printk(KERN_ERR PFX "Cannot find PCI Express capability,"
  9062. " aborting\n");
  9063. rc = -EIO;
  9064. goto err_out_release;
  9065. }
  9066. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
  9067. bp->flags |= USING_DAC_FLAG;
  9068. if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
  9069. printk(KERN_ERR PFX "pci_set_consistent_dma_mask"
  9070. " failed, aborting\n");
  9071. rc = -EIO;
  9072. goto err_out_release;
  9073. }
  9074. } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
  9075. printk(KERN_ERR PFX "System does not support DMA,"
  9076. " aborting\n");
  9077. rc = -EIO;
  9078. goto err_out_release;
  9079. }
  9080. dev->mem_start = pci_resource_start(pdev, 0);
  9081. dev->base_addr = dev->mem_start;
  9082. dev->mem_end = pci_resource_end(pdev, 0);
  9083. dev->irq = pdev->irq;
  9084. bp->regview = pci_ioremap_bar(pdev, 0);
  9085. if (!bp->regview) {
  9086. printk(KERN_ERR PFX "Cannot map register space, aborting\n");
  9087. rc = -ENOMEM;
  9088. goto err_out_release;
  9089. }
  9090. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9091. min_t(u64, BNX2X_DB_SIZE,
  9092. pci_resource_len(pdev, 2)));
  9093. if (!bp->doorbells) {
  9094. printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n");
  9095. rc = -ENOMEM;
  9096. goto err_out_unmap;
  9097. }
  9098. bnx2x_set_power_state(bp, PCI_D0);
  9099. /* clean indirect addresses */
  9100. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9101. PCICFG_VENDOR_ID_OFFSET);
  9102. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
  9103. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
  9104. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
  9105. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
  9106. dev->watchdog_timeo = TX_TIMEOUT;
  9107. dev->netdev_ops = &bnx2x_netdev_ops;
  9108. dev->ethtool_ops = &bnx2x_ethtool_ops;
  9109. dev->features |= NETIF_F_SG;
  9110. dev->features |= NETIF_F_HW_CSUM;
  9111. if (bp->flags & USING_DAC_FLAG)
  9112. dev->features |= NETIF_F_HIGHDMA;
  9113. #ifdef BCM_VLAN
  9114. dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
  9115. bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
  9116. #endif
  9117. dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
  9118. dev->features |= NETIF_F_TSO6;
  9119. return 0;
  9120. err_out_unmap:
  9121. if (bp->regview) {
  9122. iounmap(bp->regview);
  9123. bp->regview = NULL;
  9124. }
  9125. if (bp->doorbells) {
  9126. iounmap(bp->doorbells);
  9127. bp->doorbells = NULL;
  9128. }
  9129. err_out_release:
  9130. if (atomic_read(&pdev->enable_cnt) == 1)
  9131. pci_release_regions(pdev);
  9132. err_out_disable:
  9133. pci_disable_device(pdev);
  9134. pci_set_drvdata(pdev, NULL);
  9135. err_out:
  9136. return rc;
  9137. }
  9138. static int __devinit bnx2x_get_pcie_width(struct bnx2x *bp)
  9139. {
  9140. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9141. val = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9142. return val;
  9143. }
  9144. /* return value of 1=2.5GHz 2=5GHz */
  9145. static int __devinit bnx2x_get_pcie_speed(struct bnx2x *bp)
  9146. {
  9147. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9148. val = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9149. return val;
  9150. }
  9151. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9152. const struct pci_device_id *ent)
  9153. {
  9154. static int version_printed;
  9155. struct net_device *dev = NULL;
  9156. struct bnx2x *bp;
  9157. int rc;
  9158. if (version_printed++ == 0)
  9159. printk(KERN_INFO "%s", version);
  9160. /* dev zeroed in init_etherdev */
  9161. dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT);
  9162. if (!dev) {
  9163. printk(KERN_ERR PFX "Cannot allocate net device\n");
  9164. return -ENOMEM;
  9165. }
  9166. bp = netdev_priv(dev);
  9167. bp->msglevel = debug;
  9168. rc = bnx2x_init_dev(pdev, dev);
  9169. if (rc < 0) {
  9170. free_netdev(dev);
  9171. return rc;
  9172. }
  9173. pci_set_drvdata(pdev, dev);
  9174. rc = bnx2x_init_bp(bp);
  9175. if (rc)
  9176. goto init_one_exit;
  9177. rc = register_netdev(dev);
  9178. if (rc) {
  9179. dev_err(&pdev->dev, "Cannot register net device\n");
  9180. goto init_one_exit;
  9181. }
  9182. printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx,"
  9183. " IRQ %d, ", dev->name, board_info[ent->driver_data].name,
  9184. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9185. bnx2x_get_pcie_width(bp),
  9186. (bnx2x_get_pcie_speed(bp) == 2) ? "5GHz (Gen2)" : "2.5GHz",
  9187. dev->base_addr, bp->pdev->irq);
  9188. printk(KERN_CONT "node addr %pM\n", dev->dev_addr);
  9189. return 0;
  9190. init_one_exit:
  9191. if (bp->regview)
  9192. iounmap(bp->regview);
  9193. if (bp->doorbells)
  9194. iounmap(bp->doorbells);
  9195. free_netdev(dev);
  9196. if (atomic_read(&pdev->enable_cnt) == 1)
  9197. pci_release_regions(pdev);
  9198. pci_disable_device(pdev);
  9199. pci_set_drvdata(pdev, NULL);
  9200. return rc;
  9201. }
  9202. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9203. {
  9204. struct net_device *dev = pci_get_drvdata(pdev);
  9205. struct bnx2x *bp;
  9206. if (!dev) {
  9207. printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
  9208. return;
  9209. }
  9210. bp = netdev_priv(dev);
  9211. unregister_netdev(dev);
  9212. if (bp->regview)
  9213. iounmap(bp->regview);
  9214. if (bp->doorbells)
  9215. iounmap(bp->doorbells);
  9216. free_netdev(dev);
  9217. if (atomic_read(&pdev->enable_cnt) == 1)
  9218. pci_release_regions(pdev);
  9219. pci_disable_device(pdev);
  9220. pci_set_drvdata(pdev, NULL);
  9221. }
  9222. static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
  9223. {
  9224. struct net_device *dev = pci_get_drvdata(pdev);
  9225. struct bnx2x *bp;
  9226. if (!dev) {
  9227. printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
  9228. return -ENODEV;
  9229. }
  9230. bp = netdev_priv(dev);
  9231. rtnl_lock();
  9232. pci_save_state(pdev);
  9233. if (!netif_running(dev)) {
  9234. rtnl_unlock();
  9235. return 0;
  9236. }
  9237. netif_device_detach(dev);
  9238. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  9239. bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
  9240. rtnl_unlock();
  9241. return 0;
  9242. }
  9243. static int bnx2x_resume(struct pci_dev *pdev)
  9244. {
  9245. struct net_device *dev = pci_get_drvdata(pdev);
  9246. struct bnx2x *bp;
  9247. int rc;
  9248. if (!dev) {
  9249. printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
  9250. return -ENODEV;
  9251. }
  9252. bp = netdev_priv(dev);
  9253. rtnl_lock();
  9254. pci_restore_state(pdev);
  9255. if (!netif_running(dev)) {
  9256. rtnl_unlock();
  9257. return 0;
  9258. }
  9259. bnx2x_set_power_state(bp, PCI_D0);
  9260. netif_device_attach(dev);
  9261. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9262. rtnl_unlock();
  9263. return rc;
  9264. }
  9265. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9266. {
  9267. int i;
  9268. bp->state = BNX2X_STATE_ERROR;
  9269. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9270. bnx2x_netif_stop(bp, 0);
  9271. del_timer_sync(&bp->timer);
  9272. bp->stats_state = STATS_STATE_DISABLED;
  9273. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  9274. /* Release IRQs */
  9275. bnx2x_free_irq(bp);
  9276. if (CHIP_IS_E1(bp)) {
  9277. struct mac_configuration_cmd *config =
  9278. bnx2x_sp(bp, mcast_config);
  9279. for (i = 0; i < config->hdr.length; i++)
  9280. CAM_INVALIDATE(config->config_table[i]);
  9281. }
  9282. /* Free SKBs, SGEs, TPA pool and driver internals */
  9283. bnx2x_free_skbs(bp);
  9284. for_each_rx_queue(bp, i)
  9285. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  9286. for_each_rx_queue(bp, i)
  9287. netif_napi_del(&bnx2x_fp(bp, i, napi));
  9288. bnx2x_free_mem(bp);
  9289. bp->state = BNX2X_STATE_CLOSED;
  9290. netif_carrier_off(bp->dev);
  9291. return 0;
  9292. }
  9293. static void bnx2x_eeh_recover(struct bnx2x *bp)
  9294. {
  9295. u32 val;
  9296. mutex_init(&bp->port.phy_mutex);
  9297. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  9298. bp->link_params.shmem_base = bp->common.shmem_base;
  9299. BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
  9300. if (!bp->common.shmem_base ||
  9301. (bp->common.shmem_base < 0xA0000) ||
  9302. (bp->common.shmem_base >= 0xC0000)) {
  9303. BNX2X_DEV_INFO("MCP not active\n");
  9304. bp->flags |= NO_MCP_FLAG;
  9305. return;
  9306. }
  9307. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  9308. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9309. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9310. BNX2X_ERR("BAD MCP validity signature\n");
  9311. if (!BP_NOMCP(bp)) {
  9312. bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
  9313. & DRV_MSG_SEQ_NUMBER_MASK);
  9314. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9315. }
  9316. }
  9317. /**
  9318. * bnx2x_io_error_detected - called when PCI error is detected
  9319. * @pdev: Pointer to PCI device
  9320. * @state: The current pci connection state
  9321. *
  9322. * This function is called after a PCI bus error affecting
  9323. * this device has been detected.
  9324. */
  9325. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  9326. pci_channel_state_t state)
  9327. {
  9328. struct net_device *dev = pci_get_drvdata(pdev);
  9329. struct bnx2x *bp = netdev_priv(dev);
  9330. rtnl_lock();
  9331. netif_device_detach(dev);
  9332. if (netif_running(dev))
  9333. bnx2x_eeh_nic_unload(bp);
  9334. pci_disable_device(pdev);
  9335. rtnl_unlock();
  9336. /* Request a slot reset */
  9337. return PCI_ERS_RESULT_NEED_RESET;
  9338. }
  9339. /**
  9340. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  9341. * @pdev: Pointer to PCI device
  9342. *
  9343. * Restart the card from scratch, as if from a cold-boot.
  9344. */
  9345. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  9346. {
  9347. struct net_device *dev = pci_get_drvdata(pdev);
  9348. struct bnx2x *bp = netdev_priv(dev);
  9349. rtnl_lock();
  9350. if (pci_enable_device(pdev)) {
  9351. dev_err(&pdev->dev,
  9352. "Cannot re-enable PCI device after reset\n");
  9353. rtnl_unlock();
  9354. return PCI_ERS_RESULT_DISCONNECT;
  9355. }
  9356. pci_set_master(pdev);
  9357. pci_restore_state(pdev);
  9358. if (netif_running(dev))
  9359. bnx2x_set_power_state(bp, PCI_D0);
  9360. rtnl_unlock();
  9361. return PCI_ERS_RESULT_RECOVERED;
  9362. }
  9363. /**
  9364. * bnx2x_io_resume - called when traffic can start flowing again
  9365. * @pdev: Pointer to PCI device
  9366. *
  9367. * This callback is called when the error recovery driver tells us that
  9368. * its OK to resume normal operation.
  9369. */
  9370. static void bnx2x_io_resume(struct pci_dev *pdev)
  9371. {
  9372. struct net_device *dev = pci_get_drvdata(pdev);
  9373. struct bnx2x *bp = netdev_priv(dev);
  9374. rtnl_lock();
  9375. bnx2x_eeh_recover(bp);
  9376. if (netif_running(dev))
  9377. bnx2x_nic_load(bp, LOAD_NORMAL);
  9378. netif_device_attach(dev);
  9379. rtnl_unlock();
  9380. }
  9381. static struct pci_error_handlers bnx2x_err_handler = {
  9382. .error_detected = bnx2x_io_error_detected,
  9383. .slot_reset = bnx2x_io_slot_reset,
  9384. .resume = bnx2x_io_resume,
  9385. };
  9386. static struct pci_driver bnx2x_pci_driver = {
  9387. .name = DRV_MODULE_NAME,
  9388. .id_table = bnx2x_pci_tbl,
  9389. .probe = bnx2x_init_one,
  9390. .remove = __devexit_p(bnx2x_remove_one),
  9391. .suspend = bnx2x_suspend,
  9392. .resume = bnx2x_resume,
  9393. .err_handler = &bnx2x_err_handler,
  9394. };
  9395. static int __init bnx2x_init(void)
  9396. {
  9397. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  9398. if (bnx2x_wq == NULL) {
  9399. printk(KERN_ERR PFX "Cannot create workqueue\n");
  9400. return -ENOMEM;
  9401. }
  9402. return pci_register_driver(&bnx2x_pci_driver);
  9403. }
  9404. static void __exit bnx2x_cleanup(void)
  9405. {
  9406. pci_unregister_driver(&bnx2x_pci_driver);
  9407. destroy_workqueue(bnx2x_wq);
  9408. }
  9409. module_init(bnx2x_init);
  9410. module_exit(bnx2x_cleanup);