bnx2x_main.c 319 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2012 Broadcom Corporation
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation.
  8. *
  9. * Maintained by: Eilon Greenstein <eilong@broadcom.com>
  10. * Written by: Eliezer Tamir
  11. * Based on code from Michael Chan's bnx2 driver
  12. * UDP CSUM errata workaround by Arik Gendelman
  13. * Slowpath and fastpath rework by Vladislav Zolotarov
  14. * Statistics and Link management by Yitchak Gertner
  15. *
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/module.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/kernel.h>
  21. #include <linux/device.h> /* for dev_info() */
  22. #include <linux/timer.h>
  23. #include <linux/errno.h>
  24. #include <linux/ioport.h>
  25. #include <linux/slab.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.h>
  41. #include <linux/if_vlan.h>
  42. #include <net/ip.h>
  43. #include <net/ipv6.h>
  44. #include <net/tcp.h>
  45. #include <net/checksum.h>
  46. #include <net/ip6_checksum.h>
  47. #include <linux/workqueue.h>
  48. #include <linux/crc32.h>
  49. #include <linux/crc32c.h>
  50. #include <linux/prefetch.h>
  51. #include <linux/zlib.h>
  52. #include <linux/io.h>
  53. #include <linux/stringify.h>
  54. #include <linux/vmalloc.h>
  55. #include "bnx2x.h"
  56. #include "bnx2x_init.h"
  57. #include "bnx2x_init_ops.h"
  58. #include "bnx2x_cmn.h"
  59. #include "bnx2x_dcb.h"
  60. #include "bnx2x_sp.h"
  61. #include <linux/firmware.h>
  62. #include "bnx2x_fw_file_hdr.h"
  63. /* FW files */
  64. #define FW_FILE_VERSION \
  65. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  66. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  68. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  69. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  70. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  72. /* Time in jiffies before concluding the transmitter is hung */
  73. #define TX_TIMEOUT (5*HZ)
  74. static char version[] __devinitdata =
  75. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  76. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  77. MODULE_AUTHOR("Eliezer Tamir");
  78. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  79. "BCM57710/57711/57711E/"
  80. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  81. "57840/57840_MF Driver");
  82. MODULE_LICENSE("GPL");
  83. MODULE_VERSION(DRV_MODULE_VERSION);
  84. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  87. static int multi_mode = 1;
  88. module_param(multi_mode, int, 0);
  89. MODULE_PARM_DESC(multi_mode, " Multi queue mode "
  90. "(0 Disable; 1 Enable (default))");
  91. int num_queues;
  92. module_param(num_queues, int, 0);
  93. MODULE_PARM_DESC(num_queues, " Number of queues for multi_mode=1"
  94. " (default is as a number of CPUs)");
  95. static int disable_tpa;
  96. module_param(disable_tpa, int, 0);
  97. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  98. #define INT_MODE_INTx 1
  99. #define INT_MODE_MSI 2
  100. static int int_mode;
  101. module_param(int_mode, int, 0);
  102. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  103. "(1 INT#x; 2 MSI)");
  104. static int dropless_fc;
  105. module_param(dropless_fc, int, 0);
  106. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  107. static int mrrs = -1;
  108. module_param(mrrs, int, 0);
  109. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  110. static int debug;
  111. module_param(debug, int, 0);
  112. MODULE_PARM_DESC(debug, " Default debug msglevel");
  113. struct workqueue_struct *bnx2x_wq;
  114. enum bnx2x_board_type {
  115. BCM57710 = 0,
  116. BCM57711,
  117. BCM57711E,
  118. BCM57712,
  119. BCM57712_MF,
  120. BCM57800,
  121. BCM57800_MF,
  122. BCM57810,
  123. BCM57810_MF,
  124. BCM57840,
  125. BCM57840_MF
  126. };
  127. /* indexed by board_type, above */
  128. static struct {
  129. char *name;
  130. } board_info[] __devinitdata = {
  131. { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  132. { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  133. { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  134. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  135. { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  136. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  137. { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  138. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  139. { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  140. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  141. { "Broadcom NetXtreme II BCM57840 10/20 Gigabit "
  142. "Ethernet Multi Function"}
  143. };
  144. #ifndef PCI_DEVICE_ID_NX2_57710
  145. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  146. #endif
  147. #ifndef PCI_DEVICE_ID_NX2_57711
  148. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  149. #endif
  150. #ifndef PCI_DEVICE_ID_NX2_57711E
  151. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  152. #endif
  153. #ifndef PCI_DEVICE_ID_NX2_57712
  154. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  155. #endif
  156. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  157. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  158. #endif
  159. #ifndef PCI_DEVICE_ID_NX2_57800
  160. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  161. #endif
  162. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  163. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  164. #endif
  165. #ifndef PCI_DEVICE_ID_NX2_57810
  166. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  167. #endif
  168. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  169. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57840
  172. #define PCI_DEVICE_ID_NX2_57840 CHIP_NUM_57840
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  175. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  176. #endif
  177. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  178. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  179. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  180. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  181. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  182. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  183. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  184. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  185. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  186. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  187. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840), BCM57840 },
  188. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  189. { 0 }
  190. };
  191. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  192. /****************************************************************************
  193. * General service functions
  194. ****************************************************************************/
  195. static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
  196. u32 addr, dma_addr_t mapping)
  197. {
  198. REG_WR(bp, addr, U64_LO(mapping));
  199. REG_WR(bp, addr + 4, U64_HI(mapping));
  200. }
  201. static inline void storm_memset_spq_addr(struct bnx2x *bp,
  202. dma_addr_t mapping, u16 abs_fid)
  203. {
  204. u32 addr = XSEM_REG_FAST_MEMORY +
  205. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  206. __storm_memset_dma_mapping(bp, addr, mapping);
  207. }
  208. static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  209. u16 pf_id)
  210. {
  211. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  212. pf_id);
  213. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  214. pf_id);
  215. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  216. pf_id);
  217. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  218. pf_id);
  219. }
  220. static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  221. u8 enable)
  222. {
  223. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  224. enable);
  225. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  226. enable);
  227. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  228. enable);
  229. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  230. enable);
  231. }
  232. static inline void storm_memset_eq_data(struct bnx2x *bp,
  233. struct event_ring_data *eq_data,
  234. u16 pfid)
  235. {
  236. size_t size = sizeof(struct event_ring_data);
  237. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  238. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  239. }
  240. static inline void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  241. u16 pfid)
  242. {
  243. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  244. REG_WR16(bp, addr, eq_prod);
  245. }
  246. /* used only at init
  247. * locking is done by mcp
  248. */
  249. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  250. {
  251. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  252. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  253. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  254. PCICFG_VENDOR_ID_OFFSET);
  255. }
  256. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  257. {
  258. u32 val;
  259. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  260. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  261. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  262. PCICFG_VENDOR_ID_OFFSET);
  263. return val;
  264. }
  265. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  266. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  267. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  268. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  269. #define DMAE_DP_DST_NONE "dst_addr [none]"
  270. static void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae,
  271. int msglvl)
  272. {
  273. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  274. switch (dmae->opcode & DMAE_COMMAND_DST) {
  275. case DMAE_CMD_DST_PCI:
  276. if (src_type == DMAE_CMD_SRC_PCI)
  277. DP(msglvl, "DMAE: opcode 0x%08x\n"
  278. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  279. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  280. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  281. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  282. dmae->comp_addr_hi, dmae->comp_addr_lo,
  283. dmae->comp_val);
  284. else
  285. DP(msglvl, "DMAE: opcode 0x%08x\n"
  286. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  287. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  288. dmae->opcode, dmae->src_addr_lo >> 2,
  289. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  290. dmae->comp_addr_hi, dmae->comp_addr_lo,
  291. dmae->comp_val);
  292. break;
  293. case DMAE_CMD_DST_GRC:
  294. if (src_type == DMAE_CMD_SRC_PCI)
  295. DP(msglvl, "DMAE: opcode 0x%08x\n"
  296. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  297. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  298. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  299. dmae->len, dmae->dst_addr_lo >> 2,
  300. dmae->comp_addr_hi, dmae->comp_addr_lo,
  301. dmae->comp_val);
  302. else
  303. DP(msglvl, "DMAE: opcode 0x%08x\n"
  304. "src [%08x], len [%d*4], dst [%08x]\n"
  305. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  306. dmae->opcode, dmae->src_addr_lo >> 2,
  307. dmae->len, dmae->dst_addr_lo >> 2,
  308. dmae->comp_addr_hi, dmae->comp_addr_lo,
  309. dmae->comp_val);
  310. break;
  311. default:
  312. if (src_type == DMAE_CMD_SRC_PCI)
  313. DP(msglvl, "DMAE: opcode 0x%08x\n"
  314. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  315. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  316. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  317. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  318. dmae->comp_val);
  319. else
  320. DP(msglvl, "DMAE: opcode 0x%08x\n"
  321. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  322. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  323. dmae->opcode, dmae->src_addr_lo >> 2,
  324. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  325. dmae->comp_val);
  326. break;
  327. }
  328. }
  329. /* copy command into DMAE command memory and set DMAE command go */
  330. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  331. {
  332. u32 cmd_offset;
  333. int i;
  334. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  335. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  336. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  337. }
  338. REG_WR(bp, dmae_reg_go_c[idx], 1);
  339. }
  340. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  341. {
  342. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  343. DMAE_CMD_C_ENABLE);
  344. }
  345. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  346. {
  347. return opcode & ~DMAE_CMD_SRC_RESET;
  348. }
  349. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  350. bool with_comp, u8 comp_type)
  351. {
  352. u32 opcode = 0;
  353. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  354. (dst_type << DMAE_COMMAND_DST_SHIFT));
  355. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  356. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  357. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  358. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  359. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  360. #ifdef __BIG_ENDIAN
  361. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  362. #else
  363. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  364. #endif
  365. if (with_comp)
  366. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  367. return opcode;
  368. }
  369. static void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  370. struct dmae_command *dmae,
  371. u8 src_type, u8 dst_type)
  372. {
  373. memset(dmae, 0, sizeof(struct dmae_command));
  374. /* set the opcode */
  375. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  376. true, DMAE_COMP_PCI);
  377. /* fill in the completion parameters */
  378. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  379. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  380. dmae->comp_val = DMAE_COMP_VAL;
  381. }
  382. /* issue a dmae command over the init-channel and wailt for completion */
  383. static int bnx2x_issue_dmae_with_comp(struct bnx2x *bp,
  384. struct dmae_command *dmae)
  385. {
  386. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  387. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  388. int rc = 0;
  389. /*
  390. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  391. * as long as this code is called both from syscall context and
  392. * from ndo_set_rx_mode() flow that may be called from BH.
  393. */
  394. spin_lock_bh(&bp->dmae_lock);
  395. /* reset completion */
  396. *wb_comp = 0;
  397. /* post the command on the channel used for initializations */
  398. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  399. /* wait for completion */
  400. udelay(5);
  401. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  402. if (!cnt ||
  403. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  404. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  405. BNX2X_ERR("DMAE timeout!\n");
  406. rc = DMAE_TIMEOUT;
  407. goto unlock;
  408. }
  409. cnt--;
  410. udelay(50);
  411. }
  412. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  413. BNX2X_ERR("DMAE PCI error!\n");
  414. rc = DMAE_PCI_ERROR;
  415. }
  416. unlock:
  417. spin_unlock_bh(&bp->dmae_lock);
  418. return rc;
  419. }
  420. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  421. u32 len32)
  422. {
  423. struct dmae_command dmae;
  424. if (!bp->dmae_ready) {
  425. u32 *data = bnx2x_sp(bp, wb_data[0]);
  426. if (CHIP_IS_E1(bp))
  427. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  428. else
  429. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  430. return;
  431. }
  432. /* set opcode and fixed command fields */
  433. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  434. /* fill in addresses and len */
  435. dmae.src_addr_lo = U64_LO(dma_addr);
  436. dmae.src_addr_hi = U64_HI(dma_addr);
  437. dmae.dst_addr_lo = dst_addr >> 2;
  438. dmae.dst_addr_hi = 0;
  439. dmae.len = len32;
  440. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  441. /* issue the command and wait for completion */
  442. bnx2x_issue_dmae_with_comp(bp, &dmae);
  443. }
  444. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  445. {
  446. struct dmae_command dmae;
  447. if (!bp->dmae_ready) {
  448. u32 *data = bnx2x_sp(bp, wb_data[0]);
  449. int i;
  450. if (CHIP_IS_E1(bp))
  451. for (i = 0; i < len32; i++)
  452. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  453. else
  454. for (i = 0; i < len32; i++)
  455. data[i] = REG_RD(bp, src_addr + i*4);
  456. return;
  457. }
  458. /* set opcode and fixed command fields */
  459. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  460. /* fill in addresses and len */
  461. dmae.src_addr_lo = src_addr >> 2;
  462. dmae.src_addr_hi = 0;
  463. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  464. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  465. dmae.len = len32;
  466. bnx2x_dp_dmae(bp, &dmae, BNX2X_MSG_OFF);
  467. /* issue the command and wait for completion */
  468. bnx2x_issue_dmae_with_comp(bp, &dmae);
  469. }
  470. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  471. u32 addr, u32 len)
  472. {
  473. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  474. int offset = 0;
  475. while (len > dmae_wr_max) {
  476. bnx2x_write_dmae(bp, phys_addr + offset,
  477. addr + offset, dmae_wr_max);
  478. offset += dmae_wr_max * 4;
  479. len -= dmae_wr_max;
  480. }
  481. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  482. }
  483. /* used only for slowpath so not inlined */
  484. static void bnx2x_wb_wr(struct bnx2x *bp, int reg, u32 val_hi, u32 val_lo)
  485. {
  486. u32 wb_write[2];
  487. wb_write[0] = val_hi;
  488. wb_write[1] = val_lo;
  489. REG_WR_DMAE(bp, reg, wb_write, 2);
  490. }
  491. #ifdef USE_WB_RD
  492. static u64 bnx2x_wb_rd(struct bnx2x *bp, int reg)
  493. {
  494. u32 wb_data[2];
  495. REG_RD_DMAE(bp, reg, wb_data, 2);
  496. return HILO_U64(wb_data[0], wb_data[1]);
  497. }
  498. #endif
  499. static int bnx2x_mc_assert(struct bnx2x *bp)
  500. {
  501. char last_idx;
  502. int i, rc = 0;
  503. u32 row0, row1, row2, row3;
  504. /* XSTORM */
  505. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  506. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  507. if (last_idx)
  508. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  509. /* print the asserts */
  510. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  511. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  512. XSTORM_ASSERT_LIST_OFFSET(i));
  513. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  514. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  515. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  516. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  517. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  518. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  519. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  520. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  521. i, row3, row2, row1, row0);
  522. rc++;
  523. } else {
  524. break;
  525. }
  526. }
  527. /* TSTORM */
  528. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  529. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  530. if (last_idx)
  531. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  532. /* print the asserts */
  533. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  534. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  535. TSTORM_ASSERT_LIST_OFFSET(i));
  536. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  537. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  538. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  539. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  540. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  541. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  542. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  543. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  544. i, row3, row2, row1, row0);
  545. rc++;
  546. } else {
  547. break;
  548. }
  549. }
  550. /* CSTORM */
  551. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  552. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  553. if (last_idx)
  554. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  555. /* print the asserts */
  556. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  557. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  558. CSTORM_ASSERT_LIST_OFFSET(i));
  559. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  560. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  561. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  562. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  563. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  564. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  565. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  566. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  567. i, row3, row2, row1, row0);
  568. rc++;
  569. } else {
  570. break;
  571. }
  572. }
  573. /* USTORM */
  574. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  575. USTORM_ASSERT_LIST_INDEX_OFFSET);
  576. if (last_idx)
  577. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  578. /* print the asserts */
  579. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  580. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  581. USTORM_ASSERT_LIST_OFFSET(i));
  582. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  583. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  584. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  585. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  586. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  587. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  588. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  589. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  590. i, row3, row2, row1, row0);
  591. rc++;
  592. } else {
  593. break;
  594. }
  595. }
  596. return rc;
  597. }
  598. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  599. {
  600. u32 addr, val;
  601. u32 mark, offset;
  602. __be32 data[9];
  603. int word;
  604. u32 trace_shmem_base;
  605. if (BP_NOMCP(bp)) {
  606. BNX2X_ERR("NO MCP - can not dump\n");
  607. return;
  608. }
  609. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  610. (bp->common.bc_ver & 0xff0000) >> 16,
  611. (bp->common.bc_ver & 0xff00) >> 8,
  612. (bp->common.bc_ver & 0xff));
  613. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  614. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  615. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  616. if (BP_PATH(bp) == 0)
  617. trace_shmem_base = bp->common.shmem_base;
  618. else
  619. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  620. addr = trace_shmem_base - 0x800;
  621. /* validate TRCB signature */
  622. mark = REG_RD(bp, addr);
  623. if (mark != MFW_TRACE_SIGNATURE) {
  624. BNX2X_ERR("Trace buffer signature is missing.");
  625. return ;
  626. }
  627. /* read cyclic buffer pointer */
  628. addr += 4;
  629. mark = REG_RD(bp, addr);
  630. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  631. + ((mark + 0x3) & ~0x3) - 0x08000000;
  632. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  633. printk("%s", lvl);
  634. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  635. for (word = 0; word < 8; word++)
  636. data[word] = htonl(REG_RD(bp, offset + 4*word));
  637. data[8] = 0x0;
  638. pr_cont("%s", (char *)data);
  639. }
  640. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  641. for (word = 0; word < 8; word++)
  642. data[word] = htonl(REG_RD(bp, offset + 4*word));
  643. data[8] = 0x0;
  644. pr_cont("%s", (char *)data);
  645. }
  646. printk("%s" "end of fw dump\n", lvl);
  647. }
  648. static inline void bnx2x_fw_dump(struct bnx2x *bp)
  649. {
  650. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  651. }
  652. void bnx2x_panic_dump(struct bnx2x *bp)
  653. {
  654. int i;
  655. u16 j;
  656. struct hc_sp_status_block_data sp_sb_data;
  657. int func = BP_FUNC(bp);
  658. #ifdef BNX2X_STOP_ON_ERROR
  659. u16 start = 0, end = 0;
  660. u8 cos;
  661. #endif
  662. bp->stats_state = STATS_STATE_DISABLED;
  663. bp->eth_stats.unrecoverable_error++;
  664. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  665. BNX2X_ERR("begin crash dump -----------------\n");
  666. /* Indices */
  667. /* Common */
  668. BNX2X_ERR("def_idx(0x%x) def_att_idx(0x%x) attn_state(0x%x) spq_prod_idx(0x%x) next_stats_cnt(0x%x)\n",
  669. bp->def_idx, bp->def_att_idx, bp->attn_state,
  670. bp->spq_prod_idx, bp->stats_counter);
  671. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  672. bp->def_status_blk->atten_status_block.attn_bits,
  673. bp->def_status_blk->atten_status_block.attn_bits_ack,
  674. bp->def_status_blk->atten_status_block.status_block_id,
  675. bp->def_status_blk->atten_status_block.attn_bits_index);
  676. BNX2X_ERR(" def (");
  677. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  678. pr_cont("0x%x%s",
  679. bp->def_status_blk->sp_sb.index_values[i],
  680. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  681. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  682. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  683. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  684. i*sizeof(u32));
  685. pr_cont("igu_sb_id(0x%x) igu_seg_id(0x%x) pf_id(0x%x) vnic_id(0x%x) vf_id(0x%x) vf_valid (0x%x) state(0x%x)\n",
  686. sp_sb_data.igu_sb_id,
  687. sp_sb_data.igu_seg_id,
  688. sp_sb_data.p_func.pf_id,
  689. sp_sb_data.p_func.vnic_id,
  690. sp_sb_data.p_func.vf_id,
  691. sp_sb_data.p_func.vf_valid,
  692. sp_sb_data.state);
  693. for_each_eth_queue(bp, i) {
  694. struct bnx2x_fastpath *fp = &bp->fp[i];
  695. int loop;
  696. struct hc_status_block_data_e2 sb_data_e2;
  697. struct hc_status_block_data_e1x sb_data_e1x;
  698. struct hc_status_block_sm *hc_sm_p =
  699. CHIP_IS_E1x(bp) ?
  700. sb_data_e1x.common.state_machine :
  701. sb_data_e2.common.state_machine;
  702. struct hc_index_data *hc_index_p =
  703. CHIP_IS_E1x(bp) ?
  704. sb_data_e1x.index_data :
  705. sb_data_e2.index_data;
  706. u8 data_size, cos;
  707. u32 *sb_data_p;
  708. struct bnx2x_fp_txdata txdata;
  709. /* Rx */
  710. BNX2X_ERR("fp%d: rx_bd_prod(0x%x) rx_bd_cons(0x%x) rx_comp_prod(0x%x) rx_comp_cons(0x%x) *rx_cons_sb(0x%x)\n",
  711. i, fp->rx_bd_prod, fp->rx_bd_cons,
  712. fp->rx_comp_prod,
  713. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  714. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  715. fp->rx_sge_prod, fp->last_max_sge,
  716. le16_to_cpu(fp->fp_hc_idx));
  717. /* Tx */
  718. for_each_cos_in_tx_queue(fp, cos)
  719. {
  720. txdata = fp->txdata[cos];
  721. BNX2X_ERR("fp%d: tx_pkt_prod(0x%x) tx_pkt_cons(0x%x) tx_bd_prod(0x%x) tx_bd_cons(0x%x) *tx_cons_sb(0x%x)\n",
  722. i, txdata.tx_pkt_prod,
  723. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  724. txdata.tx_bd_cons,
  725. le16_to_cpu(*txdata.tx_cons_sb));
  726. }
  727. loop = CHIP_IS_E1x(bp) ?
  728. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  729. /* host sb data */
  730. #ifdef BCM_CNIC
  731. if (IS_FCOE_FP(fp))
  732. continue;
  733. #endif
  734. BNX2X_ERR(" run indexes (");
  735. for (j = 0; j < HC_SB_MAX_SM; j++)
  736. pr_cont("0x%x%s",
  737. fp->sb_running_index[j],
  738. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  739. BNX2X_ERR(" indexes (");
  740. for (j = 0; j < loop; j++)
  741. pr_cont("0x%x%s",
  742. fp->sb_index_values[j],
  743. (j == loop - 1) ? ")" : " ");
  744. /* fw sb data */
  745. data_size = CHIP_IS_E1x(bp) ?
  746. sizeof(struct hc_status_block_data_e1x) :
  747. sizeof(struct hc_status_block_data_e2);
  748. data_size /= sizeof(u32);
  749. sb_data_p = CHIP_IS_E1x(bp) ?
  750. (u32 *)&sb_data_e1x :
  751. (u32 *)&sb_data_e2;
  752. /* copy sb data in here */
  753. for (j = 0; j < data_size; j++)
  754. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  755. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  756. j * sizeof(u32));
  757. if (!CHIP_IS_E1x(bp)) {
  758. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  759. sb_data_e2.common.p_func.pf_id,
  760. sb_data_e2.common.p_func.vf_id,
  761. sb_data_e2.common.p_func.vf_valid,
  762. sb_data_e2.common.p_func.vnic_id,
  763. sb_data_e2.common.same_igu_sb_1b,
  764. sb_data_e2.common.state);
  765. } else {
  766. pr_cont("pf_id(0x%x) vf_id(0x%x) vf_valid(0x%x) vnic_id(0x%x) same_igu_sb_1b(0x%x) state(0x%x)\n",
  767. sb_data_e1x.common.p_func.pf_id,
  768. sb_data_e1x.common.p_func.vf_id,
  769. sb_data_e1x.common.p_func.vf_valid,
  770. sb_data_e1x.common.p_func.vnic_id,
  771. sb_data_e1x.common.same_igu_sb_1b,
  772. sb_data_e1x.common.state);
  773. }
  774. /* SB_SMs data */
  775. for (j = 0; j < HC_SB_MAX_SM; j++) {
  776. pr_cont("SM[%d] __flags (0x%x) igu_sb_id (0x%x) igu_seg_id(0x%x) time_to_expire (0x%x) timer_value(0x%x)\n",
  777. j, hc_sm_p[j].__flags,
  778. hc_sm_p[j].igu_sb_id,
  779. hc_sm_p[j].igu_seg_id,
  780. hc_sm_p[j].time_to_expire,
  781. hc_sm_p[j].timer_value);
  782. }
  783. /* Indecies data */
  784. for (j = 0; j < loop; j++) {
  785. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  786. hc_index_p[j].flags,
  787. hc_index_p[j].timeout);
  788. }
  789. }
  790. #ifdef BNX2X_STOP_ON_ERROR
  791. /* Rings */
  792. /* Rx */
  793. for_each_rx_queue(bp, i) {
  794. struct bnx2x_fastpath *fp = &bp->fp[i];
  795. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  796. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  797. for (j = start; j != end; j = RX_BD(j + 1)) {
  798. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  799. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  800. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  801. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  802. }
  803. start = RX_SGE(fp->rx_sge_prod);
  804. end = RX_SGE(fp->last_max_sge);
  805. for (j = start; j != end; j = RX_SGE(j + 1)) {
  806. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  807. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  808. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  809. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  810. }
  811. start = RCQ_BD(fp->rx_comp_cons - 10);
  812. end = RCQ_BD(fp->rx_comp_cons + 503);
  813. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  814. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  815. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  816. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  817. }
  818. }
  819. /* Tx */
  820. for_each_tx_queue(bp, i) {
  821. struct bnx2x_fastpath *fp = &bp->fp[i];
  822. for_each_cos_in_tx_queue(fp, cos) {
  823. struct bnx2x_fp_txdata *txdata = &fp->txdata[cos];
  824. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  825. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  826. for (j = start; j != end; j = TX_BD(j + 1)) {
  827. struct sw_tx_bd *sw_bd =
  828. &txdata->tx_buf_ring[j];
  829. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  830. i, cos, j, sw_bd->skb,
  831. sw_bd->first_bd);
  832. }
  833. start = TX_BD(txdata->tx_bd_cons - 10);
  834. end = TX_BD(txdata->tx_bd_cons + 254);
  835. for (j = start; j != end; j = TX_BD(j + 1)) {
  836. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  837. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  838. i, cos, j, tx_bd[0], tx_bd[1],
  839. tx_bd[2], tx_bd[3]);
  840. }
  841. }
  842. }
  843. #endif
  844. bnx2x_fw_dump(bp);
  845. bnx2x_mc_assert(bp);
  846. BNX2X_ERR("end crash dump -----------------\n");
  847. }
  848. /*
  849. * FLR Support for E2
  850. *
  851. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  852. * initialization.
  853. */
  854. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  855. #define FLR_WAIT_INTERVAL 50 /* usec */
  856. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  857. struct pbf_pN_buf_regs {
  858. int pN;
  859. u32 init_crd;
  860. u32 crd;
  861. u32 crd_freed;
  862. };
  863. struct pbf_pN_cmd_regs {
  864. int pN;
  865. u32 lines_occup;
  866. u32 lines_freed;
  867. };
  868. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  869. struct pbf_pN_buf_regs *regs,
  870. u32 poll_count)
  871. {
  872. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  873. u32 cur_cnt = poll_count;
  874. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  875. crd = crd_start = REG_RD(bp, regs->crd);
  876. init_crd = REG_RD(bp, regs->init_crd);
  877. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  878. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  879. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  880. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  881. (init_crd - crd_start))) {
  882. if (cur_cnt--) {
  883. udelay(FLR_WAIT_INTERVAL);
  884. crd = REG_RD(bp, regs->crd);
  885. crd_freed = REG_RD(bp, regs->crd_freed);
  886. } else {
  887. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  888. regs->pN);
  889. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  890. regs->pN, crd);
  891. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  892. regs->pN, crd_freed);
  893. break;
  894. }
  895. }
  896. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  897. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  898. }
  899. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  900. struct pbf_pN_cmd_regs *regs,
  901. u32 poll_count)
  902. {
  903. u32 occup, to_free, freed, freed_start;
  904. u32 cur_cnt = poll_count;
  905. occup = to_free = REG_RD(bp, regs->lines_occup);
  906. freed = freed_start = REG_RD(bp, regs->lines_freed);
  907. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  908. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  909. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  910. if (cur_cnt--) {
  911. udelay(FLR_WAIT_INTERVAL);
  912. occup = REG_RD(bp, regs->lines_occup);
  913. freed = REG_RD(bp, regs->lines_freed);
  914. } else {
  915. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  916. regs->pN);
  917. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  918. regs->pN, occup);
  919. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  920. regs->pN, freed);
  921. break;
  922. }
  923. }
  924. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  925. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  926. }
  927. static inline u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  928. u32 expected, u32 poll_count)
  929. {
  930. u32 cur_cnt = poll_count;
  931. u32 val;
  932. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  933. udelay(FLR_WAIT_INTERVAL);
  934. return val;
  935. }
  936. static inline int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  937. char *msg, u32 poll_cnt)
  938. {
  939. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  940. if (val != 0) {
  941. BNX2X_ERR("%s usage count=%d\n", msg, val);
  942. return 1;
  943. }
  944. return 0;
  945. }
  946. static u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  947. {
  948. /* adjust polling timeout */
  949. if (CHIP_REV_IS_EMUL(bp))
  950. return FLR_POLL_CNT * 2000;
  951. if (CHIP_REV_IS_FPGA(bp))
  952. return FLR_POLL_CNT * 120;
  953. return FLR_POLL_CNT;
  954. }
  955. static void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  956. {
  957. struct pbf_pN_cmd_regs cmd_regs[] = {
  958. {0, (CHIP_IS_E3B0(bp)) ?
  959. PBF_REG_TQ_OCCUPANCY_Q0 :
  960. PBF_REG_P0_TQ_OCCUPANCY,
  961. (CHIP_IS_E3B0(bp)) ?
  962. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  963. PBF_REG_P0_TQ_LINES_FREED_CNT},
  964. {1, (CHIP_IS_E3B0(bp)) ?
  965. PBF_REG_TQ_OCCUPANCY_Q1 :
  966. PBF_REG_P1_TQ_OCCUPANCY,
  967. (CHIP_IS_E3B0(bp)) ?
  968. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  969. PBF_REG_P1_TQ_LINES_FREED_CNT},
  970. {4, (CHIP_IS_E3B0(bp)) ?
  971. PBF_REG_TQ_OCCUPANCY_LB_Q :
  972. PBF_REG_P4_TQ_OCCUPANCY,
  973. (CHIP_IS_E3B0(bp)) ?
  974. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  975. PBF_REG_P4_TQ_LINES_FREED_CNT}
  976. };
  977. struct pbf_pN_buf_regs buf_regs[] = {
  978. {0, (CHIP_IS_E3B0(bp)) ?
  979. PBF_REG_INIT_CRD_Q0 :
  980. PBF_REG_P0_INIT_CRD ,
  981. (CHIP_IS_E3B0(bp)) ?
  982. PBF_REG_CREDIT_Q0 :
  983. PBF_REG_P0_CREDIT,
  984. (CHIP_IS_E3B0(bp)) ?
  985. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  986. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  987. {1, (CHIP_IS_E3B0(bp)) ?
  988. PBF_REG_INIT_CRD_Q1 :
  989. PBF_REG_P1_INIT_CRD,
  990. (CHIP_IS_E3B0(bp)) ?
  991. PBF_REG_CREDIT_Q1 :
  992. PBF_REG_P1_CREDIT,
  993. (CHIP_IS_E3B0(bp)) ?
  994. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  995. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  996. {4, (CHIP_IS_E3B0(bp)) ?
  997. PBF_REG_INIT_CRD_LB_Q :
  998. PBF_REG_P4_INIT_CRD,
  999. (CHIP_IS_E3B0(bp)) ?
  1000. PBF_REG_CREDIT_LB_Q :
  1001. PBF_REG_P4_CREDIT,
  1002. (CHIP_IS_E3B0(bp)) ?
  1003. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1004. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1005. };
  1006. int i;
  1007. /* Verify the command queues are flushed P0, P1, P4 */
  1008. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1009. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1010. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1011. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1012. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1013. }
  1014. #define OP_GEN_PARAM(param) \
  1015. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1016. #define OP_GEN_TYPE(type) \
  1017. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1018. #define OP_GEN_AGG_VECT(index) \
  1019. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1020. static inline int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func,
  1021. u32 poll_cnt)
  1022. {
  1023. struct sdm_op_gen op_gen = {0};
  1024. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1025. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1026. int ret = 0;
  1027. if (REG_RD(bp, comp_addr)) {
  1028. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1029. return 1;
  1030. }
  1031. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1032. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1033. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1034. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1035. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1036. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1037. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1038. BNX2X_ERR("FW final cleanup did not succeed\n");
  1039. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1040. (REG_RD(bp, comp_addr)));
  1041. ret = 1;
  1042. }
  1043. /* Zero completion for nxt FLR */
  1044. REG_WR(bp, comp_addr, 0);
  1045. return ret;
  1046. }
  1047. static inline u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1048. {
  1049. int pos;
  1050. u16 status;
  1051. pos = pci_pcie_cap(dev);
  1052. if (!pos)
  1053. return false;
  1054. pci_read_config_word(dev, pos + PCI_EXP_DEVSTA, &status);
  1055. return status & PCI_EXP_DEVSTA_TRPND;
  1056. }
  1057. /* PF FLR specific routines
  1058. */
  1059. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1060. {
  1061. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1062. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1063. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1064. "CFC PF usage counter timed out",
  1065. poll_cnt))
  1066. return 1;
  1067. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1068. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1069. DORQ_REG_PF_USAGE_CNT,
  1070. "DQ PF usage counter timed out",
  1071. poll_cnt))
  1072. return 1;
  1073. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1074. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1075. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1076. "QM PF usage counter timed out",
  1077. poll_cnt))
  1078. return 1;
  1079. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1080. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1081. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1082. "Timers VNIC usage counter timed out",
  1083. poll_cnt))
  1084. return 1;
  1085. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1086. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1087. "Timers NUM_SCANS usage counter timed out",
  1088. poll_cnt))
  1089. return 1;
  1090. /* Wait DMAE PF usage counter to zero */
  1091. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1092. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1093. "DMAE dommand register timed out",
  1094. poll_cnt))
  1095. return 1;
  1096. return 0;
  1097. }
  1098. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1099. {
  1100. u32 val;
  1101. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1102. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1103. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1104. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1105. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1106. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1107. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1108. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1109. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1110. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1111. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1112. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1113. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1114. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1115. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1116. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1117. val);
  1118. }
  1119. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1120. {
  1121. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1122. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1123. /* Re-enable PF target read access */
  1124. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1125. /* Poll HW usage counters */
  1126. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1127. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1128. return -EBUSY;
  1129. /* Zero the igu 'trailing edge' and 'leading edge' */
  1130. /* Send the FW cleanup command */
  1131. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1132. return -EBUSY;
  1133. /* ATC cleanup */
  1134. /* Verify TX hw is flushed */
  1135. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1136. /* Wait 100ms (not adjusted according to platform) */
  1137. msleep(100);
  1138. /* Verify no pending pci transactions */
  1139. if (bnx2x_is_pcie_pending(bp->pdev))
  1140. BNX2X_ERR("PCIE Transactions still pending\n");
  1141. /* Debug */
  1142. bnx2x_hw_enable_status(bp);
  1143. /*
  1144. * Master enable - Due to WB DMAE writes performed before this
  1145. * register is re-initialized as part of the regular function init
  1146. */
  1147. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1148. return 0;
  1149. }
  1150. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1151. {
  1152. int port = BP_PORT(bp);
  1153. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1154. u32 val = REG_RD(bp, addr);
  1155. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1156. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1157. if (msix) {
  1158. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1159. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1160. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1161. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1162. } else if (msi) {
  1163. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1164. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1165. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1166. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1167. } else {
  1168. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1169. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1170. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1171. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1172. if (!CHIP_IS_E1(bp)) {
  1173. DP(NETIF_MSG_IFUP,
  1174. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1175. REG_WR(bp, addr, val);
  1176. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1177. }
  1178. }
  1179. if (CHIP_IS_E1(bp))
  1180. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1181. DP(NETIF_MSG_IFUP,
  1182. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1183. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1184. REG_WR(bp, addr, val);
  1185. /*
  1186. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1187. */
  1188. mmiowb();
  1189. barrier();
  1190. if (!CHIP_IS_E1(bp)) {
  1191. /* init leading/trailing edge */
  1192. if (IS_MF(bp)) {
  1193. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1194. if (bp->port.pmf)
  1195. /* enable nig and gpio3 attention */
  1196. val |= 0x1100;
  1197. } else
  1198. val = 0xffff;
  1199. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1200. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1201. }
  1202. /* Make sure that interrupts are indeed enabled from here on */
  1203. mmiowb();
  1204. }
  1205. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1206. {
  1207. u32 val;
  1208. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1209. int msi = (bp->flags & USING_MSI_FLAG) ? 1 : 0;
  1210. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1211. if (msix) {
  1212. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1213. IGU_PF_CONF_SINGLE_ISR_EN);
  1214. val |= (IGU_PF_CONF_FUNC_EN |
  1215. IGU_PF_CONF_MSI_MSIX_EN |
  1216. IGU_PF_CONF_ATTN_BIT_EN);
  1217. } else if (msi) {
  1218. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1219. val |= (IGU_PF_CONF_FUNC_EN |
  1220. IGU_PF_CONF_MSI_MSIX_EN |
  1221. IGU_PF_CONF_ATTN_BIT_EN |
  1222. IGU_PF_CONF_SINGLE_ISR_EN);
  1223. } else {
  1224. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1225. val |= (IGU_PF_CONF_FUNC_EN |
  1226. IGU_PF_CONF_INT_LINE_EN |
  1227. IGU_PF_CONF_ATTN_BIT_EN |
  1228. IGU_PF_CONF_SINGLE_ISR_EN);
  1229. }
  1230. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1231. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1232. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1233. barrier();
  1234. /* init leading/trailing edge */
  1235. if (IS_MF(bp)) {
  1236. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1237. if (bp->port.pmf)
  1238. /* enable nig and gpio3 attention */
  1239. val |= 0x1100;
  1240. } else
  1241. val = 0xffff;
  1242. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1243. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1244. /* Make sure that interrupts are indeed enabled from here on */
  1245. mmiowb();
  1246. }
  1247. void bnx2x_int_enable(struct bnx2x *bp)
  1248. {
  1249. if (bp->common.int_block == INT_BLOCK_HC)
  1250. bnx2x_hc_int_enable(bp);
  1251. else
  1252. bnx2x_igu_int_enable(bp);
  1253. }
  1254. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  1255. {
  1256. int port = BP_PORT(bp);
  1257. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1258. u32 val = REG_RD(bp, addr);
  1259. /*
  1260. * in E1 we must use only PCI configuration space to disable
  1261. * MSI/MSIX capablility
  1262. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  1263. */
  1264. if (CHIP_IS_E1(bp)) {
  1265. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  1266. * Use mask register to prevent from HC sending interrupts
  1267. * after we exit the function
  1268. */
  1269. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  1270. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1271. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1272. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1273. } else
  1274. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1275. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1276. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1277. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1278. DP(NETIF_MSG_IFDOWN,
  1279. "write %x to HC %d (addr 0x%x)\n",
  1280. val, port, addr);
  1281. /* flush all outstanding writes */
  1282. mmiowb();
  1283. REG_WR(bp, addr, val);
  1284. if (REG_RD(bp, addr) != val)
  1285. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1286. }
  1287. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  1288. {
  1289. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1290. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  1291. IGU_PF_CONF_INT_LINE_EN |
  1292. IGU_PF_CONF_ATTN_BIT_EN);
  1293. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  1294. /* flush all outstanding writes */
  1295. mmiowb();
  1296. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1297. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  1298. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  1299. }
  1300. void bnx2x_int_disable(struct bnx2x *bp)
  1301. {
  1302. if (bp->common.int_block == INT_BLOCK_HC)
  1303. bnx2x_hc_int_disable(bp);
  1304. else
  1305. bnx2x_igu_int_disable(bp);
  1306. }
  1307. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1308. {
  1309. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1310. int i, offset;
  1311. if (disable_hw)
  1312. /* prevent the HW from sending interrupts */
  1313. bnx2x_int_disable(bp);
  1314. /* make sure all ISRs are done */
  1315. if (msix) {
  1316. synchronize_irq(bp->msix_table[0].vector);
  1317. offset = 1;
  1318. #ifdef BCM_CNIC
  1319. offset++;
  1320. #endif
  1321. for_each_eth_queue(bp, i)
  1322. synchronize_irq(bp->msix_table[offset++].vector);
  1323. } else
  1324. synchronize_irq(bp->pdev->irq);
  1325. /* make sure sp_task is not running */
  1326. cancel_delayed_work(&bp->sp_task);
  1327. cancel_delayed_work(&bp->period_task);
  1328. flush_workqueue(bnx2x_wq);
  1329. }
  1330. /* fast path */
  1331. /*
  1332. * General service functions
  1333. */
  1334. /* Return true if succeeded to acquire the lock */
  1335. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1336. {
  1337. u32 lock_status;
  1338. u32 resource_bit = (1 << resource);
  1339. int func = BP_FUNC(bp);
  1340. u32 hw_lock_control_reg;
  1341. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1342. "Trying to take a lock on resource %d\n", resource);
  1343. /* Validating that the resource is within range */
  1344. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1345. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1346. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1347. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1348. return false;
  1349. }
  1350. if (func <= 5)
  1351. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1352. else
  1353. hw_lock_control_reg =
  1354. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1355. /* Try to acquire the lock */
  1356. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1357. lock_status = REG_RD(bp, hw_lock_control_reg);
  1358. if (lock_status & resource_bit)
  1359. return true;
  1360. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1361. "Failed to get a lock on resource %d\n", resource);
  1362. return false;
  1363. }
  1364. /**
  1365. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1366. *
  1367. * @bp: driver handle
  1368. *
  1369. * Returns the recovery leader resource id according to the engine this function
  1370. * belongs to. Currently only only 2 engines is supported.
  1371. */
  1372. static inline int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1373. {
  1374. if (BP_PATH(bp))
  1375. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1376. else
  1377. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1378. }
  1379. /**
  1380. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1381. *
  1382. * @bp: driver handle
  1383. *
  1384. * Tries to aquire a leader lock for cuurent engine.
  1385. */
  1386. static inline bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1387. {
  1388. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1389. }
  1390. #ifdef BCM_CNIC
  1391. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1392. #endif
  1393. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1394. {
  1395. struct bnx2x *bp = fp->bp;
  1396. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1397. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1398. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1399. struct bnx2x_queue_sp_obj *q_obj = &fp->q_obj;
  1400. DP(BNX2X_MSG_SP,
  1401. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1402. fp->index, cid, command, bp->state,
  1403. rr_cqe->ramrod_cqe.ramrod_type);
  1404. switch (command) {
  1405. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1406. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1407. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1408. break;
  1409. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1410. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1411. drv_cmd = BNX2X_Q_CMD_SETUP;
  1412. break;
  1413. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1414. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1415. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1416. break;
  1417. case (RAMROD_CMD_ID_ETH_HALT):
  1418. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1419. drv_cmd = BNX2X_Q_CMD_HALT;
  1420. break;
  1421. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1422. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1423. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1424. break;
  1425. case (RAMROD_CMD_ID_ETH_EMPTY):
  1426. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1427. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1428. break;
  1429. default:
  1430. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1431. command, fp->index);
  1432. return;
  1433. }
  1434. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1435. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1436. /* q_obj->complete_cmd() failure means that this was
  1437. * an unexpected completion.
  1438. *
  1439. * In this case we don't want to increase the bp->spq_left
  1440. * because apparently we haven't sent this command the first
  1441. * place.
  1442. */
  1443. #ifdef BNX2X_STOP_ON_ERROR
  1444. bnx2x_panic();
  1445. #else
  1446. return;
  1447. #endif
  1448. smp_mb__before_atomic_inc();
  1449. atomic_inc(&bp->cq_spq_left);
  1450. /* push the change in bp->spq_left and towards the memory */
  1451. smp_mb__after_atomic_inc();
  1452. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1453. return;
  1454. }
  1455. void bnx2x_update_rx_prod(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  1456. u16 bd_prod, u16 rx_comp_prod, u16 rx_sge_prod)
  1457. {
  1458. u32 start = BAR_USTRORM_INTMEM + fp->ustorm_rx_prods_offset;
  1459. bnx2x_update_rx_prod_gen(bp, fp, bd_prod, rx_comp_prod, rx_sge_prod,
  1460. start);
  1461. }
  1462. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1463. {
  1464. struct bnx2x *bp = netdev_priv(dev_instance);
  1465. u16 status = bnx2x_ack_int(bp);
  1466. u16 mask;
  1467. int i;
  1468. u8 cos;
  1469. /* Return here if interrupt is shared and it's not for us */
  1470. if (unlikely(status == 0)) {
  1471. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1472. return IRQ_NONE;
  1473. }
  1474. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1475. #ifdef BNX2X_STOP_ON_ERROR
  1476. if (unlikely(bp->panic))
  1477. return IRQ_HANDLED;
  1478. #endif
  1479. for_each_eth_queue(bp, i) {
  1480. struct bnx2x_fastpath *fp = &bp->fp[i];
  1481. mask = 0x2 << (fp->index + CNIC_PRESENT);
  1482. if (status & mask) {
  1483. /* Handle Rx or Tx according to SB id */
  1484. prefetch(fp->rx_cons_sb);
  1485. for_each_cos_in_tx_queue(fp, cos)
  1486. prefetch(fp->txdata[cos].tx_cons_sb);
  1487. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1488. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1489. status &= ~mask;
  1490. }
  1491. }
  1492. #ifdef BCM_CNIC
  1493. mask = 0x2;
  1494. if (status & (mask | 0x1)) {
  1495. struct cnic_ops *c_ops = NULL;
  1496. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1497. rcu_read_lock();
  1498. c_ops = rcu_dereference(bp->cnic_ops);
  1499. if (c_ops)
  1500. c_ops->cnic_handler(bp->cnic_data, NULL);
  1501. rcu_read_unlock();
  1502. }
  1503. status &= ~mask;
  1504. }
  1505. #endif
  1506. if (unlikely(status & 0x1)) {
  1507. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1508. status &= ~0x1;
  1509. if (!status)
  1510. return IRQ_HANDLED;
  1511. }
  1512. if (unlikely(status))
  1513. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1514. status);
  1515. return IRQ_HANDLED;
  1516. }
  1517. /* Link */
  1518. /*
  1519. * General service functions
  1520. */
  1521. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1522. {
  1523. u32 lock_status;
  1524. u32 resource_bit = (1 << resource);
  1525. int func = BP_FUNC(bp);
  1526. u32 hw_lock_control_reg;
  1527. int cnt;
  1528. /* Validating that the resource is within range */
  1529. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1530. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1531. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1532. return -EINVAL;
  1533. }
  1534. if (func <= 5) {
  1535. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1536. } else {
  1537. hw_lock_control_reg =
  1538. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1539. }
  1540. /* Validating that the resource is not already taken */
  1541. lock_status = REG_RD(bp, hw_lock_control_reg);
  1542. if (lock_status & resource_bit) {
  1543. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1544. lock_status, resource_bit);
  1545. return -EEXIST;
  1546. }
  1547. /* Try for 5 second every 5ms */
  1548. for (cnt = 0; cnt < 1000; cnt++) {
  1549. /* Try to acquire the lock */
  1550. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1551. lock_status = REG_RD(bp, hw_lock_control_reg);
  1552. if (lock_status & resource_bit)
  1553. return 0;
  1554. msleep(5);
  1555. }
  1556. BNX2X_ERR("Timeout\n");
  1557. return -EAGAIN;
  1558. }
  1559. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1560. {
  1561. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1562. }
  1563. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1564. {
  1565. u32 lock_status;
  1566. u32 resource_bit = (1 << resource);
  1567. int func = BP_FUNC(bp);
  1568. u32 hw_lock_control_reg;
  1569. /* Validating that the resource is within range */
  1570. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1571. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1572. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1573. return -EINVAL;
  1574. }
  1575. if (func <= 5) {
  1576. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1577. } else {
  1578. hw_lock_control_reg =
  1579. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1580. }
  1581. /* Validating that the resource is currently taken */
  1582. lock_status = REG_RD(bp, hw_lock_control_reg);
  1583. if (!(lock_status & resource_bit)) {
  1584. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1585. lock_status, resource_bit);
  1586. return -EFAULT;
  1587. }
  1588. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1589. return 0;
  1590. }
  1591. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1592. {
  1593. /* The GPIO should be swapped if swap register is set and active */
  1594. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1595. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1596. int gpio_shift = gpio_num +
  1597. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1598. u32 gpio_mask = (1 << gpio_shift);
  1599. u32 gpio_reg;
  1600. int value;
  1601. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1602. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1603. return -EINVAL;
  1604. }
  1605. /* read GPIO value */
  1606. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1607. /* get the requested pin value */
  1608. if ((gpio_reg & gpio_mask) == gpio_mask)
  1609. value = 1;
  1610. else
  1611. value = 0;
  1612. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1613. return value;
  1614. }
  1615. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1616. {
  1617. /* The GPIO should be swapped if swap register is set and active */
  1618. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1619. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1620. int gpio_shift = gpio_num +
  1621. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1622. u32 gpio_mask = (1 << gpio_shift);
  1623. u32 gpio_reg;
  1624. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1625. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1626. return -EINVAL;
  1627. }
  1628. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1629. /* read GPIO and mask except the float bits */
  1630. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1631. switch (mode) {
  1632. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1633. DP(NETIF_MSG_LINK,
  1634. "Set GPIO %d (shift %d) -> output low\n",
  1635. gpio_num, gpio_shift);
  1636. /* clear FLOAT and set CLR */
  1637. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1638. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1639. break;
  1640. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1641. DP(NETIF_MSG_LINK,
  1642. "Set GPIO %d (shift %d) -> output high\n",
  1643. gpio_num, gpio_shift);
  1644. /* clear FLOAT and set SET */
  1645. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1646. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1647. break;
  1648. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1649. DP(NETIF_MSG_LINK,
  1650. "Set GPIO %d (shift %d) -> input\n",
  1651. gpio_num, gpio_shift);
  1652. /* set FLOAT */
  1653. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1654. break;
  1655. default:
  1656. break;
  1657. }
  1658. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1659. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1660. return 0;
  1661. }
  1662. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1663. {
  1664. u32 gpio_reg = 0;
  1665. int rc = 0;
  1666. /* Any port swapping should be handled by caller. */
  1667. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1668. /* read GPIO and mask except the float bits */
  1669. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1670. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1671. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1672. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1673. switch (mode) {
  1674. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1675. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1676. /* set CLR */
  1677. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1678. break;
  1679. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1680. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1681. /* set SET */
  1682. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1683. break;
  1684. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1685. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1686. /* set FLOAT */
  1687. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1688. break;
  1689. default:
  1690. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1691. rc = -EINVAL;
  1692. break;
  1693. }
  1694. if (rc == 0)
  1695. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1696. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1697. return rc;
  1698. }
  1699. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1700. {
  1701. /* The GPIO should be swapped if swap register is set and active */
  1702. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1703. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1704. int gpio_shift = gpio_num +
  1705. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1706. u32 gpio_mask = (1 << gpio_shift);
  1707. u32 gpio_reg;
  1708. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1709. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1710. return -EINVAL;
  1711. }
  1712. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1713. /* read GPIO int */
  1714. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1715. switch (mode) {
  1716. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1717. DP(NETIF_MSG_LINK,
  1718. "Clear GPIO INT %d (shift %d) -> output low\n",
  1719. gpio_num, gpio_shift);
  1720. /* clear SET and set CLR */
  1721. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1722. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1723. break;
  1724. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1725. DP(NETIF_MSG_LINK,
  1726. "Set GPIO INT %d (shift %d) -> output high\n",
  1727. gpio_num, gpio_shift);
  1728. /* clear CLR and set SET */
  1729. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1730. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1731. break;
  1732. default:
  1733. break;
  1734. }
  1735. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1736. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1737. return 0;
  1738. }
  1739. static int bnx2x_set_spio(struct bnx2x *bp, int spio_num, u32 mode)
  1740. {
  1741. u32 spio_mask = (1 << spio_num);
  1742. u32 spio_reg;
  1743. if ((spio_num < MISC_REGISTERS_SPIO_4) ||
  1744. (spio_num > MISC_REGISTERS_SPIO_7)) {
  1745. BNX2X_ERR("Invalid SPIO %d\n", spio_num);
  1746. return -EINVAL;
  1747. }
  1748. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1749. /* read SPIO and mask except the float bits */
  1750. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_REGISTERS_SPIO_FLOAT);
  1751. switch (mode) {
  1752. case MISC_REGISTERS_SPIO_OUTPUT_LOW:
  1753. DP(NETIF_MSG_HW, "Set SPIO %d -> output low\n", spio_num);
  1754. /* clear FLOAT and set CLR */
  1755. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1756. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_CLR_POS);
  1757. break;
  1758. case MISC_REGISTERS_SPIO_OUTPUT_HIGH:
  1759. DP(NETIF_MSG_HW, "Set SPIO %d -> output high\n", spio_num);
  1760. /* clear FLOAT and set SET */
  1761. spio_reg &= ~(spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1762. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_SET_POS);
  1763. break;
  1764. case MISC_REGISTERS_SPIO_INPUT_HI_Z:
  1765. DP(NETIF_MSG_HW, "Set SPIO %d -> input\n", spio_num);
  1766. /* set FLOAT */
  1767. spio_reg |= (spio_mask << MISC_REGISTERS_SPIO_FLOAT_POS);
  1768. break;
  1769. default:
  1770. break;
  1771. }
  1772. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1773. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1774. return 0;
  1775. }
  1776. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1777. {
  1778. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1779. switch (bp->link_vars.ieee_fc &
  1780. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1781. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1782. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1783. ADVERTISED_Pause);
  1784. break;
  1785. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1786. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1787. ADVERTISED_Pause);
  1788. break;
  1789. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1790. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1791. break;
  1792. default:
  1793. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1794. ADVERTISED_Pause);
  1795. break;
  1796. }
  1797. }
  1798. u8 bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1799. {
  1800. if (!BP_NOMCP(bp)) {
  1801. u8 rc;
  1802. int cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1803. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1804. /*
  1805. * Initialize link parameters structure variables
  1806. * It is recommended to turn off RX FC for jumbo frames
  1807. * for better performance
  1808. */
  1809. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1810. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1811. else
  1812. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1813. bnx2x_acquire_phy_lock(bp);
  1814. if (load_mode == LOAD_DIAG) {
  1815. struct link_params *lp = &bp->link_params;
  1816. lp->loopback_mode = LOOPBACK_XGXS;
  1817. /* do PHY loopback at 10G speed, if possible */
  1818. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1819. if (lp->speed_cap_mask[cfx_idx] &
  1820. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1821. lp->req_line_speed[cfx_idx] =
  1822. SPEED_10000;
  1823. else
  1824. lp->req_line_speed[cfx_idx] =
  1825. SPEED_1000;
  1826. }
  1827. }
  1828. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1829. bnx2x_release_phy_lock(bp);
  1830. bnx2x_calc_fc_adv(bp);
  1831. if (CHIP_REV_IS_SLOW(bp) && bp->link_vars.link_up) {
  1832. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1833. bnx2x_link_report(bp);
  1834. } else
  1835. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1836. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1837. return rc;
  1838. }
  1839. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1840. return -EINVAL;
  1841. }
  1842. void bnx2x_link_set(struct bnx2x *bp)
  1843. {
  1844. if (!BP_NOMCP(bp)) {
  1845. bnx2x_acquire_phy_lock(bp);
  1846. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1847. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1848. bnx2x_release_phy_lock(bp);
  1849. bnx2x_calc_fc_adv(bp);
  1850. } else
  1851. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1852. }
  1853. static void bnx2x__link_reset(struct bnx2x *bp)
  1854. {
  1855. if (!BP_NOMCP(bp)) {
  1856. bnx2x_acquire_phy_lock(bp);
  1857. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1858. bnx2x_release_phy_lock(bp);
  1859. } else
  1860. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1861. }
  1862. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1863. {
  1864. u8 rc = 0;
  1865. if (!BP_NOMCP(bp)) {
  1866. bnx2x_acquire_phy_lock(bp);
  1867. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1868. is_serdes);
  1869. bnx2x_release_phy_lock(bp);
  1870. } else
  1871. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1872. return rc;
  1873. }
  1874. static void bnx2x_init_port_minmax(struct bnx2x *bp)
  1875. {
  1876. u32 r_param = bp->link_vars.line_speed / 8;
  1877. u32 fair_periodic_timeout_usec;
  1878. u32 t_fair;
  1879. memset(&(bp->cmng.rs_vars), 0,
  1880. sizeof(struct rate_shaping_vars_per_port));
  1881. memset(&(bp->cmng.fair_vars), 0, sizeof(struct fairness_vars_per_port));
  1882. /* 100 usec in SDM ticks = 25 since each tick is 4 usec */
  1883. bp->cmng.rs_vars.rs_periodic_timeout = RS_PERIODIC_TIMEOUT_USEC / 4;
  1884. /* this is the threshold below which no timer arming will occur
  1885. 1.25 coefficient is for the threshold to be a little bigger
  1886. than the real time, to compensate for timer in-accuracy */
  1887. bp->cmng.rs_vars.rs_threshold =
  1888. (RS_PERIODIC_TIMEOUT_USEC * r_param * 5) / 4;
  1889. /* resolution of fairness timer */
  1890. fair_periodic_timeout_usec = QM_ARB_BYTES / r_param;
  1891. /* for 10G it is 1000usec. for 1G it is 10000usec. */
  1892. t_fair = T_FAIR_COEF / bp->link_vars.line_speed;
  1893. /* this is the threshold below which we won't arm the timer anymore */
  1894. bp->cmng.fair_vars.fair_threshold = QM_ARB_BYTES;
  1895. /* we multiply by 1e3/8 to get bytes/msec.
  1896. We don't want the credits to pass a credit
  1897. of the t_fair*FAIR_MEM (algorithm resolution) */
  1898. bp->cmng.fair_vars.upper_bound = r_param * t_fair * FAIR_MEM;
  1899. /* since each tick is 4 usec */
  1900. bp->cmng.fair_vars.fairness_timeout = fair_periodic_timeout_usec / 4;
  1901. }
  1902. /* Calculates the sum of vn_min_rates.
  1903. It's needed for further normalizing of the min_rates.
  1904. Returns:
  1905. sum of vn_min_rates.
  1906. or
  1907. 0 - if all the min_rates are 0.
  1908. In the later case fainess algorithm should be deactivated.
  1909. If not all min_rates are zero then those that are zeroes will be set to 1.
  1910. */
  1911. static void bnx2x_calc_vn_weight_sum(struct bnx2x *bp)
  1912. {
  1913. int all_zero = 1;
  1914. int vn;
  1915. bp->vn_weight_sum = 0;
  1916. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1917. u32 vn_cfg = bp->mf_config[vn];
  1918. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1919. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1920. /* Skip hidden vns */
  1921. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1922. continue;
  1923. /* If min rate is zero - set it to 1 */
  1924. if (!vn_min_rate)
  1925. vn_min_rate = DEF_MIN_RATE;
  1926. else
  1927. all_zero = 0;
  1928. bp->vn_weight_sum += vn_min_rate;
  1929. }
  1930. /* if ETS or all min rates are zeros - disable fairness */
  1931. if (BNX2X_IS_ETS_ENABLED(bp)) {
  1932. bp->cmng.flags.cmng_enables &=
  1933. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1934. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  1935. } else if (all_zero) {
  1936. bp->cmng.flags.cmng_enables &=
  1937. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1938. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  1939. " fairness will be disabled\n");
  1940. } else
  1941. bp->cmng.flags.cmng_enables |=
  1942. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  1943. }
  1944. static void bnx2x_init_vn_minmax(struct bnx2x *bp, int vn)
  1945. {
  1946. struct rate_shaping_vars_per_vn m_rs_vn;
  1947. struct fairness_vars_per_vn m_fair_vn;
  1948. u32 vn_cfg = bp->mf_config[vn];
  1949. int func = func_by_vn(bp, vn);
  1950. u16 vn_min_rate, vn_max_rate;
  1951. int i;
  1952. /* If function is hidden - set min and max to zeroes */
  1953. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE) {
  1954. vn_min_rate = 0;
  1955. vn_max_rate = 0;
  1956. } else {
  1957. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  1958. vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1959. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1960. /* If fairness is enabled (not all min rates are zeroes) and
  1961. if current min rate is zero - set it to 1.
  1962. This is a requirement of the algorithm. */
  1963. if (bp->vn_weight_sum && (vn_min_rate == 0))
  1964. vn_min_rate = DEF_MIN_RATE;
  1965. if (IS_MF_SI(bp))
  1966. /* maxCfg in percents of linkspeed */
  1967. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  1968. else
  1969. /* maxCfg is absolute in 100Mb units */
  1970. vn_max_rate = maxCfg * 100;
  1971. }
  1972. DP(NETIF_MSG_IFUP,
  1973. "func %d: vn_min_rate %d vn_max_rate %d vn_weight_sum %d\n",
  1974. func, vn_min_rate, vn_max_rate, bp->vn_weight_sum);
  1975. memset(&m_rs_vn, 0, sizeof(struct rate_shaping_vars_per_vn));
  1976. memset(&m_fair_vn, 0, sizeof(struct fairness_vars_per_vn));
  1977. /* global vn counter - maximal Mbps for this vn */
  1978. m_rs_vn.vn_counter.rate = vn_max_rate;
  1979. /* quota - number of bytes transmitted in this period */
  1980. m_rs_vn.vn_counter.quota =
  1981. (vn_max_rate * RS_PERIODIC_TIMEOUT_USEC) / 8;
  1982. if (bp->vn_weight_sum) {
  1983. /* credit for each period of the fairness algorithm:
  1984. number of bytes in T_FAIR (the vn share the port rate).
  1985. vn_weight_sum should not be larger than 10000, thus
  1986. T_FAIR_COEF / (8 * vn_weight_sum) will always be greater
  1987. than zero */
  1988. m_fair_vn.vn_credit_delta =
  1989. max_t(u32, (vn_min_rate * (T_FAIR_COEF /
  1990. (8 * bp->vn_weight_sum))),
  1991. (bp->cmng.fair_vars.fair_threshold +
  1992. MIN_ABOVE_THRESH));
  1993. DP(NETIF_MSG_IFUP, "m_fair_vn.vn_credit_delta %d\n",
  1994. m_fair_vn.vn_credit_delta);
  1995. }
  1996. /* Store it to internal memory */
  1997. for (i = 0; i < sizeof(struct rate_shaping_vars_per_vn)/4; i++)
  1998. REG_WR(bp, BAR_XSTRORM_INTMEM +
  1999. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func) + i * 4,
  2000. ((u32 *)(&m_rs_vn))[i]);
  2001. for (i = 0; i < sizeof(struct fairness_vars_per_vn)/4; i++)
  2002. REG_WR(bp, BAR_XSTRORM_INTMEM +
  2003. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func) + i * 4,
  2004. ((u32 *)(&m_fair_vn))[i]);
  2005. }
  2006. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2007. {
  2008. if (CHIP_REV_IS_SLOW(bp))
  2009. return CMNG_FNS_NONE;
  2010. if (IS_MF(bp))
  2011. return CMNG_FNS_MINMAX;
  2012. return CMNG_FNS_NONE;
  2013. }
  2014. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2015. {
  2016. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2017. if (BP_NOMCP(bp))
  2018. return; /* what should be the default bvalue in this case */
  2019. /* For 2 port configuration the absolute function number formula
  2020. * is:
  2021. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2022. *
  2023. * and there are 4 functions per port
  2024. *
  2025. * For 4 port configuration it is
  2026. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2027. *
  2028. * and there are 2 functions per port
  2029. */
  2030. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2031. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2032. if (func >= E1H_FUNC_MAX)
  2033. break;
  2034. bp->mf_config[vn] =
  2035. MF_CFG_RD(bp, func_mf_config[func].config);
  2036. }
  2037. }
  2038. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2039. {
  2040. if (cmng_type == CMNG_FNS_MINMAX) {
  2041. int vn;
  2042. /* clear cmng_enables */
  2043. bp->cmng.flags.cmng_enables = 0;
  2044. /* read mf conf from shmem */
  2045. if (read_cfg)
  2046. bnx2x_read_mf_cfg(bp);
  2047. /* Init rate shaping and fairness contexts */
  2048. bnx2x_init_port_minmax(bp);
  2049. /* vn_weight_sum and enable fairness if not 0 */
  2050. bnx2x_calc_vn_weight_sum(bp);
  2051. /* calculate and set min-max rate for each vn */
  2052. if (bp->port.pmf)
  2053. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2054. bnx2x_init_vn_minmax(bp, vn);
  2055. /* always enable rate shaping and fairness */
  2056. bp->cmng.flags.cmng_enables |=
  2057. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2058. if (!bp->vn_weight_sum)
  2059. DP(NETIF_MSG_IFUP, "All MIN values are zeroes"
  2060. " fairness will be disabled\n");
  2061. return;
  2062. }
  2063. /* rate shaping and fairness are disabled */
  2064. DP(NETIF_MSG_IFUP,
  2065. "rate shaping and fairness are disabled\n");
  2066. }
  2067. /* This function is called upon link interrupt */
  2068. static void bnx2x_link_attn(struct bnx2x *bp)
  2069. {
  2070. /* Make sure that we are synced with the current statistics */
  2071. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2072. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2073. if (bp->link_vars.link_up) {
  2074. /* dropless flow control */
  2075. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2076. int port = BP_PORT(bp);
  2077. u32 pause_enabled = 0;
  2078. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2079. pause_enabled = 1;
  2080. REG_WR(bp, BAR_USTRORM_INTMEM +
  2081. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2082. pause_enabled);
  2083. }
  2084. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2085. struct host_port_stats *pstats;
  2086. pstats = bnx2x_sp(bp, port_stats);
  2087. /* reset old mac stats */
  2088. memset(&(pstats->mac_stx[0]), 0,
  2089. sizeof(struct mac_stx));
  2090. }
  2091. if (bp->state == BNX2X_STATE_OPEN)
  2092. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2093. }
  2094. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2095. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2096. if (cmng_fns != CMNG_FNS_NONE) {
  2097. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2098. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2099. } else
  2100. /* rate shaping and fairness are disabled */
  2101. DP(NETIF_MSG_IFUP,
  2102. "single function mode without fairness\n");
  2103. }
  2104. __bnx2x_link_report(bp);
  2105. if (IS_MF(bp))
  2106. bnx2x_link_sync_notify(bp);
  2107. }
  2108. void bnx2x__link_status_update(struct bnx2x *bp)
  2109. {
  2110. if (bp->state != BNX2X_STATE_OPEN)
  2111. return;
  2112. /* read updated dcb configuration */
  2113. bnx2x_dcbx_pmf_update(bp);
  2114. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2115. if (bp->link_vars.link_up)
  2116. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2117. else
  2118. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2119. /* indicate link status */
  2120. bnx2x_link_report(bp);
  2121. }
  2122. static void bnx2x_pmf_update(struct bnx2x *bp)
  2123. {
  2124. int port = BP_PORT(bp);
  2125. u32 val;
  2126. bp->port.pmf = 1;
  2127. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2128. /*
  2129. * We need the mb() to ensure the ordering between the writing to
  2130. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2131. */
  2132. smp_mb();
  2133. /* queue a periodic task */
  2134. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2135. bnx2x_dcbx_pmf_update(bp);
  2136. /* enable nig attention */
  2137. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2138. if (bp->common.int_block == INT_BLOCK_HC) {
  2139. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2140. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2141. } else if (!CHIP_IS_E1x(bp)) {
  2142. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2143. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2144. }
  2145. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2146. }
  2147. /* end of Link */
  2148. /* slow path */
  2149. /*
  2150. * General service functions
  2151. */
  2152. /* send the MCP a request, block until there is a reply */
  2153. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2154. {
  2155. int mb_idx = BP_FW_MB_IDX(bp);
  2156. u32 seq;
  2157. u32 rc = 0;
  2158. u32 cnt = 1;
  2159. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2160. mutex_lock(&bp->fw_mb_mutex);
  2161. seq = ++bp->fw_seq;
  2162. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2163. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2164. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2165. (command | seq), param);
  2166. do {
  2167. /* let the FW do it's magic ... */
  2168. msleep(delay);
  2169. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2170. /* Give the FW up to 5 second (500*10ms) */
  2171. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2172. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2173. cnt*delay, rc, seq);
  2174. /* is this a reply to our command? */
  2175. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2176. rc &= FW_MSG_CODE_MASK;
  2177. else {
  2178. /* FW BUG! */
  2179. BNX2X_ERR("FW failed to respond!\n");
  2180. bnx2x_fw_dump(bp);
  2181. rc = 0;
  2182. }
  2183. mutex_unlock(&bp->fw_mb_mutex);
  2184. return rc;
  2185. }
  2186. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2187. {
  2188. if (CHIP_IS_E1x(bp)) {
  2189. struct tstorm_eth_function_common_config tcfg = {0};
  2190. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2191. }
  2192. /* Enable the function in the FW */
  2193. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2194. storm_memset_func_en(bp, p->func_id, 1);
  2195. /* spq */
  2196. if (p->func_flgs & FUNC_FLG_SPQ) {
  2197. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2198. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2199. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2200. }
  2201. }
  2202. /**
  2203. * bnx2x_get_tx_only_flags - Return common flags
  2204. *
  2205. * @bp device handle
  2206. * @fp queue handle
  2207. * @zero_stats TRUE if statistics zeroing is needed
  2208. *
  2209. * Return the flags that are common for the Tx-only and not normal connections.
  2210. */
  2211. static inline unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2212. struct bnx2x_fastpath *fp,
  2213. bool zero_stats)
  2214. {
  2215. unsigned long flags = 0;
  2216. /* PF driver will always initialize the Queue to an ACTIVE state */
  2217. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2218. /* tx only connections collect statistics (on the same index as the
  2219. * parent connection). The statistics are zeroed when the parent
  2220. * connection is initialized.
  2221. */
  2222. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2223. if (zero_stats)
  2224. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2225. return flags;
  2226. }
  2227. static inline unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2228. struct bnx2x_fastpath *fp,
  2229. bool leading)
  2230. {
  2231. unsigned long flags = 0;
  2232. /* calculate other queue flags */
  2233. if (IS_MF_SD(bp))
  2234. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2235. if (IS_FCOE_FP(fp))
  2236. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2237. if (!fp->disable_tpa) {
  2238. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2239. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2240. if (fp->mode == TPA_MODE_GRO)
  2241. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2242. }
  2243. if (leading) {
  2244. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2245. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2246. }
  2247. /* Always set HW VLAN stripping */
  2248. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2249. return flags | bnx2x_get_common_flags(bp, fp, true);
  2250. }
  2251. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2252. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2253. u8 cos)
  2254. {
  2255. gen_init->stat_id = bnx2x_stats_id(fp);
  2256. gen_init->spcl_id = fp->cl_id;
  2257. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2258. if (IS_FCOE_FP(fp))
  2259. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2260. else
  2261. gen_init->mtu = bp->dev->mtu;
  2262. gen_init->cos = cos;
  2263. }
  2264. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2265. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2266. struct bnx2x_rxq_setup_params *rxq_init)
  2267. {
  2268. u8 max_sge = 0;
  2269. u16 sge_sz = 0;
  2270. u16 tpa_agg_size = 0;
  2271. if (!fp->disable_tpa) {
  2272. pause->sge_th_lo = SGE_TH_LO(bp);
  2273. pause->sge_th_hi = SGE_TH_HI(bp);
  2274. /* validate SGE ring has enough to cross high threshold */
  2275. WARN_ON(bp->dropless_fc &&
  2276. pause->sge_th_hi + FW_PREFETCH_CNT >
  2277. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2278. tpa_agg_size = min_t(u32,
  2279. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2280. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2281. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2282. SGE_PAGE_SHIFT;
  2283. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2284. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2285. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2286. 0xffff);
  2287. }
  2288. /* pause - not for e1 */
  2289. if (!CHIP_IS_E1(bp)) {
  2290. pause->bd_th_lo = BD_TH_LO(bp);
  2291. pause->bd_th_hi = BD_TH_HI(bp);
  2292. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2293. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2294. /*
  2295. * validate that rings have enough entries to cross
  2296. * high thresholds
  2297. */
  2298. WARN_ON(bp->dropless_fc &&
  2299. pause->bd_th_hi + FW_PREFETCH_CNT >
  2300. bp->rx_ring_size);
  2301. WARN_ON(bp->dropless_fc &&
  2302. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2303. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2304. pause->pri_map = 1;
  2305. }
  2306. /* rxq setup */
  2307. rxq_init->dscr_map = fp->rx_desc_mapping;
  2308. rxq_init->sge_map = fp->rx_sge_mapping;
  2309. rxq_init->rcq_map = fp->rx_comp_mapping;
  2310. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2311. /* This should be a maximum number of data bytes that may be
  2312. * placed on the BD (not including paddings).
  2313. */
  2314. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2315. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2316. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2317. rxq_init->tpa_agg_sz = tpa_agg_size;
  2318. rxq_init->sge_buf_sz = sge_sz;
  2319. rxq_init->max_sges_pkt = max_sge;
  2320. rxq_init->rss_engine_id = BP_FUNC(bp);
  2321. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2322. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2323. *
  2324. * For PF Clients it should be the maximum avaliable number.
  2325. * VF driver(s) may want to define it to a smaller value.
  2326. */
  2327. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2328. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2329. rxq_init->fw_sb_id = fp->fw_sb_id;
  2330. if (IS_FCOE_FP(fp))
  2331. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2332. else
  2333. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2334. }
  2335. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2336. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2337. u8 cos)
  2338. {
  2339. txq_init->dscr_map = fp->txdata[cos].tx_desc_mapping;
  2340. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2341. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2342. txq_init->fw_sb_id = fp->fw_sb_id;
  2343. /*
  2344. * set the tss leading client id for TX classfication ==
  2345. * leading RSS client id
  2346. */
  2347. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2348. if (IS_FCOE_FP(fp)) {
  2349. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2350. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2351. }
  2352. }
  2353. static void bnx2x_pf_init(struct bnx2x *bp)
  2354. {
  2355. struct bnx2x_func_init_params func_init = {0};
  2356. struct event_ring_data eq_data = { {0} };
  2357. u16 flags;
  2358. if (!CHIP_IS_E1x(bp)) {
  2359. /* reset IGU PF statistics: MSIX + ATTN */
  2360. /* PF */
  2361. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2362. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2363. (CHIP_MODE_IS_4_PORT(bp) ?
  2364. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2365. /* ATTN */
  2366. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2367. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2368. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2369. (CHIP_MODE_IS_4_PORT(bp) ?
  2370. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2371. }
  2372. /* function setup flags */
  2373. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2374. /* This flag is relevant for E1x only.
  2375. * E2 doesn't have a TPA configuration in a function level.
  2376. */
  2377. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2378. func_init.func_flgs = flags;
  2379. func_init.pf_id = BP_FUNC(bp);
  2380. func_init.func_id = BP_FUNC(bp);
  2381. func_init.spq_map = bp->spq_mapping;
  2382. func_init.spq_prod = bp->spq_prod_idx;
  2383. bnx2x_func_init(bp, &func_init);
  2384. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2385. /*
  2386. * Congestion management values depend on the link rate
  2387. * There is no active link so initial link rate is set to 10 Gbps.
  2388. * When the link comes up The congestion management values are
  2389. * re-calculated according to the actual link rate.
  2390. */
  2391. bp->link_vars.line_speed = SPEED_10000;
  2392. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2393. /* Only the PMF sets the HW */
  2394. if (bp->port.pmf)
  2395. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2396. /* init Event Queue */
  2397. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2398. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2399. eq_data.producer = bp->eq_prod;
  2400. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2401. eq_data.sb_id = DEF_SB_ID;
  2402. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2403. }
  2404. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2405. {
  2406. int port = BP_PORT(bp);
  2407. bnx2x_tx_disable(bp);
  2408. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2409. }
  2410. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2411. {
  2412. int port = BP_PORT(bp);
  2413. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2414. /* Tx queue should be only reenabled */
  2415. netif_tx_wake_all_queues(bp->dev);
  2416. /*
  2417. * Should not call netif_carrier_on since it will be called if the link
  2418. * is up when checking for link state
  2419. */
  2420. }
  2421. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2422. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2423. {
  2424. struct eth_stats_info *ether_stat =
  2425. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2426. /* leave last char as NULL */
  2427. memcpy(ether_stat->version, DRV_MODULE_VERSION,
  2428. ETH_STAT_INFO_VERSION_LEN - 1);
  2429. bp->fp[0].mac_obj.get_n_elements(bp, &bp->fp[0].mac_obj,
  2430. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2431. ether_stat->mac_local);
  2432. ether_stat->mtu_size = bp->dev->mtu;
  2433. if (bp->dev->features & NETIF_F_RXCSUM)
  2434. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2435. if (bp->dev->features & NETIF_F_TSO)
  2436. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2437. ether_stat->feature_flags |= bp->common.boot_mode;
  2438. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2439. ether_stat->txq_size = bp->tx_ring_size;
  2440. ether_stat->rxq_size = bp->rx_ring_size;
  2441. }
  2442. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2443. {
  2444. #ifdef BCM_CNIC
  2445. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2446. struct fcoe_stats_info *fcoe_stat =
  2447. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2448. memcpy(fcoe_stat->mac_local, bp->fip_mac, ETH_ALEN);
  2449. fcoe_stat->qos_priority =
  2450. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2451. /* insert FCoE stats from ramrod response */
  2452. if (!NO_FCOE(bp)) {
  2453. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2454. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2455. tstorm_queue_statistics;
  2456. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2457. &bp->fw_stats_data->queue_stats[FCOE_IDX].
  2458. xstorm_queue_statistics;
  2459. struct fcoe_statistics_params *fw_fcoe_stat =
  2460. &bp->fw_stats_data->fcoe;
  2461. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2462. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2463. ADD_64(fcoe_stat->rx_bytes_hi,
  2464. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2465. fcoe_stat->rx_bytes_lo,
  2466. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2467. ADD_64(fcoe_stat->rx_bytes_hi,
  2468. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2469. fcoe_stat->rx_bytes_lo,
  2470. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2471. ADD_64(fcoe_stat->rx_bytes_hi,
  2472. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2473. fcoe_stat->rx_bytes_lo,
  2474. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2475. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2476. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2477. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2478. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2479. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2480. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2481. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2482. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2483. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2484. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2485. ADD_64(fcoe_stat->tx_bytes_hi,
  2486. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2487. fcoe_stat->tx_bytes_lo,
  2488. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2489. ADD_64(fcoe_stat->tx_bytes_hi,
  2490. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2491. fcoe_stat->tx_bytes_lo,
  2492. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2493. ADD_64(fcoe_stat->tx_bytes_hi,
  2494. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2495. fcoe_stat->tx_bytes_lo,
  2496. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2497. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2498. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2499. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2500. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2501. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2502. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2503. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2504. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2505. }
  2506. /* ask L5 driver to add data to the struct */
  2507. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2508. #endif
  2509. }
  2510. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2511. {
  2512. #ifdef BCM_CNIC
  2513. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2514. struct iscsi_stats_info *iscsi_stat =
  2515. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2516. memcpy(iscsi_stat->mac_local, bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2517. iscsi_stat->qos_priority =
  2518. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2519. /* ask L5 driver to add data to the struct */
  2520. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2521. #endif
  2522. }
  2523. /* called due to MCP event (on pmf):
  2524. * reread new bandwidth configuration
  2525. * configure FW
  2526. * notify others function about the change
  2527. */
  2528. static inline void bnx2x_config_mf_bw(struct bnx2x *bp)
  2529. {
  2530. if (bp->link_vars.link_up) {
  2531. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2532. bnx2x_link_sync_notify(bp);
  2533. }
  2534. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2535. }
  2536. static inline void bnx2x_set_mf_bw(struct bnx2x *bp)
  2537. {
  2538. bnx2x_config_mf_bw(bp);
  2539. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2540. }
  2541. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2542. {
  2543. enum drv_info_opcode op_code;
  2544. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2545. /* if drv_info version supported by MFW doesn't match - send NACK */
  2546. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2547. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2548. return;
  2549. }
  2550. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2551. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2552. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2553. sizeof(union drv_info_to_mcp));
  2554. switch (op_code) {
  2555. case ETH_STATS_OPCODE:
  2556. bnx2x_drv_info_ether_stat(bp);
  2557. break;
  2558. case FCOE_STATS_OPCODE:
  2559. bnx2x_drv_info_fcoe_stat(bp);
  2560. break;
  2561. case ISCSI_STATS_OPCODE:
  2562. bnx2x_drv_info_iscsi_stat(bp);
  2563. break;
  2564. default:
  2565. /* if op code isn't supported - send NACK */
  2566. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2567. return;
  2568. }
  2569. /* if we got drv_info attn from MFW then these fields are defined in
  2570. * shmem2 for sure
  2571. */
  2572. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2573. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2574. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2575. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2576. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2577. }
  2578. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2579. {
  2580. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2581. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2582. /*
  2583. * This is the only place besides the function initialization
  2584. * where the bp->flags can change so it is done without any
  2585. * locks
  2586. */
  2587. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2588. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2589. bp->flags |= MF_FUNC_DIS;
  2590. bnx2x_e1h_disable(bp);
  2591. } else {
  2592. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2593. bp->flags &= ~MF_FUNC_DIS;
  2594. bnx2x_e1h_enable(bp);
  2595. }
  2596. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2597. }
  2598. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2599. bnx2x_config_mf_bw(bp);
  2600. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2601. }
  2602. /* Report results to MCP */
  2603. if (dcc_event)
  2604. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2605. else
  2606. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2607. }
  2608. /* must be called under the spq lock */
  2609. static inline struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2610. {
  2611. struct eth_spe *next_spe = bp->spq_prod_bd;
  2612. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2613. bp->spq_prod_bd = bp->spq;
  2614. bp->spq_prod_idx = 0;
  2615. DP(BNX2X_MSG_SP, "end of spq\n");
  2616. } else {
  2617. bp->spq_prod_bd++;
  2618. bp->spq_prod_idx++;
  2619. }
  2620. return next_spe;
  2621. }
  2622. /* must be called under the spq lock */
  2623. static inline void bnx2x_sp_prod_update(struct bnx2x *bp)
  2624. {
  2625. int func = BP_FUNC(bp);
  2626. /*
  2627. * Make sure that BD data is updated before writing the producer:
  2628. * BD data is written to the memory, the producer is read from the
  2629. * memory, thus we need a full memory barrier to ensure the ordering.
  2630. */
  2631. mb();
  2632. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2633. bp->spq_prod_idx);
  2634. mmiowb();
  2635. }
  2636. /**
  2637. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2638. *
  2639. * @cmd: command to check
  2640. * @cmd_type: command type
  2641. */
  2642. static inline bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2643. {
  2644. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2645. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2646. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2647. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2648. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2649. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2650. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2651. return true;
  2652. else
  2653. return false;
  2654. }
  2655. /**
  2656. * bnx2x_sp_post - place a single command on an SP ring
  2657. *
  2658. * @bp: driver handle
  2659. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2660. * @cid: SW CID the command is related to
  2661. * @data_hi: command private data address (high 32 bits)
  2662. * @data_lo: command private data address (low 32 bits)
  2663. * @cmd_type: command type (e.g. NONE, ETH)
  2664. *
  2665. * SP data is handled as if it's always an address pair, thus data fields are
  2666. * not swapped to little endian in upper functions. Instead this function swaps
  2667. * data as if it's two u32 fields.
  2668. */
  2669. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2670. u32 data_hi, u32 data_lo, int cmd_type)
  2671. {
  2672. struct eth_spe *spe;
  2673. u16 type;
  2674. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2675. #ifdef BNX2X_STOP_ON_ERROR
  2676. if (unlikely(bp->panic)) {
  2677. BNX2X_ERR("Can't post SP when there is panic\n");
  2678. return -EIO;
  2679. }
  2680. #endif
  2681. spin_lock_bh(&bp->spq_lock);
  2682. if (common) {
  2683. if (!atomic_read(&bp->eq_spq_left)) {
  2684. BNX2X_ERR("BUG! EQ ring full!\n");
  2685. spin_unlock_bh(&bp->spq_lock);
  2686. bnx2x_panic();
  2687. return -EBUSY;
  2688. }
  2689. } else if (!atomic_read(&bp->cq_spq_left)) {
  2690. BNX2X_ERR("BUG! SPQ ring full!\n");
  2691. spin_unlock_bh(&bp->spq_lock);
  2692. bnx2x_panic();
  2693. return -EBUSY;
  2694. }
  2695. spe = bnx2x_sp_get_next(bp);
  2696. /* CID needs port number to be encoded int it */
  2697. spe->hdr.conn_and_cmd_data =
  2698. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2699. HW_CID(bp, cid));
  2700. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2701. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2702. SPE_HDR_FUNCTION_ID);
  2703. spe->hdr.type = cpu_to_le16(type);
  2704. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2705. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2706. /*
  2707. * It's ok if the actual decrement is issued towards the memory
  2708. * somewhere between the spin_lock and spin_unlock. Thus no
  2709. * more explict memory barrier is needed.
  2710. */
  2711. if (common)
  2712. atomic_dec(&bp->eq_spq_left);
  2713. else
  2714. atomic_dec(&bp->cq_spq_left);
  2715. DP(BNX2X_MSG_SP,
  2716. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2717. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2718. (u32)(U64_LO(bp->spq_mapping) +
  2719. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2720. HW_CID(bp, cid), data_hi, data_lo, type,
  2721. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  2722. bnx2x_sp_prod_update(bp);
  2723. spin_unlock_bh(&bp->spq_lock);
  2724. return 0;
  2725. }
  2726. /* acquire split MCP access lock register */
  2727. static int bnx2x_acquire_alr(struct bnx2x *bp)
  2728. {
  2729. u32 j, val;
  2730. int rc = 0;
  2731. might_sleep();
  2732. for (j = 0; j < 1000; j++) {
  2733. val = (1UL << 31);
  2734. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  2735. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  2736. if (val & (1L << 31))
  2737. break;
  2738. msleep(5);
  2739. }
  2740. if (!(val & (1L << 31))) {
  2741. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  2742. rc = -EBUSY;
  2743. }
  2744. return rc;
  2745. }
  2746. /* release split MCP access lock register */
  2747. static void bnx2x_release_alr(struct bnx2x *bp)
  2748. {
  2749. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  2750. }
  2751. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  2752. #define BNX2X_DEF_SB_IDX 0x0002
  2753. static inline u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  2754. {
  2755. struct host_sp_status_block *def_sb = bp->def_status_blk;
  2756. u16 rc = 0;
  2757. barrier(); /* status block is written to by the chip */
  2758. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  2759. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  2760. rc |= BNX2X_DEF_SB_ATT_IDX;
  2761. }
  2762. if (bp->def_idx != def_sb->sp_sb.running_index) {
  2763. bp->def_idx = def_sb->sp_sb.running_index;
  2764. rc |= BNX2X_DEF_SB_IDX;
  2765. }
  2766. /* Do not reorder: indecies reading should complete before handling */
  2767. barrier();
  2768. return rc;
  2769. }
  2770. /*
  2771. * slow path service functions
  2772. */
  2773. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  2774. {
  2775. int port = BP_PORT(bp);
  2776. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  2777. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  2778. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  2779. NIG_REG_MASK_INTERRUPT_PORT0;
  2780. u32 aeu_mask;
  2781. u32 nig_mask = 0;
  2782. u32 reg_addr;
  2783. if (bp->attn_state & asserted)
  2784. BNX2X_ERR("IGU ERROR\n");
  2785. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2786. aeu_mask = REG_RD(bp, aeu_addr);
  2787. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  2788. aeu_mask, asserted);
  2789. aeu_mask &= ~(asserted & 0x3ff);
  2790. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  2791. REG_WR(bp, aeu_addr, aeu_mask);
  2792. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  2793. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  2794. bp->attn_state |= asserted;
  2795. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  2796. if (asserted & ATTN_HARD_WIRED_MASK) {
  2797. if (asserted & ATTN_NIG_FOR_FUNC) {
  2798. bnx2x_acquire_phy_lock(bp);
  2799. /* save nig interrupt mask */
  2800. nig_mask = REG_RD(bp, nig_int_mask_addr);
  2801. /* If nig_mask is not set, no need to call the update
  2802. * function.
  2803. */
  2804. if (nig_mask) {
  2805. REG_WR(bp, nig_int_mask_addr, 0);
  2806. bnx2x_link_attn(bp);
  2807. }
  2808. /* handle unicore attn? */
  2809. }
  2810. if (asserted & ATTN_SW_TIMER_4_FUNC)
  2811. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  2812. if (asserted & GPIO_2_FUNC)
  2813. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  2814. if (asserted & GPIO_3_FUNC)
  2815. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  2816. if (asserted & GPIO_4_FUNC)
  2817. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  2818. if (port == 0) {
  2819. if (asserted & ATTN_GENERAL_ATTN_1) {
  2820. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  2821. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  2822. }
  2823. if (asserted & ATTN_GENERAL_ATTN_2) {
  2824. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  2825. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  2826. }
  2827. if (asserted & ATTN_GENERAL_ATTN_3) {
  2828. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  2829. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  2830. }
  2831. } else {
  2832. if (asserted & ATTN_GENERAL_ATTN_4) {
  2833. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  2834. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  2835. }
  2836. if (asserted & ATTN_GENERAL_ATTN_5) {
  2837. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  2838. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  2839. }
  2840. if (asserted & ATTN_GENERAL_ATTN_6) {
  2841. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  2842. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  2843. }
  2844. }
  2845. } /* if hardwired */
  2846. if (bp->common.int_block == INT_BLOCK_HC)
  2847. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  2848. COMMAND_REG_ATTN_BITS_SET);
  2849. else
  2850. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  2851. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  2852. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  2853. REG_WR(bp, reg_addr, asserted);
  2854. /* now set back the mask */
  2855. if (asserted & ATTN_NIG_FOR_FUNC) {
  2856. REG_WR(bp, nig_int_mask_addr, nig_mask);
  2857. bnx2x_release_phy_lock(bp);
  2858. }
  2859. }
  2860. static inline void bnx2x_fan_failure(struct bnx2x *bp)
  2861. {
  2862. int port = BP_PORT(bp);
  2863. u32 ext_phy_config;
  2864. /* mark the failure */
  2865. ext_phy_config =
  2866. SHMEM_RD(bp,
  2867. dev_info.port_hw_config[port].external_phy_config);
  2868. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  2869. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  2870. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  2871. ext_phy_config);
  2872. /* log the failure */
  2873. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  2874. "Please contact OEM Support for assistance\n");
  2875. /*
  2876. * Scheudle device reset (unload)
  2877. * This is due to some boards consuming sufficient power when driver is
  2878. * up to overheat if fan fails.
  2879. */
  2880. smp_mb__before_clear_bit();
  2881. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  2882. smp_mb__after_clear_bit();
  2883. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  2884. }
  2885. static inline void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  2886. {
  2887. int port = BP_PORT(bp);
  2888. int reg_offset;
  2889. u32 val;
  2890. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  2891. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  2892. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  2893. val = REG_RD(bp, reg_offset);
  2894. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  2895. REG_WR(bp, reg_offset, val);
  2896. BNX2X_ERR("SPIO5 hw attention\n");
  2897. /* Fan failure attention */
  2898. bnx2x_hw_reset_phy(&bp->link_params);
  2899. bnx2x_fan_failure(bp);
  2900. }
  2901. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  2902. bnx2x_acquire_phy_lock(bp);
  2903. bnx2x_handle_module_detect_int(&bp->link_params);
  2904. bnx2x_release_phy_lock(bp);
  2905. }
  2906. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  2907. val = REG_RD(bp, reg_offset);
  2908. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  2909. REG_WR(bp, reg_offset, val);
  2910. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  2911. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  2912. bnx2x_panic();
  2913. }
  2914. }
  2915. static inline void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  2916. {
  2917. u32 val;
  2918. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  2919. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  2920. BNX2X_ERR("DB hw attention 0x%x\n", val);
  2921. /* DORQ discard attention */
  2922. if (val & 0x2)
  2923. BNX2X_ERR("FATAL error from DORQ\n");
  2924. }
  2925. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  2926. int port = BP_PORT(bp);
  2927. int reg_offset;
  2928. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  2929. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  2930. val = REG_RD(bp, reg_offset);
  2931. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  2932. REG_WR(bp, reg_offset, val);
  2933. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  2934. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  2935. bnx2x_panic();
  2936. }
  2937. }
  2938. static inline void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  2939. {
  2940. u32 val;
  2941. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  2942. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  2943. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  2944. /* CFC error attention */
  2945. if (val & 0x2)
  2946. BNX2X_ERR("FATAL error from CFC\n");
  2947. }
  2948. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  2949. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  2950. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  2951. /* RQ_USDMDP_FIFO_OVERFLOW */
  2952. if (val & 0x18000)
  2953. BNX2X_ERR("FATAL error from PXP\n");
  2954. if (!CHIP_IS_E1x(bp)) {
  2955. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  2956. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  2957. }
  2958. }
  2959. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  2960. int port = BP_PORT(bp);
  2961. int reg_offset;
  2962. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  2963. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  2964. val = REG_RD(bp, reg_offset);
  2965. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  2966. REG_WR(bp, reg_offset, val);
  2967. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  2968. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  2969. bnx2x_panic();
  2970. }
  2971. }
  2972. static inline void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  2973. {
  2974. u32 val;
  2975. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  2976. if (attn & BNX2X_PMF_LINK_ASSERT) {
  2977. int func = BP_FUNC(bp);
  2978. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  2979. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  2980. func_mf_config[BP_ABS_FUNC(bp)].config);
  2981. val = SHMEM_RD(bp,
  2982. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  2983. if (val & DRV_STATUS_DCC_EVENT_MASK)
  2984. bnx2x_dcc_event(bp,
  2985. (val & DRV_STATUS_DCC_EVENT_MASK));
  2986. if (val & DRV_STATUS_SET_MF_BW)
  2987. bnx2x_set_mf_bw(bp);
  2988. if (val & DRV_STATUS_DRV_INFO_REQ)
  2989. bnx2x_handle_drv_info_req(bp);
  2990. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  2991. bnx2x_pmf_update(bp);
  2992. if (bp->port.pmf &&
  2993. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  2994. bp->dcbx_enabled > 0)
  2995. /* start dcbx state machine */
  2996. bnx2x_dcbx_set_params(bp,
  2997. BNX2X_DCBX_STATE_NEG_RECEIVED);
  2998. if (bp->link_vars.periodic_flags &
  2999. PERIODIC_FLAGS_LINK_EVENT) {
  3000. /* sync with link */
  3001. bnx2x_acquire_phy_lock(bp);
  3002. bp->link_vars.periodic_flags &=
  3003. ~PERIODIC_FLAGS_LINK_EVENT;
  3004. bnx2x_release_phy_lock(bp);
  3005. if (IS_MF(bp))
  3006. bnx2x_link_sync_notify(bp);
  3007. bnx2x_link_report(bp);
  3008. }
  3009. /* Always call it here: bnx2x_link_report() will
  3010. * prevent the link indication duplication.
  3011. */
  3012. bnx2x__link_status_update(bp);
  3013. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3014. BNX2X_ERR("MC assert!\n");
  3015. bnx2x_mc_assert(bp);
  3016. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3017. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3018. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3019. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3020. bnx2x_panic();
  3021. } else if (attn & BNX2X_MCP_ASSERT) {
  3022. BNX2X_ERR("MCP assert!\n");
  3023. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3024. bnx2x_fw_dump(bp);
  3025. } else
  3026. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3027. }
  3028. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3029. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3030. if (attn & BNX2X_GRC_TIMEOUT) {
  3031. val = CHIP_IS_E1(bp) ? 0 :
  3032. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3033. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3034. }
  3035. if (attn & BNX2X_GRC_RSV) {
  3036. val = CHIP_IS_E1(bp) ? 0 :
  3037. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3038. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3039. }
  3040. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3041. }
  3042. }
  3043. /*
  3044. * Bits map:
  3045. * 0-7 - Engine0 load counter.
  3046. * 8-15 - Engine1 load counter.
  3047. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3048. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3049. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3050. * on the engine
  3051. * 19 - Engine1 ONE_IS_LOADED.
  3052. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3053. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3054. * just the one belonging to its engine).
  3055. *
  3056. */
  3057. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3058. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3059. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3060. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3061. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3062. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3063. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3064. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3065. /*
  3066. * Set the GLOBAL_RESET bit.
  3067. *
  3068. * Should be run under rtnl lock
  3069. */
  3070. void bnx2x_set_reset_global(struct bnx2x *bp)
  3071. {
  3072. u32 val;
  3073. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3074. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3075. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3076. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3077. }
  3078. /*
  3079. * Clear the GLOBAL_RESET bit.
  3080. *
  3081. * Should be run under rtnl lock
  3082. */
  3083. static inline void bnx2x_clear_reset_global(struct bnx2x *bp)
  3084. {
  3085. u32 val;
  3086. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3087. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3088. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3089. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3090. }
  3091. /*
  3092. * Checks the GLOBAL_RESET bit.
  3093. *
  3094. * should be run under rtnl lock
  3095. */
  3096. static inline bool bnx2x_reset_is_global(struct bnx2x *bp)
  3097. {
  3098. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3099. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3100. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3101. }
  3102. /*
  3103. * Clear RESET_IN_PROGRESS bit for the current engine.
  3104. *
  3105. * Should be run under rtnl lock
  3106. */
  3107. static inline void bnx2x_set_reset_done(struct bnx2x *bp)
  3108. {
  3109. u32 val;
  3110. u32 bit = BP_PATH(bp) ?
  3111. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3112. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3113. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3114. /* Clear the bit */
  3115. val &= ~bit;
  3116. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3117. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3118. }
  3119. /*
  3120. * Set RESET_IN_PROGRESS for the current engine.
  3121. *
  3122. * should be run under rtnl lock
  3123. */
  3124. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3125. {
  3126. u32 val;
  3127. u32 bit = BP_PATH(bp) ?
  3128. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3129. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3130. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3131. /* Set the bit */
  3132. val |= bit;
  3133. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3134. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3135. }
  3136. /*
  3137. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3138. * should be run under rtnl lock
  3139. */
  3140. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3141. {
  3142. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3143. u32 bit = engine ?
  3144. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3145. /* return false if bit is set */
  3146. return (val & bit) ? false : true;
  3147. }
  3148. /*
  3149. * set pf load for the current pf.
  3150. *
  3151. * should be run under rtnl lock
  3152. */
  3153. void bnx2x_set_pf_load(struct bnx2x *bp)
  3154. {
  3155. u32 val1, val;
  3156. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3157. BNX2X_PATH0_LOAD_CNT_MASK;
  3158. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3159. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3160. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3161. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3162. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3163. /* get the current counter value */
  3164. val1 = (val & mask) >> shift;
  3165. /* set bit of that PF */
  3166. val1 |= (1 << bp->pf_num);
  3167. /* clear the old value */
  3168. val &= ~mask;
  3169. /* set the new one */
  3170. val |= ((val1 << shift) & mask);
  3171. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3172. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3173. }
  3174. /**
  3175. * bnx2x_clear_pf_load - clear pf load mark
  3176. *
  3177. * @bp: driver handle
  3178. *
  3179. * Should be run under rtnl lock.
  3180. * Decrements the load counter for the current engine. Returns
  3181. * whether other functions are still loaded
  3182. */
  3183. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3184. {
  3185. u32 val1, val;
  3186. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3187. BNX2X_PATH0_LOAD_CNT_MASK;
  3188. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3189. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3190. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3191. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3192. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3193. /* get the current counter value */
  3194. val1 = (val & mask) >> shift;
  3195. /* clear bit of that PF */
  3196. val1 &= ~(1 << bp->pf_num);
  3197. /* clear the old value */
  3198. val &= ~mask;
  3199. /* set the new one */
  3200. val |= ((val1 << shift) & mask);
  3201. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3202. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3203. return val1 != 0;
  3204. }
  3205. /*
  3206. * Read the load status for the current engine.
  3207. *
  3208. * should be run under rtnl lock
  3209. */
  3210. static inline bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3211. {
  3212. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3213. BNX2X_PATH0_LOAD_CNT_MASK);
  3214. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3215. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3216. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3217. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3218. val = (val & mask) >> shift;
  3219. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3220. engine, val);
  3221. return val != 0;
  3222. }
  3223. /*
  3224. * Reset the load status for the current engine.
  3225. */
  3226. static inline void bnx2x_clear_load_status(struct bnx2x *bp)
  3227. {
  3228. u32 val;
  3229. u32 mask = (BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3230. BNX2X_PATH0_LOAD_CNT_MASK);
  3231. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3232. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3233. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~mask));
  3234. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3235. }
  3236. static inline void _print_next_block(int idx, const char *blk)
  3237. {
  3238. pr_cont("%s%s", idx ? ", " : "", blk);
  3239. }
  3240. static inline int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3241. bool print)
  3242. {
  3243. int i = 0;
  3244. u32 cur_bit = 0;
  3245. for (i = 0; sig; i++) {
  3246. cur_bit = ((u32)0x1 << i);
  3247. if (sig & cur_bit) {
  3248. switch (cur_bit) {
  3249. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3250. if (print)
  3251. _print_next_block(par_num++, "BRB");
  3252. break;
  3253. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3254. if (print)
  3255. _print_next_block(par_num++, "PARSER");
  3256. break;
  3257. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3258. if (print)
  3259. _print_next_block(par_num++, "TSDM");
  3260. break;
  3261. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3262. if (print)
  3263. _print_next_block(par_num++,
  3264. "SEARCHER");
  3265. break;
  3266. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3267. if (print)
  3268. _print_next_block(par_num++, "TCM");
  3269. break;
  3270. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3271. if (print)
  3272. _print_next_block(par_num++, "TSEMI");
  3273. break;
  3274. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3275. if (print)
  3276. _print_next_block(par_num++, "XPB");
  3277. break;
  3278. }
  3279. /* Clear the bit */
  3280. sig &= ~cur_bit;
  3281. }
  3282. }
  3283. return par_num;
  3284. }
  3285. static inline int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3286. bool *global, bool print)
  3287. {
  3288. int i = 0;
  3289. u32 cur_bit = 0;
  3290. for (i = 0; sig; i++) {
  3291. cur_bit = ((u32)0x1 << i);
  3292. if (sig & cur_bit) {
  3293. switch (cur_bit) {
  3294. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3295. if (print)
  3296. _print_next_block(par_num++, "PBF");
  3297. break;
  3298. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3299. if (print)
  3300. _print_next_block(par_num++, "QM");
  3301. break;
  3302. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3303. if (print)
  3304. _print_next_block(par_num++, "TM");
  3305. break;
  3306. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3307. if (print)
  3308. _print_next_block(par_num++, "XSDM");
  3309. break;
  3310. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3311. if (print)
  3312. _print_next_block(par_num++, "XCM");
  3313. break;
  3314. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3315. if (print)
  3316. _print_next_block(par_num++, "XSEMI");
  3317. break;
  3318. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3319. if (print)
  3320. _print_next_block(par_num++,
  3321. "DOORBELLQ");
  3322. break;
  3323. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3324. if (print)
  3325. _print_next_block(par_num++, "NIG");
  3326. break;
  3327. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3328. if (print)
  3329. _print_next_block(par_num++,
  3330. "VAUX PCI CORE");
  3331. *global = true;
  3332. break;
  3333. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3334. if (print)
  3335. _print_next_block(par_num++, "DEBUG");
  3336. break;
  3337. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3338. if (print)
  3339. _print_next_block(par_num++, "USDM");
  3340. break;
  3341. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3342. if (print)
  3343. _print_next_block(par_num++, "UCM");
  3344. break;
  3345. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3346. if (print)
  3347. _print_next_block(par_num++, "USEMI");
  3348. break;
  3349. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3350. if (print)
  3351. _print_next_block(par_num++, "UPB");
  3352. break;
  3353. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3354. if (print)
  3355. _print_next_block(par_num++, "CSDM");
  3356. break;
  3357. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3358. if (print)
  3359. _print_next_block(par_num++, "CCM");
  3360. break;
  3361. }
  3362. /* Clear the bit */
  3363. sig &= ~cur_bit;
  3364. }
  3365. }
  3366. return par_num;
  3367. }
  3368. static inline int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3369. bool print)
  3370. {
  3371. int i = 0;
  3372. u32 cur_bit = 0;
  3373. for (i = 0; sig; i++) {
  3374. cur_bit = ((u32)0x1 << i);
  3375. if (sig & cur_bit) {
  3376. switch (cur_bit) {
  3377. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3378. if (print)
  3379. _print_next_block(par_num++, "CSEMI");
  3380. break;
  3381. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3382. if (print)
  3383. _print_next_block(par_num++, "PXP");
  3384. break;
  3385. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3386. if (print)
  3387. _print_next_block(par_num++,
  3388. "PXPPCICLOCKCLIENT");
  3389. break;
  3390. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3391. if (print)
  3392. _print_next_block(par_num++, "CFC");
  3393. break;
  3394. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3395. if (print)
  3396. _print_next_block(par_num++, "CDU");
  3397. break;
  3398. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3399. if (print)
  3400. _print_next_block(par_num++, "DMAE");
  3401. break;
  3402. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3403. if (print)
  3404. _print_next_block(par_num++, "IGU");
  3405. break;
  3406. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3407. if (print)
  3408. _print_next_block(par_num++, "MISC");
  3409. break;
  3410. }
  3411. /* Clear the bit */
  3412. sig &= ~cur_bit;
  3413. }
  3414. }
  3415. return par_num;
  3416. }
  3417. static inline int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3418. bool *global, bool print)
  3419. {
  3420. int i = 0;
  3421. u32 cur_bit = 0;
  3422. for (i = 0; sig; i++) {
  3423. cur_bit = ((u32)0x1 << i);
  3424. if (sig & cur_bit) {
  3425. switch (cur_bit) {
  3426. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3427. if (print)
  3428. _print_next_block(par_num++, "MCP ROM");
  3429. *global = true;
  3430. break;
  3431. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3432. if (print)
  3433. _print_next_block(par_num++,
  3434. "MCP UMP RX");
  3435. *global = true;
  3436. break;
  3437. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3438. if (print)
  3439. _print_next_block(par_num++,
  3440. "MCP UMP TX");
  3441. *global = true;
  3442. break;
  3443. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3444. if (print)
  3445. _print_next_block(par_num++,
  3446. "MCP SCPAD");
  3447. *global = true;
  3448. break;
  3449. }
  3450. /* Clear the bit */
  3451. sig &= ~cur_bit;
  3452. }
  3453. }
  3454. return par_num;
  3455. }
  3456. static inline int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3457. bool print)
  3458. {
  3459. int i = 0;
  3460. u32 cur_bit = 0;
  3461. for (i = 0; sig; i++) {
  3462. cur_bit = ((u32)0x1 << i);
  3463. if (sig & cur_bit) {
  3464. switch (cur_bit) {
  3465. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3466. if (print)
  3467. _print_next_block(par_num++, "PGLUE_B");
  3468. break;
  3469. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3470. if (print)
  3471. _print_next_block(par_num++, "ATC");
  3472. break;
  3473. }
  3474. /* Clear the bit */
  3475. sig &= ~cur_bit;
  3476. }
  3477. }
  3478. return par_num;
  3479. }
  3480. static inline bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3481. u32 *sig)
  3482. {
  3483. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3484. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3485. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3486. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3487. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3488. int par_num = 0;
  3489. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3490. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3491. sig[0] & HW_PRTY_ASSERT_SET_0,
  3492. sig[1] & HW_PRTY_ASSERT_SET_1,
  3493. sig[2] & HW_PRTY_ASSERT_SET_2,
  3494. sig[3] & HW_PRTY_ASSERT_SET_3,
  3495. sig[4] & HW_PRTY_ASSERT_SET_4);
  3496. if (print)
  3497. netdev_err(bp->dev,
  3498. "Parity errors detected in blocks: ");
  3499. par_num = bnx2x_check_blocks_with_parity0(
  3500. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3501. par_num = bnx2x_check_blocks_with_parity1(
  3502. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3503. par_num = bnx2x_check_blocks_with_parity2(
  3504. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3505. par_num = bnx2x_check_blocks_with_parity3(
  3506. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3507. par_num = bnx2x_check_blocks_with_parity4(
  3508. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3509. if (print)
  3510. pr_cont("\n");
  3511. return true;
  3512. } else
  3513. return false;
  3514. }
  3515. /**
  3516. * bnx2x_chk_parity_attn - checks for parity attentions.
  3517. *
  3518. * @bp: driver handle
  3519. * @global: true if there was a global attention
  3520. * @print: show parity attention in syslog
  3521. */
  3522. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3523. {
  3524. struct attn_route attn = { {0} };
  3525. int port = BP_PORT(bp);
  3526. attn.sig[0] = REG_RD(bp,
  3527. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3528. port*4);
  3529. attn.sig[1] = REG_RD(bp,
  3530. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3531. port*4);
  3532. attn.sig[2] = REG_RD(bp,
  3533. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3534. port*4);
  3535. attn.sig[3] = REG_RD(bp,
  3536. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3537. port*4);
  3538. if (!CHIP_IS_E1x(bp))
  3539. attn.sig[4] = REG_RD(bp,
  3540. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3541. port*4);
  3542. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3543. }
  3544. static inline void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3545. {
  3546. u32 val;
  3547. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3548. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3549. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3550. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3551. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3552. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3553. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3554. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3555. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3556. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3557. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3558. if (val &
  3559. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3560. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3561. if (val &
  3562. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3563. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3564. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3565. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3566. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3567. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3568. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3569. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3570. }
  3571. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3572. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3573. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3574. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3575. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3576. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3577. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3578. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3579. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3580. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3581. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3582. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3583. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3584. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3585. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3586. }
  3587. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3588. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3589. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3590. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3591. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3592. }
  3593. }
  3594. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3595. {
  3596. struct attn_route attn, *group_mask;
  3597. int port = BP_PORT(bp);
  3598. int index;
  3599. u32 reg_addr;
  3600. u32 val;
  3601. u32 aeu_mask;
  3602. bool global = false;
  3603. /* need to take HW lock because MCP or other port might also
  3604. try to handle this event */
  3605. bnx2x_acquire_alr(bp);
  3606. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3607. #ifndef BNX2X_STOP_ON_ERROR
  3608. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3609. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3610. /* Disable HW interrupts */
  3611. bnx2x_int_disable(bp);
  3612. /* In case of parity errors don't handle attentions so that
  3613. * other function would "see" parity errors.
  3614. */
  3615. #else
  3616. bnx2x_panic();
  3617. #endif
  3618. bnx2x_release_alr(bp);
  3619. return;
  3620. }
  3621. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3622. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3623. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3624. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3625. if (!CHIP_IS_E1x(bp))
  3626. attn.sig[4] =
  3627. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3628. else
  3629. attn.sig[4] = 0;
  3630. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3631. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3632. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3633. if (deasserted & (1 << index)) {
  3634. group_mask = &bp->attn_group[index];
  3635. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3636. index,
  3637. group_mask->sig[0], group_mask->sig[1],
  3638. group_mask->sig[2], group_mask->sig[3],
  3639. group_mask->sig[4]);
  3640. bnx2x_attn_int_deasserted4(bp,
  3641. attn.sig[4] & group_mask->sig[4]);
  3642. bnx2x_attn_int_deasserted3(bp,
  3643. attn.sig[3] & group_mask->sig[3]);
  3644. bnx2x_attn_int_deasserted1(bp,
  3645. attn.sig[1] & group_mask->sig[1]);
  3646. bnx2x_attn_int_deasserted2(bp,
  3647. attn.sig[2] & group_mask->sig[2]);
  3648. bnx2x_attn_int_deasserted0(bp,
  3649. attn.sig[0] & group_mask->sig[0]);
  3650. }
  3651. }
  3652. bnx2x_release_alr(bp);
  3653. if (bp->common.int_block == INT_BLOCK_HC)
  3654. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3655. COMMAND_REG_ATTN_BITS_CLR);
  3656. else
  3657. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3658. val = ~deasserted;
  3659. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3660. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3661. REG_WR(bp, reg_addr, val);
  3662. if (~bp->attn_state & deasserted)
  3663. BNX2X_ERR("IGU ERROR\n");
  3664. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3665. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3666. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3667. aeu_mask = REG_RD(bp, reg_addr);
  3668. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3669. aeu_mask, deasserted);
  3670. aeu_mask |= (deasserted & 0x3ff);
  3671. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3672. REG_WR(bp, reg_addr, aeu_mask);
  3673. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3674. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3675. bp->attn_state &= ~deasserted;
  3676. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3677. }
  3678. static void bnx2x_attn_int(struct bnx2x *bp)
  3679. {
  3680. /* read local copy of bits */
  3681. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3682. attn_bits);
  3683. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3684. attn_bits_ack);
  3685. u32 attn_state = bp->attn_state;
  3686. /* look for changed bits */
  3687. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3688. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3689. DP(NETIF_MSG_HW,
  3690. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3691. attn_bits, attn_ack, asserted, deasserted);
  3692. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3693. BNX2X_ERR("BAD attention state\n");
  3694. /* handle bits that were raised */
  3695. if (asserted)
  3696. bnx2x_attn_int_asserted(bp, asserted);
  3697. if (deasserted)
  3698. bnx2x_attn_int_deasserted(bp, deasserted);
  3699. }
  3700. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3701. u16 index, u8 op, u8 update)
  3702. {
  3703. u32 igu_addr = BAR_IGU_INTMEM + (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3704. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3705. igu_addr);
  3706. }
  3707. static inline void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3708. {
  3709. /* No memory barriers */
  3710. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  3711. mmiowb(); /* keep prod updates ordered */
  3712. }
  3713. #ifdef BCM_CNIC
  3714. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  3715. union event_ring_elem *elem)
  3716. {
  3717. u8 err = elem->message.error;
  3718. if (!bp->cnic_eth_dev.starting_cid ||
  3719. (cid < bp->cnic_eth_dev.starting_cid &&
  3720. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  3721. return 1;
  3722. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  3723. if (unlikely(err)) {
  3724. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  3725. cid);
  3726. bnx2x_panic_dump(bp);
  3727. }
  3728. bnx2x_cnic_cfc_comp(bp, cid, err);
  3729. return 0;
  3730. }
  3731. #endif
  3732. static inline void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  3733. {
  3734. struct bnx2x_mcast_ramrod_params rparam;
  3735. int rc;
  3736. memset(&rparam, 0, sizeof(rparam));
  3737. rparam.mcast_obj = &bp->mcast_obj;
  3738. netif_addr_lock_bh(bp->dev);
  3739. /* Clear pending state for the last command */
  3740. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  3741. /* If there are pending mcast commands - send them */
  3742. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  3743. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  3744. if (rc < 0)
  3745. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  3746. rc);
  3747. }
  3748. netif_addr_unlock_bh(bp->dev);
  3749. }
  3750. static inline void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  3751. union event_ring_elem *elem)
  3752. {
  3753. unsigned long ramrod_flags = 0;
  3754. int rc = 0;
  3755. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  3756. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  3757. /* Always push next commands out, don't wait here */
  3758. __set_bit(RAMROD_CONT, &ramrod_flags);
  3759. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  3760. case BNX2X_FILTER_MAC_PENDING:
  3761. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  3762. #ifdef BCM_CNIC
  3763. if (cid == BNX2X_ISCSI_ETH_CID)
  3764. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  3765. else
  3766. #endif
  3767. vlan_mac_obj = &bp->fp[cid].mac_obj;
  3768. break;
  3769. case BNX2X_FILTER_MCAST_PENDING:
  3770. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  3771. /* This is only relevant for 57710 where multicast MACs are
  3772. * configured as unicast MACs using the same ramrod.
  3773. */
  3774. bnx2x_handle_mcast_eqe(bp);
  3775. return;
  3776. default:
  3777. BNX2X_ERR("Unsupported classification command: %d\n",
  3778. elem->message.data.eth_event.echo);
  3779. return;
  3780. }
  3781. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  3782. if (rc < 0)
  3783. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  3784. else if (rc > 0)
  3785. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  3786. }
  3787. #ifdef BCM_CNIC
  3788. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  3789. #endif
  3790. static inline void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  3791. {
  3792. netif_addr_lock_bh(bp->dev);
  3793. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  3794. /* Send rx_mode command again if was requested */
  3795. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  3796. bnx2x_set_storm_rx_mode(bp);
  3797. #ifdef BCM_CNIC
  3798. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  3799. &bp->sp_state))
  3800. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  3801. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  3802. &bp->sp_state))
  3803. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  3804. #endif
  3805. netif_addr_unlock_bh(bp->dev);
  3806. }
  3807. static inline struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  3808. struct bnx2x *bp, u32 cid)
  3809. {
  3810. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  3811. #ifdef BCM_CNIC
  3812. if (cid == BNX2X_FCOE_ETH_CID)
  3813. return &bnx2x_fcoe(bp, q_obj);
  3814. else
  3815. #endif
  3816. return &bnx2x_fp(bp, CID_TO_FP(cid), q_obj);
  3817. }
  3818. static void bnx2x_eq_int(struct bnx2x *bp)
  3819. {
  3820. u16 hw_cons, sw_cons, sw_prod;
  3821. union event_ring_elem *elem;
  3822. u32 cid;
  3823. u8 opcode;
  3824. int spqe_cnt = 0;
  3825. struct bnx2x_queue_sp_obj *q_obj;
  3826. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  3827. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  3828. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  3829. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  3830. * when we get the the next-page we nned to adjust so the loop
  3831. * condition below will be met. The next element is the size of a
  3832. * regular element and hence incrementing by 1
  3833. */
  3834. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  3835. hw_cons++;
  3836. /* This function may never run in parallel with itself for a
  3837. * specific bp, thus there is no need in "paired" read memory
  3838. * barrier here.
  3839. */
  3840. sw_cons = bp->eq_cons;
  3841. sw_prod = bp->eq_prod;
  3842. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  3843. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  3844. for (; sw_cons != hw_cons;
  3845. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  3846. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  3847. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  3848. opcode = elem->message.opcode;
  3849. /* handle eq element */
  3850. switch (opcode) {
  3851. case EVENT_RING_OPCODE_STAT_QUERY:
  3852. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  3853. "got statistics comp event %d\n",
  3854. bp->stats_comp++);
  3855. /* nothing to do with stats comp */
  3856. goto next_spqe;
  3857. case EVENT_RING_OPCODE_CFC_DEL:
  3858. /* handle according to cid range */
  3859. /*
  3860. * we may want to verify here that the bp state is
  3861. * HALTING
  3862. */
  3863. DP(BNX2X_MSG_SP,
  3864. "got delete ramrod for MULTI[%d]\n", cid);
  3865. #ifdef BCM_CNIC
  3866. if (!bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  3867. goto next_spqe;
  3868. #endif
  3869. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  3870. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  3871. break;
  3872. goto next_spqe;
  3873. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  3874. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  3875. if (f_obj->complete_cmd(bp, f_obj,
  3876. BNX2X_F_CMD_TX_STOP))
  3877. break;
  3878. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  3879. goto next_spqe;
  3880. case EVENT_RING_OPCODE_START_TRAFFIC:
  3881. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  3882. if (f_obj->complete_cmd(bp, f_obj,
  3883. BNX2X_F_CMD_TX_START))
  3884. break;
  3885. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  3886. goto next_spqe;
  3887. case EVENT_RING_OPCODE_FUNCTION_START:
  3888. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  3889. "got FUNC_START ramrod\n");
  3890. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  3891. break;
  3892. goto next_spqe;
  3893. case EVENT_RING_OPCODE_FUNCTION_STOP:
  3894. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  3895. "got FUNC_STOP ramrod\n");
  3896. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  3897. break;
  3898. goto next_spqe;
  3899. }
  3900. switch (opcode | bp->state) {
  3901. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3902. BNX2X_STATE_OPEN):
  3903. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  3904. BNX2X_STATE_OPENING_WAIT4_PORT):
  3905. cid = elem->message.data.eth_event.echo &
  3906. BNX2X_SWCID_MASK;
  3907. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  3908. cid);
  3909. rss_raw->clear_pending(rss_raw);
  3910. break;
  3911. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  3912. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  3913. case (EVENT_RING_OPCODE_SET_MAC |
  3914. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3915. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3916. BNX2X_STATE_OPEN):
  3917. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3918. BNX2X_STATE_DIAG):
  3919. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  3920. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3921. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  3922. bnx2x_handle_classification_eqe(bp, elem);
  3923. break;
  3924. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3925. BNX2X_STATE_OPEN):
  3926. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3927. BNX2X_STATE_DIAG):
  3928. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  3929. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3930. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  3931. bnx2x_handle_mcast_eqe(bp);
  3932. break;
  3933. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3934. BNX2X_STATE_OPEN):
  3935. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3936. BNX2X_STATE_DIAG):
  3937. case (EVENT_RING_OPCODE_FILTERS_RULES |
  3938. BNX2X_STATE_CLOSING_WAIT4_HALT):
  3939. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  3940. bnx2x_handle_rx_mode_eqe(bp);
  3941. break;
  3942. default:
  3943. /* unknown event log error and continue */
  3944. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  3945. elem->message.opcode, bp->state);
  3946. }
  3947. next_spqe:
  3948. spqe_cnt++;
  3949. } /* for */
  3950. smp_mb__before_atomic_inc();
  3951. atomic_add(spqe_cnt, &bp->eq_spq_left);
  3952. bp->eq_cons = sw_cons;
  3953. bp->eq_prod = sw_prod;
  3954. /* Make sure that above mem writes were issued towards the memory */
  3955. smp_wmb();
  3956. /* update producer */
  3957. bnx2x_update_eq_prod(bp, bp->eq_prod);
  3958. }
  3959. static void bnx2x_sp_task(struct work_struct *work)
  3960. {
  3961. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  3962. u16 status;
  3963. status = bnx2x_update_dsb_idx(bp);
  3964. /* if (status == 0) */
  3965. /* BNX2X_ERR("spurious slowpath interrupt!\n"); */
  3966. DP(BNX2X_MSG_SP, "got a slowpath interrupt (status 0x%x)\n", status);
  3967. /* HW attentions */
  3968. if (status & BNX2X_DEF_SB_ATT_IDX) {
  3969. bnx2x_attn_int(bp);
  3970. status &= ~BNX2X_DEF_SB_ATT_IDX;
  3971. }
  3972. /* SP events: STAT_QUERY and others */
  3973. if (status & BNX2X_DEF_SB_IDX) {
  3974. #ifdef BCM_CNIC
  3975. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  3976. if ((!NO_FCOE(bp)) &&
  3977. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  3978. /*
  3979. * Prevent local bottom-halves from running as
  3980. * we are going to change the local NAPI list.
  3981. */
  3982. local_bh_disable();
  3983. napi_schedule(&bnx2x_fcoe(bp, napi));
  3984. local_bh_enable();
  3985. }
  3986. #endif
  3987. /* Handle EQ completions */
  3988. bnx2x_eq_int(bp);
  3989. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  3990. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  3991. status &= ~BNX2X_DEF_SB_IDX;
  3992. }
  3993. if (unlikely(status))
  3994. DP(BNX2X_MSG_SP, "got an unknown interrupt! (status 0x%x)\n",
  3995. status);
  3996. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  3997. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  3998. }
  3999. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4000. {
  4001. struct net_device *dev = dev_instance;
  4002. struct bnx2x *bp = netdev_priv(dev);
  4003. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4004. IGU_INT_DISABLE, 0);
  4005. #ifdef BNX2X_STOP_ON_ERROR
  4006. if (unlikely(bp->panic))
  4007. return IRQ_HANDLED;
  4008. #endif
  4009. #ifdef BCM_CNIC
  4010. {
  4011. struct cnic_ops *c_ops;
  4012. rcu_read_lock();
  4013. c_ops = rcu_dereference(bp->cnic_ops);
  4014. if (c_ops)
  4015. c_ops->cnic_handler(bp->cnic_data, NULL);
  4016. rcu_read_unlock();
  4017. }
  4018. #endif
  4019. queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  4020. return IRQ_HANDLED;
  4021. }
  4022. /* end of slow path */
  4023. void bnx2x_drv_pulse(struct bnx2x *bp)
  4024. {
  4025. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4026. bp->fw_drv_pulse_wr_seq);
  4027. }
  4028. static void bnx2x_timer(unsigned long data)
  4029. {
  4030. struct bnx2x *bp = (struct bnx2x *) data;
  4031. if (!netif_running(bp->dev))
  4032. return;
  4033. if (!BP_NOMCP(bp)) {
  4034. int mb_idx = BP_FW_MB_IDX(bp);
  4035. u32 drv_pulse;
  4036. u32 mcp_pulse;
  4037. ++bp->fw_drv_pulse_wr_seq;
  4038. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4039. /* TBD - add SYSTEM_TIME */
  4040. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4041. bnx2x_drv_pulse(bp);
  4042. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4043. MCP_PULSE_SEQ_MASK);
  4044. /* The delta between driver pulse and mcp response
  4045. * should be 1 (before mcp response) or 0 (after mcp response)
  4046. */
  4047. if ((drv_pulse != mcp_pulse) &&
  4048. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4049. /* someone lost a heartbeat... */
  4050. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4051. drv_pulse, mcp_pulse);
  4052. }
  4053. }
  4054. if (bp->state == BNX2X_STATE_OPEN)
  4055. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4056. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4057. }
  4058. /* end of Statistics */
  4059. /* nic init */
  4060. /*
  4061. * nic init service functions
  4062. */
  4063. static inline void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4064. {
  4065. u32 i;
  4066. if (!(len%4) && !(addr%4))
  4067. for (i = 0; i < len; i += 4)
  4068. REG_WR(bp, addr + i, fill);
  4069. else
  4070. for (i = 0; i < len; i++)
  4071. REG_WR8(bp, addr + i, fill);
  4072. }
  4073. /* helper: writes FP SP data to FW - data_size in dwords */
  4074. static inline void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4075. int fw_sb_id,
  4076. u32 *sb_data_p,
  4077. u32 data_size)
  4078. {
  4079. int index;
  4080. for (index = 0; index < data_size; index++)
  4081. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4082. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4083. sizeof(u32)*index,
  4084. *(sb_data_p + index));
  4085. }
  4086. static inline void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4087. {
  4088. u32 *sb_data_p;
  4089. u32 data_size = 0;
  4090. struct hc_status_block_data_e2 sb_data_e2;
  4091. struct hc_status_block_data_e1x sb_data_e1x;
  4092. /* disable the function first */
  4093. if (!CHIP_IS_E1x(bp)) {
  4094. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4095. sb_data_e2.common.state = SB_DISABLED;
  4096. sb_data_e2.common.p_func.vf_valid = false;
  4097. sb_data_p = (u32 *)&sb_data_e2;
  4098. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4099. } else {
  4100. memset(&sb_data_e1x, 0,
  4101. sizeof(struct hc_status_block_data_e1x));
  4102. sb_data_e1x.common.state = SB_DISABLED;
  4103. sb_data_e1x.common.p_func.vf_valid = false;
  4104. sb_data_p = (u32 *)&sb_data_e1x;
  4105. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4106. }
  4107. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4108. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4109. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4110. CSTORM_STATUS_BLOCK_SIZE);
  4111. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4112. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4113. CSTORM_SYNC_BLOCK_SIZE);
  4114. }
  4115. /* helper: writes SP SB data to FW */
  4116. static inline void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4117. struct hc_sp_status_block_data *sp_sb_data)
  4118. {
  4119. int func = BP_FUNC(bp);
  4120. int i;
  4121. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4122. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4123. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4124. i*sizeof(u32),
  4125. *((u32 *)sp_sb_data + i));
  4126. }
  4127. static inline void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4128. {
  4129. int func = BP_FUNC(bp);
  4130. struct hc_sp_status_block_data sp_sb_data;
  4131. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4132. sp_sb_data.state = SB_DISABLED;
  4133. sp_sb_data.p_func.vf_valid = false;
  4134. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4135. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4136. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4137. CSTORM_SP_STATUS_BLOCK_SIZE);
  4138. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4139. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4140. CSTORM_SP_SYNC_BLOCK_SIZE);
  4141. }
  4142. static inline
  4143. void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4144. int igu_sb_id, int igu_seg_id)
  4145. {
  4146. hc_sm->igu_sb_id = igu_sb_id;
  4147. hc_sm->igu_seg_id = igu_seg_id;
  4148. hc_sm->timer_value = 0xFF;
  4149. hc_sm->time_to_expire = 0xFFFFFFFF;
  4150. }
  4151. /* allocates state machine ids. */
  4152. static inline
  4153. void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4154. {
  4155. /* zero out state machine indices */
  4156. /* rx indices */
  4157. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4158. /* tx indices */
  4159. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4160. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4161. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4162. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4163. /* map indices */
  4164. /* rx indices */
  4165. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4166. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4167. /* tx indices */
  4168. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4169. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4170. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4171. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4172. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4173. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4174. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4175. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4176. }
  4177. static void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4178. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4179. {
  4180. int igu_seg_id;
  4181. struct hc_status_block_data_e2 sb_data_e2;
  4182. struct hc_status_block_data_e1x sb_data_e1x;
  4183. struct hc_status_block_sm *hc_sm_p;
  4184. int data_size;
  4185. u32 *sb_data_p;
  4186. if (CHIP_INT_MODE_IS_BC(bp))
  4187. igu_seg_id = HC_SEG_ACCESS_NORM;
  4188. else
  4189. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4190. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4191. if (!CHIP_IS_E1x(bp)) {
  4192. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4193. sb_data_e2.common.state = SB_ENABLED;
  4194. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4195. sb_data_e2.common.p_func.vf_id = vfid;
  4196. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4197. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4198. sb_data_e2.common.same_igu_sb_1b = true;
  4199. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4200. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4201. hc_sm_p = sb_data_e2.common.state_machine;
  4202. sb_data_p = (u32 *)&sb_data_e2;
  4203. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4204. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4205. } else {
  4206. memset(&sb_data_e1x, 0,
  4207. sizeof(struct hc_status_block_data_e1x));
  4208. sb_data_e1x.common.state = SB_ENABLED;
  4209. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4210. sb_data_e1x.common.p_func.vf_id = 0xff;
  4211. sb_data_e1x.common.p_func.vf_valid = false;
  4212. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4213. sb_data_e1x.common.same_igu_sb_1b = true;
  4214. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4215. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4216. hc_sm_p = sb_data_e1x.common.state_machine;
  4217. sb_data_p = (u32 *)&sb_data_e1x;
  4218. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4219. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4220. }
  4221. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4222. igu_sb_id, igu_seg_id);
  4223. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4224. igu_sb_id, igu_seg_id);
  4225. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4226. /* write indecies to HW */
  4227. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4228. }
  4229. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4230. u16 tx_usec, u16 rx_usec)
  4231. {
  4232. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4233. false, rx_usec);
  4234. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4235. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4236. tx_usec);
  4237. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4238. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4239. tx_usec);
  4240. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4241. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4242. tx_usec);
  4243. }
  4244. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4245. {
  4246. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4247. dma_addr_t mapping = bp->def_status_blk_mapping;
  4248. int igu_sp_sb_index;
  4249. int igu_seg_id;
  4250. int port = BP_PORT(bp);
  4251. int func = BP_FUNC(bp);
  4252. int reg_offset, reg_offset_en5;
  4253. u64 section;
  4254. int index;
  4255. struct hc_sp_status_block_data sp_sb_data;
  4256. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4257. if (CHIP_INT_MODE_IS_BC(bp)) {
  4258. igu_sp_sb_index = DEF_SB_IGU_ID;
  4259. igu_seg_id = HC_SEG_ACCESS_DEF;
  4260. } else {
  4261. igu_sp_sb_index = bp->igu_dsb_id;
  4262. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4263. }
  4264. /* ATTN */
  4265. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4266. atten_status_block);
  4267. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4268. bp->attn_state = 0;
  4269. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4270. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4271. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4272. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4273. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4274. int sindex;
  4275. /* take care of sig[0]..sig[4] */
  4276. for (sindex = 0; sindex < 4; sindex++)
  4277. bp->attn_group[index].sig[sindex] =
  4278. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4279. if (!CHIP_IS_E1x(bp))
  4280. /*
  4281. * enable5 is separate from the rest of the registers,
  4282. * and therefore the address skip is 4
  4283. * and not 16 between the different groups
  4284. */
  4285. bp->attn_group[index].sig[4] = REG_RD(bp,
  4286. reg_offset_en5 + 0x4*index);
  4287. else
  4288. bp->attn_group[index].sig[4] = 0;
  4289. }
  4290. if (bp->common.int_block == INT_BLOCK_HC) {
  4291. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4292. HC_REG_ATTN_MSG0_ADDR_L);
  4293. REG_WR(bp, reg_offset, U64_LO(section));
  4294. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4295. } else if (!CHIP_IS_E1x(bp)) {
  4296. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4297. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4298. }
  4299. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4300. sp_sb);
  4301. bnx2x_zero_sp_sb(bp);
  4302. sp_sb_data.state = SB_ENABLED;
  4303. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4304. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4305. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4306. sp_sb_data.igu_seg_id = igu_seg_id;
  4307. sp_sb_data.p_func.pf_id = func;
  4308. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4309. sp_sb_data.p_func.vf_id = 0xff;
  4310. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4311. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4312. }
  4313. void bnx2x_update_coalesce(struct bnx2x *bp)
  4314. {
  4315. int i;
  4316. for_each_eth_queue(bp, i)
  4317. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4318. bp->tx_ticks, bp->rx_ticks);
  4319. }
  4320. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4321. {
  4322. spin_lock_init(&bp->spq_lock);
  4323. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4324. bp->spq_prod_idx = 0;
  4325. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4326. bp->spq_prod_bd = bp->spq;
  4327. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4328. }
  4329. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4330. {
  4331. int i;
  4332. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4333. union event_ring_elem *elem =
  4334. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4335. elem->next_page.addr.hi =
  4336. cpu_to_le32(U64_HI(bp->eq_mapping +
  4337. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4338. elem->next_page.addr.lo =
  4339. cpu_to_le32(U64_LO(bp->eq_mapping +
  4340. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4341. }
  4342. bp->eq_cons = 0;
  4343. bp->eq_prod = NUM_EQ_DESC;
  4344. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4345. /* we want a warning message before it gets rought... */
  4346. atomic_set(&bp->eq_spq_left,
  4347. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4348. }
  4349. /* called with netif_addr_lock_bh() */
  4350. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4351. unsigned long rx_mode_flags,
  4352. unsigned long rx_accept_flags,
  4353. unsigned long tx_accept_flags,
  4354. unsigned long ramrod_flags)
  4355. {
  4356. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4357. int rc;
  4358. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4359. /* Prepare ramrod parameters */
  4360. ramrod_param.cid = 0;
  4361. ramrod_param.cl_id = cl_id;
  4362. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4363. ramrod_param.func_id = BP_FUNC(bp);
  4364. ramrod_param.pstate = &bp->sp_state;
  4365. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4366. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4367. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4368. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4369. ramrod_param.ramrod_flags = ramrod_flags;
  4370. ramrod_param.rx_mode_flags = rx_mode_flags;
  4371. ramrod_param.rx_accept_flags = rx_accept_flags;
  4372. ramrod_param.tx_accept_flags = tx_accept_flags;
  4373. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4374. if (rc < 0) {
  4375. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4376. return;
  4377. }
  4378. }
  4379. /* called with netif_addr_lock_bh() */
  4380. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4381. {
  4382. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4383. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4384. #ifdef BCM_CNIC
  4385. if (!NO_FCOE(bp))
  4386. /* Configure rx_mode of FCoE Queue */
  4387. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4388. #endif
  4389. switch (bp->rx_mode) {
  4390. case BNX2X_RX_MODE_NONE:
  4391. /*
  4392. * 'drop all' supersedes any accept flags that may have been
  4393. * passed to the function.
  4394. */
  4395. break;
  4396. case BNX2X_RX_MODE_NORMAL:
  4397. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4398. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4399. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4400. /* internal switching mode */
  4401. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4402. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4403. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4404. break;
  4405. case BNX2X_RX_MODE_ALLMULTI:
  4406. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4407. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4408. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4409. /* internal switching mode */
  4410. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4411. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4412. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4413. break;
  4414. case BNX2X_RX_MODE_PROMISC:
  4415. /* According to deffinition of SI mode, iface in promisc mode
  4416. * should receive matched and unmatched (in resolution of port)
  4417. * unicast packets.
  4418. */
  4419. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4420. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4421. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4422. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4423. /* internal switching mode */
  4424. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4425. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4426. if (IS_MF_SI(bp))
  4427. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4428. else
  4429. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4430. break;
  4431. default:
  4432. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4433. return;
  4434. }
  4435. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4436. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4437. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4438. }
  4439. __set_bit(RAMROD_RX, &ramrod_flags);
  4440. __set_bit(RAMROD_TX, &ramrod_flags);
  4441. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4442. tx_accept_flags, ramrod_flags);
  4443. }
  4444. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4445. {
  4446. int i;
  4447. if (IS_MF_SI(bp))
  4448. /*
  4449. * In switch independent mode, the TSTORM needs to accept
  4450. * packets that failed classification, since approximate match
  4451. * mac addresses aren't written to NIG LLH
  4452. */
  4453. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4454. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4455. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4456. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4457. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4458. /* Zero this manually as its initialization is
  4459. currently missing in the initTool */
  4460. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4461. REG_WR(bp, BAR_USTRORM_INTMEM +
  4462. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4463. if (!CHIP_IS_E1x(bp)) {
  4464. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4465. CHIP_INT_MODE_IS_BC(bp) ?
  4466. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4467. }
  4468. }
  4469. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4470. {
  4471. switch (load_code) {
  4472. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4473. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4474. bnx2x_init_internal_common(bp);
  4475. /* no break */
  4476. case FW_MSG_CODE_DRV_LOAD_PORT:
  4477. /* nothing to do */
  4478. /* no break */
  4479. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4480. /* internal memory per function is
  4481. initialized inside bnx2x_pf_init */
  4482. break;
  4483. default:
  4484. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4485. break;
  4486. }
  4487. }
  4488. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4489. {
  4490. return fp->bp->igu_base_sb + fp->index + CNIC_PRESENT;
  4491. }
  4492. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4493. {
  4494. return fp->bp->base_fw_ndsb + fp->index + CNIC_PRESENT;
  4495. }
  4496. static inline u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4497. {
  4498. if (CHIP_IS_E1x(fp->bp))
  4499. return BP_L_ID(fp->bp) + fp->index;
  4500. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4501. return bnx2x_fp_igu_sb_id(fp);
  4502. }
  4503. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4504. {
  4505. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4506. u8 cos;
  4507. unsigned long q_type = 0;
  4508. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4509. fp->rx_queue = fp_idx;
  4510. fp->cid = fp_idx;
  4511. fp->cl_id = bnx2x_fp_cl_id(fp);
  4512. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4513. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4514. /* qZone id equals to FW (per path) client id */
  4515. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4516. /* init shortcut */
  4517. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4518. /* Setup SB indicies */
  4519. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4520. /* Configure Queue State object */
  4521. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4522. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4523. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4524. /* init tx data */
  4525. for_each_cos_in_tx_queue(fp, cos) {
  4526. bnx2x_init_txdata(bp, &fp->txdata[cos],
  4527. CID_COS_TO_TX_ONLY_CID(fp->cid, cos),
  4528. FP_COS_TO_TXQ(fp, cos),
  4529. BNX2X_TX_SB_INDEX_BASE + cos);
  4530. cids[cos] = fp->txdata[cos].cid;
  4531. }
  4532. bnx2x_init_queue_obj(bp, &fp->q_obj, fp->cl_id, cids, fp->max_cos,
  4533. BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4534. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4535. /**
  4536. * Configure classification DBs: Always enable Tx switching
  4537. */
  4538. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4539. DP(NETIF_MSG_IFUP, "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4540. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4541. fp->igu_sb_id);
  4542. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4543. fp->fw_sb_id, fp->igu_sb_id);
  4544. bnx2x_update_fpsb_idx(fp);
  4545. }
  4546. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  4547. {
  4548. int i;
  4549. for_each_eth_queue(bp, i)
  4550. bnx2x_init_eth_fp(bp, i);
  4551. #ifdef BCM_CNIC
  4552. if (!NO_FCOE(bp))
  4553. bnx2x_init_fcoe_fp(bp);
  4554. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4555. BNX2X_VF_ID_INVALID, false,
  4556. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4557. #endif
  4558. /* Initialize MOD_ABS interrupts */
  4559. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  4560. bp->common.shmem_base, bp->common.shmem2_base,
  4561. BP_PORT(bp));
  4562. /* ensure status block indices were read */
  4563. rmb();
  4564. bnx2x_init_def_sb(bp);
  4565. bnx2x_update_dsb_idx(bp);
  4566. bnx2x_init_rx_rings(bp);
  4567. bnx2x_init_tx_rings(bp);
  4568. bnx2x_init_sp_ring(bp);
  4569. bnx2x_init_eq_ring(bp);
  4570. bnx2x_init_internal(bp, load_code);
  4571. bnx2x_pf_init(bp);
  4572. bnx2x_stats_init(bp);
  4573. /* flush all before enabling interrupts */
  4574. mb();
  4575. mmiowb();
  4576. bnx2x_int_enable(bp);
  4577. /* Check for SPIO5 */
  4578. bnx2x_attn_int_deasserted0(bp,
  4579. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  4580. AEU_INPUTS_ATTN_BITS_SPIO5);
  4581. }
  4582. /* end of nic init */
  4583. /*
  4584. * gzip service functions
  4585. */
  4586. static int bnx2x_gunzip_init(struct bnx2x *bp)
  4587. {
  4588. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  4589. &bp->gunzip_mapping, GFP_KERNEL);
  4590. if (bp->gunzip_buf == NULL)
  4591. goto gunzip_nomem1;
  4592. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  4593. if (bp->strm == NULL)
  4594. goto gunzip_nomem2;
  4595. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  4596. if (bp->strm->workspace == NULL)
  4597. goto gunzip_nomem3;
  4598. return 0;
  4599. gunzip_nomem3:
  4600. kfree(bp->strm);
  4601. bp->strm = NULL;
  4602. gunzip_nomem2:
  4603. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4604. bp->gunzip_mapping);
  4605. bp->gunzip_buf = NULL;
  4606. gunzip_nomem1:
  4607. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  4608. return -ENOMEM;
  4609. }
  4610. static void bnx2x_gunzip_end(struct bnx2x *bp)
  4611. {
  4612. if (bp->strm) {
  4613. vfree(bp->strm->workspace);
  4614. kfree(bp->strm);
  4615. bp->strm = NULL;
  4616. }
  4617. if (bp->gunzip_buf) {
  4618. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  4619. bp->gunzip_mapping);
  4620. bp->gunzip_buf = NULL;
  4621. }
  4622. }
  4623. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  4624. {
  4625. int n, rc;
  4626. /* check gzip header */
  4627. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  4628. BNX2X_ERR("Bad gzip header\n");
  4629. return -EINVAL;
  4630. }
  4631. n = 10;
  4632. #define FNAME 0x8
  4633. if (zbuf[3] & FNAME)
  4634. while ((zbuf[n++] != 0) && (n < len));
  4635. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  4636. bp->strm->avail_in = len - n;
  4637. bp->strm->next_out = bp->gunzip_buf;
  4638. bp->strm->avail_out = FW_BUF_SIZE;
  4639. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  4640. if (rc != Z_OK)
  4641. return rc;
  4642. rc = zlib_inflate(bp->strm, Z_FINISH);
  4643. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  4644. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  4645. bp->strm->msg);
  4646. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  4647. if (bp->gunzip_outlen & 0x3)
  4648. netdev_err(bp->dev,
  4649. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  4650. bp->gunzip_outlen);
  4651. bp->gunzip_outlen >>= 2;
  4652. zlib_inflateEnd(bp->strm);
  4653. if (rc == Z_STREAM_END)
  4654. return 0;
  4655. return rc;
  4656. }
  4657. /* nic load/unload */
  4658. /*
  4659. * General service functions
  4660. */
  4661. /* send a NIG loopback debug packet */
  4662. static void bnx2x_lb_pckt(struct bnx2x *bp)
  4663. {
  4664. u32 wb_write[3];
  4665. /* Ethernet source and destination addresses */
  4666. wb_write[0] = 0x55555555;
  4667. wb_write[1] = 0x55555555;
  4668. wb_write[2] = 0x20; /* SOP */
  4669. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4670. /* NON-IP protocol */
  4671. wb_write[0] = 0x09000000;
  4672. wb_write[1] = 0x55555555;
  4673. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  4674. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  4675. }
  4676. /* some of the internal memories
  4677. * are not directly readable from the driver
  4678. * to test them we send debug packets
  4679. */
  4680. static int bnx2x_int_mem_test(struct bnx2x *bp)
  4681. {
  4682. int factor;
  4683. int count, i;
  4684. u32 val = 0;
  4685. if (CHIP_REV_IS_FPGA(bp))
  4686. factor = 120;
  4687. else if (CHIP_REV_IS_EMUL(bp))
  4688. factor = 200;
  4689. else
  4690. factor = 1;
  4691. /* Disable inputs of parser neighbor blocks */
  4692. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4693. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4694. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4695. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4696. /* Write 0 to parser credits for CFC search request */
  4697. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4698. /* send Ethernet packet */
  4699. bnx2x_lb_pckt(bp);
  4700. /* TODO do i reset NIG statistic? */
  4701. /* Wait until NIG register shows 1 packet of size 0x10 */
  4702. count = 1000 * factor;
  4703. while (count) {
  4704. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4705. val = *bnx2x_sp(bp, wb_data[0]);
  4706. if (val == 0x10)
  4707. break;
  4708. msleep(10);
  4709. count--;
  4710. }
  4711. if (val != 0x10) {
  4712. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4713. return -1;
  4714. }
  4715. /* Wait until PRS register shows 1 packet */
  4716. count = 1000 * factor;
  4717. while (count) {
  4718. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4719. if (val == 1)
  4720. break;
  4721. msleep(10);
  4722. count--;
  4723. }
  4724. if (val != 0x1) {
  4725. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4726. return -2;
  4727. }
  4728. /* Reset and init BRB, PRS */
  4729. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4730. msleep(50);
  4731. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4732. msleep(50);
  4733. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4734. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4735. DP(NETIF_MSG_HW, "part2\n");
  4736. /* Disable inputs of parser neighbor blocks */
  4737. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  4738. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  4739. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  4740. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  4741. /* Write 0 to parser credits for CFC search request */
  4742. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  4743. /* send 10 Ethernet packets */
  4744. for (i = 0; i < 10; i++)
  4745. bnx2x_lb_pckt(bp);
  4746. /* Wait until NIG register shows 10 + 1
  4747. packets of size 11*0x10 = 0xb0 */
  4748. count = 1000 * factor;
  4749. while (count) {
  4750. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  4751. val = *bnx2x_sp(bp, wb_data[0]);
  4752. if (val == 0xb0)
  4753. break;
  4754. msleep(10);
  4755. count--;
  4756. }
  4757. if (val != 0xb0) {
  4758. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  4759. return -3;
  4760. }
  4761. /* Wait until PRS register shows 2 packets */
  4762. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4763. if (val != 2)
  4764. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4765. /* Write 1 to parser credits for CFC search request */
  4766. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  4767. /* Wait until PRS register shows 3 packets */
  4768. msleep(10 * factor);
  4769. /* Wait until NIG register shows 1 packet of size 0x10 */
  4770. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  4771. if (val != 3)
  4772. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  4773. /* clear NIG EOP FIFO */
  4774. for (i = 0; i < 11; i++)
  4775. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  4776. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  4777. if (val != 1) {
  4778. BNX2X_ERR("clear of NIG failed\n");
  4779. return -4;
  4780. }
  4781. /* Reset and init BRB, PRS, NIG */
  4782. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  4783. msleep(50);
  4784. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  4785. msleep(50);
  4786. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  4787. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  4788. #ifndef BCM_CNIC
  4789. /* set NIC mode */
  4790. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  4791. #endif
  4792. /* Enable inputs of parser neighbor blocks */
  4793. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  4794. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  4795. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  4796. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  4797. DP(NETIF_MSG_HW, "done\n");
  4798. return 0; /* OK */
  4799. }
  4800. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  4801. {
  4802. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  4803. if (!CHIP_IS_E1x(bp))
  4804. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  4805. else
  4806. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  4807. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  4808. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  4809. /*
  4810. * mask read length error interrupts in brb for parser
  4811. * (parsing unit and 'checksum and crc' unit)
  4812. * these errors are legal (PU reads fixed length and CAC can cause
  4813. * read length error on truncated packets)
  4814. */
  4815. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  4816. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  4817. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  4818. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  4819. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  4820. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  4821. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  4822. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  4823. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  4824. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  4825. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  4826. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  4827. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  4828. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  4829. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  4830. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  4831. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  4832. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  4833. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  4834. if (CHIP_REV_IS_FPGA(bp))
  4835. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x580000);
  4836. else if (!CHIP_IS_E1x(bp))
  4837. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0,
  4838. (PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF
  4839. | PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT
  4840. | PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN
  4841. | PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED
  4842. | PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED));
  4843. else
  4844. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, 0x480000);
  4845. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  4846. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  4847. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  4848. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  4849. if (!CHIP_IS_E1x(bp))
  4850. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  4851. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  4852. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  4853. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  4854. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  4855. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  4856. }
  4857. static void bnx2x_reset_common(struct bnx2x *bp)
  4858. {
  4859. u32 val = 0x1400;
  4860. /* reset_common */
  4861. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  4862. 0xd3ffff7f);
  4863. if (CHIP_IS_E3(bp)) {
  4864. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  4865. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  4866. }
  4867. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  4868. }
  4869. static void bnx2x_setup_dmae(struct bnx2x *bp)
  4870. {
  4871. bp->dmae_ready = 0;
  4872. spin_lock_init(&bp->dmae_lock);
  4873. }
  4874. static void bnx2x_init_pxp(struct bnx2x *bp)
  4875. {
  4876. u16 devctl;
  4877. int r_order, w_order;
  4878. pci_read_config_word(bp->pdev,
  4879. pci_pcie_cap(bp->pdev) + PCI_EXP_DEVCTL, &devctl);
  4880. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  4881. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  4882. if (bp->mrrs == -1)
  4883. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  4884. else {
  4885. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  4886. r_order = bp->mrrs;
  4887. }
  4888. bnx2x_init_pxp_arb(bp, r_order, w_order);
  4889. }
  4890. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  4891. {
  4892. int is_required;
  4893. u32 val;
  4894. int port;
  4895. if (BP_NOMCP(bp))
  4896. return;
  4897. is_required = 0;
  4898. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  4899. SHARED_HW_CFG_FAN_FAILURE_MASK;
  4900. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  4901. is_required = 1;
  4902. /*
  4903. * The fan failure mechanism is usually related to the PHY type since
  4904. * the power consumption of the board is affected by the PHY. Currently,
  4905. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  4906. */
  4907. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  4908. for (port = PORT_0; port < PORT_MAX; port++) {
  4909. is_required |=
  4910. bnx2x_fan_failure_det_req(
  4911. bp,
  4912. bp->common.shmem_base,
  4913. bp->common.shmem2_base,
  4914. port);
  4915. }
  4916. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  4917. if (is_required == 0)
  4918. return;
  4919. /* Fan failure is indicated by SPIO 5 */
  4920. bnx2x_set_spio(bp, MISC_REGISTERS_SPIO_5,
  4921. MISC_REGISTERS_SPIO_INPUT_HI_Z);
  4922. /* set to active low mode */
  4923. val = REG_RD(bp, MISC_REG_SPIO_INT);
  4924. val |= ((1 << MISC_REGISTERS_SPIO_5) <<
  4925. MISC_REGISTERS_SPIO_INT_OLD_SET_POS);
  4926. REG_WR(bp, MISC_REG_SPIO_INT, val);
  4927. /* enable interrupt to signal the IGU */
  4928. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  4929. val |= (1 << MISC_REGISTERS_SPIO_5);
  4930. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  4931. }
  4932. static void bnx2x_pretend_func(struct bnx2x *bp, u8 pretend_func_num)
  4933. {
  4934. u32 offset = 0;
  4935. if (CHIP_IS_E1(bp))
  4936. return;
  4937. if (CHIP_IS_E1H(bp) && (pretend_func_num >= E1H_FUNC_MAX))
  4938. return;
  4939. switch (BP_ABS_FUNC(bp)) {
  4940. case 0:
  4941. offset = PXP2_REG_PGL_PRETEND_FUNC_F0;
  4942. break;
  4943. case 1:
  4944. offset = PXP2_REG_PGL_PRETEND_FUNC_F1;
  4945. break;
  4946. case 2:
  4947. offset = PXP2_REG_PGL_PRETEND_FUNC_F2;
  4948. break;
  4949. case 3:
  4950. offset = PXP2_REG_PGL_PRETEND_FUNC_F3;
  4951. break;
  4952. case 4:
  4953. offset = PXP2_REG_PGL_PRETEND_FUNC_F4;
  4954. break;
  4955. case 5:
  4956. offset = PXP2_REG_PGL_PRETEND_FUNC_F5;
  4957. break;
  4958. case 6:
  4959. offset = PXP2_REG_PGL_PRETEND_FUNC_F6;
  4960. break;
  4961. case 7:
  4962. offset = PXP2_REG_PGL_PRETEND_FUNC_F7;
  4963. break;
  4964. default:
  4965. return;
  4966. }
  4967. REG_WR(bp, offset, pretend_func_num);
  4968. REG_RD(bp, offset);
  4969. DP(NETIF_MSG_HW, "Pretending to func %d\n", pretend_func_num);
  4970. }
  4971. void bnx2x_pf_disable(struct bnx2x *bp)
  4972. {
  4973. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  4974. val &= ~IGU_PF_CONF_FUNC_EN;
  4975. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  4976. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  4977. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  4978. }
  4979. static inline void bnx2x__common_init_phy(struct bnx2x *bp)
  4980. {
  4981. u32 shmem_base[2], shmem2_base[2];
  4982. shmem_base[0] = bp->common.shmem_base;
  4983. shmem2_base[0] = bp->common.shmem2_base;
  4984. if (!CHIP_IS_E1x(bp)) {
  4985. shmem_base[1] =
  4986. SHMEM2_RD(bp, other_shmem_base_addr);
  4987. shmem2_base[1] =
  4988. SHMEM2_RD(bp, other_shmem2_base_addr);
  4989. }
  4990. bnx2x_acquire_phy_lock(bp);
  4991. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  4992. bp->common.chip_id);
  4993. bnx2x_release_phy_lock(bp);
  4994. }
  4995. /**
  4996. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  4997. *
  4998. * @bp: driver handle
  4999. */
  5000. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5001. {
  5002. u32 val;
  5003. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5004. /*
  5005. * take the UNDI lock to protect undi_unload flow from accessing
  5006. * registers while we're resetting the chip
  5007. */
  5008. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5009. bnx2x_reset_common(bp);
  5010. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5011. val = 0xfffc;
  5012. if (CHIP_IS_E3(bp)) {
  5013. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5014. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5015. }
  5016. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5017. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5018. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5019. if (!CHIP_IS_E1x(bp)) {
  5020. u8 abs_func_id;
  5021. /**
  5022. * 4-port mode or 2-port mode we need to turn of master-enable
  5023. * for everyone, after that, turn it back on for self.
  5024. * so, we disregard multi-function or not, and always disable
  5025. * for all functions on the given path, this means 0,2,4,6 for
  5026. * path 0 and 1,3,5,7 for path 1
  5027. */
  5028. for (abs_func_id = BP_PATH(bp);
  5029. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5030. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5031. REG_WR(bp,
  5032. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5033. 1);
  5034. continue;
  5035. }
  5036. bnx2x_pretend_func(bp, abs_func_id);
  5037. /* clear pf enable */
  5038. bnx2x_pf_disable(bp);
  5039. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5040. }
  5041. }
  5042. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5043. if (CHIP_IS_E1(bp)) {
  5044. /* enable HW interrupt from PXP on USDM overflow
  5045. bit 16 on INT_MASK_0 */
  5046. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5047. }
  5048. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5049. bnx2x_init_pxp(bp);
  5050. #ifdef __BIG_ENDIAN
  5051. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5052. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5053. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5054. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5055. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5056. /* make sure this value is 0 */
  5057. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5058. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5059. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5060. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5061. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5062. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5063. #endif
  5064. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5065. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5066. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5067. /* let the HW do it's magic ... */
  5068. msleep(100);
  5069. /* finish PXP init */
  5070. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5071. if (val != 1) {
  5072. BNX2X_ERR("PXP2 CFG failed\n");
  5073. return -EBUSY;
  5074. }
  5075. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5076. if (val != 1) {
  5077. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5078. return -EBUSY;
  5079. }
  5080. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5081. * have entries with value "0" and valid bit on.
  5082. * This needs to be done by the first PF that is loaded in a path
  5083. * (i.e. common phase)
  5084. */
  5085. if (!CHIP_IS_E1x(bp)) {
  5086. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5087. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5088. * This occurs when a different function (func2,3) is being marked
  5089. * as "scan-off". Real-life scenario for example: if a driver is being
  5090. * load-unloaded while func6,7 are down. This will cause the timer to access
  5091. * the ilt, translate to a logical address and send a request to read/write.
  5092. * Since the ilt for the function that is down is not valid, this will cause
  5093. * a translation error which is unrecoverable.
  5094. * The Workaround is intended to make sure that when this happens nothing fatal
  5095. * will occur. The workaround:
  5096. * 1. First PF driver which loads on a path will:
  5097. * a. After taking the chip out of reset, by using pretend,
  5098. * it will write "0" to the following registers of
  5099. * the other vnics.
  5100. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5101. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5102. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5103. * And for itself it will write '1' to
  5104. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5105. * dmae-operations (writing to pram for example.)
  5106. * note: can be done for only function 6,7 but cleaner this
  5107. * way.
  5108. * b. Write zero+valid to the entire ILT.
  5109. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5110. * VNIC3 (of that port). The range allocated will be the
  5111. * entire ILT. This is needed to prevent ILT range error.
  5112. * 2. Any PF driver load flow:
  5113. * a. ILT update with the physical addresses of the allocated
  5114. * logical pages.
  5115. * b. Wait 20msec. - note that this timeout is needed to make
  5116. * sure there are no requests in one of the PXP internal
  5117. * queues with "old" ILT addresses.
  5118. * c. PF enable in the PGLC.
  5119. * d. Clear the was_error of the PF in the PGLC. (could have
  5120. * occured while driver was down)
  5121. * e. PF enable in the CFC (WEAK + STRONG)
  5122. * f. Timers scan enable
  5123. * 3. PF driver unload flow:
  5124. * a. Clear the Timers scan_en.
  5125. * b. Polling for scan_on=0 for that PF.
  5126. * c. Clear the PF enable bit in the PXP.
  5127. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5128. * e. Write zero+valid to all ILT entries (The valid bit must
  5129. * stay set)
  5130. * f. If this is VNIC 3 of a port then also init
  5131. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5132. * to the last enrty in the ILT.
  5133. *
  5134. * Notes:
  5135. * Currently the PF error in the PGLC is non recoverable.
  5136. * In the future the there will be a recovery routine for this error.
  5137. * Currently attention is masked.
  5138. * Having an MCP lock on the load/unload process does not guarantee that
  5139. * there is no Timer disable during Func6/7 enable. This is because the
  5140. * Timers scan is currently being cleared by the MCP on FLR.
  5141. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5142. * there is error before clearing it. But the flow above is simpler and
  5143. * more general.
  5144. * All ILT entries are written by zero+valid and not just PF6/7
  5145. * ILT entries since in the future the ILT entries allocation for
  5146. * PF-s might be dynamic.
  5147. */
  5148. struct ilt_client_info ilt_cli;
  5149. struct bnx2x_ilt ilt;
  5150. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5151. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5152. /* initialize dummy TM client */
  5153. ilt_cli.start = 0;
  5154. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5155. ilt_cli.client_num = ILT_CLIENT_TM;
  5156. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5157. * Step 2: set the timers first/last ilt entry to point
  5158. * to the entire range to prevent ILT range error for 3rd/4th
  5159. * vnic (this code assumes existance of the vnic)
  5160. *
  5161. * both steps performed by call to bnx2x_ilt_client_init_op()
  5162. * with dummy TM client
  5163. *
  5164. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5165. * and his brother are split registers
  5166. */
  5167. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5168. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5169. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5170. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5171. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5172. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5173. }
  5174. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5175. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5176. if (!CHIP_IS_E1x(bp)) {
  5177. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5178. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5179. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5180. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5181. /* let the HW do it's magic ... */
  5182. do {
  5183. msleep(200);
  5184. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5185. } while (factor-- && (val != 1));
  5186. if (val != 1) {
  5187. BNX2X_ERR("ATC_INIT failed\n");
  5188. return -EBUSY;
  5189. }
  5190. }
  5191. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5192. /* clean the DMAE memory */
  5193. bp->dmae_ready = 1;
  5194. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5195. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5196. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5197. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5198. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5199. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5200. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5201. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5202. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5203. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5204. /* QM queues pointers table */
  5205. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5206. /* soft reset pulse */
  5207. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5208. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5209. #ifdef BCM_CNIC
  5210. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5211. #endif
  5212. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5213. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5214. if (!CHIP_REV_IS_SLOW(bp))
  5215. /* enable hw interrupt from doorbell Q */
  5216. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5217. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5218. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5219. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5220. if (!CHIP_IS_E1(bp))
  5221. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5222. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp))
  5223. /* Bit-map indicating which L2 hdrs may appear
  5224. * after the basic Ethernet header
  5225. */
  5226. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5227. bp->path_has_ovlan ? 7 : 6);
  5228. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5229. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5230. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5231. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5232. if (!CHIP_IS_E1x(bp)) {
  5233. /* reset VFC memories */
  5234. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5235. VFC_MEMORIES_RST_REG_CAM_RST |
  5236. VFC_MEMORIES_RST_REG_RAM_RST);
  5237. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5238. VFC_MEMORIES_RST_REG_CAM_RST |
  5239. VFC_MEMORIES_RST_REG_RAM_RST);
  5240. msleep(20);
  5241. }
  5242. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5243. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5244. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5245. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5246. /* sync semi rtc */
  5247. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5248. 0x80000000);
  5249. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5250. 0x80000000);
  5251. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5252. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5253. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5254. if (!CHIP_IS_E1x(bp))
  5255. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5256. bp->path_has_ovlan ? 7 : 6);
  5257. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5258. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5259. #ifdef BCM_CNIC
  5260. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5261. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5262. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5263. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5264. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5265. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5266. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5267. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5268. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5269. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5270. #endif
  5271. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5272. if (sizeof(union cdu_context) != 1024)
  5273. /* we currently assume that a context is 1024 bytes */
  5274. dev_alert(&bp->pdev->dev,
  5275. "please adjust the size of cdu_context(%ld)\n",
  5276. (long)sizeof(union cdu_context));
  5277. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5278. val = (4 << 24) + (0 << 12) + 1024;
  5279. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5280. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5281. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5282. /* enable context validation interrupt from CFC */
  5283. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5284. /* set the thresholds to prevent CFC/CDU race */
  5285. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5286. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5287. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5288. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5289. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5290. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5291. /* Reset PCIE errors for debug */
  5292. REG_WR(bp, 0x2814, 0xffffffff);
  5293. REG_WR(bp, 0x3820, 0xffffffff);
  5294. if (!CHIP_IS_E1x(bp)) {
  5295. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5296. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5297. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5298. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5299. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5300. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5301. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5302. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5303. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5304. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5305. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5306. }
  5307. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5308. if (!CHIP_IS_E1(bp)) {
  5309. /* in E3 this done in per-port section */
  5310. if (!CHIP_IS_E3(bp))
  5311. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5312. }
  5313. if (CHIP_IS_E1H(bp))
  5314. /* not applicable for E2 (and above ...) */
  5315. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5316. if (CHIP_REV_IS_SLOW(bp))
  5317. msleep(200);
  5318. /* finish CFC init */
  5319. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5320. if (val != 1) {
  5321. BNX2X_ERR("CFC LL_INIT failed\n");
  5322. return -EBUSY;
  5323. }
  5324. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5325. if (val != 1) {
  5326. BNX2X_ERR("CFC AC_INIT failed\n");
  5327. return -EBUSY;
  5328. }
  5329. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5330. if (val != 1) {
  5331. BNX2X_ERR("CFC CAM_INIT failed\n");
  5332. return -EBUSY;
  5333. }
  5334. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5335. if (CHIP_IS_E1(bp)) {
  5336. /* read NIG statistic
  5337. to see if this is our first up since powerup */
  5338. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5339. val = *bnx2x_sp(bp, wb_data[0]);
  5340. /* do internal memory self test */
  5341. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5342. BNX2X_ERR("internal mem self test failed\n");
  5343. return -EBUSY;
  5344. }
  5345. }
  5346. bnx2x_setup_fan_failure_detection(bp);
  5347. /* clear PXP2 attentions */
  5348. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5349. bnx2x_enable_blocks_attention(bp);
  5350. bnx2x_enable_blocks_parity(bp);
  5351. if (!BP_NOMCP(bp)) {
  5352. if (CHIP_IS_E1x(bp))
  5353. bnx2x__common_init_phy(bp);
  5354. } else
  5355. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5356. return 0;
  5357. }
  5358. /**
  5359. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5360. *
  5361. * @bp: driver handle
  5362. */
  5363. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5364. {
  5365. int rc = bnx2x_init_hw_common(bp);
  5366. if (rc)
  5367. return rc;
  5368. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5369. if (!BP_NOMCP(bp))
  5370. bnx2x__common_init_phy(bp);
  5371. return 0;
  5372. }
  5373. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5374. {
  5375. int port = BP_PORT(bp);
  5376. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5377. u32 low, high;
  5378. u32 val;
  5379. bnx2x__link_reset(bp);
  5380. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5381. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5382. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5383. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5384. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5385. /* Timers bug workaround: disables the pf_master bit in pglue at
  5386. * common phase, we need to enable it here before any dmae access are
  5387. * attempted. Therefore we manually added the enable-master to the
  5388. * port phase (it also happens in the function phase)
  5389. */
  5390. if (!CHIP_IS_E1x(bp))
  5391. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5392. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5393. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5394. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5395. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5396. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5397. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5398. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5399. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5400. /* QM cid (connection) count */
  5401. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5402. #ifdef BCM_CNIC
  5403. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5404. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5405. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5406. #endif
  5407. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5408. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5409. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5410. if (IS_MF(bp))
  5411. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5412. else if (bp->dev->mtu > 4096) {
  5413. if (bp->flags & ONE_PORT_FLAG)
  5414. low = 160;
  5415. else {
  5416. val = bp->dev->mtu;
  5417. /* (24*1024 + val*4)/256 */
  5418. low = 96 + (val/64) +
  5419. ((val % 64) ? 1 : 0);
  5420. }
  5421. } else
  5422. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5423. high = low + 56; /* 14*1024/256 */
  5424. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5425. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5426. }
  5427. if (CHIP_MODE_IS_4_PORT(bp))
  5428. REG_WR(bp, (BP_PORT(bp) ?
  5429. BRB1_REG_MAC_GUARANTIED_1 :
  5430. BRB1_REG_MAC_GUARANTIED_0), 40);
  5431. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5432. if (CHIP_IS_E3B0(bp))
  5433. /* Ovlan exists only if we are in multi-function +
  5434. * switch-dependent mode, in switch-independent there
  5435. * is no ovlan headers
  5436. */
  5437. REG_WR(bp, BP_PORT(bp) ?
  5438. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5439. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5440. (bp->path_has_ovlan ? 7 : 6));
  5441. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5442. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5443. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5444. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5445. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5446. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5447. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5448. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5449. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5450. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5451. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5452. if (CHIP_IS_E1x(bp)) {
  5453. /* configure PBF to work without PAUSE mtu 9000 */
  5454. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5455. /* update threshold */
  5456. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5457. /* update init credit */
  5458. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5459. /* probe changes */
  5460. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5461. udelay(50);
  5462. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5463. }
  5464. #ifdef BCM_CNIC
  5465. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5466. #endif
  5467. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5468. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5469. if (CHIP_IS_E1(bp)) {
  5470. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5471. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5472. }
  5473. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5474. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5475. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5476. /* init aeu_mask_attn_func_0/1:
  5477. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5478. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5479. * bits 4-7 are used for "per vn group attention" */
  5480. val = IS_MF(bp) ? 0xF7 : 0x7;
  5481. /* Enable DCBX attention for all but E1 */
  5482. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5483. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5484. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5485. if (!CHIP_IS_E1x(bp)) {
  5486. /* Bit-map indicating which L2 hdrs may appear after the
  5487. * basic Ethernet header
  5488. */
  5489. REG_WR(bp, BP_PORT(bp) ?
  5490. NIG_REG_P1_HDRS_AFTER_BASIC :
  5491. NIG_REG_P0_HDRS_AFTER_BASIC,
  5492. IS_MF_SD(bp) ? 7 : 6);
  5493. if (CHIP_IS_E3(bp))
  5494. REG_WR(bp, BP_PORT(bp) ?
  5495. NIG_REG_LLH1_MF_MODE :
  5496. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5497. }
  5498. if (!CHIP_IS_E3(bp))
  5499. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5500. if (!CHIP_IS_E1(bp)) {
  5501. /* 0x2 disable mf_ov, 0x1 enable */
  5502. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5503. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5504. if (!CHIP_IS_E1x(bp)) {
  5505. val = 0;
  5506. switch (bp->mf_mode) {
  5507. case MULTI_FUNCTION_SD:
  5508. val = 1;
  5509. break;
  5510. case MULTI_FUNCTION_SI:
  5511. val = 2;
  5512. break;
  5513. }
  5514. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5515. NIG_REG_LLH0_CLS_TYPE), val);
  5516. }
  5517. {
  5518. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5519. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5520. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5521. }
  5522. }
  5523. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5524. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5525. if (val & (1 << MISC_REGISTERS_SPIO_5)) {
  5526. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5527. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5528. val = REG_RD(bp, reg_addr);
  5529. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5530. REG_WR(bp, reg_addr, val);
  5531. }
  5532. return 0;
  5533. }
  5534. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5535. {
  5536. int reg;
  5537. if (CHIP_IS_E1(bp))
  5538. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5539. else
  5540. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5541. bnx2x_wb_wr(bp, reg, ONCHIP_ADDR1(addr), ONCHIP_ADDR2(addr));
  5542. }
  5543. static inline void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  5544. {
  5545. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  5546. }
  5547. static inline void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  5548. {
  5549. u32 i, base = FUNC_ILT_BASE(func);
  5550. for (i = base; i < base + ILT_PER_FUNC; i++)
  5551. bnx2x_ilt_wr(bp, i, 0);
  5552. }
  5553. static int bnx2x_init_hw_func(struct bnx2x *bp)
  5554. {
  5555. int port = BP_PORT(bp);
  5556. int func = BP_FUNC(bp);
  5557. int init_phase = PHASE_PF0 + func;
  5558. struct bnx2x_ilt *ilt = BP_ILT(bp);
  5559. u16 cdu_ilt_start;
  5560. u32 addr, val;
  5561. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  5562. int i, main_mem_width, rc;
  5563. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  5564. /* FLR cleanup - hmmm */
  5565. if (!CHIP_IS_E1x(bp)) {
  5566. rc = bnx2x_pf_flr_clnup(bp);
  5567. if (rc)
  5568. return rc;
  5569. }
  5570. /* set MSI reconfigure capability */
  5571. if (bp->common.int_block == INT_BLOCK_HC) {
  5572. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  5573. val = REG_RD(bp, addr);
  5574. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  5575. REG_WR(bp, addr, val);
  5576. }
  5577. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5578. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5579. ilt = BP_ILT(bp);
  5580. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  5581. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  5582. ilt->lines[cdu_ilt_start + i].page =
  5583. bp->context.vcxt + (ILT_PAGE_CIDS * i);
  5584. ilt->lines[cdu_ilt_start + i].page_mapping =
  5585. bp->context.cxt_mapping + (CDU_ILT_PAGE_SZ * i);
  5586. /* cdu ilt pages are allocated manually so there's no need to
  5587. set the size */
  5588. }
  5589. bnx2x_ilt_init_op(bp, INITOP_SET);
  5590. #ifdef BCM_CNIC
  5591. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  5592. /* T1 hash bits value determines the T1 number of entries */
  5593. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  5594. #endif
  5595. #ifndef BCM_CNIC
  5596. /* set NIC mode */
  5597. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5598. #endif /* BCM_CNIC */
  5599. if (!CHIP_IS_E1x(bp)) {
  5600. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  5601. /* Turn on a single ISR mode in IGU if driver is going to use
  5602. * INT#x or MSI
  5603. */
  5604. if (!(bp->flags & USING_MSIX_FLAG))
  5605. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  5606. /*
  5607. * Timers workaround bug: function init part.
  5608. * Need to wait 20msec after initializing ILT,
  5609. * needed to make sure there are no requests in
  5610. * one of the PXP internal queues with "old" ILT addresses
  5611. */
  5612. msleep(20);
  5613. /*
  5614. * Master enable - Due to WB DMAE writes performed before this
  5615. * register is re-initialized as part of the regular function
  5616. * init
  5617. */
  5618. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5619. /* Enable the function in IGU */
  5620. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  5621. }
  5622. bp->dmae_ready = 1;
  5623. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5624. if (!CHIP_IS_E1x(bp))
  5625. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  5626. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5627. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5628. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5629. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5630. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5631. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5632. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5633. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5634. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5635. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5636. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5637. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5638. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5639. if (!CHIP_IS_E1x(bp))
  5640. REG_WR(bp, QM_REG_PF_EN, 1);
  5641. if (!CHIP_IS_E1x(bp)) {
  5642. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5643. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5644. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5645. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  5646. }
  5647. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5648. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5649. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5650. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5651. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5652. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5653. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5654. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5655. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5656. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5657. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5658. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5659. if (!CHIP_IS_E1x(bp))
  5660. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  5661. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5662. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5663. if (!CHIP_IS_E1x(bp))
  5664. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  5665. if (IS_MF(bp)) {
  5666. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  5667. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  5668. }
  5669. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5670. /* HC init per function */
  5671. if (bp->common.int_block == INT_BLOCK_HC) {
  5672. if (CHIP_IS_E1H(bp)) {
  5673. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5674. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5675. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5676. }
  5677. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5678. } else {
  5679. int num_segs, sb_idx, prod_offset;
  5680. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  5681. if (!CHIP_IS_E1x(bp)) {
  5682. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  5683. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  5684. }
  5685. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5686. if (!CHIP_IS_E1x(bp)) {
  5687. int dsb_idx = 0;
  5688. /**
  5689. * Producer memory:
  5690. * E2 mode: address 0-135 match to the mapping memory;
  5691. * 136 - PF0 default prod; 137 - PF1 default prod;
  5692. * 138 - PF2 default prod; 139 - PF3 default prod;
  5693. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  5694. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  5695. * 144-147 reserved.
  5696. *
  5697. * E1.5 mode - In backward compatible mode;
  5698. * for non default SB; each even line in the memory
  5699. * holds the U producer and each odd line hold
  5700. * the C producer. The first 128 producers are for
  5701. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  5702. * producers are for the DSB for each PF.
  5703. * Each PF has five segments: (the order inside each
  5704. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  5705. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  5706. * 144-147 attn prods;
  5707. */
  5708. /* non-default-status-blocks */
  5709. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5710. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  5711. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  5712. prod_offset = (bp->igu_base_sb + sb_idx) *
  5713. num_segs;
  5714. for (i = 0; i < num_segs; i++) {
  5715. addr = IGU_REG_PROD_CONS_MEMORY +
  5716. (prod_offset + i) * 4;
  5717. REG_WR(bp, addr, 0);
  5718. }
  5719. /* send consumer update with value 0 */
  5720. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  5721. USTORM_ID, 0, IGU_INT_NOP, 1);
  5722. bnx2x_igu_clear_sb(bp,
  5723. bp->igu_base_sb + sb_idx);
  5724. }
  5725. /* default-status-blocks */
  5726. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  5727. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  5728. if (CHIP_MODE_IS_4_PORT(bp))
  5729. dsb_idx = BP_FUNC(bp);
  5730. else
  5731. dsb_idx = BP_VN(bp);
  5732. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  5733. IGU_BC_BASE_DSB_PROD + dsb_idx :
  5734. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  5735. /*
  5736. * igu prods come in chunks of E1HVN_MAX (4) -
  5737. * does not matters what is the current chip mode
  5738. */
  5739. for (i = 0; i < (num_segs * E1HVN_MAX);
  5740. i += E1HVN_MAX) {
  5741. addr = IGU_REG_PROD_CONS_MEMORY +
  5742. (prod_offset + i)*4;
  5743. REG_WR(bp, addr, 0);
  5744. }
  5745. /* send consumer update with 0 */
  5746. if (CHIP_INT_MODE_IS_BC(bp)) {
  5747. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5748. USTORM_ID, 0, IGU_INT_NOP, 1);
  5749. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5750. CSTORM_ID, 0, IGU_INT_NOP, 1);
  5751. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5752. XSTORM_ID, 0, IGU_INT_NOP, 1);
  5753. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5754. TSTORM_ID, 0, IGU_INT_NOP, 1);
  5755. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5756. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5757. } else {
  5758. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5759. USTORM_ID, 0, IGU_INT_NOP, 1);
  5760. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  5761. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  5762. }
  5763. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  5764. /* !!! these should become driver const once
  5765. rf-tool supports split-68 const */
  5766. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  5767. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  5768. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  5769. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  5770. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  5771. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  5772. }
  5773. }
  5774. /* Reset PCIE errors for debug */
  5775. REG_WR(bp, 0x2114, 0xffffffff);
  5776. REG_WR(bp, 0x2120, 0xffffffff);
  5777. if (CHIP_IS_E1x(bp)) {
  5778. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  5779. main_mem_base = HC_REG_MAIN_MEMORY +
  5780. BP_PORT(bp) * (main_mem_size * 4);
  5781. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  5782. main_mem_width = 8;
  5783. val = REG_RD(bp, main_mem_prty_clr);
  5784. if (val)
  5785. DP(NETIF_MSG_HW,
  5786. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  5787. val);
  5788. /* Clear "false" parity errors in MSI-X table */
  5789. for (i = main_mem_base;
  5790. i < main_mem_base + main_mem_size * 4;
  5791. i += main_mem_width) {
  5792. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  5793. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  5794. i, main_mem_width / 4);
  5795. }
  5796. /* Clear HC parity attention */
  5797. REG_RD(bp, main_mem_prty_clr);
  5798. }
  5799. #ifdef BNX2X_STOP_ON_ERROR
  5800. /* Enable STORMs SP logging */
  5801. REG_WR8(bp, BAR_USTRORM_INTMEM +
  5802. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5803. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5804. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5805. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  5806. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5807. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  5808. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  5809. #endif
  5810. bnx2x_phy_probe(&bp->link_params);
  5811. return 0;
  5812. }
  5813. void bnx2x_free_mem(struct bnx2x *bp)
  5814. {
  5815. /* fastpath */
  5816. bnx2x_free_fp_mem(bp);
  5817. /* end of fastpath */
  5818. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  5819. sizeof(struct host_sp_status_block));
  5820. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5821. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5822. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  5823. sizeof(struct bnx2x_slowpath));
  5824. BNX2X_PCI_FREE(bp->context.vcxt, bp->context.cxt_mapping,
  5825. bp->context.size);
  5826. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  5827. BNX2X_FREE(bp->ilt->lines);
  5828. #ifdef BCM_CNIC
  5829. if (!CHIP_IS_E1x(bp))
  5830. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  5831. sizeof(struct host_hc_status_block_e2));
  5832. else
  5833. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  5834. sizeof(struct host_hc_status_block_e1x));
  5835. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  5836. #endif
  5837. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  5838. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  5839. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5840. }
  5841. static inline int bnx2x_alloc_fw_stats_mem(struct bnx2x *bp)
  5842. {
  5843. int num_groups;
  5844. int is_fcoe_stats = NO_FCOE(bp) ? 0 : 1;
  5845. /* number of queues for statistics is number of eth queues + FCoE */
  5846. u8 num_queue_stats = BNX2X_NUM_ETH_QUEUES(bp) + is_fcoe_stats;
  5847. /* Total number of FW statistics requests =
  5848. * 1 for port stats + 1 for PF stats + potential 1 for FCoE stats +
  5849. * num of queues
  5850. */
  5851. bp->fw_stats_num = 2 + is_fcoe_stats + num_queue_stats;
  5852. /* Request is built from stats_query_header and an array of
  5853. * stats_query_cmd_group each of which contains
  5854. * STATS_QUERY_CMD_COUNT rules. The real number or requests is
  5855. * configured in the stats_query_header.
  5856. */
  5857. num_groups = ((bp->fw_stats_num) / STATS_QUERY_CMD_COUNT) +
  5858. (((bp->fw_stats_num) % STATS_QUERY_CMD_COUNT) ? 1 : 0);
  5859. bp->fw_stats_req_sz = sizeof(struct stats_query_header) +
  5860. num_groups * sizeof(struct stats_query_cmd_group);
  5861. /* Data for statistics requests + stats_conter
  5862. *
  5863. * stats_counter holds per-STORM counters that are incremented
  5864. * when STORM has finished with the current request.
  5865. *
  5866. * memory for FCoE offloaded statistics are counted anyway,
  5867. * even if they will not be sent.
  5868. */
  5869. bp->fw_stats_data_sz = sizeof(struct per_port_stats) +
  5870. sizeof(struct per_pf_stats) +
  5871. sizeof(struct fcoe_statistics_params) +
  5872. sizeof(struct per_queue_stats) * num_queue_stats +
  5873. sizeof(struct stats_counter);
  5874. BNX2X_PCI_ALLOC(bp->fw_stats, &bp->fw_stats_mapping,
  5875. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5876. /* Set shortcuts */
  5877. bp->fw_stats_req = (struct bnx2x_fw_stats_req *)bp->fw_stats;
  5878. bp->fw_stats_req_mapping = bp->fw_stats_mapping;
  5879. bp->fw_stats_data = (struct bnx2x_fw_stats_data *)
  5880. ((u8 *)bp->fw_stats + bp->fw_stats_req_sz);
  5881. bp->fw_stats_data_mapping = bp->fw_stats_mapping +
  5882. bp->fw_stats_req_sz;
  5883. return 0;
  5884. alloc_mem_err:
  5885. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  5886. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  5887. BNX2X_ERR("Can't allocate memory\n");
  5888. return -ENOMEM;
  5889. }
  5890. int bnx2x_alloc_mem(struct bnx2x *bp)
  5891. {
  5892. #ifdef BCM_CNIC
  5893. if (!CHIP_IS_E1x(bp))
  5894. /* size = the status block + ramrod buffers */
  5895. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  5896. sizeof(struct host_hc_status_block_e2));
  5897. else
  5898. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb, &bp->cnic_sb_mapping,
  5899. sizeof(struct host_hc_status_block_e1x));
  5900. /* allocate searcher T2 table */
  5901. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  5902. #endif
  5903. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  5904. sizeof(struct host_sp_status_block));
  5905. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  5906. sizeof(struct bnx2x_slowpath));
  5907. #ifdef BCM_CNIC
  5908. /* write address to which L5 should insert its values */
  5909. bp->cnic_eth_dev.addr_drv_info_to_mcp = &bp->slowpath->drv_info_to_mcp;
  5910. #endif
  5911. /* Allocated memory for FW statistics */
  5912. if (bnx2x_alloc_fw_stats_mem(bp))
  5913. goto alloc_mem_err;
  5914. bp->context.size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  5915. BNX2X_PCI_ALLOC(bp->context.vcxt, &bp->context.cxt_mapping,
  5916. bp->context.size);
  5917. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  5918. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  5919. goto alloc_mem_err;
  5920. /* Slow path ring */
  5921. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  5922. /* EQ */
  5923. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  5924. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  5925. /* fastpath */
  5926. /* need to be done at the end, since it's self adjusting to amount
  5927. * of memory available for RSS queues
  5928. */
  5929. if (bnx2x_alloc_fp_mem(bp))
  5930. goto alloc_mem_err;
  5931. return 0;
  5932. alloc_mem_err:
  5933. bnx2x_free_mem(bp);
  5934. BNX2X_ERR("Can't allocate memory\n");
  5935. return -ENOMEM;
  5936. }
  5937. /*
  5938. * Init service functions
  5939. */
  5940. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  5941. struct bnx2x_vlan_mac_obj *obj, bool set,
  5942. int mac_type, unsigned long *ramrod_flags)
  5943. {
  5944. int rc;
  5945. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  5946. memset(&ramrod_param, 0, sizeof(ramrod_param));
  5947. /* Fill general parameters */
  5948. ramrod_param.vlan_mac_obj = obj;
  5949. ramrod_param.ramrod_flags = *ramrod_flags;
  5950. /* Fill a user request section if needed */
  5951. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  5952. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  5953. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  5954. /* Set the command: ADD or DEL */
  5955. if (set)
  5956. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  5957. else
  5958. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  5959. }
  5960. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  5961. if (rc < 0)
  5962. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  5963. return rc;
  5964. }
  5965. int bnx2x_del_all_macs(struct bnx2x *bp,
  5966. struct bnx2x_vlan_mac_obj *mac_obj,
  5967. int mac_type, bool wait_for_comp)
  5968. {
  5969. int rc;
  5970. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  5971. /* Wait for completion of requested */
  5972. if (wait_for_comp)
  5973. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5974. /* Set the mac type of addresses we want to clear */
  5975. __set_bit(mac_type, &vlan_mac_flags);
  5976. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  5977. if (rc < 0)
  5978. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  5979. return rc;
  5980. }
  5981. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  5982. {
  5983. unsigned long ramrod_flags = 0;
  5984. #ifdef BCM_CNIC
  5985. if (is_zero_ether_addr(bp->dev->dev_addr) && IS_MF_STORAGE_SD(bp)) {
  5986. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  5987. "Ignoring Zero MAC for STORAGE SD mode\n");
  5988. return 0;
  5989. }
  5990. #endif
  5991. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  5992. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  5993. /* Eth MAC is set on RSS leading client (fp[0]) */
  5994. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->fp->mac_obj, set,
  5995. BNX2X_ETH_MAC, &ramrod_flags);
  5996. }
  5997. int bnx2x_setup_leading(struct bnx2x *bp)
  5998. {
  5999. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6000. }
  6001. /**
  6002. * bnx2x_set_int_mode - configure interrupt mode
  6003. *
  6004. * @bp: driver handle
  6005. *
  6006. * In case of MSI-X it will also try to enable MSI-X.
  6007. */
  6008. static void __devinit bnx2x_set_int_mode(struct bnx2x *bp)
  6009. {
  6010. switch (int_mode) {
  6011. case INT_MODE_MSI:
  6012. bnx2x_enable_msi(bp);
  6013. /* falling through... */
  6014. case INT_MODE_INTx:
  6015. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6016. BNX2X_DEV_INFO("set number of queues to 1\n");
  6017. break;
  6018. default:
  6019. /* Set number of queues according to bp->multi_mode value */
  6020. bnx2x_set_num_queues(bp);
  6021. BNX2X_DEV_INFO("set number of queues to %d\n", bp->num_queues);
  6022. /* if we can't use MSI-X we only need one fp,
  6023. * so try to enable MSI-X with the requested number of fp's
  6024. * and fallback to MSI or legacy INTx with one fp
  6025. */
  6026. if (bnx2x_enable_msix(bp)) {
  6027. /* failed to enable MSI-X */
  6028. BNX2X_DEV_INFO("Failed to enable MSI-X (%d), set number of queues to %d\n",
  6029. bp->num_queues, 1 + NON_ETH_CONTEXT_USE);
  6030. bp->num_queues = 1 + NON_ETH_CONTEXT_USE;
  6031. /* Try to enable MSI */
  6032. if (!(bp->flags & DISABLE_MSI_FLAG))
  6033. bnx2x_enable_msi(bp);
  6034. }
  6035. break;
  6036. }
  6037. }
  6038. /* must be called prioir to any HW initializations */
  6039. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6040. {
  6041. return L2_ILT_LINES(bp);
  6042. }
  6043. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6044. {
  6045. struct ilt_client_info *ilt_client;
  6046. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6047. u16 line = 0;
  6048. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6049. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6050. /* CDU */
  6051. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6052. ilt_client->client_num = ILT_CLIENT_CDU;
  6053. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6054. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6055. ilt_client->start = line;
  6056. line += bnx2x_cid_ilt_lines(bp);
  6057. #ifdef BCM_CNIC
  6058. line += CNIC_ILT_LINES;
  6059. #endif
  6060. ilt_client->end = line - 1;
  6061. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6062. ilt_client->start,
  6063. ilt_client->end,
  6064. ilt_client->page_size,
  6065. ilt_client->flags,
  6066. ilog2(ilt_client->page_size >> 12));
  6067. /* QM */
  6068. if (QM_INIT(bp->qm_cid_count)) {
  6069. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6070. ilt_client->client_num = ILT_CLIENT_QM;
  6071. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6072. ilt_client->flags = 0;
  6073. ilt_client->start = line;
  6074. /* 4 bytes for each cid */
  6075. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6076. QM_ILT_PAGE_SZ);
  6077. ilt_client->end = line - 1;
  6078. DP(NETIF_MSG_IFUP,
  6079. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6080. ilt_client->start,
  6081. ilt_client->end,
  6082. ilt_client->page_size,
  6083. ilt_client->flags,
  6084. ilog2(ilt_client->page_size >> 12));
  6085. }
  6086. /* SRC */
  6087. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6088. #ifdef BCM_CNIC
  6089. ilt_client->client_num = ILT_CLIENT_SRC;
  6090. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6091. ilt_client->flags = 0;
  6092. ilt_client->start = line;
  6093. line += SRC_ILT_LINES;
  6094. ilt_client->end = line - 1;
  6095. DP(NETIF_MSG_IFUP,
  6096. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6097. ilt_client->start,
  6098. ilt_client->end,
  6099. ilt_client->page_size,
  6100. ilt_client->flags,
  6101. ilog2(ilt_client->page_size >> 12));
  6102. #else
  6103. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6104. #endif
  6105. /* TM */
  6106. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6107. #ifdef BCM_CNIC
  6108. ilt_client->client_num = ILT_CLIENT_TM;
  6109. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6110. ilt_client->flags = 0;
  6111. ilt_client->start = line;
  6112. line += TM_ILT_LINES;
  6113. ilt_client->end = line - 1;
  6114. DP(NETIF_MSG_IFUP,
  6115. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6116. ilt_client->start,
  6117. ilt_client->end,
  6118. ilt_client->page_size,
  6119. ilt_client->flags,
  6120. ilog2(ilt_client->page_size >> 12));
  6121. #else
  6122. ilt_client->flags = (ILT_CLIENT_SKIP_INIT | ILT_CLIENT_SKIP_MEM);
  6123. #endif
  6124. BUG_ON(line > ILT_MAX_LINES);
  6125. }
  6126. /**
  6127. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6128. *
  6129. * @bp: driver handle
  6130. * @fp: pointer to fastpath
  6131. * @init_params: pointer to parameters structure
  6132. *
  6133. * parameters configured:
  6134. * - HC configuration
  6135. * - Queue's CDU context
  6136. */
  6137. static inline void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6138. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6139. {
  6140. u8 cos;
  6141. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6142. if (!IS_FCOE_FP(fp)) {
  6143. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6144. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6145. /* If HC is supporterd, enable host coalescing in the transition
  6146. * to INIT state.
  6147. */
  6148. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6149. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6150. /* HC rate */
  6151. init_params->rx.hc_rate = bp->rx_ticks ?
  6152. (1000000 / bp->rx_ticks) : 0;
  6153. init_params->tx.hc_rate = bp->tx_ticks ?
  6154. (1000000 / bp->tx_ticks) : 0;
  6155. /* FW SB ID */
  6156. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6157. fp->fw_sb_id;
  6158. /*
  6159. * CQ index among the SB indices: FCoE clients uses the default
  6160. * SB, therefore it's different.
  6161. */
  6162. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6163. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6164. }
  6165. /* set maximum number of COSs supported by this queue */
  6166. init_params->max_cos = fp->max_cos;
  6167. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6168. fp->index, init_params->max_cos);
  6169. /* set the context pointers queue object */
  6170. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++)
  6171. init_params->cxts[cos] =
  6172. &bp->context.vcxt[fp->txdata[cos].cid].eth;
  6173. }
  6174. int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6175. struct bnx2x_queue_state_params *q_params,
  6176. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6177. int tx_index, bool leading)
  6178. {
  6179. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6180. /* Set the command */
  6181. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6182. /* Set tx-only QUEUE flags: don't zero statistics */
  6183. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6184. /* choose the index of the cid to send the slow path on */
  6185. tx_only_params->cid_index = tx_index;
  6186. /* Set general TX_ONLY_SETUP parameters */
  6187. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6188. /* Set Tx TX_ONLY_SETUP parameters */
  6189. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6190. DP(NETIF_MSG_IFUP,
  6191. "preparing to send tx-only ramrod for connection: cos %d, primary cid %d, cid %d, client id %d, sp-client id %d, flags %lx\n",
  6192. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6193. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6194. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6195. /* send the ramrod */
  6196. return bnx2x_queue_state_change(bp, q_params);
  6197. }
  6198. /**
  6199. * bnx2x_setup_queue - setup queue
  6200. *
  6201. * @bp: driver handle
  6202. * @fp: pointer to fastpath
  6203. * @leading: is leading
  6204. *
  6205. * This function performs 2 steps in a Queue state machine
  6206. * actually: 1) RESET->INIT 2) INIT->SETUP
  6207. */
  6208. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6209. bool leading)
  6210. {
  6211. struct bnx2x_queue_state_params q_params = {NULL};
  6212. struct bnx2x_queue_setup_params *setup_params =
  6213. &q_params.params.setup;
  6214. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6215. &q_params.params.tx_only;
  6216. int rc;
  6217. u8 tx_index;
  6218. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6219. /* reset IGU state skip FCoE L2 queue */
  6220. if (!IS_FCOE_FP(fp))
  6221. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6222. IGU_INT_ENABLE, 0);
  6223. q_params.q_obj = &fp->q_obj;
  6224. /* We want to wait for completion in this context */
  6225. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6226. /* Prepare the INIT parameters */
  6227. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6228. /* Set the command */
  6229. q_params.cmd = BNX2X_Q_CMD_INIT;
  6230. /* Change the state to INIT */
  6231. rc = bnx2x_queue_state_change(bp, &q_params);
  6232. if (rc) {
  6233. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6234. return rc;
  6235. }
  6236. DP(NETIF_MSG_IFUP, "init complete\n");
  6237. /* Now move the Queue to the SETUP state... */
  6238. memset(setup_params, 0, sizeof(*setup_params));
  6239. /* Set QUEUE flags */
  6240. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6241. /* Set general SETUP parameters */
  6242. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6243. FIRST_TX_COS_INDEX);
  6244. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6245. &setup_params->rxq_params);
  6246. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6247. FIRST_TX_COS_INDEX);
  6248. /* Set the command */
  6249. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6250. /* Change the state to SETUP */
  6251. rc = bnx2x_queue_state_change(bp, &q_params);
  6252. if (rc) {
  6253. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6254. return rc;
  6255. }
  6256. /* loop through the relevant tx-only indices */
  6257. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6258. tx_index < fp->max_cos;
  6259. tx_index++) {
  6260. /* prepare and send tx-only ramrod*/
  6261. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6262. tx_only_params, tx_index, leading);
  6263. if (rc) {
  6264. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6265. fp->index, tx_index);
  6266. return rc;
  6267. }
  6268. }
  6269. return rc;
  6270. }
  6271. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6272. {
  6273. struct bnx2x_fastpath *fp = &bp->fp[index];
  6274. struct bnx2x_fp_txdata *txdata;
  6275. struct bnx2x_queue_state_params q_params = {NULL};
  6276. int rc, tx_index;
  6277. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6278. q_params.q_obj = &fp->q_obj;
  6279. /* We want to wait for completion in this context */
  6280. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6281. /* close tx-only connections */
  6282. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6283. tx_index < fp->max_cos;
  6284. tx_index++){
  6285. /* ascertain this is a normal queue*/
  6286. txdata = &fp->txdata[tx_index];
  6287. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6288. txdata->txq_index);
  6289. /* send halt terminate on tx-only connection */
  6290. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6291. memset(&q_params.params.terminate, 0,
  6292. sizeof(q_params.params.terminate));
  6293. q_params.params.terminate.cid_index = tx_index;
  6294. rc = bnx2x_queue_state_change(bp, &q_params);
  6295. if (rc)
  6296. return rc;
  6297. /* send halt terminate on tx-only connection */
  6298. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6299. memset(&q_params.params.cfc_del, 0,
  6300. sizeof(q_params.params.cfc_del));
  6301. q_params.params.cfc_del.cid_index = tx_index;
  6302. rc = bnx2x_queue_state_change(bp, &q_params);
  6303. if (rc)
  6304. return rc;
  6305. }
  6306. /* Stop the primary connection: */
  6307. /* ...halt the connection */
  6308. q_params.cmd = BNX2X_Q_CMD_HALT;
  6309. rc = bnx2x_queue_state_change(bp, &q_params);
  6310. if (rc)
  6311. return rc;
  6312. /* ...terminate the connection */
  6313. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6314. memset(&q_params.params.terminate, 0,
  6315. sizeof(q_params.params.terminate));
  6316. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6317. rc = bnx2x_queue_state_change(bp, &q_params);
  6318. if (rc)
  6319. return rc;
  6320. /* ...delete cfc entry */
  6321. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6322. memset(&q_params.params.cfc_del, 0,
  6323. sizeof(q_params.params.cfc_del));
  6324. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6325. return bnx2x_queue_state_change(bp, &q_params);
  6326. }
  6327. static void bnx2x_reset_func(struct bnx2x *bp)
  6328. {
  6329. int port = BP_PORT(bp);
  6330. int func = BP_FUNC(bp);
  6331. int i;
  6332. /* Disable the function in the FW */
  6333. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6334. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6335. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6336. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6337. /* FP SBs */
  6338. for_each_eth_queue(bp, i) {
  6339. struct bnx2x_fastpath *fp = &bp->fp[i];
  6340. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6341. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6342. SB_DISABLED);
  6343. }
  6344. #ifdef BCM_CNIC
  6345. /* CNIC SB */
  6346. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6347. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(bnx2x_cnic_fw_sb_id(bp)),
  6348. SB_DISABLED);
  6349. #endif
  6350. /* SP SB */
  6351. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6352. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6353. SB_DISABLED);
  6354. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6355. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6356. 0);
  6357. /* Configure IGU */
  6358. if (bp->common.int_block == INT_BLOCK_HC) {
  6359. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6360. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6361. } else {
  6362. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6363. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6364. }
  6365. #ifdef BCM_CNIC
  6366. /* Disable Timer scan */
  6367. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6368. /*
  6369. * Wait for at least 10ms and up to 2 second for the timers scan to
  6370. * complete
  6371. */
  6372. for (i = 0; i < 200; i++) {
  6373. msleep(10);
  6374. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6375. break;
  6376. }
  6377. #endif
  6378. /* Clear ILT */
  6379. bnx2x_clear_func_ilt(bp, func);
  6380. /* Timers workaround bug for E2: if this is vnic-3,
  6381. * we need to set the entire ilt range for this timers.
  6382. */
  6383. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6384. struct ilt_client_info ilt_cli;
  6385. /* use dummy TM client */
  6386. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6387. ilt_cli.start = 0;
  6388. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6389. ilt_cli.client_num = ILT_CLIENT_TM;
  6390. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6391. }
  6392. /* this assumes that reset_port() called before reset_func()*/
  6393. if (!CHIP_IS_E1x(bp))
  6394. bnx2x_pf_disable(bp);
  6395. bp->dmae_ready = 0;
  6396. }
  6397. static void bnx2x_reset_port(struct bnx2x *bp)
  6398. {
  6399. int port = BP_PORT(bp);
  6400. u32 val;
  6401. /* Reset physical Link */
  6402. bnx2x__link_reset(bp);
  6403. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6404. /* Do not rcv packets to BRB */
  6405. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6406. /* Do not direct rcv packets that are not for MCP to the BRB */
  6407. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  6408. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  6409. /* Configure AEU */
  6410. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  6411. msleep(100);
  6412. /* Check for BRB port occupancy */
  6413. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  6414. if (val)
  6415. DP(NETIF_MSG_IFDOWN,
  6416. "BRB1 is not empty %d blocks are occupied\n", val);
  6417. /* TODO: Close Doorbell port? */
  6418. }
  6419. static inline int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  6420. {
  6421. struct bnx2x_func_state_params func_params = {NULL};
  6422. /* Prepare parameters for function state transitions */
  6423. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6424. func_params.f_obj = &bp->func_obj;
  6425. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  6426. func_params.params.hw_init.load_phase = load_code;
  6427. return bnx2x_func_state_change(bp, &func_params);
  6428. }
  6429. static inline int bnx2x_func_stop(struct bnx2x *bp)
  6430. {
  6431. struct bnx2x_func_state_params func_params = {NULL};
  6432. int rc;
  6433. /* Prepare parameters for function state transitions */
  6434. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6435. func_params.f_obj = &bp->func_obj;
  6436. func_params.cmd = BNX2X_F_CMD_STOP;
  6437. /*
  6438. * Try to stop the function the 'good way'. If fails (in case
  6439. * of a parity error during bnx2x_chip_cleanup()) and we are
  6440. * not in a debug mode, perform a state transaction in order to
  6441. * enable further HW_RESET transaction.
  6442. */
  6443. rc = bnx2x_func_state_change(bp, &func_params);
  6444. if (rc) {
  6445. #ifdef BNX2X_STOP_ON_ERROR
  6446. return rc;
  6447. #else
  6448. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  6449. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  6450. return bnx2x_func_state_change(bp, &func_params);
  6451. #endif
  6452. }
  6453. return 0;
  6454. }
  6455. /**
  6456. * bnx2x_send_unload_req - request unload mode from the MCP.
  6457. *
  6458. * @bp: driver handle
  6459. * @unload_mode: requested function's unload mode
  6460. *
  6461. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  6462. */
  6463. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  6464. {
  6465. u32 reset_code = 0;
  6466. int port = BP_PORT(bp);
  6467. /* Select the UNLOAD request mode */
  6468. if (unload_mode == UNLOAD_NORMAL)
  6469. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6470. else if (bp->flags & NO_WOL_FLAG)
  6471. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  6472. else if (bp->wol) {
  6473. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  6474. u8 *mac_addr = bp->dev->dev_addr;
  6475. u32 val;
  6476. u16 pmc;
  6477. /* The mac address is written to entries 1-4 to
  6478. * preserve entry 0 which is used by the PMF
  6479. */
  6480. u8 entry = (BP_VN(bp) + 1)*8;
  6481. val = (mac_addr[0] << 8) | mac_addr[1];
  6482. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  6483. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  6484. (mac_addr[4] << 8) | mac_addr[5];
  6485. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  6486. /* Enable the PME and clear the status */
  6487. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  6488. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  6489. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  6490. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  6491. } else
  6492. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  6493. /* Send the request to the MCP */
  6494. if (!BP_NOMCP(bp))
  6495. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  6496. else {
  6497. int path = BP_PATH(bp);
  6498. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  6499. path, load_count[path][0], load_count[path][1],
  6500. load_count[path][2]);
  6501. load_count[path][0]--;
  6502. load_count[path][1 + port]--;
  6503. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  6504. path, load_count[path][0], load_count[path][1],
  6505. load_count[path][2]);
  6506. if (load_count[path][0] == 0)
  6507. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  6508. else if (load_count[path][1 + port] == 0)
  6509. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  6510. else
  6511. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  6512. }
  6513. return reset_code;
  6514. }
  6515. /**
  6516. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  6517. *
  6518. * @bp: driver handle
  6519. */
  6520. void bnx2x_send_unload_done(struct bnx2x *bp)
  6521. {
  6522. /* Report UNLOAD_DONE to MCP */
  6523. if (!BP_NOMCP(bp))
  6524. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  6525. }
  6526. static inline int bnx2x_func_wait_started(struct bnx2x *bp)
  6527. {
  6528. int tout = 50;
  6529. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  6530. if (!bp->port.pmf)
  6531. return 0;
  6532. /*
  6533. * (assumption: No Attention from MCP at this stage)
  6534. * PMF probably in the middle of TXdisable/enable transaction
  6535. * 1. Sync IRS for default SB
  6536. * 2. Sync SP queue - this guarantes us that attention handling started
  6537. * 3. Wait, that TXdisable/enable transaction completes
  6538. *
  6539. * 1+2 guranty that if DCBx attention was scheduled it already changed
  6540. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  6541. * received complettion for the transaction the state is TX_STOPPED.
  6542. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  6543. * transaction.
  6544. */
  6545. /* make sure default SB ISR is done */
  6546. if (msix)
  6547. synchronize_irq(bp->msix_table[0].vector);
  6548. else
  6549. synchronize_irq(bp->pdev->irq);
  6550. flush_workqueue(bnx2x_wq);
  6551. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6552. BNX2X_F_STATE_STARTED && tout--)
  6553. msleep(20);
  6554. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  6555. BNX2X_F_STATE_STARTED) {
  6556. #ifdef BNX2X_STOP_ON_ERROR
  6557. BNX2X_ERR("Wrong function state\n");
  6558. return -EBUSY;
  6559. #else
  6560. /*
  6561. * Failed to complete the transaction in a "good way"
  6562. * Force both transactions with CLR bit
  6563. */
  6564. struct bnx2x_func_state_params func_params = {NULL};
  6565. DP(NETIF_MSG_IFDOWN,
  6566. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  6567. func_params.f_obj = &bp->func_obj;
  6568. __set_bit(RAMROD_DRV_CLR_ONLY,
  6569. &func_params.ramrod_flags);
  6570. /* STARTED-->TX_ST0PPED */
  6571. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  6572. bnx2x_func_state_change(bp, &func_params);
  6573. /* TX_ST0PPED-->STARTED */
  6574. func_params.cmd = BNX2X_F_CMD_TX_START;
  6575. return bnx2x_func_state_change(bp, &func_params);
  6576. #endif
  6577. }
  6578. return 0;
  6579. }
  6580. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode)
  6581. {
  6582. int port = BP_PORT(bp);
  6583. int i, rc = 0;
  6584. u8 cos;
  6585. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  6586. u32 reset_code;
  6587. /* Wait until tx fastpath tasks complete */
  6588. for_each_tx_queue(bp, i) {
  6589. struct bnx2x_fastpath *fp = &bp->fp[i];
  6590. for_each_cos_in_tx_queue(fp, cos)
  6591. rc = bnx2x_clean_tx_queue(bp, &fp->txdata[cos]);
  6592. #ifdef BNX2X_STOP_ON_ERROR
  6593. if (rc)
  6594. return;
  6595. #endif
  6596. }
  6597. /* Give HW time to discard old tx messages */
  6598. usleep_range(1000, 1000);
  6599. /* Clean all ETH MACs */
  6600. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_ETH_MAC, false);
  6601. if (rc < 0)
  6602. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  6603. /* Clean up UC list */
  6604. rc = bnx2x_del_all_macs(bp, &bp->fp[0].mac_obj, BNX2X_UC_LIST_MAC,
  6605. true);
  6606. if (rc < 0)
  6607. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  6608. rc);
  6609. /* Disable LLH */
  6610. if (!CHIP_IS_E1(bp))
  6611. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  6612. /* Set "drop all" (stop Rx).
  6613. * We need to take a netif_addr_lock() here in order to prevent
  6614. * a race between the completion code and this code.
  6615. */
  6616. netif_addr_lock_bh(bp->dev);
  6617. /* Schedule the rx_mode command */
  6618. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  6619. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  6620. else
  6621. bnx2x_set_storm_rx_mode(bp);
  6622. /* Cleanup multicast configuration */
  6623. rparam.mcast_obj = &bp->mcast_obj;
  6624. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  6625. if (rc < 0)
  6626. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  6627. netif_addr_unlock_bh(bp->dev);
  6628. /*
  6629. * Send the UNLOAD_REQUEST to the MCP. This will return if
  6630. * this function should perform FUNC, PORT or COMMON HW
  6631. * reset.
  6632. */
  6633. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  6634. /*
  6635. * (assumption: No Attention from MCP at this stage)
  6636. * PMF probably in the middle of TXdisable/enable transaction
  6637. */
  6638. rc = bnx2x_func_wait_started(bp);
  6639. if (rc) {
  6640. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  6641. #ifdef BNX2X_STOP_ON_ERROR
  6642. return;
  6643. #endif
  6644. }
  6645. /* Close multi and leading connections
  6646. * Completions for ramrods are collected in a synchronous way
  6647. */
  6648. for_each_queue(bp, i)
  6649. if (bnx2x_stop_queue(bp, i))
  6650. #ifdef BNX2X_STOP_ON_ERROR
  6651. return;
  6652. #else
  6653. goto unload_error;
  6654. #endif
  6655. /* If SP settings didn't get completed so far - something
  6656. * very wrong has happen.
  6657. */
  6658. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  6659. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  6660. #ifndef BNX2X_STOP_ON_ERROR
  6661. unload_error:
  6662. #endif
  6663. rc = bnx2x_func_stop(bp);
  6664. if (rc) {
  6665. BNX2X_ERR("Function stop failed!\n");
  6666. #ifdef BNX2X_STOP_ON_ERROR
  6667. return;
  6668. #endif
  6669. }
  6670. /* Disable HW interrupts, NAPI */
  6671. bnx2x_netif_stop(bp, 1);
  6672. /* Release IRQs */
  6673. bnx2x_free_irq(bp);
  6674. /* Reset the chip */
  6675. rc = bnx2x_reset_hw(bp, reset_code);
  6676. if (rc)
  6677. BNX2X_ERR("HW_RESET failed\n");
  6678. /* Report UNLOAD_DONE to MCP */
  6679. bnx2x_send_unload_done(bp);
  6680. }
  6681. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  6682. {
  6683. u32 val;
  6684. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  6685. if (CHIP_IS_E1(bp)) {
  6686. int port = BP_PORT(bp);
  6687. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  6688. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  6689. val = REG_RD(bp, addr);
  6690. val &= ~(0x300);
  6691. REG_WR(bp, addr, val);
  6692. } else {
  6693. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  6694. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  6695. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  6696. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  6697. }
  6698. }
  6699. /* Close gates #2, #3 and #4: */
  6700. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  6701. {
  6702. u32 val;
  6703. /* Gates #2 and #4a are closed/opened for "not E1" only */
  6704. if (!CHIP_IS_E1(bp)) {
  6705. /* #4 */
  6706. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  6707. /* #2 */
  6708. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  6709. }
  6710. /* #3 */
  6711. if (CHIP_IS_E1x(bp)) {
  6712. /* Prevent interrupts from HC on both ports */
  6713. val = REG_RD(bp, HC_REG_CONFIG_1);
  6714. REG_WR(bp, HC_REG_CONFIG_1,
  6715. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  6716. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  6717. val = REG_RD(bp, HC_REG_CONFIG_0);
  6718. REG_WR(bp, HC_REG_CONFIG_0,
  6719. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  6720. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  6721. } else {
  6722. /* Prevent incomming interrupts in IGU */
  6723. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  6724. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  6725. (!close) ?
  6726. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  6727. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  6728. }
  6729. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  6730. close ? "closing" : "opening");
  6731. mmiowb();
  6732. }
  6733. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  6734. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  6735. {
  6736. /* Do some magic... */
  6737. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6738. *magic_val = val & SHARED_MF_CLP_MAGIC;
  6739. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  6740. }
  6741. /**
  6742. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  6743. *
  6744. * @bp: driver handle
  6745. * @magic_val: old value of the `magic' bit.
  6746. */
  6747. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  6748. {
  6749. /* Restore the `magic' bit value... */
  6750. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  6751. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  6752. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  6753. }
  6754. /**
  6755. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  6756. *
  6757. * @bp: driver handle
  6758. * @magic_val: old value of 'magic' bit.
  6759. *
  6760. * Takes care of CLP configurations.
  6761. */
  6762. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  6763. {
  6764. u32 shmem;
  6765. u32 validity_offset;
  6766. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  6767. /* Set `magic' bit in order to save MF config */
  6768. if (!CHIP_IS_E1(bp))
  6769. bnx2x_clp_reset_prep(bp, magic_val);
  6770. /* Get shmem offset */
  6771. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6772. validity_offset = offsetof(struct shmem_region, validity_map[0]);
  6773. /* Clear validity map flags */
  6774. if (shmem > 0)
  6775. REG_WR(bp, shmem + validity_offset, 0);
  6776. }
  6777. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  6778. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  6779. /**
  6780. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  6781. *
  6782. * @bp: driver handle
  6783. */
  6784. static inline void bnx2x_mcp_wait_one(struct bnx2x *bp)
  6785. {
  6786. /* special handling for emulation and FPGA,
  6787. wait 10 times longer */
  6788. if (CHIP_REV_IS_SLOW(bp))
  6789. msleep(MCP_ONE_TIMEOUT*10);
  6790. else
  6791. msleep(MCP_ONE_TIMEOUT);
  6792. }
  6793. /*
  6794. * initializes bp->common.shmem_base and waits for validity signature to appear
  6795. */
  6796. static int bnx2x_init_shmem(struct bnx2x *bp)
  6797. {
  6798. int cnt = 0;
  6799. u32 val = 0;
  6800. do {
  6801. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  6802. if (bp->common.shmem_base) {
  6803. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  6804. if (val & SHR_MEM_VALIDITY_MB)
  6805. return 0;
  6806. }
  6807. bnx2x_mcp_wait_one(bp);
  6808. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  6809. BNX2X_ERR("BAD MCP validity signature\n");
  6810. return -ENODEV;
  6811. }
  6812. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  6813. {
  6814. int rc = bnx2x_init_shmem(bp);
  6815. /* Restore the `magic' bit value */
  6816. if (!CHIP_IS_E1(bp))
  6817. bnx2x_clp_reset_done(bp, magic_val);
  6818. return rc;
  6819. }
  6820. static void bnx2x_pxp_prep(struct bnx2x *bp)
  6821. {
  6822. if (!CHIP_IS_E1(bp)) {
  6823. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  6824. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  6825. mmiowb();
  6826. }
  6827. }
  6828. /*
  6829. * Reset the whole chip except for:
  6830. * - PCIE core
  6831. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  6832. * one reset bit)
  6833. * - IGU
  6834. * - MISC (including AEU)
  6835. * - GRC
  6836. * - RBCN, RBCP
  6837. */
  6838. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  6839. {
  6840. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  6841. u32 global_bits2, stay_reset2;
  6842. /*
  6843. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  6844. * (per chip) blocks.
  6845. */
  6846. global_bits2 =
  6847. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  6848. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  6849. /* Don't reset the following blocks */
  6850. not_reset_mask1 =
  6851. MISC_REGISTERS_RESET_REG_1_RST_HC |
  6852. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  6853. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  6854. not_reset_mask2 =
  6855. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  6856. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  6857. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  6858. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  6859. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  6860. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  6861. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  6862. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  6863. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  6864. MISC_REGISTERS_RESET_REG_2_PGLC;
  6865. /*
  6866. * Keep the following blocks in reset:
  6867. * - all xxMACs are handled by the bnx2x_link code.
  6868. */
  6869. stay_reset2 =
  6870. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  6871. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  6872. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  6873. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  6874. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  6875. MISC_REGISTERS_RESET_REG_2_UMAC1 |
  6876. MISC_REGISTERS_RESET_REG_2_XMAC |
  6877. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  6878. /* Full reset masks according to the chip */
  6879. reset_mask1 = 0xffffffff;
  6880. if (CHIP_IS_E1(bp))
  6881. reset_mask2 = 0xffff;
  6882. else if (CHIP_IS_E1H(bp))
  6883. reset_mask2 = 0x1ffff;
  6884. else if (CHIP_IS_E2(bp))
  6885. reset_mask2 = 0xfffff;
  6886. else /* CHIP_IS_E3 */
  6887. reset_mask2 = 0x3ffffff;
  6888. /* Don't reset global blocks unless we need to */
  6889. if (!global)
  6890. reset_mask2 &= ~global_bits2;
  6891. /*
  6892. * In case of attention in the QM, we need to reset PXP
  6893. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  6894. * because otherwise QM reset would release 'close the gates' shortly
  6895. * before resetting the PXP, then the PSWRQ would send a write
  6896. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  6897. * read the payload data from PSWWR, but PSWWR would not
  6898. * respond. The write queue in PGLUE would stuck, dmae commands
  6899. * would not return. Therefore it's important to reset the second
  6900. * reset register (containing the
  6901. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  6902. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  6903. * bit).
  6904. */
  6905. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  6906. reset_mask2 & (~not_reset_mask2));
  6907. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  6908. reset_mask1 & (~not_reset_mask1));
  6909. barrier();
  6910. mmiowb();
  6911. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  6912. reset_mask2 & (~stay_reset2));
  6913. barrier();
  6914. mmiowb();
  6915. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  6916. mmiowb();
  6917. }
  6918. /**
  6919. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  6920. * It should get cleared in no more than 1s.
  6921. *
  6922. * @bp: driver handle
  6923. *
  6924. * It should get cleared in no more than 1s. Returns 0 if
  6925. * pending writes bit gets cleared.
  6926. */
  6927. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  6928. {
  6929. u32 cnt = 1000;
  6930. u32 pend_bits = 0;
  6931. do {
  6932. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  6933. if (pend_bits == 0)
  6934. break;
  6935. usleep_range(1000, 1000);
  6936. } while (cnt-- > 0);
  6937. if (cnt <= 0) {
  6938. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  6939. pend_bits);
  6940. return -EBUSY;
  6941. }
  6942. return 0;
  6943. }
  6944. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  6945. {
  6946. int cnt = 1000;
  6947. u32 val = 0;
  6948. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  6949. /* Empty the Tetris buffer, wait for 1s */
  6950. do {
  6951. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  6952. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  6953. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  6954. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  6955. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  6956. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  6957. ((port_is_idle_0 & 0x1) == 0x1) &&
  6958. ((port_is_idle_1 & 0x1) == 0x1) &&
  6959. (pgl_exp_rom2 == 0xffffffff))
  6960. break;
  6961. usleep_range(1000, 1000);
  6962. } while (cnt-- > 0);
  6963. if (cnt <= 0) {
  6964. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  6965. BNX2X_ERR("sr_cnt=0x%08x, blk_cnt=0x%08x, port_is_idle_0=0x%08x, port_is_idle_1=0x%08x, pgl_exp_rom2=0x%08x\n",
  6966. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  6967. pgl_exp_rom2);
  6968. return -EAGAIN;
  6969. }
  6970. barrier();
  6971. /* Close gates #2, #3 and #4 */
  6972. bnx2x_set_234_gates(bp, true);
  6973. /* Poll for IGU VQs for 57712 and newer chips */
  6974. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  6975. return -EAGAIN;
  6976. /* TBD: Indicate that "process kill" is in progress to MCP */
  6977. /* Clear "unprepared" bit */
  6978. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  6979. barrier();
  6980. /* Make sure all is written to the chip before the reset */
  6981. mmiowb();
  6982. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  6983. * PSWHST, GRC and PSWRD Tetris buffer.
  6984. */
  6985. usleep_range(1000, 1000);
  6986. /* Prepare to chip reset: */
  6987. /* MCP */
  6988. if (global)
  6989. bnx2x_reset_mcp_prep(bp, &val);
  6990. /* PXP */
  6991. bnx2x_pxp_prep(bp);
  6992. barrier();
  6993. /* reset the chip */
  6994. bnx2x_process_kill_chip_reset(bp, global);
  6995. barrier();
  6996. /* Recover after reset: */
  6997. /* MCP */
  6998. if (global && bnx2x_reset_mcp_comp(bp, val))
  6999. return -EAGAIN;
  7000. /* TBD: Add resetting the NO_MCP mode DB here */
  7001. /* PXP */
  7002. bnx2x_pxp_prep(bp);
  7003. /* Open the gates #2, #3 and #4 */
  7004. bnx2x_set_234_gates(bp, false);
  7005. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7006. * reset state, re-enable attentions. */
  7007. return 0;
  7008. }
  7009. int bnx2x_leader_reset(struct bnx2x *bp)
  7010. {
  7011. int rc = 0;
  7012. bool global = bnx2x_reset_is_global(bp);
  7013. u32 load_code;
  7014. /* if not going to reset MCP - load "fake" driver to reset HW while
  7015. * driver is owner of the HW
  7016. */
  7017. if (!global && !BP_NOMCP(bp)) {
  7018. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ, 0);
  7019. if (!load_code) {
  7020. BNX2X_ERR("MCP response failure, aborting\n");
  7021. rc = -EAGAIN;
  7022. goto exit_leader_reset;
  7023. }
  7024. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7025. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7026. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7027. rc = -EAGAIN;
  7028. goto exit_leader_reset2;
  7029. }
  7030. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7031. if (!load_code) {
  7032. BNX2X_ERR("MCP response failure, aborting\n");
  7033. rc = -EAGAIN;
  7034. goto exit_leader_reset2;
  7035. }
  7036. }
  7037. /* Try to recover after the failure */
  7038. if (bnx2x_process_kill(bp, global)) {
  7039. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7040. BP_PATH(bp));
  7041. rc = -EAGAIN;
  7042. goto exit_leader_reset2;
  7043. }
  7044. /*
  7045. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7046. * state.
  7047. */
  7048. bnx2x_set_reset_done(bp);
  7049. if (global)
  7050. bnx2x_clear_reset_global(bp);
  7051. exit_leader_reset2:
  7052. /* unload "fake driver" if it was loaded */
  7053. if (!global && !BP_NOMCP(bp)) {
  7054. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7055. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7056. }
  7057. exit_leader_reset:
  7058. bp->is_leader = 0;
  7059. bnx2x_release_leader_lock(bp);
  7060. smp_mb();
  7061. return rc;
  7062. }
  7063. static inline void bnx2x_recovery_failed(struct bnx2x *bp)
  7064. {
  7065. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7066. /* Disconnect this device */
  7067. netif_device_detach(bp->dev);
  7068. /*
  7069. * Block ifup for all function on this engine until "process kill"
  7070. * or power cycle.
  7071. */
  7072. bnx2x_set_reset_in_progress(bp);
  7073. /* Shut down the power */
  7074. bnx2x_set_power_state(bp, PCI_D3hot);
  7075. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7076. smp_mb();
  7077. }
  7078. /*
  7079. * Assumption: runs under rtnl lock. This together with the fact
  7080. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7081. * will never be called when netif_running(bp->dev) is false.
  7082. */
  7083. static void bnx2x_parity_recover(struct bnx2x *bp)
  7084. {
  7085. bool global = false;
  7086. u32 error_recovered, error_unrecovered;
  7087. bool is_parity;
  7088. DP(NETIF_MSG_HW, "Handling parity\n");
  7089. while (1) {
  7090. switch (bp->recovery_state) {
  7091. case BNX2X_RECOVERY_INIT:
  7092. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7093. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7094. WARN_ON(!is_parity);
  7095. /* Try to get a LEADER_LOCK HW lock */
  7096. if (bnx2x_trylock_leader_lock(bp)) {
  7097. bnx2x_set_reset_in_progress(bp);
  7098. /*
  7099. * Check if there is a global attention and if
  7100. * there was a global attention, set the global
  7101. * reset bit.
  7102. */
  7103. if (global)
  7104. bnx2x_set_reset_global(bp);
  7105. bp->is_leader = 1;
  7106. }
  7107. /* Stop the driver */
  7108. /* If interface has been removed - break */
  7109. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY))
  7110. return;
  7111. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7112. /* Ensure "is_leader", MCP command sequence and
  7113. * "recovery_state" update values are seen on other
  7114. * CPUs.
  7115. */
  7116. smp_mb();
  7117. break;
  7118. case BNX2X_RECOVERY_WAIT:
  7119. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7120. if (bp->is_leader) {
  7121. int other_engine = BP_PATH(bp) ? 0 : 1;
  7122. bool other_load_status =
  7123. bnx2x_get_load_status(bp, other_engine);
  7124. bool load_status =
  7125. bnx2x_get_load_status(bp, BP_PATH(bp));
  7126. global = bnx2x_reset_is_global(bp);
  7127. /*
  7128. * In case of a parity in a global block, let
  7129. * the first leader that performs a
  7130. * leader_reset() reset the global blocks in
  7131. * order to clear global attentions. Otherwise
  7132. * the the gates will remain closed for that
  7133. * engine.
  7134. */
  7135. if (load_status ||
  7136. (global && other_load_status)) {
  7137. /* Wait until all other functions get
  7138. * down.
  7139. */
  7140. schedule_delayed_work(&bp->sp_rtnl_task,
  7141. HZ/10);
  7142. return;
  7143. } else {
  7144. /* If all other functions got down -
  7145. * try to bring the chip back to
  7146. * normal. In any case it's an exit
  7147. * point for a leader.
  7148. */
  7149. if (bnx2x_leader_reset(bp)) {
  7150. bnx2x_recovery_failed(bp);
  7151. return;
  7152. }
  7153. /* If we are here, means that the
  7154. * leader has succeeded and doesn't
  7155. * want to be a leader any more. Try
  7156. * to continue as a none-leader.
  7157. */
  7158. break;
  7159. }
  7160. } else { /* non-leader */
  7161. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7162. /* Try to get a LEADER_LOCK HW lock as
  7163. * long as a former leader may have
  7164. * been unloaded by the user or
  7165. * released a leadership by another
  7166. * reason.
  7167. */
  7168. if (bnx2x_trylock_leader_lock(bp)) {
  7169. /* I'm a leader now! Restart a
  7170. * switch case.
  7171. */
  7172. bp->is_leader = 1;
  7173. break;
  7174. }
  7175. schedule_delayed_work(&bp->sp_rtnl_task,
  7176. HZ/10);
  7177. return;
  7178. } else {
  7179. /*
  7180. * If there was a global attention, wait
  7181. * for it to be cleared.
  7182. */
  7183. if (bnx2x_reset_is_global(bp)) {
  7184. schedule_delayed_work(
  7185. &bp->sp_rtnl_task,
  7186. HZ/10);
  7187. return;
  7188. }
  7189. error_recovered =
  7190. bp->eth_stats.recoverable_error;
  7191. error_unrecovered =
  7192. bp->eth_stats.unrecoverable_error;
  7193. bp->recovery_state =
  7194. BNX2X_RECOVERY_NIC_LOADING;
  7195. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7196. error_unrecovered++;
  7197. netdev_err(bp->dev,
  7198. "Recovery failed. Power cycle needed\n");
  7199. /* Disconnect this device */
  7200. netif_device_detach(bp->dev);
  7201. /* Shut down the power */
  7202. bnx2x_set_power_state(
  7203. bp, PCI_D3hot);
  7204. smp_mb();
  7205. } else {
  7206. bp->recovery_state =
  7207. BNX2X_RECOVERY_DONE;
  7208. error_recovered++;
  7209. smp_mb();
  7210. }
  7211. bp->eth_stats.recoverable_error =
  7212. error_recovered;
  7213. bp->eth_stats.unrecoverable_error =
  7214. error_unrecovered;
  7215. return;
  7216. }
  7217. }
  7218. default:
  7219. return;
  7220. }
  7221. }
  7222. }
  7223. static int bnx2x_close(struct net_device *dev);
  7224. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7225. * scheduled on a general queue in order to prevent a dead lock.
  7226. */
  7227. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7228. {
  7229. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7230. rtnl_lock();
  7231. if (!netif_running(bp->dev))
  7232. goto sp_rtnl_exit;
  7233. /* if stop on error is defined no recovery flows should be executed */
  7234. #ifdef BNX2X_STOP_ON_ERROR
  7235. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7236. "you will need to reboot when done\n");
  7237. goto sp_rtnl_not_reset;
  7238. #endif
  7239. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7240. /*
  7241. * Clear all pending SP commands as we are going to reset the
  7242. * function anyway.
  7243. */
  7244. bp->sp_rtnl_state = 0;
  7245. smp_mb();
  7246. bnx2x_parity_recover(bp);
  7247. goto sp_rtnl_exit;
  7248. }
  7249. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7250. /*
  7251. * Clear all pending SP commands as we are going to reset the
  7252. * function anyway.
  7253. */
  7254. bp->sp_rtnl_state = 0;
  7255. smp_mb();
  7256. bnx2x_nic_unload(bp, UNLOAD_NORMAL);
  7257. bnx2x_nic_load(bp, LOAD_NORMAL);
  7258. goto sp_rtnl_exit;
  7259. }
  7260. #ifdef BNX2X_STOP_ON_ERROR
  7261. sp_rtnl_not_reset:
  7262. #endif
  7263. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7264. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7265. /*
  7266. * in case of fan failure we need to reset id if the "stop on error"
  7267. * debug flag is set, since we trying to prevent permanent overheating
  7268. * damage
  7269. */
  7270. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7271. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7272. netif_device_detach(bp->dev);
  7273. bnx2x_close(bp->dev);
  7274. }
  7275. sp_rtnl_exit:
  7276. rtnl_unlock();
  7277. }
  7278. /* end of nic load/unload */
  7279. static void bnx2x_period_task(struct work_struct *work)
  7280. {
  7281. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7282. if (!netif_running(bp->dev))
  7283. goto period_task_exit;
  7284. if (CHIP_REV_IS_SLOW(bp)) {
  7285. BNX2X_ERR("period task called on emulation, ignoring\n");
  7286. goto period_task_exit;
  7287. }
  7288. bnx2x_acquire_phy_lock(bp);
  7289. /*
  7290. * The barrier is needed to ensure the ordering between the writing to
  7291. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7292. * the reading here.
  7293. */
  7294. smp_mb();
  7295. if (bp->port.pmf) {
  7296. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7297. /* Re-queue task in 1 sec */
  7298. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7299. }
  7300. bnx2x_release_phy_lock(bp);
  7301. period_task_exit:
  7302. return;
  7303. }
  7304. /*
  7305. * Init service functions
  7306. */
  7307. static u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7308. {
  7309. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7310. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7311. return base + (BP_ABS_FUNC(bp)) * stride;
  7312. }
  7313. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7314. {
  7315. u32 reg = bnx2x_get_pretend_reg(bp);
  7316. /* Flush all outstanding writes */
  7317. mmiowb();
  7318. /* Pretend to be function 0 */
  7319. REG_WR(bp, reg, 0);
  7320. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7321. /* From now we are in the "like-E1" mode */
  7322. bnx2x_int_disable(bp);
  7323. /* Flush all outstanding writes */
  7324. mmiowb();
  7325. /* Restore the original function */
  7326. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7327. REG_RD(bp, reg);
  7328. }
  7329. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7330. {
  7331. if (CHIP_IS_E1(bp))
  7332. bnx2x_int_disable(bp);
  7333. else
  7334. bnx2x_undi_int_disable_e1h(bp);
  7335. }
  7336. static void __devinit bnx2x_undi_unload(struct bnx2x *bp)
  7337. {
  7338. u32 val;
  7339. /* possibly another driver is trying to reset the chip */
  7340. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  7341. /* check if doorbell queue is reset */
  7342. if (REG_RD(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET)
  7343. & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  7344. /*
  7345. * Check if it is the UNDI driver
  7346. * UNDI driver initializes CID offset for normal bell to 0x7
  7347. */
  7348. val = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  7349. if (val == 0x7) {
  7350. u32 reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7351. /* save our pf_num */
  7352. int orig_pf_num = bp->pf_num;
  7353. int port;
  7354. u32 swap_en, swap_val, value;
  7355. /* clear the UNDI indication */
  7356. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  7357. BNX2X_DEV_INFO("UNDI is active! reset device\n");
  7358. /* try unload UNDI on port 0 */
  7359. bp->pf_num = 0;
  7360. bp->fw_seq =
  7361. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7362. DRV_MSG_SEQ_NUMBER_MASK);
  7363. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7364. /* if UNDI is loaded on the other port */
  7365. if (reset_code != FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  7366. /* send "DONE" for previous unload */
  7367. bnx2x_fw_command(bp,
  7368. DRV_MSG_CODE_UNLOAD_DONE, 0);
  7369. /* unload UNDI on port 1 */
  7370. bp->pf_num = 1;
  7371. bp->fw_seq =
  7372. (SHMEM_RD(bp, func_mb[bp->pf_num].drv_mb_header) &
  7373. DRV_MSG_SEQ_NUMBER_MASK);
  7374. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7375. bnx2x_fw_command(bp, reset_code, 0);
  7376. }
  7377. bnx2x_undi_int_disable(bp);
  7378. port = BP_PORT(bp);
  7379. /* close input traffic and wait for it */
  7380. /* Do not rcv packets to BRB */
  7381. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
  7382. NIG_REG_LLH0_BRB1_DRV_MASK), 0x0);
  7383. /* Do not direct rcv packets that are not for MCP to
  7384. * the BRB */
  7385. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7386. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7387. /* clear AEU */
  7388. REG_WR(bp, (port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7389. MISC_REG_AEU_MASK_ATTN_FUNC_0), 0);
  7390. msleep(10);
  7391. /* save NIG port swap info */
  7392. swap_val = REG_RD(bp, NIG_REG_PORT_SWAP);
  7393. swap_en = REG_RD(bp, NIG_REG_STRAP_OVERRIDE);
  7394. /* reset device */
  7395. REG_WR(bp,
  7396. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7397. 0xd3ffffff);
  7398. value = 0x1400;
  7399. if (CHIP_IS_E3(bp)) {
  7400. value |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  7401. value |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  7402. }
  7403. REG_WR(bp,
  7404. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7405. value);
  7406. /* take the NIG out of reset and restore swap values */
  7407. REG_WR(bp,
  7408. GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  7409. MISC_REGISTERS_RESET_REG_1_RST_NIG);
  7410. REG_WR(bp, NIG_REG_PORT_SWAP, swap_val);
  7411. REG_WR(bp, NIG_REG_STRAP_OVERRIDE, swap_en);
  7412. /* send unload done to the MCP */
  7413. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7414. /* restore our func and fw_seq */
  7415. bp->pf_num = orig_pf_num;
  7416. }
  7417. }
  7418. /* now it's safe to release the lock */
  7419. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  7420. }
  7421. static void __devinit bnx2x_get_common_hwinfo(struct bnx2x *bp)
  7422. {
  7423. u32 val, val2, val3, val4, id, boot_mode;
  7424. u16 pmc;
  7425. /* Get the chip revision id and number. */
  7426. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  7427. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  7428. id = ((val & 0xffff) << 16);
  7429. val = REG_RD(bp, MISC_REG_CHIP_REV);
  7430. id |= ((val & 0xf) << 12);
  7431. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  7432. id |= ((val & 0xff) << 4);
  7433. val = REG_RD(bp, MISC_REG_BOND_ID);
  7434. id |= (val & 0xf);
  7435. bp->common.chip_id = id;
  7436. /* Set doorbell size */
  7437. bp->db_size = (1 << BNX2X_DB_SHIFT);
  7438. if (!CHIP_IS_E1x(bp)) {
  7439. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  7440. if ((val & 1) == 0)
  7441. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  7442. else
  7443. val = (val >> 1) & 1;
  7444. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  7445. "2_PORT_MODE");
  7446. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  7447. CHIP_2_PORT_MODE;
  7448. if (CHIP_MODE_IS_4_PORT(bp))
  7449. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  7450. else
  7451. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  7452. } else {
  7453. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  7454. bp->pfid = bp->pf_num; /* 0..7 */
  7455. }
  7456. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  7457. bp->link_params.chip_id = bp->common.chip_id;
  7458. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  7459. val = (REG_RD(bp, 0x2874) & 0x55);
  7460. if ((bp->common.chip_id & 0x1) ||
  7461. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  7462. bp->flags |= ONE_PORT_FLAG;
  7463. BNX2X_DEV_INFO("single port device\n");
  7464. }
  7465. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  7466. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  7467. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  7468. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  7469. bp->common.flash_size, bp->common.flash_size);
  7470. bnx2x_init_shmem(bp);
  7471. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  7472. MISC_REG_GENERIC_CR_1 :
  7473. MISC_REG_GENERIC_CR_0));
  7474. bp->link_params.shmem_base = bp->common.shmem_base;
  7475. bp->link_params.shmem2_base = bp->common.shmem2_base;
  7476. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  7477. bp->common.shmem_base, bp->common.shmem2_base);
  7478. if (!bp->common.shmem_base) {
  7479. BNX2X_DEV_INFO("MCP not active\n");
  7480. bp->flags |= NO_MCP_FLAG;
  7481. return;
  7482. }
  7483. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  7484. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  7485. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  7486. SHARED_HW_CFG_LED_MODE_MASK) >>
  7487. SHARED_HW_CFG_LED_MODE_SHIFT);
  7488. bp->link_params.feature_config_flags = 0;
  7489. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  7490. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  7491. bp->link_params.feature_config_flags |=
  7492. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7493. else
  7494. bp->link_params.feature_config_flags &=
  7495. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  7496. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  7497. bp->common.bc_ver = val;
  7498. BNX2X_DEV_INFO("bc_ver %X\n", val);
  7499. if (val < BNX2X_BC_VER) {
  7500. /* for now only warn
  7501. * later we might need to enforce this */
  7502. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  7503. BNX2X_BC_VER, val);
  7504. }
  7505. bp->link_params.feature_config_flags |=
  7506. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  7507. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  7508. bp->link_params.feature_config_flags |=
  7509. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  7510. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  7511. bp->link_params.feature_config_flags |=
  7512. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  7513. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  7514. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  7515. BC_SUPPORTS_PFC_STATS : 0;
  7516. boot_mode = SHMEM_RD(bp,
  7517. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  7518. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  7519. switch (boot_mode) {
  7520. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  7521. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  7522. break;
  7523. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  7524. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  7525. break;
  7526. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  7527. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  7528. break;
  7529. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  7530. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  7531. break;
  7532. }
  7533. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  7534. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  7535. BNX2X_DEV_INFO("%sWoL capable\n",
  7536. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  7537. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  7538. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  7539. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  7540. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  7541. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  7542. val, val2, val3, val4);
  7543. }
  7544. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  7545. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  7546. static void __devinit bnx2x_get_igu_cam_info(struct bnx2x *bp)
  7547. {
  7548. int pfid = BP_FUNC(bp);
  7549. int igu_sb_id;
  7550. u32 val;
  7551. u8 fid, igu_sb_cnt = 0;
  7552. bp->igu_base_sb = 0xff;
  7553. if (CHIP_INT_MODE_IS_BC(bp)) {
  7554. int vn = BP_VN(bp);
  7555. igu_sb_cnt = bp->igu_sb_cnt;
  7556. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  7557. FP_SB_MAX_E1x;
  7558. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  7559. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  7560. return;
  7561. }
  7562. /* IGU in normal mode - read CAM */
  7563. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  7564. igu_sb_id++) {
  7565. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  7566. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  7567. continue;
  7568. fid = IGU_FID(val);
  7569. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  7570. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  7571. continue;
  7572. if (IGU_VEC(val) == 0)
  7573. /* default status block */
  7574. bp->igu_dsb_id = igu_sb_id;
  7575. else {
  7576. if (bp->igu_base_sb == 0xff)
  7577. bp->igu_base_sb = igu_sb_id;
  7578. igu_sb_cnt++;
  7579. }
  7580. }
  7581. }
  7582. #ifdef CONFIG_PCI_MSI
  7583. /*
  7584. * It's expected that number of CAM entries for this functions is equal
  7585. * to the number evaluated based on the MSI-X table size. We want a
  7586. * harsh warning if these values are different!
  7587. */
  7588. WARN_ON(bp->igu_sb_cnt != igu_sb_cnt);
  7589. #endif
  7590. if (igu_sb_cnt == 0)
  7591. BNX2X_ERR("CAM configuration error\n");
  7592. }
  7593. static void __devinit bnx2x_link_settings_supported(struct bnx2x *bp,
  7594. u32 switch_cfg)
  7595. {
  7596. int cfg_size = 0, idx, port = BP_PORT(bp);
  7597. /* Aggregation of supported attributes of all external phys */
  7598. bp->port.supported[0] = 0;
  7599. bp->port.supported[1] = 0;
  7600. switch (bp->link_params.num_phys) {
  7601. case 1:
  7602. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  7603. cfg_size = 1;
  7604. break;
  7605. case 2:
  7606. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  7607. cfg_size = 1;
  7608. break;
  7609. case 3:
  7610. if (bp->link_params.multi_phy_config &
  7611. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  7612. bp->port.supported[1] =
  7613. bp->link_params.phy[EXT_PHY1].supported;
  7614. bp->port.supported[0] =
  7615. bp->link_params.phy[EXT_PHY2].supported;
  7616. } else {
  7617. bp->port.supported[0] =
  7618. bp->link_params.phy[EXT_PHY1].supported;
  7619. bp->port.supported[1] =
  7620. bp->link_params.phy[EXT_PHY2].supported;
  7621. }
  7622. cfg_size = 2;
  7623. break;
  7624. }
  7625. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  7626. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  7627. SHMEM_RD(bp,
  7628. dev_info.port_hw_config[port].external_phy_config),
  7629. SHMEM_RD(bp,
  7630. dev_info.port_hw_config[port].external_phy_config2));
  7631. return;
  7632. }
  7633. if (CHIP_IS_E3(bp))
  7634. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  7635. else {
  7636. switch (switch_cfg) {
  7637. case SWITCH_CFG_1G:
  7638. bp->port.phy_addr = REG_RD(
  7639. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  7640. break;
  7641. case SWITCH_CFG_10G:
  7642. bp->port.phy_addr = REG_RD(
  7643. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  7644. break;
  7645. default:
  7646. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  7647. bp->port.link_config[0]);
  7648. return;
  7649. }
  7650. }
  7651. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  7652. /* mask what we support according to speed_cap_mask per configuration */
  7653. for (idx = 0; idx < cfg_size; idx++) {
  7654. if (!(bp->link_params.speed_cap_mask[idx] &
  7655. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  7656. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  7657. if (!(bp->link_params.speed_cap_mask[idx] &
  7658. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  7659. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  7660. if (!(bp->link_params.speed_cap_mask[idx] &
  7661. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  7662. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  7663. if (!(bp->link_params.speed_cap_mask[idx] &
  7664. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  7665. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  7666. if (!(bp->link_params.speed_cap_mask[idx] &
  7667. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  7668. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  7669. SUPPORTED_1000baseT_Full);
  7670. if (!(bp->link_params.speed_cap_mask[idx] &
  7671. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  7672. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  7673. if (!(bp->link_params.speed_cap_mask[idx] &
  7674. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  7675. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  7676. }
  7677. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  7678. bp->port.supported[1]);
  7679. }
  7680. static void __devinit bnx2x_link_settings_requested(struct bnx2x *bp)
  7681. {
  7682. u32 link_config, idx, cfg_size = 0;
  7683. bp->port.advertising[0] = 0;
  7684. bp->port.advertising[1] = 0;
  7685. switch (bp->link_params.num_phys) {
  7686. case 1:
  7687. case 2:
  7688. cfg_size = 1;
  7689. break;
  7690. case 3:
  7691. cfg_size = 2;
  7692. break;
  7693. }
  7694. for (idx = 0; idx < cfg_size; idx++) {
  7695. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  7696. link_config = bp->port.link_config[idx];
  7697. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  7698. case PORT_FEATURE_LINK_SPEED_AUTO:
  7699. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  7700. bp->link_params.req_line_speed[idx] =
  7701. SPEED_AUTO_NEG;
  7702. bp->port.advertising[idx] |=
  7703. bp->port.supported[idx];
  7704. if (bp->link_params.phy[EXT_PHY1].type ==
  7705. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  7706. bp->port.advertising[idx] |=
  7707. (SUPPORTED_100baseT_Half |
  7708. SUPPORTED_100baseT_Full);
  7709. } else {
  7710. /* force 10G, no AN */
  7711. bp->link_params.req_line_speed[idx] =
  7712. SPEED_10000;
  7713. bp->port.advertising[idx] |=
  7714. (ADVERTISED_10000baseT_Full |
  7715. ADVERTISED_FIBRE);
  7716. continue;
  7717. }
  7718. break;
  7719. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  7720. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  7721. bp->link_params.req_line_speed[idx] =
  7722. SPEED_10;
  7723. bp->port.advertising[idx] |=
  7724. (ADVERTISED_10baseT_Full |
  7725. ADVERTISED_TP);
  7726. } else {
  7727. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7728. link_config,
  7729. bp->link_params.speed_cap_mask[idx]);
  7730. return;
  7731. }
  7732. break;
  7733. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  7734. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  7735. bp->link_params.req_line_speed[idx] =
  7736. SPEED_10;
  7737. bp->link_params.req_duplex[idx] =
  7738. DUPLEX_HALF;
  7739. bp->port.advertising[idx] |=
  7740. (ADVERTISED_10baseT_Half |
  7741. ADVERTISED_TP);
  7742. } else {
  7743. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7744. link_config,
  7745. bp->link_params.speed_cap_mask[idx]);
  7746. return;
  7747. }
  7748. break;
  7749. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  7750. if (bp->port.supported[idx] &
  7751. SUPPORTED_100baseT_Full) {
  7752. bp->link_params.req_line_speed[idx] =
  7753. SPEED_100;
  7754. bp->port.advertising[idx] |=
  7755. (ADVERTISED_100baseT_Full |
  7756. ADVERTISED_TP);
  7757. } else {
  7758. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7759. link_config,
  7760. bp->link_params.speed_cap_mask[idx]);
  7761. return;
  7762. }
  7763. break;
  7764. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  7765. if (bp->port.supported[idx] &
  7766. SUPPORTED_100baseT_Half) {
  7767. bp->link_params.req_line_speed[idx] =
  7768. SPEED_100;
  7769. bp->link_params.req_duplex[idx] =
  7770. DUPLEX_HALF;
  7771. bp->port.advertising[idx] |=
  7772. (ADVERTISED_100baseT_Half |
  7773. ADVERTISED_TP);
  7774. } else {
  7775. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7776. link_config,
  7777. bp->link_params.speed_cap_mask[idx]);
  7778. return;
  7779. }
  7780. break;
  7781. case PORT_FEATURE_LINK_SPEED_1G:
  7782. if (bp->port.supported[idx] &
  7783. SUPPORTED_1000baseT_Full) {
  7784. bp->link_params.req_line_speed[idx] =
  7785. SPEED_1000;
  7786. bp->port.advertising[idx] |=
  7787. (ADVERTISED_1000baseT_Full |
  7788. ADVERTISED_TP);
  7789. } else {
  7790. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7791. link_config,
  7792. bp->link_params.speed_cap_mask[idx]);
  7793. return;
  7794. }
  7795. break;
  7796. case PORT_FEATURE_LINK_SPEED_2_5G:
  7797. if (bp->port.supported[idx] &
  7798. SUPPORTED_2500baseX_Full) {
  7799. bp->link_params.req_line_speed[idx] =
  7800. SPEED_2500;
  7801. bp->port.advertising[idx] |=
  7802. (ADVERTISED_2500baseX_Full |
  7803. ADVERTISED_TP);
  7804. } else {
  7805. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7806. link_config,
  7807. bp->link_params.speed_cap_mask[idx]);
  7808. return;
  7809. }
  7810. break;
  7811. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  7812. if (bp->port.supported[idx] &
  7813. SUPPORTED_10000baseT_Full) {
  7814. bp->link_params.req_line_speed[idx] =
  7815. SPEED_10000;
  7816. bp->port.advertising[idx] |=
  7817. (ADVERTISED_10000baseT_Full |
  7818. ADVERTISED_FIBRE);
  7819. } else {
  7820. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  7821. link_config,
  7822. bp->link_params.speed_cap_mask[idx]);
  7823. return;
  7824. }
  7825. break;
  7826. case PORT_FEATURE_LINK_SPEED_20G:
  7827. bp->link_params.req_line_speed[idx] = SPEED_20000;
  7828. break;
  7829. default:
  7830. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  7831. link_config);
  7832. bp->link_params.req_line_speed[idx] =
  7833. SPEED_AUTO_NEG;
  7834. bp->port.advertising[idx] =
  7835. bp->port.supported[idx];
  7836. break;
  7837. }
  7838. bp->link_params.req_flow_ctrl[idx] = (link_config &
  7839. PORT_FEATURE_FLOW_CONTROL_MASK);
  7840. if ((bp->link_params.req_flow_ctrl[idx] ==
  7841. BNX2X_FLOW_CTRL_AUTO) &&
  7842. !(bp->port.supported[idx] & SUPPORTED_Autoneg)) {
  7843. bp->link_params.req_flow_ctrl[idx] =
  7844. BNX2X_FLOW_CTRL_NONE;
  7845. }
  7846. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  7847. bp->link_params.req_line_speed[idx],
  7848. bp->link_params.req_duplex[idx],
  7849. bp->link_params.req_flow_ctrl[idx],
  7850. bp->port.advertising[idx]);
  7851. }
  7852. }
  7853. static void __devinit bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  7854. {
  7855. mac_hi = cpu_to_be16(mac_hi);
  7856. mac_lo = cpu_to_be32(mac_lo);
  7857. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  7858. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  7859. }
  7860. static void __devinit bnx2x_get_port_hwinfo(struct bnx2x *bp)
  7861. {
  7862. int port = BP_PORT(bp);
  7863. u32 config;
  7864. u32 ext_phy_type, ext_phy_config;
  7865. bp->link_params.bp = bp;
  7866. bp->link_params.port = port;
  7867. bp->link_params.lane_config =
  7868. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  7869. bp->link_params.speed_cap_mask[0] =
  7870. SHMEM_RD(bp,
  7871. dev_info.port_hw_config[port].speed_capability_mask);
  7872. bp->link_params.speed_cap_mask[1] =
  7873. SHMEM_RD(bp,
  7874. dev_info.port_hw_config[port].speed_capability_mask2);
  7875. bp->port.link_config[0] =
  7876. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  7877. bp->port.link_config[1] =
  7878. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  7879. bp->link_params.multi_phy_config =
  7880. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  7881. /* If the device is capable of WoL, set the default state according
  7882. * to the HW
  7883. */
  7884. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  7885. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  7886. (config & PORT_FEATURE_WOL_ENABLED));
  7887. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  7888. bp->link_params.lane_config,
  7889. bp->link_params.speed_cap_mask[0],
  7890. bp->port.link_config[0]);
  7891. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  7892. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  7893. bnx2x_phy_probe(&bp->link_params);
  7894. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  7895. bnx2x_link_settings_requested(bp);
  7896. /*
  7897. * If connected directly, work with the internal PHY, otherwise, work
  7898. * with the external PHY
  7899. */
  7900. ext_phy_config =
  7901. SHMEM_RD(bp,
  7902. dev_info.port_hw_config[port].external_phy_config);
  7903. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  7904. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  7905. bp->mdio.prtad = bp->port.phy_addr;
  7906. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  7907. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  7908. bp->mdio.prtad =
  7909. XGXS_EXT_PHY_ADDR(ext_phy_config);
  7910. /*
  7911. * Check if hw lock is required to access MDC/MDIO bus to the PHY(s)
  7912. * In MF mode, it is set to cover self test cases
  7913. */
  7914. if (IS_MF(bp))
  7915. bp->port.need_hw_lock = 1;
  7916. else
  7917. bp->port.need_hw_lock = bnx2x_hw_lock_required(bp,
  7918. bp->common.shmem_base,
  7919. bp->common.shmem2_base);
  7920. }
  7921. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  7922. {
  7923. u32 no_flags = NO_ISCSI_FLAG;
  7924. #ifdef BCM_CNIC
  7925. int port = BP_PORT(bp);
  7926. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7927. drv_lic_key[port].max_iscsi_conn);
  7928. /* Get the number of maximum allowed iSCSI connections */
  7929. bp->cnic_eth_dev.max_iscsi_conn =
  7930. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  7931. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  7932. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  7933. bp->cnic_eth_dev.max_iscsi_conn);
  7934. /*
  7935. * If maximum allowed number of connections is zero -
  7936. * disable the feature.
  7937. */
  7938. if (!bp->cnic_eth_dev.max_iscsi_conn)
  7939. bp->flags |= no_flags;
  7940. #else
  7941. bp->flags |= no_flags;
  7942. #endif
  7943. }
  7944. #ifdef BCM_CNIC
  7945. static void __devinit bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  7946. {
  7947. /* Port info */
  7948. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  7949. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  7950. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  7951. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  7952. /* Node info */
  7953. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  7954. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  7955. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  7956. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  7957. }
  7958. #endif
  7959. static void __devinit bnx2x_get_fcoe_info(struct bnx2x *bp)
  7960. {
  7961. #ifdef BCM_CNIC
  7962. int port = BP_PORT(bp);
  7963. int func = BP_ABS_FUNC(bp);
  7964. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  7965. drv_lic_key[port].max_fcoe_conn);
  7966. /* Get the number of maximum allowed FCoE connections */
  7967. bp->cnic_eth_dev.max_fcoe_conn =
  7968. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  7969. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  7970. /* Read the WWN: */
  7971. if (!IS_MF(bp)) {
  7972. /* Port info */
  7973. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  7974. SHMEM_RD(bp,
  7975. dev_info.port_hw_config[port].
  7976. fcoe_wwn_port_name_upper);
  7977. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  7978. SHMEM_RD(bp,
  7979. dev_info.port_hw_config[port].
  7980. fcoe_wwn_port_name_lower);
  7981. /* Node info */
  7982. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  7983. SHMEM_RD(bp,
  7984. dev_info.port_hw_config[port].
  7985. fcoe_wwn_node_name_upper);
  7986. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  7987. SHMEM_RD(bp,
  7988. dev_info.port_hw_config[port].
  7989. fcoe_wwn_node_name_lower);
  7990. } else if (!IS_MF_SD(bp)) {
  7991. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  7992. /*
  7993. * Read the WWN info only if the FCoE feature is enabled for
  7994. * this function.
  7995. */
  7996. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD)
  7997. bnx2x_get_ext_wwn_info(bp, func);
  7998. } else if (IS_MF_FCOE_SD(bp))
  7999. bnx2x_get_ext_wwn_info(bp, func);
  8000. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8001. /*
  8002. * If maximum allowed number of connections is zero -
  8003. * disable the feature.
  8004. */
  8005. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8006. bp->flags |= NO_FCOE_FLAG;
  8007. #else
  8008. bp->flags |= NO_FCOE_FLAG;
  8009. #endif
  8010. }
  8011. static void __devinit bnx2x_get_cnic_info(struct bnx2x *bp)
  8012. {
  8013. /*
  8014. * iSCSI may be dynamically disabled but reading
  8015. * info here we will decrease memory usage by driver
  8016. * if the feature is disabled for good
  8017. */
  8018. bnx2x_get_iscsi_info(bp);
  8019. bnx2x_get_fcoe_info(bp);
  8020. }
  8021. static void __devinit bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  8022. {
  8023. u32 val, val2;
  8024. int func = BP_ABS_FUNC(bp);
  8025. int port = BP_PORT(bp);
  8026. #ifdef BCM_CNIC
  8027. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8028. u8 *fip_mac = bp->fip_mac;
  8029. #endif
  8030. /* Zero primary MAC configuration */
  8031. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8032. if (BP_NOMCP(bp)) {
  8033. BNX2X_ERROR("warning: random MAC workaround active\n");
  8034. eth_hw_addr_random(bp->dev);
  8035. } else if (IS_MF(bp)) {
  8036. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  8037. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  8038. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  8039. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  8040. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8041. #ifdef BCM_CNIC
  8042. /*
  8043. * iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8044. * FCoE MAC then the appropriate feature should be disabled.
  8045. *
  8046. * In non SD mode features configuration comes from
  8047. * struct func_ext_config.
  8048. */
  8049. if (!IS_MF_SD(bp)) {
  8050. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8051. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8052. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8053. iscsi_mac_addr_upper);
  8054. val = MF_CFG_RD(bp, func_ext_config[func].
  8055. iscsi_mac_addr_lower);
  8056. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8057. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8058. iscsi_mac);
  8059. } else
  8060. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  8061. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  8062. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8063. fcoe_mac_addr_upper);
  8064. val = MF_CFG_RD(bp, func_ext_config[func].
  8065. fcoe_mac_addr_lower);
  8066. bnx2x_set_mac_buf(fip_mac, val, val2);
  8067. BNX2X_DEV_INFO("Read FCoE L2 MAC: %pM\n",
  8068. fip_mac);
  8069. } else
  8070. bp->flags |= NO_FCOE_FLAG;
  8071. } else { /* SD MODE */
  8072. if (IS_MF_STORAGE_SD(bp)) {
  8073. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  8074. /* use primary mac as iscsi mac */
  8075. memcpy(iscsi_mac, bp->dev->dev_addr,
  8076. ETH_ALEN);
  8077. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  8078. BNX2X_DEV_INFO("Read iSCSI MAC: %pM\n",
  8079. iscsi_mac);
  8080. } else { /* FCoE */
  8081. memcpy(fip_mac, bp->dev->dev_addr,
  8082. ETH_ALEN);
  8083. BNX2X_DEV_INFO("SD FCoE MODE\n");
  8084. BNX2X_DEV_INFO("Read FIP MAC: %pM\n",
  8085. fip_mac);
  8086. }
  8087. /* Zero primary MAC configuration */
  8088. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  8089. }
  8090. }
  8091. #endif
  8092. } else {
  8093. /* in SF read MACs from port configuration */
  8094. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  8095. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  8096. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  8097. #ifdef BCM_CNIC
  8098. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8099. iscsi_mac_upper);
  8100. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8101. iscsi_mac_lower);
  8102. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8103. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8104. fcoe_fip_mac_upper);
  8105. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  8106. fcoe_fip_mac_lower);
  8107. bnx2x_set_mac_buf(fip_mac, val, val2);
  8108. #endif
  8109. }
  8110. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  8111. memcpy(bp->dev->perm_addr, bp->dev->dev_addr, ETH_ALEN);
  8112. #ifdef BCM_CNIC
  8113. /* Disable iSCSI if MAC configuration is
  8114. * invalid.
  8115. */
  8116. if (!is_valid_ether_addr(iscsi_mac)) {
  8117. bp->flags |= NO_ISCSI_FLAG;
  8118. memset(iscsi_mac, 0, ETH_ALEN);
  8119. }
  8120. /* Disable FCoE if MAC configuration is
  8121. * invalid.
  8122. */
  8123. if (!is_valid_ether_addr(fip_mac)) {
  8124. bp->flags |= NO_FCOE_FLAG;
  8125. memset(bp->fip_mac, 0, ETH_ALEN);
  8126. }
  8127. #endif
  8128. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  8129. dev_err(&bp->pdev->dev,
  8130. "bad Ethernet MAC address configuration: %pM\n"
  8131. "change it manually before bringing up the appropriate network interface\n",
  8132. bp->dev->dev_addr);
  8133. }
  8134. static int __devinit bnx2x_get_hwinfo(struct bnx2x *bp)
  8135. {
  8136. int /*abs*/func = BP_ABS_FUNC(bp);
  8137. int vn;
  8138. u32 val = 0;
  8139. int rc = 0;
  8140. bnx2x_get_common_hwinfo(bp);
  8141. /*
  8142. * initialize IGU parameters
  8143. */
  8144. if (CHIP_IS_E1x(bp)) {
  8145. bp->common.int_block = INT_BLOCK_HC;
  8146. bp->igu_dsb_id = DEF_SB_IGU_ID;
  8147. bp->igu_base_sb = 0;
  8148. } else {
  8149. bp->common.int_block = INT_BLOCK_IGU;
  8150. /* do not allow device reset during IGU info preocessing */
  8151. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8152. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  8153. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8154. int tout = 5000;
  8155. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  8156. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  8157. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  8158. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  8159. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8160. tout--;
  8161. usleep_range(1000, 1000);
  8162. }
  8163. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  8164. dev_err(&bp->pdev->dev,
  8165. "FORCING Normal Mode failed!!!\n");
  8166. return -EPERM;
  8167. }
  8168. }
  8169. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  8170. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  8171. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  8172. } else
  8173. BNX2X_DEV_INFO("IGU Normal Mode\n");
  8174. bnx2x_get_igu_cam_info(bp);
  8175. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  8176. }
  8177. /*
  8178. * set base FW non-default (fast path) status block id, this value is
  8179. * used to initialize the fw_sb_id saved on the fp/queue structure to
  8180. * determine the id used by the FW.
  8181. */
  8182. if (CHIP_IS_E1x(bp))
  8183. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  8184. else /*
  8185. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  8186. * the same queue are indicated on the same IGU SB). So we prefer
  8187. * FW and IGU SBs to be the same value.
  8188. */
  8189. bp->base_fw_ndsb = bp->igu_base_sb;
  8190. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  8191. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  8192. bp->igu_sb_cnt, bp->base_fw_ndsb);
  8193. /*
  8194. * Initialize MF configuration
  8195. */
  8196. bp->mf_ov = 0;
  8197. bp->mf_mode = 0;
  8198. vn = BP_VN(bp);
  8199. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  8200. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  8201. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  8202. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  8203. if (SHMEM2_HAS(bp, mf_cfg_addr))
  8204. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  8205. else
  8206. bp->common.mf_cfg_base = bp->common.shmem_base +
  8207. offsetof(struct shmem_region, func_mb) +
  8208. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  8209. /*
  8210. * get mf configuration:
  8211. * 1. existence of MF configuration
  8212. * 2. MAC address must be legal (check only upper bytes)
  8213. * for Switch-Independent mode;
  8214. * OVLAN must be legal for Switch-Dependent mode
  8215. * 3. SF_MODE configures specific MF mode
  8216. */
  8217. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8218. /* get mf configuration */
  8219. val = SHMEM_RD(bp,
  8220. dev_info.shared_feature_config.config);
  8221. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  8222. switch (val) {
  8223. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  8224. val = MF_CFG_RD(bp, func_mf_config[func].
  8225. mac_upper);
  8226. /* check for legal mac (upper bytes)*/
  8227. if (val != 0xffff) {
  8228. bp->mf_mode = MULTI_FUNCTION_SI;
  8229. bp->mf_config[vn] = MF_CFG_RD(bp,
  8230. func_mf_config[func].config);
  8231. } else
  8232. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  8233. break;
  8234. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  8235. /* get OV configuration */
  8236. val = MF_CFG_RD(bp,
  8237. func_mf_config[FUNC_0].e1hov_tag);
  8238. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  8239. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8240. bp->mf_mode = MULTI_FUNCTION_SD;
  8241. bp->mf_config[vn] = MF_CFG_RD(bp,
  8242. func_mf_config[func].config);
  8243. } else
  8244. BNX2X_DEV_INFO("illegal OV for SD\n");
  8245. break;
  8246. default:
  8247. /* Unknown configuration: reset mf_config */
  8248. bp->mf_config[vn] = 0;
  8249. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  8250. }
  8251. }
  8252. BNX2X_DEV_INFO("%s function mode\n",
  8253. IS_MF(bp) ? "multi" : "single");
  8254. switch (bp->mf_mode) {
  8255. case MULTI_FUNCTION_SD:
  8256. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  8257. FUNC_MF_CFG_E1HOV_TAG_MASK;
  8258. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  8259. bp->mf_ov = val;
  8260. bp->path_has_ovlan = true;
  8261. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  8262. func, bp->mf_ov, bp->mf_ov);
  8263. } else {
  8264. dev_err(&bp->pdev->dev,
  8265. "No valid MF OV for func %d, aborting\n",
  8266. func);
  8267. return -EPERM;
  8268. }
  8269. break;
  8270. case MULTI_FUNCTION_SI:
  8271. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  8272. func);
  8273. break;
  8274. default:
  8275. if (vn) {
  8276. dev_err(&bp->pdev->dev,
  8277. "VN %d is in a single function mode, aborting\n",
  8278. vn);
  8279. return -EPERM;
  8280. }
  8281. break;
  8282. }
  8283. /* check if other port on the path needs ovlan:
  8284. * Since MF configuration is shared between ports
  8285. * Possible mixed modes are only
  8286. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  8287. */
  8288. if (CHIP_MODE_IS_4_PORT(bp) &&
  8289. !bp->path_has_ovlan &&
  8290. !IS_MF(bp) &&
  8291. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  8292. u8 other_port = !BP_PORT(bp);
  8293. u8 other_func = BP_PATH(bp) + 2*other_port;
  8294. val = MF_CFG_RD(bp,
  8295. func_mf_config[other_func].e1hov_tag);
  8296. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  8297. bp->path_has_ovlan = true;
  8298. }
  8299. }
  8300. /* adjust igu_sb_cnt to MF for E1x */
  8301. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  8302. bp->igu_sb_cnt /= E1HVN_MAX;
  8303. /* port info */
  8304. bnx2x_get_port_hwinfo(bp);
  8305. /* Get MAC addresses */
  8306. bnx2x_get_mac_hwinfo(bp);
  8307. bnx2x_get_cnic_info(bp);
  8308. return rc;
  8309. }
  8310. static void __devinit bnx2x_read_fwinfo(struct bnx2x *bp)
  8311. {
  8312. int cnt, i, block_end, rodi;
  8313. char vpd_start[BNX2X_VPD_LEN+1];
  8314. char str_id_reg[VENDOR_ID_LEN+1];
  8315. char str_id_cap[VENDOR_ID_LEN+1];
  8316. char *vpd_data;
  8317. char *vpd_extended_data = NULL;
  8318. u8 len;
  8319. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  8320. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  8321. if (cnt < BNX2X_VPD_LEN)
  8322. goto out_not_found;
  8323. /* VPD RO tag should be first tag after identifier string, hence
  8324. * we should be able to find it in first BNX2X_VPD_LEN chars
  8325. */
  8326. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  8327. PCI_VPD_LRDT_RO_DATA);
  8328. if (i < 0)
  8329. goto out_not_found;
  8330. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  8331. pci_vpd_lrdt_size(&vpd_start[i]);
  8332. i += PCI_VPD_LRDT_TAG_SIZE;
  8333. if (block_end > BNX2X_VPD_LEN) {
  8334. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  8335. if (vpd_extended_data == NULL)
  8336. goto out_not_found;
  8337. /* read rest of vpd image into vpd_extended_data */
  8338. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  8339. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  8340. block_end - BNX2X_VPD_LEN,
  8341. vpd_extended_data + BNX2X_VPD_LEN);
  8342. if (cnt < (block_end - BNX2X_VPD_LEN))
  8343. goto out_not_found;
  8344. vpd_data = vpd_extended_data;
  8345. } else
  8346. vpd_data = vpd_start;
  8347. /* now vpd_data holds full vpd content in both cases */
  8348. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8349. PCI_VPD_RO_KEYWORD_MFR_ID);
  8350. if (rodi < 0)
  8351. goto out_not_found;
  8352. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8353. if (len != VENDOR_ID_LEN)
  8354. goto out_not_found;
  8355. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8356. /* vendor specific info */
  8357. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  8358. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  8359. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  8360. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  8361. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  8362. PCI_VPD_RO_KEYWORD_VENDOR0);
  8363. if (rodi >= 0) {
  8364. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  8365. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  8366. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  8367. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  8368. bp->fw_ver[len] = ' ';
  8369. }
  8370. }
  8371. kfree(vpd_extended_data);
  8372. return;
  8373. }
  8374. out_not_found:
  8375. kfree(vpd_extended_data);
  8376. return;
  8377. }
  8378. static void __devinit bnx2x_set_modes_bitmap(struct bnx2x *bp)
  8379. {
  8380. u32 flags = 0;
  8381. if (CHIP_REV_IS_FPGA(bp))
  8382. SET_FLAGS(flags, MODE_FPGA);
  8383. else if (CHIP_REV_IS_EMUL(bp))
  8384. SET_FLAGS(flags, MODE_EMUL);
  8385. else
  8386. SET_FLAGS(flags, MODE_ASIC);
  8387. if (CHIP_MODE_IS_4_PORT(bp))
  8388. SET_FLAGS(flags, MODE_PORT4);
  8389. else
  8390. SET_FLAGS(flags, MODE_PORT2);
  8391. if (CHIP_IS_E2(bp))
  8392. SET_FLAGS(flags, MODE_E2);
  8393. else if (CHIP_IS_E3(bp)) {
  8394. SET_FLAGS(flags, MODE_E3);
  8395. if (CHIP_REV(bp) == CHIP_REV_Ax)
  8396. SET_FLAGS(flags, MODE_E3_A0);
  8397. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  8398. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  8399. }
  8400. if (IS_MF(bp)) {
  8401. SET_FLAGS(flags, MODE_MF);
  8402. switch (bp->mf_mode) {
  8403. case MULTI_FUNCTION_SD:
  8404. SET_FLAGS(flags, MODE_MF_SD);
  8405. break;
  8406. case MULTI_FUNCTION_SI:
  8407. SET_FLAGS(flags, MODE_MF_SI);
  8408. break;
  8409. }
  8410. } else
  8411. SET_FLAGS(flags, MODE_SF);
  8412. #if defined(__LITTLE_ENDIAN)
  8413. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  8414. #else /*(__BIG_ENDIAN)*/
  8415. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  8416. #endif
  8417. INIT_MODE_FLAGS(bp) = flags;
  8418. }
  8419. static int __devinit bnx2x_init_bp(struct bnx2x *bp)
  8420. {
  8421. int func;
  8422. int rc;
  8423. mutex_init(&bp->port.phy_mutex);
  8424. mutex_init(&bp->fw_mb_mutex);
  8425. spin_lock_init(&bp->stats_lock);
  8426. #ifdef BCM_CNIC
  8427. mutex_init(&bp->cnic_mutex);
  8428. #endif
  8429. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  8430. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  8431. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  8432. rc = bnx2x_get_hwinfo(bp);
  8433. if (rc)
  8434. return rc;
  8435. bnx2x_set_modes_bitmap(bp);
  8436. rc = bnx2x_alloc_mem_bp(bp);
  8437. if (rc)
  8438. return rc;
  8439. bnx2x_read_fwinfo(bp);
  8440. func = BP_FUNC(bp);
  8441. /* need to reset chip if undi was active */
  8442. if (!BP_NOMCP(bp))
  8443. bnx2x_undi_unload(bp);
  8444. if (CHIP_REV_IS_FPGA(bp))
  8445. dev_err(&bp->pdev->dev, "FPGA detected\n");
  8446. if (BP_NOMCP(bp) && (func == 0))
  8447. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  8448. bp->multi_mode = multi_mode;
  8449. bp->disable_tpa = disable_tpa;
  8450. #ifdef BCM_CNIC
  8451. bp->disable_tpa |= IS_MF_STORAGE_SD(bp);
  8452. #endif
  8453. /* Set TPA flags */
  8454. if (bp->disable_tpa) {
  8455. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  8456. bp->dev->features &= ~NETIF_F_LRO;
  8457. } else {
  8458. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  8459. bp->dev->features |= NETIF_F_LRO;
  8460. }
  8461. if (CHIP_IS_E1(bp))
  8462. bp->dropless_fc = 0;
  8463. else
  8464. bp->dropless_fc = dropless_fc;
  8465. bp->mrrs = mrrs;
  8466. bp->tx_ring_size = MAX_TX_AVAIL;
  8467. /* make sure that the numbers are in the right granularity */
  8468. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  8469. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  8470. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  8471. init_timer(&bp->timer);
  8472. bp->timer.expires = jiffies + bp->current_interval;
  8473. bp->timer.data = (unsigned long) bp;
  8474. bp->timer.function = bnx2x_timer;
  8475. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  8476. bnx2x_dcbx_init_params(bp);
  8477. #ifdef BCM_CNIC
  8478. if (CHIP_IS_E1x(bp))
  8479. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  8480. else
  8481. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  8482. #endif
  8483. /* multiple tx priority */
  8484. if (CHIP_IS_E1x(bp))
  8485. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  8486. if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  8487. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  8488. if (CHIP_IS_E3B0(bp))
  8489. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  8490. bp->gro_check = bnx2x_need_gro_check(bp->dev->mtu);
  8491. return rc;
  8492. }
  8493. /****************************************************************************
  8494. * General service functions
  8495. ****************************************************************************/
  8496. /*
  8497. * net_device service functions
  8498. */
  8499. /* called with rtnl_lock */
  8500. static int bnx2x_open(struct net_device *dev)
  8501. {
  8502. struct bnx2x *bp = netdev_priv(dev);
  8503. bool global = false;
  8504. int other_engine = BP_PATH(bp) ? 0 : 1;
  8505. bool other_load_status, load_status;
  8506. bp->stats_init = true;
  8507. netif_carrier_off(dev);
  8508. bnx2x_set_power_state(bp, PCI_D0);
  8509. other_load_status = bnx2x_get_load_status(bp, other_engine);
  8510. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  8511. /*
  8512. * If parity had happen during the unload, then attentions
  8513. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  8514. * want the first function loaded on the current engine to
  8515. * complete the recovery.
  8516. */
  8517. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  8518. bnx2x_chk_parity_attn(bp, &global, true))
  8519. do {
  8520. /*
  8521. * If there are attentions and they are in a global
  8522. * blocks, set the GLOBAL_RESET bit regardless whether
  8523. * it will be this function that will complete the
  8524. * recovery or not.
  8525. */
  8526. if (global)
  8527. bnx2x_set_reset_global(bp);
  8528. /*
  8529. * Only the first function on the current engine should
  8530. * try to recover in open. In case of attentions in
  8531. * global blocks only the first in the chip should try
  8532. * to recover.
  8533. */
  8534. if ((!load_status &&
  8535. (!global || !other_load_status)) &&
  8536. bnx2x_trylock_leader_lock(bp) &&
  8537. !bnx2x_leader_reset(bp)) {
  8538. netdev_info(bp->dev, "Recovered in open\n");
  8539. break;
  8540. }
  8541. /* recovery has failed... */
  8542. bnx2x_set_power_state(bp, PCI_D3hot);
  8543. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  8544. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  8545. "If you still see this message after a few retries then power cycle is required.\n");
  8546. return -EAGAIN;
  8547. } while (0);
  8548. bp->recovery_state = BNX2X_RECOVERY_DONE;
  8549. return bnx2x_nic_load(bp, LOAD_OPEN);
  8550. }
  8551. /* called with rtnl_lock */
  8552. static int bnx2x_close(struct net_device *dev)
  8553. {
  8554. struct bnx2x *bp = netdev_priv(dev);
  8555. /* Unload the driver, release IRQs */
  8556. bnx2x_nic_unload(bp, UNLOAD_CLOSE);
  8557. /* Power off */
  8558. bnx2x_set_power_state(bp, PCI_D3hot);
  8559. return 0;
  8560. }
  8561. static inline int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  8562. struct bnx2x_mcast_ramrod_params *p)
  8563. {
  8564. int mc_count = netdev_mc_count(bp->dev);
  8565. struct bnx2x_mcast_list_elem *mc_mac =
  8566. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  8567. struct netdev_hw_addr *ha;
  8568. if (!mc_mac)
  8569. return -ENOMEM;
  8570. INIT_LIST_HEAD(&p->mcast_list);
  8571. netdev_for_each_mc_addr(ha, bp->dev) {
  8572. mc_mac->mac = bnx2x_mc_addr(ha);
  8573. list_add_tail(&mc_mac->link, &p->mcast_list);
  8574. mc_mac++;
  8575. }
  8576. p->mcast_list_len = mc_count;
  8577. return 0;
  8578. }
  8579. static inline void bnx2x_free_mcast_macs_list(
  8580. struct bnx2x_mcast_ramrod_params *p)
  8581. {
  8582. struct bnx2x_mcast_list_elem *mc_mac =
  8583. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  8584. link);
  8585. WARN_ON(!mc_mac);
  8586. kfree(mc_mac);
  8587. }
  8588. /**
  8589. * bnx2x_set_uc_list - configure a new unicast MACs list.
  8590. *
  8591. * @bp: driver handle
  8592. *
  8593. * We will use zero (0) as a MAC type for these MACs.
  8594. */
  8595. static inline int bnx2x_set_uc_list(struct bnx2x *bp)
  8596. {
  8597. int rc;
  8598. struct net_device *dev = bp->dev;
  8599. struct netdev_hw_addr *ha;
  8600. struct bnx2x_vlan_mac_obj *mac_obj = &bp->fp->mac_obj;
  8601. unsigned long ramrod_flags = 0;
  8602. /* First schedule a cleanup up of old configuration */
  8603. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  8604. if (rc < 0) {
  8605. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  8606. return rc;
  8607. }
  8608. netdev_for_each_uc_addr(ha, dev) {
  8609. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  8610. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8611. if (rc < 0) {
  8612. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  8613. rc);
  8614. return rc;
  8615. }
  8616. }
  8617. /* Execute the pending commands */
  8618. __set_bit(RAMROD_CONT, &ramrod_flags);
  8619. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  8620. BNX2X_UC_LIST_MAC, &ramrod_flags);
  8621. }
  8622. static inline int bnx2x_set_mc_list(struct bnx2x *bp)
  8623. {
  8624. struct net_device *dev = bp->dev;
  8625. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  8626. int rc = 0;
  8627. rparam.mcast_obj = &bp->mcast_obj;
  8628. /* first, clear all configured multicast MACs */
  8629. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  8630. if (rc < 0) {
  8631. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  8632. return rc;
  8633. }
  8634. /* then, configure a new MACs list */
  8635. if (netdev_mc_count(dev)) {
  8636. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  8637. if (rc) {
  8638. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  8639. rc);
  8640. return rc;
  8641. }
  8642. /* Now add the new MACs */
  8643. rc = bnx2x_config_mcast(bp, &rparam,
  8644. BNX2X_MCAST_CMD_ADD);
  8645. if (rc < 0)
  8646. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  8647. rc);
  8648. bnx2x_free_mcast_macs_list(&rparam);
  8649. }
  8650. return rc;
  8651. }
  8652. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  8653. void bnx2x_set_rx_mode(struct net_device *dev)
  8654. {
  8655. struct bnx2x *bp = netdev_priv(dev);
  8656. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  8657. if (bp->state != BNX2X_STATE_OPEN) {
  8658. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  8659. return;
  8660. }
  8661. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  8662. if (dev->flags & IFF_PROMISC)
  8663. rx_mode = BNX2X_RX_MODE_PROMISC;
  8664. else if ((dev->flags & IFF_ALLMULTI) ||
  8665. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  8666. CHIP_IS_E1(bp)))
  8667. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8668. else {
  8669. /* some multicasts */
  8670. if (bnx2x_set_mc_list(bp) < 0)
  8671. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  8672. if (bnx2x_set_uc_list(bp) < 0)
  8673. rx_mode = BNX2X_RX_MODE_PROMISC;
  8674. }
  8675. bp->rx_mode = rx_mode;
  8676. #ifdef BCM_CNIC
  8677. /* handle ISCSI SD mode */
  8678. if (IS_MF_ISCSI_SD(bp))
  8679. bp->rx_mode = BNX2X_RX_MODE_NONE;
  8680. #endif
  8681. /* Schedule the rx_mode command */
  8682. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  8683. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  8684. return;
  8685. }
  8686. bnx2x_set_storm_rx_mode(bp);
  8687. }
  8688. /* called with rtnl_lock */
  8689. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  8690. int devad, u16 addr)
  8691. {
  8692. struct bnx2x *bp = netdev_priv(netdev);
  8693. u16 value;
  8694. int rc;
  8695. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  8696. prtad, devad, addr);
  8697. /* The HW expects different devad if CL22 is used */
  8698. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8699. bnx2x_acquire_phy_lock(bp);
  8700. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  8701. bnx2x_release_phy_lock(bp);
  8702. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  8703. if (!rc)
  8704. rc = value;
  8705. return rc;
  8706. }
  8707. /* called with rtnl_lock */
  8708. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  8709. u16 addr, u16 value)
  8710. {
  8711. struct bnx2x *bp = netdev_priv(netdev);
  8712. int rc;
  8713. DP(NETIF_MSG_LINK,
  8714. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  8715. prtad, devad, addr, value);
  8716. /* The HW expects different devad if CL22 is used */
  8717. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  8718. bnx2x_acquire_phy_lock(bp);
  8719. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  8720. bnx2x_release_phy_lock(bp);
  8721. return rc;
  8722. }
  8723. /* called with rtnl_lock */
  8724. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  8725. {
  8726. struct bnx2x *bp = netdev_priv(dev);
  8727. struct mii_ioctl_data *mdio = if_mii(ifr);
  8728. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  8729. mdio->phy_id, mdio->reg_num, mdio->val_in);
  8730. if (!netif_running(dev))
  8731. return -EAGAIN;
  8732. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  8733. }
  8734. #ifdef CONFIG_NET_POLL_CONTROLLER
  8735. static void poll_bnx2x(struct net_device *dev)
  8736. {
  8737. struct bnx2x *bp = netdev_priv(dev);
  8738. disable_irq(bp->pdev->irq);
  8739. bnx2x_interrupt(bp->pdev->irq, dev);
  8740. enable_irq(bp->pdev->irq);
  8741. }
  8742. #endif
  8743. static int bnx2x_validate_addr(struct net_device *dev)
  8744. {
  8745. struct bnx2x *bp = netdev_priv(dev);
  8746. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  8747. BNX2X_ERR("Non-valid Ethernet address\n");
  8748. return -EADDRNOTAVAIL;
  8749. }
  8750. return 0;
  8751. }
  8752. static const struct net_device_ops bnx2x_netdev_ops = {
  8753. .ndo_open = bnx2x_open,
  8754. .ndo_stop = bnx2x_close,
  8755. .ndo_start_xmit = bnx2x_start_xmit,
  8756. .ndo_select_queue = bnx2x_select_queue,
  8757. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  8758. .ndo_set_mac_address = bnx2x_change_mac_addr,
  8759. .ndo_validate_addr = bnx2x_validate_addr,
  8760. .ndo_do_ioctl = bnx2x_ioctl,
  8761. .ndo_change_mtu = bnx2x_change_mtu,
  8762. .ndo_fix_features = bnx2x_fix_features,
  8763. .ndo_set_features = bnx2x_set_features,
  8764. .ndo_tx_timeout = bnx2x_tx_timeout,
  8765. #ifdef CONFIG_NET_POLL_CONTROLLER
  8766. .ndo_poll_controller = poll_bnx2x,
  8767. #endif
  8768. .ndo_setup_tc = bnx2x_setup_tc,
  8769. #if defined(NETDEV_FCOE_WWNN) && defined(BCM_CNIC)
  8770. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  8771. #endif
  8772. };
  8773. static inline int bnx2x_set_coherency_mask(struct bnx2x *bp)
  8774. {
  8775. struct device *dev = &bp->pdev->dev;
  8776. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  8777. bp->flags |= USING_DAC_FLAG;
  8778. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  8779. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  8780. return -EIO;
  8781. }
  8782. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  8783. dev_err(dev, "System does not support DMA, aborting\n");
  8784. return -EIO;
  8785. }
  8786. return 0;
  8787. }
  8788. static int __devinit bnx2x_init_dev(struct pci_dev *pdev,
  8789. struct net_device *dev,
  8790. unsigned long board_type)
  8791. {
  8792. struct bnx2x *bp;
  8793. int rc;
  8794. u32 pci_cfg_dword;
  8795. bool chip_is_e1x = (board_type == BCM57710 ||
  8796. board_type == BCM57711 ||
  8797. board_type == BCM57711E);
  8798. SET_NETDEV_DEV(dev, &pdev->dev);
  8799. bp = netdev_priv(dev);
  8800. bp->dev = dev;
  8801. bp->pdev = pdev;
  8802. bp->flags = 0;
  8803. rc = pci_enable_device(pdev);
  8804. if (rc) {
  8805. dev_err(&bp->pdev->dev,
  8806. "Cannot enable PCI device, aborting\n");
  8807. goto err_out;
  8808. }
  8809. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  8810. dev_err(&bp->pdev->dev,
  8811. "Cannot find PCI device base address, aborting\n");
  8812. rc = -ENODEV;
  8813. goto err_out_disable;
  8814. }
  8815. if (!(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  8816. dev_err(&bp->pdev->dev, "Cannot find second PCI device"
  8817. " base address, aborting\n");
  8818. rc = -ENODEV;
  8819. goto err_out_disable;
  8820. }
  8821. if (atomic_read(&pdev->enable_cnt) == 1) {
  8822. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  8823. if (rc) {
  8824. dev_err(&bp->pdev->dev,
  8825. "Cannot obtain PCI resources, aborting\n");
  8826. goto err_out_disable;
  8827. }
  8828. pci_set_master(pdev);
  8829. pci_save_state(pdev);
  8830. }
  8831. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  8832. if (bp->pm_cap == 0) {
  8833. dev_err(&bp->pdev->dev,
  8834. "Cannot find power management capability, aborting\n");
  8835. rc = -EIO;
  8836. goto err_out_release;
  8837. }
  8838. if (!pci_is_pcie(pdev)) {
  8839. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  8840. rc = -EIO;
  8841. goto err_out_release;
  8842. }
  8843. rc = bnx2x_set_coherency_mask(bp);
  8844. if (rc)
  8845. goto err_out_release;
  8846. dev->mem_start = pci_resource_start(pdev, 0);
  8847. dev->base_addr = dev->mem_start;
  8848. dev->mem_end = pci_resource_end(pdev, 0);
  8849. dev->irq = pdev->irq;
  8850. bp->regview = pci_ioremap_bar(pdev, 0);
  8851. if (!bp->regview) {
  8852. dev_err(&bp->pdev->dev,
  8853. "Cannot map register space, aborting\n");
  8854. rc = -ENOMEM;
  8855. goto err_out_release;
  8856. }
  8857. /* In E1/E1H use pci device function given by kernel.
  8858. * In E2/E3 read physical function from ME register since these chips
  8859. * support Physical Device Assignment where kernel BDF maybe arbitrary
  8860. * (depending on hypervisor).
  8861. */
  8862. if (chip_is_e1x)
  8863. bp->pf_num = PCI_FUNC(pdev->devfn);
  8864. else {/* chip is E2/3*/
  8865. pci_read_config_dword(bp->pdev,
  8866. PCICFG_ME_REGISTER, &pci_cfg_dword);
  8867. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  8868. ME_REG_ABS_PF_NUM_SHIFT);
  8869. }
  8870. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  8871. bnx2x_set_power_state(bp, PCI_D0);
  8872. /* clean indirect addresses */
  8873. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  8874. PCICFG_VENDOR_ID_OFFSET);
  8875. /*
  8876. * Clean the following indirect addresses for all functions since it
  8877. * is not used by the driver.
  8878. */
  8879. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  8880. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  8881. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  8882. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  8883. if (chip_is_e1x) {
  8884. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  8885. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  8886. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  8887. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  8888. }
  8889. /*
  8890. * Enable internal target-read (in case we are probed after PF FLR).
  8891. * Must be done prior to any BAR read access. Only for 57712 and up
  8892. */
  8893. if (!chip_is_e1x)
  8894. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  8895. /* Reset the load counter */
  8896. bnx2x_clear_load_status(bp);
  8897. dev->watchdog_timeo = TX_TIMEOUT;
  8898. dev->netdev_ops = &bnx2x_netdev_ops;
  8899. bnx2x_set_ethtool_ops(dev);
  8900. dev->priv_flags |= IFF_UNICAST_FLT;
  8901. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8902. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  8903. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  8904. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  8905. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  8906. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  8907. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  8908. if (bp->flags & USING_DAC_FLAG)
  8909. dev->features |= NETIF_F_HIGHDMA;
  8910. /* Add Loopback capability to the device */
  8911. dev->hw_features |= NETIF_F_LOOPBACK;
  8912. #ifdef BCM_DCBNL
  8913. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  8914. #endif
  8915. /* get_port_hwinfo() will set prtad and mmds properly */
  8916. bp->mdio.prtad = MDIO_PRTAD_NONE;
  8917. bp->mdio.mmds = 0;
  8918. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  8919. bp->mdio.dev = dev;
  8920. bp->mdio.mdio_read = bnx2x_mdio_read;
  8921. bp->mdio.mdio_write = bnx2x_mdio_write;
  8922. return 0;
  8923. err_out_release:
  8924. if (atomic_read(&pdev->enable_cnt) == 1)
  8925. pci_release_regions(pdev);
  8926. err_out_disable:
  8927. pci_disable_device(pdev);
  8928. pci_set_drvdata(pdev, NULL);
  8929. err_out:
  8930. return rc;
  8931. }
  8932. static void __devinit bnx2x_get_pcie_width_speed(struct bnx2x *bp,
  8933. int *width, int *speed)
  8934. {
  8935. u32 val = REG_RD(bp, PCICFG_OFFSET + PCICFG_LINK_CONTROL);
  8936. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  8937. /* return value of 1=2.5GHz 2=5GHz */
  8938. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  8939. }
  8940. static int bnx2x_check_firmware(struct bnx2x *bp)
  8941. {
  8942. const struct firmware *firmware = bp->firmware;
  8943. struct bnx2x_fw_file_hdr *fw_hdr;
  8944. struct bnx2x_fw_file_section *sections;
  8945. u32 offset, len, num_ops;
  8946. u16 *ops_offsets;
  8947. int i;
  8948. const u8 *fw_ver;
  8949. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  8950. BNX2X_ERR("Wrong FW size\n");
  8951. return -EINVAL;
  8952. }
  8953. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  8954. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  8955. /* Make sure none of the offsets and sizes make us read beyond
  8956. * the end of the firmware data */
  8957. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  8958. offset = be32_to_cpu(sections[i].offset);
  8959. len = be32_to_cpu(sections[i].len);
  8960. if (offset + len > firmware->size) {
  8961. BNX2X_ERR("Section %d length is out of bounds\n", i);
  8962. return -EINVAL;
  8963. }
  8964. }
  8965. /* Likewise for the init_ops offsets */
  8966. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  8967. ops_offsets = (u16 *)(firmware->data + offset);
  8968. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  8969. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  8970. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  8971. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  8972. return -EINVAL;
  8973. }
  8974. }
  8975. /* Check FW version */
  8976. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  8977. fw_ver = firmware->data + offset;
  8978. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  8979. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  8980. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  8981. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  8982. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  8983. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  8984. BCM_5710_FW_MAJOR_VERSION,
  8985. BCM_5710_FW_MINOR_VERSION,
  8986. BCM_5710_FW_REVISION_VERSION,
  8987. BCM_5710_FW_ENGINEERING_VERSION);
  8988. return -EINVAL;
  8989. }
  8990. return 0;
  8991. }
  8992. static inline void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  8993. {
  8994. const __be32 *source = (const __be32 *)_source;
  8995. u32 *target = (u32 *)_target;
  8996. u32 i;
  8997. for (i = 0; i < n/4; i++)
  8998. target[i] = be32_to_cpu(source[i]);
  8999. }
  9000. /*
  9001. Ops array is stored in the following format:
  9002. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  9003. */
  9004. static inline void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  9005. {
  9006. const __be32 *source = (const __be32 *)_source;
  9007. struct raw_op *target = (struct raw_op *)_target;
  9008. u32 i, j, tmp;
  9009. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  9010. tmp = be32_to_cpu(source[j]);
  9011. target[i].op = (tmp >> 24) & 0xff;
  9012. target[i].offset = tmp & 0xffffff;
  9013. target[i].raw_data = be32_to_cpu(source[j + 1]);
  9014. }
  9015. }
  9016. /**
  9017. * IRO array is stored in the following format:
  9018. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  9019. */
  9020. static inline void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  9021. {
  9022. const __be32 *source = (const __be32 *)_source;
  9023. struct iro *target = (struct iro *)_target;
  9024. u32 i, j, tmp;
  9025. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  9026. target[i].base = be32_to_cpu(source[j]);
  9027. j++;
  9028. tmp = be32_to_cpu(source[j]);
  9029. target[i].m1 = (tmp >> 16) & 0xffff;
  9030. target[i].m2 = tmp & 0xffff;
  9031. j++;
  9032. tmp = be32_to_cpu(source[j]);
  9033. target[i].m3 = (tmp >> 16) & 0xffff;
  9034. target[i].size = tmp & 0xffff;
  9035. j++;
  9036. }
  9037. }
  9038. static inline void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  9039. {
  9040. const __be16 *source = (const __be16 *)_source;
  9041. u16 *target = (u16 *)_target;
  9042. u32 i;
  9043. for (i = 0; i < n/2; i++)
  9044. target[i] = be16_to_cpu(source[i]);
  9045. }
  9046. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  9047. do { \
  9048. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  9049. bp->arr = kmalloc(len, GFP_KERNEL); \
  9050. if (!bp->arr) \
  9051. goto lbl; \
  9052. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  9053. (u8 *)bp->arr, len); \
  9054. } while (0)
  9055. static int bnx2x_init_firmware(struct bnx2x *bp)
  9056. {
  9057. const char *fw_file_name;
  9058. struct bnx2x_fw_file_hdr *fw_hdr;
  9059. int rc;
  9060. if (bp->firmware)
  9061. return 0;
  9062. if (CHIP_IS_E1(bp))
  9063. fw_file_name = FW_FILE_NAME_E1;
  9064. else if (CHIP_IS_E1H(bp))
  9065. fw_file_name = FW_FILE_NAME_E1H;
  9066. else if (!CHIP_IS_E1x(bp))
  9067. fw_file_name = FW_FILE_NAME_E2;
  9068. else {
  9069. BNX2X_ERR("Unsupported chip revision\n");
  9070. return -EINVAL;
  9071. }
  9072. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  9073. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  9074. if (rc) {
  9075. BNX2X_ERR("Can't load firmware file %s\n",
  9076. fw_file_name);
  9077. goto request_firmware_exit;
  9078. }
  9079. rc = bnx2x_check_firmware(bp);
  9080. if (rc) {
  9081. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  9082. goto request_firmware_exit;
  9083. }
  9084. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  9085. /* Initialize the pointers to the init arrays */
  9086. /* Blob */
  9087. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  9088. /* Opcodes */
  9089. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  9090. /* Offsets */
  9091. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  9092. be16_to_cpu_n);
  9093. /* STORMs firmware */
  9094. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9095. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  9096. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  9097. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  9098. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9099. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  9100. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  9101. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  9102. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9103. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  9104. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  9105. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  9106. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  9107. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  9108. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  9109. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  9110. /* IRO */
  9111. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  9112. return 0;
  9113. iro_alloc_err:
  9114. kfree(bp->init_ops_offsets);
  9115. init_offsets_alloc_err:
  9116. kfree(bp->init_ops);
  9117. init_ops_alloc_err:
  9118. kfree(bp->init_data);
  9119. request_firmware_exit:
  9120. release_firmware(bp->firmware);
  9121. bp->firmware = NULL;
  9122. return rc;
  9123. }
  9124. static void bnx2x_release_firmware(struct bnx2x *bp)
  9125. {
  9126. kfree(bp->init_ops_offsets);
  9127. kfree(bp->init_ops);
  9128. kfree(bp->init_data);
  9129. release_firmware(bp->firmware);
  9130. bp->firmware = NULL;
  9131. }
  9132. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  9133. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  9134. .init_hw_cmn = bnx2x_init_hw_common,
  9135. .init_hw_port = bnx2x_init_hw_port,
  9136. .init_hw_func = bnx2x_init_hw_func,
  9137. .reset_hw_cmn = bnx2x_reset_common,
  9138. .reset_hw_port = bnx2x_reset_port,
  9139. .reset_hw_func = bnx2x_reset_func,
  9140. .gunzip_init = bnx2x_gunzip_init,
  9141. .gunzip_end = bnx2x_gunzip_end,
  9142. .init_fw = bnx2x_init_firmware,
  9143. .release_fw = bnx2x_release_firmware,
  9144. };
  9145. void bnx2x__init_func_obj(struct bnx2x *bp)
  9146. {
  9147. /* Prepare DMAE related driver resources */
  9148. bnx2x_setup_dmae(bp);
  9149. bnx2x_init_func_obj(bp, &bp->func_obj,
  9150. bnx2x_sp(bp, func_rdata),
  9151. bnx2x_sp_mapping(bp, func_rdata),
  9152. &bnx2x_func_sp_drv);
  9153. }
  9154. /* must be called after sriov-enable */
  9155. static inline int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  9156. {
  9157. int cid_count = BNX2X_L2_CID_COUNT(bp);
  9158. #ifdef BCM_CNIC
  9159. cid_count += CNIC_CID_MAX;
  9160. #endif
  9161. return roundup(cid_count, QM_CID_ROUND);
  9162. }
  9163. /**
  9164. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  9165. *
  9166. * @dev: pci device
  9167. *
  9168. */
  9169. static inline int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev)
  9170. {
  9171. int pos;
  9172. u16 control;
  9173. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  9174. /*
  9175. * If MSI-X is not supported - return number of SBs needed to support
  9176. * one fast path queue: one FP queue + SB for CNIC
  9177. */
  9178. if (!pos)
  9179. return 1 + CNIC_PRESENT;
  9180. /*
  9181. * The value in the PCI configuration space is the index of the last
  9182. * entry, namely one less than the actual size of the table, which is
  9183. * exactly what we want to return from this function: number of all SBs
  9184. * without the default SB.
  9185. */
  9186. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  9187. return control & PCI_MSIX_FLAGS_QSIZE;
  9188. }
  9189. static int __devinit bnx2x_init_one(struct pci_dev *pdev,
  9190. const struct pci_device_id *ent)
  9191. {
  9192. struct net_device *dev = NULL;
  9193. struct bnx2x *bp;
  9194. int pcie_width, pcie_speed;
  9195. int rc, max_non_def_sbs;
  9196. int rx_count, tx_count, rss_count;
  9197. /*
  9198. * An estimated maximum supported CoS number according to the chip
  9199. * version.
  9200. * We will try to roughly estimate the maximum number of CoSes this chip
  9201. * may support in order to minimize the memory allocated for Tx
  9202. * netdev_queue's. This number will be accurately calculated during the
  9203. * initialization of bp->max_cos based on the chip versions AND chip
  9204. * revision in the bnx2x_init_bp().
  9205. */
  9206. u8 max_cos_est = 0;
  9207. switch (ent->driver_data) {
  9208. case BCM57710:
  9209. case BCM57711:
  9210. case BCM57711E:
  9211. max_cos_est = BNX2X_MULTI_TX_COS_E1X;
  9212. break;
  9213. case BCM57712:
  9214. case BCM57712_MF:
  9215. max_cos_est = BNX2X_MULTI_TX_COS_E2_E3A0;
  9216. break;
  9217. case BCM57800:
  9218. case BCM57800_MF:
  9219. case BCM57810:
  9220. case BCM57810_MF:
  9221. case BCM57840:
  9222. case BCM57840_MF:
  9223. max_cos_est = BNX2X_MULTI_TX_COS_E3B0;
  9224. break;
  9225. default:
  9226. pr_err("Unknown board_type (%ld), aborting\n",
  9227. ent->driver_data);
  9228. return -ENODEV;
  9229. }
  9230. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev);
  9231. /* !!! FIXME !!!
  9232. * Do not allow the maximum SB count to grow above 16
  9233. * since Special CIDs starts from 16*BNX2X_MULTI_TX_COS=48.
  9234. * We will use the FP_SB_MAX_E1x macro for this matter.
  9235. */
  9236. max_non_def_sbs = min_t(int, FP_SB_MAX_E1x, max_non_def_sbs);
  9237. WARN_ON(!max_non_def_sbs);
  9238. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  9239. rss_count = max_non_def_sbs - CNIC_PRESENT;
  9240. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  9241. rx_count = rss_count + FCOE_PRESENT;
  9242. /*
  9243. * Maximum number of netdev Tx queues:
  9244. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  9245. */
  9246. tx_count = MAX_TXQS_PER_COS * max_cos_est + FCOE_PRESENT;
  9247. /* dev zeroed in init_etherdev */
  9248. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  9249. if (!dev)
  9250. return -ENOMEM;
  9251. bp = netdev_priv(dev);
  9252. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  9253. tx_count, rx_count);
  9254. bp->igu_sb_cnt = max_non_def_sbs;
  9255. bp->msg_enable = debug;
  9256. pci_set_drvdata(pdev, dev);
  9257. rc = bnx2x_init_dev(pdev, dev, ent->driver_data);
  9258. if (rc < 0) {
  9259. free_netdev(dev);
  9260. return rc;
  9261. }
  9262. BNX2X_DEV_INFO("max_non_def_sbs %d\n", max_non_def_sbs);
  9263. rc = bnx2x_init_bp(bp);
  9264. if (rc)
  9265. goto init_one_exit;
  9266. /*
  9267. * Map doorbels here as we need the real value of bp->max_cos which
  9268. * is initialized in bnx2x_init_bp().
  9269. */
  9270. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  9271. min_t(u64, BNX2X_DB_SIZE(bp),
  9272. pci_resource_len(pdev, 2)));
  9273. if (!bp->doorbells) {
  9274. dev_err(&bp->pdev->dev,
  9275. "Cannot map doorbell space, aborting\n");
  9276. rc = -ENOMEM;
  9277. goto init_one_exit;
  9278. }
  9279. /* calc qm_cid_count */
  9280. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  9281. #ifdef BCM_CNIC
  9282. /* disable FCOE L2 queue for E1x */
  9283. if (CHIP_IS_E1x(bp))
  9284. bp->flags |= NO_FCOE_FLAG;
  9285. #endif
  9286. /* Configure interrupt mode: try to enable MSI-X/MSI if
  9287. * needed, set bp->num_queues appropriately.
  9288. */
  9289. bnx2x_set_int_mode(bp);
  9290. /* Add all NAPI objects */
  9291. bnx2x_add_all_napi(bp);
  9292. rc = register_netdev(dev);
  9293. if (rc) {
  9294. dev_err(&pdev->dev, "Cannot register net device\n");
  9295. goto init_one_exit;
  9296. }
  9297. #ifdef BCM_CNIC
  9298. if (!NO_FCOE(bp)) {
  9299. /* Add storage MAC address */
  9300. rtnl_lock();
  9301. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9302. rtnl_unlock();
  9303. }
  9304. #endif
  9305. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  9306. BNX2X_DEV_INFO(
  9307. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  9308. board_info[ent->driver_data].name,
  9309. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  9310. pcie_width,
  9311. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  9312. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  9313. "5GHz (Gen2)" : "2.5GHz",
  9314. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  9315. return 0;
  9316. init_one_exit:
  9317. if (bp->regview)
  9318. iounmap(bp->regview);
  9319. if (bp->doorbells)
  9320. iounmap(bp->doorbells);
  9321. free_netdev(dev);
  9322. if (atomic_read(&pdev->enable_cnt) == 1)
  9323. pci_release_regions(pdev);
  9324. pci_disable_device(pdev);
  9325. pci_set_drvdata(pdev, NULL);
  9326. return rc;
  9327. }
  9328. static void __devexit bnx2x_remove_one(struct pci_dev *pdev)
  9329. {
  9330. struct net_device *dev = pci_get_drvdata(pdev);
  9331. struct bnx2x *bp;
  9332. if (!dev) {
  9333. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  9334. return;
  9335. }
  9336. bp = netdev_priv(dev);
  9337. #ifdef BCM_CNIC
  9338. /* Delete storage MAC address */
  9339. if (!NO_FCOE(bp)) {
  9340. rtnl_lock();
  9341. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  9342. rtnl_unlock();
  9343. }
  9344. #endif
  9345. #ifdef BCM_DCBNL
  9346. /* Delete app tlvs from dcbnl */
  9347. bnx2x_dcbnl_update_applist(bp, true);
  9348. #endif
  9349. unregister_netdev(dev);
  9350. /* Delete all NAPI objects */
  9351. bnx2x_del_all_napi(bp);
  9352. /* Power on: we can't let PCI layer write to us while we are in D3 */
  9353. bnx2x_set_power_state(bp, PCI_D0);
  9354. /* Disable MSI/MSI-X */
  9355. bnx2x_disable_msi(bp);
  9356. /* Power off */
  9357. bnx2x_set_power_state(bp, PCI_D3hot);
  9358. /* Make sure RESET task is not scheduled before continuing */
  9359. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  9360. if (bp->regview)
  9361. iounmap(bp->regview);
  9362. if (bp->doorbells)
  9363. iounmap(bp->doorbells);
  9364. bnx2x_release_firmware(bp);
  9365. bnx2x_free_mem_bp(bp);
  9366. free_netdev(dev);
  9367. if (atomic_read(&pdev->enable_cnt) == 1)
  9368. pci_release_regions(pdev);
  9369. pci_disable_device(pdev);
  9370. pci_set_drvdata(pdev, NULL);
  9371. }
  9372. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  9373. {
  9374. int i;
  9375. bp->state = BNX2X_STATE_ERROR;
  9376. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9377. #ifdef BCM_CNIC
  9378. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  9379. #endif
  9380. /* Stop Tx */
  9381. bnx2x_tx_disable(bp);
  9382. bnx2x_netif_stop(bp, 0);
  9383. del_timer_sync(&bp->timer);
  9384. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  9385. /* Release IRQs */
  9386. bnx2x_free_irq(bp);
  9387. /* Free SKBs, SGEs, TPA pool and driver internals */
  9388. bnx2x_free_skbs(bp);
  9389. for_each_rx_queue(bp, i)
  9390. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  9391. bnx2x_free_mem(bp);
  9392. bp->state = BNX2X_STATE_CLOSED;
  9393. netif_carrier_off(bp->dev);
  9394. return 0;
  9395. }
  9396. static void bnx2x_eeh_recover(struct bnx2x *bp)
  9397. {
  9398. u32 val;
  9399. mutex_init(&bp->port.phy_mutex);
  9400. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  9401. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9402. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  9403. BNX2X_ERR("BAD MCP validity signature\n");
  9404. }
  9405. /**
  9406. * bnx2x_io_error_detected - called when PCI error is detected
  9407. * @pdev: Pointer to PCI device
  9408. * @state: The current pci connection state
  9409. *
  9410. * This function is called after a PCI bus error affecting
  9411. * this device has been detected.
  9412. */
  9413. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  9414. pci_channel_state_t state)
  9415. {
  9416. struct net_device *dev = pci_get_drvdata(pdev);
  9417. struct bnx2x *bp = netdev_priv(dev);
  9418. rtnl_lock();
  9419. netif_device_detach(dev);
  9420. if (state == pci_channel_io_perm_failure) {
  9421. rtnl_unlock();
  9422. return PCI_ERS_RESULT_DISCONNECT;
  9423. }
  9424. if (netif_running(dev))
  9425. bnx2x_eeh_nic_unload(bp);
  9426. pci_disable_device(pdev);
  9427. rtnl_unlock();
  9428. /* Request a slot reset */
  9429. return PCI_ERS_RESULT_NEED_RESET;
  9430. }
  9431. /**
  9432. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  9433. * @pdev: Pointer to PCI device
  9434. *
  9435. * Restart the card from scratch, as if from a cold-boot.
  9436. */
  9437. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  9438. {
  9439. struct net_device *dev = pci_get_drvdata(pdev);
  9440. struct bnx2x *bp = netdev_priv(dev);
  9441. rtnl_lock();
  9442. if (pci_enable_device(pdev)) {
  9443. dev_err(&pdev->dev,
  9444. "Cannot re-enable PCI device after reset\n");
  9445. rtnl_unlock();
  9446. return PCI_ERS_RESULT_DISCONNECT;
  9447. }
  9448. pci_set_master(pdev);
  9449. pci_restore_state(pdev);
  9450. if (netif_running(dev))
  9451. bnx2x_set_power_state(bp, PCI_D0);
  9452. rtnl_unlock();
  9453. return PCI_ERS_RESULT_RECOVERED;
  9454. }
  9455. /**
  9456. * bnx2x_io_resume - called when traffic can start flowing again
  9457. * @pdev: Pointer to PCI device
  9458. *
  9459. * This callback is called when the error recovery driver tells us that
  9460. * its OK to resume normal operation.
  9461. */
  9462. static void bnx2x_io_resume(struct pci_dev *pdev)
  9463. {
  9464. struct net_device *dev = pci_get_drvdata(pdev);
  9465. struct bnx2x *bp = netdev_priv(dev);
  9466. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  9467. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  9468. return;
  9469. }
  9470. rtnl_lock();
  9471. bnx2x_eeh_recover(bp);
  9472. if (netif_running(dev))
  9473. bnx2x_nic_load(bp, LOAD_NORMAL);
  9474. netif_device_attach(dev);
  9475. rtnl_unlock();
  9476. }
  9477. static struct pci_error_handlers bnx2x_err_handler = {
  9478. .error_detected = bnx2x_io_error_detected,
  9479. .slot_reset = bnx2x_io_slot_reset,
  9480. .resume = bnx2x_io_resume,
  9481. };
  9482. static struct pci_driver bnx2x_pci_driver = {
  9483. .name = DRV_MODULE_NAME,
  9484. .id_table = bnx2x_pci_tbl,
  9485. .probe = bnx2x_init_one,
  9486. .remove = __devexit_p(bnx2x_remove_one),
  9487. .suspend = bnx2x_suspend,
  9488. .resume = bnx2x_resume,
  9489. .err_handler = &bnx2x_err_handler,
  9490. };
  9491. static int __init bnx2x_init(void)
  9492. {
  9493. int ret;
  9494. pr_info("%s", version);
  9495. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  9496. if (bnx2x_wq == NULL) {
  9497. pr_err("Cannot create workqueue\n");
  9498. return -ENOMEM;
  9499. }
  9500. ret = pci_register_driver(&bnx2x_pci_driver);
  9501. if (ret) {
  9502. pr_err("Cannot register driver\n");
  9503. destroy_workqueue(bnx2x_wq);
  9504. }
  9505. return ret;
  9506. }
  9507. static void __exit bnx2x_cleanup(void)
  9508. {
  9509. pci_unregister_driver(&bnx2x_pci_driver);
  9510. destroy_workqueue(bnx2x_wq);
  9511. }
  9512. void bnx2x_notify_link_changed(struct bnx2x *bp)
  9513. {
  9514. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  9515. }
  9516. module_init(bnx2x_init);
  9517. module_exit(bnx2x_cleanup);
  9518. #ifdef BCM_CNIC
  9519. /**
  9520. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  9521. *
  9522. * @bp: driver handle
  9523. * @set: set or clear the CAM entry
  9524. *
  9525. * This function will wait until the ramdord completion returns.
  9526. * Return 0 if success, -ENODEV if ramrod doesn't return.
  9527. */
  9528. static inline int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  9529. {
  9530. unsigned long ramrod_flags = 0;
  9531. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  9532. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  9533. &bp->iscsi_l2_mac_obj, true,
  9534. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  9535. }
  9536. /* count denotes the number of new completions we have seen */
  9537. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  9538. {
  9539. struct eth_spe *spe;
  9540. #ifdef BNX2X_STOP_ON_ERROR
  9541. if (unlikely(bp->panic))
  9542. return;
  9543. #endif
  9544. spin_lock_bh(&bp->spq_lock);
  9545. BUG_ON(bp->cnic_spq_pending < count);
  9546. bp->cnic_spq_pending -= count;
  9547. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  9548. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  9549. & SPE_HDR_CONN_TYPE) >>
  9550. SPE_HDR_CONN_TYPE_SHIFT;
  9551. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  9552. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  9553. /* Set validation for iSCSI L2 client before sending SETUP
  9554. * ramrod
  9555. */
  9556. if (type == ETH_CONNECTION_TYPE) {
  9557. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP)
  9558. bnx2x_set_ctx_validation(bp, &bp->context.
  9559. vcxt[BNX2X_ISCSI_ETH_CID].eth,
  9560. BNX2X_ISCSI_ETH_CID);
  9561. }
  9562. /*
  9563. * There may be not more than 8 L2, not more than 8 L5 SPEs
  9564. * and in the air. We also check that number of outstanding
  9565. * COMMON ramrods is not more than the EQ and SPQ can
  9566. * accommodate.
  9567. */
  9568. if (type == ETH_CONNECTION_TYPE) {
  9569. if (!atomic_read(&bp->cq_spq_left))
  9570. break;
  9571. else
  9572. atomic_dec(&bp->cq_spq_left);
  9573. } else if (type == NONE_CONNECTION_TYPE) {
  9574. if (!atomic_read(&bp->eq_spq_left))
  9575. break;
  9576. else
  9577. atomic_dec(&bp->eq_spq_left);
  9578. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  9579. (type == FCOE_CONNECTION_TYPE)) {
  9580. if (bp->cnic_spq_pending >=
  9581. bp->cnic_eth_dev.max_kwqe_pending)
  9582. break;
  9583. else
  9584. bp->cnic_spq_pending++;
  9585. } else {
  9586. BNX2X_ERR("Unknown SPE type: %d\n", type);
  9587. bnx2x_panic();
  9588. break;
  9589. }
  9590. spe = bnx2x_sp_get_next(bp);
  9591. *spe = *bp->cnic_kwq_cons;
  9592. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  9593. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  9594. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  9595. bp->cnic_kwq_cons = bp->cnic_kwq;
  9596. else
  9597. bp->cnic_kwq_cons++;
  9598. }
  9599. bnx2x_sp_prod_update(bp);
  9600. spin_unlock_bh(&bp->spq_lock);
  9601. }
  9602. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  9603. struct kwqe_16 *kwqes[], u32 count)
  9604. {
  9605. struct bnx2x *bp = netdev_priv(dev);
  9606. int i;
  9607. #ifdef BNX2X_STOP_ON_ERROR
  9608. if (unlikely(bp->panic)) {
  9609. BNX2X_ERR("Can't post to SP queue while panic\n");
  9610. return -EIO;
  9611. }
  9612. #endif
  9613. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  9614. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  9615. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  9616. return -EAGAIN;
  9617. }
  9618. spin_lock_bh(&bp->spq_lock);
  9619. for (i = 0; i < count; i++) {
  9620. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  9621. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  9622. break;
  9623. *bp->cnic_kwq_prod = *spe;
  9624. bp->cnic_kwq_pending++;
  9625. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  9626. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  9627. spe->data.update_data_addr.hi,
  9628. spe->data.update_data_addr.lo,
  9629. bp->cnic_kwq_pending);
  9630. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  9631. bp->cnic_kwq_prod = bp->cnic_kwq;
  9632. else
  9633. bp->cnic_kwq_prod++;
  9634. }
  9635. spin_unlock_bh(&bp->spq_lock);
  9636. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  9637. bnx2x_cnic_sp_post(bp, 0);
  9638. return i;
  9639. }
  9640. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9641. {
  9642. struct cnic_ops *c_ops;
  9643. int rc = 0;
  9644. mutex_lock(&bp->cnic_mutex);
  9645. c_ops = rcu_dereference_protected(bp->cnic_ops,
  9646. lockdep_is_held(&bp->cnic_mutex));
  9647. if (c_ops)
  9648. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9649. mutex_unlock(&bp->cnic_mutex);
  9650. return rc;
  9651. }
  9652. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  9653. {
  9654. struct cnic_ops *c_ops;
  9655. int rc = 0;
  9656. rcu_read_lock();
  9657. c_ops = rcu_dereference(bp->cnic_ops);
  9658. if (c_ops)
  9659. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  9660. rcu_read_unlock();
  9661. return rc;
  9662. }
  9663. /*
  9664. * for commands that have no data
  9665. */
  9666. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  9667. {
  9668. struct cnic_ctl_info ctl = {0};
  9669. ctl.cmd = cmd;
  9670. return bnx2x_cnic_ctl_send(bp, &ctl);
  9671. }
  9672. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  9673. {
  9674. struct cnic_ctl_info ctl = {0};
  9675. /* first we tell CNIC and only then we count this as a completion */
  9676. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  9677. ctl.data.comp.cid = cid;
  9678. ctl.data.comp.error = err;
  9679. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  9680. bnx2x_cnic_sp_post(bp, 0);
  9681. }
  9682. /* Called with netif_addr_lock_bh() taken.
  9683. * Sets an rx_mode config for an iSCSI ETH client.
  9684. * Doesn't block.
  9685. * Completion should be checked outside.
  9686. */
  9687. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  9688. {
  9689. unsigned long accept_flags = 0, ramrod_flags = 0;
  9690. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9691. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  9692. if (start) {
  9693. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  9694. * because it's the only way for UIO Queue to accept
  9695. * multicasts (in non-promiscuous mode only one Queue per
  9696. * function will receive multicast packets (leading in our
  9697. * case).
  9698. */
  9699. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  9700. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  9701. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  9702. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  9703. /* Clear STOP_PENDING bit if START is requested */
  9704. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  9705. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  9706. } else
  9707. /* Clear START_PENDING bit if STOP is requested */
  9708. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  9709. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  9710. set_bit(sched_state, &bp->sp_state);
  9711. else {
  9712. __set_bit(RAMROD_RX, &ramrod_flags);
  9713. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  9714. ramrod_flags);
  9715. }
  9716. }
  9717. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  9718. {
  9719. struct bnx2x *bp = netdev_priv(dev);
  9720. int rc = 0;
  9721. switch (ctl->cmd) {
  9722. case DRV_CTL_CTXTBL_WR_CMD: {
  9723. u32 index = ctl->data.io.offset;
  9724. dma_addr_t addr = ctl->data.io.dma_addr;
  9725. bnx2x_ilt_wr(bp, index, addr);
  9726. break;
  9727. }
  9728. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  9729. int count = ctl->data.credit.credit_count;
  9730. bnx2x_cnic_sp_post(bp, count);
  9731. break;
  9732. }
  9733. /* rtnl_lock is held. */
  9734. case DRV_CTL_START_L2_CMD: {
  9735. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9736. unsigned long sp_bits = 0;
  9737. /* Configure the iSCSI classification object */
  9738. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  9739. cp->iscsi_l2_client_id,
  9740. cp->iscsi_l2_cid, BP_FUNC(bp),
  9741. bnx2x_sp(bp, mac_rdata),
  9742. bnx2x_sp_mapping(bp, mac_rdata),
  9743. BNX2X_FILTER_MAC_PENDING,
  9744. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  9745. &bp->macs_pool);
  9746. /* Set iSCSI MAC address */
  9747. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  9748. if (rc)
  9749. break;
  9750. mmiowb();
  9751. barrier();
  9752. /* Start accepting on iSCSI L2 ring */
  9753. netif_addr_lock_bh(dev);
  9754. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  9755. netif_addr_unlock_bh(dev);
  9756. /* bits to wait on */
  9757. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9758. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  9759. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9760. BNX2X_ERR("rx_mode completion timed out!\n");
  9761. break;
  9762. }
  9763. /* rtnl_lock is held. */
  9764. case DRV_CTL_STOP_L2_CMD: {
  9765. unsigned long sp_bits = 0;
  9766. /* Stop accepting on iSCSI L2 ring */
  9767. netif_addr_lock_bh(dev);
  9768. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  9769. netif_addr_unlock_bh(dev);
  9770. /* bits to wait on */
  9771. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  9772. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  9773. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  9774. BNX2X_ERR("rx_mode completion timed out!\n");
  9775. mmiowb();
  9776. barrier();
  9777. /* Unset iSCSI L2 MAC */
  9778. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  9779. BNX2X_ISCSI_ETH_MAC, true);
  9780. break;
  9781. }
  9782. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  9783. int count = ctl->data.credit.credit_count;
  9784. smp_mb__before_atomic_inc();
  9785. atomic_add(count, &bp->cq_spq_left);
  9786. smp_mb__after_atomic_inc();
  9787. break;
  9788. }
  9789. case DRV_CTL_ULP_REGISTER_CMD: {
  9790. int ulp_type = ctl->data.ulp_type;
  9791. if (CHIP_IS_E3(bp)) {
  9792. int idx = BP_FW_MB_IDX(bp);
  9793. u32 cap;
  9794. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  9795. if (ulp_type == CNIC_ULP_ISCSI)
  9796. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  9797. else if (ulp_type == CNIC_ULP_FCOE)
  9798. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  9799. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  9800. }
  9801. break;
  9802. }
  9803. case DRV_CTL_ULP_UNREGISTER_CMD: {
  9804. int ulp_type = ctl->data.ulp_type;
  9805. if (CHIP_IS_E3(bp)) {
  9806. int idx = BP_FW_MB_IDX(bp);
  9807. u32 cap;
  9808. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  9809. if (ulp_type == CNIC_ULP_ISCSI)
  9810. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  9811. else if (ulp_type == CNIC_ULP_FCOE)
  9812. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  9813. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  9814. }
  9815. break;
  9816. }
  9817. default:
  9818. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  9819. rc = -EINVAL;
  9820. }
  9821. return rc;
  9822. }
  9823. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  9824. {
  9825. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9826. if (bp->flags & USING_MSIX_FLAG) {
  9827. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  9828. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  9829. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  9830. } else {
  9831. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  9832. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  9833. }
  9834. if (!CHIP_IS_E1x(bp))
  9835. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  9836. else
  9837. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  9838. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  9839. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  9840. cp->irq_arr[1].status_blk = bp->def_status_blk;
  9841. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  9842. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  9843. cp->num_irq = 2;
  9844. }
  9845. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  9846. void *data)
  9847. {
  9848. struct bnx2x *bp = netdev_priv(dev);
  9849. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9850. if (ops == NULL) {
  9851. BNX2X_ERR("NULL ops received\n");
  9852. return -EINVAL;
  9853. }
  9854. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  9855. if (!bp->cnic_kwq)
  9856. return -ENOMEM;
  9857. bp->cnic_kwq_cons = bp->cnic_kwq;
  9858. bp->cnic_kwq_prod = bp->cnic_kwq;
  9859. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  9860. bp->cnic_spq_pending = 0;
  9861. bp->cnic_kwq_pending = 0;
  9862. bp->cnic_data = data;
  9863. cp->num_irq = 0;
  9864. cp->drv_state |= CNIC_DRV_STATE_REGD;
  9865. cp->iro_arr = bp->iro_arr;
  9866. bnx2x_setup_cnic_irq_info(bp);
  9867. rcu_assign_pointer(bp->cnic_ops, ops);
  9868. return 0;
  9869. }
  9870. static int bnx2x_unregister_cnic(struct net_device *dev)
  9871. {
  9872. struct bnx2x *bp = netdev_priv(dev);
  9873. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9874. mutex_lock(&bp->cnic_mutex);
  9875. cp->drv_state = 0;
  9876. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  9877. mutex_unlock(&bp->cnic_mutex);
  9878. synchronize_rcu();
  9879. kfree(bp->cnic_kwq);
  9880. bp->cnic_kwq = NULL;
  9881. return 0;
  9882. }
  9883. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  9884. {
  9885. struct bnx2x *bp = netdev_priv(dev);
  9886. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  9887. /* If both iSCSI and FCoE are disabled - return NULL in
  9888. * order to indicate CNIC that it should not try to work
  9889. * with this device.
  9890. */
  9891. if (NO_ISCSI(bp) && NO_FCOE(bp))
  9892. return NULL;
  9893. cp->drv_owner = THIS_MODULE;
  9894. cp->chip_id = CHIP_ID(bp);
  9895. cp->pdev = bp->pdev;
  9896. cp->io_base = bp->regview;
  9897. cp->io_base2 = bp->doorbells;
  9898. cp->max_kwqe_pending = 8;
  9899. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  9900. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  9901. bnx2x_cid_ilt_lines(bp);
  9902. cp->ctx_tbl_len = CNIC_ILT_LINES;
  9903. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  9904. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  9905. cp->drv_ctl = bnx2x_drv_ctl;
  9906. cp->drv_register_cnic = bnx2x_register_cnic;
  9907. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  9908. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID;
  9909. cp->iscsi_l2_client_id =
  9910. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  9911. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID;
  9912. if (NO_ISCSI_OOO(bp))
  9913. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  9914. if (NO_ISCSI(bp))
  9915. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  9916. if (NO_FCOE(bp))
  9917. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  9918. BNX2X_DEV_INFO(
  9919. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  9920. cp->ctx_blk_size,
  9921. cp->ctx_tbl_offset,
  9922. cp->ctx_tbl_len,
  9923. cp->starting_cid);
  9924. return cp;
  9925. }
  9926. EXPORT_SYMBOL(bnx2x_cnic_probe);
  9927. #endif /* BCM_CNIC */