bnx2x_main.c 308 KB

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