bnx2x_main.c 362 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434
  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_vfpf.h"
  60. #include "bnx2x_dcb.h"
  61. #include "bnx2x_sp.h"
  62. #include <linux/firmware.h>
  63. #include "bnx2x_fw_file_hdr.h"
  64. /* FW files */
  65. #define FW_FILE_VERSION \
  66. __stringify(BCM_5710_FW_MAJOR_VERSION) "." \
  67. __stringify(BCM_5710_FW_MINOR_VERSION) "." \
  68. __stringify(BCM_5710_FW_REVISION_VERSION) "." \
  69. __stringify(BCM_5710_FW_ENGINEERING_VERSION)
  70. #define FW_FILE_NAME_E1 "bnx2x/bnx2x-e1-" FW_FILE_VERSION ".fw"
  71. #define FW_FILE_NAME_E1H "bnx2x/bnx2x-e1h-" FW_FILE_VERSION ".fw"
  72. #define FW_FILE_NAME_E2 "bnx2x/bnx2x-e2-" FW_FILE_VERSION ".fw"
  73. #define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
  74. /* Time in jiffies before concluding the transmitter is hung */
  75. #define TX_TIMEOUT (5*HZ)
  76. static char version[] =
  77. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  78. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  79. MODULE_AUTHOR("Eliezer Tamir");
  80. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  81. "BCM57710/57711/57711E/"
  82. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  83. "57840/57840_MF Driver");
  84. MODULE_LICENSE("GPL");
  85. MODULE_VERSION(DRV_MODULE_VERSION);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  88. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  89. int num_queues;
  90. module_param(num_queues, int, 0);
  91. MODULE_PARM_DESC(num_queues,
  92. " Set number of queues (default is as a number of CPUs)");
  93. static int disable_tpa;
  94. module_param(disable_tpa, int, 0);
  95. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  96. #define INT_MODE_INTx 1
  97. #define INT_MODE_MSI 2
  98. int int_mode;
  99. module_param(int_mode, int, 0);
  100. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  101. "(1 INT#x; 2 MSI)");
  102. static int dropless_fc;
  103. module_param(dropless_fc, int, 0);
  104. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  105. static int mrrs = -1;
  106. module_param(mrrs, int, 0);
  107. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  108. static int debug;
  109. module_param(debug, int, 0);
  110. MODULE_PARM_DESC(debug, " Default debug msglevel");
  111. struct workqueue_struct *bnx2x_wq;
  112. struct bnx2x_mac_vals {
  113. u32 xmac_addr;
  114. u32 xmac_val;
  115. u32 emac_addr;
  116. u32 emac_val;
  117. u32 umac_addr;
  118. u32 umac_val;
  119. u32 bmac_addr;
  120. u32 bmac_val[2];
  121. };
  122. enum bnx2x_board_type {
  123. BCM57710 = 0,
  124. BCM57711,
  125. BCM57711E,
  126. BCM57712,
  127. BCM57712_MF,
  128. BCM57712_VF,
  129. BCM57800,
  130. BCM57800_MF,
  131. BCM57800_VF,
  132. BCM57810,
  133. BCM57810_MF,
  134. BCM57810_VF,
  135. BCM57840_4_10,
  136. BCM57840_2_20,
  137. BCM57840_MF,
  138. BCM57840_VF,
  139. BCM57811,
  140. BCM57811_MF,
  141. BCM57840_O,
  142. BCM57840_MFO,
  143. BCM57811_VF
  144. };
  145. /* indexed by board_type, above */
  146. static struct {
  147. char *name;
  148. } board_info[] = {
  149. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  150. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  151. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  152. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  153. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  154. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  156. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  157. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  159. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  160. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  161. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  162. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  163. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  164. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  165. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  166. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  167. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  168. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  169. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  170. };
  171. #ifndef PCI_DEVICE_ID_NX2_57710
  172. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711
  175. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57711E
  178. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712
  181. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  184. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  187. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800
  190. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  193. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  196. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810
  199. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  202. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57840_O
  205. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  208. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  211. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  214. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  217. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  220. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  223. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811
  226. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  229. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  230. #endif
  231. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  232. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  233. #endif
  234. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  253. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  254. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  255. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  256. { 0 }
  257. };
  258. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  259. /* Global resources for unloading a previously loaded device */
  260. #define BNX2X_PREV_WAIT_NEEDED 1
  261. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  262. static LIST_HEAD(bnx2x_prev_list);
  263. /****************************************************************************
  264. * General service functions
  265. ****************************************************************************/
  266. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  267. u32 addr, dma_addr_t mapping)
  268. {
  269. REG_WR(bp, addr, U64_LO(mapping));
  270. REG_WR(bp, addr + 4, U64_HI(mapping));
  271. }
  272. static void storm_memset_spq_addr(struct bnx2x *bp,
  273. dma_addr_t mapping, u16 abs_fid)
  274. {
  275. u32 addr = XSEM_REG_FAST_MEMORY +
  276. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  277. __storm_memset_dma_mapping(bp, addr, mapping);
  278. }
  279. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  280. u16 pf_id)
  281. {
  282. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  283. pf_id);
  284. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  285. pf_id);
  286. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  287. pf_id);
  288. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  289. pf_id);
  290. }
  291. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  292. u8 enable)
  293. {
  294. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  295. enable);
  296. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  297. enable);
  298. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  299. enable);
  300. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  301. enable);
  302. }
  303. static void storm_memset_eq_data(struct bnx2x *bp,
  304. struct event_ring_data *eq_data,
  305. u16 pfid)
  306. {
  307. size_t size = sizeof(struct event_ring_data);
  308. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  309. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  310. }
  311. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  312. u16 pfid)
  313. {
  314. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  315. REG_WR16(bp, addr, eq_prod);
  316. }
  317. /* used only at init
  318. * locking is done by mcp
  319. */
  320. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  321. {
  322. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  323. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  324. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  325. PCICFG_VENDOR_ID_OFFSET);
  326. }
  327. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  328. {
  329. u32 val;
  330. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  331. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  332. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  333. PCICFG_VENDOR_ID_OFFSET);
  334. return val;
  335. }
  336. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  337. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  338. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  339. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  340. #define DMAE_DP_DST_NONE "dst_addr [none]"
  341. void bnx2x_dp_dmae(struct bnx2x *bp, struct dmae_command *dmae, int msglvl)
  342. {
  343. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  344. switch (dmae->opcode & DMAE_COMMAND_DST) {
  345. case DMAE_CMD_DST_PCI:
  346. if (src_type == DMAE_CMD_SRC_PCI)
  347. DP(msglvl, "DMAE: opcode 0x%08x\n"
  348. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  349. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  350. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  351. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  352. dmae->comp_addr_hi, dmae->comp_addr_lo,
  353. dmae->comp_val);
  354. else
  355. DP(msglvl, "DMAE: opcode 0x%08x\n"
  356. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  357. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  358. dmae->opcode, dmae->src_addr_lo >> 2,
  359. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  360. dmae->comp_addr_hi, dmae->comp_addr_lo,
  361. dmae->comp_val);
  362. break;
  363. case DMAE_CMD_DST_GRC:
  364. if (src_type == DMAE_CMD_SRC_PCI)
  365. DP(msglvl, "DMAE: opcode 0x%08x\n"
  366. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  367. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  368. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  369. dmae->len, dmae->dst_addr_lo >> 2,
  370. dmae->comp_addr_hi, dmae->comp_addr_lo,
  371. dmae->comp_val);
  372. else
  373. DP(msglvl, "DMAE: opcode 0x%08x\n"
  374. "src [%08x], len [%d*4], dst [%08x]\n"
  375. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  376. dmae->opcode, dmae->src_addr_lo >> 2,
  377. dmae->len, dmae->dst_addr_lo >> 2,
  378. dmae->comp_addr_hi, dmae->comp_addr_lo,
  379. dmae->comp_val);
  380. break;
  381. default:
  382. if (src_type == DMAE_CMD_SRC_PCI)
  383. DP(msglvl, "DMAE: opcode 0x%08x\n"
  384. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  385. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  386. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  387. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  388. dmae->comp_val);
  389. else
  390. DP(msglvl, "DMAE: opcode 0x%08x\n"
  391. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  392. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  393. dmae->opcode, dmae->src_addr_lo >> 2,
  394. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  395. dmae->comp_val);
  396. break;
  397. }
  398. }
  399. /* copy command into DMAE command memory and set DMAE command go */
  400. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  401. {
  402. u32 cmd_offset;
  403. int i;
  404. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  405. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  406. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  407. }
  408. REG_WR(bp, dmae_reg_go_c[idx], 1);
  409. }
  410. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  411. {
  412. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  413. DMAE_CMD_C_ENABLE);
  414. }
  415. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  416. {
  417. return opcode & ~DMAE_CMD_SRC_RESET;
  418. }
  419. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  420. bool with_comp, u8 comp_type)
  421. {
  422. u32 opcode = 0;
  423. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  424. (dst_type << DMAE_COMMAND_DST_SHIFT));
  425. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  426. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  427. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  428. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  429. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  430. #ifdef __BIG_ENDIAN
  431. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  432. #else
  433. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  434. #endif
  435. if (with_comp)
  436. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  437. return opcode;
  438. }
  439. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  440. struct dmae_command *dmae,
  441. u8 src_type, u8 dst_type)
  442. {
  443. memset(dmae, 0, sizeof(struct dmae_command));
  444. /* set the opcode */
  445. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  446. true, DMAE_COMP_PCI);
  447. /* fill in the completion parameters */
  448. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  449. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  450. dmae->comp_val = DMAE_COMP_VAL;
  451. }
  452. /* issue a dmae command over the init-channel and wait for completion */
  453. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  454. {
  455. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  456. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  457. int rc = 0;
  458. /*
  459. * Lock the dmae channel. Disable BHs to prevent a dead-lock
  460. * as long as this code is called both from syscall context and
  461. * from ndo_set_rx_mode() flow that may be called from BH.
  462. */
  463. spin_lock_bh(&bp->dmae_lock);
  464. /* reset completion */
  465. *wb_comp = 0;
  466. /* post the command on the channel used for initializations */
  467. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  468. /* wait for completion */
  469. udelay(5);
  470. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  471. if (!cnt ||
  472. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  473. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  474. BNX2X_ERR("DMAE timeout!\n");
  475. rc = DMAE_TIMEOUT;
  476. goto unlock;
  477. }
  478. cnt--;
  479. udelay(50);
  480. }
  481. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  482. BNX2X_ERR("DMAE PCI error!\n");
  483. rc = DMAE_PCI_ERROR;
  484. }
  485. unlock:
  486. spin_unlock_bh(&bp->dmae_lock);
  487. return rc;
  488. }
  489. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  490. u32 len32)
  491. {
  492. struct dmae_command dmae;
  493. if (!bp->dmae_ready) {
  494. u32 *data = bnx2x_sp(bp, wb_data[0]);
  495. if (CHIP_IS_E1(bp))
  496. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  497. else
  498. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  499. return;
  500. }
  501. /* set opcode and fixed command fields */
  502. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  503. /* fill in addresses and len */
  504. dmae.src_addr_lo = U64_LO(dma_addr);
  505. dmae.src_addr_hi = U64_HI(dma_addr);
  506. dmae.dst_addr_lo = dst_addr >> 2;
  507. dmae.dst_addr_hi = 0;
  508. dmae.len = len32;
  509. /* issue the command and wait for completion */
  510. bnx2x_issue_dmae_with_comp(bp, &dmae);
  511. }
  512. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  513. {
  514. struct dmae_command dmae;
  515. if (!bp->dmae_ready) {
  516. u32 *data = bnx2x_sp(bp, wb_data[0]);
  517. int i;
  518. if (CHIP_IS_E1(bp))
  519. for (i = 0; i < len32; i++)
  520. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  521. else
  522. for (i = 0; i < len32; i++)
  523. data[i] = REG_RD(bp, src_addr + i*4);
  524. return;
  525. }
  526. /* set opcode and fixed command fields */
  527. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  528. /* fill in addresses and len */
  529. dmae.src_addr_lo = src_addr >> 2;
  530. dmae.src_addr_hi = 0;
  531. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  532. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  533. dmae.len = len32;
  534. /* issue the command and wait for completion */
  535. bnx2x_issue_dmae_with_comp(bp, &dmae);
  536. }
  537. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  538. u32 addr, u32 len)
  539. {
  540. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  541. int offset = 0;
  542. while (len > dmae_wr_max) {
  543. bnx2x_write_dmae(bp, phys_addr + offset,
  544. addr + offset, dmae_wr_max);
  545. offset += dmae_wr_max * 4;
  546. len -= dmae_wr_max;
  547. }
  548. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  549. }
  550. static int bnx2x_mc_assert(struct bnx2x *bp)
  551. {
  552. char last_idx;
  553. int i, rc = 0;
  554. u32 row0, row1, row2, row3;
  555. /* XSTORM */
  556. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  557. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  558. if (last_idx)
  559. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  560. /* print the asserts */
  561. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  562. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  563. XSTORM_ASSERT_LIST_OFFSET(i));
  564. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  565. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  566. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  567. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  568. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  570. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  571. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  572. i, row3, row2, row1, row0);
  573. rc++;
  574. } else {
  575. break;
  576. }
  577. }
  578. /* TSTORM */
  579. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  580. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  581. if (last_idx)
  582. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  583. /* print the asserts */
  584. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  585. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  586. TSTORM_ASSERT_LIST_OFFSET(i));
  587. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  588. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  589. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  590. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  591. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  593. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  594. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  595. i, row3, row2, row1, row0);
  596. rc++;
  597. } else {
  598. break;
  599. }
  600. }
  601. /* CSTORM */
  602. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  603. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  604. if (last_idx)
  605. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  606. /* print the asserts */
  607. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  608. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  609. CSTORM_ASSERT_LIST_OFFSET(i));
  610. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  611. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  612. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  613. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  614. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  616. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  617. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  618. i, row3, row2, row1, row0);
  619. rc++;
  620. } else {
  621. break;
  622. }
  623. }
  624. /* USTORM */
  625. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  626. USTORM_ASSERT_LIST_INDEX_OFFSET);
  627. if (last_idx)
  628. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  629. /* print the asserts */
  630. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  631. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  632. USTORM_ASSERT_LIST_OFFSET(i));
  633. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  634. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  635. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  636. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  637. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  639. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  640. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  641. i, row3, row2, row1, row0);
  642. rc++;
  643. } else {
  644. break;
  645. }
  646. }
  647. return rc;
  648. }
  649. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  650. {
  651. u32 addr, val;
  652. u32 mark, offset;
  653. __be32 data[9];
  654. int word;
  655. u32 trace_shmem_base;
  656. if (BP_NOMCP(bp)) {
  657. BNX2X_ERR("NO MCP - can not dump\n");
  658. return;
  659. }
  660. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  661. (bp->common.bc_ver & 0xff0000) >> 16,
  662. (bp->common.bc_ver & 0xff00) >> 8,
  663. (bp->common.bc_ver & 0xff));
  664. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  665. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  666. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  667. if (BP_PATH(bp) == 0)
  668. trace_shmem_base = bp->common.shmem_base;
  669. else
  670. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  671. addr = trace_shmem_base - 0x800;
  672. /* validate TRCB signature */
  673. mark = REG_RD(bp, addr);
  674. if (mark != MFW_TRACE_SIGNATURE) {
  675. BNX2X_ERR("Trace buffer signature is missing.");
  676. return ;
  677. }
  678. /* read cyclic buffer pointer */
  679. addr += 4;
  680. mark = REG_RD(bp, addr);
  681. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  682. + ((mark + 0x3) & ~0x3) - 0x08000000;
  683. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  684. printk("%s", lvl);
  685. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  686. for (word = 0; word < 8; word++)
  687. data[word] = htonl(REG_RD(bp, offset + 4*word));
  688. data[8] = 0x0;
  689. pr_cont("%s", (char *)data);
  690. }
  691. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  692. for (word = 0; word < 8; word++)
  693. data[word] = htonl(REG_RD(bp, offset + 4*word));
  694. data[8] = 0x0;
  695. pr_cont("%s", (char *)data);
  696. }
  697. printk("%s" "end of fw dump\n", lvl);
  698. }
  699. static void bnx2x_fw_dump(struct bnx2x *bp)
  700. {
  701. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  702. }
  703. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  704. {
  705. int port = BP_PORT(bp);
  706. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  707. u32 val = REG_RD(bp, addr);
  708. /* in E1 we must use only PCI configuration space to disable
  709. * MSI/MSIX capablility
  710. * It's forbitten to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  711. */
  712. if (CHIP_IS_E1(bp)) {
  713. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  714. * Use mask register to prevent from HC sending interrupts
  715. * after we exit the function
  716. */
  717. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  718. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  719. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  720. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  721. } else
  722. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  723. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  724. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  725. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  726. DP(NETIF_MSG_IFDOWN,
  727. "write %x to HC %d (addr 0x%x)\n",
  728. val, port, addr);
  729. /* flush all outstanding writes */
  730. mmiowb();
  731. REG_WR(bp, addr, val);
  732. if (REG_RD(bp, addr) != val)
  733. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  734. }
  735. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  736. {
  737. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  738. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  739. IGU_PF_CONF_INT_LINE_EN |
  740. IGU_PF_CONF_ATTN_BIT_EN);
  741. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  742. /* flush all outstanding writes */
  743. mmiowb();
  744. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  745. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  746. BNX2X_ERR("BUG! proper val not read from IGU!\n");
  747. }
  748. static void bnx2x_int_disable(struct bnx2x *bp)
  749. {
  750. if (bp->common.int_block == INT_BLOCK_HC)
  751. bnx2x_hc_int_disable(bp);
  752. else
  753. bnx2x_igu_int_disable(bp);
  754. }
  755. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  756. {
  757. int i;
  758. u16 j;
  759. struct hc_sp_status_block_data sp_sb_data;
  760. int func = BP_FUNC(bp);
  761. #ifdef BNX2X_STOP_ON_ERROR
  762. u16 start = 0, end = 0;
  763. u8 cos;
  764. #endif
  765. if (disable_int)
  766. bnx2x_int_disable(bp);
  767. bp->stats_state = STATS_STATE_DISABLED;
  768. bp->eth_stats.unrecoverable_error++;
  769. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  770. BNX2X_ERR("begin crash dump -----------------\n");
  771. /* Indices */
  772. /* Common */
  773. 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",
  774. bp->def_idx, bp->def_att_idx, bp->attn_state,
  775. bp->spq_prod_idx, bp->stats_counter);
  776. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  777. bp->def_status_blk->atten_status_block.attn_bits,
  778. bp->def_status_blk->atten_status_block.attn_bits_ack,
  779. bp->def_status_blk->atten_status_block.status_block_id,
  780. bp->def_status_blk->atten_status_block.attn_bits_index);
  781. BNX2X_ERR(" def (");
  782. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  783. pr_cont("0x%x%s",
  784. bp->def_status_blk->sp_sb.index_values[i],
  785. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  786. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  787. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  788. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  789. i*sizeof(u32));
  790. 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",
  791. sp_sb_data.igu_sb_id,
  792. sp_sb_data.igu_seg_id,
  793. sp_sb_data.p_func.pf_id,
  794. sp_sb_data.p_func.vnic_id,
  795. sp_sb_data.p_func.vf_id,
  796. sp_sb_data.p_func.vf_valid,
  797. sp_sb_data.state);
  798. for_each_eth_queue(bp, i) {
  799. struct bnx2x_fastpath *fp = &bp->fp[i];
  800. int loop;
  801. struct hc_status_block_data_e2 sb_data_e2;
  802. struct hc_status_block_data_e1x sb_data_e1x;
  803. struct hc_status_block_sm *hc_sm_p =
  804. CHIP_IS_E1x(bp) ?
  805. sb_data_e1x.common.state_machine :
  806. sb_data_e2.common.state_machine;
  807. struct hc_index_data *hc_index_p =
  808. CHIP_IS_E1x(bp) ?
  809. sb_data_e1x.index_data :
  810. sb_data_e2.index_data;
  811. u8 data_size, cos;
  812. u32 *sb_data_p;
  813. struct bnx2x_fp_txdata txdata;
  814. /* Rx */
  815. 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",
  816. i, fp->rx_bd_prod, fp->rx_bd_cons,
  817. fp->rx_comp_prod,
  818. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  819. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  820. fp->rx_sge_prod, fp->last_max_sge,
  821. le16_to_cpu(fp->fp_hc_idx));
  822. /* Tx */
  823. for_each_cos_in_tx_queue(fp, cos)
  824. {
  825. txdata = *fp->txdata_ptr[cos];
  826. 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",
  827. i, txdata.tx_pkt_prod,
  828. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  829. txdata.tx_bd_cons,
  830. le16_to_cpu(*txdata.tx_cons_sb));
  831. }
  832. loop = CHIP_IS_E1x(bp) ?
  833. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  834. /* host sb data */
  835. if (IS_FCOE_FP(fp))
  836. continue;
  837. BNX2X_ERR(" run indexes (");
  838. for (j = 0; j < HC_SB_MAX_SM; j++)
  839. pr_cont("0x%x%s",
  840. fp->sb_running_index[j],
  841. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  842. BNX2X_ERR(" indexes (");
  843. for (j = 0; j < loop; j++)
  844. pr_cont("0x%x%s",
  845. fp->sb_index_values[j],
  846. (j == loop - 1) ? ")" : " ");
  847. /* fw sb data */
  848. data_size = CHIP_IS_E1x(bp) ?
  849. sizeof(struct hc_status_block_data_e1x) :
  850. sizeof(struct hc_status_block_data_e2);
  851. data_size /= sizeof(u32);
  852. sb_data_p = CHIP_IS_E1x(bp) ?
  853. (u32 *)&sb_data_e1x :
  854. (u32 *)&sb_data_e2;
  855. /* copy sb data in here */
  856. for (j = 0; j < data_size; j++)
  857. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  858. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  859. j * sizeof(u32));
  860. if (!CHIP_IS_E1x(bp)) {
  861. 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",
  862. sb_data_e2.common.p_func.pf_id,
  863. sb_data_e2.common.p_func.vf_id,
  864. sb_data_e2.common.p_func.vf_valid,
  865. sb_data_e2.common.p_func.vnic_id,
  866. sb_data_e2.common.same_igu_sb_1b,
  867. sb_data_e2.common.state);
  868. } else {
  869. 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",
  870. sb_data_e1x.common.p_func.pf_id,
  871. sb_data_e1x.common.p_func.vf_id,
  872. sb_data_e1x.common.p_func.vf_valid,
  873. sb_data_e1x.common.p_func.vnic_id,
  874. sb_data_e1x.common.same_igu_sb_1b,
  875. sb_data_e1x.common.state);
  876. }
  877. /* SB_SMs data */
  878. for (j = 0; j < HC_SB_MAX_SM; j++) {
  879. 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",
  880. j, hc_sm_p[j].__flags,
  881. hc_sm_p[j].igu_sb_id,
  882. hc_sm_p[j].igu_seg_id,
  883. hc_sm_p[j].time_to_expire,
  884. hc_sm_p[j].timer_value);
  885. }
  886. /* Indecies data */
  887. for (j = 0; j < loop; j++) {
  888. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  889. hc_index_p[j].flags,
  890. hc_index_p[j].timeout);
  891. }
  892. }
  893. #ifdef BNX2X_STOP_ON_ERROR
  894. /* Rings */
  895. /* Rx */
  896. for_each_valid_rx_queue(bp, i) {
  897. struct bnx2x_fastpath *fp = &bp->fp[i];
  898. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  899. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  900. for (j = start; j != end; j = RX_BD(j + 1)) {
  901. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  902. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  903. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  904. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  905. }
  906. start = RX_SGE(fp->rx_sge_prod);
  907. end = RX_SGE(fp->last_max_sge);
  908. for (j = start; j != end; j = RX_SGE(j + 1)) {
  909. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  910. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  911. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  912. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  913. }
  914. start = RCQ_BD(fp->rx_comp_cons - 10);
  915. end = RCQ_BD(fp->rx_comp_cons + 503);
  916. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  917. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  918. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  919. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  920. }
  921. }
  922. /* Tx */
  923. for_each_valid_tx_queue(bp, i) {
  924. struct bnx2x_fastpath *fp = &bp->fp[i];
  925. for_each_cos_in_tx_queue(fp, cos) {
  926. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  927. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  928. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  929. for (j = start; j != end; j = TX_BD(j + 1)) {
  930. struct sw_tx_bd *sw_bd =
  931. &txdata->tx_buf_ring[j];
  932. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  933. i, cos, j, sw_bd->skb,
  934. sw_bd->first_bd);
  935. }
  936. start = TX_BD(txdata->tx_bd_cons - 10);
  937. end = TX_BD(txdata->tx_bd_cons + 254);
  938. for (j = start; j != end; j = TX_BD(j + 1)) {
  939. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  940. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  941. i, cos, j, tx_bd[0], tx_bd[1],
  942. tx_bd[2], tx_bd[3]);
  943. }
  944. }
  945. }
  946. #endif
  947. bnx2x_fw_dump(bp);
  948. bnx2x_mc_assert(bp);
  949. BNX2X_ERR("end crash dump -----------------\n");
  950. }
  951. /*
  952. * FLR Support for E2
  953. *
  954. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  955. * initialization.
  956. */
  957. #define FLR_WAIT_USEC 10000 /* 10 miliseconds */
  958. #define FLR_WAIT_INTERVAL 50 /* usec */
  959. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  960. struct pbf_pN_buf_regs {
  961. int pN;
  962. u32 init_crd;
  963. u32 crd;
  964. u32 crd_freed;
  965. };
  966. struct pbf_pN_cmd_regs {
  967. int pN;
  968. u32 lines_occup;
  969. u32 lines_freed;
  970. };
  971. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  972. struct pbf_pN_buf_regs *regs,
  973. u32 poll_count)
  974. {
  975. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  976. u32 cur_cnt = poll_count;
  977. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  978. crd = crd_start = REG_RD(bp, regs->crd);
  979. init_crd = REG_RD(bp, regs->init_crd);
  980. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  981. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  982. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  983. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  984. (init_crd - crd_start))) {
  985. if (cur_cnt--) {
  986. udelay(FLR_WAIT_INTERVAL);
  987. crd = REG_RD(bp, regs->crd);
  988. crd_freed = REG_RD(bp, regs->crd_freed);
  989. } else {
  990. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  991. regs->pN);
  992. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  993. regs->pN, crd);
  994. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  995. regs->pN, crd_freed);
  996. break;
  997. }
  998. }
  999. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1000. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1001. }
  1002. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1003. struct pbf_pN_cmd_regs *regs,
  1004. u32 poll_count)
  1005. {
  1006. u32 occup, to_free, freed, freed_start;
  1007. u32 cur_cnt = poll_count;
  1008. occup = to_free = REG_RD(bp, regs->lines_occup);
  1009. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1010. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1011. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1012. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1013. if (cur_cnt--) {
  1014. udelay(FLR_WAIT_INTERVAL);
  1015. occup = REG_RD(bp, regs->lines_occup);
  1016. freed = REG_RD(bp, regs->lines_freed);
  1017. } else {
  1018. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1019. regs->pN);
  1020. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1021. regs->pN, occup);
  1022. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1023. regs->pN, freed);
  1024. break;
  1025. }
  1026. }
  1027. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1028. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1029. }
  1030. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1031. u32 expected, u32 poll_count)
  1032. {
  1033. u32 cur_cnt = poll_count;
  1034. u32 val;
  1035. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1036. udelay(FLR_WAIT_INTERVAL);
  1037. return val;
  1038. }
  1039. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1040. char *msg, u32 poll_cnt)
  1041. {
  1042. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1043. if (val != 0) {
  1044. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1045. return 1;
  1046. }
  1047. return 0;
  1048. }
  1049. /* Common routines with VF FLR cleanup */
  1050. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1051. {
  1052. /* adjust polling timeout */
  1053. if (CHIP_REV_IS_EMUL(bp))
  1054. return FLR_POLL_CNT * 2000;
  1055. if (CHIP_REV_IS_FPGA(bp))
  1056. return FLR_POLL_CNT * 120;
  1057. return FLR_POLL_CNT;
  1058. }
  1059. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1060. {
  1061. struct pbf_pN_cmd_regs cmd_regs[] = {
  1062. {0, (CHIP_IS_E3B0(bp)) ?
  1063. PBF_REG_TQ_OCCUPANCY_Q0 :
  1064. PBF_REG_P0_TQ_OCCUPANCY,
  1065. (CHIP_IS_E3B0(bp)) ?
  1066. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1067. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1068. {1, (CHIP_IS_E3B0(bp)) ?
  1069. PBF_REG_TQ_OCCUPANCY_Q1 :
  1070. PBF_REG_P1_TQ_OCCUPANCY,
  1071. (CHIP_IS_E3B0(bp)) ?
  1072. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1073. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1074. {4, (CHIP_IS_E3B0(bp)) ?
  1075. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1076. PBF_REG_P4_TQ_OCCUPANCY,
  1077. (CHIP_IS_E3B0(bp)) ?
  1078. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1079. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1080. };
  1081. struct pbf_pN_buf_regs buf_regs[] = {
  1082. {0, (CHIP_IS_E3B0(bp)) ?
  1083. PBF_REG_INIT_CRD_Q0 :
  1084. PBF_REG_P0_INIT_CRD ,
  1085. (CHIP_IS_E3B0(bp)) ?
  1086. PBF_REG_CREDIT_Q0 :
  1087. PBF_REG_P0_CREDIT,
  1088. (CHIP_IS_E3B0(bp)) ?
  1089. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1090. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1091. {1, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_INIT_CRD_Q1 :
  1093. PBF_REG_P1_INIT_CRD,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_CREDIT_Q1 :
  1096. PBF_REG_P1_CREDIT,
  1097. (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1099. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1100. {4, (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_INIT_CRD_LB_Q :
  1102. PBF_REG_P4_INIT_CRD,
  1103. (CHIP_IS_E3B0(bp)) ?
  1104. PBF_REG_CREDIT_LB_Q :
  1105. PBF_REG_P4_CREDIT,
  1106. (CHIP_IS_E3B0(bp)) ?
  1107. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1108. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1109. };
  1110. int i;
  1111. /* Verify the command queues are flushed P0, P1, P4 */
  1112. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1113. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1114. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1115. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1116. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1117. }
  1118. #define OP_GEN_PARAM(param) \
  1119. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1120. #define OP_GEN_TYPE(type) \
  1121. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1122. #define OP_GEN_AGG_VECT(index) \
  1123. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1124. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1125. {
  1126. struct sdm_op_gen op_gen = {0};
  1127. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1128. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1129. int ret = 0;
  1130. if (REG_RD(bp, comp_addr)) {
  1131. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1132. return 1;
  1133. }
  1134. op_gen.command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1135. op_gen.command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1136. op_gen.command |= OP_GEN_AGG_VECT(clnup_func);
  1137. op_gen.command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1138. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1139. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen.command);
  1140. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1141. BNX2X_ERR("FW final cleanup did not succeed\n");
  1142. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1143. (REG_RD(bp, comp_addr)));
  1144. bnx2x_panic();
  1145. return 1;
  1146. }
  1147. /* Zero completion for nxt FLR */
  1148. REG_WR(bp, comp_addr, 0);
  1149. return ret;
  1150. }
  1151. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1152. {
  1153. u16 status;
  1154. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1155. return status & PCI_EXP_DEVSTA_TRPND;
  1156. }
  1157. /* PF FLR specific routines
  1158. */
  1159. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1160. {
  1161. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1162. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1163. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1164. "CFC PF usage counter timed out",
  1165. poll_cnt))
  1166. return 1;
  1167. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1168. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1169. DORQ_REG_PF_USAGE_CNT,
  1170. "DQ PF usage counter timed out",
  1171. poll_cnt))
  1172. return 1;
  1173. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1174. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1175. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1176. "QM PF usage counter timed out",
  1177. poll_cnt))
  1178. return 1;
  1179. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1180. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1181. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1182. "Timers VNIC usage counter timed out",
  1183. poll_cnt))
  1184. return 1;
  1185. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1186. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1187. "Timers NUM_SCANS usage counter timed out",
  1188. poll_cnt))
  1189. return 1;
  1190. /* Wait DMAE PF usage counter to zero */
  1191. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1192. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1193. "DMAE dommand register timed out",
  1194. poll_cnt))
  1195. return 1;
  1196. return 0;
  1197. }
  1198. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1199. {
  1200. u32 val;
  1201. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1202. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1203. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1204. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1205. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1206. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1207. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1208. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1209. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1210. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1211. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1212. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1213. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1214. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1215. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1216. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1217. val);
  1218. }
  1219. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1220. {
  1221. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1222. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1223. /* Re-enable PF target read access */
  1224. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1225. /* Poll HW usage counters */
  1226. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1227. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1228. return -EBUSY;
  1229. /* Zero the igu 'trailing edge' and 'leading edge' */
  1230. /* Send the FW cleanup command */
  1231. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1232. return -EBUSY;
  1233. /* ATC cleanup */
  1234. /* Verify TX hw is flushed */
  1235. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1236. /* Wait 100ms (not adjusted according to platform) */
  1237. msleep(100);
  1238. /* Verify no pending pci transactions */
  1239. if (bnx2x_is_pcie_pending(bp->pdev))
  1240. BNX2X_ERR("PCIE Transactions still pending\n");
  1241. /* Debug */
  1242. bnx2x_hw_enable_status(bp);
  1243. /*
  1244. * Master enable - Due to WB DMAE writes performed before this
  1245. * register is re-initialized as part of the regular function init
  1246. */
  1247. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1248. return 0;
  1249. }
  1250. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1251. {
  1252. int port = BP_PORT(bp);
  1253. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1254. u32 val = REG_RD(bp, addr);
  1255. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1256. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1257. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1258. if (msix) {
  1259. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1260. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1261. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1262. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1263. if (single_msix)
  1264. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1265. } else if (msi) {
  1266. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1267. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1268. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1269. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1270. } else {
  1271. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1272. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1273. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1274. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1275. if (!CHIP_IS_E1(bp)) {
  1276. DP(NETIF_MSG_IFUP,
  1277. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1278. REG_WR(bp, addr, val);
  1279. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1280. }
  1281. }
  1282. if (CHIP_IS_E1(bp))
  1283. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1284. DP(NETIF_MSG_IFUP,
  1285. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1286. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1287. REG_WR(bp, addr, val);
  1288. /*
  1289. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1290. */
  1291. mmiowb();
  1292. barrier();
  1293. if (!CHIP_IS_E1(bp)) {
  1294. /* init leading/trailing edge */
  1295. if (IS_MF(bp)) {
  1296. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1297. if (bp->port.pmf)
  1298. /* enable nig and gpio3 attention */
  1299. val |= 0x1100;
  1300. } else
  1301. val = 0xffff;
  1302. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1303. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1304. }
  1305. /* Make sure that interrupts are indeed enabled from here on */
  1306. mmiowb();
  1307. }
  1308. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1309. {
  1310. u32 val;
  1311. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1312. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1313. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1314. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1315. if (msix) {
  1316. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1317. IGU_PF_CONF_SINGLE_ISR_EN);
  1318. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1319. IGU_PF_CONF_ATTN_BIT_EN);
  1320. if (single_msix)
  1321. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1322. } else if (msi) {
  1323. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1324. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1325. IGU_PF_CONF_ATTN_BIT_EN |
  1326. IGU_PF_CONF_SINGLE_ISR_EN);
  1327. } else {
  1328. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1329. val |= (IGU_PF_CONF_INT_LINE_EN |
  1330. IGU_PF_CONF_ATTN_BIT_EN |
  1331. IGU_PF_CONF_SINGLE_ISR_EN);
  1332. }
  1333. /* Clean previous status - need to configure igu prior to ack*/
  1334. if ((!msix) || single_msix) {
  1335. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1336. bnx2x_ack_int(bp);
  1337. }
  1338. val |= IGU_PF_CONF_FUNC_EN;
  1339. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1340. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1341. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1342. if (val & IGU_PF_CONF_INT_LINE_EN)
  1343. pci_intx(bp->pdev, true);
  1344. barrier();
  1345. /* init leading/trailing edge */
  1346. if (IS_MF(bp)) {
  1347. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1348. if (bp->port.pmf)
  1349. /* enable nig and gpio3 attention */
  1350. val |= 0x1100;
  1351. } else
  1352. val = 0xffff;
  1353. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1354. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1355. /* Make sure that interrupts are indeed enabled from here on */
  1356. mmiowb();
  1357. }
  1358. void bnx2x_int_enable(struct bnx2x *bp)
  1359. {
  1360. if (bp->common.int_block == INT_BLOCK_HC)
  1361. bnx2x_hc_int_enable(bp);
  1362. else
  1363. bnx2x_igu_int_enable(bp);
  1364. }
  1365. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1366. {
  1367. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1368. int i, offset;
  1369. if (disable_hw)
  1370. /* prevent the HW from sending interrupts */
  1371. bnx2x_int_disable(bp);
  1372. /* make sure all ISRs are done */
  1373. if (msix) {
  1374. synchronize_irq(bp->msix_table[0].vector);
  1375. offset = 1;
  1376. if (CNIC_SUPPORT(bp))
  1377. offset++;
  1378. for_each_eth_queue(bp, i)
  1379. synchronize_irq(bp->msix_table[offset++].vector);
  1380. } else
  1381. synchronize_irq(bp->pdev->irq);
  1382. /* make sure sp_task is not running */
  1383. cancel_delayed_work(&bp->sp_task);
  1384. cancel_delayed_work(&bp->period_task);
  1385. flush_workqueue(bnx2x_wq);
  1386. }
  1387. /* fast path */
  1388. /*
  1389. * General service functions
  1390. */
  1391. /* Return true if succeeded to acquire the lock */
  1392. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1393. {
  1394. u32 lock_status;
  1395. u32 resource_bit = (1 << resource);
  1396. int func = BP_FUNC(bp);
  1397. u32 hw_lock_control_reg;
  1398. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1399. "Trying to take a lock on resource %d\n", resource);
  1400. /* Validating that the resource is within range */
  1401. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1402. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1403. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1404. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1405. return false;
  1406. }
  1407. if (func <= 5)
  1408. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1409. else
  1410. hw_lock_control_reg =
  1411. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1412. /* Try to acquire the lock */
  1413. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1414. lock_status = REG_RD(bp, hw_lock_control_reg);
  1415. if (lock_status & resource_bit)
  1416. return true;
  1417. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1418. "Failed to get a lock on resource %d\n", resource);
  1419. return false;
  1420. }
  1421. /**
  1422. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1423. *
  1424. * @bp: driver handle
  1425. *
  1426. * Returns the recovery leader resource id according to the engine this function
  1427. * belongs to. Currently only only 2 engines is supported.
  1428. */
  1429. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1430. {
  1431. if (BP_PATH(bp))
  1432. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1433. else
  1434. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1435. }
  1436. /**
  1437. * bnx2x_trylock_leader_lock- try to aquire a leader lock.
  1438. *
  1439. * @bp: driver handle
  1440. *
  1441. * Tries to aquire a leader lock for current engine.
  1442. */
  1443. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1444. {
  1445. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1446. }
  1447. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1448. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1449. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1450. {
  1451. /* Set the interrupt occurred bit for the sp-task to recognize it
  1452. * must ack the interrupt and transition according to the IGU
  1453. * state machine.
  1454. */
  1455. atomic_set(&bp->interrupt_occurred, 1);
  1456. /* The sp_task must execute only after this bit
  1457. * is set, otherwise we will get out of sync and miss all
  1458. * further interrupts. Hence, the barrier.
  1459. */
  1460. smp_wmb();
  1461. /* schedule sp_task to workqueue */
  1462. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1463. }
  1464. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1465. {
  1466. struct bnx2x *bp = fp->bp;
  1467. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1468. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1469. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1470. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1471. DP(BNX2X_MSG_SP,
  1472. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1473. fp->index, cid, command, bp->state,
  1474. rr_cqe->ramrod_cqe.ramrod_type);
  1475. /* If cid is within VF range, replace the slowpath object with the
  1476. * one corresponding to this VF
  1477. */
  1478. if (cid >= BNX2X_FIRST_VF_CID &&
  1479. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1480. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1481. switch (command) {
  1482. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1483. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1484. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1485. break;
  1486. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1487. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1488. drv_cmd = BNX2X_Q_CMD_SETUP;
  1489. break;
  1490. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1491. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1492. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1493. break;
  1494. case (RAMROD_CMD_ID_ETH_HALT):
  1495. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1496. drv_cmd = BNX2X_Q_CMD_HALT;
  1497. break;
  1498. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1499. DP(BNX2X_MSG_SP, "got MULTI[%d] teminate ramrod\n", cid);
  1500. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1501. break;
  1502. case (RAMROD_CMD_ID_ETH_EMPTY):
  1503. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1504. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1505. break;
  1506. default:
  1507. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1508. command, fp->index);
  1509. return;
  1510. }
  1511. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1512. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1513. /* q_obj->complete_cmd() failure means that this was
  1514. * an unexpected completion.
  1515. *
  1516. * In this case we don't want to increase the bp->spq_left
  1517. * because apparently we haven't sent this command the first
  1518. * place.
  1519. */
  1520. #ifdef BNX2X_STOP_ON_ERROR
  1521. bnx2x_panic();
  1522. #else
  1523. return;
  1524. #endif
  1525. /* SRIOV: reschedule any 'in_progress' operations */
  1526. bnx2x_iov_sp_event(bp, cid, true);
  1527. smp_mb__before_atomic_inc();
  1528. atomic_inc(&bp->cq_spq_left);
  1529. /* push the change in bp->spq_left and towards the memory */
  1530. smp_mb__after_atomic_inc();
  1531. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1532. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1533. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1534. /* if Q update ramrod is completed for last Q in AFEX vif set
  1535. * flow, then ACK MCP at the end
  1536. *
  1537. * mark pending ACK to MCP bit.
  1538. * prevent case that both bits are cleared.
  1539. * At the end of load/unload driver checks that
  1540. * sp_state is cleaerd, and this order prevents
  1541. * races
  1542. */
  1543. smp_mb__before_clear_bit();
  1544. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1545. wmb();
  1546. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1547. smp_mb__after_clear_bit();
  1548. /* schedule the sp task as mcp ack is required */
  1549. bnx2x_schedule_sp_task(bp);
  1550. }
  1551. return;
  1552. }
  1553. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1554. {
  1555. struct bnx2x *bp = netdev_priv(dev_instance);
  1556. u16 status = bnx2x_ack_int(bp);
  1557. u16 mask;
  1558. int i;
  1559. u8 cos;
  1560. /* Return here if interrupt is shared and it's not for us */
  1561. if (unlikely(status == 0)) {
  1562. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1563. return IRQ_NONE;
  1564. }
  1565. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1566. #ifdef BNX2X_STOP_ON_ERROR
  1567. if (unlikely(bp->panic))
  1568. return IRQ_HANDLED;
  1569. #endif
  1570. for_each_eth_queue(bp, i) {
  1571. struct bnx2x_fastpath *fp = &bp->fp[i];
  1572. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1573. if (status & mask) {
  1574. /* Handle Rx or Tx according to SB id */
  1575. prefetch(fp->rx_cons_sb);
  1576. for_each_cos_in_tx_queue(fp, cos)
  1577. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1578. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1579. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1580. status &= ~mask;
  1581. }
  1582. }
  1583. if (CNIC_SUPPORT(bp)) {
  1584. mask = 0x2;
  1585. if (status & (mask | 0x1)) {
  1586. struct cnic_ops *c_ops = NULL;
  1587. if (likely(bp->state == BNX2X_STATE_OPEN)) {
  1588. rcu_read_lock();
  1589. c_ops = rcu_dereference(bp->cnic_ops);
  1590. if (c_ops)
  1591. c_ops->cnic_handler(bp->cnic_data,
  1592. NULL);
  1593. rcu_read_unlock();
  1594. }
  1595. status &= ~mask;
  1596. }
  1597. }
  1598. if (unlikely(status & 0x1)) {
  1599. /* schedule sp task to perform default status block work, ack
  1600. * attentions and enable interrupts.
  1601. */
  1602. bnx2x_schedule_sp_task(bp);
  1603. status &= ~0x1;
  1604. if (!status)
  1605. return IRQ_HANDLED;
  1606. }
  1607. if (unlikely(status))
  1608. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1609. status);
  1610. return IRQ_HANDLED;
  1611. }
  1612. /* Link */
  1613. /*
  1614. * General service functions
  1615. */
  1616. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1617. {
  1618. u32 lock_status;
  1619. u32 resource_bit = (1 << resource);
  1620. int func = BP_FUNC(bp);
  1621. u32 hw_lock_control_reg;
  1622. int cnt;
  1623. /* Validating that the resource is within range */
  1624. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1625. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1626. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1627. return -EINVAL;
  1628. }
  1629. if (func <= 5) {
  1630. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1631. } else {
  1632. hw_lock_control_reg =
  1633. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1634. }
  1635. /* Validating that the resource is not already taken */
  1636. lock_status = REG_RD(bp, hw_lock_control_reg);
  1637. if (lock_status & resource_bit) {
  1638. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1639. lock_status, resource_bit);
  1640. return -EEXIST;
  1641. }
  1642. /* Try for 5 second every 5ms */
  1643. for (cnt = 0; cnt < 1000; cnt++) {
  1644. /* Try to acquire the lock */
  1645. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1646. lock_status = REG_RD(bp, hw_lock_control_reg);
  1647. if (lock_status & resource_bit)
  1648. return 0;
  1649. msleep(5);
  1650. }
  1651. BNX2X_ERR("Timeout\n");
  1652. return -EAGAIN;
  1653. }
  1654. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1655. {
  1656. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1657. }
  1658. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1659. {
  1660. u32 lock_status;
  1661. u32 resource_bit = (1 << resource);
  1662. int func = BP_FUNC(bp);
  1663. u32 hw_lock_control_reg;
  1664. /* Validating that the resource is within range */
  1665. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1666. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1667. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1668. return -EINVAL;
  1669. }
  1670. if (func <= 5) {
  1671. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1672. } else {
  1673. hw_lock_control_reg =
  1674. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1675. }
  1676. /* Validating that the resource is currently taken */
  1677. lock_status = REG_RD(bp, hw_lock_control_reg);
  1678. if (!(lock_status & resource_bit)) {
  1679. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. unlock was called but lock wasn't taken!\n",
  1680. lock_status, resource_bit);
  1681. return -EFAULT;
  1682. }
  1683. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1684. return 0;
  1685. }
  1686. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1687. {
  1688. /* The GPIO should be swapped if swap register is set and active */
  1689. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1690. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1691. int gpio_shift = gpio_num +
  1692. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1693. u32 gpio_mask = (1 << gpio_shift);
  1694. u32 gpio_reg;
  1695. int value;
  1696. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1697. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1698. return -EINVAL;
  1699. }
  1700. /* read GPIO value */
  1701. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1702. /* get the requested pin value */
  1703. if ((gpio_reg & gpio_mask) == gpio_mask)
  1704. value = 1;
  1705. else
  1706. value = 0;
  1707. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1708. return value;
  1709. }
  1710. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1711. {
  1712. /* The GPIO should be swapped if swap register is set and active */
  1713. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1714. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1715. int gpio_shift = gpio_num +
  1716. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1717. u32 gpio_mask = (1 << gpio_shift);
  1718. u32 gpio_reg;
  1719. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1720. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1721. return -EINVAL;
  1722. }
  1723. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1724. /* read GPIO and mask except the float bits */
  1725. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1726. switch (mode) {
  1727. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1728. DP(NETIF_MSG_LINK,
  1729. "Set GPIO %d (shift %d) -> output low\n",
  1730. gpio_num, gpio_shift);
  1731. /* clear FLOAT and set CLR */
  1732. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1733. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1734. break;
  1735. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1736. DP(NETIF_MSG_LINK,
  1737. "Set GPIO %d (shift %d) -> output high\n",
  1738. gpio_num, gpio_shift);
  1739. /* clear FLOAT and set SET */
  1740. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1741. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1742. break;
  1743. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1744. DP(NETIF_MSG_LINK,
  1745. "Set GPIO %d (shift %d) -> input\n",
  1746. gpio_num, gpio_shift);
  1747. /* set FLOAT */
  1748. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1749. break;
  1750. default:
  1751. break;
  1752. }
  1753. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1754. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1755. return 0;
  1756. }
  1757. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1758. {
  1759. u32 gpio_reg = 0;
  1760. int rc = 0;
  1761. /* Any port swapping should be handled by caller. */
  1762. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1763. /* read GPIO and mask except the float bits */
  1764. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1765. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1766. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1767. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1768. switch (mode) {
  1769. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1770. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1771. /* set CLR */
  1772. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1773. break;
  1774. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1775. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1776. /* set SET */
  1777. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1778. break;
  1779. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1780. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1781. /* set FLOAT */
  1782. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1783. break;
  1784. default:
  1785. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1786. rc = -EINVAL;
  1787. break;
  1788. }
  1789. if (rc == 0)
  1790. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1791. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1792. return rc;
  1793. }
  1794. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1795. {
  1796. /* The GPIO should be swapped if swap register is set and active */
  1797. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1798. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1799. int gpio_shift = gpio_num +
  1800. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1801. u32 gpio_mask = (1 << gpio_shift);
  1802. u32 gpio_reg;
  1803. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1804. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1805. return -EINVAL;
  1806. }
  1807. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1808. /* read GPIO int */
  1809. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1810. switch (mode) {
  1811. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1812. DP(NETIF_MSG_LINK,
  1813. "Clear GPIO INT %d (shift %d) -> output low\n",
  1814. gpio_num, gpio_shift);
  1815. /* clear SET and set CLR */
  1816. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1817. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1818. break;
  1819. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1820. DP(NETIF_MSG_LINK,
  1821. "Set GPIO INT %d (shift %d) -> output high\n",
  1822. gpio_num, gpio_shift);
  1823. /* clear CLR and set SET */
  1824. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1825. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1826. break;
  1827. default:
  1828. break;
  1829. }
  1830. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1831. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1832. return 0;
  1833. }
  1834. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1835. {
  1836. u32 spio_reg;
  1837. /* Only 2 SPIOs are configurable */
  1838. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1839. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1840. return -EINVAL;
  1841. }
  1842. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1843. /* read SPIO and mask except the float bits */
  1844. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1845. switch (mode) {
  1846. case MISC_SPIO_OUTPUT_LOW:
  1847. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1848. /* clear FLOAT and set CLR */
  1849. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1850. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1851. break;
  1852. case MISC_SPIO_OUTPUT_HIGH:
  1853. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1854. /* clear FLOAT and set SET */
  1855. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1856. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1857. break;
  1858. case MISC_SPIO_INPUT_HI_Z:
  1859. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1860. /* set FLOAT */
  1861. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1862. break;
  1863. default:
  1864. break;
  1865. }
  1866. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1867. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1868. return 0;
  1869. }
  1870. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1871. {
  1872. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1873. switch (bp->link_vars.ieee_fc &
  1874. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1875. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1876. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1877. ADVERTISED_Pause);
  1878. break;
  1879. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1880. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1881. ADVERTISED_Pause);
  1882. break;
  1883. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1884. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1885. break;
  1886. default:
  1887. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1888. ADVERTISED_Pause);
  1889. break;
  1890. }
  1891. }
  1892. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1893. {
  1894. /* Initialize link parameters structure variables
  1895. * It is recommended to turn off RX FC for jumbo frames
  1896. * for better performance
  1897. */
  1898. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1899. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1900. else
  1901. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1902. }
  1903. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1904. {
  1905. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1906. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1907. if (!BP_NOMCP(bp)) {
  1908. bnx2x_set_requested_fc(bp);
  1909. bnx2x_acquire_phy_lock(bp);
  1910. if (load_mode == LOAD_DIAG) {
  1911. struct link_params *lp = &bp->link_params;
  1912. lp->loopback_mode = LOOPBACK_XGXS;
  1913. /* do PHY loopback at 10G speed, if possible */
  1914. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1915. if (lp->speed_cap_mask[cfx_idx] &
  1916. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1917. lp->req_line_speed[cfx_idx] =
  1918. SPEED_10000;
  1919. else
  1920. lp->req_line_speed[cfx_idx] =
  1921. SPEED_1000;
  1922. }
  1923. }
  1924. if (load_mode == LOAD_LOOPBACK_EXT) {
  1925. struct link_params *lp = &bp->link_params;
  1926. lp->loopback_mode = LOOPBACK_EXT;
  1927. }
  1928. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1929. bnx2x_release_phy_lock(bp);
  1930. bnx2x_calc_fc_adv(bp);
  1931. if (bp->link_vars.link_up) {
  1932. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1933. bnx2x_link_report(bp);
  1934. }
  1935. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1936. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1937. return rc;
  1938. }
  1939. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1940. return -EINVAL;
  1941. }
  1942. void bnx2x_link_set(struct bnx2x *bp)
  1943. {
  1944. if (!BP_NOMCP(bp)) {
  1945. bnx2x_acquire_phy_lock(bp);
  1946. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1947. bnx2x_release_phy_lock(bp);
  1948. bnx2x_calc_fc_adv(bp);
  1949. } else
  1950. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1951. }
  1952. static void bnx2x__link_reset(struct bnx2x *bp)
  1953. {
  1954. if (!BP_NOMCP(bp)) {
  1955. bnx2x_acquire_phy_lock(bp);
  1956. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1957. bnx2x_release_phy_lock(bp);
  1958. } else
  1959. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1960. }
  1961. void bnx2x_force_link_reset(struct bnx2x *bp)
  1962. {
  1963. bnx2x_acquire_phy_lock(bp);
  1964. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1965. bnx2x_release_phy_lock(bp);
  1966. }
  1967. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1968. {
  1969. u8 rc = 0;
  1970. if (!BP_NOMCP(bp)) {
  1971. bnx2x_acquire_phy_lock(bp);
  1972. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1973. is_serdes);
  1974. bnx2x_release_phy_lock(bp);
  1975. } else
  1976. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1977. return rc;
  1978. }
  1979. /* Calculates the sum of vn_min_rates.
  1980. It's needed for further normalizing of the min_rates.
  1981. Returns:
  1982. sum of vn_min_rates.
  1983. or
  1984. 0 - if all the min_rates are 0.
  1985. In the later case fainess algorithm should be deactivated.
  1986. If not all min_rates are zero then those that are zeroes will be set to 1.
  1987. */
  1988. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  1989. struct cmng_init_input *input)
  1990. {
  1991. int all_zero = 1;
  1992. int vn;
  1993. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  1994. u32 vn_cfg = bp->mf_config[vn];
  1995. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  1996. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  1997. /* Skip hidden vns */
  1998. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  1999. vn_min_rate = 0;
  2000. /* If min rate is zero - set it to 1 */
  2001. else if (!vn_min_rate)
  2002. vn_min_rate = DEF_MIN_RATE;
  2003. else
  2004. all_zero = 0;
  2005. input->vnic_min_rate[vn] = vn_min_rate;
  2006. }
  2007. /* if ETS or all min rates are zeros - disable fairness */
  2008. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2009. input->flags.cmng_enables &=
  2010. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2011. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2012. } else if (all_zero) {
  2013. input->flags.cmng_enables &=
  2014. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2015. DP(NETIF_MSG_IFUP,
  2016. "All MIN values are zeroes fairness will be disabled\n");
  2017. } else
  2018. input->flags.cmng_enables |=
  2019. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2020. }
  2021. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2022. struct cmng_init_input *input)
  2023. {
  2024. u16 vn_max_rate;
  2025. u32 vn_cfg = bp->mf_config[vn];
  2026. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2027. vn_max_rate = 0;
  2028. else {
  2029. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2030. if (IS_MF_SI(bp)) {
  2031. /* maxCfg in percents of linkspeed */
  2032. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2033. } else /* SD modes */
  2034. /* maxCfg is absolute in 100Mb units */
  2035. vn_max_rate = maxCfg * 100;
  2036. }
  2037. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2038. input->vnic_max_rate[vn] = vn_max_rate;
  2039. }
  2040. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2041. {
  2042. if (CHIP_REV_IS_SLOW(bp))
  2043. return CMNG_FNS_NONE;
  2044. if (IS_MF(bp))
  2045. return CMNG_FNS_MINMAX;
  2046. return CMNG_FNS_NONE;
  2047. }
  2048. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2049. {
  2050. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2051. if (BP_NOMCP(bp))
  2052. return; /* what should be the default bvalue in this case */
  2053. /* For 2 port configuration the absolute function number formula
  2054. * is:
  2055. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2056. *
  2057. * and there are 4 functions per port
  2058. *
  2059. * For 4 port configuration it is
  2060. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2061. *
  2062. * and there are 2 functions per port
  2063. */
  2064. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2065. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2066. if (func >= E1H_FUNC_MAX)
  2067. break;
  2068. bp->mf_config[vn] =
  2069. MF_CFG_RD(bp, func_mf_config[func].config);
  2070. }
  2071. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2072. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2073. bp->flags |= MF_FUNC_DIS;
  2074. } else {
  2075. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2076. bp->flags &= ~MF_FUNC_DIS;
  2077. }
  2078. }
  2079. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2080. {
  2081. struct cmng_init_input input;
  2082. memset(&input, 0, sizeof(struct cmng_init_input));
  2083. input.port_rate = bp->link_vars.line_speed;
  2084. if (cmng_type == CMNG_FNS_MINMAX) {
  2085. int vn;
  2086. /* read mf conf from shmem */
  2087. if (read_cfg)
  2088. bnx2x_read_mf_cfg(bp);
  2089. /* vn_weight_sum and enable fairness if not 0 */
  2090. bnx2x_calc_vn_min(bp, &input);
  2091. /* calculate and set min-max rate for each vn */
  2092. if (bp->port.pmf)
  2093. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2094. bnx2x_calc_vn_max(bp, vn, &input);
  2095. /* always enable rate shaping and fairness */
  2096. input.flags.cmng_enables |=
  2097. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2098. bnx2x_init_cmng(&input, &bp->cmng);
  2099. return;
  2100. }
  2101. /* rate shaping and fairness are disabled */
  2102. DP(NETIF_MSG_IFUP,
  2103. "rate shaping and fairness are disabled\n");
  2104. }
  2105. static void storm_memset_cmng(struct bnx2x *bp,
  2106. struct cmng_init *cmng,
  2107. u8 port)
  2108. {
  2109. int vn;
  2110. size_t size = sizeof(struct cmng_struct_per_port);
  2111. u32 addr = BAR_XSTRORM_INTMEM +
  2112. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2113. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2114. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2115. int func = func_by_vn(bp, vn);
  2116. addr = BAR_XSTRORM_INTMEM +
  2117. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2118. size = sizeof(struct rate_shaping_vars_per_vn);
  2119. __storm_memset_struct(bp, addr, size,
  2120. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2121. addr = BAR_XSTRORM_INTMEM +
  2122. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2123. size = sizeof(struct fairness_vars_per_vn);
  2124. __storm_memset_struct(bp, addr, size,
  2125. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2126. }
  2127. }
  2128. /* This function is called upon link interrupt */
  2129. static void bnx2x_link_attn(struct bnx2x *bp)
  2130. {
  2131. /* Make sure that we are synced with the current statistics */
  2132. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2133. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2134. if (bp->link_vars.link_up) {
  2135. /* dropless flow control */
  2136. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2137. int port = BP_PORT(bp);
  2138. u32 pause_enabled = 0;
  2139. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2140. pause_enabled = 1;
  2141. REG_WR(bp, BAR_USTRORM_INTMEM +
  2142. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2143. pause_enabled);
  2144. }
  2145. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2146. struct host_port_stats *pstats;
  2147. pstats = bnx2x_sp(bp, port_stats);
  2148. /* reset old mac stats */
  2149. memset(&(pstats->mac_stx[0]), 0,
  2150. sizeof(struct mac_stx));
  2151. }
  2152. if (bp->state == BNX2X_STATE_OPEN)
  2153. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2154. }
  2155. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2156. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2157. if (cmng_fns != CMNG_FNS_NONE) {
  2158. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2159. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2160. } else
  2161. /* rate shaping and fairness are disabled */
  2162. DP(NETIF_MSG_IFUP,
  2163. "single function mode without fairness\n");
  2164. }
  2165. __bnx2x_link_report(bp);
  2166. if (IS_MF(bp))
  2167. bnx2x_link_sync_notify(bp);
  2168. }
  2169. void bnx2x__link_status_update(struct bnx2x *bp)
  2170. {
  2171. if (bp->state != BNX2X_STATE_OPEN)
  2172. return;
  2173. /* read updated dcb configuration */
  2174. if (IS_PF(bp)) {
  2175. bnx2x_dcbx_pmf_update(bp);
  2176. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2177. if (bp->link_vars.link_up)
  2178. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2179. else
  2180. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2181. /* indicate link status */
  2182. bnx2x_link_report(bp);
  2183. } else { /* VF */
  2184. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2185. SUPPORTED_10baseT_Full |
  2186. SUPPORTED_100baseT_Half |
  2187. SUPPORTED_100baseT_Full |
  2188. SUPPORTED_1000baseT_Full |
  2189. SUPPORTED_2500baseX_Full |
  2190. SUPPORTED_10000baseT_Full |
  2191. SUPPORTED_TP |
  2192. SUPPORTED_FIBRE |
  2193. SUPPORTED_Autoneg |
  2194. SUPPORTED_Pause |
  2195. SUPPORTED_Asym_Pause);
  2196. bp->port.advertising[0] = bp->port.supported[0];
  2197. bp->link_params.bp = bp;
  2198. bp->link_params.port = BP_PORT(bp);
  2199. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2200. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2201. bp->link_params.req_line_speed[0] = SPEED_10000;
  2202. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2203. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2204. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2205. bp->link_vars.line_speed = SPEED_10000;
  2206. bp->link_vars.link_status =
  2207. (LINK_STATUS_LINK_UP |
  2208. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2209. bp->link_vars.link_up = 1;
  2210. bp->link_vars.duplex = DUPLEX_FULL;
  2211. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2212. __bnx2x_link_report(bp);
  2213. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2214. }
  2215. }
  2216. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2217. u16 vlan_val, u8 allowed_prio)
  2218. {
  2219. struct bnx2x_func_state_params func_params = {0};
  2220. struct bnx2x_func_afex_update_params *f_update_params =
  2221. &func_params.params.afex_update;
  2222. func_params.f_obj = &bp->func_obj;
  2223. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2224. /* no need to wait for RAMROD completion, so don't
  2225. * set RAMROD_COMP_WAIT flag
  2226. */
  2227. f_update_params->vif_id = vifid;
  2228. f_update_params->afex_default_vlan = vlan_val;
  2229. f_update_params->allowed_priorities = allowed_prio;
  2230. /* if ramrod can not be sent, response to MCP immediately */
  2231. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2232. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2233. return 0;
  2234. }
  2235. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2236. u16 vif_index, u8 func_bit_map)
  2237. {
  2238. struct bnx2x_func_state_params func_params = {0};
  2239. struct bnx2x_func_afex_viflists_params *update_params =
  2240. &func_params.params.afex_viflists;
  2241. int rc;
  2242. u32 drv_msg_code;
  2243. /* validate only LIST_SET and LIST_GET are received from switch */
  2244. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2245. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2246. cmd_type);
  2247. func_params.f_obj = &bp->func_obj;
  2248. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2249. /* set parameters according to cmd_type */
  2250. update_params->afex_vif_list_command = cmd_type;
  2251. update_params->vif_list_index = cpu_to_le16(vif_index);
  2252. update_params->func_bit_map =
  2253. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2254. update_params->func_to_clear = 0;
  2255. drv_msg_code =
  2256. (cmd_type == VIF_LIST_RULE_GET) ?
  2257. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2258. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2259. /* if ramrod can not be sent, respond to MCP immediately for
  2260. * SET and GET requests (other are not triggered from MCP)
  2261. */
  2262. rc = bnx2x_func_state_change(bp, &func_params);
  2263. if (rc < 0)
  2264. bnx2x_fw_command(bp, drv_msg_code, 0);
  2265. return 0;
  2266. }
  2267. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2268. {
  2269. struct afex_stats afex_stats;
  2270. u32 func = BP_ABS_FUNC(bp);
  2271. u32 mf_config;
  2272. u16 vlan_val;
  2273. u32 vlan_prio;
  2274. u16 vif_id;
  2275. u8 allowed_prio;
  2276. u8 vlan_mode;
  2277. u32 addr_to_write, vifid, addrs, stats_type, i;
  2278. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2279. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2280. DP(BNX2X_MSG_MCP,
  2281. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2282. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2283. }
  2284. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2285. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2286. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2287. DP(BNX2X_MSG_MCP,
  2288. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2289. vifid, addrs);
  2290. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2291. addrs);
  2292. }
  2293. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2294. addr_to_write = SHMEM2_RD(bp,
  2295. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2296. stats_type = SHMEM2_RD(bp,
  2297. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2298. DP(BNX2X_MSG_MCP,
  2299. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2300. addr_to_write);
  2301. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2302. /* write response to scratchpad, for MCP */
  2303. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2304. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2305. *(((u32 *)(&afex_stats))+i));
  2306. /* send ack message to MCP */
  2307. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2308. }
  2309. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2310. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2311. bp->mf_config[BP_VN(bp)] = mf_config;
  2312. DP(BNX2X_MSG_MCP,
  2313. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2314. mf_config);
  2315. /* if VIF_SET is "enabled" */
  2316. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2317. /* set rate limit directly to internal RAM */
  2318. struct cmng_init_input cmng_input;
  2319. struct rate_shaping_vars_per_vn m_rs_vn;
  2320. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2321. u32 addr = BAR_XSTRORM_INTMEM +
  2322. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2323. bp->mf_config[BP_VN(bp)] = mf_config;
  2324. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2325. m_rs_vn.vn_counter.rate =
  2326. cmng_input.vnic_max_rate[BP_VN(bp)];
  2327. m_rs_vn.vn_counter.quota =
  2328. (m_rs_vn.vn_counter.rate *
  2329. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2330. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2331. /* read relevant values from mf_cfg struct in shmem */
  2332. vif_id =
  2333. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2334. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2335. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2336. vlan_val =
  2337. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2338. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2339. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2340. vlan_prio = (mf_config &
  2341. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2342. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2343. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2344. vlan_mode =
  2345. (MF_CFG_RD(bp,
  2346. func_mf_config[func].afex_config) &
  2347. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2348. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2349. allowed_prio =
  2350. (MF_CFG_RD(bp,
  2351. func_mf_config[func].afex_config) &
  2352. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2353. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2354. /* send ramrod to FW, return in case of failure */
  2355. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2356. allowed_prio))
  2357. return;
  2358. bp->afex_def_vlan_tag = vlan_val;
  2359. bp->afex_vlan_mode = vlan_mode;
  2360. } else {
  2361. /* notify link down because BP->flags is disabled */
  2362. bnx2x_link_report(bp);
  2363. /* send INVALID VIF ramrod to FW */
  2364. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2365. /* Reset the default afex VLAN */
  2366. bp->afex_def_vlan_tag = -1;
  2367. }
  2368. }
  2369. }
  2370. static void bnx2x_pmf_update(struct bnx2x *bp)
  2371. {
  2372. int port = BP_PORT(bp);
  2373. u32 val;
  2374. bp->port.pmf = 1;
  2375. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2376. /*
  2377. * We need the mb() to ensure the ordering between the writing to
  2378. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2379. */
  2380. smp_mb();
  2381. /* queue a periodic task */
  2382. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2383. bnx2x_dcbx_pmf_update(bp);
  2384. /* enable nig attention */
  2385. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2386. if (bp->common.int_block == INT_BLOCK_HC) {
  2387. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2388. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2389. } else if (!CHIP_IS_E1x(bp)) {
  2390. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2391. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2392. }
  2393. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2394. }
  2395. /* end of Link */
  2396. /* slow path */
  2397. /*
  2398. * General service functions
  2399. */
  2400. /* send the MCP a request, block until there is a reply */
  2401. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2402. {
  2403. int mb_idx = BP_FW_MB_IDX(bp);
  2404. u32 seq;
  2405. u32 rc = 0;
  2406. u32 cnt = 1;
  2407. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2408. mutex_lock(&bp->fw_mb_mutex);
  2409. seq = ++bp->fw_seq;
  2410. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2411. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2412. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2413. (command | seq), param);
  2414. do {
  2415. /* let the FW do it's magic ... */
  2416. msleep(delay);
  2417. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2418. /* Give the FW up to 5 second (500*10ms) */
  2419. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2420. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2421. cnt*delay, rc, seq);
  2422. /* is this a reply to our command? */
  2423. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2424. rc &= FW_MSG_CODE_MASK;
  2425. else {
  2426. /* FW BUG! */
  2427. BNX2X_ERR("FW failed to respond!\n");
  2428. bnx2x_fw_dump(bp);
  2429. rc = 0;
  2430. }
  2431. mutex_unlock(&bp->fw_mb_mutex);
  2432. return rc;
  2433. }
  2434. static void storm_memset_func_cfg(struct bnx2x *bp,
  2435. struct tstorm_eth_function_common_config *tcfg,
  2436. u16 abs_fid)
  2437. {
  2438. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2439. u32 addr = BAR_TSTRORM_INTMEM +
  2440. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2441. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2442. }
  2443. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2444. {
  2445. if (CHIP_IS_E1x(bp)) {
  2446. struct tstorm_eth_function_common_config tcfg = {0};
  2447. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2448. }
  2449. /* Enable the function in the FW */
  2450. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2451. storm_memset_func_en(bp, p->func_id, 1);
  2452. /* spq */
  2453. if (p->func_flgs & FUNC_FLG_SPQ) {
  2454. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2455. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2456. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2457. }
  2458. }
  2459. /**
  2460. * bnx2x_get_tx_only_flags - Return common flags
  2461. *
  2462. * @bp device handle
  2463. * @fp queue handle
  2464. * @zero_stats TRUE if statistics zeroing is needed
  2465. *
  2466. * Return the flags that are common for the Tx-only and not normal connections.
  2467. */
  2468. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2469. struct bnx2x_fastpath *fp,
  2470. bool zero_stats)
  2471. {
  2472. unsigned long flags = 0;
  2473. /* PF driver will always initialize the Queue to an ACTIVE state */
  2474. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2475. /* tx only connections collect statistics (on the same index as the
  2476. * parent connection). The statistics are zeroed when the parent
  2477. * connection is initialized.
  2478. */
  2479. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2480. if (zero_stats)
  2481. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2482. #ifdef BNX2X_STOP_ON_ERROR
  2483. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2484. #endif
  2485. return flags;
  2486. }
  2487. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2488. struct bnx2x_fastpath *fp,
  2489. bool leading)
  2490. {
  2491. unsigned long flags = 0;
  2492. /* calculate other queue flags */
  2493. if (IS_MF_SD(bp))
  2494. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2495. if (IS_FCOE_FP(fp)) {
  2496. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2497. /* For FCoE - force usage of default priority (for afex) */
  2498. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2499. }
  2500. if (!fp->disable_tpa) {
  2501. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2502. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2503. if (fp->mode == TPA_MODE_GRO)
  2504. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2505. }
  2506. if (leading) {
  2507. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2508. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2509. }
  2510. /* Always set HW VLAN stripping */
  2511. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2512. /* configure silent vlan removal */
  2513. if (IS_MF_AFEX(bp))
  2514. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2515. return flags | bnx2x_get_common_flags(bp, fp, true);
  2516. }
  2517. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2518. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2519. u8 cos)
  2520. {
  2521. gen_init->stat_id = bnx2x_stats_id(fp);
  2522. gen_init->spcl_id = fp->cl_id;
  2523. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2524. if (IS_FCOE_FP(fp))
  2525. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2526. else
  2527. gen_init->mtu = bp->dev->mtu;
  2528. gen_init->cos = cos;
  2529. }
  2530. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2531. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2532. struct bnx2x_rxq_setup_params *rxq_init)
  2533. {
  2534. u8 max_sge = 0;
  2535. u16 sge_sz = 0;
  2536. u16 tpa_agg_size = 0;
  2537. if (!fp->disable_tpa) {
  2538. pause->sge_th_lo = SGE_TH_LO(bp);
  2539. pause->sge_th_hi = SGE_TH_HI(bp);
  2540. /* validate SGE ring has enough to cross high threshold */
  2541. WARN_ON(bp->dropless_fc &&
  2542. pause->sge_th_hi + FW_PREFETCH_CNT >
  2543. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2544. tpa_agg_size = min_t(u32,
  2545. (min_t(u32, 8, MAX_SKB_FRAGS) *
  2546. SGE_PAGE_SIZE * PAGES_PER_SGE), 0xffff);
  2547. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2548. SGE_PAGE_SHIFT;
  2549. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2550. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2551. sge_sz = (u16)min_t(u32, SGE_PAGE_SIZE * PAGES_PER_SGE,
  2552. 0xffff);
  2553. }
  2554. /* pause - not for e1 */
  2555. if (!CHIP_IS_E1(bp)) {
  2556. pause->bd_th_lo = BD_TH_LO(bp);
  2557. pause->bd_th_hi = BD_TH_HI(bp);
  2558. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2559. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2560. /*
  2561. * validate that rings have enough entries to cross
  2562. * high thresholds
  2563. */
  2564. WARN_ON(bp->dropless_fc &&
  2565. pause->bd_th_hi + FW_PREFETCH_CNT >
  2566. bp->rx_ring_size);
  2567. WARN_ON(bp->dropless_fc &&
  2568. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2569. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2570. pause->pri_map = 1;
  2571. }
  2572. /* rxq setup */
  2573. rxq_init->dscr_map = fp->rx_desc_mapping;
  2574. rxq_init->sge_map = fp->rx_sge_mapping;
  2575. rxq_init->rcq_map = fp->rx_comp_mapping;
  2576. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2577. /* This should be a maximum number of data bytes that may be
  2578. * placed on the BD (not including paddings).
  2579. */
  2580. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2581. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2582. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2583. rxq_init->tpa_agg_sz = tpa_agg_size;
  2584. rxq_init->sge_buf_sz = sge_sz;
  2585. rxq_init->max_sges_pkt = max_sge;
  2586. rxq_init->rss_engine_id = BP_FUNC(bp);
  2587. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2588. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2589. *
  2590. * For PF Clients it should be the maximum avaliable number.
  2591. * VF driver(s) may want to define it to a smaller value.
  2592. */
  2593. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2594. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2595. rxq_init->fw_sb_id = fp->fw_sb_id;
  2596. if (IS_FCOE_FP(fp))
  2597. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2598. else
  2599. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2600. /* configure silent vlan removal
  2601. * if multi function mode is afex, then mask default vlan
  2602. */
  2603. if (IS_MF_AFEX(bp)) {
  2604. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2605. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2606. }
  2607. }
  2608. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2609. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2610. u8 cos)
  2611. {
  2612. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2613. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2614. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2615. txq_init->fw_sb_id = fp->fw_sb_id;
  2616. /*
  2617. * set the tss leading client id for TX classfication ==
  2618. * leading RSS client id
  2619. */
  2620. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2621. if (IS_FCOE_FP(fp)) {
  2622. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2623. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2624. }
  2625. }
  2626. static void bnx2x_pf_init(struct bnx2x *bp)
  2627. {
  2628. struct bnx2x_func_init_params func_init = {0};
  2629. struct event_ring_data eq_data = { {0} };
  2630. u16 flags;
  2631. if (!CHIP_IS_E1x(bp)) {
  2632. /* reset IGU PF statistics: MSIX + ATTN */
  2633. /* PF */
  2634. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2635. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2636. (CHIP_MODE_IS_4_PORT(bp) ?
  2637. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2638. /* ATTN */
  2639. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2640. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2641. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2642. (CHIP_MODE_IS_4_PORT(bp) ?
  2643. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2644. }
  2645. /* function setup flags */
  2646. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2647. /* This flag is relevant for E1x only.
  2648. * E2 doesn't have a TPA configuration in a function level.
  2649. */
  2650. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2651. func_init.func_flgs = flags;
  2652. func_init.pf_id = BP_FUNC(bp);
  2653. func_init.func_id = BP_FUNC(bp);
  2654. func_init.spq_map = bp->spq_mapping;
  2655. func_init.spq_prod = bp->spq_prod_idx;
  2656. bnx2x_func_init(bp, &func_init);
  2657. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2658. /*
  2659. * Congestion management values depend on the link rate
  2660. * There is no active link so initial link rate is set to 10 Gbps.
  2661. * When the link comes up The congestion management values are
  2662. * re-calculated according to the actual link rate.
  2663. */
  2664. bp->link_vars.line_speed = SPEED_10000;
  2665. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2666. /* Only the PMF sets the HW */
  2667. if (bp->port.pmf)
  2668. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2669. /* init Event Queue */
  2670. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2671. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2672. eq_data.producer = bp->eq_prod;
  2673. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2674. eq_data.sb_id = DEF_SB_ID;
  2675. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2676. }
  2677. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2678. {
  2679. int port = BP_PORT(bp);
  2680. bnx2x_tx_disable(bp);
  2681. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2682. }
  2683. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2684. {
  2685. int port = BP_PORT(bp);
  2686. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2687. /* Tx queue should be only reenabled */
  2688. netif_tx_wake_all_queues(bp->dev);
  2689. /*
  2690. * Should not call netif_carrier_on since it will be called if the link
  2691. * is up when checking for link state
  2692. */
  2693. }
  2694. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2695. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2696. {
  2697. struct eth_stats_info *ether_stat =
  2698. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2699. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2700. ETH_STAT_INFO_VERSION_LEN);
  2701. bp->sp_objs[0].mac_obj.get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2702. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2703. ether_stat->mac_local);
  2704. ether_stat->mtu_size = bp->dev->mtu;
  2705. if (bp->dev->features & NETIF_F_RXCSUM)
  2706. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2707. if (bp->dev->features & NETIF_F_TSO)
  2708. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2709. ether_stat->feature_flags |= bp->common.boot_mode;
  2710. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2711. ether_stat->txq_size = bp->tx_ring_size;
  2712. ether_stat->rxq_size = bp->rx_ring_size;
  2713. }
  2714. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2715. {
  2716. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2717. struct fcoe_stats_info *fcoe_stat =
  2718. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2719. if (!CNIC_LOADED(bp))
  2720. return;
  2721. memcpy(fcoe_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2722. bp->fip_mac, ETH_ALEN);
  2723. fcoe_stat->qos_priority =
  2724. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2725. /* insert FCoE stats from ramrod response */
  2726. if (!NO_FCOE(bp)) {
  2727. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2728. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2729. tstorm_queue_statistics;
  2730. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2731. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2732. xstorm_queue_statistics;
  2733. struct fcoe_statistics_params *fw_fcoe_stat =
  2734. &bp->fw_stats_data->fcoe;
  2735. ADD_64(fcoe_stat->rx_bytes_hi, 0, fcoe_stat->rx_bytes_lo,
  2736. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2737. ADD_64(fcoe_stat->rx_bytes_hi,
  2738. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2739. fcoe_stat->rx_bytes_lo,
  2740. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2741. ADD_64(fcoe_stat->rx_bytes_hi,
  2742. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2743. fcoe_stat->rx_bytes_lo,
  2744. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2745. ADD_64(fcoe_stat->rx_bytes_hi,
  2746. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2747. fcoe_stat->rx_bytes_lo,
  2748. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2749. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2750. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2751. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2752. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2753. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2754. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2755. ADD_64(fcoe_stat->rx_frames_hi, 0, fcoe_stat->rx_frames_lo,
  2756. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2757. ADD_64(fcoe_stat->tx_bytes_hi, 0, fcoe_stat->tx_bytes_lo,
  2758. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2759. ADD_64(fcoe_stat->tx_bytes_hi,
  2760. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2761. fcoe_stat->tx_bytes_lo,
  2762. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2763. ADD_64(fcoe_stat->tx_bytes_hi,
  2764. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2765. fcoe_stat->tx_bytes_lo,
  2766. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2767. ADD_64(fcoe_stat->tx_bytes_hi,
  2768. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2769. fcoe_stat->tx_bytes_lo,
  2770. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2771. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2772. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2773. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2774. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2775. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2776. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2777. ADD_64(fcoe_stat->tx_frames_hi, 0, fcoe_stat->tx_frames_lo,
  2778. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2779. }
  2780. /* ask L5 driver to add data to the struct */
  2781. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2782. }
  2783. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2784. {
  2785. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2786. struct iscsi_stats_info *iscsi_stat =
  2787. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2788. if (!CNIC_LOADED(bp))
  2789. return;
  2790. memcpy(iscsi_stat->mac_local + MAC_LEADING_ZERO_CNT,
  2791. bp->cnic_eth_dev.iscsi_mac, ETH_ALEN);
  2792. iscsi_stat->qos_priority =
  2793. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2794. /* ask L5 driver to add data to the struct */
  2795. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2796. }
  2797. /* called due to MCP event (on pmf):
  2798. * reread new bandwidth configuration
  2799. * configure FW
  2800. * notify others function about the change
  2801. */
  2802. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2803. {
  2804. if (bp->link_vars.link_up) {
  2805. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2806. bnx2x_link_sync_notify(bp);
  2807. }
  2808. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2809. }
  2810. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2811. {
  2812. bnx2x_config_mf_bw(bp);
  2813. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2814. }
  2815. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2816. {
  2817. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2818. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2819. }
  2820. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2821. {
  2822. enum drv_info_opcode op_code;
  2823. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2824. /* if drv_info version supported by MFW doesn't match - send NACK */
  2825. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2826. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2827. return;
  2828. }
  2829. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2830. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2831. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2832. sizeof(union drv_info_to_mcp));
  2833. switch (op_code) {
  2834. case ETH_STATS_OPCODE:
  2835. bnx2x_drv_info_ether_stat(bp);
  2836. break;
  2837. case FCOE_STATS_OPCODE:
  2838. bnx2x_drv_info_fcoe_stat(bp);
  2839. break;
  2840. case ISCSI_STATS_OPCODE:
  2841. bnx2x_drv_info_iscsi_stat(bp);
  2842. break;
  2843. default:
  2844. /* if op code isn't supported - send NACK */
  2845. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2846. return;
  2847. }
  2848. /* if we got drv_info attn from MFW then these fields are defined in
  2849. * shmem2 for sure
  2850. */
  2851. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2852. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2853. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2854. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2855. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2856. }
  2857. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2858. {
  2859. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2860. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2861. /*
  2862. * This is the only place besides the function initialization
  2863. * where the bp->flags can change so it is done without any
  2864. * locks
  2865. */
  2866. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2867. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2868. bp->flags |= MF_FUNC_DIS;
  2869. bnx2x_e1h_disable(bp);
  2870. } else {
  2871. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2872. bp->flags &= ~MF_FUNC_DIS;
  2873. bnx2x_e1h_enable(bp);
  2874. }
  2875. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2876. }
  2877. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2878. bnx2x_config_mf_bw(bp);
  2879. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2880. }
  2881. /* Report results to MCP */
  2882. if (dcc_event)
  2883. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2884. else
  2885. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2886. }
  2887. /* must be called under the spq lock */
  2888. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2889. {
  2890. struct eth_spe *next_spe = bp->spq_prod_bd;
  2891. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2892. bp->spq_prod_bd = bp->spq;
  2893. bp->spq_prod_idx = 0;
  2894. DP(BNX2X_MSG_SP, "end of spq\n");
  2895. } else {
  2896. bp->spq_prod_bd++;
  2897. bp->spq_prod_idx++;
  2898. }
  2899. return next_spe;
  2900. }
  2901. /* must be called under the spq lock */
  2902. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2903. {
  2904. int func = BP_FUNC(bp);
  2905. /*
  2906. * Make sure that BD data is updated before writing the producer:
  2907. * BD data is written to the memory, the producer is read from the
  2908. * memory, thus we need a full memory barrier to ensure the ordering.
  2909. */
  2910. mb();
  2911. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2912. bp->spq_prod_idx);
  2913. mmiowb();
  2914. }
  2915. /**
  2916. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2917. *
  2918. * @cmd: command to check
  2919. * @cmd_type: command type
  2920. */
  2921. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2922. {
  2923. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2924. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2925. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2926. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2927. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2928. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2929. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2930. return true;
  2931. else
  2932. return false;
  2933. }
  2934. /**
  2935. * bnx2x_sp_post - place a single command on an SP ring
  2936. *
  2937. * @bp: driver handle
  2938. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2939. * @cid: SW CID the command is related to
  2940. * @data_hi: command private data address (high 32 bits)
  2941. * @data_lo: command private data address (low 32 bits)
  2942. * @cmd_type: command type (e.g. NONE, ETH)
  2943. *
  2944. * SP data is handled as if it's always an address pair, thus data fields are
  2945. * not swapped to little endian in upper functions. Instead this function swaps
  2946. * data as if it's two u32 fields.
  2947. */
  2948. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2949. u32 data_hi, u32 data_lo, int cmd_type)
  2950. {
  2951. struct eth_spe *spe;
  2952. u16 type;
  2953. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2954. #ifdef BNX2X_STOP_ON_ERROR
  2955. if (unlikely(bp->panic)) {
  2956. BNX2X_ERR("Can't post SP when there is panic\n");
  2957. return -EIO;
  2958. }
  2959. #endif
  2960. spin_lock_bh(&bp->spq_lock);
  2961. if (common) {
  2962. if (!atomic_read(&bp->eq_spq_left)) {
  2963. BNX2X_ERR("BUG! EQ ring full!\n");
  2964. spin_unlock_bh(&bp->spq_lock);
  2965. bnx2x_panic();
  2966. return -EBUSY;
  2967. }
  2968. } else if (!atomic_read(&bp->cq_spq_left)) {
  2969. BNX2X_ERR("BUG! SPQ ring full!\n");
  2970. spin_unlock_bh(&bp->spq_lock);
  2971. bnx2x_panic();
  2972. return -EBUSY;
  2973. }
  2974. spe = bnx2x_sp_get_next(bp);
  2975. /* CID needs port number to be encoded int it */
  2976. spe->hdr.conn_and_cmd_data =
  2977. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  2978. HW_CID(bp, cid));
  2979. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  2980. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  2981. SPE_HDR_FUNCTION_ID);
  2982. spe->hdr.type = cpu_to_le16(type);
  2983. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  2984. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  2985. /*
  2986. * It's ok if the actual decrement is issued towards the memory
  2987. * somewhere between the spin_lock and spin_unlock. Thus no
  2988. * more explict memory barrier is needed.
  2989. */
  2990. if (common)
  2991. atomic_dec(&bp->eq_spq_left);
  2992. else
  2993. atomic_dec(&bp->cq_spq_left);
  2994. DP(BNX2X_MSG_SP,
  2995. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  2996. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  2997. (u32)(U64_LO(bp->spq_mapping) +
  2998. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  2999. HW_CID(bp, cid), data_hi, data_lo, type,
  3000. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3001. bnx2x_sp_prod_update(bp);
  3002. spin_unlock_bh(&bp->spq_lock);
  3003. return 0;
  3004. }
  3005. /* acquire split MCP access lock register */
  3006. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3007. {
  3008. u32 j, val;
  3009. int rc = 0;
  3010. might_sleep();
  3011. for (j = 0; j < 1000; j++) {
  3012. val = (1UL << 31);
  3013. REG_WR(bp, GRCBASE_MCP + 0x9c, val);
  3014. val = REG_RD(bp, GRCBASE_MCP + 0x9c);
  3015. if (val & (1L << 31))
  3016. break;
  3017. msleep(5);
  3018. }
  3019. if (!(val & (1L << 31))) {
  3020. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3021. rc = -EBUSY;
  3022. }
  3023. return rc;
  3024. }
  3025. /* release split MCP access lock register */
  3026. static void bnx2x_release_alr(struct bnx2x *bp)
  3027. {
  3028. REG_WR(bp, GRCBASE_MCP + 0x9c, 0);
  3029. }
  3030. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3031. #define BNX2X_DEF_SB_IDX 0x0002
  3032. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3033. {
  3034. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3035. u16 rc = 0;
  3036. barrier(); /* status block is written to by the chip */
  3037. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3038. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3039. rc |= BNX2X_DEF_SB_ATT_IDX;
  3040. }
  3041. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3042. bp->def_idx = def_sb->sp_sb.running_index;
  3043. rc |= BNX2X_DEF_SB_IDX;
  3044. }
  3045. /* Do not reorder: indecies reading should complete before handling */
  3046. barrier();
  3047. return rc;
  3048. }
  3049. /*
  3050. * slow path service functions
  3051. */
  3052. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3053. {
  3054. int port = BP_PORT(bp);
  3055. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3056. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3057. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3058. NIG_REG_MASK_INTERRUPT_PORT0;
  3059. u32 aeu_mask;
  3060. u32 nig_mask = 0;
  3061. u32 reg_addr;
  3062. if (bp->attn_state & asserted)
  3063. BNX2X_ERR("IGU ERROR\n");
  3064. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3065. aeu_mask = REG_RD(bp, aeu_addr);
  3066. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3067. aeu_mask, asserted);
  3068. aeu_mask &= ~(asserted & 0x3ff);
  3069. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3070. REG_WR(bp, aeu_addr, aeu_mask);
  3071. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3072. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3073. bp->attn_state |= asserted;
  3074. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3075. if (asserted & ATTN_HARD_WIRED_MASK) {
  3076. if (asserted & ATTN_NIG_FOR_FUNC) {
  3077. bnx2x_acquire_phy_lock(bp);
  3078. /* save nig interrupt mask */
  3079. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3080. /* If nig_mask is not set, no need to call the update
  3081. * function.
  3082. */
  3083. if (nig_mask) {
  3084. REG_WR(bp, nig_int_mask_addr, 0);
  3085. bnx2x_link_attn(bp);
  3086. }
  3087. /* handle unicore attn? */
  3088. }
  3089. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3090. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3091. if (asserted & GPIO_2_FUNC)
  3092. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3093. if (asserted & GPIO_3_FUNC)
  3094. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3095. if (asserted & GPIO_4_FUNC)
  3096. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3097. if (port == 0) {
  3098. if (asserted & ATTN_GENERAL_ATTN_1) {
  3099. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3100. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3101. }
  3102. if (asserted & ATTN_GENERAL_ATTN_2) {
  3103. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3104. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3105. }
  3106. if (asserted & ATTN_GENERAL_ATTN_3) {
  3107. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3108. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3109. }
  3110. } else {
  3111. if (asserted & ATTN_GENERAL_ATTN_4) {
  3112. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3113. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3114. }
  3115. if (asserted & ATTN_GENERAL_ATTN_5) {
  3116. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3117. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3118. }
  3119. if (asserted & ATTN_GENERAL_ATTN_6) {
  3120. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3121. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3122. }
  3123. }
  3124. } /* if hardwired */
  3125. if (bp->common.int_block == INT_BLOCK_HC)
  3126. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3127. COMMAND_REG_ATTN_BITS_SET);
  3128. else
  3129. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3130. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3131. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3132. REG_WR(bp, reg_addr, asserted);
  3133. /* now set back the mask */
  3134. if (asserted & ATTN_NIG_FOR_FUNC) {
  3135. /* Verify that IGU ack through BAR was written before restoring
  3136. * NIG mask. This loop should exit after 2-3 iterations max.
  3137. */
  3138. if (bp->common.int_block != INT_BLOCK_HC) {
  3139. u32 cnt = 0, igu_acked;
  3140. do {
  3141. igu_acked = REG_RD(bp,
  3142. IGU_REG_ATTENTION_ACK_BITS);
  3143. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3144. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3145. if (!igu_acked)
  3146. DP(NETIF_MSG_HW,
  3147. "Failed to verify IGU ack on time\n");
  3148. barrier();
  3149. }
  3150. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3151. bnx2x_release_phy_lock(bp);
  3152. }
  3153. }
  3154. static void bnx2x_fan_failure(struct bnx2x *bp)
  3155. {
  3156. int port = BP_PORT(bp);
  3157. u32 ext_phy_config;
  3158. /* mark the failure */
  3159. ext_phy_config =
  3160. SHMEM_RD(bp,
  3161. dev_info.port_hw_config[port].external_phy_config);
  3162. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3163. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3164. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3165. ext_phy_config);
  3166. /* log the failure */
  3167. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3168. "Please contact OEM Support for assistance\n");
  3169. /*
  3170. * Scheudle device reset (unload)
  3171. * This is due to some boards consuming sufficient power when driver is
  3172. * up to overheat if fan fails.
  3173. */
  3174. smp_mb__before_clear_bit();
  3175. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3176. smp_mb__after_clear_bit();
  3177. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3178. }
  3179. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3180. {
  3181. int port = BP_PORT(bp);
  3182. int reg_offset;
  3183. u32 val;
  3184. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3185. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3186. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3187. val = REG_RD(bp, reg_offset);
  3188. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3189. REG_WR(bp, reg_offset, val);
  3190. BNX2X_ERR("SPIO5 hw attention\n");
  3191. /* Fan failure attention */
  3192. bnx2x_hw_reset_phy(&bp->link_params);
  3193. bnx2x_fan_failure(bp);
  3194. }
  3195. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3196. bnx2x_acquire_phy_lock(bp);
  3197. bnx2x_handle_module_detect_int(&bp->link_params);
  3198. bnx2x_release_phy_lock(bp);
  3199. }
  3200. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3201. val = REG_RD(bp, reg_offset);
  3202. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3203. REG_WR(bp, reg_offset, val);
  3204. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3205. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3206. bnx2x_panic();
  3207. }
  3208. }
  3209. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3210. {
  3211. u32 val;
  3212. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3213. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3214. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3215. /* DORQ discard attention */
  3216. if (val & 0x2)
  3217. BNX2X_ERR("FATAL error from DORQ\n");
  3218. }
  3219. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3220. int port = BP_PORT(bp);
  3221. int reg_offset;
  3222. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3223. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3224. val = REG_RD(bp, reg_offset);
  3225. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3226. REG_WR(bp, reg_offset, val);
  3227. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3228. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3229. bnx2x_panic();
  3230. }
  3231. }
  3232. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3233. {
  3234. u32 val;
  3235. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3236. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3237. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3238. /* CFC error attention */
  3239. if (val & 0x2)
  3240. BNX2X_ERR("FATAL error from CFC\n");
  3241. }
  3242. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3243. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3244. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3245. /* RQ_USDMDP_FIFO_OVERFLOW */
  3246. if (val & 0x18000)
  3247. BNX2X_ERR("FATAL error from PXP\n");
  3248. if (!CHIP_IS_E1x(bp)) {
  3249. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3250. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3251. }
  3252. }
  3253. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3254. int port = BP_PORT(bp);
  3255. int reg_offset;
  3256. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3257. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3258. val = REG_RD(bp, reg_offset);
  3259. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3260. REG_WR(bp, reg_offset, val);
  3261. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3262. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3263. bnx2x_panic();
  3264. }
  3265. }
  3266. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3267. {
  3268. u32 val;
  3269. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3270. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3271. int func = BP_FUNC(bp);
  3272. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3273. bnx2x_read_mf_cfg(bp);
  3274. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3275. func_mf_config[BP_ABS_FUNC(bp)].config);
  3276. val = SHMEM_RD(bp,
  3277. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3278. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3279. bnx2x_dcc_event(bp,
  3280. (val & DRV_STATUS_DCC_EVENT_MASK));
  3281. if (val & DRV_STATUS_SET_MF_BW)
  3282. bnx2x_set_mf_bw(bp);
  3283. if (val & DRV_STATUS_DRV_INFO_REQ)
  3284. bnx2x_handle_drv_info_req(bp);
  3285. if (val & DRV_STATUS_VF_DISABLED)
  3286. bnx2x_vf_handle_flr_event(bp);
  3287. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3288. bnx2x_pmf_update(bp);
  3289. if (bp->port.pmf &&
  3290. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3291. bp->dcbx_enabled > 0)
  3292. /* start dcbx state machine */
  3293. bnx2x_dcbx_set_params(bp,
  3294. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3295. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3296. bnx2x_handle_afex_cmd(bp,
  3297. val & DRV_STATUS_AFEX_EVENT_MASK);
  3298. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3299. bnx2x_handle_eee_event(bp);
  3300. if (bp->link_vars.periodic_flags &
  3301. PERIODIC_FLAGS_LINK_EVENT) {
  3302. /* sync with link */
  3303. bnx2x_acquire_phy_lock(bp);
  3304. bp->link_vars.periodic_flags &=
  3305. ~PERIODIC_FLAGS_LINK_EVENT;
  3306. bnx2x_release_phy_lock(bp);
  3307. if (IS_MF(bp))
  3308. bnx2x_link_sync_notify(bp);
  3309. bnx2x_link_report(bp);
  3310. }
  3311. /* Always call it here: bnx2x_link_report() will
  3312. * prevent the link indication duplication.
  3313. */
  3314. bnx2x__link_status_update(bp);
  3315. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3316. BNX2X_ERR("MC assert!\n");
  3317. bnx2x_mc_assert(bp);
  3318. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3319. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3320. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3321. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3322. bnx2x_panic();
  3323. } else if (attn & BNX2X_MCP_ASSERT) {
  3324. BNX2X_ERR("MCP assert!\n");
  3325. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3326. bnx2x_fw_dump(bp);
  3327. } else
  3328. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3329. }
  3330. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3331. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3332. if (attn & BNX2X_GRC_TIMEOUT) {
  3333. val = CHIP_IS_E1(bp) ? 0 :
  3334. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3335. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3336. }
  3337. if (attn & BNX2X_GRC_RSV) {
  3338. val = CHIP_IS_E1(bp) ? 0 :
  3339. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3340. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3341. }
  3342. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3343. }
  3344. }
  3345. /*
  3346. * Bits map:
  3347. * 0-7 - Engine0 load counter.
  3348. * 8-15 - Engine1 load counter.
  3349. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3350. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3351. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3352. * on the engine
  3353. * 19 - Engine1 ONE_IS_LOADED.
  3354. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3355. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3356. * just the one belonging to its engine).
  3357. *
  3358. */
  3359. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3360. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3361. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3362. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3363. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3364. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3365. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3366. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3367. /*
  3368. * Set the GLOBAL_RESET bit.
  3369. *
  3370. * Should be run under rtnl lock
  3371. */
  3372. void bnx2x_set_reset_global(struct bnx2x *bp)
  3373. {
  3374. u32 val;
  3375. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3376. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3377. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3378. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3379. }
  3380. /*
  3381. * Clear the GLOBAL_RESET bit.
  3382. *
  3383. * Should be run under rtnl lock
  3384. */
  3385. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3386. {
  3387. u32 val;
  3388. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3389. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3390. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3391. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3392. }
  3393. /*
  3394. * Checks the GLOBAL_RESET bit.
  3395. *
  3396. * should be run under rtnl lock
  3397. */
  3398. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3399. {
  3400. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3401. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3402. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3403. }
  3404. /*
  3405. * Clear RESET_IN_PROGRESS bit for the current engine.
  3406. *
  3407. * Should be run under rtnl lock
  3408. */
  3409. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3410. {
  3411. u32 val;
  3412. u32 bit = BP_PATH(bp) ?
  3413. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3414. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3415. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3416. /* Clear the bit */
  3417. val &= ~bit;
  3418. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3419. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3420. }
  3421. /*
  3422. * Set RESET_IN_PROGRESS for the current engine.
  3423. *
  3424. * should be run under rtnl lock
  3425. */
  3426. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3427. {
  3428. u32 val;
  3429. u32 bit = BP_PATH(bp) ?
  3430. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3431. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3432. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3433. /* Set the bit */
  3434. val |= bit;
  3435. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3436. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3437. }
  3438. /*
  3439. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3440. * should be run under rtnl lock
  3441. */
  3442. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3443. {
  3444. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3445. u32 bit = engine ?
  3446. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3447. /* return false if bit is set */
  3448. return (val & bit) ? false : true;
  3449. }
  3450. /*
  3451. * set pf load for the current pf.
  3452. *
  3453. * should be run under rtnl lock
  3454. */
  3455. void bnx2x_set_pf_load(struct bnx2x *bp)
  3456. {
  3457. u32 val1, val;
  3458. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3459. BNX2X_PATH0_LOAD_CNT_MASK;
  3460. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3461. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3462. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3463. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3464. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3465. /* get the current counter value */
  3466. val1 = (val & mask) >> shift;
  3467. /* set bit of that PF */
  3468. val1 |= (1 << bp->pf_num);
  3469. /* clear the old value */
  3470. val &= ~mask;
  3471. /* set the new one */
  3472. val |= ((val1 << shift) & mask);
  3473. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3474. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3475. }
  3476. /**
  3477. * bnx2x_clear_pf_load - clear pf load mark
  3478. *
  3479. * @bp: driver handle
  3480. *
  3481. * Should be run under rtnl lock.
  3482. * Decrements the load counter for the current engine. Returns
  3483. * whether other functions are still loaded
  3484. */
  3485. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3486. {
  3487. u32 val1, val;
  3488. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3489. BNX2X_PATH0_LOAD_CNT_MASK;
  3490. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3491. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3492. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3493. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3494. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3495. /* get the current counter value */
  3496. val1 = (val & mask) >> shift;
  3497. /* clear bit of that PF */
  3498. val1 &= ~(1 << bp->pf_num);
  3499. /* clear the old value */
  3500. val &= ~mask;
  3501. /* set the new one */
  3502. val |= ((val1 << shift) & mask);
  3503. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3504. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3505. return val1 != 0;
  3506. }
  3507. /*
  3508. * Read the load status for the current engine.
  3509. *
  3510. * should be run under rtnl lock
  3511. */
  3512. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3513. {
  3514. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3515. BNX2X_PATH0_LOAD_CNT_MASK);
  3516. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3517. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3518. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3519. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3520. val = (val & mask) >> shift;
  3521. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3522. engine, val);
  3523. return val != 0;
  3524. }
  3525. static void _print_next_block(int idx, const char *blk)
  3526. {
  3527. pr_cont("%s%s", idx ? ", " : "", blk);
  3528. }
  3529. static int bnx2x_check_blocks_with_parity0(u32 sig, int par_num,
  3530. bool print)
  3531. {
  3532. int i = 0;
  3533. u32 cur_bit = 0;
  3534. for (i = 0; sig; i++) {
  3535. cur_bit = ((u32)0x1 << i);
  3536. if (sig & cur_bit) {
  3537. switch (cur_bit) {
  3538. case AEU_INPUTS_ATTN_BITS_BRB_PARITY_ERROR:
  3539. if (print)
  3540. _print_next_block(par_num++, "BRB");
  3541. break;
  3542. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3543. if (print)
  3544. _print_next_block(par_num++, "PARSER");
  3545. break;
  3546. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3547. if (print)
  3548. _print_next_block(par_num++, "TSDM");
  3549. break;
  3550. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3551. if (print)
  3552. _print_next_block(par_num++,
  3553. "SEARCHER");
  3554. break;
  3555. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3556. if (print)
  3557. _print_next_block(par_num++, "TCM");
  3558. break;
  3559. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3560. if (print)
  3561. _print_next_block(par_num++, "TSEMI");
  3562. break;
  3563. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3564. if (print)
  3565. _print_next_block(par_num++, "XPB");
  3566. break;
  3567. }
  3568. /* Clear the bit */
  3569. sig &= ~cur_bit;
  3570. }
  3571. }
  3572. return par_num;
  3573. }
  3574. static int bnx2x_check_blocks_with_parity1(u32 sig, int par_num,
  3575. bool *global, bool print)
  3576. {
  3577. int i = 0;
  3578. u32 cur_bit = 0;
  3579. for (i = 0; sig; i++) {
  3580. cur_bit = ((u32)0x1 << i);
  3581. if (sig & cur_bit) {
  3582. switch (cur_bit) {
  3583. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3584. if (print)
  3585. _print_next_block(par_num++, "PBF");
  3586. break;
  3587. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3588. if (print)
  3589. _print_next_block(par_num++, "QM");
  3590. break;
  3591. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3592. if (print)
  3593. _print_next_block(par_num++, "TM");
  3594. break;
  3595. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3596. if (print)
  3597. _print_next_block(par_num++, "XSDM");
  3598. break;
  3599. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3600. if (print)
  3601. _print_next_block(par_num++, "XCM");
  3602. break;
  3603. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3604. if (print)
  3605. _print_next_block(par_num++, "XSEMI");
  3606. break;
  3607. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3608. if (print)
  3609. _print_next_block(par_num++,
  3610. "DOORBELLQ");
  3611. break;
  3612. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3613. if (print)
  3614. _print_next_block(par_num++, "NIG");
  3615. break;
  3616. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3617. if (print)
  3618. _print_next_block(par_num++,
  3619. "VAUX PCI CORE");
  3620. *global = true;
  3621. break;
  3622. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3623. if (print)
  3624. _print_next_block(par_num++, "DEBUG");
  3625. break;
  3626. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3627. if (print)
  3628. _print_next_block(par_num++, "USDM");
  3629. break;
  3630. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3631. if (print)
  3632. _print_next_block(par_num++, "UCM");
  3633. break;
  3634. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3635. if (print)
  3636. _print_next_block(par_num++, "USEMI");
  3637. break;
  3638. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3639. if (print)
  3640. _print_next_block(par_num++, "UPB");
  3641. break;
  3642. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3643. if (print)
  3644. _print_next_block(par_num++, "CSDM");
  3645. break;
  3646. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3647. if (print)
  3648. _print_next_block(par_num++, "CCM");
  3649. break;
  3650. }
  3651. /* Clear the bit */
  3652. sig &= ~cur_bit;
  3653. }
  3654. }
  3655. return par_num;
  3656. }
  3657. static int bnx2x_check_blocks_with_parity2(u32 sig, int par_num,
  3658. bool print)
  3659. {
  3660. int i = 0;
  3661. u32 cur_bit = 0;
  3662. for (i = 0; sig; i++) {
  3663. cur_bit = ((u32)0x1 << i);
  3664. if (sig & cur_bit) {
  3665. switch (cur_bit) {
  3666. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3667. if (print)
  3668. _print_next_block(par_num++, "CSEMI");
  3669. break;
  3670. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3671. if (print)
  3672. _print_next_block(par_num++, "PXP");
  3673. break;
  3674. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3675. if (print)
  3676. _print_next_block(par_num++,
  3677. "PXPPCICLOCKCLIENT");
  3678. break;
  3679. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3680. if (print)
  3681. _print_next_block(par_num++, "CFC");
  3682. break;
  3683. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3684. if (print)
  3685. _print_next_block(par_num++, "CDU");
  3686. break;
  3687. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3688. if (print)
  3689. _print_next_block(par_num++, "DMAE");
  3690. break;
  3691. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3692. if (print)
  3693. _print_next_block(par_num++, "IGU");
  3694. break;
  3695. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3696. if (print)
  3697. _print_next_block(par_num++, "MISC");
  3698. break;
  3699. }
  3700. /* Clear the bit */
  3701. sig &= ~cur_bit;
  3702. }
  3703. }
  3704. return par_num;
  3705. }
  3706. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3707. bool *global, bool print)
  3708. {
  3709. int i = 0;
  3710. u32 cur_bit = 0;
  3711. for (i = 0; sig; i++) {
  3712. cur_bit = ((u32)0x1 << i);
  3713. if (sig & cur_bit) {
  3714. switch (cur_bit) {
  3715. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3716. if (print)
  3717. _print_next_block(par_num++, "MCP ROM");
  3718. *global = true;
  3719. break;
  3720. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3721. if (print)
  3722. _print_next_block(par_num++,
  3723. "MCP UMP RX");
  3724. *global = true;
  3725. break;
  3726. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3727. if (print)
  3728. _print_next_block(par_num++,
  3729. "MCP UMP TX");
  3730. *global = true;
  3731. break;
  3732. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3733. if (print)
  3734. _print_next_block(par_num++,
  3735. "MCP SCPAD");
  3736. *global = true;
  3737. break;
  3738. }
  3739. /* Clear the bit */
  3740. sig &= ~cur_bit;
  3741. }
  3742. }
  3743. return par_num;
  3744. }
  3745. static int bnx2x_check_blocks_with_parity4(u32 sig, int par_num,
  3746. bool print)
  3747. {
  3748. int i = 0;
  3749. u32 cur_bit = 0;
  3750. for (i = 0; sig; i++) {
  3751. cur_bit = ((u32)0x1 << i);
  3752. if (sig & cur_bit) {
  3753. switch (cur_bit) {
  3754. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3755. if (print)
  3756. _print_next_block(par_num++, "PGLUE_B");
  3757. break;
  3758. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3759. if (print)
  3760. _print_next_block(par_num++, "ATC");
  3761. break;
  3762. }
  3763. /* Clear the bit */
  3764. sig &= ~cur_bit;
  3765. }
  3766. }
  3767. return par_num;
  3768. }
  3769. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3770. u32 *sig)
  3771. {
  3772. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3773. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3774. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3775. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3776. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3777. int par_num = 0;
  3778. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3779. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3780. sig[0] & HW_PRTY_ASSERT_SET_0,
  3781. sig[1] & HW_PRTY_ASSERT_SET_1,
  3782. sig[2] & HW_PRTY_ASSERT_SET_2,
  3783. sig[3] & HW_PRTY_ASSERT_SET_3,
  3784. sig[4] & HW_PRTY_ASSERT_SET_4);
  3785. if (print)
  3786. netdev_err(bp->dev,
  3787. "Parity errors detected in blocks: ");
  3788. par_num = bnx2x_check_blocks_with_parity0(
  3789. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3790. par_num = bnx2x_check_blocks_with_parity1(
  3791. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3792. par_num = bnx2x_check_blocks_with_parity2(
  3793. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3794. par_num = bnx2x_check_blocks_with_parity3(
  3795. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3796. par_num = bnx2x_check_blocks_with_parity4(
  3797. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3798. if (print)
  3799. pr_cont("\n");
  3800. return true;
  3801. } else
  3802. return false;
  3803. }
  3804. /**
  3805. * bnx2x_chk_parity_attn - checks for parity attentions.
  3806. *
  3807. * @bp: driver handle
  3808. * @global: true if there was a global attention
  3809. * @print: show parity attention in syslog
  3810. */
  3811. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3812. {
  3813. struct attn_route attn = { {0} };
  3814. int port = BP_PORT(bp);
  3815. attn.sig[0] = REG_RD(bp,
  3816. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3817. port*4);
  3818. attn.sig[1] = REG_RD(bp,
  3819. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3820. port*4);
  3821. attn.sig[2] = REG_RD(bp,
  3822. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3823. port*4);
  3824. attn.sig[3] = REG_RD(bp,
  3825. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3826. port*4);
  3827. if (!CHIP_IS_E1x(bp))
  3828. attn.sig[4] = REG_RD(bp,
  3829. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3830. port*4);
  3831. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3832. }
  3833. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3834. {
  3835. u32 val;
  3836. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3837. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3838. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3839. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3840. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3841. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3842. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3843. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3844. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3845. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3846. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3847. if (val &
  3848. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  3849. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  3850. if (val &
  3851. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  3852. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  3853. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  3854. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  3855. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  3856. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  3857. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  3858. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  3859. }
  3860. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  3861. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  3862. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  3863. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  3864. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  3865. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  3866. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  3867. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  3868. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  3869. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  3870. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  3871. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  3872. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  3873. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  3874. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  3875. }
  3876. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3877. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  3878. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  3879. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  3880. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  3881. }
  3882. }
  3883. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  3884. {
  3885. struct attn_route attn, *group_mask;
  3886. int port = BP_PORT(bp);
  3887. int index;
  3888. u32 reg_addr;
  3889. u32 val;
  3890. u32 aeu_mask;
  3891. bool global = false;
  3892. /* need to take HW lock because MCP or other port might also
  3893. try to handle this event */
  3894. bnx2x_acquire_alr(bp);
  3895. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  3896. #ifndef BNX2X_STOP_ON_ERROR
  3897. bp->recovery_state = BNX2X_RECOVERY_INIT;
  3898. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3899. /* Disable HW interrupts */
  3900. bnx2x_int_disable(bp);
  3901. /* In case of parity errors don't handle attentions so that
  3902. * other function would "see" parity errors.
  3903. */
  3904. #else
  3905. bnx2x_panic();
  3906. #endif
  3907. bnx2x_release_alr(bp);
  3908. return;
  3909. }
  3910. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  3911. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  3912. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  3913. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  3914. if (!CHIP_IS_E1x(bp))
  3915. attn.sig[4] =
  3916. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  3917. else
  3918. attn.sig[4] = 0;
  3919. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  3920. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  3921. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  3922. if (deasserted & (1 << index)) {
  3923. group_mask = &bp->attn_group[index];
  3924. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  3925. index,
  3926. group_mask->sig[0], group_mask->sig[1],
  3927. group_mask->sig[2], group_mask->sig[3],
  3928. group_mask->sig[4]);
  3929. bnx2x_attn_int_deasserted4(bp,
  3930. attn.sig[4] & group_mask->sig[4]);
  3931. bnx2x_attn_int_deasserted3(bp,
  3932. attn.sig[3] & group_mask->sig[3]);
  3933. bnx2x_attn_int_deasserted1(bp,
  3934. attn.sig[1] & group_mask->sig[1]);
  3935. bnx2x_attn_int_deasserted2(bp,
  3936. attn.sig[2] & group_mask->sig[2]);
  3937. bnx2x_attn_int_deasserted0(bp,
  3938. attn.sig[0] & group_mask->sig[0]);
  3939. }
  3940. }
  3941. bnx2x_release_alr(bp);
  3942. if (bp->common.int_block == INT_BLOCK_HC)
  3943. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3944. COMMAND_REG_ATTN_BITS_CLR);
  3945. else
  3946. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  3947. val = ~deasserted;
  3948. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  3949. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3950. REG_WR(bp, reg_addr, val);
  3951. if (~bp->attn_state & deasserted)
  3952. BNX2X_ERR("IGU ERROR\n");
  3953. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3954. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3955. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3956. aeu_mask = REG_RD(bp, reg_addr);
  3957. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  3958. aeu_mask, deasserted);
  3959. aeu_mask |= (deasserted & 0x3ff);
  3960. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3961. REG_WR(bp, reg_addr, aeu_mask);
  3962. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3963. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3964. bp->attn_state &= ~deasserted;
  3965. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3966. }
  3967. static void bnx2x_attn_int(struct bnx2x *bp)
  3968. {
  3969. /* read local copy of bits */
  3970. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3971. attn_bits);
  3972. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  3973. attn_bits_ack);
  3974. u32 attn_state = bp->attn_state;
  3975. /* look for changed bits */
  3976. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  3977. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  3978. DP(NETIF_MSG_HW,
  3979. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  3980. attn_bits, attn_ack, asserted, deasserted);
  3981. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  3982. BNX2X_ERR("BAD attention state\n");
  3983. /* handle bits that were raised */
  3984. if (asserted)
  3985. bnx2x_attn_int_asserted(bp, asserted);
  3986. if (deasserted)
  3987. bnx2x_attn_int_deasserted(bp, deasserted);
  3988. }
  3989. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  3990. u16 index, u8 op, u8 update)
  3991. {
  3992. u32 igu_addr = bp->igu_base_addr;
  3993. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  3994. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  3995. igu_addr);
  3996. }
  3997. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  3998. {
  3999. /* No memory barriers */
  4000. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4001. mmiowb(); /* keep prod updates ordered */
  4002. }
  4003. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4004. union event_ring_elem *elem)
  4005. {
  4006. u8 err = elem->message.error;
  4007. if (!bp->cnic_eth_dev.starting_cid ||
  4008. (cid < bp->cnic_eth_dev.starting_cid &&
  4009. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4010. return 1;
  4011. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4012. if (unlikely(err)) {
  4013. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4014. cid);
  4015. bnx2x_panic_dump(bp, false);
  4016. }
  4017. bnx2x_cnic_cfc_comp(bp, cid, err);
  4018. return 0;
  4019. }
  4020. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4021. {
  4022. struct bnx2x_mcast_ramrod_params rparam;
  4023. int rc;
  4024. memset(&rparam, 0, sizeof(rparam));
  4025. rparam.mcast_obj = &bp->mcast_obj;
  4026. netif_addr_lock_bh(bp->dev);
  4027. /* Clear pending state for the last command */
  4028. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4029. /* If there are pending mcast commands - send them */
  4030. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4031. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4032. if (rc < 0)
  4033. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4034. rc);
  4035. }
  4036. netif_addr_unlock_bh(bp->dev);
  4037. }
  4038. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4039. union event_ring_elem *elem)
  4040. {
  4041. unsigned long ramrod_flags = 0;
  4042. int rc = 0;
  4043. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4044. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4045. /* Always push next commands out, don't wait here */
  4046. __set_bit(RAMROD_CONT, &ramrod_flags);
  4047. switch (elem->message.data.eth_event.echo >> BNX2X_SWCID_SHIFT) {
  4048. case BNX2X_FILTER_MAC_PENDING:
  4049. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4050. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4051. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4052. else
  4053. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4054. break;
  4055. case BNX2X_FILTER_MCAST_PENDING:
  4056. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4057. /* This is only relevant for 57710 where multicast MACs are
  4058. * configured as unicast MACs using the same ramrod.
  4059. */
  4060. bnx2x_handle_mcast_eqe(bp);
  4061. return;
  4062. default:
  4063. BNX2X_ERR("Unsupported classification command: %d\n",
  4064. elem->message.data.eth_event.echo);
  4065. return;
  4066. }
  4067. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4068. if (rc < 0)
  4069. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4070. else if (rc > 0)
  4071. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4072. }
  4073. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4074. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4075. {
  4076. netif_addr_lock_bh(bp->dev);
  4077. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4078. /* Send rx_mode command again if was requested */
  4079. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4080. bnx2x_set_storm_rx_mode(bp);
  4081. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4082. &bp->sp_state))
  4083. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4084. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4085. &bp->sp_state))
  4086. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4087. netif_addr_unlock_bh(bp->dev);
  4088. }
  4089. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4090. union event_ring_elem *elem)
  4091. {
  4092. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4093. DP(BNX2X_MSG_SP,
  4094. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4095. elem->message.data.vif_list_event.func_bit_map);
  4096. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4097. elem->message.data.vif_list_event.func_bit_map);
  4098. } else if (elem->message.data.vif_list_event.echo ==
  4099. VIF_LIST_RULE_SET) {
  4100. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4101. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4102. }
  4103. }
  4104. /* called with rtnl_lock */
  4105. static void bnx2x_after_function_update(struct bnx2x *bp)
  4106. {
  4107. int q, rc;
  4108. struct bnx2x_fastpath *fp;
  4109. struct bnx2x_queue_state_params queue_params = {NULL};
  4110. struct bnx2x_queue_update_params *q_update_params =
  4111. &queue_params.params.update;
  4112. /* Send Q update command with afex vlan removal values for all Qs */
  4113. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4114. /* set silent vlan removal values according to vlan mode */
  4115. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4116. &q_update_params->update_flags);
  4117. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4118. &q_update_params->update_flags);
  4119. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4120. /* in access mode mark mask and value are 0 to strip all vlans */
  4121. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4122. q_update_params->silent_removal_value = 0;
  4123. q_update_params->silent_removal_mask = 0;
  4124. } else {
  4125. q_update_params->silent_removal_value =
  4126. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4127. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4128. }
  4129. for_each_eth_queue(bp, q) {
  4130. /* Set the appropriate Queue object */
  4131. fp = &bp->fp[q];
  4132. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4133. /* send the ramrod */
  4134. rc = bnx2x_queue_state_change(bp, &queue_params);
  4135. if (rc < 0)
  4136. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4137. q);
  4138. }
  4139. if (!NO_FCOE(bp)) {
  4140. fp = &bp->fp[FCOE_IDX(bp)];
  4141. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4142. /* clear pending completion bit */
  4143. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4144. /* mark latest Q bit */
  4145. smp_mb__before_clear_bit();
  4146. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4147. smp_mb__after_clear_bit();
  4148. /* send Q update ramrod for FCoE Q */
  4149. rc = bnx2x_queue_state_change(bp, &queue_params);
  4150. if (rc < 0)
  4151. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4152. q);
  4153. } else {
  4154. /* If no FCoE ring - ACK MCP now */
  4155. bnx2x_link_report(bp);
  4156. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4157. }
  4158. }
  4159. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4160. struct bnx2x *bp, u32 cid)
  4161. {
  4162. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4163. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4164. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4165. else
  4166. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4167. }
  4168. static void bnx2x_eq_int(struct bnx2x *bp)
  4169. {
  4170. u16 hw_cons, sw_cons, sw_prod;
  4171. union event_ring_elem *elem;
  4172. u8 echo;
  4173. u32 cid;
  4174. u8 opcode;
  4175. int rc, spqe_cnt = 0;
  4176. struct bnx2x_queue_sp_obj *q_obj;
  4177. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4178. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4179. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4180. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4181. * when we get the the next-page we nned to adjust so the loop
  4182. * condition below will be met. The next element is the size of a
  4183. * regular element and hence incrementing by 1
  4184. */
  4185. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4186. hw_cons++;
  4187. /* This function may never run in parallel with itself for a
  4188. * specific bp, thus there is no need in "paired" read memory
  4189. * barrier here.
  4190. */
  4191. sw_cons = bp->eq_cons;
  4192. sw_prod = bp->eq_prod;
  4193. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4194. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4195. for (; sw_cons != hw_cons;
  4196. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4197. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4198. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4199. if (!rc) {
  4200. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4201. rc);
  4202. goto next_spqe;
  4203. }
  4204. cid = SW_CID(elem->message.data.cfc_del_event.cid);
  4205. opcode = elem->message.opcode;
  4206. /* handle eq element */
  4207. switch (opcode) {
  4208. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4209. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4210. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4211. continue;
  4212. case EVENT_RING_OPCODE_STAT_QUERY:
  4213. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4214. "got statistics comp event %d\n",
  4215. bp->stats_comp++);
  4216. /* nothing to do with stats comp */
  4217. goto next_spqe;
  4218. case EVENT_RING_OPCODE_CFC_DEL:
  4219. /* handle according to cid range */
  4220. /*
  4221. * we may want to verify here that the bp state is
  4222. * HALTING
  4223. */
  4224. DP(BNX2X_MSG_SP,
  4225. "got delete ramrod for MULTI[%d]\n", cid);
  4226. if (CNIC_LOADED(bp) &&
  4227. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4228. goto next_spqe;
  4229. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4230. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4231. break;
  4232. goto next_spqe;
  4233. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4234. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4235. if (f_obj->complete_cmd(bp, f_obj,
  4236. BNX2X_F_CMD_TX_STOP))
  4237. break;
  4238. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4239. goto next_spqe;
  4240. case EVENT_RING_OPCODE_START_TRAFFIC:
  4241. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4242. if (f_obj->complete_cmd(bp, f_obj,
  4243. BNX2X_F_CMD_TX_START))
  4244. break;
  4245. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4246. goto next_spqe;
  4247. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4248. echo = elem->message.data.function_update_event.echo;
  4249. if (echo == SWITCH_UPDATE) {
  4250. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4251. "got FUNC_SWITCH_UPDATE ramrod\n");
  4252. if (f_obj->complete_cmd(
  4253. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4254. break;
  4255. } else {
  4256. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4257. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4258. f_obj->complete_cmd(bp, f_obj,
  4259. BNX2X_F_CMD_AFEX_UPDATE);
  4260. /* We will perform the Queues update from
  4261. * sp_rtnl task as all Queue SP operations
  4262. * should run under rtnl_lock.
  4263. */
  4264. smp_mb__before_clear_bit();
  4265. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4266. &bp->sp_rtnl_state);
  4267. smp_mb__after_clear_bit();
  4268. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4269. }
  4270. goto next_spqe;
  4271. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4272. f_obj->complete_cmd(bp, f_obj,
  4273. BNX2X_F_CMD_AFEX_VIFLISTS);
  4274. bnx2x_after_afex_vif_lists(bp, elem);
  4275. goto next_spqe;
  4276. case EVENT_RING_OPCODE_FUNCTION_START:
  4277. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4278. "got FUNC_START ramrod\n");
  4279. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4280. break;
  4281. goto next_spqe;
  4282. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4283. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4284. "got FUNC_STOP ramrod\n");
  4285. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4286. break;
  4287. goto next_spqe;
  4288. }
  4289. switch (opcode | bp->state) {
  4290. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4291. BNX2X_STATE_OPEN):
  4292. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4293. BNX2X_STATE_OPENING_WAIT4_PORT):
  4294. cid = elem->message.data.eth_event.echo &
  4295. BNX2X_SWCID_MASK;
  4296. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4297. cid);
  4298. rss_raw->clear_pending(rss_raw);
  4299. break;
  4300. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4301. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4302. case (EVENT_RING_OPCODE_SET_MAC |
  4303. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4304. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4305. BNX2X_STATE_OPEN):
  4306. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4307. BNX2X_STATE_DIAG):
  4308. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4309. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4310. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4311. bnx2x_handle_classification_eqe(bp, elem);
  4312. break;
  4313. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4314. BNX2X_STATE_OPEN):
  4315. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4316. BNX2X_STATE_DIAG):
  4317. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4318. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4319. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4320. bnx2x_handle_mcast_eqe(bp);
  4321. break;
  4322. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4323. BNX2X_STATE_OPEN):
  4324. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4325. BNX2X_STATE_DIAG):
  4326. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4327. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4328. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4329. bnx2x_handle_rx_mode_eqe(bp);
  4330. break;
  4331. default:
  4332. /* unknown event log error and continue */
  4333. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4334. elem->message.opcode, bp->state);
  4335. }
  4336. next_spqe:
  4337. spqe_cnt++;
  4338. } /* for */
  4339. smp_mb__before_atomic_inc();
  4340. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4341. bp->eq_cons = sw_cons;
  4342. bp->eq_prod = sw_prod;
  4343. /* Make sure that above mem writes were issued towards the memory */
  4344. smp_wmb();
  4345. /* update producer */
  4346. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4347. }
  4348. static void bnx2x_sp_task(struct work_struct *work)
  4349. {
  4350. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4351. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4352. /* make sure the atomic interupt_occurred has been written */
  4353. smp_rmb();
  4354. if (atomic_read(&bp->interrupt_occurred)) {
  4355. /* what work needs to be performed? */
  4356. u16 status = bnx2x_update_dsb_idx(bp);
  4357. DP(BNX2X_MSG_SP, "status %x\n", status);
  4358. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4359. atomic_set(&bp->interrupt_occurred, 0);
  4360. /* HW attentions */
  4361. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4362. bnx2x_attn_int(bp);
  4363. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4364. }
  4365. /* SP events: STAT_QUERY and others */
  4366. if (status & BNX2X_DEF_SB_IDX) {
  4367. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4368. if (FCOE_INIT(bp) &&
  4369. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4370. /* Prevent local bottom-halves from running as
  4371. * we are going to change the local NAPI list.
  4372. */
  4373. local_bh_disable();
  4374. napi_schedule(&bnx2x_fcoe(bp, napi));
  4375. local_bh_enable();
  4376. }
  4377. /* Handle EQ completions */
  4378. bnx2x_eq_int(bp);
  4379. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4380. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4381. status &= ~BNX2X_DEF_SB_IDX;
  4382. }
  4383. /* if status is non zero then perhaps something went wrong */
  4384. if (unlikely(status))
  4385. DP(BNX2X_MSG_SP,
  4386. "got an unknown interrupt! (status 0x%x)\n", status);
  4387. /* ack status block only if something was actually handled */
  4388. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4389. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4390. }
  4391. /* must be called after the EQ processing (since eq leads to sriov
  4392. * ramrod completion flows).
  4393. * This flow may have been scheduled by the arrival of a ramrod
  4394. * completion, or by the sriov code rescheduling itself.
  4395. */
  4396. bnx2x_iov_sp_task(bp);
  4397. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4398. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4399. &bp->sp_state)) {
  4400. bnx2x_link_report(bp);
  4401. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4402. }
  4403. }
  4404. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4405. {
  4406. struct net_device *dev = dev_instance;
  4407. struct bnx2x *bp = netdev_priv(dev);
  4408. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4409. IGU_INT_DISABLE, 0);
  4410. #ifdef BNX2X_STOP_ON_ERROR
  4411. if (unlikely(bp->panic))
  4412. return IRQ_HANDLED;
  4413. #endif
  4414. if (CNIC_LOADED(bp)) {
  4415. struct cnic_ops *c_ops;
  4416. rcu_read_lock();
  4417. c_ops = rcu_dereference(bp->cnic_ops);
  4418. if (c_ops)
  4419. c_ops->cnic_handler(bp->cnic_data, NULL);
  4420. rcu_read_unlock();
  4421. }
  4422. /* schedule sp task to perform default status block work, ack
  4423. * attentions and enable interrupts.
  4424. */
  4425. bnx2x_schedule_sp_task(bp);
  4426. return IRQ_HANDLED;
  4427. }
  4428. /* end of slow path */
  4429. void bnx2x_drv_pulse(struct bnx2x *bp)
  4430. {
  4431. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4432. bp->fw_drv_pulse_wr_seq);
  4433. }
  4434. static void bnx2x_timer(unsigned long data)
  4435. {
  4436. struct bnx2x *bp = (struct bnx2x *) data;
  4437. if (!netif_running(bp->dev))
  4438. return;
  4439. if (IS_PF(bp) &&
  4440. !BP_NOMCP(bp)) {
  4441. int mb_idx = BP_FW_MB_IDX(bp);
  4442. u32 drv_pulse;
  4443. u32 mcp_pulse;
  4444. ++bp->fw_drv_pulse_wr_seq;
  4445. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4446. /* TBD - add SYSTEM_TIME */
  4447. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4448. bnx2x_drv_pulse(bp);
  4449. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4450. MCP_PULSE_SEQ_MASK);
  4451. /* The delta between driver pulse and mcp response
  4452. * should be 1 (before mcp response) or 0 (after mcp response)
  4453. */
  4454. if ((drv_pulse != mcp_pulse) &&
  4455. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4456. /* someone lost a heartbeat... */
  4457. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4458. drv_pulse, mcp_pulse);
  4459. }
  4460. }
  4461. if (bp->state == BNX2X_STATE_OPEN)
  4462. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4463. /* sample pf vf bulletin board for new posts from pf */
  4464. if (IS_VF(bp))
  4465. bnx2x_sample_bulletin(bp);
  4466. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4467. }
  4468. /* end of Statistics */
  4469. /* nic init */
  4470. /*
  4471. * nic init service functions
  4472. */
  4473. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4474. {
  4475. u32 i;
  4476. if (!(len%4) && !(addr%4))
  4477. for (i = 0; i < len; i += 4)
  4478. REG_WR(bp, addr + i, fill);
  4479. else
  4480. for (i = 0; i < len; i++)
  4481. REG_WR8(bp, addr + i, fill);
  4482. }
  4483. /* helper: writes FP SP data to FW - data_size in dwords */
  4484. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4485. int fw_sb_id,
  4486. u32 *sb_data_p,
  4487. u32 data_size)
  4488. {
  4489. int index;
  4490. for (index = 0; index < data_size; index++)
  4491. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4492. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4493. sizeof(u32)*index,
  4494. *(sb_data_p + index));
  4495. }
  4496. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4497. {
  4498. u32 *sb_data_p;
  4499. u32 data_size = 0;
  4500. struct hc_status_block_data_e2 sb_data_e2;
  4501. struct hc_status_block_data_e1x sb_data_e1x;
  4502. /* disable the function first */
  4503. if (!CHIP_IS_E1x(bp)) {
  4504. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4505. sb_data_e2.common.state = SB_DISABLED;
  4506. sb_data_e2.common.p_func.vf_valid = false;
  4507. sb_data_p = (u32 *)&sb_data_e2;
  4508. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4509. } else {
  4510. memset(&sb_data_e1x, 0,
  4511. sizeof(struct hc_status_block_data_e1x));
  4512. sb_data_e1x.common.state = SB_DISABLED;
  4513. sb_data_e1x.common.p_func.vf_valid = false;
  4514. sb_data_p = (u32 *)&sb_data_e1x;
  4515. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4516. }
  4517. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4518. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4519. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4520. CSTORM_STATUS_BLOCK_SIZE);
  4521. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4522. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4523. CSTORM_SYNC_BLOCK_SIZE);
  4524. }
  4525. /* helper: writes SP SB data to FW */
  4526. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4527. struct hc_sp_status_block_data *sp_sb_data)
  4528. {
  4529. int func = BP_FUNC(bp);
  4530. int i;
  4531. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4532. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4533. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4534. i*sizeof(u32),
  4535. *((u32 *)sp_sb_data + i));
  4536. }
  4537. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4538. {
  4539. int func = BP_FUNC(bp);
  4540. struct hc_sp_status_block_data sp_sb_data;
  4541. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4542. sp_sb_data.state = SB_DISABLED;
  4543. sp_sb_data.p_func.vf_valid = false;
  4544. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4545. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4546. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4547. CSTORM_SP_STATUS_BLOCK_SIZE);
  4548. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4549. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4550. CSTORM_SP_SYNC_BLOCK_SIZE);
  4551. }
  4552. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4553. int igu_sb_id, int igu_seg_id)
  4554. {
  4555. hc_sm->igu_sb_id = igu_sb_id;
  4556. hc_sm->igu_seg_id = igu_seg_id;
  4557. hc_sm->timer_value = 0xFF;
  4558. hc_sm->time_to_expire = 0xFFFFFFFF;
  4559. }
  4560. /* allocates state machine ids. */
  4561. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4562. {
  4563. /* zero out state machine indices */
  4564. /* rx indices */
  4565. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4566. /* tx indices */
  4567. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4568. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4569. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4570. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4571. /* map indices */
  4572. /* rx indices */
  4573. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4574. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4575. /* tx indices */
  4576. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4577. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4578. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4579. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4580. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4581. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4582. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4583. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4584. }
  4585. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4586. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4587. {
  4588. int igu_seg_id;
  4589. struct hc_status_block_data_e2 sb_data_e2;
  4590. struct hc_status_block_data_e1x sb_data_e1x;
  4591. struct hc_status_block_sm *hc_sm_p;
  4592. int data_size;
  4593. u32 *sb_data_p;
  4594. if (CHIP_INT_MODE_IS_BC(bp))
  4595. igu_seg_id = HC_SEG_ACCESS_NORM;
  4596. else
  4597. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4598. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4599. if (!CHIP_IS_E1x(bp)) {
  4600. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4601. sb_data_e2.common.state = SB_ENABLED;
  4602. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4603. sb_data_e2.common.p_func.vf_id = vfid;
  4604. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4605. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4606. sb_data_e2.common.same_igu_sb_1b = true;
  4607. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4608. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4609. hc_sm_p = sb_data_e2.common.state_machine;
  4610. sb_data_p = (u32 *)&sb_data_e2;
  4611. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4612. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4613. } else {
  4614. memset(&sb_data_e1x, 0,
  4615. sizeof(struct hc_status_block_data_e1x));
  4616. sb_data_e1x.common.state = SB_ENABLED;
  4617. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4618. sb_data_e1x.common.p_func.vf_id = 0xff;
  4619. sb_data_e1x.common.p_func.vf_valid = false;
  4620. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4621. sb_data_e1x.common.same_igu_sb_1b = true;
  4622. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4623. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4624. hc_sm_p = sb_data_e1x.common.state_machine;
  4625. sb_data_p = (u32 *)&sb_data_e1x;
  4626. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4627. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4628. }
  4629. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4630. igu_sb_id, igu_seg_id);
  4631. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4632. igu_sb_id, igu_seg_id);
  4633. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4634. /* write indecies to HW */
  4635. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4636. }
  4637. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4638. u16 tx_usec, u16 rx_usec)
  4639. {
  4640. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4641. false, rx_usec);
  4642. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4643. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4644. tx_usec);
  4645. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4646. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4647. tx_usec);
  4648. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4649. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4650. tx_usec);
  4651. }
  4652. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4653. {
  4654. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4655. dma_addr_t mapping = bp->def_status_blk_mapping;
  4656. int igu_sp_sb_index;
  4657. int igu_seg_id;
  4658. int port = BP_PORT(bp);
  4659. int func = BP_FUNC(bp);
  4660. int reg_offset, reg_offset_en5;
  4661. u64 section;
  4662. int index;
  4663. struct hc_sp_status_block_data sp_sb_data;
  4664. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4665. if (CHIP_INT_MODE_IS_BC(bp)) {
  4666. igu_sp_sb_index = DEF_SB_IGU_ID;
  4667. igu_seg_id = HC_SEG_ACCESS_DEF;
  4668. } else {
  4669. igu_sp_sb_index = bp->igu_dsb_id;
  4670. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4671. }
  4672. /* ATTN */
  4673. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4674. atten_status_block);
  4675. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4676. bp->attn_state = 0;
  4677. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4678. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4679. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4680. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4681. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4682. int sindex;
  4683. /* take care of sig[0]..sig[4] */
  4684. for (sindex = 0; sindex < 4; sindex++)
  4685. bp->attn_group[index].sig[sindex] =
  4686. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4687. if (!CHIP_IS_E1x(bp))
  4688. /*
  4689. * enable5 is separate from the rest of the registers,
  4690. * and therefore the address skip is 4
  4691. * and not 16 between the different groups
  4692. */
  4693. bp->attn_group[index].sig[4] = REG_RD(bp,
  4694. reg_offset_en5 + 0x4*index);
  4695. else
  4696. bp->attn_group[index].sig[4] = 0;
  4697. }
  4698. if (bp->common.int_block == INT_BLOCK_HC) {
  4699. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4700. HC_REG_ATTN_MSG0_ADDR_L);
  4701. REG_WR(bp, reg_offset, U64_LO(section));
  4702. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4703. } else if (!CHIP_IS_E1x(bp)) {
  4704. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4705. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4706. }
  4707. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4708. sp_sb);
  4709. bnx2x_zero_sp_sb(bp);
  4710. sp_sb_data.state = SB_ENABLED;
  4711. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4712. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4713. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4714. sp_sb_data.igu_seg_id = igu_seg_id;
  4715. sp_sb_data.p_func.pf_id = func;
  4716. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4717. sp_sb_data.p_func.vf_id = 0xff;
  4718. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4719. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4720. }
  4721. void bnx2x_update_coalesce(struct bnx2x *bp)
  4722. {
  4723. int i;
  4724. for_each_eth_queue(bp, i)
  4725. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4726. bp->tx_ticks, bp->rx_ticks);
  4727. }
  4728. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4729. {
  4730. spin_lock_init(&bp->spq_lock);
  4731. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4732. bp->spq_prod_idx = 0;
  4733. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4734. bp->spq_prod_bd = bp->spq;
  4735. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4736. }
  4737. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4738. {
  4739. int i;
  4740. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4741. union event_ring_elem *elem =
  4742. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4743. elem->next_page.addr.hi =
  4744. cpu_to_le32(U64_HI(bp->eq_mapping +
  4745. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4746. elem->next_page.addr.lo =
  4747. cpu_to_le32(U64_LO(bp->eq_mapping +
  4748. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4749. }
  4750. bp->eq_cons = 0;
  4751. bp->eq_prod = NUM_EQ_DESC;
  4752. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4753. /* we want a warning message before it gets rought... */
  4754. atomic_set(&bp->eq_spq_left,
  4755. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4756. }
  4757. /* called with netif_addr_lock_bh() */
  4758. void bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4759. unsigned long rx_mode_flags,
  4760. unsigned long rx_accept_flags,
  4761. unsigned long tx_accept_flags,
  4762. unsigned long ramrod_flags)
  4763. {
  4764. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4765. int rc;
  4766. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4767. /* Prepare ramrod parameters */
  4768. ramrod_param.cid = 0;
  4769. ramrod_param.cl_id = cl_id;
  4770. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4771. ramrod_param.func_id = BP_FUNC(bp);
  4772. ramrod_param.pstate = &bp->sp_state;
  4773. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4774. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4775. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4776. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4777. ramrod_param.ramrod_flags = ramrod_flags;
  4778. ramrod_param.rx_mode_flags = rx_mode_flags;
  4779. ramrod_param.rx_accept_flags = rx_accept_flags;
  4780. ramrod_param.tx_accept_flags = tx_accept_flags;
  4781. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4782. if (rc < 0) {
  4783. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4784. return;
  4785. }
  4786. }
  4787. /* called with netif_addr_lock_bh() */
  4788. void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  4789. {
  4790. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  4791. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  4792. if (!NO_FCOE(bp))
  4793. /* Configure rx_mode of FCoE Queue */
  4794. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  4795. switch (bp->rx_mode) {
  4796. case BNX2X_RX_MODE_NONE:
  4797. /*
  4798. * 'drop all' supersedes any accept flags that may have been
  4799. * passed to the function.
  4800. */
  4801. break;
  4802. case BNX2X_RX_MODE_NORMAL:
  4803. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4804. __set_bit(BNX2X_ACCEPT_MULTICAST, &rx_accept_flags);
  4805. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4806. /* internal switching mode */
  4807. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4808. __set_bit(BNX2X_ACCEPT_MULTICAST, &tx_accept_flags);
  4809. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4810. break;
  4811. case BNX2X_RX_MODE_ALLMULTI:
  4812. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4813. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4814. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4815. /* internal switching mode */
  4816. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4817. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4818. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4819. break;
  4820. case BNX2X_RX_MODE_PROMISC:
  4821. /* According to deffinition of SI mode, iface in promisc mode
  4822. * should receive matched and unmatched (in resolution of port)
  4823. * unicast packets.
  4824. */
  4825. __set_bit(BNX2X_ACCEPT_UNMATCHED, &rx_accept_flags);
  4826. __set_bit(BNX2X_ACCEPT_UNICAST, &rx_accept_flags);
  4827. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &rx_accept_flags);
  4828. __set_bit(BNX2X_ACCEPT_BROADCAST, &rx_accept_flags);
  4829. /* internal switching mode */
  4830. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &tx_accept_flags);
  4831. __set_bit(BNX2X_ACCEPT_BROADCAST, &tx_accept_flags);
  4832. if (IS_MF_SI(bp))
  4833. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, &tx_accept_flags);
  4834. else
  4835. __set_bit(BNX2X_ACCEPT_UNICAST, &tx_accept_flags);
  4836. break;
  4837. default:
  4838. BNX2X_ERR("Unknown rx_mode: %d\n", bp->rx_mode);
  4839. return;
  4840. }
  4841. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  4842. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &rx_accept_flags);
  4843. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &tx_accept_flags);
  4844. }
  4845. __set_bit(RAMROD_RX, &ramrod_flags);
  4846. __set_bit(RAMROD_TX, &ramrod_flags);
  4847. bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags, rx_accept_flags,
  4848. tx_accept_flags, ramrod_flags);
  4849. }
  4850. static void bnx2x_init_internal_common(struct bnx2x *bp)
  4851. {
  4852. int i;
  4853. if (IS_MF_SI(bp))
  4854. /*
  4855. * In switch independent mode, the TSTORM needs to accept
  4856. * packets that failed classification, since approximate match
  4857. * mac addresses aren't written to NIG LLH
  4858. */
  4859. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4860. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  4861. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  4862. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  4863. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  4864. /* Zero this manually as its initialization is
  4865. currently missing in the initTool */
  4866. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  4867. REG_WR(bp, BAR_USTRORM_INTMEM +
  4868. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  4869. if (!CHIP_IS_E1x(bp)) {
  4870. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  4871. CHIP_INT_MODE_IS_BC(bp) ?
  4872. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  4873. }
  4874. }
  4875. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  4876. {
  4877. switch (load_code) {
  4878. case FW_MSG_CODE_DRV_LOAD_COMMON:
  4879. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  4880. bnx2x_init_internal_common(bp);
  4881. /* no break */
  4882. case FW_MSG_CODE_DRV_LOAD_PORT:
  4883. /* nothing to do */
  4884. /* no break */
  4885. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  4886. /* internal memory per function is
  4887. initialized inside bnx2x_pf_init */
  4888. break;
  4889. default:
  4890. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  4891. break;
  4892. }
  4893. }
  4894. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  4895. {
  4896. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  4897. }
  4898. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  4899. {
  4900. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  4901. }
  4902. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  4903. {
  4904. if (CHIP_IS_E1x(fp->bp))
  4905. return BP_L_ID(fp->bp) + fp->index;
  4906. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  4907. return bnx2x_fp_igu_sb_id(fp);
  4908. }
  4909. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  4910. {
  4911. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  4912. u8 cos;
  4913. unsigned long q_type = 0;
  4914. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  4915. fp->rx_queue = fp_idx;
  4916. fp->cid = fp_idx;
  4917. fp->cl_id = bnx2x_fp_cl_id(fp);
  4918. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  4919. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  4920. /* qZone id equals to FW (per path) client id */
  4921. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  4922. /* init shortcut */
  4923. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  4924. /* Setup SB indicies */
  4925. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  4926. /* Configure Queue State object */
  4927. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  4928. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  4929. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  4930. /* init tx data */
  4931. for_each_cos_in_tx_queue(fp, cos) {
  4932. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  4933. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  4934. FP_COS_TO_TXQ(fp, cos, bp),
  4935. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  4936. cids[cos] = fp->txdata_ptr[cos]->cid;
  4937. }
  4938. /* nothing more for vf to do here */
  4939. if (IS_VF(bp))
  4940. return;
  4941. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  4942. fp->fw_sb_id, fp->igu_sb_id);
  4943. bnx2x_update_fpsb_idx(fp);
  4944. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  4945. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  4946. bnx2x_sp_mapping(bp, q_rdata), q_type);
  4947. /**
  4948. * Configure classification DBs: Always enable Tx switching
  4949. */
  4950. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  4951. DP(NETIF_MSG_IFUP,
  4952. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  4953. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  4954. fp->igu_sb_id);
  4955. }
  4956. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  4957. {
  4958. int i;
  4959. for (i = 1; i <= NUM_TX_RINGS; i++) {
  4960. struct eth_tx_next_bd *tx_next_bd =
  4961. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  4962. tx_next_bd->addr_hi =
  4963. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  4964. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4965. tx_next_bd->addr_lo =
  4966. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  4967. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  4968. }
  4969. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  4970. txdata->tx_db.data.zero_fill1 = 0;
  4971. txdata->tx_db.data.prod = 0;
  4972. txdata->tx_pkt_prod = 0;
  4973. txdata->tx_pkt_cons = 0;
  4974. txdata->tx_bd_prod = 0;
  4975. txdata->tx_bd_cons = 0;
  4976. txdata->tx_pkt = 0;
  4977. }
  4978. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  4979. {
  4980. int i;
  4981. for_each_tx_queue_cnic(bp, i)
  4982. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  4983. }
  4984. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  4985. {
  4986. int i;
  4987. u8 cos;
  4988. for_each_eth_queue(bp, i)
  4989. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  4990. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  4991. }
  4992. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  4993. {
  4994. if (!NO_FCOE(bp))
  4995. bnx2x_init_fcoe_fp(bp);
  4996. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  4997. BNX2X_VF_ID_INVALID, false,
  4998. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  4999. /* ensure status block indices were read */
  5000. rmb();
  5001. bnx2x_init_rx_rings_cnic(bp);
  5002. bnx2x_init_tx_rings_cnic(bp);
  5003. /* flush all */
  5004. mb();
  5005. mmiowb();
  5006. }
  5007. void bnx2x_nic_init(struct bnx2x *bp, u32 load_code)
  5008. {
  5009. int i;
  5010. for_each_eth_queue(bp, i)
  5011. bnx2x_init_eth_fp(bp, i);
  5012. /* ensure status block indices were read */
  5013. rmb();
  5014. bnx2x_init_rx_rings(bp);
  5015. bnx2x_init_tx_rings(bp);
  5016. if (IS_VF(bp))
  5017. return;
  5018. /* Initialize MOD_ABS interrupts */
  5019. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5020. bp->common.shmem_base, bp->common.shmem2_base,
  5021. BP_PORT(bp));
  5022. bnx2x_init_def_sb(bp);
  5023. bnx2x_update_dsb_idx(bp);
  5024. bnx2x_init_sp_ring(bp);
  5025. bnx2x_init_eq_ring(bp);
  5026. bnx2x_init_internal(bp, load_code);
  5027. bnx2x_pf_init(bp);
  5028. bnx2x_stats_init(bp);
  5029. /* flush all before enabling interrupts */
  5030. mb();
  5031. mmiowb();
  5032. bnx2x_int_enable(bp);
  5033. /* Check for SPIO5 */
  5034. bnx2x_attn_int_deasserted0(bp,
  5035. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5036. AEU_INPUTS_ATTN_BITS_SPIO5);
  5037. }
  5038. /* end of nic init */
  5039. /*
  5040. * gzip service functions
  5041. */
  5042. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5043. {
  5044. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5045. &bp->gunzip_mapping, GFP_KERNEL);
  5046. if (bp->gunzip_buf == NULL)
  5047. goto gunzip_nomem1;
  5048. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5049. if (bp->strm == NULL)
  5050. goto gunzip_nomem2;
  5051. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5052. if (bp->strm->workspace == NULL)
  5053. goto gunzip_nomem3;
  5054. return 0;
  5055. gunzip_nomem3:
  5056. kfree(bp->strm);
  5057. bp->strm = NULL;
  5058. gunzip_nomem2:
  5059. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5060. bp->gunzip_mapping);
  5061. bp->gunzip_buf = NULL;
  5062. gunzip_nomem1:
  5063. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5064. return -ENOMEM;
  5065. }
  5066. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5067. {
  5068. if (bp->strm) {
  5069. vfree(bp->strm->workspace);
  5070. kfree(bp->strm);
  5071. bp->strm = NULL;
  5072. }
  5073. if (bp->gunzip_buf) {
  5074. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5075. bp->gunzip_mapping);
  5076. bp->gunzip_buf = NULL;
  5077. }
  5078. }
  5079. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5080. {
  5081. int n, rc;
  5082. /* check gzip header */
  5083. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5084. BNX2X_ERR("Bad gzip header\n");
  5085. return -EINVAL;
  5086. }
  5087. n = 10;
  5088. #define FNAME 0x8
  5089. if (zbuf[3] & FNAME)
  5090. while ((zbuf[n++] != 0) && (n < len));
  5091. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5092. bp->strm->avail_in = len - n;
  5093. bp->strm->next_out = bp->gunzip_buf;
  5094. bp->strm->avail_out = FW_BUF_SIZE;
  5095. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5096. if (rc != Z_OK)
  5097. return rc;
  5098. rc = zlib_inflate(bp->strm, Z_FINISH);
  5099. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5100. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5101. bp->strm->msg);
  5102. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5103. if (bp->gunzip_outlen & 0x3)
  5104. netdev_err(bp->dev,
  5105. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5106. bp->gunzip_outlen);
  5107. bp->gunzip_outlen >>= 2;
  5108. zlib_inflateEnd(bp->strm);
  5109. if (rc == Z_STREAM_END)
  5110. return 0;
  5111. return rc;
  5112. }
  5113. /* nic load/unload */
  5114. /*
  5115. * General service functions
  5116. */
  5117. /* send a NIG loopback debug packet */
  5118. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5119. {
  5120. u32 wb_write[3];
  5121. /* Ethernet source and destination addresses */
  5122. wb_write[0] = 0x55555555;
  5123. wb_write[1] = 0x55555555;
  5124. wb_write[2] = 0x20; /* SOP */
  5125. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5126. /* NON-IP protocol */
  5127. wb_write[0] = 0x09000000;
  5128. wb_write[1] = 0x55555555;
  5129. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5130. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5131. }
  5132. /* some of the internal memories
  5133. * are not directly readable from the driver
  5134. * to test them we send debug packets
  5135. */
  5136. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5137. {
  5138. int factor;
  5139. int count, i;
  5140. u32 val = 0;
  5141. if (CHIP_REV_IS_FPGA(bp))
  5142. factor = 120;
  5143. else if (CHIP_REV_IS_EMUL(bp))
  5144. factor = 200;
  5145. else
  5146. factor = 1;
  5147. /* Disable inputs of parser neighbor blocks */
  5148. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5149. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5150. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5151. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5152. /* Write 0 to parser credits for CFC search request */
  5153. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5154. /* send Ethernet packet */
  5155. bnx2x_lb_pckt(bp);
  5156. /* TODO do i reset NIG statistic? */
  5157. /* Wait until NIG register shows 1 packet of size 0x10 */
  5158. count = 1000 * factor;
  5159. while (count) {
  5160. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5161. val = *bnx2x_sp(bp, wb_data[0]);
  5162. if (val == 0x10)
  5163. break;
  5164. msleep(10);
  5165. count--;
  5166. }
  5167. if (val != 0x10) {
  5168. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5169. return -1;
  5170. }
  5171. /* Wait until PRS register shows 1 packet */
  5172. count = 1000 * factor;
  5173. while (count) {
  5174. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5175. if (val == 1)
  5176. break;
  5177. msleep(10);
  5178. count--;
  5179. }
  5180. if (val != 0x1) {
  5181. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5182. return -2;
  5183. }
  5184. /* Reset and init BRB, PRS */
  5185. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5186. msleep(50);
  5187. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5188. msleep(50);
  5189. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5190. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5191. DP(NETIF_MSG_HW, "part2\n");
  5192. /* Disable inputs of parser neighbor blocks */
  5193. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5194. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5195. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5196. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5197. /* Write 0 to parser credits for CFC search request */
  5198. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5199. /* send 10 Ethernet packets */
  5200. for (i = 0; i < 10; i++)
  5201. bnx2x_lb_pckt(bp);
  5202. /* Wait until NIG register shows 10 + 1
  5203. packets of size 11*0x10 = 0xb0 */
  5204. count = 1000 * factor;
  5205. while (count) {
  5206. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5207. val = *bnx2x_sp(bp, wb_data[0]);
  5208. if (val == 0xb0)
  5209. break;
  5210. msleep(10);
  5211. count--;
  5212. }
  5213. if (val != 0xb0) {
  5214. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5215. return -3;
  5216. }
  5217. /* Wait until PRS register shows 2 packets */
  5218. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5219. if (val != 2)
  5220. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5221. /* Write 1 to parser credits for CFC search request */
  5222. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5223. /* Wait until PRS register shows 3 packets */
  5224. msleep(10 * factor);
  5225. /* Wait until NIG register shows 1 packet of size 0x10 */
  5226. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5227. if (val != 3)
  5228. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5229. /* clear NIG EOP FIFO */
  5230. for (i = 0; i < 11; i++)
  5231. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5232. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5233. if (val != 1) {
  5234. BNX2X_ERR("clear of NIG failed\n");
  5235. return -4;
  5236. }
  5237. /* Reset and init BRB, PRS, NIG */
  5238. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5239. msleep(50);
  5240. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5241. msleep(50);
  5242. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5243. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5244. if (!CNIC_SUPPORT(bp))
  5245. /* set NIC mode */
  5246. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5247. /* Enable inputs of parser neighbor blocks */
  5248. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5249. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5250. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5251. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5252. DP(NETIF_MSG_HW, "done\n");
  5253. return 0; /* OK */
  5254. }
  5255. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5256. {
  5257. u32 val;
  5258. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5259. if (!CHIP_IS_E1x(bp))
  5260. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5261. else
  5262. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5263. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5264. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5265. /*
  5266. * mask read length error interrupts in brb for parser
  5267. * (parsing unit and 'checksum and crc' unit)
  5268. * these errors are legal (PU reads fixed length and CAC can cause
  5269. * read length error on truncated packets)
  5270. */
  5271. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5272. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5273. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5274. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5275. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5276. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5277. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5278. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5279. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5280. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5281. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5282. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5283. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5284. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5285. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5286. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5287. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5288. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5289. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5290. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5291. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5292. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5293. if (!CHIP_IS_E1x(bp))
  5294. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5295. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5296. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5297. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5298. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5299. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5300. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5301. if (!CHIP_IS_E1x(bp))
  5302. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5303. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5304. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5305. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5306. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5307. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5308. }
  5309. static void bnx2x_reset_common(struct bnx2x *bp)
  5310. {
  5311. u32 val = 0x1400;
  5312. /* reset_common */
  5313. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5314. 0xd3ffff7f);
  5315. if (CHIP_IS_E3(bp)) {
  5316. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5317. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5318. }
  5319. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5320. }
  5321. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5322. {
  5323. bp->dmae_ready = 0;
  5324. spin_lock_init(&bp->dmae_lock);
  5325. }
  5326. static void bnx2x_init_pxp(struct bnx2x *bp)
  5327. {
  5328. u16 devctl;
  5329. int r_order, w_order;
  5330. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5331. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5332. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5333. if (bp->mrrs == -1)
  5334. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5335. else {
  5336. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5337. r_order = bp->mrrs;
  5338. }
  5339. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5340. }
  5341. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5342. {
  5343. int is_required;
  5344. u32 val;
  5345. int port;
  5346. if (BP_NOMCP(bp))
  5347. return;
  5348. is_required = 0;
  5349. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5350. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5351. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5352. is_required = 1;
  5353. /*
  5354. * The fan failure mechanism is usually related to the PHY type since
  5355. * the power consumption of the board is affected by the PHY. Currently,
  5356. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5357. */
  5358. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5359. for (port = PORT_0; port < PORT_MAX; port++) {
  5360. is_required |=
  5361. bnx2x_fan_failure_det_req(
  5362. bp,
  5363. bp->common.shmem_base,
  5364. bp->common.shmem2_base,
  5365. port);
  5366. }
  5367. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5368. if (is_required == 0)
  5369. return;
  5370. /* Fan failure is indicated by SPIO 5 */
  5371. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5372. /* set to active low mode */
  5373. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5374. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5375. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5376. /* enable interrupt to signal the IGU */
  5377. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5378. val |= MISC_SPIO_SPIO5;
  5379. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5380. }
  5381. void bnx2x_pf_disable(struct bnx2x *bp)
  5382. {
  5383. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5384. val &= ~IGU_PF_CONF_FUNC_EN;
  5385. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5386. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5387. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5388. }
  5389. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5390. {
  5391. u32 shmem_base[2], shmem2_base[2];
  5392. /* Avoid common init in case MFW supports LFA */
  5393. if (SHMEM2_RD(bp, size) >
  5394. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5395. return;
  5396. shmem_base[0] = bp->common.shmem_base;
  5397. shmem2_base[0] = bp->common.shmem2_base;
  5398. if (!CHIP_IS_E1x(bp)) {
  5399. shmem_base[1] =
  5400. SHMEM2_RD(bp, other_shmem_base_addr);
  5401. shmem2_base[1] =
  5402. SHMEM2_RD(bp, other_shmem2_base_addr);
  5403. }
  5404. bnx2x_acquire_phy_lock(bp);
  5405. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5406. bp->common.chip_id);
  5407. bnx2x_release_phy_lock(bp);
  5408. }
  5409. /**
  5410. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5411. *
  5412. * @bp: driver handle
  5413. */
  5414. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5415. {
  5416. u32 val;
  5417. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5418. /*
  5419. * take the UNDI lock to protect undi_unload flow from accessing
  5420. * registers while we're resetting the chip
  5421. */
  5422. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5423. bnx2x_reset_common(bp);
  5424. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5425. val = 0xfffc;
  5426. if (CHIP_IS_E3(bp)) {
  5427. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5428. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5429. }
  5430. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5431. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5432. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5433. if (!CHIP_IS_E1x(bp)) {
  5434. u8 abs_func_id;
  5435. /**
  5436. * 4-port mode or 2-port mode we need to turn of master-enable
  5437. * for everyone, after that, turn it back on for self.
  5438. * so, we disregard multi-function or not, and always disable
  5439. * for all functions on the given path, this means 0,2,4,6 for
  5440. * path 0 and 1,3,5,7 for path 1
  5441. */
  5442. for (abs_func_id = BP_PATH(bp);
  5443. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5444. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5445. REG_WR(bp,
  5446. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5447. 1);
  5448. continue;
  5449. }
  5450. bnx2x_pretend_func(bp, abs_func_id);
  5451. /* clear pf enable */
  5452. bnx2x_pf_disable(bp);
  5453. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5454. }
  5455. }
  5456. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5457. if (CHIP_IS_E1(bp)) {
  5458. /* enable HW interrupt from PXP on USDM overflow
  5459. bit 16 on INT_MASK_0 */
  5460. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5461. }
  5462. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5463. bnx2x_init_pxp(bp);
  5464. #ifdef __BIG_ENDIAN
  5465. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5466. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5467. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5468. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5469. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5470. /* make sure this value is 0 */
  5471. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5472. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5473. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5474. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5475. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5476. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5477. #endif
  5478. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5479. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5480. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5481. /* let the HW do it's magic ... */
  5482. msleep(100);
  5483. /* finish PXP init */
  5484. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5485. if (val != 1) {
  5486. BNX2X_ERR("PXP2 CFG failed\n");
  5487. return -EBUSY;
  5488. }
  5489. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5490. if (val != 1) {
  5491. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5492. return -EBUSY;
  5493. }
  5494. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5495. * have entries with value "0" and valid bit on.
  5496. * This needs to be done by the first PF that is loaded in a path
  5497. * (i.e. common phase)
  5498. */
  5499. if (!CHIP_IS_E1x(bp)) {
  5500. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5501. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5502. * This occurs when a different function (func2,3) is being marked
  5503. * as "scan-off". Real-life scenario for example: if a driver is being
  5504. * load-unloaded while func6,7 are down. This will cause the timer to access
  5505. * the ilt, translate to a logical address and send a request to read/write.
  5506. * Since the ilt for the function that is down is not valid, this will cause
  5507. * a translation error which is unrecoverable.
  5508. * The Workaround is intended to make sure that when this happens nothing fatal
  5509. * will occur. The workaround:
  5510. * 1. First PF driver which loads on a path will:
  5511. * a. After taking the chip out of reset, by using pretend,
  5512. * it will write "0" to the following registers of
  5513. * the other vnics.
  5514. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5515. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5516. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5517. * And for itself it will write '1' to
  5518. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5519. * dmae-operations (writing to pram for example.)
  5520. * note: can be done for only function 6,7 but cleaner this
  5521. * way.
  5522. * b. Write zero+valid to the entire ILT.
  5523. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5524. * VNIC3 (of that port). The range allocated will be the
  5525. * entire ILT. This is needed to prevent ILT range error.
  5526. * 2. Any PF driver load flow:
  5527. * a. ILT update with the physical addresses of the allocated
  5528. * logical pages.
  5529. * b. Wait 20msec. - note that this timeout is needed to make
  5530. * sure there are no requests in one of the PXP internal
  5531. * queues with "old" ILT addresses.
  5532. * c. PF enable in the PGLC.
  5533. * d. Clear the was_error of the PF in the PGLC. (could have
  5534. * occured while driver was down)
  5535. * e. PF enable in the CFC (WEAK + STRONG)
  5536. * f. Timers scan enable
  5537. * 3. PF driver unload flow:
  5538. * a. Clear the Timers scan_en.
  5539. * b. Polling for scan_on=0 for that PF.
  5540. * c. Clear the PF enable bit in the PXP.
  5541. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5542. * e. Write zero+valid to all ILT entries (The valid bit must
  5543. * stay set)
  5544. * f. If this is VNIC 3 of a port then also init
  5545. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5546. * to the last enrty in the ILT.
  5547. *
  5548. * Notes:
  5549. * Currently the PF error in the PGLC is non recoverable.
  5550. * In the future the there will be a recovery routine for this error.
  5551. * Currently attention is masked.
  5552. * Having an MCP lock on the load/unload process does not guarantee that
  5553. * there is no Timer disable during Func6/7 enable. This is because the
  5554. * Timers scan is currently being cleared by the MCP on FLR.
  5555. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5556. * there is error before clearing it. But the flow above is simpler and
  5557. * more general.
  5558. * All ILT entries are written by zero+valid and not just PF6/7
  5559. * ILT entries since in the future the ILT entries allocation for
  5560. * PF-s might be dynamic.
  5561. */
  5562. struct ilt_client_info ilt_cli;
  5563. struct bnx2x_ilt ilt;
  5564. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5565. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5566. /* initialize dummy TM client */
  5567. ilt_cli.start = 0;
  5568. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5569. ilt_cli.client_num = ILT_CLIENT_TM;
  5570. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5571. * Step 2: set the timers first/last ilt entry to point
  5572. * to the entire range to prevent ILT range error for 3rd/4th
  5573. * vnic (this code assumes existance of the vnic)
  5574. *
  5575. * both steps performed by call to bnx2x_ilt_client_init_op()
  5576. * with dummy TM client
  5577. *
  5578. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5579. * and his brother are split registers
  5580. */
  5581. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5582. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5583. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5584. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5585. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5586. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5587. }
  5588. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5589. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5590. if (!CHIP_IS_E1x(bp)) {
  5591. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5592. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5593. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5594. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5595. /* let the HW do it's magic ... */
  5596. do {
  5597. msleep(200);
  5598. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5599. } while (factor-- && (val != 1));
  5600. if (val != 1) {
  5601. BNX2X_ERR("ATC_INIT failed\n");
  5602. return -EBUSY;
  5603. }
  5604. }
  5605. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5606. bnx2x_iov_init_dmae(bp);
  5607. /* clean the DMAE memory */
  5608. bp->dmae_ready = 1;
  5609. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5610. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5611. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5612. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5613. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5614. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5615. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5616. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5617. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5618. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5619. /* QM queues pointers table */
  5620. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5621. /* soft reset pulse */
  5622. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5623. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5624. if (CNIC_SUPPORT(bp))
  5625. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5626. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5627. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5628. if (!CHIP_REV_IS_SLOW(bp))
  5629. /* enable hw interrupt from doorbell Q */
  5630. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5631. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5632. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5633. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5634. if (!CHIP_IS_E1(bp))
  5635. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5636. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5637. if (IS_MF_AFEX(bp)) {
  5638. /* configure that VNTag and VLAN headers must be
  5639. * received in afex mode
  5640. */
  5641. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5642. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5643. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5644. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5645. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5646. } else {
  5647. /* Bit-map indicating which L2 hdrs may appear
  5648. * after the basic Ethernet header
  5649. */
  5650. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5651. bp->path_has_ovlan ? 7 : 6);
  5652. }
  5653. }
  5654. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5655. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5656. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5657. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5658. if (!CHIP_IS_E1x(bp)) {
  5659. /* reset VFC memories */
  5660. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5661. VFC_MEMORIES_RST_REG_CAM_RST |
  5662. VFC_MEMORIES_RST_REG_RAM_RST);
  5663. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5664. VFC_MEMORIES_RST_REG_CAM_RST |
  5665. VFC_MEMORIES_RST_REG_RAM_RST);
  5666. msleep(20);
  5667. }
  5668. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5669. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5670. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5671. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5672. /* sync semi rtc */
  5673. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5674. 0x80000000);
  5675. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5676. 0x80000000);
  5677. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5678. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5679. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5680. if (!CHIP_IS_E1x(bp)) {
  5681. if (IS_MF_AFEX(bp)) {
  5682. /* configure that VNTag and VLAN headers must be
  5683. * sent in afex mode
  5684. */
  5685. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5686. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5687. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5688. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5689. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5690. } else {
  5691. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5692. bp->path_has_ovlan ? 7 : 6);
  5693. }
  5694. }
  5695. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5696. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5697. if (CNIC_SUPPORT(bp)) {
  5698. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5699. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5700. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5701. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5702. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5703. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5704. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5705. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5706. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5707. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5708. }
  5709. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5710. if (sizeof(union cdu_context) != 1024)
  5711. /* we currently assume that a context is 1024 bytes */
  5712. dev_alert(&bp->pdev->dev,
  5713. "please adjust the size of cdu_context(%ld)\n",
  5714. (long)sizeof(union cdu_context));
  5715. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5716. val = (4 << 24) + (0 << 12) + 1024;
  5717. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5718. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5719. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5720. /* enable context validation interrupt from CFC */
  5721. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5722. /* set the thresholds to prevent CFC/CDU race */
  5723. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5724. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5725. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5726. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5727. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5728. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5729. /* Reset PCIE errors for debug */
  5730. REG_WR(bp, 0x2814, 0xffffffff);
  5731. REG_WR(bp, 0x3820, 0xffffffff);
  5732. if (!CHIP_IS_E1x(bp)) {
  5733. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5734. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5735. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5736. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5737. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5738. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5739. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5740. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5741. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5742. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5743. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5744. }
  5745. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5746. if (!CHIP_IS_E1(bp)) {
  5747. /* in E3 this done in per-port section */
  5748. if (!CHIP_IS_E3(bp))
  5749. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5750. }
  5751. if (CHIP_IS_E1H(bp))
  5752. /* not applicable for E2 (and above ...) */
  5753. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5754. if (CHIP_REV_IS_SLOW(bp))
  5755. msleep(200);
  5756. /* finish CFC init */
  5757. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5758. if (val != 1) {
  5759. BNX2X_ERR("CFC LL_INIT failed\n");
  5760. return -EBUSY;
  5761. }
  5762. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5763. if (val != 1) {
  5764. BNX2X_ERR("CFC AC_INIT failed\n");
  5765. return -EBUSY;
  5766. }
  5767. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5768. if (val != 1) {
  5769. BNX2X_ERR("CFC CAM_INIT failed\n");
  5770. return -EBUSY;
  5771. }
  5772. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5773. if (CHIP_IS_E1(bp)) {
  5774. /* read NIG statistic
  5775. to see if this is our first up since powerup */
  5776. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5777. val = *bnx2x_sp(bp, wb_data[0]);
  5778. /* do internal memory self test */
  5779. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5780. BNX2X_ERR("internal mem self test failed\n");
  5781. return -EBUSY;
  5782. }
  5783. }
  5784. bnx2x_setup_fan_failure_detection(bp);
  5785. /* clear PXP2 attentions */
  5786. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5787. bnx2x_enable_blocks_attention(bp);
  5788. bnx2x_enable_blocks_parity(bp);
  5789. if (!BP_NOMCP(bp)) {
  5790. if (CHIP_IS_E1x(bp))
  5791. bnx2x__common_init_phy(bp);
  5792. } else
  5793. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5794. return 0;
  5795. }
  5796. /**
  5797. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5798. *
  5799. * @bp: driver handle
  5800. */
  5801. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5802. {
  5803. int rc = bnx2x_init_hw_common(bp);
  5804. if (rc)
  5805. return rc;
  5806. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5807. if (!BP_NOMCP(bp))
  5808. bnx2x__common_init_phy(bp);
  5809. return 0;
  5810. }
  5811. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5812. {
  5813. int port = BP_PORT(bp);
  5814. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  5815. u32 low, high;
  5816. u32 val;
  5817. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  5818. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  5819. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  5820. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  5821. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  5822. /* Timers bug workaround: disables the pf_master bit in pglue at
  5823. * common phase, we need to enable it here before any dmae access are
  5824. * attempted. Therefore we manually added the enable-master to the
  5825. * port phase (it also happens in the function phase)
  5826. */
  5827. if (!CHIP_IS_E1x(bp))
  5828. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  5829. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  5830. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  5831. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  5832. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  5833. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  5834. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  5835. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  5836. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  5837. /* QM cid (connection) count */
  5838. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  5839. if (CNIC_SUPPORT(bp)) {
  5840. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  5841. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  5842. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  5843. }
  5844. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  5845. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  5846. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  5847. if (IS_MF(bp))
  5848. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  5849. else if (bp->dev->mtu > 4096) {
  5850. if (bp->flags & ONE_PORT_FLAG)
  5851. low = 160;
  5852. else {
  5853. val = bp->dev->mtu;
  5854. /* (24*1024 + val*4)/256 */
  5855. low = 96 + (val/64) +
  5856. ((val % 64) ? 1 : 0);
  5857. }
  5858. } else
  5859. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  5860. high = low + 56; /* 14*1024/256 */
  5861. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  5862. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  5863. }
  5864. if (CHIP_MODE_IS_4_PORT(bp))
  5865. REG_WR(bp, (BP_PORT(bp) ?
  5866. BRB1_REG_MAC_GUARANTIED_1 :
  5867. BRB1_REG_MAC_GUARANTIED_0), 40);
  5868. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  5869. if (CHIP_IS_E3B0(bp)) {
  5870. if (IS_MF_AFEX(bp)) {
  5871. /* configure headers for AFEX mode */
  5872. REG_WR(bp, BP_PORT(bp) ?
  5873. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5874. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  5875. REG_WR(bp, BP_PORT(bp) ?
  5876. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  5877. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  5878. REG_WR(bp, BP_PORT(bp) ?
  5879. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  5880. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  5881. } else {
  5882. /* Ovlan exists only if we are in multi-function +
  5883. * switch-dependent mode, in switch-independent there
  5884. * is no ovlan headers
  5885. */
  5886. REG_WR(bp, BP_PORT(bp) ?
  5887. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  5888. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  5889. (bp->path_has_ovlan ? 7 : 6));
  5890. }
  5891. }
  5892. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  5893. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  5894. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  5895. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  5896. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  5897. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  5898. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  5899. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  5900. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  5901. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  5902. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  5903. if (CHIP_IS_E1x(bp)) {
  5904. /* configure PBF to work without PAUSE mtu 9000 */
  5905. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  5906. /* update threshold */
  5907. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  5908. /* update init credit */
  5909. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  5910. /* probe changes */
  5911. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  5912. udelay(50);
  5913. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  5914. }
  5915. if (CNIC_SUPPORT(bp))
  5916. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  5917. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  5918. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  5919. if (CHIP_IS_E1(bp)) {
  5920. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  5921. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  5922. }
  5923. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  5924. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  5925. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  5926. /* init aeu_mask_attn_func_0/1:
  5927. * - SF mode: bits 3-7 are masked. only bits 0-2 are in use
  5928. * - MF mode: bit 3 is masked. bits 0-2 are in use as in SF
  5929. * bits 4-7 are used for "per vn group attention" */
  5930. val = IS_MF(bp) ? 0xF7 : 0x7;
  5931. /* Enable DCBX attention for all but E1 */
  5932. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  5933. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  5934. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  5935. if (!CHIP_IS_E1x(bp)) {
  5936. /* Bit-map indicating which L2 hdrs may appear after the
  5937. * basic Ethernet header
  5938. */
  5939. if (IS_MF_AFEX(bp))
  5940. REG_WR(bp, BP_PORT(bp) ?
  5941. NIG_REG_P1_HDRS_AFTER_BASIC :
  5942. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  5943. else
  5944. REG_WR(bp, BP_PORT(bp) ?
  5945. NIG_REG_P1_HDRS_AFTER_BASIC :
  5946. NIG_REG_P0_HDRS_AFTER_BASIC,
  5947. IS_MF_SD(bp) ? 7 : 6);
  5948. if (CHIP_IS_E3(bp))
  5949. REG_WR(bp, BP_PORT(bp) ?
  5950. NIG_REG_LLH1_MF_MODE :
  5951. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5952. }
  5953. if (!CHIP_IS_E3(bp))
  5954. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  5955. if (!CHIP_IS_E1(bp)) {
  5956. /* 0x2 disable mf_ov, 0x1 enable */
  5957. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  5958. (IS_MF_SD(bp) ? 0x1 : 0x2));
  5959. if (!CHIP_IS_E1x(bp)) {
  5960. val = 0;
  5961. switch (bp->mf_mode) {
  5962. case MULTI_FUNCTION_SD:
  5963. val = 1;
  5964. break;
  5965. case MULTI_FUNCTION_SI:
  5966. case MULTI_FUNCTION_AFEX:
  5967. val = 2;
  5968. break;
  5969. }
  5970. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  5971. NIG_REG_LLH0_CLS_TYPE), val);
  5972. }
  5973. {
  5974. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  5975. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  5976. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  5977. }
  5978. }
  5979. /* If SPIO5 is set to generate interrupts, enable it for this port */
  5980. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5981. if (val & MISC_SPIO_SPIO5) {
  5982. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  5983. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  5984. val = REG_RD(bp, reg_addr);
  5985. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  5986. REG_WR(bp, reg_addr, val);
  5987. }
  5988. return 0;
  5989. }
  5990. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  5991. {
  5992. int reg;
  5993. u32 wb_write[2];
  5994. if (CHIP_IS_E1(bp))
  5995. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  5996. else
  5997. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  5998. wb_write[0] = ONCHIP_ADDR1(addr);
  5999. wb_write[1] = ONCHIP_ADDR2(addr);
  6000. REG_WR_DMAE(bp, reg, wb_write, 2);
  6001. }
  6002. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6003. {
  6004. u32 data, ctl, cnt = 100;
  6005. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6006. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6007. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6008. u32 sb_bit = 1 << (idu_sb_id%32);
  6009. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6010. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6011. /* Not supported in BC mode */
  6012. if (CHIP_INT_MODE_IS_BC(bp))
  6013. return;
  6014. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6015. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6016. IGU_REGULAR_CLEANUP_SET |
  6017. IGU_REGULAR_BCLEANUP;
  6018. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6019. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6020. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6021. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6022. data, igu_addr_data);
  6023. REG_WR(bp, igu_addr_data, data);
  6024. mmiowb();
  6025. barrier();
  6026. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6027. ctl, igu_addr_ctl);
  6028. REG_WR(bp, igu_addr_ctl, ctl);
  6029. mmiowb();
  6030. barrier();
  6031. /* wait for clean up to finish */
  6032. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6033. msleep(20);
  6034. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6035. DP(NETIF_MSG_HW,
  6036. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6037. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6038. }
  6039. }
  6040. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6041. {
  6042. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6043. }
  6044. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6045. {
  6046. u32 i, base = FUNC_ILT_BASE(func);
  6047. for (i = base; i < base + ILT_PER_FUNC; i++)
  6048. bnx2x_ilt_wr(bp, i, 0);
  6049. }
  6050. static void bnx2x_init_searcher(struct bnx2x *bp)
  6051. {
  6052. int port = BP_PORT(bp);
  6053. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6054. /* T1 hash bits value determines the T1 number of entries */
  6055. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6056. }
  6057. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6058. {
  6059. int rc;
  6060. struct bnx2x_func_state_params func_params = {NULL};
  6061. struct bnx2x_func_switch_update_params *switch_update_params =
  6062. &func_params.params.switch_update;
  6063. /* Prepare parameters for function state transitions */
  6064. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6065. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6066. func_params.f_obj = &bp->func_obj;
  6067. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6068. /* Function parameters */
  6069. switch_update_params->suspend = suspend;
  6070. rc = bnx2x_func_state_change(bp, &func_params);
  6071. return rc;
  6072. }
  6073. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6074. {
  6075. int rc, i, port = BP_PORT(bp);
  6076. int vlan_en = 0, mac_en[NUM_MACS];
  6077. /* Close input from network */
  6078. if (bp->mf_mode == SINGLE_FUNCTION) {
  6079. bnx2x_set_rx_filter(&bp->link_params, 0);
  6080. } else {
  6081. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6082. NIG_REG_LLH0_FUNC_EN);
  6083. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6084. NIG_REG_LLH0_FUNC_EN, 0);
  6085. for (i = 0; i < NUM_MACS; i++) {
  6086. mac_en[i] = REG_RD(bp, port ?
  6087. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6088. 4 * i) :
  6089. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6090. 4 * i));
  6091. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6092. 4 * i) :
  6093. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6094. }
  6095. }
  6096. /* Close BMC to host */
  6097. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6098. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6099. /* Suspend Tx switching to the PF. Completion of this ramrod
  6100. * further guarantees that all the packets of that PF / child
  6101. * VFs in BRB were processed by the Parser, so it is safe to
  6102. * change the NIC_MODE register.
  6103. */
  6104. rc = bnx2x_func_switch_update(bp, 1);
  6105. if (rc) {
  6106. BNX2X_ERR("Can't suspend tx-switching!\n");
  6107. return rc;
  6108. }
  6109. /* Change NIC_MODE register */
  6110. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6111. /* Open input from network */
  6112. if (bp->mf_mode == SINGLE_FUNCTION) {
  6113. bnx2x_set_rx_filter(&bp->link_params, 1);
  6114. } else {
  6115. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6116. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6117. for (i = 0; i < NUM_MACS; i++) {
  6118. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6119. 4 * i) :
  6120. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6121. mac_en[i]);
  6122. }
  6123. }
  6124. /* Enable BMC to host */
  6125. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6126. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6127. /* Resume Tx switching to the PF */
  6128. rc = bnx2x_func_switch_update(bp, 0);
  6129. if (rc) {
  6130. BNX2X_ERR("Can't resume tx-switching!\n");
  6131. return rc;
  6132. }
  6133. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6134. return 0;
  6135. }
  6136. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6137. {
  6138. int rc;
  6139. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6140. if (CONFIGURE_NIC_MODE(bp)) {
  6141. /* Configrue searcher as part of function hw init */
  6142. bnx2x_init_searcher(bp);
  6143. /* Reset NIC mode */
  6144. rc = bnx2x_reset_nic_mode(bp);
  6145. if (rc)
  6146. BNX2X_ERR("Can't change NIC mode!\n");
  6147. return rc;
  6148. }
  6149. return 0;
  6150. }
  6151. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6152. {
  6153. int port = BP_PORT(bp);
  6154. int func = BP_FUNC(bp);
  6155. int init_phase = PHASE_PF0 + func;
  6156. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6157. u16 cdu_ilt_start;
  6158. u32 addr, val;
  6159. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6160. int i, main_mem_width, rc;
  6161. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6162. /* FLR cleanup - hmmm */
  6163. if (!CHIP_IS_E1x(bp)) {
  6164. rc = bnx2x_pf_flr_clnup(bp);
  6165. if (rc)
  6166. return rc;
  6167. }
  6168. /* set MSI reconfigure capability */
  6169. if (bp->common.int_block == INT_BLOCK_HC) {
  6170. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6171. val = REG_RD(bp, addr);
  6172. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6173. REG_WR(bp, addr, val);
  6174. }
  6175. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6176. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6177. ilt = BP_ILT(bp);
  6178. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6179. if (IS_SRIOV(bp))
  6180. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6181. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6182. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6183. * those of the VFs, so start line should be reset
  6184. */
  6185. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6186. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6187. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6188. ilt->lines[cdu_ilt_start + i].page_mapping =
  6189. bp->context[i].cxt_mapping;
  6190. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6191. }
  6192. bnx2x_ilt_init_op(bp, INITOP_SET);
  6193. if (!CONFIGURE_NIC_MODE(bp)) {
  6194. bnx2x_init_searcher(bp);
  6195. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6196. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6197. } else {
  6198. /* Set NIC mode */
  6199. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6200. DP(NETIF_MSG_IFUP, "NIC MODE configrued\n");
  6201. }
  6202. if (!CHIP_IS_E1x(bp)) {
  6203. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6204. /* Turn on a single ISR mode in IGU if driver is going to use
  6205. * INT#x or MSI
  6206. */
  6207. if (!(bp->flags & USING_MSIX_FLAG))
  6208. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6209. /*
  6210. * Timers workaround bug: function init part.
  6211. * Need to wait 20msec after initializing ILT,
  6212. * needed to make sure there are no requests in
  6213. * one of the PXP internal queues with "old" ILT addresses
  6214. */
  6215. msleep(20);
  6216. /*
  6217. * Master enable - Due to WB DMAE writes performed before this
  6218. * register is re-initialized as part of the regular function
  6219. * init
  6220. */
  6221. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6222. /* Enable the function in IGU */
  6223. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6224. }
  6225. bp->dmae_ready = 1;
  6226. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6227. if (!CHIP_IS_E1x(bp))
  6228. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6229. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6230. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6231. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6232. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6233. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6234. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6235. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6236. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6237. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6238. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6239. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6240. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6241. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6242. if (!CHIP_IS_E1x(bp))
  6243. REG_WR(bp, QM_REG_PF_EN, 1);
  6244. if (!CHIP_IS_E1x(bp)) {
  6245. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6246. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6247. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6248. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6249. }
  6250. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6251. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6252. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6253. bnx2x_iov_init_dq(bp);
  6254. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6255. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6256. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6257. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6258. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6259. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6260. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6261. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6262. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6263. if (!CHIP_IS_E1x(bp))
  6264. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6265. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6266. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6267. if (!CHIP_IS_E1x(bp))
  6268. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6269. if (IS_MF(bp)) {
  6270. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6271. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6272. }
  6273. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6274. /* HC init per function */
  6275. if (bp->common.int_block == INT_BLOCK_HC) {
  6276. if (CHIP_IS_E1H(bp)) {
  6277. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6278. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6279. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6280. }
  6281. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6282. } else {
  6283. int num_segs, sb_idx, prod_offset;
  6284. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6285. if (!CHIP_IS_E1x(bp)) {
  6286. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6287. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6288. }
  6289. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6290. if (!CHIP_IS_E1x(bp)) {
  6291. int dsb_idx = 0;
  6292. /**
  6293. * Producer memory:
  6294. * E2 mode: address 0-135 match to the mapping memory;
  6295. * 136 - PF0 default prod; 137 - PF1 default prod;
  6296. * 138 - PF2 default prod; 139 - PF3 default prod;
  6297. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6298. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6299. * 144-147 reserved.
  6300. *
  6301. * E1.5 mode - In backward compatible mode;
  6302. * for non default SB; each even line in the memory
  6303. * holds the U producer and each odd line hold
  6304. * the C producer. The first 128 producers are for
  6305. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6306. * producers are for the DSB for each PF.
  6307. * Each PF has five segments: (the order inside each
  6308. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6309. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6310. * 144-147 attn prods;
  6311. */
  6312. /* non-default-status-blocks */
  6313. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6314. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6315. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6316. prod_offset = (bp->igu_base_sb + sb_idx) *
  6317. num_segs;
  6318. for (i = 0; i < num_segs; i++) {
  6319. addr = IGU_REG_PROD_CONS_MEMORY +
  6320. (prod_offset + i) * 4;
  6321. REG_WR(bp, addr, 0);
  6322. }
  6323. /* send consumer update with value 0 */
  6324. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6325. USTORM_ID, 0, IGU_INT_NOP, 1);
  6326. bnx2x_igu_clear_sb(bp,
  6327. bp->igu_base_sb + sb_idx);
  6328. }
  6329. /* default-status-blocks */
  6330. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6331. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6332. if (CHIP_MODE_IS_4_PORT(bp))
  6333. dsb_idx = BP_FUNC(bp);
  6334. else
  6335. dsb_idx = BP_VN(bp);
  6336. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6337. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6338. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6339. /*
  6340. * igu prods come in chunks of E1HVN_MAX (4) -
  6341. * does not matters what is the current chip mode
  6342. */
  6343. for (i = 0; i < (num_segs * E1HVN_MAX);
  6344. i += E1HVN_MAX) {
  6345. addr = IGU_REG_PROD_CONS_MEMORY +
  6346. (prod_offset + i)*4;
  6347. REG_WR(bp, addr, 0);
  6348. }
  6349. /* send consumer update with 0 */
  6350. if (CHIP_INT_MODE_IS_BC(bp)) {
  6351. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6352. USTORM_ID, 0, IGU_INT_NOP, 1);
  6353. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6354. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6355. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6356. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6357. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6358. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6359. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6360. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6361. } else {
  6362. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6363. USTORM_ID, 0, IGU_INT_NOP, 1);
  6364. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6365. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6366. }
  6367. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6368. /* !!! these should become driver const once
  6369. rf-tool supports split-68 const */
  6370. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6371. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6372. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6373. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6374. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6375. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6376. }
  6377. }
  6378. /* Reset PCIE errors for debug */
  6379. REG_WR(bp, 0x2114, 0xffffffff);
  6380. REG_WR(bp, 0x2120, 0xffffffff);
  6381. if (CHIP_IS_E1x(bp)) {
  6382. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6383. main_mem_base = HC_REG_MAIN_MEMORY +
  6384. BP_PORT(bp) * (main_mem_size * 4);
  6385. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6386. main_mem_width = 8;
  6387. val = REG_RD(bp, main_mem_prty_clr);
  6388. if (val)
  6389. DP(NETIF_MSG_HW,
  6390. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6391. val);
  6392. /* Clear "false" parity errors in MSI-X table */
  6393. for (i = main_mem_base;
  6394. i < main_mem_base + main_mem_size * 4;
  6395. i += main_mem_width) {
  6396. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6397. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6398. i, main_mem_width / 4);
  6399. }
  6400. /* Clear HC parity attention */
  6401. REG_RD(bp, main_mem_prty_clr);
  6402. }
  6403. #ifdef BNX2X_STOP_ON_ERROR
  6404. /* Enable STORMs SP logging */
  6405. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6406. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6407. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6408. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6409. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6410. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6411. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6412. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6413. #endif
  6414. bnx2x_phy_probe(&bp->link_params);
  6415. return 0;
  6416. }
  6417. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6418. {
  6419. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6420. if (!CHIP_IS_E1x(bp))
  6421. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6422. sizeof(struct host_hc_status_block_e2));
  6423. else
  6424. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6425. sizeof(struct host_hc_status_block_e1x));
  6426. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6427. }
  6428. void bnx2x_free_mem(struct bnx2x *bp)
  6429. {
  6430. int i;
  6431. /* fastpath */
  6432. bnx2x_free_fp_mem(bp);
  6433. /* end of fastpath */
  6434. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6435. sizeof(struct host_sp_status_block));
  6436. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6437. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6438. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6439. sizeof(struct bnx2x_slowpath));
  6440. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6441. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6442. bp->context[i].size);
  6443. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6444. BNX2X_FREE(bp->ilt->lines);
  6445. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6446. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6447. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6448. }
  6449. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6450. {
  6451. if (!CHIP_IS_E1x(bp))
  6452. /* size = the status block + ramrod buffers */
  6453. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6454. sizeof(struct host_hc_status_block_e2));
  6455. else
  6456. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6457. &bp->cnic_sb_mapping,
  6458. sizeof(struct
  6459. host_hc_status_block_e1x));
  6460. if (CONFIGURE_NIC_MODE(bp))
  6461. /* allocate searcher T2 table, as it wan't allocated before */
  6462. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6463. /* write address to which L5 should insert its values */
  6464. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6465. &bp->slowpath->drv_info_to_mcp;
  6466. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6467. goto alloc_mem_err;
  6468. return 0;
  6469. alloc_mem_err:
  6470. bnx2x_free_mem_cnic(bp);
  6471. BNX2X_ERR("Can't allocate memory\n");
  6472. return -ENOMEM;
  6473. }
  6474. int bnx2x_alloc_mem(struct bnx2x *bp)
  6475. {
  6476. int i, allocated, context_size;
  6477. if (!CONFIGURE_NIC_MODE(bp))
  6478. /* allocate searcher T2 table */
  6479. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6480. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6481. sizeof(struct host_sp_status_block));
  6482. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6483. sizeof(struct bnx2x_slowpath));
  6484. /* Allocate memory for CDU context:
  6485. * This memory is allocated separately and not in the generic ILT
  6486. * functions because CDU differs in few aspects:
  6487. * 1. There are multiple entities allocating memory for context -
  6488. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6489. * its own ILT lines.
  6490. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6491. * for the other ILT clients), to be efficient we want to support
  6492. * allocation of sub-page-size in the last entry.
  6493. * 3. Context pointers are used by the driver to pass to FW / update
  6494. * the context (for the other ILT clients the pointers are used just to
  6495. * free the memory during unload).
  6496. */
  6497. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6498. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6499. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6500. (context_size - allocated));
  6501. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6502. &bp->context[i].cxt_mapping,
  6503. bp->context[i].size);
  6504. allocated += bp->context[i].size;
  6505. }
  6506. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6507. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6508. goto alloc_mem_err;
  6509. if (bnx2x_iov_alloc_mem(bp))
  6510. goto alloc_mem_err;
  6511. /* Slow path ring */
  6512. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6513. /* EQ */
  6514. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6515. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6516. return 0;
  6517. alloc_mem_err:
  6518. bnx2x_free_mem(bp);
  6519. BNX2X_ERR("Can't allocate memory\n");
  6520. return -ENOMEM;
  6521. }
  6522. /*
  6523. * Init service functions
  6524. */
  6525. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6526. struct bnx2x_vlan_mac_obj *obj, bool set,
  6527. int mac_type, unsigned long *ramrod_flags)
  6528. {
  6529. int rc;
  6530. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6531. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6532. /* Fill general parameters */
  6533. ramrod_param.vlan_mac_obj = obj;
  6534. ramrod_param.ramrod_flags = *ramrod_flags;
  6535. /* Fill a user request section if needed */
  6536. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6537. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6538. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6539. /* Set the command: ADD or DEL */
  6540. if (set)
  6541. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6542. else
  6543. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6544. }
  6545. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6546. if (rc == -EEXIST) {
  6547. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6548. /* do not treat adding same MAC as error */
  6549. rc = 0;
  6550. } else if (rc < 0)
  6551. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6552. return rc;
  6553. }
  6554. int bnx2x_del_all_macs(struct bnx2x *bp,
  6555. struct bnx2x_vlan_mac_obj *mac_obj,
  6556. int mac_type, bool wait_for_comp)
  6557. {
  6558. int rc;
  6559. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6560. /* Wait for completion of requested */
  6561. if (wait_for_comp)
  6562. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6563. /* Set the mac type of addresses we want to clear */
  6564. __set_bit(mac_type, &vlan_mac_flags);
  6565. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6566. if (rc < 0)
  6567. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6568. return rc;
  6569. }
  6570. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6571. {
  6572. unsigned long ramrod_flags = 0;
  6573. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6574. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6575. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6576. "Ignoring Zero MAC for STORAGE SD mode\n");
  6577. return 0;
  6578. }
  6579. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6580. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6581. /* Eth MAC is set on RSS leading client (fp[0]) */
  6582. return bnx2x_set_mac_one(bp, bp->dev->dev_addr, &bp->sp_objs->mac_obj,
  6583. set, BNX2X_ETH_MAC, &ramrod_flags);
  6584. }
  6585. int bnx2x_setup_leading(struct bnx2x *bp)
  6586. {
  6587. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6588. }
  6589. /**
  6590. * bnx2x_set_int_mode - configure interrupt mode
  6591. *
  6592. * @bp: driver handle
  6593. *
  6594. * In case of MSI-X it will also try to enable MSI-X.
  6595. */
  6596. int bnx2x_set_int_mode(struct bnx2x *bp)
  6597. {
  6598. int rc = 0;
  6599. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6600. return -EINVAL;
  6601. switch (int_mode) {
  6602. case BNX2X_INT_MODE_MSIX:
  6603. /* attempt to enable msix */
  6604. rc = bnx2x_enable_msix(bp);
  6605. /* msix attained */
  6606. if (!rc)
  6607. return 0;
  6608. /* vfs use only msix */
  6609. if (rc && IS_VF(bp))
  6610. return rc;
  6611. /* failed to enable multiple MSI-X */
  6612. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6613. bp->num_queues,
  6614. 1 + bp->num_cnic_queues);
  6615. /* falling through... */
  6616. case BNX2X_INT_MODE_MSI:
  6617. bnx2x_enable_msi(bp);
  6618. /* falling through... */
  6619. case BNX2X_INT_MODE_INTX:
  6620. bp->num_ethernet_queues = 1;
  6621. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6622. BNX2X_DEV_INFO("set number of queues to 1\n");
  6623. break;
  6624. default:
  6625. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6626. return -EINVAL;
  6627. }
  6628. return 0;
  6629. }
  6630. /* must be called prior to any HW initializations */
  6631. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6632. {
  6633. if (IS_SRIOV(bp))
  6634. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6635. return L2_ILT_LINES(bp);
  6636. }
  6637. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6638. {
  6639. struct ilt_client_info *ilt_client;
  6640. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6641. u16 line = 0;
  6642. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6643. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6644. /* CDU */
  6645. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6646. ilt_client->client_num = ILT_CLIENT_CDU;
  6647. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6648. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6649. ilt_client->start = line;
  6650. line += bnx2x_cid_ilt_lines(bp);
  6651. if (CNIC_SUPPORT(bp))
  6652. line += CNIC_ILT_LINES;
  6653. ilt_client->end = line - 1;
  6654. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6655. ilt_client->start,
  6656. ilt_client->end,
  6657. ilt_client->page_size,
  6658. ilt_client->flags,
  6659. ilog2(ilt_client->page_size >> 12));
  6660. /* QM */
  6661. if (QM_INIT(bp->qm_cid_count)) {
  6662. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6663. ilt_client->client_num = ILT_CLIENT_QM;
  6664. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6665. ilt_client->flags = 0;
  6666. ilt_client->start = line;
  6667. /* 4 bytes for each cid */
  6668. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6669. QM_ILT_PAGE_SZ);
  6670. ilt_client->end = line - 1;
  6671. DP(NETIF_MSG_IFUP,
  6672. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6673. ilt_client->start,
  6674. ilt_client->end,
  6675. ilt_client->page_size,
  6676. ilt_client->flags,
  6677. ilog2(ilt_client->page_size >> 12));
  6678. }
  6679. if (CNIC_SUPPORT(bp)) {
  6680. /* SRC */
  6681. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6682. ilt_client->client_num = ILT_CLIENT_SRC;
  6683. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6684. ilt_client->flags = 0;
  6685. ilt_client->start = line;
  6686. line += SRC_ILT_LINES;
  6687. ilt_client->end = line - 1;
  6688. DP(NETIF_MSG_IFUP,
  6689. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6690. ilt_client->start,
  6691. ilt_client->end,
  6692. ilt_client->page_size,
  6693. ilt_client->flags,
  6694. ilog2(ilt_client->page_size >> 12));
  6695. /* TM */
  6696. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6697. ilt_client->client_num = ILT_CLIENT_TM;
  6698. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6699. ilt_client->flags = 0;
  6700. ilt_client->start = line;
  6701. line += TM_ILT_LINES;
  6702. ilt_client->end = line - 1;
  6703. DP(NETIF_MSG_IFUP,
  6704. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6705. ilt_client->start,
  6706. ilt_client->end,
  6707. ilt_client->page_size,
  6708. ilt_client->flags,
  6709. ilog2(ilt_client->page_size >> 12));
  6710. }
  6711. BUG_ON(line > ILT_MAX_LINES);
  6712. }
  6713. /**
  6714. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6715. *
  6716. * @bp: driver handle
  6717. * @fp: pointer to fastpath
  6718. * @init_params: pointer to parameters structure
  6719. *
  6720. * parameters configured:
  6721. * - HC configuration
  6722. * - Queue's CDU context
  6723. */
  6724. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6725. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6726. {
  6727. u8 cos;
  6728. int cxt_index, cxt_offset;
  6729. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6730. if (!IS_FCOE_FP(fp)) {
  6731. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6732. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6733. /* If HC is supporterd, enable host coalescing in the transition
  6734. * to INIT state.
  6735. */
  6736. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6737. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6738. /* HC rate */
  6739. init_params->rx.hc_rate = bp->rx_ticks ?
  6740. (1000000 / bp->rx_ticks) : 0;
  6741. init_params->tx.hc_rate = bp->tx_ticks ?
  6742. (1000000 / bp->tx_ticks) : 0;
  6743. /* FW SB ID */
  6744. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6745. fp->fw_sb_id;
  6746. /*
  6747. * CQ index among the SB indices: FCoE clients uses the default
  6748. * SB, therefore it's different.
  6749. */
  6750. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6751. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6752. }
  6753. /* set maximum number of COSs supported by this queue */
  6754. init_params->max_cos = fp->max_cos;
  6755. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6756. fp->index, init_params->max_cos);
  6757. /* set the context pointers queue object */
  6758. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6759. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6760. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6761. ILT_PAGE_CIDS);
  6762. init_params->cxts[cos] =
  6763. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6764. }
  6765. }
  6766. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6767. struct bnx2x_queue_state_params *q_params,
  6768. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6769. int tx_index, bool leading)
  6770. {
  6771. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6772. /* Set the command */
  6773. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6774. /* Set tx-only QUEUE flags: don't zero statistics */
  6775. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6776. /* choose the index of the cid to send the slow path on */
  6777. tx_only_params->cid_index = tx_index;
  6778. /* Set general TX_ONLY_SETUP parameters */
  6779. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6780. /* Set Tx TX_ONLY_SETUP parameters */
  6781. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6782. DP(NETIF_MSG_IFUP,
  6783. "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",
  6784. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6785. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6786. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6787. /* send the ramrod */
  6788. return bnx2x_queue_state_change(bp, q_params);
  6789. }
  6790. /**
  6791. * bnx2x_setup_queue - setup queue
  6792. *
  6793. * @bp: driver handle
  6794. * @fp: pointer to fastpath
  6795. * @leading: is leading
  6796. *
  6797. * This function performs 2 steps in a Queue state machine
  6798. * actually: 1) RESET->INIT 2) INIT->SETUP
  6799. */
  6800. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6801. bool leading)
  6802. {
  6803. struct bnx2x_queue_state_params q_params = {NULL};
  6804. struct bnx2x_queue_setup_params *setup_params =
  6805. &q_params.params.setup;
  6806. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6807. &q_params.params.tx_only;
  6808. int rc;
  6809. u8 tx_index;
  6810. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  6811. /* reset IGU state skip FCoE L2 queue */
  6812. if (!IS_FCOE_FP(fp))
  6813. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  6814. IGU_INT_ENABLE, 0);
  6815. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6816. /* We want to wait for completion in this context */
  6817. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6818. /* Prepare the INIT parameters */
  6819. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  6820. /* Set the command */
  6821. q_params.cmd = BNX2X_Q_CMD_INIT;
  6822. /* Change the state to INIT */
  6823. rc = bnx2x_queue_state_change(bp, &q_params);
  6824. if (rc) {
  6825. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  6826. return rc;
  6827. }
  6828. DP(NETIF_MSG_IFUP, "init complete\n");
  6829. /* Now move the Queue to the SETUP state... */
  6830. memset(setup_params, 0, sizeof(*setup_params));
  6831. /* Set QUEUE flags */
  6832. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  6833. /* Set general SETUP parameters */
  6834. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  6835. FIRST_TX_COS_INDEX);
  6836. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  6837. &setup_params->rxq_params);
  6838. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  6839. FIRST_TX_COS_INDEX);
  6840. /* Set the command */
  6841. q_params.cmd = BNX2X_Q_CMD_SETUP;
  6842. if (IS_FCOE_FP(fp))
  6843. bp->fcoe_init = true;
  6844. /* Change the state to SETUP */
  6845. rc = bnx2x_queue_state_change(bp, &q_params);
  6846. if (rc) {
  6847. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  6848. return rc;
  6849. }
  6850. /* loop through the relevant tx-only indices */
  6851. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6852. tx_index < fp->max_cos;
  6853. tx_index++) {
  6854. /* prepare and send tx-only ramrod*/
  6855. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  6856. tx_only_params, tx_index, leading);
  6857. if (rc) {
  6858. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  6859. fp->index, tx_index);
  6860. return rc;
  6861. }
  6862. }
  6863. return rc;
  6864. }
  6865. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  6866. {
  6867. struct bnx2x_fastpath *fp = &bp->fp[index];
  6868. struct bnx2x_fp_txdata *txdata;
  6869. struct bnx2x_queue_state_params q_params = {NULL};
  6870. int rc, tx_index;
  6871. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  6872. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  6873. /* We want to wait for completion in this context */
  6874. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  6875. /* close tx-only connections */
  6876. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  6877. tx_index < fp->max_cos;
  6878. tx_index++){
  6879. /* ascertain this is a normal queue*/
  6880. txdata = fp->txdata_ptr[tx_index];
  6881. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  6882. txdata->txq_index);
  6883. /* send halt terminate on tx-only connection */
  6884. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6885. memset(&q_params.params.terminate, 0,
  6886. sizeof(q_params.params.terminate));
  6887. q_params.params.terminate.cid_index = tx_index;
  6888. rc = bnx2x_queue_state_change(bp, &q_params);
  6889. if (rc)
  6890. return rc;
  6891. /* send halt terminate on tx-only connection */
  6892. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6893. memset(&q_params.params.cfc_del, 0,
  6894. sizeof(q_params.params.cfc_del));
  6895. q_params.params.cfc_del.cid_index = tx_index;
  6896. rc = bnx2x_queue_state_change(bp, &q_params);
  6897. if (rc)
  6898. return rc;
  6899. }
  6900. /* Stop the primary connection: */
  6901. /* ...halt the connection */
  6902. q_params.cmd = BNX2X_Q_CMD_HALT;
  6903. rc = bnx2x_queue_state_change(bp, &q_params);
  6904. if (rc)
  6905. return rc;
  6906. /* ...terminate the connection */
  6907. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  6908. memset(&q_params.params.terminate, 0,
  6909. sizeof(q_params.params.terminate));
  6910. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  6911. rc = bnx2x_queue_state_change(bp, &q_params);
  6912. if (rc)
  6913. return rc;
  6914. /* ...delete cfc entry */
  6915. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  6916. memset(&q_params.params.cfc_del, 0,
  6917. sizeof(q_params.params.cfc_del));
  6918. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  6919. return bnx2x_queue_state_change(bp, &q_params);
  6920. }
  6921. static void bnx2x_reset_func(struct bnx2x *bp)
  6922. {
  6923. int port = BP_PORT(bp);
  6924. int func = BP_FUNC(bp);
  6925. int i;
  6926. /* Disable the function in the FW */
  6927. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  6928. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  6929. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  6930. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  6931. /* FP SBs */
  6932. for_each_eth_queue(bp, i) {
  6933. struct bnx2x_fastpath *fp = &bp->fp[i];
  6934. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6935. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  6936. SB_DISABLED);
  6937. }
  6938. if (CNIC_LOADED(bp))
  6939. /* CNIC SB */
  6940. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6941. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  6942. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  6943. /* SP SB */
  6944. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6945. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  6946. SB_DISABLED);
  6947. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  6948. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  6949. 0);
  6950. /* Configure IGU */
  6951. if (bp->common.int_block == INT_BLOCK_HC) {
  6952. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6953. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6954. } else {
  6955. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6956. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6957. }
  6958. if (CNIC_LOADED(bp)) {
  6959. /* Disable Timer scan */
  6960. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  6961. /*
  6962. * Wait for at least 10ms and up to 2 second for the timers
  6963. * scan to complete
  6964. */
  6965. for (i = 0; i < 200; i++) {
  6966. msleep(10);
  6967. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  6968. break;
  6969. }
  6970. }
  6971. /* Clear ILT */
  6972. bnx2x_clear_func_ilt(bp, func);
  6973. /* Timers workaround bug for E2: if this is vnic-3,
  6974. * we need to set the entire ilt range for this timers.
  6975. */
  6976. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  6977. struct ilt_client_info ilt_cli;
  6978. /* use dummy TM client */
  6979. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  6980. ilt_cli.start = 0;
  6981. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  6982. ilt_cli.client_num = ILT_CLIENT_TM;
  6983. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  6984. }
  6985. /* this assumes that reset_port() called before reset_func()*/
  6986. if (!CHIP_IS_E1x(bp))
  6987. bnx2x_pf_disable(bp);
  6988. bp->dmae_ready = 0;
  6989. }
  6990. static void bnx2x_reset_port(struct bnx2x *bp)
  6991. {
  6992. int port = BP_PORT(bp);
  6993. u32 val;
  6994. /* Reset physical Link */
  6995. bnx2x__link_reset(bp);
  6996. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6997. /* Do not rcv packets to BRB */
  6998. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  6999. /* Do not direct rcv packets that are not for MCP to the BRB */
  7000. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7001. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7002. /* Configure AEU */
  7003. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7004. msleep(100);
  7005. /* Check for BRB port occupancy */
  7006. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7007. if (val)
  7008. DP(NETIF_MSG_IFDOWN,
  7009. "BRB1 is not empty %d blocks are occupied\n", val);
  7010. /* TODO: Close Doorbell port? */
  7011. }
  7012. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7013. {
  7014. struct bnx2x_func_state_params func_params = {NULL};
  7015. /* Prepare parameters for function state transitions */
  7016. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7017. func_params.f_obj = &bp->func_obj;
  7018. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7019. func_params.params.hw_init.load_phase = load_code;
  7020. return bnx2x_func_state_change(bp, &func_params);
  7021. }
  7022. static int bnx2x_func_stop(struct bnx2x *bp)
  7023. {
  7024. struct bnx2x_func_state_params func_params = {NULL};
  7025. int rc;
  7026. /* Prepare parameters for function state transitions */
  7027. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7028. func_params.f_obj = &bp->func_obj;
  7029. func_params.cmd = BNX2X_F_CMD_STOP;
  7030. /*
  7031. * Try to stop the function the 'good way'. If fails (in case
  7032. * of a parity error during bnx2x_chip_cleanup()) and we are
  7033. * not in a debug mode, perform a state transaction in order to
  7034. * enable further HW_RESET transaction.
  7035. */
  7036. rc = bnx2x_func_state_change(bp, &func_params);
  7037. if (rc) {
  7038. #ifdef BNX2X_STOP_ON_ERROR
  7039. return rc;
  7040. #else
  7041. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7042. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7043. return bnx2x_func_state_change(bp, &func_params);
  7044. #endif
  7045. }
  7046. return 0;
  7047. }
  7048. /**
  7049. * bnx2x_send_unload_req - request unload mode from the MCP.
  7050. *
  7051. * @bp: driver handle
  7052. * @unload_mode: requested function's unload mode
  7053. *
  7054. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7055. */
  7056. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7057. {
  7058. u32 reset_code = 0;
  7059. int port = BP_PORT(bp);
  7060. /* Select the UNLOAD request mode */
  7061. if (unload_mode == UNLOAD_NORMAL)
  7062. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7063. else if (bp->flags & NO_WOL_FLAG)
  7064. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7065. else if (bp->wol) {
  7066. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7067. u8 *mac_addr = bp->dev->dev_addr;
  7068. u32 val;
  7069. u16 pmc;
  7070. /* The mac address is written to entries 1-4 to
  7071. * preserve entry 0 which is used by the PMF
  7072. */
  7073. u8 entry = (BP_VN(bp) + 1)*8;
  7074. val = (mac_addr[0] << 8) | mac_addr[1];
  7075. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7076. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7077. (mac_addr[4] << 8) | mac_addr[5];
  7078. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7079. /* Enable the PME and clear the status */
  7080. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7081. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7082. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7083. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7084. } else
  7085. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7086. /* Send the request to the MCP */
  7087. if (!BP_NOMCP(bp))
  7088. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7089. else {
  7090. int path = BP_PATH(bp);
  7091. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7092. path, load_count[path][0], load_count[path][1],
  7093. load_count[path][2]);
  7094. load_count[path][0]--;
  7095. load_count[path][1 + port]--;
  7096. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7097. path, load_count[path][0], load_count[path][1],
  7098. load_count[path][2]);
  7099. if (load_count[path][0] == 0)
  7100. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7101. else if (load_count[path][1 + port] == 0)
  7102. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7103. else
  7104. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7105. }
  7106. return reset_code;
  7107. }
  7108. /**
  7109. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7110. *
  7111. * @bp: driver handle
  7112. * @keep_link: true iff link should be kept up
  7113. */
  7114. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7115. {
  7116. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7117. /* Report UNLOAD_DONE to MCP */
  7118. if (!BP_NOMCP(bp))
  7119. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7120. }
  7121. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7122. {
  7123. int tout = 50;
  7124. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7125. if (!bp->port.pmf)
  7126. return 0;
  7127. /*
  7128. * (assumption: No Attention from MCP at this stage)
  7129. * PMF probably in the middle of TXdisable/enable transaction
  7130. * 1. Sync IRS for default SB
  7131. * 2. Sync SP queue - this guarantes us that attention handling started
  7132. * 3. Wait, that TXdisable/enable transaction completes
  7133. *
  7134. * 1+2 guranty that if DCBx attention was scheduled it already changed
  7135. * pending bit of transaction from STARTED-->TX_STOPPED, if we alredy
  7136. * received complettion for the transaction the state is TX_STOPPED.
  7137. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7138. * transaction.
  7139. */
  7140. /* make sure default SB ISR is done */
  7141. if (msix)
  7142. synchronize_irq(bp->msix_table[0].vector);
  7143. else
  7144. synchronize_irq(bp->pdev->irq);
  7145. flush_workqueue(bnx2x_wq);
  7146. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7147. BNX2X_F_STATE_STARTED && tout--)
  7148. msleep(20);
  7149. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7150. BNX2X_F_STATE_STARTED) {
  7151. #ifdef BNX2X_STOP_ON_ERROR
  7152. BNX2X_ERR("Wrong function state\n");
  7153. return -EBUSY;
  7154. #else
  7155. /*
  7156. * Failed to complete the transaction in a "good way"
  7157. * Force both transactions with CLR bit
  7158. */
  7159. struct bnx2x_func_state_params func_params = {NULL};
  7160. DP(NETIF_MSG_IFDOWN,
  7161. "Hmmm... unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7162. func_params.f_obj = &bp->func_obj;
  7163. __set_bit(RAMROD_DRV_CLR_ONLY,
  7164. &func_params.ramrod_flags);
  7165. /* STARTED-->TX_ST0PPED */
  7166. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7167. bnx2x_func_state_change(bp, &func_params);
  7168. /* TX_ST0PPED-->STARTED */
  7169. func_params.cmd = BNX2X_F_CMD_TX_START;
  7170. return bnx2x_func_state_change(bp, &func_params);
  7171. #endif
  7172. }
  7173. return 0;
  7174. }
  7175. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7176. {
  7177. int port = BP_PORT(bp);
  7178. int i, rc = 0;
  7179. u8 cos;
  7180. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7181. u32 reset_code;
  7182. /* Wait until tx fastpath tasks complete */
  7183. for_each_tx_queue(bp, i) {
  7184. struct bnx2x_fastpath *fp = &bp->fp[i];
  7185. for_each_cos_in_tx_queue(fp, cos)
  7186. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7187. #ifdef BNX2X_STOP_ON_ERROR
  7188. if (rc)
  7189. return;
  7190. #endif
  7191. }
  7192. /* Give HW time to discard old tx messages */
  7193. usleep_range(1000, 1000);
  7194. /* Clean all ETH MACs */
  7195. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7196. false);
  7197. if (rc < 0)
  7198. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7199. /* Clean up UC list */
  7200. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7201. true);
  7202. if (rc < 0)
  7203. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7204. rc);
  7205. /* Disable LLH */
  7206. if (!CHIP_IS_E1(bp))
  7207. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7208. /* Set "drop all" (stop Rx).
  7209. * We need to take a netif_addr_lock() here in order to prevent
  7210. * a race between the completion code and this code.
  7211. */
  7212. netif_addr_lock_bh(bp->dev);
  7213. /* Schedule the rx_mode command */
  7214. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7215. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7216. else
  7217. bnx2x_set_storm_rx_mode(bp);
  7218. /* Cleanup multicast configuration */
  7219. rparam.mcast_obj = &bp->mcast_obj;
  7220. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7221. if (rc < 0)
  7222. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7223. netif_addr_unlock_bh(bp->dev);
  7224. bnx2x_iov_chip_cleanup(bp);
  7225. /*
  7226. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7227. * this function should perform FUNC, PORT or COMMON HW
  7228. * reset.
  7229. */
  7230. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7231. /*
  7232. * (assumption: No Attention from MCP at this stage)
  7233. * PMF probably in the middle of TXdisable/enable transaction
  7234. */
  7235. rc = bnx2x_func_wait_started(bp);
  7236. if (rc) {
  7237. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7238. #ifdef BNX2X_STOP_ON_ERROR
  7239. return;
  7240. #endif
  7241. }
  7242. /* Close multi and leading connections
  7243. * Completions for ramrods are collected in a synchronous way
  7244. */
  7245. for_each_eth_queue(bp, i)
  7246. if (bnx2x_stop_queue(bp, i))
  7247. #ifdef BNX2X_STOP_ON_ERROR
  7248. return;
  7249. #else
  7250. goto unload_error;
  7251. #endif
  7252. if (CNIC_LOADED(bp)) {
  7253. for_each_cnic_queue(bp, i)
  7254. if (bnx2x_stop_queue(bp, i))
  7255. #ifdef BNX2X_STOP_ON_ERROR
  7256. return;
  7257. #else
  7258. goto unload_error;
  7259. #endif
  7260. }
  7261. /* If SP settings didn't get completed so far - something
  7262. * very wrong has happen.
  7263. */
  7264. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7265. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7266. #ifndef BNX2X_STOP_ON_ERROR
  7267. unload_error:
  7268. #endif
  7269. rc = bnx2x_func_stop(bp);
  7270. if (rc) {
  7271. BNX2X_ERR("Function stop failed!\n");
  7272. #ifdef BNX2X_STOP_ON_ERROR
  7273. return;
  7274. #endif
  7275. }
  7276. /* Disable HW interrupts, NAPI */
  7277. bnx2x_netif_stop(bp, 1);
  7278. /* Delete all NAPI objects */
  7279. bnx2x_del_all_napi(bp);
  7280. if (CNIC_LOADED(bp))
  7281. bnx2x_del_all_napi_cnic(bp);
  7282. /* Release IRQs */
  7283. bnx2x_free_irq(bp);
  7284. /* Reset the chip */
  7285. rc = bnx2x_reset_hw(bp, reset_code);
  7286. if (rc)
  7287. BNX2X_ERR("HW_RESET failed\n");
  7288. /* Report UNLOAD_DONE to MCP */
  7289. bnx2x_send_unload_done(bp, keep_link);
  7290. }
  7291. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7292. {
  7293. u32 val;
  7294. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7295. if (CHIP_IS_E1(bp)) {
  7296. int port = BP_PORT(bp);
  7297. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7298. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7299. val = REG_RD(bp, addr);
  7300. val &= ~(0x300);
  7301. REG_WR(bp, addr, val);
  7302. } else {
  7303. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7304. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7305. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7306. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7307. }
  7308. }
  7309. /* Close gates #2, #3 and #4: */
  7310. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7311. {
  7312. u32 val;
  7313. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7314. if (!CHIP_IS_E1(bp)) {
  7315. /* #4 */
  7316. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7317. /* #2 */
  7318. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7319. }
  7320. /* #3 */
  7321. if (CHIP_IS_E1x(bp)) {
  7322. /* Prevent interrupts from HC on both ports */
  7323. val = REG_RD(bp, HC_REG_CONFIG_1);
  7324. REG_WR(bp, HC_REG_CONFIG_1,
  7325. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7326. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7327. val = REG_RD(bp, HC_REG_CONFIG_0);
  7328. REG_WR(bp, HC_REG_CONFIG_0,
  7329. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7330. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7331. } else {
  7332. /* Prevent incomming interrupts in IGU */
  7333. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7334. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7335. (!close) ?
  7336. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7337. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7338. }
  7339. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7340. close ? "closing" : "opening");
  7341. mmiowb();
  7342. }
  7343. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7344. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7345. {
  7346. /* Do some magic... */
  7347. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7348. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7349. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7350. }
  7351. /**
  7352. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7353. *
  7354. * @bp: driver handle
  7355. * @magic_val: old value of the `magic' bit.
  7356. */
  7357. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7358. {
  7359. /* Restore the `magic' bit value... */
  7360. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7361. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7362. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7363. }
  7364. /**
  7365. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7366. *
  7367. * @bp: driver handle
  7368. * @magic_val: old value of 'magic' bit.
  7369. *
  7370. * Takes care of CLP configurations.
  7371. */
  7372. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7373. {
  7374. u32 shmem;
  7375. u32 validity_offset;
  7376. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7377. /* Set `magic' bit in order to save MF config */
  7378. if (!CHIP_IS_E1(bp))
  7379. bnx2x_clp_reset_prep(bp, magic_val);
  7380. /* Get shmem offset */
  7381. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7382. validity_offset =
  7383. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7384. /* Clear validity map flags */
  7385. if (shmem > 0)
  7386. REG_WR(bp, shmem + validity_offset, 0);
  7387. }
  7388. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7389. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7390. /**
  7391. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7392. *
  7393. * @bp: driver handle
  7394. */
  7395. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7396. {
  7397. /* special handling for emulation and FPGA,
  7398. wait 10 times longer */
  7399. if (CHIP_REV_IS_SLOW(bp))
  7400. msleep(MCP_ONE_TIMEOUT*10);
  7401. else
  7402. msleep(MCP_ONE_TIMEOUT);
  7403. }
  7404. /*
  7405. * initializes bp->common.shmem_base and waits for validity signature to appear
  7406. */
  7407. static int bnx2x_init_shmem(struct bnx2x *bp)
  7408. {
  7409. int cnt = 0;
  7410. u32 val = 0;
  7411. do {
  7412. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7413. if (bp->common.shmem_base) {
  7414. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7415. if (val & SHR_MEM_VALIDITY_MB)
  7416. return 0;
  7417. }
  7418. bnx2x_mcp_wait_one(bp);
  7419. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7420. BNX2X_ERR("BAD MCP validity signature\n");
  7421. return -ENODEV;
  7422. }
  7423. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7424. {
  7425. int rc = bnx2x_init_shmem(bp);
  7426. /* Restore the `magic' bit value */
  7427. if (!CHIP_IS_E1(bp))
  7428. bnx2x_clp_reset_done(bp, magic_val);
  7429. return rc;
  7430. }
  7431. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7432. {
  7433. if (!CHIP_IS_E1(bp)) {
  7434. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7435. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7436. mmiowb();
  7437. }
  7438. }
  7439. /*
  7440. * Reset the whole chip except for:
  7441. * - PCIE core
  7442. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7443. * one reset bit)
  7444. * - IGU
  7445. * - MISC (including AEU)
  7446. * - GRC
  7447. * - RBCN, RBCP
  7448. */
  7449. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7450. {
  7451. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7452. u32 global_bits2, stay_reset2;
  7453. /*
  7454. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7455. * (per chip) blocks.
  7456. */
  7457. global_bits2 =
  7458. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7459. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7460. /* Don't reset the following blocks.
  7461. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7462. * reset, as in 4 port device they might still be owned
  7463. * by the MCP (there is only one leader per path).
  7464. */
  7465. not_reset_mask1 =
  7466. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7467. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7468. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7469. not_reset_mask2 =
  7470. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7471. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7472. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7473. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7474. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7475. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7476. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7477. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7478. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7479. MISC_REGISTERS_RESET_REG_2_PGLC |
  7480. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7481. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7482. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7483. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7484. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7485. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7486. /*
  7487. * Keep the following blocks in reset:
  7488. * - all xxMACs are handled by the bnx2x_link code.
  7489. */
  7490. stay_reset2 =
  7491. MISC_REGISTERS_RESET_REG_2_XMAC |
  7492. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7493. /* Full reset masks according to the chip */
  7494. reset_mask1 = 0xffffffff;
  7495. if (CHIP_IS_E1(bp))
  7496. reset_mask2 = 0xffff;
  7497. else if (CHIP_IS_E1H(bp))
  7498. reset_mask2 = 0x1ffff;
  7499. else if (CHIP_IS_E2(bp))
  7500. reset_mask2 = 0xfffff;
  7501. else /* CHIP_IS_E3 */
  7502. reset_mask2 = 0x3ffffff;
  7503. /* Don't reset global blocks unless we need to */
  7504. if (!global)
  7505. reset_mask2 &= ~global_bits2;
  7506. /*
  7507. * In case of attention in the QM, we need to reset PXP
  7508. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7509. * because otherwise QM reset would release 'close the gates' shortly
  7510. * before resetting the PXP, then the PSWRQ would send a write
  7511. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7512. * read the payload data from PSWWR, but PSWWR would not
  7513. * respond. The write queue in PGLUE would stuck, dmae commands
  7514. * would not return. Therefore it's important to reset the second
  7515. * reset register (containing the
  7516. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7517. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7518. * bit).
  7519. */
  7520. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7521. reset_mask2 & (~not_reset_mask2));
  7522. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7523. reset_mask1 & (~not_reset_mask1));
  7524. barrier();
  7525. mmiowb();
  7526. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7527. reset_mask2 & (~stay_reset2));
  7528. barrier();
  7529. mmiowb();
  7530. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7531. mmiowb();
  7532. }
  7533. /**
  7534. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7535. * It should get cleared in no more than 1s.
  7536. *
  7537. * @bp: driver handle
  7538. *
  7539. * It should get cleared in no more than 1s. Returns 0 if
  7540. * pending writes bit gets cleared.
  7541. */
  7542. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7543. {
  7544. u32 cnt = 1000;
  7545. u32 pend_bits = 0;
  7546. do {
  7547. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7548. if (pend_bits == 0)
  7549. break;
  7550. usleep_range(1000, 1000);
  7551. } while (cnt-- > 0);
  7552. if (cnt <= 0) {
  7553. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7554. pend_bits);
  7555. return -EBUSY;
  7556. }
  7557. return 0;
  7558. }
  7559. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7560. {
  7561. int cnt = 1000;
  7562. u32 val = 0;
  7563. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7564. u32 tags_63_32 = 0;
  7565. /* Empty the Tetris buffer, wait for 1s */
  7566. do {
  7567. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7568. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7569. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7570. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7571. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7572. if (CHIP_IS_E3(bp))
  7573. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7574. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7575. ((port_is_idle_0 & 0x1) == 0x1) &&
  7576. ((port_is_idle_1 & 0x1) == 0x1) &&
  7577. (pgl_exp_rom2 == 0xffffffff) &&
  7578. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7579. break;
  7580. usleep_range(1000, 1000);
  7581. } while (cnt-- > 0);
  7582. if (cnt <= 0) {
  7583. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7584. 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",
  7585. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7586. pgl_exp_rom2);
  7587. return -EAGAIN;
  7588. }
  7589. barrier();
  7590. /* Close gates #2, #3 and #4 */
  7591. bnx2x_set_234_gates(bp, true);
  7592. /* Poll for IGU VQs for 57712 and newer chips */
  7593. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7594. return -EAGAIN;
  7595. /* TBD: Indicate that "process kill" is in progress to MCP */
  7596. /* Clear "unprepared" bit */
  7597. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7598. barrier();
  7599. /* Make sure all is written to the chip before the reset */
  7600. mmiowb();
  7601. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7602. * PSWHST, GRC and PSWRD Tetris buffer.
  7603. */
  7604. usleep_range(1000, 1000);
  7605. /* Prepare to chip reset: */
  7606. /* MCP */
  7607. if (global)
  7608. bnx2x_reset_mcp_prep(bp, &val);
  7609. /* PXP */
  7610. bnx2x_pxp_prep(bp);
  7611. barrier();
  7612. /* reset the chip */
  7613. bnx2x_process_kill_chip_reset(bp, global);
  7614. barrier();
  7615. /* Recover after reset: */
  7616. /* MCP */
  7617. if (global && bnx2x_reset_mcp_comp(bp, val))
  7618. return -EAGAIN;
  7619. /* TBD: Add resetting the NO_MCP mode DB here */
  7620. /* Open the gates #2, #3 and #4 */
  7621. bnx2x_set_234_gates(bp, false);
  7622. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7623. * reset state, re-enable attentions. */
  7624. return 0;
  7625. }
  7626. static int bnx2x_leader_reset(struct bnx2x *bp)
  7627. {
  7628. int rc = 0;
  7629. bool global = bnx2x_reset_is_global(bp);
  7630. u32 load_code;
  7631. /* if not going to reset MCP - load "fake" driver to reset HW while
  7632. * driver is owner of the HW
  7633. */
  7634. if (!global && !BP_NOMCP(bp)) {
  7635. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7636. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7637. if (!load_code) {
  7638. BNX2X_ERR("MCP response failure, aborting\n");
  7639. rc = -EAGAIN;
  7640. goto exit_leader_reset;
  7641. }
  7642. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7643. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7644. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7645. rc = -EAGAIN;
  7646. goto exit_leader_reset2;
  7647. }
  7648. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7649. if (!load_code) {
  7650. BNX2X_ERR("MCP response failure, aborting\n");
  7651. rc = -EAGAIN;
  7652. goto exit_leader_reset2;
  7653. }
  7654. }
  7655. /* Try to recover after the failure */
  7656. if (bnx2x_process_kill(bp, global)) {
  7657. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7658. BP_PATH(bp));
  7659. rc = -EAGAIN;
  7660. goto exit_leader_reset2;
  7661. }
  7662. /*
  7663. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7664. * state.
  7665. */
  7666. bnx2x_set_reset_done(bp);
  7667. if (global)
  7668. bnx2x_clear_reset_global(bp);
  7669. exit_leader_reset2:
  7670. /* unload "fake driver" if it was loaded */
  7671. if (!global && !BP_NOMCP(bp)) {
  7672. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7673. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7674. }
  7675. exit_leader_reset:
  7676. bp->is_leader = 0;
  7677. bnx2x_release_leader_lock(bp);
  7678. smp_mb();
  7679. return rc;
  7680. }
  7681. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7682. {
  7683. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7684. /* Disconnect this device */
  7685. netif_device_detach(bp->dev);
  7686. /*
  7687. * Block ifup for all function on this engine until "process kill"
  7688. * or power cycle.
  7689. */
  7690. bnx2x_set_reset_in_progress(bp);
  7691. /* Shut down the power */
  7692. bnx2x_set_power_state(bp, PCI_D3hot);
  7693. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7694. smp_mb();
  7695. }
  7696. /*
  7697. * Assumption: runs under rtnl lock. This together with the fact
  7698. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7699. * will never be called when netif_running(bp->dev) is false.
  7700. */
  7701. static void bnx2x_parity_recover(struct bnx2x *bp)
  7702. {
  7703. bool global = false;
  7704. u32 error_recovered, error_unrecovered;
  7705. bool is_parity;
  7706. DP(NETIF_MSG_HW, "Handling parity\n");
  7707. while (1) {
  7708. switch (bp->recovery_state) {
  7709. case BNX2X_RECOVERY_INIT:
  7710. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7711. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7712. WARN_ON(!is_parity);
  7713. /* Try to get a LEADER_LOCK HW lock */
  7714. if (bnx2x_trylock_leader_lock(bp)) {
  7715. bnx2x_set_reset_in_progress(bp);
  7716. /*
  7717. * Check if there is a global attention and if
  7718. * there was a global attention, set the global
  7719. * reset bit.
  7720. */
  7721. if (global)
  7722. bnx2x_set_reset_global(bp);
  7723. bp->is_leader = 1;
  7724. }
  7725. /* Stop the driver */
  7726. /* If interface has been removed - break */
  7727. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7728. return;
  7729. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7730. /* Ensure "is_leader", MCP command sequence and
  7731. * "recovery_state" update values are seen on other
  7732. * CPUs.
  7733. */
  7734. smp_mb();
  7735. break;
  7736. case BNX2X_RECOVERY_WAIT:
  7737. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7738. if (bp->is_leader) {
  7739. int other_engine = BP_PATH(bp) ? 0 : 1;
  7740. bool other_load_status =
  7741. bnx2x_get_load_status(bp, other_engine);
  7742. bool load_status =
  7743. bnx2x_get_load_status(bp, BP_PATH(bp));
  7744. global = bnx2x_reset_is_global(bp);
  7745. /*
  7746. * In case of a parity in a global block, let
  7747. * the first leader that performs a
  7748. * leader_reset() reset the global blocks in
  7749. * order to clear global attentions. Otherwise
  7750. * the the gates will remain closed for that
  7751. * engine.
  7752. */
  7753. if (load_status ||
  7754. (global && other_load_status)) {
  7755. /* Wait until all other functions get
  7756. * down.
  7757. */
  7758. schedule_delayed_work(&bp->sp_rtnl_task,
  7759. HZ/10);
  7760. return;
  7761. } else {
  7762. /* If all other functions got down -
  7763. * try to bring the chip back to
  7764. * normal. In any case it's an exit
  7765. * point for a leader.
  7766. */
  7767. if (bnx2x_leader_reset(bp)) {
  7768. bnx2x_recovery_failed(bp);
  7769. return;
  7770. }
  7771. /* If we are here, means that the
  7772. * leader has succeeded and doesn't
  7773. * want to be a leader any more. Try
  7774. * to continue as a none-leader.
  7775. */
  7776. break;
  7777. }
  7778. } else { /* non-leader */
  7779. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7780. /* Try to get a LEADER_LOCK HW lock as
  7781. * long as a former leader may have
  7782. * been unloaded by the user or
  7783. * released a leadership by another
  7784. * reason.
  7785. */
  7786. if (bnx2x_trylock_leader_lock(bp)) {
  7787. /* I'm a leader now! Restart a
  7788. * switch case.
  7789. */
  7790. bp->is_leader = 1;
  7791. break;
  7792. }
  7793. schedule_delayed_work(&bp->sp_rtnl_task,
  7794. HZ/10);
  7795. return;
  7796. } else {
  7797. /*
  7798. * If there was a global attention, wait
  7799. * for it to be cleared.
  7800. */
  7801. if (bnx2x_reset_is_global(bp)) {
  7802. schedule_delayed_work(
  7803. &bp->sp_rtnl_task,
  7804. HZ/10);
  7805. return;
  7806. }
  7807. error_recovered =
  7808. bp->eth_stats.recoverable_error;
  7809. error_unrecovered =
  7810. bp->eth_stats.unrecoverable_error;
  7811. bp->recovery_state =
  7812. BNX2X_RECOVERY_NIC_LOADING;
  7813. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  7814. error_unrecovered++;
  7815. netdev_err(bp->dev,
  7816. "Recovery failed. Power cycle needed\n");
  7817. /* Disconnect this device */
  7818. netif_device_detach(bp->dev);
  7819. /* Shut down the power */
  7820. bnx2x_set_power_state(
  7821. bp, PCI_D3hot);
  7822. smp_mb();
  7823. } else {
  7824. bp->recovery_state =
  7825. BNX2X_RECOVERY_DONE;
  7826. error_recovered++;
  7827. smp_mb();
  7828. }
  7829. bp->eth_stats.recoverable_error =
  7830. error_recovered;
  7831. bp->eth_stats.unrecoverable_error =
  7832. error_unrecovered;
  7833. return;
  7834. }
  7835. }
  7836. default:
  7837. return;
  7838. }
  7839. }
  7840. }
  7841. static int bnx2x_close(struct net_device *dev);
  7842. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  7843. * scheduled on a general queue in order to prevent a dead lock.
  7844. */
  7845. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  7846. {
  7847. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  7848. rtnl_lock();
  7849. if (!netif_running(bp->dev)) {
  7850. rtnl_unlock();
  7851. return;
  7852. }
  7853. /* if stop on error is defined no recovery flows should be executed */
  7854. #ifdef BNX2X_STOP_ON_ERROR
  7855. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  7856. "you will need to reboot when done\n");
  7857. goto sp_rtnl_not_reset;
  7858. #endif
  7859. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  7860. /*
  7861. * Clear all pending SP commands as we are going to reset the
  7862. * function anyway.
  7863. */
  7864. bp->sp_rtnl_state = 0;
  7865. smp_mb();
  7866. bnx2x_parity_recover(bp);
  7867. rtnl_unlock();
  7868. return;
  7869. }
  7870. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  7871. /*
  7872. * Clear all pending SP commands as we are going to reset the
  7873. * function anyway.
  7874. */
  7875. bp->sp_rtnl_state = 0;
  7876. smp_mb();
  7877. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  7878. bnx2x_nic_load(bp, LOAD_NORMAL);
  7879. rtnl_unlock();
  7880. return;
  7881. }
  7882. #ifdef BNX2X_STOP_ON_ERROR
  7883. sp_rtnl_not_reset:
  7884. #endif
  7885. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  7886. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  7887. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  7888. bnx2x_after_function_update(bp);
  7889. /*
  7890. * in case of fan failure we need to reset id if the "stop on error"
  7891. * debug flag is set, since we trying to prevent permanent overheating
  7892. * damage
  7893. */
  7894. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  7895. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  7896. netif_device_detach(bp->dev);
  7897. bnx2x_close(bp->dev);
  7898. rtnl_unlock();
  7899. return;
  7900. }
  7901. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  7902. DP(BNX2X_MSG_SP,
  7903. "sending set mcast vf pf channel message from rtnl sp-task\n");
  7904. bnx2x_vfpf_set_mcast(bp->dev);
  7905. }
  7906. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  7907. &bp->sp_rtnl_state)) {
  7908. DP(BNX2X_MSG_SP,
  7909. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  7910. bnx2x_vfpf_storm_rx_mode(bp);
  7911. }
  7912. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  7913. * can be called from other contexts as well)
  7914. */
  7915. rtnl_unlock();
  7916. /* enable SR-IOV if applicable */
  7917. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  7918. &bp->sp_rtnl_state))
  7919. bnx2x_enable_sriov(bp);
  7920. }
  7921. static void bnx2x_period_task(struct work_struct *work)
  7922. {
  7923. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  7924. if (!netif_running(bp->dev))
  7925. goto period_task_exit;
  7926. if (CHIP_REV_IS_SLOW(bp)) {
  7927. BNX2X_ERR("period task called on emulation, ignoring\n");
  7928. goto period_task_exit;
  7929. }
  7930. bnx2x_acquire_phy_lock(bp);
  7931. /*
  7932. * The barrier is needed to ensure the ordering between the writing to
  7933. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  7934. * the reading here.
  7935. */
  7936. smp_mb();
  7937. if (bp->port.pmf) {
  7938. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  7939. /* Re-queue task in 1 sec */
  7940. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  7941. }
  7942. bnx2x_release_phy_lock(bp);
  7943. period_task_exit:
  7944. return;
  7945. }
  7946. /*
  7947. * Init service functions
  7948. */
  7949. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  7950. {
  7951. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  7952. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  7953. return base + (BP_ABS_FUNC(bp)) * stride;
  7954. }
  7955. static void bnx2x_undi_int_disable_e1h(struct bnx2x *bp)
  7956. {
  7957. u32 reg = bnx2x_get_pretend_reg(bp);
  7958. /* Flush all outstanding writes */
  7959. mmiowb();
  7960. /* Pretend to be function 0 */
  7961. REG_WR(bp, reg, 0);
  7962. REG_RD(bp, reg); /* Flush the GRC transaction (in the chip) */
  7963. /* From now we are in the "like-E1" mode */
  7964. bnx2x_int_disable(bp);
  7965. /* Flush all outstanding writes */
  7966. mmiowb();
  7967. /* Restore the original function */
  7968. REG_WR(bp, reg, BP_ABS_FUNC(bp));
  7969. REG_RD(bp, reg);
  7970. }
  7971. static inline void bnx2x_undi_int_disable(struct bnx2x *bp)
  7972. {
  7973. if (CHIP_IS_E1(bp))
  7974. bnx2x_int_disable(bp);
  7975. else
  7976. bnx2x_undi_int_disable_e1h(bp);
  7977. }
  7978. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  7979. struct bnx2x_mac_vals *vals)
  7980. {
  7981. u32 val, base_addr, offset, mask, reset_reg;
  7982. bool mac_stopped = false;
  7983. u8 port = BP_PORT(bp);
  7984. /* reset addresses as they also mark which values were changed */
  7985. vals->bmac_addr = 0;
  7986. vals->umac_addr = 0;
  7987. vals->xmac_addr = 0;
  7988. vals->emac_addr = 0;
  7989. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  7990. if (!CHIP_IS_E3(bp)) {
  7991. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  7992. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  7993. if ((mask & reset_reg) && val) {
  7994. u32 wb_data[2];
  7995. BNX2X_DEV_INFO("Disable bmac Rx\n");
  7996. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  7997. : NIG_REG_INGRESS_BMAC0_MEM;
  7998. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  7999. : BIGMAC_REGISTER_BMAC_CONTROL;
  8000. /*
  8001. * use rd/wr since we cannot use dmae. This is safe
  8002. * since MCP won't access the bus due to the request
  8003. * to unload, and no function on the path can be
  8004. * loaded at this time.
  8005. */
  8006. wb_data[0] = REG_RD(bp, base_addr + offset);
  8007. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8008. vals->bmac_addr = base_addr + offset;
  8009. vals->bmac_val[0] = wb_data[0];
  8010. vals->bmac_val[1] = wb_data[1];
  8011. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8012. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8013. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8014. }
  8015. BNX2X_DEV_INFO("Disable emac Rx\n");
  8016. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8017. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8018. REG_WR(bp, vals->emac_addr, 0);
  8019. mac_stopped = true;
  8020. } else {
  8021. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8022. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8023. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8024. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8025. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8026. val & ~(1 << 1));
  8027. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8028. val | (1 << 1));
  8029. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8030. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8031. REG_WR(bp, vals->xmac_addr, 0);
  8032. mac_stopped = true;
  8033. }
  8034. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8035. if (mask & reset_reg) {
  8036. BNX2X_DEV_INFO("Disable umac Rx\n");
  8037. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8038. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8039. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8040. REG_WR(bp, vals->umac_addr, 0);
  8041. mac_stopped = true;
  8042. }
  8043. }
  8044. if (mac_stopped)
  8045. msleep(20);
  8046. }
  8047. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8048. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8049. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8050. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8051. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8052. {
  8053. u16 rcq, bd;
  8054. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8055. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8056. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8057. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8058. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8059. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8060. port, bd, rcq);
  8061. }
  8062. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8063. {
  8064. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8065. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8066. if (!rc) {
  8067. BNX2X_ERR("MCP response failure, aborting\n");
  8068. return -EBUSY;
  8069. }
  8070. return 0;
  8071. }
  8072. static struct bnx2x_prev_path_list *
  8073. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8074. {
  8075. struct bnx2x_prev_path_list *tmp_list;
  8076. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8077. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8078. bp->pdev->bus->number == tmp_list->bus &&
  8079. BP_PATH(bp) == tmp_list->path)
  8080. return tmp_list;
  8081. return NULL;
  8082. }
  8083. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8084. {
  8085. struct bnx2x_prev_path_list *tmp_list;
  8086. int rc = false;
  8087. if (down_trylock(&bnx2x_prev_sem))
  8088. return false;
  8089. list_for_each_entry(tmp_list, &bnx2x_prev_list, list) {
  8090. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8091. bp->pdev->bus->number == tmp_list->bus &&
  8092. BP_PATH(bp) == tmp_list->path) {
  8093. rc = true;
  8094. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8095. BP_PATH(bp));
  8096. break;
  8097. }
  8098. }
  8099. up(&bnx2x_prev_sem);
  8100. return rc;
  8101. }
  8102. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8103. {
  8104. struct bnx2x_prev_path_list *tmp_list;
  8105. int rc;
  8106. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8107. if (!tmp_list) {
  8108. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8109. return -ENOMEM;
  8110. }
  8111. tmp_list->bus = bp->pdev->bus->number;
  8112. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8113. tmp_list->path = BP_PATH(bp);
  8114. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8115. rc = down_interruptible(&bnx2x_prev_sem);
  8116. if (rc) {
  8117. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8118. kfree(tmp_list);
  8119. } else {
  8120. BNX2X_DEV_INFO("Marked path [%d] - finished previous unload\n",
  8121. BP_PATH(bp));
  8122. list_add(&tmp_list->list, &bnx2x_prev_list);
  8123. up(&bnx2x_prev_sem);
  8124. }
  8125. return rc;
  8126. }
  8127. static int bnx2x_do_flr(struct bnx2x *bp)
  8128. {
  8129. int i;
  8130. u16 status;
  8131. struct pci_dev *dev = bp->pdev;
  8132. if (CHIP_IS_E1x(bp)) {
  8133. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8134. return -EINVAL;
  8135. }
  8136. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8137. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8138. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8139. bp->common.bc_ver);
  8140. return -EINVAL;
  8141. }
  8142. /* Wait for Transaction Pending bit clean */
  8143. for (i = 0; i < 4; i++) {
  8144. if (i)
  8145. msleep((1 << (i - 1)) * 100);
  8146. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8147. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8148. goto clear;
  8149. }
  8150. dev_err(&dev->dev,
  8151. "transaction is not cleared; proceeding with reset anyway\n");
  8152. clear:
  8153. BNX2X_DEV_INFO("Initiating FLR\n");
  8154. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8155. return 0;
  8156. }
  8157. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8158. {
  8159. int rc;
  8160. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8161. /* Test if previous unload process was already finished for this path */
  8162. if (bnx2x_prev_is_path_marked(bp))
  8163. return bnx2x_prev_mcp_done(bp);
  8164. /* If function has FLR capabilities, and existing FW version matches
  8165. * the one required, then FLR will be sufficient to clean any residue
  8166. * left by previous driver
  8167. */
  8168. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8169. if (!rc) {
  8170. /* fw version is good */
  8171. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8172. rc = bnx2x_do_flr(bp);
  8173. }
  8174. if (!rc) {
  8175. /* FLR was performed */
  8176. BNX2X_DEV_INFO("FLR successful\n");
  8177. return 0;
  8178. }
  8179. BNX2X_DEV_INFO("Could not FLR\n");
  8180. /* Close the MCP request, return failure*/
  8181. rc = bnx2x_prev_mcp_done(bp);
  8182. if (!rc)
  8183. rc = BNX2X_PREV_WAIT_NEEDED;
  8184. return rc;
  8185. }
  8186. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8187. {
  8188. u32 reset_reg, tmp_reg = 0, rc;
  8189. bool prev_undi = false;
  8190. struct bnx2x_mac_vals mac_vals;
  8191. /* It is possible a previous function received 'common' answer,
  8192. * but hasn't loaded yet, therefore creating a scenario of
  8193. * multiple functions receiving 'common' on the same path.
  8194. */
  8195. BNX2X_DEV_INFO("Common unload Flow\n");
  8196. memset(&mac_vals, 0, sizeof(mac_vals));
  8197. if (bnx2x_prev_is_path_marked(bp))
  8198. return bnx2x_prev_mcp_done(bp);
  8199. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8200. /* Reset should be performed after BRB is emptied */
  8201. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8202. u32 timer_count = 1000;
  8203. /* Close the MAC Rx to prevent BRB from filling up */
  8204. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8205. /* close LLH filters towards the BRB */
  8206. bnx2x_set_rx_filter(&bp->link_params, 0);
  8207. /* Check if the UNDI driver was previously loaded
  8208. * UNDI driver initializes CID offset for normal bell to 0x7
  8209. */
  8210. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8211. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8212. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8213. if (tmp_reg == 0x7) {
  8214. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8215. prev_undi = true;
  8216. /* clear the UNDI indication */
  8217. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8218. /* clear possible idle check errors */
  8219. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8220. }
  8221. }
  8222. /* wait until BRB is empty */
  8223. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8224. while (timer_count) {
  8225. u32 prev_brb = tmp_reg;
  8226. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8227. if (!tmp_reg)
  8228. break;
  8229. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8230. /* reset timer as long as BRB actually gets emptied */
  8231. if (prev_brb > tmp_reg)
  8232. timer_count = 1000;
  8233. else
  8234. timer_count--;
  8235. /* If UNDI resides in memory, manually increment it */
  8236. if (prev_undi)
  8237. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8238. udelay(10);
  8239. }
  8240. if (!timer_count)
  8241. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8242. }
  8243. /* No packets are in the pipeline, path is ready for reset */
  8244. bnx2x_reset_common(bp);
  8245. if (mac_vals.xmac_addr)
  8246. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8247. if (mac_vals.umac_addr)
  8248. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8249. if (mac_vals.emac_addr)
  8250. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8251. if (mac_vals.bmac_addr) {
  8252. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8253. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8254. }
  8255. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8256. if (rc) {
  8257. bnx2x_prev_mcp_done(bp);
  8258. return rc;
  8259. }
  8260. return bnx2x_prev_mcp_done(bp);
  8261. }
  8262. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8263. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8264. * the addresses of the transaction, resulting in was-error bit set in the pci
  8265. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8266. * to clear the interrupt which detected this from the pglueb and the was done
  8267. * bit
  8268. */
  8269. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8270. {
  8271. if (!CHIP_IS_E1x(bp)) {
  8272. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8273. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8274. BNX2X_ERR("was error bit was found to be set in pglueb upon startup. Clearing");
  8275. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8276. 1 << BP_FUNC(bp));
  8277. }
  8278. }
  8279. }
  8280. static int bnx2x_prev_unload(struct bnx2x *bp)
  8281. {
  8282. int time_counter = 10;
  8283. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8284. struct bnx2x_prev_path_list *prev_list;
  8285. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8286. /* clear hw from errors which may have resulted from an interrupted
  8287. * dmae transaction.
  8288. */
  8289. bnx2x_prev_interrupted_dmae(bp);
  8290. /* Release previously held locks */
  8291. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8292. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8293. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8294. hw_lock_val = (REG_RD(bp, hw_lock_reg));
  8295. if (hw_lock_val) {
  8296. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8297. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8298. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8299. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8300. }
  8301. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8302. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8303. } else
  8304. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8305. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8306. BNX2X_DEV_INFO("Release previously held alr\n");
  8307. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  8308. }
  8309. do {
  8310. /* Lock MCP using an unload request */
  8311. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8312. if (!fw) {
  8313. BNX2X_ERR("MCP response failure, aborting\n");
  8314. rc = -EBUSY;
  8315. break;
  8316. }
  8317. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON) {
  8318. rc = bnx2x_prev_unload_common(bp);
  8319. break;
  8320. }
  8321. /* non-common reply from MCP night require looping */
  8322. rc = bnx2x_prev_unload_uncommon(bp);
  8323. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8324. break;
  8325. msleep(20);
  8326. } while (--time_counter);
  8327. if (!time_counter || rc) {
  8328. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8329. rc = -EBUSY;
  8330. }
  8331. /* Mark function if its port was used to boot from SAN */
  8332. prev_list = bnx2x_prev_path_get_entry(bp);
  8333. if (prev_list && (prev_list->undi & (1 << BP_PORT(bp))))
  8334. bp->link_params.feature_config_flags |=
  8335. FEATURE_CONFIG_BOOT_FROM_SAN;
  8336. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8337. return rc;
  8338. }
  8339. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8340. {
  8341. u32 val, val2, val3, val4, id, boot_mode;
  8342. u16 pmc;
  8343. /* Get the chip revision id and number. */
  8344. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8345. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8346. id = ((val & 0xffff) << 16);
  8347. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8348. id |= ((val & 0xf) << 12);
  8349. val = REG_RD(bp, MISC_REG_CHIP_METAL);
  8350. id |= ((val & 0xff) << 4);
  8351. val = REG_RD(bp, MISC_REG_BOND_ID);
  8352. id |= (val & 0xf);
  8353. bp->common.chip_id = id;
  8354. /* force 57811 according to MISC register */
  8355. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8356. if (CHIP_IS_57810(bp))
  8357. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8358. (bp->common.chip_id & 0x0000FFFF);
  8359. else if (CHIP_IS_57810_MF(bp))
  8360. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8361. (bp->common.chip_id & 0x0000FFFF);
  8362. bp->common.chip_id |= 0x1;
  8363. }
  8364. /* Set doorbell size */
  8365. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8366. if (!CHIP_IS_E1x(bp)) {
  8367. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8368. if ((val & 1) == 0)
  8369. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8370. else
  8371. val = (val >> 1) & 1;
  8372. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8373. "2_PORT_MODE");
  8374. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8375. CHIP_2_PORT_MODE;
  8376. if (CHIP_MODE_IS_4_PORT(bp))
  8377. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8378. else
  8379. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8380. } else {
  8381. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8382. bp->pfid = bp->pf_num; /* 0..7 */
  8383. }
  8384. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8385. bp->link_params.chip_id = bp->common.chip_id;
  8386. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8387. val = (REG_RD(bp, 0x2874) & 0x55);
  8388. if ((bp->common.chip_id & 0x1) ||
  8389. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8390. bp->flags |= ONE_PORT_FLAG;
  8391. BNX2X_DEV_INFO("single port device\n");
  8392. }
  8393. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8394. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8395. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8396. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8397. bp->common.flash_size, bp->common.flash_size);
  8398. bnx2x_init_shmem(bp);
  8399. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8400. MISC_REG_GENERIC_CR_1 :
  8401. MISC_REG_GENERIC_CR_0));
  8402. bp->link_params.shmem_base = bp->common.shmem_base;
  8403. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8404. if (SHMEM2_RD(bp, size) >
  8405. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8406. bp->link_params.lfa_base =
  8407. REG_RD(bp, bp->common.shmem2_base +
  8408. (u32)offsetof(struct shmem2_region,
  8409. lfa_host_addr[BP_PORT(bp)]));
  8410. else
  8411. bp->link_params.lfa_base = 0;
  8412. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8413. bp->common.shmem_base, bp->common.shmem2_base);
  8414. if (!bp->common.shmem_base) {
  8415. BNX2X_DEV_INFO("MCP not active\n");
  8416. bp->flags |= NO_MCP_FLAG;
  8417. return;
  8418. }
  8419. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8420. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8421. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8422. SHARED_HW_CFG_LED_MODE_MASK) >>
  8423. SHARED_HW_CFG_LED_MODE_SHIFT);
  8424. bp->link_params.feature_config_flags = 0;
  8425. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8426. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8427. bp->link_params.feature_config_flags |=
  8428. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8429. else
  8430. bp->link_params.feature_config_flags &=
  8431. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8432. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8433. bp->common.bc_ver = val;
  8434. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8435. if (val < BNX2X_BC_VER) {
  8436. /* for now only warn
  8437. * later we might need to enforce this */
  8438. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8439. BNX2X_BC_VER, val);
  8440. }
  8441. bp->link_params.feature_config_flags |=
  8442. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8443. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8444. bp->link_params.feature_config_flags |=
  8445. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8446. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8447. bp->link_params.feature_config_flags |=
  8448. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8449. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8450. bp->link_params.feature_config_flags |=
  8451. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8452. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8453. bp->link_params.feature_config_flags |=
  8454. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8455. FEATURE_CONFIG_MT_SUPPORT : 0;
  8456. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8457. BC_SUPPORTS_PFC_STATS : 0;
  8458. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8459. BC_SUPPORTS_FCOE_FEATURES : 0;
  8460. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8461. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8462. boot_mode = SHMEM_RD(bp,
  8463. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8464. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8465. switch (boot_mode) {
  8466. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8467. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8468. break;
  8469. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8470. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8471. break;
  8472. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8473. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8474. break;
  8475. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8476. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8477. break;
  8478. }
  8479. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8480. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8481. BNX2X_DEV_INFO("%sWoL capable\n",
  8482. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8483. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8484. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8485. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8486. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8487. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8488. val, val2, val3, val4);
  8489. }
  8490. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8491. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8492. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8493. {
  8494. int pfid = BP_FUNC(bp);
  8495. int igu_sb_id;
  8496. u32 val;
  8497. u8 fid, igu_sb_cnt = 0;
  8498. bp->igu_base_sb = 0xff;
  8499. if (CHIP_INT_MODE_IS_BC(bp)) {
  8500. int vn = BP_VN(bp);
  8501. igu_sb_cnt = bp->igu_sb_cnt;
  8502. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8503. FP_SB_MAX_E1x;
  8504. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8505. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8506. return 0;
  8507. }
  8508. /* IGU in normal mode - read CAM */
  8509. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8510. igu_sb_id++) {
  8511. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8512. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8513. continue;
  8514. fid = IGU_FID(val);
  8515. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8516. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8517. continue;
  8518. if (IGU_VEC(val) == 0)
  8519. /* default status block */
  8520. bp->igu_dsb_id = igu_sb_id;
  8521. else {
  8522. if (bp->igu_base_sb == 0xff)
  8523. bp->igu_base_sb = igu_sb_id;
  8524. igu_sb_cnt++;
  8525. }
  8526. }
  8527. }
  8528. #ifdef CONFIG_PCI_MSI
  8529. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8530. * optional that number of CAM entries will not be equal to the value
  8531. * advertised in PCI.
  8532. * Driver should use the minimal value of both as the actual status
  8533. * block count
  8534. */
  8535. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8536. #endif
  8537. if (igu_sb_cnt == 0) {
  8538. BNX2X_ERR("CAM configuration error\n");
  8539. return -EINVAL;
  8540. }
  8541. return 0;
  8542. }
  8543. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8544. {
  8545. int cfg_size = 0, idx, port = BP_PORT(bp);
  8546. /* Aggregation of supported attributes of all external phys */
  8547. bp->port.supported[0] = 0;
  8548. bp->port.supported[1] = 0;
  8549. switch (bp->link_params.num_phys) {
  8550. case 1:
  8551. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8552. cfg_size = 1;
  8553. break;
  8554. case 2:
  8555. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8556. cfg_size = 1;
  8557. break;
  8558. case 3:
  8559. if (bp->link_params.multi_phy_config &
  8560. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8561. bp->port.supported[1] =
  8562. bp->link_params.phy[EXT_PHY1].supported;
  8563. bp->port.supported[0] =
  8564. bp->link_params.phy[EXT_PHY2].supported;
  8565. } else {
  8566. bp->port.supported[0] =
  8567. bp->link_params.phy[EXT_PHY1].supported;
  8568. bp->port.supported[1] =
  8569. bp->link_params.phy[EXT_PHY2].supported;
  8570. }
  8571. cfg_size = 2;
  8572. break;
  8573. }
  8574. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8575. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8576. SHMEM_RD(bp,
  8577. dev_info.port_hw_config[port].external_phy_config),
  8578. SHMEM_RD(bp,
  8579. dev_info.port_hw_config[port].external_phy_config2));
  8580. return;
  8581. }
  8582. if (CHIP_IS_E3(bp))
  8583. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8584. else {
  8585. switch (switch_cfg) {
  8586. case SWITCH_CFG_1G:
  8587. bp->port.phy_addr = REG_RD(
  8588. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8589. break;
  8590. case SWITCH_CFG_10G:
  8591. bp->port.phy_addr = REG_RD(
  8592. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8593. break;
  8594. default:
  8595. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8596. bp->port.link_config[0]);
  8597. return;
  8598. }
  8599. }
  8600. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8601. /* mask what we support according to speed_cap_mask per configuration */
  8602. for (idx = 0; idx < cfg_size; idx++) {
  8603. if (!(bp->link_params.speed_cap_mask[idx] &
  8604. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8605. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8606. if (!(bp->link_params.speed_cap_mask[idx] &
  8607. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8608. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8609. if (!(bp->link_params.speed_cap_mask[idx] &
  8610. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8611. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8612. if (!(bp->link_params.speed_cap_mask[idx] &
  8613. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8614. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8615. if (!(bp->link_params.speed_cap_mask[idx] &
  8616. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8617. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8618. SUPPORTED_1000baseT_Full);
  8619. if (!(bp->link_params.speed_cap_mask[idx] &
  8620. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8621. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8622. if (!(bp->link_params.speed_cap_mask[idx] &
  8623. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8624. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8625. }
  8626. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8627. bp->port.supported[1]);
  8628. }
  8629. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8630. {
  8631. u32 link_config, idx, cfg_size = 0;
  8632. bp->port.advertising[0] = 0;
  8633. bp->port.advertising[1] = 0;
  8634. switch (bp->link_params.num_phys) {
  8635. case 1:
  8636. case 2:
  8637. cfg_size = 1;
  8638. break;
  8639. case 3:
  8640. cfg_size = 2;
  8641. break;
  8642. }
  8643. for (idx = 0; idx < cfg_size; idx++) {
  8644. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8645. link_config = bp->port.link_config[idx];
  8646. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8647. case PORT_FEATURE_LINK_SPEED_AUTO:
  8648. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8649. bp->link_params.req_line_speed[idx] =
  8650. SPEED_AUTO_NEG;
  8651. bp->port.advertising[idx] |=
  8652. bp->port.supported[idx];
  8653. if (bp->link_params.phy[EXT_PHY1].type ==
  8654. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8655. bp->port.advertising[idx] |=
  8656. (SUPPORTED_100baseT_Half |
  8657. SUPPORTED_100baseT_Full);
  8658. } else {
  8659. /* force 10G, no AN */
  8660. bp->link_params.req_line_speed[idx] =
  8661. SPEED_10000;
  8662. bp->port.advertising[idx] |=
  8663. (ADVERTISED_10000baseT_Full |
  8664. ADVERTISED_FIBRE);
  8665. continue;
  8666. }
  8667. break;
  8668. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8669. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8670. bp->link_params.req_line_speed[idx] =
  8671. SPEED_10;
  8672. bp->port.advertising[idx] |=
  8673. (ADVERTISED_10baseT_Full |
  8674. ADVERTISED_TP);
  8675. } else {
  8676. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8677. link_config,
  8678. bp->link_params.speed_cap_mask[idx]);
  8679. return;
  8680. }
  8681. break;
  8682. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8683. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8684. bp->link_params.req_line_speed[idx] =
  8685. SPEED_10;
  8686. bp->link_params.req_duplex[idx] =
  8687. DUPLEX_HALF;
  8688. bp->port.advertising[idx] |=
  8689. (ADVERTISED_10baseT_Half |
  8690. ADVERTISED_TP);
  8691. } else {
  8692. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8693. link_config,
  8694. bp->link_params.speed_cap_mask[idx]);
  8695. return;
  8696. }
  8697. break;
  8698. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8699. if (bp->port.supported[idx] &
  8700. SUPPORTED_100baseT_Full) {
  8701. bp->link_params.req_line_speed[idx] =
  8702. SPEED_100;
  8703. bp->port.advertising[idx] |=
  8704. (ADVERTISED_100baseT_Full |
  8705. ADVERTISED_TP);
  8706. } else {
  8707. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8708. link_config,
  8709. bp->link_params.speed_cap_mask[idx]);
  8710. return;
  8711. }
  8712. break;
  8713. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8714. if (bp->port.supported[idx] &
  8715. SUPPORTED_100baseT_Half) {
  8716. bp->link_params.req_line_speed[idx] =
  8717. SPEED_100;
  8718. bp->link_params.req_duplex[idx] =
  8719. DUPLEX_HALF;
  8720. bp->port.advertising[idx] |=
  8721. (ADVERTISED_100baseT_Half |
  8722. ADVERTISED_TP);
  8723. } else {
  8724. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8725. link_config,
  8726. bp->link_params.speed_cap_mask[idx]);
  8727. return;
  8728. }
  8729. break;
  8730. case PORT_FEATURE_LINK_SPEED_1G:
  8731. if (bp->port.supported[idx] &
  8732. SUPPORTED_1000baseT_Full) {
  8733. bp->link_params.req_line_speed[idx] =
  8734. SPEED_1000;
  8735. bp->port.advertising[idx] |=
  8736. (ADVERTISED_1000baseT_Full |
  8737. ADVERTISED_TP);
  8738. } else {
  8739. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8740. link_config,
  8741. bp->link_params.speed_cap_mask[idx]);
  8742. return;
  8743. }
  8744. break;
  8745. case PORT_FEATURE_LINK_SPEED_2_5G:
  8746. if (bp->port.supported[idx] &
  8747. SUPPORTED_2500baseX_Full) {
  8748. bp->link_params.req_line_speed[idx] =
  8749. SPEED_2500;
  8750. bp->port.advertising[idx] |=
  8751. (ADVERTISED_2500baseX_Full |
  8752. ADVERTISED_TP);
  8753. } else {
  8754. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8755. link_config,
  8756. bp->link_params.speed_cap_mask[idx]);
  8757. return;
  8758. }
  8759. break;
  8760. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  8761. if (bp->port.supported[idx] &
  8762. SUPPORTED_10000baseT_Full) {
  8763. bp->link_params.req_line_speed[idx] =
  8764. SPEED_10000;
  8765. bp->port.advertising[idx] |=
  8766. (ADVERTISED_10000baseT_Full |
  8767. ADVERTISED_FIBRE);
  8768. } else {
  8769. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8770. link_config,
  8771. bp->link_params.speed_cap_mask[idx]);
  8772. return;
  8773. }
  8774. break;
  8775. case PORT_FEATURE_LINK_SPEED_20G:
  8776. bp->link_params.req_line_speed[idx] = SPEED_20000;
  8777. break;
  8778. default:
  8779. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  8780. link_config);
  8781. bp->link_params.req_line_speed[idx] =
  8782. SPEED_AUTO_NEG;
  8783. bp->port.advertising[idx] =
  8784. bp->port.supported[idx];
  8785. break;
  8786. }
  8787. bp->link_params.req_flow_ctrl[idx] = (link_config &
  8788. PORT_FEATURE_FLOW_CONTROL_MASK);
  8789. if (bp->link_params.req_flow_ctrl[idx] ==
  8790. BNX2X_FLOW_CTRL_AUTO) {
  8791. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  8792. bp->link_params.req_flow_ctrl[idx] =
  8793. BNX2X_FLOW_CTRL_NONE;
  8794. else
  8795. bnx2x_set_requested_fc(bp);
  8796. }
  8797. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  8798. bp->link_params.req_line_speed[idx],
  8799. bp->link_params.req_duplex[idx],
  8800. bp->link_params.req_flow_ctrl[idx],
  8801. bp->port.advertising[idx]);
  8802. }
  8803. }
  8804. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  8805. {
  8806. mac_hi = cpu_to_be16(mac_hi);
  8807. mac_lo = cpu_to_be32(mac_lo);
  8808. memcpy(mac_buf, &mac_hi, sizeof(mac_hi));
  8809. memcpy(mac_buf + sizeof(mac_hi), &mac_lo, sizeof(mac_lo));
  8810. }
  8811. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  8812. {
  8813. int port = BP_PORT(bp);
  8814. u32 config;
  8815. u32 ext_phy_type, ext_phy_config, eee_mode;
  8816. bp->link_params.bp = bp;
  8817. bp->link_params.port = port;
  8818. bp->link_params.lane_config =
  8819. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  8820. bp->link_params.speed_cap_mask[0] =
  8821. SHMEM_RD(bp,
  8822. dev_info.port_hw_config[port].speed_capability_mask);
  8823. bp->link_params.speed_cap_mask[1] =
  8824. SHMEM_RD(bp,
  8825. dev_info.port_hw_config[port].speed_capability_mask2);
  8826. bp->port.link_config[0] =
  8827. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  8828. bp->port.link_config[1] =
  8829. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  8830. bp->link_params.multi_phy_config =
  8831. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  8832. /* If the device is capable of WoL, set the default state according
  8833. * to the HW
  8834. */
  8835. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  8836. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  8837. (config & PORT_FEATURE_WOL_ENABLED));
  8838. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8839. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  8840. bp->flags |= NO_ISCSI_FLAG;
  8841. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  8842. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  8843. bp->flags |= NO_FCOE_FLAG;
  8844. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  8845. bp->link_params.lane_config,
  8846. bp->link_params.speed_cap_mask[0],
  8847. bp->port.link_config[0]);
  8848. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  8849. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  8850. bnx2x_phy_probe(&bp->link_params);
  8851. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  8852. bnx2x_link_settings_requested(bp);
  8853. /*
  8854. * If connected directly, work with the internal PHY, otherwise, work
  8855. * with the external PHY
  8856. */
  8857. ext_phy_config =
  8858. SHMEM_RD(bp,
  8859. dev_info.port_hw_config[port].external_phy_config);
  8860. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  8861. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  8862. bp->mdio.prtad = bp->port.phy_addr;
  8863. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  8864. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  8865. bp->mdio.prtad =
  8866. XGXS_EXT_PHY_ADDR(ext_phy_config);
  8867. /* Configure link feature according to nvram value */
  8868. eee_mode = (((SHMEM_RD(bp, dev_info.
  8869. port_feature_config[port].eee_power_mode)) &
  8870. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  8871. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  8872. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  8873. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  8874. EEE_MODE_ENABLE_LPI |
  8875. EEE_MODE_OUTPUT_TIME;
  8876. } else {
  8877. bp->link_params.eee_mode = 0;
  8878. }
  8879. }
  8880. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  8881. {
  8882. u32 no_flags = NO_ISCSI_FLAG;
  8883. int port = BP_PORT(bp);
  8884. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8885. drv_lic_key[port].max_iscsi_conn);
  8886. if (!CNIC_SUPPORT(bp)) {
  8887. bp->flags |= no_flags;
  8888. return;
  8889. }
  8890. /* Get the number of maximum allowed iSCSI connections */
  8891. bp->cnic_eth_dev.max_iscsi_conn =
  8892. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  8893. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  8894. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  8895. bp->cnic_eth_dev.max_iscsi_conn);
  8896. /*
  8897. * If maximum allowed number of connections is zero -
  8898. * disable the feature.
  8899. */
  8900. if (!bp->cnic_eth_dev.max_iscsi_conn)
  8901. bp->flags |= no_flags;
  8902. }
  8903. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  8904. {
  8905. /* Port info */
  8906. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8907. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  8908. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8909. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  8910. /* Node info */
  8911. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8912. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  8913. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8914. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  8915. }
  8916. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  8917. {
  8918. int port = BP_PORT(bp);
  8919. int func = BP_ABS_FUNC(bp);
  8920. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  8921. drv_lic_key[port].max_fcoe_conn);
  8922. if (!CNIC_SUPPORT(bp)) {
  8923. bp->flags |= NO_FCOE_FLAG;
  8924. return;
  8925. }
  8926. /* Get the number of maximum allowed FCoE connections */
  8927. bp->cnic_eth_dev.max_fcoe_conn =
  8928. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  8929. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  8930. /* Read the WWN: */
  8931. if (!IS_MF(bp)) {
  8932. /* Port info */
  8933. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  8934. SHMEM_RD(bp,
  8935. dev_info.port_hw_config[port].
  8936. fcoe_wwn_port_name_upper);
  8937. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  8938. SHMEM_RD(bp,
  8939. dev_info.port_hw_config[port].
  8940. fcoe_wwn_port_name_lower);
  8941. /* Node info */
  8942. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  8943. SHMEM_RD(bp,
  8944. dev_info.port_hw_config[port].
  8945. fcoe_wwn_node_name_upper);
  8946. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  8947. SHMEM_RD(bp,
  8948. dev_info.port_hw_config[port].
  8949. fcoe_wwn_node_name_lower);
  8950. } else if (!IS_MF_SD(bp)) {
  8951. /*
  8952. * Read the WWN info only if the FCoE feature is enabled for
  8953. * this function.
  8954. */
  8955. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  8956. bnx2x_get_ext_wwn_info(bp, func);
  8957. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  8958. bnx2x_get_ext_wwn_info(bp, func);
  8959. }
  8960. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  8961. /*
  8962. * If maximum allowed number of connections is zero -
  8963. * disable the feature.
  8964. */
  8965. if (!bp->cnic_eth_dev.max_fcoe_conn)
  8966. bp->flags |= NO_FCOE_FLAG;
  8967. }
  8968. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  8969. {
  8970. /*
  8971. * iSCSI may be dynamically disabled but reading
  8972. * info here we will decrease memory usage by driver
  8973. * if the feature is disabled for good
  8974. */
  8975. bnx2x_get_iscsi_info(bp);
  8976. bnx2x_get_fcoe_info(bp);
  8977. }
  8978. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  8979. {
  8980. u32 val, val2;
  8981. int func = BP_ABS_FUNC(bp);
  8982. int port = BP_PORT(bp);
  8983. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  8984. u8 *fip_mac = bp->fip_mac;
  8985. if (IS_MF(bp)) {
  8986. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  8987. * FCoE MAC then the appropriate feature should be disabled.
  8988. * In non SD mode features configuration comes from struct
  8989. * func_ext_config.
  8990. */
  8991. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  8992. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  8993. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  8994. val2 = MF_CFG_RD(bp, func_ext_config[func].
  8995. iscsi_mac_addr_upper);
  8996. val = MF_CFG_RD(bp, func_ext_config[func].
  8997. iscsi_mac_addr_lower);
  8998. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  8999. BNX2X_DEV_INFO
  9000. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9001. } else {
  9002. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9003. }
  9004. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9005. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9006. fcoe_mac_addr_upper);
  9007. val = MF_CFG_RD(bp, func_ext_config[func].
  9008. fcoe_mac_addr_lower);
  9009. bnx2x_set_mac_buf(fip_mac, val, val2);
  9010. BNX2X_DEV_INFO
  9011. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9012. } else {
  9013. bp->flags |= NO_FCOE_FLAG;
  9014. }
  9015. bp->mf_ext_config = cfg;
  9016. } else { /* SD MODE */
  9017. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9018. /* use primary mac as iscsi mac */
  9019. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9020. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9021. BNX2X_DEV_INFO
  9022. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9023. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9024. /* use primary mac as fip mac */
  9025. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9026. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9027. BNX2X_DEV_INFO
  9028. ("Read FIP MAC: %pM\n", fip_mac);
  9029. }
  9030. }
  9031. if (IS_MF_STORAGE_SD(bp))
  9032. /* Zero primary MAC configuration */
  9033. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9034. if (IS_MF_FCOE_AFEX(bp) || IS_MF_FCOE_SD(bp))
  9035. /* use FIP MAC as primary MAC */
  9036. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9037. } else {
  9038. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9039. iscsi_mac_upper);
  9040. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9041. iscsi_mac_lower);
  9042. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9043. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9044. fcoe_fip_mac_upper);
  9045. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9046. fcoe_fip_mac_lower);
  9047. bnx2x_set_mac_buf(fip_mac, val, val2);
  9048. }
  9049. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9050. if (!is_valid_ether_addr(iscsi_mac)) {
  9051. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9052. memset(iscsi_mac, 0, ETH_ALEN);
  9053. }
  9054. /* Disable FCoE if MAC configuration is invalid. */
  9055. if (!is_valid_ether_addr(fip_mac)) {
  9056. bp->flags |= NO_FCOE_FLAG;
  9057. memset(bp->fip_mac, 0, ETH_ALEN);
  9058. }
  9059. }
  9060. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9061. {
  9062. u32 val, val2;
  9063. int func = BP_ABS_FUNC(bp);
  9064. int port = BP_PORT(bp);
  9065. /* Zero primary MAC configuration */
  9066. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9067. if (BP_NOMCP(bp)) {
  9068. BNX2X_ERROR("warning: random MAC workaround active\n");
  9069. eth_hw_addr_random(bp->dev);
  9070. } else if (IS_MF(bp)) {
  9071. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9072. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9073. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9074. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9075. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9076. if (CNIC_SUPPORT(bp))
  9077. bnx2x_get_cnic_mac_hwinfo(bp);
  9078. } else {
  9079. /* in SF read MACs from port configuration */
  9080. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9081. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9082. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9083. if (CNIC_SUPPORT(bp))
  9084. bnx2x_get_cnic_mac_hwinfo(bp);
  9085. }
  9086. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9087. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9088. dev_err(&bp->pdev->dev,
  9089. "bad Ethernet MAC address configuration: %pM\n"
  9090. "change it manually before bringing up the appropriate network interface\n",
  9091. bp->dev->dev_addr);
  9092. }
  9093. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9094. {
  9095. int tmp;
  9096. u32 cfg;
  9097. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9098. /* Take function: tmp = func */
  9099. tmp = BP_ABS_FUNC(bp);
  9100. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9101. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9102. } else {
  9103. /* Take port: tmp = port */
  9104. tmp = BP_PORT(bp);
  9105. cfg = SHMEM_RD(bp,
  9106. dev_info.port_hw_config[tmp].generic_features);
  9107. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9108. }
  9109. return cfg;
  9110. }
  9111. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9112. {
  9113. int /*abs*/func = BP_ABS_FUNC(bp);
  9114. int vn;
  9115. u32 val = 0;
  9116. int rc = 0;
  9117. bnx2x_get_common_hwinfo(bp);
  9118. /*
  9119. * initialize IGU parameters
  9120. */
  9121. if (CHIP_IS_E1x(bp)) {
  9122. bp->common.int_block = INT_BLOCK_HC;
  9123. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9124. bp->igu_base_sb = 0;
  9125. } else {
  9126. bp->common.int_block = INT_BLOCK_IGU;
  9127. /* do not allow device reset during IGU info preocessing */
  9128. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9129. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9130. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9131. int tout = 5000;
  9132. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9133. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9134. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9135. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9136. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9137. tout--;
  9138. usleep_range(1000, 1000);
  9139. }
  9140. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9141. dev_err(&bp->pdev->dev,
  9142. "FORCING Normal Mode failed!!!\n");
  9143. bnx2x_release_hw_lock(bp,
  9144. HW_LOCK_RESOURCE_RESET);
  9145. return -EPERM;
  9146. }
  9147. }
  9148. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9149. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9150. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9151. } else
  9152. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9153. rc = bnx2x_get_igu_cam_info(bp);
  9154. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9155. if (rc)
  9156. return rc;
  9157. }
  9158. /*
  9159. * set base FW non-default (fast path) status block id, this value is
  9160. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9161. * determine the id used by the FW.
  9162. */
  9163. if (CHIP_IS_E1x(bp))
  9164. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9165. else /*
  9166. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9167. * the same queue are indicated on the same IGU SB). So we prefer
  9168. * FW and IGU SBs to be the same value.
  9169. */
  9170. bp->base_fw_ndsb = bp->igu_base_sb;
  9171. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9172. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9173. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9174. /*
  9175. * Initialize MF configuration
  9176. */
  9177. bp->mf_ov = 0;
  9178. bp->mf_mode = 0;
  9179. vn = BP_VN(bp);
  9180. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9181. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9182. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9183. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9184. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9185. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9186. else
  9187. bp->common.mf_cfg_base = bp->common.shmem_base +
  9188. offsetof(struct shmem_region, func_mb) +
  9189. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9190. /*
  9191. * get mf configuration:
  9192. * 1. existence of MF configuration
  9193. * 2. MAC address must be legal (check only upper bytes)
  9194. * for Switch-Independent mode;
  9195. * OVLAN must be legal for Switch-Dependent mode
  9196. * 3. SF_MODE configures specific MF mode
  9197. */
  9198. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9199. /* get mf configuration */
  9200. val = SHMEM_RD(bp,
  9201. dev_info.shared_feature_config.config);
  9202. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9203. switch (val) {
  9204. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9205. val = MF_CFG_RD(bp, func_mf_config[func].
  9206. mac_upper);
  9207. /* check for legal mac (upper bytes)*/
  9208. if (val != 0xffff) {
  9209. bp->mf_mode = MULTI_FUNCTION_SI;
  9210. bp->mf_config[vn] = MF_CFG_RD(bp,
  9211. func_mf_config[func].config);
  9212. } else
  9213. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9214. break;
  9215. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9216. if ((!CHIP_IS_E1x(bp)) &&
  9217. (MF_CFG_RD(bp, func_mf_config[func].
  9218. mac_upper) != 0xffff) &&
  9219. (SHMEM2_HAS(bp,
  9220. afex_driver_support))) {
  9221. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9222. bp->mf_config[vn] = MF_CFG_RD(bp,
  9223. func_mf_config[func].config);
  9224. } else {
  9225. BNX2X_DEV_INFO("can not configure afex mode\n");
  9226. }
  9227. break;
  9228. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9229. /* get OV configuration */
  9230. val = MF_CFG_RD(bp,
  9231. func_mf_config[FUNC_0].e1hov_tag);
  9232. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9233. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9234. bp->mf_mode = MULTI_FUNCTION_SD;
  9235. bp->mf_config[vn] = MF_CFG_RD(bp,
  9236. func_mf_config[func].config);
  9237. } else
  9238. BNX2X_DEV_INFO("illegal OV for SD\n");
  9239. break;
  9240. default:
  9241. /* Unknown configuration: reset mf_config */
  9242. bp->mf_config[vn] = 0;
  9243. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9244. }
  9245. }
  9246. BNX2X_DEV_INFO("%s function mode\n",
  9247. IS_MF(bp) ? "multi" : "single");
  9248. switch (bp->mf_mode) {
  9249. case MULTI_FUNCTION_SD:
  9250. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9251. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9252. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9253. bp->mf_ov = val;
  9254. bp->path_has_ovlan = true;
  9255. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9256. func, bp->mf_ov, bp->mf_ov);
  9257. } else {
  9258. dev_err(&bp->pdev->dev,
  9259. "No valid MF OV for func %d, aborting\n",
  9260. func);
  9261. return -EPERM;
  9262. }
  9263. break;
  9264. case MULTI_FUNCTION_AFEX:
  9265. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9266. break;
  9267. case MULTI_FUNCTION_SI:
  9268. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9269. func);
  9270. break;
  9271. default:
  9272. if (vn) {
  9273. dev_err(&bp->pdev->dev,
  9274. "VN %d is in a single function mode, aborting\n",
  9275. vn);
  9276. return -EPERM;
  9277. }
  9278. break;
  9279. }
  9280. /* check if other port on the path needs ovlan:
  9281. * Since MF configuration is shared between ports
  9282. * Possible mixed modes are only
  9283. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9284. */
  9285. if (CHIP_MODE_IS_4_PORT(bp) &&
  9286. !bp->path_has_ovlan &&
  9287. !IS_MF(bp) &&
  9288. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9289. u8 other_port = !BP_PORT(bp);
  9290. u8 other_func = BP_PATH(bp) + 2*other_port;
  9291. val = MF_CFG_RD(bp,
  9292. func_mf_config[other_func].e1hov_tag);
  9293. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9294. bp->path_has_ovlan = true;
  9295. }
  9296. }
  9297. /* adjust igu_sb_cnt to MF for E1x */
  9298. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9299. bp->igu_sb_cnt /= E1HVN_MAX;
  9300. /* port info */
  9301. bnx2x_get_port_hwinfo(bp);
  9302. /* Get MAC addresses */
  9303. bnx2x_get_mac_hwinfo(bp);
  9304. bnx2x_get_cnic_info(bp);
  9305. return rc;
  9306. }
  9307. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9308. {
  9309. int cnt, i, block_end, rodi;
  9310. char vpd_start[BNX2X_VPD_LEN+1];
  9311. char str_id_reg[VENDOR_ID_LEN+1];
  9312. char str_id_cap[VENDOR_ID_LEN+1];
  9313. char *vpd_data;
  9314. char *vpd_extended_data = NULL;
  9315. u8 len;
  9316. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9317. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9318. if (cnt < BNX2X_VPD_LEN)
  9319. goto out_not_found;
  9320. /* VPD RO tag should be first tag after identifier string, hence
  9321. * we should be able to find it in first BNX2X_VPD_LEN chars
  9322. */
  9323. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9324. PCI_VPD_LRDT_RO_DATA);
  9325. if (i < 0)
  9326. goto out_not_found;
  9327. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9328. pci_vpd_lrdt_size(&vpd_start[i]);
  9329. i += PCI_VPD_LRDT_TAG_SIZE;
  9330. if (block_end > BNX2X_VPD_LEN) {
  9331. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9332. if (vpd_extended_data == NULL)
  9333. goto out_not_found;
  9334. /* read rest of vpd image into vpd_extended_data */
  9335. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9336. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9337. block_end - BNX2X_VPD_LEN,
  9338. vpd_extended_data + BNX2X_VPD_LEN);
  9339. if (cnt < (block_end - BNX2X_VPD_LEN))
  9340. goto out_not_found;
  9341. vpd_data = vpd_extended_data;
  9342. } else
  9343. vpd_data = vpd_start;
  9344. /* now vpd_data holds full vpd content in both cases */
  9345. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9346. PCI_VPD_RO_KEYWORD_MFR_ID);
  9347. if (rodi < 0)
  9348. goto out_not_found;
  9349. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9350. if (len != VENDOR_ID_LEN)
  9351. goto out_not_found;
  9352. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9353. /* vendor specific info */
  9354. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9355. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9356. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9357. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9358. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9359. PCI_VPD_RO_KEYWORD_VENDOR0);
  9360. if (rodi >= 0) {
  9361. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9362. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9363. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9364. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9365. bp->fw_ver[len] = ' ';
  9366. }
  9367. }
  9368. kfree(vpd_extended_data);
  9369. return;
  9370. }
  9371. out_not_found:
  9372. kfree(vpd_extended_data);
  9373. return;
  9374. }
  9375. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9376. {
  9377. u32 flags = 0;
  9378. if (CHIP_REV_IS_FPGA(bp))
  9379. SET_FLAGS(flags, MODE_FPGA);
  9380. else if (CHIP_REV_IS_EMUL(bp))
  9381. SET_FLAGS(flags, MODE_EMUL);
  9382. else
  9383. SET_FLAGS(flags, MODE_ASIC);
  9384. if (CHIP_MODE_IS_4_PORT(bp))
  9385. SET_FLAGS(flags, MODE_PORT4);
  9386. else
  9387. SET_FLAGS(flags, MODE_PORT2);
  9388. if (CHIP_IS_E2(bp))
  9389. SET_FLAGS(flags, MODE_E2);
  9390. else if (CHIP_IS_E3(bp)) {
  9391. SET_FLAGS(flags, MODE_E3);
  9392. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9393. SET_FLAGS(flags, MODE_E3_A0);
  9394. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9395. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9396. }
  9397. if (IS_MF(bp)) {
  9398. SET_FLAGS(flags, MODE_MF);
  9399. switch (bp->mf_mode) {
  9400. case MULTI_FUNCTION_SD:
  9401. SET_FLAGS(flags, MODE_MF_SD);
  9402. break;
  9403. case MULTI_FUNCTION_SI:
  9404. SET_FLAGS(flags, MODE_MF_SI);
  9405. break;
  9406. case MULTI_FUNCTION_AFEX:
  9407. SET_FLAGS(flags, MODE_MF_AFEX);
  9408. break;
  9409. }
  9410. } else
  9411. SET_FLAGS(flags, MODE_SF);
  9412. #if defined(__LITTLE_ENDIAN)
  9413. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9414. #else /*(__BIG_ENDIAN)*/
  9415. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9416. #endif
  9417. INIT_MODE_FLAGS(bp) = flags;
  9418. }
  9419. static int bnx2x_init_bp(struct bnx2x *bp)
  9420. {
  9421. int func;
  9422. int rc;
  9423. mutex_init(&bp->port.phy_mutex);
  9424. mutex_init(&bp->fw_mb_mutex);
  9425. spin_lock_init(&bp->stats_lock);
  9426. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9427. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9428. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9429. if (IS_PF(bp)) {
  9430. rc = bnx2x_get_hwinfo(bp);
  9431. if (rc)
  9432. return rc;
  9433. } else {
  9434. random_ether_addr(bp->dev->dev_addr);
  9435. }
  9436. bnx2x_set_modes_bitmap(bp);
  9437. rc = bnx2x_alloc_mem_bp(bp);
  9438. if (rc)
  9439. return rc;
  9440. bnx2x_read_fwinfo(bp);
  9441. func = BP_FUNC(bp);
  9442. /* need to reset chip if undi was active */
  9443. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9444. /* init fw_seq */
  9445. bp->fw_seq =
  9446. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9447. DRV_MSG_SEQ_NUMBER_MASK;
  9448. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9449. bnx2x_prev_unload(bp);
  9450. }
  9451. if (CHIP_REV_IS_FPGA(bp))
  9452. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9453. if (BP_NOMCP(bp) && (func == 0))
  9454. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9455. bp->disable_tpa = disable_tpa;
  9456. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9457. /* Set TPA flags */
  9458. if (bp->disable_tpa) {
  9459. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9460. bp->dev->features &= ~NETIF_F_LRO;
  9461. } else {
  9462. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9463. bp->dev->features |= NETIF_F_LRO;
  9464. }
  9465. if (CHIP_IS_E1(bp))
  9466. bp->dropless_fc = 0;
  9467. else
  9468. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9469. bp->mrrs = mrrs;
  9470. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9471. if (IS_VF(bp))
  9472. bp->rx_ring_size = MAX_RX_AVAIL;
  9473. /* make sure that the numbers are in the right granularity */
  9474. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9475. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9476. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9477. init_timer(&bp->timer);
  9478. bp->timer.expires = jiffies + bp->current_interval;
  9479. bp->timer.data = (unsigned long) bp;
  9480. bp->timer.function = bnx2x_timer;
  9481. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9482. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9483. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9484. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9485. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9486. bnx2x_dcbx_init_params(bp);
  9487. } else {
  9488. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9489. }
  9490. if (CHIP_IS_E1x(bp))
  9491. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9492. else
  9493. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9494. /* multiple tx priority */
  9495. if (IS_VF(bp))
  9496. bp->max_cos = 1;
  9497. else if (CHIP_IS_E1x(bp))
  9498. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9499. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9500. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9501. else if (CHIP_IS_E3B0(bp))
  9502. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9503. else
  9504. BNX2X_ERR("unknown chip %x revision %x\n",
  9505. CHIP_NUM(bp), CHIP_REV(bp));
  9506. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9507. /* We need at least one default status block for slow-path events,
  9508. * second status block for the L2 queue, and a third status block for
  9509. * CNIC if supproted.
  9510. */
  9511. if (CNIC_SUPPORT(bp))
  9512. bp->min_msix_vec_cnt = 3;
  9513. else
  9514. bp->min_msix_vec_cnt = 2;
  9515. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9516. return rc;
  9517. }
  9518. /****************************************************************************
  9519. * General service functions
  9520. ****************************************************************************/
  9521. /*
  9522. * net_device service functions
  9523. */
  9524. static int bnx2x_open_epilog(struct bnx2x *bp)
  9525. {
  9526. /* Enable sriov via delayed work. This must be done via delayed work
  9527. * because it causes the probe of the vf devices to be run, which invoke
  9528. * register_netdevice which must have rtnl lock taken. As we are holding
  9529. * the lock right now, that could only work if the probe would not take
  9530. * the lock. However, as the probe of the vf may be called from other
  9531. * contexts as well (such as passthrough to vm failes) it can't assume
  9532. * the lock is being held for it. Using delayed work here allows the
  9533. * probe code to simply take the lock (i.e. wait for it to be released
  9534. * if it is being held).
  9535. */
  9536. smp_mb__before_clear_bit();
  9537. set_bit(BNX2X_SP_RTNL_ENABLE_SRIOV, &bp->sp_rtnl_state);
  9538. smp_mb__after_clear_bit();
  9539. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9540. return 0;
  9541. }
  9542. /* called with rtnl_lock */
  9543. static int bnx2x_open(struct net_device *dev)
  9544. {
  9545. struct bnx2x *bp = netdev_priv(dev);
  9546. bool global = false;
  9547. int other_engine = BP_PATH(bp) ? 0 : 1;
  9548. bool other_load_status, load_status;
  9549. int rc;
  9550. bp->stats_init = true;
  9551. netif_carrier_off(dev);
  9552. bnx2x_set_power_state(bp, PCI_D0);
  9553. /* If parity had happen during the unload, then attentions
  9554. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9555. * want the first function loaded on the current engine to
  9556. * complete the recovery.
  9557. * Parity recovery is only relevant for PF driver.
  9558. */
  9559. if (IS_PF(bp)) {
  9560. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9561. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9562. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9563. bnx2x_chk_parity_attn(bp, &global, true)) {
  9564. do {
  9565. /* If there are attentions and they are in a
  9566. * global blocks, set the GLOBAL_RESET bit
  9567. * regardless whether it will be this function
  9568. * that will complete the recovery or not.
  9569. */
  9570. if (global)
  9571. bnx2x_set_reset_global(bp);
  9572. /* Only the first function on the current
  9573. * engine should try to recover in open. In case
  9574. * of attentions in global blocks only the first
  9575. * in the chip should try to recover.
  9576. */
  9577. if ((!load_status &&
  9578. (!global || !other_load_status)) &&
  9579. bnx2x_trylock_leader_lock(bp) &&
  9580. !bnx2x_leader_reset(bp)) {
  9581. netdev_info(bp->dev,
  9582. "Recovered in open\n");
  9583. break;
  9584. }
  9585. /* recovery has failed... */
  9586. bnx2x_set_power_state(bp, PCI_D3hot);
  9587. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9588. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9589. "If you still see this message after a few retries then power cycle is required.\n");
  9590. return -EAGAIN;
  9591. } while (0);
  9592. }
  9593. }
  9594. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9595. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9596. if (rc)
  9597. return rc;
  9598. return bnx2x_open_epilog(bp);
  9599. }
  9600. /* called with rtnl_lock */
  9601. static int bnx2x_close(struct net_device *dev)
  9602. {
  9603. struct bnx2x *bp = netdev_priv(dev);
  9604. /* Unload the driver, release IRQs */
  9605. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9606. /* Power off */
  9607. bnx2x_set_power_state(bp, PCI_D3hot);
  9608. return 0;
  9609. }
  9610. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9611. struct bnx2x_mcast_ramrod_params *p)
  9612. {
  9613. int mc_count = netdev_mc_count(bp->dev);
  9614. struct bnx2x_mcast_list_elem *mc_mac =
  9615. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9616. struct netdev_hw_addr *ha;
  9617. if (!mc_mac)
  9618. return -ENOMEM;
  9619. INIT_LIST_HEAD(&p->mcast_list);
  9620. netdev_for_each_mc_addr(ha, bp->dev) {
  9621. mc_mac->mac = bnx2x_mc_addr(ha);
  9622. list_add_tail(&mc_mac->link, &p->mcast_list);
  9623. mc_mac++;
  9624. }
  9625. p->mcast_list_len = mc_count;
  9626. return 0;
  9627. }
  9628. static void bnx2x_free_mcast_macs_list(
  9629. struct bnx2x_mcast_ramrod_params *p)
  9630. {
  9631. struct bnx2x_mcast_list_elem *mc_mac =
  9632. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9633. link);
  9634. WARN_ON(!mc_mac);
  9635. kfree(mc_mac);
  9636. }
  9637. /**
  9638. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9639. *
  9640. * @bp: driver handle
  9641. *
  9642. * We will use zero (0) as a MAC type for these MACs.
  9643. */
  9644. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9645. {
  9646. int rc;
  9647. struct net_device *dev = bp->dev;
  9648. struct netdev_hw_addr *ha;
  9649. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9650. unsigned long ramrod_flags = 0;
  9651. /* First schedule a cleanup up of old configuration */
  9652. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9653. if (rc < 0) {
  9654. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9655. return rc;
  9656. }
  9657. netdev_for_each_uc_addr(ha, dev) {
  9658. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9659. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9660. if (rc == -EEXIST) {
  9661. DP(BNX2X_MSG_SP,
  9662. "Failed to schedule ADD operations: %d\n", rc);
  9663. /* do not treat adding same MAC as error */
  9664. rc = 0;
  9665. } else if (rc < 0) {
  9666. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9667. rc);
  9668. return rc;
  9669. }
  9670. }
  9671. /* Execute the pending commands */
  9672. __set_bit(RAMROD_CONT, &ramrod_flags);
  9673. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9674. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9675. }
  9676. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9677. {
  9678. struct net_device *dev = bp->dev;
  9679. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9680. int rc = 0;
  9681. rparam.mcast_obj = &bp->mcast_obj;
  9682. /* first, clear all configured multicast MACs */
  9683. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9684. if (rc < 0) {
  9685. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9686. return rc;
  9687. }
  9688. /* then, configure a new MACs list */
  9689. if (netdev_mc_count(dev)) {
  9690. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9691. if (rc) {
  9692. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9693. rc);
  9694. return rc;
  9695. }
  9696. /* Now add the new MACs */
  9697. rc = bnx2x_config_mcast(bp, &rparam,
  9698. BNX2X_MCAST_CMD_ADD);
  9699. if (rc < 0)
  9700. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9701. rc);
  9702. bnx2x_free_mcast_macs_list(&rparam);
  9703. }
  9704. return rc;
  9705. }
  9706. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9707. void bnx2x_set_rx_mode(struct net_device *dev)
  9708. {
  9709. struct bnx2x *bp = netdev_priv(dev);
  9710. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9711. if (bp->state != BNX2X_STATE_OPEN) {
  9712. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9713. return;
  9714. }
  9715. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9716. if (dev->flags & IFF_PROMISC)
  9717. rx_mode = BNX2X_RX_MODE_PROMISC;
  9718. else if ((dev->flags & IFF_ALLMULTI) ||
  9719. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  9720. CHIP_IS_E1(bp)))
  9721. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9722. else {
  9723. if (IS_PF(bp)) {
  9724. /* some multicasts */
  9725. if (bnx2x_set_mc_list(bp) < 0)
  9726. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  9727. if (bnx2x_set_uc_list(bp) < 0)
  9728. rx_mode = BNX2X_RX_MODE_PROMISC;
  9729. } else {
  9730. /* configuring mcast to a vf involves sleeping (when we
  9731. * wait for the pf's response). Since this function is
  9732. * called from non sleepable context we must schedule
  9733. * a work item for this purpose
  9734. */
  9735. smp_mb__before_clear_bit();
  9736. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  9737. &bp->sp_rtnl_state);
  9738. smp_mb__after_clear_bit();
  9739. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9740. }
  9741. }
  9742. bp->rx_mode = rx_mode;
  9743. /* handle ISCSI SD mode */
  9744. if (IS_MF_ISCSI_SD(bp))
  9745. bp->rx_mode = BNX2X_RX_MODE_NONE;
  9746. /* Schedule the rx_mode command */
  9747. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  9748. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  9749. return;
  9750. }
  9751. if (IS_PF(bp)) {
  9752. bnx2x_set_storm_rx_mode(bp);
  9753. } else {
  9754. /* configuring rx mode to storms in a vf involves sleeping (when
  9755. * we wait for the pf's response). Since this function is
  9756. * called from non sleepable context we must schedule
  9757. * a work item for this purpose
  9758. */
  9759. smp_mb__before_clear_bit();
  9760. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  9761. &bp->sp_rtnl_state);
  9762. smp_mb__after_clear_bit();
  9763. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  9764. }
  9765. }
  9766. /* called with rtnl_lock */
  9767. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  9768. int devad, u16 addr)
  9769. {
  9770. struct bnx2x *bp = netdev_priv(netdev);
  9771. u16 value;
  9772. int rc;
  9773. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  9774. prtad, devad, addr);
  9775. /* The HW expects different devad if CL22 is used */
  9776. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9777. bnx2x_acquire_phy_lock(bp);
  9778. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  9779. bnx2x_release_phy_lock(bp);
  9780. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  9781. if (!rc)
  9782. rc = value;
  9783. return rc;
  9784. }
  9785. /* called with rtnl_lock */
  9786. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  9787. u16 addr, u16 value)
  9788. {
  9789. struct bnx2x *bp = netdev_priv(netdev);
  9790. int rc;
  9791. DP(NETIF_MSG_LINK,
  9792. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  9793. prtad, devad, addr, value);
  9794. /* The HW expects different devad if CL22 is used */
  9795. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  9796. bnx2x_acquire_phy_lock(bp);
  9797. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  9798. bnx2x_release_phy_lock(bp);
  9799. return rc;
  9800. }
  9801. /* called with rtnl_lock */
  9802. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  9803. {
  9804. struct bnx2x *bp = netdev_priv(dev);
  9805. struct mii_ioctl_data *mdio = if_mii(ifr);
  9806. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  9807. mdio->phy_id, mdio->reg_num, mdio->val_in);
  9808. if (!netif_running(dev))
  9809. return -EAGAIN;
  9810. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  9811. }
  9812. #ifdef CONFIG_NET_POLL_CONTROLLER
  9813. static void poll_bnx2x(struct net_device *dev)
  9814. {
  9815. struct bnx2x *bp = netdev_priv(dev);
  9816. int i;
  9817. for_each_eth_queue(bp, i) {
  9818. struct bnx2x_fastpath *fp = &bp->fp[i];
  9819. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  9820. }
  9821. }
  9822. #endif
  9823. static int bnx2x_validate_addr(struct net_device *dev)
  9824. {
  9825. struct bnx2x *bp = netdev_priv(dev);
  9826. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  9827. BNX2X_ERR("Non-valid Ethernet address\n");
  9828. return -EADDRNOTAVAIL;
  9829. }
  9830. return 0;
  9831. }
  9832. static const struct net_device_ops bnx2x_netdev_ops = {
  9833. .ndo_open = bnx2x_open,
  9834. .ndo_stop = bnx2x_close,
  9835. .ndo_start_xmit = bnx2x_start_xmit,
  9836. .ndo_select_queue = bnx2x_select_queue,
  9837. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  9838. .ndo_set_mac_address = bnx2x_change_mac_addr,
  9839. .ndo_validate_addr = bnx2x_validate_addr,
  9840. .ndo_do_ioctl = bnx2x_ioctl,
  9841. .ndo_change_mtu = bnx2x_change_mtu,
  9842. .ndo_fix_features = bnx2x_fix_features,
  9843. .ndo_set_features = bnx2x_set_features,
  9844. .ndo_tx_timeout = bnx2x_tx_timeout,
  9845. #ifdef CONFIG_NET_POLL_CONTROLLER
  9846. .ndo_poll_controller = poll_bnx2x,
  9847. #endif
  9848. .ndo_setup_tc = bnx2x_setup_tc,
  9849. #ifdef CONFIG_BNX2X_SRIOV
  9850. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  9851. #endif
  9852. #ifdef NETDEV_FCOE_WWNN
  9853. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  9854. #endif
  9855. };
  9856. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  9857. {
  9858. struct device *dev = &bp->pdev->dev;
  9859. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  9860. bp->flags |= USING_DAC_FLAG;
  9861. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  9862. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  9863. return -EIO;
  9864. }
  9865. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  9866. dev_err(dev, "System does not support DMA, aborting\n");
  9867. return -EIO;
  9868. }
  9869. return 0;
  9870. }
  9871. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  9872. struct net_device *dev, unsigned long board_type)
  9873. {
  9874. int rc;
  9875. u32 pci_cfg_dword;
  9876. bool chip_is_e1x = (board_type == BCM57710 ||
  9877. board_type == BCM57711 ||
  9878. board_type == BCM57711E);
  9879. SET_NETDEV_DEV(dev, &pdev->dev);
  9880. bp->dev = dev;
  9881. bp->pdev = pdev;
  9882. rc = pci_enable_device(pdev);
  9883. if (rc) {
  9884. dev_err(&bp->pdev->dev,
  9885. "Cannot enable PCI device, aborting\n");
  9886. goto err_out;
  9887. }
  9888. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  9889. dev_err(&bp->pdev->dev,
  9890. "Cannot find PCI device base address, aborting\n");
  9891. rc = -ENODEV;
  9892. goto err_out_disable;
  9893. }
  9894. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  9895. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  9896. rc = -ENODEV;
  9897. goto err_out_disable;
  9898. }
  9899. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  9900. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  9901. PCICFG_REVESION_ID_ERROR_VAL) {
  9902. pr_err("PCI device error, probably due to fan failure, aborting\n");
  9903. rc = -ENODEV;
  9904. goto err_out_disable;
  9905. }
  9906. if (atomic_read(&pdev->enable_cnt) == 1) {
  9907. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  9908. if (rc) {
  9909. dev_err(&bp->pdev->dev,
  9910. "Cannot obtain PCI resources, aborting\n");
  9911. goto err_out_disable;
  9912. }
  9913. pci_set_master(pdev);
  9914. pci_save_state(pdev);
  9915. }
  9916. if (IS_PF(bp)) {
  9917. bp->pm_cap = pci_find_capability(pdev, PCI_CAP_ID_PM);
  9918. if (bp->pm_cap == 0) {
  9919. dev_err(&bp->pdev->dev,
  9920. "Cannot find power management capability, aborting\n");
  9921. rc = -EIO;
  9922. goto err_out_release;
  9923. }
  9924. }
  9925. if (!pci_is_pcie(pdev)) {
  9926. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  9927. rc = -EIO;
  9928. goto err_out_release;
  9929. }
  9930. rc = bnx2x_set_coherency_mask(bp);
  9931. if (rc)
  9932. goto err_out_release;
  9933. dev->mem_start = pci_resource_start(pdev, 0);
  9934. dev->base_addr = dev->mem_start;
  9935. dev->mem_end = pci_resource_end(pdev, 0);
  9936. dev->irq = pdev->irq;
  9937. bp->regview = pci_ioremap_bar(pdev, 0);
  9938. if (!bp->regview) {
  9939. dev_err(&bp->pdev->dev,
  9940. "Cannot map register space, aborting\n");
  9941. rc = -ENOMEM;
  9942. goto err_out_release;
  9943. }
  9944. /* In E1/E1H use pci device function given by kernel.
  9945. * In E2/E3 read physical function from ME register since these chips
  9946. * support Physical Device Assignment where kernel BDF maybe arbitrary
  9947. * (depending on hypervisor).
  9948. */
  9949. if (chip_is_e1x)
  9950. bp->pf_num = PCI_FUNC(pdev->devfn);
  9951. else {/* chip is E2/3*/
  9952. pci_read_config_dword(bp->pdev,
  9953. PCICFG_ME_REGISTER, &pci_cfg_dword);
  9954. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  9955. ME_REG_ABS_PF_NUM_SHIFT);
  9956. }
  9957. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  9958. bnx2x_set_power_state(bp, PCI_D0);
  9959. /* clean indirect addresses */
  9960. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  9961. PCICFG_VENDOR_ID_OFFSET);
  9962. /*
  9963. * Clean the following indirect addresses for all functions since it
  9964. * is not used by the driver.
  9965. */
  9966. if (IS_PF(bp)) {
  9967. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  9968. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  9969. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  9970. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  9971. if (chip_is_e1x) {
  9972. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  9973. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  9974. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  9975. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  9976. }
  9977. /* Enable internal target-read (in case we are probed after PF
  9978. * FLR). Must be done prior to any BAR read access. Only for
  9979. * 57712 and up
  9980. */
  9981. if (!chip_is_e1x)
  9982. REG_WR(bp,
  9983. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  9984. }
  9985. dev->watchdog_timeo = TX_TIMEOUT;
  9986. dev->netdev_ops = &bnx2x_netdev_ops;
  9987. bnx2x_set_ethtool_ops(dev);
  9988. dev->priv_flags |= IFF_UNICAST_FLT;
  9989. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9990. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  9991. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  9992. NETIF_F_RXHASH | NETIF_F_HW_VLAN_TX;
  9993. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  9994. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  9995. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_RX;
  9996. if (bp->flags & USING_DAC_FLAG)
  9997. dev->features |= NETIF_F_HIGHDMA;
  9998. /* Add Loopback capability to the device */
  9999. dev->hw_features |= NETIF_F_LOOPBACK;
  10000. #ifdef BCM_DCBNL
  10001. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10002. #endif
  10003. /* get_port_hwinfo() will set prtad and mmds properly */
  10004. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10005. bp->mdio.mmds = 0;
  10006. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10007. bp->mdio.dev = dev;
  10008. bp->mdio.mdio_read = bnx2x_mdio_read;
  10009. bp->mdio.mdio_write = bnx2x_mdio_write;
  10010. return 0;
  10011. err_out_release:
  10012. if (atomic_read(&pdev->enable_cnt) == 1)
  10013. pci_release_regions(pdev);
  10014. err_out_disable:
  10015. pci_disable_device(pdev);
  10016. pci_set_drvdata(pdev, NULL);
  10017. err_out:
  10018. return rc;
  10019. }
  10020. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width, int *speed)
  10021. {
  10022. u32 val = 0;
  10023. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10024. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10025. /* return value of 1=2.5GHz 2=5GHz */
  10026. *speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10027. }
  10028. static int bnx2x_check_firmware(struct bnx2x *bp)
  10029. {
  10030. const struct firmware *firmware = bp->firmware;
  10031. struct bnx2x_fw_file_hdr *fw_hdr;
  10032. struct bnx2x_fw_file_section *sections;
  10033. u32 offset, len, num_ops;
  10034. u16 *ops_offsets;
  10035. int i;
  10036. const u8 *fw_ver;
  10037. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10038. BNX2X_ERR("Wrong FW size\n");
  10039. return -EINVAL;
  10040. }
  10041. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10042. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10043. /* Make sure none of the offsets and sizes make us read beyond
  10044. * the end of the firmware data */
  10045. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10046. offset = be32_to_cpu(sections[i].offset);
  10047. len = be32_to_cpu(sections[i].len);
  10048. if (offset + len > firmware->size) {
  10049. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10050. return -EINVAL;
  10051. }
  10052. }
  10053. /* Likewise for the init_ops offsets */
  10054. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10055. ops_offsets = (u16 *)(firmware->data + offset);
  10056. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10057. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10058. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10059. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10060. return -EINVAL;
  10061. }
  10062. }
  10063. /* Check FW version */
  10064. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10065. fw_ver = firmware->data + offset;
  10066. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10067. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10068. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10069. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10070. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10071. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10072. BCM_5710_FW_MAJOR_VERSION,
  10073. BCM_5710_FW_MINOR_VERSION,
  10074. BCM_5710_FW_REVISION_VERSION,
  10075. BCM_5710_FW_ENGINEERING_VERSION);
  10076. return -EINVAL;
  10077. }
  10078. return 0;
  10079. }
  10080. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10081. {
  10082. const __be32 *source = (const __be32 *)_source;
  10083. u32 *target = (u32 *)_target;
  10084. u32 i;
  10085. for (i = 0; i < n/4; i++)
  10086. target[i] = be32_to_cpu(source[i]);
  10087. }
  10088. /*
  10089. Ops array is stored in the following format:
  10090. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10091. */
  10092. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10093. {
  10094. const __be32 *source = (const __be32 *)_source;
  10095. struct raw_op *target = (struct raw_op *)_target;
  10096. u32 i, j, tmp;
  10097. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10098. tmp = be32_to_cpu(source[j]);
  10099. target[i].op = (tmp >> 24) & 0xff;
  10100. target[i].offset = tmp & 0xffffff;
  10101. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10102. }
  10103. }
  10104. /* IRO array is stored in the following format:
  10105. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10106. */
  10107. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10108. {
  10109. const __be32 *source = (const __be32 *)_source;
  10110. struct iro *target = (struct iro *)_target;
  10111. u32 i, j, tmp;
  10112. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10113. target[i].base = be32_to_cpu(source[j]);
  10114. j++;
  10115. tmp = be32_to_cpu(source[j]);
  10116. target[i].m1 = (tmp >> 16) & 0xffff;
  10117. target[i].m2 = tmp & 0xffff;
  10118. j++;
  10119. tmp = be32_to_cpu(source[j]);
  10120. target[i].m3 = (tmp >> 16) & 0xffff;
  10121. target[i].size = tmp & 0xffff;
  10122. j++;
  10123. }
  10124. }
  10125. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10126. {
  10127. const __be16 *source = (const __be16 *)_source;
  10128. u16 *target = (u16 *)_target;
  10129. u32 i;
  10130. for (i = 0; i < n/2; i++)
  10131. target[i] = be16_to_cpu(source[i]);
  10132. }
  10133. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10134. do { \
  10135. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10136. bp->arr = kmalloc(len, GFP_KERNEL); \
  10137. if (!bp->arr) \
  10138. goto lbl; \
  10139. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10140. (u8 *)bp->arr, len); \
  10141. } while (0)
  10142. static int bnx2x_init_firmware(struct bnx2x *bp)
  10143. {
  10144. const char *fw_file_name;
  10145. struct bnx2x_fw_file_hdr *fw_hdr;
  10146. int rc;
  10147. if (bp->firmware)
  10148. return 0;
  10149. if (CHIP_IS_E1(bp))
  10150. fw_file_name = FW_FILE_NAME_E1;
  10151. else if (CHIP_IS_E1H(bp))
  10152. fw_file_name = FW_FILE_NAME_E1H;
  10153. else if (!CHIP_IS_E1x(bp))
  10154. fw_file_name = FW_FILE_NAME_E2;
  10155. else {
  10156. BNX2X_ERR("Unsupported chip revision\n");
  10157. return -EINVAL;
  10158. }
  10159. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10160. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10161. if (rc) {
  10162. BNX2X_ERR("Can't load firmware file %s\n",
  10163. fw_file_name);
  10164. goto request_firmware_exit;
  10165. }
  10166. rc = bnx2x_check_firmware(bp);
  10167. if (rc) {
  10168. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10169. goto request_firmware_exit;
  10170. }
  10171. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10172. /* Initialize the pointers to the init arrays */
  10173. /* Blob */
  10174. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10175. /* Opcodes */
  10176. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10177. /* Offsets */
  10178. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10179. be16_to_cpu_n);
  10180. /* STORMs firmware */
  10181. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10182. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10183. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10184. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10185. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10186. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10187. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10188. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10189. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10190. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10191. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10192. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10193. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10194. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10195. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10196. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10197. /* IRO */
  10198. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10199. return 0;
  10200. iro_alloc_err:
  10201. kfree(bp->init_ops_offsets);
  10202. init_offsets_alloc_err:
  10203. kfree(bp->init_ops);
  10204. init_ops_alloc_err:
  10205. kfree(bp->init_data);
  10206. request_firmware_exit:
  10207. release_firmware(bp->firmware);
  10208. bp->firmware = NULL;
  10209. return rc;
  10210. }
  10211. static void bnx2x_release_firmware(struct bnx2x *bp)
  10212. {
  10213. kfree(bp->init_ops_offsets);
  10214. kfree(bp->init_ops);
  10215. kfree(bp->init_data);
  10216. release_firmware(bp->firmware);
  10217. bp->firmware = NULL;
  10218. }
  10219. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10220. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10221. .init_hw_cmn = bnx2x_init_hw_common,
  10222. .init_hw_port = bnx2x_init_hw_port,
  10223. .init_hw_func = bnx2x_init_hw_func,
  10224. .reset_hw_cmn = bnx2x_reset_common,
  10225. .reset_hw_port = bnx2x_reset_port,
  10226. .reset_hw_func = bnx2x_reset_func,
  10227. .gunzip_init = bnx2x_gunzip_init,
  10228. .gunzip_end = bnx2x_gunzip_end,
  10229. .init_fw = bnx2x_init_firmware,
  10230. .release_fw = bnx2x_release_firmware,
  10231. };
  10232. void bnx2x__init_func_obj(struct bnx2x *bp)
  10233. {
  10234. /* Prepare DMAE related driver resources */
  10235. bnx2x_setup_dmae(bp);
  10236. bnx2x_init_func_obj(bp, &bp->func_obj,
  10237. bnx2x_sp(bp, func_rdata),
  10238. bnx2x_sp_mapping(bp, func_rdata),
  10239. bnx2x_sp(bp, func_afex_rdata),
  10240. bnx2x_sp_mapping(bp, func_afex_rdata),
  10241. &bnx2x_func_sp_drv);
  10242. }
  10243. /* must be called after sriov-enable */
  10244. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10245. {
  10246. int cid_count = BNX2X_L2_MAX_CID(bp);
  10247. if (IS_SRIOV(bp))
  10248. cid_count += BNX2X_VF_CIDS;
  10249. if (CNIC_SUPPORT(bp))
  10250. cid_count += CNIC_CID_MAX;
  10251. return roundup(cid_count, QM_CID_ROUND);
  10252. }
  10253. /**
  10254. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10255. *
  10256. * @dev: pci device
  10257. *
  10258. */
  10259. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10260. int cnic_cnt, bool is_vf)
  10261. {
  10262. int pos, index;
  10263. u16 control = 0;
  10264. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10265. /*
  10266. * If MSI-X is not supported - return number of SBs needed to support
  10267. * one fast path queue: one FP queue + SB for CNIC
  10268. */
  10269. if (!pos) {
  10270. dev_info(&pdev->dev, "no msix capability found\n");
  10271. return 1 + cnic_cnt;
  10272. }
  10273. dev_info(&pdev->dev, "msix capability found\n");
  10274. /*
  10275. * The value in the PCI configuration space is the index of the last
  10276. * entry, namely one less than the actual size of the table, which is
  10277. * exactly what we want to return from this function: number of all SBs
  10278. * without the default SB.
  10279. * For VFs there is no default SB, then we return (index+1).
  10280. */
  10281. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10282. index = control & PCI_MSIX_FLAGS_QSIZE;
  10283. return is_vf ? index + 1 : index;
  10284. }
  10285. static int set_max_cos_est(int chip_id)
  10286. {
  10287. switch (chip_id) {
  10288. case BCM57710:
  10289. case BCM57711:
  10290. case BCM57711E:
  10291. return BNX2X_MULTI_TX_COS_E1X;
  10292. case BCM57712:
  10293. case BCM57712_MF:
  10294. case BCM57712_VF:
  10295. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10296. case BCM57800:
  10297. case BCM57800_MF:
  10298. case BCM57800_VF:
  10299. case BCM57810:
  10300. case BCM57810_MF:
  10301. case BCM57840_4_10:
  10302. case BCM57840_2_20:
  10303. case BCM57840_O:
  10304. case BCM57840_MFO:
  10305. case BCM57810_VF:
  10306. case BCM57840_MF:
  10307. case BCM57840_VF:
  10308. case BCM57811:
  10309. case BCM57811_MF:
  10310. case BCM57811_VF:
  10311. return BNX2X_MULTI_TX_COS_E3B0;
  10312. return 1;
  10313. default:
  10314. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10315. return -ENODEV;
  10316. }
  10317. }
  10318. static int set_is_vf(int chip_id)
  10319. {
  10320. switch (chip_id) {
  10321. case BCM57712_VF:
  10322. case BCM57800_VF:
  10323. case BCM57810_VF:
  10324. case BCM57840_VF:
  10325. case BCM57811_VF:
  10326. return true;
  10327. default:
  10328. return false;
  10329. }
  10330. }
  10331. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10332. static int bnx2x_init_one(struct pci_dev *pdev,
  10333. const struct pci_device_id *ent)
  10334. {
  10335. struct net_device *dev = NULL;
  10336. struct bnx2x *bp;
  10337. int pcie_width, pcie_speed;
  10338. int rc, max_non_def_sbs;
  10339. int rx_count, tx_count, rss_count, doorbell_size;
  10340. int max_cos_est;
  10341. bool is_vf;
  10342. int cnic_cnt;
  10343. /* An estimated maximum supported CoS number according to the chip
  10344. * version.
  10345. * We will try to roughly estimate the maximum number of CoSes this chip
  10346. * may support in order to minimize the memory allocated for Tx
  10347. * netdev_queue's. This number will be accurately calculated during the
  10348. * initialization of bp->max_cos based on the chip versions AND chip
  10349. * revision in the bnx2x_init_bp().
  10350. */
  10351. max_cos_est = set_max_cos_est(ent->driver_data);
  10352. if (max_cos_est < 0)
  10353. return max_cos_est;
  10354. is_vf = set_is_vf(ent->driver_data);
  10355. cnic_cnt = is_vf ? 0 : 1;
  10356. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10357. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10358. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10359. if (rss_count < 1)
  10360. return -EINVAL;
  10361. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10362. rx_count = rss_count + cnic_cnt;
  10363. /* Maximum number of netdev Tx queues:
  10364. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10365. */
  10366. tx_count = rss_count * max_cos_est + cnic_cnt;
  10367. /* dev zeroed in init_etherdev */
  10368. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10369. if (!dev)
  10370. return -ENOMEM;
  10371. bp = netdev_priv(dev);
  10372. bp->flags = 0;
  10373. if (is_vf)
  10374. bp->flags |= IS_VF_FLAG;
  10375. bp->igu_sb_cnt = max_non_def_sbs;
  10376. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10377. bp->msg_enable = debug;
  10378. bp->cnic_support = cnic_cnt;
  10379. bp->cnic_probe = bnx2x_cnic_probe;
  10380. pci_set_drvdata(pdev, dev);
  10381. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10382. if (rc < 0) {
  10383. free_netdev(dev);
  10384. return rc;
  10385. }
  10386. BNX2X_DEV_INFO("This is a %s function\n",
  10387. IS_PF(bp) ? "physical" : "virtual");
  10388. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10389. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10390. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10391. tx_count, rx_count);
  10392. rc = bnx2x_init_bp(bp);
  10393. if (rc)
  10394. goto init_one_exit;
  10395. /* Map doorbells here as we need the real value of bp->max_cos which
  10396. * is initialized in bnx2x_init_bp() to determine the number of
  10397. * l2 connections.
  10398. */
  10399. if (IS_VF(bp)) {
  10400. bnx2x_vf_map_doorbells(bp);
  10401. rc = bnx2x_vf_pci_alloc(bp);
  10402. if (rc)
  10403. goto init_one_exit;
  10404. } else {
  10405. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10406. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10407. dev_err(&bp->pdev->dev,
  10408. "Cannot map doorbells, bar size too small, aborting\n");
  10409. rc = -ENOMEM;
  10410. goto init_one_exit;
  10411. }
  10412. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10413. doorbell_size);
  10414. }
  10415. if (!bp->doorbells) {
  10416. dev_err(&bp->pdev->dev,
  10417. "Cannot map doorbell space, aborting\n");
  10418. rc = -ENOMEM;
  10419. goto init_one_exit;
  10420. }
  10421. if (IS_VF(bp)) {
  10422. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10423. if (rc)
  10424. goto init_one_exit;
  10425. }
  10426. /* Enable SRIOV if capability found in configuration space.
  10427. * Once the generic SR-IOV framework makes it in from the
  10428. * pci tree this will be revised, to allow dynamic control
  10429. * over the number of VFs. Right now, change the num of vfs
  10430. * param below to enable SR-IOV.
  10431. */
  10432. rc = bnx2x_iov_init_one(bp, int_mode, 0/*num vfs*/);
  10433. if (rc)
  10434. goto init_one_exit;
  10435. /* calc qm_cid_count */
  10436. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10437. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10438. /* disable FCOE L2 queue for E1x*/
  10439. if (CHIP_IS_E1x(bp))
  10440. bp->flags |= NO_FCOE_FLAG;
  10441. /* disable FCOE for 57840 device, until FW supports it */
  10442. switch (ent->driver_data) {
  10443. case BCM57840_O:
  10444. case BCM57840_4_10:
  10445. case BCM57840_2_20:
  10446. case BCM57840_MFO:
  10447. case BCM57840_MF:
  10448. bp->flags |= NO_FCOE_FLAG;
  10449. }
  10450. /* Set bp->num_queues for MSI-X mode*/
  10451. bnx2x_set_num_queues(bp);
  10452. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10453. * needed.
  10454. */
  10455. rc = bnx2x_set_int_mode(bp);
  10456. if (rc) {
  10457. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10458. goto init_one_exit;
  10459. }
  10460. /* register the net device */
  10461. rc = register_netdev(dev);
  10462. if (rc) {
  10463. dev_err(&pdev->dev, "Cannot register net device\n");
  10464. goto init_one_exit;
  10465. }
  10466. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10467. if (!NO_FCOE(bp)) {
  10468. /* Add storage MAC address */
  10469. rtnl_lock();
  10470. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10471. rtnl_unlock();
  10472. }
  10473. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10474. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10475. pcie_width, pcie_speed);
  10476. BNX2X_DEV_INFO(
  10477. "%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10478. board_info[ent->driver_data].name,
  10479. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10480. pcie_width,
  10481. ((!CHIP_IS_E2(bp) && pcie_speed == 2) ||
  10482. (CHIP_IS_E2(bp) && pcie_speed == 1)) ?
  10483. "5GHz (Gen2)" : "2.5GHz",
  10484. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10485. return 0;
  10486. init_one_exit:
  10487. if (bp->regview)
  10488. iounmap(bp->regview);
  10489. if (IS_PF(bp) && bp->doorbells)
  10490. iounmap(bp->doorbells);
  10491. free_netdev(dev);
  10492. if (atomic_read(&pdev->enable_cnt) == 1)
  10493. pci_release_regions(pdev);
  10494. pci_disable_device(pdev);
  10495. pci_set_drvdata(pdev, NULL);
  10496. return rc;
  10497. }
  10498. static void bnx2x_remove_one(struct pci_dev *pdev)
  10499. {
  10500. struct net_device *dev = pci_get_drvdata(pdev);
  10501. struct bnx2x *bp;
  10502. if (!dev) {
  10503. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10504. return;
  10505. }
  10506. bp = netdev_priv(dev);
  10507. /* Delete storage MAC address */
  10508. if (!NO_FCOE(bp)) {
  10509. rtnl_lock();
  10510. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10511. rtnl_unlock();
  10512. }
  10513. #ifdef BCM_DCBNL
  10514. /* Delete app tlvs from dcbnl */
  10515. bnx2x_dcbnl_update_applist(bp, true);
  10516. #endif
  10517. unregister_netdev(dev);
  10518. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10519. if (IS_PF(bp))
  10520. bnx2x_set_power_state(bp, PCI_D0);
  10521. /* Disable MSI/MSI-X */
  10522. bnx2x_disable_msi(bp);
  10523. /* Power off */
  10524. if (IS_PF(bp))
  10525. bnx2x_set_power_state(bp, PCI_D3hot);
  10526. /* Make sure RESET task is not scheduled before continuing */
  10527. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10528. bnx2x_iov_remove_one(bp);
  10529. /* send message via vfpf channel to release the resources of this vf */
  10530. if (IS_VF(bp))
  10531. bnx2x_vfpf_release(bp);
  10532. if (bp->regview)
  10533. iounmap(bp->regview);
  10534. /* for vf doorbells are part of the regview and were unmapped along with
  10535. * it. FW is only loaded by PF.
  10536. */
  10537. if (IS_PF(bp)) {
  10538. if (bp->doorbells)
  10539. iounmap(bp->doorbells);
  10540. bnx2x_release_firmware(bp);
  10541. }
  10542. bnx2x_free_mem_bp(bp);
  10543. free_netdev(dev);
  10544. if (atomic_read(&pdev->enable_cnt) == 1)
  10545. pci_release_regions(pdev);
  10546. pci_disable_device(pdev);
  10547. pci_set_drvdata(pdev, NULL);
  10548. }
  10549. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10550. {
  10551. int i;
  10552. bp->state = BNX2X_STATE_ERROR;
  10553. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10554. if (CNIC_LOADED(bp))
  10555. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10556. /* Stop Tx */
  10557. bnx2x_tx_disable(bp);
  10558. bnx2x_netif_stop(bp, 0);
  10559. /* Delete all NAPI objects */
  10560. bnx2x_del_all_napi(bp);
  10561. if (CNIC_LOADED(bp))
  10562. bnx2x_del_all_napi_cnic(bp);
  10563. del_timer_sync(&bp->timer);
  10564. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  10565. /* Release IRQs */
  10566. bnx2x_free_irq(bp);
  10567. /* Free SKBs, SGEs, TPA pool and driver internals */
  10568. bnx2x_free_skbs(bp);
  10569. for_each_rx_queue(bp, i)
  10570. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10571. bnx2x_free_mem(bp);
  10572. bp->state = BNX2X_STATE_CLOSED;
  10573. netif_carrier_off(bp->dev);
  10574. return 0;
  10575. }
  10576. static void bnx2x_eeh_recover(struct bnx2x *bp)
  10577. {
  10578. u32 val;
  10579. mutex_init(&bp->port.phy_mutex);
  10580. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  10581. if ((val & (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10582. != (SHR_MEM_VALIDITY_DEV_INFO | SHR_MEM_VALIDITY_MB))
  10583. BNX2X_ERR("BAD MCP validity signature\n");
  10584. }
  10585. /**
  10586. * bnx2x_io_error_detected - called when PCI error is detected
  10587. * @pdev: Pointer to PCI device
  10588. * @state: The current pci connection state
  10589. *
  10590. * This function is called after a PCI bus error affecting
  10591. * this device has been detected.
  10592. */
  10593. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10594. pci_channel_state_t state)
  10595. {
  10596. struct net_device *dev = pci_get_drvdata(pdev);
  10597. struct bnx2x *bp = netdev_priv(dev);
  10598. rtnl_lock();
  10599. netif_device_detach(dev);
  10600. if (state == pci_channel_io_perm_failure) {
  10601. rtnl_unlock();
  10602. return PCI_ERS_RESULT_DISCONNECT;
  10603. }
  10604. if (netif_running(dev))
  10605. bnx2x_eeh_nic_unload(bp);
  10606. pci_disable_device(pdev);
  10607. rtnl_unlock();
  10608. /* Request a slot reset */
  10609. return PCI_ERS_RESULT_NEED_RESET;
  10610. }
  10611. /**
  10612. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10613. * @pdev: Pointer to PCI device
  10614. *
  10615. * Restart the card from scratch, as if from a cold-boot.
  10616. */
  10617. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10618. {
  10619. struct net_device *dev = pci_get_drvdata(pdev);
  10620. struct bnx2x *bp = netdev_priv(dev);
  10621. rtnl_lock();
  10622. if (pci_enable_device(pdev)) {
  10623. dev_err(&pdev->dev,
  10624. "Cannot re-enable PCI device after reset\n");
  10625. rtnl_unlock();
  10626. return PCI_ERS_RESULT_DISCONNECT;
  10627. }
  10628. pci_set_master(pdev);
  10629. pci_restore_state(pdev);
  10630. if (netif_running(dev))
  10631. bnx2x_set_power_state(bp, PCI_D0);
  10632. rtnl_unlock();
  10633. return PCI_ERS_RESULT_RECOVERED;
  10634. }
  10635. /**
  10636. * bnx2x_io_resume - called when traffic can start flowing again
  10637. * @pdev: Pointer to PCI device
  10638. *
  10639. * This callback is called when the error recovery driver tells us that
  10640. * its OK to resume normal operation.
  10641. */
  10642. static void bnx2x_io_resume(struct pci_dev *pdev)
  10643. {
  10644. struct net_device *dev = pci_get_drvdata(pdev);
  10645. struct bnx2x *bp = netdev_priv(dev);
  10646. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10647. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10648. return;
  10649. }
  10650. rtnl_lock();
  10651. bnx2x_eeh_recover(bp);
  10652. if (netif_running(dev))
  10653. bnx2x_nic_load(bp, LOAD_NORMAL);
  10654. netif_device_attach(dev);
  10655. rtnl_unlock();
  10656. }
  10657. static const struct pci_error_handlers bnx2x_err_handler = {
  10658. .error_detected = bnx2x_io_error_detected,
  10659. .slot_reset = bnx2x_io_slot_reset,
  10660. .resume = bnx2x_io_resume,
  10661. };
  10662. static struct pci_driver bnx2x_pci_driver = {
  10663. .name = DRV_MODULE_NAME,
  10664. .id_table = bnx2x_pci_tbl,
  10665. .probe = bnx2x_init_one,
  10666. .remove = bnx2x_remove_one,
  10667. .suspend = bnx2x_suspend,
  10668. .resume = bnx2x_resume,
  10669. .err_handler = &bnx2x_err_handler,
  10670. };
  10671. static int __init bnx2x_init(void)
  10672. {
  10673. int ret;
  10674. pr_info("%s", version);
  10675. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  10676. if (bnx2x_wq == NULL) {
  10677. pr_err("Cannot create workqueue\n");
  10678. return -ENOMEM;
  10679. }
  10680. ret = pci_register_driver(&bnx2x_pci_driver);
  10681. if (ret) {
  10682. pr_err("Cannot register driver\n");
  10683. destroy_workqueue(bnx2x_wq);
  10684. }
  10685. return ret;
  10686. }
  10687. static void __exit bnx2x_cleanup(void)
  10688. {
  10689. struct list_head *pos, *q;
  10690. pci_unregister_driver(&bnx2x_pci_driver);
  10691. destroy_workqueue(bnx2x_wq);
  10692. /* Free globablly allocated resources */
  10693. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  10694. struct bnx2x_prev_path_list *tmp =
  10695. list_entry(pos, struct bnx2x_prev_path_list, list);
  10696. list_del(pos);
  10697. kfree(tmp);
  10698. }
  10699. }
  10700. void bnx2x_notify_link_changed(struct bnx2x *bp)
  10701. {
  10702. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  10703. }
  10704. module_init(bnx2x_init);
  10705. module_exit(bnx2x_cleanup);
  10706. /**
  10707. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  10708. *
  10709. * @bp: driver handle
  10710. * @set: set or clear the CAM entry
  10711. *
  10712. * This function will wait until the ramdord completion returns.
  10713. * Return 0 if success, -ENODEV if ramrod doesn't return.
  10714. */
  10715. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  10716. {
  10717. unsigned long ramrod_flags = 0;
  10718. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  10719. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  10720. &bp->iscsi_l2_mac_obj, true,
  10721. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  10722. }
  10723. /* count denotes the number of new completions we have seen */
  10724. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  10725. {
  10726. struct eth_spe *spe;
  10727. int cxt_index, cxt_offset;
  10728. #ifdef BNX2X_STOP_ON_ERROR
  10729. if (unlikely(bp->panic))
  10730. return;
  10731. #endif
  10732. spin_lock_bh(&bp->spq_lock);
  10733. BUG_ON(bp->cnic_spq_pending < count);
  10734. bp->cnic_spq_pending -= count;
  10735. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  10736. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  10737. & SPE_HDR_CONN_TYPE) >>
  10738. SPE_HDR_CONN_TYPE_SHIFT;
  10739. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  10740. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  10741. /* Set validation for iSCSI L2 client before sending SETUP
  10742. * ramrod
  10743. */
  10744. if (type == ETH_CONNECTION_TYPE) {
  10745. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  10746. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  10747. ILT_PAGE_CIDS;
  10748. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  10749. (cxt_index * ILT_PAGE_CIDS);
  10750. bnx2x_set_ctx_validation(bp,
  10751. &bp->context[cxt_index].
  10752. vcxt[cxt_offset].eth,
  10753. BNX2X_ISCSI_ETH_CID(bp));
  10754. }
  10755. }
  10756. /*
  10757. * There may be not more than 8 L2, not more than 8 L5 SPEs
  10758. * and in the air. We also check that number of outstanding
  10759. * COMMON ramrods is not more than the EQ and SPQ can
  10760. * accommodate.
  10761. */
  10762. if (type == ETH_CONNECTION_TYPE) {
  10763. if (!atomic_read(&bp->cq_spq_left))
  10764. break;
  10765. else
  10766. atomic_dec(&bp->cq_spq_left);
  10767. } else if (type == NONE_CONNECTION_TYPE) {
  10768. if (!atomic_read(&bp->eq_spq_left))
  10769. break;
  10770. else
  10771. atomic_dec(&bp->eq_spq_left);
  10772. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  10773. (type == FCOE_CONNECTION_TYPE)) {
  10774. if (bp->cnic_spq_pending >=
  10775. bp->cnic_eth_dev.max_kwqe_pending)
  10776. break;
  10777. else
  10778. bp->cnic_spq_pending++;
  10779. } else {
  10780. BNX2X_ERR("Unknown SPE type: %d\n", type);
  10781. bnx2x_panic();
  10782. break;
  10783. }
  10784. spe = bnx2x_sp_get_next(bp);
  10785. *spe = *bp->cnic_kwq_cons;
  10786. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  10787. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  10788. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  10789. bp->cnic_kwq_cons = bp->cnic_kwq;
  10790. else
  10791. bp->cnic_kwq_cons++;
  10792. }
  10793. bnx2x_sp_prod_update(bp);
  10794. spin_unlock_bh(&bp->spq_lock);
  10795. }
  10796. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  10797. struct kwqe_16 *kwqes[], u32 count)
  10798. {
  10799. struct bnx2x *bp = netdev_priv(dev);
  10800. int i;
  10801. #ifdef BNX2X_STOP_ON_ERROR
  10802. if (unlikely(bp->panic)) {
  10803. BNX2X_ERR("Can't post to SP queue while panic\n");
  10804. return -EIO;
  10805. }
  10806. #endif
  10807. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  10808. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  10809. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  10810. return -EAGAIN;
  10811. }
  10812. spin_lock_bh(&bp->spq_lock);
  10813. for (i = 0; i < count; i++) {
  10814. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  10815. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  10816. break;
  10817. *bp->cnic_kwq_prod = *spe;
  10818. bp->cnic_kwq_pending++;
  10819. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  10820. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  10821. spe->data.update_data_addr.hi,
  10822. spe->data.update_data_addr.lo,
  10823. bp->cnic_kwq_pending);
  10824. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  10825. bp->cnic_kwq_prod = bp->cnic_kwq;
  10826. else
  10827. bp->cnic_kwq_prod++;
  10828. }
  10829. spin_unlock_bh(&bp->spq_lock);
  10830. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  10831. bnx2x_cnic_sp_post(bp, 0);
  10832. return i;
  10833. }
  10834. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10835. {
  10836. struct cnic_ops *c_ops;
  10837. int rc = 0;
  10838. mutex_lock(&bp->cnic_mutex);
  10839. c_ops = rcu_dereference_protected(bp->cnic_ops,
  10840. lockdep_is_held(&bp->cnic_mutex));
  10841. if (c_ops)
  10842. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10843. mutex_unlock(&bp->cnic_mutex);
  10844. return rc;
  10845. }
  10846. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  10847. {
  10848. struct cnic_ops *c_ops;
  10849. int rc = 0;
  10850. rcu_read_lock();
  10851. c_ops = rcu_dereference(bp->cnic_ops);
  10852. if (c_ops)
  10853. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  10854. rcu_read_unlock();
  10855. return rc;
  10856. }
  10857. /*
  10858. * for commands that have no data
  10859. */
  10860. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  10861. {
  10862. struct cnic_ctl_info ctl = {0};
  10863. ctl.cmd = cmd;
  10864. return bnx2x_cnic_ctl_send(bp, &ctl);
  10865. }
  10866. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  10867. {
  10868. struct cnic_ctl_info ctl = {0};
  10869. /* first we tell CNIC and only then we count this as a completion */
  10870. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  10871. ctl.data.comp.cid = cid;
  10872. ctl.data.comp.error = err;
  10873. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  10874. bnx2x_cnic_sp_post(bp, 0);
  10875. }
  10876. /* Called with netif_addr_lock_bh() taken.
  10877. * Sets an rx_mode config for an iSCSI ETH client.
  10878. * Doesn't block.
  10879. * Completion should be checked outside.
  10880. */
  10881. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  10882. {
  10883. unsigned long accept_flags = 0, ramrod_flags = 0;
  10884. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  10885. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  10886. if (start) {
  10887. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  10888. * because it's the only way for UIO Queue to accept
  10889. * multicasts (in non-promiscuous mode only one Queue per
  10890. * function will receive multicast packets (leading in our
  10891. * case).
  10892. */
  10893. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  10894. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  10895. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  10896. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  10897. /* Clear STOP_PENDING bit if START is requested */
  10898. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  10899. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  10900. } else
  10901. /* Clear START_PENDING bit if STOP is requested */
  10902. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  10903. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  10904. set_bit(sched_state, &bp->sp_state);
  10905. else {
  10906. __set_bit(RAMROD_RX, &ramrod_flags);
  10907. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  10908. ramrod_flags);
  10909. }
  10910. }
  10911. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  10912. {
  10913. struct bnx2x *bp = netdev_priv(dev);
  10914. int rc = 0;
  10915. switch (ctl->cmd) {
  10916. case DRV_CTL_CTXTBL_WR_CMD: {
  10917. u32 index = ctl->data.io.offset;
  10918. dma_addr_t addr = ctl->data.io.dma_addr;
  10919. bnx2x_ilt_wr(bp, index, addr);
  10920. break;
  10921. }
  10922. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  10923. int count = ctl->data.credit.credit_count;
  10924. bnx2x_cnic_sp_post(bp, count);
  10925. break;
  10926. }
  10927. /* rtnl_lock is held. */
  10928. case DRV_CTL_START_L2_CMD: {
  10929. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  10930. unsigned long sp_bits = 0;
  10931. /* Configure the iSCSI classification object */
  10932. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  10933. cp->iscsi_l2_client_id,
  10934. cp->iscsi_l2_cid, BP_FUNC(bp),
  10935. bnx2x_sp(bp, mac_rdata),
  10936. bnx2x_sp_mapping(bp, mac_rdata),
  10937. BNX2X_FILTER_MAC_PENDING,
  10938. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  10939. &bp->macs_pool);
  10940. /* Set iSCSI MAC address */
  10941. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  10942. if (rc)
  10943. break;
  10944. mmiowb();
  10945. barrier();
  10946. /* Start accepting on iSCSI L2 ring */
  10947. netif_addr_lock_bh(dev);
  10948. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  10949. netif_addr_unlock_bh(dev);
  10950. /* bits to wait on */
  10951. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10952. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  10953. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10954. BNX2X_ERR("rx_mode completion timed out!\n");
  10955. break;
  10956. }
  10957. /* rtnl_lock is held. */
  10958. case DRV_CTL_STOP_L2_CMD: {
  10959. unsigned long sp_bits = 0;
  10960. /* Stop accepting on iSCSI L2 ring */
  10961. netif_addr_lock_bh(dev);
  10962. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  10963. netif_addr_unlock_bh(dev);
  10964. /* bits to wait on */
  10965. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  10966. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  10967. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  10968. BNX2X_ERR("rx_mode completion timed out!\n");
  10969. mmiowb();
  10970. barrier();
  10971. /* Unset iSCSI L2 MAC */
  10972. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  10973. BNX2X_ISCSI_ETH_MAC, true);
  10974. break;
  10975. }
  10976. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  10977. int count = ctl->data.credit.credit_count;
  10978. smp_mb__before_atomic_inc();
  10979. atomic_add(count, &bp->cq_spq_left);
  10980. smp_mb__after_atomic_inc();
  10981. break;
  10982. }
  10983. case DRV_CTL_ULP_REGISTER_CMD: {
  10984. int ulp_type = ctl->data.register_data.ulp_type;
  10985. if (CHIP_IS_E3(bp)) {
  10986. int idx = BP_FW_MB_IDX(bp);
  10987. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  10988. int path = BP_PATH(bp);
  10989. int port = BP_PORT(bp);
  10990. int i;
  10991. u32 scratch_offset;
  10992. u32 *host_addr;
  10993. /* first write capability to shmem2 */
  10994. if (ulp_type == CNIC_ULP_ISCSI)
  10995. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  10996. else if (ulp_type == CNIC_ULP_FCOE)
  10997. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  10998. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  10999. if ((ulp_type != CNIC_ULP_FCOE) ||
  11000. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11001. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11002. break;
  11003. /* if reached here - should write fcoe capabilities */
  11004. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11005. if (!scratch_offset)
  11006. break;
  11007. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11008. fcoe_features[path][port]);
  11009. host_addr = (u32 *) &(ctl->data.register_data.
  11010. fcoe_features);
  11011. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11012. i += 4)
  11013. REG_WR(bp, scratch_offset + i,
  11014. *(host_addr + i/4));
  11015. }
  11016. break;
  11017. }
  11018. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11019. int ulp_type = ctl->data.ulp_type;
  11020. if (CHIP_IS_E3(bp)) {
  11021. int idx = BP_FW_MB_IDX(bp);
  11022. u32 cap;
  11023. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11024. if (ulp_type == CNIC_ULP_ISCSI)
  11025. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11026. else if (ulp_type == CNIC_ULP_FCOE)
  11027. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11028. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11029. }
  11030. break;
  11031. }
  11032. default:
  11033. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11034. rc = -EINVAL;
  11035. }
  11036. return rc;
  11037. }
  11038. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11039. {
  11040. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11041. if (bp->flags & USING_MSIX_FLAG) {
  11042. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11043. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11044. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11045. } else {
  11046. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11047. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11048. }
  11049. if (!CHIP_IS_E1x(bp))
  11050. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11051. else
  11052. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11053. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11054. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11055. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11056. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11057. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11058. cp->num_irq = 2;
  11059. }
  11060. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11061. {
  11062. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11063. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11064. bnx2x_cid_ilt_lines(bp);
  11065. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11066. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11067. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11068. if (NO_ISCSI_OOO(bp))
  11069. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11070. }
  11071. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11072. void *data)
  11073. {
  11074. struct bnx2x *bp = netdev_priv(dev);
  11075. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11076. int rc;
  11077. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11078. if (ops == NULL) {
  11079. BNX2X_ERR("NULL ops received\n");
  11080. return -EINVAL;
  11081. }
  11082. if (!CNIC_SUPPORT(bp)) {
  11083. BNX2X_ERR("Can't register CNIC when not supported\n");
  11084. return -EOPNOTSUPP;
  11085. }
  11086. if (!CNIC_LOADED(bp)) {
  11087. rc = bnx2x_load_cnic(bp);
  11088. if (rc) {
  11089. BNX2X_ERR("CNIC-related load failed\n");
  11090. return rc;
  11091. }
  11092. }
  11093. bp->cnic_enabled = true;
  11094. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11095. if (!bp->cnic_kwq)
  11096. return -ENOMEM;
  11097. bp->cnic_kwq_cons = bp->cnic_kwq;
  11098. bp->cnic_kwq_prod = bp->cnic_kwq;
  11099. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11100. bp->cnic_spq_pending = 0;
  11101. bp->cnic_kwq_pending = 0;
  11102. bp->cnic_data = data;
  11103. cp->num_irq = 0;
  11104. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11105. cp->iro_arr = bp->iro_arr;
  11106. bnx2x_setup_cnic_irq_info(bp);
  11107. rcu_assign_pointer(bp->cnic_ops, ops);
  11108. return 0;
  11109. }
  11110. static int bnx2x_unregister_cnic(struct net_device *dev)
  11111. {
  11112. struct bnx2x *bp = netdev_priv(dev);
  11113. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11114. mutex_lock(&bp->cnic_mutex);
  11115. cp->drv_state = 0;
  11116. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11117. mutex_unlock(&bp->cnic_mutex);
  11118. synchronize_rcu();
  11119. kfree(bp->cnic_kwq);
  11120. bp->cnic_kwq = NULL;
  11121. return 0;
  11122. }
  11123. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11124. {
  11125. struct bnx2x *bp = netdev_priv(dev);
  11126. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11127. /* If both iSCSI and FCoE are disabled - return NULL in
  11128. * order to indicate CNIC that it should not try to work
  11129. * with this device.
  11130. */
  11131. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11132. return NULL;
  11133. cp->drv_owner = THIS_MODULE;
  11134. cp->chip_id = CHIP_ID(bp);
  11135. cp->pdev = bp->pdev;
  11136. cp->io_base = bp->regview;
  11137. cp->io_base2 = bp->doorbells;
  11138. cp->max_kwqe_pending = 8;
  11139. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11140. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11141. bnx2x_cid_ilt_lines(bp);
  11142. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11143. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11144. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11145. cp->drv_ctl = bnx2x_drv_ctl;
  11146. cp->drv_register_cnic = bnx2x_register_cnic;
  11147. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11148. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11149. cp->iscsi_l2_client_id =
  11150. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11151. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11152. if (NO_ISCSI_OOO(bp))
  11153. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11154. if (NO_ISCSI(bp))
  11155. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11156. if (NO_FCOE(bp))
  11157. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11158. BNX2X_DEV_INFO(
  11159. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11160. cp->ctx_blk_size,
  11161. cp->ctx_tbl_offset,
  11162. cp->ctx_tbl_len,
  11163. cp->starting_cid);
  11164. return cp;
  11165. }
  11166. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11167. {
  11168. struct bnx2x *bp = fp->bp;
  11169. u32 offset = BAR_USTRORM_INTMEM;
  11170. if (IS_VF(bp))
  11171. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11172. else if (!CHIP_IS_E1x(bp))
  11173. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11174. else
  11175. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11176. return offset;
  11177. }
  11178. /* called only on E1H or E2.
  11179. * When pretending to be PF, the pretend value is the function number 0...7
  11180. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11181. * combination
  11182. */
  11183. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11184. {
  11185. u32 pretend_reg;
  11186. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11187. return -1;
  11188. /* get my own pretend register */
  11189. pretend_reg = bnx2x_get_pretend_reg(bp);
  11190. REG_WR(bp, pretend_reg, pretend_func_val);
  11191. REG_RD(bp, pretend_reg);
  11192. return 0;
  11193. }