bnx2x_main.c 344 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840
  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 and fastpath 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 <linux/stringify.h>
  52. #include "bnx2x.h"
  53. #include "bnx2x_init.h"
  54. #include "bnx2x_init_ops.h"
  55. #include "bnx2x_dump.h"
  56. #define DRV_MODULE_VERSION "1.52.1-4"
  57. #define DRV_MODULE_RELDATE "2009/11/09"
  58. #define BNX2X_BC_VER 0x040200
  59. #include <linux/firmware.h>
  60. #include "bnx2x_fw_file_hdr.h"
  61. /* FW files */
  62. #define FW_FILE_VERSION \
  63. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  64. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  65. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  66. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  67. #define FW_FILE_NAME_E1 "bnx2x-e1-" FW_FILE_VERSION ".fw"
  68. #define FW_FILE_NAME_E1H "bnx2x-e1h-" FW_FILE_VERSION ".fw"
  69. /* Time in jiffies before concluding the transmitter is hung */
  70. #define TX_TIMEOUT (5*HZ)
  71. static char version[] __devinitdata =
  72. "Broadcom NetXtreme II 5771x 10Gigabit Ethernet Driver "
  73. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  74. MODULE_AUTHOR("Eliezer Tamir");
  75. MODULE_DESCRIPTION("Broadcom NetXtreme II BCM57710/57711/57711E Driver");
  76. MODULE_LICENSE("GPL");
  77. MODULE_VERSION(DRV_MODULE_VERSION);
  78. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  79. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  80. static int multi_mode = 1;
  81. module_param(multi_mode, int, 0);
  82. MODULE_PARM_DESC(multi_mode, " Multi queue mode "
  83. "(0 Disable; 1 Enable (default))");
  84. static int num_rx_queues;
  85. module_param(num_rx_queues, int, 0);
  86. MODULE_PARM_DESC(num_rx_queues, " Number of Rx queues for multi_mode=1"
  87. " (default is half number of CPUs)");
  88. static int num_tx_queues;
  89. module_param(num_tx_queues, int, 0);
  90. MODULE_PARM_DESC(num_tx_queues, " Number of Tx queues for multi_mode=1"
  91. " (default is half number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. static int int_mode;
  96. module_param(int_mode, int, 0);
  97. MODULE_PARM_DESC(int_mode, " Force interrupt mode (1 INT#x; 2 MSI)");
  98. static int dropless_fc;
  99. module_param(dropless_fc, int, 0);
  100. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  101. static int poll;
  102. module_param(poll, int, 0);
  103. MODULE_PARM_DESC(poll, " Use polling (for debug)");
  104. static int mrrs = -1;
  105. module_param(mrrs, int, 0);
  106. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  107. static int debug;
  108. module_param(debug, int, 0);
  109. MODULE_PARM_DESC(debug, " Default debug msglevel");
  110. static int load_count[3]; /* 0-common, 1-port0, 2-port1 */
  111. static struct workqueue_struct *bnx2x_wq;
  112. enum bnx2x_board_type {
  113. BCM57710 = 0,
  114. BCM57711 = 1,
  115. BCM57711E = 2,
  116. };
  117. /* indexed by board_type, above */
  118. static struct {
  119. char *name;
  120. } board_info[] __devinitdata = {
  121. { "Broadcom NetXtreme II BCM57710 XGb" },
  122. { "Broadcom NetXtreme II BCM57711 XGb" },
  123. { "Broadcom NetXtreme II BCM57711E XGb" }
  124. };
  125. static const struct pci_device_id bnx2x_pci_tbl[] = {
  126. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  127. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  128. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  129. { 0 }
  130. };
  131. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  132. /****************************************************************************
  133. * General service functions
  134. ****************************************************************************/
  135. /* used only at init
  136. * locking is done by mcp
  137. */
  138. void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  139. {
  140. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  141. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  142. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  143. PCICFG_VENDOR_ID_OFFSET);
  144. }
  145. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  146. {
  147. u32 val;
  148. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  149. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  150. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  151. PCICFG_VENDOR_ID_OFFSET);
  152. return val;
  153. }
  154. static const u32 dmae_reg_go_c[] = {
  155. DMAE_REG_GO_C0, DMAE_REG_GO_C1, DMAE_REG_GO_C2, DMAE_REG_GO_C3,
  156. DMAE_REG_GO_C4, DMAE_REG_GO_C5, DMAE_REG_GO_C6, DMAE_REG_GO_C7,
  157. DMAE_REG_GO_C8, DMAE_REG_GO_C9, DMAE_REG_GO_C10, DMAE_REG_GO_C11,
  158. DMAE_REG_GO_C12, DMAE_REG_GO_C13, DMAE_REG_GO_C14, DMAE_REG_GO_C15
  159. };
  160. /* copy command into DMAE command memory and set DMAE command go */
  161. static void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae,
  162. int idx)
  163. {
  164. u32 cmd_offset;
  165. int i;
  166. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  167. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  168. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  169. DP(BNX2X_MSG_OFF, "DMAE cmd[%d].%d (0x%08x) : 0x%08x\n",
  170. idx, i, cmd_offset + i*4, *(((u32 *)dmae) + i));
  171. }
  172. REG_WR(bp, dmae_reg_go_c[idx], 1);
  173. }
  174. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  175. u32 len32)
  176. {
  177. struct dmae_command dmae;
  178. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  179. int cnt = 200;
  180. if (!bp->dmae_ready) {
  181. u32 *data = bnx2x_sp(bp, wb_data[0]);
  182. DP(BNX2X_MSG_OFF, "DMAE is not ready (dst_addr %08x len32 %d)"
  183. " using indirect\n", dst_addr, len32);
  184. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  185. return;
  186. }
  187. memset(&dmae, 0, sizeof(struct dmae_command));
  188. dmae.opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  189. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  190. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  191. #ifdef __BIG_ENDIAN
  192. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  193. #else
  194. DMAE_CMD_ENDIANITY_DW_SWAP |
  195. #endif
  196. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  197. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  198. dmae.src_addr_lo = U64_LO(dma_addr);
  199. dmae.src_addr_hi = U64_HI(dma_addr);
  200. dmae.dst_addr_lo = dst_addr >> 2;
  201. dmae.dst_addr_hi = 0;
  202. dmae.len = len32;
  203. dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  204. dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  205. dmae.comp_val = DMAE_COMP_VAL;
  206. DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
  207. DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
  208. "dst_addr [%x:%08x (%08x)]\n"
  209. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  210. dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo,
  211. dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, dst_addr,
  212. dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val);
  213. DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  214. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  215. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  216. mutex_lock(&bp->dmae_mutex);
  217. *wb_comp = 0;
  218. bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp));
  219. udelay(5);
  220. while (*wb_comp != DMAE_COMP_VAL) {
  221. DP(BNX2X_MSG_OFF, "wb_comp 0x%08x\n", *wb_comp);
  222. if (!cnt) {
  223. BNX2X_ERR("DMAE timeout!\n");
  224. break;
  225. }
  226. cnt--;
  227. /* adjust delay for emulation/FPGA */
  228. if (CHIP_REV_IS_SLOW(bp))
  229. msleep(100);
  230. else
  231. udelay(5);
  232. }
  233. mutex_unlock(&bp->dmae_mutex);
  234. }
  235. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  236. {
  237. struct dmae_command dmae;
  238. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  239. int cnt = 200;
  240. if (!bp->dmae_ready) {
  241. u32 *data = bnx2x_sp(bp, wb_data[0]);
  242. int i;
  243. DP(BNX2X_MSG_OFF, "DMAE is not ready (src_addr %08x len32 %d)"
  244. " using indirect\n", src_addr, len32);
  245. for (i = 0; i < len32; i++)
  246. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  247. return;
  248. }
  249. memset(&dmae, 0, sizeof(struct dmae_command));
  250. dmae.opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  251. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  252. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  253. #ifdef __BIG_ENDIAN
  254. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  255. #else
  256. DMAE_CMD_ENDIANITY_DW_SWAP |
  257. #endif
  258. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  259. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  260. dmae.src_addr_lo = src_addr >> 2;
  261. dmae.src_addr_hi = 0;
  262. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  263. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  264. dmae.len = len32;
  265. dmae.comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  266. dmae.comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  267. dmae.comp_val = DMAE_COMP_VAL;
  268. DP(BNX2X_MSG_OFF, "DMAE: opcode 0x%08x\n"
  269. DP_LEVEL "src_addr [%x:%08x] len [%d *4] "
  270. "dst_addr [%x:%08x (%08x)]\n"
  271. DP_LEVEL "comp_addr [%x:%08x] comp_val 0x%08x\n",
  272. dmae.opcode, dmae.src_addr_hi, dmae.src_addr_lo,
  273. dmae.len, dmae.dst_addr_hi, dmae.dst_addr_lo, src_addr,
  274. dmae.comp_addr_hi, dmae.comp_addr_lo, dmae.comp_val);
  275. mutex_lock(&bp->dmae_mutex);
  276. memset(bnx2x_sp(bp, wb_data[0]), 0, sizeof(u32) * 4);
  277. *wb_comp = 0;
  278. bnx2x_post_dmae(bp, &dmae, INIT_DMAE_C(bp));
  279. udelay(5);
  280. while (*wb_comp != DMAE_COMP_VAL) {
  281. if (!cnt) {
  282. BNX2X_ERR("DMAE timeout!\n");
  283. break;
  284. }
  285. cnt--;
  286. /* adjust delay for emulation/FPGA */
  287. if (CHIP_REV_IS_SLOW(bp))
  288. msleep(100);
  289. else
  290. udelay(5);
  291. }
  292. DP(BNX2X_MSG_OFF, "data [0x%08x 0x%08x 0x%08x 0x%08x]\n",
  293. bp->slowpath->wb_data[0], bp->slowpath->wb_data[1],
  294. bp->slowpath->wb_data[2], bp->slowpath->wb_data[3]);
  295. mutex_unlock(&bp->dmae_mutex);
  296. }
  297. void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  298. u32 addr, u32 len)
  299. {
  300. int offset = 0;
  301. while (len > DMAE_LEN32_WR_MAX) {
  302. bnx2x_write_dmae(bp, phys_addr + offset,
  303. addr + offset, DMAE_LEN32_WR_MAX);
  304. offset += DMAE_LEN32_WR_MAX * 4;
  305. len -= DMAE_LEN32_WR_MAX;
  306. }
  307. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  308. }
  309. /* used only for slowpath so not inlined */
  310. static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
  311. {
  312. u32 wb_write[2];
  313. wb_write[0] = val_hi;
  314. wb_write[1] = val_lo;
  315. REG_WR_DMAE(bp, reg, wb_write, 2);
  316. }
  317. #ifdef USE_WB_RD
  318. static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
  319. {
  320. u32 wb_data[2];
  321. REG_RD_DMAE(bp, reg, wb_data, 2);
  322. return HILO_U64(wb_data[0], wb_data[1]);
  323. }
  324. #endif
  325. static int bnx2x_mc_assert(struct bnx2x *bp)
  326. {
  327. char last_idx;
  328. int i, rc = 0;
  329. u32 row0, row1, row2, row3;
  330. /* XSTORM */
  331. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  332. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  333. if (last_idx)
  334. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  335. /* print the asserts */
  336. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  337. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  338. XSTORM_ASSERT_LIST_OFFSET(i));
  339. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  340. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  341. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  342. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  343. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  344. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  345. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  346. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  347. " 0x%08x 0x%08x 0x%08x\n",
  348. i, row3, row2, row1, row0);
  349. rc++;
  350. } else {
  351. break;
  352. }
  353. }
  354. /* TSTORM */
  355. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  356. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  357. if (last_idx)
  358. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  359. /* print the asserts */
  360. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  361. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  362. TSTORM_ASSERT_LIST_OFFSET(i));
  363. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  364. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  365. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  366. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  367. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  368. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  369. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  370. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  371. " 0x%08x 0x%08x 0x%08x\n",
  372. i, row3, row2, row1, row0);
  373. rc++;
  374. } else {
  375. break;
  376. }
  377. }
  378. /* CSTORM */
  379. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  380. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  381. if (last_idx)
  382. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  383. /* print the asserts */
  384. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  385. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  386. CSTORM_ASSERT_LIST_OFFSET(i));
  387. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  388. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  389. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  390. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  391. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  392. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  393. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  394. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x"
  395. " 0x%08x 0x%08x 0x%08x\n",
  396. i, row3, row2, row1, row0);
  397. rc++;
  398. } else {
  399. break;
  400. }
  401. }
  402. /* USTORM */
  403. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  404. USTORM_ASSERT_LIST_INDEX_OFFSET);
  405. if (last_idx)
  406. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  407. /* print the asserts */
  408. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  409. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  410. USTORM_ASSERT_LIST_OFFSET(i));
  411. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  412. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  413. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  414. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  415. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  416. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  417. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  418. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x"
  419. " 0x%08x 0x%08x 0x%08x\n",
  420. i, row3, row2, row1, row0);
  421. rc++;
  422. } else {
  423. break;
  424. }
  425. }
  426. return rc;
  427. }
  428. static void bnx2x_fw_dump(struct bnx2x *bp)
  429. {
  430. u32 mark, offset;
  431. __be32 data[9];
  432. int word;
  433. mark = REG_RD(bp, MCP_REG_MCPR_SCRATCH + 0xf104);
  434. mark = ((mark + 0x3) & ~0x3);
  435. printk(KERN_ERR PFX "begin fw dump (mark 0x%x)\n", mark);
  436. printk(KERN_ERR PFX);
  437. for (offset = mark - 0x08000000; offset <= 0xF900; offset += 0x8*4) {
  438. for (word = 0; word < 8; word++)
  439. data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
  440. offset + 4*word));
  441. data[8] = 0x0;
  442. printk(KERN_CONT "%s", (char *)data);
  443. }
  444. for (offset = 0xF108; offset <= mark - 0x08000000; offset += 0x8*4) {
  445. for (word = 0; word < 8; word++)
  446. data[word] = htonl(REG_RD(bp, MCP_REG_MCPR_SCRATCH +
  447. offset + 4*word));
  448. data[8] = 0x0;
  449. printk(KERN_CONT "%s", (char *)data);
  450. }
  451. printk(KERN_ERR PFX "end of fw dump\n");
  452. }
  453. static void bnx2x_panic_dump(struct bnx2x *bp)
  454. {
  455. int i;
  456. u16 j, start, end;
  457. bp->stats_state = STATS_STATE_DISABLED;
  458. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  459. BNX2X_ERR("begin crash dump -----------------\n");
  460. /* Indices */
  461. /* Common */
  462. BNX2X_ERR("def_c_idx(%u) def_u_idx(%u) def_x_idx(%u)"
  463. " def_t_idx(%u) def_att_idx(%u) attn_state(%u)"
  464. " spq_prod_idx(%u)\n",
  465. bp->def_c_idx, bp->def_u_idx, bp->def_x_idx, bp->def_t_idx,
  466. bp->def_att_idx, bp->attn_state, bp->spq_prod_idx);
  467. /* Rx */
  468. for_each_rx_queue(bp, i) {
  469. struct bnx2x_fastpath *fp = &bp->fp[i];
  470. BNX2X_ERR("fp%d: rx_bd_prod(%x) rx_bd_cons(%x)"
  471. " *rx_bd_cons_sb(%x) rx_comp_prod(%x)"
  472. " rx_comp_cons(%x) *rx_cons_sb(%x)\n",
  473. i, fp->rx_bd_prod, fp->rx_bd_cons,
  474. le16_to_cpu(*fp->rx_bd_cons_sb), fp->rx_comp_prod,
  475. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  476. BNX2X_ERR(" rx_sge_prod(%x) last_max_sge(%x)"
  477. " fp_u_idx(%x) *sb_u_idx(%x)\n",
  478. fp->rx_sge_prod, fp->last_max_sge,
  479. le16_to_cpu(fp->fp_u_idx),
  480. fp->status_blk->u_status_block.status_block_index);
  481. }
  482. /* Tx */
  483. for_each_tx_queue(bp, i) {
  484. struct bnx2x_fastpath *fp = &bp->fp[i];
  485. BNX2X_ERR("fp%d: tx_pkt_prod(%x) tx_pkt_cons(%x)"
  486. " tx_bd_prod(%x) tx_bd_cons(%x) *tx_cons_sb(%x)\n",
  487. i, fp->tx_pkt_prod, fp->tx_pkt_cons, fp->tx_bd_prod,
  488. fp->tx_bd_cons, le16_to_cpu(*fp->tx_cons_sb));
  489. BNX2X_ERR(" fp_c_idx(%x) *sb_c_idx(%x)"
  490. " tx_db_prod(%x)\n", le16_to_cpu(fp->fp_c_idx),
  491. fp->status_blk->c_status_block.status_block_index,
  492. fp->tx_db.data.prod);
  493. }
  494. /* Rings */
  495. /* Rx */
  496. for_each_rx_queue(bp, i) {
  497. struct bnx2x_fastpath *fp = &bp->fp[i];
  498. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  499. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  500. for (j = start; j != end; j = RX_BD(j + 1)) {
  501. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  502. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  503. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  504. i, j, rx_bd[1], rx_bd[0], sw_bd->skb);
  505. }
  506. start = RX_SGE(fp->rx_sge_prod);
  507. end = RX_SGE(fp->last_max_sge);
  508. for (j = start; j != end; j = RX_SGE(j + 1)) {
  509. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  510. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  511. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  512. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  513. }
  514. start = RCQ_BD(fp->rx_comp_cons - 10);
  515. end = RCQ_BD(fp->rx_comp_cons + 503);
  516. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  517. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  518. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  519. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  520. }
  521. }
  522. /* Tx */
  523. for_each_tx_queue(bp, i) {
  524. struct bnx2x_fastpath *fp = &bp->fp[i];
  525. start = TX_BD(le16_to_cpu(*fp->tx_cons_sb) - 10);
  526. end = TX_BD(le16_to_cpu(*fp->tx_cons_sb) + 245);
  527. for (j = start; j != end; j = TX_BD(j + 1)) {
  528. struct sw_tx_bd *sw_bd = &fp->tx_buf_ring[j];
  529. BNX2X_ERR("fp%d: packet[%x]=[%p,%x]\n",
  530. i, j, sw_bd->skb, sw_bd->first_bd);
  531. }
  532. start = TX_BD(fp->tx_bd_cons - 10);
  533. end = TX_BD(fp->tx_bd_cons + 254);
  534. for (j = start; j != end; j = TX_BD(j + 1)) {
  535. u32 *tx_bd = (u32 *)&fp->tx_desc_ring[j];
  536. BNX2X_ERR("fp%d: tx_bd[%x]=[%x:%x:%x:%x]\n",
  537. i, j, tx_bd[0], tx_bd[1], tx_bd[2], tx_bd[3]);
  538. }
  539. }
  540. bnx2x_fw_dump(bp);
  541. bnx2x_mc_assert(bp);
  542. BNX2X_ERR("end crash dump -----------------\n");
  543. }
  544. static void bnx2x_int_enable(struct bnx2x *bp)
  545. {
  546. int port = BP_PORT(bp);
  547. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  548. u32 val = REG_RD(bp, addr);
  549. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  550. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  551. if (msix) {
  552. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  553. HC_CONFIG_0_REG_INT_LINE_EN_0);
  554. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  555. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  556. } else if (msi) {
  557. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  558. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  559. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  560. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  561. } else {
  562. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  563. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  564. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  565. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  566. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  567. val, port, addr);
  568. REG_WR(bp, addr, val);
  569. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  570. }
  571. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x) mode %s\n",
  572. val, port, addr, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  573. REG_WR(bp, addr, val);
  574. /*
  575. * Ensure that HC_CONFIG is written before leading/trailing edge config
  576. */
  577. mmiowb();
  578. barrier();
  579. if (CHIP_IS_E1H(bp)) {
  580. /* init leading/trailing edge */
  581. if (IS_E1HMF(bp)) {
  582. val = (0xee0f | (1 << (BP_E1HVN(bp) + 4)));
  583. if (bp->port.pmf)
  584. /* enable nig and gpio3 attention */
  585. val |= 0x1100;
  586. } else
  587. val = 0xffff;
  588. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  589. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  590. }
  591. /* Make sure that interrupts are indeed enabled from here on */
  592. mmiowb();
  593. }
  594. static void bnx2x_int_disable(struct bnx2x *bp)
  595. {
  596. int port = BP_PORT(bp);
  597. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  598. u32 val = REG_RD(bp, addr);
  599. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  600. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  601. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  602. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  603. DP(NETIF_MSG_INTR, "write %x to HC %d (addr 0x%x)\n",
  604. val, port, addr);
  605. /* flush all outstanding writes */
  606. mmiowb();
  607. REG_WR(bp, addr, val);
  608. if (REG_RD(bp, addr) != val)
  609. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  610. }
  611. static void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  612. {
  613. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  614. int i, offset;
  615. /* disable interrupt handling */
  616. atomic_inc(&bp->intr_sem);
  617. smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
  618. if (disable_hw)
  619. /* prevent the HW from sending interrupts */
  620. bnx2x_int_disable(bp);
  621. /* make sure all ISRs are done */
  622. if (msix) {
  623. synchronize_irq(bp->msix_table[0].vector);
  624. offset = 1;
  625. #ifdef BCM_CNIC
  626. offset++;
  627. #endif
  628. for_each_queue(bp, i)
  629. synchronize_irq(bp->msix_table[i + offset].vector);
  630. } else
  631. synchronize_irq(bp->pdev->irq);
  632. /* make sure sp_task is not running */
  633. cancel_delayed_work(&bp->sp_task);
  634. flush_workqueue(bnx2x_wq);
  635. }
  636. /* fast path */
  637. /*
  638. * General service functions
  639. */
  640. static inline void bnx2x_ack_sb(struct bnx2x *bp, u8 sb_id,
  641. u8 storm, u16 index, u8 op, u8 update)
  642. {
  643. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  644. COMMAND_REG_INT_ACK);
  645. struct igu_ack_register igu_ack;
  646. igu_ack.status_block_index = index;
  647. igu_ack.sb_id_and_flags =
  648. ((sb_id << IGU_ACK_REGISTER_STATUS_BLOCK_ID_SHIFT) |
  649. (storm << IGU_ACK_REGISTER_STORM_ID_SHIFT) |
  650. (update << IGU_ACK_REGISTER_UPDATE_INDEX_SHIFT) |
  651. (op << IGU_ACK_REGISTER_INTERRUPT_MODE_SHIFT));
  652. DP(BNX2X_MSG_OFF, "write 0x%08x to HC addr 0x%x\n",
  653. (*(u32 *)&igu_ack), hc_addr);
  654. REG_WR(bp, hc_addr, (*(u32 *)&igu_ack));
  655. /* Make sure that ACK is written */
  656. mmiowb();
  657. barrier();
  658. }
  659. static inline u16 bnx2x_update_fpsb_idx(struct bnx2x_fastpath *fp)
  660. {
  661. struct host_status_block *fpsb = fp->status_blk;
  662. u16 rc = 0;
  663. barrier(); /* status block is written to by the chip */
  664. if (fp->fp_c_idx != fpsb->c_status_block.status_block_index) {
  665. fp->fp_c_idx = fpsb->c_status_block.status_block_index;
  666. rc |= 1;
  667. }
  668. if (fp->fp_u_idx != fpsb->u_status_block.status_block_index) {
  669. fp->fp_u_idx = fpsb->u_status_block.status_block_index;
  670. rc |= 2;
  671. }
  672. return rc;
  673. }
  674. static u16 bnx2x_ack_int(struct bnx2x *bp)
  675. {
  676. u32 hc_addr = (HC_REG_COMMAND_REG + BP_PORT(bp)*32 +
  677. COMMAND_REG_SIMD_MASK);
  678. u32 result = REG_RD(bp, hc_addr);
  679. DP(BNX2X_MSG_OFF, "read 0x%08x from HC addr 0x%x\n",
  680. result, hc_addr);
  681. return result;
  682. }
  683. /*
  684. * fast path service functions
  685. */
  686. static inline int bnx2x_has_tx_work_unload(struct bnx2x_fastpath *fp)
  687. {
  688. /* Tell compiler that consumer and producer can change */
  689. barrier();
  690. return (fp->tx_pkt_prod != fp->tx_pkt_cons);
  691. }
  692. /* free skb in the packet ring at pos idx
  693. * return idx of last bd freed
  694. */
  695. static u16 bnx2x_free_tx_pkt(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  696. u16 idx)
  697. {
  698. struct sw_tx_bd *tx_buf = &fp->tx_buf_ring[idx];
  699. struct eth_tx_start_bd *tx_start_bd;
  700. struct eth_tx_bd *tx_data_bd;
  701. struct sk_buff *skb = tx_buf->skb;
  702. u16 bd_idx = TX_BD(tx_buf->first_bd), new_cons;
  703. int nbd;
  704. DP(BNX2X_MSG_OFF, "pkt_idx %d buff @(%p)->skb %p\n",
  705. idx, tx_buf, skb);
  706. /* unmap first bd */
  707. DP(BNX2X_MSG_OFF, "free bd_idx %d\n", bd_idx);
  708. tx_start_bd = &fp->tx_desc_ring[bd_idx].start_bd;
  709. pci_unmap_single(bp->pdev, BD_UNMAP_ADDR(tx_start_bd),
  710. BD_UNMAP_LEN(tx_start_bd), PCI_DMA_TODEVICE);
  711. nbd = le16_to_cpu(tx_start_bd->nbd) - 1;
  712. #ifdef BNX2X_STOP_ON_ERROR
  713. if ((nbd - 1) > (MAX_SKB_FRAGS + 2)) {
  714. BNX2X_ERR("BAD nbd!\n");
  715. bnx2x_panic();
  716. }
  717. #endif
  718. new_cons = nbd + tx_buf->first_bd;
  719. /* Get the next bd */
  720. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  721. /* Skip a parse bd... */
  722. --nbd;
  723. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  724. /* ...and the TSO split header bd since they have no mapping */
  725. if (tx_buf->flags & BNX2X_TSO_SPLIT_BD) {
  726. --nbd;
  727. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  728. }
  729. /* now free frags */
  730. while (nbd > 0) {
  731. DP(BNX2X_MSG_OFF, "free frag bd_idx %d\n", bd_idx);
  732. tx_data_bd = &fp->tx_desc_ring[bd_idx].reg_bd;
  733. pci_unmap_page(bp->pdev, BD_UNMAP_ADDR(tx_data_bd),
  734. BD_UNMAP_LEN(tx_data_bd), PCI_DMA_TODEVICE);
  735. if (--nbd)
  736. bd_idx = TX_BD(NEXT_TX_IDX(bd_idx));
  737. }
  738. /* release skb */
  739. WARN_ON(!skb);
  740. dev_kfree_skb_any(skb);
  741. tx_buf->first_bd = 0;
  742. tx_buf->skb = NULL;
  743. return new_cons;
  744. }
  745. static inline u16 bnx2x_tx_avail(struct bnx2x_fastpath *fp)
  746. {
  747. s16 used;
  748. u16 prod;
  749. u16 cons;
  750. barrier(); /* Tell compiler that prod and cons can change */
  751. prod = fp->tx_bd_prod;
  752. cons = fp->tx_bd_cons;
  753. /* NUM_TX_RINGS = number of "next-page" entries
  754. It will be used as a threshold */
  755. used = SUB_S16(prod, cons) + (s16)NUM_TX_RINGS;
  756. #ifdef BNX2X_STOP_ON_ERROR
  757. WARN_ON(used < 0);
  758. WARN_ON(used > fp->bp->tx_ring_size);
  759. WARN_ON((fp->bp->tx_ring_size - used) > MAX_TX_AVAIL);
  760. #endif
  761. return (s16)(fp->bp->tx_ring_size) - used;
  762. }
  763. static void bnx2x_tx_int(struct bnx2x_fastpath *fp)
  764. {
  765. struct bnx2x *bp = fp->bp;
  766. struct netdev_queue *txq;
  767. u16 hw_cons, sw_cons, bd_cons = fp->tx_bd_cons;
  768. int done = 0;
  769. #ifdef BNX2X_STOP_ON_ERROR
  770. if (unlikely(bp->panic))
  771. return;
  772. #endif
  773. txq = netdev_get_tx_queue(bp->dev, fp->index - bp->num_rx_queues);
  774. hw_cons = le16_to_cpu(*fp->tx_cons_sb);
  775. sw_cons = fp->tx_pkt_cons;
  776. while (sw_cons != hw_cons) {
  777. u16 pkt_cons;
  778. pkt_cons = TX_BD(sw_cons);
  779. /* prefetch(bp->tx_buf_ring[pkt_cons].skb); */
  780. DP(NETIF_MSG_TX_DONE, "hw_cons %u sw_cons %u pkt_cons %u\n",
  781. hw_cons, sw_cons, pkt_cons);
  782. /* if (NEXT_TX_IDX(sw_cons) != hw_cons) {
  783. rmb();
  784. prefetch(fp->tx_buf_ring[NEXT_TX_IDX(sw_cons)].skb);
  785. }
  786. */
  787. bd_cons = bnx2x_free_tx_pkt(bp, fp, pkt_cons);
  788. sw_cons++;
  789. done++;
  790. }
  791. fp->tx_pkt_cons = sw_cons;
  792. fp->tx_bd_cons = bd_cons;
  793. /* TBD need a thresh? */
  794. if (unlikely(netif_tx_queue_stopped(txq))) {
  795. /* Need to make the tx_bd_cons update visible to start_xmit()
  796. * before checking for netif_tx_queue_stopped(). Without the
  797. * memory barrier, there is a small possibility that
  798. * start_xmit() will miss it and cause the queue to be stopped
  799. * forever.
  800. */
  801. smp_mb();
  802. if ((netif_tx_queue_stopped(txq)) &&
  803. (bp->state == BNX2X_STATE_OPEN) &&
  804. (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3))
  805. netif_tx_wake_queue(txq);
  806. }
  807. }
  808. #ifdef BCM_CNIC
  809. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid);
  810. #endif
  811. static void bnx2x_sp_event(struct bnx2x_fastpath *fp,
  812. union eth_rx_cqe *rr_cqe)
  813. {
  814. struct bnx2x *bp = fp->bp;
  815. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  816. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  817. DP(BNX2X_MSG_SP,
  818. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  819. fp->index, cid, command, bp->state,
  820. rr_cqe->ramrod_cqe.ramrod_type);
  821. bp->spq_left++;
  822. if (fp->index) {
  823. switch (command | fp->state) {
  824. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP |
  825. BNX2X_FP_STATE_OPENING):
  826. DP(NETIF_MSG_IFUP, "got MULTI[%d] setup ramrod\n",
  827. cid);
  828. fp->state = BNX2X_FP_STATE_OPEN;
  829. break;
  830. case (RAMROD_CMD_ID_ETH_HALT | BNX2X_FP_STATE_HALTING):
  831. DP(NETIF_MSG_IFDOWN, "got MULTI[%d] halt ramrod\n",
  832. cid);
  833. fp->state = BNX2X_FP_STATE_HALTED;
  834. break;
  835. default:
  836. BNX2X_ERR("unexpected MC reply (%d) "
  837. "fp->state is %x\n", command, fp->state);
  838. break;
  839. }
  840. mb(); /* force bnx2x_wait_ramrod() to see the change */
  841. return;
  842. }
  843. switch (command | bp->state) {
  844. case (RAMROD_CMD_ID_ETH_PORT_SETUP | BNX2X_STATE_OPENING_WAIT4_PORT):
  845. DP(NETIF_MSG_IFUP, "got setup ramrod\n");
  846. bp->state = BNX2X_STATE_OPEN;
  847. break;
  848. case (RAMROD_CMD_ID_ETH_HALT | BNX2X_STATE_CLOSING_WAIT4_HALT):
  849. DP(NETIF_MSG_IFDOWN, "got halt ramrod\n");
  850. bp->state = BNX2X_STATE_CLOSING_WAIT4_DELETE;
  851. fp->state = BNX2X_FP_STATE_HALTED;
  852. break;
  853. case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_CLOSING_WAIT4_HALT):
  854. DP(NETIF_MSG_IFDOWN, "got delete ramrod for MULTI[%d]\n", cid);
  855. bnx2x_fp(bp, cid, state) = BNX2X_FP_STATE_CLOSED;
  856. break;
  857. #ifdef BCM_CNIC
  858. case (RAMROD_CMD_ID_ETH_CFC_DEL | BNX2X_STATE_OPEN):
  859. DP(NETIF_MSG_IFDOWN, "got delete ramrod for CID %d\n", cid);
  860. bnx2x_cnic_cfc_comp(bp, cid);
  861. break;
  862. #endif
  863. case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_OPEN):
  864. case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_DIAG):
  865. DP(NETIF_MSG_IFUP, "got set mac ramrod\n");
  866. bp->set_mac_pending--;
  867. smp_wmb();
  868. break;
  869. case (RAMROD_CMD_ID_ETH_SET_MAC | BNX2X_STATE_CLOSING_WAIT4_HALT):
  870. DP(NETIF_MSG_IFDOWN, "got (un)set mac ramrod\n");
  871. bp->set_mac_pending--;
  872. smp_wmb();
  873. break;
  874. default:
  875. BNX2X_ERR("unexpected MC reply (%d) bp->state is %x\n",
  876. command, bp->state);
  877. break;
  878. }
  879. mb(); /* force bnx2x_wait_ramrod() to see the change */
  880. }
  881. static inline void bnx2x_free_rx_sge(struct bnx2x *bp,
  882. struct bnx2x_fastpath *fp, u16 index)
  883. {
  884. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  885. struct page *page = sw_buf->page;
  886. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  887. /* Skip "next page" elements */
  888. if (!page)
  889. return;
  890. pci_unmap_page(bp->pdev, pci_unmap_addr(sw_buf, mapping),
  891. SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
  892. __free_pages(page, PAGES_PER_SGE_SHIFT);
  893. sw_buf->page = NULL;
  894. sge->addr_hi = 0;
  895. sge->addr_lo = 0;
  896. }
  897. static inline void bnx2x_free_rx_sge_range(struct bnx2x *bp,
  898. struct bnx2x_fastpath *fp, int last)
  899. {
  900. int i;
  901. for (i = 0; i < last; i++)
  902. bnx2x_free_rx_sge(bp, fp, i);
  903. }
  904. static inline int bnx2x_alloc_rx_sge(struct bnx2x *bp,
  905. struct bnx2x_fastpath *fp, u16 index)
  906. {
  907. struct page *page = alloc_pages(GFP_ATOMIC, PAGES_PER_SGE_SHIFT);
  908. struct sw_rx_page *sw_buf = &fp->rx_page_ring[index];
  909. struct eth_rx_sge *sge = &fp->rx_sge_ring[index];
  910. dma_addr_t mapping;
  911. if (unlikely(page == NULL))
  912. return -ENOMEM;
  913. mapping = pci_map_page(bp->pdev, page, 0, SGE_PAGE_SIZE*PAGES_PER_SGE,
  914. PCI_DMA_FROMDEVICE);
  915. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  916. __free_pages(page, PAGES_PER_SGE_SHIFT);
  917. return -ENOMEM;
  918. }
  919. sw_buf->page = page;
  920. pci_unmap_addr_set(sw_buf, mapping, mapping);
  921. sge->addr_hi = cpu_to_le32(U64_HI(mapping));
  922. sge->addr_lo = cpu_to_le32(U64_LO(mapping));
  923. return 0;
  924. }
  925. static inline int bnx2x_alloc_rx_skb(struct bnx2x *bp,
  926. struct bnx2x_fastpath *fp, u16 index)
  927. {
  928. struct sk_buff *skb;
  929. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[index];
  930. struct eth_rx_bd *rx_bd = &fp->rx_desc_ring[index];
  931. dma_addr_t mapping;
  932. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  933. if (unlikely(skb == NULL))
  934. return -ENOMEM;
  935. mapping = pci_map_single(bp->pdev, skb->data, bp->rx_buf_size,
  936. PCI_DMA_FROMDEVICE);
  937. if (unlikely(dma_mapping_error(&bp->pdev->dev, mapping))) {
  938. dev_kfree_skb(skb);
  939. return -ENOMEM;
  940. }
  941. rx_buf->skb = skb;
  942. pci_unmap_addr_set(rx_buf, mapping, mapping);
  943. rx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  944. rx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  945. return 0;
  946. }
  947. /* note that we are not allocating a new skb,
  948. * we are just moving one from cons to prod
  949. * we are not creating a new mapping,
  950. * so there is no need to check for dma_mapping_error().
  951. */
  952. static void bnx2x_reuse_rx_skb(struct bnx2x_fastpath *fp,
  953. struct sk_buff *skb, u16 cons, u16 prod)
  954. {
  955. struct bnx2x *bp = fp->bp;
  956. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  957. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  958. struct eth_rx_bd *cons_bd = &fp->rx_desc_ring[cons];
  959. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  960. pci_dma_sync_single_for_device(bp->pdev,
  961. pci_unmap_addr(cons_rx_buf, mapping),
  962. RX_COPY_THRESH, PCI_DMA_FROMDEVICE);
  963. prod_rx_buf->skb = cons_rx_buf->skb;
  964. pci_unmap_addr_set(prod_rx_buf, mapping,
  965. pci_unmap_addr(cons_rx_buf, mapping));
  966. *prod_bd = *cons_bd;
  967. }
  968. static inline void bnx2x_update_last_max_sge(struct bnx2x_fastpath *fp,
  969. u16 idx)
  970. {
  971. u16 last_max = fp->last_max_sge;
  972. if (SUB_S16(idx, last_max) > 0)
  973. fp->last_max_sge = idx;
  974. }
  975. static void bnx2x_clear_sge_mask_next_elems(struct bnx2x_fastpath *fp)
  976. {
  977. int i, j;
  978. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  979. int idx = RX_SGE_CNT * i - 1;
  980. for (j = 0; j < 2; j++) {
  981. SGE_MASK_CLEAR_BIT(fp, idx);
  982. idx--;
  983. }
  984. }
  985. }
  986. static void bnx2x_update_sge_prod(struct bnx2x_fastpath *fp,
  987. struct eth_fast_path_rx_cqe *fp_cqe)
  988. {
  989. struct bnx2x *bp = fp->bp;
  990. u16 sge_len = SGE_PAGE_ALIGN(le16_to_cpu(fp_cqe->pkt_len) -
  991. le16_to_cpu(fp_cqe->len_on_bd)) >>
  992. SGE_PAGE_SHIFT;
  993. u16 last_max, last_elem, first_elem;
  994. u16 delta = 0;
  995. u16 i;
  996. if (!sge_len)
  997. return;
  998. /* First mark all used pages */
  999. for (i = 0; i < sge_len; i++)
  1000. SGE_MASK_CLEAR_BIT(fp, RX_SGE(le16_to_cpu(fp_cqe->sgl[i])));
  1001. DP(NETIF_MSG_RX_STATUS, "fp_cqe->sgl[%d] = %d\n",
  1002. sge_len - 1, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
  1003. /* Here we assume that the last SGE index is the biggest */
  1004. prefetch((void *)(fp->sge_mask));
  1005. bnx2x_update_last_max_sge(fp, le16_to_cpu(fp_cqe->sgl[sge_len - 1]));
  1006. last_max = RX_SGE(fp->last_max_sge);
  1007. last_elem = last_max >> RX_SGE_MASK_ELEM_SHIFT;
  1008. first_elem = RX_SGE(fp->rx_sge_prod) >> RX_SGE_MASK_ELEM_SHIFT;
  1009. /* If ring is not full */
  1010. if (last_elem + 1 != first_elem)
  1011. last_elem++;
  1012. /* Now update the prod */
  1013. for (i = first_elem; i != last_elem; i = NEXT_SGE_MASK_ELEM(i)) {
  1014. if (likely(fp->sge_mask[i]))
  1015. break;
  1016. fp->sge_mask[i] = RX_SGE_MASK_ELEM_ONE_MASK;
  1017. delta += RX_SGE_MASK_ELEM_SZ;
  1018. }
  1019. if (delta > 0) {
  1020. fp->rx_sge_prod += delta;
  1021. /* clear page-end entries */
  1022. bnx2x_clear_sge_mask_next_elems(fp);
  1023. }
  1024. DP(NETIF_MSG_RX_STATUS,
  1025. "fp->last_max_sge = %d fp->rx_sge_prod = %d\n",
  1026. fp->last_max_sge, fp->rx_sge_prod);
  1027. }
  1028. static inline void bnx2x_init_sge_ring_bit_mask(struct bnx2x_fastpath *fp)
  1029. {
  1030. /* Set the mask to all 1-s: it's faster to compare to 0 than to 0xf-s */
  1031. memset(fp->sge_mask, 0xff,
  1032. (NUM_RX_SGE >> RX_SGE_MASK_ELEM_SHIFT)*sizeof(u64));
  1033. /* Clear the two last indices in the page to 1:
  1034. these are the indices that correspond to the "next" element,
  1035. hence will never be indicated and should be removed from
  1036. the calculations. */
  1037. bnx2x_clear_sge_mask_next_elems(fp);
  1038. }
  1039. static void bnx2x_tpa_start(struct bnx2x_fastpath *fp, u16 queue,
  1040. struct sk_buff *skb, u16 cons, u16 prod)
  1041. {
  1042. struct bnx2x *bp = fp->bp;
  1043. struct sw_rx_bd *cons_rx_buf = &fp->rx_buf_ring[cons];
  1044. struct sw_rx_bd *prod_rx_buf = &fp->rx_buf_ring[prod];
  1045. struct eth_rx_bd *prod_bd = &fp->rx_desc_ring[prod];
  1046. dma_addr_t mapping;
  1047. /* move empty skb from pool to prod and map it */
  1048. prod_rx_buf->skb = fp->tpa_pool[queue].skb;
  1049. mapping = pci_map_single(bp->pdev, fp->tpa_pool[queue].skb->data,
  1050. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  1051. pci_unmap_addr_set(prod_rx_buf, mapping, mapping);
  1052. /* move partial skb from cons to pool (don't unmap yet) */
  1053. fp->tpa_pool[queue] = *cons_rx_buf;
  1054. /* mark bin state as start - print error if current state != stop */
  1055. if (fp->tpa_state[queue] != BNX2X_TPA_STOP)
  1056. BNX2X_ERR("start of bin not in stop [%d]\n", queue);
  1057. fp->tpa_state[queue] = BNX2X_TPA_START;
  1058. /* point prod_bd to new skb */
  1059. prod_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  1060. prod_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  1061. #ifdef BNX2X_STOP_ON_ERROR
  1062. fp->tpa_queue_used |= (1 << queue);
  1063. #ifdef __powerpc64__
  1064. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%lx\n",
  1065. #else
  1066. DP(NETIF_MSG_RX_STATUS, "fp->tpa_queue_used = 0x%llx\n",
  1067. #endif
  1068. fp->tpa_queue_used);
  1069. #endif
  1070. }
  1071. static int bnx2x_fill_frag_skb(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1072. struct sk_buff *skb,
  1073. struct eth_fast_path_rx_cqe *fp_cqe,
  1074. u16 cqe_idx)
  1075. {
  1076. struct sw_rx_page *rx_pg, old_rx_pg;
  1077. u16 len_on_bd = le16_to_cpu(fp_cqe->len_on_bd);
  1078. u32 i, frag_len, frag_size, pages;
  1079. int err;
  1080. int j;
  1081. frag_size = le16_to_cpu(fp_cqe->pkt_len) - len_on_bd;
  1082. pages = SGE_PAGE_ALIGN(frag_size) >> SGE_PAGE_SHIFT;
  1083. /* This is needed in order to enable forwarding support */
  1084. if (frag_size)
  1085. skb_shinfo(skb)->gso_size = min((u32)SGE_PAGE_SIZE,
  1086. max(frag_size, (u32)len_on_bd));
  1087. #ifdef BNX2X_STOP_ON_ERROR
  1088. if (pages >
  1089. min((u32)8, (u32)MAX_SKB_FRAGS) * SGE_PAGE_SIZE * PAGES_PER_SGE) {
  1090. BNX2X_ERR("SGL length is too long: %d. CQE index is %d\n",
  1091. pages, cqe_idx);
  1092. BNX2X_ERR("fp_cqe->pkt_len = %d fp_cqe->len_on_bd = %d\n",
  1093. fp_cqe->pkt_len, len_on_bd);
  1094. bnx2x_panic();
  1095. return -EINVAL;
  1096. }
  1097. #endif
  1098. /* Run through the SGL and compose the fragmented skb */
  1099. for (i = 0, j = 0; i < pages; i += PAGES_PER_SGE, j++) {
  1100. u16 sge_idx = RX_SGE(le16_to_cpu(fp_cqe->sgl[j]));
  1101. /* FW gives the indices of the SGE as if the ring is an array
  1102. (meaning that "next" element will consume 2 indices) */
  1103. frag_len = min(frag_size, (u32)(SGE_PAGE_SIZE*PAGES_PER_SGE));
  1104. rx_pg = &fp->rx_page_ring[sge_idx];
  1105. old_rx_pg = *rx_pg;
  1106. /* If we fail to allocate a substitute page, we simply stop
  1107. where we are and drop the whole packet */
  1108. err = bnx2x_alloc_rx_sge(bp, fp, sge_idx);
  1109. if (unlikely(err)) {
  1110. fp->eth_q_stats.rx_skb_alloc_failed++;
  1111. return err;
  1112. }
  1113. /* Unmap the page as we r going to pass it to the stack */
  1114. pci_unmap_page(bp->pdev, pci_unmap_addr(&old_rx_pg, mapping),
  1115. SGE_PAGE_SIZE*PAGES_PER_SGE, PCI_DMA_FROMDEVICE);
  1116. /* Add one frag and update the appropriate fields in the skb */
  1117. skb_fill_page_desc(skb, j, old_rx_pg.page, 0, frag_len);
  1118. skb->data_len += frag_len;
  1119. skb->truesize += frag_len;
  1120. skb->len += frag_len;
  1121. frag_size -= frag_len;
  1122. }
  1123. return 0;
  1124. }
  1125. static void bnx2x_tpa_stop(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1126. u16 queue, int pad, int len, union eth_rx_cqe *cqe,
  1127. u16 cqe_idx)
  1128. {
  1129. struct sw_rx_bd *rx_buf = &fp->tpa_pool[queue];
  1130. struct sk_buff *skb = rx_buf->skb;
  1131. /* alloc new skb */
  1132. struct sk_buff *new_skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  1133. /* Unmap skb in the pool anyway, as we are going to change
  1134. pool entry status to BNX2X_TPA_STOP even if new skb allocation
  1135. fails. */
  1136. pci_unmap_single(bp->pdev, pci_unmap_addr(rx_buf, mapping),
  1137. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  1138. if (likely(new_skb)) {
  1139. /* fix ip xsum and give it to the stack */
  1140. /* (no need to map the new skb) */
  1141. #ifdef BCM_VLAN
  1142. int is_vlan_cqe =
  1143. (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
  1144. PARSING_FLAGS_VLAN);
  1145. int is_not_hwaccel_vlan_cqe =
  1146. (is_vlan_cqe && (!(bp->flags & HW_VLAN_RX_FLAG)));
  1147. #endif
  1148. prefetch(skb);
  1149. prefetch(((char *)(skb)) + 128);
  1150. #ifdef BNX2X_STOP_ON_ERROR
  1151. if (pad + len > bp->rx_buf_size) {
  1152. BNX2X_ERR("skb_put is about to fail... "
  1153. "pad %d len %d rx_buf_size %d\n",
  1154. pad, len, bp->rx_buf_size);
  1155. bnx2x_panic();
  1156. return;
  1157. }
  1158. #endif
  1159. skb_reserve(skb, pad);
  1160. skb_put(skb, len);
  1161. skb->protocol = eth_type_trans(skb, bp->dev);
  1162. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1163. {
  1164. struct iphdr *iph;
  1165. iph = (struct iphdr *)skb->data;
  1166. #ifdef BCM_VLAN
  1167. /* If there is no Rx VLAN offloading -
  1168. take VLAN tag into an account */
  1169. if (unlikely(is_not_hwaccel_vlan_cqe))
  1170. iph = (struct iphdr *)((u8 *)iph + VLAN_HLEN);
  1171. #endif
  1172. iph->check = 0;
  1173. iph->check = ip_fast_csum((u8 *)iph, iph->ihl);
  1174. }
  1175. if (!bnx2x_fill_frag_skb(bp, fp, skb,
  1176. &cqe->fast_path_cqe, cqe_idx)) {
  1177. #ifdef BCM_VLAN
  1178. if ((bp->vlgrp != NULL) && is_vlan_cqe &&
  1179. (!is_not_hwaccel_vlan_cqe))
  1180. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1181. le16_to_cpu(cqe->fast_path_cqe.
  1182. vlan_tag));
  1183. else
  1184. #endif
  1185. netif_receive_skb(skb);
  1186. } else {
  1187. DP(NETIF_MSG_RX_STATUS, "Failed to allocate new pages"
  1188. " - dropping packet!\n");
  1189. dev_kfree_skb(skb);
  1190. }
  1191. /* put new skb in bin */
  1192. fp->tpa_pool[queue].skb = new_skb;
  1193. } else {
  1194. /* else drop the packet and keep the buffer in the bin */
  1195. DP(NETIF_MSG_RX_STATUS,
  1196. "Failed to allocate new skb - dropping packet!\n");
  1197. fp->eth_q_stats.rx_skb_alloc_failed++;
  1198. }
  1199. fp->tpa_state[queue] = BNX2X_TPA_STOP;
  1200. }
  1201. static inline void bnx2x_update_rx_prod(struct bnx2x *bp,
  1202. struct bnx2x_fastpath *fp,
  1203. u16 bd_prod, u16 rx_comp_prod,
  1204. u16 rx_sge_prod)
  1205. {
  1206. struct ustorm_eth_rx_producers rx_prods = {0};
  1207. int i;
  1208. /* Update producers */
  1209. rx_prods.bd_prod = bd_prod;
  1210. rx_prods.cqe_prod = rx_comp_prod;
  1211. rx_prods.sge_prod = rx_sge_prod;
  1212. /*
  1213. * Make sure that the BD and SGE data is updated before updating the
  1214. * producers since FW might read the BD/SGE right after the producer
  1215. * is updated.
  1216. * This is only applicable for weak-ordered memory model archs such
  1217. * as IA-64. The following barrier is also mandatory since FW will
  1218. * assumes BDs must have buffers.
  1219. */
  1220. wmb();
  1221. for (i = 0; i < sizeof(struct ustorm_eth_rx_producers)/4; i++)
  1222. REG_WR(bp, BAR_USTRORM_INTMEM +
  1223. USTORM_RX_PRODS_OFFSET(BP_PORT(bp), fp->cl_id) + i*4,
  1224. ((u32 *)&rx_prods)[i]);
  1225. mmiowb(); /* keep prod updates ordered */
  1226. DP(NETIF_MSG_RX_STATUS,
  1227. "queue[%d]: wrote bd_prod %u cqe_prod %u sge_prod %u\n",
  1228. fp->index, bd_prod, rx_comp_prod, rx_sge_prod);
  1229. }
  1230. static int bnx2x_rx_int(struct bnx2x_fastpath *fp, int budget)
  1231. {
  1232. struct bnx2x *bp = fp->bp;
  1233. u16 bd_cons, bd_prod, bd_prod_fw, comp_ring_cons;
  1234. u16 hw_comp_cons, sw_comp_cons, sw_comp_prod;
  1235. int rx_pkt = 0;
  1236. #ifdef BNX2X_STOP_ON_ERROR
  1237. if (unlikely(bp->panic))
  1238. return 0;
  1239. #endif
  1240. /* CQ "next element" is of the size of the regular element,
  1241. that's why it's ok here */
  1242. hw_comp_cons = le16_to_cpu(*fp->rx_cons_sb);
  1243. if ((hw_comp_cons & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  1244. hw_comp_cons++;
  1245. bd_cons = fp->rx_bd_cons;
  1246. bd_prod = fp->rx_bd_prod;
  1247. bd_prod_fw = bd_prod;
  1248. sw_comp_cons = fp->rx_comp_cons;
  1249. sw_comp_prod = fp->rx_comp_prod;
  1250. /* Memory barrier necessary as speculative reads of the rx
  1251. * buffer can be ahead of the index in the status block
  1252. */
  1253. rmb();
  1254. DP(NETIF_MSG_RX_STATUS,
  1255. "queue[%d]: hw_comp_cons %u sw_comp_cons %u\n",
  1256. fp->index, hw_comp_cons, sw_comp_cons);
  1257. while (sw_comp_cons != hw_comp_cons) {
  1258. struct sw_rx_bd *rx_buf = NULL;
  1259. struct sk_buff *skb;
  1260. union eth_rx_cqe *cqe;
  1261. u8 cqe_fp_flags;
  1262. u16 len, pad;
  1263. comp_ring_cons = RCQ_BD(sw_comp_cons);
  1264. bd_prod = RX_BD(bd_prod);
  1265. bd_cons = RX_BD(bd_cons);
  1266. /* Prefetch the page containing the BD descriptor
  1267. at producer's index. It will be needed when new skb is
  1268. allocated */
  1269. prefetch((void *)(PAGE_ALIGN((unsigned long)
  1270. (&fp->rx_desc_ring[bd_prod])) -
  1271. PAGE_SIZE + 1));
  1272. cqe = &fp->rx_comp_ring[comp_ring_cons];
  1273. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  1274. DP(NETIF_MSG_RX_STATUS, "CQE type %x err %x status %x"
  1275. " queue %x vlan %x len %u\n", CQE_TYPE(cqe_fp_flags),
  1276. cqe_fp_flags, cqe->fast_path_cqe.status_flags,
  1277. le32_to_cpu(cqe->fast_path_cqe.rss_hash_result),
  1278. le16_to_cpu(cqe->fast_path_cqe.vlan_tag),
  1279. le16_to_cpu(cqe->fast_path_cqe.pkt_len));
  1280. /* is this a slowpath msg? */
  1281. if (unlikely(CQE_TYPE(cqe_fp_flags))) {
  1282. bnx2x_sp_event(fp, cqe);
  1283. goto next_cqe;
  1284. /* this is an rx packet */
  1285. } else {
  1286. rx_buf = &fp->rx_buf_ring[bd_cons];
  1287. skb = rx_buf->skb;
  1288. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  1289. pad = cqe->fast_path_cqe.placement_offset;
  1290. /* If CQE is marked both TPA_START and TPA_END
  1291. it is a non-TPA CQE */
  1292. if ((!fp->disable_tpa) &&
  1293. (TPA_TYPE(cqe_fp_flags) !=
  1294. (TPA_TYPE_START | TPA_TYPE_END))) {
  1295. u16 queue = cqe->fast_path_cqe.queue_index;
  1296. if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_START) {
  1297. DP(NETIF_MSG_RX_STATUS,
  1298. "calling tpa_start on queue %d\n",
  1299. queue);
  1300. bnx2x_tpa_start(fp, queue, skb,
  1301. bd_cons, bd_prod);
  1302. goto next_rx;
  1303. }
  1304. if (TPA_TYPE(cqe_fp_flags) == TPA_TYPE_END) {
  1305. DP(NETIF_MSG_RX_STATUS,
  1306. "calling tpa_stop on queue %d\n",
  1307. queue);
  1308. if (!BNX2X_RX_SUM_FIX(cqe))
  1309. BNX2X_ERR("STOP on none TCP "
  1310. "data\n");
  1311. /* This is a size of the linear data
  1312. on this skb */
  1313. len = le16_to_cpu(cqe->fast_path_cqe.
  1314. len_on_bd);
  1315. bnx2x_tpa_stop(bp, fp, queue, pad,
  1316. len, cqe, comp_ring_cons);
  1317. #ifdef BNX2X_STOP_ON_ERROR
  1318. if (bp->panic)
  1319. return 0;
  1320. #endif
  1321. bnx2x_update_sge_prod(fp,
  1322. &cqe->fast_path_cqe);
  1323. goto next_cqe;
  1324. }
  1325. }
  1326. pci_dma_sync_single_for_device(bp->pdev,
  1327. pci_unmap_addr(rx_buf, mapping),
  1328. pad + RX_COPY_THRESH,
  1329. PCI_DMA_FROMDEVICE);
  1330. prefetch(skb);
  1331. prefetch(((char *)(skb)) + 128);
  1332. /* is this an error packet? */
  1333. if (unlikely(cqe_fp_flags & ETH_RX_ERROR_FALGS)) {
  1334. DP(NETIF_MSG_RX_ERR,
  1335. "ERROR flags %x rx packet %u\n",
  1336. cqe_fp_flags, sw_comp_cons);
  1337. fp->eth_q_stats.rx_err_discard_pkt++;
  1338. goto reuse_rx;
  1339. }
  1340. /* Since we don't have a jumbo ring
  1341. * copy small packets if mtu > 1500
  1342. */
  1343. if ((bp->dev->mtu > ETH_MAX_PACKET_SIZE) &&
  1344. (len <= RX_COPY_THRESH)) {
  1345. struct sk_buff *new_skb;
  1346. new_skb = netdev_alloc_skb(bp->dev,
  1347. len + pad);
  1348. if (new_skb == NULL) {
  1349. DP(NETIF_MSG_RX_ERR,
  1350. "ERROR packet dropped "
  1351. "because of alloc failure\n");
  1352. fp->eth_q_stats.rx_skb_alloc_failed++;
  1353. goto reuse_rx;
  1354. }
  1355. /* aligned copy */
  1356. skb_copy_from_linear_data_offset(skb, pad,
  1357. new_skb->data + pad, len);
  1358. skb_reserve(new_skb, pad);
  1359. skb_put(new_skb, len);
  1360. bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
  1361. skb = new_skb;
  1362. } else
  1363. if (likely(bnx2x_alloc_rx_skb(bp, fp, bd_prod) == 0)) {
  1364. pci_unmap_single(bp->pdev,
  1365. pci_unmap_addr(rx_buf, mapping),
  1366. bp->rx_buf_size,
  1367. PCI_DMA_FROMDEVICE);
  1368. skb_reserve(skb, pad);
  1369. skb_put(skb, len);
  1370. } else {
  1371. DP(NETIF_MSG_RX_ERR,
  1372. "ERROR packet dropped because "
  1373. "of alloc failure\n");
  1374. fp->eth_q_stats.rx_skb_alloc_failed++;
  1375. reuse_rx:
  1376. bnx2x_reuse_rx_skb(fp, skb, bd_cons, bd_prod);
  1377. goto next_rx;
  1378. }
  1379. skb->protocol = eth_type_trans(skb, bp->dev);
  1380. skb->ip_summed = CHECKSUM_NONE;
  1381. if (bp->rx_csum) {
  1382. if (likely(BNX2X_RX_CSUM_OK(cqe)))
  1383. skb->ip_summed = CHECKSUM_UNNECESSARY;
  1384. else
  1385. fp->eth_q_stats.hw_csum_err++;
  1386. }
  1387. }
  1388. skb_record_rx_queue(skb, fp->index);
  1389. #ifdef BCM_VLAN
  1390. if ((bp->vlgrp != NULL) && (bp->flags & HW_VLAN_RX_FLAG) &&
  1391. (le16_to_cpu(cqe->fast_path_cqe.pars_flags.flags) &
  1392. PARSING_FLAGS_VLAN))
  1393. vlan_hwaccel_receive_skb(skb, bp->vlgrp,
  1394. le16_to_cpu(cqe->fast_path_cqe.vlan_tag));
  1395. else
  1396. #endif
  1397. netif_receive_skb(skb);
  1398. next_rx:
  1399. rx_buf->skb = NULL;
  1400. bd_cons = NEXT_RX_IDX(bd_cons);
  1401. bd_prod = NEXT_RX_IDX(bd_prod);
  1402. bd_prod_fw = NEXT_RX_IDX(bd_prod_fw);
  1403. rx_pkt++;
  1404. next_cqe:
  1405. sw_comp_prod = NEXT_RCQ_IDX(sw_comp_prod);
  1406. sw_comp_cons = NEXT_RCQ_IDX(sw_comp_cons);
  1407. if (rx_pkt == budget)
  1408. break;
  1409. } /* while */
  1410. fp->rx_bd_cons = bd_cons;
  1411. fp->rx_bd_prod = bd_prod_fw;
  1412. fp->rx_comp_cons = sw_comp_cons;
  1413. fp->rx_comp_prod = sw_comp_prod;
  1414. /* Update producers */
  1415. bnx2x_update_rx_prod(bp, fp, bd_prod_fw, sw_comp_prod,
  1416. fp->rx_sge_prod);
  1417. fp->rx_pkt += rx_pkt;
  1418. fp->rx_calls++;
  1419. return rx_pkt;
  1420. }
  1421. static irqreturn_t bnx2x_msix_fp_int(int irq, void *fp_cookie)
  1422. {
  1423. struct bnx2x_fastpath *fp = fp_cookie;
  1424. struct bnx2x *bp = fp->bp;
  1425. /* Return here if interrupt is disabled */
  1426. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1427. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  1428. return IRQ_HANDLED;
  1429. }
  1430. DP(BNX2X_MSG_FP, "got an MSI-X interrupt on IDX:SB [%d:%d]\n",
  1431. fp->index, fp->sb_id);
  1432. bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID, 0, IGU_INT_DISABLE, 0);
  1433. #ifdef BNX2X_STOP_ON_ERROR
  1434. if (unlikely(bp->panic))
  1435. return IRQ_HANDLED;
  1436. #endif
  1437. /* Handle Rx or Tx according to MSI-X vector */
  1438. if (fp->is_rx_queue) {
  1439. prefetch(fp->rx_cons_sb);
  1440. prefetch(&fp->status_blk->u_status_block.status_block_index);
  1441. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1442. } else {
  1443. prefetch(fp->tx_cons_sb);
  1444. prefetch(&fp->status_blk->c_status_block.status_block_index);
  1445. bnx2x_update_fpsb_idx(fp);
  1446. rmb();
  1447. bnx2x_tx_int(fp);
  1448. /* Re-enable interrupts */
  1449. bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
  1450. le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
  1451. bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
  1452. le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
  1453. }
  1454. return IRQ_HANDLED;
  1455. }
  1456. static irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1457. {
  1458. struct bnx2x *bp = netdev_priv(dev_instance);
  1459. u16 status = bnx2x_ack_int(bp);
  1460. u16 mask;
  1461. int i;
  1462. /* Return here if interrupt is shared and it's not for us */
  1463. if (unlikely(status == 0)) {
  1464. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1465. return IRQ_NONE;
  1466. }
  1467. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1468. /* Return here if interrupt is disabled */
  1469. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  1470. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  1471. return IRQ_HANDLED;
  1472. }
  1473. #ifdef BNX2X_STOP_ON_ERROR
  1474. if (unlikely(bp->panic))
  1475. return IRQ_HANDLED;
  1476. #endif
  1477. for (i = 0; i < BNX2X_NUM_QUEUES(bp); i++) {
  1478. struct bnx2x_fastpath *fp = &bp->fp[i];
  1479. mask = 0x2 << fp->sb_id;
  1480. if (status & mask) {
  1481. /* Handle Rx or Tx according to SB id */
  1482. if (fp->is_rx_queue) {
  1483. prefetch(fp->rx_cons_sb);
  1484. prefetch(&fp->status_blk->u_status_block.
  1485. status_block_index);
  1486. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1487. } else {
  1488. prefetch(fp->tx_cons_sb);
  1489. prefetch(&fp->status_blk->c_status_block.
  1490. status_block_index);
  1491. bnx2x_update_fpsb_idx(fp);
  1492. rmb();
  1493. bnx2x_tx_int(fp);
  1494. /* Re-enable interrupts */
  1495. bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
  1496. le16_to_cpu(fp->fp_u_idx),
  1497. IGU_INT_NOP, 1);
  1498. bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
  1499. le16_to_cpu(fp->fp_c_idx),
  1500. IGU_INT_ENABLE, 1);
  1501. }
  1502. status &= ~mask;
  1503. }
  1504. }
  1505. #ifdef BCM_CNIC
  1506. mask = 0x2 << CNIC_SB_ID(bp);
  1507. if (status & (mask | 0x1)) {
  1508. struct cnic_ops *c_ops = NULL;
  1509. rcu_read_lock();
  1510. c_ops = rcu_dereference(bp->cnic_ops);
  1511. if (c_ops)
  1512. c_ops->cnic_handler(bp->cnic_data, NULL);
  1513. rcu_read_unlock();
  1514. status &= ~mask;
  1515. }
  1516. #endif
  1517. if (unlikely(status & 0x1)) {
  1518. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1519. status &= ~0x1;
  1520. if (!status)
  1521. return IRQ_HANDLED;
  1522. }
  1523. if (status)
  1524. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status %u)\n",
  1525. status);
  1526. return IRQ_HANDLED;
  1527. }
  1528. /* end of fast path */
  1529. static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event);
  1530. /* Link */
  1531. /*
  1532. * General service functions
  1533. */
  1534. static int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1535. {
  1536. u32 lock_status;
  1537. u32 resource_bit = (1 << resource);
  1538. int func = BP_FUNC(bp);
  1539. u32 hw_lock_control_reg;
  1540. int cnt;
  1541. /* Validating that the resource is within range */
  1542. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1543. DP(NETIF_MSG_HW,
  1544. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1545. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1546. return -EINVAL;
  1547. }
  1548. if (func <= 5) {
  1549. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1550. } else {
  1551. hw_lock_control_reg =
  1552. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1553. }
  1554. /* Validating that the resource is not already taken */
  1555. lock_status = REG_RD(bp, hw_lock_control_reg);
  1556. if (lock_status & resource_bit) {
  1557. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1558. lock_status, resource_bit);
  1559. return -EEXIST;
  1560. }
  1561. /* Try for 5 second every 5ms */
  1562. for (cnt = 0; cnt < 1000; cnt++) {
  1563. /* Try to acquire the lock */
  1564. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1565. lock_status = REG_RD(bp, hw_lock_control_reg);
  1566. if (lock_status & resource_bit)
  1567. return 0;
  1568. msleep(5);
  1569. }
  1570. DP(NETIF_MSG_HW, "Timeout\n");
  1571. return -EAGAIN;
  1572. }
  1573. static int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1574. {
  1575. u32 lock_status;
  1576. u32 resource_bit = (1 << resource);
  1577. int func = BP_FUNC(bp);
  1578. u32 hw_lock_control_reg;
  1579. /* Validating that the resource is within range */
  1580. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1581. DP(NETIF_MSG_HW,
  1582. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1583. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1584. return -EINVAL;
  1585. }
  1586. if (func <= 5) {
  1587. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1588. } else {
  1589. hw_lock_control_reg =
  1590. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1591. }
  1592. /* Validating that the resource is currently taken */
  1593. lock_status = REG_RD(bp, hw_lock_control_reg);
  1594. if (!(lock_status & resource_bit)) {
  1595. DP(NETIF_MSG_HW, "lock_status 0x%x resource_bit 0x%x\n",
  1596. lock_status, resource_bit);
  1597. return -EFAULT;
  1598. }
  1599. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1600. return 0;
  1601. }
  1602. /* HW Lock for shared dual port PHYs */
  1603. static void bnx2x_acquire_phy_lock(struct bnx2x *bp)
  1604. {
  1605. mutex_lock(&bp->port.phy_mutex);
  1606. if (bp->port.need_hw_lock)
  1607. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  1608. }
  1609. static void bnx2x_release_phy_lock(struct bnx2x *bp)
  1610. {
  1611. if (bp->port.need_hw_lock)
  1612. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_MDIO);
  1613. mutex_unlock(&bp->port.phy_mutex);
  1614. }
  1615. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1616. {
  1617. /* The GPIO should be swapped if swap register is set and active */
  1618. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1619. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1620. int gpio_shift = gpio_num +
  1621. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1622. u32 gpio_mask = (1 << gpio_shift);
  1623. u32 gpio_reg;
  1624. int value;
  1625. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1626. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1627. return -EINVAL;
  1628. }
  1629. /* read GPIO value */
  1630. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1631. /* get the requested pin value */
  1632. if ((gpio_reg & gpio_mask) == gpio_mask)
  1633. value = 1;
  1634. else
  1635. value = 0;
  1636. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1637. return value;
  1638. }
  1639. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1640. {
  1641. /* The GPIO should be swapped if swap register is set and active */
  1642. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1643. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1644. int gpio_shift = gpio_num +
  1645. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1646. u32 gpio_mask = (1 << gpio_shift);
  1647. u32 gpio_reg;
  1648. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1649. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1650. return -EINVAL;
  1651. }
  1652. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1653. /* read GPIO and mask except the float bits */
  1654. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1655. switch (mode) {
  1656. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1657. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output low\n",
  1658. gpio_num, gpio_shift);
  1659. /* clear FLOAT and set CLR */
  1660. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1661. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1662. break;
  1663. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1664. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> output high\n",
  1665. gpio_num, gpio_shift);
  1666. /* clear FLOAT and set SET */
  1667. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1668. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1669. break;
  1670. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1671. DP(NETIF_MSG_LINK, "Set GPIO %d (shift %d) -> input\n",
  1672. gpio_num, gpio_shift);
  1673. /* set FLOAT */
  1674. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1675. break;
  1676. default:
  1677. break;
  1678. }
  1679. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1680. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1681. return 0;
  1682. }
  1683. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1684. {
  1685. /* The GPIO should be swapped if swap register is set and active */
  1686. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1687. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1688. int gpio_shift = gpio_num +
  1689. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1690. u32 gpio_mask = (1 << gpio_shift);
  1691. u32 gpio_reg;
  1692. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1693. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1694. return -EINVAL;
  1695. }
  1696. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1697. /* read GPIO int */
  1698. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1699. switch (mode) {
  1700. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1701. DP(NETIF_MSG_LINK, "Clear GPIO INT %d (shift %d) -> "
  1702. "output low\n", gpio_num, gpio_shift);
  1703. /* clear SET and set CLR */
  1704. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1705. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1706. break;
  1707. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1708. DP(NETIF_MSG_LINK, "Set GPIO INT %d (shift %d) -> "
  1709. "output high\n", gpio_num, gpio_shift);
  1710. /* clear CLR and set SET */
  1711. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1712. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1713. break;
  1714. default:
  1715. break;
  1716. }
  1717. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1718. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1719. return 0;
  1720. }
  1721. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1722. {
  1723. u32 spio_mask = (1 << spio_num);
  1724. u32 spio_reg;
  1725. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1726. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1727. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1728. return -EINVAL;
  1729. }
  1730. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1731. /* read SPIO and mask except the float bits */
  1732. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1733. switch (mode) {
  1734. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1735. DP(NETIF_MSG_LINK, "Set SPIO %d -> output low\n", spio_num);
  1736. /* clear FLOAT and set CLR */
  1737. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1738. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1739. break;
  1740. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1741. DP(NETIF_MSG_LINK, "Set SPIO %d -> output high\n", spio_num);
  1742. /* clear FLOAT and set SET */
  1743. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1744. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1745. break;
  1746. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1747. DP(NETIF_MSG_LINK, "Set SPIO %d -> input\n", spio_num);
  1748. /* set FLOAT */
  1749. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1750. break;
  1751. default:
  1752. break;
  1753. }
  1754. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1755. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1756. return 0;
  1757. }
  1758. static void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1759. {
  1760. switch (bp->link_vars.ieee_fc &
  1761. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1762. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1763. bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
  1764. ADVERTISED_Pause);
  1765. break;
  1766. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1767. bp->port.advertising |= (ADVERTISED_Asym_Pause |
  1768. ADVERTISED_Pause);
  1769. break;
  1770. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1771. bp->port.advertising |= ADVERTISED_Asym_Pause;
  1772. break;
  1773. default:
  1774. bp->port.advertising &= ~(ADVERTISED_Asym_Pause |
  1775. ADVERTISED_Pause);
  1776. break;
  1777. }
  1778. }
  1779. static void bnx2x_link_report(struct bnx2x *bp)
  1780. {
  1781. if (bp->flags & MF_FUNC_DIS) {
  1782. netif_carrier_off(bp->dev);
  1783. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  1784. return;
  1785. }
  1786. if (bp->link_vars.link_up) {
  1787. u16 line_speed;
  1788. if (bp->state == BNX2X_STATE_OPEN)
  1789. netif_carrier_on(bp->dev);
  1790. printk(KERN_INFO PFX "%s NIC Link is Up, ", bp->dev->name);
  1791. line_speed = bp->link_vars.line_speed;
  1792. if (IS_E1HMF(bp)) {
  1793. u16 vn_max_rate;
  1794. vn_max_rate =
  1795. ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
  1796. FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
  1797. if (vn_max_rate < line_speed)
  1798. line_speed = vn_max_rate;
  1799. }
  1800. printk("%d Mbps ", line_speed);
  1801. if (bp->link_vars.duplex == DUPLEX_FULL)
  1802. printk("full duplex");
  1803. else
  1804. printk("half duplex");
  1805. if (bp->link_vars.flow_ctrl != BNX2X_FLOW_CTRL_NONE) {
  1806. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) {
  1807. printk(", receive ");
  1808. if (bp->link_vars.flow_ctrl &
  1809. BNX2X_FLOW_CTRL_TX)
  1810. printk("& transmit ");
  1811. } else {
  1812. printk(", transmit ");
  1813. }
  1814. printk("flow control ON");
  1815. }
  1816. printk("\n");
  1817. } else { /* link_down */
  1818. netif_carrier_off(bp->dev);
  1819. printk(KERN_ERR PFX "%s NIC Link is Down\n", bp->dev->name);
  1820. }
  1821. }
  1822. static u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1823. {
  1824. if (!BP_NOMCP(bp)) {
  1825. u8 rc;
  1826. /* Initialize link parameters structure variables */
  1827. /* It is recommended to turn off RX FC for jumbo frames
  1828. for better performance */
  1829. if (bp->dev->mtu > 5000)
  1830. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1831. else
  1832. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1833. bnx2x_acquire_phy_lock(bp);
  1834. if (load_mode == LOAD_DIAG)
  1835. bp->link_params.loopback_mode = LOOPBACK_XGXS_10;
  1836. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1837. bnx2x_release_phy_lock(bp);
  1838. bnx2x_calc_fc_adv(bp);
  1839. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1840. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1841. bnx2x_link_report(bp);
  1842. }
  1843. return rc;
  1844. }
  1845. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1846. return -EINVAL;
  1847. }
  1848. static void bnx2x_link_set(struct bnx2x *bp)
  1849. {
  1850. if (!BP_NOMCP(bp)) {
  1851. bnx2x_acquire_phy_lock(bp);
  1852. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1853. bnx2x_release_phy_lock(bp);
  1854. bnx2x_calc_fc_adv(bp);
  1855. } else
  1856. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1857. }
  1858. static void bnx2x__link_reset(struct bnx2x *bp)
  1859. {
  1860. if (!BP_NOMCP(bp)) {
  1861. bnx2x_acquire_phy_lock(bp);
  1862. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1863. bnx2x_release_phy_lock(bp);
  1864. } else
  1865. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1866. }
  1867. static u8 bnx2x_link_test(struct bnx2x *bp)
  1868. {
  1869. u8 rc;
  1870. bnx2x_acquire_phy_lock(bp);
  1871. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars);
  1872. bnx2x_release_phy_lock(bp);
  1873. return rc;
  1874. }
  1875. static void bnx2x_init_port_minmax(struct bnx2x *bp)
  1876. {
  1877. u32 r_param = bp->link_vars.line_speed / 8;
  1878. u32 fair_periodic_timeout_usec;
  1879. u32 t_fair;
  1880. memset(&(bp->cmng.rs_vars), 0,
  1881. sizeof(struct rate_shaping_vars_per_port));
  1882. memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
  1883. /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
  1884. bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
  1885. /* this is the threshold below which no timer arming will occur
  1886. 1.25 coefficient is for the threshold to be a little bigger
  1887. than the real time, to compensate for timer in-accuracy */
  1888. bp->cmng.rs_vars.rs_threshold =
  1889. (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
  1890. /* resolution of fairness timer */
  1891. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  1892. /* for 10G it is 1000usec. for 1G it is 10000usec. */
  1893. t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
  1894. /* this is the threshold below which we won't arm the timer anymore */
  1895. bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
  1896. /* we multiply by 1e3/8 to get bytes/msec.
  1897. We don't want the credits to pass a credit
  1898. of the t_fair*FAIR_MEM (algorithm resolution) */
  1899. bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
  1900. /* since each tick is 4 usec */
  1901. bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
  1902. }
  1903. /* Calculates the sum of vn_min_rates.
  1904. It's needed for further normalizing of the min_rates.
  1905. Returns:
  1906. sum of vn_min_rates.
  1907. or
  1908. 0 - if all the min_rates are 0.
  1909. In the later case fainess algorithm should be deactivated.
  1910. If not all min_rates are zero then those that are zeroes will be set to 1.
  1911. */
  1912. static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
  1913. {
  1914. int all_zero = 1;
  1915. int port = BP_PORT(bp);
  1916. int vn;
  1917. bp->vn_weight_sum = 0;
  1918. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  1919. int func = 2*vn + port;
  1920. u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  1921. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1922. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1923. /* Skip hidden vns */
  1924. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1925. continue;
  1926. /* If min rate is zero - set it to 1 */
  1927. if (!vn_min_rate)
  1928. vn_min_rate = DEF_MIN_RATE;
  1929. else
  1930. all_zero = 0;
  1931. bp->vn_weight_sum += vn_min_rate;
  1932. }
  1933. /* ... only if all min rates are zeros - disable fairness */
  1934. if (all_zero) {
  1935. bp->cmng.flags.cmng_enables &=
  1936. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1937. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  1938. " fairness will be disabled\n");
  1939. } else
  1940. bp->cmng.flags.cmng_enables |=
  1941. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1942. }
  1943. static void bnx2x_init_vn_minmax(struct bnx2x *bp, int func)
  1944. {
  1945. struct rate_shaping_vars_per_vn m_rs_vn;
  1946. struct fairness_vars_per_vn m_fair_vn;
  1947. u32 vn_cfg = SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  1948. u16 vn_min_rate, vn_max_rate;
  1949. int i;
  1950. /* If function is hidden - set min and max to zeroes */
  1951. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
  1952. vn_min_rate = 0;
  1953. vn_max_rate = 0;
  1954. } else {
  1955. vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1956. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1957. /* If min rate is zero - set it to 1 */
  1958. if (!vn_min_rate)
  1959. vn_min_rate = DEF_MIN_RATE;
  1960. vn_max_rate = ((vn_cfg & FUNC_MF_CFG_MAX_BW_MASK) >>
  1961. FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
  1962. }
  1963. DP(NETIF_MSG_IFUP,
  1964. "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
  1965. func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
  1966. memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
  1967. memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
  1968. /* global vn counter - maximal Mbps for this vn */
  1969. m_rs_vn.vn_counter.rate = vn_max_rate;
  1970. /* quota - number of bytes transmitted in this period */
  1971. m_rs_vn.vn_counter.quota =
  1972. (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
  1973. if (bp->vn_weight_sum) {
  1974. /* credit for each period of the fairness algorithm:
  1975. number of bytes in T_FAIR (the vn share the port rate).
  1976. vn_weight_sum should not be larger than 10000, thus
  1977. T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
  1978. than zero */
  1979. m_fair_vn.vn_credit_delta =
  1980. max((u32)(vn_min_rate * (T_FAIR_COEF /
  1981. (8 * bp->vn_weight_sum))),
  1982. (u32)(bp->cmng.fair_vars.fair_threshold * 2));
  1983. DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta=%d\n",
  1984. m_fair_vn.vn_credit_delta);
  1985. }
  1986. /* Store it to internal memory */
  1987. for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
  1988. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1989. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
  1990. ((u32 *)(&m_rs_vn))[i]);
  1991. for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
  1992. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1993. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
  1994. ((u32 *)(&m_fair_vn))[i]);
  1995. }
  1996. /* This function is called upon link interrupt */
  1997. static void bnx2x_link_attn(struct bnx2x *bp)
  1998. {
  1999. /* Make sure that we are synced with the current statistics */
  2000. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2001. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2002. if (bp->link_vars.link_up) {
  2003. /* dropless flow control */
  2004. if (CHIP_IS_E1H(bp) && bp->dropless_fc) {
  2005. int port = BP_PORT(bp);
  2006. u32 pause_enabled = 0;
  2007. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2008. pause_enabled = 1;
  2009. REG_WR(bp, BAR_USTRORM_INTMEM +
  2010. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2011. pause_enabled);
  2012. }
  2013. if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
  2014. struct host_port_stats *pstats;
  2015. pstats = bnx2x_sp(bp, port_stats);
  2016. /* reset old bmac stats */
  2017. memset(&(pstats->mac_stx[0]), 0,
  2018. sizeof(struct mac_stx));
  2019. }
  2020. if (bp->state == BNX2X_STATE_OPEN)
  2021. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2022. }
  2023. /* indicate link status */
  2024. bnx2x_link_report(bp);
  2025. if (IS_E1HMF(bp)) {
  2026. int port = BP_PORT(bp);
  2027. int func;
  2028. int vn;
  2029. /* Set the attention towards other drivers on the same port */
  2030. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  2031. if (vn == BP_E1HVN(bp))
  2032. continue;
  2033. func = ((vn << 1) | port);
  2034. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  2035. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  2036. }
  2037. if (bp->link_vars.link_up) {
  2038. int i;
  2039. /* Init rate shaping and fairness contexts */
  2040. bnx2x_init_port_minmax(bp);
  2041. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  2042. bnx2x_init_vn_minmax(bp, 2*vn + port);
  2043. /* Store it to internal memory */
  2044. for (i = 0;
  2045. i < sizeof(struct cmng_struct_per_port) / 4; i++)
  2046. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2047. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
  2048. ((u32 *)(&bp->cmng))[i]);
  2049. }
  2050. }
  2051. }
  2052. static void bnx2x__link_status_update(struct bnx2x *bp)
  2053. {
  2054. if ((bp->state != BNX2X_STATE_OPEN) || (bp->flags & MF_FUNC_DIS))
  2055. return;
  2056. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2057. if (bp->link_vars.link_up)
  2058. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2059. else
  2060. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2061. bnx2x_calc_vn_weight_sum(bp);
  2062. /* indicate link status */
  2063. bnx2x_link_report(bp);
  2064. }
  2065. static void bnx2x_pmf_update(struct bnx2x *bp)
  2066. {
  2067. int port = BP_PORT(bp);
  2068. u32 val;
  2069. bp->port.pmf = 1;
  2070. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  2071. /* enable nig attention */
  2072. val = (0xff0f | (1 << (BP_E1HVN(bp) + 4)));
  2073. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2074. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2075. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2076. }
  2077. /* end of Link */
  2078. /* slow path */
  2079. /*
  2080. * General service functions
  2081. */
  2082. /* send the MCP a request, block until there is a reply */
  2083. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command)
  2084. {
  2085. int func = BP_FUNC(bp);
  2086. u32 seq = ++bp->fw_seq;
  2087. u32 rc = 0;
  2088. u32 cnt = 1;
  2089. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2090. mutex_lock(&bp->fw_mb_mutex);
  2091. SHMEM_WR(bp, func_mb[func].drv_mb_header, (command | seq));
  2092. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB\n", (command | seq));
  2093. do {
  2094. /* let the FW do it's magic ... */
  2095. msleep(delay);
  2096. rc = SHMEM_RD(bp, func_mb[func].fw_mb_header);
  2097. /* Give the FW up to 5 second (500*10ms) */
  2098. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2099. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2100. cnt*delay, rc, seq);
  2101. /* is this a reply to our command? */
  2102. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2103. rc &= FW_MSG_CODE_MASK;
  2104. else {
  2105. /* FW BUG! */
  2106. BNX2X_ERR("FW failed to respond!\n");
  2107. bnx2x_fw_dump(bp);
  2108. rc = 0;
  2109. }
  2110. mutex_unlock(&bp->fw_mb_mutex);
  2111. return rc;
  2112. }
  2113. static void bnx2x_set_storm_rx_mode(struct bnx2x *bp);
  2114. static void bnx2x_set_eth_mac_addr_e1h(struct bnx2x *bp, int set);
  2115. static void bnx2x_set_rx_mode(struct net_device *dev);
  2116. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2117. {
  2118. int port = BP_PORT(bp);
  2119. netif_tx_disable(bp->dev);
  2120. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  2121. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2122. netif_carrier_off(bp->dev);
  2123. }
  2124. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2125. {
  2126. int port = BP_PORT(bp);
  2127. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2128. /* Tx queue should be only reenabled */
  2129. netif_tx_wake_all_queues(bp->dev);
  2130. /*
  2131. * Should not call netif_carrier_on since it will be called if the link
  2132. * is up when checking for link state
  2133. */
  2134. }
  2135. static void bnx2x_update_min_max(struct bnx2x *bp)
  2136. {
  2137. int port = BP_PORT(bp);
  2138. int vn, i;
  2139. /* Init rate shaping and fairness contexts */
  2140. bnx2x_init_port_minmax(bp);
  2141. bnx2x_calc_vn_weight_sum(bp);
  2142. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  2143. bnx2x_init_vn_minmax(bp, 2*vn + port);
  2144. if (bp->port.pmf) {
  2145. int func;
  2146. /* Set the attention towards other drivers on the same port */
  2147. for (vn = VN_0; vn < E1HVN_MAX; vn++) {
  2148. if (vn == BP_E1HVN(bp))
  2149. continue;
  2150. func = ((vn << 1) | port);
  2151. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_0 +
  2152. (LINK_SYNC_ATTENTION_BIT_FUNC_0 + func)*4, 1);
  2153. }
  2154. /* Store it to internal memory */
  2155. for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
  2156. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2157. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i*4,
  2158. ((u32 *)(&bp->cmng))[i]);
  2159. }
  2160. }
  2161. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2162. {
  2163. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2164. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2165. /*
  2166. * This is the only place besides the function initialization
  2167. * where the bp->flags can change so it is done without any
  2168. * locks
  2169. */
  2170. if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
  2171. DP(NETIF_MSG_IFDOWN, "mf_cfg function disabled\n");
  2172. bp->flags |= MF_FUNC_DIS;
  2173. bnx2x_e1h_disable(bp);
  2174. } else {
  2175. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2176. bp->flags &= ~MF_FUNC_DIS;
  2177. bnx2x_e1h_enable(bp);
  2178. }
  2179. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2180. }
  2181. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2182. bnx2x_update_min_max(bp);
  2183. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2184. }
  2185. /* Report results to MCP */
  2186. if (dcc_event)
  2187. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE);
  2188. else
  2189. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK);
  2190. }
  2191. /* must be called under the spq lock */
  2192. static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2193. {
  2194. struct eth_spe *next_spe = bp->spq_prod_bd;
  2195. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2196. bp->spq_prod_bd = bp->spq;
  2197. bp->spq_prod_idx = 0;
  2198. DP(NETIF_MSG_TIMER, "end of spq\n");
  2199. } else {
  2200. bp->spq_prod_bd++;
  2201. bp->spq_prod_idx++;
  2202. }
  2203. return next_spe;
  2204. }
  2205. /* must be called under the spq lock */
  2206. static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
  2207. {
  2208. int func = BP_FUNC(bp);
  2209. /* Make sure that BD data is updated before writing the producer */
  2210. wmb();
  2211. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2212. bp->spq_prod_idx);
  2213. mmiowb();
  2214. }
  2215. /* the slow path queue is odd since completions arrive on the fastpath ring */
  2216. static int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2217. u32 data_hi, u32 data_lo, int common)
  2218. {
  2219. struct eth_spe *spe;
  2220. DP(BNX2X_MSG_SP/*NETIF_MSG_TIMER*/,
  2221. "SPQE (%x:%x) command %d hw_cid %x data (%x:%x) left %x\n",
  2222. (u32)U64_HI(bp->spq_mapping), (u32)(U64_LO(bp->spq_mapping) +
  2223. (void *)bp->spq_prod_bd - (void *)bp->spq), command,
  2224. HW_CID(bp, cid), data_hi, data_lo, bp->spq_left);
  2225. #ifdef BNX2X_STOP_ON_ERROR
  2226. if (unlikely(bp->panic))
  2227. return -EIO;
  2228. #endif
  2229. spin_lock_bh(&bp->spq_lock);
  2230. if (!bp->spq_left) {
  2231. BNX2X_ERR("BUG! SPQ ring full!\n");
  2232. spin_unlock_bh(&bp->spq_lock);
  2233. bnx2x_panic();
  2234. return -EBUSY;
  2235. }
  2236. spe = bnx2x_sp_get_next(bp);
  2237. /* CID needs port number to be encoded int it */
  2238. spe->hdr.conn_and_cmd_data =
  2239. cpu_to_le32(((command << SPE_HDR_CMD_ID_SHIFT) |
  2240. HW_CID(bp, cid)));
  2241. spe->hdr.type = cpu_to_le16(ETH_CONNECTION_TYPE);
  2242. if (common)
  2243. spe->hdr.type |=
  2244. cpu_to_le16((1 << SPE_HDR_COMMON_RAMROD_SHIFT));
  2245. spe->data.mac_config_addr.hi = cpu_to_le32(data_hi);
  2246. spe->data.mac_config_addr.lo = cpu_to_le32(data_lo);
  2247. bp->spq_left--;
  2248. bnx2x_sp_prod_update(bp);
  2249. spin_unlock_bh(&bp->spq_lock);
  2250. return 0;
  2251. }
  2252. /* acquire split MCP access lock register */
  2253. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2254. {
  2255. u32 i, j, val;
  2256. int rc = 0;
  2257. might_sleep();
  2258. i = 100;
  2259. for (j = 0; j < i*10; j++) {
  2260. val = (1UL << 31);
  2261. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2262. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2263. if (val & (1L << 31))
  2264. break;
  2265. msleep(5);
  2266. }
  2267. if (!(val & (1L << 31))) {
  2268. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2269. rc = -EBUSY;
  2270. }
  2271. return rc;
  2272. }
  2273. /* release split MCP access lock register */
  2274. static void bnx2x_release_alr(struct bnx2x *bp)
  2275. {
  2276. u32 val = 0;
  2277. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2278. }
  2279. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2280. {
  2281. struct host_def_status_block *def_sb = bp->def_status_blk;
  2282. u16 rc = 0;
  2283. barrier(); /* status block is written to by the chip */
  2284. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2285. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2286. rc |= 1;
  2287. }
  2288. if (bp->def_c_idx != def_sb->c_def_status_block.status_block_index) {
  2289. bp->def_c_idx = def_sb->c_def_status_block.status_block_index;
  2290. rc |= 2;
  2291. }
  2292. if (bp->def_u_idx != def_sb->u_def_status_block.status_block_index) {
  2293. bp->def_u_idx = def_sb->u_def_status_block.status_block_index;
  2294. rc |= 4;
  2295. }
  2296. if (bp->def_x_idx != def_sb->x_def_status_block.status_block_index) {
  2297. bp->def_x_idx = def_sb->x_def_status_block.status_block_index;
  2298. rc |= 8;
  2299. }
  2300. if (bp->def_t_idx != def_sb->t_def_status_block.status_block_index) {
  2301. bp->def_t_idx = def_sb->t_def_status_block.status_block_index;
  2302. rc |= 16;
  2303. }
  2304. return rc;
  2305. }
  2306. /*
  2307. * slow path service functions
  2308. */
  2309. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2310. {
  2311. int port = BP_PORT(bp);
  2312. u32 hc_addr = (HC_REG_COMMAND_REG + port*32 +
  2313. COMMAND_REG_ATTN_BITS_SET);
  2314. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2315. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2316. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2317. NIG_REG_MASK_INTERRUPT_PORT0;
  2318. u32 aeu_mask;
  2319. u32 nig_mask = 0;
  2320. if (bp->attn_state & asserted)
  2321. BNX2X_ERR("IGU ERROR\n");
  2322. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2323. aeu_mask = REG_RD(bp, aeu_addr);
  2324. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2325. aeu_mask, asserted);
  2326. aeu_mask &= ~(asserted & 0xff);
  2327. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2328. REG_WR(bp, aeu_addr, aeu_mask);
  2329. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2330. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2331. bp->attn_state |= asserted;
  2332. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2333. if (asserted & ATTN_HARD_WIRED_MASK) {
  2334. if (asserted & ATTN_NIG_FOR_FUNC) {
  2335. bnx2x_acquire_phy_lock(bp);
  2336. /* save nig interrupt mask */
  2337. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2338. REG_WR(bp, nig_int_mask_addr, 0);
  2339. bnx2x_link_attn(bp);
  2340. /* handle unicore attn? */
  2341. }
  2342. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2343. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2344. if (asserted & GPIO_2_FUNC)
  2345. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2346. if (asserted & GPIO_3_FUNC)
  2347. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2348. if (asserted & GPIO_4_FUNC)
  2349. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2350. if (port == 0) {
  2351. if (asserted & ATTN_GENERAL_ATTN_1) {
  2352. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2353. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2354. }
  2355. if (asserted & ATTN_GENERAL_ATTN_2) {
  2356. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2357. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2358. }
  2359. if (asserted & ATTN_GENERAL_ATTN_3) {
  2360. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2361. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2362. }
  2363. } else {
  2364. if (asserted & ATTN_GENERAL_ATTN_4) {
  2365. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2366. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2367. }
  2368. if (asserted & ATTN_GENERAL_ATTN_5) {
  2369. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2370. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2371. }
  2372. if (asserted & ATTN_GENERAL_ATTN_6) {
  2373. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2374. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2375. }
  2376. }
  2377. } /* if hardwired */
  2378. DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
  2379. asserted, hc_addr);
  2380. REG_WR(bp, hc_addr, asserted);
  2381. /* now set back the mask */
  2382. if (asserted & ATTN_NIG_FOR_FUNC) {
  2383. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2384. bnx2x_release_phy_lock(bp);
  2385. }
  2386. }
  2387. static inline void bnx2x_fan_failure(struct bnx2x *bp)
  2388. {
  2389. int port = BP_PORT(bp);
  2390. /* mark the failure */
  2391. bp->link_params.ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2392. bp->link_params.ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2393. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2394. bp->link_params.ext_phy_config);
  2395. /* log the failure */
  2396. printk(KERN_ERR PFX "Fan Failure on Network Controller %s has caused"
  2397. " the driver to shutdown the card to prevent permanent"
  2398. " damage. Please contact Dell Support for assistance\n",
  2399. bp->dev->name);
  2400. }
  2401. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2402. {
  2403. int port = BP_PORT(bp);
  2404. int reg_offset;
  2405. u32 val, swap_val, swap_override;
  2406. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2407. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2408. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2409. val = REG_RD(bp, reg_offset);
  2410. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2411. REG_WR(bp, reg_offset, val);
  2412. BNX2X_ERR("SPIO5 hw attention\n");
  2413. /* Fan failure attention */
  2414. switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
  2415. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  2416. /* Low power mode is controlled by GPIO 2 */
  2417. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_2,
  2418. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  2419. /* The PHY reset is controlled by GPIO 1 */
  2420. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  2421. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  2422. break;
  2423. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  2424. /* The PHY reset is controlled by GPIO 1 */
  2425. /* fake the port number to cancel the swap done in
  2426. set_gpio() */
  2427. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  2428. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  2429. port = (swap_val && swap_override) ^ 1;
  2430. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_1,
  2431. MISC_REGISTERS_GPIO_OUTPUT_LOW, port);
  2432. break;
  2433. default:
  2434. break;
  2435. }
  2436. bnx2x_fan_failure(bp);
  2437. }
  2438. if (attn & (AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 |
  2439. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1)) {
  2440. bnx2x_acquire_phy_lock(bp);
  2441. bnx2x_handle_module_detect_int(&bp->link_params);
  2442. bnx2x_release_phy_lock(bp);
  2443. }
  2444. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2445. val = REG_RD(bp, reg_offset);
  2446. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2447. REG_WR(bp, reg_offset, val);
  2448. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2449. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  2450. bnx2x_panic();
  2451. }
  2452. }
  2453. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2454. {
  2455. u32 val;
  2456. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2457. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2458. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2459. /* DORQ discard attention */
  2460. if (val & 0x2)
  2461. BNX2X_ERR("FATAL error from DORQ\n");
  2462. }
  2463. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2464. int port = BP_PORT(bp);
  2465. int reg_offset;
  2466. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2467. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2468. val = REG_RD(bp, reg_offset);
  2469. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2470. REG_WR(bp, reg_offset, val);
  2471. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2472. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  2473. bnx2x_panic();
  2474. }
  2475. }
  2476. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2477. {
  2478. u32 val;
  2479. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2480. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2481. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2482. /* CFC error attention */
  2483. if (val & 0x2)
  2484. BNX2X_ERR("FATAL error from CFC\n");
  2485. }
  2486. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2487. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2488. BNX2X_ERR("PXP hw attention 0x%x\n", val);
  2489. /* RQ_USDMDP_FIFO_OVERFLOW */
  2490. if (val & 0x18000)
  2491. BNX2X_ERR("FATAL error from PXP\n");
  2492. }
  2493. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2494. int port = BP_PORT(bp);
  2495. int reg_offset;
  2496. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2497. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2498. val = REG_RD(bp, reg_offset);
  2499. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2500. REG_WR(bp, reg_offset, val);
  2501. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2502. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  2503. bnx2x_panic();
  2504. }
  2505. }
  2506. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2507. {
  2508. u32 val;
  2509. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2510. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2511. int func = BP_FUNC(bp);
  2512. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2513. bp->mf_config = SHMEM_RD(bp,
  2514. mf_cfg.func_mf_config[func].config);
  2515. val = SHMEM_RD(bp, func_mb[func].drv_status);
  2516. if (val & DRV_STATUS_DCC_EVENT_MASK)
  2517. bnx2x_dcc_event(bp,
  2518. (val & DRV_STATUS_DCC_EVENT_MASK));
  2519. bnx2x__link_status_update(bp);
  2520. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  2521. bnx2x_pmf_update(bp);
  2522. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  2523. BNX2X_ERR("MC assert!\n");
  2524. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  2525. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  2526. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  2527. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  2528. bnx2x_panic();
  2529. } else if (attn & BNX2X_MCP_ASSERT) {
  2530. BNX2X_ERR("MCP assert!\n");
  2531. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  2532. bnx2x_fw_dump(bp);
  2533. } else
  2534. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  2535. }
  2536. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  2537. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  2538. if (attn & BNX2X_GRC_TIMEOUT) {
  2539. val = CHIP_IS_E1H(bp) ?
  2540. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN) : 0;
  2541. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  2542. }
  2543. if (attn & BNX2X_GRC_RSV) {
  2544. val = CHIP_IS_E1H(bp) ?
  2545. REG_RD(bp, MISC_REG_GRC_RSV_ATTN) : 0;
  2546. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  2547. }
  2548. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  2549. }
  2550. }
  2551. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  2552. {
  2553. struct attn_route attn;
  2554. struct attn_route group_mask;
  2555. int port = BP_PORT(bp);
  2556. int index;
  2557. u32 reg_addr;
  2558. u32 val;
  2559. u32 aeu_mask;
  2560. /* need to take HW lock because MCP or other port might also
  2561. try to handle this event */
  2562. bnx2x_acquire_alr(bp);
  2563. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  2564. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  2565. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  2566. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  2567. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x\n",
  2568. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3]);
  2569. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  2570. if (deasserted & (1 << index)) {
  2571. group_mask = bp->attn_group[index];
  2572. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x\n",
  2573. index, group_mask.sig[0], group_mask.sig[1],
  2574. group_mask.sig[2], group_mask.sig[3]);
  2575. bnx2x_attn_int_deasserted3(bp,
  2576. attn.sig[3] & group_mask.sig[3]);
  2577. bnx2x_attn_int_deasserted1(bp,
  2578. attn.sig[1] & group_mask.sig[1]);
  2579. bnx2x_attn_int_deasserted2(bp,
  2580. attn.sig[2] & group_mask.sig[2]);
  2581. bnx2x_attn_int_deasserted0(bp,
  2582. attn.sig[0] & group_mask.sig[0]);
  2583. if ((attn.sig[0] & group_mask.sig[0] &
  2584. HW_PRTY_ASSERT_SET_0) ||
  2585. (attn.sig[1] & group_mask.sig[1] &
  2586. HW_PRTY_ASSERT_SET_1) ||
  2587. (attn.sig[2] & group_mask.sig[2] &
  2588. HW_PRTY_ASSERT_SET_2))
  2589. BNX2X_ERR("FATAL HW block parity attention\n");
  2590. }
  2591. }
  2592. bnx2x_release_alr(bp);
  2593. reg_addr = (HC_REG_COMMAND_REG + port*32 + COMMAND_REG_ATTN_BITS_CLR);
  2594. val = ~deasserted;
  2595. DP(NETIF_MSG_HW, "about to mask 0x%08x at HC addr 0x%x\n",
  2596. val, reg_addr);
  2597. REG_WR(bp, reg_addr, val);
  2598. if (~bp->attn_state & deasserted)
  2599. BNX2X_ERR("IGU ERROR\n");
  2600. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2601. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2602. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2603. aeu_mask = REG_RD(bp, reg_addr);
  2604. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  2605. aeu_mask, deasserted);
  2606. aeu_mask |= (deasserted & 0xff);
  2607. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2608. REG_WR(bp, reg_addr, aeu_mask);
  2609. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2610. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2611. bp->attn_state &= ~deasserted;
  2612. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2613. }
  2614. static void bnx2x_attn_int(struct bnx2x *bp)
  2615. {
  2616. /* read local copy of bits */
  2617. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  2618. attn_bits);
  2619. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  2620. attn_bits_ack);
  2621. u32 attn_state = bp->attn_state;
  2622. /* look for changed bits */
  2623. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  2624. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  2625. DP(NETIF_MSG_HW,
  2626. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  2627. attn_bits, attn_ack, asserted, deasserted);
  2628. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  2629. BNX2X_ERR("BAD attention state\n");
  2630. /* handle bits that were raised */
  2631. if (asserted)
  2632. bnx2x_attn_int_asserted(bp, asserted);
  2633. if (deasserted)
  2634. bnx2x_attn_int_deasserted(bp, deasserted);
  2635. }
  2636. static void bnx2x_sp_task(struct work_struct *work)
  2637. {
  2638. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  2639. u16 status;
  2640. /* Return here if interrupt is disabled */
  2641. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  2642. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  2643. return;
  2644. }
  2645. status = bnx2x_update_dsb_idx(bp);
  2646. /* if (status == 0) */
  2647. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  2648. DP(NETIF_MSG_INTR, "got a slowpath interrupt (updated %x)\n", status);
  2649. /* HW attentions */
  2650. if (status & 0x1)
  2651. bnx2x_attn_int(bp);
  2652. bnx2x_ack_sb(bp, DEF_SB_ID, ATTENTION_ID, le16_to_cpu(bp->def_att_idx),
  2653. IGU_INT_NOP, 1);
  2654. bnx2x_ack_sb(bp, DEF_SB_ID, USTORM_ID, le16_to_cpu(bp->def_u_idx),
  2655. IGU_INT_NOP, 1);
  2656. bnx2x_ack_sb(bp, DEF_SB_ID, CSTORM_ID, le16_to_cpu(bp->def_c_idx),
  2657. IGU_INT_NOP, 1);
  2658. bnx2x_ack_sb(bp, DEF_SB_ID, XSTORM_ID, le16_to_cpu(bp->def_x_idx),
  2659. IGU_INT_NOP, 1);
  2660. bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, le16_to_cpu(bp->def_t_idx),
  2661. IGU_INT_ENABLE, 1);
  2662. }
  2663. static irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  2664. {
  2665. struct net_device *dev = dev_instance;
  2666. struct bnx2x *bp = netdev_priv(dev);
  2667. /* Return here if interrupt is disabled */
  2668. if (unlikely(atomic_read(&bp->intr_sem) != 0)) {
  2669. DP(NETIF_MSG_INTR, "called but intr_sem not 0, returning\n");
  2670. return IRQ_HANDLED;
  2671. }
  2672. bnx2x_ack_sb(bp, DEF_SB_ID, TSTORM_ID, 0, IGU_INT_DISABLE, 0);
  2673. #ifdef BNX2X_STOP_ON_ERROR
  2674. if (unlikely(bp->panic))
  2675. return IRQ_HANDLED;
  2676. #endif
  2677. #ifdef BCM_CNIC
  2678. {
  2679. struct cnic_ops *c_ops;
  2680. rcu_read_lock();
  2681. c_ops = rcu_dereference(bp->cnic_ops);
  2682. if (c_ops)
  2683. c_ops->cnic_handler(bp->cnic_data, NULL);
  2684. rcu_read_unlock();
  2685. }
  2686. #endif
  2687. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  2688. return IRQ_HANDLED;
  2689. }
  2690. /* end of slow path */
  2691. /* Statistics */
  2692. /****************************************************************************
  2693. * Macros
  2694. ****************************************************************************/
  2695. /* sum[hi:lo] += add[hi:lo] */
  2696. #define ADD_64(s_hi, a_hi, s_lo, a_lo) \
  2697. do { \
  2698. s_lo += a_lo; \
  2699. s_hi += a_hi + ((s_lo < a_lo) ? 1 : 0); \
  2700. } while (0)
  2701. /* difference = minuend - subtrahend */
  2702. #define DIFF_64(d_hi, m_hi, s_hi, d_lo, m_lo, s_lo) \
  2703. do { \
  2704. if (m_lo < s_lo) { \
  2705. /* underflow */ \
  2706. d_hi = m_hi - s_hi; \
  2707. if (d_hi > 0) { \
  2708. /* we can 'loan' 1 */ \
  2709. d_hi--; \
  2710. d_lo = m_lo + (UINT_MAX - s_lo) + 1; \
  2711. } else { \
  2712. /* m_hi <= s_hi */ \
  2713. d_hi = 0; \
  2714. d_lo = 0; \
  2715. } \
  2716. } else { \
  2717. /* m_lo >= s_lo */ \
  2718. if (m_hi < s_hi) { \
  2719. d_hi = 0; \
  2720. d_lo = 0; \
  2721. } else { \
  2722. /* m_hi >= s_hi */ \
  2723. d_hi = m_hi - s_hi; \
  2724. d_lo = m_lo - s_lo; \
  2725. } \
  2726. } \
  2727. } while (0)
  2728. #define UPDATE_STAT64(s, t) \
  2729. do { \
  2730. DIFF_64(diff.hi, new->s##_hi, pstats->mac_stx[0].t##_hi, \
  2731. diff.lo, new->s##_lo, pstats->mac_stx[0].t##_lo); \
  2732. pstats->mac_stx[0].t##_hi = new->s##_hi; \
  2733. pstats->mac_stx[0].t##_lo = new->s##_lo; \
  2734. ADD_64(pstats->mac_stx[1].t##_hi, diff.hi, \
  2735. pstats->mac_stx[1].t##_lo, diff.lo); \
  2736. } while (0)
  2737. #define UPDATE_STAT64_NIG(s, t) \
  2738. do { \
  2739. DIFF_64(diff.hi, new->s##_hi, old->s##_hi, \
  2740. diff.lo, new->s##_lo, old->s##_lo); \
  2741. ADD_64(estats->t##_hi, diff.hi, \
  2742. estats->t##_lo, diff.lo); \
  2743. } while (0)
  2744. /* sum[hi:lo] += add */
  2745. #define ADD_EXTEND_64(s_hi, s_lo, a) \
  2746. do { \
  2747. s_lo += a; \
  2748. s_hi += (s_lo < a) ? 1 : 0; \
  2749. } while (0)
  2750. #define UPDATE_EXTEND_STAT(s) \
  2751. do { \
  2752. ADD_EXTEND_64(pstats->mac_stx[1].s##_hi, \
  2753. pstats->mac_stx[1].s##_lo, \
  2754. new->s); \
  2755. } while (0)
  2756. #define UPDATE_EXTEND_TSTAT(s, t) \
  2757. do { \
  2758. diff = le32_to_cpu(tclient->s) - le32_to_cpu(old_tclient->s); \
  2759. old_tclient->s = tclient->s; \
  2760. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2761. } while (0)
  2762. #define UPDATE_EXTEND_USTAT(s, t) \
  2763. do { \
  2764. diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
  2765. old_uclient->s = uclient->s; \
  2766. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2767. } while (0)
  2768. #define UPDATE_EXTEND_XSTAT(s, t) \
  2769. do { \
  2770. diff = le32_to_cpu(xclient->s) - le32_to_cpu(old_xclient->s); \
  2771. old_xclient->s = xclient->s; \
  2772. ADD_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2773. } while (0)
  2774. /* minuend -= subtrahend */
  2775. #define SUB_64(m_hi, s_hi, m_lo, s_lo) \
  2776. do { \
  2777. DIFF_64(m_hi, m_hi, s_hi, m_lo, m_lo, s_lo); \
  2778. } while (0)
  2779. /* minuend[hi:lo] -= subtrahend */
  2780. #define SUB_EXTEND_64(m_hi, m_lo, s) \
  2781. do { \
  2782. SUB_64(m_hi, 0, m_lo, s); \
  2783. } while (0)
  2784. #define SUB_EXTEND_USTAT(s, t) \
  2785. do { \
  2786. diff = le32_to_cpu(uclient->s) - le32_to_cpu(old_uclient->s); \
  2787. SUB_EXTEND_64(qstats->t##_hi, qstats->t##_lo, diff); \
  2788. } while (0)
  2789. /*
  2790. * General service functions
  2791. */
  2792. static inline long bnx2x_hilo(u32 *hiref)
  2793. {
  2794. u32 lo = *(hiref + 1);
  2795. #if (BITS_PER_LONG == 64)
  2796. u32 hi = *hiref;
  2797. return HILO_U64(hi, lo);
  2798. #else
  2799. return lo;
  2800. #endif
  2801. }
  2802. /*
  2803. * Init service functions
  2804. */
  2805. static void bnx2x_storm_stats_post(struct bnx2x *bp)
  2806. {
  2807. if (!bp->stats_pending) {
  2808. struct eth_query_ramrod_data ramrod_data = {0};
  2809. int i, rc;
  2810. ramrod_data.drv_counter = bp->stats_counter++;
  2811. ramrod_data.collect_port = bp->port.pmf ? 1 : 0;
  2812. for_each_queue(bp, i)
  2813. ramrod_data.ctr_id_vector |= (1 << bp->fp[i].cl_id);
  2814. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_STAT_QUERY, 0,
  2815. ((u32 *)&ramrod_data)[1],
  2816. ((u32 *)&ramrod_data)[0], 0);
  2817. if (rc == 0) {
  2818. /* stats ramrod has it's own slot on the spq */
  2819. bp->spq_left++;
  2820. bp->stats_pending = 1;
  2821. }
  2822. }
  2823. }
  2824. static void bnx2x_hw_stats_post(struct bnx2x *bp)
  2825. {
  2826. struct dmae_command *dmae = &bp->stats_dmae;
  2827. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2828. *stats_comp = DMAE_COMP_VAL;
  2829. if (CHIP_REV_IS_SLOW(bp))
  2830. return;
  2831. /* loader */
  2832. if (bp->executer_idx) {
  2833. int loader_idx = PMF_DMAE_C(bp);
  2834. memset(dmae, 0, sizeof(struct dmae_command));
  2835. dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  2836. DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
  2837. DMAE_CMD_DST_RESET |
  2838. #ifdef __BIG_ENDIAN
  2839. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2840. #else
  2841. DMAE_CMD_ENDIANITY_DW_SWAP |
  2842. #endif
  2843. (BP_PORT(bp) ? DMAE_CMD_PORT_1 :
  2844. DMAE_CMD_PORT_0) |
  2845. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  2846. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, dmae[0]));
  2847. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, dmae[0]));
  2848. dmae->dst_addr_lo = (DMAE_REG_CMD_MEM +
  2849. sizeof(struct dmae_command) *
  2850. (loader_idx + 1)) >> 2;
  2851. dmae->dst_addr_hi = 0;
  2852. dmae->len = sizeof(struct dmae_command) >> 2;
  2853. if (CHIP_IS_E1(bp))
  2854. dmae->len--;
  2855. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx + 1] >> 2;
  2856. dmae->comp_addr_hi = 0;
  2857. dmae->comp_val = 1;
  2858. *stats_comp = 0;
  2859. bnx2x_post_dmae(bp, dmae, loader_idx);
  2860. } else if (bp->func_stx) {
  2861. *stats_comp = 0;
  2862. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  2863. }
  2864. }
  2865. static int bnx2x_stats_comp(struct bnx2x *bp)
  2866. {
  2867. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2868. int cnt = 10;
  2869. might_sleep();
  2870. while (*stats_comp != DMAE_COMP_VAL) {
  2871. if (!cnt) {
  2872. BNX2X_ERR("timeout waiting for stats finished\n");
  2873. break;
  2874. }
  2875. cnt--;
  2876. msleep(1);
  2877. }
  2878. return 1;
  2879. }
  2880. /*
  2881. * Statistics service functions
  2882. */
  2883. static void bnx2x_stats_pmf_update(struct bnx2x *bp)
  2884. {
  2885. struct dmae_command *dmae;
  2886. u32 opcode;
  2887. int loader_idx = PMF_DMAE_C(bp);
  2888. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2889. /* sanity */
  2890. if (!IS_E1HMF(bp) || !bp->port.pmf || !bp->port.port_stx) {
  2891. BNX2X_ERR("BUG!\n");
  2892. return;
  2893. }
  2894. bp->executer_idx = 0;
  2895. opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  2896. DMAE_CMD_C_ENABLE |
  2897. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2898. #ifdef __BIG_ENDIAN
  2899. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2900. #else
  2901. DMAE_CMD_ENDIANITY_DW_SWAP |
  2902. #endif
  2903. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2904. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  2905. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2906. dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
  2907. dmae->src_addr_lo = bp->port.port_stx >> 2;
  2908. dmae->src_addr_hi = 0;
  2909. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  2910. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  2911. dmae->len = DMAE_LEN32_RD_MAX;
  2912. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2913. dmae->comp_addr_hi = 0;
  2914. dmae->comp_val = 1;
  2915. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2916. dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
  2917. dmae->src_addr_lo = (bp->port.port_stx >> 2) + DMAE_LEN32_RD_MAX;
  2918. dmae->src_addr_hi = 0;
  2919. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats) +
  2920. DMAE_LEN32_RD_MAX * 4);
  2921. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats) +
  2922. DMAE_LEN32_RD_MAX * 4);
  2923. dmae->len = (sizeof(struct host_port_stats) >> 2) - DMAE_LEN32_RD_MAX;
  2924. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  2925. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  2926. dmae->comp_val = DMAE_COMP_VAL;
  2927. *stats_comp = 0;
  2928. bnx2x_hw_stats_post(bp);
  2929. bnx2x_stats_comp(bp);
  2930. }
  2931. static void bnx2x_port_stats_init(struct bnx2x *bp)
  2932. {
  2933. struct dmae_command *dmae;
  2934. int port = BP_PORT(bp);
  2935. int vn = BP_E1HVN(bp);
  2936. u32 opcode;
  2937. int loader_idx = PMF_DMAE_C(bp);
  2938. u32 mac_addr;
  2939. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  2940. /* sanity */
  2941. if (!bp->link_vars.link_up || !bp->port.pmf) {
  2942. BNX2X_ERR("BUG!\n");
  2943. return;
  2944. }
  2945. bp->executer_idx = 0;
  2946. /* MCP */
  2947. opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  2948. DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
  2949. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2950. #ifdef __BIG_ENDIAN
  2951. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2952. #else
  2953. DMAE_CMD_ENDIANITY_DW_SWAP |
  2954. #endif
  2955. (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2956. (vn << DMAE_CMD_E1HVN_SHIFT));
  2957. if (bp->port.port_stx) {
  2958. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2959. dmae->opcode = opcode;
  2960. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  2961. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  2962. dmae->dst_addr_lo = bp->port.port_stx >> 2;
  2963. dmae->dst_addr_hi = 0;
  2964. dmae->len = sizeof(struct host_port_stats) >> 2;
  2965. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2966. dmae->comp_addr_hi = 0;
  2967. dmae->comp_val = 1;
  2968. }
  2969. if (bp->func_stx) {
  2970. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2971. dmae->opcode = opcode;
  2972. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
  2973. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
  2974. dmae->dst_addr_lo = bp->func_stx >> 2;
  2975. dmae->dst_addr_hi = 0;
  2976. dmae->len = sizeof(struct host_func_stats) >> 2;
  2977. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  2978. dmae->comp_addr_hi = 0;
  2979. dmae->comp_val = 1;
  2980. }
  2981. /* MAC */
  2982. opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  2983. DMAE_CMD_C_DST_GRC | DMAE_CMD_C_ENABLE |
  2984. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  2985. #ifdef __BIG_ENDIAN
  2986. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  2987. #else
  2988. DMAE_CMD_ENDIANITY_DW_SWAP |
  2989. #endif
  2990. (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  2991. (vn << DMAE_CMD_E1HVN_SHIFT));
  2992. if (bp->link_vars.mac_type == MAC_TYPE_BMAC) {
  2993. mac_addr = (port ? NIG_REG_INGRESS_BMAC1_MEM :
  2994. NIG_REG_INGRESS_BMAC0_MEM);
  2995. /* BIGMAC_REGISTER_TX_STAT_GTPKT ..
  2996. BIGMAC_REGISTER_TX_STAT_GTBYT */
  2997. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  2998. dmae->opcode = opcode;
  2999. dmae->src_addr_lo = (mac_addr +
  3000. BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
  3001. dmae->src_addr_hi = 0;
  3002. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
  3003. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
  3004. dmae->len = (8 + BIGMAC_REGISTER_TX_STAT_GTBYT -
  3005. BIGMAC_REGISTER_TX_STAT_GTPKT) >> 2;
  3006. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3007. dmae->comp_addr_hi = 0;
  3008. dmae->comp_val = 1;
  3009. /* BIGMAC_REGISTER_RX_STAT_GR64 ..
  3010. BIGMAC_REGISTER_RX_STAT_GRIPJ */
  3011. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3012. dmae->opcode = opcode;
  3013. dmae->src_addr_lo = (mac_addr +
  3014. BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
  3015. dmae->src_addr_hi = 0;
  3016. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
  3017. offsetof(struct bmac_stats, rx_stat_gr64_lo));
  3018. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
  3019. offsetof(struct bmac_stats, rx_stat_gr64_lo));
  3020. dmae->len = (8 + BIGMAC_REGISTER_RX_STAT_GRIPJ -
  3021. BIGMAC_REGISTER_RX_STAT_GR64) >> 2;
  3022. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3023. dmae->comp_addr_hi = 0;
  3024. dmae->comp_val = 1;
  3025. } else if (bp->link_vars.mac_type == MAC_TYPE_EMAC) {
  3026. mac_addr = (port ? GRCBASE_EMAC1 : GRCBASE_EMAC0);
  3027. /* EMAC_REG_EMAC_RX_STAT_AC (EMAC_REG_EMAC_RX_STAT_AC_COUNT)*/
  3028. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3029. dmae->opcode = opcode;
  3030. dmae->src_addr_lo = (mac_addr +
  3031. EMAC_REG_EMAC_RX_STAT_AC) >> 2;
  3032. dmae->src_addr_hi = 0;
  3033. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats));
  3034. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats));
  3035. dmae->len = EMAC_REG_EMAC_RX_STAT_AC_COUNT;
  3036. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3037. dmae->comp_addr_hi = 0;
  3038. dmae->comp_val = 1;
  3039. /* EMAC_REG_EMAC_RX_STAT_AC_28 */
  3040. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3041. dmae->opcode = opcode;
  3042. dmae->src_addr_lo = (mac_addr +
  3043. EMAC_REG_EMAC_RX_STAT_AC_28) >> 2;
  3044. dmae->src_addr_hi = 0;
  3045. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
  3046. offsetof(struct emac_stats, rx_stat_falsecarriererrors));
  3047. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
  3048. offsetof(struct emac_stats, rx_stat_falsecarriererrors));
  3049. dmae->len = 1;
  3050. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3051. dmae->comp_addr_hi = 0;
  3052. dmae->comp_val = 1;
  3053. /* EMAC_REG_EMAC_TX_STAT_AC (EMAC_REG_EMAC_TX_STAT_AC_COUNT)*/
  3054. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3055. dmae->opcode = opcode;
  3056. dmae->src_addr_lo = (mac_addr +
  3057. EMAC_REG_EMAC_TX_STAT_AC) >> 2;
  3058. dmae->src_addr_hi = 0;
  3059. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, mac_stats) +
  3060. offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
  3061. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, mac_stats) +
  3062. offsetof(struct emac_stats, tx_stat_ifhcoutoctets));
  3063. dmae->len = EMAC_REG_EMAC_TX_STAT_AC_COUNT;
  3064. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3065. dmae->comp_addr_hi = 0;
  3066. dmae->comp_val = 1;
  3067. }
  3068. /* NIG */
  3069. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3070. dmae->opcode = opcode;
  3071. dmae->src_addr_lo = (port ? NIG_REG_STAT1_BRB_DISCARD :
  3072. NIG_REG_STAT0_BRB_DISCARD) >> 2;
  3073. dmae->src_addr_hi = 0;
  3074. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats));
  3075. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats));
  3076. dmae->len = (sizeof(struct nig_stats) - 4*sizeof(u32)) >> 2;
  3077. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3078. dmae->comp_addr_hi = 0;
  3079. dmae->comp_val = 1;
  3080. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3081. dmae->opcode = opcode;
  3082. dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT0 :
  3083. NIG_REG_STAT0_EGRESS_MAC_PKT0) >> 2;
  3084. dmae->src_addr_hi = 0;
  3085. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
  3086. offsetof(struct nig_stats, egress_mac_pkt0_lo));
  3087. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
  3088. offsetof(struct nig_stats, egress_mac_pkt0_lo));
  3089. dmae->len = (2*sizeof(u32)) >> 2;
  3090. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3091. dmae->comp_addr_hi = 0;
  3092. dmae->comp_val = 1;
  3093. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3094. dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  3095. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  3096. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  3097. #ifdef __BIG_ENDIAN
  3098. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  3099. #else
  3100. DMAE_CMD_ENDIANITY_DW_SWAP |
  3101. #endif
  3102. (port ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  3103. (vn << DMAE_CMD_E1HVN_SHIFT));
  3104. dmae->src_addr_lo = (port ? NIG_REG_STAT1_EGRESS_MAC_PKT1 :
  3105. NIG_REG_STAT0_EGRESS_MAC_PKT1) >> 2;
  3106. dmae->src_addr_hi = 0;
  3107. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, nig_stats) +
  3108. offsetof(struct nig_stats, egress_mac_pkt1_lo));
  3109. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, nig_stats) +
  3110. offsetof(struct nig_stats, egress_mac_pkt1_lo));
  3111. dmae->len = (2*sizeof(u32)) >> 2;
  3112. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3113. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3114. dmae->comp_val = DMAE_COMP_VAL;
  3115. *stats_comp = 0;
  3116. }
  3117. static void bnx2x_func_stats_init(struct bnx2x *bp)
  3118. {
  3119. struct dmae_command *dmae = &bp->stats_dmae;
  3120. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3121. /* sanity */
  3122. if (!bp->func_stx) {
  3123. BNX2X_ERR("BUG!\n");
  3124. return;
  3125. }
  3126. bp->executer_idx = 0;
  3127. memset(dmae, 0, sizeof(struct dmae_command));
  3128. dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  3129. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  3130. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  3131. #ifdef __BIG_ENDIAN
  3132. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  3133. #else
  3134. DMAE_CMD_ENDIANITY_DW_SWAP |
  3135. #endif
  3136. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  3137. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  3138. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
  3139. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
  3140. dmae->dst_addr_lo = bp->func_stx >> 2;
  3141. dmae->dst_addr_hi = 0;
  3142. dmae->len = sizeof(struct host_func_stats) >> 2;
  3143. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3144. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3145. dmae->comp_val = DMAE_COMP_VAL;
  3146. *stats_comp = 0;
  3147. }
  3148. static void bnx2x_stats_start(struct bnx2x *bp)
  3149. {
  3150. if (bp->port.pmf)
  3151. bnx2x_port_stats_init(bp);
  3152. else if (bp->func_stx)
  3153. bnx2x_func_stats_init(bp);
  3154. bnx2x_hw_stats_post(bp);
  3155. bnx2x_storm_stats_post(bp);
  3156. }
  3157. static void bnx2x_stats_pmf_start(struct bnx2x *bp)
  3158. {
  3159. bnx2x_stats_comp(bp);
  3160. bnx2x_stats_pmf_update(bp);
  3161. bnx2x_stats_start(bp);
  3162. }
  3163. static void bnx2x_stats_restart(struct bnx2x *bp)
  3164. {
  3165. bnx2x_stats_comp(bp);
  3166. bnx2x_stats_start(bp);
  3167. }
  3168. static void bnx2x_bmac_stats_update(struct bnx2x *bp)
  3169. {
  3170. struct bmac_stats *new = bnx2x_sp(bp, mac_stats.bmac_stats);
  3171. struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
  3172. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3173. struct {
  3174. u32 lo;
  3175. u32 hi;
  3176. } diff;
  3177. UPDATE_STAT64(rx_stat_grerb, rx_stat_ifhcinbadoctets);
  3178. UPDATE_STAT64(rx_stat_grfcs, rx_stat_dot3statsfcserrors);
  3179. UPDATE_STAT64(rx_stat_grund, rx_stat_etherstatsundersizepkts);
  3180. UPDATE_STAT64(rx_stat_grovr, rx_stat_dot3statsframestoolong);
  3181. UPDATE_STAT64(rx_stat_grfrg, rx_stat_etherstatsfragments);
  3182. UPDATE_STAT64(rx_stat_grjbr, rx_stat_etherstatsjabbers);
  3183. UPDATE_STAT64(rx_stat_grxcf, rx_stat_maccontrolframesreceived);
  3184. UPDATE_STAT64(rx_stat_grxpf, rx_stat_xoffstateentered);
  3185. UPDATE_STAT64(rx_stat_grxpf, rx_stat_bmac_xpf);
  3186. UPDATE_STAT64(tx_stat_gtxpf, tx_stat_outxoffsent);
  3187. UPDATE_STAT64(tx_stat_gtxpf, tx_stat_flowcontroldone);
  3188. UPDATE_STAT64(tx_stat_gt64, tx_stat_etherstatspkts64octets);
  3189. UPDATE_STAT64(tx_stat_gt127,
  3190. tx_stat_etherstatspkts65octetsto127octets);
  3191. UPDATE_STAT64(tx_stat_gt255,
  3192. tx_stat_etherstatspkts128octetsto255octets);
  3193. UPDATE_STAT64(tx_stat_gt511,
  3194. tx_stat_etherstatspkts256octetsto511octets);
  3195. UPDATE_STAT64(tx_stat_gt1023,
  3196. tx_stat_etherstatspkts512octetsto1023octets);
  3197. UPDATE_STAT64(tx_stat_gt1518,
  3198. tx_stat_etherstatspkts1024octetsto1522octets);
  3199. UPDATE_STAT64(tx_stat_gt2047, tx_stat_bmac_2047);
  3200. UPDATE_STAT64(tx_stat_gt4095, tx_stat_bmac_4095);
  3201. UPDATE_STAT64(tx_stat_gt9216, tx_stat_bmac_9216);
  3202. UPDATE_STAT64(tx_stat_gt16383, tx_stat_bmac_16383);
  3203. UPDATE_STAT64(tx_stat_gterr,
  3204. tx_stat_dot3statsinternalmactransmiterrors);
  3205. UPDATE_STAT64(tx_stat_gtufl, tx_stat_bmac_ufl);
  3206. estats->pause_frames_received_hi =
  3207. pstats->mac_stx[1].rx_stat_bmac_xpf_hi;
  3208. estats->pause_frames_received_lo =
  3209. pstats->mac_stx[1].rx_stat_bmac_xpf_lo;
  3210. estats->pause_frames_sent_hi =
  3211. pstats->mac_stx[1].tx_stat_outxoffsent_hi;
  3212. estats->pause_frames_sent_lo =
  3213. pstats->mac_stx[1].tx_stat_outxoffsent_lo;
  3214. }
  3215. static void bnx2x_emac_stats_update(struct bnx2x *bp)
  3216. {
  3217. struct emac_stats *new = bnx2x_sp(bp, mac_stats.emac_stats);
  3218. struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
  3219. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3220. UPDATE_EXTEND_STAT(rx_stat_ifhcinbadoctets);
  3221. UPDATE_EXTEND_STAT(tx_stat_ifhcoutbadoctets);
  3222. UPDATE_EXTEND_STAT(rx_stat_dot3statsfcserrors);
  3223. UPDATE_EXTEND_STAT(rx_stat_dot3statsalignmenterrors);
  3224. UPDATE_EXTEND_STAT(rx_stat_dot3statscarriersenseerrors);
  3225. UPDATE_EXTEND_STAT(rx_stat_falsecarriererrors);
  3226. UPDATE_EXTEND_STAT(rx_stat_etherstatsundersizepkts);
  3227. UPDATE_EXTEND_STAT(rx_stat_dot3statsframestoolong);
  3228. UPDATE_EXTEND_STAT(rx_stat_etherstatsfragments);
  3229. UPDATE_EXTEND_STAT(rx_stat_etherstatsjabbers);
  3230. UPDATE_EXTEND_STAT(rx_stat_maccontrolframesreceived);
  3231. UPDATE_EXTEND_STAT(rx_stat_xoffstateentered);
  3232. UPDATE_EXTEND_STAT(rx_stat_xonpauseframesreceived);
  3233. UPDATE_EXTEND_STAT(rx_stat_xoffpauseframesreceived);
  3234. UPDATE_EXTEND_STAT(tx_stat_outxonsent);
  3235. UPDATE_EXTEND_STAT(tx_stat_outxoffsent);
  3236. UPDATE_EXTEND_STAT(tx_stat_flowcontroldone);
  3237. UPDATE_EXTEND_STAT(tx_stat_etherstatscollisions);
  3238. UPDATE_EXTEND_STAT(tx_stat_dot3statssinglecollisionframes);
  3239. UPDATE_EXTEND_STAT(tx_stat_dot3statsmultiplecollisionframes);
  3240. UPDATE_EXTEND_STAT(tx_stat_dot3statsdeferredtransmissions);
  3241. UPDATE_EXTEND_STAT(tx_stat_dot3statsexcessivecollisions);
  3242. UPDATE_EXTEND_STAT(tx_stat_dot3statslatecollisions);
  3243. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts64octets);
  3244. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts65octetsto127octets);
  3245. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts128octetsto255octets);
  3246. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts256octetsto511octets);
  3247. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts512octetsto1023octets);
  3248. UPDATE_EXTEND_STAT(tx_stat_etherstatspkts1024octetsto1522octets);
  3249. UPDATE_EXTEND_STAT(tx_stat_etherstatspktsover1522octets);
  3250. UPDATE_EXTEND_STAT(tx_stat_dot3statsinternalmactransmiterrors);
  3251. estats->pause_frames_received_hi =
  3252. pstats->mac_stx[1].rx_stat_xonpauseframesreceived_hi;
  3253. estats->pause_frames_received_lo =
  3254. pstats->mac_stx[1].rx_stat_xonpauseframesreceived_lo;
  3255. ADD_64(estats->pause_frames_received_hi,
  3256. pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_hi,
  3257. estats->pause_frames_received_lo,
  3258. pstats->mac_stx[1].rx_stat_xoffpauseframesreceived_lo);
  3259. estats->pause_frames_sent_hi =
  3260. pstats->mac_stx[1].tx_stat_outxonsent_hi;
  3261. estats->pause_frames_sent_lo =
  3262. pstats->mac_stx[1].tx_stat_outxonsent_lo;
  3263. ADD_64(estats->pause_frames_sent_hi,
  3264. pstats->mac_stx[1].tx_stat_outxoffsent_hi,
  3265. estats->pause_frames_sent_lo,
  3266. pstats->mac_stx[1].tx_stat_outxoffsent_lo);
  3267. }
  3268. static int bnx2x_hw_stats_update(struct bnx2x *bp)
  3269. {
  3270. struct nig_stats *new = bnx2x_sp(bp, nig_stats);
  3271. struct nig_stats *old = &(bp->port.old_nig_stats);
  3272. struct host_port_stats *pstats = bnx2x_sp(bp, port_stats);
  3273. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3274. struct {
  3275. u32 lo;
  3276. u32 hi;
  3277. } diff;
  3278. u32 nig_timer_max;
  3279. if (bp->link_vars.mac_type == MAC_TYPE_BMAC)
  3280. bnx2x_bmac_stats_update(bp);
  3281. else if (bp->link_vars.mac_type == MAC_TYPE_EMAC)
  3282. bnx2x_emac_stats_update(bp);
  3283. else { /* unreached */
  3284. BNX2X_ERR("stats updated by DMAE but no MAC active\n");
  3285. return -1;
  3286. }
  3287. ADD_EXTEND_64(pstats->brb_drop_hi, pstats->brb_drop_lo,
  3288. new->brb_discard - old->brb_discard);
  3289. ADD_EXTEND_64(estats->brb_truncate_hi, estats->brb_truncate_lo,
  3290. new->brb_truncate - old->brb_truncate);
  3291. UPDATE_STAT64_NIG(egress_mac_pkt0,
  3292. etherstatspkts1024octetsto1522octets);
  3293. UPDATE_STAT64_NIG(egress_mac_pkt1, etherstatspktsover1522octets);
  3294. memcpy(old, new, sizeof(struct nig_stats));
  3295. memcpy(&(estats->rx_stat_ifhcinbadoctets_hi), &(pstats->mac_stx[1]),
  3296. sizeof(struct mac_stx));
  3297. estats->brb_drop_hi = pstats->brb_drop_hi;
  3298. estats->brb_drop_lo = pstats->brb_drop_lo;
  3299. pstats->host_port_stats_start = ++pstats->host_port_stats_end;
  3300. nig_timer_max = SHMEM_RD(bp, port_mb[BP_PORT(bp)].stat_nig_timer);
  3301. if (nig_timer_max != estats->nig_timer_max) {
  3302. estats->nig_timer_max = nig_timer_max;
  3303. BNX2X_ERR("NIG timer max (%u)\n", estats->nig_timer_max);
  3304. }
  3305. return 0;
  3306. }
  3307. static int bnx2x_storm_stats_update(struct bnx2x *bp)
  3308. {
  3309. struct eth_stats_query *stats = bnx2x_sp(bp, fw_stats);
  3310. struct tstorm_per_port_stats *tport =
  3311. &stats->tstorm_common.port_statistics;
  3312. struct host_func_stats *fstats = bnx2x_sp(bp, func_stats);
  3313. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3314. int i;
  3315. memcpy(&(fstats->total_bytes_received_hi),
  3316. &(bnx2x_sp(bp, func_stats_base)->total_bytes_received_hi),
  3317. sizeof(struct host_func_stats) - 2*sizeof(u32));
  3318. estats->error_bytes_received_hi = 0;
  3319. estats->error_bytes_received_lo = 0;
  3320. estats->etherstatsoverrsizepkts_hi = 0;
  3321. estats->etherstatsoverrsizepkts_lo = 0;
  3322. estats->no_buff_discard_hi = 0;
  3323. estats->no_buff_discard_lo = 0;
  3324. for_each_rx_queue(bp, i) {
  3325. struct bnx2x_fastpath *fp = &bp->fp[i];
  3326. int cl_id = fp->cl_id;
  3327. struct tstorm_per_client_stats *tclient =
  3328. &stats->tstorm_common.client_statistics[cl_id];
  3329. struct tstorm_per_client_stats *old_tclient = &fp->old_tclient;
  3330. struct ustorm_per_client_stats *uclient =
  3331. &stats->ustorm_common.client_statistics[cl_id];
  3332. struct ustorm_per_client_stats *old_uclient = &fp->old_uclient;
  3333. struct xstorm_per_client_stats *xclient =
  3334. &stats->xstorm_common.client_statistics[cl_id];
  3335. struct xstorm_per_client_stats *old_xclient = &fp->old_xclient;
  3336. struct bnx2x_eth_q_stats *qstats = &fp->eth_q_stats;
  3337. u32 diff;
  3338. /* are storm stats valid? */
  3339. if ((u16)(le16_to_cpu(xclient->stats_counter) + 1) !=
  3340. bp->stats_counter) {
  3341. DP(BNX2X_MSG_STATS, "[%d] stats not updated by xstorm"
  3342. " xstorm counter (%d) != stats_counter (%d)\n",
  3343. i, xclient->stats_counter, bp->stats_counter);
  3344. return -1;
  3345. }
  3346. if ((u16)(le16_to_cpu(tclient->stats_counter) + 1) !=
  3347. bp->stats_counter) {
  3348. DP(BNX2X_MSG_STATS, "[%d] stats not updated by tstorm"
  3349. " tstorm counter (%d) != stats_counter (%d)\n",
  3350. i, tclient->stats_counter, bp->stats_counter);
  3351. return -2;
  3352. }
  3353. if ((u16)(le16_to_cpu(uclient->stats_counter) + 1) !=
  3354. bp->stats_counter) {
  3355. DP(BNX2X_MSG_STATS, "[%d] stats not updated by ustorm"
  3356. " ustorm counter (%d) != stats_counter (%d)\n",
  3357. i, uclient->stats_counter, bp->stats_counter);
  3358. return -4;
  3359. }
  3360. qstats->total_bytes_received_hi =
  3361. le32_to_cpu(tclient->rcv_broadcast_bytes.hi);
  3362. qstats->total_bytes_received_lo =
  3363. le32_to_cpu(tclient->rcv_broadcast_bytes.lo);
  3364. ADD_64(qstats->total_bytes_received_hi,
  3365. le32_to_cpu(tclient->rcv_multicast_bytes.hi),
  3366. qstats->total_bytes_received_lo,
  3367. le32_to_cpu(tclient->rcv_multicast_bytes.lo));
  3368. ADD_64(qstats->total_bytes_received_hi,
  3369. le32_to_cpu(tclient->rcv_unicast_bytes.hi),
  3370. qstats->total_bytes_received_lo,
  3371. le32_to_cpu(tclient->rcv_unicast_bytes.lo));
  3372. qstats->valid_bytes_received_hi =
  3373. qstats->total_bytes_received_hi;
  3374. qstats->valid_bytes_received_lo =
  3375. qstats->total_bytes_received_lo;
  3376. qstats->error_bytes_received_hi =
  3377. le32_to_cpu(tclient->rcv_error_bytes.hi);
  3378. qstats->error_bytes_received_lo =
  3379. le32_to_cpu(tclient->rcv_error_bytes.lo);
  3380. ADD_64(qstats->total_bytes_received_hi,
  3381. qstats->error_bytes_received_hi,
  3382. qstats->total_bytes_received_lo,
  3383. qstats->error_bytes_received_lo);
  3384. UPDATE_EXTEND_TSTAT(rcv_unicast_pkts,
  3385. total_unicast_packets_received);
  3386. UPDATE_EXTEND_TSTAT(rcv_multicast_pkts,
  3387. total_multicast_packets_received);
  3388. UPDATE_EXTEND_TSTAT(rcv_broadcast_pkts,
  3389. total_broadcast_packets_received);
  3390. UPDATE_EXTEND_TSTAT(packets_too_big_discard,
  3391. etherstatsoverrsizepkts);
  3392. UPDATE_EXTEND_TSTAT(no_buff_discard, no_buff_discard);
  3393. SUB_EXTEND_USTAT(ucast_no_buff_pkts,
  3394. total_unicast_packets_received);
  3395. SUB_EXTEND_USTAT(mcast_no_buff_pkts,
  3396. total_multicast_packets_received);
  3397. SUB_EXTEND_USTAT(bcast_no_buff_pkts,
  3398. total_broadcast_packets_received);
  3399. UPDATE_EXTEND_USTAT(ucast_no_buff_pkts, no_buff_discard);
  3400. UPDATE_EXTEND_USTAT(mcast_no_buff_pkts, no_buff_discard);
  3401. UPDATE_EXTEND_USTAT(bcast_no_buff_pkts, no_buff_discard);
  3402. qstats->total_bytes_transmitted_hi =
  3403. le32_to_cpu(xclient->unicast_bytes_sent.hi);
  3404. qstats->total_bytes_transmitted_lo =
  3405. le32_to_cpu(xclient->unicast_bytes_sent.lo);
  3406. ADD_64(qstats->total_bytes_transmitted_hi,
  3407. le32_to_cpu(xclient->multicast_bytes_sent.hi),
  3408. qstats->total_bytes_transmitted_lo,
  3409. le32_to_cpu(xclient->multicast_bytes_sent.lo));
  3410. ADD_64(qstats->total_bytes_transmitted_hi,
  3411. le32_to_cpu(xclient->broadcast_bytes_sent.hi),
  3412. qstats->total_bytes_transmitted_lo,
  3413. le32_to_cpu(xclient->broadcast_bytes_sent.lo));
  3414. UPDATE_EXTEND_XSTAT(unicast_pkts_sent,
  3415. total_unicast_packets_transmitted);
  3416. UPDATE_EXTEND_XSTAT(multicast_pkts_sent,
  3417. total_multicast_packets_transmitted);
  3418. UPDATE_EXTEND_XSTAT(broadcast_pkts_sent,
  3419. total_broadcast_packets_transmitted);
  3420. old_tclient->checksum_discard = tclient->checksum_discard;
  3421. old_tclient->ttl0_discard = tclient->ttl0_discard;
  3422. ADD_64(fstats->total_bytes_received_hi,
  3423. qstats->total_bytes_received_hi,
  3424. fstats->total_bytes_received_lo,
  3425. qstats->total_bytes_received_lo);
  3426. ADD_64(fstats->total_bytes_transmitted_hi,
  3427. qstats->total_bytes_transmitted_hi,
  3428. fstats->total_bytes_transmitted_lo,
  3429. qstats->total_bytes_transmitted_lo);
  3430. ADD_64(fstats->total_unicast_packets_received_hi,
  3431. qstats->total_unicast_packets_received_hi,
  3432. fstats->total_unicast_packets_received_lo,
  3433. qstats->total_unicast_packets_received_lo);
  3434. ADD_64(fstats->total_multicast_packets_received_hi,
  3435. qstats->total_multicast_packets_received_hi,
  3436. fstats->total_multicast_packets_received_lo,
  3437. qstats->total_multicast_packets_received_lo);
  3438. ADD_64(fstats->total_broadcast_packets_received_hi,
  3439. qstats->total_broadcast_packets_received_hi,
  3440. fstats->total_broadcast_packets_received_lo,
  3441. qstats->total_broadcast_packets_received_lo);
  3442. ADD_64(fstats->total_unicast_packets_transmitted_hi,
  3443. qstats->total_unicast_packets_transmitted_hi,
  3444. fstats->total_unicast_packets_transmitted_lo,
  3445. qstats->total_unicast_packets_transmitted_lo);
  3446. ADD_64(fstats->total_multicast_packets_transmitted_hi,
  3447. qstats->total_multicast_packets_transmitted_hi,
  3448. fstats->total_multicast_packets_transmitted_lo,
  3449. qstats->total_multicast_packets_transmitted_lo);
  3450. ADD_64(fstats->total_broadcast_packets_transmitted_hi,
  3451. qstats->total_broadcast_packets_transmitted_hi,
  3452. fstats->total_broadcast_packets_transmitted_lo,
  3453. qstats->total_broadcast_packets_transmitted_lo);
  3454. ADD_64(fstats->valid_bytes_received_hi,
  3455. qstats->valid_bytes_received_hi,
  3456. fstats->valid_bytes_received_lo,
  3457. qstats->valid_bytes_received_lo);
  3458. ADD_64(estats->error_bytes_received_hi,
  3459. qstats->error_bytes_received_hi,
  3460. estats->error_bytes_received_lo,
  3461. qstats->error_bytes_received_lo);
  3462. ADD_64(estats->etherstatsoverrsizepkts_hi,
  3463. qstats->etherstatsoverrsizepkts_hi,
  3464. estats->etherstatsoverrsizepkts_lo,
  3465. qstats->etherstatsoverrsizepkts_lo);
  3466. ADD_64(estats->no_buff_discard_hi, qstats->no_buff_discard_hi,
  3467. estats->no_buff_discard_lo, qstats->no_buff_discard_lo);
  3468. }
  3469. ADD_64(fstats->total_bytes_received_hi,
  3470. estats->rx_stat_ifhcinbadoctets_hi,
  3471. fstats->total_bytes_received_lo,
  3472. estats->rx_stat_ifhcinbadoctets_lo);
  3473. memcpy(estats, &(fstats->total_bytes_received_hi),
  3474. sizeof(struct host_func_stats) - 2*sizeof(u32));
  3475. ADD_64(estats->etherstatsoverrsizepkts_hi,
  3476. estats->rx_stat_dot3statsframestoolong_hi,
  3477. estats->etherstatsoverrsizepkts_lo,
  3478. estats->rx_stat_dot3statsframestoolong_lo);
  3479. ADD_64(estats->error_bytes_received_hi,
  3480. estats->rx_stat_ifhcinbadoctets_hi,
  3481. estats->error_bytes_received_lo,
  3482. estats->rx_stat_ifhcinbadoctets_lo);
  3483. if (bp->port.pmf) {
  3484. estats->mac_filter_discard =
  3485. le32_to_cpu(tport->mac_filter_discard);
  3486. estats->xxoverflow_discard =
  3487. le32_to_cpu(tport->xxoverflow_discard);
  3488. estats->brb_truncate_discard =
  3489. le32_to_cpu(tport->brb_truncate_discard);
  3490. estats->mac_discard = le32_to_cpu(tport->mac_discard);
  3491. }
  3492. fstats->host_func_stats_start = ++fstats->host_func_stats_end;
  3493. bp->stats_pending = 0;
  3494. return 0;
  3495. }
  3496. static void bnx2x_net_stats_update(struct bnx2x *bp)
  3497. {
  3498. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3499. struct net_device_stats *nstats = &bp->dev->stats;
  3500. int i;
  3501. nstats->rx_packets =
  3502. bnx2x_hilo(&estats->total_unicast_packets_received_hi) +
  3503. bnx2x_hilo(&estats->total_multicast_packets_received_hi) +
  3504. bnx2x_hilo(&estats->total_broadcast_packets_received_hi);
  3505. nstats->tx_packets =
  3506. bnx2x_hilo(&estats->total_unicast_packets_transmitted_hi) +
  3507. bnx2x_hilo(&estats->total_multicast_packets_transmitted_hi) +
  3508. bnx2x_hilo(&estats->total_broadcast_packets_transmitted_hi);
  3509. nstats->rx_bytes = bnx2x_hilo(&estats->total_bytes_received_hi);
  3510. nstats->tx_bytes = bnx2x_hilo(&estats->total_bytes_transmitted_hi);
  3511. nstats->rx_dropped = estats->mac_discard;
  3512. for_each_rx_queue(bp, i)
  3513. nstats->rx_dropped +=
  3514. le32_to_cpu(bp->fp[i].old_tclient.checksum_discard);
  3515. nstats->tx_dropped = 0;
  3516. nstats->multicast =
  3517. bnx2x_hilo(&estats->total_multicast_packets_received_hi);
  3518. nstats->collisions =
  3519. bnx2x_hilo(&estats->tx_stat_etherstatscollisions_hi);
  3520. nstats->rx_length_errors =
  3521. bnx2x_hilo(&estats->rx_stat_etherstatsundersizepkts_hi) +
  3522. bnx2x_hilo(&estats->etherstatsoverrsizepkts_hi);
  3523. nstats->rx_over_errors = bnx2x_hilo(&estats->brb_drop_hi) +
  3524. bnx2x_hilo(&estats->brb_truncate_hi);
  3525. nstats->rx_crc_errors =
  3526. bnx2x_hilo(&estats->rx_stat_dot3statsfcserrors_hi);
  3527. nstats->rx_frame_errors =
  3528. bnx2x_hilo(&estats->rx_stat_dot3statsalignmenterrors_hi);
  3529. nstats->rx_fifo_errors = bnx2x_hilo(&estats->no_buff_discard_hi);
  3530. nstats->rx_missed_errors = estats->xxoverflow_discard;
  3531. nstats->rx_errors = nstats->rx_length_errors +
  3532. nstats->rx_over_errors +
  3533. nstats->rx_crc_errors +
  3534. nstats->rx_frame_errors +
  3535. nstats->rx_fifo_errors +
  3536. nstats->rx_missed_errors;
  3537. nstats->tx_aborted_errors =
  3538. bnx2x_hilo(&estats->tx_stat_dot3statslatecollisions_hi) +
  3539. bnx2x_hilo(&estats->tx_stat_dot3statsexcessivecollisions_hi);
  3540. nstats->tx_carrier_errors =
  3541. bnx2x_hilo(&estats->rx_stat_dot3statscarriersenseerrors_hi);
  3542. nstats->tx_fifo_errors = 0;
  3543. nstats->tx_heartbeat_errors = 0;
  3544. nstats->tx_window_errors = 0;
  3545. nstats->tx_errors = nstats->tx_aborted_errors +
  3546. nstats->tx_carrier_errors +
  3547. bnx2x_hilo(&estats->tx_stat_dot3statsinternalmactransmiterrors_hi);
  3548. }
  3549. static void bnx2x_drv_stats_update(struct bnx2x *bp)
  3550. {
  3551. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3552. int i;
  3553. estats->driver_xoff = 0;
  3554. estats->rx_err_discard_pkt = 0;
  3555. estats->rx_skb_alloc_failed = 0;
  3556. estats->hw_csum_err = 0;
  3557. for_each_rx_queue(bp, i) {
  3558. struct bnx2x_eth_q_stats *qstats = &bp->fp[i].eth_q_stats;
  3559. estats->driver_xoff += qstats->driver_xoff;
  3560. estats->rx_err_discard_pkt += qstats->rx_err_discard_pkt;
  3561. estats->rx_skb_alloc_failed += qstats->rx_skb_alloc_failed;
  3562. estats->hw_csum_err += qstats->hw_csum_err;
  3563. }
  3564. }
  3565. static void bnx2x_stats_update(struct bnx2x *bp)
  3566. {
  3567. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3568. if (*stats_comp != DMAE_COMP_VAL)
  3569. return;
  3570. if (bp->port.pmf)
  3571. bnx2x_hw_stats_update(bp);
  3572. if (bnx2x_storm_stats_update(bp) && (bp->stats_pending++ == 3)) {
  3573. BNX2X_ERR("storm stats were not updated for 3 times\n");
  3574. bnx2x_panic();
  3575. return;
  3576. }
  3577. bnx2x_net_stats_update(bp);
  3578. bnx2x_drv_stats_update(bp);
  3579. if (bp->msglevel & NETIF_MSG_TIMER) {
  3580. struct bnx2x_fastpath *fp0_rx = bp->fp;
  3581. struct bnx2x_fastpath *fp0_tx = &(bp->fp[bp->num_rx_queues]);
  3582. struct tstorm_per_client_stats *old_tclient =
  3583. &bp->fp->old_tclient;
  3584. struct bnx2x_eth_q_stats *qstats = &bp->fp->eth_q_stats;
  3585. struct bnx2x_eth_stats *estats = &bp->eth_stats;
  3586. struct net_device_stats *nstats = &bp->dev->stats;
  3587. int i;
  3588. printk(KERN_DEBUG "%s:\n", bp->dev->name);
  3589. printk(KERN_DEBUG " tx avail (%4x) tx hc idx (%x)"
  3590. " tx pkt (%lx)\n",
  3591. bnx2x_tx_avail(fp0_tx),
  3592. le16_to_cpu(*fp0_tx->tx_cons_sb), nstats->tx_packets);
  3593. printk(KERN_DEBUG " rx usage (%4x) rx hc idx (%x)"
  3594. " rx pkt (%lx)\n",
  3595. (u16)(le16_to_cpu(*fp0_rx->rx_cons_sb) -
  3596. fp0_rx->rx_comp_cons),
  3597. le16_to_cpu(*fp0_rx->rx_cons_sb), nstats->rx_packets);
  3598. printk(KERN_DEBUG " %s (Xoff events %u) brb drops %u "
  3599. "brb truncate %u\n",
  3600. (netif_queue_stopped(bp->dev) ? "Xoff" : "Xon"),
  3601. qstats->driver_xoff,
  3602. estats->brb_drop_lo, estats->brb_truncate_lo);
  3603. printk(KERN_DEBUG "tstats: checksum_discard %u "
  3604. "packets_too_big_discard %lu no_buff_discard %lu "
  3605. "mac_discard %u mac_filter_discard %u "
  3606. "xxovrflow_discard %u brb_truncate_discard %u "
  3607. "ttl0_discard %u\n",
  3608. le32_to_cpu(old_tclient->checksum_discard),
  3609. bnx2x_hilo(&qstats->etherstatsoverrsizepkts_hi),
  3610. bnx2x_hilo(&qstats->no_buff_discard_hi),
  3611. estats->mac_discard, estats->mac_filter_discard,
  3612. estats->xxoverflow_discard, estats->brb_truncate_discard,
  3613. le32_to_cpu(old_tclient->ttl0_discard));
  3614. for_each_queue(bp, i) {
  3615. printk(KERN_DEBUG "[%d]: %lu\t%lu\t%lu\n", i,
  3616. bnx2x_fp(bp, i, tx_pkt),
  3617. bnx2x_fp(bp, i, rx_pkt),
  3618. bnx2x_fp(bp, i, rx_calls));
  3619. }
  3620. }
  3621. bnx2x_hw_stats_post(bp);
  3622. bnx2x_storm_stats_post(bp);
  3623. }
  3624. static void bnx2x_port_stats_stop(struct bnx2x *bp)
  3625. {
  3626. struct dmae_command *dmae;
  3627. u32 opcode;
  3628. int loader_idx = PMF_DMAE_C(bp);
  3629. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3630. bp->executer_idx = 0;
  3631. opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  3632. DMAE_CMD_C_ENABLE |
  3633. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  3634. #ifdef __BIG_ENDIAN
  3635. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  3636. #else
  3637. DMAE_CMD_ENDIANITY_DW_SWAP |
  3638. #endif
  3639. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  3640. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  3641. if (bp->port.port_stx) {
  3642. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3643. if (bp->func_stx)
  3644. dmae->opcode = (opcode | DMAE_CMD_C_DST_GRC);
  3645. else
  3646. dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
  3647. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  3648. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  3649. dmae->dst_addr_lo = bp->port.port_stx >> 2;
  3650. dmae->dst_addr_hi = 0;
  3651. dmae->len = sizeof(struct host_port_stats) >> 2;
  3652. if (bp->func_stx) {
  3653. dmae->comp_addr_lo = dmae_reg_go_c[loader_idx] >> 2;
  3654. dmae->comp_addr_hi = 0;
  3655. dmae->comp_val = 1;
  3656. } else {
  3657. dmae->comp_addr_lo =
  3658. U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3659. dmae->comp_addr_hi =
  3660. U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3661. dmae->comp_val = DMAE_COMP_VAL;
  3662. *stats_comp = 0;
  3663. }
  3664. }
  3665. if (bp->func_stx) {
  3666. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3667. dmae->opcode = (opcode | DMAE_CMD_C_DST_PCI);
  3668. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats));
  3669. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats));
  3670. dmae->dst_addr_lo = bp->func_stx >> 2;
  3671. dmae->dst_addr_hi = 0;
  3672. dmae->len = sizeof(struct host_func_stats) >> 2;
  3673. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3674. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3675. dmae->comp_val = DMAE_COMP_VAL;
  3676. *stats_comp = 0;
  3677. }
  3678. }
  3679. static void bnx2x_stats_stop(struct bnx2x *bp)
  3680. {
  3681. int update = 0;
  3682. bnx2x_stats_comp(bp);
  3683. if (bp->port.pmf)
  3684. update = (bnx2x_hw_stats_update(bp) == 0);
  3685. update |= (bnx2x_storm_stats_update(bp) == 0);
  3686. if (update) {
  3687. bnx2x_net_stats_update(bp);
  3688. if (bp->port.pmf)
  3689. bnx2x_port_stats_stop(bp);
  3690. bnx2x_hw_stats_post(bp);
  3691. bnx2x_stats_comp(bp);
  3692. }
  3693. }
  3694. static void bnx2x_stats_do_nothing(struct bnx2x *bp)
  3695. {
  3696. }
  3697. static const struct {
  3698. void (*action)(struct bnx2x *bp);
  3699. enum bnx2x_stats_state next_state;
  3700. } bnx2x_stats_stm[STATS_STATE_MAX][STATS_EVENT_MAX] = {
  3701. /* state event */
  3702. {
  3703. /* DISABLED PMF */ {bnx2x_stats_pmf_update, STATS_STATE_DISABLED},
  3704. /* LINK_UP */ {bnx2x_stats_start, STATS_STATE_ENABLED},
  3705. /* UPDATE */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED},
  3706. /* STOP */ {bnx2x_stats_do_nothing, STATS_STATE_DISABLED}
  3707. },
  3708. {
  3709. /* ENABLED PMF */ {bnx2x_stats_pmf_start, STATS_STATE_ENABLED},
  3710. /* LINK_UP */ {bnx2x_stats_restart, STATS_STATE_ENABLED},
  3711. /* UPDATE */ {bnx2x_stats_update, STATS_STATE_ENABLED},
  3712. /* STOP */ {bnx2x_stats_stop, STATS_STATE_DISABLED}
  3713. }
  3714. };
  3715. static void bnx2x_stats_handle(struct bnx2x *bp, enum bnx2x_stats_event event)
  3716. {
  3717. enum bnx2x_stats_state state = bp->stats_state;
  3718. bnx2x_stats_stm[state][event].action(bp);
  3719. bp->stats_state = bnx2x_stats_stm[state][event].next_state;
  3720. /* Make sure the state has been "changed" */
  3721. smp_wmb();
  3722. if ((event != STATS_EVENT_UPDATE) || (bp->msglevel & NETIF_MSG_TIMER))
  3723. DP(BNX2X_MSG_STATS, "state %d -> event %d -> state %d\n",
  3724. state, event, bp->stats_state);
  3725. }
  3726. static void bnx2x_port_stats_base_init(struct bnx2x *bp)
  3727. {
  3728. struct dmae_command *dmae;
  3729. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3730. /* sanity */
  3731. if (!bp->port.pmf || !bp->port.port_stx) {
  3732. BNX2X_ERR("BUG!\n");
  3733. return;
  3734. }
  3735. bp->executer_idx = 0;
  3736. dmae = bnx2x_sp(bp, dmae[bp->executer_idx++]);
  3737. dmae->opcode = (DMAE_CMD_SRC_PCI | DMAE_CMD_DST_GRC |
  3738. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  3739. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  3740. #ifdef __BIG_ENDIAN
  3741. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  3742. #else
  3743. DMAE_CMD_ENDIANITY_DW_SWAP |
  3744. #endif
  3745. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  3746. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  3747. dmae->src_addr_lo = U64_LO(bnx2x_sp_mapping(bp, port_stats));
  3748. dmae->src_addr_hi = U64_HI(bnx2x_sp_mapping(bp, port_stats));
  3749. dmae->dst_addr_lo = bp->port.port_stx >> 2;
  3750. dmae->dst_addr_hi = 0;
  3751. dmae->len = sizeof(struct host_port_stats) >> 2;
  3752. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3753. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3754. dmae->comp_val = DMAE_COMP_VAL;
  3755. *stats_comp = 0;
  3756. bnx2x_hw_stats_post(bp);
  3757. bnx2x_stats_comp(bp);
  3758. }
  3759. static void bnx2x_func_stats_base_init(struct bnx2x *bp)
  3760. {
  3761. int vn, vn_max = IS_E1HMF(bp) ? E1HVN_MAX : E1VN_MAX;
  3762. int port = BP_PORT(bp);
  3763. int func;
  3764. u32 func_stx;
  3765. /* sanity */
  3766. if (!bp->port.pmf || !bp->func_stx) {
  3767. BNX2X_ERR("BUG!\n");
  3768. return;
  3769. }
  3770. /* save our func_stx */
  3771. func_stx = bp->func_stx;
  3772. for (vn = VN_0; vn < vn_max; vn++) {
  3773. func = 2*vn + port;
  3774. bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
  3775. bnx2x_func_stats_init(bp);
  3776. bnx2x_hw_stats_post(bp);
  3777. bnx2x_stats_comp(bp);
  3778. }
  3779. /* restore our func_stx */
  3780. bp->func_stx = func_stx;
  3781. }
  3782. static void bnx2x_func_stats_base_update(struct bnx2x *bp)
  3783. {
  3784. struct dmae_command *dmae = &bp->stats_dmae;
  3785. u32 *stats_comp = bnx2x_sp(bp, stats_comp);
  3786. /* sanity */
  3787. if (!bp->func_stx) {
  3788. BNX2X_ERR("BUG!\n");
  3789. return;
  3790. }
  3791. bp->executer_idx = 0;
  3792. memset(dmae, 0, sizeof(struct dmae_command));
  3793. dmae->opcode = (DMAE_CMD_SRC_GRC | DMAE_CMD_DST_PCI |
  3794. DMAE_CMD_C_DST_PCI | DMAE_CMD_C_ENABLE |
  3795. DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET |
  3796. #ifdef __BIG_ENDIAN
  3797. DMAE_CMD_ENDIANITY_B_DW_SWAP |
  3798. #else
  3799. DMAE_CMD_ENDIANITY_DW_SWAP |
  3800. #endif
  3801. (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0) |
  3802. (BP_E1HVN(bp) << DMAE_CMD_E1HVN_SHIFT));
  3803. dmae->src_addr_lo = bp->func_stx >> 2;
  3804. dmae->src_addr_hi = 0;
  3805. dmae->dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, func_stats_base));
  3806. dmae->dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, func_stats_base));
  3807. dmae->len = sizeof(struct host_func_stats) >> 2;
  3808. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, stats_comp));
  3809. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, stats_comp));
  3810. dmae->comp_val = DMAE_COMP_VAL;
  3811. *stats_comp = 0;
  3812. bnx2x_hw_stats_post(bp);
  3813. bnx2x_stats_comp(bp);
  3814. }
  3815. static void bnx2x_stats_init(struct bnx2x *bp)
  3816. {
  3817. int port = BP_PORT(bp);
  3818. int func = BP_FUNC(bp);
  3819. int i;
  3820. bp->stats_pending = 0;
  3821. bp->executer_idx = 0;
  3822. bp->stats_counter = 0;
  3823. /* port and func stats for management */
  3824. if (!BP_NOMCP(bp)) {
  3825. bp->port.port_stx = SHMEM_RD(bp, port_mb[port].port_stx);
  3826. bp->func_stx = SHMEM_RD(bp, func_mb[func].fw_mb_param);
  3827. } else {
  3828. bp->port.port_stx = 0;
  3829. bp->func_stx = 0;
  3830. }
  3831. DP(BNX2X_MSG_STATS, "port_stx 0x%x func_stx 0x%x\n",
  3832. bp->port.port_stx, bp->func_stx);
  3833. /* port stats */
  3834. memset(&(bp->port.old_nig_stats), 0, sizeof(struct nig_stats));
  3835. bp->port.old_nig_stats.brb_discard =
  3836. REG_RD(bp, NIG_REG_STAT0_BRB_DISCARD + port*0x38);
  3837. bp->port.old_nig_stats.brb_truncate =
  3838. REG_RD(bp, NIG_REG_STAT0_BRB_TRUNCATE + port*0x38);
  3839. REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT0 + port*0x50,
  3840. &(bp->port.old_nig_stats.egress_mac_pkt0_lo), 2);
  3841. REG_RD_DMAE(bp, NIG_REG_STAT0_EGRESS_MAC_PKT1 + port*0x50,
  3842. &(bp->port.old_nig_stats.egress_mac_pkt1_lo), 2);
  3843. /* function stats */
  3844. for_each_queue(bp, i) {
  3845. struct bnx2x_fastpath *fp = &bp->fp[i];
  3846. memset(&fp->old_tclient, 0,
  3847. sizeof(struct tstorm_per_client_stats));
  3848. memset(&fp->old_uclient, 0,
  3849. sizeof(struct ustorm_per_client_stats));
  3850. memset(&fp->old_xclient, 0,
  3851. sizeof(struct xstorm_per_client_stats));
  3852. memset(&fp->eth_q_stats, 0, sizeof(struct bnx2x_eth_q_stats));
  3853. }
  3854. memset(&bp->dev->stats, 0, sizeof(struct net_device_stats));
  3855. memset(&bp->eth_stats, 0, sizeof(struct bnx2x_eth_stats));
  3856. bp->stats_state = STATS_STATE_DISABLED;
  3857. if (bp->port.pmf) {
  3858. if (bp->port.port_stx)
  3859. bnx2x_port_stats_base_init(bp);
  3860. if (bp->func_stx)
  3861. bnx2x_func_stats_base_init(bp);
  3862. } else if (bp->func_stx)
  3863. bnx2x_func_stats_base_update(bp);
  3864. }
  3865. static void bnx2x_timer(unsigned long data)
  3866. {
  3867. struct bnx2x *bp = (struct bnx2x *) data;
  3868. if (!netif_running(bp->dev))
  3869. return;
  3870. if (atomic_read(&bp->intr_sem) != 0)
  3871. goto timer_restart;
  3872. if (poll) {
  3873. struct bnx2x_fastpath *fp = &bp->fp[0];
  3874. int rc;
  3875. bnx2x_tx_int(fp);
  3876. rc = bnx2x_rx_int(fp, 1000);
  3877. }
  3878. if (!BP_NOMCP(bp)) {
  3879. int func = BP_FUNC(bp);
  3880. u32 drv_pulse;
  3881. u32 mcp_pulse;
  3882. ++bp->fw_drv_pulse_wr_seq;
  3883. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  3884. /* TBD - add SYSTEM_TIME */
  3885. drv_pulse = bp->fw_drv_pulse_wr_seq;
  3886. SHMEM_WR(bp, func_mb[func].drv_pulse_mb, drv_pulse);
  3887. mcp_pulse = (SHMEM_RD(bp, func_mb[func].mcp_pulse_mb) &
  3888. MCP_PULSE_SEQ_MASK);
  3889. /* The delta between driver pulse and mcp response
  3890. * should be 1 (before mcp response) or 0 (after mcp response)
  3891. */
  3892. if ((drv_pulse != mcp_pulse) &&
  3893. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  3894. /* someone lost a heartbeat... */
  3895. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  3896. drv_pulse, mcp_pulse);
  3897. }
  3898. }
  3899. if (bp->state == BNX2X_STATE_OPEN)
  3900. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  3901. timer_restart:
  3902. mod_timer(&bp->timer, jiffies + bp->current_interval);
  3903. }
  3904. /* end of Statistics */
  3905. /* nic init */
  3906. /*
  3907. * nic init service functions
  3908. */
  3909. static void bnx2x_zero_sb(struct bnx2x *bp, int sb_id)
  3910. {
  3911. int port = BP_PORT(bp);
  3912. /* "CSTORM" */
  3913. bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
  3914. CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), 0,
  3915. CSTORM_SB_STATUS_BLOCK_U_SIZE / 4);
  3916. bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
  3917. CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), 0,
  3918. CSTORM_SB_STATUS_BLOCK_C_SIZE / 4);
  3919. }
  3920. static void bnx2x_init_sb(struct bnx2x *bp, struct host_status_block *sb,
  3921. dma_addr_t mapping, int sb_id)
  3922. {
  3923. int port = BP_PORT(bp);
  3924. int func = BP_FUNC(bp);
  3925. int index;
  3926. u64 section;
  3927. /* USTORM */
  3928. section = ((u64)mapping) + offsetof(struct host_status_block,
  3929. u_status_block);
  3930. sb->u_status_block.status_block_id = sb_id;
  3931. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3932. CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id), U64_LO(section));
  3933. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3934. ((CSTORM_SB_HOST_SB_ADDR_U_OFFSET(port, sb_id)) + 4),
  3935. U64_HI(section));
  3936. REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_USB_FUNC_OFF +
  3937. CSTORM_SB_HOST_STATUS_BLOCK_U_OFFSET(port, sb_id), func);
  3938. for (index = 0; index < HC_USTORM_SB_NUM_INDICES; index++)
  3939. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  3940. CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id, index), 1);
  3941. /* CSTORM */
  3942. section = ((u64)mapping) + offsetof(struct host_status_block,
  3943. c_status_block);
  3944. sb->c_status_block.status_block_id = sb_id;
  3945. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3946. CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id), U64_LO(section));
  3947. REG_WR(bp, BAR_CSTRORM_INTMEM +
  3948. ((CSTORM_SB_HOST_SB_ADDR_C_OFFSET(port, sb_id)) + 4),
  3949. U64_HI(section));
  3950. REG_WR8(bp, BAR_CSTRORM_INTMEM + FP_CSB_FUNC_OFF +
  3951. CSTORM_SB_HOST_STATUS_BLOCK_C_OFFSET(port, sb_id), func);
  3952. for (index = 0; index < HC_CSTORM_SB_NUM_INDICES; index++)
  3953. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  3954. CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id, index), 1);
  3955. bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  3956. }
  3957. static void bnx2x_zero_def_sb(struct bnx2x *bp)
  3958. {
  3959. int func = BP_FUNC(bp);
  3960. bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY +
  3961. TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
  3962. sizeof(struct tstorm_def_status_block)/4);
  3963. bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
  3964. CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), 0,
  3965. sizeof(struct cstorm_def_status_block_u)/4);
  3966. bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY +
  3967. CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), 0,
  3968. sizeof(struct cstorm_def_status_block_c)/4);
  3969. bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY +
  3970. XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), 0,
  3971. sizeof(struct xstorm_def_status_block)/4);
  3972. }
  3973. static void bnx2x_init_def_sb(struct bnx2x *bp,
  3974. struct host_def_status_block *def_sb,
  3975. dma_addr_t mapping, int sb_id)
  3976. {
  3977. int port = BP_PORT(bp);
  3978. int func = BP_FUNC(bp);
  3979. int index, val, reg_offset;
  3980. u64 section;
  3981. /* ATTN */
  3982. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  3983. atten_status_block);
  3984. def_sb->atten_status_block.status_block_id = sb_id;
  3985. bp->attn_state = 0;
  3986. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3987. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3988. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3989. bp->attn_group[index].sig[0] = REG_RD(bp,
  3990. reg_offset + 0x10*index);
  3991. bp->attn_group[index].sig[1] = REG_RD(bp,
  3992. reg_offset + 0x4 + 0x10*index);
  3993. bp->attn_group[index].sig[2] = REG_RD(bp,
  3994. reg_offset + 0x8 + 0x10*index);
  3995. bp->attn_group[index].sig[3] = REG_RD(bp,
  3996. reg_offset + 0xc + 0x10*index);
  3997. }
  3998. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  3999. HC_REG_ATTN_MSG0_ADDR_L);
  4000. REG_WR(bp, reg_offset, U64_LO(section));
  4001. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4002. reg_offset = (port ? HC_REG_ATTN_NUM_P1 : HC_REG_ATTN_NUM_P0);
  4003. val = REG_RD(bp, reg_offset);
  4004. val |= sb_id;
  4005. REG_WR(bp, reg_offset, val);
  4006. /* USTORM */
  4007. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  4008. u_def_status_block);
  4009. def_sb->u_def_status_block.status_block_id = sb_id;
  4010. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4011. CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func), U64_LO(section));
  4012. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4013. ((CSTORM_DEF_SB_HOST_SB_ADDR_U_OFFSET(func)) + 4),
  4014. U64_HI(section));
  4015. REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_USB_FUNC_OFF +
  4016. CSTORM_DEF_SB_HOST_STATUS_BLOCK_U_OFFSET(func), func);
  4017. for (index = 0; index < HC_USTORM_DEF_SB_NUM_INDICES; index++)
  4018. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  4019. CSTORM_DEF_SB_HC_DISABLE_U_OFFSET(func, index), 1);
  4020. /* CSTORM */
  4021. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  4022. c_def_status_block);
  4023. def_sb->c_def_status_block.status_block_id = sb_id;
  4024. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4025. CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func), U64_LO(section));
  4026. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4027. ((CSTORM_DEF_SB_HOST_SB_ADDR_C_OFFSET(func)) + 4),
  4028. U64_HI(section));
  4029. REG_WR8(bp, BAR_CSTRORM_INTMEM + DEF_CSB_FUNC_OFF +
  4030. CSTORM_DEF_SB_HOST_STATUS_BLOCK_C_OFFSET(func), func);
  4031. for (index = 0; index < HC_CSTORM_DEF_SB_NUM_INDICES; index++)
  4032. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  4033. CSTORM_DEF_SB_HC_DISABLE_C_OFFSET(func, index), 1);
  4034. /* TSTORM */
  4035. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  4036. t_def_status_block);
  4037. def_sb->t_def_status_block.status_block_id = sb_id;
  4038. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4039. TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
  4040. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4041. ((TSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
  4042. U64_HI(section));
  4043. REG_WR8(bp, BAR_TSTRORM_INTMEM + DEF_TSB_FUNC_OFF +
  4044. TSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
  4045. for (index = 0; index < HC_TSTORM_DEF_SB_NUM_INDICES; index++)
  4046. REG_WR16(bp, BAR_TSTRORM_INTMEM +
  4047. TSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
  4048. /* XSTORM */
  4049. section = ((u64)mapping) + offsetof(struct host_def_status_block,
  4050. x_def_status_block);
  4051. def_sb->x_def_status_block.status_block_id = sb_id;
  4052. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4053. XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func), U64_LO(section));
  4054. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4055. ((XSTORM_DEF_SB_HOST_SB_ADDR_OFFSET(func)) + 4),
  4056. U64_HI(section));
  4057. REG_WR8(bp, BAR_XSTRORM_INTMEM + DEF_XSB_FUNC_OFF +
  4058. XSTORM_DEF_SB_HOST_STATUS_BLOCK_OFFSET(func), func);
  4059. for (index = 0; index < HC_XSTORM_DEF_SB_NUM_INDICES; index++)
  4060. REG_WR16(bp, BAR_XSTRORM_INTMEM +
  4061. XSTORM_DEF_SB_HC_DISABLE_OFFSET(func, index), 1);
  4062. bp->stats_pending = 0;
  4063. bp->set_mac_pending = 0;
  4064. bnx2x_ack_sb(bp, sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  4065. }
  4066. static void bnx2x_update_coalesce(struct bnx2x *bp)
  4067. {
  4068. int port = BP_PORT(bp);
  4069. int i;
  4070. for_each_queue(bp, i) {
  4071. int sb_id = bp->fp[i].sb_id;
  4072. /* HC_INDEX_U_ETH_RX_CQ_CONS */
  4073. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  4074. CSTORM_SB_HC_TIMEOUT_U_OFFSET(port, sb_id,
  4075. U_SB_ETH_RX_CQ_INDEX),
  4076. bp->rx_ticks/(4 * BNX2X_BTR));
  4077. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  4078. CSTORM_SB_HC_DISABLE_U_OFFSET(port, sb_id,
  4079. U_SB_ETH_RX_CQ_INDEX),
  4080. (bp->rx_ticks/(4 * BNX2X_BTR)) ? 0 : 1);
  4081. /* HC_INDEX_C_ETH_TX_CQ_CONS */
  4082. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  4083. CSTORM_SB_HC_TIMEOUT_C_OFFSET(port, sb_id,
  4084. C_SB_ETH_TX_CQ_INDEX),
  4085. bp->tx_ticks/(4 * BNX2X_BTR));
  4086. REG_WR16(bp, BAR_CSTRORM_INTMEM +
  4087. CSTORM_SB_HC_DISABLE_C_OFFSET(port, sb_id,
  4088. C_SB_ETH_TX_CQ_INDEX),
  4089. (bp->tx_ticks/(4 * BNX2X_BTR)) ? 0 : 1);
  4090. }
  4091. }
  4092. static inline void bnx2x_free_tpa_pool(struct bnx2x *bp,
  4093. struct bnx2x_fastpath *fp, int last)
  4094. {
  4095. int i;
  4096. for (i = 0; i < last; i++) {
  4097. struct sw_rx_bd *rx_buf = &(fp->tpa_pool[i]);
  4098. struct sk_buff *skb = rx_buf->skb;
  4099. if (skb == NULL) {
  4100. DP(NETIF_MSG_IFDOWN, "tpa bin %d empty on free\n", i);
  4101. continue;
  4102. }
  4103. if (fp->tpa_state[i] == BNX2X_TPA_START)
  4104. pci_unmap_single(bp->pdev,
  4105. pci_unmap_addr(rx_buf, mapping),
  4106. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  4107. dev_kfree_skb(skb);
  4108. rx_buf->skb = NULL;
  4109. }
  4110. }
  4111. static void bnx2x_init_rx_rings(struct bnx2x *bp)
  4112. {
  4113. int func = BP_FUNC(bp);
  4114. int max_agg_queues = CHIP_IS_E1(bp) ? ETH_MAX_AGGREGATION_QUEUES_E1 :
  4115. ETH_MAX_AGGREGATION_QUEUES_E1H;
  4116. u16 ring_prod, cqe_ring_prod;
  4117. int i, j;
  4118. bp->rx_buf_size = bp->dev->mtu + ETH_OVREHEAD + BNX2X_RX_ALIGN;
  4119. DP(NETIF_MSG_IFUP,
  4120. "mtu %d rx_buf_size %d\n", bp->dev->mtu, bp->rx_buf_size);
  4121. if (bp->flags & TPA_ENABLE_FLAG) {
  4122. for_each_rx_queue(bp, j) {
  4123. struct bnx2x_fastpath *fp = &bp->fp[j];
  4124. for (i = 0; i < max_agg_queues; i++) {
  4125. fp->tpa_pool[i].skb =
  4126. netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  4127. if (!fp->tpa_pool[i].skb) {
  4128. BNX2X_ERR("Failed to allocate TPA "
  4129. "skb pool for queue[%d] - "
  4130. "disabling TPA on this "
  4131. "queue!\n", j);
  4132. bnx2x_free_tpa_pool(bp, fp, i);
  4133. fp->disable_tpa = 1;
  4134. break;
  4135. }
  4136. pci_unmap_addr_set((struct sw_rx_bd *)
  4137. &bp->fp->tpa_pool[i],
  4138. mapping, 0);
  4139. fp->tpa_state[i] = BNX2X_TPA_STOP;
  4140. }
  4141. }
  4142. }
  4143. for_each_rx_queue(bp, j) {
  4144. struct bnx2x_fastpath *fp = &bp->fp[j];
  4145. fp->rx_bd_cons = 0;
  4146. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4147. fp->rx_bd_cons_sb = BNX2X_RX_SB_BD_INDEX;
  4148. /* Mark queue as Rx */
  4149. fp->is_rx_queue = 1;
  4150. /* "next page" elements initialization */
  4151. /* SGE ring */
  4152. for (i = 1; i <= NUM_RX_SGE_PAGES; i++) {
  4153. struct eth_rx_sge *sge;
  4154. sge = &fp->rx_sge_ring[RX_SGE_CNT * i - 2];
  4155. sge->addr_hi =
  4156. cpu_to_le32(U64_HI(fp->rx_sge_mapping +
  4157. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  4158. sge->addr_lo =
  4159. cpu_to_le32(U64_LO(fp->rx_sge_mapping +
  4160. BCM_PAGE_SIZE*(i % NUM_RX_SGE_PAGES)));
  4161. }
  4162. bnx2x_init_sge_ring_bit_mask(fp);
  4163. /* RX BD ring */
  4164. for (i = 1; i <= NUM_RX_RINGS; i++) {
  4165. struct eth_rx_bd *rx_bd;
  4166. rx_bd = &fp->rx_desc_ring[RX_DESC_CNT * i - 2];
  4167. rx_bd->addr_hi =
  4168. cpu_to_le32(U64_HI(fp->rx_desc_mapping +
  4169. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  4170. rx_bd->addr_lo =
  4171. cpu_to_le32(U64_LO(fp->rx_desc_mapping +
  4172. BCM_PAGE_SIZE*(i % NUM_RX_RINGS)));
  4173. }
  4174. /* CQ ring */
  4175. for (i = 1; i <= NUM_RCQ_RINGS; i++) {
  4176. struct eth_rx_cqe_next_page *nextpg;
  4177. nextpg = (struct eth_rx_cqe_next_page *)
  4178. &fp->rx_comp_ring[RCQ_DESC_CNT * i - 1];
  4179. nextpg->addr_hi =
  4180. cpu_to_le32(U64_HI(fp->rx_comp_mapping +
  4181. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  4182. nextpg->addr_lo =
  4183. cpu_to_le32(U64_LO(fp->rx_comp_mapping +
  4184. BCM_PAGE_SIZE*(i % NUM_RCQ_RINGS)));
  4185. }
  4186. /* Allocate SGEs and initialize the ring elements */
  4187. for (i = 0, ring_prod = 0;
  4188. i < MAX_RX_SGE_CNT*NUM_RX_SGE_PAGES; i++) {
  4189. if (bnx2x_alloc_rx_sge(bp, fp, ring_prod) < 0) {
  4190. BNX2X_ERR("was only able to allocate "
  4191. "%d rx sges\n", i);
  4192. BNX2X_ERR("disabling TPA for queue[%d]\n", j);
  4193. /* Cleanup already allocated elements */
  4194. bnx2x_free_rx_sge_range(bp, fp, ring_prod);
  4195. bnx2x_free_tpa_pool(bp, fp, max_agg_queues);
  4196. fp->disable_tpa = 1;
  4197. ring_prod = 0;
  4198. break;
  4199. }
  4200. ring_prod = NEXT_SGE_IDX(ring_prod);
  4201. }
  4202. fp->rx_sge_prod = ring_prod;
  4203. /* Allocate BDs and initialize BD ring */
  4204. fp->rx_comp_cons = 0;
  4205. cqe_ring_prod = ring_prod = 0;
  4206. for (i = 0; i < bp->rx_ring_size; i++) {
  4207. if (bnx2x_alloc_rx_skb(bp, fp, ring_prod) < 0) {
  4208. BNX2X_ERR("was only able to allocate "
  4209. "%d rx skbs on queue[%d]\n", i, j);
  4210. fp->eth_q_stats.rx_skb_alloc_failed++;
  4211. break;
  4212. }
  4213. ring_prod = NEXT_RX_IDX(ring_prod);
  4214. cqe_ring_prod = NEXT_RCQ_IDX(cqe_ring_prod);
  4215. WARN_ON(ring_prod <= i);
  4216. }
  4217. fp->rx_bd_prod = ring_prod;
  4218. /* must not have more available CQEs than BDs */
  4219. fp->rx_comp_prod = min((u16)(NUM_RCQ_RINGS*RCQ_DESC_CNT),
  4220. cqe_ring_prod);
  4221. fp->rx_pkt = fp->rx_calls = 0;
  4222. /* Warning!
  4223. * this will generate an interrupt (to the TSTORM)
  4224. * must only be done after chip is initialized
  4225. */
  4226. bnx2x_update_rx_prod(bp, fp, ring_prod, fp->rx_comp_prod,
  4227. fp->rx_sge_prod);
  4228. if (j != 0)
  4229. continue;
  4230. REG_WR(bp, BAR_USTRORM_INTMEM +
  4231. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func),
  4232. U64_LO(fp->rx_comp_mapping));
  4233. REG_WR(bp, BAR_USTRORM_INTMEM +
  4234. USTORM_MEM_WORKAROUND_ADDRESS_OFFSET(func) + 4,
  4235. U64_HI(fp->rx_comp_mapping));
  4236. }
  4237. }
  4238. static void bnx2x_init_tx_ring(struct bnx2x *bp)
  4239. {
  4240. int i, j;
  4241. for_each_tx_queue(bp, j) {
  4242. struct bnx2x_fastpath *fp = &bp->fp[j];
  4243. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4244. struct eth_tx_next_bd *tx_next_bd =
  4245. &fp->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4246. tx_next_bd->addr_hi =
  4247. cpu_to_le32(U64_HI(fp->tx_desc_mapping +
  4248. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4249. tx_next_bd->addr_lo =
  4250. cpu_to_le32(U64_LO(fp->tx_desc_mapping +
  4251. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4252. }
  4253. fp->tx_db.data.header.header = DOORBELL_HDR_DB_TYPE;
  4254. fp->tx_db.data.zero_fill1 = 0;
  4255. fp->tx_db.data.prod = 0;
  4256. fp->tx_pkt_prod = 0;
  4257. fp->tx_pkt_cons = 0;
  4258. fp->tx_bd_prod = 0;
  4259. fp->tx_bd_cons = 0;
  4260. fp->tx_cons_sb = BNX2X_TX_SB_INDEX;
  4261. fp->tx_pkt = 0;
  4262. }
  4263. /* clean tx statistics */
  4264. for_each_rx_queue(bp, i)
  4265. bnx2x_fp(bp, i, tx_pkt) = 0;
  4266. }
  4267. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4268. {
  4269. int func = BP_FUNC(bp);
  4270. spin_lock_init(&bp->spq_lock);
  4271. bp->spq_left = MAX_SPQ_PENDING;
  4272. bp->spq_prod_idx = 0;
  4273. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4274. bp->spq_prod_bd = bp->spq;
  4275. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4276. REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func),
  4277. U64_LO(bp->spq_mapping));
  4278. REG_WR(bp,
  4279. XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PAGE_BASE_OFFSET(func) + 4,
  4280. U64_HI(bp->spq_mapping));
  4281. REG_WR(bp, XSEM_REG_FAST_MEMORY + XSTORM_SPQ_PROD_OFFSET(func),
  4282. bp->spq_prod_idx);
  4283. }
  4284. static void bnx2x_init_context(struct bnx2x *bp)
  4285. {
  4286. int i;
  4287. for_each_rx_queue(bp, i) {
  4288. struct eth_context *context = bnx2x_sp(bp, context[i].eth);
  4289. struct bnx2x_fastpath *fp = &bp->fp[i];
  4290. u8 cl_id = fp->cl_id;
  4291. context->ustorm_st_context.common.sb_index_numbers =
  4292. BNX2X_RX_SB_INDEX_NUM;
  4293. context->ustorm_st_context.common.clientId = cl_id;
  4294. context->ustorm_st_context.common.status_block_id = fp->sb_id;
  4295. context->ustorm_st_context.common.flags =
  4296. (USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_MC_ALIGNMENT |
  4297. USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_STATISTICS);
  4298. context->ustorm_st_context.common.statistics_counter_id =
  4299. cl_id;
  4300. context->ustorm_st_context.common.mc_alignment_log_size =
  4301. BNX2X_RX_ALIGN_SHIFT;
  4302. context->ustorm_st_context.common.bd_buff_size =
  4303. bp->rx_buf_size;
  4304. context->ustorm_st_context.common.bd_page_base_hi =
  4305. U64_HI(fp->rx_desc_mapping);
  4306. context->ustorm_st_context.common.bd_page_base_lo =
  4307. U64_LO(fp->rx_desc_mapping);
  4308. if (!fp->disable_tpa) {
  4309. context->ustorm_st_context.common.flags |=
  4310. USTORM_ETH_ST_CONTEXT_CONFIG_ENABLE_TPA;
  4311. context->ustorm_st_context.common.sge_buff_size =
  4312. (u16)min((u32)SGE_PAGE_SIZE*PAGES_PER_SGE,
  4313. (u32)0xffff);
  4314. context->ustorm_st_context.common.sge_page_base_hi =
  4315. U64_HI(fp->rx_sge_mapping);
  4316. context->ustorm_st_context.common.sge_page_base_lo =
  4317. U64_LO(fp->rx_sge_mapping);
  4318. context->ustorm_st_context.common.max_sges_for_packet =
  4319. SGE_PAGE_ALIGN(bp->dev->mtu) >> SGE_PAGE_SHIFT;
  4320. context->ustorm_st_context.common.max_sges_for_packet =
  4321. ((context->ustorm_st_context.common.
  4322. max_sges_for_packet + PAGES_PER_SGE - 1) &
  4323. (~(PAGES_PER_SGE - 1))) >> PAGES_PER_SGE_SHIFT;
  4324. }
  4325. context->ustorm_ag_context.cdu_usage =
  4326. CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
  4327. CDU_REGION_NUMBER_UCM_AG,
  4328. ETH_CONNECTION_TYPE);
  4329. context->xstorm_ag_context.cdu_reserved =
  4330. CDU_RSRVD_VALUE_TYPE_A(HW_CID(bp, i),
  4331. CDU_REGION_NUMBER_XCM_AG,
  4332. ETH_CONNECTION_TYPE);
  4333. }
  4334. for_each_tx_queue(bp, i) {
  4335. struct bnx2x_fastpath *fp = &bp->fp[i];
  4336. struct eth_context *context =
  4337. bnx2x_sp(bp, context[i - bp->num_rx_queues].eth);
  4338. context->cstorm_st_context.sb_index_number =
  4339. C_SB_ETH_TX_CQ_INDEX;
  4340. context->cstorm_st_context.status_block_id = fp->sb_id;
  4341. context->xstorm_st_context.tx_bd_page_base_hi =
  4342. U64_HI(fp->tx_desc_mapping);
  4343. context->xstorm_st_context.tx_bd_page_base_lo =
  4344. U64_LO(fp->tx_desc_mapping);
  4345. context->xstorm_st_context.statistics_data = (fp->cl_id |
  4346. XSTORM_ETH_ST_CONTEXT_STATISTICS_ENABLE);
  4347. }
  4348. }
  4349. static void bnx2x_init_ind_table(struct bnx2x *bp)
  4350. {
  4351. int func = BP_FUNC(bp);
  4352. int i;
  4353. if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
  4354. return;
  4355. DP(NETIF_MSG_IFUP,
  4356. "Initializing indirection table multi_mode %d\n", bp->multi_mode);
  4357. for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
  4358. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4359. TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
  4360. bp->fp->cl_id + (i % bp->num_rx_queues));
  4361. }
  4362. static void bnx2x_set_client_config(struct bnx2x *bp)
  4363. {
  4364. struct tstorm_eth_client_config tstorm_client = {0};
  4365. int port = BP_PORT(bp);
  4366. int i;
  4367. tstorm_client.mtu = bp->dev->mtu;
  4368. tstorm_client.config_flags =
  4369. (TSTORM_ETH_CLIENT_CONFIG_STATSITICS_ENABLE |
  4370. TSTORM_ETH_CLIENT_CONFIG_E1HOV_REM_ENABLE);
  4371. #ifdef BCM_VLAN
  4372. if (bp->rx_mode && bp->vlgrp && (bp->flags & HW_VLAN_RX_FLAG)) {
  4373. tstorm_client.config_flags |=
  4374. TSTORM_ETH_CLIENT_CONFIG_VLAN_REM_ENABLE;
  4375. DP(NETIF_MSG_IFUP, "vlan removal enabled\n");
  4376. }
  4377. #endif
  4378. for_each_queue(bp, i) {
  4379. tstorm_client.statistics_counter_id = bp->fp[i].cl_id;
  4380. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4381. TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id),
  4382. ((u32 *)&tstorm_client)[0]);
  4383. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4384. TSTORM_CLIENT_CONFIG_OFFSET(port, bp->fp[i].cl_id) + 4,
  4385. ((u32 *)&tstorm_client)[1]);
  4386. }
  4387. DP(BNX2X_MSG_OFF, "tstorm_client: 0x%08x 0x%08x\n",
  4388. ((u32 *)&tstorm_client)[0], ((u32 *)&tstorm_client)[1]);
  4389. }
  4390. static void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4391. {
  4392. struct tstorm_eth_mac_filter_config tstorm_mac_filter = {0};
  4393. int mode = bp->rx_mode;
  4394. int mask = bp->rx_mode_cl_mask;
  4395. int func = BP_FUNC(bp);
  4396. int port = BP_PORT(bp);
  4397. int i;
  4398. /* All but management unicast packets should pass to the host as well */
  4399. u32 llh_mask =
  4400. NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_BRCST |
  4401. NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_MLCST |
  4402. NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_VLAN |
  4403. NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_NO_VLAN;
  4404. DP(NETIF_MSG_IFUP, "rx mode %d mask 0x%x\n", mode, mask);
  4405. switch (mode) {
  4406. case BNX2X_RX_MODE_NONE: /* no Rx */
  4407. tstorm_mac_filter.ucast_drop_all = mask;
  4408. tstorm_mac_filter.mcast_drop_all = mask;
  4409. tstorm_mac_filter.bcast_drop_all = mask;
  4410. break;
  4411. case BNX2X_RX_MODE_NORMAL:
  4412. tstorm_mac_filter.bcast_accept_all = mask;
  4413. break;
  4414. case BNX2X_RX_MODE_ALLMULTI:
  4415. tstorm_mac_filter.mcast_accept_all = mask;
  4416. tstorm_mac_filter.bcast_accept_all = mask;
  4417. break;
  4418. case BNX2X_RX_MODE_PROMISC:
  4419. tstorm_mac_filter.ucast_accept_all = mask;
  4420. tstorm_mac_filter.mcast_accept_all = mask;
  4421. tstorm_mac_filter.bcast_accept_all = mask;
  4422. /* pass management unicast packets as well */
  4423. llh_mask |= NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_UNCST;
  4424. break;
  4425. default:
  4426. BNX2X_ERR("BAD rx mode (%d)\n", mode);
  4427. break;
  4428. }
  4429. REG_WR(bp,
  4430. (port ? NIG_REG_LLH1_BRB1_DRV_MASK : NIG_REG_LLH0_BRB1_DRV_MASK),
  4431. llh_mask);
  4432. for (i = 0; i < sizeof(struct tstorm_eth_mac_filter_config)/4; i++) {
  4433. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4434. TSTORM_MAC_FILTER_CONFIG_OFFSET(func) + i * 4,
  4435. ((u32 *)&tstorm_mac_filter)[i]);
  4436. /* DP(NETIF_MSG_IFUP, "tstorm_mac_filter[%d]: 0x%08x\n", i,
  4437. ((u32 *)&tstorm_mac_filter)[i]); */
  4438. }
  4439. if (mode != BNX2X_RX_MODE_NONE)
  4440. bnx2x_set_client_config(bp);
  4441. }
  4442. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4443. {
  4444. int i;
  4445. /* Zero this manually as its initialization is
  4446. currently missing in the initTool */
  4447. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4448. REG_WR(bp, BAR_USTRORM_INTMEM +
  4449. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4450. }
  4451. static void bnx2x_init_internal_port(struct bnx2x *bp)
  4452. {
  4453. int port = BP_PORT(bp);
  4454. REG_WR(bp,
  4455. BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_U_OFFSET(port), BNX2X_BTR);
  4456. REG_WR(bp,
  4457. BAR_CSTRORM_INTMEM + CSTORM_HC_BTR_C_OFFSET(port), BNX2X_BTR);
  4458. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
  4459. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_HC_BTR_OFFSET(port), BNX2X_BTR);
  4460. }
  4461. static void bnx2x_init_internal_func(struct bnx2x *bp)
  4462. {
  4463. struct tstorm_eth_function_common_config tstorm_config = {0};
  4464. struct stats_indication_flags stats_flags = {0};
  4465. int port = BP_PORT(bp);
  4466. int func = BP_FUNC(bp);
  4467. int i, j;
  4468. u32 offset;
  4469. u16 max_agg_size;
  4470. if (is_multi(bp)) {
  4471. tstorm_config.config_flags = MULTI_FLAGS(bp);
  4472. tstorm_config.rss_result_mask = MULTI_MASK;
  4473. }
  4474. /* Enable TPA if needed */
  4475. if (bp->flags & TPA_ENABLE_FLAG)
  4476. tstorm_config.config_flags |=
  4477. TSTORM_ETH_FUNCTION_COMMON_CONFIG_ENABLE_TPA;
  4478. if (IS_E1HMF(bp))
  4479. tstorm_config.config_flags |=
  4480. TSTORM_ETH_FUNCTION_COMMON_CONFIG_E1HOV_IN_CAM;
  4481. tstorm_config.leading_client_id = BP_L_ID(bp);
  4482. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4483. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(func),
  4484. (*(u32 *)&tstorm_config));
  4485. bp->rx_mode = BNX2X_RX_MODE_NONE; /* no rx until link is up */
  4486. bp->rx_mode_cl_mask = (1 << BP_L_ID(bp));
  4487. bnx2x_set_storm_rx_mode(bp);
  4488. for_each_queue(bp, i) {
  4489. u8 cl_id = bp->fp[i].cl_id;
  4490. /* reset xstorm per client statistics */
  4491. offset = BAR_XSTRORM_INTMEM +
  4492. XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
  4493. for (j = 0;
  4494. j < sizeof(struct xstorm_per_client_stats) / 4; j++)
  4495. REG_WR(bp, offset + j*4, 0);
  4496. /* reset tstorm per client statistics */
  4497. offset = BAR_TSTRORM_INTMEM +
  4498. TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
  4499. for (j = 0;
  4500. j < sizeof(struct tstorm_per_client_stats) / 4; j++)
  4501. REG_WR(bp, offset + j*4, 0);
  4502. /* reset ustorm per client statistics */
  4503. offset = BAR_USTRORM_INTMEM +
  4504. USTORM_PER_COUNTER_ID_STATS_OFFSET(port, cl_id);
  4505. for (j = 0;
  4506. j < sizeof(struct ustorm_per_client_stats) / 4; j++)
  4507. REG_WR(bp, offset + j*4, 0);
  4508. }
  4509. /* Init statistics related context */
  4510. stats_flags.collect_eth = 1;
  4511. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func),
  4512. ((u32 *)&stats_flags)[0]);
  4513. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(func) + 4,
  4514. ((u32 *)&stats_flags)[1]);
  4515. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func),
  4516. ((u32 *)&stats_flags)[0]);
  4517. REG_WR(bp, BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(func) + 4,
  4518. ((u32 *)&stats_flags)[1]);
  4519. REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func),
  4520. ((u32 *)&stats_flags)[0]);
  4521. REG_WR(bp, BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(func) + 4,
  4522. ((u32 *)&stats_flags)[1]);
  4523. REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func),
  4524. ((u32 *)&stats_flags)[0]);
  4525. REG_WR(bp, BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(func) + 4,
  4526. ((u32 *)&stats_flags)[1]);
  4527. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4528. XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
  4529. U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
  4530. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4531. XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
  4532. U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
  4533. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4534. TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
  4535. U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
  4536. REG_WR(bp, BAR_TSTRORM_INTMEM +
  4537. TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
  4538. U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
  4539. REG_WR(bp, BAR_USTRORM_INTMEM +
  4540. USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func),
  4541. U64_LO(bnx2x_sp_mapping(bp, fw_stats)));
  4542. REG_WR(bp, BAR_USTRORM_INTMEM +
  4543. USTORM_ETH_STATS_QUERY_ADDR_OFFSET(func) + 4,
  4544. U64_HI(bnx2x_sp_mapping(bp, fw_stats)));
  4545. if (CHIP_IS_E1H(bp)) {
  4546. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNCTION_MODE_OFFSET,
  4547. IS_E1HMF(bp));
  4548. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNCTION_MODE_OFFSET,
  4549. IS_E1HMF(bp));
  4550. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNCTION_MODE_OFFSET,
  4551. IS_E1HMF(bp));
  4552. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNCTION_MODE_OFFSET,
  4553. IS_E1HMF(bp));
  4554. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_E1HOV_OFFSET(func),
  4555. bp->e1hov);
  4556. }
  4557. /* Init CQ ring mapping and aggregation size, the FW limit is 8 frags */
  4558. max_agg_size =
  4559. min((u32)(min((u32)8, (u32)MAX_SKB_FRAGS) *
  4560. SGE_PAGE_SIZE * PAGES_PER_SGE),
  4561. (u32)0xffff);
  4562. for_each_rx_queue(bp, i) {
  4563. struct bnx2x_fastpath *fp = &bp->fp[i];
  4564. REG_WR(bp, BAR_USTRORM_INTMEM +
  4565. USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id),
  4566. U64_LO(fp->rx_comp_mapping));
  4567. REG_WR(bp, BAR_USTRORM_INTMEM +
  4568. USTORM_CQE_PAGE_BASE_OFFSET(port, fp->cl_id) + 4,
  4569. U64_HI(fp->rx_comp_mapping));
  4570. /* Next page */
  4571. REG_WR(bp, BAR_USTRORM_INTMEM +
  4572. USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id),
  4573. U64_LO(fp->rx_comp_mapping + BCM_PAGE_SIZE));
  4574. REG_WR(bp, BAR_USTRORM_INTMEM +
  4575. USTORM_CQE_PAGE_NEXT_OFFSET(port, fp->cl_id) + 4,
  4576. U64_HI(fp->rx_comp_mapping + BCM_PAGE_SIZE));
  4577. REG_WR16(bp, BAR_USTRORM_INTMEM +
  4578. USTORM_MAX_AGG_SIZE_OFFSET(port, fp->cl_id),
  4579. max_agg_size);
  4580. }
  4581. /* dropless flow control */
  4582. if (CHIP_IS_E1H(bp)) {
  4583. struct ustorm_eth_rx_pause_data_e1h rx_pause = {0};
  4584. rx_pause.bd_thr_low = 250;
  4585. rx_pause.cqe_thr_low = 250;
  4586. rx_pause.cos = 1;
  4587. rx_pause.sge_thr_low = 0;
  4588. rx_pause.bd_thr_high = 350;
  4589. rx_pause.cqe_thr_high = 350;
  4590. rx_pause.sge_thr_high = 0;
  4591. for_each_rx_queue(bp, i) {
  4592. struct bnx2x_fastpath *fp = &bp->fp[i];
  4593. if (!fp->disable_tpa) {
  4594. rx_pause.sge_thr_low = 150;
  4595. rx_pause.sge_thr_high = 250;
  4596. }
  4597. offset = BAR_USTRORM_INTMEM +
  4598. USTORM_ETH_RING_PAUSE_DATA_OFFSET(port,
  4599. fp->cl_id);
  4600. for (j = 0;
  4601. j < sizeof(struct ustorm_eth_rx_pause_data_e1h)/4;
  4602. j++)
  4603. REG_WR(bp, offset + j*4,
  4604. ((u32 *)&rx_pause)[j]);
  4605. }
  4606. }
  4607. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  4608. /* Init rate shaping and fairness contexts */
  4609. if (IS_E1HMF(bp)) {
  4610. int vn;
  4611. /* During init there is no active link
  4612. Until link is up, set link rate to 10Gbps */
  4613. bp->link_vars.line_speed = SPEED_10000;
  4614. bnx2x_init_port_minmax(bp);
  4615. if (!BP_NOMCP(bp))
  4616. bp->mf_config =
  4617. SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  4618. bnx2x_calc_vn_weight_sum(bp);
  4619. for (vn = VN_0; vn < E1HVN_MAX; vn++)
  4620. bnx2x_init_vn_minmax(bp, 2*vn + port);
  4621. /* Enable rate shaping and fairness */
  4622. bp->cmng.flags.cmng_enables |=
  4623. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  4624. } else {
  4625. /* rate shaping and fairness are disabled */
  4626. DP(NETIF_MSG_IFUP,
  4627. "single function mode minmax will be disabled\n");
  4628. }
  4629. /* Store it to internal memory */
  4630. if (bp->port.pmf)
  4631. for (i = 0; i < sizeof(struct cmng_struct_per_port) / 4; i++)
  4632. REG_WR(bp, BAR_XSTRORM_INTMEM +
  4633. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port) + i * 4,
  4634. ((u32 *)(&bp->cmng))[i]);
  4635. }
  4636. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4637. {
  4638. switch (load_code) {
  4639. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4640. bnx2x_init_internal_common(bp);
  4641. /* no break */
  4642. case FW_MSG_CODE_DRV_LOAD_PORT:
  4643. bnx2x_init_internal_port(bp);
  4644. /* no break */
  4645. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4646. bnx2x_init_internal_func(bp);
  4647. break;
  4648. default:
  4649. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4650. break;
  4651. }
  4652. }
  4653. static void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4654. {
  4655. int i;
  4656. for_each_queue(bp, i) {
  4657. struct bnx2x_fastpath *fp = &bp->fp[i];
  4658. fp->bp = bp;
  4659. fp->state = BNX2X_FP_STATE_CLOSED;
  4660. fp->index = i;
  4661. fp->cl_id = BP_L_ID(bp) + i;
  4662. #ifdef BCM_CNIC
  4663. fp->sb_id = fp->cl_id + 1;
  4664. #else
  4665. fp->sb_id = fp->cl_id;
  4666. #endif
  4667. /* Suitable Rx and Tx SBs are served by the same client */
  4668. if (i >= bp->num_rx_queues)
  4669. fp->cl_id -= bp->num_rx_queues;
  4670. DP(NETIF_MSG_IFUP,
  4671. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d sb %d\n",
  4672. i, bp, fp->status_blk, fp->cl_id, fp->sb_id);
  4673. bnx2x_init_sb(bp, fp->status_blk, fp->status_blk_mapping,
  4674. fp->sb_id);
  4675. bnx2x_update_fpsb_idx(fp);
  4676. }
  4677. /* ensure status block indices were read */
  4678. rmb();
  4679. bnx2x_init_def_sb(bp, bp->def_status_blk, bp->def_status_blk_mapping,
  4680. DEF_SB_ID);
  4681. bnx2x_update_dsb_idx(bp);
  4682. bnx2x_update_coalesce(bp);
  4683. bnx2x_init_rx_rings(bp);
  4684. bnx2x_init_tx_ring(bp);
  4685. bnx2x_init_sp_ring(bp);
  4686. bnx2x_init_context(bp);
  4687. bnx2x_init_internal(bp, load_code);
  4688. bnx2x_init_ind_table(bp);
  4689. bnx2x_stats_init(bp);
  4690. /* At this point, we are ready for interrupts */
  4691. atomic_set(&bp->intr_sem, 0);
  4692. /* flush all before enabling interrupts */
  4693. mb();
  4694. mmiowb();
  4695. bnx2x_int_enable(bp);
  4696. /* Check for SPIO5 */
  4697. bnx2x_attn_int_deasserted0(bp,
  4698. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4699. AEU_INPUTS_ATTN_BITS_SPIO5);
  4700. }
  4701. /* end of nic init */
  4702. /*
  4703. * gzip service functions
  4704. */
  4705. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4706. {
  4707. bp->gunzip_buf = pci_alloc_consistent(bp->pdev, FW_BUF_SIZE,
  4708. &bp->gunzip_mapping);
  4709. if (bp->gunzip_buf == NULL)
  4710. goto gunzip_nomem1;
  4711. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4712. if (bp->strm == NULL)
  4713. goto gunzip_nomem2;
  4714. bp->strm->workspace = kmalloc(zlib_inflate_workspacesize(),
  4715. GFP_KERNEL);
  4716. if (bp->strm->workspace == NULL)
  4717. goto gunzip_nomem3;
  4718. return 0;
  4719. gunzip_nomem3:
  4720. kfree(bp->strm);
  4721. bp->strm = NULL;
  4722. gunzip_nomem2:
  4723. pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
  4724. bp->gunzip_mapping);
  4725. bp->gunzip_buf = NULL;
  4726. gunzip_nomem1:
  4727. printk(KERN_ERR PFX "%s: Cannot allocate firmware buffer for"
  4728. " un-compression\n", bp->dev->name);
  4729. return -ENOMEM;
  4730. }
  4731. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4732. {
  4733. kfree(bp->strm->workspace);
  4734. kfree(bp->strm);
  4735. bp->strm = NULL;
  4736. if (bp->gunzip_buf) {
  4737. pci_free_consistent(bp->pdev, FW_BUF_SIZE, bp->gunzip_buf,
  4738. bp->gunzip_mapping);
  4739. bp->gunzip_buf = NULL;
  4740. }
  4741. }
  4742. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4743. {
  4744. int n, rc;
  4745. /* check gzip header */
  4746. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4747. BNX2X_ERR("Bad gzip header\n");
  4748. return -EINVAL;
  4749. }
  4750. n = 10;
  4751. #define FNAME 0x8
  4752. if (zbuf[3] & FNAME)
  4753. while ((zbuf[n++] != 0) && (n < len));
  4754. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4755. bp->strm->avail_in = len - n;
  4756. bp->strm->next_out = bp->gunzip_buf;
  4757. bp->strm->avail_out = FW_BUF_SIZE;
  4758. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4759. if (rc != Z_OK)
  4760. return rc;
  4761. rc = zlib_inflate(bp->strm, Z_FINISH);
  4762. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4763. printk(KERN_ERR PFX "%s: Firmware decompression error: %s\n",
  4764. bp->dev->name, bp->strm->msg);
  4765. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4766. if (bp->gunzip_outlen & 0x3)
  4767. printk(KERN_ERR PFX "%s: Firmware decompression error:"
  4768. " gunzip_outlen (%d) not aligned\n",
  4769. bp->dev->name, bp->gunzip_outlen);
  4770. bp->gunzip_outlen >>= 2;
  4771. zlib_inflateEnd(bp->strm);
  4772. if (rc == Z_STREAM_END)
  4773. return 0;
  4774. return rc;
  4775. }
  4776. /* nic load/unload */
  4777. /*
  4778. * General service functions
  4779. */
  4780. /* send a NIG loopback debug packet */
  4781. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4782. {
  4783. u32 wb_write[3];
  4784. /* Ethernet source and destination addresses */
  4785. wb_write[0] = 0x55555555;
  4786. wb_write[1] = 0x55555555;
  4787. wb_write[2] = 0x20; /* SOP */
  4788. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4789. /* NON-IP protocol */
  4790. wb_write[0] = 0x09000000;
  4791. wb_write[1] = 0x55555555;
  4792. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4793. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4794. }
  4795. /* some of the internal memories
  4796. * are not directly readable from the driver
  4797. * to test them we send debug packets
  4798. */
  4799. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4800. {
  4801. int factor;
  4802. int count, i;
  4803. u32 val = 0;
  4804. if (CHIP_REV_IS_FPGA(bp))
  4805. factor = 120;
  4806. else if (CHIP_REV_IS_EMUL(bp))
  4807. factor = 200;
  4808. else
  4809. factor = 1;
  4810. DP(NETIF_MSG_HW, "start part1\n");
  4811. /* Disable inputs of parser neighbor blocks */
  4812. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4813. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4814. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4815. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4816. /* Write 0 to parser credits for CFC search request */
  4817. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4818. /* send Ethernet packet */
  4819. bnx2x_lb_pckt(bp);
  4820. /* TODO do i reset NIG statistic? */
  4821. /* Wait until NIG register shows 1 packet of size 0x10 */
  4822. count = 1000 * factor;
  4823. while (count) {
  4824. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4825. val = *bnx2x_sp(bp, wb_data[0]);
  4826. if (val == 0x10)
  4827. break;
  4828. msleep(10);
  4829. count--;
  4830. }
  4831. if (val != 0x10) {
  4832. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4833. return -1;
  4834. }
  4835. /* Wait until PRS register shows 1 packet */
  4836. count = 1000 * factor;
  4837. while (count) {
  4838. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4839. if (val == 1)
  4840. break;
  4841. msleep(10);
  4842. count--;
  4843. }
  4844. if (val != 0x1) {
  4845. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4846. return -2;
  4847. }
  4848. /* Reset and init BRB, PRS */
  4849. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4850. msleep(50);
  4851. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4852. msleep(50);
  4853. bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
  4854. bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
  4855. DP(NETIF_MSG_HW, "part2\n");
  4856. /* Disable inputs of parser neighbor blocks */
  4857. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4858. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4859. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4860. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4861. /* Write 0 to parser credits for CFC search request */
  4862. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4863. /* send 10 Ethernet packets */
  4864. for (i = 0; i < 10; i++)
  4865. bnx2x_lb_pckt(bp);
  4866. /* Wait until NIG register shows 10 + 1
  4867. packets of size 11*0x10 = 0xb0 */
  4868. count = 1000 * factor;
  4869. while (count) {
  4870. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4871. val = *bnx2x_sp(bp, wb_data[0]);
  4872. if (val == 0xb0)
  4873. break;
  4874. msleep(10);
  4875. count--;
  4876. }
  4877. if (val != 0xb0) {
  4878. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4879. return -3;
  4880. }
  4881. /* Wait until PRS register shows 2 packets */
  4882. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4883. if (val != 2)
  4884. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4885. /* Write 1 to parser credits for CFC search request */
  4886. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4887. /* Wait until PRS register shows 3 packets */
  4888. msleep(10 * factor);
  4889. /* Wait until NIG register shows 1 packet of size 0x10 */
  4890. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4891. if (val != 3)
  4892. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4893. /* clear NIG EOP FIFO */
  4894. for (i = 0; i < 11; i++)
  4895. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4896. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4897. if (val != 1) {
  4898. BNX2X_ERR("clear of NIG failed\n");
  4899. return -4;
  4900. }
  4901. /* Reset and init BRB, PRS, NIG */
  4902. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4903. msleep(50);
  4904. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4905. msleep(50);
  4906. bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
  4907. bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
  4908. #ifndef BCM_CNIC
  4909. /* set NIC mode */
  4910. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4911. #endif
  4912. /* Enable inputs of parser neighbor blocks */
  4913. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4914. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4915. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4916. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4917. DP(NETIF_MSG_HW, "done\n");
  4918. return 0; /* OK */
  4919. }
  4920. static void enable_blocks_attention(struct bnx2x *bp)
  4921. {
  4922. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4923. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4924. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4925. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4926. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4927. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4928. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4929. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4930. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4931. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4932. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4933. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4934. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4935. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4936. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4937. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4938. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4939. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4940. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4941. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4942. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4943. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4944. if (CHIP_REV_IS_FPGA(bp))
  4945. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4946. else
  4947. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4948. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4949. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4950. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4951. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4952. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0); */
  4953. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4954. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4955. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4956. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0X18); /* bit 3,4 masked */
  4957. }
  4958. static void bnx2x_reset_common(struct bnx2x *bp)
  4959. {
  4960. /* reset_common */
  4961. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4962. 0xd3ffff7f);
  4963. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, 0x1403);
  4964. }
  4965. static void bnx2x_init_pxp(struct bnx2x *bp)
  4966. {
  4967. u16 devctl;
  4968. int r_order, w_order;
  4969. pci_read_config_word(bp->pdev,
  4970. bp->pcie_cap + PCI_EXP_DEVCTL, &devctl);
  4971. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  4972. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  4973. if (bp->mrrs == -1)
  4974. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  4975. else {
  4976. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  4977. r_order = bp->mrrs;
  4978. }
  4979. bnx2x_init_pxp_arb(bp, r_order, w_order);
  4980. }
  4981. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  4982. {
  4983. u32 val;
  4984. u8 port;
  4985. u8 is_required = 0;
  4986. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  4987. SHARED_HW_CFG_FAN_FAILURE_MASK;
  4988. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  4989. is_required = 1;
  4990. /*
  4991. * The fan failure mechanism is usually related to the PHY type since
  4992. * the power consumption of the board is affected by the PHY. Currently,
  4993. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  4994. */
  4995. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  4996. for (port = PORT_0; port < PORT_MAX; port++) {
  4997. u32 phy_type =
  4998. SHMEM_RD(bp, dev_info.port_hw_config[port].
  4999. external_phy_config) &
  5000. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  5001. is_required |=
  5002. ((phy_type ==
  5003. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) ||
  5004. (phy_type ==
  5005. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727) ||
  5006. (phy_type ==
  5007. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481));
  5008. }
  5009. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5010. if (is_required == 0)
  5011. return;
  5012. /* Fan failure is indicated by SPIO 5 */
  5013. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  5014. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  5015. /* set to active low mode */
  5016. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5017. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  5018. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  5019. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5020. /* enable interrupt to signal the IGU */
  5021. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5022. val |= (1 << MISC_REGISTERS_SPIO_5);
  5023. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5024. }
  5025. static int bnx2x_init_common(struct bnx2x *bp)
  5026. {
  5027. u32 val, i;
  5028. #ifdef BCM_CNIC
  5029. u32 wb_write[2];
  5030. #endif
  5031. DP(BNX2X_MSG_MCP, "starting common init func %d\n", BP_FUNC(bp));
  5032. bnx2x_reset_common(bp);
  5033. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5034. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, 0xfffc);
  5035. bnx2x_init_block(bp, MISC_BLOCK, COMMON_STAGE);
  5036. if (CHIP_IS_E1H(bp))
  5037. REG_WR(bp, MISC_REG_E1HMF_MODE, IS_E1HMF(bp));
  5038. REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x100);
  5039. msleep(30);
  5040. REG_WR(bp, MISC_REG_LCPLL_CTRL_REG_2, 0x0);
  5041. bnx2x_init_block(bp, PXP_BLOCK, COMMON_STAGE);
  5042. if (CHIP_IS_E1(bp)) {
  5043. /* enable HW interrupt from PXP on USDM overflow
  5044. bit 16 on INT_MASK_0 */
  5045. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5046. }
  5047. bnx2x_init_block(bp, PXP2_BLOCK, COMMON_STAGE);
  5048. bnx2x_init_pxp(bp);
  5049. #ifdef __BIG_ENDIAN
  5050. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5051. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5052. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5053. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5054. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5055. /* make sure this value is 0 */
  5056. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5057. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5058. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5059. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5060. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5061. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5062. #endif
  5063. REG_WR(bp, PXP2_REG_RQ_CDU_P_SIZE, 2);
  5064. #ifdef BCM_CNIC
  5065. REG_WR(bp, PXP2_REG_RQ_TM_P_SIZE, 5);
  5066. REG_WR(bp, PXP2_REG_RQ_QM_P_SIZE, 5);
  5067. REG_WR(bp, PXP2_REG_RQ_SRC_P_SIZE, 5);
  5068. #endif
  5069. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5070. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5071. /* let the HW do it's magic ... */
  5072. msleep(100);
  5073. /* finish PXP init */
  5074. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5075. if (val != 1) {
  5076. BNX2X_ERR("PXP2 CFG failed\n");
  5077. return -EBUSY;
  5078. }
  5079. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5080. if (val != 1) {
  5081. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5082. return -EBUSY;
  5083. }
  5084. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5085. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5086. bnx2x_init_block(bp, DMAE_BLOCK, COMMON_STAGE);
  5087. /* clean the DMAE memory */
  5088. bp->dmae_ready = 1;
  5089. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8);
  5090. bnx2x_init_block(bp, TCM_BLOCK, COMMON_STAGE);
  5091. bnx2x_init_block(bp, UCM_BLOCK, COMMON_STAGE);
  5092. bnx2x_init_block(bp, CCM_BLOCK, COMMON_STAGE);
  5093. bnx2x_init_block(bp, XCM_BLOCK, COMMON_STAGE);
  5094. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5095. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5096. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5097. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5098. bnx2x_init_block(bp, QM_BLOCK, COMMON_STAGE);
  5099. #ifdef BCM_CNIC
  5100. wb_write[0] = 0;
  5101. wb_write[1] = 0;
  5102. for (i = 0; i < 64; i++) {
  5103. REG_WR(bp, QM_REG_BASEADDR + i*4, 1024 * 4 * (i%16));
  5104. bnx2x_init_ind_wr(bp, QM_REG_PTRTBL + i*8, wb_write, 2);
  5105. if (CHIP_IS_E1H(bp)) {
  5106. REG_WR(bp, QM_REG_BASEADDR_EXT_A + i*4, 1024*4*(i%16));
  5107. bnx2x_init_ind_wr(bp, QM_REG_PTRTBL_EXT_A + i*8,
  5108. wb_write, 2);
  5109. }
  5110. }
  5111. #endif
  5112. /* soft reset pulse */
  5113. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5114. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5115. #ifdef BCM_CNIC
  5116. bnx2x_init_block(bp, TIMERS_BLOCK, COMMON_STAGE);
  5117. #endif
  5118. bnx2x_init_block(bp, DQ_BLOCK, COMMON_STAGE);
  5119. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BCM_PAGE_SHIFT);
  5120. if (!CHIP_REV_IS_SLOW(bp)) {
  5121. /* enable hw interrupt from doorbell Q */
  5122. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5123. }
  5124. bnx2x_init_block(bp, BRB1_BLOCK, COMMON_STAGE);
  5125. bnx2x_init_block(bp, PRS_BLOCK, COMMON_STAGE);
  5126. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5127. #ifndef BCM_CNIC
  5128. /* set NIC mode */
  5129. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5130. #endif
  5131. if (CHIP_IS_E1H(bp))
  5132. REG_WR(bp, PRS_REG_E1HOV_MODE, IS_E1HMF(bp));
  5133. bnx2x_init_block(bp, TSDM_BLOCK, COMMON_STAGE);
  5134. bnx2x_init_block(bp, CSDM_BLOCK, COMMON_STAGE);
  5135. bnx2x_init_block(bp, USDM_BLOCK, COMMON_STAGE);
  5136. bnx2x_init_block(bp, XSDM_BLOCK, COMMON_STAGE);
  5137. bnx2x_init_fill(bp, TSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
  5138. bnx2x_init_fill(bp, USEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
  5139. bnx2x_init_fill(bp, CSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
  5140. bnx2x_init_fill(bp, XSEM_REG_FAST_MEMORY, 0, STORM_INTMEM_SIZE(bp));
  5141. bnx2x_init_block(bp, TSEM_BLOCK, COMMON_STAGE);
  5142. bnx2x_init_block(bp, USEM_BLOCK, COMMON_STAGE);
  5143. bnx2x_init_block(bp, CSEM_BLOCK, COMMON_STAGE);
  5144. bnx2x_init_block(bp, XSEM_BLOCK, COMMON_STAGE);
  5145. /* sync semi rtc */
  5146. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5147. 0x80000000);
  5148. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5149. 0x80000000);
  5150. bnx2x_init_block(bp, UPB_BLOCK, COMMON_STAGE);
  5151. bnx2x_init_block(bp, XPB_BLOCK, COMMON_STAGE);
  5152. bnx2x_init_block(bp, PBF_BLOCK, COMMON_STAGE);
  5153. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5154. for (i = SRC_REG_KEYRSS0_0; i <= SRC_REG_KEYRSS1_9; i += 4) {
  5155. REG_WR(bp, i, 0xc0cac01a);
  5156. /* TODO: replace with something meaningful */
  5157. }
  5158. bnx2x_init_block(bp, SRCH_BLOCK, COMMON_STAGE);
  5159. #ifdef BCM_CNIC
  5160. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5161. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5162. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5163. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5164. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5165. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5166. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5167. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5168. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5169. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5170. #endif
  5171. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5172. if (sizeof(union cdu_context) != 1024)
  5173. /* we currently assume that a context is 1024 bytes */
  5174. printk(KERN_ALERT PFX "please adjust the size of"
  5175. " cdu_context(%ld)\n", (long)sizeof(union cdu_context));
  5176. bnx2x_init_block(bp, CDU_BLOCK, COMMON_STAGE);
  5177. val = (4 << 24) + (0 << 12) + 1024;
  5178. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5179. bnx2x_init_block(bp, CFC_BLOCK, COMMON_STAGE);
  5180. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5181. /* enable context validation interrupt from CFC */
  5182. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5183. /* set the thresholds to prevent CFC/CDU race */
  5184. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5185. bnx2x_init_block(bp, HC_BLOCK, COMMON_STAGE);
  5186. bnx2x_init_block(bp, MISC_AEU_BLOCK, COMMON_STAGE);
  5187. bnx2x_init_block(bp, PXPCS_BLOCK, COMMON_STAGE);
  5188. /* Reset PCIE errors for debug */
  5189. REG_WR(bp, 0x2814, 0xffffffff);
  5190. REG_WR(bp, 0x3820, 0xffffffff);
  5191. bnx2x_init_block(bp, EMAC0_BLOCK, COMMON_STAGE);
  5192. bnx2x_init_block(bp, EMAC1_BLOCK, COMMON_STAGE);
  5193. bnx2x_init_block(bp, DBU_BLOCK, COMMON_STAGE);
  5194. bnx2x_init_block(bp, DBG_BLOCK, COMMON_STAGE);
  5195. bnx2x_init_block(bp, NIG_BLOCK, COMMON_STAGE);
  5196. if (CHIP_IS_E1H(bp)) {
  5197. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_E1HMF(bp));
  5198. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_E1HMF(bp));
  5199. }
  5200. if (CHIP_REV_IS_SLOW(bp))
  5201. msleep(200);
  5202. /* finish CFC init */
  5203. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5204. if (val != 1) {
  5205. BNX2X_ERR("CFC LL_INIT failed\n");
  5206. return -EBUSY;
  5207. }
  5208. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5209. if (val != 1) {
  5210. BNX2X_ERR("CFC AC_INIT failed\n");
  5211. return -EBUSY;
  5212. }
  5213. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5214. if (val != 1) {
  5215. BNX2X_ERR("CFC CAM_INIT failed\n");
  5216. return -EBUSY;
  5217. }
  5218. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5219. /* read NIG statistic
  5220. to see if this is our first up since powerup */
  5221. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5222. val = *bnx2x_sp(bp, wb_data[0]);
  5223. /* do internal memory self test */
  5224. if ((CHIP_IS_E1(bp)) && (val == 0) && bnx2x_int_mem_test(bp)) {
  5225. BNX2X_ERR("internal mem self test failed\n");
  5226. return -EBUSY;
  5227. }
  5228. switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
  5229. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
  5230. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  5231. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  5232. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  5233. bp->port.need_hw_lock = 1;
  5234. break;
  5235. default:
  5236. break;
  5237. }
  5238. bnx2x_setup_fan_failure_detection(bp);
  5239. /* clear PXP2 attentions */
  5240. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5241. enable_blocks_attention(bp);
  5242. if (!BP_NOMCP(bp)) {
  5243. bnx2x_acquire_phy_lock(bp);
  5244. bnx2x_common_init_phy(bp, bp->common.shmem_base);
  5245. bnx2x_release_phy_lock(bp);
  5246. } else
  5247. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5248. return 0;
  5249. }
  5250. static int bnx2x_init_port(struct bnx2x *bp)
  5251. {
  5252. int port = BP_PORT(bp);
  5253. int init_stage = port ? PORT1_STAGE : PORT0_STAGE;
  5254. u32 low, high;
  5255. u32 val;
  5256. DP(BNX2X_MSG_MCP, "starting port init port %x\n", port);
  5257. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5258. bnx2x_init_block(bp, PXP_BLOCK, init_stage);
  5259. bnx2x_init_block(bp, PXP2_BLOCK, init_stage);
  5260. bnx2x_init_block(bp, TCM_BLOCK, init_stage);
  5261. bnx2x_init_block(bp, UCM_BLOCK, init_stage);
  5262. bnx2x_init_block(bp, CCM_BLOCK, init_stage);
  5263. bnx2x_init_block(bp, XCM_BLOCK, init_stage);
  5264. #ifdef BCM_CNIC
  5265. REG_WR(bp, QM_REG_CONNNUM_0 + port*4, 1024/16 - 1);
  5266. bnx2x_init_block(bp, TIMERS_BLOCK, init_stage);
  5267. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5268. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5269. #endif
  5270. bnx2x_init_block(bp, DQ_BLOCK, init_stage);
  5271. bnx2x_init_block(bp, BRB1_BLOCK, init_stage);
  5272. if (CHIP_REV_IS_SLOW(bp) && !CHIP_IS_E1H(bp)) {
  5273. /* no pause for emulation and FPGA */
  5274. low = 0;
  5275. high = 513;
  5276. } else {
  5277. if (IS_E1HMF(bp))
  5278. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5279. else if (bp->dev->mtu > 4096) {
  5280. if (bp->flags & ONE_PORT_FLAG)
  5281. low = 160;
  5282. else {
  5283. val = bp->dev->mtu;
  5284. /* (24*1024 + val*4)/256 */
  5285. low = 96 + (val/64) + ((val % 64) ? 1 : 0);
  5286. }
  5287. } else
  5288. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5289. high = low + 56; /* 14*1024/256 */
  5290. }
  5291. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5292. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5293. bnx2x_init_block(bp, PRS_BLOCK, init_stage);
  5294. bnx2x_init_block(bp, TSDM_BLOCK, init_stage);
  5295. bnx2x_init_block(bp, CSDM_BLOCK, init_stage);
  5296. bnx2x_init_block(bp, USDM_BLOCK, init_stage);
  5297. bnx2x_init_block(bp, XSDM_BLOCK, init_stage);
  5298. bnx2x_init_block(bp, TSEM_BLOCK, init_stage);
  5299. bnx2x_init_block(bp, USEM_BLOCK, init_stage);
  5300. bnx2x_init_block(bp, CSEM_BLOCK, init_stage);
  5301. bnx2x_init_block(bp, XSEM_BLOCK, init_stage);
  5302. bnx2x_init_block(bp, UPB_BLOCK, init_stage);
  5303. bnx2x_init_block(bp, XPB_BLOCK, init_stage);
  5304. bnx2x_init_block(bp, PBF_BLOCK, init_stage);
  5305. /* configure PBF to work without PAUSE mtu 9000 */
  5306. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5307. /* update threshold */
  5308. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5309. /* update init credit */
  5310. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5311. /* probe changes */
  5312. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5313. msleep(5);
  5314. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5315. #ifdef BCM_CNIC
  5316. bnx2x_init_block(bp, SRCH_BLOCK, init_stage);
  5317. #endif
  5318. bnx2x_init_block(bp, CDU_BLOCK, init_stage);
  5319. bnx2x_init_block(bp, CFC_BLOCK, init_stage);
  5320. if (CHIP_IS_E1(bp)) {
  5321. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5322. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5323. }
  5324. bnx2x_init_block(bp, HC_BLOCK, init_stage);
  5325. bnx2x_init_block(bp, MISC_AEU_BLOCK, init_stage);
  5326. /* init aeu_mask_attn_func_0/1:
  5327. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5328. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5329. * bits 4-7 are used for "per vn group attention" */
  5330. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4,
  5331. (IS_E1HMF(bp) ? 0xF7 : 0x7));
  5332. bnx2x_init_block(bp, PXPCS_BLOCK, init_stage);
  5333. bnx2x_init_block(bp, EMAC0_BLOCK, init_stage);
  5334. bnx2x_init_block(bp, EMAC1_BLOCK, init_stage);
  5335. bnx2x_init_block(bp, DBU_BLOCK, init_stage);
  5336. bnx2x_init_block(bp, DBG_BLOCK, init_stage);
  5337. bnx2x_init_block(bp, NIG_BLOCK, init_stage);
  5338. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5339. if (CHIP_IS_E1H(bp)) {
  5340. /* 0x2 disable e1hov, 0x1 enable */
  5341. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5342. (IS_E1HMF(bp) ? 0x1 : 0x2));
  5343. {
  5344. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5345. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5346. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5347. }
  5348. }
  5349. bnx2x_init_block(bp, MCP_BLOCK, init_stage);
  5350. bnx2x_init_block(bp, DMAE_BLOCK, init_stage);
  5351. switch (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config)) {
  5352. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  5353. {
  5354. u32 swap_val, swap_override, aeu_gpio_mask, offset;
  5355. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_3,
  5356. MISC_REGISTERS_GPIO_INPUT_HI_Z, port);
  5357. /* The GPIO should be swapped if the swap register is
  5358. set and active */
  5359. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  5360. swap_override = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  5361. /* Select function upon port-swap configuration */
  5362. if (port == 0) {
  5363. offset = MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0;
  5364. aeu_gpio_mask = (swap_val && swap_override) ?
  5365. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1 :
  5366. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0;
  5367. } else {
  5368. offset = MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0;
  5369. aeu_gpio_mask = (swap_val && swap_override) ?
  5370. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_0 :
  5371. AEU_INPUTS_ATTN_BITS_GPIO3_FUNCTION_1;
  5372. }
  5373. val = REG_RD(bp, offset);
  5374. /* add GPIO3 to group */
  5375. val |= aeu_gpio_mask;
  5376. REG_WR(bp, offset, val);
  5377. }
  5378. break;
  5379. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  5380. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  5381. /* add SPIO 5 to group 0 */
  5382. {
  5383. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5384. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5385. val = REG_RD(bp, reg_addr);
  5386. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5387. REG_WR(bp, reg_addr, val);
  5388. }
  5389. break;
  5390. default:
  5391. break;
  5392. }
  5393. bnx2x__link_reset(bp);
  5394. return 0;
  5395. }
  5396. #define ILT_PER_FUNC (768/2)
  5397. #define FUNC_ILT_BASE(func) (func * ILT_PER_FUNC)
  5398. /* the phys address is shifted right 12 bits and has an added
  5399. 1=valid bit added to the 53rd bit
  5400. then since this is a wide register(TM)
  5401. we split it into two 32 bit writes
  5402. */
  5403. #define ONCHIP_ADDR1(x) ((u32)(((u64)x >> 12) & 0xFFFFFFFF))
  5404. #define ONCHIP_ADDR2(x) ((u32)((1 << 20) | ((u64)x >> 44)))
  5405. #define PXP_ONE_ILT(x) (((x) << 10) | x)
  5406. #define PXP_ILT_RANGE(f, l) (((l) << 10) | f)
  5407. #ifdef BCM_CNIC
  5408. #define CNIC_ILT_LINES 127
  5409. #define CNIC_CTX_PER_ILT 16
  5410. #else
  5411. #define CNIC_ILT_LINES 0
  5412. #endif
  5413. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5414. {
  5415. int reg;
  5416. if (CHIP_IS_E1H(bp))
  5417. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5418. else /* E1 */
  5419. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5420. bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
  5421. }
  5422. static int bnx2x_init_func(struct bnx2x *bp)
  5423. {
  5424. int port = BP_PORT(bp);
  5425. int func = BP_FUNC(bp);
  5426. u32 addr, val;
  5427. int i;
  5428. DP(BNX2X_MSG_MCP, "starting func init func %x\n", func);
  5429. /* set MSI reconfigure capability */
  5430. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5431. val = REG_RD(bp, addr);
  5432. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5433. REG_WR(bp, addr, val);
  5434. i = FUNC_ILT_BASE(func);
  5435. bnx2x_ilt_wr(bp, i, bnx2x_sp_mapping(bp, context));
  5436. if (CHIP_IS_E1H(bp)) {
  5437. REG_WR(bp, PXP2_REG_RQ_CDU_FIRST_ILT, i);
  5438. REG_WR(bp, PXP2_REG_RQ_CDU_LAST_ILT, i + CNIC_ILT_LINES);
  5439. } else /* E1 */
  5440. REG_WR(bp, PXP2_REG_PSWRQ_CDU0_L2P + func*4,
  5441. PXP_ILT_RANGE(i, i + CNIC_ILT_LINES));
  5442. #ifdef BCM_CNIC
  5443. i += 1 + CNIC_ILT_LINES;
  5444. bnx2x_ilt_wr(bp, i, bp->timers_mapping);
  5445. if (CHIP_IS_E1(bp))
  5446. REG_WR(bp, PXP2_REG_PSWRQ_TM0_L2P + func*4, PXP_ONE_ILT(i));
  5447. else {
  5448. REG_WR(bp, PXP2_REG_RQ_TM_FIRST_ILT, i);
  5449. REG_WR(bp, PXP2_REG_RQ_TM_LAST_ILT, i);
  5450. }
  5451. i++;
  5452. bnx2x_ilt_wr(bp, i, bp->qm_mapping);
  5453. if (CHIP_IS_E1(bp))
  5454. REG_WR(bp, PXP2_REG_PSWRQ_QM0_L2P + func*4, PXP_ONE_ILT(i));
  5455. else {
  5456. REG_WR(bp, PXP2_REG_RQ_QM_FIRST_ILT, i);
  5457. REG_WR(bp, PXP2_REG_RQ_QM_LAST_ILT, i);
  5458. }
  5459. i++;
  5460. bnx2x_ilt_wr(bp, i, bp->t1_mapping);
  5461. if (CHIP_IS_E1(bp))
  5462. REG_WR(bp, PXP2_REG_PSWRQ_SRC0_L2P + func*4, PXP_ONE_ILT(i));
  5463. else {
  5464. REG_WR(bp, PXP2_REG_RQ_SRC_FIRST_ILT, i);
  5465. REG_WR(bp, PXP2_REG_RQ_SRC_LAST_ILT, i);
  5466. }
  5467. /* tell the searcher where the T2 table is */
  5468. REG_WR(bp, SRC_REG_COUNTFREE0 + port*4, 16*1024/64);
  5469. bnx2x_wb_wr(bp, SRC_REG_FIRSTFREE0 + port*16,
  5470. U64_LO(bp->t2_mapping), U64_HI(bp->t2_mapping));
  5471. bnx2x_wb_wr(bp, SRC_REG_LASTFREE0 + port*16,
  5472. U64_LO((u64)bp->t2_mapping + 16*1024 - 64),
  5473. U64_HI((u64)bp->t2_mapping + 16*1024 - 64));
  5474. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, 10);
  5475. #endif
  5476. if (CHIP_IS_E1H(bp)) {
  5477. bnx2x_init_block(bp, MISC_BLOCK, FUNC0_STAGE + func);
  5478. bnx2x_init_block(bp, TCM_BLOCK, FUNC0_STAGE + func);
  5479. bnx2x_init_block(bp, UCM_BLOCK, FUNC0_STAGE + func);
  5480. bnx2x_init_block(bp, CCM_BLOCK, FUNC0_STAGE + func);
  5481. bnx2x_init_block(bp, XCM_BLOCK, FUNC0_STAGE + func);
  5482. bnx2x_init_block(bp, TSEM_BLOCK, FUNC0_STAGE + func);
  5483. bnx2x_init_block(bp, USEM_BLOCK, FUNC0_STAGE + func);
  5484. bnx2x_init_block(bp, CSEM_BLOCK, FUNC0_STAGE + func);
  5485. bnx2x_init_block(bp, XSEM_BLOCK, FUNC0_STAGE + func);
  5486. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5487. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->e1hov);
  5488. }
  5489. /* HC init per function */
  5490. if (CHIP_IS_E1H(bp)) {
  5491. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5492. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5493. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5494. }
  5495. bnx2x_init_block(bp, HC_BLOCK, FUNC0_STAGE + func);
  5496. /* Reset PCIE errors for debug */
  5497. REG_WR(bp, 0x2114, 0xffffffff);
  5498. REG_WR(bp, 0x2120, 0xffffffff);
  5499. return 0;
  5500. }
  5501. static int bnx2x_init_hw(struct bnx2x *bp, u32 load_code)
  5502. {
  5503. int i, rc = 0;
  5504. DP(BNX2X_MSG_MCP, "function %d load_code %x\n",
  5505. BP_FUNC(bp), load_code);
  5506. bp->dmae_ready = 0;
  5507. mutex_init(&bp->dmae_mutex);
  5508. rc = bnx2x_gunzip_init(bp);
  5509. if (rc)
  5510. return rc;
  5511. switch (load_code) {
  5512. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5513. rc = bnx2x_init_common(bp);
  5514. if (rc)
  5515. goto init_hw_err;
  5516. /* no break */
  5517. case FW_MSG_CODE_DRV_LOAD_PORT:
  5518. bp->dmae_ready = 1;
  5519. rc = bnx2x_init_port(bp);
  5520. if (rc)
  5521. goto init_hw_err;
  5522. /* no break */
  5523. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5524. bp->dmae_ready = 1;
  5525. rc = bnx2x_init_func(bp);
  5526. if (rc)
  5527. goto init_hw_err;
  5528. break;
  5529. default:
  5530. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5531. break;
  5532. }
  5533. if (!BP_NOMCP(bp)) {
  5534. int func = BP_FUNC(bp);
  5535. bp->fw_drv_pulse_wr_seq =
  5536. (SHMEM_RD(bp, func_mb[func].drv_pulse_mb) &
  5537. DRV_PULSE_SEQ_MASK);
  5538. DP(BNX2X_MSG_MCP, "drv_pulse 0x%x\n", bp->fw_drv_pulse_wr_seq);
  5539. }
  5540. /* this needs to be done before gunzip end */
  5541. bnx2x_zero_def_sb(bp);
  5542. for_each_queue(bp, i)
  5543. bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
  5544. #ifdef BCM_CNIC
  5545. bnx2x_zero_sb(bp, BP_L_ID(bp) + i);
  5546. #endif
  5547. init_hw_err:
  5548. bnx2x_gunzip_end(bp);
  5549. return rc;
  5550. }
  5551. static void bnx2x_free_mem(struct bnx2x *bp)
  5552. {
  5553. #define BNX2X_PCI_FREE(x, y, size) \
  5554. do { \
  5555. if (x) { \
  5556. pci_free_consistent(bp->pdev, size, x, y); \
  5557. x = NULL; \
  5558. y = 0; \
  5559. } \
  5560. } while (0)
  5561. #define BNX2X_FREE(x) \
  5562. do { \
  5563. if (x) { \
  5564. vfree(x); \
  5565. x = NULL; \
  5566. } \
  5567. } while (0)
  5568. int i;
  5569. /* fastpath */
  5570. /* Common */
  5571. for_each_queue(bp, i) {
  5572. /* status blocks */
  5573. BNX2X_PCI_FREE(bnx2x_fp(bp, i, status_blk),
  5574. bnx2x_fp(bp, i, status_blk_mapping),
  5575. sizeof(struct host_status_block));
  5576. }
  5577. /* Rx */
  5578. for_each_rx_queue(bp, i) {
  5579. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  5580. BNX2X_FREE(bnx2x_fp(bp, i, rx_buf_ring));
  5581. BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_desc_ring),
  5582. bnx2x_fp(bp, i, rx_desc_mapping),
  5583. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  5584. BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_comp_ring),
  5585. bnx2x_fp(bp, i, rx_comp_mapping),
  5586. sizeof(struct eth_fast_path_rx_cqe) *
  5587. NUM_RCQ_BD);
  5588. /* SGE ring */
  5589. BNX2X_FREE(bnx2x_fp(bp, i, rx_page_ring));
  5590. BNX2X_PCI_FREE(bnx2x_fp(bp, i, rx_sge_ring),
  5591. bnx2x_fp(bp, i, rx_sge_mapping),
  5592. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  5593. }
  5594. /* Tx */
  5595. for_each_tx_queue(bp, i) {
  5596. /* fastpath tx rings: tx_buf tx_desc */
  5597. BNX2X_FREE(bnx2x_fp(bp, i, tx_buf_ring));
  5598. BNX2X_PCI_FREE(bnx2x_fp(bp, i, tx_desc_ring),
  5599. bnx2x_fp(bp, i, tx_desc_mapping),
  5600. sizeof(union eth_tx_bd_types) * NUM_TX_BD);
  5601. }
  5602. /* end of fastpath */
  5603. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5604. sizeof(struct host_def_status_block));
  5605. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5606. sizeof(struct bnx2x_slowpath));
  5607. #ifdef BCM_CNIC
  5608. BNX2X_PCI_FREE(bp->t1, bp->t1_mapping, 64*1024);
  5609. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, 16*1024);
  5610. BNX2X_PCI_FREE(bp->timers, bp->timers_mapping, 8*1024);
  5611. BNX2X_PCI_FREE(bp->qm, bp->qm_mapping, 128*1024);
  5612. BNX2X_PCI_FREE(bp->cnic_sb, bp->cnic_sb_mapping,
  5613. sizeof(struct host_status_block));
  5614. #endif
  5615. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5616. #undef BNX2X_PCI_FREE
  5617. #undef BNX2X_KFREE
  5618. }
  5619. static int bnx2x_alloc_mem(struct bnx2x *bp)
  5620. {
  5621. #define BNX2X_PCI_ALLOC(x, y, size) \
  5622. do { \
  5623. x = pci_alloc_consistent(bp->pdev, size, y); \
  5624. if (x == NULL) \
  5625. goto alloc_mem_err; \
  5626. memset(x, 0, size); \
  5627. } while (0)
  5628. #define BNX2X_ALLOC(x, size) \
  5629. do { \
  5630. x = vmalloc(size); \
  5631. if (x == NULL) \
  5632. goto alloc_mem_err; \
  5633. memset(x, 0, size); \
  5634. } while (0)
  5635. int i;
  5636. /* fastpath */
  5637. /* Common */
  5638. for_each_queue(bp, i) {
  5639. bnx2x_fp(bp, i, bp) = bp;
  5640. /* status blocks */
  5641. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, status_blk),
  5642. &bnx2x_fp(bp, i, status_blk_mapping),
  5643. sizeof(struct host_status_block));
  5644. }
  5645. /* Rx */
  5646. for_each_rx_queue(bp, i) {
  5647. /* fastpath rx rings: rx_buf rx_desc rx_comp */
  5648. BNX2X_ALLOC(bnx2x_fp(bp, i, rx_buf_ring),
  5649. sizeof(struct sw_rx_bd) * NUM_RX_BD);
  5650. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_desc_ring),
  5651. &bnx2x_fp(bp, i, rx_desc_mapping),
  5652. sizeof(struct eth_rx_bd) * NUM_RX_BD);
  5653. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_comp_ring),
  5654. &bnx2x_fp(bp, i, rx_comp_mapping),
  5655. sizeof(struct eth_fast_path_rx_cqe) *
  5656. NUM_RCQ_BD);
  5657. /* SGE ring */
  5658. BNX2X_ALLOC(bnx2x_fp(bp, i, rx_page_ring),
  5659. sizeof(struct sw_rx_page) * NUM_RX_SGE);
  5660. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, rx_sge_ring),
  5661. &bnx2x_fp(bp, i, rx_sge_mapping),
  5662. BCM_PAGE_SIZE * NUM_RX_SGE_PAGES);
  5663. }
  5664. /* Tx */
  5665. for_each_tx_queue(bp, i) {
  5666. /* fastpath tx rings: tx_buf tx_desc */
  5667. BNX2X_ALLOC(bnx2x_fp(bp, i, tx_buf_ring),
  5668. sizeof(struct sw_tx_bd) * NUM_TX_BD);
  5669. BNX2X_PCI_ALLOC(bnx2x_fp(bp, i, tx_desc_ring),
  5670. &bnx2x_fp(bp, i, tx_desc_mapping),
  5671. sizeof(union eth_tx_bd_types) * NUM_TX_BD);
  5672. }
  5673. /* end of fastpath */
  5674. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5675. sizeof(struct host_def_status_block));
  5676. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5677. sizeof(struct bnx2x_slowpath));
  5678. #ifdef BCM_CNIC
  5679. BNX2X_PCI_ALLOC(bp->t1, &bp->t1_mapping, 64*1024);
  5680. /* allocate searcher T2 table
  5681. we allocate 1/4 of alloc num for T2
  5682. (which is not entered into the ILT) */
  5683. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, 16*1024);
  5684. /* Initialize T2 (for 1024 connections) */
  5685. for (i = 0; i < 16*1024; i += 64)
  5686. *(u64 *)((char *)bp->t2 + i + 56) = bp->t2_mapping + i + 64;
  5687. /* Timer block array (8*MAX_CONN) phys uncached for now 1024 conns */
  5688. BNX2X_PCI_ALLOC(bp->timers, &bp->timers_mapping, 8*1024);
  5689. /* QM queues (128*MAX_CONN) */
  5690. BNX2X_PCI_ALLOC(bp->qm, &bp->qm_mapping, 128*1024);
  5691. BNX2X_PCI_ALLOC(bp->cnic_sb, &bp->cnic_sb_mapping,
  5692. sizeof(struct host_status_block));
  5693. #endif
  5694. /* Slow path ring */
  5695. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5696. return 0;
  5697. alloc_mem_err:
  5698. bnx2x_free_mem(bp);
  5699. return -ENOMEM;
  5700. #undef BNX2X_PCI_ALLOC
  5701. #undef BNX2X_ALLOC
  5702. }
  5703. static void bnx2x_free_tx_skbs(struct bnx2x *bp)
  5704. {
  5705. int i;
  5706. for_each_tx_queue(bp, i) {
  5707. struct bnx2x_fastpath *fp = &bp->fp[i];
  5708. u16 bd_cons = fp->tx_bd_cons;
  5709. u16 sw_prod = fp->tx_pkt_prod;
  5710. u16 sw_cons = fp->tx_pkt_cons;
  5711. while (sw_cons != sw_prod) {
  5712. bd_cons = bnx2x_free_tx_pkt(bp, fp, TX_BD(sw_cons));
  5713. sw_cons++;
  5714. }
  5715. }
  5716. }
  5717. static void bnx2x_free_rx_skbs(struct bnx2x *bp)
  5718. {
  5719. int i, j;
  5720. for_each_rx_queue(bp, j) {
  5721. struct bnx2x_fastpath *fp = &bp->fp[j];
  5722. for (i = 0; i < NUM_RX_BD; i++) {
  5723. struct sw_rx_bd *rx_buf = &fp->rx_buf_ring[i];
  5724. struct sk_buff *skb = rx_buf->skb;
  5725. if (skb == NULL)
  5726. continue;
  5727. pci_unmap_single(bp->pdev,
  5728. pci_unmap_addr(rx_buf, mapping),
  5729. bp->rx_buf_size, PCI_DMA_FROMDEVICE);
  5730. rx_buf->skb = NULL;
  5731. dev_kfree_skb(skb);
  5732. }
  5733. if (!fp->disable_tpa)
  5734. bnx2x_free_tpa_pool(bp, fp, CHIP_IS_E1(bp) ?
  5735. ETH_MAX_AGGREGATION_QUEUES_E1 :
  5736. ETH_MAX_AGGREGATION_QUEUES_E1H);
  5737. }
  5738. }
  5739. static void bnx2x_free_skbs(struct bnx2x *bp)
  5740. {
  5741. bnx2x_free_tx_skbs(bp);
  5742. bnx2x_free_rx_skbs(bp);
  5743. }
  5744. static void bnx2x_free_msix_irqs(struct bnx2x *bp)
  5745. {
  5746. int i, offset = 1;
  5747. free_irq(bp->msix_table[0].vector, bp->dev);
  5748. DP(NETIF_MSG_IFDOWN, "released sp irq (%d)\n",
  5749. bp->msix_table[0].vector);
  5750. #ifdef BCM_CNIC
  5751. offset++;
  5752. #endif
  5753. for_each_queue(bp, i) {
  5754. DP(NETIF_MSG_IFDOWN, "about to release fp #%d->%d irq "
  5755. "state %x\n", i, bp->msix_table[i + offset].vector,
  5756. bnx2x_fp(bp, i, state));
  5757. free_irq(bp->msix_table[i + offset].vector, &bp->fp[i]);
  5758. }
  5759. }
  5760. static void bnx2x_free_irq(struct bnx2x *bp)
  5761. {
  5762. if (bp->flags & USING_MSIX_FLAG) {
  5763. bnx2x_free_msix_irqs(bp);
  5764. pci_disable_msix(bp->pdev);
  5765. bp->flags &= ~USING_MSIX_FLAG;
  5766. } else if (bp->flags & USING_MSI_FLAG) {
  5767. free_irq(bp->pdev->irq, bp->dev);
  5768. pci_disable_msi(bp->pdev);
  5769. bp->flags &= ~USING_MSI_FLAG;
  5770. } else
  5771. free_irq(bp->pdev->irq, bp->dev);
  5772. }
  5773. static int bnx2x_enable_msix(struct bnx2x *bp)
  5774. {
  5775. int i, rc, offset = 1;
  5776. int igu_vec = 0;
  5777. bp->msix_table[0].entry = igu_vec;
  5778. DP(NETIF_MSG_IFUP, "msix_table[0].entry = %d (slowpath)\n", igu_vec);
  5779. #ifdef BCM_CNIC
  5780. igu_vec = BP_L_ID(bp) + offset;
  5781. bp->msix_table[1].entry = igu_vec;
  5782. DP(NETIF_MSG_IFUP, "msix_table[1].entry = %d (CNIC)\n", igu_vec);
  5783. offset++;
  5784. #endif
  5785. for_each_queue(bp, i) {
  5786. igu_vec = BP_L_ID(bp) + offset + i;
  5787. bp->msix_table[i + offset].entry = igu_vec;
  5788. DP(NETIF_MSG_IFUP, "msix_table[%d].entry = %d "
  5789. "(fastpath #%u)\n", i + offset, igu_vec, i);
  5790. }
  5791. rc = pci_enable_msix(bp->pdev, &bp->msix_table[0],
  5792. BNX2X_NUM_QUEUES(bp) + offset);
  5793. if (rc) {
  5794. DP(NETIF_MSG_IFUP, "MSI-X is not attainable rc %d\n", rc);
  5795. return rc;
  5796. }
  5797. bp->flags |= USING_MSIX_FLAG;
  5798. return 0;
  5799. }
  5800. static int bnx2x_req_msix_irqs(struct bnx2x *bp)
  5801. {
  5802. int i, rc, offset = 1;
  5803. rc = request_irq(bp->msix_table[0].vector, bnx2x_msix_sp_int, 0,
  5804. bp->dev->name, bp->dev);
  5805. if (rc) {
  5806. BNX2X_ERR("request sp irq failed\n");
  5807. return -EBUSY;
  5808. }
  5809. #ifdef BCM_CNIC
  5810. offset++;
  5811. #endif
  5812. for_each_queue(bp, i) {
  5813. struct bnx2x_fastpath *fp = &bp->fp[i];
  5814. if (i < bp->num_rx_queues)
  5815. sprintf(fp->name, "%s-rx-%d", bp->dev->name, i);
  5816. else
  5817. sprintf(fp->name, "%s-tx-%d",
  5818. bp->dev->name, i - bp->num_rx_queues);
  5819. rc = request_irq(bp->msix_table[i + offset].vector,
  5820. bnx2x_msix_fp_int, 0, fp->name, fp);
  5821. if (rc) {
  5822. BNX2X_ERR("request fp #%d irq failed rc %d\n", i, rc);
  5823. bnx2x_free_msix_irqs(bp);
  5824. return -EBUSY;
  5825. }
  5826. fp->state = BNX2X_FP_STATE_IRQ;
  5827. }
  5828. i = BNX2X_NUM_QUEUES(bp);
  5829. printk(KERN_INFO PFX "%s: using MSI-X IRQs: sp %d fp[%d] %d"
  5830. " ... fp[%d] %d\n",
  5831. bp->dev->name, bp->msix_table[0].vector,
  5832. 0, bp->msix_table[offset].vector,
  5833. i - 1, bp->msix_table[offset + i - 1].vector);
  5834. return 0;
  5835. }
  5836. static int bnx2x_enable_msi(struct bnx2x *bp)
  5837. {
  5838. int rc;
  5839. rc = pci_enable_msi(bp->pdev);
  5840. if (rc) {
  5841. DP(NETIF_MSG_IFUP, "MSI is not attainable\n");
  5842. return -1;
  5843. }
  5844. bp->flags |= USING_MSI_FLAG;
  5845. return 0;
  5846. }
  5847. static int bnx2x_req_irq(struct bnx2x *bp)
  5848. {
  5849. unsigned long flags;
  5850. int rc;
  5851. if (bp->flags & USING_MSI_FLAG)
  5852. flags = 0;
  5853. else
  5854. flags = IRQF_SHARED;
  5855. rc = request_irq(bp->pdev->irq, bnx2x_interrupt, flags,
  5856. bp->dev->name, bp->dev);
  5857. if (!rc)
  5858. bnx2x_fp(bp, 0, state) = BNX2X_FP_STATE_IRQ;
  5859. return rc;
  5860. }
  5861. static void bnx2x_napi_enable(struct bnx2x *bp)
  5862. {
  5863. int i;
  5864. for_each_rx_queue(bp, i)
  5865. napi_enable(&bnx2x_fp(bp, i, napi));
  5866. }
  5867. static void bnx2x_napi_disable(struct bnx2x *bp)
  5868. {
  5869. int i;
  5870. for_each_rx_queue(bp, i)
  5871. napi_disable(&bnx2x_fp(bp, i, napi));
  5872. }
  5873. static void bnx2x_netif_start(struct bnx2x *bp)
  5874. {
  5875. int intr_sem;
  5876. intr_sem = atomic_dec_and_test(&bp->intr_sem);
  5877. smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
  5878. if (intr_sem) {
  5879. if (netif_running(bp->dev)) {
  5880. bnx2x_napi_enable(bp);
  5881. bnx2x_int_enable(bp);
  5882. if (bp->state == BNX2X_STATE_OPEN)
  5883. netif_tx_wake_all_queues(bp->dev);
  5884. }
  5885. }
  5886. }
  5887. static void bnx2x_netif_stop(struct bnx2x *bp, int disable_hw)
  5888. {
  5889. bnx2x_int_disable_sync(bp, disable_hw);
  5890. bnx2x_napi_disable(bp);
  5891. netif_tx_disable(bp->dev);
  5892. bp->dev->trans_start = jiffies; /* prevent tx timeout */
  5893. }
  5894. /*
  5895. * Init service functions
  5896. */
  5897. /**
  5898. * Sets a MAC in a CAM for a few L2 Clients for E1 chip
  5899. *
  5900. * @param bp driver descriptor
  5901. * @param set set or clear an entry (1 or 0)
  5902. * @param mac pointer to a buffer containing a MAC
  5903. * @param cl_bit_vec bit vector of clients to register a MAC for
  5904. * @param cam_offset offset in a CAM to use
  5905. * @param with_bcast set broadcast MAC as well
  5906. */
  5907. static void bnx2x_set_mac_addr_e1_gen(struct bnx2x *bp, int set, u8 *mac,
  5908. u32 cl_bit_vec, u8 cam_offset,
  5909. u8 with_bcast)
  5910. {
  5911. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  5912. int port = BP_PORT(bp);
  5913. /* CAM allocation
  5914. * unicasts 0-31:port0 32-63:port1
  5915. * multicast 64-127:port0 128-191:port1
  5916. */
  5917. config->hdr.length = 1 + (with_bcast ? 1 : 0);
  5918. config->hdr.offset = cam_offset;
  5919. config->hdr.client_id = 0xff;
  5920. config->hdr.reserved1 = 0;
  5921. /* primary MAC */
  5922. config->config_table[0].cam_entry.msb_mac_addr =
  5923. swab16(*(u16 *)&mac[0]);
  5924. config->config_table[0].cam_entry.middle_mac_addr =
  5925. swab16(*(u16 *)&mac[2]);
  5926. config->config_table[0].cam_entry.lsb_mac_addr =
  5927. swab16(*(u16 *)&mac[4]);
  5928. config->config_table[0].cam_entry.flags = cpu_to_le16(port);
  5929. if (set)
  5930. config->config_table[0].target_table_entry.flags = 0;
  5931. else
  5932. CAM_INVALIDATE(config->config_table[0]);
  5933. config->config_table[0].target_table_entry.clients_bit_vector =
  5934. cpu_to_le32(cl_bit_vec);
  5935. config->config_table[0].target_table_entry.vlan_id = 0;
  5936. DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x)\n",
  5937. (set ? "setting" : "clearing"),
  5938. config->config_table[0].cam_entry.msb_mac_addr,
  5939. config->config_table[0].cam_entry.middle_mac_addr,
  5940. config->config_table[0].cam_entry.lsb_mac_addr);
  5941. /* broadcast */
  5942. if (with_bcast) {
  5943. config->config_table[1].cam_entry.msb_mac_addr =
  5944. cpu_to_le16(0xffff);
  5945. config->config_table[1].cam_entry.middle_mac_addr =
  5946. cpu_to_le16(0xffff);
  5947. config->config_table[1].cam_entry.lsb_mac_addr =
  5948. cpu_to_le16(0xffff);
  5949. config->config_table[1].cam_entry.flags = cpu_to_le16(port);
  5950. if (set)
  5951. config->config_table[1].target_table_entry.flags =
  5952. TSTORM_CAM_TARGET_TABLE_ENTRY_BROADCAST;
  5953. else
  5954. CAM_INVALIDATE(config->config_table[1]);
  5955. config->config_table[1].target_table_entry.clients_bit_vector =
  5956. cpu_to_le32(cl_bit_vec);
  5957. config->config_table[1].target_table_entry.vlan_id = 0;
  5958. }
  5959. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  5960. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  5961. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  5962. }
  5963. /**
  5964. * Sets a MAC in a CAM for a few L2 Clients for E1H chip
  5965. *
  5966. * @param bp driver descriptor
  5967. * @param set set or clear an entry (1 or 0)
  5968. * @param mac pointer to a buffer containing a MAC
  5969. * @param cl_bit_vec bit vector of clients to register a MAC for
  5970. * @param cam_offset offset in a CAM to use
  5971. */
  5972. static void bnx2x_set_mac_addr_e1h_gen(struct bnx2x *bp, int set, u8 *mac,
  5973. u32 cl_bit_vec, u8 cam_offset)
  5974. {
  5975. struct mac_configuration_cmd_e1h *config =
  5976. (struct mac_configuration_cmd_e1h *)bnx2x_sp(bp, mac_config);
  5977. config->hdr.length = 1;
  5978. config->hdr.offset = cam_offset;
  5979. config->hdr.client_id = 0xff;
  5980. config->hdr.reserved1 = 0;
  5981. /* primary MAC */
  5982. config->config_table[0].msb_mac_addr =
  5983. swab16(*(u16 *)&mac[0]);
  5984. config->config_table[0].middle_mac_addr =
  5985. swab16(*(u16 *)&mac[2]);
  5986. config->config_table[0].lsb_mac_addr =
  5987. swab16(*(u16 *)&mac[4]);
  5988. config->config_table[0].clients_bit_vector =
  5989. cpu_to_le32(cl_bit_vec);
  5990. config->config_table[0].vlan_id = 0;
  5991. config->config_table[0].e1hov_id = cpu_to_le16(bp->e1hov);
  5992. if (set)
  5993. config->config_table[0].flags = BP_PORT(bp);
  5994. else
  5995. config->config_table[0].flags =
  5996. MAC_CONFIGURATION_ENTRY_E1H_ACTION_TYPE;
  5997. DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) E1HOV %d CLID mask %d\n",
  5998. (set ? "setting" : "clearing"),
  5999. config->config_table[0].msb_mac_addr,
  6000. config->config_table[0].middle_mac_addr,
  6001. config->config_table[0].lsb_mac_addr, bp->e1hov, cl_bit_vec);
  6002. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  6003. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  6004. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  6005. }
  6006. static int bnx2x_wait_ramrod(struct bnx2x *bp, int state, int idx,
  6007. int *state_p, int poll)
  6008. {
  6009. /* can take a while if any port is running */
  6010. int cnt = 5000;
  6011. DP(NETIF_MSG_IFUP, "%s for state to become %x on IDX [%d]\n",
  6012. poll ? "polling" : "waiting", state, idx);
  6013. might_sleep();
  6014. while (cnt--) {
  6015. if (poll) {
  6016. bnx2x_rx_int(bp->fp, 10);
  6017. /* if index is different from 0
  6018. * the reply for some commands will
  6019. * be on the non default queue
  6020. */
  6021. if (idx)
  6022. bnx2x_rx_int(&bp->fp[idx], 10);
  6023. }
  6024. mb(); /* state is changed by bnx2x_sp_event() */
  6025. if (*state_p == state) {
  6026. #ifdef BNX2X_STOP_ON_ERROR
  6027. DP(NETIF_MSG_IFUP, "exit (cnt %d)\n", 5000 - cnt);
  6028. #endif
  6029. return 0;
  6030. }
  6031. msleep(1);
  6032. if (bp->panic)
  6033. return -EIO;
  6034. }
  6035. /* timeout! */
  6036. BNX2X_ERR("timeout %s for state %x on IDX [%d]\n",
  6037. poll ? "polling" : "waiting", state, idx);
  6038. #ifdef BNX2X_STOP_ON_ERROR
  6039. bnx2x_panic();
  6040. #endif
  6041. return -EBUSY;
  6042. }
  6043. static void bnx2x_set_eth_mac_addr_e1h(struct bnx2x *bp, int set)
  6044. {
  6045. bp->set_mac_pending++;
  6046. smp_wmb();
  6047. bnx2x_set_mac_addr_e1h_gen(bp, set, bp->dev->dev_addr,
  6048. (1 << bp->fp->cl_id), BP_FUNC(bp));
  6049. /* Wait for a completion */
  6050. bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
  6051. }
  6052. static void bnx2x_set_eth_mac_addr_e1(struct bnx2x *bp, int set)
  6053. {
  6054. bp->set_mac_pending++;
  6055. smp_wmb();
  6056. bnx2x_set_mac_addr_e1_gen(bp, set, bp->dev->dev_addr,
  6057. (1 << bp->fp->cl_id), (BP_PORT(bp) ? 32 : 0),
  6058. 1);
  6059. /* Wait for a completion */
  6060. bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
  6061. }
  6062. #ifdef BCM_CNIC
  6063. /**
  6064. * Set iSCSI MAC(s) at the next enties in the CAM after the ETH
  6065. * MAC(s). This function will wait until the ramdord completion
  6066. * returns.
  6067. *
  6068. * @param bp driver handle
  6069. * @param set set or clear the CAM entry
  6070. *
  6071. * @return 0 if cussess, -ENODEV if ramrod doesn't return.
  6072. */
  6073. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp, int set)
  6074. {
  6075. u32 cl_bit_vec = (1 << BCM_ISCSI_ETH_CL_ID);
  6076. bp->set_mac_pending++;
  6077. smp_wmb();
  6078. /* Send a SET_MAC ramrod */
  6079. if (CHIP_IS_E1(bp))
  6080. bnx2x_set_mac_addr_e1_gen(bp, set, bp->iscsi_mac,
  6081. cl_bit_vec, (BP_PORT(bp) ? 32 : 0) + 2,
  6082. 1);
  6083. else
  6084. /* CAM allocation for E1H
  6085. * unicasts: by func number
  6086. * multicast: 20+FUNC*20, 20 each
  6087. */
  6088. bnx2x_set_mac_addr_e1h_gen(bp, set, bp->iscsi_mac,
  6089. cl_bit_vec, E1H_FUNC_MAX + BP_FUNC(bp));
  6090. /* Wait for a completion when setting */
  6091. bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, set ? 0 : 1);
  6092. return 0;
  6093. }
  6094. #endif
  6095. static int bnx2x_setup_leading(struct bnx2x *bp)
  6096. {
  6097. int rc;
  6098. /* reset IGU state */
  6099. bnx2x_ack_sb(bp, bp->fp[0].sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  6100. /* SETUP ramrod */
  6101. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_SETUP, 0, 0, 0, 0);
  6102. /* Wait for completion */
  6103. rc = bnx2x_wait_ramrod(bp, BNX2X_STATE_OPEN, 0, &(bp->state), 0);
  6104. return rc;
  6105. }
  6106. static int bnx2x_setup_multi(struct bnx2x *bp, int index)
  6107. {
  6108. struct bnx2x_fastpath *fp = &bp->fp[index];
  6109. /* reset IGU state */
  6110. bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID, 0, IGU_INT_ENABLE, 0);
  6111. /* SETUP ramrod */
  6112. fp->state = BNX2X_FP_STATE_OPENING;
  6113. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_SETUP, index, 0,
  6114. fp->cl_id, 0);
  6115. /* Wait for completion */
  6116. return bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_OPEN, index,
  6117. &(fp->state), 0);
  6118. }
  6119. static int bnx2x_poll(struct napi_struct *napi, int budget);
  6120. static void bnx2x_set_int_mode_msix(struct bnx2x *bp, int *num_rx_queues_out,
  6121. int *num_tx_queues_out)
  6122. {
  6123. int _num_rx_queues = 0, _num_tx_queues = 0;
  6124. switch (bp->multi_mode) {
  6125. case ETH_RSS_MODE_DISABLED:
  6126. _num_rx_queues = 1;
  6127. _num_tx_queues = 1;
  6128. break;
  6129. case ETH_RSS_MODE_REGULAR:
  6130. if (num_rx_queues)
  6131. _num_rx_queues = min_t(u32, num_rx_queues,
  6132. BNX2X_MAX_QUEUES(bp));
  6133. else
  6134. _num_rx_queues = min_t(u32, num_online_cpus(),
  6135. BNX2X_MAX_QUEUES(bp));
  6136. if (num_tx_queues)
  6137. _num_tx_queues = min_t(u32, num_tx_queues,
  6138. BNX2X_MAX_QUEUES(bp));
  6139. else
  6140. _num_tx_queues = min_t(u32, num_online_cpus(),
  6141. BNX2X_MAX_QUEUES(bp));
  6142. /* There must be not more Tx queues than Rx queues */
  6143. if (_num_tx_queues > _num_rx_queues) {
  6144. BNX2X_ERR("number of tx queues (%d) > "
  6145. "number of rx queues (%d)"
  6146. " defaulting to %d\n",
  6147. _num_tx_queues, _num_rx_queues,
  6148. _num_rx_queues);
  6149. _num_tx_queues = _num_rx_queues;
  6150. }
  6151. break;
  6152. default:
  6153. _num_rx_queues = 1;
  6154. _num_tx_queues = 1;
  6155. break;
  6156. }
  6157. *num_rx_queues_out = _num_rx_queues;
  6158. *num_tx_queues_out = _num_tx_queues;
  6159. }
  6160. static int bnx2x_set_int_mode(struct bnx2x *bp)
  6161. {
  6162. int rc = 0;
  6163. switch (int_mode) {
  6164. case INT_MODE_INTx:
  6165. case INT_MODE_MSI:
  6166. bp->num_rx_queues = 1;
  6167. bp->num_tx_queues = 1;
  6168. DP(NETIF_MSG_IFUP, "set number of queues to 1\n");
  6169. break;
  6170. case INT_MODE_MSIX:
  6171. default:
  6172. /* Set interrupt mode according to bp->multi_mode value */
  6173. bnx2x_set_int_mode_msix(bp, &bp->num_rx_queues,
  6174. &bp->num_tx_queues);
  6175. DP(NETIF_MSG_IFUP, "set number of queues to: rx %d tx %d\n",
  6176. bp->num_rx_queues, bp->num_tx_queues);
  6177. /* if we can't use MSI-X we only need one fp,
  6178. * so try to enable MSI-X with the requested number of fp's
  6179. * and fallback to MSI or legacy INTx with one fp
  6180. */
  6181. rc = bnx2x_enable_msix(bp);
  6182. if (rc) {
  6183. /* failed to enable MSI-X */
  6184. bp->num_rx_queues = 1;
  6185. bp->num_tx_queues = 1;
  6186. }
  6187. break;
  6188. }
  6189. bp->dev->real_num_tx_queues = bp->num_tx_queues;
  6190. return rc;
  6191. }
  6192. #ifdef BCM_CNIC
  6193. static int bnx2x_cnic_notify(struct bnx2x *bp, int cmd);
  6194. static void bnx2x_setup_cnic_irq_info(struct bnx2x *bp);
  6195. #endif
  6196. /* must be called with rtnl_lock */
  6197. static int bnx2x_nic_load(struct bnx2x *bp, int load_mode)
  6198. {
  6199. u32 load_code;
  6200. int i, rc;
  6201. #ifdef BNX2X_STOP_ON_ERROR
  6202. if (unlikely(bp->panic))
  6203. return -EPERM;
  6204. #endif
  6205. bp->state = BNX2X_STATE_OPENING_WAIT4_LOAD;
  6206. rc = bnx2x_set_int_mode(bp);
  6207. if (bnx2x_alloc_mem(bp))
  6208. return -ENOMEM;
  6209. for_each_rx_queue(bp, i)
  6210. bnx2x_fp(bp, i, disable_tpa) =
  6211. ((bp->flags & TPA_ENABLE_FLAG) == 0);
  6212. for_each_rx_queue(bp, i)
  6213. netif_napi_add(bp->dev, &bnx2x_fp(bp, i, napi),
  6214. bnx2x_poll, 128);
  6215. bnx2x_napi_enable(bp);
  6216. if (bp->flags & USING_MSIX_FLAG) {
  6217. rc = bnx2x_req_msix_irqs(bp);
  6218. if (rc) {
  6219. pci_disable_msix(bp->pdev);
  6220. goto load_error1;
  6221. }
  6222. } else {
  6223. /* Fall to INTx if failed to enable MSI-X due to lack of
  6224. memory (in bnx2x_set_int_mode()) */
  6225. if ((rc != -ENOMEM) && (int_mode != INT_MODE_INTx))
  6226. bnx2x_enable_msi(bp);
  6227. bnx2x_ack_int(bp);
  6228. rc = bnx2x_req_irq(bp);
  6229. if (rc) {
  6230. BNX2X_ERR("IRQ request failed rc %d, aborting\n", rc);
  6231. if (bp->flags & USING_MSI_FLAG)
  6232. pci_disable_msi(bp->pdev);
  6233. goto load_error1;
  6234. }
  6235. if (bp->flags & USING_MSI_FLAG) {
  6236. bp->dev->irq = bp->pdev->irq;
  6237. printk(KERN_INFO PFX "%s: using MSI IRQ %d\n",
  6238. bp->dev->name, bp->pdev->irq);
  6239. }
  6240. }
  6241. /* Send LOAD_REQUEST command to MCP
  6242. Returns the type of LOAD command:
  6243. if it is the first port to be initialized
  6244. common blocks should be initialized, otherwise - not
  6245. */
  6246. if (!BP_NOMCP(bp)) {
  6247. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ);
  6248. if (!load_code) {
  6249. BNX2X_ERR("MCP response failure, aborting\n");
  6250. rc = -EBUSY;
  6251. goto load_error2;
  6252. }
  6253. if (load_code == FW_MSG_CODE_DRV_LOAD_REFUSED) {
  6254. rc = -EBUSY; /* other port in diagnostic mode */
  6255. goto load_error2;
  6256. }
  6257. } else {
  6258. int port = BP_PORT(bp);
  6259. DP(NETIF_MSG_IFUP, "NO MCP - load counts %d, %d, %d\n",
  6260. load_count[0], load_count[1], load_count[2]);
  6261. load_count[0]++;
  6262. load_count[1 + port]++;
  6263. DP(NETIF_MSG_IFUP, "NO MCP - new load counts %d, %d, %d\n",
  6264. load_count[0], load_count[1], load_count[2]);
  6265. if (load_count[0] == 1)
  6266. load_code = FW_MSG_CODE_DRV_LOAD_COMMON;
  6267. else if (load_count[1 + port] == 1)
  6268. load_code = FW_MSG_CODE_DRV_LOAD_PORT;
  6269. else
  6270. load_code = FW_MSG_CODE_DRV_LOAD_FUNCTION;
  6271. }
  6272. if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) ||
  6273. (load_code == FW_MSG_CODE_DRV_LOAD_PORT))
  6274. bp->port.pmf = 1;
  6275. else
  6276. bp->port.pmf = 0;
  6277. DP(NETIF_MSG_LINK, "pmf %d\n", bp->port.pmf);
  6278. /* Initialize HW */
  6279. rc = bnx2x_init_hw(bp, load_code);
  6280. if (rc) {
  6281. BNX2X_ERR("HW init failed, aborting\n");
  6282. goto load_error2;
  6283. }
  6284. /* Setup NIC internals and enable interrupts */
  6285. bnx2x_nic_init(bp, load_code);
  6286. if ((load_code == FW_MSG_CODE_DRV_LOAD_COMMON) &&
  6287. (bp->common.shmem2_base))
  6288. SHMEM2_WR(bp, dcc_support,
  6289. (SHMEM_DCC_SUPPORT_DISABLE_ENABLE_PF_TLV |
  6290. SHMEM_DCC_SUPPORT_BANDWIDTH_ALLOCATION_TLV));
  6291. /* Send LOAD_DONE command to MCP */
  6292. if (!BP_NOMCP(bp)) {
  6293. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE);
  6294. if (!load_code) {
  6295. BNX2X_ERR("MCP response failure, aborting\n");
  6296. rc = -EBUSY;
  6297. goto load_error3;
  6298. }
  6299. }
  6300. bp->state = BNX2X_STATE_OPENING_WAIT4_PORT;
  6301. rc = bnx2x_setup_leading(bp);
  6302. if (rc) {
  6303. BNX2X_ERR("Setup leading failed!\n");
  6304. #ifndef BNX2X_STOP_ON_ERROR
  6305. goto load_error3;
  6306. #else
  6307. bp->panic = 1;
  6308. return -EBUSY;
  6309. #endif
  6310. }
  6311. if (CHIP_IS_E1H(bp))
  6312. if (bp->mf_config & FUNC_MF_CFG_FUNC_DISABLED) {
  6313. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  6314. bp->flags |= MF_FUNC_DIS;
  6315. }
  6316. if (bp->state == BNX2X_STATE_OPEN) {
  6317. #ifdef BCM_CNIC
  6318. /* Enable Timer scan */
  6319. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + BP_PORT(bp)*4, 1);
  6320. #endif
  6321. for_each_nondefault_queue(bp, i) {
  6322. rc = bnx2x_setup_multi(bp, i);
  6323. if (rc)
  6324. #ifdef BCM_CNIC
  6325. goto load_error4;
  6326. #else
  6327. goto load_error3;
  6328. #endif
  6329. }
  6330. if (CHIP_IS_E1(bp))
  6331. bnx2x_set_eth_mac_addr_e1(bp, 1);
  6332. else
  6333. bnx2x_set_eth_mac_addr_e1h(bp, 1);
  6334. #ifdef BCM_CNIC
  6335. /* Set iSCSI L2 MAC */
  6336. mutex_lock(&bp->cnic_mutex);
  6337. if (bp->cnic_eth_dev.drv_state & CNIC_DRV_STATE_REGD) {
  6338. bnx2x_set_iscsi_eth_mac_addr(bp, 1);
  6339. bp->cnic_flags |= BNX2X_CNIC_FLAG_MAC_SET;
  6340. }
  6341. mutex_unlock(&bp->cnic_mutex);
  6342. #endif
  6343. }
  6344. if (bp->port.pmf)
  6345. bnx2x_initial_phy_init(bp, load_mode);
  6346. /* Start fast path */
  6347. switch (load_mode) {
  6348. case LOAD_NORMAL:
  6349. if (bp->state == BNX2X_STATE_OPEN) {
  6350. /* Tx queue should be only reenabled */
  6351. netif_tx_wake_all_queues(bp->dev);
  6352. }
  6353. /* Initialize the receive filter. */
  6354. bnx2x_set_rx_mode(bp->dev);
  6355. break;
  6356. case LOAD_OPEN:
  6357. netif_tx_start_all_queues(bp->dev);
  6358. if (bp->state != BNX2X_STATE_OPEN)
  6359. netif_tx_disable(bp->dev);
  6360. /* Initialize the receive filter. */
  6361. bnx2x_set_rx_mode(bp->dev);
  6362. break;
  6363. case LOAD_DIAG:
  6364. /* Initialize the receive filter. */
  6365. bnx2x_set_rx_mode(bp->dev);
  6366. bp->state = BNX2X_STATE_DIAG;
  6367. break;
  6368. default:
  6369. break;
  6370. }
  6371. if (!bp->port.pmf)
  6372. bnx2x__link_status_update(bp);
  6373. /* start the timer */
  6374. mod_timer(&bp->timer, jiffies + bp->current_interval);
  6375. #ifdef BCM_CNIC
  6376. bnx2x_setup_cnic_irq_info(bp);
  6377. if (bp->state == BNX2X_STATE_OPEN)
  6378. bnx2x_cnic_notify(bp, CNIC_CTL_START_CMD);
  6379. #endif
  6380. return 0;
  6381. #ifdef BCM_CNIC
  6382. load_error4:
  6383. /* Disable Timer scan */
  6384. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + BP_PORT(bp)*4, 0);
  6385. #endif
  6386. load_error3:
  6387. bnx2x_int_disable_sync(bp, 1);
  6388. if (!BP_NOMCP(bp)) {
  6389. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP);
  6390. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6391. }
  6392. bp->port.pmf = 0;
  6393. /* Free SKBs, SGEs, TPA pool and driver internals */
  6394. bnx2x_free_skbs(bp);
  6395. for_each_rx_queue(bp, i)
  6396. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  6397. load_error2:
  6398. /* Release IRQs */
  6399. bnx2x_free_irq(bp);
  6400. load_error1:
  6401. bnx2x_napi_disable(bp);
  6402. for_each_rx_queue(bp, i)
  6403. netif_napi_del(&bnx2x_fp(bp, i, napi));
  6404. bnx2x_free_mem(bp);
  6405. return rc;
  6406. }
  6407. static int bnx2x_stop_multi(struct bnx2x *bp, int index)
  6408. {
  6409. struct bnx2x_fastpath *fp = &bp->fp[index];
  6410. int rc;
  6411. /* halt the connection */
  6412. fp->state = BNX2X_FP_STATE_HALTING;
  6413. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, index, 0, fp->cl_id, 0);
  6414. /* Wait for completion */
  6415. rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, index,
  6416. &(fp->state), 1);
  6417. if (rc) /* timeout */
  6418. return rc;
  6419. /* delete cfc entry */
  6420. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CFC_DEL, index, 0, 0, 1);
  6421. /* Wait for completion */
  6422. rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_CLOSED, index,
  6423. &(fp->state), 1);
  6424. return rc;
  6425. }
  6426. static int bnx2x_stop_leading(struct bnx2x *bp)
  6427. {
  6428. __le16 dsb_sp_prod_idx;
  6429. /* if the other port is handling traffic,
  6430. this can take a lot of time */
  6431. int cnt = 500;
  6432. int rc;
  6433. might_sleep();
  6434. /* Send HALT ramrod */
  6435. bp->fp[0].state = BNX2X_FP_STATE_HALTING;
  6436. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT, 0, 0, bp->fp->cl_id, 0);
  6437. /* Wait for completion */
  6438. rc = bnx2x_wait_ramrod(bp, BNX2X_FP_STATE_HALTED, 0,
  6439. &(bp->fp[0].state), 1);
  6440. if (rc) /* timeout */
  6441. return rc;
  6442. dsb_sp_prod_idx = *bp->dsb_sp_prod;
  6443. /* Send PORT_DELETE ramrod */
  6444. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_PORT_DEL, 0, 0, 0, 1);
  6445. /* Wait for completion to arrive on default status block
  6446. we are going to reset the chip anyway
  6447. so there is not much to do if this times out
  6448. */
  6449. while (dsb_sp_prod_idx == *bp->dsb_sp_prod) {
  6450. if (!cnt) {
  6451. DP(NETIF_MSG_IFDOWN, "timeout waiting for port del "
  6452. "dsb_sp_prod 0x%x != dsb_sp_prod_idx 0x%x\n",
  6453. *bp->dsb_sp_prod, dsb_sp_prod_idx);
  6454. #ifdef BNX2X_STOP_ON_ERROR
  6455. bnx2x_panic();
  6456. #endif
  6457. rc = -EBUSY;
  6458. break;
  6459. }
  6460. cnt--;
  6461. msleep(1);
  6462. rmb(); /* Refresh the dsb_sp_prod */
  6463. }
  6464. bp->state = BNX2X_STATE_CLOSING_WAIT4_UNLOAD;
  6465. bp->fp[0].state = BNX2X_FP_STATE_CLOSED;
  6466. return rc;
  6467. }
  6468. static void bnx2x_reset_func(struct bnx2x *bp)
  6469. {
  6470. int port = BP_PORT(bp);
  6471. int func = BP_FUNC(bp);
  6472. int base, i;
  6473. /* Configure IGU */
  6474. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6475. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6476. #ifdef BCM_CNIC
  6477. /* Disable Timer scan */
  6478. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6479. /*
  6480. * Wait for at least 10ms and up to 2 second for the timers scan to
  6481. * complete
  6482. */
  6483. for (i = 0; i < 200; i++) {
  6484. msleep(10);
  6485. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6486. break;
  6487. }
  6488. #endif
  6489. /* Clear ILT */
  6490. base = FUNC_ILT_BASE(func);
  6491. for (i = base; i < base + ILT_PER_FUNC; i++)
  6492. bnx2x_ilt_wr(bp, i, 0);
  6493. }
  6494. static void bnx2x_reset_port(struct bnx2x *bp)
  6495. {
  6496. int port = BP_PORT(bp);
  6497. u32 val;
  6498. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6499. /* Do not rcv packets to BRB */
  6500. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6501. /* Do not direct rcv packets that are not for MCP to the BRB */
  6502. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6503. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6504. /* Configure AEU */
  6505. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6506. msleep(100);
  6507. /* Check for BRB port occupancy */
  6508. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6509. if (val)
  6510. DP(NETIF_MSG_IFDOWN,
  6511. "BRB1 is not empty %d blocks are occupied\n", val);
  6512. /* TODO: Close Doorbell port? */
  6513. }
  6514. static void bnx2x_reset_chip(struct bnx2x *bp, u32 reset_code)
  6515. {
  6516. DP(BNX2X_MSG_MCP, "function %d reset_code %x\n",
  6517. BP_FUNC(bp), reset_code);
  6518. switch (reset_code) {
  6519. case FW_MSG_CODE_DRV_UNLOAD_COMMON:
  6520. bnx2x_reset_port(bp);
  6521. bnx2x_reset_func(bp);
  6522. bnx2x_reset_common(bp);
  6523. break;
  6524. case FW_MSG_CODE_DRV_UNLOAD_PORT:
  6525. bnx2x_reset_port(bp);
  6526. bnx2x_reset_func(bp);
  6527. break;
  6528. case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
  6529. bnx2x_reset_func(bp);
  6530. break;
  6531. default:
  6532. BNX2X_ERR("Unknown reset_code (0x%x) from MCP\n", reset_code);
  6533. break;
  6534. }
  6535. }
  6536. /* must be called with rtnl_lock */
  6537. static int bnx2x_nic_unload(struct bnx2x *bp, int unload_mode)
  6538. {
  6539. int port = BP_PORT(bp);
  6540. u32 reset_code = 0;
  6541. int i, cnt, rc;
  6542. #ifdef BCM_CNIC
  6543. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  6544. #endif
  6545. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  6546. /* Set "drop all" */
  6547. bp->rx_mode = BNX2X_RX_MODE_NONE;
  6548. bnx2x_set_storm_rx_mode(bp);
  6549. /* Disable HW interrupts, NAPI and Tx */
  6550. bnx2x_netif_stop(bp, 1);
  6551. del_timer_sync(&bp->timer);
  6552. SHMEM_WR(bp, func_mb[BP_FUNC(bp)].drv_pulse_mb,
  6553. (DRV_PULSE_ALWAYS_ALIVE | bp->fw_drv_pulse_wr_seq));
  6554. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  6555. /* Release IRQs */
  6556. bnx2x_free_irq(bp);
  6557. /* Wait until tx fastpath tasks complete */
  6558. for_each_tx_queue(bp, i) {
  6559. struct bnx2x_fastpath *fp = &bp->fp[i];
  6560. cnt = 1000;
  6561. while (bnx2x_has_tx_work_unload(fp)) {
  6562. bnx2x_tx_int(fp);
  6563. if (!cnt) {
  6564. BNX2X_ERR("timeout waiting for queue[%d]\n",
  6565. i);
  6566. #ifdef BNX2X_STOP_ON_ERROR
  6567. bnx2x_panic();
  6568. return -EBUSY;
  6569. #else
  6570. break;
  6571. #endif
  6572. }
  6573. cnt--;
  6574. msleep(1);
  6575. }
  6576. }
  6577. /* Give HW time to discard old tx messages */
  6578. msleep(1);
  6579. if (CHIP_IS_E1(bp)) {
  6580. struct mac_configuration_cmd *config =
  6581. bnx2x_sp(bp, mcast_config);
  6582. bnx2x_set_eth_mac_addr_e1(bp, 0);
  6583. for (i = 0; i < config->hdr.length; i++)
  6584. CAM_INVALIDATE(config->config_table[i]);
  6585. config->hdr.length = i;
  6586. if (CHIP_REV_IS_SLOW(bp))
  6587. config->hdr.offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
  6588. else
  6589. config->hdr.offset = BNX2X_MAX_MULTICAST*(1 + port);
  6590. config->hdr.client_id = bp->fp->cl_id;
  6591. config->hdr.reserved1 = 0;
  6592. bp->set_mac_pending++;
  6593. smp_wmb();
  6594. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  6595. U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
  6596. U64_LO(bnx2x_sp_mapping(bp, mcast_config)), 0);
  6597. } else { /* E1H */
  6598. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6599. bnx2x_set_eth_mac_addr_e1h(bp, 0);
  6600. for (i = 0; i < MC_HASH_SIZE; i++)
  6601. REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
  6602. REG_WR(bp, MISC_REG_E1HMF_MODE, 0);
  6603. }
  6604. #ifdef BCM_CNIC
  6605. /* Clear iSCSI L2 MAC */
  6606. mutex_lock(&bp->cnic_mutex);
  6607. if (bp->cnic_flags & BNX2X_CNIC_FLAG_MAC_SET) {
  6608. bnx2x_set_iscsi_eth_mac_addr(bp, 0);
  6609. bp->cnic_flags &= ~BNX2X_CNIC_FLAG_MAC_SET;
  6610. }
  6611. mutex_unlock(&bp->cnic_mutex);
  6612. #endif
  6613. if (unload_mode == UNLOAD_NORMAL)
  6614. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6615. else if (bp->flags & NO_WOL_FLAG)
  6616. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6617. else if (bp->wol) {
  6618. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6619. u8 *mac_addr = bp->dev->dev_addr;
  6620. u32 val;
  6621. /* The mac address is written to entries 1-4 to
  6622. preserve entry 0 which is used by the PMF */
  6623. u8 entry = (BP_E1HVN(bp) + 1)*8;
  6624. val = (mac_addr[0] << 8) | mac_addr[1];
  6625. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6626. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6627. (mac_addr[4] << 8) | mac_addr[5];
  6628. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6629. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6630. } else
  6631. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6632. /* Close multi and leading connections
  6633. Completions for ramrods are collected in a synchronous way */
  6634. for_each_nondefault_queue(bp, i)
  6635. if (bnx2x_stop_multi(bp, i))
  6636. goto unload_error;
  6637. rc = bnx2x_stop_leading(bp);
  6638. if (rc) {
  6639. BNX2X_ERR("Stop leading failed!\n");
  6640. #ifdef BNX2X_STOP_ON_ERROR
  6641. return -EBUSY;
  6642. #else
  6643. goto unload_error;
  6644. #endif
  6645. }
  6646. unload_error:
  6647. if (!BP_NOMCP(bp))
  6648. reset_code = bnx2x_fw_command(bp, reset_code);
  6649. else {
  6650. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts %d, %d, %d\n",
  6651. load_count[0], load_count[1], load_count[2]);
  6652. load_count[0]--;
  6653. load_count[1 + port]--;
  6654. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts %d, %d, %d\n",
  6655. load_count[0], load_count[1], load_count[2]);
  6656. if (load_count[0] == 0)
  6657. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6658. else if (load_count[1 + port] == 0)
  6659. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6660. else
  6661. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6662. }
  6663. if ((reset_code == FW_MSG_CODE_DRV_UNLOAD_COMMON) ||
  6664. (reset_code == FW_MSG_CODE_DRV_UNLOAD_PORT))
  6665. bnx2x__link_reset(bp);
  6666. /* Reset the chip */
  6667. bnx2x_reset_chip(bp, reset_code);
  6668. /* Report UNLOAD_DONE to MCP */
  6669. if (!BP_NOMCP(bp))
  6670. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6671. bp->port.pmf = 0;
  6672. /* Free SKBs, SGEs, TPA pool and driver internals */
  6673. bnx2x_free_skbs(bp);
  6674. for_each_rx_queue(bp, i)
  6675. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  6676. for_each_rx_queue(bp, i)
  6677. netif_napi_del(&bnx2x_fp(bp, i, napi));
  6678. bnx2x_free_mem(bp);
  6679. bp->state = BNX2X_STATE_CLOSED;
  6680. netif_carrier_off(bp->dev);
  6681. return 0;
  6682. }
  6683. static void bnx2x_reset_task(struct work_struct *work)
  6684. {
  6685. struct bnx2x *bp = container_of(work, struct bnx2x, reset_task);
  6686. #ifdef BNX2X_STOP_ON_ERROR
  6687. BNX2X_ERR("reset task called but STOP_ON_ERROR defined"
  6688. " so reset not done to allow debug dump,\n"
  6689. " you will need to reboot when done\n");
  6690. return;
  6691. #endif
  6692. rtnl_lock();
  6693. if (!netif_running(bp->dev))
  6694. goto reset_task_exit;
  6695. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  6696. bnx2x_nic_load(bp, LOAD_NORMAL);
  6697. reset_task_exit:
  6698. rtnl_unlock();
  6699. }
  6700. /* end of nic load/unload */
  6701. /* ethtool_ops */
  6702. /*
  6703. * Init service functions
  6704. */
  6705. static inline u32 bnx2x_get_pretend_reg(struct bnx2x *bp, int func)
  6706. {
  6707. switch (func) {
  6708. case 0: return PXP2_REG_PGL_PRETEND_FUNC_F0;
  6709. case 1: return PXP2_REG_PGL_PRETEND_FUNC_F1;
  6710. case 2: return PXP2_REG_PGL_PRETEND_FUNC_F2;
  6711. case 3: return PXP2_REG_PGL_PRETEND_FUNC_F3;
  6712. case 4: return PXP2_REG_PGL_PRETEND_FUNC_F4;
  6713. case 5: return PXP2_REG_PGL_PRETEND_FUNC_F5;
  6714. case 6: return PXP2_REG_PGL_PRETEND_FUNC_F6;
  6715. case 7: return PXP2_REG_PGL_PRETEND_FUNC_F7;
  6716. default:
  6717. BNX2X_ERR("Unsupported function index: %d\n", func);
  6718. return (u32)(-1);
  6719. }
  6720. }
  6721. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp, int orig_func)
  6722. {
  6723. u32 reg = bnx2x_get_pretend_reg(bp, orig_func), new_val;
  6724. /* Flush all outstanding writes */
  6725. mmiowb();
  6726. /* Pretend to be function 0 */
  6727. REG_WR(bp, reg, 0);
  6728. /* Flush the GRC transaction (in the chip) */
  6729. new_val = REG_RD(bp, reg);
  6730. if (new_val != 0) {
  6731. BNX2X_ERR("Hmmm... Pretend register wasn't updated: (0,%d)!\n",
  6732. new_val);
  6733. BUG();
  6734. }
  6735. /* From now we are in the "like-E1" mode */
  6736. bnx2x_int_disable(bp);
  6737. /* Flush all outstanding writes */
  6738. mmiowb();
  6739. /* Restore the original funtion settings */
  6740. REG_WR(bp, reg, orig_func);
  6741. new_val = REG_RD(bp, reg);
  6742. if (new_val != orig_func) {
  6743. BNX2X_ERR("Hmmm... Pretend register wasn't updated: (%d,%d)!\n",
  6744. orig_func, new_val);
  6745. BUG();
  6746. }
  6747. }
  6748. static inline void bnx2x_undi_int_disable(struct bnx2x *bp, int func)
  6749. {
  6750. if (CHIP_IS_E1H(bp))
  6751. bnx2x_undi_int_disable_e1h(bp, func);
  6752. else
  6753. bnx2x_int_disable(bp);
  6754. }
  6755. static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
  6756. {
  6757. u32 val;
  6758. /* Check if there is any driver already loaded */
  6759. val = REG_RD(bp, MISC_REG_UNPREPARED);
  6760. if (val == 0x1) {
  6761. /* Check if it is the UNDI driver
  6762. * UNDI driver initializes CID offset for normal bell to 0x7
  6763. */
  6764. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6765. val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  6766. if (val == 0x7) {
  6767. u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6768. /* save our func */
  6769. int func = BP_FUNC(bp);
  6770. u32 swap_en;
  6771. u32 swap_val;
  6772. /* clear the UNDI indication */
  6773. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  6774. BNX2X_DEV_INFO("UNDI is active! reset device\n");
  6775. /* try unload UNDI on port 0 */
  6776. bp->func = 0;
  6777. bp->fw_seq =
  6778. (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
  6779. DRV_MSG_SEQ_NUMBER_MASK);
  6780. reset_code = bnx2x_fw_command(bp, reset_code);
  6781. /* if UNDI is loaded on the other port */
  6782. if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  6783. /* send "DONE" for previous unload */
  6784. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6785. /* unload UNDI on port 1 */
  6786. bp->func = 1;
  6787. bp->fw_seq =
  6788. (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
  6789. DRV_MSG_SEQ_NUMBER_MASK);
  6790. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6791. bnx2x_fw_command(bp, reset_code);
  6792. }
  6793. /* now it's safe to release the lock */
  6794. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6795. bnx2x_undi_int_disable(bp, func);
  6796. /* close input traffic and wait for it */
  6797. /* Do not rcv packets to BRB */
  6798. REG_WR(bp,
  6799. (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_DRV_MASK :
  6800. NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
  6801. /* Do not direct rcv packets that are not for MCP to
  6802. * the BRB */
  6803. REG_WR(bp,
  6804. (BP_PORT(bp) ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6805. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6806. /* clear AEU */
  6807. REG_WR(bp,
  6808. (BP_PORT(bp) ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6809. MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
  6810. msleep(10);
  6811. /* save NIG port swap info */
  6812. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  6813. swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  6814. /* reset device */
  6815. REG_WR(bp,
  6816. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6817. 0xd3ffffff);
  6818. REG_WR(bp,
  6819. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6820. 0x1403);
  6821. /* take the NIG out of reset and restore swap values */
  6822. REG_WR(bp,
  6823. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  6824. MISC_REGISTERS_RESET_REG_1_RST_NIG);
  6825. REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
  6826. REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
  6827. /* send unload done to the MCP */
  6828. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE);
  6829. /* restore our func and fw_seq */
  6830. bp->func = func;
  6831. bp->fw_seq =
  6832. (SHMEM_RD(bp, func_mb[bp->func].drv_mb_header) &
  6833. DRV_MSG_SEQ_NUMBER_MASK);
  6834. } else
  6835. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_UNDI);
  6836. }
  6837. }
  6838. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  6839. {
  6840. u32 val, val2, val3, val4, id;
  6841. u16 pmc;
  6842. /* Get the chip revision id and number. */
  6843. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  6844. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  6845. id = ((val & 0xffff) << 16);
  6846. val = REG_RD(bp, MISC_REG_CHIP_REV);
  6847. id |= ((val & 0xf) << 12);
  6848. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  6849. id |= ((val & 0xff) << 4);
  6850. val = REG_RD(bp, MISC_REG_BOND_ID);
  6851. id |= (val & 0xf);
  6852. bp->common.chip_id = id;
  6853. bp->link_params.chip_id = bp->common.chip_id;
  6854. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  6855. val = (REG_RD(bp, 0x2874) & 0x55);
  6856. if ((bp->common.chip_id & 0x1) ||
  6857. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  6858. bp->flags |= ONE_PORT_FLAG;
  6859. BNX2X_DEV_INFO("single port device\n");
  6860. }
  6861. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  6862. bp->common.flash_size = (NVRAM_1MB_SIZE <<
  6863. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  6864. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  6865. bp->common.flash_size, bp->common.flash_size);
  6866. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6867. bp->common.shmem2_base = REG_RD(bp, MISC_REG_GENERIC_CR_0);
  6868. bp->link_params.shmem_base = bp->common.shmem_base;
  6869. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  6870. bp->common.shmem_base, bp->common.shmem2_base);
  6871. if (!bp->common.shmem_base ||
  6872. (bp->common.shmem_base < 0xA0000) ||
  6873. (bp->common.shmem_base >= 0xC0000)) {
  6874. BNX2X_DEV_INFO("MCP not active\n");
  6875. bp->flags |= NO_MCP_FLAG;
  6876. return;
  6877. }
  6878. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6879. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  6880. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  6881. BNX2X_ERR("BAD MCP validity signature\n");
  6882. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  6883. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  6884. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  6885. SHARED_HW_CFG_LED_MODE_MASK) >>
  6886. SHARED_HW_CFG_LED_MODE_SHIFT);
  6887. bp->link_params.feature_config_flags = 0;
  6888. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  6889. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  6890. bp->link_params.feature_config_flags |=
  6891. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  6892. else
  6893. bp->link_params.feature_config_flags &=
  6894. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  6895. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  6896. bp->common.bc_ver = val;
  6897. BNX2X_DEV_INFO("bc_ver %X\n", val);
  6898. if (val < BNX2X_BC_VER) {
  6899. /* for now only warn
  6900. * later we might need to enforce this */
  6901. BNX2X_ERR("This driver needs bc_ver %X but found %X,"
  6902. " please upgrade BC\n", BNX2X_BC_VER, val);
  6903. }
  6904. bp->link_params.feature_config_flags |=
  6905. (val >= REQ_BC_VER_4_VRFY_OPT_MDL) ?
  6906. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  6907. if (BP_E1HVN(bp) == 0) {
  6908. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  6909. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  6910. } else {
  6911. /* no WOL capability for E1HVN != 0 */
  6912. bp->flags |= NO_WOL_FLAG;
  6913. }
  6914. BNX2X_DEV_INFO("%sWoL capable\n",
  6915. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  6916. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  6917. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  6918. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  6919. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  6920. printk(KERN_INFO PFX "part number %X-%X-%X-%X\n",
  6921. val, val2, val3, val4);
  6922. }
  6923. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  6924. u32 switch_cfg)
  6925. {
  6926. int port = BP_PORT(bp);
  6927. u32 ext_phy_type;
  6928. switch (switch_cfg) {
  6929. case SWITCH_CFG_1G:
  6930. BNX2X_DEV_INFO("switch_cfg 0x%x (1G)\n", switch_cfg);
  6931. ext_phy_type =
  6932. SERDES_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  6933. switch (ext_phy_type) {
  6934. case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_DIRECT:
  6935. BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
  6936. ext_phy_type);
  6937. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6938. SUPPORTED_10baseT_Full |
  6939. SUPPORTED_100baseT_Half |
  6940. SUPPORTED_100baseT_Full |
  6941. SUPPORTED_1000baseT_Full |
  6942. SUPPORTED_2500baseX_Full |
  6943. SUPPORTED_TP |
  6944. SUPPORTED_FIBRE |
  6945. SUPPORTED_Autoneg |
  6946. SUPPORTED_Pause |
  6947. SUPPORTED_Asym_Pause);
  6948. break;
  6949. case PORT_HW_CFG_SERDES_EXT_PHY_TYPE_BCM5482:
  6950. BNX2X_DEV_INFO("ext_phy_type 0x%x (5482)\n",
  6951. ext_phy_type);
  6952. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6953. SUPPORTED_10baseT_Full |
  6954. SUPPORTED_100baseT_Half |
  6955. SUPPORTED_100baseT_Full |
  6956. SUPPORTED_1000baseT_Full |
  6957. SUPPORTED_TP |
  6958. SUPPORTED_FIBRE |
  6959. SUPPORTED_Autoneg |
  6960. SUPPORTED_Pause |
  6961. SUPPORTED_Asym_Pause);
  6962. break;
  6963. default:
  6964. BNX2X_ERR("NVRAM config error. "
  6965. "BAD SerDes ext_phy_config 0x%x\n",
  6966. bp->link_params.ext_phy_config);
  6967. return;
  6968. }
  6969. bp->port.phy_addr = REG_RD(bp, NIG_REG_SERDES0_CTRL_PHY_ADDR +
  6970. port*0x10);
  6971. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  6972. break;
  6973. case SWITCH_CFG_10G:
  6974. BNX2X_DEV_INFO("switch_cfg 0x%x (10G)\n", switch_cfg);
  6975. ext_phy_type =
  6976. XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  6977. switch (ext_phy_type) {
  6978. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  6979. BNX2X_DEV_INFO("ext_phy_type 0x%x (Direct)\n",
  6980. ext_phy_type);
  6981. bp->port.supported |= (SUPPORTED_10baseT_Half |
  6982. SUPPORTED_10baseT_Full |
  6983. SUPPORTED_100baseT_Half |
  6984. SUPPORTED_100baseT_Full |
  6985. SUPPORTED_1000baseT_Full |
  6986. SUPPORTED_2500baseX_Full |
  6987. SUPPORTED_10000baseT_Full |
  6988. SUPPORTED_TP |
  6989. SUPPORTED_FIBRE |
  6990. SUPPORTED_Autoneg |
  6991. SUPPORTED_Pause |
  6992. SUPPORTED_Asym_Pause);
  6993. break;
  6994. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
  6995. BNX2X_DEV_INFO("ext_phy_type 0x%x (8072)\n",
  6996. ext_phy_type);
  6997. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  6998. SUPPORTED_1000baseT_Full |
  6999. SUPPORTED_FIBRE |
  7000. SUPPORTED_Autoneg |
  7001. SUPPORTED_Pause |
  7002. SUPPORTED_Asym_Pause);
  7003. break;
  7004. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  7005. BNX2X_DEV_INFO("ext_phy_type 0x%x (8073)\n",
  7006. ext_phy_type);
  7007. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  7008. SUPPORTED_2500baseX_Full |
  7009. SUPPORTED_1000baseT_Full |
  7010. SUPPORTED_FIBRE |
  7011. SUPPORTED_Autoneg |
  7012. SUPPORTED_Pause |
  7013. SUPPORTED_Asym_Pause);
  7014. break;
  7015. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
  7016. BNX2X_DEV_INFO("ext_phy_type 0x%x (8705)\n",
  7017. ext_phy_type);
  7018. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  7019. SUPPORTED_FIBRE |
  7020. SUPPORTED_Pause |
  7021. SUPPORTED_Asym_Pause);
  7022. break;
  7023. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
  7024. BNX2X_DEV_INFO("ext_phy_type 0x%x (8706)\n",
  7025. ext_phy_type);
  7026. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  7027. SUPPORTED_1000baseT_Full |
  7028. SUPPORTED_FIBRE |
  7029. SUPPORTED_Pause |
  7030. SUPPORTED_Asym_Pause);
  7031. break;
  7032. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  7033. BNX2X_DEV_INFO("ext_phy_type 0x%x (8726)\n",
  7034. ext_phy_type);
  7035. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  7036. SUPPORTED_1000baseT_Full |
  7037. SUPPORTED_Autoneg |
  7038. SUPPORTED_FIBRE |
  7039. SUPPORTED_Pause |
  7040. SUPPORTED_Asym_Pause);
  7041. break;
  7042. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  7043. BNX2X_DEV_INFO("ext_phy_type 0x%x (8727)\n",
  7044. ext_phy_type);
  7045. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  7046. SUPPORTED_1000baseT_Full |
  7047. SUPPORTED_Autoneg |
  7048. SUPPORTED_FIBRE |
  7049. SUPPORTED_Pause |
  7050. SUPPORTED_Asym_Pause);
  7051. break;
  7052. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  7053. BNX2X_DEV_INFO("ext_phy_type 0x%x (SFX7101)\n",
  7054. ext_phy_type);
  7055. bp->port.supported |= (SUPPORTED_10000baseT_Full |
  7056. SUPPORTED_TP |
  7057. SUPPORTED_Autoneg |
  7058. SUPPORTED_Pause |
  7059. SUPPORTED_Asym_Pause);
  7060. break;
  7061. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
  7062. BNX2X_DEV_INFO("ext_phy_type 0x%x (BCM8481)\n",
  7063. ext_phy_type);
  7064. bp->port.supported |= (SUPPORTED_10baseT_Half |
  7065. SUPPORTED_10baseT_Full |
  7066. SUPPORTED_100baseT_Half |
  7067. SUPPORTED_100baseT_Full |
  7068. SUPPORTED_1000baseT_Full |
  7069. SUPPORTED_10000baseT_Full |
  7070. SUPPORTED_TP |
  7071. SUPPORTED_Autoneg |
  7072. SUPPORTED_Pause |
  7073. SUPPORTED_Asym_Pause);
  7074. break;
  7075. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  7076. BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
  7077. bp->link_params.ext_phy_config);
  7078. break;
  7079. default:
  7080. BNX2X_ERR("NVRAM config error. "
  7081. "BAD XGXS ext_phy_config 0x%x\n",
  7082. bp->link_params.ext_phy_config);
  7083. return;
  7084. }
  7085. bp->port.phy_addr = REG_RD(bp, NIG_REG_XGXS0_CTRL_PHY_ADDR +
  7086. port*0x18);
  7087. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  7088. break;
  7089. default:
  7090. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  7091. bp->port.link_config);
  7092. return;
  7093. }
  7094. bp->link_params.phy_addr = bp->port.phy_addr;
  7095. /* mask what we support according to speed_cap_mask */
  7096. if (!(bp->link_params.speed_cap_mask &
  7097. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  7098. bp->port.supported &= ~SUPPORTED_10baseT_Half;
  7099. if (!(bp->link_params.speed_cap_mask &
  7100. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  7101. bp->port.supported &= ~SUPPORTED_10baseT_Full;
  7102. if (!(bp->link_params.speed_cap_mask &
  7103. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  7104. bp->port.supported &= ~SUPPORTED_100baseT_Half;
  7105. if (!(bp->link_params.speed_cap_mask &
  7106. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  7107. bp->port.supported &= ~SUPPORTED_100baseT_Full;
  7108. if (!(bp->link_params.speed_cap_mask &
  7109. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  7110. bp->port.supported &= ~(SUPPORTED_1000baseT_Half |
  7111. SUPPORTED_1000baseT_Full);
  7112. if (!(bp->link_params.speed_cap_mask &
  7113. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  7114. bp->port.supported &= ~SUPPORTED_2500baseX_Full;
  7115. if (!(bp->link_params.speed_cap_mask &
  7116. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  7117. bp->port.supported &= ~SUPPORTED_10000baseT_Full;
  7118. BNX2X_DEV_INFO("supported 0x%x\n", bp->port.supported);
  7119. }
  7120. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  7121. {
  7122. bp->link_params.req_duplex = DUPLEX_FULL;
  7123. switch (bp->port.link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  7124. case PORT_FEATURE_LINK_SPEED_AUTO:
  7125. if (bp->port.supported & SUPPORTED_Autoneg) {
  7126. bp->link_params.req_line_speed = SPEED_AUTO_NEG;
  7127. bp->port.advertising = bp->port.supported;
  7128. } else {
  7129. u32 ext_phy_type =
  7130. XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  7131. if ((ext_phy_type ==
  7132. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705) ||
  7133. (ext_phy_type ==
  7134. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706)) {
  7135. /* force 10G, no AN */
  7136. bp->link_params.req_line_speed = SPEED_10000;
  7137. bp->port.advertising =
  7138. (ADVERTISED_10000baseT_Full |
  7139. ADVERTISED_FIBRE);
  7140. break;
  7141. }
  7142. BNX2X_ERR("NVRAM config error. "
  7143. "Invalid link_config 0x%x"
  7144. " Autoneg not supported\n",
  7145. bp->port.link_config);
  7146. return;
  7147. }
  7148. break;
  7149. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  7150. if (bp->port.supported & SUPPORTED_10baseT_Full) {
  7151. bp->link_params.req_line_speed = SPEED_10;
  7152. bp->port.advertising = (ADVERTISED_10baseT_Full |
  7153. ADVERTISED_TP);
  7154. } else {
  7155. BNX2X_ERR("NVRAM config error. "
  7156. "Invalid link_config 0x%x"
  7157. " speed_cap_mask 0x%x\n",
  7158. bp->port.link_config,
  7159. bp->link_params.speed_cap_mask);
  7160. return;
  7161. }
  7162. break;
  7163. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  7164. if (bp->port.supported & SUPPORTED_10baseT_Half) {
  7165. bp->link_params.req_line_speed = SPEED_10;
  7166. bp->link_params.req_duplex = DUPLEX_HALF;
  7167. bp->port.advertising = (ADVERTISED_10baseT_Half |
  7168. ADVERTISED_TP);
  7169. } else {
  7170. BNX2X_ERR("NVRAM config error. "
  7171. "Invalid link_config 0x%x"
  7172. " speed_cap_mask 0x%x\n",
  7173. bp->port.link_config,
  7174. bp->link_params.speed_cap_mask);
  7175. return;
  7176. }
  7177. break;
  7178. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  7179. if (bp->port.supported & SUPPORTED_100baseT_Full) {
  7180. bp->link_params.req_line_speed = SPEED_100;
  7181. bp->port.advertising = (ADVERTISED_100baseT_Full |
  7182. ADVERTISED_TP);
  7183. } else {
  7184. BNX2X_ERR("NVRAM config error. "
  7185. "Invalid link_config 0x%x"
  7186. " speed_cap_mask 0x%x\n",
  7187. bp->port.link_config,
  7188. bp->link_params.speed_cap_mask);
  7189. return;
  7190. }
  7191. break;
  7192. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  7193. if (bp->port.supported & SUPPORTED_100baseT_Half) {
  7194. bp->link_params.req_line_speed = SPEED_100;
  7195. bp->link_params.req_duplex = DUPLEX_HALF;
  7196. bp->port.advertising = (ADVERTISED_100baseT_Half |
  7197. ADVERTISED_TP);
  7198. } else {
  7199. BNX2X_ERR("NVRAM config error. "
  7200. "Invalid link_config 0x%x"
  7201. " speed_cap_mask 0x%x\n",
  7202. bp->port.link_config,
  7203. bp->link_params.speed_cap_mask);
  7204. return;
  7205. }
  7206. break;
  7207. case PORT_FEATURE_LINK_SPEED_1G:
  7208. if (bp->port.supported & SUPPORTED_1000baseT_Full) {
  7209. bp->link_params.req_line_speed = SPEED_1000;
  7210. bp->port.advertising = (ADVERTISED_1000baseT_Full |
  7211. ADVERTISED_TP);
  7212. } else {
  7213. BNX2X_ERR("NVRAM config error. "
  7214. "Invalid link_config 0x%x"
  7215. " speed_cap_mask 0x%x\n",
  7216. bp->port.link_config,
  7217. bp->link_params.speed_cap_mask);
  7218. return;
  7219. }
  7220. break;
  7221. case PORT_FEATURE_LINK_SPEED_2_5G:
  7222. if (bp->port.supported & SUPPORTED_2500baseX_Full) {
  7223. bp->link_params.req_line_speed = SPEED_2500;
  7224. bp->port.advertising = (ADVERTISED_2500baseX_Full |
  7225. ADVERTISED_TP);
  7226. } else {
  7227. BNX2X_ERR("NVRAM config error. "
  7228. "Invalid link_config 0x%x"
  7229. " speed_cap_mask 0x%x\n",
  7230. bp->port.link_config,
  7231. bp->link_params.speed_cap_mask);
  7232. return;
  7233. }
  7234. break;
  7235. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  7236. case PORT_FEATURE_LINK_SPEED_10G_KX4:
  7237. case PORT_FEATURE_LINK_SPEED_10G_KR:
  7238. if (bp->port.supported & SUPPORTED_10000baseT_Full) {
  7239. bp->link_params.req_line_speed = SPEED_10000;
  7240. bp->port.advertising = (ADVERTISED_10000baseT_Full |
  7241. ADVERTISED_FIBRE);
  7242. } else {
  7243. BNX2X_ERR("NVRAM config error. "
  7244. "Invalid link_config 0x%x"
  7245. " speed_cap_mask 0x%x\n",
  7246. bp->port.link_config,
  7247. bp->link_params.speed_cap_mask);
  7248. return;
  7249. }
  7250. break;
  7251. default:
  7252. BNX2X_ERR("NVRAM config error. "
  7253. "BAD link speed link_config 0x%x\n",
  7254. bp->port.link_config);
  7255. bp->link_params.req_line_speed = SPEED_AUTO_NEG;
  7256. bp->port.advertising = bp->port.supported;
  7257. break;
  7258. }
  7259. bp->link_params.req_flow_ctrl = (bp->port.link_config &
  7260. PORT_FEATURE_FLOW_CONTROL_MASK);
  7261. if ((bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO) &&
  7262. !(bp->port.supported & SUPPORTED_Autoneg))
  7263. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  7264. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x"
  7265. " advertising 0x%x\n",
  7266. bp->link_params.req_line_speed,
  7267. bp->link_params.req_duplex,
  7268. bp->link_params.req_flow_ctrl, bp->port.advertising);
  7269. }
  7270. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  7271. {
  7272. mac_hi = cpu_to_be16(mac_hi);
  7273. mac_lo = cpu_to_be32(mac_lo);
  7274. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  7275. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  7276. }
  7277. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  7278. {
  7279. int port = BP_PORT(bp);
  7280. u32 val, val2;
  7281. u32 config;
  7282. u16 i;
  7283. u32 ext_phy_type;
  7284. bp->link_params.bp = bp;
  7285. bp->link_params.port = port;
  7286. bp->link_params.lane_config =
  7287. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  7288. bp->link_params.ext_phy_config =
  7289. SHMEM_RD(bp,
  7290. dev_info.port_hw_config[port].external_phy_config);
  7291. /* BCM8727_NOC => BCM8727 no over current */
  7292. if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
  7293. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727_NOC) {
  7294. bp->link_params.ext_phy_config &=
  7295. ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  7296. bp->link_params.ext_phy_config |=
  7297. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727;
  7298. bp->link_params.feature_config_flags |=
  7299. FEATURE_CONFIG_BCM8727_NOC;
  7300. }
  7301. bp->link_params.speed_cap_mask =
  7302. SHMEM_RD(bp,
  7303. dev_info.port_hw_config[port].speed_capability_mask);
  7304. bp->port.link_config =
  7305. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  7306. /* Get the 4 lanes xgxs config rx and tx */
  7307. for (i = 0; i < 2; i++) {
  7308. val = SHMEM_RD(bp,
  7309. dev_info.port_hw_config[port].xgxs_config_rx[i<<1]);
  7310. bp->link_params.xgxs_config_rx[i << 1] = ((val>>16) & 0xffff);
  7311. bp->link_params.xgxs_config_rx[(i << 1) + 1] = (val & 0xffff);
  7312. val = SHMEM_RD(bp,
  7313. dev_info.port_hw_config[port].xgxs_config_tx[i<<1]);
  7314. bp->link_params.xgxs_config_tx[i << 1] = ((val>>16) & 0xffff);
  7315. bp->link_params.xgxs_config_tx[(i << 1) + 1] = (val & 0xffff);
  7316. }
  7317. /* If the device is capable of WoL, set the default state according
  7318. * to the HW
  7319. */
  7320. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  7321. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  7322. (config & PORT_FEATURE_WOL_ENABLED));
  7323. BNX2X_DEV_INFO("lane_config 0x%08x ext_phy_config 0x%08x"
  7324. " speed_cap_mask 0x%08x link_config 0x%08x\n",
  7325. bp->link_params.lane_config,
  7326. bp->link_params.ext_phy_config,
  7327. bp->link_params.speed_cap_mask, bp->port.link_config);
  7328. bp->link_params.switch_cfg |= (bp->port.link_config &
  7329. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  7330. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  7331. bnx2x_link_settings_requested(bp);
  7332. /*
  7333. * If connected directly, work with the internal PHY, otherwise, work
  7334. * with the external PHY
  7335. */
  7336. ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  7337. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7338. bp->mdio.prtad = bp->link_params.phy_addr;
  7339. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  7340. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  7341. bp->mdio.prtad =
  7342. XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config);
  7343. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  7344. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  7345. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  7346. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  7347. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  7348. #ifdef BCM_CNIC
  7349. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].iscsi_mac_upper);
  7350. val = SHMEM_RD(bp, dev_info.port_hw_config[port].iscsi_mac_lower);
  7351. bnx2x_set_mac_buf(bp->iscsi_mac, val, val2);
  7352. #endif
  7353. }
  7354. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  7355. {
  7356. int func = BP_FUNC(bp);
  7357. u32 val, val2;
  7358. int rc = 0;
  7359. bnx2x_get_common_hwinfo(bp);
  7360. bp->e1hov = 0;
  7361. bp->e1hmf = 0;
  7362. if (CHIP_IS_E1H(bp)) {
  7363. bp->mf_config =
  7364. SHMEM_RD(bp, mf_cfg.func_mf_config[func].config);
  7365. val = (SHMEM_RD(bp, mf_cfg.func_mf_config[FUNC_0].e1hov_tag) &
  7366. FUNC_MF_CFG_E1HOV_TAG_MASK);
  7367. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  7368. bp->e1hmf = 1;
  7369. BNX2X_DEV_INFO("%s function mode\n",
  7370. IS_E1HMF(bp) ? "multi" : "single");
  7371. if (IS_E1HMF(bp)) {
  7372. val = (SHMEM_RD(bp, mf_cfg.func_mf_config[func].
  7373. e1hov_tag) &
  7374. FUNC_MF_CFG_E1HOV_TAG_MASK);
  7375. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  7376. bp->e1hov = val;
  7377. BNX2X_DEV_INFO("E1HOV for func %d is %d "
  7378. "(0x%04x)\n",
  7379. func, bp->e1hov, bp->e1hov);
  7380. } else {
  7381. BNX2X_ERR("!!! No valid E1HOV for func %d,"
  7382. " aborting\n", func);
  7383. rc = -EPERM;
  7384. }
  7385. } else {
  7386. if (BP_E1HVN(bp)) {
  7387. BNX2X_ERR("!!! VN %d in single function mode,"
  7388. " aborting\n", BP_E1HVN(bp));
  7389. rc = -EPERM;
  7390. }
  7391. }
  7392. }
  7393. if (!BP_NOMCP(bp)) {
  7394. bnx2x_get_port_hwinfo(bp);
  7395. bp->fw_seq = (SHMEM_RD(bp, func_mb[func].drv_mb_header) &
  7396. DRV_MSG_SEQ_NUMBER_MASK);
  7397. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  7398. }
  7399. if (IS_E1HMF(bp)) {
  7400. val2 = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_upper);
  7401. val = SHMEM_RD(bp, mf_cfg.func_mf_config[func].mac_lower);
  7402. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  7403. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT)) {
  7404. bp->dev->dev_addr[0] = (u8)(val2 >> 8 & 0xff);
  7405. bp->dev->dev_addr[1] = (u8)(val2 & 0xff);
  7406. bp->dev->dev_addr[2] = (u8)(val >> 24 & 0xff);
  7407. bp->dev->dev_addr[3] = (u8)(val >> 16 & 0xff);
  7408. bp->dev->dev_addr[4] = (u8)(val >> 8 & 0xff);
  7409. bp->dev->dev_addr[5] = (u8)(val & 0xff);
  7410. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr,
  7411. ETH_ALEN);
  7412. memcpy(bp->dev->perm_addr, bp->dev->dev_addr,
  7413. ETH_ALEN);
  7414. }
  7415. return rc;
  7416. }
  7417. if (BP_NOMCP(bp)) {
  7418. /* only supposed to happen on emulation/FPGA */
  7419. BNX2X_ERR("warning random MAC workaround active\n");
  7420. random_ether_addr(bp->dev->dev_addr);
  7421. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  7422. }
  7423. return rc;
  7424. }
  7425. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  7426. {
  7427. int func = BP_FUNC(bp);
  7428. int timer_interval;
  7429. int rc;
  7430. /* Disable interrupt handling until HW is initialized */
  7431. atomic_set(&bp->intr_sem, 1);
  7432. smp_wmb(); /* Ensure that bp->intr_sem update is SMP-safe */
  7433. mutex_init(&bp->port.phy_mutex);
  7434. mutex_init(&bp->fw_mb_mutex);
  7435. #ifdef BCM_CNIC
  7436. mutex_init(&bp->cnic_mutex);
  7437. #endif
  7438. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  7439. INIT_WORK(&bp->reset_task, bnx2x_reset_task);
  7440. rc = bnx2x_get_hwinfo(bp);
  7441. /* need to reset chip if undi was active */
  7442. if (!BP_NOMCP(bp))
  7443. bnx2x_undi_unload(bp);
  7444. if (CHIP_REV_IS_FPGA(bp))
  7445. printk(KERN_ERR PFX "FPGA detected\n");
  7446. if (BP_NOMCP(bp) && (func == 0))
  7447. printk(KERN_ERR PFX
  7448. "MCP disabled, must load devices in order!\n");
  7449. /* Set multi queue mode */
  7450. if ((multi_mode != ETH_RSS_MODE_DISABLED) &&
  7451. ((int_mode == INT_MODE_INTx) || (int_mode == INT_MODE_MSI))) {
  7452. printk(KERN_ERR PFX
  7453. "Multi disabled since int_mode requested is not MSI-X\n");
  7454. multi_mode = ETH_RSS_MODE_DISABLED;
  7455. }
  7456. bp->multi_mode = multi_mode;
  7457. /* Set TPA flags */
  7458. if (disable_tpa) {
  7459. bp->flags &= ~TPA_ENABLE_FLAG;
  7460. bp->dev->features &= ~NETIF_F_LRO;
  7461. } else {
  7462. bp->flags |= TPA_ENABLE_FLAG;
  7463. bp->dev->features |= NETIF_F_LRO;
  7464. }
  7465. if (CHIP_IS_E1(bp))
  7466. bp->dropless_fc = 0;
  7467. else
  7468. bp->dropless_fc = dropless_fc;
  7469. bp->mrrs = mrrs;
  7470. bp->tx_ring_size = MAX_TX_AVAIL;
  7471. bp->rx_ring_size = MAX_RX_AVAIL;
  7472. bp->rx_csum = 1;
  7473. /* make sure that the numbers are in the right granularity */
  7474. bp->tx_ticks = (50 / (4 * BNX2X_BTR)) * (4 * BNX2X_BTR);
  7475. bp->rx_ticks = (25 / (4 * BNX2X_BTR)) * (4 * BNX2X_BTR);
  7476. timer_interval = (CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ);
  7477. bp->current_interval = (poll ? poll : timer_interval);
  7478. init_timer(&bp->timer);
  7479. bp->timer.expires = jiffies + bp->current_interval;
  7480. bp->timer.data = (unsigned long) bp;
  7481. bp->timer.function = bnx2x_timer;
  7482. return rc;
  7483. }
  7484. /*
  7485. * ethtool service functions
  7486. */
  7487. /* All ethtool functions called with rtnl_lock */
  7488. static int bnx2x_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7489. {
  7490. struct bnx2x *bp = netdev_priv(dev);
  7491. cmd->supported = bp->port.supported;
  7492. cmd->advertising = bp->port.advertising;
  7493. if ((bp->state == BNX2X_STATE_OPEN) &&
  7494. !(bp->flags & MF_FUNC_DIS) &&
  7495. (bp->link_vars.link_up)) {
  7496. cmd->speed = bp->link_vars.line_speed;
  7497. cmd->duplex = bp->link_vars.duplex;
  7498. if (IS_E1HMF(bp)) {
  7499. u16 vn_max_rate;
  7500. vn_max_rate =
  7501. ((bp->mf_config & FUNC_MF_CFG_MAX_BW_MASK) >>
  7502. FUNC_MF_CFG_MAX_BW_SHIFT) * 100;
  7503. if (vn_max_rate < cmd->speed)
  7504. cmd->speed = vn_max_rate;
  7505. }
  7506. } else {
  7507. cmd->speed = -1;
  7508. cmd->duplex = -1;
  7509. }
  7510. if (bp->link_params.switch_cfg == SWITCH_CFG_10G) {
  7511. u32 ext_phy_type =
  7512. XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  7513. switch (ext_phy_type) {
  7514. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT:
  7515. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8072:
  7516. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8073:
  7517. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8705:
  7518. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8706:
  7519. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8726:
  7520. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8727:
  7521. cmd->port = PORT_FIBRE;
  7522. break;
  7523. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101:
  7524. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM8481:
  7525. cmd->port = PORT_TP;
  7526. break;
  7527. case PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE:
  7528. BNX2X_ERR("XGXS PHY Failure detected 0x%x\n",
  7529. bp->link_params.ext_phy_config);
  7530. break;
  7531. default:
  7532. DP(NETIF_MSG_LINK, "BAD XGXS ext_phy_config 0x%x\n",
  7533. bp->link_params.ext_phy_config);
  7534. break;
  7535. }
  7536. } else
  7537. cmd->port = PORT_TP;
  7538. cmd->phy_address = bp->mdio.prtad;
  7539. cmd->transceiver = XCVR_INTERNAL;
  7540. if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
  7541. cmd->autoneg = AUTONEG_ENABLE;
  7542. else
  7543. cmd->autoneg = AUTONEG_DISABLE;
  7544. cmd->maxtxpkt = 0;
  7545. cmd->maxrxpkt = 0;
  7546. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  7547. DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
  7548. DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
  7549. DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  7550. cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
  7551. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  7552. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  7553. return 0;
  7554. }
  7555. static int bnx2x_set_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  7556. {
  7557. struct bnx2x *bp = netdev_priv(dev);
  7558. u32 advertising;
  7559. if (IS_E1HMF(bp))
  7560. return 0;
  7561. DP(NETIF_MSG_LINK, "ethtool_cmd: cmd %d\n"
  7562. DP_LEVEL " supported 0x%x advertising 0x%x speed %d\n"
  7563. DP_LEVEL " duplex %d port %d phy_address %d transceiver %d\n"
  7564. DP_LEVEL " autoneg %d maxtxpkt %d maxrxpkt %d\n",
  7565. cmd->cmd, cmd->supported, cmd->advertising, cmd->speed,
  7566. cmd->duplex, cmd->port, cmd->phy_address, cmd->transceiver,
  7567. cmd->autoneg, cmd->maxtxpkt, cmd->maxrxpkt);
  7568. if (cmd->autoneg == AUTONEG_ENABLE) {
  7569. if (!(bp->port.supported & SUPPORTED_Autoneg)) {
  7570. DP(NETIF_MSG_LINK, "Autoneg not supported\n");
  7571. return -EINVAL;
  7572. }
  7573. /* advertise the requested speed and duplex if supported */
  7574. cmd->advertising &= bp->port.supported;
  7575. bp->link_params.req_line_speed = SPEED_AUTO_NEG;
  7576. bp->link_params.req_duplex = DUPLEX_FULL;
  7577. bp->port.advertising |= (ADVERTISED_Autoneg |
  7578. cmd->advertising);
  7579. } else { /* forced speed */
  7580. /* advertise the requested speed and duplex if supported */
  7581. switch (cmd->speed) {
  7582. case SPEED_10:
  7583. if (cmd->duplex == DUPLEX_FULL) {
  7584. if (!(bp->port.supported &
  7585. SUPPORTED_10baseT_Full)) {
  7586. DP(NETIF_MSG_LINK,
  7587. "10M full not supported\n");
  7588. return -EINVAL;
  7589. }
  7590. advertising = (ADVERTISED_10baseT_Full |
  7591. ADVERTISED_TP);
  7592. } else {
  7593. if (!(bp->port.supported &
  7594. SUPPORTED_10baseT_Half)) {
  7595. DP(NETIF_MSG_LINK,
  7596. "10M half not supported\n");
  7597. return -EINVAL;
  7598. }
  7599. advertising = (ADVERTISED_10baseT_Half |
  7600. ADVERTISED_TP);
  7601. }
  7602. break;
  7603. case SPEED_100:
  7604. if (cmd->duplex == DUPLEX_FULL) {
  7605. if (!(bp->port.supported &
  7606. SUPPORTED_100baseT_Full)) {
  7607. DP(NETIF_MSG_LINK,
  7608. "100M full not supported\n");
  7609. return -EINVAL;
  7610. }
  7611. advertising = (ADVERTISED_100baseT_Full |
  7612. ADVERTISED_TP);
  7613. } else {
  7614. if (!(bp->port.supported &
  7615. SUPPORTED_100baseT_Half)) {
  7616. DP(NETIF_MSG_LINK,
  7617. "100M half not supported\n");
  7618. return -EINVAL;
  7619. }
  7620. advertising = (ADVERTISED_100baseT_Half |
  7621. ADVERTISED_TP);
  7622. }
  7623. break;
  7624. case SPEED_1000:
  7625. if (cmd->duplex != DUPLEX_FULL) {
  7626. DP(NETIF_MSG_LINK, "1G half not supported\n");
  7627. return -EINVAL;
  7628. }
  7629. if (!(bp->port.supported & SUPPORTED_1000baseT_Full)) {
  7630. DP(NETIF_MSG_LINK, "1G full not supported\n");
  7631. return -EINVAL;
  7632. }
  7633. advertising = (ADVERTISED_1000baseT_Full |
  7634. ADVERTISED_TP);
  7635. break;
  7636. case SPEED_2500:
  7637. if (cmd->duplex != DUPLEX_FULL) {
  7638. DP(NETIF_MSG_LINK,
  7639. "2.5G half not supported\n");
  7640. return -EINVAL;
  7641. }
  7642. if (!(bp->port.supported & SUPPORTED_2500baseX_Full)) {
  7643. DP(NETIF_MSG_LINK,
  7644. "2.5G full not supported\n");
  7645. return -EINVAL;
  7646. }
  7647. advertising = (ADVERTISED_2500baseX_Full |
  7648. ADVERTISED_TP);
  7649. break;
  7650. case SPEED_10000:
  7651. if (cmd->duplex != DUPLEX_FULL) {
  7652. DP(NETIF_MSG_LINK, "10G half not supported\n");
  7653. return -EINVAL;
  7654. }
  7655. if (!(bp->port.supported & SUPPORTED_10000baseT_Full)) {
  7656. DP(NETIF_MSG_LINK, "10G full not supported\n");
  7657. return -EINVAL;
  7658. }
  7659. advertising = (ADVERTISED_10000baseT_Full |
  7660. ADVERTISED_FIBRE);
  7661. break;
  7662. default:
  7663. DP(NETIF_MSG_LINK, "Unsupported speed\n");
  7664. return -EINVAL;
  7665. }
  7666. bp->link_params.req_line_speed = cmd->speed;
  7667. bp->link_params.req_duplex = cmd->duplex;
  7668. bp->port.advertising = advertising;
  7669. }
  7670. DP(NETIF_MSG_LINK, "req_line_speed %d\n"
  7671. DP_LEVEL " req_duplex %d advertising 0x%x\n",
  7672. bp->link_params.req_line_speed, bp->link_params.req_duplex,
  7673. bp->port.advertising);
  7674. if (netif_running(dev)) {
  7675. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  7676. bnx2x_link_set(bp);
  7677. }
  7678. return 0;
  7679. }
  7680. #define IS_E1_ONLINE(info) (((info) & RI_E1_ONLINE) == RI_E1_ONLINE)
  7681. #define IS_E1H_ONLINE(info) (((info) & RI_E1H_ONLINE) == RI_E1H_ONLINE)
  7682. static int bnx2x_get_regs_len(struct net_device *dev)
  7683. {
  7684. struct bnx2x *bp = netdev_priv(dev);
  7685. int regdump_len = 0;
  7686. int i;
  7687. if (CHIP_IS_E1(bp)) {
  7688. for (i = 0; i < REGS_COUNT; i++)
  7689. if (IS_E1_ONLINE(reg_addrs[i].info))
  7690. regdump_len += reg_addrs[i].size;
  7691. for (i = 0; i < WREGS_COUNT_E1; i++)
  7692. if (IS_E1_ONLINE(wreg_addrs_e1[i].info))
  7693. regdump_len += wreg_addrs_e1[i].size *
  7694. (1 + wreg_addrs_e1[i].read_regs_count);
  7695. } else { /* E1H */
  7696. for (i = 0; i < REGS_COUNT; i++)
  7697. if (IS_E1H_ONLINE(reg_addrs[i].info))
  7698. regdump_len += reg_addrs[i].size;
  7699. for (i = 0; i < WREGS_COUNT_E1H; i++)
  7700. if (IS_E1H_ONLINE(wreg_addrs_e1h[i].info))
  7701. regdump_len += wreg_addrs_e1h[i].size *
  7702. (1 + wreg_addrs_e1h[i].read_regs_count);
  7703. }
  7704. regdump_len *= 4;
  7705. regdump_len += sizeof(struct dump_hdr);
  7706. return regdump_len;
  7707. }
  7708. static void bnx2x_get_regs(struct net_device *dev,
  7709. struct ethtool_regs *regs, void *_p)
  7710. {
  7711. u32 *p = _p, i, j;
  7712. struct bnx2x *bp = netdev_priv(dev);
  7713. struct dump_hdr dump_hdr = {0};
  7714. regs->version = 0;
  7715. memset(p, 0, regs->len);
  7716. if (!netif_running(bp->dev))
  7717. return;
  7718. dump_hdr.hdr_size = (sizeof(struct dump_hdr) / 4) - 1;
  7719. dump_hdr.dump_sign = dump_sign_all;
  7720. dump_hdr.xstorm_waitp = REG_RD(bp, XSTORM_WAITP_ADDR);
  7721. dump_hdr.tstorm_waitp = REG_RD(bp, TSTORM_WAITP_ADDR);
  7722. dump_hdr.ustorm_waitp = REG_RD(bp, USTORM_WAITP_ADDR);
  7723. dump_hdr.cstorm_waitp = REG_RD(bp, CSTORM_WAITP_ADDR);
  7724. dump_hdr.info = CHIP_IS_E1(bp) ? RI_E1_ONLINE : RI_E1H_ONLINE;
  7725. memcpy(p, &dump_hdr, sizeof(struct dump_hdr));
  7726. p += dump_hdr.hdr_size + 1;
  7727. if (CHIP_IS_E1(bp)) {
  7728. for (i = 0; i < REGS_COUNT; i++)
  7729. if (IS_E1_ONLINE(reg_addrs[i].info))
  7730. for (j = 0; j < reg_addrs[i].size; j++)
  7731. *p++ = REG_RD(bp,
  7732. reg_addrs[i].addr + j*4);
  7733. } else { /* E1H */
  7734. for (i = 0; i < REGS_COUNT; i++)
  7735. if (IS_E1H_ONLINE(reg_addrs[i].info))
  7736. for (j = 0; j < reg_addrs[i].size; j++)
  7737. *p++ = REG_RD(bp,
  7738. reg_addrs[i].addr + j*4);
  7739. }
  7740. }
  7741. #define PHY_FW_VER_LEN 10
  7742. static void bnx2x_get_drvinfo(struct net_device *dev,
  7743. struct ethtool_drvinfo *info)
  7744. {
  7745. struct bnx2x *bp = netdev_priv(dev);
  7746. u8 phy_fw_ver[PHY_FW_VER_LEN];
  7747. strcpy(info->driver, DRV_MODULE_NAME);
  7748. strcpy(info->version, DRV_MODULE_VERSION);
  7749. phy_fw_ver[0] = '\0';
  7750. if (bp->port.pmf) {
  7751. bnx2x_acquire_phy_lock(bp);
  7752. bnx2x_get_ext_phy_fw_version(&bp->link_params,
  7753. (bp->state != BNX2X_STATE_CLOSED),
  7754. phy_fw_ver, PHY_FW_VER_LEN);
  7755. bnx2x_release_phy_lock(bp);
  7756. }
  7757. snprintf(info->fw_version, 32, "BC:%d.%d.%d%s%s",
  7758. (bp->common.bc_ver & 0xff0000) >> 16,
  7759. (bp->common.bc_ver & 0xff00) >> 8,
  7760. (bp->common.bc_ver & 0xff),
  7761. ((phy_fw_ver[0] != '\0') ? " PHY:" : ""), phy_fw_ver);
  7762. strcpy(info->bus_info, pci_name(bp->pdev));
  7763. info->n_stats = BNX2X_NUM_STATS;
  7764. info->testinfo_len = BNX2X_NUM_TESTS;
  7765. info->eedump_len = bp->common.flash_size;
  7766. info->regdump_len = bnx2x_get_regs_len(dev);
  7767. }
  7768. static void bnx2x_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7769. {
  7770. struct bnx2x *bp = netdev_priv(dev);
  7771. if (bp->flags & NO_WOL_FLAG) {
  7772. wol->supported = 0;
  7773. wol->wolopts = 0;
  7774. } else {
  7775. wol->supported = WAKE_MAGIC;
  7776. if (bp->wol)
  7777. wol->wolopts = WAKE_MAGIC;
  7778. else
  7779. wol->wolopts = 0;
  7780. }
  7781. memset(&wol->sopass, 0, sizeof(wol->sopass));
  7782. }
  7783. static int bnx2x_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol)
  7784. {
  7785. struct bnx2x *bp = netdev_priv(dev);
  7786. if (wol->wolopts & ~WAKE_MAGIC)
  7787. return -EINVAL;
  7788. if (wol->wolopts & WAKE_MAGIC) {
  7789. if (bp->flags & NO_WOL_FLAG)
  7790. return -EINVAL;
  7791. bp->wol = 1;
  7792. } else
  7793. bp->wol = 0;
  7794. return 0;
  7795. }
  7796. static u32 bnx2x_get_msglevel(struct net_device *dev)
  7797. {
  7798. struct bnx2x *bp = netdev_priv(dev);
  7799. return bp->msglevel;
  7800. }
  7801. static void bnx2x_set_msglevel(struct net_device *dev, u32 level)
  7802. {
  7803. struct bnx2x *bp = netdev_priv(dev);
  7804. if (capable(CAP_NET_ADMIN))
  7805. bp->msglevel = level;
  7806. }
  7807. static int bnx2x_nway_reset(struct net_device *dev)
  7808. {
  7809. struct bnx2x *bp = netdev_priv(dev);
  7810. if (!bp->port.pmf)
  7811. return 0;
  7812. if (netif_running(dev)) {
  7813. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  7814. bnx2x_link_set(bp);
  7815. }
  7816. return 0;
  7817. }
  7818. static u32 bnx2x_get_link(struct net_device *dev)
  7819. {
  7820. struct bnx2x *bp = netdev_priv(dev);
  7821. if (bp->flags & MF_FUNC_DIS)
  7822. return 0;
  7823. return bp->link_vars.link_up;
  7824. }
  7825. static int bnx2x_get_eeprom_len(struct net_device *dev)
  7826. {
  7827. struct bnx2x *bp = netdev_priv(dev);
  7828. return bp->common.flash_size;
  7829. }
  7830. static int bnx2x_acquire_nvram_lock(struct bnx2x *bp)
  7831. {
  7832. int port = BP_PORT(bp);
  7833. int count, i;
  7834. u32 val = 0;
  7835. /* adjust timeout for emulation/FPGA */
  7836. count = NVRAM_TIMEOUT_COUNT;
  7837. if (CHIP_REV_IS_SLOW(bp))
  7838. count *= 100;
  7839. /* request access to nvram interface */
  7840. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7841. (MCPR_NVM_SW_ARB_ARB_REQ_SET1 << port));
  7842. for (i = 0; i < count*10; i++) {
  7843. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  7844. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))
  7845. break;
  7846. udelay(5);
  7847. }
  7848. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port))) {
  7849. DP(BNX2X_MSG_NVM, "cannot get access to nvram interface\n");
  7850. return -EBUSY;
  7851. }
  7852. return 0;
  7853. }
  7854. static int bnx2x_release_nvram_lock(struct bnx2x *bp)
  7855. {
  7856. int port = BP_PORT(bp);
  7857. int count, i;
  7858. u32 val = 0;
  7859. /* adjust timeout for emulation/FPGA */
  7860. count = NVRAM_TIMEOUT_COUNT;
  7861. if (CHIP_REV_IS_SLOW(bp))
  7862. count *= 100;
  7863. /* relinquish nvram interface */
  7864. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  7865. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << port));
  7866. for (i = 0; i < count*10; i++) {
  7867. val = REG_RD(bp, MCP_REG_MCPR_NVM_SW_ARB);
  7868. if (!(val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)))
  7869. break;
  7870. udelay(5);
  7871. }
  7872. if (val & (MCPR_NVM_SW_ARB_ARB_ARB1 << port)) {
  7873. DP(BNX2X_MSG_NVM, "cannot free access to nvram interface\n");
  7874. return -EBUSY;
  7875. }
  7876. return 0;
  7877. }
  7878. static void bnx2x_enable_nvram_access(struct bnx2x *bp)
  7879. {
  7880. u32 val;
  7881. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  7882. /* enable both bits, even on read */
  7883. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  7884. (val | MCPR_NVM_ACCESS_ENABLE_EN |
  7885. MCPR_NVM_ACCESS_ENABLE_WR_EN));
  7886. }
  7887. static void bnx2x_disable_nvram_access(struct bnx2x *bp)
  7888. {
  7889. u32 val;
  7890. val = REG_RD(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE);
  7891. /* disable both bits, even after read */
  7892. REG_WR(bp, MCP_REG_MCPR_NVM_ACCESS_ENABLE,
  7893. (val & ~(MCPR_NVM_ACCESS_ENABLE_EN |
  7894. MCPR_NVM_ACCESS_ENABLE_WR_EN)));
  7895. }
  7896. static int bnx2x_nvram_read_dword(struct bnx2x *bp, u32 offset, __be32 *ret_val,
  7897. u32 cmd_flags)
  7898. {
  7899. int count, i, rc;
  7900. u32 val;
  7901. /* build the command word */
  7902. cmd_flags |= MCPR_NVM_COMMAND_DOIT;
  7903. /* need to clear DONE bit separately */
  7904. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  7905. /* address of the NVRAM to read from */
  7906. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  7907. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  7908. /* issue a read command */
  7909. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  7910. /* adjust timeout for emulation/FPGA */
  7911. count = NVRAM_TIMEOUT_COUNT;
  7912. if (CHIP_REV_IS_SLOW(bp))
  7913. count *= 100;
  7914. /* wait for completion */
  7915. *ret_val = 0;
  7916. rc = -EBUSY;
  7917. for (i = 0; i < count; i++) {
  7918. udelay(5);
  7919. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  7920. if (val & MCPR_NVM_COMMAND_DONE) {
  7921. val = REG_RD(bp, MCP_REG_MCPR_NVM_READ);
  7922. /* we read nvram data in cpu order
  7923. * but ethtool sees it as an array of bytes
  7924. * converting to big-endian will do the work */
  7925. *ret_val = cpu_to_be32(val);
  7926. rc = 0;
  7927. break;
  7928. }
  7929. }
  7930. return rc;
  7931. }
  7932. static int bnx2x_nvram_read(struct bnx2x *bp, u32 offset, u8 *ret_buf,
  7933. int buf_size)
  7934. {
  7935. int rc;
  7936. u32 cmd_flags;
  7937. __be32 val;
  7938. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  7939. DP(BNX2X_MSG_NVM,
  7940. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  7941. offset, buf_size);
  7942. return -EINVAL;
  7943. }
  7944. if (offset + buf_size > bp->common.flash_size) {
  7945. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  7946. " buf_size (0x%x) > flash_size (0x%x)\n",
  7947. offset, buf_size, bp->common.flash_size);
  7948. return -EINVAL;
  7949. }
  7950. /* request access to nvram interface */
  7951. rc = bnx2x_acquire_nvram_lock(bp);
  7952. if (rc)
  7953. return rc;
  7954. /* enable access to nvram interface */
  7955. bnx2x_enable_nvram_access(bp);
  7956. /* read the first word(s) */
  7957. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  7958. while ((buf_size > sizeof(u32)) && (rc == 0)) {
  7959. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  7960. memcpy(ret_buf, &val, 4);
  7961. /* advance to the next dword */
  7962. offset += sizeof(u32);
  7963. ret_buf += sizeof(u32);
  7964. buf_size -= sizeof(u32);
  7965. cmd_flags = 0;
  7966. }
  7967. if (rc == 0) {
  7968. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  7969. rc = bnx2x_nvram_read_dword(bp, offset, &val, cmd_flags);
  7970. memcpy(ret_buf, &val, 4);
  7971. }
  7972. /* disable access to nvram interface */
  7973. bnx2x_disable_nvram_access(bp);
  7974. bnx2x_release_nvram_lock(bp);
  7975. return rc;
  7976. }
  7977. static int bnx2x_get_eeprom(struct net_device *dev,
  7978. struct ethtool_eeprom *eeprom, u8 *eebuf)
  7979. {
  7980. struct bnx2x *bp = netdev_priv(dev);
  7981. int rc;
  7982. if (!netif_running(dev))
  7983. return -EAGAIN;
  7984. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  7985. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  7986. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  7987. eeprom->len, eeprom->len);
  7988. /* parameters already validated in ethtool_get_eeprom */
  7989. rc = bnx2x_nvram_read(bp, eeprom->offset, eebuf, eeprom->len);
  7990. return rc;
  7991. }
  7992. static int bnx2x_nvram_write_dword(struct bnx2x *bp, u32 offset, u32 val,
  7993. u32 cmd_flags)
  7994. {
  7995. int count, i, rc;
  7996. /* build the command word */
  7997. cmd_flags |= MCPR_NVM_COMMAND_DOIT | MCPR_NVM_COMMAND_WR;
  7998. /* need to clear DONE bit separately */
  7999. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, MCPR_NVM_COMMAND_DONE);
  8000. /* write the data */
  8001. REG_WR(bp, MCP_REG_MCPR_NVM_WRITE, val);
  8002. /* address of the NVRAM to write to */
  8003. REG_WR(bp, MCP_REG_MCPR_NVM_ADDR,
  8004. (offset & MCPR_NVM_ADDR_NVM_ADDR_VALUE));
  8005. /* issue the write command */
  8006. REG_WR(bp, MCP_REG_MCPR_NVM_COMMAND, cmd_flags);
  8007. /* adjust timeout for emulation/FPGA */
  8008. count = NVRAM_TIMEOUT_COUNT;
  8009. if (CHIP_REV_IS_SLOW(bp))
  8010. count *= 100;
  8011. /* wait for completion */
  8012. rc = -EBUSY;
  8013. for (i = 0; i < count; i++) {
  8014. udelay(5);
  8015. val = REG_RD(bp, MCP_REG_MCPR_NVM_COMMAND);
  8016. if (val & MCPR_NVM_COMMAND_DONE) {
  8017. rc = 0;
  8018. break;
  8019. }
  8020. }
  8021. return rc;
  8022. }
  8023. #define BYTE_OFFSET(offset) (8 * (offset & 0x03))
  8024. static int bnx2x_nvram_write1(struct bnx2x *bp, u32 offset, u8 *data_buf,
  8025. int buf_size)
  8026. {
  8027. int rc;
  8028. u32 cmd_flags;
  8029. u32 align_offset;
  8030. __be32 val;
  8031. if (offset + buf_size > bp->common.flash_size) {
  8032. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  8033. " buf_size (0x%x) > flash_size (0x%x)\n",
  8034. offset, buf_size, bp->common.flash_size);
  8035. return -EINVAL;
  8036. }
  8037. /* request access to nvram interface */
  8038. rc = bnx2x_acquire_nvram_lock(bp);
  8039. if (rc)
  8040. return rc;
  8041. /* enable access to nvram interface */
  8042. bnx2x_enable_nvram_access(bp);
  8043. cmd_flags = (MCPR_NVM_COMMAND_FIRST | MCPR_NVM_COMMAND_LAST);
  8044. align_offset = (offset & ~0x03);
  8045. rc = bnx2x_nvram_read_dword(bp, align_offset, &val, cmd_flags);
  8046. if (rc == 0) {
  8047. val &= ~(0xff << BYTE_OFFSET(offset));
  8048. val |= (*data_buf << BYTE_OFFSET(offset));
  8049. /* nvram data is returned as an array of bytes
  8050. * convert it back to cpu order */
  8051. val = be32_to_cpu(val);
  8052. rc = bnx2x_nvram_write_dword(bp, align_offset, val,
  8053. cmd_flags);
  8054. }
  8055. /* disable access to nvram interface */
  8056. bnx2x_disable_nvram_access(bp);
  8057. bnx2x_release_nvram_lock(bp);
  8058. return rc;
  8059. }
  8060. static int bnx2x_nvram_write(struct bnx2x *bp, u32 offset, u8 *data_buf,
  8061. int buf_size)
  8062. {
  8063. int rc;
  8064. u32 cmd_flags;
  8065. u32 val;
  8066. u32 written_so_far;
  8067. if (buf_size == 1) /* ethtool */
  8068. return bnx2x_nvram_write1(bp, offset, data_buf, buf_size);
  8069. if ((offset & 0x03) || (buf_size & 0x03) || (buf_size == 0)) {
  8070. DP(BNX2X_MSG_NVM,
  8071. "Invalid parameter: offset 0x%x buf_size 0x%x\n",
  8072. offset, buf_size);
  8073. return -EINVAL;
  8074. }
  8075. if (offset + buf_size > bp->common.flash_size) {
  8076. DP(BNX2X_MSG_NVM, "Invalid parameter: offset (0x%x) +"
  8077. " buf_size (0x%x) > flash_size (0x%x)\n",
  8078. offset, buf_size, bp->common.flash_size);
  8079. return -EINVAL;
  8080. }
  8081. /* request access to nvram interface */
  8082. rc = bnx2x_acquire_nvram_lock(bp);
  8083. if (rc)
  8084. return rc;
  8085. /* enable access to nvram interface */
  8086. bnx2x_enable_nvram_access(bp);
  8087. written_so_far = 0;
  8088. cmd_flags = MCPR_NVM_COMMAND_FIRST;
  8089. while ((written_so_far < buf_size) && (rc == 0)) {
  8090. if (written_so_far == (buf_size - sizeof(u32)))
  8091. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  8092. else if (((offset + 4) % NVRAM_PAGE_SIZE) == 0)
  8093. cmd_flags |= MCPR_NVM_COMMAND_LAST;
  8094. else if ((offset % NVRAM_PAGE_SIZE) == 0)
  8095. cmd_flags |= MCPR_NVM_COMMAND_FIRST;
  8096. memcpy(&val, data_buf, 4);
  8097. rc = bnx2x_nvram_write_dword(bp, offset, val, cmd_flags);
  8098. /* advance to the next dword */
  8099. offset += sizeof(u32);
  8100. data_buf += sizeof(u32);
  8101. written_so_far += sizeof(u32);
  8102. cmd_flags = 0;
  8103. }
  8104. /* disable access to nvram interface */
  8105. bnx2x_disable_nvram_access(bp);
  8106. bnx2x_release_nvram_lock(bp);
  8107. return rc;
  8108. }
  8109. static int bnx2x_set_eeprom(struct net_device *dev,
  8110. struct ethtool_eeprom *eeprom, u8 *eebuf)
  8111. {
  8112. struct bnx2x *bp = netdev_priv(dev);
  8113. int port = BP_PORT(bp);
  8114. int rc = 0;
  8115. if (!netif_running(dev))
  8116. return -EAGAIN;
  8117. DP(BNX2X_MSG_NVM, "ethtool_eeprom: cmd %d\n"
  8118. DP_LEVEL " magic 0x%x offset 0x%x (%d) len 0x%x (%d)\n",
  8119. eeprom->cmd, eeprom->magic, eeprom->offset, eeprom->offset,
  8120. eeprom->len, eeprom->len);
  8121. /* parameters already validated in ethtool_set_eeprom */
  8122. /* PHY eeprom can be accessed only by the PMF */
  8123. if ((eeprom->magic >= 0x50485900) && (eeprom->magic <= 0x504859FF) &&
  8124. !bp->port.pmf)
  8125. return -EINVAL;
  8126. if (eeprom->magic == 0x50485950) {
  8127. /* 'PHYP' (0x50485950): prepare phy for FW upgrade */
  8128. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  8129. bnx2x_acquire_phy_lock(bp);
  8130. rc |= bnx2x_link_reset(&bp->link_params,
  8131. &bp->link_vars, 0);
  8132. if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
  8133. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101)
  8134. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  8135. MISC_REGISTERS_GPIO_HIGH, port);
  8136. bnx2x_release_phy_lock(bp);
  8137. bnx2x_link_report(bp);
  8138. } else if (eeprom->magic == 0x50485952) {
  8139. /* 'PHYR' (0x50485952): re-init link after FW upgrade */
  8140. if (bp->state == BNX2X_STATE_OPEN) {
  8141. bnx2x_acquire_phy_lock(bp);
  8142. rc |= bnx2x_link_reset(&bp->link_params,
  8143. &bp->link_vars, 1);
  8144. rc |= bnx2x_phy_init(&bp->link_params,
  8145. &bp->link_vars);
  8146. bnx2x_release_phy_lock(bp);
  8147. bnx2x_calc_fc_adv(bp);
  8148. }
  8149. } else if (eeprom->magic == 0x53985943) {
  8150. /* 'PHYC' (0x53985943): PHY FW upgrade completed */
  8151. if (XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config) ==
  8152. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_SFX7101) {
  8153. u8 ext_phy_addr =
  8154. XGXS_EXT_PHY_ADDR(bp->link_params.ext_phy_config);
  8155. /* DSP Remove Download Mode */
  8156. bnx2x_set_gpio(bp, MISC_REGISTERS_GPIO_0,
  8157. MISC_REGISTERS_GPIO_LOW, port);
  8158. bnx2x_acquire_phy_lock(bp);
  8159. bnx2x_sfx7101_sp_sw_reset(bp, port, ext_phy_addr);
  8160. /* wait 0.5 sec to allow it to run */
  8161. msleep(500);
  8162. bnx2x_ext_phy_hw_reset(bp, port);
  8163. msleep(500);
  8164. bnx2x_release_phy_lock(bp);
  8165. }
  8166. } else
  8167. rc = bnx2x_nvram_write(bp, eeprom->offset, eebuf, eeprom->len);
  8168. return rc;
  8169. }
  8170. static int bnx2x_get_coalesce(struct net_device *dev,
  8171. struct ethtool_coalesce *coal)
  8172. {
  8173. struct bnx2x *bp = netdev_priv(dev);
  8174. memset(coal, 0, sizeof(struct ethtool_coalesce));
  8175. coal->rx_coalesce_usecs = bp->rx_ticks;
  8176. coal->tx_coalesce_usecs = bp->tx_ticks;
  8177. return 0;
  8178. }
  8179. #define BNX2X_MAX_COALES_TOUT (0xf0*12) /* Maximal coalescing timeout in us */
  8180. static int bnx2x_set_coalesce(struct net_device *dev,
  8181. struct ethtool_coalesce *coal)
  8182. {
  8183. struct bnx2x *bp = netdev_priv(dev);
  8184. bp->rx_ticks = (u16) coal->rx_coalesce_usecs;
  8185. if (bp->rx_ticks > BNX2X_MAX_COALES_TOUT)
  8186. bp->rx_ticks = BNX2X_MAX_COALES_TOUT;
  8187. bp->tx_ticks = (u16) coal->tx_coalesce_usecs;
  8188. if (bp->tx_ticks > BNX2X_MAX_COALES_TOUT)
  8189. bp->tx_ticks = BNX2X_MAX_COALES_TOUT;
  8190. if (netif_running(dev))
  8191. bnx2x_update_coalesce(bp);
  8192. return 0;
  8193. }
  8194. static void bnx2x_get_ringparam(struct net_device *dev,
  8195. struct ethtool_ringparam *ering)
  8196. {
  8197. struct bnx2x *bp = netdev_priv(dev);
  8198. ering->rx_max_pending = MAX_RX_AVAIL;
  8199. ering->rx_mini_max_pending = 0;
  8200. ering->rx_jumbo_max_pending = 0;
  8201. ering->rx_pending = bp->rx_ring_size;
  8202. ering->rx_mini_pending = 0;
  8203. ering->rx_jumbo_pending = 0;
  8204. ering->tx_max_pending = MAX_TX_AVAIL;
  8205. ering->tx_pending = bp->tx_ring_size;
  8206. }
  8207. static int bnx2x_set_ringparam(struct net_device *dev,
  8208. struct ethtool_ringparam *ering)
  8209. {
  8210. struct bnx2x *bp = netdev_priv(dev);
  8211. int rc = 0;
  8212. if ((ering->rx_pending > MAX_RX_AVAIL) ||
  8213. (ering->tx_pending > MAX_TX_AVAIL) ||
  8214. (ering->tx_pending <= MAX_SKB_FRAGS + 4))
  8215. return -EINVAL;
  8216. bp->rx_ring_size = ering->rx_pending;
  8217. bp->tx_ring_size = ering->tx_pending;
  8218. if (netif_running(dev)) {
  8219. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  8220. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  8221. }
  8222. return rc;
  8223. }
  8224. static void bnx2x_get_pauseparam(struct net_device *dev,
  8225. struct ethtool_pauseparam *epause)
  8226. {
  8227. struct bnx2x *bp = netdev_priv(dev);
  8228. epause->autoneg = (bp->link_params.req_flow_ctrl ==
  8229. BNX2X_FLOW_CTRL_AUTO) &&
  8230. (bp->link_params.req_line_speed == SPEED_AUTO_NEG);
  8231. epause->rx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_RX) ==
  8232. BNX2X_FLOW_CTRL_RX);
  8233. epause->tx_pause = ((bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX) ==
  8234. BNX2X_FLOW_CTRL_TX);
  8235. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  8236. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  8237. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  8238. }
  8239. static int bnx2x_set_pauseparam(struct net_device *dev,
  8240. struct ethtool_pauseparam *epause)
  8241. {
  8242. struct bnx2x *bp = netdev_priv(dev);
  8243. if (IS_E1HMF(bp))
  8244. return 0;
  8245. DP(NETIF_MSG_LINK, "ethtool_pauseparam: cmd %d\n"
  8246. DP_LEVEL " autoneg %d rx_pause %d tx_pause %d\n",
  8247. epause->cmd, epause->autoneg, epause->rx_pause, epause->tx_pause);
  8248. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
  8249. if (epause->rx_pause)
  8250. bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_RX;
  8251. if (epause->tx_pause)
  8252. bp->link_params.req_flow_ctrl |= BNX2X_FLOW_CTRL_TX;
  8253. if (bp->link_params.req_flow_ctrl == BNX2X_FLOW_CTRL_AUTO)
  8254. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  8255. if (epause->autoneg) {
  8256. if (!(bp->port.supported & SUPPORTED_Autoneg)) {
  8257. DP(NETIF_MSG_LINK, "autoneg not supported\n");
  8258. return -EINVAL;
  8259. }
  8260. if (bp->link_params.req_line_speed == SPEED_AUTO_NEG)
  8261. bp->link_params.req_flow_ctrl = BNX2X_FLOW_CTRL_AUTO;
  8262. }
  8263. DP(NETIF_MSG_LINK,
  8264. "req_flow_ctrl 0x%x\n", bp->link_params.req_flow_ctrl);
  8265. if (netif_running(dev)) {
  8266. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  8267. bnx2x_link_set(bp);
  8268. }
  8269. return 0;
  8270. }
  8271. static int bnx2x_set_flags(struct net_device *dev, u32 data)
  8272. {
  8273. struct bnx2x *bp = netdev_priv(dev);
  8274. int changed = 0;
  8275. int rc = 0;
  8276. /* TPA requires Rx CSUM offloading */
  8277. if ((data & ETH_FLAG_LRO) && bp->rx_csum) {
  8278. if (!(dev->features & NETIF_F_LRO)) {
  8279. dev->features |= NETIF_F_LRO;
  8280. bp->flags |= TPA_ENABLE_FLAG;
  8281. changed = 1;
  8282. }
  8283. } else if (dev->features & NETIF_F_LRO) {
  8284. dev->features &= ~NETIF_F_LRO;
  8285. bp->flags &= ~TPA_ENABLE_FLAG;
  8286. changed = 1;
  8287. }
  8288. if (changed && netif_running(dev)) {
  8289. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  8290. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  8291. }
  8292. return rc;
  8293. }
  8294. static u32 bnx2x_get_rx_csum(struct net_device *dev)
  8295. {
  8296. struct bnx2x *bp = netdev_priv(dev);
  8297. return bp->rx_csum;
  8298. }
  8299. static int bnx2x_set_rx_csum(struct net_device *dev, u32 data)
  8300. {
  8301. struct bnx2x *bp = netdev_priv(dev);
  8302. int rc = 0;
  8303. bp->rx_csum = data;
  8304. /* Disable TPA, when Rx CSUM is disabled. Otherwise all
  8305. TPA'ed packets will be discarded due to wrong TCP CSUM */
  8306. if (!data) {
  8307. u32 flags = ethtool_op_get_flags(dev);
  8308. rc = bnx2x_set_flags(dev, (flags & ~ETH_FLAG_LRO));
  8309. }
  8310. return rc;
  8311. }
  8312. static int bnx2x_set_tso(struct net_device *dev, u32 data)
  8313. {
  8314. if (data) {
  8315. dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
  8316. dev->features |= NETIF_F_TSO6;
  8317. } else {
  8318. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO_ECN);
  8319. dev->features &= ~NETIF_F_TSO6;
  8320. }
  8321. return 0;
  8322. }
  8323. static const struct {
  8324. char string[ETH_GSTRING_LEN];
  8325. } bnx2x_tests_str_arr[BNX2X_NUM_TESTS] = {
  8326. { "register_test (offline)" },
  8327. { "memory_test (offline)" },
  8328. { "loopback_test (offline)" },
  8329. { "nvram_test (online)" },
  8330. { "interrupt_test (online)" },
  8331. { "link_test (online)" },
  8332. { "idle check (online)" }
  8333. };
  8334. static int bnx2x_test_registers(struct bnx2x *bp)
  8335. {
  8336. int idx, i, rc = -ENODEV;
  8337. u32 wr_val = 0;
  8338. int port = BP_PORT(bp);
  8339. static const struct {
  8340. u32 offset0;
  8341. u32 offset1;
  8342. u32 mask;
  8343. } reg_tbl[] = {
  8344. /* 0 */ { BRB1_REG_PAUSE_LOW_THRESHOLD_0, 4, 0x000003ff },
  8345. { DORQ_REG_DB_ADDR0, 4, 0xffffffff },
  8346. { HC_REG_AGG_INT_0, 4, 0x000003ff },
  8347. { PBF_REG_MAC_IF0_ENABLE, 4, 0x00000001 },
  8348. { PBF_REG_P0_INIT_CRD, 4, 0x000007ff },
  8349. { PRS_REG_CID_PORT_0, 4, 0x00ffffff },
  8350. { PXP2_REG_PSWRQ_CDU0_L2P, 4, 0x000fffff },
  8351. { PXP2_REG_RQ_CDU0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  8352. { PXP2_REG_PSWRQ_TM0_L2P, 4, 0x000fffff },
  8353. { PXP2_REG_RQ_USDM0_EFIRST_MEM_ADDR, 8, 0x0003ffff },
  8354. /* 10 */ { PXP2_REG_PSWRQ_TSDM0_L2P, 4, 0x000fffff },
  8355. { QM_REG_CONNNUM_0, 4, 0x000fffff },
  8356. { TM_REG_LIN0_MAX_ACTIVE_CID, 4, 0x0003ffff },
  8357. { SRC_REG_KEYRSS0_0, 40, 0xffffffff },
  8358. { SRC_REG_KEYRSS0_7, 40, 0xffffffff },
  8359. { XCM_REG_WU_DA_SET_TMR_CNT_FLG_CMD00, 4, 0x00000001 },
  8360. { XCM_REG_WU_DA_CNT_CMD00, 4, 0x00000003 },
  8361. { XCM_REG_GLB_DEL_ACK_MAX_CNT_0, 4, 0x000000ff },
  8362. { NIG_REG_LLH0_T_BIT, 4, 0x00000001 },
  8363. { NIG_REG_EMAC0_IN_EN, 4, 0x00000001 },
  8364. /* 20 */ { NIG_REG_BMAC0_IN_EN, 4, 0x00000001 },
  8365. { NIG_REG_XCM0_OUT_EN, 4, 0x00000001 },
  8366. { NIG_REG_BRB0_OUT_EN, 4, 0x00000001 },
  8367. { NIG_REG_LLH0_XCM_MASK, 4, 0x00000007 },
  8368. { NIG_REG_LLH0_ACPI_PAT_6_LEN, 68, 0x000000ff },
  8369. { NIG_REG_LLH0_ACPI_PAT_0_CRC, 68, 0xffffffff },
  8370. { NIG_REG_LLH0_DEST_MAC_0_0, 160, 0xffffffff },
  8371. { NIG_REG_LLH0_DEST_IP_0_1, 160, 0xffffffff },
  8372. { NIG_REG_LLH0_IPV4_IPV6_0, 160, 0x00000001 },
  8373. { NIG_REG_LLH0_DEST_UDP_0, 160, 0x0000ffff },
  8374. /* 30 */ { NIG_REG_LLH0_DEST_TCP_0, 160, 0x0000ffff },
  8375. { NIG_REG_LLH0_VLAN_ID_0, 160, 0x00000fff },
  8376. { NIG_REG_XGXS_SERDES0_MODE_SEL, 4, 0x00000001 },
  8377. { NIG_REG_LED_CONTROL_OVERRIDE_TRAFFIC_P0, 4, 0x00000001 },
  8378. { NIG_REG_STATUS_INTERRUPT_PORT0, 4, 0x07ffffff },
  8379. { NIG_REG_XGXS0_CTRL_EXTREMOTEMDIOST, 24, 0x00000001 },
  8380. { NIG_REG_SERDES0_CTRL_PHY_ADDR, 16, 0x0000001f },
  8381. { 0xffffffff, 0, 0x00000000 }
  8382. };
  8383. if (!netif_running(bp->dev))
  8384. return rc;
  8385. /* Repeat the test twice:
  8386. First by writing 0x00000000, second by writing 0xffffffff */
  8387. for (idx = 0; idx < 2; idx++) {
  8388. switch (idx) {
  8389. case 0:
  8390. wr_val = 0;
  8391. break;
  8392. case 1:
  8393. wr_val = 0xffffffff;
  8394. break;
  8395. }
  8396. for (i = 0; reg_tbl[i].offset0 != 0xffffffff; i++) {
  8397. u32 offset, mask, save_val, val;
  8398. offset = reg_tbl[i].offset0 + port*reg_tbl[i].offset1;
  8399. mask = reg_tbl[i].mask;
  8400. save_val = REG_RD(bp, offset);
  8401. REG_WR(bp, offset, wr_val);
  8402. val = REG_RD(bp, offset);
  8403. /* Restore the original register's value */
  8404. REG_WR(bp, offset, save_val);
  8405. /* verify that value is as expected value */
  8406. if ((val & mask) != (wr_val & mask))
  8407. goto test_reg_exit;
  8408. }
  8409. }
  8410. rc = 0;
  8411. test_reg_exit:
  8412. return rc;
  8413. }
  8414. static int bnx2x_test_memory(struct bnx2x *bp)
  8415. {
  8416. int i, j, rc = -ENODEV;
  8417. u32 val;
  8418. static const struct {
  8419. u32 offset;
  8420. int size;
  8421. } mem_tbl[] = {
  8422. { CCM_REG_XX_DESCR_TABLE, CCM_REG_XX_DESCR_TABLE_SIZE },
  8423. { CFC_REG_ACTIVITY_COUNTER, CFC_REG_ACTIVITY_COUNTER_SIZE },
  8424. { CFC_REG_LINK_LIST, CFC_REG_LINK_LIST_SIZE },
  8425. { DMAE_REG_CMD_MEM, DMAE_REG_CMD_MEM_SIZE },
  8426. { TCM_REG_XX_DESCR_TABLE, TCM_REG_XX_DESCR_TABLE_SIZE },
  8427. { UCM_REG_XX_DESCR_TABLE, UCM_REG_XX_DESCR_TABLE_SIZE },
  8428. { XCM_REG_XX_DESCR_TABLE, XCM_REG_XX_DESCR_TABLE_SIZE },
  8429. { 0xffffffff, 0 }
  8430. };
  8431. static const struct {
  8432. char *name;
  8433. u32 offset;
  8434. u32 e1_mask;
  8435. u32 e1h_mask;
  8436. } prty_tbl[] = {
  8437. { "CCM_PRTY_STS", CCM_REG_CCM_PRTY_STS, 0x3ffc0, 0 },
  8438. { "CFC_PRTY_STS", CFC_REG_CFC_PRTY_STS, 0x2, 0x2 },
  8439. { "DMAE_PRTY_STS", DMAE_REG_DMAE_PRTY_STS, 0, 0 },
  8440. { "TCM_PRTY_STS", TCM_REG_TCM_PRTY_STS, 0x3ffc0, 0 },
  8441. { "UCM_PRTY_STS", UCM_REG_UCM_PRTY_STS, 0x3ffc0, 0 },
  8442. { "XCM_PRTY_STS", XCM_REG_XCM_PRTY_STS, 0x3ffc1, 0 },
  8443. { NULL, 0xffffffff, 0, 0 }
  8444. };
  8445. if (!netif_running(bp->dev))
  8446. return rc;
  8447. /* Go through all the memories */
  8448. for (i = 0; mem_tbl[i].offset != 0xffffffff; i++)
  8449. for (j = 0; j < mem_tbl[i].size; j++)
  8450. REG_RD(bp, mem_tbl[i].offset + j*4);
  8451. /* Check the parity status */
  8452. for (i = 0; prty_tbl[i].offset != 0xffffffff; i++) {
  8453. val = REG_RD(bp, prty_tbl[i].offset);
  8454. if ((CHIP_IS_E1(bp) && (val & ~(prty_tbl[i].e1_mask))) ||
  8455. (CHIP_IS_E1H(bp) && (val & ~(prty_tbl[i].e1h_mask)))) {
  8456. DP(NETIF_MSG_HW,
  8457. "%s is 0x%x\n", prty_tbl[i].name, val);
  8458. goto test_mem_exit;
  8459. }
  8460. }
  8461. rc = 0;
  8462. test_mem_exit:
  8463. return rc;
  8464. }
  8465. static void bnx2x_wait_for_link(struct bnx2x *bp, u8 link_up)
  8466. {
  8467. int cnt = 1000;
  8468. if (link_up)
  8469. while (bnx2x_link_test(bp) && cnt--)
  8470. msleep(10);
  8471. }
  8472. static int bnx2x_run_loopback(struct bnx2x *bp, int loopback_mode, u8 link_up)
  8473. {
  8474. unsigned int pkt_size, num_pkts, i;
  8475. struct sk_buff *skb;
  8476. unsigned char *packet;
  8477. struct bnx2x_fastpath *fp_rx = &bp->fp[0];
  8478. struct bnx2x_fastpath *fp_tx = &bp->fp[bp->num_rx_queues];
  8479. u16 tx_start_idx, tx_idx;
  8480. u16 rx_start_idx, rx_idx;
  8481. u16 pkt_prod, bd_prod;
  8482. struct sw_tx_bd *tx_buf;
  8483. struct eth_tx_start_bd *tx_start_bd;
  8484. struct eth_tx_parse_bd *pbd = NULL;
  8485. dma_addr_t mapping;
  8486. union eth_rx_cqe *cqe;
  8487. u8 cqe_fp_flags;
  8488. struct sw_rx_bd *rx_buf;
  8489. u16 len;
  8490. int rc = -ENODEV;
  8491. /* check the loopback mode */
  8492. switch (loopback_mode) {
  8493. case BNX2X_PHY_LOOPBACK:
  8494. if (bp->link_params.loopback_mode != LOOPBACK_XGXS_10)
  8495. return -EINVAL;
  8496. break;
  8497. case BNX2X_MAC_LOOPBACK:
  8498. bp->link_params.loopback_mode = LOOPBACK_BMAC;
  8499. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  8500. break;
  8501. default:
  8502. return -EINVAL;
  8503. }
  8504. /* prepare the loopback packet */
  8505. pkt_size = (((bp->dev->mtu < ETH_MAX_PACKET_SIZE) ?
  8506. bp->dev->mtu : ETH_MAX_PACKET_SIZE) + ETH_HLEN);
  8507. skb = netdev_alloc_skb(bp->dev, bp->rx_buf_size);
  8508. if (!skb) {
  8509. rc = -ENOMEM;
  8510. goto test_loopback_exit;
  8511. }
  8512. packet = skb_put(skb, pkt_size);
  8513. memcpy(packet, bp->dev->dev_addr, ETH_ALEN);
  8514. memset(packet + ETH_ALEN, 0, ETH_ALEN);
  8515. memset(packet + 2*ETH_ALEN, 0x77, (ETH_HLEN - 2*ETH_ALEN));
  8516. for (i = ETH_HLEN; i < pkt_size; i++)
  8517. packet[i] = (unsigned char) (i & 0xff);
  8518. /* send the loopback packet */
  8519. num_pkts = 0;
  8520. tx_start_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  8521. rx_start_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  8522. pkt_prod = fp_tx->tx_pkt_prod++;
  8523. tx_buf = &fp_tx->tx_buf_ring[TX_BD(pkt_prod)];
  8524. tx_buf->first_bd = fp_tx->tx_bd_prod;
  8525. tx_buf->skb = skb;
  8526. tx_buf->flags = 0;
  8527. bd_prod = TX_BD(fp_tx->tx_bd_prod);
  8528. tx_start_bd = &fp_tx->tx_desc_ring[bd_prod].start_bd;
  8529. mapping = pci_map_single(bp->pdev, skb->data,
  8530. skb_headlen(skb), PCI_DMA_TODEVICE);
  8531. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  8532. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  8533. tx_start_bd->nbd = cpu_to_le16(2); /* start + pbd */
  8534. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  8535. tx_start_bd->vlan = cpu_to_le16(pkt_prod);
  8536. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  8537. tx_start_bd->general_data = ((UNICAST_ADDRESS <<
  8538. ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT) | 1);
  8539. /* turn on parsing and get a BD */
  8540. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  8541. pbd = &fp_tx->tx_desc_ring[bd_prod].parse_bd;
  8542. memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
  8543. wmb();
  8544. fp_tx->tx_db.data.prod += 2;
  8545. barrier();
  8546. DOORBELL(bp, fp_tx->index - bp->num_rx_queues, fp_tx->tx_db.raw);
  8547. mmiowb();
  8548. num_pkts++;
  8549. fp_tx->tx_bd_prod += 2; /* start + pbd */
  8550. bp->dev->trans_start = jiffies;
  8551. udelay(100);
  8552. tx_idx = le16_to_cpu(*fp_tx->tx_cons_sb);
  8553. if (tx_idx != tx_start_idx + num_pkts)
  8554. goto test_loopback_exit;
  8555. rx_idx = le16_to_cpu(*fp_rx->rx_cons_sb);
  8556. if (rx_idx != rx_start_idx + num_pkts)
  8557. goto test_loopback_exit;
  8558. cqe = &fp_rx->rx_comp_ring[RCQ_BD(fp_rx->rx_comp_cons)];
  8559. cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;
  8560. if (CQE_TYPE(cqe_fp_flags) || (cqe_fp_flags & ETH_RX_ERROR_FALGS))
  8561. goto test_loopback_rx_exit;
  8562. len = le16_to_cpu(cqe->fast_path_cqe.pkt_len);
  8563. if (len != pkt_size)
  8564. goto test_loopback_rx_exit;
  8565. rx_buf = &fp_rx->rx_buf_ring[RX_BD(fp_rx->rx_bd_cons)];
  8566. skb = rx_buf->skb;
  8567. skb_reserve(skb, cqe->fast_path_cqe.placement_offset);
  8568. for (i = ETH_HLEN; i < pkt_size; i++)
  8569. if (*(skb->data + i) != (unsigned char) (i & 0xff))
  8570. goto test_loopback_rx_exit;
  8571. rc = 0;
  8572. test_loopback_rx_exit:
  8573. fp_rx->rx_bd_cons = NEXT_RX_IDX(fp_rx->rx_bd_cons);
  8574. fp_rx->rx_bd_prod = NEXT_RX_IDX(fp_rx->rx_bd_prod);
  8575. fp_rx->rx_comp_cons = NEXT_RCQ_IDX(fp_rx->rx_comp_cons);
  8576. fp_rx->rx_comp_prod = NEXT_RCQ_IDX(fp_rx->rx_comp_prod);
  8577. /* Update producers */
  8578. bnx2x_update_rx_prod(bp, fp_rx, fp_rx->rx_bd_prod, fp_rx->rx_comp_prod,
  8579. fp_rx->rx_sge_prod);
  8580. test_loopback_exit:
  8581. bp->link_params.loopback_mode = LOOPBACK_NONE;
  8582. return rc;
  8583. }
  8584. static int bnx2x_test_loopback(struct bnx2x *bp, u8 link_up)
  8585. {
  8586. int rc = 0, res;
  8587. if (!netif_running(bp->dev))
  8588. return BNX2X_LOOPBACK_FAILED;
  8589. bnx2x_netif_stop(bp, 1);
  8590. bnx2x_acquire_phy_lock(bp);
  8591. res = bnx2x_run_loopback(bp, BNX2X_PHY_LOOPBACK, link_up);
  8592. if (res) {
  8593. DP(NETIF_MSG_PROBE, " PHY loopback failed (res %d)\n", res);
  8594. rc |= BNX2X_PHY_LOOPBACK_FAILED;
  8595. }
  8596. res = bnx2x_run_loopback(bp, BNX2X_MAC_LOOPBACK, link_up);
  8597. if (res) {
  8598. DP(NETIF_MSG_PROBE, " MAC loopback failed (res %d)\n", res);
  8599. rc |= BNX2X_MAC_LOOPBACK_FAILED;
  8600. }
  8601. bnx2x_release_phy_lock(bp);
  8602. bnx2x_netif_start(bp);
  8603. return rc;
  8604. }
  8605. #define CRC32_RESIDUAL 0xdebb20e3
  8606. static int bnx2x_test_nvram(struct bnx2x *bp)
  8607. {
  8608. static const struct {
  8609. int offset;
  8610. int size;
  8611. } nvram_tbl[] = {
  8612. { 0, 0x14 }, /* bootstrap */
  8613. { 0x14, 0xec }, /* dir */
  8614. { 0x100, 0x350 }, /* manuf_info */
  8615. { 0x450, 0xf0 }, /* feature_info */
  8616. { 0x640, 0x64 }, /* upgrade_key_info */
  8617. { 0x6a4, 0x64 },
  8618. { 0x708, 0x70 }, /* manuf_key_info */
  8619. { 0x778, 0x70 },
  8620. { 0, 0 }
  8621. };
  8622. __be32 buf[0x350 / 4];
  8623. u8 *data = (u8 *)buf;
  8624. int i, rc;
  8625. u32 magic, crc;
  8626. rc = bnx2x_nvram_read(bp, 0, data, 4);
  8627. if (rc) {
  8628. DP(NETIF_MSG_PROBE, "magic value read (rc %d)\n", rc);
  8629. goto test_nvram_exit;
  8630. }
  8631. magic = be32_to_cpu(buf[0]);
  8632. if (magic != 0x669955aa) {
  8633. DP(NETIF_MSG_PROBE, "magic value (0x%08x)\n", magic);
  8634. rc = -ENODEV;
  8635. goto test_nvram_exit;
  8636. }
  8637. for (i = 0; nvram_tbl[i].size; i++) {
  8638. rc = bnx2x_nvram_read(bp, nvram_tbl[i].offset, data,
  8639. nvram_tbl[i].size);
  8640. if (rc) {
  8641. DP(NETIF_MSG_PROBE,
  8642. "nvram_tbl[%d] read data (rc %d)\n", i, rc);
  8643. goto test_nvram_exit;
  8644. }
  8645. crc = ether_crc_le(nvram_tbl[i].size, data);
  8646. if (crc != CRC32_RESIDUAL) {
  8647. DP(NETIF_MSG_PROBE,
  8648. "nvram_tbl[%d] crc value (0x%08x)\n", i, crc);
  8649. rc = -ENODEV;
  8650. goto test_nvram_exit;
  8651. }
  8652. }
  8653. test_nvram_exit:
  8654. return rc;
  8655. }
  8656. static int bnx2x_test_intr(struct bnx2x *bp)
  8657. {
  8658. struct mac_configuration_cmd *config = bnx2x_sp(bp, mac_config);
  8659. int i, rc;
  8660. if (!netif_running(bp->dev))
  8661. return -ENODEV;
  8662. config->hdr.length = 0;
  8663. if (CHIP_IS_E1(bp))
  8664. config->hdr.offset = (BP_PORT(bp) ? 32 : 0);
  8665. else
  8666. config->hdr.offset = BP_FUNC(bp);
  8667. config->hdr.client_id = bp->fp->cl_id;
  8668. config->hdr.reserved1 = 0;
  8669. bp->set_mac_pending++;
  8670. smp_wmb();
  8671. rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  8672. U64_HI(bnx2x_sp_mapping(bp, mac_config)),
  8673. U64_LO(bnx2x_sp_mapping(bp, mac_config)), 0);
  8674. if (rc == 0) {
  8675. for (i = 0; i < 10; i++) {
  8676. if (!bp->set_mac_pending)
  8677. break;
  8678. smp_rmb();
  8679. msleep_interruptible(10);
  8680. }
  8681. if (i == 10)
  8682. rc = -ENODEV;
  8683. }
  8684. return rc;
  8685. }
  8686. static void bnx2x_self_test(struct net_device *dev,
  8687. struct ethtool_test *etest, u64 *buf)
  8688. {
  8689. struct bnx2x *bp = netdev_priv(dev);
  8690. memset(buf, 0, sizeof(u64) * BNX2X_NUM_TESTS);
  8691. if (!netif_running(dev))
  8692. return;
  8693. /* offline tests are not supported in MF mode */
  8694. if (IS_E1HMF(bp))
  8695. etest->flags &= ~ETH_TEST_FL_OFFLINE;
  8696. if (etest->flags & ETH_TEST_FL_OFFLINE) {
  8697. int port = BP_PORT(bp);
  8698. u32 val;
  8699. u8 link_up;
  8700. /* save current value of input enable for TX port IF */
  8701. val = REG_RD(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4);
  8702. /* disable input for TX port IF */
  8703. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, 0);
  8704. link_up = (bnx2x_link_test(bp) == 0);
  8705. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  8706. bnx2x_nic_load(bp, LOAD_DIAG);
  8707. /* wait until link state is restored */
  8708. bnx2x_wait_for_link(bp, link_up);
  8709. if (bnx2x_test_registers(bp) != 0) {
  8710. buf[0] = 1;
  8711. etest->flags |= ETH_TEST_FL_FAILED;
  8712. }
  8713. if (bnx2x_test_memory(bp) != 0) {
  8714. buf[1] = 1;
  8715. etest->flags |= ETH_TEST_FL_FAILED;
  8716. }
  8717. buf[2] = bnx2x_test_loopback(bp, link_up);
  8718. if (buf[2] != 0)
  8719. etest->flags |= ETH_TEST_FL_FAILED;
  8720. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  8721. /* restore input for TX port IF */
  8722. REG_WR(bp, NIG_REG_EGRESS_UMP0_IN_EN + port*4, val);
  8723. bnx2x_nic_load(bp, LOAD_NORMAL);
  8724. /* wait until link state is restored */
  8725. bnx2x_wait_for_link(bp, link_up);
  8726. }
  8727. if (bnx2x_test_nvram(bp) != 0) {
  8728. buf[3] = 1;
  8729. etest->flags |= ETH_TEST_FL_FAILED;
  8730. }
  8731. if (bnx2x_test_intr(bp) != 0) {
  8732. buf[4] = 1;
  8733. etest->flags |= ETH_TEST_FL_FAILED;
  8734. }
  8735. if (bp->port.pmf)
  8736. if (bnx2x_link_test(bp) != 0) {
  8737. buf[5] = 1;
  8738. etest->flags |= ETH_TEST_FL_FAILED;
  8739. }
  8740. #ifdef BNX2X_EXTRA_DEBUG
  8741. bnx2x_panic_dump(bp);
  8742. #endif
  8743. }
  8744. static const struct {
  8745. long offset;
  8746. int size;
  8747. u8 string[ETH_GSTRING_LEN];
  8748. } bnx2x_q_stats_arr[BNX2X_NUM_Q_STATS] = {
  8749. /* 1 */ { Q_STATS_OFFSET32(total_bytes_received_hi), 8, "[%d]: rx_bytes" },
  8750. { Q_STATS_OFFSET32(error_bytes_received_hi),
  8751. 8, "[%d]: rx_error_bytes" },
  8752. { Q_STATS_OFFSET32(total_unicast_packets_received_hi),
  8753. 8, "[%d]: rx_ucast_packets" },
  8754. { Q_STATS_OFFSET32(total_multicast_packets_received_hi),
  8755. 8, "[%d]: rx_mcast_packets" },
  8756. { Q_STATS_OFFSET32(total_broadcast_packets_received_hi),
  8757. 8, "[%d]: rx_bcast_packets" },
  8758. { Q_STATS_OFFSET32(no_buff_discard_hi), 8, "[%d]: rx_discards" },
  8759. { Q_STATS_OFFSET32(rx_err_discard_pkt),
  8760. 4, "[%d]: rx_phy_ip_err_discards"},
  8761. { Q_STATS_OFFSET32(rx_skb_alloc_failed),
  8762. 4, "[%d]: rx_skb_alloc_discard" },
  8763. { Q_STATS_OFFSET32(hw_csum_err), 4, "[%d]: rx_csum_offload_errors" },
  8764. /* 10 */{ Q_STATS_OFFSET32(total_bytes_transmitted_hi), 8, "[%d]: tx_bytes" },
  8765. { Q_STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  8766. 8, "[%d]: tx_packets" }
  8767. };
  8768. static const struct {
  8769. long offset;
  8770. int size;
  8771. u32 flags;
  8772. #define STATS_FLAGS_PORT 1
  8773. #define STATS_FLAGS_FUNC 2
  8774. #define STATS_FLAGS_BOTH (STATS_FLAGS_FUNC | STATS_FLAGS_PORT)
  8775. u8 string[ETH_GSTRING_LEN];
  8776. } bnx2x_stats_arr[BNX2X_NUM_STATS] = {
  8777. /* 1 */ { STATS_OFFSET32(total_bytes_received_hi),
  8778. 8, STATS_FLAGS_BOTH, "rx_bytes" },
  8779. { STATS_OFFSET32(error_bytes_received_hi),
  8780. 8, STATS_FLAGS_BOTH, "rx_error_bytes" },
  8781. { STATS_OFFSET32(total_unicast_packets_received_hi),
  8782. 8, STATS_FLAGS_BOTH, "rx_ucast_packets" },
  8783. { STATS_OFFSET32(total_multicast_packets_received_hi),
  8784. 8, STATS_FLAGS_BOTH, "rx_mcast_packets" },
  8785. { STATS_OFFSET32(total_broadcast_packets_received_hi),
  8786. 8, STATS_FLAGS_BOTH, "rx_bcast_packets" },
  8787. { STATS_OFFSET32(rx_stat_dot3statsfcserrors_hi),
  8788. 8, STATS_FLAGS_PORT, "rx_crc_errors" },
  8789. { STATS_OFFSET32(rx_stat_dot3statsalignmenterrors_hi),
  8790. 8, STATS_FLAGS_PORT, "rx_align_errors" },
  8791. { STATS_OFFSET32(rx_stat_etherstatsundersizepkts_hi),
  8792. 8, STATS_FLAGS_PORT, "rx_undersize_packets" },
  8793. { STATS_OFFSET32(etherstatsoverrsizepkts_hi),
  8794. 8, STATS_FLAGS_PORT, "rx_oversize_packets" },
  8795. /* 10 */{ STATS_OFFSET32(rx_stat_etherstatsfragments_hi),
  8796. 8, STATS_FLAGS_PORT, "rx_fragments" },
  8797. { STATS_OFFSET32(rx_stat_etherstatsjabbers_hi),
  8798. 8, STATS_FLAGS_PORT, "rx_jabbers" },
  8799. { STATS_OFFSET32(no_buff_discard_hi),
  8800. 8, STATS_FLAGS_BOTH, "rx_discards" },
  8801. { STATS_OFFSET32(mac_filter_discard),
  8802. 4, STATS_FLAGS_PORT, "rx_filtered_packets" },
  8803. { STATS_OFFSET32(xxoverflow_discard),
  8804. 4, STATS_FLAGS_PORT, "rx_fw_discards" },
  8805. { STATS_OFFSET32(brb_drop_hi),
  8806. 8, STATS_FLAGS_PORT, "rx_brb_discard" },
  8807. { STATS_OFFSET32(brb_truncate_hi),
  8808. 8, STATS_FLAGS_PORT, "rx_brb_truncate" },
  8809. { STATS_OFFSET32(pause_frames_received_hi),
  8810. 8, STATS_FLAGS_PORT, "rx_pause_frames" },
  8811. { STATS_OFFSET32(rx_stat_maccontrolframesreceived_hi),
  8812. 8, STATS_FLAGS_PORT, "rx_mac_ctrl_frames" },
  8813. { STATS_OFFSET32(nig_timer_max),
  8814. 4, STATS_FLAGS_PORT, "rx_constant_pause_events" },
  8815. /* 20 */{ STATS_OFFSET32(rx_err_discard_pkt),
  8816. 4, STATS_FLAGS_BOTH, "rx_phy_ip_err_discards"},
  8817. { STATS_OFFSET32(rx_skb_alloc_failed),
  8818. 4, STATS_FLAGS_BOTH, "rx_skb_alloc_discard" },
  8819. { STATS_OFFSET32(hw_csum_err),
  8820. 4, STATS_FLAGS_BOTH, "rx_csum_offload_errors" },
  8821. { STATS_OFFSET32(total_bytes_transmitted_hi),
  8822. 8, STATS_FLAGS_BOTH, "tx_bytes" },
  8823. { STATS_OFFSET32(tx_stat_ifhcoutbadoctets_hi),
  8824. 8, STATS_FLAGS_PORT, "tx_error_bytes" },
  8825. { STATS_OFFSET32(total_unicast_packets_transmitted_hi),
  8826. 8, STATS_FLAGS_BOTH, "tx_packets" },
  8827. { STATS_OFFSET32(tx_stat_dot3statsinternalmactransmiterrors_hi),
  8828. 8, STATS_FLAGS_PORT, "tx_mac_errors" },
  8829. { STATS_OFFSET32(rx_stat_dot3statscarriersenseerrors_hi),
  8830. 8, STATS_FLAGS_PORT, "tx_carrier_errors" },
  8831. { STATS_OFFSET32(tx_stat_dot3statssinglecollisionframes_hi),
  8832. 8, STATS_FLAGS_PORT, "tx_single_collisions" },
  8833. { STATS_OFFSET32(tx_stat_dot3statsmultiplecollisionframes_hi),
  8834. 8, STATS_FLAGS_PORT, "tx_multi_collisions" },
  8835. /* 30 */{ STATS_OFFSET32(tx_stat_dot3statsdeferredtransmissions_hi),
  8836. 8, STATS_FLAGS_PORT, "tx_deferred" },
  8837. { STATS_OFFSET32(tx_stat_dot3statsexcessivecollisions_hi),
  8838. 8, STATS_FLAGS_PORT, "tx_excess_collisions" },
  8839. { STATS_OFFSET32(tx_stat_dot3statslatecollisions_hi),
  8840. 8, STATS_FLAGS_PORT, "tx_late_collisions" },
  8841. { STATS_OFFSET32(tx_stat_etherstatscollisions_hi),
  8842. 8, STATS_FLAGS_PORT, "tx_total_collisions" },
  8843. { STATS_OFFSET32(tx_stat_etherstatspkts64octets_hi),
  8844. 8, STATS_FLAGS_PORT, "tx_64_byte_packets" },
  8845. { STATS_OFFSET32(tx_stat_etherstatspkts65octetsto127octets_hi),
  8846. 8, STATS_FLAGS_PORT, "tx_65_to_127_byte_packets" },
  8847. { STATS_OFFSET32(tx_stat_etherstatspkts128octetsto255octets_hi),
  8848. 8, STATS_FLAGS_PORT, "tx_128_to_255_byte_packets" },
  8849. { STATS_OFFSET32(tx_stat_etherstatspkts256octetsto511octets_hi),
  8850. 8, STATS_FLAGS_PORT, "tx_256_to_511_byte_packets" },
  8851. { STATS_OFFSET32(tx_stat_etherstatspkts512octetsto1023octets_hi),
  8852. 8, STATS_FLAGS_PORT, "tx_512_to_1023_byte_packets" },
  8853. { STATS_OFFSET32(etherstatspkts1024octetsto1522octets_hi),
  8854. 8, STATS_FLAGS_PORT, "tx_1024_to_1522_byte_packets" },
  8855. /* 40 */{ STATS_OFFSET32(etherstatspktsover1522octets_hi),
  8856. 8, STATS_FLAGS_PORT, "tx_1523_to_9022_byte_packets" },
  8857. { STATS_OFFSET32(pause_frames_sent_hi),
  8858. 8, STATS_FLAGS_PORT, "tx_pause_frames" }
  8859. };
  8860. #define IS_PORT_STAT(i) \
  8861. ((bnx2x_stats_arr[i].flags & STATS_FLAGS_BOTH) == STATS_FLAGS_PORT)
  8862. #define IS_FUNC_STAT(i) (bnx2x_stats_arr[i].flags & STATS_FLAGS_FUNC)
  8863. #define IS_E1HMF_MODE_STAT(bp) \
  8864. (IS_E1HMF(bp) && !(bp->msglevel & BNX2X_MSG_STATS))
  8865. static int bnx2x_get_sset_count(struct net_device *dev, int stringset)
  8866. {
  8867. struct bnx2x *bp = netdev_priv(dev);
  8868. int i, num_stats;
  8869. switch(stringset) {
  8870. case ETH_SS_STATS:
  8871. if (is_multi(bp)) {
  8872. num_stats = BNX2X_NUM_Q_STATS * bp->num_rx_queues;
  8873. if (!IS_E1HMF_MODE_STAT(bp))
  8874. num_stats += BNX2X_NUM_STATS;
  8875. } else {
  8876. if (IS_E1HMF_MODE_STAT(bp)) {
  8877. num_stats = 0;
  8878. for (i = 0; i < BNX2X_NUM_STATS; i++)
  8879. if (IS_FUNC_STAT(i))
  8880. num_stats++;
  8881. } else
  8882. num_stats = BNX2X_NUM_STATS;
  8883. }
  8884. return num_stats;
  8885. case ETH_SS_TEST:
  8886. return BNX2X_NUM_TESTS;
  8887. default:
  8888. return -EINVAL;
  8889. }
  8890. }
  8891. static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
  8892. {
  8893. struct bnx2x *bp = netdev_priv(dev);
  8894. int i, j, k;
  8895. switch (stringset) {
  8896. case ETH_SS_STATS:
  8897. if (is_multi(bp)) {
  8898. k = 0;
  8899. for_each_rx_queue(bp, i) {
  8900. for (j = 0; j < BNX2X_NUM_Q_STATS; j++)
  8901. sprintf(buf + (k + j)*ETH_GSTRING_LEN,
  8902. bnx2x_q_stats_arr[j].string, i);
  8903. k += BNX2X_NUM_Q_STATS;
  8904. }
  8905. if (IS_E1HMF_MODE_STAT(bp))
  8906. break;
  8907. for (j = 0; j < BNX2X_NUM_STATS; j++)
  8908. strcpy(buf + (k + j)*ETH_GSTRING_LEN,
  8909. bnx2x_stats_arr[j].string);
  8910. } else {
  8911. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  8912. if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
  8913. continue;
  8914. strcpy(buf + j*ETH_GSTRING_LEN,
  8915. bnx2x_stats_arr[i].string);
  8916. j++;
  8917. }
  8918. }
  8919. break;
  8920. case ETH_SS_TEST:
  8921. memcpy(buf, bnx2x_tests_str_arr, sizeof(bnx2x_tests_str_arr));
  8922. break;
  8923. }
  8924. }
  8925. static void bnx2x_get_ethtool_stats(struct net_device *dev,
  8926. struct ethtool_stats *stats, u64 *buf)
  8927. {
  8928. struct bnx2x *bp = netdev_priv(dev);
  8929. u32 *hw_stats, *offset;
  8930. int i, j, k;
  8931. if (is_multi(bp)) {
  8932. k = 0;
  8933. for_each_rx_queue(bp, i) {
  8934. hw_stats = (u32 *)&bp->fp[i].eth_q_stats;
  8935. for (j = 0; j < BNX2X_NUM_Q_STATS; j++) {
  8936. if (bnx2x_q_stats_arr[j].size == 0) {
  8937. /* skip this counter */
  8938. buf[k + j] = 0;
  8939. continue;
  8940. }
  8941. offset = (hw_stats +
  8942. bnx2x_q_stats_arr[j].offset);
  8943. if (bnx2x_q_stats_arr[j].size == 4) {
  8944. /* 4-byte counter */
  8945. buf[k + j] = (u64) *offset;
  8946. continue;
  8947. }
  8948. /* 8-byte counter */
  8949. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  8950. }
  8951. k += BNX2X_NUM_Q_STATS;
  8952. }
  8953. if (IS_E1HMF_MODE_STAT(bp))
  8954. return;
  8955. hw_stats = (u32 *)&bp->eth_stats;
  8956. for (j = 0; j < BNX2X_NUM_STATS; j++) {
  8957. if (bnx2x_stats_arr[j].size == 0) {
  8958. /* skip this counter */
  8959. buf[k + j] = 0;
  8960. continue;
  8961. }
  8962. offset = (hw_stats + bnx2x_stats_arr[j].offset);
  8963. if (bnx2x_stats_arr[j].size == 4) {
  8964. /* 4-byte counter */
  8965. buf[k + j] = (u64) *offset;
  8966. continue;
  8967. }
  8968. /* 8-byte counter */
  8969. buf[k + j] = HILO_U64(*offset, *(offset + 1));
  8970. }
  8971. } else {
  8972. hw_stats = (u32 *)&bp->eth_stats;
  8973. for (i = 0, j = 0; i < BNX2X_NUM_STATS; i++) {
  8974. if (IS_E1HMF_MODE_STAT(bp) && IS_PORT_STAT(i))
  8975. continue;
  8976. if (bnx2x_stats_arr[i].size == 0) {
  8977. /* skip this counter */
  8978. buf[j] = 0;
  8979. j++;
  8980. continue;
  8981. }
  8982. offset = (hw_stats + bnx2x_stats_arr[i].offset);
  8983. if (bnx2x_stats_arr[i].size == 4) {
  8984. /* 4-byte counter */
  8985. buf[j] = (u64) *offset;
  8986. j++;
  8987. continue;
  8988. }
  8989. /* 8-byte counter */
  8990. buf[j] = HILO_U64(*offset, *(offset + 1));
  8991. j++;
  8992. }
  8993. }
  8994. }
  8995. static int bnx2x_phys_id(struct net_device *dev, u32 data)
  8996. {
  8997. struct bnx2x *bp = netdev_priv(dev);
  8998. int i;
  8999. if (!netif_running(dev))
  9000. return 0;
  9001. if (!bp->port.pmf)
  9002. return 0;
  9003. if (data == 0)
  9004. data = 2;
  9005. for (i = 0; i < (data * 2); i++) {
  9006. if ((i % 2) == 0)
  9007. bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
  9008. SPEED_1000);
  9009. else
  9010. bnx2x_set_led(&bp->link_params, LED_MODE_OFF, 0);
  9011. msleep_interruptible(500);
  9012. if (signal_pending(current))
  9013. break;
  9014. }
  9015. if (bp->link_vars.link_up)
  9016. bnx2x_set_led(&bp->link_params, LED_MODE_OPER,
  9017. bp->link_vars.line_speed);
  9018. return 0;
  9019. }
  9020. static const struct ethtool_ops bnx2x_ethtool_ops = {
  9021. .get_settings = bnx2x_get_settings,
  9022. .set_settings = bnx2x_set_settings,
  9023. .get_drvinfo = bnx2x_get_drvinfo,
  9024. .get_regs_len = bnx2x_get_regs_len,
  9025. .get_regs = bnx2x_get_regs,
  9026. .get_wol = bnx2x_get_wol,
  9027. .set_wol = bnx2x_set_wol,
  9028. .get_msglevel = bnx2x_get_msglevel,
  9029. .set_msglevel = bnx2x_set_msglevel,
  9030. .nway_reset = bnx2x_nway_reset,
  9031. .get_link = bnx2x_get_link,
  9032. .get_eeprom_len = bnx2x_get_eeprom_len,
  9033. .get_eeprom = bnx2x_get_eeprom,
  9034. .set_eeprom = bnx2x_set_eeprom,
  9035. .get_coalesce = bnx2x_get_coalesce,
  9036. .set_coalesce = bnx2x_set_coalesce,
  9037. .get_ringparam = bnx2x_get_ringparam,
  9038. .set_ringparam = bnx2x_set_ringparam,
  9039. .get_pauseparam = bnx2x_get_pauseparam,
  9040. .set_pauseparam = bnx2x_set_pauseparam,
  9041. .get_rx_csum = bnx2x_get_rx_csum,
  9042. .set_rx_csum = bnx2x_set_rx_csum,
  9043. .get_tx_csum = ethtool_op_get_tx_csum,
  9044. .set_tx_csum = ethtool_op_set_tx_hw_csum,
  9045. .set_flags = bnx2x_set_flags,
  9046. .get_flags = ethtool_op_get_flags,
  9047. .get_sg = ethtool_op_get_sg,
  9048. .set_sg = ethtool_op_set_sg,
  9049. .get_tso = ethtool_op_get_tso,
  9050. .set_tso = bnx2x_set_tso,
  9051. .self_test = bnx2x_self_test,
  9052. .get_sset_count = bnx2x_get_sset_count,
  9053. .get_strings = bnx2x_get_strings,
  9054. .phys_id = bnx2x_phys_id,
  9055. .get_ethtool_stats = bnx2x_get_ethtool_stats,
  9056. };
  9057. /* end of ethtool_ops */
  9058. /****************************************************************************
  9059. * General service functions
  9060. ****************************************************************************/
  9061. static int bnx2x_set_power_state(struct bnx2x *bp, pci_power_t state)
  9062. {
  9063. u16 pmcsr;
  9064. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmcsr);
  9065. switch (state) {
  9066. case PCI_D0:
  9067. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  9068. ((pmcsr & ~PCI_PM_CTRL_STATE_MASK) |
  9069. PCI_PM_CTRL_PME_STATUS));
  9070. if (pmcsr & PCI_PM_CTRL_STATE_MASK)
  9071. /* delay required during transition out of D3hot */
  9072. msleep(20);
  9073. break;
  9074. case PCI_D3hot:
  9075. pmcsr &= ~PCI_PM_CTRL_STATE_MASK;
  9076. pmcsr |= 3;
  9077. if (bp->wol)
  9078. pmcsr |= PCI_PM_CTRL_PME_ENABLE;
  9079. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL,
  9080. pmcsr);
  9081. /* No more memory access after this point until
  9082. * device is brought back to D0.
  9083. */
  9084. break;
  9085. default:
  9086. return -EINVAL;
  9087. }
  9088. return 0;
  9089. }
  9090. static inline int bnx2x_has_rx_work(struct bnx2x_fastpath *fp)
  9091. {
  9092. u16 rx_cons_sb;
  9093. /* Tell compiler that status block fields can change */
  9094. barrier();
  9095. rx_cons_sb = le16_to_cpu(*fp->rx_cons_sb);
  9096. if ((rx_cons_sb & MAX_RCQ_DESC_CNT) == MAX_RCQ_DESC_CNT)
  9097. rx_cons_sb++;
  9098. return (fp->rx_comp_cons != rx_cons_sb);
  9099. }
  9100. /*
  9101. * net_device service functions
  9102. */
  9103. static int bnx2x_poll(struct napi_struct *napi, int budget)
  9104. {
  9105. struct bnx2x_fastpath *fp = container_of(napi, struct bnx2x_fastpath,
  9106. napi);
  9107. struct bnx2x *bp = fp->bp;
  9108. int work_done = 0;
  9109. #ifdef BNX2X_STOP_ON_ERROR
  9110. if (unlikely(bp->panic))
  9111. goto poll_panic;
  9112. #endif
  9113. prefetch(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb);
  9114. prefetch((char *)(fp->rx_buf_ring[RX_BD(fp->rx_bd_cons)].skb) + 256);
  9115. bnx2x_update_fpsb_idx(fp);
  9116. if (bnx2x_has_rx_work(fp)) {
  9117. work_done = bnx2x_rx_int(fp, budget);
  9118. /* must not complete if we consumed full budget */
  9119. if (work_done >= budget)
  9120. goto poll_again;
  9121. }
  9122. /* bnx2x_has_rx_work() reads the status block, thus we need to
  9123. * ensure that status block indices have been actually read
  9124. * (bnx2x_update_fpsb_idx) prior to this check (bnx2x_has_rx_work)
  9125. * so that we won't write the "newer" value of the status block to IGU
  9126. * (if there was a DMA right after bnx2x_has_rx_work and
  9127. * if there is no rmb, the memory reading (bnx2x_update_fpsb_idx)
  9128. * may be postponed to right before bnx2x_ack_sb). In this case
  9129. * there will never be another interrupt until there is another update
  9130. * of the status block, while there is still unhandled work.
  9131. */
  9132. rmb();
  9133. if (!bnx2x_has_rx_work(fp)) {
  9134. #ifdef BNX2X_STOP_ON_ERROR
  9135. poll_panic:
  9136. #endif
  9137. napi_complete(napi);
  9138. bnx2x_ack_sb(bp, fp->sb_id, USTORM_ID,
  9139. le16_to_cpu(fp->fp_u_idx), IGU_INT_NOP, 1);
  9140. bnx2x_ack_sb(bp, fp->sb_id, CSTORM_ID,
  9141. le16_to_cpu(fp->fp_c_idx), IGU_INT_ENABLE, 1);
  9142. }
  9143. poll_again:
  9144. return work_done;
  9145. }
  9146. /* we split the first BD into headers and data BDs
  9147. * to ease the pain of our fellow microcode engineers
  9148. * we use one mapping for both BDs
  9149. * So far this has only been observed to happen
  9150. * in Other Operating Systems(TM)
  9151. */
  9152. static noinline u16 bnx2x_tx_split(struct bnx2x *bp,
  9153. struct bnx2x_fastpath *fp,
  9154. struct sw_tx_bd *tx_buf,
  9155. struct eth_tx_start_bd **tx_bd, u16 hlen,
  9156. u16 bd_prod, int nbd)
  9157. {
  9158. struct eth_tx_start_bd *h_tx_bd = *tx_bd;
  9159. struct eth_tx_bd *d_tx_bd;
  9160. dma_addr_t mapping;
  9161. int old_len = le16_to_cpu(h_tx_bd->nbytes);
  9162. /* first fix first BD */
  9163. h_tx_bd->nbd = cpu_to_le16(nbd);
  9164. h_tx_bd->nbytes = cpu_to_le16(hlen);
  9165. DP(NETIF_MSG_TX_QUEUED, "TSO split header size is %d "
  9166. "(%x:%x) nbd %d\n", h_tx_bd->nbytes, h_tx_bd->addr_hi,
  9167. h_tx_bd->addr_lo, h_tx_bd->nbd);
  9168. /* now get a new data BD
  9169. * (after the pbd) and fill it */
  9170. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  9171. d_tx_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
  9172. mapping = HILO_U64(le32_to_cpu(h_tx_bd->addr_hi),
  9173. le32_to_cpu(h_tx_bd->addr_lo)) + hlen;
  9174. d_tx_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  9175. d_tx_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  9176. d_tx_bd->nbytes = cpu_to_le16(old_len - hlen);
  9177. /* this marks the BD as one that has no individual mapping */
  9178. tx_buf->flags |= BNX2X_TSO_SPLIT_BD;
  9179. DP(NETIF_MSG_TX_QUEUED,
  9180. "TSO split data size is %d (%x:%x)\n",
  9181. d_tx_bd->nbytes, d_tx_bd->addr_hi, d_tx_bd->addr_lo);
  9182. /* update tx_bd */
  9183. *tx_bd = (struct eth_tx_start_bd *)d_tx_bd;
  9184. return bd_prod;
  9185. }
  9186. static inline u16 bnx2x_csum_fix(unsigned char *t_header, u16 csum, s8 fix)
  9187. {
  9188. if (fix > 0)
  9189. csum = (u16) ~csum_fold(csum_sub(csum,
  9190. csum_partial(t_header - fix, fix, 0)));
  9191. else if (fix < 0)
  9192. csum = (u16) ~csum_fold(csum_add(csum,
  9193. csum_partial(t_header, -fix, 0)));
  9194. return swab16(csum);
  9195. }
  9196. static inline u32 bnx2x_xmit_type(struct bnx2x *bp, struct sk_buff *skb)
  9197. {
  9198. u32 rc;
  9199. if (skb->ip_summed != CHECKSUM_PARTIAL)
  9200. rc = XMIT_PLAIN;
  9201. else {
  9202. if (skb->protocol == htons(ETH_P_IPV6)) {
  9203. rc = XMIT_CSUM_V6;
  9204. if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP)
  9205. rc |= XMIT_CSUM_TCP;
  9206. } else {
  9207. rc = XMIT_CSUM_V4;
  9208. if (ip_hdr(skb)->protocol == IPPROTO_TCP)
  9209. rc |= XMIT_CSUM_TCP;
  9210. }
  9211. }
  9212. if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV4)
  9213. rc |= (XMIT_GSO_V4 | XMIT_CSUM_V4 | XMIT_CSUM_TCP);
  9214. else if (skb_shinfo(skb)->gso_type & SKB_GSO_TCPV6)
  9215. rc |= (XMIT_GSO_V6 | XMIT_CSUM_TCP | XMIT_CSUM_V6);
  9216. return rc;
  9217. }
  9218. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  9219. /* check if packet requires linearization (packet is too fragmented)
  9220. no need to check fragmentation if page size > 8K (there will be no
  9221. violation to FW restrictions) */
  9222. static int bnx2x_pkt_req_lin(struct bnx2x *bp, struct sk_buff *skb,
  9223. u32 xmit_type)
  9224. {
  9225. int to_copy = 0;
  9226. int hlen = 0;
  9227. int first_bd_sz = 0;
  9228. /* 3 = 1 (for linear data BD) + 2 (for PBD and last BD) */
  9229. if (skb_shinfo(skb)->nr_frags >= (MAX_FETCH_BD - 3)) {
  9230. if (xmit_type & XMIT_GSO) {
  9231. unsigned short lso_mss = skb_shinfo(skb)->gso_size;
  9232. /* Check if LSO packet needs to be copied:
  9233. 3 = 1 (for headers BD) + 2 (for PBD and last BD) */
  9234. int wnd_size = MAX_FETCH_BD - 3;
  9235. /* Number of windows to check */
  9236. int num_wnds = skb_shinfo(skb)->nr_frags - wnd_size;
  9237. int wnd_idx = 0;
  9238. int frag_idx = 0;
  9239. u32 wnd_sum = 0;
  9240. /* Headers length */
  9241. hlen = (int)(skb_transport_header(skb) - skb->data) +
  9242. tcp_hdrlen(skb);
  9243. /* Amount of data (w/o headers) on linear part of SKB*/
  9244. first_bd_sz = skb_headlen(skb) - hlen;
  9245. wnd_sum = first_bd_sz;
  9246. /* Calculate the first sum - it's special */
  9247. for (frag_idx = 0; frag_idx < wnd_size - 1; frag_idx++)
  9248. wnd_sum +=
  9249. skb_shinfo(skb)->frags[frag_idx].size;
  9250. /* If there was data on linear skb data - check it */
  9251. if (first_bd_sz > 0) {
  9252. if (unlikely(wnd_sum < lso_mss)) {
  9253. to_copy = 1;
  9254. goto exit_lbl;
  9255. }
  9256. wnd_sum -= first_bd_sz;
  9257. }
  9258. /* Others are easier: run through the frag list and
  9259. check all windows */
  9260. for (wnd_idx = 0; wnd_idx <= num_wnds; wnd_idx++) {
  9261. wnd_sum +=
  9262. skb_shinfo(skb)->frags[wnd_idx + wnd_size - 1].size;
  9263. if (unlikely(wnd_sum < lso_mss)) {
  9264. to_copy = 1;
  9265. break;
  9266. }
  9267. wnd_sum -=
  9268. skb_shinfo(skb)->frags[wnd_idx].size;
  9269. }
  9270. } else {
  9271. /* in non-LSO too fragmented packet should always
  9272. be linearized */
  9273. to_copy = 1;
  9274. }
  9275. }
  9276. exit_lbl:
  9277. if (unlikely(to_copy))
  9278. DP(NETIF_MSG_TX_QUEUED,
  9279. "Linearization IS REQUIRED for %s packet. "
  9280. "num_frags %d hlen %d first_bd_sz %d\n",
  9281. (xmit_type & XMIT_GSO) ? "LSO" : "non-LSO",
  9282. skb_shinfo(skb)->nr_frags, hlen, first_bd_sz);
  9283. return to_copy;
  9284. }
  9285. #endif
  9286. /* called with netif_tx_lock
  9287. * bnx2x_tx_int() runs without netif_tx_lock unless it needs to call
  9288. * netif_wake_queue()
  9289. */
  9290. static netdev_tx_t bnx2x_start_xmit(struct sk_buff *skb, struct net_device *dev)
  9291. {
  9292. struct bnx2x *bp = netdev_priv(dev);
  9293. struct bnx2x_fastpath *fp, *fp_stat;
  9294. struct netdev_queue *txq;
  9295. struct sw_tx_bd *tx_buf;
  9296. struct eth_tx_start_bd *tx_start_bd;
  9297. struct eth_tx_bd *tx_data_bd, *total_pkt_bd = NULL;
  9298. struct eth_tx_parse_bd *pbd = NULL;
  9299. u16 pkt_prod, bd_prod;
  9300. int nbd, fp_index;
  9301. dma_addr_t mapping;
  9302. u32 xmit_type = bnx2x_xmit_type(bp, skb);
  9303. int i;
  9304. u8 hlen = 0;
  9305. __le16 pkt_size = 0;
  9306. #ifdef BNX2X_STOP_ON_ERROR
  9307. if (unlikely(bp->panic))
  9308. return NETDEV_TX_BUSY;
  9309. #endif
  9310. fp_index = skb_get_queue_mapping(skb);
  9311. txq = netdev_get_tx_queue(dev, fp_index);
  9312. fp = &bp->fp[fp_index + bp->num_rx_queues];
  9313. fp_stat = &bp->fp[fp_index];
  9314. if (unlikely(bnx2x_tx_avail(fp) < (skb_shinfo(skb)->nr_frags + 3))) {
  9315. fp_stat->eth_q_stats.driver_xoff++;
  9316. netif_tx_stop_queue(txq);
  9317. BNX2X_ERR("BUG! Tx ring full when queue awake!\n");
  9318. return NETDEV_TX_BUSY;
  9319. }
  9320. DP(NETIF_MSG_TX_QUEUED, "SKB: summed %x protocol %x protocol(%x,%x)"
  9321. " gso type %x xmit_type %x\n",
  9322. skb->ip_summed, skb->protocol, ipv6_hdr(skb)->nexthdr,
  9323. ip_hdr(skb)->protocol, skb_shinfo(skb)->gso_type, xmit_type);
  9324. #if (MAX_SKB_FRAGS >= MAX_FETCH_BD - 3)
  9325. /* First, check if we need to linearize the skb (due to FW
  9326. restrictions). No need to check fragmentation if page size > 8K
  9327. (there will be no violation to FW restrictions) */
  9328. if (bnx2x_pkt_req_lin(bp, skb, xmit_type)) {
  9329. /* Statistics of linearization */
  9330. bp->lin_cnt++;
  9331. if (skb_linearize(skb) != 0) {
  9332. DP(NETIF_MSG_TX_QUEUED, "SKB linearization failed - "
  9333. "silently dropping this SKB\n");
  9334. dev_kfree_skb_any(skb);
  9335. return NETDEV_TX_OK;
  9336. }
  9337. }
  9338. #endif
  9339. /*
  9340. Please read carefully. First we use one BD which we mark as start,
  9341. then we have a parsing info BD (used for TSO or xsum),
  9342. and only then we have the rest of the TSO BDs.
  9343. (don't forget to mark the last one as last,
  9344. and to unmap only AFTER you write to the BD ...)
  9345. And above all, all pdb sizes are in words - NOT DWORDS!
  9346. */
  9347. pkt_prod = fp->tx_pkt_prod++;
  9348. bd_prod = TX_BD(fp->tx_bd_prod);
  9349. /* get a tx_buf and first BD */
  9350. tx_buf = &fp->tx_buf_ring[TX_BD(pkt_prod)];
  9351. tx_start_bd = &fp->tx_desc_ring[bd_prod].start_bd;
  9352. tx_start_bd->bd_flags.as_bitfield = ETH_TX_BD_FLAGS_START_BD;
  9353. tx_start_bd->general_data = (UNICAST_ADDRESS <<
  9354. ETH_TX_START_BD_ETH_ADDR_TYPE_SHIFT);
  9355. /* header nbd */
  9356. tx_start_bd->general_data |= (1 << ETH_TX_START_BD_HDR_NBDS_SHIFT);
  9357. /* remember the first BD of the packet */
  9358. tx_buf->first_bd = fp->tx_bd_prod;
  9359. tx_buf->skb = skb;
  9360. tx_buf->flags = 0;
  9361. DP(NETIF_MSG_TX_QUEUED,
  9362. "sending pkt %u @%p next_idx %u bd %u @%p\n",
  9363. pkt_prod, tx_buf, fp->tx_pkt_prod, bd_prod, tx_start_bd);
  9364. #ifdef BCM_VLAN
  9365. if ((bp->vlgrp != NULL) && vlan_tx_tag_present(skb) &&
  9366. (bp->flags & HW_VLAN_TX_FLAG)) {
  9367. tx_start_bd->vlan = cpu_to_le16(vlan_tx_tag_get(skb));
  9368. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_VLAN_TAG;
  9369. } else
  9370. #endif
  9371. tx_start_bd->vlan = cpu_to_le16(pkt_prod);
  9372. /* turn on parsing and get a BD */
  9373. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  9374. pbd = &fp->tx_desc_ring[bd_prod].parse_bd;
  9375. memset(pbd, 0, sizeof(struct eth_tx_parse_bd));
  9376. if (xmit_type & XMIT_CSUM) {
  9377. hlen = (skb_network_header(skb) - skb->data) / 2;
  9378. /* for now NS flag is not used in Linux */
  9379. pbd->global_data =
  9380. (hlen | ((skb->protocol == cpu_to_be16(ETH_P_8021Q)) <<
  9381. ETH_TX_PARSE_BD_LLC_SNAP_EN_SHIFT));
  9382. pbd->ip_hlen = (skb_transport_header(skb) -
  9383. skb_network_header(skb)) / 2;
  9384. hlen += pbd->ip_hlen + tcp_hdrlen(skb) / 2;
  9385. pbd->total_hlen = cpu_to_le16(hlen);
  9386. hlen = hlen*2;
  9387. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_L4_CSUM;
  9388. if (xmit_type & XMIT_CSUM_V4)
  9389. tx_start_bd->bd_flags.as_bitfield |=
  9390. ETH_TX_BD_FLAGS_IP_CSUM;
  9391. else
  9392. tx_start_bd->bd_flags.as_bitfield |=
  9393. ETH_TX_BD_FLAGS_IPV6;
  9394. if (xmit_type & XMIT_CSUM_TCP) {
  9395. pbd->tcp_pseudo_csum = swab16(tcp_hdr(skb)->check);
  9396. } else {
  9397. s8 fix = SKB_CS_OFF(skb); /* signed! */
  9398. pbd->global_data |= ETH_TX_PARSE_BD_UDP_CS_FLG;
  9399. DP(NETIF_MSG_TX_QUEUED,
  9400. "hlen %d fix %d csum before fix %x\n",
  9401. le16_to_cpu(pbd->total_hlen), fix, SKB_CS(skb));
  9402. /* HW bug: fixup the CSUM */
  9403. pbd->tcp_pseudo_csum =
  9404. bnx2x_csum_fix(skb_transport_header(skb),
  9405. SKB_CS(skb), fix);
  9406. DP(NETIF_MSG_TX_QUEUED, "csum after fix %x\n",
  9407. pbd->tcp_pseudo_csum);
  9408. }
  9409. }
  9410. mapping = pci_map_single(bp->pdev, skb->data,
  9411. skb_headlen(skb), PCI_DMA_TODEVICE);
  9412. tx_start_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  9413. tx_start_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  9414. nbd = skb_shinfo(skb)->nr_frags + 2; /* start_bd + pbd + frags */
  9415. tx_start_bd->nbd = cpu_to_le16(nbd);
  9416. tx_start_bd->nbytes = cpu_to_le16(skb_headlen(skb));
  9417. pkt_size = tx_start_bd->nbytes;
  9418. DP(NETIF_MSG_TX_QUEUED, "first bd @%p addr (%x:%x) nbd %d"
  9419. " nbytes %d flags %x vlan %x\n",
  9420. tx_start_bd, tx_start_bd->addr_hi, tx_start_bd->addr_lo,
  9421. le16_to_cpu(tx_start_bd->nbd), le16_to_cpu(tx_start_bd->nbytes),
  9422. tx_start_bd->bd_flags.as_bitfield, le16_to_cpu(tx_start_bd->vlan));
  9423. if (xmit_type & XMIT_GSO) {
  9424. DP(NETIF_MSG_TX_QUEUED,
  9425. "TSO packet len %d hlen %d total len %d tso size %d\n",
  9426. skb->len, hlen, skb_headlen(skb),
  9427. skb_shinfo(skb)->gso_size);
  9428. tx_start_bd->bd_flags.as_bitfield |= ETH_TX_BD_FLAGS_SW_LSO;
  9429. if (unlikely(skb_headlen(skb) > hlen))
  9430. bd_prod = bnx2x_tx_split(bp, fp, tx_buf, &tx_start_bd,
  9431. hlen, bd_prod, ++nbd);
  9432. pbd->lso_mss = cpu_to_le16(skb_shinfo(skb)->gso_size);
  9433. pbd->tcp_send_seq = swab32(tcp_hdr(skb)->seq);
  9434. pbd->tcp_flags = pbd_tcp_flags(skb);
  9435. if (xmit_type & XMIT_GSO_V4) {
  9436. pbd->ip_id = swab16(ip_hdr(skb)->id);
  9437. pbd->tcp_pseudo_csum =
  9438. swab16(~csum_tcpudp_magic(ip_hdr(skb)->saddr,
  9439. ip_hdr(skb)->daddr,
  9440. 0, IPPROTO_TCP, 0));
  9441. } else
  9442. pbd->tcp_pseudo_csum =
  9443. swab16(~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
  9444. &ipv6_hdr(skb)->daddr,
  9445. 0, IPPROTO_TCP, 0));
  9446. pbd->global_data |= ETH_TX_PARSE_BD_PSEUDO_CS_WITHOUT_LEN;
  9447. }
  9448. tx_data_bd = (struct eth_tx_bd *)tx_start_bd;
  9449. for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) {
  9450. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  9451. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  9452. tx_data_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
  9453. if (total_pkt_bd == NULL)
  9454. total_pkt_bd = &fp->tx_desc_ring[bd_prod].reg_bd;
  9455. mapping = pci_map_page(bp->pdev, frag->page, frag->page_offset,
  9456. frag->size, PCI_DMA_TODEVICE);
  9457. tx_data_bd->addr_hi = cpu_to_le32(U64_HI(mapping));
  9458. tx_data_bd->addr_lo = cpu_to_le32(U64_LO(mapping));
  9459. tx_data_bd->nbytes = cpu_to_le16(frag->size);
  9460. le16_add_cpu(&pkt_size, frag->size);
  9461. DP(NETIF_MSG_TX_QUEUED,
  9462. "frag %d bd @%p addr (%x:%x) nbytes %d\n",
  9463. i, tx_data_bd, tx_data_bd->addr_hi, tx_data_bd->addr_lo,
  9464. le16_to_cpu(tx_data_bd->nbytes));
  9465. }
  9466. DP(NETIF_MSG_TX_QUEUED, "last bd @%p\n", tx_data_bd);
  9467. bd_prod = TX_BD(NEXT_TX_IDX(bd_prod));
  9468. /* now send a tx doorbell, counting the next BD
  9469. * if the packet contains or ends with it
  9470. */
  9471. if (TX_BD_POFF(bd_prod) < nbd)
  9472. nbd++;
  9473. if (total_pkt_bd != NULL)
  9474. total_pkt_bd->total_pkt_bytes = pkt_size;
  9475. if (pbd)
  9476. DP(NETIF_MSG_TX_QUEUED,
  9477. "PBD @%p ip_data %x ip_hlen %u ip_id %u lso_mss %u"
  9478. " tcp_flags %x xsum %x seq %u hlen %u\n",
  9479. pbd, pbd->global_data, pbd->ip_hlen, pbd->ip_id,
  9480. pbd->lso_mss, pbd->tcp_flags, pbd->tcp_pseudo_csum,
  9481. pbd->tcp_send_seq, le16_to_cpu(pbd->total_hlen));
  9482. DP(NETIF_MSG_TX_QUEUED, "doorbell: nbd %d bd %u\n", nbd, bd_prod);
  9483. /*
  9484. * Make sure that the BD data is updated before updating the producer
  9485. * since FW might read the BD right after the producer is updated.
  9486. * This is only applicable for weak-ordered memory model archs such
  9487. * as IA-64. The following barrier is also mandatory since FW will
  9488. * assumes packets must have BDs.
  9489. */
  9490. wmb();
  9491. fp->tx_db.data.prod += nbd;
  9492. barrier();
  9493. DOORBELL(bp, fp->index - bp->num_rx_queues, fp->tx_db.raw);
  9494. mmiowb();
  9495. fp->tx_bd_prod += nbd;
  9496. if (unlikely(bnx2x_tx_avail(fp) < MAX_SKB_FRAGS + 3)) {
  9497. netif_tx_stop_queue(txq);
  9498. /* We want bnx2x_tx_int to "see" the updated tx_bd_prod
  9499. if we put Tx into XOFF state. */
  9500. smp_mb();
  9501. fp_stat->eth_q_stats.driver_xoff++;
  9502. if (bnx2x_tx_avail(fp) >= MAX_SKB_FRAGS + 3)
  9503. netif_tx_wake_queue(txq);
  9504. }
  9505. fp_stat->tx_pkt++;
  9506. return NETDEV_TX_OK;
  9507. }
  9508. /* called with rtnl_lock */
  9509. static int bnx2x_open(struct net_device *dev)
  9510. {
  9511. struct bnx2x *bp = netdev_priv(dev);
  9512. netif_carrier_off(dev);
  9513. bnx2x_set_power_state(bp, PCI_D0);
  9514. return bnx2x_nic_load(bp, LOAD_OPEN);
  9515. }
  9516. /* called with rtnl_lock */
  9517. static int bnx2x_close(struct net_device *dev)
  9518. {
  9519. struct bnx2x *bp = netdev_priv(dev);
  9520. /* Unload the driver, release IRQs */
  9521. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  9522. if (atomic_read(&bp->pdev->enable_cnt) == 1)
  9523. if (!CHIP_REV_IS_SLOW(bp))
  9524. bnx2x_set_power_state(bp, PCI_D3hot);
  9525. return 0;
  9526. }
  9527. /* called with netif_tx_lock from dev_mcast.c */
  9528. static void bnx2x_set_rx_mode(struct net_device *dev)
  9529. {
  9530. struct bnx2x *bp = netdev_priv(dev);
  9531. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9532. int port = BP_PORT(bp);
  9533. if (bp->state != BNX2X_STATE_OPEN) {
  9534. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9535. return;
  9536. }
  9537. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", dev->flags);
  9538. if (dev->flags & IFF_PROMISC)
  9539. rx_mode = BNX2X_RX_MODE_PROMISC;
  9540. else if ((dev->flags & IFF_ALLMULTI) ||
  9541. ((dev->mc_count > BNX2X_MAX_MULTICAST) && CHIP_IS_E1(bp)))
  9542. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9543. else { /* some multicasts */
  9544. if (CHIP_IS_E1(bp)) {
  9545. int i, old, offset;
  9546. struct dev_mc_list *mclist;
  9547. struct mac_configuration_cmd *config =
  9548. bnx2x_sp(bp, mcast_config);
  9549. for (i = 0, mclist = dev->mc_list;
  9550. mclist && (i < dev->mc_count);
  9551. i++, mclist = mclist->next) {
  9552. config->config_table[i].
  9553. cam_entry.msb_mac_addr =
  9554. swab16(*(u16 *)&mclist->dmi_addr[0]);
  9555. config->config_table[i].
  9556. cam_entry.middle_mac_addr =
  9557. swab16(*(u16 *)&mclist->dmi_addr[2]);
  9558. config->config_table[i].
  9559. cam_entry.lsb_mac_addr =
  9560. swab16(*(u16 *)&mclist->dmi_addr[4]);
  9561. config->config_table[i].cam_entry.flags =
  9562. cpu_to_le16(port);
  9563. config->config_table[i].
  9564. target_table_entry.flags = 0;
  9565. config->config_table[i].target_table_entry.
  9566. clients_bit_vector =
  9567. cpu_to_le32(1 << BP_L_ID(bp));
  9568. config->config_table[i].
  9569. target_table_entry.vlan_id = 0;
  9570. DP(NETIF_MSG_IFUP,
  9571. "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
  9572. config->config_table[i].
  9573. cam_entry.msb_mac_addr,
  9574. config->config_table[i].
  9575. cam_entry.middle_mac_addr,
  9576. config->config_table[i].
  9577. cam_entry.lsb_mac_addr);
  9578. }
  9579. old = config->hdr.length;
  9580. if (old > i) {
  9581. for (; i < old; i++) {
  9582. if (CAM_IS_INVALID(config->
  9583. config_table[i])) {
  9584. /* already invalidated */
  9585. break;
  9586. }
  9587. /* invalidate */
  9588. CAM_INVALIDATE(config->
  9589. config_table[i]);
  9590. }
  9591. }
  9592. if (CHIP_REV_IS_SLOW(bp))
  9593. offset = BNX2X_MAX_EMUL_MULTI*(1 + port);
  9594. else
  9595. offset = BNX2X_MAX_MULTICAST*(1 + port);
  9596. config->hdr.length = i;
  9597. config->hdr.offset = offset;
  9598. config->hdr.client_id = bp->fp->cl_id;
  9599. config->hdr.reserved1 = 0;
  9600. bp->set_mac_pending++;
  9601. smp_wmb();
  9602. bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, 0,
  9603. U64_HI(bnx2x_sp_mapping(bp, mcast_config)),
  9604. U64_LO(bnx2x_sp_mapping(bp, mcast_config)),
  9605. 0);
  9606. } else { /* E1H */
  9607. /* Accept one or more multicasts */
  9608. struct dev_mc_list *mclist;
  9609. u32 mc_filter[MC_HASH_SIZE];
  9610. u32 crc, bit, regidx;
  9611. int i;
  9612. memset(mc_filter, 0, 4 * MC_HASH_SIZE);
  9613. for (i = 0, mclist = dev->mc_list;
  9614. mclist && (i < dev->mc_count);
  9615. i++, mclist = mclist->next) {
  9616. DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
  9617. mclist->dmi_addr);
  9618. crc = crc32c_le(0, mclist->dmi_addr, ETH_ALEN);
  9619. bit = (crc >> 24) & 0xff;
  9620. regidx = bit >> 5;
  9621. bit &= 0x1f;
  9622. mc_filter[regidx] |= (1 << bit);
  9623. }
  9624. for (i = 0; i < MC_HASH_SIZE; i++)
  9625. REG_WR(bp, MC_HASH_OFFSET(bp, i),
  9626. mc_filter[i]);
  9627. }
  9628. }
  9629. bp->rx_mode = rx_mode;
  9630. bnx2x_set_storm_rx_mode(bp);
  9631. }
  9632. /* called with rtnl_lock */
  9633. static int bnx2x_change_mac_addr(struct net_device *dev, void *p)
  9634. {
  9635. struct sockaddr *addr = p;
  9636. struct bnx2x *bp = netdev_priv(dev);
  9637. if (!is_valid_ether_addr((u8 *)(addr->sa_data)))
  9638. return -EINVAL;
  9639. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  9640. if (netif_running(dev)) {
  9641. if (CHIP_IS_E1(bp))
  9642. bnx2x_set_eth_mac_addr_e1(bp, 1);
  9643. else
  9644. bnx2x_set_eth_mac_addr_e1h(bp, 1);
  9645. }
  9646. return 0;
  9647. }
  9648. /* called with rtnl_lock */
  9649. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9650. int devad, u16 addr)
  9651. {
  9652. struct bnx2x *bp = netdev_priv(netdev);
  9653. u16 value;
  9654. int rc;
  9655. u32 phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  9656. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9657. prtad, devad, addr);
  9658. if (prtad != bp->mdio.prtad) {
  9659. DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n",
  9660. prtad, bp->mdio.prtad);
  9661. return -EINVAL;
  9662. }
  9663. /* The HW expects different devad if CL22 is used */
  9664. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9665. bnx2x_acquire_phy_lock(bp);
  9666. rc = bnx2x_cl45_read(bp, BP_PORT(bp), phy_type, prtad,
  9667. devad, addr, &value);
  9668. bnx2x_release_phy_lock(bp);
  9669. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9670. if (!rc)
  9671. rc = value;
  9672. return rc;
  9673. }
  9674. /* called with rtnl_lock */
  9675. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9676. u16 addr, u16 value)
  9677. {
  9678. struct bnx2x *bp = netdev_priv(netdev);
  9679. u32 ext_phy_type = XGXS_EXT_PHY_TYPE(bp->link_params.ext_phy_config);
  9680. int rc;
  9681. DP(NETIF_MSG_LINK, "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x,"
  9682. " value 0x%x\n", prtad, devad, addr, value);
  9683. if (prtad != bp->mdio.prtad) {
  9684. DP(NETIF_MSG_LINK, "prtad missmatch (cmd:0x%x != bp:0x%x)\n",
  9685. prtad, bp->mdio.prtad);
  9686. return -EINVAL;
  9687. }
  9688. /* The HW expects different devad if CL22 is used */
  9689. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9690. bnx2x_acquire_phy_lock(bp);
  9691. rc = bnx2x_cl45_write(bp, BP_PORT(bp), ext_phy_type, prtad,
  9692. devad, addr, value);
  9693. bnx2x_release_phy_lock(bp);
  9694. return rc;
  9695. }
  9696. /* called with rtnl_lock */
  9697. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9698. {
  9699. struct bnx2x *bp = netdev_priv(dev);
  9700. struct mii_ioctl_data *mdio = if_mii(ifr);
  9701. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9702. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9703. if (!netif_running(dev))
  9704. return -EAGAIN;
  9705. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9706. }
  9707. /* called with rtnl_lock */
  9708. static int bnx2x_change_mtu(struct net_device *dev, int new_mtu)
  9709. {
  9710. struct bnx2x *bp = netdev_priv(dev);
  9711. int rc = 0;
  9712. if ((new_mtu > ETH_MAX_JUMBO_PACKET_SIZE) ||
  9713. ((new_mtu + ETH_HLEN) < ETH_MIN_PACKET_SIZE))
  9714. return -EINVAL;
  9715. /* This does not race with packet allocation
  9716. * because the actual alloc size is
  9717. * only updated as part of load
  9718. */
  9719. dev->mtu = new_mtu;
  9720. if (netif_running(dev)) {
  9721. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  9722. rc = bnx2x_nic_load(bp, LOAD_NORMAL);
  9723. }
  9724. return rc;
  9725. }
  9726. static void bnx2x_tx_timeout(struct net_device *dev)
  9727. {
  9728. struct bnx2x *bp = netdev_priv(dev);
  9729. #ifdef BNX2X_STOP_ON_ERROR
  9730. if (!bp->panic)
  9731. bnx2x_panic();
  9732. #endif
  9733. /* This allows the netif to be shutdown gracefully before resetting */
  9734. schedule_work(&bp->reset_task);
  9735. }
  9736. #ifdef BCM_VLAN
  9737. /* called with rtnl_lock */
  9738. static void bnx2x_vlan_rx_register(struct net_device *dev,
  9739. struct vlan_group *vlgrp)
  9740. {
  9741. struct bnx2x *bp = netdev_priv(dev);
  9742. bp->vlgrp = vlgrp;
  9743. /* Set flags according to the required capabilities */
  9744. bp->flags &= ~(HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
  9745. if (dev->features & NETIF_F_HW_VLAN_TX)
  9746. bp->flags |= HW_VLAN_TX_FLAG;
  9747. if (dev->features & NETIF_F_HW_VLAN_RX)
  9748. bp->flags |= HW_VLAN_RX_FLAG;
  9749. if (netif_running(dev))
  9750. bnx2x_set_client_config(bp);
  9751. }
  9752. #endif
  9753. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  9754. static void poll_bnx2x(struct net_device *dev)
  9755. {
  9756. struct bnx2x *bp = netdev_priv(dev);
  9757. disable_irq(bp->pdev->irq);
  9758. bnx2x_interrupt(bp->pdev->irq, dev);
  9759. enable_irq(bp->pdev->irq);
  9760. }
  9761. #endif
  9762. static const struct net_device_ops bnx2x_netdev_ops = {
  9763. .ndo_open = bnx2x_open,
  9764. .ndo_stop = bnx2x_close,
  9765. .ndo_start_xmit = bnx2x_start_xmit,
  9766. .ndo_set_multicast_list = bnx2x_set_rx_mode,
  9767. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9768. .ndo_validate_addr = eth_validate_addr,
  9769. .ndo_do_ioctl = bnx2x_ioctl,
  9770. .ndo_change_mtu = bnx2x_change_mtu,
  9771. .ndo_tx_timeout = bnx2x_tx_timeout,
  9772. #ifdef BCM_VLAN
  9773. .ndo_vlan_rx_register = bnx2x_vlan_rx_register,
  9774. #endif
  9775. #if defined(HAVE_POLL_CONTROLLER) || defined(CONFIG_NET_POLL_CONTROLLER)
  9776. .ndo_poll_controller = poll_bnx2x,
  9777. #endif
  9778. };
  9779. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  9780. struct net_device *dev)
  9781. {
  9782. struct bnx2x *bp;
  9783. int rc;
  9784. SET_NETDEV_DEV(dev, &pdev->dev);
  9785. bp = netdev_priv(dev);
  9786. bp->dev = dev;
  9787. bp->pdev = pdev;
  9788. bp->flags = 0;
  9789. bp->func = PCI_FUNC(pdev->devfn);
  9790. rc = pci_enable_device(pdev);
  9791. if (rc) {
  9792. printk(KERN_ERR PFX "Cannot enable PCI device, aborting\n");
  9793. goto err_out;
  9794. }
  9795. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9796. printk(KERN_ERR PFX "Cannot find PCI device base address,"
  9797. " aborting\n");
  9798. rc = -ENODEV;
  9799. goto err_out_disable;
  9800. }
  9801. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9802. printk(KERN_ERR PFX "Cannot find second PCI device"
  9803. " base address, aborting\n");
  9804. rc = -ENODEV;
  9805. goto err_out_disable;
  9806. }
  9807. if (atomic_read(&pdev->enable_cnt) == 1) {
  9808. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9809. if (rc) {
  9810. printk(KERN_ERR PFX "Cannot obtain PCI resources,"
  9811. " aborting\n");
  9812. goto err_out_disable;
  9813. }
  9814. pci_set_master(pdev);
  9815. pci_save_state(pdev);
  9816. }
  9817. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9818. if (bp->pm_cap == 0) {
  9819. printk(KERN_ERR PFX "Cannot find power management"
  9820. " capability, aborting\n");
  9821. rc = -EIO;
  9822. goto err_out_release;
  9823. }
  9824. bp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP);
  9825. if (bp->pcie_cap == 0) {
  9826. printk(KERN_ERR PFX "Cannot find PCI Express capability,"
  9827. " aborting\n");
  9828. rc = -EIO;
  9829. goto err_out_release;
  9830. }
  9831. if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) == 0) {
  9832. bp->flags |= USING_DAC_FLAG;
  9833. if (pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) {
  9834. printk(KERN_ERR PFX "pci_set_consistent_dma_mask"
  9835. " failed, aborting\n");
  9836. rc = -EIO;
  9837. goto err_out_release;
  9838. }
  9839. } else if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) {
  9840. printk(KERN_ERR PFX "System does not support DMA,"
  9841. " aborting\n");
  9842. rc = -EIO;
  9843. goto err_out_release;
  9844. }
  9845. dev->mem_start = pci_resource_start(pdev, 0);
  9846. dev->base_addr = dev->mem_start;
  9847. dev->mem_end = pci_resource_end(pdev, 0);
  9848. dev->irq = pdev->irq;
  9849. bp->regview = pci_ioremap_bar(pdev, 0);
  9850. if (!bp->regview) {
  9851. printk(KERN_ERR PFX "Cannot map register space, aborting\n");
  9852. rc = -ENOMEM;
  9853. goto err_out_release;
  9854. }
  9855. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9856. min_t(u64, BNX2X_DB_SIZE,
  9857. pci_resource_len(pdev, 2)));
  9858. if (!bp->doorbells) {
  9859. printk(KERN_ERR PFX "Cannot map doorbell space, aborting\n");
  9860. rc = -ENOMEM;
  9861. goto err_out_unmap;
  9862. }
  9863. bnx2x_set_power_state(bp, PCI_D0);
  9864. /* clean indirect addresses */
  9865. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9866. PCICFG_VENDOR_ID_OFFSET);
  9867. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0 + BP_PORT(bp)*16, 0);
  9868. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0 + BP_PORT(bp)*16, 0);
  9869. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0 + BP_PORT(bp)*16, 0);
  9870. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0 + BP_PORT(bp)*16, 0);
  9871. dev->watchdog_timeo = TX_TIMEOUT;
  9872. dev->netdev_ops = &bnx2x_netdev_ops;
  9873. dev->ethtool_ops = &bnx2x_ethtool_ops;
  9874. dev->features |= NETIF_F_SG;
  9875. dev->features |= NETIF_F_HW_CSUM;
  9876. if (bp->flags & USING_DAC_FLAG)
  9877. dev->features |= NETIF_F_HIGHDMA;
  9878. dev->features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
  9879. dev->features |= NETIF_F_TSO6;
  9880. #ifdef BCM_VLAN
  9881. dev->features |= (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX);
  9882. bp->flags |= (HW_VLAN_RX_FLAG | HW_VLAN_TX_FLAG);
  9883. dev->vlan_features |= NETIF_F_SG;
  9884. dev->vlan_features |= NETIF_F_HW_CSUM;
  9885. if (bp->flags & USING_DAC_FLAG)
  9886. dev->vlan_features |= NETIF_F_HIGHDMA;
  9887. dev->vlan_features |= (NETIF_F_TSO | NETIF_F_TSO_ECN);
  9888. dev->vlan_features |= NETIF_F_TSO6;
  9889. #endif
  9890. /* get_port_hwinfo() will set prtad and mmds properly */
  9891. bp->mdio.prtad = MDIO_PRTAD_NONE;
  9892. bp->mdio.mmds = 0;
  9893. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  9894. bp->mdio.dev = dev;
  9895. bp->mdio.mdio_read = bnx2x_mdio_read;
  9896. bp->mdio.mdio_write = bnx2x_mdio_write;
  9897. return 0;
  9898. err_out_unmap:
  9899. if (bp->regview) {
  9900. iounmap(bp->regview);
  9901. bp->regview = NULL;
  9902. }
  9903. if (bp->doorbells) {
  9904. iounmap(bp->doorbells);
  9905. bp->doorbells = NULL;
  9906. }
  9907. err_out_release:
  9908. if (atomic_read(&pdev->enable_cnt) == 1)
  9909. pci_release_regions(pdev);
  9910. err_out_disable:
  9911. pci_disable_device(pdev);
  9912. pci_set_drvdata(pdev, NULL);
  9913. err_out:
  9914. return rc;
  9915. }
  9916. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  9917. int *width, int *speed)
  9918. {
  9919. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  9920. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  9921. /* return value of 1=2.5GHz 2=5GHz */
  9922. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  9923. }
  9924. static int __devinit bnx2x_check_firmware(struct bnx2x *bp)
  9925. {
  9926. const struct firmware *firmware = bp->firmware;
  9927. struct bnx2x_fw_file_hdr *fw_hdr;
  9928. struct bnx2x_fw_file_section *sections;
  9929. u32 offset, len, num_ops;
  9930. u16 *ops_offsets;
  9931. int i;
  9932. const u8 *fw_ver;
  9933. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr))
  9934. return -EINVAL;
  9935. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  9936. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  9937. /* Make sure none of the offsets and sizes make us read beyond
  9938. * the end of the firmware data */
  9939. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  9940. offset = be32_to_cpu(sections[i].offset);
  9941. len = be32_to_cpu(sections[i].len);
  9942. if (offset + len > firmware->size) {
  9943. printk(KERN_ERR PFX "Section %d length is out of "
  9944. "bounds\n", i);
  9945. return -EINVAL;
  9946. }
  9947. }
  9948. /* Likewise for the init_ops offsets */
  9949. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  9950. ops_offsets = (u16 *)(firmware->data + offset);
  9951. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  9952. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  9953. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  9954. printk(KERN_ERR PFX "Section offset %d is out of "
  9955. "bounds\n", i);
  9956. return -EINVAL;
  9957. }
  9958. }
  9959. /* Check FW version */
  9960. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  9961. fw_ver = firmware->data + offset;
  9962. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  9963. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  9964. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  9965. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  9966. printk(KERN_ERR PFX "Bad FW version:%d.%d.%d.%d."
  9967. " Should be %d.%d.%d.%d\n",
  9968. fw_ver[0], fw_ver[1], fw_ver[2],
  9969. fw_ver[3], BCM_5710_FW_MAJOR_VERSION,
  9970. BCM_5710_FW_MINOR_VERSION,
  9971. BCM_5710_FW_REVISION_VERSION,
  9972. BCM_5710_FW_ENGINEERING_VERSION);
  9973. return -EINVAL;
  9974. }
  9975. return 0;
  9976. }
  9977. static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9978. {
  9979. const __be32 *source = (const __be32 *)_source;
  9980. u32 *target = (u32 *)_target;
  9981. u32 i;
  9982. for (i = 0; i < n/4; i++)
  9983. target[i] = be32_to_cpu(source[i]);
  9984. }
  9985. /*
  9986. Ops array is stored in the following format:
  9987. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9988. */
  9989. static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9990. {
  9991. const __be32 *source = (const __be32 *)_source;
  9992. struct raw_op *target = (struct raw_op *)_target;
  9993. u32 i, j, tmp;
  9994. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9995. tmp = be32_to_cpu(source[j]);
  9996. target[i].op = (tmp >> 24) & 0xff;
  9997. target[i].offset = tmp & 0xffffff;
  9998. target[i].raw_data = be32_to_cpu(source[j+1]);
  9999. }
  10000. }
  10001. static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10002. {
  10003. const __be16 *source = (const __be16 *)_source;
  10004. u16 *target = (u16 *)_target;
  10005. u32 i;
  10006. for (i = 0; i < n/2; i++)
  10007. target[i] = be16_to_cpu(source[i]);
  10008. }
  10009. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10010. do { \
  10011. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10012. bp->arr = kmalloc(len, GFP_KERNEL); \
  10013. if (!bp->arr) { \
  10014. printk(KERN_ERR PFX "Failed to allocate %d bytes " \
  10015. "for "#arr"\n", len); \
  10016. goto lbl; \
  10017. } \
  10018. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10019. (u8 *)bp->arr, len); \
  10020. } while (0)
  10021. static int __devinit bnx2x_init_firmware(struct bnx2x *bp, struct device *dev)
  10022. {
  10023. const char *fw_file_name;
  10024. struct bnx2x_fw_file_hdr *fw_hdr;
  10025. int rc;
  10026. if (CHIP_IS_E1(bp))
  10027. fw_file_name = FW_FILE_NAME_E1;
  10028. else
  10029. fw_file_name = FW_FILE_NAME_E1H;
  10030. printk(KERN_INFO PFX "Loading %s\n", fw_file_name);
  10031. rc = request_firmware(&bp->firmware, fw_file_name, dev);
  10032. if (rc) {
  10033. printk(KERN_ERR PFX "Can't load firmware file %s\n",
  10034. fw_file_name);
  10035. goto request_firmware_exit;
  10036. }
  10037. rc = bnx2x_check_firmware(bp);
  10038. if (rc) {
  10039. printk(KERN_ERR PFX "Corrupt firmware file %s\n", fw_file_name);
  10040. goto request_firmware_exit;
  10041. }
  10042. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10043. /* Initialize the pointers to the init arrays */
  10044. /* Blob */
  10045. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10046. /* Opcodes */
  10047. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10048. /* Offsets */
  10049. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10050. be16_to_cpu_n);
  10051. /* STORMs firmware */
  10052. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10053. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10054. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10055. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10056. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10057. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10058. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10059. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10060. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10061. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10062. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10063. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10064. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10065. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10066. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10067. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10068. return 0;
  10069. init_offsets_alloc_err:
  10070. kfree(bp->init_ops);
  10071. init_ops_alloc_err:
  10072. kfree(bp->init_data);
  10073. request_firmware_exit:
  10074. release_firmware(bp->firmware);
  10075. return rc;
  10076. }
  10077. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  10078. const struct pci_device_id *ent)
  10079. {
  10080. struct net_device *dev = NULL;
  10081. struct bnx2x *bp;
  10082. int pcie_width, pcie_speed;
  10083. int rc;
  10084. /* dev zeroed in init_etherdev */
  10085. dev = alloc_etherdev_mq(sizeof(*bp), MAX_CONTEXT);
  10086. if (!dev) {
  10087. printk(KERN_ERR PFX "Cannot allocate net device\n");
  10088. return -ENOMEM;
  10089. }
  10090. bp = netdev_priv(dev);
  10091. bp->msglevel = debug;
  10092. pci_set_drvdata(pdev, dev);
  10093. rc = bnx2x_init_dev(pdev, dev);
  10094. if (rc < 0) {
  10095. free_netdev(dev);
  10096. return rc;
  10097. }
  10098. rc = bnx2x_init_bp(bp);
  10099. if (rc)
  10100. goto init_one_exit;
  10101. /* Set init arrays */
  10102. rc = bnx2x_init_firmware(bp, &pdev->dev);
  10103. if (rc) {
  10104. printk(KERN_ERR PFX "Error loading firmware\n");
  10105. goto init_one_exit;
  10106. }
  10107. rc = register_netdev(dev);
  10108. if (rc) {
  10109. dev_err(&pdev->dev, "Cannot register net device\n");
  10110. goto init_one_exit;
  10111. }
  10112. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10113. printk(KERN_INFO "%s: %s (%c%d) PCI-E x%d %s found at mem %lx,"
  10114. " IRQ %d, ", dev->name, board_info[ent->driver_data].name,
  10115. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10116. pcie_width, (pcie_speed == 2) ? "5GHz (Gen2)" : "2.5GHz",
  10117. dev->base_addr, bp->pdev->irq);
  10118. printk(KERN_CONT "node addr %pM\n", dev->dev_addr);
  10119. return 0;
  10120. init_one_exit:
  10121. if (bp->regview)
  10122. iounmap(bp->regview);
  10123. if (bp->doorbells)
  10124. iounmap(bp->doorbells);
  10125. free_netdev(dev);
  10126. if (atomic_read(&pdev->enable_cnt) == 1)
  10127. pci_release_regions(pdev);
  10128. pci_disable_device(pdev);
  10129. pci_set_drvdata(pdev, NULL);
  10130. return rc;
  10131. }
  10132. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  10133. {
  10134. struct net_device *dev = pci_get_drvdata(pdev);
  10135. struct bnx2x *bp;
  10136. if (!dev) {
  10137. printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
  10138. return;
  10139. }
  10140. bp = netdev_priv(dev);
  10141. unregister_netdev(dev);
  10142. kfree(bp->init_ops_offsets);
  10143. kfree(bp->init_ops);
  10144. kfree(bp->init_data);
  10145. release_firmware(bp->firmware);
  10146. if (bp->regview)
  10147. iounmap(bp->regview);
  10148. if (bp->doorbells)
  10149. iounmap(bp->doorbells);
  10150. free_netdev(dev);
  10151. if (atomic_read(&pdev->enable_cnt) == 1)
  10152. pci_release_regions(pdev);
  10153. pci_disable_device(pdev);
  10154. pci_set_drvdata(pdev, NULL);
  10155. }
  10156. static int bnx2x_suspend(struct pci_dev *pdev, pm_message_t state)
  10157. {
  10158. struct net_device *dev = pci_get_drvdata(pdev);
  10159. struct bnx2x *bp;
  10160. if (!dev) {
  10161. printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
  10162. return -ENODEV;
  10163. }
  10164. bp = netdev_priv(dev);
  10165. rtnl_lock();
  10166. pci_save_state(pdev);
  10167. if (!netif_running(dev)) {
  10168. rtnl_unlock();
  10169. return 0;
  10170. }
  10171. netif_device_detach(dev);
  10172. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  10173. bnx2x_set_power_state(bp, pci_choose_state(pdev, state));
  10174. rtnl_unlock();
  10175. return 0;
  10176. }
  10177. static int bnx2x_resume(struct pci_dev *pdev)
  10178. {
  10179. struct net_device *dev = pci_get_drvdata(pdev);
  10180. struct bnx2x *bp;
  10181. int rc;
  10182. if (!dev) {
  10183. printk(KERN_ERR PFX "BAD net device from bnx2x_init_one\n");
  10184. return -ENODEV;
  10185. }
  10186. bp = netdev_priv(dev);
  10187. rtnl_lock();
  10188. pci_restore_state(pdev);
  10189. if (!netif_running(dev)) {
  10190. rtnl_unlock();
  10191. return 0;
  10192. }
  10193. bnx2x_set_power_state(bp, PCI_D0);
  10194. netif_device_attach(dev);
  10195. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  10196. rtnl_unlock();
  10197. return rc;
  10198. }
  10199. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10200. {
  10201. int i;
  10202. bp->state = BNX2X_STATE_ERROR;
  10203. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10204. bnx2x_netif_stop(bp, 0);
  10205. del_timer_sync(&bp->timer);
  10206. bp->stats_state = STATS_STATE_DISABLED;
  10207. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  10208. /* Release IRQs */
  10209. bnx2x_free_irq(bp);
  10210. if (CHIP_IS_E1(bp)) {
  10211. struct mac_configuration_cmd *config =
  10212. bnx2x_sp(bp, mcast_config);
  10213. for (i = 0; i < config->hdr.length; i++)
  10214. CAM_INVALIDATE(config->config_table[i]);
  10215. }
  10216. /* Free SKBs, SGEs, TPA pool and driver internals */
  10217. bnx2x_free_skbs(bp);
  10218. for_each_rx_queue(bp, i)
  10219. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10220. for_each_rx_queue(bp, i)
  10221. netif_napi_del(&bnx2x_fp(bp, i, napi));
  10222. bnx2x_free_mem(bp);
  10223. bp->state = BNX2X_STATE_CLOSED;
  10224. netif_carrier_off(bp->dev);
  10225. return 0;
  10226. }
  10227. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10228. {
  10229. u32 val;
  10230. mutex_init(&bp->port.phy_mutex);
  10231. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  10232. bp->link_params.shmem_base = bp->common.shmem_base;
  10233. BNX2X_DEV_INFO("shmem offset is 0x%x\n", bp->common.shmem_base);
  10234. if (!bp->common.shmem_base ||
  10235. (bp->common.shmem_base < 0xA0000) ||
  10236. (bp->common.shmem_base >= 0xC0000)) {
  10237. BNX2X_DEV_INFO("MCP not active\n");
  10238. bp->flags |= NO_MCP_FLAG;
  10239. return;
  10240. }
  10241. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10242. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10243. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10244. BNX2X_ERR("BAD MCP validity signature\n");
  10245. if (!BP_NOMCP(bp)) {
  10246. bp->fw_seq = (SHMEM_RD(bp, func_mb[BP_FUNC(bp)].drv_mb_header)
  10247. & DRV_MSG_SEQ_NUMBER_MASK);
  10248. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  10249. }
  10250. }
  10251. /**
  10252. * bnx2x_io_error_detected - called when PCI error is detected
  10253. * @pdev: Pointer to PCI device
  10254. * @state: The current pci connection state
  10255. *
  10256. * This function is called after a PCI bus error affecting
  10257. * this device has been detected.
  10258. */
  10259. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10260. pci_channel_state_t state)
  10261. {
  10262. struct net_device *dev = pci_get_drvdata(pdev);
  10263. struct bnx2x *bp = netdev_priv(dev);
  10264. rtnl_lock();
  10265. netif_device_detach(dev);
  10266. if (state == pci_channel_io_perm_failure) {
  10267. rtnl_unlock();
  10268. return PCI_ERS_RESULT_DISCONNECT;
  10269. }
  10270. if (netif_running(dev))
  10271. bnx2x_eeh_nic_unload(bp);
  10272. pci_disable_device(pdev);
  10273. rtnl_unlock();
  10274. /* Request a slot reset */
  10275. return PCI_ERS_RESULT_NEED_RESET;
  10276. }
  10277. /**
  10278. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10279. * @pdev: Pointer to PCI device
  10280. *
  10281. * Restart the card from scratch, as if from a cold-boot.
  10282. */
  10283. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10284. {
  10285. struct net_device *dev = pci_get_drvdata(pdev);
  10286. struct bnx2x *bp = netdev_priv(dev);
  10287. rtnl_lock();
  10288. if (pci_enable_device(pdev)) {
  10289. dev_err(&pdev->dev,
  10290. "Cannot re-enable PCI device after reset\n");
  10291. rtnl_unlock();
  10292. return PCI_ERS_RESULT_DISCONNECT;
  10293. }
  10294. pci_set_master(pdev);
  10295. pci_restore_state(pdev);
  10296. if (netif_running(dev))
  10297. bnx2x_set_power_state(bp, PCI_D0);
  10298. rtnl_unlock();
  10299. return PCI_ERS_RESULT_RECOVERED;
  10300. }
  10301. /**
  10302. * bnx2x_io_resume - called when traffic can start flowing again
  10303. * @pdev: Pointer to PCI device
  10304. *
  10305. * This callback is called when the error recovery driver tells us that
  10306. * its OK to resume normal operation.
  10307. */
  10308. static void bnx2x_io_resume(struct pci_dev *pdev)
  10309. {
  10310. struct net_device *dev = pci_get_drvdata(pdev);
  10311. struct bnx2x *bp = netdev_priv(dev);
  10312. rtnl_lock();
  10313. bnx2x_eeh_recover(bp);
  10314. if (netif_running(dev))
  10315. bnx2x_nic_load(bp, LOAD_NORMAL);
  10316. netif_device_attach(dev);
  10317. rtnl_unlock();
  10318. }
  10319. static struct pci_error_handlers bnx2x_err_handler = {
  10320. .error_detected = bnx2x_io_error_detected,
  10321. .slot_reset = bnx2x_io_slot_reset,
  10322. .resume = bnx2x_io_resume,
  10323. };
  10324. static struct pci_driver bnx2x_pci_driver = {
  10325. .name = DRV_MODULE_NAME,
  10326. .id_table = bnx2x_pci_tbl,
  10327. .probe = bnx2x_init_one,
  10328. .remove = __devexit_p(bnx2x_remove_one),
  10329. .suspend = bnx2x_suspend,
  10330. .resume = bnx2x_resume,
  10331. .err_handler = &bnx2x_err_handler,
  10332. };
  10333. static int __init bnx2x_init(void)
  10334. {
  10335. int ret;
  10336. printk(KERN_INFO "%s", version);
  10337. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10338. if (bnx2x_wq == NULL) {
  10339. printk(KERN_ERR PFX "Cannot create workqueue\n");
  10340. return -ENOMEM;
  10341. }
  10342. ret = pci_register_driver(&bnx2x_pci_driver);
  10343. if (ret) {
  10344. printk(KERN_ERR PFX "Cannot register driver\n");
  10345. destroy_workqueue(bnx2x_wq);
  10346. }
  10347. return ret;
  10348. }
  10349. static void __exit bnx2x_cleanup(void)
  10350. {
  10351. pci_unregister_driver(&bnx2x_pci_driver);
  10352. destroy_workqueue(bnx2x_wq);
  10353. }
  10354. module_init(bnx2x_init);
  10355. module_exit(bnx2x_cleanup);
  10356. #ifdef BCM_CNIC
  10357. /* count denotes the number of new completions we have seen */
  10358. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10359. {
  10360. struct eth_spe *spe;
  10361. #ifdef BNX2X_STOP_ON_ERROR
  10362. if (unlikely(bp->panic))
  10363. return;
  10364. #endif
  10365. spin_lock_bh(&bp->spq_lock);
  10366. bp->cnic_spq_pending -= count;
  10367. for (; bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending;
  10368. bp->cnic_spq_pending++) {
  10369. if (!bp->cnic_kwq_pending)
  10370. break;
  10371. spe = bnx2x_sp_get_next(bp);
  10372. *spe = *bp->cnic_kwq_cons;
  10373. bp->cnic_kwq_pending--;
  10374. DP(NETIF_MSG_TIMER, "pending on SPQ %d, on KWQ %d count %d\n",
  10375. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10376. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10377. bp->cnic_kwq_cons = bp->cnic_kwq;
  10378. else
  10379. bp->cnic_kwq_cons++;
  10380. }
  10381. bnx2x_sp_prod_update(bp);
  10382. spin_unlock_bh(&bp->spq_lock);
  10383. }
  10384. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10385. struct kwqe_16 *kwqes[], u32 count)
  10386. {
  10387. struct bnx2x *bp = netdev_priv(dev);
  10388. int i;
  10389. #ifdef BNX2X_STOP_ON_ERROR
  10390. if (unlikely(bp->panic))
  10391. return -EIO;
  10392. #endif
  10393. spin_lock_bh(&bp->spq_lock);
  10394. for (i = 0; i < count; i++) {
  10395. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10396. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10397. break;
  10398. *bp->cnic_kwq_prod = *spe;
  10399. bp->cnic_kwq_pending++;
  10400. DP(NETIF_MSG_TIMER, "L5 SPQE %x %x %x:%x pos %d\n",
  10401. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10402. spe->data.mac_config_addr.hi,
  10403. spe->data.mac_config_addr.lo,
  10404. bp->cnic_kwq_pending);
  10405. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10406. bp->cnic_kwq_prod = bp->cnic_kwq;
  10407. else
  10408. bp->cnic_kwq_prod++;
  10409. }
  10410. spin_unlock_bh(&bp->spq_lock);
  10411. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10412. bnx2x_cnic_sp_post(bp, 0);
  10413. return i;
  10414. }
  10415. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10416. {
  10417. struct cnic_ops *c_ops;
  10418. int rc = 0;
  10419. mutex_lock(&bp->cnic_mutex);
  10420. c_ops = bp->cnic_ops;
  10421. if (c_ops)
  10422. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10423. mutex_unlock(&bp->cnic_mutex);
  10424. return rc;
  10425. }
  10426. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10427. {
  10428. struct cnic_ops *c_ops;
  10429. int rc = 0;
  10430. rcu_read_lock();
  10431. c_ops = rcu_dereference(bp->cnic_ops);
  10432. if (c_ops)
  10433. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10434. rcu_read_unlock();
  10435. return rc;
  10436. }
  10437. /*
  10438. * for commands that have no data
  10439. */
  10440. static int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10441. {
  10442. struct cnic_ctl_info ctl = {0};
  10443. ctl.cmd = cmd;
  10444. return bnx2x_cnic_ctl_send(bp, &ctl);
  10445. }
  10446. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid)
  10447. {
  10448. struct cnic_ctl_info ctl;
  10449. /* first we tell CNIC and only then we count this as a completion */
  10450. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10451. ctl.data.comp.cid = cid;
  10452. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10453. bnx2x_cnic_sp_post(bp, 1);
  10454. }
  10455. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10456. {
  10457. struct bnx2x *bp = netdev_priv(dev);
  10458. int rc = 0;
  10459. switch (ctl->cmd) {
  10460. case DRV_CTL_CTXTBL_WR_CMD: {
  10461. u32 index = ctl->data.io.offset;
  10462. dma_addr_t addr = ctl->data.io.dma_addr;
  10463. bnx2x_ilt_wr(bp, index, addr);
  10464. break;
  10465. }
  10466. case DRV_CTL_COMPLETION_CMD: {
  10467. int count = ctl->data.comp.comp_count;
  10468. bnx2x_cnic_sp_post(bp, count);
  10469. break;
  10470. }
  10471. /* rtnl_lock is held. */
  10472. case DRV_CTL_START_L2_CMD: {
  10473. u32 cli = ctl->data.ring.client_id;
  10474. bp->rx_mode_cl_mask |= (1 << cli);
  10475. bnx2x_set_storm_rx_mode(bp);
  10476. break;
  10477. }
  10478. /* rtnl_lock is held. */
  10479. case DRV_CTL_STOP_L2_CMD: {
  10480. u32 cli = ctl->data.ring.client_id;
  10481. bp->rx_mode_cl_mask &= ~(1 << cli);
  10482. bnx2x_set_storm_rx_mode(bp);
  10483. break;
  10484. }
  10485. default:
  10486. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  10487. rc = -EINVAL;
  10488. }
  10489. return rc;
  10490. }
  10491. static void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  10492. {
  10493. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10494. if (bp->flags & USING_MSIX_FLAG) {
  10495. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  10496. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  10497. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  10498. } else {
  10499. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  10500. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  10501. }
  10502. cp->irq_arr[0].status_blk = bp->cnic_sb;
  10503. cp->irq_arr[0].status_blk_num = CNIC_SB_ID(bp);
  10504. cp->irq_arr[1].status_blk = bp->def_status_blk;
  10505. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  10506. cp->num_irq = 2;
  10507. }
  10508. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  10509. void *data)
  10510. {
  10511. struct bnx2x *bp = netdev_priv(dev);
  10512. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10513. if (ops == NULL)
  10514. return -EINVAL;
  10515. if (atomic_read(&bp->intr_sem) != 0)
  10516. return -EBUSY;
  10517. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  10518. if (!bp->cnic_kwq)
  10519. return -ENOMEM;
  10520. bp->cnic_kwq_cons = bp->cnic_kwq;
  10521. bp->cnic_kwq_prod = bp->cnic_kwq;
  10522. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  10523. bp->cnic_spq_pending = 0;
  10524. bp->cnic_kwq_pending = 0;
  10525. bp->cnic_data = data;
  10526. cp->num_irq = 0;
  10527. cp->drv_state = CNIC_DRV_STATE_REGD;
  10528. bnx2x_init_sb(bp, bp->cnic_sb, bp->cnic_sb_mapping, CNIC_SB_ID(bp));
  10529. bnx2x_setup_cnic_irq_info(bp);
  10530. bnx2x_set_iscsi_eth_mac_addr(bp, 1);
  10531. bp->cnic_flags |= BNX2X_CNIC_FLAG_MAC_SET;
  10532. rcu_assign_pointer(bp->cnic_ops, ops);
  10533. return 0;
  10534. }
  10535. static int bnx2x_unregister_cnic(struct net_device *dev)
  10536. {
  10537. struct bnx2x *bp = netdev_priv(dev);
  10538. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10539. mutex_lock(&bp->cnic_mutex);
  10540. if (bp->cnic_flags & BNX2X_CNIC_FLAG_MAC_SET) {
  10541. bp->cnic_flags &= ~BNX2X_CNIC_FLAG_MAC_SET;
  10542. bnx2x_set_iscsi_eth_mac_addr(bp, 0);
  10543. }
  10544. cp->drv_state = 0;
  10545. rcu_assign_pointer(bp->cnic_ops, NULL);
  10546. mutex_unlock(&bp->cnic_mutex);
  10547. synchronize_rcu();
  10548. kfree(bp->cnic_kwq);
  10549. bp->cnic_kwq = NULL;
  10550. return 0;
  10551. }
  10552. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  10553. {
  10554. struct bnx2x *bp = netdev_priv(dev);
  10555. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10556. cp->drv_owner = THIS_MODULE;
  10557. cp->chip_id = CHIP_ID(bp);
  10558. cp->pdev = bp->pdev;
  10559. cp->io_base = bp->regview;
  10560. cp->io_base2 = bp->doorbells;
  10561. cp->max_kwqe_pending = 8;
  10562. cp->ctx_blk_size = CNIC_CTX_PER_ILT * sizeof(union cdu_context);
  10563. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) + 1;
  10564. cp->ctx_tbl_len = CNIC_ILT_LINES;
  10565. cp->starting_cid = BCM_CNIC_CID_START;
  10566. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  10567. cp->drv_ctl = bnx2x_drv_ctl;
  10568. cp->drv_register_cnic = bnx2x_register_cnic;
  10569. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  10570. return cp;
  10571. }
  10572. EXPORT_SYMBOL(bnx2x_cnic_probe);
  10573. #endif /* BCM_CNIC */