bnx2x_main.c 314 KB

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