bnx2x_main.c 338 KB

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