bnx2x_main.c 305 KB

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