bnx2x_main.c 306 KB

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