bnx2x_main.c 373 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758
  1. /* bnx2x_main.c: Broadcom Everest network driver.
  2. *
  3. * Copyright (c) 2007-2013 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. /* Time in jiffies before concluding the transmitter is hung */
  74. #define TX_TIMEOUT (5*HZ)
  75. static char version[] =
  76. "Broadcom NetXtreme II 5771x/578xx 10/20-Gigabit Ethernet Driver "
  77. DRV_MODULE_NAME " " DRV_MODULE_VERSION " (" DRV_MODULE_RELDATE ")\n";
  78. MODULE_AUTHOR("Eliezer Tamir");
  79. MODULE_DESCRIPTION("Broadcom NetXtreme II "
  80. "BCM57710/57711/57711E/"
  81. "57712/57712_MF/57800/57800_MF/57810/57810_MF/"
  82. "57840/57840_MF Driver");
  83. MODULE_LICENSE("GPL");
  84. MODULE_VERSION(DRV_MODULE_VERSION);
  85. MODULE_FIRMWARE(FW_FILE_NAME_E1);
  86. MODULE_FIRMWARE(FW_FILE_NAME_E1H);
  87. MODULE_FIRMWARE(FW_FILE_NAME_E2);
  88. int num_queues;
  89. module_param(num_queues, int, 0);
  90. MODULE_PARM_DESC(num_queues,
  91. " Set number of queues (default is as a number of CPUs)");
  92. static int disable_tpa;
  93. module_param(disable_tpa, int, 0);
  94. MODULE_PARM_DESC(disable_tpa, " Disable the TPA (LRO) feature");
  95. int int_mode;
  96. module_param(int_mode, int, 0);
  97. MODULE_PARM_DESC(int_mode, " Force interrupt mode other than MSI-X "
  98. "(1 INT#x; 2 MSI)");
  99. static int dropless_fc;
  100. module_param(dropless_fc, int, 0);
  101. MODULE_PARM_DESC(dropless_fc, " Pause on exhausted host ring");
  102. static int mrrs = -1;
  103. module_param(mrrs, int, 0);
  104. MODULE_PARM_DESC(mrrs, " Force Max Read Req Size (0..3) (for debug)");
  105. static int debug;
  106. module_param(debug, int, 0);
  107. MODULE_PARM_DESC(debug, " Default debug msglevel");
  108. struct workqueue_struct *bnx2x_wq;
  109. struct bnx2x_mac_vals {
  110. u32 xmac_addr;
  111. u32 xmac_val;
  112. u32 emac_addr;
  113. u32 emac_val;
  114. u32 umac_addr;
  115. u32 umac_val;
  116. u32 bmac_addr;
  117. u32 bmac_val[2];
  118. };
  119. enum bnx2x_board_type {
  120. BCM57710 = 0,
  121. BCM57711,
  122. BCM57711E,
  123. BCM57712,
  124. BCM57712_MF,
  125. BCM57712_VF,
  126. BCM57800,
  127. BCM57800_MF,
  128. BCM57800_VF,
  129. BCM57810,
  130. BCM57810_MF,
  131. BCM57810_VF,
  132. BCM57840_4_10,
  133. BCM57840_2_20,
  134. BCM57840_MF,
  135. BCM57840_VF,
  136. BCM57811,
  137. BCM57811_MF,
  138. BCM57840_O,
  139. BCM57840_MFO,
  140. BCM57811_VF
  141. };
  142. /* indexed by board_type, above */
  143. static struct {
  144. char *name;
  145. } board_info[] = {
  146. [BCM57710] = { "Broadcom NetXtreme II BCM57710 10 Gigabit PCIe [Everest]" },
  147. [BCM57711] = { "Broadcom NetXtreme II BCM57711 10 Gigabit PCIe" },
  148. [BCM57711E] = { "Broadcom NetXtreme II BCM57711E 10 Gigabit PCIe" },
  149. [BCM57712] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet" },
  150. [BCM57712_MF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Multi Function" },
  151. [BCM57712_VF] = { "Broadcom NetXtreme II BCM57712 10 Gigabit Ethernet Virtual Function" },
  152. [BCM57800] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet" },
  153. [BCM57800_MF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Multi Function" },
  154. [BCM57800_VF] = { "Broadcom NetXtreme II BCM57800 10 Gigabit Ethernet Virtual Function" },
  155. [BCM57810] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet" },
  156. [BCM57810_MF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Multi Function" },
  157. [BCM57810_VF] = { "Broadcom NetXtreme II BCM57810 10 Gigabit Ethernet Virtual Function" },
  158. [BCM57840_4_10] = { "Broadcom NetXtreme II BCM57840 10 Gigabit Ethernet" },
  159. [BCM57840_2_20] = { "Broadcom NetXtreme II BCM57840 20 Gigabit Ethernet" },
  160. [BCM57840_MF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  161. [BCM57840_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" },
  162. [BCM57811] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet" },
  163. [BCM57811_MF] = { "Broadcom NetXtreme II BCM57811 10 Gigabit Ethernet Multi Function" },
  164. [BCM57840_O] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet" },
  165. [BCM57840_MFO] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Multi Function" },
  166. [BCM57811_VF] = { "Broadcom NetXtreme II BCM57840 10/20 Gigabit Ethernet Virtual Function" }
  167. };
  168. #ifndef PCI_DEVICE_ID_NX2_57710
  169. #define PCI_DEVICE_ID_NX2_57710 CHIP_NUM_57710
  170. #endif
  171. #ifndef PCI_DEVICE_ID_NX2_57711
  172. #define PCI_DEVICE_ID_NX2_57711 CHIP_NUM_57711
  173. #endif
  174. #ifndef PCI_DEVICE_ID_NX2_57711E
  175. #define PCI_DEVICE_ID_NX2_57711E CHIP_NUM_57711E
  176. #endif
  177. #ifndef PCI_DEVICE_ID_NX2_57712
  178. #define PCI_DEVICE_ID_NX2_57712 CHIP_NUM_57712
  179. #endif
  180. #ifndef PCI_DEVICE_ID_NX2_57712_MF
  181. #define PCI_DEVICE_ID_NX2_57712_MF CHIP_NUM_57712_MF
  182. #endif
  183. #ifndef PCI_DEVICE_ID_NX2_57712_VF
  184. #define PCI_DEVICE_ID_NX2_57712_VF CHIP_NUM_57712_VF
  185. #endif
  186. #ifndef PCI_DEVICE_ID_NX2_57800
  187. #define PCI_DEVICE_ID_NX2_57800 CHIP_NUM_57800
  188. #endif
  189. #ifndef PCI_DEVICE_ID_NX2_57800_MF
  190. #define PCI_DEVICE_ID_NX2_57800_MF CHIP_NUM_57800_MF
  191. #endif
  192. #ifndef PCI_DEVICE_ID_NX2_57800_VF
  193. #define PCI_DEVICE_ID_NX2_57800_VF CHIP_NUM_57800_VF
  194. #endif
  195. #ifndef PCI_DEVICE_ID_NX2_57810
  196. #define PCI_DEVICE_ID_NX2_57810 CHIP_NUM_57810
  197. #endif
  198. #ifndef PCI_DEVICE_ID_NX2_57810_MF
  199. #define PCI_DEVICE_ID_NX2_57810_MF CHIP_NUM_57810_MF
  200. #endif
  201. #ifndef PCI_DEVICE_ID_NX2_57840_O
  202. #define PCI_DEVICE_ID_NX2_57840_O CHIP_NUM_57840_OBSOLETE
  203. #endif
  204. #ifndef PCI_DEVICE_ID_NX2_57810_VF
  205. #define PCI_DEVICE_ID_NX2_57810_VF CHIP_NUM_57810_VF
  206. #endif
  207. #ifndef PCI_DEVICE_ID_NX2_57840_4_10
  208. #define PCI_DEVICE_ID_NX2_57840_4_10 CHIP_NUM_57840_4_10
  209. #endif
  210. #ifndef PCI_DEVICE_ID_NX2_57840_2_20
  211. #define PCI_DEVICE_ID_NX2_57840_2_20 CHIP_NUM_57840_2_20
  212. #endif
  213. #ifndef PCI_DEVICE_ID_NX2_57840_MFO
  214. #define PCI_DEVICE_ID_NX2_57840_MFO CHIP_NUM_57840_MF_OBSOLETE
  215. #endif
  216. #ifndef PCI_DEVICE_ID_NX2_57840_MF
  217. #define PCI_DEVICE_ID_NX2_57840_MF CHIP_NUM_57840_MF
  218. #endif
  219. #ifndef PCI_DEVICE_ID_NX2_57840_VF
  220. #define PCI_DEVICE_ID_NX2_57840_VF CHIP_NUM_57840_VF
  221. #endif
  222. #ifndef PCI_DEVICE_ID_NX2_57811
  223. #define PCI_DEVICE_ID_NX2_57811 CHIP_NUM_57811
  224. #endif
  225. #ifndef PCI_DEVICE_ID_NX2_57811_MF
  226. #define PCI_DEVICE_ID_NX2_57811_MF CHIP_NUM_57811_MF
  227. #endif
  228. #ifndef PCI_DEVICE_ID_NX2_57811_VF
  229. #define PCI_DEVICE_ID_NX2_57811_VF CHIP_NUM_57811_VF
  230. #endif
  231. static DEFINE_PCI_DEVICE_TABLE(bnx2x_pci_tbl) = {
  232. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57710), BCM57710 },
  233. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711), BCM57711 },
  234. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57711E), BCM57711E },
  235. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712), BCM57712 },
  236. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_MF), BCM57712_MF },
  237. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57712_VF), BCM57712_VF },
  238. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800), BCM57800 },
  239. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_MF), BCM57800_MF },
  240. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57800_VF), BCM57800_VF },
  241. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810), BCM57810 },
  242. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_MF), BCM57810_MF },
  243. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_O), BCM57840_O },
  244. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10), BCM57840_4_10 },
  245. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20), BCM57840_2_20 },
  246. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57810_VF), BCM57810_VF },
  247. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MFO), BCM57840_MFO },
  248. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_MF), BCM57840_MF },
  249. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57840_VF), BCM57840_VF },
  250. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811), BCM57811 },
  251. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_MF), BCM57811_MF },
  252. { PCI_VDEVICE(BROADCOM, PCI_DEVICE_ID_NX2_57811_VF), BCM57811_VF },
  253. { 0 }
  254. };
  255. MODULE_DEVICE_TABLE(pci, bnx2x_pci_tbl);
  256. /* Global resources for unloading a previously loaded device */
  257. #define BNX2X_PREV_WAIT_NEEDED 1
  258. static DEFINE_SEMAPHORE(bnx2x_prev_sem);
  259. static LIST_HEAD(bnx2x_prev_list);
  260. /****************************************************************************
  261. * General service functions
  262. ****************************************************************************/
  263. static void __storm_memset_dma_mapping(struct bnx2x *bp,
  264. u32 addr, dma_addr_t mapping)
  265. {
  266. REG_WR(bp, addr, U64_LO(mapping));
  267. REG_WR(bp, addr + 4, U64_HI(mapping));
  268. }
  269. static void storm_memset_spq_addr(struct bnx2x *bp,
  270. dma_addr_t mapping, u16 abs_fid)
  271. {
  272. u32 addr = XSEM_REG_FAST_MEMORY +
  273. XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
  274. __storm_memset_dma_mapping(bp, addr, mapping);
  275. }
  276. static void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
  277. u16 pf_id)
  278. {
  279. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
  280. pf_id);
  281. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
  282. pf_id);
  283. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
  284. pf_id);
  285. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
  286. pf_id);
  287. }
  288. static void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
  289. u8 enable)
  290. {
  291. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
  292. enable);
  293. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
  294. enable);
  295. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
  296. enable);
  297. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
  298. enable);
  299. }
  300. static void storm_memset_eq_data(struct bnx2x *bp,
  301. struct event_ring_data *eq_data,
  302. u16 pfid)
  303. {
  304. size_t size = sizeof(struct event_ring_data);
  305. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_DATA_OFFSET(pfid);
  306. __storm_memset_struct(bp, addr, size, (u32 *)eq_data);
  307. }
  308. static void storm_memset_eq_prod(struct bnx2x *bp, u16 eq_prod,
  309. u16 pfid)
  310. {
  311. u32 addr = BAR_CSTRORM_INTMEM + CSTORM_EVENT_RING_PROD_OFFSET(pfid);
  312. REG_WR16(bp, addr, eq_prod);
  313. }
  314. /* used only at init
  315. * locking is done by mcp
  316. */
  317. static void bnx2x_reg_wr_ind(struct bnx2x *bp, u32 addr, u32 val)
  318. {
  319. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  320. pci_write_config_dword(bp->pdev, PCICFG_GRC_DATA, val);
  321. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  322. PCICFG_VENDOR_ID_OFFSET);
  323. }
  324. static u32 bnx2x_reg_rd_ind(struct bnx2x *bp, u32 addr)
  325. {
  326. u32 val;
  327. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS, addr);
  328. pci_read_config_dword(bp->pdev, PCICFG_GRC_DATA, &val);
  329. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  330. PCICFG_VENDOR_ID_OFFSET);
  331. return val;
  332. }
  333. #define DMAE_DP_SRC_GRC "grc src_addr [%08x]"
  334. #define DMAE_DP_SRC_PCI "pci src_addr [%x:%08x]"
  335. #define DMAE_DP_DST_GRC "grc dst_addr [%08x]"
  336. #define DMAE_DP_DST_PCI "pci dst_addr [%x:%08x]"
  337. #define DMAE_DP_DST_NONE "dst_addr [none]"
  338. static void bnx2x_dp_dmae(struct bnx2x *bp,
  339. struct dmae_command *dmae, int msglvl)
  340. {
  341. u32 src_type = dmae->opcode & DMAE_COMMAND_SRC;
  342. int i;
  343. switch (dmae->opcode & DMAE_COMMAND_DST) {
  344. case DMAE_CMD_DST_PCI:
  345. if (src_type == DMAE_CMD_SRC_PCI)
  346. DP(msglvl, "DMAE: opcode 0x%08x\n"
  347. "src [%x:%08x], len [%d*4], dst [%x:%08x]\n"
  348. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  349. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  350. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  351. dmae->comp_addr_hi, dmae->comp_addr_lo,
  352. dmae->comp_val);
  353. else
  354. DP(msglvl, "DMAE: opcode 0x%08x\n"
  355. "src [%08x], len [%d*4], dst [%x:%08x]\n"
  356. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  357. dmae->opcode, dmae->src_addr_lo >> 2,
  358. dmae->len, dmae->dst_addr_hi, dmae->dst_addr_lo,
  359. dmae->comp_addr_hi, dmae->comp_addr_lo,
  360. dmae->comp_val);
  361. break;
  362. case DMAE_CMD_DST_GRC:
  363. if (src_type == DMAE_CMD_SRC_PCI)
  364. DP(msglvl, "DMAE: opcode 0x%08x\n"
  365. "src [%x:%08x], len [%d*4], dst_addr [%08x]\n"
  366. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  367. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  368. dmae->len, dmae->dst_addr_lo >> 2,
  369. dmae->comp_addr_hi, dmae->comp_addr_lo,
  370. dmae->comp_val);
  371. else
  372. DP(msglvl, "DMAE: opcode 0x%08x\n"
  373. "src [%08x], len [%d*4], dst [%08x]\n"
  374. "comp_addr [%x:%08x], comp_val 0x%08x\n",
  375. dmae->opcode, dmae->src_addr_lo >> 2,
  376. dmae->len, dmae->dst_addr_lo >> 2,
  377. dmae->comp_addr_hi, dmae->comp_addr_lo,
  378. dmae->comp_val);
  379. break;
  380. default:
  381. if (src_type == DMAE_CMD_SRC_PCI)
  382. DP(msglvl, "DMAE: opcode 0x%08x\n"
  383. "src_addr [%x:%08x] len [%d * 4] dst_addr [none]\n"
  384. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  385. dmae->opcode, dmae->src_addr_hi, dmae->src_addr_lo,
  386. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  387. dmae->comp_val);
  388. else
  389. DP(msglvl, "DMAE: opcode 0x%08x\n"
  390. "src_addr [%08x] len [%d * 4] dst_addr [none]\n"
  391. "comp_addr [%x:%08x] comp_val 0x%08x\n",
  392. dmae->opcode, dmae->src_addr_lo >> 2,
  393. dmae->len, dmae->comp_addr_hi, dmae->comp_addr_lo,
  394. dmae->comp_val);
  395. break;
  396. }
  397. for (i = 0; i < (sizeof(struct dmae_command)/4); i++)
  398. DP(msglvl, "DMAE RAW [%02d]: 0x%08x\n",
  399. i, *(((u32 *)dmae) + i));
  400. }
  401. /* copy command into DMAE command memory and set DMAE command go */
  402. void bnx2x_post_dmae(struct bnx2x *bp, struct dmae_command *dmae, int idx)
  403. {
  404. u32 cmd_offset;
  405. int i;
  406. cmd_offset = (DMAE_REG_CMD_MEM + sizeof(struct dmae_command) * idx);
  407. for (i = 0; i < (sizeof(struct dmae_command)/4); i++) {
  408. REG_WR(bp, cmd_offset + i*4, *(((u32 *)dmae) + i));
  409. }
  410. REG_WR(bp, dmae_reg_go_c[idx], 1);
  411. }
  412. u32 bnx2x_dmae_opcode_add_comp(u32 opcode, u8 comp_type)
  413. {
  414. return opcode | ((comp_type << DMAE_COMMAND_C_DST_SHIFT) |
  415. DMAE_CMD_C_ENABLE);
  416. }
  417. u32 bnx2x_dmae_opcode_clr_src_reset(u32 opcode)
  418. {
  419. return opcode & ~DMAE_CMD_SRC_RESET;
  420. }
  421. u32 bnx2x_dmae_opcode(struct bnx2x *bp, u8 src_type, u8 dst_type,
  422. bool with_comp, u8 comp_type)
  423. {
  424. u32 opcode = 0;
  425. opcode |= ((src_type << DMAE_COMMAND_SRC_SHIFT) |
  426. (dst_type << DMAE_COMMAND_DST_SHIFT));
  427. opcode |= (DMAE_CMD_SRC_RESET | DMAE_CMD_DST_RESET);
  428. opcode |= (BP_PORT(bp) ? DMAE_CMD_PORT_1 : DMAE_CMD_PORT_0);
  429. opcode |= ((BP_VN(bp) << DMAE_CMD_E1HVN_SHIFT) |
  430. (BP_VN(bp) << DMAE_COMMAND_DST_VN_SHIFT));
  431. opcode |= (DMAE_COM_SET_ERR << DMAE_COMMAND_ERR_POLICY_SHIFT);
  432. #ifdef __BIG_ENDIAN
  433. opcode |= DMAE_CMD_ENDIANITY_B_DW_SWAP;
  434. #else
  435. opcode |= DMAE_CMD_ENDIANITY_DW_SWAP;
  436. #endif
  437. if (with_comp)
  438. opcode = bnx2x_dmae_opcode_add_comp(opcode, comp_type);
  439. return opcode;
  440. }
  441. void bnx2x_prep_dmae_with_comp(struct bnx2x *bp,
  442. struct dmae_command *dmae,
  443. u8 src_type, u8 dst_type)
  444. {
  445. memset(dmae, 0, sizeof(struct dmae_command));
  446. /* set the opcode */
  447. dmae->opcode = bnx2x_dmae_opcode(bp, src_type, dst_type,
  448. true, DMAE_COMP_PCI);
  449. /* fill in the completion parameters */
  450. dmae->comp_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_comp));
  451. dmae->comp_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_comp));
  452. dmae->comp_val = DMAE_COMP_VAL;
  453. }
  454. /* issue a dmae command over the init-channel and wait for completion */
  455. int bnx2x_issue_dmae_with_comp(struct bnx2x *bp, struct dmae_command *dmae)
  456. {
  457. u32 *wb_comp = bnx2x_sp(bp, wb_comp);
  458. int cnt = CHIP_REV_IS_SLOW(bp) ? (400000) : 4000;
  459. int rc = 0;
  460. bnx2x_dp_dmae(bp, dmae, BNX2X_MSG_DMAE);
  461. /* Lock the dmae channel. Disable BHs to prevent a dead-lock
  462. * as long as this code is called both from syscall context and
  463. * from ndo_set_rx_mode() flow that may be called from BH.
  464. */
  465. spin_lock_bh(&bp->dmae_lock);
  466. /* reset completion */
  467. *wb_comp = 0;
  468. /* post the command on the channel used for initializations */
  469. bnx2x_post_dmae(bp, dmae, INIT_DMAE_C(bp));
  470. /* wait for completion */
  471. udelay(5);
  472. while ((*wb_comp & ~DMAE_PCI_ERR_FLAG) != DMAE_COMP_VAL) {
  473. if (!cnt ||
  474. (bp->recovery_state != BNX2X_RECOVERY_DONE &&
  475. bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  476. BNX2X_ERR("DMAE timeout!\n");
  477. rc = DMAE_TIMEOUT;
  478. goto unlock;
  479. }
  480. cnt--;
  481. udelay(50);
  482. }
  483. if (*wb_comp & DMAE_PCI_ERR_FLAG) {
  484. BNX2X_ERR("DMAE PCI error!\n");
  485. rc = DMAE_PCI_ERROR;
  486. }
  487. unlock:
  488. spin_unlock_bh(&bp->dmae_lock);
  489. return rc;
  490. }
  491. void bnx2x_write_dmae(struct bnx2x *bp, dma_addr_t dma_addr, u32 dst_addr,
  492. u32 len32)
  493. {
  494. int rc;
  495. struct dmae_command dmae;
  496. if (!bp->dmae_ready) {
  497. u32 *data = bnx2x_sp(bp, wb_data[0]);
  498. if (CHIP_IS_E1(bp))
  499. bnx2x_init_ind_wr(bp, dst_addr, data, len32);
  500. else
  501. bnx2x_init_str_wr(bp, dst_addr, data, len32);
  502. return;
  503. }
  504. /* set opcode and fixed command fields */
  505. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_PCI, DMAE_DST_GRC);
  506. /* fill in addresses and len */
  507. dmae.src_addr_lo = U64_LO(dma_addr);
  508. dmae.src_addr_hi = U64_HI(dma_addr);
  509. dmae.dst_addr_lo = dst_addr >> 2;
  510. dmae.dst_addr_hi = 0;
  511. dmae.len = len32;
  512. /* issue the command and wait for completion */
  513. rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
  514. if (rc) {
  515. BNX2X_ERR("DMAE returned failure %d\n", rc);
  516. bnx2x_panic();
  517. }
  518. }
  519. void bnx2x_read_dmae(struct bnx2x *bp, u32 src_addr, u32 len32)
  520. {
  521. int rc;
  522. struct dmae_command dmae;
  523. if (!bp->dmae_ready) {
  524. u32 *data = bnx2x_sp(bp, wb_data[0]);
  525. int i;
  526. if (CHIP_IS_E1(bp))
  527. for (i = 0; i < len32; i++)
  528. data[i] = bnx2x_reg_rd_ind(bp, src_addr + i*4);
  529. else
  530. for (i = 0; i < len32; i++)
  531. data[i] = REG_RD(bp, src_addr + i*4);
  532. return;
  533. }
  534. /* set opcode and fixed command fields */
  535. bnx2x_prep_dmae_with_comp(bp, &dmae, DMAE_SRC_GRC, DMAE_DST_PCI);
  536. /* fill in addresses and len */
  537. dmae.src_addr_lo = src_addr >> 2;
  538. dmae.src_addr_hi = 0;
  539. dmae.dst_addr_lo = U64_LO(bnx2x_sp_mapping(bp, wb_data));
  540. dmae.dst_addr_hi = U64_HI(bnx2x_sp_mapping(bp, wb_data));
  541. dmae.len = len32;
  542. /* issue the command and wait for completion */
  543. rc = bnx2x_issue_dmae_with_comp(bp, &dmae);
  544. if (rc) {
  545. BNX2X_ERR("DMAE returned failure %d\n", rc);
  546. bnx2x_panic();
  547. };
  548. }
  549. static void bnx2x_write_dmae_phys_len(struct bnx2x *bp, dma_addr_t phys_addr,
  550. u32 addr, u32 len)
  551. {
  552. int dmae_wr_max = DMAE_LEN32_WR_MAX(bp);
  553. int offset = 0;
  554. while (len > dmae_wr_max) {
  555. bnx2x_write_dmae(bp, phys_addr + offset,
  556. addr + offset, dmae_wr_max);
  557. offset += dmae_wr_max * 4;
  558. len -= dmae_wr_max;
  559. }
  560. bnx2x_write_dmae(bp, phys_addr + offset, addr + offset, len);
  561. }
  562. static int bnx2x_mc_assert(struct bnx2x *bp)
  563. {
  564. char last_idx;
  565. int i, rc = 0;
  566. u32 row0, row1, row2, row3;
  567. /* XSTORM */
  568. last_idx = REG_RD8(bp, BAR_XSTRORM_INTMEM +
  569. XSTORM_ASSERT_LIST_INDEX_OFFSET);
  570. if (last_idx)
  571. BNX2X_ERR("XSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  572. /* print the asserts */
  573. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  574. row0 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  575. XSTORM_ASSERT_LIST_OFFSET(i));
  576. row1 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  577. XSTORM_ASSERT_LIST_OFFSET(i) + 4);
  578. row2 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  579. XSTORM_ASSERT_LIST_OFFSET(i) + 8);
  580. row3 = REG_RD(bp, BAR_XSTRORM_INTMEM +
  581. XSTORM_ASSERT_LIST_OFFSET(i) + 12);
  582. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  583. BNX2X_ERR("XSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  584. i, row3, row2, row1, row0);
  585. rc++;
  586. } else {
  587. break;
  588. }
  589. }
  590. /* TSTORM */
  591. last_idx = REG_RD8(bp, BAR_TSTRORM_INTMEM +
  592. TSTORM_ASSERT_LIST_INDEX_OFFSET);
  593. if (last_idx)
  594. BNX2X_ERR("TSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  595. /* print the asserts */
  596. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  597. row0 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  598. TSTORM_ASSERT_LIST_OFFSET(i));
  599. row1 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  600. TSTORM_ASSERT_LIST_OFFSET(i) + 4);
  601. row2 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  602. TSTORM_ASSERT_LIST_OFFSET(i) + 8);
  603. row3 = REG_RD(bp, BAR_TSTRORM_INTMEM +
  604. TSTORM_ASSERT_LIST_OFFSET(i) + 12);
  605. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  606. BNX2X_ERR("TSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  607. i, row3, row2, row1, row0);
  608. rc++;
  609. } else {
  610. break;
  611. }
  612. }
  613. /* CSTORM */
  614. last_idx = REG_RD8(bp, BAR_CSTRORM_INTMEM +
  615. CSTORM_ASSERT_LIST_INDEX_OFFSET);
  616. if (last_idx)
  617. BNX2X_ERR("CSTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  618. /* print the asserts */
  619. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  620. row0 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  621. CSTORM_ASSERT_LIST_OFFSET(i));
  622. row1 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  623. CSTORM_ASSERT_LIST_OFFSET(i) + 4);
  624. row2 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  625. CSTORM_ASSERT_LIST_OFFSET(i) + 8);
  626. row3 = REG_RD(bp, BAR_CSTRORM_INTMEM +
  627. CSTORM_ASSERT_LIST_OFFSET(i) + 12);
  628. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  629. BNX2X_ERR("CSTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  630. i, row3, row2, row1, row0);
  631. rc++;
  632. } else {
  633. break;
  634. }
  635. }
  636. /* USTORM */
  637. last_idx = REG_RD8(bp, BAR_USTRORM_INTMEM +
  638. USTORM_ASSERT_LIST_INDEX_OFFSET);
  639. if (last_idx)
  640. BNX2X_ERR("USTORM_ASSERT_LIST_INDEX 0x%x\n", last_idx);
  641. /* print the asserts */
  642. for (i = 0; i < STROM_ASSERT_ARRAY_SIZE; i++) {
  643. row0 = REG_RD(bp, BAR_USTRORM_INTMEM +
  644. USTORM_ASSERT_LIST_OFFSET(i));
  645. row1 = REG_RD(bp, BAR_USTRORM_INTMEM +
  646. USTORM_ASSERT_LIST_OFFSET(i) + 4);
  647. row2 = REG_RD(bp, BAR_USTRORM_INTMEM +
  648. USTORM_ASSERT_LIST_OFFSET(i) + 8);
  649. row3 = REG_RD(bp, BAR_USTRORM_INTMEM +
  650. USTORM_ASSERT_LIST_OFFSET(i) + 12);
  651. if (row0 != COMMON_ASM_INVALID_ASSERT_OPCODE) {
  652. BNX2X_ERR("USTORM_ASSERT_INDEX 0x%x = 0x%08x 0x%08x 0x%08x 0x%08x\n",
  653. i, row3, row2, row1, row0);
  654. rc++;
  655. } else {
  656. break;
  657. }
  658. }
  659. return rc;
  660. }
  661. void bnx2x_fw_dump_lvl(struct bnx2x *bp, const char *lvl)
  662. {
  663. u32 addr, val;
  664. u32 mark, offset;
  665. __be32 data[9];
  666. int word;
  667. u32 trace_shmem_base;
  668. if (BP_NOMCP(bp)) {
  669. BNX2X_ERR("NO MCP - can not dump\n");
  670. return;
  671. }
  672. netdev_printk(lvl, bp->dev, "bc %d.%d.%d\n",
  673. (bp->common.bc_ver & 0xff0000) >> 16,
  674. (bp->common.bc_ver & 0xff00) >> 8,
  675. (bp->common.bc_ver & 0xff));
  676. val = REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER);
  677. if (val == REG_RD(bp, MCP_REG_MCPR_CPU_PROGRAM_COUNTER))
  678. BNX2X_ERR("%s" "MCP PC at 0x%x\n", lvl, val);
  679. if (BP_PATH(bp) == 0)
  680. trace_shmem_base = bp->common.shmem_base;
  681. else
  682. trace_shmem_base = SHMEM2_RD(bp, other_shmem_base_addr);
  683. addr = trace_shmem_base - 0x800;
  684. /* validate TRCB signature */
  685. mark = REG_RD(bp, addr);
  686. if (mark != MFW_TRACE_SIGNATURE) {
  687. BNX2X_ERR("Trace buffer signature is missing.");
  688. return ;
  689. }
  690. /* read cyclic buffer pointer */
  691. addr += 4;
  692. mark = REG_RD(bp, addr);
  693. mark = (CHIP_IS_E1x(bp) ? MCP_REG_MCPR_SCRATCH : MCP_A_REG_MCPR_SCRATCH)
  694. + ((mark + 0x3) & ~0x3) - 0x08000000;
  695. printk("%s" "begin fw dump (mark 0x%x)\n", lvl, mark);
  696. printk("%s", lvl);
  697. /* dump buffer after the mark */
  698. for (offset = mark; offset <= trace_shmem_base; offset += 0x8*4) {
  699. for (word = 0; word < 8; word++)
  700. data[word] = htonl(REG_RD(bp, offset + 4*word));
  701. data[8] = 0x0;
  702. pr_cont("%s", (char *)data);
  703. }
  704. /* dump buffer before the mark */
  705. for (offset = addr + 4; offset <= mark; offset += 0x8*4) {
  706. for (word = 0; word < 8; word++)
  707. data[word] = htonl(REG_RD(bp, offset + 4*word));
  708. data[8] = 0x0;
  709. pr_cont("%s", (char *)data);
  710. }
  711. printk("%s" "end of fw dump\n", lvl);
  712. }
  713. static void bnx2x_fw_dump(struct bnx2x *bp)
  714. {
  715. bnx2x_fw_dump_lvl(bp, KERN_ERR);
  716. }
  717. static void bnx2x_hc_int_disable(struct bnx2x *bp)
  718. {
  719. int port = BP_PORT(bp);
  720. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  721. u32 val = REG_RD(bp, addr);
  722. /* in E1 we must use only PCI configuration space to disable
  723. * MSI/MSIX capability
  724. * It's forbidden to disable IGU_PF_CONF_MSI_MSIX_EN in HC block
  725. */
  726. if (CHIP_IS_E1(bp)) {
  727. /* Since IGU_PF_CONF_MSI_MSIX_EN still always on
  728. * Use mask register to prevent from HC sending interrupts
  729. * after we exit the function
  730. */
  731. REG_WR(bp, HC_REG_INT_MASK + port*4, 0);
  732. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  733. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  734. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  735. } else
  736. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  737. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  738. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  739. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  740. DP(NETIF_MSG_IFDOWN,
  741. "write %x to HC %d (addr 0x%x)\n",
  742. val, port, addr);
  743. /* flush all outstanding writes */
  744. mmiowb();
  745. REG_WR(bp, addr, val);
  746. if (REG_RD(bp, addr) != val)
  747. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  748. }
  749. static void bnx2x_igu_int_disable(struct bnx2x *bp)
  750. {
  751. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  752. val &= ~(IGU_PF_CONF_MSI_MSIX_EN |
  753. IGU_PF_CONF_INT_LINE_EN |
  754. IGU_PF_CONF_ATTN_BIT_EN);
  755. DP(NETIF_MSG_IFDOWN, "write %x to IGU\n", val);
  756. /* flush all outstanding writes */
  757. mmiowb();
  758. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  759. if (REG_RD(bp, IGU_REG_PF_CONFIGURATION) != val)
  760. BNX2X_ERR("BUG! Proper val not read from IGU!\n");
  761. }
  762. static void bnx2x_int_disable(struct bnx2x *bp)
  763. {
  764. if (bp->common.int_block == INT_BLOCK_HC)
  765. bnx2x_hc_int_disable(bp);
  766. else
  767. bnx2x_igu_int_disable(bp);
  768. }
  769. void bnx2x_panic_dump(struct bnx2x *bp, bool disable_int)
  770. {
  771. int i;
  772. u16 j;
  773. struct hc_sp_status_block_data sp_sb_data;
  774. int func = BP_FUNC(bp);
  775. #ifdef BNX2X_STOP_ON_ERROR
  776. u16 start = 0, end = 0;
  777. u8 cos;
  778. #endif
  779. if (disable_int)
  780. bnx2x_int_disable(bp);
  781. bp->stats_state = STATS_STATE_DISABLED;
  782. bp->eth_stats.unrecoverable_error++;
  783. DP(BNX2X_MSG_STATS, "stats_state - DISABLED\n");
  784. BNX2X_ERR("begin crash dump -----------------\n");
  785. /* Indices */
  786. /* Common */
  787. 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",
  788. bp->def_idx, bp->def_att_idx, bp->attn_state,
  789. bp->spq_prod_idx, bp->stats_counter);
  790. BNX2X_ERR("DSB: attn bits(0x%x) ack(0x%x) id(0x%x) idx(0x%x)\n",
  791. bp->def_status_blk->atten_status_block.attn_bits,
  792. bp->def_status_blk->atten_status_block.attn_bits_ack,
  793. bp->def_status_blk->atten_status_block.status_block_id,
  794. bp->def_status_blk->atten_status_block.attn_bits_index);
  795. BNX2X_ERR(" def (");
  796. for (i = 0; i < HC_SP_SB_MAX_INDICES; i++)
  797. pr_cont("0x%x%s",
  798. bp->def_status_blk->sp_sb.index_values[i],
  799. (i == HC_SP_SB_MAX_INDICES - 1) ? ") " : " ");
  800. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  801. *((u32 *)&sp_sb_data + i) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  802. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  803. i*sizeof(u32));
  804. 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",
  805. sp_sb_data.igu_sb_id,
  806. sp_sb_data.igu_seg_id,
  807. sp_sb_data.p_func.pf_id,
  808. sp_sb_data.p_func.vnic_id,
  809. sp_sb_data.p_func.vf_id,
  810. sp_sb_data.p_func.vf_valid,
  811. sp_sb_data.state);
  812. for_each_eth_queue(bp, i) {
  813. struct bnx2x_fastpath *fp = &bp->fp[i];
  814. int loop;
  815. struct hc_status_block_data_e2 sb_data_e2;
  816. struct hc_status_block_data_e1x sb_data_e1x;
  817. struct hc_status_block_sm *hc_sm_p =
  818. CHIP_IS_E1x(bp) ?
  819. sb_data_e1x.common.state_machine :
  820. sb_data_e2.common.state_machine;
  821. struct hc_index_data *hc_index_p =
  822. CHIP_IS_E1x(bp) ?
  823. sb_data_e1x.index_data :
  824. sb_data_e2.index_data;
  825. u8 data_size, cos;
  826. u32 *sb_data_p;
  827. struct bnx2x_fp_txdata txdata;
  828. /* Rx */
  829. 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",
  830. i, fp->rx_bd_prod, fp->rx_bd_cons,
  831. fp->rx_comp_prod,
  832. fp->rx_comp_cons, le16_to_cpu(*fp->rx_cons_sb));
  833. BNX2X_ERR(" rx_sge_prod(0x%x) last_max_sge(0x%x) fp_hc_idx(0x%x)\n",
  834. fp->rx_sge_prod, fp->last_max_sge,
  835. le16_to_cpu(fp->fp_hc_idx));
  836. /* Tx */
  837. for_each_cos_in_tx_queue(fp, cos)
  838. {
  839. txdata = *fp->txdata_ptr[cos];
  840. 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",
  841. i, txdata.tx_pkt_prod,
  842. txdata.tx_pkt_cons, txdata.tx_bd_prod,
  843. txdata.tx_bd_cons,
  844. le16_to_cpu(*txdata.tx_cons_sb));
  845. }
  846. loop = CHIP_IS_E1x(bp) ?
  847. HC_SB_MAX_INDICES_E1X : HC_SB_MAX_INDICES_E2;
  848. /* host sb data */
  849. if (IS_FCOE_FP(fp))
  850. continue;
  851. BNX2X_ERR(" run indexes (");
  852. for (j = 0; j < HC_SB_MAX_SM; j++)
  853. pr_cont("0x%x%s",
  854. fp->sb_running_index[j],
  855. (j == HC_SB_MAX_SM - 1) ? ")" : " ");
  856. BNX2X_ERR(" indexes (");
  857. for (j = 0; j < loop; j++)
  858. pr_cont("0x%x%s",
  859. fp->sb_index_values[j],
  860. (j == loop - 1) ? ")" : " ");
  861. /* fw sb data */
  862. data_size = CHIP_IS_E1x(bp) ?
  863. sizeof(struct hc_status_block_data_e1x) :
  864. sizeof(struct hc_status_block_data_e2);
  865. data_size /= sizeof(u32);
  866. sb_data_p = CHIP_IS_E1x(bp) ?
  867. (u32 *)&sb_data_e1x :
  868. (u32 *)&sb_data_e2;
  869. /* copy sb data in here */
  870. for (j = 0; j < data_size; j++)
  871. *(sb_data_p + j) = REG_RD(bp, BAR_CSTRORM_INTMEM +
  872. CSTORM_STATUS_BLOCK_DATA_OFFSET(fp->fw_sb_id) +
  873. j * sizeof(u32));
  874. if (!CHIP_IS_E1x(bp)) {
  875. 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",
  876. sb_data_e2.common.p_func.pf_id,
  877. sb_data_e2.common.p_func.vf_id,
  878. sb_data_e2.common.p_func.vf_valid,
  879. sb_data_e2.common.p_func.vnic_id,
  880. sb_data_e2.common.same_igu_sb_1b,
  881. sb_data_e2.common.state);
  882. } else {
  883. 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",
  884. sb_data_e1x.common.p_func.pf_id,
  885. sb_data_e1x.common.p_func.vf_id,
  886. sb_data_e1x.common.p_func.vf_valid,
  887. sb_data_e1x.common.p_func.vnic_id,
  888. sb_data_e1x.common.same_igu_sb_1b,
  889. sb_data_e1x.common.state);
  890. }
  891. /* SB_SMs data */
  892. for (j = 0; j < HC_SB_MAX_SM; j++) {
  893. 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",
  894. j, hc_sm_p[j].__flags,
  895. hc_sm_p[j].igu_sb_id,
  896. hc_sm_p[j].igu_seg_id,
  897. hc_sm_p[j].time_to_expire,
  898. hc_sm_p[j].timer_value);
  899. }
  900. /* Indices data */
  901. for (j = 0; j < loop; j++) {
  902. pr_cont("INDEX[%d] flags (0x%x) timeout (0x%x)\n", j,
  903. hc_index_p[j].flags,
  904. hc_index_p[j].timeout);
  905. }
  906. }
  907. #ifdef BNX2X_STOP_ON_ERROR
  908. /* event queue */
  909. BNX2X_ERR("eq cons %x prod %x\n", bp->eq_cons, bp->eq_prod);
  910. for (i = 0; i < NUM_EQ_DESC; i++) {
  911. u32 *data = (u32 *)&bp->eq_ring[i].message.data;
  912. BNX2X_ERR("event queue [%d]: header: opcode %d, error %d\n",
  913. i, bp->eq_ring[i].message.opcode,
  914. bp->eq_ring[i].message.error);
  915. BNX2X_ERR("data: %x %x %x\n", data[0], data[1], data[2]);
  916. }
  917. /* Rings */
  918. /* Rx */
  919. for_each_valid_rx_queue(bp, i) {
  920. struct bnx2x_fastpath *fp = &bp->fp[i];
  921. start = RX_BD(le16_to_cpu(*fp->rx_cons_sb) - 10);
  922. end = RX_BD(le16_to_cpu(*fp->rx_cons_sb) + 503);
  923. for (j = start; j != end; j = RX_BD(j + 1)) {
  924. u32 *rx_bd = (u32 *)&fp->rx_desc_ring[j];
  925. struct sw_rx_bd *sw_bd = &fp->rx_buf_ring[j];
  926. BNX2X_ERR("fp%d: rx_bd[%x]=[%x:%x] sw_bd=[%p]\n",
  927. i, j, rx_bd[1], rx_bd[0], sw_bd->data);
  928. }
  929. start = RX_SGE(fp->rx_sge_prod);
  930. end = RX_SGE(fp->last_max_sge);
  931. for (j = start; j != end; j = RX_SGE(j + 1)) {
  932. u32 *rx_sge = (u32 *)&fp->rx_sge_ring[j];
  933. struct sw_rx_page *sw_page = &fp->rx_page_ring[j];
  934. BNX2X_ERR("fp%d: rx_sge[%x]=[%x:%x] sw_page=[%p]\n",
  935. i, j, rx_sge[1], rx_sge[0], sw_page->page);
  936. }
  937. start = RCQ_BD(fp->rx_comp_cons - 10);
  938. end = RCQ_BD(fp->rx_comp_cons + 503);
  939. for (j = start; j != end; j = RCQ_BD(j + 1)) {
  940. u32 *cqe = (u32 *)&fp->rx_comp_ring[j];
  941. BNX2X_ERR("fp%d: cqe[%x]=[%x:%x:%x:%x]\n",
  942. i, j, cqe[0], cqe[1], cqe[2], cqe[3]);
  943. }
  944. }
  945. /* Tx */
  946. for_each_valid_tx_queue(bp, i) {
  947. struct bnx2x_fastpath *fp = &bp->fp[i];
  948. for_each_cos_in_tx_queue(fp, cos) {
  949. struct bnx2x_fp_txdata *txdata = fp->txdata_ptr[cos];
  950. start = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) - 10);
  951. end = TX_BD(le16_to_cpu(*txdata->tx_cons_sb) + 245);
  952. for (j = start; j != end; j = TX_BD(j + 1)) {
  953. struct sw_tx_bd *sw_bd =
  954. &txdata->tx_buf_ring[j];
  955. BNX2X_ERR("fp%d: txdata %d, packet[%x]=[%p,%x]\n",
  956. i, cos, j, sw_bd->skb,
  957. sw_bd->first_bd);
  958. }
  959. start = TX_BD(txdata->tx_bd_cons - 10);
  960. end = TX_BD(txdata->tx_bd_cons + 254);
  961. for (j = start; j != end; j = TX_BD(j + 1)) {
  962. u32 *tx_bd = (u32 *)&txdata->tx_desc_ring[j];
  963. BNX2X_ERR("fp%d: txdata %d, tx_bd[%x]=[%x:%x:%x:%x]\n",
  964. i, cos, j, tx_bd[0], tx_bd[1],
  965. tx_bd[2], tx_bd[3]);
  966. }
  967. }
  968. }
  969. #endif
  970. bnx2x_fw_dump(bp);
  971. bnx2x_mc_assert(bp);
  972. BNX2X_ERR("end crash dump -----------------\n");
  973. }
  974. /*
  975. * FLR Support for E2
  976. *
  977. * bnx2x_pf_flr_clnup() is called during nic_load in the per function HW
  978. * initialization.
  979. */
  980. #define FLR_WAIT_USEC 10000 /* 10 milliseconds */
  981. #define FLR_WAIT_INTERVAL 50 /* usec */
  982. #define FLR_POLL_CNT (FLR_WAIT_USEC/FLR_WAIT_INTERVAL) /* 200 */
  983. struct pbf_pN_buf_regs {
  984. int pN;
  985. u32 init_crd;
  986. u32 crd;
  987. u32 crd_freed;
  988. };
  989. struct pbf_pN_cmd_regs {
  990. int pN;
  991. u32 lines_occup;
  992. u32 lines_freed;
  993. };
  994. static void bnx2x_pbf_pN_buf_flushed(struct bnx2x *bp,
  995. struct pbf_pN_buf_regs *regs,
  996. u32 poll_count)
  997. {
  998. u32 init_crd, crd, crd_start, crd_freed, crd_freed_start;
  999. u32 cur_cnt = poll_count;
  1000. crd_freed = crd_freed_start = REG_RD(bp, regs->crd_freed);
  1001. crd = crd_start = REG_RD(bp, regs->crd);
  1002. init_crd = REG_RD(bp, regs->init_crd);
  1003. DP(BNX2X_MSG_SP, "INIT CREDIT[%d] : %x\n", regs->pN, init_crd);
  1004. DP(BNX2X_MSG_SP, "CREDIT[%d] : s:%x\n", regs->pN, crd);
  1005. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: s:%x\n", regs->pN, crd_freed);
  1006. while ((crd != init_crd) && ((u32)SUB_S32(crd_freed, crd_freed_start) <
  1007. (init_crd - crd_start))) {
  1008. if (cur_cnt--) {
  1009. udelay(FLR_WAIT_INTERVAL);
  1010. crd = REG_RD(bp, regs->crd);
  1011. crd_freed = REG_RD(bp, regs->crd_freed);
  1012. } else {
  1013. DP(BNX2X_MSG_SP, "PBF tx buffer[%d] timed out\n",
  1014. regs->pN);
  1015. DP(BNX2X_MSG_SP, "CREDIT[%d] : c:%x\n",
  1016. regs->pN, crd);
  1017. DP(BNX2X_MSG_SP, "CREDIT_FREED[%d]: c:%x\n",
  1018. regs->pN, crd_freed);
  1019. break;
  1020. }
  1021. }
  1022. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF tx buffer[%d]\n",
  1023. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1024. }
  1025. static void bnx2x_pbf_pN_cmd_flushed(struct bnx2x *bp,
  1026. struct pbf_pN_cmd_regs *regs,
  1027. u32 poll_count)
  1028. {
  1029. u32 occup, to_free, freed, freed_start;
  1030. u32 cur_cnt = poll_count;
  1031. occup = to_free = REG_RD(bp, regs->lines_occup);
  1032. freed = freed_start = REG_RD(bp, regs->lines_freed);
  1033. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n", regs->pN, occup);
  1034. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n", regs->pN, freed);
  1035. while (occup && ((u32)SUB_S32(freed, freed_start) < to_free)) {
  1036. if (cur_cnt--) {
  1037. udelay(FLR_WAIT_INTERVAL);
  1038. occup = REG_RD(bp, regs->lines_occup);
  1039. freed = REG_RD(bp, regs->lines_freed);
  1040. } else {
  1041. DP(BNX2X_MSG_SP, "PBF cmd queue[%d] timed out\n",
  1042. regs->pN);
  1043. DP(BNX2X_MSG_SP, "OCCUPANCY[%d] : s:%x\n",
  1044. regs->pN, occup);
  1045. DP(BNX2X_MSG_SP, "LINES_FREED[%d] : s:%x\n",
  1046. regs->pN, freed);
  1047. break;
  1048. }
  1049. }
  1050. DP(BNX2X_MSG_SP, "Waited %d*%d usec for PBF cmd queue[%d]\n",
  1051. poll_count-cur_cnt, FLR_WAIT_INTERVAL, regs->pN);
  1052. }
  1053. static u32 bnx2x_flr_clnup_reg_poll(struct bnx2x *bp, u32 reg,
  1054. u32 expected, u32 poll_count)
  1055. {
  1056. u32 cur_cnt = poll_count;
  1057. u32 val;
  1058. while ((val = REG_RD(bp, reg)) != expected && cur_cnt--)
  1059. udelay(FLR_WAIT_INTERVAL);
  1060. return val;
  1061. }
  1062. int bnx2x_flr_clnup_poll_hw_counter(struct bnx2x *bp, u32 reg,
  1063. char *msg, u32 poll_cnt)
  1064. {
  1065. u32 val = bnx2x_flr_clnup_reg_poll(bp, reg, 0, poll_cnt);
  1066. if (val != 0) {
  1067. BNX2X_ERR("%s usage count=%d\n", msg, val);
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. /* Common routines with VF FLR cleanup */
  1073. u32 bnx2x_flr_clnup_poll_count(struct bnx2x *bp)
  1074. {
  1075. /* adjust polling timeout */
  1076. if (CHIP_REV_IS_EMUL(bp))
  1077. return FLR_POLL_CNT * 2000;
  1078. if (CHIP_REV_IS_FPGA(bp))
  1079. return FLR_POLL_CNT * 120;
  1080. return FLR_POLL_CNT;
  1081. }
  1082. void bnx2x_tx_hw_flushed(struct bnx2x *bp, u32 poll_count)
  1083. {
  1084. struct pbf_pN_cmd_regs cmd_regs[] = {
  1085. {0, (CHIP_IS_E3B0(bp)) ?
  1086. PBF_REG_TQ_OCCUPANCY_Q0 :
  1087. PBF_REG_P0_TQ_OCCUPANCY,
  1088. (CHIP_IS_E3B0(bp)) ?
  1089. PBF_REG_TQ_LINES_FREED_CNT_Q0 :
  1090. PBF_REG_P0_TQ_LINES_FREED_CNT},
  1091. {1, (CHIP_IS_E3B0(bp)) ?
  1092. PBF_REG_TQ_OCCUPANCY_Q1 :
  1093. PBF_REG_P1_TQ_OCCUPANCY,
  1094. (CHIP_IS_E3B0(bp)) ?
  1095. PBF_REG_TQ_LINES_FREED_CNT_Q1 :
  1096. PBF_REG_P1_TQ_LINES_FREED_CNT},
  1097. {4, (CHIP_IS_E3B0(bp)) ?
  1098. PBF_REG_TQ_OCCUPANCY_LB_Q :
  1099. PBF_REG_P4_TQ_OCCUPANCY,
  1100. (CHIP_IS_E3B0(bp)) ?
  1101. PBF_REG_TQ_LINES_FREED_CNT_LB_Q :
  1102. PBF_REG_P4_TQ_LINES_FREED_CNT}
  1103. };
  1104. struct pbf_pN_buf_regs buf_regs[] = {
  1105. {0, (CHIP_IS_E3B0(bp)) ?
  1106. PBF_REG_INIT_CRD_Q0 :
  1107. PBF_REG_P0_INIT_CRD ,
  1108. (CHIP_IS_E3B0(bp)) ?
  1109. PBF_REG_CREDIT_Q0 :
  1110. PBF_REG_P0_CREDIT,
  1111. (CHIP_IS_E3B0(bp)) ?
  1112. PBF_REG_INTERNAL_CRD_FREED_CNT_Q0 :
  1113. PBF_REG_P0_INTERNAL_CRD_FREED_CNT},
  1114. {1, (CHIP_IS_E3B0(bp)) ?
  1115. PBF_REG_INIT_CRD_Q1 :
  1116. PBF_REG_P1_INIT_CRD,
  1117. (CHIP_IS_E3B0(bp)) ?
  1118. PBF_REG_CREDIT_Q1 :
  1119. PBF_REG_P1_CREDIT,
  1120. (CHIP_IS_E3B0(bp)) ?
  1121. PBF_REG_INTERNAL_CRD_FREED_CNT_Q1 :
  1122. PBF_REG_P1_INTERNAL_CRD_FREED_CNT},
  1123. {4, (CHIP_IS_E3B0(bp)) ?
  1124. PBF_REG_INIT_CRD_LB_Q :
  1125. PBF_REG_P4_INIT_CRD,
  1126. (CHIP_IS_E3B0(bp)) ?
  1127. PBF_REG_CREDIT_LB_Q :
  1128. PBF_REG_P4_CREDIT,
  1129. (CHIP_IS_E3B0(bp)) ?
  1130. PBF_REG_INTERNAL_CRD_FREED_CNT_LB_Q :
  1131. PBF_REG_P4_INTERNAL_CRD_FREED_CNT},
  1132. };
  1133. int i;
  1134. /* Verify the command queues are flushed P0, P1, P4 */
  1135. for (i = 0; i < ARRAY_SIZE(cmd_regs); i++)
  1136. bnx2x_pbf_pN_cmd_flushed(bp, &cmd_regs[i], poll_count);
  1137. /* Verify the transmission buffers are flushed P0, P1, P4 */
  1138. for (i = 0; i < ARRAY_SIZE(buf_regs); i++)
  1139. bnx2x_pbf_pN_buf_flushed(bp, &buf_regs[i], poll_count);
  1140. }
  1141. #define OP_GEN_PARAM(param) \
  1142. (((param) << SDM_OP_GEN_COMP_PARAM_SHIFT) & SDM_OP_GEN_COMP_PARAM)
  1143. #define OP_GEN_TYPE(type) \
  1144. (((type) << SDM_OP_GEN_COMP_TYPE_SHIFT) & SDM_OP_GEN_COMP_TYPE)
  1145. #define OP_GEN_AGG_VECT(index) \
  1146. (((index) << SDM_OP_GEN_AGG_VECT_IDX_SHIFT) & SDM_OP_GEN_AGG_VECT_IDX)
  1147. int bnx2x_send_final_clnup(struct bnx2x *bp, u8 clnup_func, u32 poll_cnt)
  1148. {
  1149. u32 op_gen_command = 0;
  1150. u32 comp_addr = BAR_CSTRORM_INTMEM +
  1151. CSTORM_FINAL_CLEANUP_COMPLETE_OFFSET(clnup_func);
  1152. int ret = 0;
  1153. if (REG_RD(bp, comp_addr)) {
  1154. BNX2X_ERR("Cleanup complete was not 0 before sending\n");
  1155. return 1;
  1156. }
  1157. op_gen_command |= OP_GEN_PARAM(XSTORM_AGG_INT_FINAL_CLEANUP_INDEX);
  1158. op_gen_command |= OP_GEN_TYPE(XSTORM_AGG_INT_FINAL_CLEANUP_COMP_TYPE);
  1159. op_gen_command |= OP_GEN_AGG_VECT(clnup_func);
  1160. op_gen_command |= 1 << SDM_OP_GEN_AGG_VECT_IDX_VALID_SHIFT;
  1161. DP(BNX2X_MSG_SP, "sending FW Final cleanup\n");
  1162. REG_WR(bp, XSDM_REG_OPERATION_GEN, op_gen_command);
  1163. if (bnx2x_flr_clnup_reg_poll(bp, comp_addr, 1, poll_cnt) != 1) {
  1164. BNX2X_ERR("FW final cleanup did not succeed\n");
  1165. DP(BNX2X_MSG_SP, "At timeout completion address contained %x\n",
  1166. (REG_RD(bp, comp_addr)));
  1167. bnx2x_panic();
  1168. return 1;
  1169. }
  1170. /* Zero completion for next FLR */
  1171. REG_WR(bp, comp_addr, 0);
  1172. return ret;
  1173. }
  1174. u8 bnx2x_is_pcie_pending(struct pci_dev *dev)
  1175. {
  1176. u16 status;
  1177. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  1178. return status & PCI_EXP_DEVSTA_TRPND;
  1179. }
  1180. /* PF FLR specific routines
  1181. */
  1182. static int bnx2x_poll_hw_usage_counters(struct bnx2x *bp, u32 poll_cnt)
  1183. {
  1184. /* wait for CFC PF usage-counter to zero (includes all the VFs) */
  1185. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1186. CFC_REG_NUM_LCIDS_INSIDE_PF,
  1187. "CFC PF usage counter timed out",
  1188. poll_cnt))
  1189. return 1;
  1190. /* Wait for DQ PF usage-counter to zero (until DQ cleanup) */
  1191. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1192. DORQ_REG_PF_USAGE_CNT,
  1193. "DQ PF usage counter timed out",
  1194. poll_cnt))
  1195. return 1;
  1196. /* Wait for QM PF usage-counter to zero (until DQ cleanup) */
  1197. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1198. QM_REG_PF_USG_CNT_0 + 4*BP_FUNC(bp),
  1199. "QM PF usage counter timed out",
  1200. poll_cnt))
  1201. return 1;
  1202. /* Wait for Timer PF usage-counters to zero (until DQ cleanup) */
  1203. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1204. TM_REG_LIN0_VNIC_UC + 4*BP_PORT(bp),
  1205. "Timers VNIC usage counter timed out",
  1206. poll_cnt))
  1207. return 1;
  1208. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1209. TM_REG_LIN0_NUM_SCANS + 4*BP_PORT(bp),
  1210. "Timers NUM_SCANS usage counter timed out",
  1211. poll_cnt))
  1212. return 1;
  1213. /* Wait DMAE PF usage counter to zero */
  1214. if (bnx2x_flr_clnup_poll_hw_counter(bp,
  1215. dmae_reg_go_c[INIT_DMAE_C(bp)],
  1216. "DMAE command register timed out",
  1217. poll_cnt))
  1218. return 1;
  1219. return 0;
  1220. }
  1221. static void bnx2x_hw_enable_status(struct bnx2x *bp)
  1222. {
  1223. u32 val;
  1224. val = REG_RD(bp, CFC_REG_WEAK_ENABLE_PF);
  1225. DP(BNX2X_MSG_SP, "CFC_REG_WEAK_ENABLE_PF is 0x%x\n", val);
  1226. val = REG_RD(bp, PBF_REG_DISABLE_PF);
  1227. DP(BNX2X_MSG_SP, "PBF_REG_DISABLE_PF is 0x%x\n", val);
  1228. val = REG_RD(bp, IGU_REG_PCI_PF_MSI_EN);
  1229. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSI_EN is 0x%x\n", val);
  1230. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_EN);
  1231. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_EN is 0x%x\n", val);
  1232. val = REG_RD(bp, IGU_REG_PCI_PF_MSIX_FUNC_MASK);
  1233. DP(BNX2X_MSG_SP, "IGU_REG_PCI_PF_MSIX_FUNC_MASK is 0x%x\n", val);
  1234. val = REG_RD(bp, PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR);
  1235. DP(BNX2X_MSG_SP, "PGLUE_B_REG_SHADOW_BME_PF_7_0_CLR is 0x%x\n", val);
  1236. val = REG_RD(bp, PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR);
  1237. DP(BNX2X_MSG_SP, "PGLUE_B_REG_FLR_REQUEST_PF_7_0_CLR is 0x%x\n", val);
  1238. val = REG_RD(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER);
  1239. DP(BNX2X_MSG_SP, "PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER is 0x%x\n",
  1240. val);
  1241. }
  1242. static int bnx2x_pf_flr_clnup(struct bnx2x *bp)
  1243. {
  1244. u32 poll_cnt = bnx2x_flr_clnup_poll_count(bp);
  1245. DP(BNX2X_MSG_SP, "Cleanup after FLR PF[%d]\n", BP_ABS_FUNC(bp));
  1246. /* Re-enable PF target read access */
  1247. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  1248. /* Poll HW usage counters */
  1249. DP(BNX2X_MSG_SP, "Polling usage counters\n");
  1250. if (bnx2x_poll_hw_usage_counters(bp, poll_cnt))
  1251. return -EBUSY;
  1252. /* Zero the igu 'trailing edge' and 'leading edge' */
  1253. /* Send the FW cleanup command */
  1254. if (bnx2x_send_final_clnup(bp, (u8)BP_FUNC(bp), poll_cnt))
  1255. return -EBUSY;
  1256. /* ATC cleanup */
  1257. /* Verify TX hw is flushed */
  1258. bnx2x_tx_hw_flushed(bp, poll_cnt);
  1259. /* Wait 100ms (not adjusted according to platform) */
  1260. msleep(100);
  1261. /* Verify no pending pci transactions */
  1262. if (bnx2x_is_pcie_pending(bp->pdev))
  1263. BNX2X_ERR("PCIE Transactions still pending\n");
  1264. /* Debug */
  1265. bnx2x_hw_enable_status(bp);
  1266. /*
  1267. * Master enable - Due to WB DMAE writes performed before this
  1268. * register is re-initialized as part of the regular function init
  1269. */
  1270. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  1271. return 0;
  1272. }
  1273. static void bnx2x_hc_int_enable(struct bnx2x *bp)
  1274. {
  1275. int port = BP_PORT(bp);
  1276. u32 addr = port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0;
  1277. u32 val = REG_RD(bp, addr);
  1278. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1279. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1280. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1281. if (msix) {
  1282. val &= ~(HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1283. HC_CONFIG_0_REG_INT_LINE_EN_0);
  1284. val |= (HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1285. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1286. if (single_msix)
  1287. val |= HC_CONFIG_0_REG_SINGLE_ISR_EN_0;
  1288. } else if (msi) {
  1289. val &= ~HC_CONFIG_0_REG_INT_LINE_EN_0;
  1290. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1291. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1292. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1293. } else {
  1294. val |= (HC_CONFIG_0_REG_SINGLE_ISR_EN_0 |
  1295. HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0 |
  1296. HC_CONFIG_0_REG_INT_LINE_EN_0 |
  1297. HC_CONFIG_0_REG_ATTN_BIT_EN_0);
  1298. if (!CHIP_IS_E1(bp)) {
  1299. DP(NETIF_MSG_IFUP,
  1300. "write %x to HC %d (addr 0x%x)\n", val, port, addr);
  1301. REG_WR(bp, addr, val);
  1302. val &= ~HC_CONFIG_0_REG_MSI_MSIX_INT_EN_0;
  1303. }
  1304. }
  1305. if (CHIP_IS_E1(bp))
  1306. REG_WR(bp, HC_REG_INT_MASK + port*4, 0x1FFFF);
  1307. DP(NETIF_MSG_IFUP,
  1308. "write %x to HC %d (addr 0x%x) mode %s\n", val, port, addr,
  1309. (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1310. REG_WR(bp, addr, val);
  1311. /*
  1312. * Ensure that HC_CONFIG is written before leading/trailing edge config
  1313. */
  1314. mmiowb();
  1315. barrier();
  1316. if (!CHIP_IS_E1(bp)) {
  1317. /* init leading/trailing edge */
  1318. if (IS_MF(bp)) {
  1319. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1320. if (bp->port.pmf)
  1321. /* enable nig and gpio3 attention */
  1322. val |= 0x1100;
  1323. } else
  1324. val = 0xffff;
  1325. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  1326. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  1327. }
  1328. /* Make sure that interrupts are indeed enabled from here on */
  1329. mmiowb();
  1330. }
  1331. static void bnx2x_igu_int_enable(struct bnx2x *bp)
  1332. {
  1333. u32 val;
  1334. bool msix = (bp->flags & USING_MSIX_FLAG) ? true : false;
  1335. bool single_msix = (bp->flags & USING_SINGLE_MSIX_FLAG) ? true : false;
  1336. bool msi = (bp->flags & USING_MSI_FLAG) ? true : false;
  1337. val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  1338. if (msix) {
  1339. val &= ~(IGU_PF_CONF_INT_LINE_EN |
  1340. IGU_PF_CONF_SINGLE_ISR_EN);
  1341. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1342. IGU_PF_CONF_ATTN_BIT_EN);
  1343. if (single_msix)
  1344. val |= IGU_PF_CONF_SINGLE_ISR_EN;
  1345. } else if (msi) {
  1346. val &= ~IGU_PF_CONF_INT_LINE_EN;
  1347. val |= (IGU_PF_CONF_MSI_MSIX_EN |
  1348. IGU_PF_CONF_ATTN_BIT_EN |
  1349. IGU_PF_CONF_SINGLE_ISR_EN);
  1350. } else {
  1351. val &= ~IGU_PF_CONF_MSI_MSIX_EN;
  1352. val |= (IGU_PF_CONF_INT_LINE_EN |
  1353. IGU_PF_CONF_ATTN_BIT_EN |
  1354. IGU_PF_CONF_SINGLE_ISR_EN);
  1355. }
  1356. /* Clean previous status - need to configure igu prior to ack*/
  1357. if ((!msix) || single_msix) {
  1358. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1359. bnx2x_ack_int(bp);
  1360. }
  1361. val |= IGU_PF_CONF_FUNC_EN;
  1362. DP(NETIF_MSG_IFUP, "write 0x%x to IGU mode %s\n",
  1363. val, (msix ? "MSI-X" : (msi ? "MSI" : "INTx")));
  1364. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  1365. if (val & IGU_PF_CONF_INT_LINE_EN)
  1366. pci_intx(bp->pdev, true);
  1367. barrier();
  1368. /* init leading/trailing edge */
  1369. if (IS_MF(bp)) {
  1370. val = (0xee0f | (1 << (BP_VN(bp) + 4)));
  1371. if (bp->port.pmf)
  1372. /* enable nig and gpio3 attention */
  1373. val |= 0x1100;
  1374. } else
  1375. val = 0xffff;
  1376. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  1377. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  1378. /* Make sure that interrupts are indeed enabled from here on */
  1379. mmiowb();
  1380. }
  1381. void bnx2x_int_enable(struct bnx2x *bp)
  1382. {
  1383. if (bp->common.int_block == INT_BLOCK_HC)
  1384. bnx2x_hc_int_enable(bp);
  1385. else
  1386. bnx2x_igu_int_enable(bp);
  1387. }
  1388. void bnx2x_int_disable_sync(struct bnx2x *bp, int disable_hw)
  1389. {
  1390. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  1391. int i, offset;
  1392. if (disable_hw)
  1393. /* prevent the HW from sending interrupts */
  1394. bnx2x_int_disable(bp);
  1395. /* make sure all ISRs are done */
  1396. if (msix) {
  1397. synchronize_irq(bp->msix_table[0].vector);
  1398. offset = 1;
  1399. if (CNIC_SUPPORT(bp))
  1400. offset++;
  1401. for_each_eth_queue(bp, i)
  1402. synchronize_irq(bp->msix_table[offset++].vector);
  1403. } else
  1404. synchronize_irq(bp->pdev->irq);
  1405. /* make sure sp_task is not running */
  1406. cancel_delayed_work(&bp->sp_task);
  1407. cancel_delayed_work(&bp->period_task);
  1408. flush_workqueue(bnx2x_wq);
  1409. }
  1410. /* fast path */
  1411. /*
  1412. * General service functions
  1413. */
  1414. /* Return true if succeeded to acquire the lock */
  1415. static bool bnx2x_trylock_hw_lock(struct bnx2x *bp, u32 resource)
  1416. {
  1417. u32 lock_status;
  1418. u32 resource_bit = (1 << resource);
  1419. int func = BP_FUNC(bp);
  1420. u32 hw_lock_control_reg;
  1421. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1422. "Trying to take a lock on resource %d\n", resource);
  1423. /* Validating that the resource is within range */
  1424. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1425. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1426. "resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1427. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1428. return false;
  1429. }
  1430. if (func <= 5)
  1431. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1432. else
  1433. hw_lock_control_reg =
  1434. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1435. /* Try to acquire the lock */
  1436. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1437. lock_status = REG_RD(bp, hw_lock_control_reg);
  1438. if (lock_status & resource_bit)
  1439. return true;
  1440. DP(NETIF_MSG_HW | NETIF_MSG_IFUP,
  1441. "Failed to get a lock on resource %d\n", resource);
  1442. return false;
  1443. }
  1444. /**
  1445. * bnx2x_get_leader_lock_resource - get the recovery leader resource id
  1446. *
  1447. * @bp: driver handle
  1448. *
  1449. * Returns the recovery leader resource id according to the engine this function
  1450. * belongs to. Currently only only 2 engines is supported.
  1451. */
  1452. static int bnx2x_get_leader_lock_resource(struct bnx2x *bp)
  1453. {
  1454. if (BP_PATH(bp))
  1455. return HW_LOCK_RESOURCE_RECOVERY_LEADER_1;
  1456. else
  1457. return HW_LOCK_RESOURCE_RECOVERY_LEADER_0;
  1458. }
  1459. /**
  1460. * bnx2x_trylock_leader_lock- try to acquire a leader lock.
  1461. *
  1462. * @bp: driver handle
  1463. *
  1464. * Tries to acquire a leader lock for current engine.
  1465. */
  1466. static bool bnx2x_trylock_leader_lock(struct bnx2x *bp)
  1467. {
  1468. return bnx2x_trylock_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1469. }
  1470. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err);
  1471. /* schedule the sp task and mark that interrupt occurred (runs from ISR) */
  1472. static int bnx2x_schedule_sp_task(struct bnx2x *bp)
  1473. {
  1474. /* Set the interrupt occurred bit for the sp-task to recognize it
  1475. * must ack the interrupt and transition according to the IGU
  1476. * state machine.
  1477. */
  1478. atomic_set(&bp->interrupt_occurred, 1);
  1479. /* The sp_task must execute only after this bit
  1480. * is set, otherwise we will get out of sync and miss all
  1481. * further interrupts. Hence, the barrier.
  1482. */
  1483. smp_wmb();
  1484. /* schedule sp_task to workqueue */
  1485. return queue_delayed_work(bnx2x_wq, &bp->sp_task, 0);
  1486. }
  1487. void bnx2x_sp_event(struct bnx2x_fastpath *fp, union eth_rx_cqe *rr_cqe)
  1488. {
  1489. struct bnx2x *bp = fp->bp;
  1490. int cid = SW_CID(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1491. int command = CQE_CMD(rr_cqe->ramrod_cqe.conn_and_cmd_data);
  1492. enum bnx2x_queue_cmd drv_cmd = BNX2X_Q_CMD_MAX;
  1493. struct bnx2x_queue_sp_obj *q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  1494. DP(BNX2X_MSG_SP,
  1495. "fp %d cid %d got ramrod #%d state is %x type is %d\n",
  1496. fp->index, cid, command, bp->state,
  1497. rr_cqe->ramrod_cqe.ramrod_type);
  1498. /* If cid is within VF range, replace the slowpath object with the
  1499. * one corresponding to this VF
  1500. */
  1501. if (cid >= BNX2X_FIRST_VF_CID &&
  1502. cid < BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)
  1503. bnx2x_iov_set_queue_sp_obj(bp, cid, &q_obj);
  1504. switch (command) {
  1505. case (RAMROD_CMD_ID_ETH_CLIENT_UPDATE):
  1506. DP(BNX2X_MSG_SP, "got UPDATE ramrod. CID %d\n", cid);
  1507. drv_cmd = BNX2X_Q_CMD_UPDATE;
  1508. break;
  1509. case (RAMROD_CMD_ID_ETH_CLIENT_SETUP):
  1510. DP(BNX2X_MSG_SP, "got MULTI[%d] setup ramrod\n", cid);
  1511. drv_cmd = BNX2X_Q_CMD_SETUP;
  1512. break;
  1513. case (RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP):
  1514. DP(BNX2X_MSG_SP, "got MULTI[%d] tx-only setup ramrod\n", cid);
  1515. drv_cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  1516. break;
  1517. case (RAMROD_CMD_ID_ETH_HALT):
  1518. DP(BNX2X_MSG_SP, "got MULTI[%d] halt ramrod\n", cid);
  1519. drv_cmd = BNX2X_Q_CMD_HALT;
  1520. break;
  1521. case (RAMROD_CMD_ID_ETH_TERMINATE):
  1522. DP(BNX2X_MSG_SP, "got MULTI[%d] terminate ramrod\n", cid);
  1523. drv_cmd = BNX2X_Q_CMD_TERMINATE;
  1524. break;
  1525. case (RAMROD_CMD_ID_ETH_EMPTY):
  1526. DP(BNX2X_MSG_SP, "got MULTI[%d] empty ramrod\n", cid);
  1527. drv_cmd = BNX2X_Q_CMD_EMPTY;
  1528. break;
  1529. default:
  1530. BNX2X_ERR("unexpected MC reply (%d) on fp[%d]\n",
  1531. command, fp->index);
  1532. return;
  1533. }
  1534. if ((drv_cmd != BNX2X_Q_CMD_MAX) &&
  1535. q_obj->complete_cmd(bp, q_obj, drv_cmd))
  1536. /* q_obj->complete_cmd() failure means that this was
  1537. * an unexpected completion.
  1538. *
  1539. * In this case we don't want to increase the bp->spq_left
  1540. * because apparently we haven't sent this command the first
  1541. * place.
  1542. */
  1543. #ifdef BNX2X_STOP_ON_ERROR
  1544. bnx2x_panic();
  1545. #else
  1546. return;
  1547. #endif
  1548. /* SRIOV: reschedule any 'in_progress' operations */
  1549. bnx2x_iov_sp_event(bp, cid, true);
  1550. smp_mb__before_atomic_inc();
  1551. atomic_inc(&bp->cq_spq_left);
  1552. /* push the change in bp->spq_left and towards the memory */
  1553. smp_mb__after_atomic_inc();
  1554. DP(BNX2X_MSG_SP, "bp->cq_spq_left %x\n", atomic_read(&bp->cq_spq_left));
  1555. if ((drv_cmd == BNX2X_Q_CMD_UPDATE) && (IS_FCOE_FP(fp)) &&
  1556. (!!test_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state))) {
  1557. /* if Q update ramrod is completed for last Q in AFEX vif set
  1558. * flow, then ACK MCP at the end
  1559. *
  1560. * mark pending ACK to MCP bit.
  1561. * prevent case that both bits are cleared.
  1562. * At the end of load/unload driver checks that
  1563. * sp_state is cleared, and this order prevents
  1564. * races
  1565. */
  1566. smp_mb__before_clear_bit();
  1567. set_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK, &bp->sp_state);
  1568. wmb();
  1569. clear_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  1570. smp_mb__after_clear_bit();
  1571. /* schedule the sp task as mcp ack is required */
  1572. bnx2x_schedule_sp_task(bp);
  1573. }
  1574. return;
  1575. }
  1576. irqreturn_t bnx2x_interrupt(int irq, void *dev_instance)
  1577. {
  1578. struct bnx2x *bp = netdev_priv(dev_instance);
  1579. u16 status = bnx2x_ack_int(bp);
  1580. u16 mask;
  1581. int i;
  1582. u8 cos;
  1583. /* Return here if interrupt is shared and it's not for us */
  1584. if (unlikely(status == 0)) {
  1585. DP(NETIF_MSG_INTR, "not our interrupt!\n");
  1586. return IRQ_NONE;
  1587. }
  1588. DP(NETIF_MSG_INTR, "got an interrupt status 0x%x\n", status);
  1589. #ifdef BNX2X_STOP_ON_ERROR
  1590. if (unlikely(bp->panic))
  1591. return IRQ_HANDLED;
  1592. #endif
  1593. for_each_eth_queue(bp, i) {
  1594. struct bnx2x_fastpath *fp = &bp->fp[i];
  1595. mask = 0x2 << (fp->index + CNIC_SUPPORT(bp));
  1596. if (status & mask) {
  1597. /* Handle Rx or Tx according to SB id */
  1598. for_each_cos_in_tx_queue(fp, cos)
  1599. prefetch(fp->txdata_ptr[cos]->tx_cons_sb);
  1600. prefetch(&fp->sb_running_index[SM_RX_ID]);
  1601. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  1602. status &= ~mask;
  1603. }
  1604. }
  1605. if (CNIC_SUPPORT(bp)) {
  1606. mask = 0x2;
  1607. if (status & (mask | 0x1)) {
  1608. struct cnic_ops *c_ops = NULL;
  1609. rcu_read_lock();
  1610. c_ops = rcu_dereference(bp->cnic_ops);
  1611. if (c_ops && (bp->cnic_eth_dev.drv_state &
  1612. CNIC_DRV_STATE_HANDLES_IRQ))
  1613. c_ops->cnic_handler(bp->cnic_data, NULL);
  1614. rcu_read_unlock();
  1615. status &= ~mask;
  1616. }
  1617. }
  1618. if (unlikely(status & 0x1)) {
  1619. /* schedule sp task to perform default status block work, ack
  1620. * attentions and enable interrupts.
  1621. */
  1622. bnx2x_schedule_sp_task(bp);
  1623. status &= ~0x1;
  1624. if (!status)
  1625. return IRQ_HANDLED;
  1626. }
  1627. if (unlikely(status))
  1628. DP(NETIF_MSG_INTR, "got an unknown interrupt! (status 0x%x)\n",
  1629. status);
  1630. return IRQ_HANDLED;
  1631. }
  1632. /* Link */
  1633. /*
  1634. * General service functions
  1635. */
  1636. int bnx2x_acquire_hw_lock(struct bnx2x *bp, u32 resource)
  1637. {
  1638. u32 lock_status;
  1639. u32 resource_bit = (1 << resource);
  1640. int func = BP_FUNC(bp);
  1641. u32 hw_lock_control_reg;
  1642. int cnt;
  1643. /* Validating that the resource is within range */
  1644. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1645. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1646. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1647. return -EINVAL;
  1648. }
  1649. if (func <= 5) {
  1650. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1651. } else {
  1652. hw_lock_control_reg =
  1653. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1654. }
  1655. /* Validating that the resource is not already taken */
  1656. lock_status = REG_RD(bp, hw_lock_control_reg);
  1657. if (lock_status & resource_bit) {
  1658. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x\n",
  1659. lock_status, resource_bit);
  1660. return -EEXIST;
  1661. }
  1662. /* Try for 5 second every 5ms */
  1663. for (cnt = 0; cnt < 1000; cnt++) {
  1664. /* Try to acquire the lock */
  1665. REG_WR(bp, hw_lock_control_reg + 4, resource_bit);
  1666. lock_status = REG_RD(bp, hw_lock_control_reg);
  1667. if (lock_status & resource_bit)
  1668. return 0;
  1669. usleep_range(5000, 10000);
  1670. }
  1671. BNX2X_ERR("Timeout\n");
  1672. return -EAGAIN;
  1673. }
  1674. int bnx2x_release_leader_lock(struct bnx2x *bp)
  1675. {
  1676. return bnx2x_release_hw_lock(bp, bnx2x_get_leader_lock_resource(bp));
  1677. }
  1678. int bnx2x_release_hw_lock(struct bnx2x *bp, u32 resource)
  1679. {
  1680. u32 lock_status;
  1681. u32 resource_bit = (1 << resource);
  1682. int func = BP_FUNC(bp);
  1683. u32 hw_lock_control_reg;
  1684. /* Validating that the resource is within range */
  1685. if (resource > HW_LOCK_MAX_RESOURCE_VALUE) {
  1686. BNX2X_ERR("resource(0x%x) > HW_LOCK_MAX_RESOURCE_VALUE(0x%x)\n",
  1687. resource, HW_LOCK_MAX_RESOURCE_VALUE);
  1688. return -EINVAL;
  1689. }
  1690. if (func <= 5) {
  1691. hw_lock_control_reg = (MISC_REG_DRIVER_CONTROL_1 + func*8);
  1692. } else {
  1693. hw_lock_control_reg =
  1694. (MISC_REG_DRIVER_CONTROL_7 + (func - 6)*8);
  1695. }
  1696. /* Validating that the resource is currently taken */
  1697. lock_status = REG_RD(bp, hw_lock_control_reg);
  1698. if (!(lock_status & resource_bit)) {
  1699. BNX2X_ERR("lock_status 0x%x resource_bit 0x%x. Unlock was called but lock wasn't taken!\n",
  1700. lock_status, resource_bit);
  1701. return -EFAULT;
  1702. }
  1703. REG_WR(bp, hw_lock_control_reg, resource_bit);
  1704. return 0;
  1705. }
  1706. int bnx2x_get_gpio(struct bnx2x *bp, int gpio_num, u8 port)
  1707. {
  1708. /* The GPIO should be swapped if swap register is set and active */
  1709. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1710. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1711. int gpio_shift = gpio_num +
  1712. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1713. u32 gpio_mask = (1 << gpio_shift);
  1714. u32 gpio_reg;
  1715. int value;
  1716. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1717. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1718. return -EINVAL;
  1719. }
  1720. /* read GPIO value */
  1721. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1722. /* get the requested pin value */
  1723. if ((gpio_reg & gpio_mask) == gpio_mask)
  1724. value = 1;
  1725. else
  1726. value = 0;
  1727. DP(NETIF_MSG_LINK, "pin %d value 0x%x\n", gpio_num, value);
  1728. return value;
  1729. }
  1730. int bnx2x_set_gpio(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1731. {
  1732. /* The GPIO should be swapped if swap register is set and active */
  1733. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1734. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1735. int gpio_shift = gpio_num +
  1736. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1737. u32 gpio_mask = (1 << gpio_shift);
  1738. u32 gpio_reg;
  1739. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1740. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1741. return -EINVAL;
  1742. }
  1743. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1744. /* read GPIO and mask except the float bits */
  1745. gpio_reg = (REG_RD(bp, MISC_REG_GPIO) & MISC_REGISTERS_GPIO_FLOAT);
  1746. switch (mode) {
  1747. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1748. DP(NETIF_MSG_LINK,
  1749. "Set GPIO %d (shift %d) -> output low\n",
  1750. gpio_num, gpio_shift);
  1751. /* clear FLOAT and set CLR */
  1752. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1753. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_CLR_POS);
  1754. break;
  1755. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1756. DP(NETIF_MSG_LINK,
  1757. "Set GPIO %d (shift %d) -> output high\n",
  1758. gpio_num, gpio_shift);
  1759. /* clear FLOAT and set SET */
  1760. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1761. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_SET_POS);
  1762. break;
  1763. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1764. DP(NETIF_MSG_LINK,
  1765. "Set GPIO %d (shift %d) -> input\n",
  1766. gpio_num, gpio_shift);
  1767. /* set FLOAT */
  1768. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_FLOAT_POS);
  1769. break;
  1770. default:
  1771. break;
  1772. }
  1773. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1774. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1775. return 0;
  1776. }
  1777. int bnx2x_set_mult_gpio(struct bnx2x *bp, u8 pins, u32 mode)
  1778. {
  1779. u32 gpio_reg = 0;
  1780. int rc = 0;
  1781. /* Any port swapping should be handled by caller. */
  1782. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1783. /* read GPIO and mask except the float bits */
  1784. gpio_reg = REG_RD(bp, MISC_REG_GPIO);
  1785. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1786. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_CLR_POS);
  1787. gpio_reg &= ~(pins << MISC_REGISTERS_GPIO_SET_POS);
  1788. switch (mode) {
  1789. case MISC_REGISTERS_GPIO_OUTPUT_LOW:
  1790. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output low\n", pins);
  1791. /* set CLR */
  1792. gpio_reg |= (pins << MISC_REGISTERS_GPIO_CLR_POS);
  1793. break;
  1794. case MISC_REGISTERS_GPIO_OUTPUT_HIGH:
  1795. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> output high\n", pins);
  1796. /* set SET */
  1797. gpio_reg |= (pins << MISC_REGISTERS_GPIO_SET_POS);
  1798. break;
  1799. case MISC_REGISTERS_GPIO_INPUT_HI_Z:
  1800. DP(NETIF_MSG_LINK, "Set GPIO 0x%x -> input\n", pins);
  1801. /* set FLOAT */
  1802. gpio_reg |= (pins << MISC_REGISTERS_GPIO_FLOAT_POS);
  1803. break;
  1804. default:
  1805. BNX2X_ERR("Invalid GPIO mode assignment %d\n", mode);
  1806. rc = -EINVAL;
  1807. break;
  1808. }
  1809. if (rc == 0)
  1810. REG_WR(bp, MISC_REG_GPIO, gpio_reg);
  1811. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1812. return rc;
  1813. }
  1814. int bnx2x_set_gpio_int(struct bnx2x *bp, int gpio_num, u32 mode, u8 port)
  1815. {
  1816. /* The GPIO should be swapped if swap register is set and active */
  1817. int gpio_port = (REG_RD(bp, NIG_REG_PORT_SWAP) &&
  1818. REG_RD(bp, NIG_REG_STRAP_OVERRIDE)) ^ port;
  1819. int gpio_shift = gpio_num +
  1820. (gpio_port ? MISC_REGISTERS_GPIO_PORT_SHIFT : 0);
  1821. u32 gpio_mask = (1 << gpio_shift);
  1822. u32 gpio_reg;
  1823. if (gpio_num > MISC_REGISTERS_GPIO_3) {
  1824. BNX2X_ERR("Invalid GPIO %d\n", gpio_num);
  1825. return -EINVAL;
  1826. }
  1827. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1828. /* read GPIO int */
  1829. gpio_reg = REG_RD(bp, MISC_REG_GPIO_INT);
  1830. switch (mode) {
  1831. case MISC_REGISTERS_GPIO_INT_OUTPUT_CLR:
  1832. DP(NETIF_MSG_LINK,
  1833. "Clear GPIO INT %d (shift %d) -> output low\n",
  1834. gpio_num, gpio_shift);
  1835. /* clear SET and set CLR */
  1836. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1837. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1838. break;
  1839. case MISC_REGISTERS_GPIO_INT_OUTPUT_SET:
  1840. DP(NETIF_MSG_LINK,
  1841. "Set GPIO INT %d (shift %d) -> output high\n",
  1842. gpio_num, gpio_shift);
  1843. /* clear CLR and set SET */
  1844. gpio_reg &= ~(gpio_mask << MISC_REGISTERS_GPIO_INT_CLR_POS);
  1845. gpio_reg |= (gpio_mask << MISC_REGISTERS_GPIO_INT_SET_POS);
  1846. break;
  1847. default:
  1848. break;
  1849. }
  1850. REG_WR(bp, MISC_REG_GPIO_INT, gpio_reg);
  1851. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_GPIO);
  1852. return 0;
  1853. }
  1854. static int bnx2x_set_spio(struct bnx2x *bp, int spio, u32 mode)
  1855. {
  1856. u32 spio_reg;
  1857. /* Only 2 SPIOs are configurable */
  1858. if ((spio != MISC_SPIO_SPIO4) && (spio != MISC_SPIO_SPIO5)) {
  1859. BNX2X_ERR("Invalid SPIO 0x%x\n", spio);
  1860. return -EINVAL;
  1861. }
  1862. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1863. /* read SPIO and mask except the float bits */
  1864. spio_reg = (REG_RD(bp, MISC_REG_SPIO) & MISC_SPIO_FLOAT);
  1865. switch (mode) {
  1866. case MISC_SPIO_OUTPUT_LOW:
  1867. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output low\n", spio);
  1868. /* clear FLOAT and set CLR */
  1869. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1870. spio_reg |= (spio << MISC_SPIO_CLR_POS);
  1871. break;
  1872. case MISC_SPIO_OUTPUT_HIGH:
  1873. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> output high\n", spio);
  1874. /* clear FLOAT and set SET */
  1875. spio_reg &= ~(spio << MISC_SPIO_FLOAT_POS);
  1876. spio_reg |= (spio << MISC_SPIO_SET_POS);
  1877. break;
  1878. case MISC_SPIO_INPUT_HI_Z:
  1879. DP(NETIF_MSG_HW, "Set SPIO 0x%x -> input\n", spio);
  1880. /* set FLOAT */
  1881. spio_reg |= (spio << MISC_SPIO_FLOAT_POS);
  1882. break;
  1883. default:
  1884. break;
  1885. }
  1886. REG_WR(bp, MISC_REG_SPIO, spio_reg);
  1887. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_SPIO);
  1888. return 0;
  1889. }
  1890. void bnx2x_calc_fc_adv(struct bnx2x *bp)
  1891. {
  1892. u8 cfg_idx = bnx2x_get_link_cfg_idx(bp);
  1893. switch (bp->link_vars.ieee_fc &
  1894. MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_MASK) {
  1895. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_NONE:
  1896. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1897. ADVERTISED_Pause);
  1898. break;
  1899. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_BOTH:
  1900. bp->port.advertising[cfg_idx] |= (ADVERTISED_Asym_Pause |
  1901. ADVERTISED_Pause);
  1902. break;
  1903. case MDIO_COMBO_IEEE0_AUTO_NEG_ADV_PAUSE_ASYMMETRIC:
  1904. bp->port.advertising[cfg_idx] |= ADVERTISED_Asym_Pause;
  1905. break;
  1906. default:
  1907. bp->port.advertising[cfg_idx] &= ~(ADVERTISED_Asym_Pause |
  1908. ADVERTISED_Pause);
  1909. break;
  1910. }
  1911. }
  1912. static void bnx2x_set_requested_fc(struct bnx2x *bp)
  1913. {
  1914. /* Initialize link parameters structure variables
  1915. * It is recommended to turn off RX FC for jumbo frames
  1916. * for better performance
  1917. */
  1918. if (CHIP_IS_E1x(bp) && (bp->dev->mtu > 5000))
  1919. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_TX;
  1920. else
  1921. bp->link_params.req_fc_auto_adv = BNX2X_FLOW_CTRL_BOTH;
  1922. }
  1923. int bnx2x_initial_phy_init(struct bnx2x *bp, int load_mode)
  1924. {
  1925. int rc, cfx_idx = bnx2x_get_link_cfg_idx(bp);
  1926. u16 req_line_speed = bp->link_params.req_line_speed[cfx_idx];
  1927. if (!BP_NOMCP(bp)) {
  1928. bnx2x_set_requested_fc(bp);
  1929. bnx2x_acquire_phy_lock(bp);
  1930. if (load_mode == LOAD_DIAG) {
  1931. struct link_params *lp = &bp->link_params;
  1932. lp->loopback_mode = LOOPBACK_XGXS;
  1933. /* do PHY loopback at 10G speed, if possible */
  1934. if (lp->req_line_speed[cfx_idx] < SPEED_10000) {
  1935. if (lp->speed_cap_mask[cfx_idx] &
  1936. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G)
  1937. lp->req_line_speed[cfx_idx] =
  1938. SPEED_10000;
  1939. else
  1940. lp->req_line_speed[cfx_idx] =
  1941. SPEED_1000;
  1942. }
  1943. }
  1944. if (load_mode == LOAD_LOOPBACK_EXT) {
  1945. struct link_params *lp = &bp->link_params;
  1946. lp->loopback_mode = LOOPBACK_EXT;
  1947. }
  1948. rc = bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1949. bnx2x_release_phy_lock(bp);
  1950. bnx2x_calc_fc_adv(bp);
  1951. if (bp->link_vars.link_up) {
  1952. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  1953. bnx2x_link_report(bp);
  1954. }
  1955. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  1956. bp->link_params.req_line_speed[cfx_idx] = req_line_speed;
  1957. return rc;
  1958. }
  1959. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  1960. return -EINVAL;
  1961. }
  1962. void bnx2x_link_set(struct bnx2x *bp)
  1963. {
  1964. if (!BP_NOMCP(bp)) {
  1965. bnx2x_acquire_phy_lock(bp);
  1966. bnx2x_phy_init(&bp->link_params, &bp->link_vars);
  1967. bnx2x_release_phy_lock(bp);
  1968. bnx2x_calc_fc_adv(bp);
  1969. } else
  1970. BNX2X_ERR("Bootcode is missing - can not set link\n");
  1971. }
  1972. static void bnx2x__link_reset(struct bnx2x *bp)
  1973. {
  1974. if (!BP_NOMCP(bp)) {
  1975. bnx2x_acquire_phy_lock(bp);
  1976. bnx2x_lfa_reset(&bp->link_params, &bp->link_vars);
  1977. bnx2x_release_phy_lock(bp);
  1978. } else
  1979. BNX2X_ERR("Bootcode is missing - can not reset link\n");
  1980. }
  1981. void bnx2x_force_link_reset(struct bnx2x *bp)
  1982. {
  1983. bnx2x_acquire_phy_lock(bp);
  1984. bnx2x_link_reset(&bp->link_params, &bp->link_vars, 1);
  1985. bnx2x_release_phy_lock(bp);
  1986. }
  1987. u8 bnx2x_link_test(struct bnx2x *bp, u8 is_serdes)
  1988. {
  1989. u8 rc = 0;
  1990. if (!BP_NOMCP(bp)) {
  1991. bnx2x_acquire_phy_lock(bp);
  1992. rc = bnx2x_test_link(&bp->link_params, &bp->link_vars,
  1993. is_serdes);
  1994. bnx2x_release_phy_lock(bp);
  1995. } else
  1996. BNX2X_ERR("Bootcode is missing - can not test link\n");
  1997. return rc;
  1998. }
  1999. /* Calculates the sum of vn_min_rates.
  2000. It's needed for further normalizing of the min_rates.
  2001. Returns:
  2002. sum of vn_min_rates.
  2003. or
  2004. 0 - if all the min_rates are 0.
  2005. In the later case fairness algorithm should be deactivated.
  2006. If not all min_rates are zero then those that are zeroes will be set to 1.
  2007. */
  2008. static void bnx2x_calc_vn_min(struct bnx2x *bp,
  2009. struct cmng_init_input *input)
  2010. {
  2011. int all_zero = 1;
  2012. int vn;
  2013. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2014. u32 vn_cfg = bp->mf_config[vn];
  2015. u32 vn_min_rate = ((vn_cfg & FUNC_MF_CFG_MIN_BW_MASK) >>
  2016. FUNC_MF_CFG_MIN_BW_SHIFT) * 100;
  2017. /* Skip hidden vns */
  2018. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2019. vn_min_rate = 0;
  2020. /* If min rate is zero - set it to 1 */
  2021. else if (!vn_min_rate)
  2022. vn_min_rate = DEF_MIN_RATE;
  2023. else
  2024. all_zero = 0;
  2025. input->vnic_min_rate[vn] = vn_min_rate;
  2026. }
  2027. /* if ETS or all min rates are zeros - disable fairness */
  2028. if (BNX2X_IS_ETS_ENABLED(bp)) {
  2029. input->flags.cmng_enables &=
  2030. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2031. DP(NETIF_MSG_IFUP, "Fairness will be disabled due to ETS\n");
  2032. } else if (all_zero) {
  2033. input->flags.cmng_enables &=
  2034. ~CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2035. DP(NETIF_MSG_IFUP,
  2036. "All MIN values are zeroes fairness will be disabled\n");
  2037. } else
  2038. input->flags.cmng_enables |=
  2039. CMNG_FLAGS_PER_PORT_FAIRNESS_VN;
  2040. }
  2041. static void bnx2x_calc_vn_max(struct bnx2x *bp, int vn,
  2042. struct cmng_init_input *input)
  2043. {
  2044. u16 vn_max_rate;
  2045. u32 vn_cfg = bp->mf_config[vn];
  2046. if (vn_cfg & FUNC_MF_CFG_FUNC_HIDE)
  2047. vn_max_rate = 0;
  2048. else {
  2049. u32 maxCfg = bnx2x_extract_max_cfg(bp, vn_cfg);
  2050. if (IS_MF_SI(bp)) {
  2051. /* maxCfg in percents of linkspeed */
  2052. vn_max_rate = (bp->link_vars.line_speed * maxCfg) / 100;
  2053. } else /* SD modes */
  2054. /* maxCfg is absolute in 100Mb units */
  2055. vn_max_rate = maxCfg * 100;
  2056. }
  2057. DP(NETIF_MSG_IFUP, "vn %d: vn_max_rate %d\n", vn, vn_max_rate);
  2058. input->vnic_max_rate[vn] = vn_max_rate;
  2059. }
  2060. static int bnx2x_get_cmng_fns_mode(struct bnx2x *bp)
  2061. {
  2062. if (CHIP_REV_IS_SLOW(bp))
  2063. return CMNG_FNS_NONE;
  2064. if (IS_MF(bp))
  2065. return CMNG_FNS_MINMAX;
  2066. return CMNG_FNS_NONE;
  2067. }
  2068. void bnx2x_read_mf_cfg(struct bnx2x *bp)
  2069. {
  2070. int vn, n = (CHIP_MODE_IS_4_PORT(bp) ? 2 : 1);
  2071. if (BP_NOMCP(bp))
  2072. return; /* what should be the default value in this case */
  2073. /* For 2 port configuration the absolute function number formula
  2074. * is:
  2075. * abs_func = 2 * vn + BP_PORT + BP_PATH
  2076. *
  2077. * and there are 4 functions per port
  2078. *
  2079. * For 4 port configuration it is
  2080. * abs_func = 4 * vn + 2 * BP_PORT + BP_PATH
  2081. *
  2082. * and there are 2 functions per port
  2083. */
  2084. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2085. int /*abs*/func = n * (2 * vn + BP_PORT(bp)) + BP_PATH(bp);
  2086. if (func >= E1H_FUNC_MAX)
  2087. break;
  2088. bp->mf_config[vn] =
  2089. MF_CFG_RD(bp, func_mf_config[func].config);
  2090. }
  2091. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2092. DP(NETIF_MSG_IFUP, "mf_cfg function disabled\n");
  2093. bp->flags |= MF_FUNC_DIS;
  2094. } else {
  2095. DP(NETIF_MSG_IFUP, "mf_cfg function enabled\n");
  2096. bp->flags &= ~MF_FUNC_DIS;
  2097. }
  2098. }
  2099. static void bnx2x_cmng_fns_init(struct bnx2x *bp, u8 read_cfg, u8 cmng_type)
  2100. {
  2101. struct cmng_init_input input;
  2102. memset(&input, 0, sizeof(struct cmng_init_input));
  2103. input.port_rate = bp->link_vars.line_speed;
  2104. if (cmng_type == CMNG_FNS_MINMAX) {
  2105. int vn;
  2106. /* read mf conf from shmem */
  2107. if (read_cfg)
  2108. bnx2x_read_mf_cfg(bp);
  2109. /* vn_weight_sum and enable fairness if not 0 */
  2110. bnx2x_calc_vn_min(bp, &input);
  2111. /* calculate and set min-max rate for each vn */
  2112. if (bp->port.pmf)
  2113. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++)
  2114. bnx2x_calc_vn_max(bp, vn, &input);
  2115. /* always enable rate shaping and fairness */
  2116. input.flags.cmng_enables |=
  2117. CMNG_FLAGS_PER_PORT_RATE_SHAPING_VN;
  2118. bnx2x_init_cmng(&input, &bp->cmng);
  2119. return;
  2120. }
  2121. /* rate shaping and fairness are disabled */
  2122. DP(NETIF_MSG_IFUP,
  2123. "rate shaping and fairness are disabled\n");
  2124. }
  2125. static void storm_memset_cmng(struct bnx2x *bp,
  2126. struct cmng_init *cmng,
  2127. u8 port)
  2128. {
  2129. int vn;
  2130. size_t size = sizeof(struct cmng_struct_per_port);
  2131. u32 addr = BAR_XSTRORM_INTMEM +
  2132. XSTORM_CMNG_PER_PORT_VARS_OFFSET(port);
  2133. __storm_memset_struct(bp, addr, size, (u32 *)&cmng->port);
  2134. for (vn = VN_0; vn < BP_MAX_VN_NUM(bp); vn++) {
  2135. int func = func_by_vn(bp, vn);
  2136. addr = BAR_XSTRORM_INTMEM +
  2137. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(func);
  2138. size = sizeof(struct rate_shaping_vars_per_vn);
  2139. __storm_memset_struct(bp, addr, size,
  2140. (u32 *)&cmng->vnic.vnic_max_rate[vn]);
  2141. addr = BAR_XSTRORM_INTMEM +
  2142. XSTORM_FAIRNESS_PER_VN_VARS_OFFSET(func);
  2143. size = sizeof(struct fairness_vars_per_vn);
  2144. __storm_memset_struct(bp, addr, size,
  2145. (u32 *)&cmng->vnic.vnic_min_rate[vn]);
  2146. }
  2147. }
  2148. /* This function is called upon link interrupt */
  2149. static void bnx2x_link_attn(struct bnx2x *bp)
  2150. {
  2151. /* Make sure that we are synced with the current statistics */
  2152. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2153. bnx2x_link_update(&bp->link_params, &bp->link_vars);
  2154. if (bp->link_vars.link_up) {
  2155. /* dropless flow control */
  2156. if (!CHIP_IS_E1(bp) && bp->dropless_fc) {
  2157. int port = BP_PORT(bp);
  2158. u32 pause_enabled = 0;
  2159. if (bp->link_vars.flow_ctrl & BNX2X_FLOW_CTRL_TX)
  2160. pause_enabled = 1;
  2161. REG_WR(bp, BAR_USTRORM_INTMEM +
  2162. USTORM_ETH_PAUSE_ENABLED_OFFSET(port),
  2163. pause_enabled);
  2164. }
  2165. if (bp->link_vars.mac_type != MAC_TYPE_EMAC) {
  2166. struct host_port_stats *pstats;
  2167. pstats = bnx2x_sp(bp, port_stats);
  2168. /* reset old mac stats */
  2169. memset(&(pstats->mac_stx[0]), 0,
  2170. sizeof(struct mac_stx));
  2171. }
  2172. if (bp->state == BNX2X_STATE_OPEN)
  2173. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2174. }
  2175. if (bp->link_vars.link_up && bp->link_vars.line_speed) {
  2176. int cmng_fns = bnx2x_get_cmng_fns_mode(bp);
  2177. if (cmng_fns != CMNG_FNS_NONE) {
  2178. bnx2x_cmng_fns_init(bp, false, cmng_fns);
  2179. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2180. } else
  2181. /* rate shaping and fairness are disabled */
  2182. DP(NETIF_MSG_IFUP,
  2183. "single function mode without fairness\n");
  2184. }
  2185. __bnx2x_link_report(bp);
  2186. if (IS_MF(bp))
  2187. bnx2x_link_sync_notify(bp);
  2188. }
  2189. void bnx2x__link_status_update(struct bnx2x *bp)
  2190. {
  2191. if (bp->state != BNX2X_STATE_OPEN)
  2192. return;
  2193. /* read updated dcb configuration */
  2194. if (IS_PF(bp)) {
  2195. bnx2x_dcbx_pmf_update(bp);
  2196. bnx2x_link_status_update(&bp->link_params, &bp->link_vars);
  2197. if (bp->link_vars.link_up)
  2198. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2199. else
  2200. bnx2x_stats_handle(bp, STATS_EVENT_STOP);
  2201. /* indicate link status */
  2202. bnx2x_link_report(bp);
  2203. } else { /* VF */
  2204. bp->port.supported[0] |= (SUPPORTED_10baseT_Half |
  2205. SUPPORTED_10baseT_Full |
  2206. SUPPORTED_100baseT_Half |
  2207. SUPPORTED_100baseT_Full |
  2208. SUPPORTED_1000baseT_Full |
  2209. SUPPORTED_2500baseX_Full |
  2210. SUPPORTED_10000baseT_Full |
  2211. SUPPORTED_TP |
  2212. SUPPORTED_FIBRE |
  2213. SUPPORTED_Autoneg |
  2214. SUPPORTED_Pause |
  2215. SUPPORTED_Asym_Pause);
  2216. bp->port.advertising[0] = bp->port.supported[0];
  2217. bp->link_params.bp = bp;
  2218. bp->link_params.port = BP_PORT(bp);
  2219. bp->link_params.req_duplex[0] = DUPLEX_FULL;
  2220. bp->link_params.req_flow_ctrl[0] = BNX2X_FLOW_CTRL_NONE;
  2221. bp->link_params.req_line_speed[0] = SPEED_10000;
  2222. bp->link_params.speed_cap_mask[0] = 0x7f0000;
  2223. bp->link_params.switch_cfg = SWITCH_CFG_10G;
  2224. bp->link_vars.mac_type = MAC_TYPE_BMAC;
  2225. bp->link_vars.line_speed = SPEED_10000;
  2226. bp->link_vars.link_status =
  2227. (LINK_STATUS_LINK_UP |
  2228. LINK_STATUS_SPEED_AND_DUPLEX_10GTFD);
  2229. bp->link_vars.link_up = 1;
  2230. bp->link_vars.duplex = DUPLEX_FULL;
  2231. bp->link_vars.flow_ctrl = BNX2X_FLOW_CTRL_NONE;
  2232. __bnx2x_link_report(bp);
  2233. bnx2x_stats_handle(bp, STATS_EVENT_LINK_UP);
  2234. }
  2235. }
  2236. static int bnx2x_afex_func_update(struct bnx2x *bp, u16 vifid,
  2237. u16 vlan_val, u8 allowed_prio)
  2238. {
  2239. struct bnx2x_func_state_params func_params = {NULL};
  2240. struct bnx2x_func_afex_update_params *f_update_params =
  2241. &func_params.params.afex_update;
  2242. func_params.f_obj = &bp->func_obj;
  2243. func_params.cmd = BNX2X_F_CMD_AFEX_UPDATE;
  2244. /* no need to wait for RAMROD completion, so don't
  2245. * set RAMROD_COMP_WAIT flag
  2246. */
  2247. f_update_params->vif_id = vifid;
  2248. f_update_params->afex_default_vlan = vlan_val;
  2249. f_update_params->allowed_priorities = allowed_prio;
  2250. /* if ramrod can not be sent, response to MCP immediately */
  2251. if (bnx2x_func_state_change(bp, &func_params) < 0)
  2252. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  2253. return 0;
  2254. }
  2255. static int bnx2x_afex_handle_vif_list_cmd(struct bnx2x *bp, u8 cmd_type,
  2256. u16 vif_index, u8 func_bit_map)
  2257. {
  2258. struct bnx2x_func_state_params func_params = {NULL};
  2259. struct bnx2x_func_afex_viflists_params *update_params =
  2260. &func_params.params.afex_viflists;
  2261. int rc;
  2262. u32 drv_msg_code;
  2263. /* validate only LIST_SET and LIST_GET are received from switch */
  2264. if ((cmd_type != VIF_LIST_RULE_GET) && (cmd_type != VIF_LIST_RULE_SET))
  2265. BNX2X_ERR("BUG! afex_handle_vif_list_cmd invalid type 0x%x\n",
  2266. cmd_type);
  2267. func_params.f_obj = &bp->func_obj;
  2268. func_params.cmd = BNX2X_F_CMD_AFEX_VIFLISTS;
  2269. /* set parameters according to cmd_type */
  2270. update_params->afex_vif_list_command = cmd_type;
  2271. update_params->vif_list_index = vif_index;
  2272. update_params->func_bit_map =
  2273. (cmd_type == VIF_LIST_RULE_GET) ? 0 : func_bit_map;
  2274. update_params->func_to_clear = 0;
  2275. drv_msg_code =
  2276. (cmd_type == VIF_LIST_RULE_GET) ?
  2277. DRV_MSG_CODE_AFEX_LISTGET_ACK :
  2278. DRV_MSG_CODE_AFEX_LISTSET_ACK;
  2279. /* if ramrod can not be sent, respond to MCP immediately for
  2280. * SET and GET requests (other are not triggered from MCP)
  2281. */
  2282. rc = bnx2x_func_state_change(bp, &func_params);
  2283. if (rc < 0)
  2284. bnx2x_fw_command(bp, drv_msg_code, 0);
  2285. return 0;
  2286. }
  2287. static void bnx2x_handle_afex_cmd(struct bnx2x *bp, u32 cmd)
  2288. {
  2289. struct afex_stats afex_stats;
  2290. u32 func = BP_ABS_FUNC(bp);
  2291. u32 mf_config;
  2292. u16 vlan_val;
  2293. u32 vlan_prio;
  2294. u16 vif_id;
  2295. u8 allowed_prio;
  2296. u8 vlan_mode;
  2297. u32 addr_to_write, vifid, addrs, stats_type, i;
  2298. if (cmd & DRV_STATUS_AFEX_LISTGET_REQ) {
  2299. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2300. DP(BNX2X_MSG_MCP,
  2301. "afex: got MCP req LISTGET_REQ for vifid 0x%x\n", vifid);
  2302. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_GET, vifid, 0);
  2303. }
  2304. if (cmd & DRV_STATUS_AFEX_LISTSET_REQ) {
  2305. vifid = SHMEM2_RD(bp, afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2306. addrs = SHMEM2_RD(bp, afex_param2_to_driver[BP_FW_MB_IDX(bp)]);
  2307. DP(BNX2X_MSG_MCP,
  2308. "afex: got MCP req LISTSET_REQ for vifid 0x%x addrs 0x%x\n",
  2309. vifid, addrs);
  2310. bnx2x_afex_handle_vif_list_cmd(bp, VIF_LIST_RULE_SET, vifid,
  2311. addrs);
  2312. }
  2313. if (cmd & DRV_STATUS_AFEX_STATSGET_REQ) {
  2314. addr_to_write = SHMEM2_RD(bp,
  2315. afex_scratchpad_addr_to_write[BP_FW_MB_IDX(bp)]);
  2316. stats_type = SHMEM2_RD(bp,
  2317. afex_param1_to_driver[BP_FW_MB_IDX(bp)]);
  2318. DP(BNX2X_MSG_MCP,
  2319. "afex: got MCP req STATSGET_REQ, write to addr 0x%x\n",
  2320. addr_to_write);
  2321. bnx2x_afex_collect_stats(bp, (void *)&afex_stats, stats_type);
  2322. /* write response to scratchpad, for MCP */
  2323. for (i = 0; i < (sizeof(struct afex_stats)/sizeof(u32)); i++)
  2324. REG_WR(bp, addr_to_write + i*sizeof(u32),
  2325. *(((u32 *)(&afex_stats))+i));
  2326. /* send ack message to MCP */
  2327. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_STATSGET_ACK, 0);
  2328. }
  2329. if (cmd & DRV_STATUS_AFEX_VIFSET_REQ) {
  2330. mf_config = MF_CFG_RD(bp, func_mf_config[func].config);
  2331. bp->mf_config[BP_VN(bp)] = mf_config;
  2332. DP(BNX2X_MSG_MCP,
  2333. "afex: got MCP req VIFSET_REQ, mf_config 0x%x\n",
  2334. mf_config);
  2335. /* if VIF_SET is "enabled" */
  2336. if (!(mf_config & FUNC_MF_CFG_FUNC_DISABLED)) {
  2337. /* set rate limit directly to internal RAM */
  2338. struct cmng_init_input cmng_input;
  2339. struct rate_shaping_vars_per_vn m_rs_vn;
  2340. size_t size = sizeof(struct rate_shaping_vars_per_vn);
  2341. u32 addr = BAR_XSTRORM_INTMEM +
  2342. XSTORM_RATE_SHAPING_PER_VN_VARS_OFFSET(BP_FUNC(bp));
  2343. bp->mf_config[BP_VN(bp)] = mf_config;
  2344. bnx2x_calc_vn_max(bp, BP_VN(bp), &cmng_input);
  2345. m_rs_vn.vn_counter.rate =
  2346. cmng_input.vnic_max_rate[BP_VN(bp)];
  2347. m_rs_vn.vn_counter.quota =
  2348. (m_rs_vn.vn_counter.rate *
  2349. RS_PERIODIC_TIMEOUT_USEC) / 8;
  2350. __storm_memset_struct(bp, addr, size, (u32 *)&m_rs_vn);
  2351. /* read relevant values from mf_cfg struct in shmem */
  2352. vif_id =
  2353. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2354. FUNC_MF_CFG_E1HOV_TAG_MASK) >>
  2355. FUNC_MF_CFG_E1HOV_TAG_SHIFT;
  2356. vlan_val =
  2357. (MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  2358. FUNC_MF_CFG_AFEX_VLAN_MASK) >>
  2359. FUNC_MF_CFG_AFEX_VLAN_SHIFT;
  2360. vlan_prio = (mf_config &
  2361. FUNC_MF_CFG_TRANSMIT_PRIORITY_MASK) >>
  2362. FUNC_MF_CFG_TRANSMIT_PRIORITY_SHIFT;
  2363. vlan_val |= (vlan_prio << VLAN_PRIO_SHIFT);
  2364. vlan_mode =
  2365. (MF_CFG_RD(bp,
  2366. func_mf_config[func].afex_config) &
  2367. FUNC_MF_CFG_AFEX_VLAN_MODE_MASK) >>
  2368. FUNC_MF_CFG_AFEX_VLAN_MODE_SHIFT;
  2369. allowed_prio =
  2370. (MF_CFG_RD(bp,
  2371. func_mf_config[func].afex_config) &
  2372. FUNC_MF_CFG_AFEX_COS_FILTER_MASK) >>
  2373. FUNC_MF_CFG_AFEX_COS_FILTER_SHIFT;
  2374. /* send ramrod to FW, return in case of failure */
  2375. if (bnx2x_afex_func_update(bp, vif_id, vlan_val,
  2376. allowed_prio))
  2377. return;
  2378. bp->afex_def_vlan_tag = vlan_val;
  2379. bp->afex_vlan_mode = vlan_mode;
  2380. } else {
  2381. /* notify link down because BP->flags is disabled */
  2382. bnx2x_link_report(bp);
  2383. /* send INVALID VIF ramrod to FW */
  2384. bnx2x_afex_func_update(bp, 0xFFFF, 0, 0);
  2385. /* Reset the default afex VLAN */
  2386. bp->afex_def_vlan_tag = -1;
  2387. }
  2388. }
  2389. }
  2390. static void bnx2x_pmf_update(struct bnx2x *bp)
  2391. {
  2392. int port = BP_PORT(bp);
  2393. u32 val;
  2394. bp->port.pmf = 1;
  2395. DP(BNX2X_MSG_MCP, "pmf %d\n", bp->port.pmf);
  2396. /*
  2397. * We need the mb() to ensure the ordering between the writing to
  2398. * bp->port.pmf here and reading it from the bnx2x_periodic_task().
  2399. */
  2400. smp_mb();
  2401. /* queue a periodic task */
  2402. queue_delayed_work(bnx2x_wq, &bp->period_task, 0);
  2403. bnx2x_dcbx_pmf_update(bp);
  2404. /* enable nig attention */
  2405. val = (0xff0f | (1 << (BP_VN(bp) + 4)));
  2406. if (bp->common.int_block == INT_BLOCK_HC) {
  2407. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, val);
  2408. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, val);
  2409. } else if (!CHIP_IS_E1x(bp)) {
  2410. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, val);
  2411. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, val);
  2412. }
  2413. bnx2x_stats_handle(bp, STATS_EVENT_PMF);
  2414. }
  2415. /* end of Link */
  2416. /* slow path */
  2417. /*
  2418. * General service functions
  2419. */
  2420. /* send the MCP a request, block until there is a reply */
  2421. u32 bnx2x_fw_command(struct bnx2x *bp, u32 command, u32 param)
  2422. {
  2423. int mb_idx = BP_FW_MB_IDX(bp);
  2424. u32 seq;
  2425. u32 rc = 0;
  2426. u32 cnt = 1;
  2427. u8 delay = CHIP_REV_IS_SLOW(bp) ? 100 : 10;
  2428. mutex_lock(&bp->fw_mb_mutex);
  2429. seq = ++bp->fw_seq;
  2430. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_param, param);
  2431. SHMEM_WR(bp, func_mb[mb_idx].drv_mb_header, (command | seq));
  2432. DP(BNX2X_MSG_MCP, "wrote command (%x) to FW MB param 0x%08x\n",
  2433. (command | seq), param);
  2434. do {
  2435. /* let the FW do it's magic ... */
  2436. msleep(delay);
  2437. rc = SHMEM_RD(bp, func_mb[mb_idx].fw_mb_header);
  2438. /* Give the FW up to 5 second (500*10ms) */
  2439. } while ((seq != (rc & FW_MSG_SEQ_NUMBER_MASK)) && (cnt++ < 500));
  2440. DP(BNX2X_MSG_MCP, "[after %d ms] read (%x) seq is (%x) from FW MB\n",
  2441. cnt*delay, rc, seq);
  2442. /* is this a reply to our command? */
  2443. if (seq == (rc & FW_MSG_SEQ_NUMBER_MASK))
  2444. rc &= FW_MSG_CODE_MASK;
  2445. else {
  2446. /* FW BUG! */
  2447. BNX2X_ERR("FW failed to respond!\n");
  2448. bnx2x_fw_dump(bp);
  2449. rc = 0;
  2450. }
  2451. mutex_unlock(&bp->fw_mb_mutex);
  2452. return rc;
  2453. }
  2454. static void storm_memset_func_cfg(struct bnx2x *bp,
  2455. struct tstorm_eth_function_common_config *tcfg,
  2456. u16 abs_fid)
  2457. {
  2458. size_t size = sizeof(struct tstorm_eth_function_common_config);
  2459. u32 addr = BAR_TSTRORM_INTMEM +
  2460. TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
  2461. __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
  2462. }
  2463. void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
  2464. {
  2465. if (CHIP_IS_E1x(bp)) {
  2466. struct tstorm_eth_function_common_config tcfg = {0};
  2467. storm_memset_func_cfg(bp, &tcfg, p->func_id);
  2468. }
  2469. /* Enable the function in the FW */
  2470. storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
  2471. storm_memset_func_en(bp, p->func_id, 1);
  2472. /* spq */
  2473. if (p->func_flgs & FUNC_FLG_SPQ) {
  2474. storm_memset_spq_addr(bp, p->spq_map, p->func_id);
  2475. REG_WR(bp, XSEM_REG_FAST_MEMORY +
  2476. XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
  2477. }
  2478. }
  2479. /**
  2480. * bnx2x_get_common_flags - Return common flags
  2481. *
  2482. * @bp device handle
  2483. * @fp queue handle
  2484. * @zero_stats TRUE if statistics zeroing is needed
  2485. *
  2486. * Return the flags that are common for the Tx-only and not normal connections.
  2487. */
  2488. static unsigned long bnx2x_get_common_flags(struct bnx2x *bp,
  2489. struct bnx2x_fastpath *fp,
  2490. bool zero_stats)
  2491. {
  2492. unsigned long flags = 0;
  2493. /* PF driver will always initialize the Queue to an ACTIVE state */
  2494. __set_bit(BNX2X_Q_FLG_ACTIVE, &flags);
  2495. /* tx only connections collect statistics (on the same index as the
  2496. * parent connection). The statistics are zeroed when the parent
  2497. * connection is initialized.
  2498. */
  2499. __set_bit(BNX2X_Q_FLG_STATS, &flags);
  2500. if (zero_stats)
  2501. __set_bit(BNX2X_Q_FLG_ZERO_STATS, &flags);
  2502. __set_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, &flags);
  2503. __set_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, &flags);
  2504. #ifdef BNX2X_STOP_ON_ERROR
  2505. __set_bit(BNX2X_Q_FLG_TX_SEC, &flags);
  2506. #endif
  2507. return flags;
  2508. }
  2509. static unsigned long bnx2x_get_q_flags(struct bnx2x *bp,
  2510. struct bnx2x_fastpath *fp,
  2511. bool leading)
  2512. {
  2513. unsigned long flags = 0;
  2514. /* calculate other queue flags */
  2515. if (IS_MF_SD(bp))
  2516. __set_bit(BNX2X_Q_FLG_OV, &flags);
  2517. if (IS_FCOE_FP(fp)) {
  2518. __set_bit(BNX2X_Q_FLG_FCOE, &flags);
  2519. /* For FCoE - force usage of default priority (for afex) */
  2520. __set_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, &flags);
  2521. }
  2522. if (!fp->disable_tpa) {
  2523. __set_bit(BNX2X_Q_FLG_TPA, &flags);
  2524. __set_bit(BNX2X_Q_FLG_TPA_IPV6, &flags);
  2525. if (fp->mode == TPA_MODE_GRO)
  2526. __set_bit(BNX2X_Q_FLG_TPA_GRO, &flags);
  2527. }
  2528. if (leading) {
  2529. __set_bit(BNX2X_Q_FLG_LEADING_RSS, &flags);
  2530. __set_bit(BNX2X_Q_FLG_MCAST, &flags);
  2531. }
  2532. /* Always set HW VLAN stripping */
  2533. __set_bit(BNX2X_Q_FLG_VLAN, &flags);
  2534. /* configure silent vlan removal */
  2535. if (IS_MF_AFEX(bp))
  2536. __set_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, &flags);
  2537. return flags | bnx2x_get_common_flags(bp, fp, true);
  2538. }
  2539. static void bnx2x_pf_q_prep_general(struct bnx2x *bp,
  2540. struct bnx2x_fastpath *fp, struct bnx2x_general_setup_params *gen_init,
  2541. u8 cos)
  2542. {
  2543. gen_init->stat_id = bnx2x_stats_id(fp);
  2544. gen_init->spcl_id = fp->cl_id;
  2545. /* Always use mini-jumbo MTU for FCoE L2 ring */
  2546. if (IS_FCOE_FP(fp))
  2547. gen_init->mtu = BNX2X_FCOE_MINI_JUMBO_MTU;
  2548. else
  2549. gen_init->mtu = bp->dev->mtu;
  2550. gen_init->cos = cos;
  2551. }
  2552. static void bnx2x_pf_rx_q_prep(struct bnx2x *bp,
  2553. struct bnx2x_fastpath *fp, struct rxq_pause_params *pause,
  2554. struct bnx2x_rxq_setup_params *rxq_init)
  2555. {
  2556. u8 max_sge = 0;
  2557. u16 sge_sz = 0;
  2558. u16 tpa_agg_size = 0;
  2559. if (!fp->disable_tpa) {
  2560. pause->sge_th_lo = SGE_TH_LO(bp);
  2561. pause->sge_th_hi = SGE_TH_HI(bp);
  2562. /* validate SGE ring has enough to cross high threshold */
  2563. WARN_ON(bp->dropless_fc &&
  2564. pause->sge_th_hi + FW_PREFETCH_CNT >
  2565. MAX_RX_SGE_CNT * NUM_RX_SGE_PAGES);
  2566. tpa_agg_size = TPA_AGG_SIZE;
  2567. max_sge = SGE_PAGE_ALIGN(bp->dev->mtu) >>
  2568. SGE_PAGE_SHIFT;
  2569. max_sge = ((max_sge + PAGES_PER_SGE - 1) &
  2570. (~(PAGES_PER_SGE-1))) >> PAGES_PER_SGE_SHIFT;
  2571. sge_sz = (u16)min_t(u32, SGE_PAGES, 0xffff);
  2572. }
  2573. /* pause - not for e1 */
  2574. if (!CHIP_IS_E1(bp)) {
  2575. pause->bd_th_lo = BD_TH_LO(bp);
  2576. pause->bd_th_hi = BD_TH_HI(bp);
  2577. pause->rcq_th_lo = RCQ_TH_LO(bp);
  2578. pause->rcq_th_hi = RCQ_TH_HI(bp);
  2579. /*
  2580. * validate that rings have enough entries to cross
  2581. * high thresholds
  2582. */
  2583. WARN_ON(bp->dropless_fc &&
  2584. pause->bd_th_hi + FW_PREFETCH_CNT >
  2585. bp->rx_ring_size);
  2586. WARN_ON(bp->dropless_fc &&
  2587. pause->rcq_th_hi + FW_PREFETCH_CNT >
  2588. NUM_RCQ_RINGS * MAX_RCQ_DESC_CNT);
  2589. pause->pri_map = 1;
  2590. }
  2591. /* rxq setup */
  2592. rxq_init->dscr_map = fp->rx_desc_mapping;
  2593. rxq_init->sge_map = fp->rx_sge_mapping;
  2594. rxq_init->rcq_map = fp->rx_comp_mapping;
  2595. rxq_init->rcq_np_map = fp->rx_comp_mapping + BCM_PAGE_SIZE;
  2596. /* This should be a maximum number of data bytes that may be
  2597. * placed on the BD (not including paddings).
  2598. */
  2599. rxq_init->buf_sz = fp->rx_buf_size - BNX2X_FW_RX_ALIGN_START -
  2600. BNX2X_FW_RX_ALIGN_END - IP_HEADER_ALIGNMENT_PADDING;
  2601. rxq_init->cl_qzone_id = fp->cl_qzone_id;
  2602. rxq_init->tpa_agg_sz = tpa_agg_size;
  2603. rxq_init->sge_buf_sz = sge_sz;
  2604. rxq_init->max_sges_pkt = max_sge;
  2605. rxq_init->rss_engine_id = BP_FUNC(bp);
  2606. rxq_init->mcast_engine_id = BP_FUNC(bp);
  2607. /* Maximum number or simultaneous TPA aggregation for this Queue.
  2608. *
  2609. * For PF Clients it should be the maximum available number.
  2610. * VF driver(s) may want to define it to a smaller value.
  2611. */
  2612. rxq_init->max_tpa_queues = MAX_AGG_QS(bp);
  2613. rxq_init->cache_line_log = BNX2X_RX_ALIGN_SHIFT;
  2614. rxq_init->fw_sb_id = fp->fw_sb_id;
  2615. if (IS_FCOE_FP(fp))
  2616. rxq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_RX_CQ_CONS;
  2617. else
  2618. rxq_init->sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  2619. /* configure silent vlan removal
  2620. * if multi function mode is afex, then mask default vlan
  2621. */
  2622. if (IS_MF_AFEX(bp)) {
  2623. rxq_init->silent_removal_value = bp->afex_def_vlan_tag;
  2624. rxq_init->silent_removal_mask = VLAN_VID_MASK;
  2625. }
  2626. }
  2627. static void bnx2x_pf_tx_q_prep(struct bnx2x *bp,
  2628. struct bnx2x_fastpath *fp, struct bnx2x_txq_setup_params *txq_init,
  2629. u8 cos)
  2630. {
  2631. txq_init->dscr_map = fp->txdata_ptr[cos]->tx_desc_mapping;
  2632. txq_init->sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS + cos;
  2633. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_NW;
  2634. txq_init->fw_sb_id = fp->fw_sb_id;
  2635. /*
  2636. * set the tss leading client id for TX classification ==
  2637. * leading RSS client id
  2638. */
  2639. txq_init->tss_leading_cl_id = bnx2x_fp(bp, 0, cl_id);
  2640. if (IS_FCOE_FP(fp)) {
  2641. txq_init->sb_cq_index = HC_SP_INDEX_ETH_FCOE_TX_CQ_CONS;
  2642. txq_init->traffic_type = LLFC_TRAFFIC_TYPE_FCOE;
  2643. }
  2644. }
  2645. static void bnx2x_pf_init(struct bnx2x *bp)
  2646. {
  2647. struct bnx2x_func_init_params func_init = {0};
  2648. struct event_ring_data eq_data = { {0} };
  2649. u16 flags;
  2650. if (!CHIP_IS_E1x(bp)) {
  2651. /* reset IGU PF statistics: MSIX + ATTN */
  2652. /* PF */
  2653. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2654. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2655. (CHIP_MODE_IS_4_PORT(bp) ?
  2656. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2657. /* ATTN */
  2658. REG_WR(bp, IGU_REG_STATISTIC_NUM_MESSAGE_SENT +
  2659. BNX2X_IGU_STAS_MSG_VF_CNT*4 +
  2660. BNX2X_IGU_STAS_MSG_PF_CNT*4 +
  2661. (CHIP_MODE_IS_4_PORT(bp) ?
  2662. BP_FUNC(bp) : BP_VN(bp))*4, 0);
  2663. }
  2664. /* function setup flags */
  2665. flags = (FUNC_FLG_STATS | FUNC_FLG_LEADING | FUNC_FLG_SPQ);
  2666. /* This flag is relevant for E1x only.
  2667. * E2 doesn't have a TPA configuration in a function level.
  2668. */
  2669. flags |= (bp->flags & TPA_ENABLE_FLAG) ? FUNC_FLG_TPA : 0;
  2670. func_init.func_flgs = flags;
  2671. func_init.pf_id = BP_FUNC(bp);
  2672. func_init.func_id = BP_FUNC(bp);
  2673. func_init.spq_map = bp->spq_mapping;
  2674. func_init.spq_prod = bp->spq_prod_idx;
  2675. bnx2x_func_init(bp, &func_init);
  2676. memset(&(bp->cmng), 0, sizeof(struct cmng_struct_per_port));
  2677. /*
  2678. * Congestion management values depend on the link rate
  2679. * There is no active link so initial link rate is set to 10 Gbps.
  2680. * When the link comes up The congestion management values are
  2681. * re-calculated according to the actual link rate.
  2682. */
  2683. bp->link_vars.line_speed = SPEED_10000;
  2684. bnx2x_cmng_fns_init(bp, true, bnx2x_get_cmng_fns_mode(bp));
  2685. /* Only the PMF sets the HW */
  2686. if (bp->port.pmf)
  2687. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2688. /* init Event Queue - PCI bus guarantees correct endianity*/
  2689. eq_data.base_addr.hi = U64_HI(bp->eq_mapping);
  2690. eq_data.base_addr.lo = U64_LO(bp->eq_mapping);
  2691. eq_data.producer = bp->eq_prod;
  2692. eq_data.index_id = HC_SP_INDEX_EQ_CONS;
  2693. eq_data.sb_id = DEF_SB_ID;
  2694. storm_memset_eq_data(bp, &eq_data, BP_FUNC(bp));
  2695. }
  2696. static void bnx2x_e1h_disable(struct bnx2x *bp)
  2697. {
  2698. int port = BP_PORT(bp);
  2699. bnx2x_tx_disable(bp);
  2700. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  2701. }
  2702. static void bnx2x_e1h_enable(struct bnx2x *bp)
  2703. {
  2704. int port = BP_PORT(bp);
  2705. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  2706. /* Tx queue should be only re-enabled */
  2707. netif_tx_wake_all_queues(bp->dev);
  2708. /*
  2709. * Should not call netif_carrier_on since it will be called if the link
  2710. * is up when checking for link state
  2711. */
  2712. }
  2713. #define DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED 3
  2714. static void bnx2x_drv_info_ether_stat(struct bnx2x *bp)
  2715. {
  2716. struct eth_stats_info *ether_stat =
  2717. &bp->slowpath->drv_info_to_mcp.ether_stat;
  2718. struct bnx2x_vlan_mac_obj *mac_obj =
  2719. &bp->sp_objs->mac_obj;
  2720. int i;
  2721. strlcpy(ether_stat->version, DRV_MODULE_VERSION,
  2722. ETH_STAT_INFO_VERSION_LEN);
  2723. /* get DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED macs, placing them in the
  2724. * mac_local field in ether_stat struct. The base address is offset by 2
  2725. * bytes to account for the field being 8 bytes but a mac address is
  2726. * only 6 bytes. Likewise, the stride for the get_n_elements function is
  2727. * 2 bytes to compensate from the 6 bytes of a mac to the 8 bytes
  2728. * allocated by the ether_stat struct, so the macs will land in their
  2729. * proper positions.
  2730. */
  2731. for (i = 0; i < DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED; i++)
  2732. memset(ether_stat->mac_local + i, 0,
  2733. sizeof(ether_stat->mac_local[0]));
  2734. mac_obj->get_n_elements(bp, &bp->sp_objs[0].mac_obj,
  2735. DRV_INFO_ETH_STAT_NUM_MACS_REQUIRED,
  2736. ether_stat->mac_local + MAC_PAD, MAC_PAD,
  2737. ETH_ALEN);
  2738. ether_stat->mtu_size = bp->dev->mtu;
  2739. if (bp->dev->features & NETIF_F_RXCSUM)
  2740. ether_stat->feature_flags |= FEATURE_ETH_CHKSUM_OFFLOAD_MASK;
  2741. if (bp->dev->features & NETIF_F_TSO)
  2742. ether_stat->feature_flags |= FEATURE_ETH_LSO_MASK;
  2743. ether_stat->feature_flags |= bp->common.boot_mode;
  2744. ether_stat->promiscuous_mode = (bp->dev->flags & IFF_PROMISC) ? 1 : 0;
  2745. ether_stat->txq_size = bp->tx_ring_size;
  2746. ether_stat->rxq_size = bp->rx_ring_size;
  2747. }
  2748. static void bnx2x_drv_info_fcoe_stat(struct bnx2x *bp)
  2749. {
  2750. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2751. struct fcoe_stats_info *fcoe_stat =
  2752. &bp->slowpath->drv_info_to_mcp.fcoe_stat;
  2753. if (!CNIC_LOADED(bp))
  2754. return;
  2755. memcpy(fcoe_stat->mac_local + MAC_PAD, bp->fip_mac, ETH_ALEN);
  2756. fcoe_stat->qos_priority =
  2757. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_FCOE];
  2758. /* insert FCoE stats from ramrod response */
  2759. if (!NO_FCOE(bp)) {
  2760. struct tstorm_per_queue_stats *fcoe_q_tstorm_stats =
  2761. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2762. tstorm_queue_statistics;
  2763. struct xstorm_per_queue_stats *fcoe_q_xstorm_stats =
  2764. &bp->fw_stats_data->queue_stats[FCOE_IDX(bp)].
  2765. xstorm_queue_statistics;
  2766. struct fcoe_statistics_params *fw_fcoe_stat =
  2767. &bp->fw_stats_data->fcoe;
  2768. ADD_64_LE(fcoe_stat->rx_bytes_hi, LE32_0,
  2769. fcoe_stat->rx_bytes_lo,
  2770. fw_fcoe_stat->rx_stat0.fcoe_rx_byte_cnt);
  2771. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2772. fcoe_q_tstorm_stats->rcv_ucast_bytes.hi,
  2773. fcoe_stat->rx_bytes_lo,
  2774. fcoe_q_tstorm_stats->rcv_ucast_bytes.lo);
  2775. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2776. fcoe_q_tstorm_stats->rcv_bcast_bytes.hi,
  2777. fcoe_stat->rx_bytes_lo,
  2778. fcoe_q_tstorm_stats->rcv_bcast_bytes.lo);
  2779. ADD_64_LE(fcoe_stat->rx_bytes_hi,
  2780. fcoe_q_tstorm_stats->rcv_mcast_bytes.hi,
  2781. fcoe_stat->rx_bytes_lo,
  2782. fcoe_q_tstorm_stats->rcv_mcast_bytes.lo);
  2783. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2784. fcoe_stat->rx_frames_lo,
  2785. fw_fcoe_stat->rx_stat0.fcoe_rx_pkt_cnt);
  2786. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2787. fcoe_stat->rx_frames_lo,
  2788. fcoe_q_tstorm_stats->rcv_ucast_pkts);
  2789. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2790. fcoe_stat->rx_frames_lo,
  2791. fcoe_q_tstorm_stats->rcv_bcast_pkts);
  2792. ADD_64_LE(fcoe_stat->rx_frames_hi, LE32_0,
  2793. fcoe_stat->rx_frames_lo,
  2794. fcoe_q_tstorm_stats->rcv_mcast_pkts);
  2795. ADD_64_LE(fcoe_stat->tx_bytes_hi, LE32_0,
  2796. fcoe_stat->tx_bytes_lo,
  2797. fw_fcoe_stat->tx_stat.fcoe_tx_byte_cnt);
  2798. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2799. fcoe_q_xstorm_stats->ucast_bytes_sent.hi,
  2800. fcoe_stat->tx_bytes_lo,
  2801. fcoe_q_xstorm_stats->ucast_bytes_sent.lo);
  2802. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2803. fcoe_q_xstorm_stats->bcast_bytes_sent.hi,
  2804. fcoe_stat->tx_bytes_lo,
  2805. fcoe_q_xstorm_stats->bcast_bytes_sent.lo);
  2806. ADD_64_LE(fcoe_stat->tx_bytes_hi,
  2807. fcoe_q_xstorm_stats->mcast_bytes_sent.hi,
  2808. fcoe_stat->tx_bytes_lo,
  2809. fcoe_q_xstorm_stats->mcast_bytes_sent.lo);
  2810. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2811. fcoe_stat->tx_frames_lo,
  2812. fw_fcoe_stat->tx_stat.fcoe_tx_pkt_cnt);
  2813. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2814. fcoe_stat->tx_frames_lo,
  2815. fcoe_q_xstorm_stats->ucast_pkts_sent);
  2816. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2817. fcoe_stat->tx_frames_lo,
  2818. fcoe_q_xstorm_stats->bcast_pkts_sent);
  2819. ADD_64_LE(fcoe_stat->tx_frames_hi, LE32_0,
  2820. fcoe_stat->tx_frames_lo,
  2821. fcoe_q_xstorm_stats->mcast_pkts_sent);
  2822. }
  2823. /* ask L5 driver to add data to the struct */
  2824. bnx2x_cnic_notify(bp, CNIC_CTL_FCOE_STATS_GET_CMD);
  2825. }
  2826. static void bnx2x_drv_info_iscsi_stat(struct bnx2x *bp)
  2827. {
  2828. struct bnx2x_dcbx_app_params *app = &bp->dcbx_port_params.app;
  2829. struct iscsi_stats_info *iscsi_stat =
  2830. &bp->slowpath->drv_info_to_mcp.iscsi_stat;
  2831. if (!CNIC_LOADED(bp))
  2832. return;
  2833. memcpy(iscsi_stat->mac_local + MAC_PAD, bp->cnic_eth_dev.iscsi_mac,
  2834. ETH_ALEN);
  2835. iscsi_stat->qos_priority =
  2836. app->traffic_type_priority[LLFC_TRAFFIC_TYPE_ISCSI];
  2837. /* ask L5 driver to add data to the struct */
  2838. bnx2x_cnic_notify(bp, CNIC_CTL_ISCSI_STATS_GET_CMD);
  2839. }
  2840. /* called due to MCP event (on pmf):
  2841. * reread new bandwidth configuration
  2842. * configure FW
  2843. * notify others function about the change
  2844. */
  2845. static void bnx2x_config_mf_bw(struct bnx2x *bp)
  2846. {
  2847. if (bp->link_vars.link_up) {
  2848. bnx2x_cmng_fns_init(bp, true, CMNG_FNS_MINMAX);
  2849. bnx2x_link_sync_notify(bp);
  2850. }
  2851. storm_memset_cmng(bp, &bp->cmng, BP_PORT(bp));
  2852. }
  2853. static void bnx2x_set_mf_bw(struct bnx2x *bp)
  2854. {
  2855. bnx2x_config_mf_bw(bp);
  2856. bnx2x_fw_command(bp, DRV_MSG_CODE_SET_MF_BW_ACK, 0);
  2857. }
  2858. static void bnx2x_handle_eee_event(struct bnx2x *bp)
  2859. {
  2860. DP(BNX2X_MSG_MCP, "EEE - LLDP event\n");
  2861. bnx2x_fw_command(bp, DRV_MSG_CODE_EEE_RESULTS_ACK, 0);
  2862. }
  2863. static void bnx2x_handle_drv_info_req(struct bnx2x *bp)
  2864. {
  2865. enum drv_info_opcode op_code;
  2866. u32 drv_info_ctl = SHMEM2_RD(bp, drv_info_control);
  2867. /* if drv_info version supported by MFW doesn't match - send NACK */
  2868. if ((drv_info_ctl & DRV_INFO_CONTROL_VER_MASK) != DRV_INFO_CUR_VER) {
  2869. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2870. return;
  2871. }
  2872. op_code = (drv_info_ctl & DRV_INFO_CONTROL_OP_CODE_MASK) >>
  2873. DRV_INFO_CONTROL_OP_CODE_SHIFT;
  2874. memset(&bp->slowpath->drv_info_to_mcp, 0,
  2875. sizeof(union drv_info_to_mcp));
  2876. switch (op_code) {
  2877. case ETH_STATS_OPCODE:
  2878. bnx2x_drv_info_ether_stat(bp);
  2879. break;
  2880. case FCOE_STATS_OPCODE:
  2881. bnx2x_drv_info_fcoe_stat(bp);
  2882. break;
  2883. case ISCSI_STATS_OPCODE:
  2884. bnx2x_drv_info_iscsi_stat(bp);
  2885. break;
  2886. default:
  2887. /* if op code isn't supported - send NACK */
  2888. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_NACK, 0);
  2889. return;
  2890. }
  2891. /* if we got drv_info attn from MFW then these fields are defined in
  2892. * shmem2 for sure
  2893. */
  2894. SHMEM2_WR(bp, drv_info_host_addr_lo,
  2895. U64_LO(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2896. SHMEM2_WR(bp, drv_info_host_addr_hi,
  2897. U64_HI(bnx2x_sp_mapping(bp, drv_info_to_mcp)));
  2898. bnx2x_fw_command(bp, DRV_MSG_CODE_DRV_INFO_ACK, 0);
  2899. }
  2900. static void bnx2x_dcc_event(struct bnx2x *bp, u32 dcc_event)
  2901. {
  2902. DP(BNX2X_MSG_MCP, "dcc_event 0x%x\n", dcc_event);
  2903. if (dcc_event & DRV_STATUS_DCC_DISABLE_ENABLE_PF) {
  2904. /*
  2905. * This is the only place besides the function initialization
  2906. * where the bp->flags can change so it is done without any
  2907. * locks
  2908. */
  2909. if (bp->mf_config[BP_VN(bp)] & FUNC_MF_CFG_FUNC_DISABLED) {
  2910. DP(BNX2X_MSG_MCP, "mf_cfg function disabled\n");
  2911. bp->flags |= MF_FUNC_DIS;
  2912. bnx2x_e1h_disable(bp);
  2913. } else {
  2914. DP(BNX2X_MSG_MCP, "mf_cfg function enabled\n");
  2915. bp->flags &= ~MF_FUNC_DIS;
  2916. bnx2x_e1h_enable(bp);
  2917. }
  2918. dcc_event &= ~DRV_STATUS_DCC_DISABLE_ENABLE_PF;
  2919. }
  2920. if (dcc_event & DRV_STATUS_DCC_BANDWIDTH_ALLOCATION) {
  2921. bnx2x_config_mf_bw(bp);
  2922. dcc_event &= ~DRV_STATUS_DCC_BANDWIDTH_ALLOCATION;
  2923. }
  2924. /* Report results to MCP */
  2925. if (dcc_event)
  2926. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_FAILURE, 0);
  2927. else
  2928. bnx2x_fw_command(bp, DRV_MSG_CODE_DCC_OK, 0);
  2929. }
  2930. /* must be called under the spq lock */
  2931. static struct eth_spe *bnx2x_sp_get_next(struct bnx2x *bp)
  2932. {
  2933. struct eth_spe *next_spe = bp->spq_prod_bd;
  2934. if (bp->spq_prod_bd == bp->spq_last_bd) {
  2935. bp->spq_prod_bd = bp->spq;
  2936. bp->spq_prod_idx = 0;
  2937. DP(BNX2X_MSG_SP, "end of spq\n");
  2938. } else {
  2939. bp->spq_prod_bd++;
  2940. bp->spq_prod_idx++;
  2941. }
  2942. return next_spe;
  2943. }
  2944. /* must be called under the spq lock */
  2945. static void bnx2x_sp_prod_update(struct bnx2x *bp)
  2946. {
  2947. int func = BP_FUNC(bp);
  2948. /*
  2949. * Make sure that BD data is updated before writing the producer:
  2950. * BD data is written to the memory, the producer is read from the
  2951. * memory, thus we need a full memory barrier to ensure the ordering.
  2952. */
  2953. mb();
  2954. REG_WR16(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_PROD_OFFSET(func),
  2955. bp->spq_prod_idx);
  2956. mmiowb();
  2957. }
  2958. /**
  2959. * bnx2x_is_contextless_ramrod - check if the current command ends on EQ
  2960. *
  2961. * @cmd: command to check
  2962. * @cmd_type: command type
  2963. */
  2964. static bool bnx2x_is_contextless_ramrod(int cmd, int cmd_type)
  2965. {
  2966. if ((cmd_type == NONE_CONNECTION_TYPE) ||
  2967. (cmd == RAMROD_CMD_ID_ETH_FORWARD_SETUP) ||
  2968. (cmd == RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES) ||
  2969. (cmd == RAMROD_CMD_ID_ETH_FILTER_RULES) ||
  2970. (cmd == RAMROD_CMD_ID_ETH_MULTICAST_RULES) ||
  2971. (cmd == RAMROD_CMD_ID_ETH_SET_MAC) ||
  2972. (cmd == RAMROD_CMD_ID_ETH_RSS_UPDATE))
  2973. return true;
  2974. else
  2975. return false;
  2976. }
  2977. /**
  2978. * bnx2x_sp_post - place a single command on an SP ring
  2979. *
  2980. * @bp: driver handle
  2981. * @command: command to place (e.g. SETUP, FILTER_RULES, etc.)
  2982. * @cid: SW CID the command is related to
  2983. * @data_hi: command private data address (high 32 bits)
  2984. * @data_lo: command private data address (low 32 bits)
  2985. * @cmd_type: command type (e.g. NONE, ETH)
  2986. *
  2987. * SP data is handled as if it's always an address pair, thus data fields are
  2988. * not swapped to little endian in upper functions. Instead this function swaps
  2989. * data as if it's two u32 fields.
  2990. */
  2991. int bnx2x_sp_post(struct bnx2x *bp, int command, int cid,
  2992. u32 data_hi, u32 data_lo, int cmd_type)
  2993. {
  2994. struct eth_spe *spe;
  2995. u16 type;
  2996. bool common = bnx2x_is_contextless_ramrod(command, cmd_type);
  2997. #ifdef BNX2X_STOP_ON_ERROR
  2998. if (unlikely(bp->panic)) {
  2999. BNX2X_ERR("Can't post SP when there is panic\n");
  3000. return -EIO;
  3001. }
  3002. #endif
  3003. spin_lock_bh(&bp->spq_lock);
  3004. if (common) {
  3005. if (!atomic_read(&bp->eq_spq_left)) {
  3006. BNX2X_ERR("BUG! EQ ring full!\n");
  3007. spin_unlock_bh(&bp->spq_lock);
  3008. bnx2x_panic();
  3009. return -EBUSY;
  3010. }
  3011. } else if (!atomic_read(&bp->cq_spq_left)) {
  3012. BNX2X_ERR("BUG! SPQ ring full!\n");
  3013. spin_unlock_bh(&bp->spq_lock);
  3014. bnx2x_panic();
  3015. return -EBUSY;
  3016. }
  3017. spe = bnx2x_sp_get_next(bp);
  3018. /* CID needs port number to be encoded int it */
  3019. spe->hdr.conn_and_cmd_data =
  3020. cpu_to_le32((command << SPE_HDR_CMD_ID_SHIFT) |
  3021. HW_CID(bp, cid));
  3022. type = (cmd_type << SPE_HDR_CONN_TYPE_SHIFT) & SPE_HDR_CONN_TYPE;
  3023. type |= ((BP_FUNC(bp) << SPE_HDR_FUNCTION_ID_SHIFT) &
  3024. SPE_HDR_FUNCTION_ID);
  3025. spe->hdr.type = cpu_to_le16(type);
  3026. spe->data.update_data_addr.hi = cpu_to_le32(data_hi);
  3027. spe->data.update_data_addr.lo = cpu_to_le32(data_lo);
  3028. /*
  3029. * It's ok if the actual decrement is issued towards the memory
  3030. * somewhere between the spin_lock and spin_unlock. Thus no
  3031. * more explicit memory barrier is needed.
  3032. */
  3033. if (common)
  3034. atomic_dec(&bp->eq_spq_left);
  3035. else
  3036. atomic_dec(&bp->cq_spq_left);
  3037. DP(BNX2X_MSG_SP,
  3038. "SPQE[%x] (%x:%x) (cmd, common?) (%d,%d) hw_cid %x data (%x:%x) type(0x%x) left (CQ, EQ) (%x,%x)\n",
  3039. bp->spq_prod_idx, (u32)U64_HI(bp->spq_mapping),
  3040. (u32)(U64_LO(bp->spq_mapping) +
  3041. (void *)bp->spq_prod_bd - (void *)bp->spq), command, common,
  3042. HW_CID(bp, cid), data_hi, data_lo, type,
  3043. atomic_read(&bp->cq_spq_left), atomic_read(&bp->eq_spq_left));
  3044. bnx2x_sp_prod_update(bp);
  3045. spin_unlock_bh(&bp->spq_lock);
  3046. return 0;
  3047. }
  3048. /* acquire split MCP access lock register */
  3049. static int bnx2x_acquire_alr(struct bnx2x *bp)
  3050. {
  3051. u32 j, val;
  3052. int rc = 0;
  3053. might_sleep();
  3054. for (j = 0; j < 1000; j++) {
  3055. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, MCPR_ACCESS_LOCK_LOCK);
  3056. val = REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK);
  3057. if (val & MCPR_ACCESS_LOCK_LOCK)
  3058. break;
  3059. usleep_range(5000, 10000);
  3060. }
  3061. if (!(val & MCPR_ACCESS_LOCK_LOCK)) {
  3062. BNX2X_ERR("Cannot acquire MCP access lock register\n");
  3063. rc = -EBUSY;
  3064. }
  3065. return rc;
  3066. }
  3067. /* release split MCP access lock register */
  3068. static void bnx2x_release_alr(struct bnx2x *bp)
  3069. {
  3070. REG_WR(bp, MCP_REG_MCPR_ACCESS_LOCK, 0);
  3071. }
  3072. #define BNX2X_DEF_SB_ATT_IDX 0x0001
  3073. #define BNX2X_DEF_SB_IDX 0x0002
  3074. static u16 bnx2x_update_dsb_idx(struct bnx2x *bp)
  3075. {
  3076. struct host_sp_status_block *def_sb = bp->def_status_blk;
  3077. u16 rc = 0;
  3078. barrier(); /* status block is written to by the chip */
  3079. if (bp->def_att_idx != def_sb->atten_status_block.attn_bits_index) {
  3080. bp->def_att_idx = def_sb->atten_status_block.attn_bits_index;
  3081. rc |= BNX2X_DEF_SB_ATT_IDX;
  3082. }
  3083. if (bp->def_idx != def_sb->sp_sb.running_index) {
  3084. bp->def_idx = def_sb->sp_sb.running_index;
  3085. rc |= BNX2X_DEF_SB_IDX;
  3086. }
  3087. /* Do not reorder: indices reading should complete before handling */
  3088. barrier();
  3089. return rc;
  3090. }
  3091. /*
  3092. * slow path service functions
  3093. */
  3094. static void bnx2x_attn_int_asserted(struct bnx2x *bp, u32 asserted)
  3095. {
  3096. int port = BP_PORT(bp);
  3097. u32 aeu_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  3098. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  3099. u32 nig_int_mask_addr = port ? NIG_REG_MASK_INTERRUPT_PORT1 :
  3100. NIG_REG_MASK_INTERRUPT_PORT0;
  3101. u32 aeu_mask;
  3102. u32 nig_mask = 0;
  3103. u32 reg_addr;
  3104. if (bp->attn_state & asserted)
  3105. BNX2X_ERR("IGU ERROR\n");
  3106. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3107. aeu_mask = REG_RD(bp, aeu_addr);
  3108. DP(NETIF_MSG_HW, "aeu_mask %x newly asserted %x\n",
  3109. aeu_mask, asserted);
  3110. aeu_mask &= ~(asserted & 0x3ff);
  3111. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  3112. REG_WR(bp, aeu_addr, aeu_mask);
  3113. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  3114. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  3115. bp->attn_state |= asserted;
  3116. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  3117. if (asserted & ATTN_HARD_WIRED_MASK) {
  3118. if (asserted & ATTN_NIG_FOR_FUNC) {
  3119. bnx2x_acquire_phy_lock(bp);
  3120. /* save nig interrupt mask */
  3121. nig_mask = REG_RD(bp, nig_int_mask_addr);
  3122. /* If nig_mask is not set, no need to call the update
  3123. * function.
  3124. */
  3125. if (nig_mask) {
  3126. REG_WR(bp, nig_int_mask_addr, 0);
  3127. bnx2x_link_attn(bp);
  3128. }
  3129. /* handle unicore attn? */
  3130. }
  3131. if (asserted & ATTN_SW_TIMER_4_FUNC)
  3132. DP(NETIF_MSG_HW, "ATTN_SW_TIMER_4_FUNC!\n");
  3133. if (asserted & GPIO_2_FUNC)
  3134. DP(NETIF_MSG_HW, "GPIO_2_FUNC!\n");
  3135. if (asserted & GPIO_3_FUNC)
  3136. DP(NETIF_MSG_HW, "GPIO_3_FUNC!\n");
  3137. if (asserted & GPIO_4_FUNC)
  3138. DP(NETIF_MSG_HW, "GPIO_4_FUNC!\n");
  3139. if (port == 0) {
  3140. if (asserted & ATTN_GENERAL_ATTN_1) {
  3141. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_1!\n");
  3142. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_1, 0x0);
  3143. }
  3144. if (asserted & ATTN_GENERAL_ATTN_2) {
  3145. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_2!\n");
  3146. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_2, 0x0);
  3147. }
  3148. if (asserted & ATTN_GENERAL_ATTN_3) {
  3149. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_3!\n");
  3150. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_3, 0x0);
  3151. }
  3152. } else {
  3153. if (asserted & ATTN_GENERAL_ATTN_4) {
  3154. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_4!\n");
  3155. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_4, 0x0);
  3156. }
  3157. if (asserted & ATTN_GENERAL_ATTN_5) {
  3158. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_5!\n");
  3159. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_5, 0x0);
  3160. }
  3161. if (asserted & ATTN_GENERAL_ATTN_6) {
  3162. DP(NETIF_MSG_HW, "ATTN_GENERAL_ATTN_6!\n");
  3163. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_6, 0x0);
  3164. }
  3165. }
  3166. } /* if hardwired */
  3167. if (bp->common.int_block == INT_BLOCK_HC)
  3168. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  3169. COMMAND_REG_ATTN_BITS_SET);
  3170. else
  3171. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_SET_UPPER*8);
  3172. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", asserted,
  3173. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  3174. REG_WR(bp, reg_addr, asserted);
  3175. /* now set back the mask */
  3176. if (asserted & ATTN_NIG_FOR_FUNC) {
  3177. /* Verify that IGU ack through BAR was written before restoring
  3178. * NIG mask. This loop should exit after 2-3 iterations max.
  3179. */
  3180. if (bp->common.int_block != INT_BLOCK_HC) {
  3181. u32 cnt = 0, igu_acked;
  3182. do {
  3183. igu_acked = REG_RD(bp,
  3184. IGU_REG_ATTENTION_ACK_BITS);
  3185. } while (((igu_acked & ATTN_NIG_FOR_FUNC) == 0) &&
  3186. (++cnt < MAX_IGU_ATTN_ACK_TO));
  3187. if (!igu_acked)
  3188. DP(NETIF_MSG_HW,
  3189. "Failed to verify IGU ack on time\n");
  3190. barrier();
  3191. }
  3192. REG_WR(bp, nig_int_mask_addr, nig_mask);
  3193. bnx2x_release_phy_lock(bp);
  3194. }
  3195. }
  3196. static void bnx2x_fan_failure(struct bnx2x *bp)
  3197. {
  3198. int port = BP_PORT(bp);
  3199. u32 ext_phy_config;
  3200. /* mark the failure */
  3201. ext_phy_config =
  3202. SHMEM_RD(bp,
  3203. dev_info.port_hw_config[port].external_phy_config);
  3204. ext_phy_config &= ~PORT_HW_CFG_XGXS_EXT_PHY_TYPE_MASK;
  3205. ext_phy_config |= PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE;
  3206. SHMEM_WR(bp, dev_info.port_hw_config[port].external_phy_config,
  3207. ext_phy_config);
  3208. /* log the failure */
  3209. netdev_err(bp->dev, "Fan Failure on Network Controller has caused the driver to shutdown the card to prevent permanent damage.\n"
  3210. "Please contact OEM Support for assistance\n");
  3211. /* Schedule device reset (unload)
  3212. * This is due to some boards consuming sufficient power when driver is
  3213. * up to overheat if fan fails.
  3214. */
  3215. smp_mb__before_clear_bit();
  3216. set_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state);
  3217. smp_mb__after_clear_bit();
  3218. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  3219. }
  3220. static void bnx2x_attn_int_deasserted0(struct bnx2x *bp, u32 attn)
  3221. {
  3222. int port = BP_PORT(bp);
  3223. int reg_offset;
  3224. u32 val;
  3225. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  3226. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  3227. if (attn & AEU_INPUTS_ATTN_BITS_SPIO5) {
  3228. val = REG_RD(bp, reg_offset);
  3229. val &= ~AEU_INPUTS_ATTN_BITS_SPIO5;
  3230. REG_WR(bp, reg_offset, val);
  3231. BNX2X_ERR("SPIO5 hw attention\n");
  3232. /* Fan failure attention */
  3233. bnx2x_hw_reset_phy(&bp->link_params);
  3234. bnx2x_fan_failure(bp);
  3235. }
  3236. if ((attn & bp->link_vars.aeu_int_mask) && bp->port.pmf) {
  3237. bnx2x_acquire_phy_lock(bp);
  3238. bnx2x_handle_module_detect_int(&bp->link_params);
  3239. bnx2x_release_phy_lock(bp);
  3240. }
  3241. if (attn & HW_INTERRUT_ASSERT_SET_0) {
  3242. val = REG_RD(bp, reg_offset);
  3243. val &= ~(attn & HW_INTERRUT_ASSERT_SET_0);
  3244. REG_WR(bp, reg_offset, val);
  3245. BNX2X_ERR("FATAL HW block attention set0 0x%x\n",
  3246. (u32)(attn & HW_INTERRUT_ASSERT_SET_0));
  3247. bnx2x_panic();
  3248. }
  3249. }
  3250. static void bnx2x_attn_int_deasserted1(struct bnx2x *bp, u32 attn)
  3251. {
  3252. u32 val;
  3253. if (attn & AEU_INPUTS_ATTN_BITS_DOORBELLQ_HW_INTERRUPT) {
  3254. val = REG_RD(bp, DORQ_REG_DORQ_INT_STS_CLR);
  3255. BNX2X_ERR("DB hw attention 0x%x\n", val);
  3256. /* DORQ discard attention */
  3257. if (val & 0x2)
  3258. BNX2X_ERR("FATAL error from DORQ\n");
  3259. }
  3260. if (attn & HW_INTERRUT_ASSERT_SET_1) {
  3261. int port = BP_PORT(bp);
  3262. int reg_offset;
  3263. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_1 :
  3264. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_1);
  3265. val = REG_RD(bp, reg_offset);
  3266. val &= ~(attn & HW_INTERRUT_ASSERT_SET_1);
  3267. REG_WR(bp, reg_offset, val);
  3268. BNX2X_ERR("FATAL HW block attention set1 0x%x\n",
  3269. (u32)(attn & HW_INTERRUT_ASSERT_SET_1));
  3270. bnx2x_panic();
  3271. }
  3272. }
  3273. static void bnx2x_attn_int_deasserted2(struct bnx2x *bp, u32 attn)
  3274. {
  3275. u32 val;
  3276. if (attn & AEU_INPUTS_ATTN_BITS_CFC_HW_INTERRUPT) {
  3277. val = REG_RD(bp, CFC_REG_CFC_INT_STS_CLR);
  3278. BNX2X_ERR("CFC hw attention 0x%x\n", val);
  3279. /* CFC error attention */
  3280. if (val & 0x2)
  3281. BNX2X_ERR("FATAL error from CFC\n");
  3282. }
  3283. if (attn & AEU_INPUTS_ATTN_BITS_PXP_HW_INTERRUPT) {
  3284. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_0);
  3285. BNX2X_ERR("PXP hw attention-0 0x%x\n", val);
  3286. /* RQ_USDMDP_FIFO_OVERFLOW */
  3287. if (val & 0x18000)
  3288. BNX2X_ERR("FATAL error from PXP\n");
  3289. if (!CHIP_IS_E1x(bp)) {
  3290. val = REG_RD(bp, PXP_REG_PXP_INT_STS_CLR_1);
  3291. BNX2X_ERR("PXP hw attention-1 0x%x\n", val);
  3292. }
  3293. }
  3294. if (attn & HW_INTERRUT_ASSERT_SET_2) {
  3295. int port = BP_PORT(bp);
  3296. int reg_offset;
  3297. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_2 :
  3298. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_2);
  3299. val = REG_RD(bp, reg_offset);
  3300. val &= ~(attn & HW_INTERRUT_ASSERT_SET_2);
  3301. REG_WR(bp, reg_offset, val);
  3302. BNX2X_ERR("FATAL HW block attention set2 0x%x\n",
  3303. (u32)(attn & HW_INTERRUT_ASSERT_SET_2));
  3304. bnx2x_panic();
  3305. }
  3306. }
  3307. static void bnx2x_attn_int_deasserted3(struct bnx2x *bp, u32 attn)
  3308. {
  3309. u32 val;
  3310. if (attn & EVEREST_GEN_ATTN_IN_USE_MASK) {
  3311. if (attn & BNX2X_PMF_LINK_ASSERT) {
  3312. int func = BP_FUNC(bp);
  3313. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  3314. bnx2x_read_mf_cfg(bp);
  3315. bp->mf_config[BP_VN(bp)] = MF_CFG_RD(bp,
  3316. func_mf_config[BP_ABS_FUNC(bp)].config);
  3317. val = SHMEM_RD(bp,
  3318. func_mb[BP_FW_MB_IDX(bp)].drv_status);
  3319. if (val & DRV_STATUS_DCC_EVENT_MASK)
  3320. bnx2x_dcc_event(bp,
  3321. (val & DRV_STATUS_DCC_EVENT_MASK));
  3322. if (val & DRV_STATUS_SET_MF_BW)
  3323. bnx2x_set_mf_bw(bp);
  3324. if (val & DRV_STATUS_DRV_INFO_REQ)
  3325. bnx2x_handle_drv_info_req(bp);
  3326. if (val & DRV_STATUS_VF_DISABLED)
  3327. bnx2x_vf_handle_flr_event(bp);
  3328. if ((bp->port.pmf == 0) && (val & DRV_STATUS_PMF))
  3329. bnx2x_pmf_update(bp);
  3330. if (bp->port.pmf &&
  3331. (val & DRV_STATUS_DCBX_NEGOTIATION_RESULTS) &&
  3332. bp->dcbx_enabled > 0)
  3333. /* start dcbx state machine */
  3334. bnx2x_dcbx_set_params(bp,
  3335. BNX2X_DCBX_STATE_NEG_RECEIVED);
  3336. if (val & DRV_STATUS_AFEX_EVENT_MASK)
  3337. bnx2x_handle_afex_cmd(bp,
  3338. val & DRV_STATUS_AFEX_EVENT_MASK);
  3339. if (val & DRV_STATUS_EEE_NEGOTIATION_RESULTS)
  3340. bnx2x_handle_eee_event(bp);
  3341. if (bp->link_vars.periodic_flags &
  3342. PERIODIC_FLAGS_LINK_EVENT) {
  3343. /* sync with link */
  3344. bnx2x_acquire_phy_lock(bp);
  3345. bp->link_vars.periodic_flags &=
  3346. ~PERIODIC_FLAGS_LINK_EVENT;
  3347. bnx2x_release_phy_lock(bp);
  3348. if (IS_MF(bp))
  3349. bnx2x_link_sync_notify(bp);
  3350. bnx2x_link_report(bp);
  3351. }
  3352. /* Always call it here: bnx2x_link_report() will
  3353. * prevent the link indication duplication.
  3354. */
  3355. bnx2x__link_status_update(bp);
  3356. } else if (attn & BNX2X_MC_ASSERT_BITS) {
  3357. BNX2X_ERR("MC assert!\n");
  3358. bnx2x_mc_assert(bp);
  3359. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_10, 0);
  3360. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_9, 0);
  3361. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_8, 0);
  3362. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_7, 0);
  3363. bnx2x_panic();
  3364. } else if (attn & BNX2X_MCP_ASSERT) {
  3365. BNX2X_ERR("MCP assert!\n");
  3366. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_11, 0);
  3367. bnx2x_fw_dump(bp);
  3368. } else
  3369. BNX2X_ERR("Unknown HW assert! (attn 0x%x)\n", attn);
  3370. }
  3371. if (attn & EVEREST_LATCHED_ATTN_IN_USE_MASK) {
  3372. BNX2X_ERR("LATCHED attention 0x%08x (masked)\n", attn);
  3373. if (attn & BNX2X_GRC_TIMEOUT) {
  3374. val = CHIP_IS_E1(bp) ? 0 :
  3375. REG_RD(bp, MISC_REG_GRC_TIMEOUT_ATTN);
  3376. BNX2X_ERR("GRC time-out 0x%08x\n", val);
  3377. }
  3378. if (attn & BNX2X_GRC_RSV) {
  3379. val = CHIP_IS_E1(bp) ? 0 :
  3380. REG_RD(bp, MISC_REG_GRC_RSV_ATTN);
  3381. BNX2X_ERR("GRC reserved 0x%08x\n", val);
  3382. }
  3383. REG_WR(bp, MISC_REG_AEU_CLR_LATCH_SIGNAL, 0x7ff);
  3384. }
  3385. }
  3386. /*
  3387. * Bits map:
  3388. * 0-7 - Engine0 load counter.
  3389. * 8-15 - Engine1 load counter.
  3390. * 16 - Engine0 RESET_IN_PROGRESS bit.
  3391. * 17 - Engine1 RESET_IN_PROGRESS bit.
  3392. * 18 - Engine0 ONE_IS_LOADED. Set when there is at least one active function
  3393. * on the engine
  3394. * 19 - Engine1 ONE_IS_LOADED.
  3395. * 20 - Chip reset flow bit. When set none-leader must wait for both engines
  3396. * leader to complete (check for both RESET_IN_PROGRESS bits and not for
  3397. * just the one belonging to its engine).
  3398. *
  3399. */
  3400. #define BNX2X_RECOVERY_GLOB_REG MISC_REG_GENERIC_POR_1
  3401. #define BNX2X_PATH0_LOAD_CNT_MASK 0x000000ff
  3402. #define BNX2X_PATH0_LOAD_CNT_SHIFT 0
  3403. #define BNX2X_PATH1_LOAD_CNT_MASK 0x0000ff00
  3404. #define BNX2X_PATH1_LOAD_CNT_SHIFT 8
  3405. #define BNX2X_PATH0_RST_IN_PROG_BIT 0x00010000
  3406. #define BNX2X_PATH1_RST_IN_PROG_BIT 0x00020000
  3407. #define BNX2X_GLOBAL_RESET_BIT 0x00040000
  3408. /*
  3409. * Set the GLOBAL_RESET bit.
  3410. *
  3411. * Should be run under rtnl lock
  3412. */
  3413. void bnx2x_set_reset_global(struct bnx2x *bp)
  3414. {
  3415. u32 val;
  3416. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3417. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3418. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val | BNX2X_GLOBAL_RESET_BIT);
  3419. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3420. }
  3421. /*
  3422. * Clear the GLOBAL_RESET bit.
  3423. *
  3424. * Should be run under rtnl lock
  3425. */
  3426. static void bnx2x_clear_reset_global(struct bnx2x *bp)
  3427. {
  3428. u32 val;
  3429. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3430. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3431. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val & (~BNX2X_GLOBAL_RESET_BIT));
  3432. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3433. }
  3434. /*
  3435. * Checks the GLOBAL_RESET bit.
  3436. *
  3437. * should be run under rtnl lock
  3438. */
  3439. static bool bnx2x_reset_is_global(struct bnx2x *bp)
  3440. {
  3441. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3442. DP(NETIF_MSG_HW, "GEN_REG_VAL=0x%08x\n", val);
  3443. return (val & BNX2X_GLOBAL_RESET_BIT) ? true : false;
  3444. }
  3445. /*
  3446. * Clear RESET_IN_PROGRESS bit for the current engine.
  3447. *
  3448. * Should be run under rtnl lock
  3449. */
  3450. static void bnx2x_set_reset_done(struct bnx2x *bp)
  3451. {
  3452. u32 val;
  3453. u32 bit = BP_PATH(bp) ?
  3454. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3455. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3456. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3457. /* Clear the bit */
  3458. val &= ~bit;
  3459. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3460. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3461. }
  3462. /*
  3463. * Set RESET_IN_PROGRESS for the current engine.
  3464. *
  3465. * should be run under rtnl lock
  3466. */
  3467. void bnx2x_set_reset_in_progress(struct bnx2x *bp)
  3468. {
  3469. u32 val;
  3470. u32 bit = BP_PATH(bp) ?
  3471. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3472. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3473. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3474. /* Set the bit */
  3475. val |= bit;
  3476. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3477. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3478. }
  3479. /*
  3480. * Checks the RESET_IN_PROGRESS bit for the given engine.
  3481. * should be run under rtnl lock
  3482. */
  3483. bool bnx2x_reset_is_done(struct bnx2x *bp, int engine)
  3484. {
  3485. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3486. u32 bit = engine ?
  3487. BNX2X_PATH1_RST_IN_PROG_BIT : BNX2X_PATH0_RST_IN_PROG_BIT;
  3488. /* return false if bit is set */
  3489. return (val & bit) ? false : true;
  3490. }
  3491. /*
  3492. * set pf load for the current pf.
  3493. *
  3494. * should be run under rtnl lock
  3495. */
  3496. void bnx2x_set_pf_load(struct bnx2x *bp)
  3497. {
  3498. u32 val1, val;
  3499. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3500. BNX2X_PATH0_LOAD_CNT_MASK;
  3501. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3502. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3503. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3504. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3505. DP(NETIF_MSG_IFUP, "Old GEN_REG_VAL=0x%08x\n", val);
  3506. /* get the current counter value */
  3507. val1 = (val & mask) >> shift;
  3508. /* set bit of that PF */
  3509. val1 |= (1 << bp->pf_num);
  3510. /* clear the old value */
  3511. val &= ~mask;
  3512. /* set the new one */
  3513. val |= ((val1 << shift) & mask);
  3514. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3515. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3516. }
  3517. /**
  3518. * bnx2x_clear_pf_load - clear pf load mark
  3519. *
  3520. * @bp: driver handle
  3521. *
  3522. * Should be run under rtnl lock.
  3523. * Decrements the load counter for the current engine. Returns
  3524. * whether other functions are still loaded
  3525. */
  3526. bool bnx2x_clear_pf_load(struct bnx2x *bp)
  3527. {
  3528. u32 val1, val;
  3529. u32 mask = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_MASK :
  3530. BNX2X_PATH0_LOAD_CNT_MASK;
  3531. u32 shift = BP_PATH(bp) ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3532. BNX2X_PATH0_LOAD_CNT_SHIFT;
  3533. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3534. val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3535. DP(NETIF_MSG_IFDOWN, "Old GEN_REG_VAL=0x%08x\n", val);
  3536. /* get the current counter value */
  3537. val1 = (val & mask) >> shift;
  3538. /* clear bit of that PF */
  3539. val1 &= ~(1 << bp->pf_num);
  3540. /* clear the old value */
  3541. val &= ~mask;
  3542. /* set the new one */
  3543. val |= ((val1 << shift) & mask);
  3544. REG_WR(bp, BNX2X_RECOVERY_GLOB_REG, val);
  3545. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RECOVERY_REG);
  3546. return val1 != 0;
  3547. }
  3548. /*
  3549. * Read the load status for the current engine.
  3550. *
  3551. * should be run under rtnl lock
  3552. */
  3553. static bool bnx2x_get_load_status(struct bnx2x *bp, int engine)
  3554. {
  3555. u32 mask = (engine ? BNX2X_PATH1_LOAD_CNT_MASK :
  3556. BNX2X_PATH0_LOAD_CNT_MASK);
  3557. u32 shift = (engine ? BNX2X_PATH1_LOAD_CNT_SHIFT :
  3558. BNX2X_PATH0_LOAD_CNT_SHIFT);
  3559. u32 val = REG_RD(bp, BNX2X_RECOVERY_GLOB_REG);
  3560. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "GLOB_REG=0x%08x\n", val);
  3561. val = (val & mask) >> shift;
  3562. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "load mask for engine %d = 0x%x\n",
  3563. engine, val);
  3564. return val != 0;
  3565. }
  3566. static void _print_parity(struct bnx2x *bp, u32 reg)
  3567. {
  3568. pr_cont(" [0x%08x] ", REG_RD(bp, reg));
  3569. }
  3570. static void _print_next_block(int idx, const char *blk)
  3571. {
  3572. pr_cont("%s%s", idx ? ", " : "", blk);
  3573. }
  3574. static int bnx2x_check_blocks_with_parity0(struct bnx2x *bp, u32 sig,
  3575. int par_num, 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_BRB_PARITY_ERROR:
  3584. if (print) {
  3585. _print_next_block(par_num++, "BRB");
  3586. _print_parity(bp,
  3587. BRB1_REG_BRB1_PRTY_STS);
  3588. }
  3589. break;
  3590. case AEU_INPUTS_ATTN_BITS_PARSER_PARITY_ERROR:
  3591. if (print) {
  3592. _print_next_block(par_num++, "PARSER");
  3593. _print_parity(bp, PRS_REG_PRS_PRTY_STS);
  3594. }
  3595. break;
  3596. case AEU_INPUTS_ATTN_BITS_TSDM_PARITY_ERROR:
  3597. if (print) {
  3598. _print_next_block(par_num++, "TSDM");
  3599. _print_parity(bp,
  3600. TSDM_REG_TSDM_PRTY_STS);
  3601. }
  3602. break;
  3603. case AEU_INPUTS_ATTN_BITS_SEARCHER_PARITY_ERROR:
  3604. if (print) {
  3605. _print_next_block(par_num++,
  3606. "SEARCHER");
  3607. _print_parity(bp, SRC_REG_SRC_PRTY_STS);
  3608. }
  3609. break;
  3610. case AEU_INPUTS_ATTN_BITS_TCM_PARITY_ERROR:
  3611. if (print) {
  3612. _print_next_block(par_num++, "TCM");
  3613. _print_parity(bp,
  3614. TCM_REG_TCM_PRTY_STS);
  3615. }
  3616. break;
  3617. case AEU_INPUTS_ATTN_BITS_TSEMI_PARITY_ERROR:
  3618. if (print) {
  3619. _print_next_block(par_num++, "TSEMI");
  3620. _print_parity(bp,
  3621. TSEM_REG_TSEM_PRTY_STS_0);
  3622. _print_parity(bp,
  3623. TSEM_REG_TSEM_PRTY_STS_1);
  3624. }
  3625. break;
  3626. case AEU_INPUTS_ATTN_BITS_PBCLIENT_PARITY_ERROR:
  3627. if (print) {
  3628. _print_next_block(par_num++, "XPB");
  3629. _print_parity(bp, GRCBASE_XPB +
  3630. PB_REG_PB_PRTY_STS);
  3631. }
  3632. break;
  3633. }
  3634. /* Clear the bit */
  3635. sig &= ~cur_bit;
  3636. }
  3637. }
  3638. return par_num;
  3639. }
  3640. static int bnx2x_check_blocks_with_parity1(struct bnx2x *bp, u32 sig,
  3641. int par_num, bool *global,
  3642. bool print)
  3643. {
  3644. int i = 0;
  3645. u32 cur_bit = 0;
  3646. for (i = 0; sig; i++) {
  3647. cur_bit = ((u32)0x1 << i);
  3648. if (sig & cur_bit) {
  3649. switch (cur_bit) {
  3650. case AEU_INPUTS_ATTN_BITS_PBF_PARITY_ERROR:
  3651. if (print) {
  3652. _print_next_block(par_num++, "PBF");
  3653. _print_parity(bp, PBF_REG_PBF_PRTY_STS);
  3654. }
  3655. break;
  3656. case AEU_INPUTS_ATTN_BITS_QM_PARITY_ERROR:
  3657. if (print) {
  3658. _print_next_block(par_num++, "QM");
  3659. _print_parity(bp, QM_REG_QM_PRTY_STS);
  3660. }
  3661. break;
  3662. case AEU_INPUTS_ATTN_BITS_TIMERS_PARITY_ERROR:
  3663. if (print) {
  3664. _print_next_block(par_num++, "TM");
  3665. _print_parity(bp, TM_REG_TM_PRTY_STS);
  3666. }
  3667. break;
  3668. case AEU_INPUTS_ATTN_BITS_XSDM_PARITY_ERROR:
  3669. if (print) {
  3670. _print_next_block(par_num++, "XSDM");
  3671. _print_parity(bp,
  3672. XSDM_REG_XSDM_PRTY_STS);
  3673. }
  3674. break;
  3675. case AEU_INPUTS_ATTN_BITS_XCM_PARITY_ERROR:
  3676. if (print) {
  3677. _print_next_block(par_num++, "XCM");
  3678. _print_parity(bp, XCM_REG_XCM_PRTY_STS);
  3679. }
  3680. break;
  3681. case AEU_INPUTS_ATTN_BITS_XSEMI_PARITY_ERROR:
  3682. if (print) {
  3683. _print_next_block(par_num++, "XSEMI");
  3684. _print_parity(bp,
  3685. XSEM_REG_XSEM_PRTY_STS_0);
  3686. _print_parity(bp,
  3687. XSEM_REG_XSEM_PRTY_STS_1);
  3688. }
  3689. break;
  3690. case AEU_INPUTS_ATTN_BITS_DOORBELLQ_PARITY_ERROR:
  3691. if (print) {
  3692. _print_next_block(par_num++,
  3693. "DOORBELLQ");
  3694. _print_parity(bp,
  3695. DORQ_REG_DORQ_PRTY_STS);
  3696. }
  3697. break;
  3698. case AEU_INPUTS_ATTN_BITS_NIG_PARITY_ERROR:
  3699. if (print) {
  3700. _print_next_block(par_num++, "NIG");
  3701. if (CHIP_IS_E1x(bp)) {
  3702. _print_parity(bp,
  3703. NIG_REG_NIG_PRTY_STS);
  3704. } else {
  3705. _print_parity(bp,
  3706. NIG_REG_NIG_PRTY_STS_0);
  3707. _print_parity(bp,
  3708. NIG_REG_NIG_PRTY_STS_1);
  3709. }
  3710. }
  3711. break;
  3712. case AEU_INPUTS_ATTN_BITS_VAUX_PCI_CORE_PARITY_ERROR:
  3713. if (print)
  3714. _print_next_block(par_num++,
  3715. "VAUX PCI CORE");
  3716. *global = true;
  3717. break;
  3718. case AEU_INPUTS_ATTN_BITS_DEBUG_PARITY_ERROR:
  3719. if (print) {
  3720. _print_next_block(par_num++, "DEBUG");
  3721. _print_parity(bp, DBG_REG_DBG_PRTY_STS);
  3722. }
  3723. break;
  3724. case AEU_INPUTS_ATTN_BITS_USDM_PARITY_ERROR:
  3725. if (print) {
  3726. _print_next_block(par_num++, "USDM");
  3727. _print_parity(bp,
  3728. USDM_REG_USDM_PRTY_STS);
  3729. }
  3730. break;
  3731. case AEU_INPUTS_ATTN_BITS_UCM_PARITY_ERROR:
  3732. if (print) {
  3733. _print_next_block(par_num++, "UCM");
  3734. _print_parity(bp, UCM_REG_UCM_PRTY_STS);
  3735. }
  3736. break;
  3737. case AEU_INPUTS_ATTN_BITS_USEMI_PARITY_ERROR:
  3738. if (print) {
  3739. _print_next_block(par_num++, "USEMI");
  3740. _print_parity(bp,
  3741. USEM_REG_USEM_PRTY_STS_0);
  3742. _print_parity(bp,
  3743. USEM_REG_USEM_PRTY_STS_1);
  3744. }
  3745. break;
  3746. case AEU_INPUTS_ATTN_BITS_UPB_PARITY_ERROR:
  3747. if (print) {
  3748. _print_next_block(par_num++, "UPB");
  3749. _print_parity(bp, GRCBASE_UPB +
  3750. PB_REG_PB_PRTY_STS);
  3751. }
  3752. break;
  3753. case AEU_INPUTS_ATTN_BITS_CSDM_PARITY_ERROR:
  3754. if (print) {
  3755. _print_next_block(par_num++, "CSDM");
  3756. _print_parity(bp,
  3757. CSDM_REG_CSDM_PRTY_STS);
  3758. }
  3759. break;
  3760. case AEU_INPUTS_ATTN_BITS_CCM_PARITY_ERROR:
  3761. if (print) {
  3762. _print_next_block(par_num++, "CCM");
  3763. _print_parity(bp, CCM_REG_CCM_PRTY_STS);
  3764. }
  3765. break;
  3766. }
  3767. /* Clear the bit */
  3768. sig &= ~cur_bit;
  3769. }
  3770. }
  3771. return par_num;
  3772. }
  3773. static int bnx2x_check_blocks_with_parity2(struct bnx2x *bp, u32 sig,
  3774. int par_num, bool print)
  3775. {
  3776. int i = 0;
  3777. u32 cur_bit = 0;
  3778. for (i = 0; sig; i++) {
  3779. cur_bit = ((u32)0x1 << i);
  3780. if (sig & cur_bit) {
  3781. switch (cur_bit) {
  3782. case AEU_INPUTS_ATTN_BITS_CSEMI_PARITY_ERROR:
  3783. if (print) {
  3784. _print_next_block(par_num++, "CSEMI");
  3785. _print_parity(bp,
  3786. CSEM_REG_CSEM_PRTY_STS_0);
  3787. _print_parity(bp,
  3788. CSEM_REG_CSEM_PRTY_STS_1);
  3789. }
  3790. break;
  3791. case AEU_INPUTS_ATTN_BITS_PXP_PARITY_ERROR:
  3792. if (print) {
  3793. _print_next_block(par_num++, "PXP");
  3794. _print_parity(bp, PXP_REG_PXP_PRTY_STS);
  3795. _print_parity(bp,
  3796. PXP2_REG_PXP2_PRTY_STS_0);
  3797. _print_parity(bp,
  3798. PXP2_REG_PXP2_PRTY_STS_1);
  3799. }
  3800. break;
  3801. case AEU_IN_ATTN_BITS_PXPPCICLOCKCLIENT_PARITY_ERROR:
  3802. if (print)
  3803. _print_next_block(par_num++,
  3804. "PXPPCICLOCKCLIENT");
  3805. break;
  3806. case AEU_INPUTS_ATTN_BITS_CFC_PARITY_ERROR:
  3807. if (print) {
  3808. _print_next_block(par_num++, "CFC");
  3809. _print_parity(bp,
  3810. CFC_REG_CFC_PRTY_STS);
  3811. }
  3812. break;
  3813. case AEU_INPUTS_ATTN_BITS_CDU_PARITY_ERROR:
  3814. if (print) {
  3815. _print_next_block(par_num++, "CDU");
  3816. _print_parity(bp, CDU_REG_CDU_PRTY_STS);
  3817. }
  3818. break;
  3819. case AEU_INPUTS_ATTN_BITS_DMAE_PARITY_ERROR:
  3820. if (print) {
  3821. _print_next_block(par_num++, "DMAE");
  3822. _print_parity(bp,
  3823. DMAE_REG_DMAE_PRTY_STS);
  3824. }
  3825. break;
  3826. case AEU_INPUTS_ATTN_BITS_IGU_PARITY_ERROR:
  3827. if (print) {
  3828. _print_next_block(par_num++, "IGU");
  3829. if (CHIP_IS_E1x(bp))
  3830. _print_parity(bp,
  3831. HC_REG_HC_PRTY_STS);
  3832. else
  3833. _print_parity(bp,
  3834. IGU_REG_IGU_PRTY_STS);
  3835. }
  3836. break;
  3837. case AEU_INPUTS_ATTN_BITS_MISC_PARITY_ERROR:
  3838. if (print) {
  3839. _print_next_block(par_num++, "MISC");
  3840. _print_parity(bp,
  3841. MISC_REG_MISC_PRTY_STS);
  3842. }
  3843. break;
  3844. }
  3845. /* Clear the bit */
  3846. sig &= ~cur_bit;
  3847. }
  3848. }
  3849. return par_num;
  3850. }
  3851. static int bnx2x_check_blocks_with_parity3(u32 sig, int par_num,
  3852. bool *global, bool print)
  3853. {
  3854. int i = 0;
  3855. u32 cur_bit = 0;
  3856. for (i = 0; sig; i++) {
  3857. cur_bit = ((u32)0x1 << i);
  3858. if (sig & cur_bit) {
  3859. switch (cur_bit) {
  3860. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_ROM_PARITY:
  3861. if (print)
  3862. _print_next_block(par_num++, "MCP ROM");
  3863. *global = true;
  3864. break;
  3865. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_RX_PARITY:
  3866. if (print)
  3867. _print_next_block(par_num++,
  3868. "MCP UMP RX");
  3869. *global = true;
  3870. break;
  3871. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_UMP_TX_PARITY:
  3872. if (print)
  3873. _print_next_block(par_num++,
  3874. "MCP UMP TX");
  3875. *global = true;
  3876. break;
  3877. case AEU_INPUTS_ATTN_BITS_MCP_LATCHED_SCPAD_PARITY:
  3878. if (print)
  3879. _print_next_block(par_num++,
  3880. "MCP SCPAD");
  3881. *global = true;
  3882. break;
  3883. }
  3884. /* Clear the bit */
  3885. sig &= ~cur_bit;
  3886. }
  3887. }
  3888. return par_num;
  3889. }
  3890. static int bnx2x_check_blocks_with_parity4(struct bnx2x *bp, u32 sig,
  3891. int par_num, bool print)
  3892. {
  3893. int i = 0;
  3894. u32 cur_bit = 0;
  3895. for (i = 0; sig; i++) {
  3896. cur_bit = ((u32)0x1 << i);
  3897. if (sig & cur_bit) {
  3898. switch (cur_bit) {
  3899. case AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR:
  3900. if (print) {
  3901. _print_next_block(par_num++, "PGLUE_B");
  3902. _print_parity(bp,
  3903. PGLUE_B_REG_PGLUE_B_PRTY_STS);
  3904. }
  3905. break;
  3906. case AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR:
  3907. if (print) {
  3908. _print_next_block(par_num++, "ATC");
  3909. _print_parity(bp,
  3910. ATC_REG_ATC_PRTY_STS);
  3911. }
  3912. break;
  3913. }
  3914. /* Clear the bit */
  3915. sig &= ~cur_bit;
  3916. }
  3917. }
  3918. return par_num;
  3919. }
  3920. static bool bnx2x_parity_attn(struct bnx2x *bp, bool *global, bool print,
  3921. u32 *sig)
  3922. {
  3923. if ((sig[0] & HW_PRTY_ASSERT_SET_0) ||
  3924. (sig[1] & HW_PRTY_ASSERT_SET_1) ||
  3925. (sig[2] & HW_PRTY_ASSERT_SET_2) ||
  3926. (sig[3] & HW_PRTY_ASSERT_SET_3) ||
  3927. (sig[4] & HW_PRTY_ASSERT_SET_4)) {
  3928. int par_num = 0;
  3929. DP(NETIF_MSG_HW, "Was parity error: HW block parity attention:\n"
  3930. "[0]:0x%08x [1]:0x%08x [2]:0x%08x [3]:0x%08x [4]:0x%08x\n",
  3931. sig[0] & HW_PRTY_ASSERT_SET_0,
  3932. sig[1] & HW_PRTY_ASSERT_SET_1,
  3933. sig[2] & HW_PRTY_ASSERT_SET_2,
  3934. sig[3] & HW_PRTY_ASSERT_SET_3,
  3935. sig[4] & HW_PRTY_ASSERT_SET_4);
  3936. if (print)
  3937. netdev_err(bp->dev,
  3938. "Parity errors detected in blocks: ");
  3939. par_num = bnx2x_check_blocks_with_parity0(bp,
  3940. sig[0] & HW_PRTY_ASSERT_SET_0, par_num, print);
  3941. par_num = bnx2x_check_blocks_with_parity1(bp,
  3942. sig[1] & HW_PRTY_ASSERT_SET_1, par_num, global, print);
  3943. par_num = bnx2x_check_blocks_with_parity2(bp,
  3944. sig[2] & HW_PRTY_ASSERT_SET_2, par_num, print);
  3945. par_num = bnx2x_check_blocks_with_parity3(
  3946. sig[3] & HW_PRTY_ASSERT_SET_3, par_num, global, print);
  3947. par_num = bnx2x_check_blocks_with_parity4(bp,
  3948. sig[4] & HW_PRTY_ASSERT_SET_4, par_num, print);
  3949. if (print)
  3950. pr_cont("\n");
  3951. return true;
  3952. } else
  3953. return false;
  3954. }
  3955. /**
  3956. * bnx2x_chk_parity_attn - checks for parity attentions.
  3957. *
  3958. * @bp: driver handle
  3959. * @global: true if there was a global attention
  3960. * @print: show parity attention in syslog
  3961. */
  3962. bool bnx2x_chk_parity_attn(struct bnx2x *bp, bool *global, bool print)
  3963. {
  3964. struct attn_route attn = { {0} };
  3965. int port = BP_PORT(bp);
  3966. attn.sig[0] = REG_RD(bp,
  3967. MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 +
  3968. port*4);
  3969. attn.sig[1] = REG_RD(bp,
  3970. MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 +
  3971. port*4);
  3972. attn.sig[2] = REG_RD(bp,
  3973. MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 +
  3974. port*4);
  3975. attn.sig[3] = REG_RD(bp,
  3976. MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 +
  3977. port*4);
  3978. if (!CHIP_IS_E1x(bp))
  3979. attn.sig[4] = REG_RD(bp,
  3980. MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 +
  3981. port*4);
  3982. return bnx2x_parity_attn(bp, global, print, attn.sig);
  3983. }
  3984. static void bnx2x_attn_int_deasserted4(struct bnx2x *bp, u32 attn)
  3985. {
  3986. u32 val;
  3987. if (attn & AEU_INPUTS_ATTN_BITS_PGLUE_HW_INTERRUPT) {
  3988. val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS_CLR);
  3989. BNX2X_ERR("PGLUE hw attention 0x%x\n", val);
  3990. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR)
  3991. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_ADDRESS_ERROR\n");
  3992. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR)
  3993. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_INCORRECT_RCV_BEHAVIOR\n");
  3994. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN)
  3995. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN\n");
  3996. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN)
  3997. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_LENGTH_VIOLATION_ATTN\n");
  3998. if (val &
  3999. PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN)
  4000. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_GRC_SPACE_VIOLATION_ATTN\n");
  4001. if (val &
  4002. PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN)
  4003. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_VF_MSIX_BAR_VIOLATION_ATTN\n");
  4004. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN)
  4005. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_ERROR_ATTN\n");
  4006. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN)
  4007. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_TCPL_IN_TWO_RCBS_ATTN\n");
  4008. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW)
  4009. BNX2X_ERR("PGLUE_B_PGLUE_B_INT_STS_REG_CSSNOOP_FIFO_OVERFLOW\n");
  4010. }
  4011. if (attn & AEU_INPUTS_ATTN_BITS_ATC_HW_INTERRUPT) {
  4012. val = REG_RD(bp, ATC_REG_ATC_INT_STS_CLR);
  4013. BNX2X_ERR("ATC hw attention 0x%x\n", val);
  4014. if (val & ATC_ATC_INT_STS_REG_ADDRESS_ERROR)
  4015. BNX2X_ERR("ATC_ATC_INT_STS_REG_ADDRESS_ERROR\n");
  4016. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND)
  4017. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_TO_NOT_PEND\n");
  4018. if (val & ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS)
  4019. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_GPA_MULTIPLE_HITS\n");
  4020. if (val & ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT)
  4021. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_RCPL_TO_EMPTY_CNT\n");
  4022. if (val & ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR)
  4023. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_TCPL_ERROR\n");
  4024. if (val & ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU)
  4025. BNX2X_ERR("ATC_ATC_INT_STS_REG_ATC_IREQ_LESS_THAN_STU\n");
  4026. }
  4027. if (attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4028. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)) {
  4029. BNX2X_ERR("FATAL parity attention set4 0x%x\n",
  4030. (u32)(attn & (AEU_INPUTS_ATTN_BITS_PGLUE_PARITY_ERROR |
  4031. AEU_INPUTS_ATTN_BITS_ATC_PARITY_ERROR)));
  4032. }
  4033. }
  4034. static void bnx2x_attn_int_deasserted(struct bnx2x *bp, u32 deasserted)
  4035. {
  4036. struct attn_route attn, *group_mask;
  4037. int port = BP_PORT(bp);
  4038. int index;
  4039. u32 reg_addr;
  4040. u32 val;
  4041. u32 aeu_mask;
  4042. bool global = false;
  4043. /* need to take HW lock because MCP or other port might also
  4044. try to handle this event */
  4045. bnx2x_acquire_alr(bp);
  4046. if (bnx2x_chk_parity_attn(bp, &global, true)) {
  4047. #ifndef BNX2X_STOP_ON_ERROR
  4048. bp->recovery_state = BNX2X_RECOVERY_INIT;
  4049. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4050. /* Disable HW interrupts */
  4051. bnx2x_int_disable(bp);
  4052. /* In case of parity errors don't handle attentions so that
  4053. * other function would "see" parity errors.
  4054. */
  4055. #else
  4056. bnx2x_panic();
  4057. #endif
  4058. bnx2x_release_alr(bp);
  4059. return;
  4060. }
  4061. attn.sig[0] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + port*4);
  4062. attn.sig[1] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_2_FUNC_0 + port*4);
  4063. attn.sig[2] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_3_FUNC_0 + port*4);
  4064. attn.sig[3] = REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_4_FUNC_0 + port*4);
  4065. if (!CHIP_IS_E1x(bp))
  4066. attn.sig[4] =
  4067. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_5_FUNC_0 + port*4);
  4068. else
  4069. attn.sig[4] = 0;
  4070. DP(NETIF_MSG_HW, "attn: %08x %08x %08x %08x %08x\n",
  4071. attn.sig[0], attn.sig[1], attn.sig[2], attn.sig[3], attn.sig[4]);
  4072. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4073. if (deasserted & (1 << index)) {
  4074. group_mask = &bp->attn_group[index];
  4075. DP(NETIF_MSG_HW, "group[%d]: %08x %08x %08x %08x %08x\n",
  4076. index,
  4077. group_mask->sig[0], group_mask->sig[1],
  4078. group_mask->sig[2], group_mask->sig[3],
  4079. group_mask->sig[4]);
  4080. bnx2x_attn_int_deasserted4(bp,
  4081. attn.sig[4] & group_mask->sig[4]);
  4082. bnx2x_attn_int_deasserted3(bp,
  4083. attn.sig[3] & group_mask->sig[3]);
  4084. bnx2x_attn_int_deasserted1(bp,
  4085. attn.sig[1] & group_mask->sig[1]);
  4086. bnx2x_attn_int_deasserted2(bp,
  4087. attn.sig[2] & group_mask->sig[2]);
  4088. bnx2x_attn_int_deasserted0(bp,
  4089. attn.sig[0] & group_mask->sig[0]);
  4090. }
  4091. }
  4092. bnx2x_release_alr(bp);
  4093. if (bp->common.int_block == INT_BLOCK_HC)
  4094. reg_addr = (HC_REG_COMMAND_REG + port*32 +
  4095. COMMAND_REG_ATTN_BITS_CLR);
  4096. else
  4097. reg_addr = (BAR_IGU_INTMEM + IGU_CMD_ATTN_BIT_CLR_UPPER*8);
  4098. val = ~deasserted;
  4099. DP(NETIF_MSG_HW, "about to mask 0x%08x at %s addr 0x%x\n", val,
  4100. (bp->common.int_block == INT_BLOCK_HC) ? "HC" : "IGU", reg_addr);
  4101. REG_WR(bp, reg_addr, val);
  4102. if (~bp->attn_state & deasserted)
  4103. BNX2X_ERR("IGU ERROR\n");
  4104. reg_addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  4105. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  4106. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4107. aeu_mask = REG_RD(bp, reg_addr);
  4108. DP(NETIF_MSG_HW, "aeu_mask %x newly deasserted %x\n",
  4109. aeu_mask, deasserted);
  4110. aeu_mask |= (deasserted & 0x3ff);
  4111. DP(NETIF_MSG_HW, "new mask %x\n", aeu_mask);
  4112. REG_WR(bp, reg_addr, aeu_mask);
  4113. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_PORT0_ATT_MASK + port);
  4114. DP(NETIF_MSG_HW, "attn_state %x\n", bp->attn_state);
  4115. bp->attn_state &= ~deasserted;
  4116. DP(NETIF_MSG_HW, "new state %x\n", bp->attn_state);
  4117. }
  4118. static void bnx2x_attn_int(struct bnx2x *bp)
  4119. {
  4120. /* read local copy of bits */
  4121. u32 attn_bits = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4122. attn_bits);
  4123. u32 attn_ack = le32_to_cpu(bp->def_status_blk->atten_status_block.
  4124. attn_bits_ack);
  4125. u32 attn_state = bp->attn_state;
  4126. /* look for changed bits */
  4127. u32 asserted = attn_bits & ~attn_ack & ~attn_state;
  4128. u32 deasserted = ~attn_bits & attn_ack & attn_state;
  4129. DP(NETIF_MSG_HW,
  4130. "attn_bits %x attn_ack %x asserted %x deasserted %x\n",
  4131. attn_bits, attn_ack, asserted, deasserted);
  4132. if (~(attn_bits ^ attn_ack) & (attn_bits ^ attn_state))
  4133. BNX2X_ERR("BAD attention state\n");
  4134. /* handle bits that were raised */
  4135. if (asserted)
  4136. bnx2x_attn_int_asserted(bp, asserted);
  4137. if (deasserted)
  4138. bnx2x_attn_int_deasserted(bp, deasserted);
  4139. }
  4140. void bnx2x_igu_ack_sb(struct bnx2x *bp, u8 igu_sb_id, u8 segment,
  4141. u16 index, u8 op, u8 update)
  4142. {
  4143. u32 igu_addr = bp->igu_base_addr;
  4144. igu_addr += (IGU_CMD_INT_ACK_BASE + igu_sb_id)*8;
  4145. bnx2x_igu_ack_sb_gen(bp, igu_sb_id, segment, index, op, update,
  4146. igu_addr);
  4147. }
  4148. static void bnx2x_update_eq_prod(struct bnx2x *bp, u16 prod)
  4149. {
  4150. /* No memory barriers */
  4151. storm_memset_eq_prod(bp, prod, BP_FUNC(bp));
  4152. mmiowb(); /* keep prod updates ordered */
  4153. }
  4154. static int bnx2x_cnic_handle_cfc_del(struct bnx2x *bp, u32 cid,
  4155. union event_ring_elem *elem)
  4156. {
  4157. u8 err = elem->message.error;
  4158. if (!bp->cnic_eth_dev.starting_cid ||
  4159. (cid < bp->cnic_eth_dev.starting_cid &&
  4160. cid != bp->cnic_eth_dev.iscsi_l2_cid))
  4161. return 1;
  4162. DP(BNX2X_MSG_SP, "got delete ramrod for CNIC CID %d\n", cid);
  4163. if (unlikely(err)) {
  4164. BNX2X_ERR("got delete ramrod for CNIC CID %d with error!\n",
  4165. cid);
  4166. bnx2x_panic_dump(bp, false);
  4167. }
  4168. bnx2x_cnic_cfc_comp(bp, cid, err);
  4169. return 0;
  4170. }
  4171. static void bnx2x_handle_mcast_eqe(struct bnx2x *bp)
  4172. {
  4173. struct bnx2x_mcast_ramrod_params rparam;
  4174. int rc;
  4175. memset(&rparam, 0, sizeof(rparam));
  4176. rparam.mcast_obj = &bp->mcast_obj;
  4177. netif_addr_lock_bh(bp->dev);
  4178. /* Clear pending state for the last command */
  4179. bp->mcast_obj.raw.clear_pending(&bp->mcast_obj.raw);
  4180. /* If there are pending mcast commands - send them */
  4181. if (bp->mcast_obj.check_pending(&bp->mcast_obj)) {
  4182. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_CONT);
  4183. if (rc < 0)
  4184. BNX2X_ERR("Failed to send pending mcast commands: %d\n",
  4185. rc);
  4186. }
  4187. netif_addr_unlock_bh(bp->dev);
  4188. }
  4189. static void bnx2x_handle_classification_eqe(struct bnx2x *bp,
  4190. union event_ring_elem *elem)
  4191. {
  4192. unsigned long ramrod_flags = 0;
  4193. int rc = 0;
  4194. u32 cid = elem->message.data.eth_event.echo & BNX2X_SWCID_MASK;
  4195. struct bnx2x_vlan_mac_obj *vlan_mac_obj;
  4196. /* Always push next commands out, don't wait here */
  4197. __set_bit(RAMROD_CONT, &ramrod_flags);
  4198. switch (le32_to_cpu((__force __le32)elem->message.data.eth_event.echo)
  4199. >> BNX2X_SWCID_SHIFT) {
  4200. case BNX2X_FILTER_MAC_PENDING:
  4201. DP(BNX2X_MSG_SP, "Got SETUP_MAC completions\n");
  4202. if (CNIC_LOADED(bp) && (cid == BNX2X_ISCSI_ETH_CID(bp)))
  4203. vlan_mac_obj = &bp->iscsi_l2_mac_obj;
  4204. else
  4205. vlan_mac_obj = &bp->sp_objs[cid].mac_obj;
  4206. break;
  4207. case BNX2X_FILTER_MCAST_PENDING:
  4208. DP(BNX2X_MSG_SP, "Got SETUP_MCAST completions\n");
  4209. /* This is only relevant for 57710 where multicast MACs are
  4210. * configured as unicast MACs using the same ramrod.
  4211. */
  4212. bnx2x_handle_mcast_eqe(bp);
  4213. return;
  4214. default:
  4215. BNX2X_ERR("Unsupported classification command: %d\n",
  4216. elem->message.data.eth_event.echo);
  4217. return;
  4218. }
  4219. rc = vlan_mac_obj->complete(bp, vlan_mac_obj, elem, &ramrod_flags);
  4220. if (rc < 0)
  4221. BNX2X_ERR("Failed to schedule new commands: %d\n", rc);
  4222. else if (rc > 0)
  4223. DP(BNX2X_MSG_SP, "Scheduled next pending commands...\n");
  4224. }
  4225. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start);
  4226. static void bnx2x_handle_rx_mode_eqe(struct bnx2x *bp)
  4227. {
  4228. netif_addr_lock_bh(bp->dev);
  4229. clear_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4230. /* Send rx_mode command again if was requested */
  4231. if (test_and_clear_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state))
  4232. bnx2x_set_storm_rx_mode(bp);
  4233. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED,
  4234. &bp->sp_state))
  4235. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  4236. else if (test_and_clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED,
  4237. &bp->sp_state))
  4238. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  4239. netif_addr_unlock_bh(bp->dev);
  4240. }
  4241. static void bnx2x_after_afex_vif_lists(struct bnx2x *bp,
  4242. union event_ring_elem *elem)
  4243. {
  4244. if (elem->message.data.vif_list_event.echo == VIF_LIST_RULE_GET) {
  4245. DP(BNX2X_MSG_SP,
  4246. "afex: ramrod completed VIF LIST_GET, addrs 0x%x\n",
  4247. elem->message.data.vif_list_event.func_bit_map);
  4248. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTGET_ACK,
  4249. elem->message.data.vif_list_event.func_bit_map);
  4250. } else if (elem->message.data.vif_list_event.echo ==
  4251. VIF_LIST_RULE_SET) {
  4252. DP(BNX2X_MSG_SP, "afex: ramrod completed VIF LIST_SET\n");
  4253. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_LISTSET_ACK, 0);
  4254. }
  4255. }
  4256. /* called with rtnl_lock */
  4257. static void bnx2x_after_function_update(struct bnx2x *bp)
  4258. {
  4259. int q, rc;
  4260. struct bnx2x_fastpath *fp;
  4261. struct bnx2x_queue_state_params queue_params = {NULL};
  4262. struct bnx2x_queue_update_params *q_update_params =
  4263. &queue_params.params.update;
  4264. /* Send Q update command with afex vlan removal values for all Qs */
  4265. queue_params.cmd = BNX2X_Q_CMD_UPDATE;
  4266. /* set silent vlan removal values according to vlan mode */
  4267. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
  4268. &q_update_params->update_flags);
  4269. __set_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM,
  4270. &q_update_params->update_flags);
  4271. __set_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4272. /* in access mode mark mask and value are 0 to strip all vlans */
  4273. if (bp->afex_vlan_mode == FUNC_MF_CFG_AFEX_VLAN_ACCESS_MODE) {
  4274. q_update_params->silent_removal_value = 0;
  4275. q_update_params->silent_removal_mask = 0;
  4276. } else {
  4277. q_update_params->silent_removal_value =
  4278. (bp->afex_def_vlan_tag & VLAN_VID_MASK);
  4279. q_update_params->silent_removal_mask = VLAN_VID_MASK;
  4280. }
  4281. for_each_eth_queue(bp, q) {
  4282. /* Set the appropriate Queue object */
  4283. fp = &bp->fp[q];
  4284. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4285. /* send the ramrod */
  4286. rc = bnx2x_queue_state_change(bp, &queue_params);
  4287. if (rc < 0)
  4288. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4289. q);
  4290. }
  4291. if (!NO_FCOE(bp) && CNIC_ENABLED(bp)) {
  4292. fp = &bp->fp[FCOE_IDX(bp)];
  4293. queue_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  4294. /* clear pending completion bit */
  4295. __clear_bit(RAMROD_COMP_WAIT, &queue_params.ramrod_flags);
  4296. /* mark latest Q bit */
  4297. smp_mb__before_clear_bit();
  4298. set_bit(BNX2X_AFEX_FCOE_Q_UPDATE_PENDING, &bp->sp_state);
  4299. smp_mb__after_clear_bit();
  4300. /* send Q update ramrod for FCoE Q */
  4301. rc = bnx2x_queue_state_change(bp, &queue_params);
  4302. if (rc < 0)
  4303. BNX2X_ERR("Failed to config silent vlan rem for Q %d\n",
  4304. q);
  4305. } else {
  4306. /* If no FCoE ring - ACK MCP now */
  4307. bnx2x_link_report(bp);
  4308. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4309. }
  4310. }
  4311. static struct bnx2x_queue_sp_obj *bnx2x_cid_to_q_obj(
  4312. struct bnx2x *bp, u32 cid)
  4313. {
  4314. DP(BNX2X_MSG_SP, "retrieving fp from cid %d\n", cid);
  4315. if (CNIC_LOADED(bp) && (cid == BNX2X_FCOE_ETH_CID(bp)))
  4316. return &bnx2x_fcoe_sp_obj(bp, q_obj);
  4317. else
  4318. return &bp->sp_objs[CID_TO_FP(cid, bp)].q_obj;
  4319. }
  4320. static void bnx2x_eq_int(struct bnx2x *bp)
  4321. {
  4322. u16 hw_cons, sw_cons, sw_prod;
  4323. union event_ring_elem *elem;
  4324. u8 echo;
  4325. u32 cid;
  4326. u8 opcode;
  4327. int rc, spqe_cnt = 0;
  4328. struct bnx2x_queue_sp_obj *q_obj;
  4329. struct bnx2x_func_sp_obj *f_obj = &bp->func_obj;
  4330. struct bnx2x_raw_obj *rss_raw = &bp->rss_conf_obj.raw;
  4331. hw_cons = le16_to_cpu(*bp->eq_cons_sb);
  4332. /* The hw_cos range is 1-255, 257 - the sw_cons range is 0-254, 256.
  4333. * when we get the next-page we need to adjust so the loop
  4334. * condition below will be met. The next element is the size of a
  4335. * regular element and hence incrementing by 1
  4336. */
  4337. if ((hw_cons & EQ_DESC_MAX_PAGE) == EQ_DESC_MAX_PAGE)
  4338. hw_cons++;
  4339. /* This function may never run in parallel with itself for a
  4340. * specific bp, thus there is no need in "paired" read memory
  4341. * barrier here.
  4342. */
  4343. sw_cons = bp->eq_cons;
  4344. sw_prod = bp->eq_prod;
  4345. DP(BNX2X_MSG_SP, "EQ: hw_cons %u sw_cons %u bp->eq_spq_left %x\n",
  4346. hw_cons, sw_cons, atomic_read(&bp->eq_spq_left));
  4347. for (; sw_cons != hw_cons;
  4348. sw_prod = NEXT_EQ_IDX(sw_prod), sw_cons = NEXT_EQ_IDX(sw_cons)) {
  4349. elem = &bp->eq_ring[EQ_DESC(sw_cons)];
  4350. rc = bnx2x_iov_eq_sp_event(bp, elem);
  4351. if (!rc) {
  4352. DP(BNX2X_MSG_IOV, "bnx2x_iov_eq_sp_event returned %d\n",
  4353. rc);
  4354. goto next_spqe;
  4355. }
  4356. /* elem CID originates from FW; actually LE */
  4357. cid = SW_CID((__force __le32)
  4358. elem->message.data.cfc_del_event.cid);
  4359. opcode = elem->message.opcode;
  4360. /* handle eq element */
  4361. switch (opcode) {
  4362. case EVENT_RING_OPCODE_VF_PF_CHANNEL:
  4363. DP(BNX2X_MSG_IOV, "vf pf channel element on eq\n");
  4364. bnx2x_vf_mbx(bp, &elem->message.data.vf_pf_event);
  4365. continue;
  4366. case EVENT_RING_OPCODE_STAT_QUERY:
  4367. DP(BNX2X_MSG_SP | BNX2X_MSG_STATS,
  4368. "got statistics comp event %d\n",
  4369. bp->stats_comp++);
  4370. /* nothing to do with stats comp */
  4371. goto next_spqe;
  4372. case EVENT_RING_OPCODE_CFC_DEL:
  4373. /* handle according to cid range */
  4374. /*
  4375. * we may want to verify here that the bp state is
  4376. * HALTING
  4377. */
  4378. DP(BNX2X_MSG_SP,
  4379. "got delete ramrod for MULTI[%d]\n", cid);
  4380. if (CNIC_LOADED(bp) &&
  4381. !bnx2x_cnic_handle_cfc_del(bp, cid, elem))
  4382. goto next_spqe;
  4383. q_obj = bnx2x_cid_to_q_obj(bp, cid);
  4384. if (q_obj->complete_cmd(bp, q_obj, BNX2X_Q_CMD_CFC_DEL))
  4385. break;
  4386. goto next_spqe;
  4387. case EVENT_RING_OPCODE_STOP_TRAFFIC:
  4388. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got STOP TRAFFIC\n");
  4389. if (f_obj->complete_cmd(bp, f_obj,
  4390. BNX2X_F_CMD_TX_STOP))
  4391. break;
  4392. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_PAUSED);
  4393. goto next_spqe;
  4394. case EVENT_RING_OPCODE_START_TRAFFIC:
  4395. DP(BNX2X_MSG_SP | BNX2X_MSG_DCB, "got START TRAFFIC\n");
  4396. if (f_obj->complete_cmd(bp, f_obj,
  4397. BNX2X_F_CMD_TX_START))
  4398. break;
  4399. bnx2x_dcbx_set_params(bp, BNX2X_DCBX_STATE_TX_RELEASED);
  4400. goto next_spqe;
  4401. case EVENT_RING_OPCODE_FUNCTION_UPDATE:
  4402. echo = elem->message.data.function_update_event.echo;
  4403. if (echo == SWITCH_UPDATE) {
  4404. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4405. "got FUNC_SWITCH_UPDATE ramrod\n");
  4406. if (f_obj->complete_cmd(
  4407. bp, f_obj, BNX2X_F_CMD_SWITCH_UPDATE))
  4408. break;
  4409. } else {
  4410. DP(BNX2X_MSG_SP | BNX2X_MSG_MCP,
  4411. "AFEX: ramrod completed FUNCTION_UPDATE\n");
  4412. f_obj->complete_cmd(bp, f_obj,
  4413. BNX2X_F_CMD_AFEX_UPDATE);
  4414. /* We will perform the Queues update from
  4415. * sp_rtnl task as all Queue SP operations
  4416. * should run under rtnl_lock.
  4417. */
  4418. smp_mb__before_clear_bit();
  4419. set_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE,
  4420. &bp->sp_rtnl_state);
  4421. smp_mb__after_clear_bit();
  4422. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4423. }
  4424. goto next_spqe;
  4425. case EVENT_RING_OPCODE_AFEX_VIF_LISTS:
  4426. f_obj->complete_cmd(bp, f_obj,
  4427. BNX2X_F_CMD_AFEX_VIFLISTS);
  4428. bnx2x_after_afex_vif_lists(bp, elem);
  4429. goto next_spqe;
  4430. case EVENT_RING_OPCODE_FUNCTION_START:
  4431. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4432. "got FUNC_START ramrod\n");
  4433. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_START))
  4434. break;
  4435. goto next_spqe;
  4436. case EVENT_RING_OPCODE_FUNCTION_STOP:
  4437. DP(BNX2X_MSG_SP | NETIF_MSG_IFUP,
  4438. "got FUNC_STOP ramrod\n");
  4439. if (f_obj->complete_cmd(bp, f_obj, BNX2X_F_CMD_STOP))
  4440. break;
  4441. goto next_spqe;
  4442. }
  4443. switch (opcode | bp->state) {
  4444. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4445. BNX2X_STATE_OPEN):
  4446. case (EVENT_RING_OPCODE_RSS_UPDATE_RULES |
  4447. BNX2X_STATE_OPENING_WAIT4_PORT):
  4448. cid = elem->message.data.eth_event.echo &
  4449. BNX2X_SWCID_MASK;
  4450. DP(BNX2X_MSG_SP, "got RSS_UPDATE ramrod. CID %d\n",
  4451. cid);
  4452. rss_raw->clear_pending(rss_raw);
  4453. break;
  4454. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_OPEN):
  4455. case (EVENT_RING_OPCODE_SET_MAC | BNX2X_STATE_DIAG):
  4456. case (EVENT_RING_OPCODE_SET_MAC |
  4457. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4458. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4459. BNX2X_STATE_OPEN):
  4460. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4461. BNX2X_STATE_DIAG):
  4462. case (EVENT_RING_OPCODE_CLASSIFICATION_RULES |
  4463. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4464. DP(BNX2X_MSG_SP, "got (un)set mac ramrod\n");
  4465. bnx2x_handle_classification_eqe(bp, elem);
  4466. break;
  4467. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4468. BNX2X_STATE_OPEN):
  4469. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4470. BNX2X_STATE_DIAG):
  4471. case (EVENT_RING_OPCODE_MULTICAST_RULES |
  4472. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4473. DP(BNX2X_MSG_SP, "got mcast ramrod\n");
  4474. bnx2x_handle_mcast_eqe(bp);
  4475. break;
  4476. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4477. BNX2X_STATE_OPEN):
  4478. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4479. BNX2X_STATE_DIAG):
  4480. case (EVENT_RING_OPCODE_FILTERS_RULES |
  4481. BNX2X_STATE_CLOSING_WAIT4_HALT):
  4482. DP(BNX2X_MSG_SP, "got rx_mode ramrod\n");
  4483. bnx2x_handle_rx_mode_eqe(bp);
  4484. break;
  4485. default:
  4486. /* unknown event log error and continue */
  4487. BNX2X_ERR("Unknown EQ event %d, bp->state 0x%x\n",
  4488. elem->message.opcode, bp->state);
  4489. }
  4490. next_spqe:
  4491. spqe_cnt++;
  4492. } /* for */
  4493. smp_mb__before_atomic_inc();
  4494. atomic_add(spqe_cnt, &bp->eq_spq_left);
  4495. bp->eq_cons = sw_cons;
  4496. bp->eq_prod = sw_prod;
  4497. /* Make sure that above mem writes were issued towards the memory */
  4498. smp_wmb();
  4499. /* update producer */
  4500. bnx2x_update_eq_prod(bp, bp->eq_prod);
  4501. }
  4502. static void bnx2x_sp_task(struct work_struct *work)
  4503. {
  4504. struct bnx2x *bp = container_of(work, struct bnx2x, sp_task.work);
  4505. DP(BNX2X_MSG_SP, "sp task invoked\n");
  4506. /* make sure the atomic interrupt_occurred has been written */
  4507. smp_rmb();
  4508. if (atomic_read(&bp->interrupt_occurred)) {
  4509. /* what work needs to be performed? */
  4510. u16 status = bnx2x_update_dsb_idx(bp);
  4511. DP(BNX2X_MSG_SP, "status %x\n", status);
  4512. DP(BNX2X_MSG_SP, "setting interrupt_occurred to 0\n");
  4513. atomic_set(&bp->interrupt_occurred, 0);
  4514. /* HW attentions */
  4515. if (status & BNX2X_DEF_SB_ATT_IDX) {
  4516. bnx2x_attn_int(bp);
  4517. status &= ~BNX2X_DEF_SB_ATT_IDX;
  4518. }
  4519. /* SP events: STAT_QUERY and others */
  4520. if (status & BNX2X_DEF_SB_IDX) {
  4521. struct bnx2x_fastpath *fp = bnx2x_fcoe_fp(bp);
  4522. if (FCOE_INIT(bp) &&
  4523. (bnx2x_has_rx_work(fp) || bnx2x_has_tx_work(fp))) {
  4524. /* Prevent local bottom-halves from running as
  4525. * we are going to change the local NAPI list.
  4526. */
  4527. local_bh_disable();
  4528. napi_schedule(&bnx2x_fcoe(bp, napi));
  4529. local_bh_enable();
  4530. }
  4531. /* Handle EQ completions */
  4532. bnx2x_eq_int(bp);
  4533. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID,
  4534. le16_to_cpu(bp->def_idx), IGU_INT_NOP, 1);
  4535. status &= ~BNX2X_DEF_SB_IDX;
  4536. }
  4537. /* if status is non zero then perhaps something went wrong */
  4538. if (unlikely(status))
  4539. DP(BNX2X_MSG_SP,
  4540. "got an unknown interrupt! (status 0x%x)\n", status);
  4541. /* ack status block only if something was actually handled */
  4542. bnx2x_ack_sb(bp, bp->igu_dsb_id, ATTENTION_ID,
  4543. le16_to_cpu(bp->def_att_idx), IGU_INT_ENABLE, 1);
  4544. }
  4545. /* must be called after the EQ processing (since eq leads to sriov
  4546. * ramrod completion flows).
  4547. * This flow may have been scheduled by the arrival of a ramrod
  4548. * completion, or by the sriov code rescheduling itself.
  4549. */
  4550. bnx2x_iov_sp_task(bp);
  4551. /* afex - poll to check if VIFSET_ACK should be sent to MFW */
  4552. if (test_and_clear_bit(BNX2X_AFEX_PENDING_VIFSET_MCP_ACK,
  4553. &bp->sp_state)) {
  4554. bnx2x_link_report(bp);
  4555. bnx2x_fw_command(bp, DRV_MSG_CODE_AFEX_VIFSET_ACK, 0);
  4556. }
  4557. }
  4558. irqreturn_t bnx2x_msix_sp_int(int irq, void *dev_instance)
  4559. {
  4560. struct net_device *dev = dev_instance;
  4561. struct bnx2x *bp = netdev_priv(dev);
  4562. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0,
  4563. IGU_INT_DISABLE, 0);
  4564. #ifdef BNX2X_STOP_ON_ERROR
  4565. if (unlikely(bp->panic))
  4566. return IRQ_HANDLED;
  4567. #endif
  4568. if (CNIC_LOADED(bp)) {
  4569. struct cnic_ops *c_ops;
  4570. rcu_read_lock();
  4571. c_ops = rcu_dereference(bp->cnic_ops);
  4572. if (c_ops)
  4573. c_ops->cnic_handler(bp->cnic_data, NULL);
  4574. rcu_read_unlock();
  4575. }
  4576. /* schedule sp task to perform default status block work, ack
  4577. * attentions and enable interrupts.
  4578. */
  4579. bnx2x_schedule_sp_task(bp);
  4580. return IRQ_HANDLED;
  4581. }
  4582. /* end of slow path */
  4583. void bnx2x_drv_pulse(struct bnx2x *bp)
  4584. {
  4585. SHMEM_WR(bp, func_mb[BP_FW_MB_IDX(bp)].drv_pulse_mb,
  4586. bp->fw_drv_pulse_wr_seq);
  4587. }
  4588. static void bnx2x_timer(unsigned long data)
  4589. {
  4590. struct bnx2x *bp = (struct bnx2x *) data;
  4591. if (!netif_running(bp->dev))
  4592. return;
  4593. if (IS_PF(bp) &&
  4594. !BP_NOMCP(bp)) {
  4595. int mb_idx = BP_FW_MB_IDX(bp);
  4596. u32 drv_pulse;
  4597. u32 mcp_pulse;
  4598. ++bp->fw_drv_pulse_wr_seq;
  4599. bp->fw_drv_pulse_wr_seq &= DRV_PULSE_SEQ_MASK;
  4600. /* TBD - add SYSTEM_TIME */
  4601. drv_pulse = bp->fw_drv_pulse_wr_seq;
  4602. bnx2x_drv_pulse(bp);
  4603. mcp_pulse = (SHMEM_RD(bp, func_mb[mb_idx].mcp_pulse_mb) &
  4604. MCP_PULSE_SEQ_MASK);
  4605. /* The delta between driver pulse and mcp response
  4606. * should be 1 (before mcp response) or 0 (after mcp response)
  4607. */
  4608. if ((drv_pulse != mcp_pulse) &&
  4609. (drv_pulse != ((mcp_pulse + 1) & MCP_PULSE_SEQ_MASK))) {
  4610. /* someone lost a heartbeat... */
  4611. BNX2X_ERR("drv_pulse (0x%x) != mcp_pulse (0x%x)\n",
  4612. drv_pulse, mcp_pulse);
  4613. }
  4614. }
  4615. if (bp->state == BNX2X_STATE_OPEN)
  4616. bnx2x_stats_handle(bp, STATS_EVENT_UPDATE);
  4617. /* sample pf vf bulletin board for new posts from pf */
  4618. if (IS_VF(bp)) {
  4619. bnx2x_sample_bulletin(bp);
  4620. /* if channel is down we need to self destruct */
  4621. if (bp->old_bulletin.valid_bitmap & 1 << CHANNEL_DOWN) {
  4622. smp_mb__before_clear_bit();
  4623. set_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  4624. &bp->sp_rtnl_state);
  4625. smp_mb__after_clear_bit();
  4626. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  4627. }
  4628. }
  4629. mod_timer(&bp->timer, jiffies + bp->current_interval);
  4630. }
  4631. /* end of Statistics */
  4632. /* nic init */
  4633. /*
  4634. * nic init service functions
  4635. */
  4636. static void bnx2x_fill(struct bnx2x *bp, u32 addr, int fill, u32 len)
  4637. {
  4638. u32 i;
  4639. if (!(len%4) && !(addr%4))
  4640. for (i = 0; i < len; i += 4)
  4641. REG_WR(bp, addr + i, fill);
  4642. else
  4643. for (i = 0; i < len; i++)
  4644. REG_WR8(bp, addr + i, fill);
  4645. }
  4646. /* helper: writes FP SP data to FW - data_size in dwords */
  4647. static void bnx2x_wr_fp_sb_data(struct bnx2x *bp,
  4648. int fw_sb_id,
  4649. u32 *sb_data_p,
  4650. u32 data_size)
  4651. {
  4652. int index;
  4653. for (index = 0; index < data_size; index++)
  4654. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4655. CSTORM_STATUS_BLOCK_DATA_OFFSET(fw_sb_id) +
  4656. sizeof(u32)*index,
  4657. *(sb_data_p + index));
  4658. }
  4659. static void bnx2x_zero_fp_sb(struct bnx2x *bp, int fw_sb_id)
  4660. {
  4661. u32 *sb_data_p;
  4662. u32 data_size = 0;
  4663. struct hc_status_block_data_e2 sb_data_e2;
  4664. struct hc_status_block_data_e1x sb_data_e1x;
  4665. /* disable the function first */
  4666. if (!CHIP_IS_E1x(bp)) {
  4667. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4668. sb_data_e2.common.state = SB_DISABLED;
  4669. sb_data_e2.common.p_func.vf_valid = false;
  4670. sb_data_p = (u32 *)&sb_data_e2;
  4671. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4672. } else {
  4673. memset(&sb_data_e1x, 0,
  4674. sizeof(struct hc_status_block_data_e1x));
  4675. sb_data_e1x.common.state = SB_DISABLED;
  4676. sb_data_e1x.common.p_func.vf_valid = false;
  4677. sb_data_p = (u32 *)&sb_data_e1x;
  4678. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4679. }
  4680. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4681. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4682. CSTORM_STATUS_BLOCK_OFFSET(fw_sb_id), 0,
  4683. CSTORM_STATUS_BLOCK_SIZE);
  4684. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4685. CSTORM_SYNC_BLOCK_OFFSET(fw_sb_id), 0,
  4686. CSTORM_SYNC_BLOCK_SIZE);
  4687. }
  4688. /* helper: writes SP SB data to FW */
  4689. static void bnx2x_wr_sp_sb_data(struct bnx2x *bp,
  4690. struct hc_sp_status_block_data *sp_sb_data)
  4691. {
  4692. int func = BP_FUNC(bp);
  4693. int i;
  4694. for (i = 0; i < sizeof(struct hc_sp_status_block_data)/sizeof(u32); i++)
  4695. REG_WR(bp, BAR_CSTRORM_INTMEM +
  4696. CSTORM_SP_STATUS_BLOCK_DATA_OFFSET(func) +
  4697. i*sizeof(u32),
  4698. *((u32 *)sp_sb_data + i));
  4699. }
  4700. static void bnx2x_zero_sp_sb(struct bnx2x *bp)
  4701. {
  4702. int func = BP_FUNC(bp);
  4703. struct hc_sp_status_block_data sp_sb_data;
  4704. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4705. sp_sb_data.state = SB_DISABLED;
  4706. sp_sb_data.p_func.vf_valid = false;
  4707. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4708. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4709. CSTORM_SP_STATUS_BLOCK_OFFSET(func), 0,
  4710. CSTORM_SP_STATUS_BLOCK_SIZE);
  4711. bnx2x_fill(bp, BAR_CSTRORM_INTMEM +
  4712. CSTORM_SP_SYNC_BLOCK_OFFSET(func), 0,
  4713. CSTORM_SP_SYNC_BLOCK_SIZE);
  4714. }
  4715. static void bnx2x_setup_ndsb_state_machine(struct hc_status_block_sm *hc_sm,
  4716. int igu_sb_id, int igu_seg_id)
  4717. {
  4718. hc_sm->igu_sb_id = igu_sb_id;
  4719. hc_sm->igu_seg_id = igu_seg_id;
  4720. hc_sm->timer_value = 0xFF;
  4721. hc_sm->time_to_expire = 0xFFFFFFFF;
  4722. }
  4723. /* allocates state machine ids. */
  4724. static void bnx2x_map_sb_state_machines(struct hc_index_data *index_data)
  4725. {
  4726. /* zero out state machine indices */
  4727. /* rx indices */
  4728. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4729. /* tx indices */
  4730. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags &= ~HC_INDEX_DATA_SM_ID;
  4731. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags &= ~HC_INDEX_DATA_SM_ID;
  4732. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags &= ~HC_INDEX_DATA_SM_ID;
  4733. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags &= ~HC_INDEX_DATA_SM_ID;
  4734. /* map indices */
  4735. /* rx indices */
  4736. index_data[HC_INDEX_ETH_RX_CQ_CONS].flags |=
  4737. SM_RX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4738. /* tx indices */
  4739. index_data[HC_INDEX_OOO_TX_CQ_CONS].flags |=
  4740. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4741. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS0].flags |=
  4742. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4743. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS1].flags |=
  4744. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4745. index_data[HC_INDEX_ETH_TX_CQ_CONS_COS2].flags |=
  4746. SM_TX_ID << HC_INDEX_DATA_SM_ID_SHIFT;
  4747. }
  4748. void bnx2x_init_sb(struct bnx2x *bp, dma_addr_t mapping, int vfid,
  4749. u8 vf_valid, int fw_sb_id, int igu_sb_id)
  4750. {
  4751. int igu_seg_id;
  4752. struct hc_status_block_data_e2 sb_data_e2;
  4753. struct hc_status_block_data_e1x sb_data_e1x;
  4754. struct hc_status_block_sm *hc_sm_p;
  4755. int data_size;
  4756. u32 *sb_data_p;
  4757. if (CHIP_INT_MODE_IS_BC(bp))
  4758. igu_seg_id = HC_SEG_ACCESS_NORM;
  4759. else
  4760. igu_seg_id = IGU_SEG_ACCESS_NORM;
  4761. bnx2x_zero_fp_sb(bp, fw_sb_id);
  4762. if (!CHIP_IS_E1x(bp)) {
  4763. memset(&sb_data_e2, 0, sizeof(struct hc_status_block_data_e2));
  4764. sb_data_e2.common.state = SB_ENABLED;
  4765. sb_data_e2.common.p_func.pf_id = BP_FUNC(bp);
  4766. sb_data_e2.common.p_func.vf_id = vfid;
  4767. sb_data_e2.common.p_func.vf_valid = vf_valid;
  4768. sb_data_e2.common.p_func.vnic_id = BP_VN(bp);
  4769. sb_data_e2.common.same_igu_sb_1b = true;
  4770. sb_data_e2.common.host_sb_addr.hi = U64_HI(mapping);
  4771. sb_data_e2.common.host_sb_addr.lo = U64_LO(mapping);
  4772. hc_sm_p = sb_data_e2.common.state_machine;
  4773. sb_data_p = (u32 *)&sb_data_e2;
  4774. data_size = sizeof(struct hc_status_block_data_e2)/sizeof(u32);
  4775. bnx2x_map_sb_state_machines(sb_data_e2.index_data);
  4776. } else {
  4777. memset(&sb_data_e1x, 0,
  4778. sizeof(struct hc_status_block_data_e1x));
  4779. sb_data_e1x.common.state = SB_ENABLED;
  4780. sb_data_e1x.common.p_func.pf_id = BP_FUNC(bp);
  4781. sb_data_e1x.common.p_func.vf_id = 0xff;
  4782. sb_data_e1x.common.p_func.vf_valid = false;
  4783. sb_data_e1x.common.p_func.vnic_id = BP_VN(bp);
  4784. sb_data_e1x.common.same_igu_sb_1b = true;
  4785. sb_data_e1x.common.host_sb_addr.hi = U64_HI(mapping);
  4786. sb_data_e1x.common.host_sb_addr.lo = U64_LO(mapping);
  4787. hc_sm_p = sb_data_e1x.common.state_machine;
  4788. sb_data_p = (u32 *)&sb_data_e1x;
  4789. data_size = sizeof(struct hc_status_block_data_e1x)/sizeof(u32);
  4790. bnx2x_map_sb_state_machines(sb_data_e1x.index_data);
  4791. }
  4792. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_RX_ID],
  4793. igu_sb_id, igu_seg_id);
  4794. bnx2x_setup_ndsb_state_machine(&hc_sm_p[SM_TX_ID],
  4795. igu_sb_id, igu_seg_id);
  4796. DP(NETIF_MSG_IFUP, "Init FW SB %d\n", fw_sb_id);
  4797. /* write indices to HW - PCI guarantees endianity of regpairs */
  4798. bnx2x_wr_fp_sb_data(bp, fw_sb_id, sb_data_p, data_size);
  4799. }
  4800. static void bnx2x_update_coalesce_sb(struct bnx2x *bp, u8 fw_sb_id,
  4801. u16 tx_usec, u16 rx_usec)
  4802. {
  4803. bnx2x_update_coalesce_sb_index(bp, fw_sb_id, HC_INDEX_ETH_RX_CQ_CONS,
  4804. false, rx_usec);
  4805. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4806. HC_INDEX_ETH_TX_CQ_CONS_COS0, false,
  4807. tx_usec);
  4808. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4809. HC_INDEX_ETH_TX_CQ_CONS_COS1, false,
  4810. tx_usec);
  4811. bnx2x_update_coalesce_sb_index(bp, fw_sb_id,
  4812. HC_INDEX_ETH_TX_CQ_CONS_COS2, false,
  4813. tx_usec);
  4814. }
  4815. static void bnx2x_init_def_sb(struct bnx2x *bp)
  4816. {
  4817. struct host_sp_status_block *def_sb = bp->def_status_blk;
  4818. dma_addr_t mapping = bp->def_status_blk_mapping;
  4819. int igu_sp_sb_index;
  4820. int igu_seg_id;
  4821. int port = BP_PORT(bp);
  4822. int func = BP_FUNC(bp);
  4823. int reg_offset, reg_offset_en5;
  4824. u64 section;
  4825. int index;
  4826. struct hc_sp_status_block_data sp_sb_data;
  4827. memset(&sp_sb_data, 0, sizeof(struct hc_sp_status_block_data));
  4828. if (CHIP_INT_MODE_IS_BC(bp)) {
  4829. igu_sp_sb_index = DEF_SB_IGU_ID;
  4830. igu_seg_id = HC_SEG_ACCESS_DEF;
  4831. } else {
  4832. igu_sp_sb_index = bp->igu_dsb_id;
  4833. igu_seg_id = IGU_SEG_ACCESS_DEF;
  4834. }
  4835. /* ATTN */
  4836. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4837. atten_status_block);
  4838. def_sb->atten_status_block.status_block_id = igu_sp_sb_index;
  4839. bp->attn_state = 0;
  4840. reg_offset = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  4841. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  4842. reg_offset_en5 = (port ? MISC_REG_AEU_ENABLE5_FUNC_1_OUT_0 :
  4843. MISC_REG_AEU_ENABLE5_FUNC_0_OUT_0);
  4844. for (index = 0; index < MAX_DYNAMIC_ATTN_GRPS; index++) {
  4845. int sindex;
  4846. /* take care of sig[0]..sig[4] */
  4847. for (sindex = 0; sindex < 4; sindex++)
  4848. bp->attn_group[index].sig[sindex] =
  4849. REG_RD(bp, reg_offset + sindex*0x4 + 0x10*index);
  4850. if (!CHIP_IS_E1x(bp))
  4851. /*
  4852. * enable5 is separate from the rest of the registers,
  4853. * and therefore the address skip is 4
  4854. * and not 16 between the different groups
  4855. */
  4856. bp->attn_group[index].sig[4] = REG_RD(bp,
  4857. reg_offset_en5 + 0x4*index);
  4858. else
  4859. bp->attn_group[index].sig[4] = 0;
  4860. }
  4861. if (bp->common.int_block == INT_BLOCK_HC) {
  4862. reg_offset = (port ? HC_REG_ATTN_MSG1_ADDR_L :
  4863. HC_REG_ATTN_MSG0_ADDR_L);
  4864. REG_WR(bp, reg_offset, U64_LO(section));
  4865. REG_WR(bp, reg_offset + 4, U64_HI(section));
  4866. } else if (!CHIP_IS_E1x(bp)) {
  4867. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_L, U64_LO(section));
  4868. REG_WR(bp, IGU_REG_ATTN_MSG_ADDR_H, U64_HI(section));
  4869. }
  4870. section = ((u64)mapping) + offsetof(struct host_sp_status_block,
  4871. sp_sb);
  4872. bnx2x_zero_sp_sb(bp);
  4873. /* PCI guarantees endianity of regpairs */
  4874. sp_sb_data.state = SB_ENABLED;
  4875. sp_sb_data.host_sb_addr.lo = U64_LO(section);
  4876. sp_sb_data.host_sb_addr.hi = U64_HI(section);
  4877. sp_sb_data.igu_sb_id = igu_sp_sb_index;
  4878. sp_sb_data.igu_seg_id = igu_seg_id;
  4879. sp_sb_data.p_func.pf_id = func;
  4880. sp_sb_data.p_func.vnic_id = BP_VN(bp);
  4881. sp_sb_data.p_func.vf_id = 0xff;
  4882. bnx2x_wr_sp_sb_data(bp, &sp_sb_data);
  4883. bnx2x_ack_sb(bp, bp->igu_dsb_id, USTORM_ID, 0, IGU_INT_ENABLE, 0);
  4884. }
  4885. void bnx2x_update_coalesce(struct bnx2x *bp)
  4886. {
  4887. int i;
  4888. for_each_eth_queue(bp, i)
  4889. bnx2x_update_coalesce_sb(bp, bp->fp[i].fw_sb_id,
  4890. bp->tx_ticks, bp->rx_ticks);
  4891. }
  4892. static void bnx2x_init_sp_ring(struct bnx2x *bp)
  4893. {
  4894. spin_lock_init(&bp->spq_lock);
  4895. atomic_set(&bp->cq_spq_left, MAX_SPQ_PENDING);
  4896. bp->spq_prod_idx = 0;
  4897. bp->dsb_sp_prod = BNX2X_SP_DSB_INDEX;
  4898. bp->spq_prod_bd = bp->spq;
  4899. bp->spq_last_bd = bp->spq_prod_bd + MAX_SP_DESC_CNT;
  4900. }
  4901. static void bnx2x_init_eq_ring(struct bnx2x *bp)
  4902. {
  4903. int i;
  4904. for (i = 1; i <= NUM_EQ_PAGES; i++) {
  4905. union event_ring_elem *elem =
  4906. &bp->eq_ring[EQ_DESC_CNT_PAGE * i - 1];
  4907. elem->next_page.addr.hi =
  4908. cpu_to_le32(U64_HI(bp->eq_mapping +
  4909. BCM_PAGE_SIZE * (i % NUM_EQ_PAGES)));
  4910. elem->next_page.addr.lo =
  4911. cpu_to_le32(U64_LO(bp->eq_mapping +
  4912. BCM_PAGE_SIZE*(i % NUM_EQ_PAGES)));
  4913. }
  4914. bp->eq_cons = 0;
  4915. bp->eq_prod = NUM_EQ_DESC;
  4916. bp->eq_cons_sb = BNX2X_EQ_INDEX;
  4917. /* we want a warning message before it gets wrought... */
  4918. atomic_set(&bp->eq_spq_left,
  4919. min_t(int, MAX_SP_DESC_CNT - MAX_SPQ_PENDING, NUM_EQ_DESC) - 1);
  4920. }
  4921. /* called with netif_addr_lock_bh() */
  4922. int bnx2x_set_q_rx_mode(struct bnx2x *bp, u8 cl_id,
  4923. unsigned long rx_mode_flags,
  4924. unsigned long rx_accept_flags,
  4925. unsigned long tx_accept_flags,
  4926. unsigned long ramrod_flags)
  4927. {
  4928. struct bnx2x_rx_mode_ramrod_params ramrod_param;
  4929. int rc;
  4930. memset(&ramrod_param, 0, sizeof(ramrod_param));
  4931. /* Prepare ramrod parameters */
  4932. ramrod_param.cid = 0;
  4933. ramrod_param.cl_id = cl_id;
  4934. ramrod_param.rx_mode_obj = &bp->rx_mode_obj;
  4935. ramrod_param.func_id = BP_FUNC(bp);
  4936. ramrod_param.pstate = &bp->sp_state;
  4937. ramrod_param.state = BNX2X_FILTER_RX_MODE_PENDING;
  4938. ramrod_param.rdata = bnx2x_sp(bp, rx_mode_rdata);
  4939. ramrod_param.rdata_mapping = bnx2x_sp_mapping(bp, rx_mode_rdata);
  4940. set_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state);
  4941. ramrod_param.ramrod_flags = ramrod_flags;
  4942. ramrod_param.rx_mode_flags = rx_mode_flags;
  4943. ramrod_param.rx_accept_flags = rx_accept_flags;
  4944. ramrod_param.tx_accept_flags = tx_accept_flags;
  4945. rc = bnx2x_config_rx_mode(bp, &ramrod_param);
  4946. if (rc < 0) {
  4947. BNX2X_ERR("Set rx_mode %d failed\n", bp->rx_mode);
  4948. return rc;
  4949. }
  4950. return 0;
  4951. }
  4952. static int bnx2x_fill_accept_flags(struct bnx2x *bp, u32 rx_mode,
  4953. unsigned long *rx_accept_flags,
  4954. unsigned long *tx_accept_flags)
  4955. {
  4956. /* Clear the flags first */
  4957. *rx_accept_flags = 0;
  4958. *tx_accept_flags = 0;
  4959. switch (rx_mode) {
  4960. case BNX2X_RX_MODE_NONE:
  4961. /*
  4962. * 'drop all' supersedes any accept flags that may have been
  4963. * passed to the function.
  4964. */
  4965. break;
  4966. case BNX2X_RX_MODE_NORMAL:
  4967. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4968. __set_bit(BNX2X_ACCEPT_MULTICAST, rx_accept_flags);
  4969. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4970. /* internal switching mode */
  4971. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4972. __set_bit(BNX2X_ACCEPT_MULTICAST, tx_accept_flags);
  4973. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4974. break;
  4975. case BNX2X_RX_MODE_ALLMULTI:
  4976. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4977. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4978. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4979. /* internal switching mode */
  4980. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  4981. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4982. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4983. break;
  4984. case BNX2X_RX_MODE_PROMISC:
  4985. /* According to definition of SI mode, iface in promisc mode
  4986. * should receive matched and unmatched (in resolution of port)
  4987. * unicast packets.
  4988. */
  4989. __set_bit(BNX2X_ACCEPT_UNMATCHED, rx_accept_flags);
  4990. __set_bit(BNX2X_ACCEPT_UNICAST, rx_accept_flags);
  4991. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, rx_accept_flags);
  4992. __set_bit(BNX2X_ACCEPT_BROADCAST, rx_accept_flags);
  4993. /* internal switching mode */
  4994. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, tx_accept_flags);
  4995. __set_bit(BNX2X_ACCEPT_BROADCAST, tx_accept_flags);
  4996. if (IS_MF_SI(bp))
  4997. __set_bit(BNX2X_ACCEPT_ALL_UNICAST, tx_accept_flags);
  4998. else
  4999. __set_bit(BNX2X_ACCEPT_UNICAST, tx_accept_flags);
  5000. break;
  5001. default:
  5002. BNX2X_ERR("Unknown rx_mode: %d\n", rx_mode);
  5003. return -EINVAL;
  5004. }
  5005. /* Set ACCEPT_ANY_VLAN as we do not enable filtering by VLAN */
  5006. if (bp->rx_mode != BNX2X_RX_MODE_NONE) {
  5007. __set_bit(BNX2X_ACCEPT_ANY_VLAN, rx_accept_flags);
  5008. __set_bit(BNX2X_ACCEPT_ANY_VLAN, tx_accept_flags);
  5009. }
  5010. return 0;
  5011. }
  5012. /* called with netif_addr_lock_bh() */
  5013. int bnx2x_set_storm_rx_mode(struct bnx2x *bp)
  5014. {
  5015. unsigned long rx_mode_flags = 0, ramrod_flags = 0;
  5016. unsigned long rx_accept_flags = 0, tx_accept_flags = 0;
  5017. int rc;
  5018. if (!NO_FCOE(bp))
  5019. /* Configure rx_mode of FCoE Queue */
  5020. __set_bit(BNX2X_RX_MODE_FCOE_ETH, &rx_mode_flags);
  5021. rc = bnx2x_fill_accept_flags(bp, bp->rx_mode, &rx_accept_flags,
  5022. &tx_accept_flags);
  5023. if (rc)
  5024. return rc;
  5025. __set_bit(RAMROD_RX, &ramrod_flags);
  5026. __set_bit(RAMROD_TX, &ramrod_flags);
  5027. return bnx2x_set_q_rx_mode(bp, bp->fp->cl_id, rx_mode_flags,
  5028. rx_accept_flags, tx_accept_flags,
  5029. ramrod_flags);
  5030. }
  5031. static void bnx2x_init_internal_common(struct bnx2x *bp)
  5032. {
  5033. int i;
  5034. if (IS_MF_SI(bp))
  5035. /*
  5036. * In switch independent mode, the TSTORM needs to accept
  5037. * packets that failed classification, since approximate match
  5038. * mac addresses aren't written to NIG LLH
  5039. */
  5040. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5041. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 2);
  5042. else if (!CHIP_IS_E1(bp)) /* 57710 doesn't support MF */
  5043. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  5044. TSTORM_ACCEPT_CLASSIFY_FAILED_OFFSET, 0);
  5045. /* Zero this manually as its initialization is
  5046. currently missing in the initTool */
  5047. for (i = 0; i < (USTORM_AGG_DATA_SIZE >> 2); i++)
  5048. REG_WR(bp, BAR_USTRORM_INTMEM +
  5049. USTORM_AGG_DATA_OFFSET + i * 4, 0);
  5050. if (!CHIP_IS_E1x(bp)) {
  5051. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_IGU_MODE_OFFSET,
  5052. CHIP_INT_MODE_IS_BC(bp) ?
  5053. HC_IGU_BC_MODE : HC_IGU_NBC_MODE);
  5054. }
  5055. }
  5056. static void bnx2x_init_internal(struct bnx2x *bp, u32 load_code)
  5057. {
  5058. switch (load_code) {
  5059. case FW_MSG_CODE_DRV_LOAD_COMMON:
  5060. case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
  5061. bnx2x_init_internal_common(bp);
  5062. /* no break */
  5063. case FW_MSG_CODE_DRV_LOAD_PORT:
  5064. /* nothing to do */
  5065. /* no break */
  5066. case FW_MSG_CODE_DRV_LOAD_FUNCTION:
  5067. /* internal memory per function is
  5068. initialized inside bnx2x_pf_init */
  5069. break;
  5070. default:
  5071. BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
  5072. break;
  5073. }
  5074. }
  5075. static inline u8 bnx2x_fp_igu_sb_id(struct bnx2x_fastpath *fp)
  5076. {
  5077. return fp->bp->igu_base_sb + fp->index + CNIC_SUPPORT(fp->bp);
  5078. }
  5079. static inline u8 bnx2x_fp_fw_sb_id(struct bnx2x_fastpath *fp)
  5080. {
  5081. return fp->bp->base_fw_ndsb + fp->index + CNIC_SUPPORT(fp->bp);
  5082. }
  5083. static u8 bnx2x_fp_cl_id(struct bnx2x_fastpath *fp)
  5084. {
  5085. if (CHIP_IS_E1x(fp->bp))
  5086. return BP_L_ID(fp->bp) + fp->index;
  5087. else /* We want Client ID to be the same as IGU SB ID for 57712 */
  5088. return bnx2x_fp_igu_sb_id(fp);
  5089. }
  5090. static void bnx2x_init_eth_fp(struct bnx2x *bp, int fp_idx)
  5091. {
  5092. struct bnx2x_fastpath *fp = &bp->fp[fp_idx];
  5093. u8 cos;
  5094. unsigned long q_type = 0;
  5095. u32 cids[BNX2X_MULTI_TX_COS] = { 0 };
  5096. fp->rx_queue = fp_idx;
  5097. fp->cid = fp_idx;
  5098. fp->cl_id = bnx2x_fp_cl_id(fp);
  5099. fp->fw_sb_id = bnx2x_fp_fw_sb_id(fp);
  5100. fp->igu_sb_id = bnx2x_fp_igu_sb_id(fp);
  5101. /* qZone id equals to FW (per path) client id */
  5102. fp->cl_qzone_id = bnx2x_fp_qzone_id(fp);
  5103. /* init shortcut */
  5104. fp->ustorm_rx_prods_offset = bnx2x_rx_ustorm_prods_offset(fp);
  5105. /* Setup SB indices */
  5106. fp->rx_cons_sb = BNX2X_RX_SB_INDEX;
  5107. /* Configure Queue State object */
  5108. __set_bit(BNX2X_Q_TYPE_HAS_RX, &q_type);
  5109. __set_bit(BNX2X_Q_TYPE_HAS_TX, &q_type);
  5110. BUG_ON(fp->max_cos > BNX2X_MULTI_TX_COS);
  5111. /* init tx data */
  5112. for_each_cos_in_tx_queue(fp, cos) {
  5113. bnx2x_init_txdata(bp, fp->txdata_ptr[cos],
  5114. CID_COS_TO_TX_ONLY_CID(fp->cid, cos, bp),
  5115. FP_COS_TO_TXQ(fp, cos, bp),
  5116. BNX2X_TX_SB_INDEX_BASE + cos, fp);
  5117. cids[cos] = fp->txdata_ptr[cos]->cid;
  5118. }
  5119. /* nothing more for vf to do here */
  5120. if (IS_VF(bp))
  5121. return;
  5122. bnx2x_init_sb(bp, fp->status_blk_mapping, BNX2X_VF_ID_INVALID, false,
  5123. fp->fw_sb_id, fp->igu_sb_id);
  5124. bnx2x_update_fpsb_idx(fp);
  5125. bnx2x_init_queue_obj(bp, &bnx2x_sp_obj(bp, fp).q_obj, fp->cl_id, cids,
  5126. fp->max_cos, BP_FUNC(bp), bnx2x_sp(bp, q_rdata),
  5127. bnx2x_sp_mapping(bp, q_rdata), q_type);
  5128. /**
  5129. * Configure classification DBs: Always enable Tx switching
  5130. */
  5131. bnx2x_init_vlan_mac_fp_objs(fp, BNX2X_OBJ_TYPE_RX_TX);
  5132. DP(NETIF_MSG_IFUP,
  5133. "queue[%d]: bnx2x_init_sb(%p,%p) cl_id %d fw_sb %d igu_sb %d\n",
  5134. fp_idx, bp, fp->status_blk.e2_sb, fp->cl_id, fp->fw_sb_id,
  5135. fp->igu_sb_id);
  5136. }
  5137. static void bnx2x_init_tx_ring_one(struct bnx2x_fp_txdata *txdata)
  5138. {
  5139. int i;
  5140. for (i = 1; i <= NUM_TX_RINGS; i++) {
  5141. struct eth_tx_next_bd *tx_next_bd =
  5142. &txdata->tx_desc_ring[TX_DESC_CNT * i - 1].next_bd;
  5143. tx_next_bd->addr_hi =
  5144. cpu_to_le32(U64_HI(txdata->tx_desc_mapping +
  5145. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5146. tx_next_bd->addr_lo =
  5147. cpu_to_le32(U64_LO(txdata->tx_desc_mapping +
  5148. BCM_PAGE_SIZE*(i % NUM_TX_RINGS)));
  5149. }
  5150. *txdata->tx_cons_sb = cpu_to_le16(0);
  5151. SET_FLAG(txdata->tx_db.data.header.header, DOORBELL_HDR_DB_TYPE, 1);
  5152. txdata->tx_db.data.zero_fill1 = 0;
  5153. txdata->tx_db.data.prod = 0;
  5154. txdata->tx_pkt_prod = 0;
  5155. txdata->tx_pkt_cons = 0;
  5156. txdata->tx_bd_prod = 0;
  5157. txdata->tx_bd_cons = 0;
  5158. txdata->tx_pkt = 0;
  5159. }
  5160. static void bnx2x_init_tx_rings_cnic(struct bnx2x *bp)
  5161. {
  5162. int i;
  5163. for_each_tx_queue_cnic(bp, i)
  5164. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[0]);
  5165. }
  5166. static void bnx2x_init_tx_rings(struct bnx2x *bp)
  5167. {
  5168. int i;
  5169. u8 cos;
  5170. for_each_eth_queue(bp, i)
  5171. for_each_cos_in_tx_queue(&bp->fp[i], cos)
  5172. bnx2x_init_tx_ring_one(bp->fp[i].txdata_ptr[cos]);
  5173. }
  5174. void bnx2x_nic_init_cnic(struct bnx2x *bp)
  5175. {
  5176. if (!NO_FCOE(bp))
  5177. bnx2x_init_fcoe_fp(bp);
  5178. bnx2x_init_sb(bp, bp->cnic_sb_mapping,
  5179. BNX2X_VF_ID_INVALID, false,
  5180. bnx2x_cnic_fw_sb_id(bp), bnx2x_cnic_igu_sb_id(bp));
  5181. /* ensure status block indices were read */
  5182. rmb();
  5183. bnx2x_init_rx_rings_cnic(bp);
  5184. bnx2x_init_tx_rings_cnic(bp);
  5185. /* flush all */
  5186. mb();
  5187. mmiowb();
  5188. }
  5189. void bnx2x_pre_irq_nic_init(struct bnx2x *bp)
  5190. {
  5191. int i;
  5192. /* Setup NIC internals and enable interrupts */
  5193. for_each_eth_queue(bp, i)
  5194. bnx2x_init_eth_fp(bp, i);
  5195. /* ensure status block indices were read */
  5196. rmb();
  5197. bnx2x_init_rx_rings(bp);
  5198. bnx2x_init_tx_rings(bp);
  5199. if (IS_PF(bp)) {
  5200. /* Initialize MOD_ABS interrupts */
  5201. bnx2x_init_mod_abs_int(bp, &bp->link_vars, bp->common.chip_id,
  5202. bp->common.shmem_base,
  5203. bp->common.shmem2_base, BP_PORT(bp));
  5204. /* initialize the default status block and sp ring */
  5205. bnx2x_init_def_sb(bp);
  5206. bnx2x_update_dsb_idx(bp);
  5207. bnx2x_init_sp_ring(bp);
  5208. } else {
  5209. bnx2x_memset_stats(bp);
  5210. }
  5211. }
  5212. void bnx2x_post_irq_nic_init(struct bnx2x *bp, u32 load_code)
  5213. {
  5214. bnx2x_init_eq_ring(bp);
  5215. bnx2x_init_internal(bp, load_code);
  5216. bnx2x_pf_init(bp);
  5217. bnx2x_stats_init(bp);
  5218. /* flush all before enabling interrupts */
  5219. mb();
  5220. mmiowb();
  5221. bnx2x_int_enable(bp);
  5222. /* Check for SPIO5 */
  5223. bnx2x_attn_int_deasserted0(bp,
  5224. REG_RD(bp, MISC_REG_AEU_AFTER_INVERT_1_FUNC_0 + BP_PORT(bp)*4) &
  5225. AEU_INPUTS_ATTN_BITS_SPIO5);
  5226. }
  5227. /* gzip service functions */
  5228. static int bnx2x_gunzip_init(struct bnx2x *bp)
  5229. {
  5230. bp->gunzip_buf = dma_alloc_coherent(&bp->pdev->dev, FW_BUF_SIZE,
  5231. &bp->gunzip_mapping, GFP_KERNEL);
  5232. if (bp->gunzip_buf == NULL)
  5233. goto gunzip_nomem1;
  5234. bp->strm = kmalloc(sizeof(*bp->strm), GFP_KERNEL);
  5235. if (bp->strm == NULL)
  5236. goto gunzip_nomem2;
  5237. bp->strm->workspace = vmalloc(zlib_inflate_workspacesize());
  5238. if (bp->strm->workspace == NULL)
  5239. goto gunzip_nomem3;
  5240. return 0;
  5241. gunzip_nomem3:
  5242. kfree(bp->strm);
  5243. bp->strm = NULL;
  5244. gunzip_nomem2:
  5245. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5246. bp->gunzip_mapping);
  5247. bp->gunzip_buf = NULL;
  5248. gunzip_nomem1:
  5249. BNX2X_ERR("Cannot allocate firmware buffer for un-compression\n");
  5250. return -ENOMEM;
  5251. }
  5252. static void bnx2x_gunzip_end(struct bnx2x *bp)
  5253. {
  5254. if (bp->strm) {
  5255. vfree(bp->strm->workspace);
  5256. kfree(bp->strm);
  5257. bp->strm = NULL;
  5258. }
  5259. if (bp->gunzip_buf) {
  5260. dma_free_coherent(&bp->pdev->dev, FW_BUF_SIZE, bp->gunzip_buf,
  5261. bp->gunzip_mapping);
  5262. bp->gunzip_buf = NULL;
  5263. }
  5264. }
  5265. static int bnx2x_gunzip(struct bnx2x *bp, const u8 *zbuf, int len)
  5266. {
  5267. int n, rc;
  5268. /* check gzip header */
  5269. if ((zbuf[0] != 0x1f) || (zbuf[1] != 0x8b) || (zbuf[2] != Z_DEFLATED)) {
  5270. BNX2X_ERR("Bad gzip header\n");
  5271. return -EINVAL;
  5272. }
  5273. n = 10;
  5274. #define FNAME 0x8
  5275. if (zbuf[3] & FNAME)
  5276. while ((zbuf[n++] != 0) && (n < len));
  5277. bp->strm->next_in = (typeof(bp->strm->next_in))zbuf + n;
  5278. bp->strm->avail_in = len - n;
  5279. bp->strm->next_out = bp->gunzip_buf;
  5280. bp->strm->avail_out = FW_BUF_SIZE;
  5281. rc = zlib_inflateInit2(bp->strm, -MAX_WBITS);
  5282. if (rc != Z_OK)
  5283. return rc;
  5284. rc = zlib_inflate(bp->strm, Z_FINISH);
  5285. if ((rc != Z_OK) && (rc != Z_STREAM_END))
  5286. netdev_err(bp->dev, "Firmware decompression error: %s\n",
  5287. bp->strm->msg);
  5288. bp->gunzip_outlen = (FW_BUF_SIZE - bp->strm->avail_out);
  5289. if (bp->gunzip_outlen & 0x3)
  5290. netdev_err(bp->dev,
  5291. "Firmware decompression error: gunzip_outlen (%d) not aligned\n",
  5292. bp->gunzip_outlen);
  5293. bp->gunzip_outlen >>= 2;
  5294. zlib_inflateEnd(bp->strm);
  5295. if (rc == Z_STREAM_END)
  5296. return 0;
  5297. return rc;
  5298. }
  5299. /* nic load/unload */
  5300. /*
  5301. * General service functions
  5302. */
  5303. /* send a NIG loopback debug packet */
  5304. static void bnx2x_lb_pckt(struct bnx2x *bp)
  5305. {
  5306. u32 wb_write[3];
  5307. /* Ethernet source and destination addresses */
  5308. wb_write[0] = 0x55555555;
  5309. wb_write[1] = 0x55555555;
  5310. wb_write[2] = 0x20; /* SOP */
  5311. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5312. /* NON-IP protocol */
  5313. wb_write[0] = 0x09000000;
  5314. wb_write[1] = 0x55555555;
  5315. wb_write[2] = 0x10; /* EOP, eop_bvalid = 0 */
  5316. REG_WR_DMAE(bp, NIG_REG_DEBUG_PACKET_LB, wb_write, 3);
  5317. }
  5318. /* some of the internal memories
  5319. * are not directly readable from the driver
  5320. * to test them we send debug packets
  5321. */
  5322. static int bnx2x_int_mem_test(struct bnx2x *bp)
  5323. {
  5324. int factor;
  5325. int count, i;
  5326. u32 val = 0;
  5327. if (CHIP_REV_IS_FPGA(bp))
  5328. factor = 120;
  5329. else if (CHIP_REV_IS_EMUL(bp))
  5330. factor = 200;
  5331. else
  5332. factor = 1;
  5333. /* Disable inputs of parser neighbor blocks */
  5334. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5335. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5336. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5337. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5338. /* Write 0 to parser credits for CFC search request */
  5339. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5340. /* send Ethernet packet */
  5341. bnx2x_lb_pckt(bp);
  5342. /* TODO do i reset NIG statistic? */
  5343. /* Wait until NIG register shows 1 packet of size 0x10 */
  5344. count = 1000 * factor;
  5345. while (count) {
  5346. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5347. val = *bnx2x_sp(bp, wb_data[0]);
  5348. if (val == 0x10)
  5349. break;
  5350. usleep_range(10000, 20000);
  5351. count--;
  5352. }
  5353. if (val != 0x10) {
  5354. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5355. return -1;
  5356. }
  5357. /* Wait until PRS register shows 1 packet */
  5358. count = 1000 * factor;
  5359. while (count) {
  5360. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5361. if (val == 1)
  5362. break;
  5363. usleep_range(10000, 20000);
  5364. count--;
  5365. }
  5366. if (val != 0x1) {
  5367. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5368. return -2;
  5369. }
  5370. /* Reset and init BRB, PRS */
  5371. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5372. msleep(50);
  5373. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5374. msleep(50);
  5375. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5376. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5377. DP(NETIF_MSG_HW, "part2\n");
  5378. /* Disable inputs of parser neighbor blocks */
  5379. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x0);
  5380. REG_WR(bp, TCM_REG_PRS_IFEN, 0x0);
  5381. REG_WR(bp, CFC_REG_DEBUG0, 0x1);
  5382. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x0);
  5383. /* Write 0 to parser credits for CFC search request */
  5384. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x0);
  5385. /* send 10 Ethernet packets */
  5386. for (i = 0; i < 10; i++)
  5387. bnx2x_lb_pckt(bp);
  5388. /* Wait until NIG register shows 10 + 1
  5389. packets of size 11*0x10 = 0xb0 */
  5390. count = 1000 * factor;
  5391. while (count) {
  5392. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5393. val = *bnx2x_sp(bp, wb_data[0]);
  5394. if (val == 0xb0)
  5395. break;
  5396. usleep_range(10000, 20000);
  5397. count--;
  5398. }
  5399. if (val != 0xb0) {
  5400. BNX2X_ERR("NIG timeout val = 0x%x\n", val);
  5401. return -3;
  5402. }
  5403. /* Wait until PRS register shows 2 packets */
  5404. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5405. if (val != 2)
  5406. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5407. /* Write 1 to parser credits for CFC search request */
  5408. REG_WR(bp, PRS_REG_CFC_SEARCH_INITIAL_CREDIT, 0x1);
  5409. /* Wait until PRS register shows 3 packets */
  5410. msleep(10 * factor);
  5411. /* Wait until NIG register shows 1 packet of size 0x10 */
  5412. val = REG_RD(bp, PRS_REG_NUM_OF_PACKETS);
  5413. if (val != 3)
  5414. BNX2X_ERR("PRS timeout val = 0x%x\n", val);
  5415. /* clear NIG EOP FIFO */
  5416. for (i = 0; i < 11; i++)
  5417. REG_RD(bp, NIG_REG_INGRESS_EOP_LB_FIFO);
  5418. val = REG_RD(bp, NIG_REG_INGRESS_EOP_LB_EMPTY);
  5419. if (val != 1) {
  5420. BNX2X_ERR("clear of NIG failed\n");
  5421. return -4;
  5422. }
  5423. /* Reset and init BRB, PRS, NIG */
  5424. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR, 0x03);
  5425. msleep(50);
  5426. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0x03);
  5427. msleep(50);
  5428. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5429. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5430. if (!CNIC_SUPPORT(bp))
  5431. /* set NIC mode */
  5432. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  5433. /* Enable inputs of parser neighbor blocks */
  5434. REG_WR(bp, TSDM_REG_ENABLE_IN1, 0x7fffffff);
  5435. REG_WR(bp, TCM_REG_PRS_IFEN, 0x1);
  5436. REG_WR(bp, CFC_REG_DEBUG0, 0x0);
  5437. REG_WR(bp, NIG_REG_PRS_REQ_IN_EN, 0x1);
  5438. DP(NETIF_MSG_HW, "done\n");
  5439. return 0; /* OK */
  5440. }
  5441. static void bnx2x_enable_blocks_attention(struct bnx2x *bp)
  5442. {
  5443. u32 val;
  5444. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5445. if (!CHIP_IS_E1x(bp))
  5446. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0x40);
  5447. else
  5448. REG_WR(bp, PXP_REG_PXP_INT_MASK_1, 0);
  5449. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5450. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5451. /*
  5452. * mask read length error interrupts in brb for parser
  5453. * (parsing unit and 'checksum and crc' unit)
  5454. * these errors are legal (PU reads fixed length and CAC can cause
  5455. * read length error on truncated packets)
  5456. */
  5457. REG_WR(bp, BRB1_REG_BRB1_INT_MASK, 0xFC00);
  5458. REG_WR(bp, QM_REG_QM_INT_MASK, 0);
  5459. REG_WR(bp, TM_REG_TM_INT_MASK, 0);
  5460. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_0, 0);
  5461. REG_WR(bp, XSDM_REG_XSDM_INT_MASK_1, 0);
  5462. REG_WR(bp, XCM_REG_XCM_INT_MASK, 0);
  5463. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_0, 0); */
  5464. /* REG_WR(bp, XSEM_REG_XSEM_INT_MASK_1, 0); */
  5465. REG_WR(bp, USDM_REG_USDM_INT_MASK_0, 0);
  5466. REG_WR(bp, USDM_REG_USDM_INT_MASK_1, 0);
  5467. REG_WR(bp, UCM_REG_UCM_INT_MASK, 0);
  5468. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_0, 0); */
  5469. /* REG_WR(bp, USEM_REG_USEM_INT_MASK_1, 0); */
  5470. REG_WR(bp, GRCBASE_UPB + PB_REG_PB_INT_MASK, 0);
  5471. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_0, 0);
  5472. REG_WR(bp, CSDM_REG_CSDM_INT_MASK_1, 0);
  5473. REG_WR(bp, CCM_REG_CCM_INT_MASK, 0);
  5474. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_0, 0); */
  5475. /* REG_WR(bp, CSEM_REG_CSEM_INT_MASK_1, 0); */
  5476. val = PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_AFT |
  5477. PXP2_PXP2_INT_MASK_0_REG_PGL_CPL_OF |
  5478. PXP2_PXP2_INT_MASK_0_REG_PGL_PCIE_ATTN;
  5479. if (!CHIP_IS_E1x(bp))
  5480. val |= PXP2_PXP2_INT_MASK_0_REG_PGL_READ_BLOCKED |
  5481. PXP2_PXP2_INT_MASK_0_REG_PGL_WRITE_BLOCKED;
  5482. REG_WR(bp, PXP2_REG_PXP2_INT_MASK_0, val);
  5483. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_0, 0);
  5484. REG_WR(bp, TSDM_REG_TSDM_INT_MASK_1, 0);
  5485. REG_WR(bp, TCM_REG_TCM_INT_MASK, 0);
  5486. /* REG_WR(bp, TSEM_REG_TSEM_INT_MASK_0, 0); */
  5487. if (!CHIP_IS_E1x(bp))
  5488. /* enable VFC attentions: bits 11 and 12, bits 31:13 reserved */
  5489. REG_WR(bp, TSEM_REG_TSEM_INT_MASK_1, 0x07ff);
  5490. REG_WR(bp, CDU_REG_CDU_INT_MASK, 0);
  5491. REG_WR(bp, DMAE_REG_DMAE_INT_MASK, 0);
  5492. /* REG_WR(bp, MISC_REG_MISC_INT_MASK, 0); */
  5493. REG_WR(bp, PBF_REG_PBF_INT_MASK, 0x18); /* bit 3,4 masked */
  5494. }
  5495. static void bnx2x_reset_common(struct bnx2x *bp)
  5496. {
  5497. u32 val = 0x1400;
  5498. /* reset_common */
  5499. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5500. 0xd3ffff7f);
  5501. if (CHIP_IS_E3(bp)) {
  5502. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5503. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5504. }
  5505. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR, val);
  5506. }
  5507. static void bnx2x_setup_dmae(struct bnx2x *bp)
  5508. {
  5509. bp->dmae_ready = 0;
  5510. spin_lock_init(&bp->dmae_lock);
  5511. }
  5512. static void bnx2x_init_pxp(struct bnx2x *bp)
  5513. {
  5514. u16 devctl;
  5515. int r_order, w_order;
  5516. pcie_capability_read_word(bp->pdev, PCI_EXP_DEVCTL, &devctl);
  5517. DP(NETIF_MSG_HW, "read 0x%x from devctl\n", devctl);
  5518. w_order = ((devctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
  5519. if (bp->mrrs == -1)
  5520. r_order = ((devctl & PCI_EXP_DEVCTL_READRQ) >> 12);
  5521. else {
  5522. DP(NETIF_MSG_HW, "force read order to %d\n", bp->mrrs);
  5523. r_order = bp->mrrs;
  5524. }
  5525. bnx2x_init_pxp_arb(bp, r_order, w_order);
  5526. }
  5527. static void bnx2x_setup_fan_failure_detection(struct bnx2x *bp)
  5528. {
  5529. int is_required;
  5530. u32 val;
  5531. int port;
  5532. if (BP_NOMCP(bp))
  5533. return;
  5534. is_required = 0;
  5535. val = SHMEM_RD(bp, dev_info.shared_hw_config.config2) &
  5536. SHARED_HW_CFG_FAN_FAILURE_MASK;
  5537. if (val == SHARED_HW_CFG_FAN_FAILURE_ENABLED)
  5538. is_required = 1;
  5539. /*
  5540. * The fan failure mechanism is usually related to the PHY type since
  5541. * the power consumption of the board is affected by the PHY. Currently,
  5542. * fan is required for most designs with SFX7101, BCM8727 and BCM8481.
  5543. */
  5544. else if (val == SHARED_HW_CFG_FAN_FAILURE_PHY_TYPE)
  5545. for (port = PORT_0; port < PORT_MAX; port++) {
  5546. is_required |=
  5547. bnx2x_fan_failure_det_req(
  5548. bp,
  5549. bp->common.shmem_base,
  5550. bp->common.shmem2_base,
  5551. port);
  5552. }
  5553. DP(NETIF_MSG_HW, "fan detection setting: %d\n", is_required);
  5554. if (is_required == 0)
  5555. return;
  5556. /* Fan failure is indicated by SPIO 5 */
  5557. bnx2x_set_spio(bp, MISC_SPIO_SPIO5, MISC_SPIO_INPUT_HI_Z);
  5558. /* set to active low mode */
  5559. val = REG_RD(bp, MISC_REG_SPIO_INT);
  5560. val |= (MISC_SPIO_SPIO5 << MISC_SPIO_INT_OLD_SET_POS);
  5561. REG_WR(bp, MISC_REG_SPIO_INT, val);
  5562. /* enable interrupt to signal the IGU */
  5563. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  5564. val |= MISC_SPIO_SPIO5;
  5565. REG_WR(bp, MISC_REG_SPIO_EVENT_EN, val);
  5566. }
  5567. void bnx2x_pf_disable(struct bnx2x *bp)
  5568. {
  5569. u32 val = REG_RD(bp, IGU_REG_PF_CONFIGURATION);
  5570. val &= ~IGU_PF_CONF_FUNC_EN;
  5571. REG_WR(bp, IGU_REG_PF_CONFIGURATION, val);
  5572. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5573. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 0);
  5574. }
  5575. static void bnx2x__common_init_phy(struct bnx2x *bp)
  5576. {
  5577. u32 shmem_base[2], shmem2_base[2];
  5578. /* Avoid common init in case MFW supports LFA */
  5579. if (SHMEM2_RD(bp, size) >
  5580. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  5581. return;
  5582. shmem_base[0] = bp->common.shmem_base;
  5583. shmem2_base[0] = bp->common.shmem2_base;
  5584. if (!CHIP_IS_E1x(bp)) {
  5585. shmem_base[1] =
  5586. SHMEM2_RD(bp, other_shmem_base_addr);
  5587. shmem2_base[1] =
  5588. SHMEM2_RD(bp, other_shmem2_base_addr);
  5589. }
  5590. bnx2x_acquire_phy_lock(bp);
  5591. bnx2x_common_init_phy(bp, shmem_base, shmem2_base,
  5592. bp->common.chip_id);
  5593. bnx2x_release_phy_lock(bp);
  5594. }
  5595. /**
  5596. * bnx2x_init_hw_common - initialize the HW at the COMMON phase.
  5597. *
  5598. * @bp: driver handle
  5599. */
  5600. static int bnx2x_init_hw_common(struct bnx2x *bp)
  5601. {
  5602. u32 val;
  5603. DP(NETIF_MSG_HW, "starting common init func %d\n", BP_ABS_FUNC(bp));
  5604. /*
  5605. * take the RESET lock to protect undi_unload flow from accessing
  5606. * registers while we're resetting the chip
  5607. */
  5608. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5609. bnx2x_reset_common(bp);
  5610. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, 0xffffffff);
  5611. val = 0xfffc;
  5612. if (CHIP_IS_E3(bp)) {
  5613. val |= MISC_REGISTERS_RESET_REG_2_MSTAT0;
  5614. val |= MISC_REGISTERS_RESET_REG_2_MSTAT1;
  5615. }
  5616. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET, val);
  5617. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  5618. bnx2x_init_block(bp, BLOCK_MISC, PHASE_COMMON);
  5619. if (!CHIP_IS_E1x(bp)) {
  5620. u8 abs_func_id;
  5621. /**
  5622. * 4-port mode or 2-port mode we need to turn of master-enable
  5623. * for everyone, after that, turn it back on for self.
  5624. * so, we disregard multi-function or not, and always disable
  5625. * for all functions on the given path, this means 0,2,4,6 for
  5626. * path 0 and 1,3,5,7 for path 1
  5627. */
  5628. for (abs_func_id = BP_PATH(bp);
  5629. abs_func_id < E2_FUNC_MAX*2; abs_func_id += 2) {
  5630. if (abs_func_id == BP_ABS_FUNC(bp)) {
  5631. REG_WR(bp,
  5632. PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER,
  5633. 1);
  5634. continue;
  5635. }
  5636. bnx2x_pretend_func(bp, abs_func_id);
  5637. /* clear pf enable */
  5638. bnx2x_pf_disable(bp);
  5639. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5640. }
  5641. }
  5642. bnx2x_init_block(bp, BLOCK_PXP, PHASE_COMMON);
  5643. if (CHIP_IS_E1(bp)) {
  5644. /* enable HW interrupt from PXP on USDM overflow
  5645. bit 16 on INT_MASK_0 */
  5646. REG_WR(bp, PXP_REG_PXP_INT_MASK_0, 0);
  5647. }
  5648. bnx2x_init_block(bp, BLOCK_PXP2, PHASE_COMMON);
  5649. bnx2x_init_pxp(bp);
  5650. #ifdef __BIG_ENDIAN
  5651. REG_WR(bp, PXP2_REG_RQ_QM_ENDIAN_M, 1);
  5652. REG_WR(bp, PXP2_REG_RQ_TM_ENDIAN_M, 1);
  5653. REG_WR(bp, PXP2_REG_RQ_SRC_ENDIAN_M, 1);
  5654. REG_WR(bp, PXP2_REG_RQ_CDU_ENDIAN_M, 1);
  5655. REG_WR(bp, PXP2_REG_RQ_DBG_ENDIAN_M, 1);
  5656. /* make sure this value is 0 */
  5657. REG_WR(bp, PXP2_REG_RQ_HC_ENDIAN_M, 0);
  5658. /* REG_WR(bp, PXP2_REG_RD_PBF_SWAP_MODE, 1); */
  5659. REG_WR(bp, PXP2_REG_RD_QM_SWAP_MODE, 1);
  5660. REG_WR(bp, PXP2_REG_RD_TM_SWAP_MODE, 1);
  5661. REG_WR(bp, PXP2_REG_RD_SRC_SWAP_MODE, 1);
  5662. REG_WR(bp, PXP2_REG_RD_CDURD_SWAP_MODE, 1);
  5663. #endif
  5664. bnx2x_ilt_init_page_size(bp, INITOP_SET);
  5665. if (CHIP_REV_IS_FPGA(bp) && CHIP_IS_E1H(bp))
  5666. REG_WR(bp, PXP2_REG_PGL_TAGS_LIMIT, 0x1);
  5667. /* let the HW do it's magic ... */
  5668. msleep(100);
  5669. /* finish PXP init */
  5670. val = REG_RD(bp, PXP2_REG_RQ_CFG_DONE);
  5671. if (val != 1) {
  5672. BNX2X_ERR("PXP2 CFG failed\n");
  5673. return -EBUSY;
  5674. }
  5675. val = REG_RD(bp, PXP2_REG_RD_INIT_DONE);
  5676. if (val != 1) {
  5677. BNX2X_ERR("PXP2 RD_INIT failed\n");
  5678. return -EBUSY;
  5679. }
  5680. /* Timers bug workaround E2 only. We need to set the entire ILT to
  5681. * have entries with value "0" and valid bit on.
  5682. * This needs to be done by the first PF that is loaded in a path
  5683. * (i.e. common phase)
  5684. */
  5685. if (!CHIP_IS_E1x(bp)) {
  5686. /* In E2 there is a bug in the timers block that can cause function 6 / 7
  5687. * (i.e. vnic3) to start even if it is marked as "scan-off".
  5688. * This occurs when a different function (func2,3) is being marked
  5689. * as "scan-off". Real-life scenario for example: if a driver is being
  5690. * load-unloaded while func6,7 are down. This will cause the timer to access
  5691. * the ilt, translate to a logical address and send a request to read/write.
  5692. * Since the ilt for the function that is down is not valid, this will cause
  5693. * a translation error which is unrecoverable.
  5694. * The Workaround is intended to make sure that when this happens nothing fatal
  5695. * will occur. The workaround:
  5696. * 1. First PF driver which loads on a path will:
  5697. * a. After taking the chip out of reset, by using pretend,
  5698. * it will write "0" to the following registers of
  5699. * the other vnics.
  5700. * REG_WR(pdev, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  5701. * REG_WR(pdev, CFC_REG_WEAK_ENABLE_PF,0);
  5702. * REG_WR(pdev, CFC_REG_STRONG_ENABLE_PF,0);
  5703. * And for itself it will write '1' to
  5704. * PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER to enable
  5705. * dmae-operations (writing to pram for example.)
  5706. * note: can be done for only function 6,7 but cleaner this
  5707. * way.
  5708. * b. Write zero+valid to the entire ILT.
  5709. * c. Init the first_timers_ilt_entry, last_timers_ilt_entry of
  5710. * VNIC3 (of that port). The range allocated will be the
  5711. * entire ILT. This is needed to prevent ILT range error.
  5712. * 2. Any PF driver load flow:
  5713. * a. ILT update with the physical addresses of the allocated
  5714. * logical pages.
  5715. * b. Wait 20msec. - note that this timeout is needed to make
  5716. * sure there are no requests in one of the PXP internal
  5717. * queues with "old" ILT addresses.
  5718. * c. PF enable in the PGLC.
  5719. * d. Clear the was_error of the PF in the PGLC. (could have
  5720. * occurred while driver was down)
  5721. * e. PF enable in the CFC (WEAK + STRONG)
  5722. * f. Timers scan enable
  5723. * 3. PF driver unload flow:
  5724. * a. Clear the Timers scan_en.
  5725. * b. Polling for scan_on=0 for that PF.
  5726. * c. Clear the PF enable bit in the PXP.
  5727. * d. Clear the PF enable in the CFC (WEAK + STRONG)
  5728. * e. Write zero+valid to all ILT entries (The valid bit must
  5729. * stay set)
  5730. * f. If this is VNIC 3 of a port then also init
  5731. * first_timers_ilt_entry to zero and last_timers_ilt_entry
  5732. * to the last entry in the ILT.
  5733. *
  5734. * Notes:
  5735. * Currently the PF error in the PGLC is non recoverable.
  5736. * In the future the there will be a recovery routine for this error.
  5737. * Currently attention is masked.
  5738. * Having an MCP lock on the load/unload process does not guarantee that
  5739. * there is no Timer disable during Func6/7 enable. This is because the
  5740. * Timers scan is currently being cleared by the MCP on FLR.
  5741. * Step 2.d can be done only for PF6/7 and the driver can also check if
  5742. * there is error before clearing it. But the flow above is simpler and
  5743. * more general.
  5744. * All ILT entries are written by zero+valid and not just PF6/7
  5745. * ILT entries since in the future the ILT entries allocation for
  5746. * PF-s might be dynamic.
  5747. */
  5748. struct ilt_client_info ilt_cli;
  5749. struct bnx2x_ilt ilt;
  5750. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  5751. memset(&ilt, 0, sizeof(struct bnx2x_ilt));
  5752. /* initialize dummy TM client */
  5753. ilt_cli.start = 0;
  5754. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  5755. ilt_cli.client_num = ILT_CLIENT_TM;
  5756. /* Step 1: set zeroes to all ilt page entries with valid bit on
  5757. * Step 2: set the timers first/last ilt entry to point
  5758. * to the entire range to prevent ILT range error for 3rd/4th
  5759. * vnic (this code assumes existence of the vnic)
  5760. *
  5761. * both steps performed by call to bnx2x_ilt_client_init_op()
  5762. * with dummy TM client
  5763. *
  5764. * we must use pretend since PXP2_REG_RQ_##blk##_FIRST_ILT
  5765. * and his brother are split registers
  5766. */
  5767. bnx2x_pretend_func(bp, (BP_PATH(bp) + 6));
  5768. bnx2x_ilt_client_init_op_ilt(bp, &ilt, &ilt_cli, INITOP_CLEAR);
  5769. bnx2x_pretend_func(bp, BP_ABS_FUNC(bp));
  5770. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN, BNX2X_PXP_DRAM_ALIGN);
  5771. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_RD, BNX2X_PXP_DRAM_ALIGN);
  5772. REG_WR(bp, PXP2_REG_RQ_DRAM_ALIGN_SEL, 1);
  5773. }
  5774. REG_WR(bp, PXP2_REG_RQ_DISABLE_INPUTS, 0);
  5775. REG_WR(bp, PXP2_REG_RD_DISABLE_INPUTS, 0);
  5776. if (!CHIP_IS_E1x(bp)) {
  5777. int factor = CHIP_REV_IS_EMUL(bp) ? 1000 :
  5778. (CHIP_REV_IS_FPGA(bp) ? 400 : 0);
  5779. bnx2x_init_block(bp, BLOCK_PGLUE_B, PHASE_COMMON);
  5780. bnx2x_init_block(bp, BLOCK_ATC, PHASE_COMMON);
  5781. /* let the HW do it's magic ... */
  5782. do {
  5783. msleep(200);
  5784. val = REG_RD(bp, ATC_REG_ATC_INIT_DONE);
  5785. } while (factor-- && (val != 1));
  5786. if (val != 1) {
  5787. BNX2X_ERR("ATC_INIT failed\n");
  5788. return -EBUSY;
  5789. }
  5790. }
  5791. bnx2x_init_block(bp, BLOCK_DMAE, PHASE_COMMON);
  5792. bnx2x_iov_init_dmae(bp);
  5793. /* clean the DMAE memory */
  5794. bp->dmae_ready = 1;
  5795. bnx2x_init_fill(bp, TSEM_REG_PRAM, 0, 8, 1);
  5796. bnx2x_init_block(bp, BLOCK_TCM, PHASE_COMMON);
  5797. bnx2x_init_block(bp, BLOCK_UCM, PHASE_COMMON);
  5798. bnx2x_init_block(bp, BLOCK_CCM, PHASE_COMMON);
  5799. bnx2x_init_block(bp, BLOCK_XCM, PHASE_COMMON);
  5800. bnx2x_read_dmae(bp, XSEM_REG_PASSIVE_BUFFER, 3);
  5801. bnx2x_read_dmae(bp, CSEM_REG_PASSIVE_BUFFER, 3);
  5802. bnx2x_read_dmae(bp, TSEM_REG_PASSIVE_BUFFER, 3);
  5803. bnx2x_read_dmae(bp, USEM_REG_PASSIVE_BUFFER, 3);
  5804. bnx2x_init_block(bp, BLOCK_QM, PHASE_COMMON);
  5805. /* QM queues pointers table */
  5806. bnx2x_qm_init_ptr_table(bp, bp->qm_cid_count, INITOP_SET);
  5807. /* soft reset pulse */
  5808. REG_WR(bp, QM_REG_SOFT_RESET, 1);
  5809. REG_WR(bp, QM_REG_SOFT_RESET, 0);
  5810. if (CNIC_SUPPORT(bp))
  5811. bnx2x_init_block(bp, BLOCK_TM, PHASE_COMMON);
  5812. bnx2x_init_block(bp, BLOCK_DORQ, PHASE_COMMON);
  5813. REG_WR(bp, DORQ_REG_DPM_CID_OFST, BNX2X_DB_SHIFT);
  5814. if (!CHIP_REV_IS_SLOW(bp))
  5815. /* enable hw interrupt from doorbell Q */
  5816. REG_WR(bp, DORQ_REG_DORQ_INT_MASK, 0);
  5817. bnx2x_init_block(bp, BLOCK_BRB1, PHASE_COMMON);
  5818. bnx2x_init_block(bp, BLOCK_PRS, PHASE_COMMON);
  5819. REG_WR(bp, PRS_REG_A_PRSU_20, 0xf);
  5820. if (!CHIP_IS_E1(bp))
  5821. REG_WR(bp, PRS_REG_E1HOV_MODE, bp->path_has_ovlan);
  5822. if (!CHIP_IS_E1x(bp) && !CHIP_IS_E3B0(bp)) {
  5823. if (IS_MF_AFEX(bp)) {
  5824. /* configure that VNTag and VLAN headers must be
  5825. * received in afex mode
  5826. */
  5827. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC, 0xE);
  5828. REG_WR(bp, PRS_REG_MUST_HAVE_HDRS, 0xA);
  5829. REG_WR(bp, PRS_REG_HDRS_AFTER_TAG_0, 0x6);
  5830. REG_WR(bp, PRS_REG_TAG_ETHERTYPE_0, 0x8926);
  5831. REG_WR(bp, PRS_REG_TAG_LEN_0, 0x4);
  5832. } else {
  5833. /* Bit-map indicating which L2 hdrs may appear
  5834. * after the basic Ethernet header
  5835. */
  5836. REG_WR(bp, PRS_REG_HDRS_AFTER_BASIC,
  5837. bp->path_has_ovlan ? 7 : 6);
  5838. }
  5839. }
  5840. bnx2x_init_block(bp, BLOCK_TSDM, PHASE_COMMON);
  5841. bnx2x_init_block(bp, BLOCK_CSDM, PHASE_COMMON);
  5842. bnx2x_init_block(bp, BLOCK_USDM, PHASE_COMMON);
  5843. bnx2x_init_block(bp, BLOCK_XSDM, PHASE_COMMON);
  5844. if (!CHIP_IS_E1x(bp)) {
  5845. /* reset VFC memories */
  5846. REG_WR(bp, TSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5847. VFC_MEMORIES_RST_REG_CAM_RST |
  5848. VFC_MEMORIES_RST_REG_RAM_RST);
  5849. REG_WR(bp, XSEM_REG_FAST_MEMORY + VFC_REG_MEMORIES_RST,
  5850. VFC_MEMORIES_RST_REG_CAM_RST |
  5851. VFC_MEMORIES_RST_REG_RAM_RST);
  5852. msleep(20);
  5853. }
  5854. bnx2x_init_block(bp, BLOCK_TSEM, PHASE_COMMON);
  5855. bnx2x_init_block(bp, BLOCK_USEM, PHASE_COMMON);
  5856. bnx2x_init_block(bp, BLOCK_CSEM, PHASE_COMMON);
  5857. bnx2x_init_block(bp, BLOCK_XSEM, PHASE_COMMON);
  5858. /* sync semi rtc */
  5859. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  5860. 0x80000000);
  5861. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET,
  5862. 0x80000000);
  5863. bnx2x_init_block(bp, BLOCK_UPB, PHASE_COMMON);
  5864. bnx2x_init_block(bp, BLOCK_XPB, PHASE_COMMON);
  5865. bnx2x_init_block(bp, BLOCK_PBF, PHASE_COMMON);
  5866. if (!CHIP_IS_E1x(bp)) {
  5867. if (IS_MF_AFEX(bp)) {
  5868. /* configure that VNTag and VLAN headers must be
  5869. * sent in afex mode
  5870. */
  5871. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC, 0xE);
  5872. REG_WR(bp, PBF_REG_MUST_HAVE_HDRS, 0xA);
  5873. REG_WR(bp, PBF_REG_HDRS_AFTER_TAG_0, 0x6);
  5874. REG_WR(bp, PBF_REG_TAG_ETHERTYPE_0, 0x8926);
  5875. REG_WR(bp, PBF_REG_TAG_LEN_0, 0x4);
  5876. } else {
  5877. REG_WR(bp, PBF_REG_HDRS_AFTER_BASIC,
  5878. bp->path_has_ovlan ? 7 : 6);
  5879. }
  5880. }
  5881. REG_WR(bp, SRC_REG_SOFT_RST, 1);
  5882. bnx2x_init_block(bp, BLOCK_SRC, PHASE_COMMON);
  5883. if (CNIC_SUPPORT(bp)) {
  5884. REG_WR(bp, SRC_REG_KEYSEARCH_0, 0x63285672);
  5885. REG_WR(bp, SRC_REG_KEYSEARCH_1, 0x24b8f2cc);
  5886. REG_WR(bp, SRC_REG_KEYSEARCH_2, 0x223aef9b);
  5887. REG_WR(bp, SRC_REG_KEYSEARCH_3, 0x26001e3a);
  5888. REG_WR(bp, SRC_REG_KEYSEARCH_4, 0x7ae91116);
  5889. REG_WR(bp, SRC_REG_KEYSEARCH_5, 0x5ce5230b);
  5890. REG_WR(bp, SRC_REG_KEYSEARCH_6, 0x298d8adf);
  5891. REG_WR(bp, SRC_REG_KEYSEARCH_7, 0x6eb0ff09);
  5892. REG_WR(bp, SRC_REG_KEYSEARCH_8, 0x1830f82f);
  5893. REG_WR(bp, SRC_REG_KEYSEARCH_9, 0x01e46be7);
  5894. }
  5895. REG_WR(bp, SRC_REG_SOFT_RST, 0);
  5896. if (sizeof(union cdu_context) != 1024)
  5897. /* we currently assume that a context is 1024 bytes */
  5898. dev_alert(&bp->pdev->dev,
  5899. "please adjust the size of cdu_context(%ld)\n",
  5900. (long)sizeof(union cdu_context));
  5901. bnx2x_init_block(bp, BLOCK_CDU, PHASE_COMMON);
  5902. val = (4 << 24) + (0 << 12) + 1024;
  5903. REG_WR(bp, CDU_REG_CDU_GLOBAL_PARAMS, val);
  5904. bnx2x_init_block(bp, BLOCK_CFC, PHASE_COMMON);
  5905. REG_WR(bp, CFC_REG_INIT_REG, 0x7FF);
  5906. /* enable context validation interrupt from CFC */
  5907. REG_WR(bp, CFC_REG_CFC_INT_MASK, 0);
  5908. /* set the thresholds to prevent CFC/CDU race */
  5909. REG_WR(bp, CFC_REG_DEBUG0, 0x20020000);
  5910. bnx2x_init_block(bp, BLOCK_HC, PHASE_COMMON);
  5911. if (!CHIP_IS_E1x(bp) && BP_NOMCP(bp))
  5912. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x36);
  5913. bnx2x_init_block(bp, BLOCK_IGU, PHASE_COMMON);
  5914. bnx2x_init_block(bp, BLOCK_MISC_AEU, PHASE_COMMON);
  5915. /* Reset PCIE errors for debug */
  5916. REG_WR(bp, 0x2814, 0xffffffff);
  5917. REG_WR(bp, 0x3820, 0xffffffff);
  5918. if (!CHIP_IS_E1x(bp)) {
  5919. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_CONTROL_5,
  5920. (PXPCS_TL_CONTROL_5_ERR_UNSPPORT1 |
  5921. PXPCS_TL_CONTROL_5_ERR_UNSPPORT));
  5922. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC345_STAT,
  5923. (PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT4 |
  5924. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT3 |
  5925. PXPCS_TL_FUNC345_STAT_ERR_UNSPPORT2));
  5926. REG_WR(bp, PCICFG_OFFSET + PXPCS_TL_FUNC678_STAT,
  5927. (PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT7 |
  5928. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT6 |
  5929. PXPCS_TL_FUNC678_STAT_ERR_UNSPPORT5));
  5930. }
  5931. bnx2x_init_block(bp, BLOCK_NIG, PHASE_COMMON);
  5932. if (!CHIP_IS_E1(bp)) {
  5933. /* in E3 this done in per-port section */
  5934. if (!CHIP_IS_E3(bp))
  5935. REG_WR(bp, NIG_REG_LLH_MF_MODE, IS_MF(bp));
  5936. }
  5937. if (CHIP_IS_E1H(bp))
  5938. /* not applicable for E2 (and above ...) */
  5939. REG_WR(bp, NIG_REG_LLH_E1HOV_MODE, IS_MF_SD(bp));
  5940. if (CHIP_REV_IS_SLOW(bp))
  5941. msleep(200);
  5942. /* finish CFC init */
  5943. val = reg_poll(bp, CFC_REG_LL_INIT_DONE, 1, 100, 10);
  5944. if (val != 1) {
  5945. BNX2X_ERR("CFC LL_INIT failed\n");
  5946. return -EBUSY;
  5947. }
  5948. val = reg_poll(bp, CFC_REG_AC_INIT_DONE, 1, 100, 10);
  5949. if (val != 1) {
  5950. BNX2X_ERR("CFC AC_INIT failed\n");
  5951. return -EBUSY;
  5952. }
  5953. val = reg_poll(bp, CFC_REG_CAM_INIT_DONE, 1, 100, 10);
  5954. if (val != 1) {
  5955. BNX2X_ERR("CFC CAM_INIT failed\n");
  5956. return -EBUSY;
  5957. }
  5958. REG_WR(bp, CFC_REG_DEBUG0, 0);
  5959. if (CHIP_IS_E1(bp)) {
  5960. /* read NIG statistic
  5961. to see if this is our first up since powerup */
  5962. bnx2x_read_dmae(bp, NIG_REG_STAT2_BRB_OCTET, 2);
  5963. val = *bnx2x_sp(bp, wb_data[0]);
  5964. /* do internal memory self test */
  5965. if ((val == 0) && bnx2x_int_mem_test(bp)) {
  5966. BNX2X_ERR("internal mem self test failed\n");
  5967. return -EBUSY;
  5968. }
  5969. }
  5970. bnx2x_setup_fan_failure_detection(bp);
  5971. /* clear PXP2 attentions */
  5972. REG_RD(bp, PXP2_REG_PXP2_INT_STS_CLR_0);
  5973. bnx2x_enable_blocks_attention(bp);
  5974. bnx2x_enable_blocks_parity(bp);
  5975. if (!BP_NOMCP(bp)) {
  5976. if (CHIP_IS_E1x(bp))
  5977. bnx2x__common_init_phy(bp);
  5978. } else
  5979. BNX2X_ERR("Bootcode is missing - can not initialize link\n");
  5980. return 0;
  5981. }
  5982. /**
  5983. * bnx2x_init_hw_common_chip - init HW at the COMMON_CHIP phase.
  5984. *
  5985. * @bp: driver handle
  5986. */
  5987. static int bnx2x_init_hw_common_chip(struct bnx2x *bp)
  5988. {
  5989. int rc = bnx2x_init_hw_common(bp);
  5990. if (rc)
  5991. return rc;
  5992. /* In E2 2-PORT mode, same ext phy is used for the two paths */
  5993. if (!BP_NOMCP(bp))
  5994. bnx2x__common_init_phy(bp);
  5995. return 0;
  5996. }
  5997. static int bnx2x_init_hw_port(struct bnx2x *bp)
  5998. {
  5999. int port = BP_PORT(bp);
  6000. int init_phase = port ? PHASE_PORT1 : PHASE_PORT0;
  6001. u32 low, high;
  6002. u32 val;
  6003. DP(NETIF_MSG_HW, "starting port init port %d\n", port);
  6004. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  6005. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6006. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6007. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6008. /* Timers bug workaround: disables the pf_master bit in pglue at
  6009. * common phase, we need to enable it here before any dmae access are
  6010. * attempted. Therefore we manually added the enable-master to the
  6011. * port phase (it also happens in the function phase)
  6012. */
  6013. if (!CHIP_IS_E1x(bp))
  6014. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6015. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6016. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6017. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6018. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6019. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6020. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6021. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6022. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6023. /* QM cid (connection) count */
  6024. bnx2x_qm_init_cid_count(bp, bp->qm_cid_count, INITOP_SET);
  6025. if (CNIC_SUPPORT(bp)) {
  6026. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6027. REG_WR(bp, TM_REG_LIN0_SCAN_TIME + port*4, 20);
  6028. REG_WR(bp, TM_REG_LIN0_MAX_ACTIVE_CID + port*4, 31);
  6029. }
  6030. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6031. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6032. if (CHIP_IS_E1(bp) || CHIP_IS_E1H(bp)) {
  6033. if (IS_MF(bp))
  6034. low = ((bp->flags & ONE_PORT_FLAG) ? 160 : 246);
  6035. else if (bp->dev->mtu > 4096) {
  6036. if (bp->flags & ONE_PORT_FLAG)
  6037. low = 160;
  6038. else {
  6039. val = bp->dev->mtu;
  6040. /* (24*1024 + val*4)/256 */
  6041. low = 96 + (val/64) +
  6042. ((val % 64) ? 1 : 0);
  6043. }
  6044. } else
  6045. low = ((bp->flags & ONE_PORT_FLAG) ? 80 : 160);
  6046. high = low + 56; /* 14*1024/256 */
  6047. REG_WR(bp, BRB1_REG_PAUSE_LOW_THRESHOLD_0 + port*4, low);
  6048. REG_WR(bp, BRB1_REG_PAUSE_HIGH_THRESHOLD_0 + port*4, high);
  6049. }
  6050. if (CHIP_MODE_IS_4_PORT(bp))
  6051. REG_WR(bp, (BP_PORT(bp) ?
  6052. BRB1_REG_MAC_GUARANTIED_1 :
  6053. BRB1_REG_MAC_GUARANTIED_0), 40);
  6054. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6055. if (CHIP_IS_E3B0(bp)) {
  6056. if (IS_MF_AFEX(bp)) {
  6057. /* configure headers for AFEX mode */
  6058. REG_WR(bp, BP_PORT(bp) ?
  6059. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6060. PRS_REG_HDRS_AFTER_BASIC_PORT_0, 0xE);
  6061. REG_WR(bp, BP_PORT(bp) ?
  6062. PRS_REG_HDRS_AFTER_TAG_0_PORT_1 :
  6063. PRS_REG_HDRS_AFTER_TAG_0_PORT_0, 0x6);
  6064. REG_WR(bp, BP_PORT(bp) ?
  6065. PRS_REG_MUST_HAVE_HDRS_PORT_1 :
  6066. PRS_REG_MUST_HAVE_HDRS_PORT_0, 0xA);
  6067. } else {
  6068. /* Ovlan exists only if we are in multi-function +
  6069. * switch-dependent mode, in switch-independent there
  6070. * is no ovlan headers
  6071. */
  6072. REG_WR(bp, BP_PORT(bp) ?
  6073. PRS_REG_HDRS_AFTER_BASIC_PORT_1 :
  6074. PRS_REG_HDRS_AFTER_BASIC_PORT_0,
  6075. (bp->path_has_ovlan ? 7 : 6));
  6076. }
  6077. }
  6078. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6079. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6080. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6081. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6082. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6083. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6084. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6085. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6086. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6087. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6088. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6089. if (CHIP_IS_E1x(bp)) {
  6090. /* configure PBF to work without PAUSE mtu 9000 */
  6091. REG_WR(bp, PBF_REG_P0_PAUSE_ENABLE + port*4, 0);
  6092. /* update threshold */
  6093. REG_WR(bp, PBF_REG_P0_ARB_THRSH + port*4, (9040/16));
  6094. /* update init credit */
  6095. REG_WR(bp, PBF_REG_P0_INIT_CRD + port*4, (9040/16) + 553 - 22);
  6096. /* probe changes */
  6097. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 1);
  6098. udelay(50);
  6099. REG_WR(bp, PBF_REG_INIT_P0 + port*4, 0);
  6100. }
  6101. if (CNIC_SUPPORT(bp))
  6102. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6103. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6104. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6105. if (CHIP_IS_E1(bp)) {
  6106. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6107. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6108. }
  6109. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6110. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6111. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6112. /* init aeu_mask_attn_func_0/1:
  6113. * - SF mode: bits 3-7 are masked. Only bits 0-2 are in use
  6114. * - MF mode: bit 3 is masked. Bits 0-2 are in use as in SF
  6115. * bits 4-7 are used for "per vn group attention" */
  6116. val = IS_MF(bp) ? 0xF7 : 0x7;
  6117. /* Enable DCBX attention for all but E1 */
  6118. val |= CHIP_IS_E1(bp) ? 0 : 0x10;
  6119. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, val);
  6120. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6121. if (!CHIP_IS_E1x(bp)) {
  6122. /* Bit-map indicating which L2 hdrs may appear after the
  6123. * basic Ethernet header
  6124. */
  6125. if (IS_MF_AFEX(bp))
  6126. REG_WR(bp, BP_PORT(bp) ?
  6127. NIG_REG_P1_HDRS_AFTER_BASIC :
  6128. NIG_REG_P0_HDRS_AFTER_BASIC, 0xE);
  6129. else
  6130. REG_WR(bp, BP_PORT(bp) ?
  6131. NIG_REG_P1_HDRS_AFTER_BASIC :
  6132. NIG_REG_P0_HDRS_AFTER_BASIC,
  6133. IS_MF_SD(bp) ? 7 : 6);
  6134. if (CHIP_IS_E3(bp))
  6135. REG_WR(bp, BP_PORT(bp) ?
  6136. NIG_REG_LLH1_MF_MODE :
  6137. NIG_REG_LLH_MF_MODE, IS_MF(bp));
  6138. }
  6139. if (!CHIP_IS_E3(bp))
  6140. REG_WR(bp, NIG_REG_XGXS_SERDES0_MODE_SEL + port*4, 1);
  6141. if (!CHIP_IS_E1(bp)) {
  6142. /* 0x2 disable mf_ov, 0x1 enable */
  6143. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK_MF + port*4,
  6144. (IS_MF_SD(bp) ? 0x1 : 0x2));
  6145. if (!CHIP_IS_E1x(bp)) {
  6146. val = 0;
  6147. switch (bp->mf_mode) {
  6148. case MULTI_FUNCTION_SD:
  6149. val = 1;
  6150. break;
  6151. case MULTI_FUNCTION_SI:
  6152. case MULTI_FUNCTION_AFEX:
  6153. val = 2;
  6154. break;
  6155. }
  6156. REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_CLS_TYPE :
  6157. NIG_REG_LLH0_CLS_TYPE), val);
  6158. }
  6159. {
  6160. REG_WR(bp, NIG_REG_LLFC_ENABLE_0 + port*4, 0);
  6161. REG_WR(bp, NIG_REG_LLFC_OUT_EN_0 + port*4, 0);
  6162. REG_WR(bp, NIG_REG_PAUSE_ENABLE_0 + port*4, 1);
  6163. }
  6164. }
  6165. /* If SPIO5 is set to generate interrupts, enable it for this port */
  6166. val = REG_RD(bp, MISC_REG_SPIO_EVENT_EN);
  6167. if (val & MISC_SPIO_SPIO5) {
  6168. u32 reg_addr = (port ? MISC_REG_AEU_ENABLE1_FUNC_1_OUT_0 :
  6169. MISC_REG_AEU_ENABLE1_FUNC_0_OUT_0);
  6170. val = REG_RD(bp, reg_addr);
  6171. val |= AEU_INPUTS_ATTN_BITS_SPIO5;
  6172. REG_WR(bp, reg_addr, val);
  6173. }
  6174. return 0;
  6175. }
  6176. static void bnx2x_ilt_wr(struct bnx2x *bp, u32 index, dma_addr_t addr)
  6177. {
  6178. int reg;
  6179. u32 wb_write[2];
  6180. if (CHIP_IS_E1(bp))
  6181. reg = PXP2_REG_RQ_ONCHIP_AT + index*8;
  6182. else
  6183. reg = PXP2_REG_RQ_ONCHIP_AT_B0 + index*8;
  6184. wb_write[0] = ONCHIP_ADDR1(addr);
  6185. wb_write[1] = ONCHIP_ADDR2(addr);
  6186. REG_WR_DMAE(bp, reg, wb_write, 2);
  6187. }
  6188. void bnx2x_igu_clear_sb_gen(struct bnx2x *bp, u8 func, u8 idu_sb_id, bool is_pf)
  6189. {
  6190. u32 data, ctl, cnt = 100;
  6191. u32 igu_addr_data = IGU_REG_COMMAND_REG_32LSB_DATA;
  6192. u32 igu_addr_ctl = IGU_REG_COMMAND_REG_CTRL;
  6193. u32 igu_addr_ack = IGU_REG_CSTORM_TYPE_0_SB_CLEANUP + (idu_sb_id/32)*4;
  6194. u32 sb_bit = 1 << (idu_sb_id%32);
  6195. u32 func_encode = func | (is_pf ? 1 : 0) << IGU_FID_ENCODE_IS_PF_SHIFT;
  6196. u32 addr_encode = IGU_CMD_E2_PROD_UPD_BASE + idu_sb_id;
  6197. /* Not supported in BC mode */
  6198. if (CHIP_INT_MODE_IS_BC(bp))
  6199. return;
  6200. data = (IGU_USE_REGISTER_cstorm_type_0_sb_cleanup
  6201. << IGU_REGULAR_CLEANUP_TYPE_SHIFT) |
  6202. IGU_REGULAR_CLEANUP_SET |
  6203. IGU_REGULAR_BCLEANUP;
  6204. ctl = addr_encode << IGU_CTRL_REG_ADDRESS_SHIFT |
  6205. func_encode << IGU_CTRL_REG_FID_SHIFT |
  6206. IGU_CTRL_CMD_TYPE_WR << IGU_CTRL_REG_TYPE_SHIFT;
  6207. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6208. data, igu_addr_data);
  6209. REG_WR(bp, igu_addr_data, data);
  6210. mmiowb();
  6211. barrier();
  6212. DP(NETIF_MSG_HW, "write 0x%08x to IGU(via GRC) addr 0x%x\n",
  6213. ctl, igu_addr_ctl);
  6214. REG_WR(bp, igu_addr_ctl, ctl);
  6215. mmiowb();
  6216. barrier();
  6217. /* wait for clean up to finish */
  6218. while (!(REG_RD(bp, igu_addr_ack) & sb_bit) && --cnt)
  6219. msleep(20);
  6220. if (!(REG_RD(bp, igu_addr_ack) & sb_bit)) {
  6221. DP(NETIF_MSG_HW,
  6222. "Unable to finish IGU cleanup: idu_sb_id %d offset %d bit %d (cnt %d)\n",
  6223. idu_sb_id, idu_sb_id/32, idu_sb_id%32, cnt);
  6224. }
  6225. }
  6226. static void bnx2x_igu_clear_sb(struct bnx2x *bp, u8 idu_sb_id)
  6227. {
  6228. bnx2x_igu_clear_sb_gen(bp, BP_FUNC(bp), idu_sb_id, true /*PF*/);
  6229. }
  6230. static void bnx2x_clear_func_ilt(struct bnx2x *bp, u32 func)
  6231. {
  6232. u32 i, base = FUNC_ILT_BASE(func);
  6233. for (i = base; i < base + ILT_PER_FUNC; i++)
  6234. bnx2x_ilt_wr(bp, i, 0);
  6235. }
  6236. static void bnx2x_init_searcher(struct bnx2x *bp)
  6237. {
  6238. int port = BP_PORT(bp);
  6239. bnx2x_src_init_t2(bp, bp->t2, bp->t2_mapping, SRC_CONN_NUM);
  6240. /* T1 hash bits value determines the T1 number of entries */
  6241. REG_WR(bp, SRC_REG_NUMBER_HASH_BITS0 + port*4, SRC_HASH_BITS);
  6242. }
  6243. static inline int bnx2x_func_switch_update(struct bnx2x *bp, int suspend)
  6244. {
  6245. int rc;
  6246. struct bnx2x_func_state_params func_params = {NULL};
  6247. struct bnx2x_func_switch_update_params *switch_update_params =
  6248. &func_params.params.switch_update;
  6249. /* Prepare parameters for function state transitions */
  6250. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  6251. __set_bit(RAMROD_RETRY, &func_params.ramrod_flags);
  6252. func_params.f_obj = &bp->func_obj;
  6253. func_params.cmd = BNX2X_F_CMD_SWITCH_UPDATE;
  6254. /* Function parameters */
  6255. switch_update_params->suspend = suspend;
  6256. rc = bnx2x_func_state_change(bp, &func_params);
  6257. return rc;
  6258. }
  6259. static int bnx2x_reset_nic_mode(struct bnx2x *bp)
  6260. {
  6261. int rc, i, port = BP_PORT(bp);
  6262. int vlan_en = 0, mac_en[NUM_MACS];
  6263. /* Close input from network */
  6264. if (bp->mf_mode == SINGLE_FUNCTION) {
  6265. bnx2x_set_rx_filter(&bp->link_params, 0);
  6266. } else {
  6267. vlan_en = REG_RD(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6268. NIG_REG_LLH0_FUNC_EN);
  6269. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6270. NIG_REG_LLH0_FUNC_EN, 0);
  6271. for (i = 0; i < NUM_MACS; i++) {
  6272. mac_en[i] = REG_RD(bp, port ?
  6273. (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6274. 4 * i) :
  6275. (NIG_REG_LLH0_FUNC_MEM_ENABLE +
  6276. 4 * i));
  6277. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6278. 4 * i) :
  6279. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i), 0);
  6280. }
  6281. }
  6282. /* Close BMC to host */
  6283. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6284. NIG_REG_P1_TX_MNG_HOST_ENABLE, 0);
  6285. /* Suspend Tx switching to the PF. Completion of this ramrod
  6286. * further guarantees that all the packets of that PF / child
  6287. * VFs in BRB were processed by the Parser, so it is safe to
  6288. * change the NIC_MODE register.
  6289. */
  6290. rc = bnx2x_func_switch_update(bp, 1);
  6291. if (rc) {
  6292. BNX2X_ERR("Can't suspend tx-switching!\n");
  6293. return rc;
  6294. }
  6295. /* Change NIC_MODE register */
  6296. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6297. /* Open input from network */
  6298. if (bp->mf_mode == SINGLE_FUNCTION) {
  6299. bnx2x_set_rx_filter(&bp->link_params, 1);
  6300. } else {
  6301. REG_WR(bp, port ? NIG_REG_LLH1_FUNC_EN :
  6302. NIG_REG_LLH0_FUNC_EN, vlan_en);
  6303. for (i = 0; i < NUM_MACS; i++) {
  6304. REG_WR(bp, port ? (NIG_REG_LLH1_FUNC_MEM_ENABLE +
  6305. 4 * i) :
  6306. (NIG_REG_LLH0_FUNC_MEM_ENABLE + 4 * i),
  6307. mac_en[i]);
  6308. }
  6309. }
  6310. /* Enable BMC to host */
  6311. REG_WR(bp, port ? NIG_REG_P0_TX_MNG_HOST_ENABLE :
  6312. NIG_REG_P1_TX_MNG_HOST_ENABLE, 1);
  6313. /* Resume Tx switching to the PF */
  6314. rc = bnx2x_func_switch_update(bp, 0);
  6315. if (rc) {
  6316. BNX2X_ERR("Can't resume tx-switching!\n");
  6317. return rc;
  6318. }
  6319. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6320. return 0;
  6321. }
  6322. int bnx2x_init_hw_func_cnic(struct bnx2x *bp)
  6323. {
  6324. int rc;
  6325. bnx2x_ilt_init_op_cnic(bp, INITOP_SET);
  6326. if (CONFIGURE_NIC_MODE(bp)) {
  6327. /* Configure searcher as part of function hw init */
  6328. bnx2x_init_searcher(bp);
  6329. /* Reset NIC mode */
  6330. rc = bnx2x_reset_nic_mode(bp);
  6331. if (rc)
  6332. BNX2X_ERR("Can't change NIC mode!\n");
  6333. return rc;
  6334. }
  6335. return 0;
  6336. }
  6337. static int bnx2x_init_hw_func(struct bnx2x *bp)
  6338. {
  6339. int port = BP_PORT(bp);
  6340. int func = BP_FUNC(bp);
  6341. int init_phase = PHASE_PF0 + func;
  6342. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6343. u16 cdu_ilt_start;
  6344. u32 addr, val;
  6345. u32 main_mem_base, main_mem_size, main_mem_prty_clr;
  6346. int i, main_mem_width, rc;
  6347. DP(NETIF_MSG_HW, "starting func init func %d\n", func);
  6348. /* FLR cleanup - hmmm */
  6349. if (!CHIP_IS_E1x(bp)) {
  6350. rc = bnx2x_pf_flr_clnup(bp);
  6351. if (rc) {
  6352. bnx2x_fw_dump(bp);
  6353. return rc;
  6354. }
  6355. }
  6356. /* set MSI reconfigure capability */
  6357. if (bp->common.int_block == INT_BLOCK_HC) {
  6358. addr = (port ? HC_REG_CONFIG_1 : HC_REG_CONFIG_0);
  6359. val = REG_RD(bp, addr);
  6360. val |= HC_CONFIG_0_REG_MSI_ATTN_EN_0;
  6361. REG_WR(bp, addr, val);
  6362. }
  6363. bnx2x_init_block(bp, BLOCK_PXP, init_phase);
  6364. bnx2x_init_block(bp, BLOCK_PXP2, init_phase);
  6365. ilt = BP_ILT(bp);
  6366. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6367. if (IS_SRIOV(bp))
  6368. cdu_ilt_start += BNX2X_FIRST_VF_CID/ILT_PAGE_CIDS;
  6369. cdu_ilt_start = bnx2x_iov_init_ilt(bp, cdu_ilt_start);
  6370. /* since BNX2X_FIRST_VF_CID > 0 the PF L2 cids precedes
  6371. * those of the VFs, so start line should be reset
  6372. */
  6373. cdu_ilt_start = ilt->clients[ILT_CLIENT_CDU].start;
  6374. for (i = 0; i < L2_ILT_LINES(bp); i++) {
  6375. ilt->lines[cdu_ilt_start + i].page = bp->context[i].vcxt;
  6376. ilt->lines[cdu_ilt_start + i].page_mapping =
  6377. bp->context[i].cxt_mapping;
  6378. ilt->lines[cdu_ilt_start + i].size = bp->context[i].size;
  6379. }
  6380. bnx2x_ilt_init_op(bp, INITOP_SET);
  6381. if (!CONFIGURE_NIC_MODE(bp)) {
  6382. bnx2x_init_searcher(bp);
  6383. REG_WR(bp, PRS_REG_NIC_MODE, 0);
  6384. DP(NETIF_MSG_IFUP, "NIC MODE disabled\n");
  6385. } else {
  6386. /* Set NIC mode */
  6387. REG_WR(bp, PRS_REG_NIC_MODE, 1);
  6388. DP(NETIF_MSG_IFUP, "NIC MODE configured\n");
  6389. }
  6390. if (!CHIP_IS_E1x(bp)) {
  6391. u32 pf_conf = IGU_PF_CONF_FUNC_EN;
  6392. /* Turn on a single ISR mode in IGU if driver is going to use
  6393. * INT#x or MSI
  6394. */
  6395. if (!(bp->flags & USING_MSIX_FLAG))
  6396. pf_conf |= IGU_PF_CONF_SINGLE_ISR_EN;
  6397. /*
  6398. * Timers workaround bug: function init part.
  6399. * Need to wait 20msec after initializing ILT,
  6400. * needed to make sure there are no requests in
  6401. * one of the PXP internal queues with "old" ILT addresses
  6402. */
  6403. msleep(20);
  6404. /*
  6405. * Master enable - Due to WB DMAE writes performed before this
  6406. * register is re-initialized as part of the regular function
  6407. * init
  6408. */
  6409. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 1);
  6410. /* Enable the function in IGU */
  6411. REG_WR(bp, IGU_REG_PF_CONFIGURATION, pf_conf);
  6412. }
  6413. bp->dmae_ready = 1;
  6414. bnx2x_init_block(bp, BLOCK_PGLUE_B, init_phase);
  6415. if (!CHIP_IS_E1x(bp))
  6416. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR, func);
  6417. bnx2x_init_block(bp, BLOCK_ATC, init_phase);
  6418. bnx2x_init_block(bp, BLOCK_DMAE, init_phase);
  6419. bnx2x_init_block(bp, BLOCK_NIG, init_phase);
  6420. bnx2x_init_block(bp, BLOCK_SRC, init_phase);
  6421. bnx2x_init_block(bp, BLOCK_MISC, init_phase);
  6422. bnx2x_init_block(bp, BLOCK_TCM, init_phase);
  6423. bnx2x_init_block(bp, BLOCK_UCM, init_phase);
  6424. bnx2x_init_block(bp, BLOCK_CCM, init_phase);
  6425. bnx2x_init_block(bp, BLOCK_XCM, init_phase);
  6426. bnx2x_init_block(bp, BLOCK_TSEM, init_phase);
  6427. bnx2x_init_block(bp, BLOCK_USEM, init_phase);
  6428. bnx2x_init_block(bp, BLOCK_CSEM, init_phase);
  6429. bnx2x_init_block(bp, BLOCK_XSEM, init_phase);
  6430. if (!CHIP_IS_E1x(bp))
  6431. REG_WR(bp, QM_REG_PF_EN, 1);
  6432. if (!CHIP_IS_E1x(bp)) {
  6433. REG_WR(bp, TSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6434. REG_WR(bp, USEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6435. REG_WR(bp, CSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6436. REG_WR(bp, XSEM_REG_VFPF_ERR_NUM, BNX2X_MAX_NUM_OF_VFS + func);
  6437. }
  6438. bnx2x_init_block(bp, BLOCK_QM, init_phase);
  6439. bnx2x_init_block(bp, BLOCK_TM, init_phase);
  6440. bnx2x_init_block(bp, BLOCK_DORQ, init_phase);
  6441. bnx2x_iov_init_dq(bp);
  6442. bnx2x_init_block(bp, BLOCK_BRB1, init_phase);
  6443. bnx2x_init_block(bp, BLOCK_PRS, init_phase);
  6444. bnx2x_init_block(bp, BLOCK_TSDM, init_phase);
  6445. bnx2x_init_block(bp, BLOCK_CSDM, init_phase);
  6446. bnx2x_init_block(bp, BLOCK_USDM, init_phase);
  6447. bnx2x_init_block(bp, BLOCK_XSDM, init_phase);
  6448. bnx2x_init_block(bp, BLOCK_UPB, init_phase);
  6449. bnx2x_init_block(bp, BLOCK_XPB, init_phase);
  6450. bnx2x_init_block(bp, BLOCK_PBF, init_phase);
  6451. if (!CHIP_IS_E1x(bp))
  6452. REG_WR(bp, PBF_REG_DISABLE_PF, 0);
  6453. bnx2x_init_block(bp, BLOCK_CDU, init_phase);
  6454. bnx2x_init_block(bp, BLOCK_CFC, init_phase);
  6455. if (!CHIP_IS_E1x(bp))
  6456. REG_WR(bp, CFC_REG_WEAK_ENABLE_PF, 1);
  6457. if (IS_MF(bp)) {
  6458. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 1);
  6459. REG_WR(bp, NIG_REG_LLH0_FUNC_VLAN_ID + port*8, bp->mf_ov);
  6460. }
  6461. bnx2x_init_block(bp, BLOCK_MISC_AEU, init_phase);
  6462. /* HC init per function */
  6463. if (bp->common.int_block == INT_BLOCK_HC) {
  6464. if (CHIP_IS_E1H(bp)) {
  6465. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6466. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  6467. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  6468. }
  6469. bnx2x_init_block(bp, BLOCK_HC, init_phase);
  6470. } else {
  6471. int num_segs, sb_idx, prod_offset;
  6472. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + func*4, 0);
  6473. if (!CHIP_IS_E1x(bp)) {
  6474. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  6475. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  6476. }
  6477. bnx2x_init_block(bp, BLOCK_IGU, init_phase);
  6478. if (!CHIP_IS_E1x(bp)) {
  6479. int dsb_idx = 0;
  6480. /**
  6481. * Producer memory:
  6482. * E2 mode: address 0-135 match to the mapping memory;
  6483. * 136 - PF0 default prod; 137 - PF1 default prod;
  6484. * 138 - PF2 default prod; 139 - PF3 default prod;
  6485. * 140 - PF0 attn prod; 141 - PF1 attn prod;
  6486. * 142 - PF2 attn prod; 143 - PF3 attn prod;
  6487. * 144-147 reserved.
  6488. *
  6489. * E1.5 mode - In backward compatible mode;
  6490. * for non default SB; each even line in the memory
  6491. * holds the U producer and each odd line hold
  6492. * the C producer. The first 128 producers are for
  6493. * NDSB (PF0 - 0-31; PF1 - 32-63 and so on). The last 20
  6494. * producers are for the DSB for each PF.
  6495. * Each PF has five segments: (the order inside each
  6496. * segment is PF0; PF1; PF2; PF3) - 128-131 U prods;
  6497. * 132-135 C prods; 136-139 X prods; 140-143 T prods;
  6498. * 144-147 attn prods;
  6499. */
  6500. /* non-default-status-blocks */
  6501. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6502. IGU_BC_NDSB_NUM_SEGS : IGU_NORM_NDSB_NUM_SEGS;
  6503. for (sb_idx = 0; sb_idx < bp->igu_sb_cnt; sb_idx++) {
  6504. prod_offset = (bp->igu_base_sb + sb_idx) *
  6505. num_segs;
  6506. for (i = 0; i < num_segs; i++) {
  6507. addr = IGU_REG_PROD_CONS_MEMORY +
  6508. (prod_offset + i) * 4;
  6509. REG_WR(bp, addr, 0);
  6510. }
  6511. /* send consumer update with value 0 */
  6512. bnx2x_ack_sb(bp, bp->igu_base_sb + sb_idx,
  6513. USTORM_ID, 0, IGU_INT_NOP, 1);
  6514. bnx2x_igu_clear_sb(bp,
  6515. bp->igu_base_sb + sb_idx);
  6516. }
  6517. /* default-status-blocks */
  6518. num_segs = CHIP_INT_MODE_IS_BC(bp) ?
  6519. IGU_BC_DSB_NUM_SEGS : IGU_NORM_DSB_NUM_SEGS;
  6520. if (CHIP_MODE_IS_4_PORT(bp))
  6521. dsb_idx = BP_FUNC(bp);
  6522. else
  6523. dsb_idx = BP_VN(bp);
  6524. prod_offset = (CHIP_INT_MODE_IS_BC(bp) ?
  6525. IGU_BC_BASE_DSB_PROD + dsb_idx :
  6526. IGU_NORM_BASE_DSB_PROD + dsb_idx);
  6527. /*
  6528. * igu prods come in chunks of E1HVN_MAX (4) -
  6529. * does not matters what is the current chip mode
  6530. */
  6531. for (i = 0; i < (num_segs * E1HVN_MAX);
  6532. i += E1HVN_MAX) {
  6533. addr = IGU_REG_PROD_CONS_MEMORY +
  6534. (prod_offset + i)*4;
  6535. REG_WR(bp, addr, 0);
  6536. }
  6537. /* send consumer update with 0 */
  6538. if (CHIP_INT_MODE_IS_BC(bp)) {
  6539. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6540. USTORM_ID, 0, IGU_INT_NOP, 1);
  6541. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6542. CSTORM_ID, 0, IGU_INT_NOP, 1);
  6543. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6544. XSTORM_ID, 0, IGU_INT_NOP, 1);
  6545. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6546. TSTORM_ID, 0, IGU_INT_NOP, 1);
  6547. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6548. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6549. } else {
  6550. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6551. USTORM_ID, 0, IGU_INT_NOP, 1);
  6552. bnx2x_ack_sb(bp, bp->igu_dsb_id,
  6553. ATTENTION_ID, 0, IGU_INT_NOP, 1);
  6554. }
  6555. bnx2x_igu_clear_sb(bp, bp->igu_dsb_id);
  6556. /* !!! These should become driver const once
  6557. rf-tool supports split-68 const */
  6558. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_LSB, 0);
  6559. REG_WR(bp, IGU_REG_SB_INT_BEFORE_MASK_MSB, 0);
  6560. REG_WR(bp, IGU_REG_SB_MASK_LSB, 0);
  6561. REG_WR(bp, IGU_REG_SB_MASK_MSB, 0);
  6562. REG_WR(bp, IGU_REG_PBA_STATUS_LSB, 0);
  6563. REG_WR(bp, IGU_REG_PBA_STATUS_MSB, 0);
  6564. }
  6565. }
  6566. /* Reset PCIE errors for debug */
  6567. REG_WR(bp, 0x2114, 0xffffffff);
  6568. REG_WR(bp, 0x2120, 0xffffffff);
  6569. if (CHIP_IS_E1x(bp)) {
  6570. main_mem_size = HC_REG_MAIN_MEMORY_SIZE / 2; /*dwords*/
  6571. main_mem_base = HC_REG_MAIN_MEMORY +
  6572. BP_PORT(bp) * (main_mem_size * 4);
  6573. main_mem_prty_clr = HC_REG_HC_PRTY_STS_CLR;
  6574. main_mem_width = 8;
  6575. val = REG_RD(bp, main_mem_prty_clr);
  6576. if (val)
  6577. DP(NETIF_MSG_HW,
  6578. "Hmmm... Parity errors in HC block during function init (0x%x)!\n",
  6579. val);
  6580. /* Clear "false" parity errors in MSI-X table */
  6581. for (i = main_mem_base;
  6582. i < main_mem_base + main_mem_size * 4;
  6583. i += main_mem_width) {
  6584. bnx2x_read_dmae(bp, i, main_mem_width / 4);
  6585. bnx2x_write_dmae(bp, bnx2x_sp_mapping(bp, wb_data),
  6586. i, main_mem_width / 4);
  6587. }
  6588. /* Clear HC parity attention */
  6589. REG_RD(bp, main_mem_prty_clr);
  6590. }
  6591. #ifdef BNX2X_STOP_ON_ERROR
  6592. /* Enable STORMs SP logging */
  6593. REG_WR8(bp, BAR_USTRORM_INTMEM +
  6594. USTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6595. REG_WR8(bp, BAR_TSTRORM_INTMEM +
  6596. TSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6597. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  6598. CSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6599. REG_WR8(bp, BAR_XSTRORM_INTMEM +
  6600. XSTORM_RECORD_SLOW_PATH_OFFSET(BP_FUNC(bp)), 1);
  6601. #endif
  6602. bnx2x_phy_probe(&bp->link_params);
  6603. return 0;
  6604. }
  6605. void bnx2x_free_mem_cnic(struct bnx2x *bp)
  6606. {
  6607. bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_FREE);
  6608. if (!CHIP_IS_E1x(bp))
  6609. BNX2X_PCI_FREE(bp->cnic_sb.e2_sb, bp->cnic_sb_mapping,
  6610. sizeof(struct host_hc_status_block_e2));
  6611. else
  6612. BNX2X_PCI_FREE(bp->cnic_sb.e1x_sb, bp->cnic_sb_mapping,
  6613. sizeof(struct host_hc_status_block_e1x));
  6614. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6615. }
  6616. void bnx2x_free_mem(struct bnx2x *bp)
  6617. {
  6618. int i;
  6619. BNX2X_PCI_FREE(bp->def_status_blk, bp->def_status_blk_mapping,
  6620. sizeof(struct host_sp_status_block));
  6621. BNX2X_PCI_FREE(bp->fw_stats, bp->fw_stats_mapping,
  6622. bp->fw_stats_data_sz + bp->fw_stats_req_sz);
  6623. BNX2X_PCI_FREE(bp->slowpath, bp->slowpath_mapping,
  6624. sizeof(struct bnx2x_slowpath));
  6625. for (i = 0; i < L2_ILT_LINES(bp); i++)
  6626. BNX2X_PCI_FREE(bp->context[i].vcxt, bp->context[i].cxt_mapping,
  6627. bp->context[i].size);
  6628. bnx2x_ilt_mem_op(bp, ILT_MEMOP_FREE);
  6629. BNX2X_FREE(bp->ilt->lines);
  6630. BNX2X_PCI_FREE(bp->spq, bp->spq_mapping, BCM_PAGE_SIZE);
  6631. BNX2X_PCI_FREE(bp->eq_ring, bp->eq_mapping,
  6632. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6633. BNX2X_PCI_FREE(bp->t2, bp->t2_mapping, SRC_T2_SZ);
  6634. bnx2x_iov_free_mem(bp);
  6635. }
  6636. int bnx2x_alloc_mem_cnic(struct bnx2x *bp)
  6637. {
  6638. if (!CHIP_IS_E1x(bp))
  6639. /* size = the status block + ramrod buffers */
  6640. BNX2X_PCI_ALLOC(bp->cnic_sb.e2_sb, &bp->cnic_sb_mapping,
  6641. sizeof(struct host_hc_status_block_e2));
  6642. else
  6643. BNX2X_PCI_ALLOC(bp->cnic_sb.e1x_sb,
  6644. &bp->cnic_sb_mapping,
  6645. sizeof(struct
  6646. host_hc_status_block_e1x));
  6647. if (CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6648. /* allocate searcher T2 table, as it wasn't allocated before */
  6649. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6650. /* write address to which L5 should insert its values */
  6651. bp->cnic_eth_dev.addr_drv_info_to_mcp =
  6652. &bp->slowpath->drv_info_to_mcp;
  6653. if (bnx2x_ilt_mem_op_cnic(bp, ILT_MEMOP_ALLOC))
  6654. goto alloc_mem_err;
  6655. return 0;
  6656. alloc_mem_err:
  6657. bnx2x_free_mem_cnic(bp);
  6658. BNX2X_ERR("Can't allocate memory\n");
  6659. return -ENOMEM;
  6660. }
  6661. int bnx2x_alloc_mem(struct bnx2x *bp)
  6662. {
  6663. int i, allocated, context_size;
  6664. if (!CONFIGURE_NIC_MODE(bp) && !bp->t2)
  6665. /* allocate searcher T2 table */
  6666. BNX2X_PCI_ALLOC(bp->t2, &bp->t2_mapping, SRC_T2_SZ);
  6667. BNX2X_PCI_ALLOC(bp->def_status_blk, &bp->def_status_blk_mapping,
  6668. sizeof(struct host_sp_status_block));
  6669. BNX2X_PCI_ALLOC(bp->slowpath, &bp->slowpath_mapping,
  6670. sizeof(struct bnx2x_slowpath));
  6671. /* Allocate memory for CDU context:
  6672. * This memory is allocated separately and not in the generic ILT
  6673. * functions because CDU differs in few aspects:
  6674. * 1. There are multiple entities allocating memory for context -
  6675. * 'regular' driver, CNIC and SRIOV driver. Each separately controls
  6676. * its own ILT lines.
  6677. * 2. Since CDU page-size is not a single 4KB page (which is the case
  6678. * for the other ILT clients), to be efficient we want to support
  6679. * allocation of sub-page-size in the last entry.
  6680. * 3. Context pointers are used by the driver to pass to FW / update
  6681. * the context (for the other ILT clients the pointers are used just to
  6682. * free the memory during unload).
  6683. */
  6684. context_size = sizeof(union cdu_context) * BNX2X_L2_CID_COUNT(bp);
  6685. for (i = 0, allocated = 0; allocated < context_size; i++) {
  6686. bp->context[i].size = min(CDU_ILT_PAGE_SZ,
  6687. (context_size - allocated));
  6688. BNX2X_PCI_ALLOC(bp->context[i].vcxt,
  6689. &bp->context[i].cxt_mapping,
  6690. bp->context[i].size);
  6691. allocated += bp->context[i].size;
  6692. }
  6693. BNX2X_ALLOC(bp->ilt->lines, sizeof(struct ilt_line) * ILT_MAX_LINES);
  6694. if (bnx2x_ilt_mem_op(bp, ILT_MEMOP_ALLOC))
  6695. goto alloc_mem_err;
  6696. if (bnx2x_iov_alloc_mem(bp))
  6697. goto alloc_mem_err;
  6698. /* Slow path ring */
  6699. BNX2X_PCI_ALLOC(bp->spq, &bp->spq_mapping, BCM_PAGE_SIZE);
  6700. /* EQ */
  6701. BNX2X_PCI_ALLOC(bp->eq_ring, &bp->eq_mapping,
  6702. BCM_PAGE_SIZE * NUM_EQ_PAGES);
  6703. return 0;
  6704. alloc_mem_err:
  6705. bnx2x_free_mem(bp);
  6706. BNX2X_ERR("Can't allocate memory\n");
  6707. return -ENOMEM;
  6708. }
  6709. /*
  6710. * Init service functions
  6711. */
  6712. int bnx2x_set_mac_one(struct bnx2x *bp, u8 *mac,
  6713. struct bnx2x_vlan_mac_obj *obj, bool set,
  6714. int mac_type, unsigned long *ramrod_flags)
  6715. {
  6716. int rc;
  6717. struct bnx2x_vlan_mac_ramrod_params ramrod_param;
  6718. memset(&ramrod_param, 0, sizeof(ramrod_param));
  6719. /* Fill general parameters */
  6720. ramrod_param.vlan_mac_obj = obj;
  6721. ramrod_param.ramrod_flags = *ramrod_flags;
  6722. /* Fill a user request section if needed */
  6723. if (!test_bit(RAMROD_CONT, ramrod_flags)) {
  6724. memcpy(ramrod_param.user_req.u.mac.mac, mac, ETH_ALEN);
  6725. __set_bit(mac_type, &ramrod_param.user_req.vlan_mac_flags);
  6726. /* Set the command: ADD or DEL */
  6727. if (set)
  6728. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_ADD;
  6729. else
  6730. ramrod_param.user_req.cmd = BNX2X_VLAN_MAC_DEL;
  6731. }
  6732. rc = bnx2x_config_vlan_mac(bp, &ramrod_param);
  6733. if (rc == -EEXIST) {
  6734. DP(BNX2X_MSG_SP, "Failed to schedule ADD operations: %d\n", rc);
  6735. /* do not treat adding same MAC as error */
  6736. rc = 0;
  6737. } else if (rc < 0)
  6738. BNX2X_ERR("%s MAC failed\n", (set ? "Set" : "Del"));
  6739. return rc;
  6740. }
  6741. int bnx2x_del_all_macs(struct bnx2x *bp,
  6742. struct bnx2x_vlan_mac_obj *mac_obj,
  6743. int mac_type, bool wait_for_comp)
  6744. {
  6745. int rc;
  6746. unsigned long ramrod_flags = 0, vlan_mac_flags = 0;
  6747. /* Wait for completion of requested */
  6748. if (wait_for_comp)
  6749. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6750. /* Set the mac type of addresses we want to clear */
  6751. __set_bit(mac_type, &vlan_mac_flags);
  6752. rc = mac_obj->delete_all(bp, mac_obj, &vlan_mac_flags, &ramrod_flags);
  6753. if (rc < 0)
  6754. BNX2X_ERR("Failed to delete MACs: %d\n", rc);
  6755. return rc;
  6756. }
  6757. int bnx2x_set_eth_mac(struct bnx2x *bp, bool set)
  6758. {
  6759. if (is_zero_ether_addr(bp->dev->dev_addr) &&
  6760. (IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp))) {
  6761. DP(NETIF_MSG_IFUP | NETIF_MSG_IFDOWN,
  6762. "Ignoring Zero MAC for STORAGE SD mode\n");
  6763. return 0;
  6764. }
  6765. if (IS_PF(bp)) {
  6766. unsigned long ramrod_flags = 0;
  6767. DP(NETIF_MSG_IFUP, "Adding Eth MAC\n");
  6768. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  6769. return bnx2x_set_mac_one(bp, bp->dev->dev_addr,
  6770. &bp->sp_objs->mac_obj, set,
  6771. BNX2X_ETH_MAC, &ramrod_flags);
  6772. } else { /* vf */
  6773. return bnx2x_vfpf_config_mac(bp, bp->dev->dev_addr,
  6774. bp->fp->index, true);
  6775. }
  6776. }
  6777. int bnx2x_setup_leading(struct bnx2x *bp)
  6778. {
  6779. return bnx2x_setup_queue(bp, &bp->fp[0], 1);
  6780. }
  6781. /**
  6782. * bnx2x_set_int_mode - configure interrupt mode
  6783. *
  6784. * @bp: driver handle
  6785. *
  6786. * In case of MSI-X it will also try to enable MSI-X.
  6787. */
  6788. int bnx2x_set_int_mode(struct bnx2x *bp)
  6789. {
  6790. int rc = 0;
  6791. if (IS_VF(bp) && int_mode != BNX2X_INT_MODE_MSIX)
  6792. return -EINVAL;
  6793. switch (int_mode) {
  6794. case BNX2X_INT_MODE_MSIX:
  6795. /* attempt to enable msix */
  6796. rc = bnx2x_enable_msix(bp);
  6797. /* msix attained */
  6798. if (!rc)
  6799. return 0;
  6800. /* vfs use only msix */
  6801. if (rc && IS_VF(bp))
  6802. return rc;
  6803. /* failed to enable multiple MSI-X */
  6804. BNX2X_DEV_INFO("Failed to enable multiple MSI-X (%d), set number of queues to %d\n",
  6805. bp->num_queues,
  6806. 1 + bp->num_cnic_queues);
  6807. /* falling through... */
  6808. case BNX2X_INT_MODE_MSI:
  6809. bnx2x_enable_msi(bp);
  6810. /* falling through... */
  6811. case BNX2X_INT_MODE_INTX:
  6812. bp->num_ethernet_queues = 1;
  6813. bp->num_queues = bp->num_ethernet_queues + bp->num_cnic_queues;
  6814. BNX2X_DEV_INFO("set number of queues to 1\n");
  6815. break;
  6816. default:
  6817. BNX2X_DEV_INFO("unknown value in int_mode module parameter\n");
  6818. return -EINVAL;
  6819. }
  6820. return 0;
  6821. }
  6822. /* must be called prior to any HW initializations */
  6823. static inline u16 bnx2x_cid_ilt_lines(struct bnx2x *bp)
  6824. {
  6825. if (IS_SRIOV(bp))
  6826. return (BNX2X_FIRST_VF_CID + BNX2X_VF_CIDS)/ILT_PAGE_CIDS;
  6827. return L2_ILT_LINES(bp);
  6828. }
  6829. void bnx2x_ilt_set_info(struct bnx2x *bp)
  6830. {
  6831. struct ilt_client_info *ilt_client;
  6832. struct bnx2x_ilt *ilt = BP_ILT(bp);
  6833. u16 line = 0;
  6834. ilt->start_line = FUNC_ILT_BASE(BP_FUNC(bp));
  6835. DP(BNX2X_MSG_SP, "ilt starts at line %d\n", ilt->start_line);
  6836. /* CDU */
  6837. ilt_client = &ilt->clients[ILT_CLIENT_CDU];
  6838. ilt_client->client_num = ILT_CLIENT_CDU;
  6839. ilt_client->page_size = CDU_ILT_PAGE_SZ;
  6840. ilt_client->flags = ILT_CLIENT_SKIP_MEM;
  6841. ilt_client->start = line;
  6842. line += bnx2x_cid_ilt_lines(bp);
  6843. if (CNIC_SUPPORT(bp))
  6844. line += CNIC_ILT_LINES;
  6845. ilt_client->end = line - 1;
  6846. DP(NETIF_MSG_IFUP, "ilt client[CDU]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6847. ilt_client->start,
  6848. ilt_client->end,
  6849. ilt_client->page_size,
  6850. ilt_client->flags,
  6851. ilog2(ilt_client->page_size >> 12));
  6852. /* QM */
  6853. if (QM_INIT(bp->qm_cid_count)) {
  6854. ilt_client = &ilt->clients[ILT_CLIENT_QM];
  6855. ilt_client->client_num = ILT_CLIENT_QM;
  6856. ilt_client->page_size = QM_ILT_PAGE_SZ;
  6857. ilt_client->flags = 0;
  6858. ilt_client->start = line;
  6859. /* 4 bytes for each cid */
  6860. line += DIV_ROUND_UP(bp->qm_cid_count * QM_QUEUES_PER_FUNC * 4,
  6861. QM_ILT_PAGE_SZ);
  6862. ilt_client->end = line - 1;
  6863. DP(NETIF_MSG_IFUP,
  6864. "ilt client[QM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6865. ilt_client->start,
  6866. ilt_client->end,
  6867. ilt_client->page_size,
  6868. ilt_client->flags,
  6869. ilog2(ilt_client->page_size >> 12));
  6870. }
  6871. if (CNIC_SUPPORT(bp)) {
  6872. /* SRC */
  6873. ilt_client = &ilt->clients[ILT_CLIENT_SRC];
  6874. ilt_client->client_num = ILT_CLIENT_SRC;
  6875. ilt_client->page_size = SRC_ILT_PAGE_SZ;
  6876. ilt_client->flags = 0;
  6877. ilt_client->start = line;
  6878. line += SRC_ILT_LINES;
  6879. ilt_client->end = line - 1;
  6880. DP(NETIF_MSG_IFUP,
  6881. "ilt client[SRC]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6882. ilt_client->start,
  6883. ilt_client->end,
  6884. ilt_client->page_size,
  6885. ilt_client->flags,
  6886. ilog2(ilt_client->page_size >> 12));
  6887. /* TM */
  6888. ilt_client = &ilt->clients[ILT_CLIENT_TM];
  6889. ilt_client->client_num = ILT_CLIENT_TM;
  6890. ilt_client->page_size = TM_ILT_PAGE_SZ;
  6891. ilt_client->flags = 0;
  6892. ilt_client->start = line;
  6893. line += TM_ILT_LINES;
  6894. ilt_client->end = line - 1;
  6895. DP(NETIF_MSG_IFUP,
  6896. "ilt client[TM]: start %d, end %d, psz 0x%x, flags 0x%x, hw psz %d\n",
  6897. ilt_client->start,
  6898. ilt_client->end,
  6899. ilt_client->page_size,
  6900. ilt_client->flags,
  6901. ilog2(ilt_client->page_size >> 12));
  6902. }
  6903. BUG_ON(line > ILT_MAX_LINES);
  6904. }
  6905. /**
  6906. * bnx2x_pf_q_prep_init - prepare INIT transition parameters
  6907. *
  6908. * @bp: driver handle
  6909. * @fp: pointer to fastpath
  6910. * @init_params: pointer to parameters structure
  6911. *
  6912. * parameters configured:
  6913. * - HC configuration
  6914. * - Queue's CDU context
  6915. */
  6916. static void bnx2x_pf_q_prep_init(struct bnx2x *bp,
  6917. struct bnx2x_fastpath *fp, struct bnx2x_queue_init_params *init_params)
  6918. {
  6919. u8 cos;
  6920. int cxt_index, cxt_offset;
  6921. /* FCoE Queue uses Default SB, thus has no HC capabilities */
  6922. if (!IS_FCOE_FP(fp)) {
  6923. __set_bit(BNX2X_Q_FLG_HC, &init_params->rx.flags);
  6924. __set_bit(BNX2X_Q_FLG_HC, &init_params->tx.flags);
  6925. /* If HC is supported, enable host coalescing in the transition
  6926. * to INIT state.
  6927. */
  6928. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->rx.flags);
  6929. __set_bit(BNX2X_Q_FLG_HC_EN, &init_params->tx.flags);
  6930. /* HC rate */
  6931. init_params->rx.hc_rate = bp->rx_ticks ?
  6932. (1000000 / bp->rx_ticks) : 0;
  6933. init_params->tx.hc_rate = bp->tx_ticks ?
  6934. (1000000 / bp->tx_ticks) : 0;
  6935. /* FW SB ID */
  6936. init_params->rx.fw_sb_id = init_params->tx.fw_sb_id =
  6937. fp->fw_sb_id;
  6938. /*
  6939. * CQ index among the SB indices: FCoE clients uses the default
  6940. * SB, therefore it's different.
  6941. */
  6942. init_params->rx.sb_cq_index = HC_INDEX_ETH_RX_CQ_CONS;
  6943. init_params->tx.sb_cq_index = HC_INDEX_ETH_FIRST_TX_CQ_CONS;
  6944. }
  6945. /* set maximum number of COSs supported by this queue */
  6946. init_params->max_cos = fp->max_cos;
  6947. DP(NETIF_MSG_IFUP, "fp: %d setting queue params max cos to: %d\n",
  6948. fp->index, init_params->max_cos);
  6949. /* set the context pointers queue object */
  6950. for (cos = FIRST_TX_COS_INDEX; cos < init_params->max_cos; cos++) {
  6951. cxt_index = fp->txdata_ptr[cos]->cid / ILT_PAGE_CIDS;
  6952. cxt_offset = fp->txdata_ptr[cos]->cid - (cxt_index *
  6953. ILT_PAGE_CIDS);
  6954. init_params->cxts[cos] =
  6955. &bp->context[cxt_index].vcxt[cxt_offset].eth;
  6956. }
  6957. }
  6958. static int bnx2x_setup_tx_only(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6959. struct bnx2x_queue_state_params *q_params,
  6960. struct bnx2x_queue_setup_tx_only_params *tx_only_params,
  6961. int tx_index, bool leading)
  6962. {
  6963. memset(tx_only_params, 0, sizeof(*tx_only_params));
  6964. /* Set the command */
  6965. q_params->cmd = BNX2X_Q_CMD_SETUP_TX_ONLY;
  6966. /* Set tx-only QUEUE flags: don't zero statistics */
  6967. tx_only_params->flags = bnx2x_get_common_flags(bp, fp, false);
  6968. /* choose the index of the cid to send the slow path on */
  6969. tx_only_params->cid_index = tx_index;
  6970. /* Set general TX_ONLY_SETUP parameters */
  6971. bnx2x_pf_q_prep_general(bp, fp, &tx_only_params->gen_params, tx_index);
  6972. /* Set Tx TX_ONLY_SETUP parameters */
  6973. bnx2x_pf_tx_q_prep(bp, fp, &tx_only_params->txq_params, tx_index);
  6974. DP(NETIF_MSG_IFUP,
  6975. "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",
  6976. tx_index, q_params->q_obj->cids[FIRST_TX_COS_INDEX],
  6977. q_params->q_obj->cids[tx_index], q_params->q_obj->cl_id,
  6978. tx_only_params->gen_params.spcl_id, tx_only_params->flags);
  6979. /* send the ramrod */
  6980. return bnx2x_queue_state_change(bp, q_params);
  6981. }
  6982. /**
  6983. * bnx2x_setup_queue - setup queue
  6984. *
  6985. * @bp: driver handle
  6986. * @fp: pointer to fastpath
  6987. * @leading: is leading
  6988. *
  6989. * This function performs 2 steps in a Queue state machine
  6990. * actually: 1) RESET->INIT 2) INIT->SETUP
  6991. */
  6992. int bnx2x_setup_queue(struct bnx2x *bp, struct bnx2x_fastpath *fp,
  6993. bool leading)
  6994. {
  6995. struct bnx2x_queue_state_params q_params = {NULL};
  6996. struct bnx2x_queue_setup_params *setup_params =
  6997. &q_params.params.setup;
  6998. struct bnx2x_queue_setup_tx_only_params *tx_only_params =
  6999. &q_params.params.tx_only;
  7000. int rc;
  7001. u8 tx_index;
  7002. DP(NETIF_MSG_IFUP, "setting up queue %d\n", fp->index);
  7003. /* reset IGU state skip FCoE L2 queue */
  7004. if (!IS_FCOE_FP(fp))
  7005. bnx2x_ack_sb(bp, fp->igu_sb_id, USTORM_ID, 0,
  7006. IGU_INT_ENABLE, 0);
  7007. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7008. /* We want to wait for completion in this context */
  7009. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7010. /* Prepare the INIT parameters */
  7011. bnx2x_pf_q_prep_init(bp, fp, &q_params.params.init);
  7012. /* Set the command */
  7013. q_params.cmd = BNX2X_Q_CMD_INIT;
  7014. /* Change the state to INIT */
  7015. rc = bnx2x_queue_state_change(bp, &q_params);
  7016. if (rc) {
  7017. BNX2X_ERR("Queue(%d) INIT failed\n", fp->index);
  7018. return rc;
  7019. }
  7020. DP(NETIF_MSG_IFUP, "init complete\n");
  7021. /* Now move the Queue to the SETUP state... */
  7022. memset(setup_params, 0, sizeof(*setup_params));
  7023. /* Set QUEUE flags */
  7024. setup_params->flags = bnx2x_get_q_flags(bp, fp, leading);
  7025. /* Set general SETUP parameters */
  7026. bnx2x_pf_q_prep_general(bp, fp, &setup_params->gen_params,
  7027. FIRST_TX_COS_INDEX);
  7028. bnx2x_pf_rx_q_prep(bp, fp, &setup_params->pause_params,
  7029. &setup_params->rxq_params);
  7030. bnx2x_pf_tx_q_prep(bp, fp, &setup_params->txq_params,
  7031. FIRST_TX_COS_INDEX);
  7032. /* Set the command */
  7033. q_params.cmd = BNX2X_Q_CMD_SETUP;
  7034. if (IS_FCOE_FP(fp))
  7035. bp->fcoe_init = true;
  7036. /* Change the state to SETUP */
  7037. rc = bnx2x_queue_state_change(bp, &q_params);
  7038. if (rc) {
  7039. BNX2X_ERR("Queue(%d) SETUP failed\n", fp->index);
  7040. return rc;
  7041. }
  7042. /* loop through the relevant tx-only indices */
  7043. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7044. tx_index < fp->max_cos;
  7045. tx_index++) {
  7046. /* prepare and send tx-only ramrod*/
  7047. rc = bnx2x_setup_tx_only(bp, fp, &q_params,
  7048. tx_only_params, tx_index, leading);
  7049. if (rc) {
  7050. BNX2X_ERR("Queue(%d.%d) TX_ONLY_SETUP failed\n",
  7051. fp->index, tx_index);
  7052. return rc;
  7053. }
  7054. }
  7055. return rc;
  7056. }
  7057. static int bnx2x_stop_queue(struct bnx2x *bp, int index)
  7058. {
  7059. struct bnx2x_fastpath *fp = &bp->fp[index];
  7060. struct bnx2x_fp_txdata *txdata;
  7061. struct bnx2x_queue_state_params q_params = {NULL};
  7062. int rc, tx_index;
  7063. DP(NETIF_MSG_IFDOWN, "stopping queue %d cid %d\n", index, fp->cid);
  7064. q_params.q_obj = &bnx2x_sp_obj(bp, fp).q_obj;
  7065. /* We want to wait for completion in this context */
  7066. __set_bit(RAMROD_COMP_WAIT, &q_params.ramrod_flags);
  7067. /* close tx-only connections */
  7068. for (tx_index = FIRST_TX_ONLY_COS_INDEX;
  7069. tx_index < fp->max_cos;
  7070. tx_index++){
  7071. /* ascertain this is a normal queue*/
  7072. txdata = fp->txdata_ptr[tx_index];
  7073. DP(NETIF_MSG_IFDOWN, "stopping tx-only queue %d\n",
  7074. txdata->txq_index);
  7075. /* send halt terminate on tx-only connection */
  7076. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7077. memset(&q_params.params.terminate, 0,
  7078. sizeof(q_params.params.terminate));
  7079. q_params.params.terminate.cid_index = tx_index;
  7080. rc = bnx2x_queue_state_change(bp, &q_params);
  7081. if (rc)
  7082. return rc;
  7083. /* send halt terminate on tx-only connection */
  7084. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7085. memset(&q_params.params.cfc_del, 0,
  7086. sizeof(q_params.params.cfc_del));
  7087. q_params.params.cfc_del.cid_index = tx_index;
  7088. rc = bnx2x_queue_state_change(bp, &q_params);
  7089. if (rc)
  7090. return rc;
  7091. }
  7092. /* Stop the primary connection: */
  7093. /* ...halt the connection */
  7094. q_params.cmd = BNX2X_Q_CMD_HALT;
  7095. rc = bnx2x_queue_state_change(bp, &q_params);
  7096. if (rc)
  7097. return rc;
  7098. /* ...terminate the connection */
  7099. q_params.cmd = BNX2X_Q_CMD_TERMINATE;
  7100. memset(&q_params.params.terminate, 0,
  7101. sizeof(q_params.params.terminate));
  7102. q_params.params.terminate.cid_index = FIRST_TX_COS_INDEX;
  7103. rc = bnx2x_queue_state_change(bp, &q_params);
  7104. if (rc)
  7105. return rc;
  7106. /* ...delete cfc entry */
  7107. q_params.cmd = BNX2X_Q_CMD_CFC_DEL;
  7108. memset(&q_params.params.cfc_del, 0,
  7109. sizeof(q_params.params.cfc_del));
  7110. q_params.params.cfc_del.cid_index = FIRST_TX_COS_INDEX;
  7111. return bnx2x_queue_state_change(bp, &q_params);
  7112. }
  7113. static void bnx2x_reset_func(struct bnx2x *bp)
  7114. {
  7115. int port = BP_PORT(bp);
  7116. int func = BP_FUNC(bp);
  7117. int i;
  7118. /* Disable the function in the FW */
  7119. REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(func), 0);
  7120. REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(func), 0);
  7121. REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(func), 0);
  7122. REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(func), 0);
  7123. /* FP SBs */
  7124. for_each_eth_queue(bp, i) {
  7125. struct bnx2x_fastpath *fp = &bp->fp[i];
  7126. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7127. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET(fp->fw_sb_id),
  7128. SB_DISABLED);
  7129. }
  7130. if (CNIC_LOADED(bp))
  7131. /* CNIC SB */
  7132. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7133. CSTORM_STATUS_BLOCK_DATA_STATE_OFFSET
  7134. (bnx2x_cnic_fw_sb_id(bp)), SB_DISABLED);
  7135. /* SP SB */
  7136. REG_WR8(bp, BAR_CSTRORM_INTMEM +
  7137. CSTORM_SP_STATUS_BLOCK_DATA_STATE_OFFSET(func),
  7138. SB_DISABLED);
  7139. for (i = 0; i < XSTORM_SPQ_DATA_SIZE / 4; i++)
  7140. REG_WR(bp, BAR_XSTRORM_INTMEM + XSTORM_SPQ_DATA_OFFSET(func),
  7141. 0);
  7142. /* Configure IGU */
  7143. if (bp->common.int_block == INT_BLOCK_HC) {
  7144. REG_WR(bp, HC_REG_LEADING_EDGE_0 + port*8, 0);
  7145. REG_WR(bp, HC_REG_TRAILING_EDGE_0 + port*8, 0);
  7146. } else {
  7147. REG_WR(bp, IGU_REG_LEADING_EDGE_LATCH, 0);
  7148. REG_WR(bp, IGU_REG_TRAILING_EDGE_LATCH, 0);
  7149. }
  7150. if (CNIC_LOADED(bp)) {
  7151. /* Disable Timer scan */
  7152. REG_WR(bp, TM_REG_EN_LINEAR0_TIMER + port*4, 0);
  7153. /*
  7154. * Wait for at least 10ms and up to 2 second for the timers
  7155. * scan to complete
  7156. */
  7157. for (i = 0; i < 200; i++) {
  7158. usleep_range(10000, 20000);
  7159. if (!REG_RD(bp, TM_REG_LIN0_SCAN_ON + port*4))
  7160. break;
  7161. }
  7162. }
  7163. /* Clear ILT */
  7164. bnx2x_clear_func_ilt(bp, func);
  7165. /* Timers workaround bug for E2: if this is vnic-3,
  7166. * we need to set the entire ilt range for this timers.
  7167. */
  7168. if (!CHIP_IS_E1x(bp) && BP_VN(bp) == 3) {
  7169. struct ilt_client_info ilt_cli;
  7170. /* use dummy TM client */
  7171. memset(&ilt_cli, 0, sizeof(struct ilt_client_info));
  7172. ilt_cli.start = 0;
  7173. ilt_cli.end = ILT_NUM_PAGE_ENTRIES - 1;
  7174. ilt_cli.client_num = ILT_CLIENT_TM;
  7175. bnx2x_ilt_boundry_init_op(bp, &ilt_cli, 0, INITOP_CLEAR);
  7176. }
  7177. /* this assumes that reset_port() called before reset_func()*/
  7178. if (!CHIP_IS_E1x(bp))
  7179. bnx2x_pf_disable(bp);
  7180. bp->dmae_ready = 0;
  7181. }
  7182. static void bnx2x_reset_port(struct bnx2x *bp)
  7183. {
  7184. int port = BP_PORT(bp);
  7185. u32 val;
  7186. /* Reset physical Link */
  7187. bnx2x__link_reset(bp);
  7188. REG_WR(bp, NIG_REG_MASK_INTERRUPT_PORT0 + port*4, 0);
  7189. /* Do not rcv packets to BRB */
  7190. REG_WR(bp, NIG_REG_LLH0_BRB1_DRV_MASK + port*4, 0x0);
  7191. /* Do not direct rcv packets that are not for MCP to the BRB */
  7192. REG_WR(bp, (port ? NIG_REG_LLH1_BRB1_NOT_MCP :
  7193. NIG_REG_LLH0_BRB1_NOT_MCP), 0x0);
  7194. /* Configure AEU */
  7195. REG_WR(bp, MISC_REG_AEU_MASK_ATTN_FUNC_0 + port*4, 0);
  7196. msleep(100);
  7197. /* Check for BRB port occupancy */
  7198. val = REG_RD(bp, BRB1_REG_PORT_NUM_OCC_BLOCKS_0 + port*4);
  7199. if (val)
  7200. DP(NETIF_MSG_IFDOWN,
  7201. "BRB1 is not empty %d blocks are occupied\n", val);
  7202. /* TODO: Close Doorbell port? */
  7203. }
  7204. static int bnx2x_reset_hw(struct bnx2x *bp, u32 load_code)
  7205. {
  7206. struct bnx2x_func_state_params func_params = {NULL};
  7207. /* Prepare parameters for function state transitions */
  7208. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7209. func_params.f_obj = &bp->func_obj;
  7210. func_params.cmd = BNX2X_F_CMD_HW_RESET;
  7211. func_params.params.hw_init.load_phase = load_code;
  7212. return bnx2x_func_state_change(bp, &func_params);
  7213. }
  7214. static int bnx2x_func_stop(struct bnx2x *bp)
  7215. {
  7216. struct bnx2x_func_state_params func_params = {NULL};
  7217. int rc;
  7218. /* Prepare parameters for function state transitions */
  7219. __set_bit(RAMROD_COMP_WAIT, &func_params.ramrod_flags);
  7220. func_params.f_obj = &bp->func_obj;
  7221. func_params.cmd = BNX2X_F_CMD_STOP;
  7222. /*
  7223. * Try to stop the function the 'good way'. If fails (in case
  7224. * of a parity error during bnx2x_chip_cleanup()) and we are
  7225. * not in a debug mode, perform a state transaction in order to
  7226. * enable further HW_RESET transaction.
  7227. */
  7228. rc = bnx2x_func_state_change(bp, &func_params);
  7229. if (rc) {
  7230. #ifdef BNX2X_STOP_ON_ERROR
  7231. return rc;
  7232. #else
  7233. BNX2X_ERR("FUNC_STOP ramrod failed. Running a dry transaction\n");
  7234. __set_bit(RAMROD_DRV_CLR_ONLY, &func_params.ramrod_flags);
  7235. return bnx2x_func_state_change(bp, &func_params);
  7236. #endif
  7237. }
  7238. return 0;
  7239. }
  7240. /**
  7241. * bnx2x_send_unload_req - request unload mode from the MCP.
  7242. *
  7243. * @bp: driver handle
  7244. * @unload_mode: requested function's unload mode
  7245. *
  7246. * Return unload mode returned by the MCP: COMMON, PORT or FUNC.
  7247. */
  7248. u32 bnx2x_send_unload_req(struct bnx2x *bp, int unload_mode)
  7249. {
  7250. u32 reset_code = 0;
  7251. int port = BP_PORT(bp);
  7252. /* Select the UNLOAD request mode */
  7253. if (unload_mode == UNLOAD_NORMAL)
  7254. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7255. else if (bp->flags & NO_WOL_FLAG)
  7256. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP;
  7257. else if (bp->wol) {
  7258. u32 emac_base = port ? GRCBASE_EMAC1 : GRCBASE_EMAC0;
  7259. u8 *mac_addr = bp->dev->dev_addr;
  7260. u32 val;
  7261. u16 pmc;
  7262. /* The mac address is written to entries 1-4 to
  7263. * preserve entry 0 which is used by the PMF
  7264. */
  7265. u8 entry = (BP_VN(bp) + 1)*8;
  7266. val = (mac_addr[0] << 8) | mac_addr[1];
  7267. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry, val);
  7268. val = (mac_addr[2] << 24) | (mac_addr[3] << 16) |
  7269. (mac_addr[4] << 8) | mac_addr[5];
  7270. EMAC_WR(bp, EMAC_REG_EMAC_MAC_MATCH + entry + 4, val);
  7271. /* Enable the PME and clear the status */
  7272. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, &pmc);
  7273. pmc |= PCI_PM_CTRL_PME_ENABLE | PCI_PM_CTRL_PME_STATUS;
  7274. pci_write_config_word(bp->pdev, bp->pm_cap + PCI_PM_CTRL, pmc);
  7275. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_EN;
  7276. } else
  7277. reset_code = DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS;
  7278. /* Send the request to the MCP */
  7279. if (!BP_NOMCP(bp))
  7280. reset_code = bnx2x_fw_command(bp, reset_code, 0);
  7281. else {
  7282. int path = BP_PATH(bp);
  7283. DP(NETIF_MSG_IFDOWN, "NO MCP - load counts[%d] %d, %d, %d\n",
  7284. path, load_count[path][0], load_count[path][1],
  7285. load_count[path][2]);
  7286. load_count[path][0]--;
  7287. load_count[path][1 + port]--;
  7288. DP(NETIF_MSG_IFDOWN, "NO MCP - new load counts[%d] %d, %d, %d\n",
  7289. path, load_count[path][0], load_count[path][1],
  7290. load_count[path][2]);
  7291. if (load_count[path][0] == 0)
  7292. reset_code = FW_MSG_CODE_DRV_UNLOAD_COMMON;
  7293. else if (load_count[path][1 + port] == 0)
  7294. reset_code = FW_MSG_CODE_DRV_UNLOAD_PORT;
  7295. else
  7296. reset_code = FW_MSG_CODE_DRV_UNLOAD_FUNCTION;
  7297. }
  7298. return reset_code;
  7299. }
  7300. /**
  7301. * bnx2x_send_unload_done - send UNLOAD_DONE command to the MCP.
  7302. *
  7303. * @bp: driver handle
  7304. * @keep_link: true iff link should be kept up
  7305. */
  7306. void bnx2x_send_unload_done(struct bnx2x *bp, bool keep_link)
  7307. {
  7308. u32 reset_param = keep_link ? DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET : 0;
  7309. /* Report UNLOAD_DONE to MCP */
  7310. if (!BP_NOMCP(bp))
  7311. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, reset_param);
  7312. }
  7313. static int bnx2x_func_wait_started(struct bnx2x *bp)
  7314. {
  7315. int tout = 50;
  7316. int msix = (bp->flags & USING_MSIX_FLAG) ? 1 : 0;
  7317. if (!bp->port.pmf)
  7318. return 0;
  7319. /*
  7320. * (assumption: No Attention from MCP at this stage)
  7321. * PMF probably in the middle of TX disable/enable transaction
  7322. * 1. Sync IRS for default SB
  7323. * 2. Sync SP queue - this guarantees us that attention handling started
  7324. * 3. Wait, that TX disable/enable transaction completes
  7325. *
  7326. * 1+2 guarantee that if DCBx attention was scheduled it already changed
  7327. * pending bit of transaction from STARTED-->TX_STOPPED, if we already
  7328. * received completion for the transaction the state is TX_STOPPED.
  7329. * State will return to STARTED after completion of TX_STOPPED-->STARTED
  7330. * transaction.
  7331. */
  7332. /* make sure default SB ISR is done */
  7333. if (msix)
  7334. synchronize_irq(bp->msix_table[0].vector);
  7335. else
  7336. synchronize_irq(bp->pdev->irq);
  7337. flush_workqueue(bnx2x_wq);
  7338. while (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7339. BNX2X_F_STATE_STARTED && tout--)
  7340. msleep(20);
  7341. if (bnx2x_func_get_state(bp, &bp->func_obj) !=
  7342. BNX2X_F_STATE_STARTED) {
  7343. #ifdef BNX2X_STOP_ON_ERROR
  7344. BNX2X_ERR("Wrong function state\n");
  7345. return -EBUSY;
  7346. #else
  7347. /*
  7348. * Failed to complete the transaction in a "good way"
  7349. * Force both transactions with CLR bit
  7350. */
  7351. struct bnx2x_func_state_params func_params = {NULL};
  7352. DP(NETIF_MSG_IFDOWN,
  7353. "Hmmm... Unexpected function state! Forcing STARTED-->TX_ST0PPED-->STARTED\n");
  7354. func_params.f_obj = &bp->func_obj;
  7355. __set_bit(RAMROD_DRV_CLR_ONLY,
  7356. &func_params.ramrod_flags);
  7357. /* STARTED-->TX_ST0PPED */
  7358. func_params.cmd = BNX2X_F_CMD_TX_STOP;
  7359. bnx2x_func_state_change(bp, &func_params);
  7360. /* TX_ST0PPED-->STARTED */
  7361. func_params.cmd = BNX2X_F_CMD_TX_START;
  7362. return bnx2x_func_state_change(bp, &func_params);
  7363. #endif
  7364. }
  7365. return 0;
  7366. }
  7367. void bnx2x_chip_cleanup(struct bnx2x *bp, int unload_mode, bool keep_link)
  7368. {
  7369. int port = BP_PORT(bp);
  7370. int i, rc = 0;
  7371. u8 cos;
  7372. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  7373. u32 reset_code;
  7374. /* Wait until tx fastpath tasks complete */
  7375. for_each_tx_queue(bp, i) {
  7376. struct bnx2x_fastpath *fp = &bp->fp[i];
  7377. for_each_cos_in_tx_queue(fp, cos)
  7378. rc = bnx2x_clean_tx_queue(bp, fp->txdata_ptr[cos]);
  7379. #ifdef BNX2X_STOP_ON_ERROR
  7380. if (rc)
  7381. return;
  7382. #endif
  7383. }
  7384. /* Give HW time to discard old tx messages */
  7385. usleep_range(1000, 2000);
  7386. /* Clean all ETH MACs */
  7387. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_ETH_MAC,
  7388. false);
  7389. if (rc < 0)
  7390. BNX2X_ERR("Failed to delete all ETH macs: %d\n", rc);
  7391. /* Clean up UC list */
  7392. rc = bnx2x_del_all_macs(bp, &bp->sp_objs[0].mac_obj, BNX2X_UC_LIST_MAC,
  7393. true);
  7394. if (rc < 0)
  7395. BNX2X_ERR("Failed to schedule DEL commands for UC MACs list: %d\n",
  7396. rc);
  7397. /* Disable LLH */
  7398. if (!CHIP_IS_E1(bp))
  7399. REG_WR(bp, NIG_REG_LLH0_FUNC_EN + port*8, 0);
  7400. /* Set "drop all" (stop Rx).
  7401. * We need to take a netif_addr_lock() here in order to prevent
  7402. * a race between the completion code and this code.
  7403. */
  7404. netif_addr_lock_bh(bp->dev);
  7405. /* Schedule the rx_mode command */
  7406. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  7407. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  7408. else
  7409. bnx2x_set_storm_rx_mode(bp);
  7410. /* Cleanup multicast configuration */
  7411. rparam.mcast_obj = &bp->mcast_obj;
  7412. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  7413. if (rc < 0)
  7414. BNX2X_ERR("Failed to send DEL multicast command: %d\n", rc);
  7415. netif_addr_unlock_bh(bp->dev);
  7416. bnx2x_iov_chip_cleanup(bp);
  7417. /*
  7418. * Send the UNLOAD_REQUEST to the MCP. This will return if
  7419. * this function should perform FUNC, PORT or COMMON HW
  7420. * reset.
  7421. */
  7422. reset_code = bnx2x_send_unload_req(bp, unload_mode);
  7423. /*
  7424. * (assumption: No Attention from MCP at this stage)
  7425. * PMF probably in the middle of TX disable/enable transaction
  7426. */
  7427. rc = bnx2x_func_wait_started(bp);
  7428. if (rc) {
  7429. BNX2X_ERR("bnx2x_func_wait_started failed\n");
  7430. #ifdef BNX2X_STOP_ON_ERROR
  7431. return;
  7432. #endif
  7433. }
  7434. /* Close multi and leading connections
  7435. * Completions for ramrods are collected in a synchronous way
  7436. */
  7437. for_each_eth_queue(bp, i)
  7438. if (bnx2x_stop_queue(bp, i))
  7439. #ifdef BNX2X_STOP_ON_ERROR
  7440. return;
  7441. #else
  7442. goto unload_error;
  7443. #endif
  7444. if (CNIC_LOADED(bp)) {
  7445. for_each_cnic_queue(bp, i)
  7446. if (bnx2x_stop_queue(bp, i))
  7447. #ifdef BNX2X_STOP_ON_ERROR
  7448. return;
  7449. #else
  7450. goto unload_error;
  7451. #endif
  7452. }
  7453. /* If SP settings didn't get completed so far - something
  7454. * very wrong has happen.
  7455. */
  7456. if (!bnx2x_wait_sp_comp(bp, ~0x0UL))
  7457. BNX2X_ERR("Hmmm... Common slow path ramrods got stuck!\n");
  7458. #ifndef BNX2X_STOP_ON_ERROR
  7459. unload_error:
  7460. #endif
  7461. rc = bnx2x_func_stop(bp);
  7462. if (rc) {
  7463. BNX2X_ERR("Function stop failed!\n");
  7464. #ifdef BNX2X_STOP_ON_ERROR
  7465. return;
  7466. #endif
  7467. }
  7468. /* Disable HW interrupts, NAPI */
  7469. bnx2x_netif_stop(bp, 1);
  7470. /* Delete all NAPI objects */
  7471. bnx2x_del_all_napi(bp);
  7472. if (CNIC_LOADED(bp))
  7473. bnx2x_del_all_napi_cnic(bp);
  7474. /* Release IRQs */
  7475. bnx2x_free_irq(bp);
  7476. /* Reset the chip */
  7477. rc = bnx2x_reset_hw(bp, reset_code);
  7478. if (rc)
  7479. BNX2X_ERR("HW_RESET failed\n");
  7480. /* Report UNLOAD_DONE to MCP */
  7481. bnx2x_send_unload_done(bp, keep_link);
  7482. }
  7483. void bnx2x_disable_close_the_gate(struct bnx2x *bp)
  7484. {
  7485. u32 val;
  7486. DP(NETIF_MSG_IFDOWN, "Disabling \"close the gates\"\n");
  7487. if (CHIP_IS_E1(bp)) {
  7488. int port = BP_PORT(bp);
  7489. u32 addr = port ? MISC_REG_AEU_MASK_ATTN_FUNC_1 :
  7490. MISC_REG_AEU_MASK_ATTN_FUNC_0;
  7491. val = REG_RD(bp, addr);
  7492. val &= ~(0x300);
  7493. REG_WR(bp, addr, val);
  7494. } else {
  7495. val = REG_RD(bp, MISC_REG_AEU_GENERAL_MASK);
  7496. val &= ~(MISC_AEU_GENERAL_MASK_REG_AEU_PXP_CLOSE_MASK |
  7497. MISC_AEU_GENERAL_MASK_REG_AEU_NIG_CLOSE_MASK);
  7498. REG_WR(bp, MISC_REG_AEU_GENERAL_MASK, val);
  7499. }
  7500. }
  7501. /* Close gates #2, #3 and #4: */
  7502. static void bnx2x_set_234_gates(struct bnx2x *bp, bool close)
  7503. {
  7504. u32 val;
  7505. /* Gates #2 and #4a are closed/opened for "not E1" only */
  7506. if (!CHIP_IS_E1(bp)) {
  7507. /* #4 */
  7508. REG_WR(bp, PXP_REG_HST_DISCARD_DOORBELLS, !!close);
  7509. /* #2 */
  7510. REG_WR(bp, PXP_REG_HST_DISCARD_INTERNAL_WRITES, !!close);
  7511. }
  7512. /* #3 */
  7513. if (CHIP_IS_E1x(bp)) {
  7514. /* Prevent interrupts from HC on both ports */
  7515. val = REG_RD(bp, HC_REG_CONFIG_1);
  7516. REG_WR(bp, HC_REG_CONFIG_1,
  7517. (!close) ? (val | HC_CONFIG_1_REG_BLOCK_DISABLE_1) :
  7518. (val & ~(u32)HC_CONFIG_1_REG_BLOCK_DISABLE_1));
  7519. val = REG_RD(bp, HC_REG_CONFIG_0);
  7520. REG_WR(bp, HC_REG_CONFIG_0,
  7521. (!close) ? (val | HC_CONFIG_0_REG_BLOCK_DISABLE_0) :
  7522. (val & ~(u32)HC_CONFIG_0_REG_BLOCK_DISABLE_0));
  7523. } else {
  7524. /* Prevent incoming interrupts in IGU */
  7525. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  7526. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION,
  7527. (!close) ?
  7528. (val | IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE) :
  7529. (val & ~(u32)IGU_BLOCK_CONFIGURATION_REG_BLOCK_ENABLE));
  7530. }
  7531. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "%s gates #2, #3 and #4\n",
  7532. close ? "closing" : "opening");
  7533. mmiowb();
  7534. }
  7535. #define SHARED_MF_CLP_MAGIC 0x80000000 /* `magic' bit */
  7536. static void bnx2x_clp_reset_prep(struct bnx2x *bp, u32 *magic_val)
  7537. {
  7538. /* Do some magic... */
  7539. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7540. *magic_val = val & SHARED_MF_CLP_MAGIC;
  7541. MF_CFG_WR(bp, shared_mf_config.clp_mb, val | SHARED_MF_CLP_MAGIC);
  7542. }
  7543. /**
  7544. * bnx2x_clp_reset_done - restore the value of the `magic' bit.
  7545. *
  7546. * @bp: driver handle
  7547. * @magic_val: old value of the `magic' bit.
  7548. */
  7549. static void bnx2x_clp_reset_done(struct bnx2x *bp, u32 magic_val)
  7550. {
  7551. /* Restore the `magic' bit value... */
  7552. u32 val = MF_CFG_RD(bp, shared_mf_config.clp_mb);
  7553. MF_CFG_WR(bp, shared_mf_config.clp_mb,
  7554. (val & (~SHARED_MF_CLP_MAGIC)) | magic_val);
  7555. }
  7556. /**
  7557. * bnx2x_reset_mcp_prep - prepare for MCP reset.
  7558. *
  7559. * @bp: driver handle
  7560. * @magic_val: old value of 'magic' bit.
  7561. *
  7562. * Takes care of CLP configurations.
  7563. */
  7564. static void bnx2x_reset_mcp_prep(struct bnx2x *bp, u32 *magic_val)
  7565. {
  7566. u32 shmem;
  7567. u32 validity_offset;
  7568. DP(NETIF_MSG_HW | NETIF_MSG_IFUP, "Starting\n");
  7569. /* Set `magic' bit in order to save MF config */
  7570. if (!CHIP_IS_E1(bp))
  7571. bnx2x_clp_reset_prep(bp, magic_val);
  7572. /* Get shmem offset */
  7573. shmem = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7574. validity_offset =
  7575. offsetof(struct shmem_region, validity_map[BP_PORT(bp)]);
  7576. /* Clear validity map flags */
  7577. if (shmem > 0)
  7578. REG_WR(bp, shmem + validity_offset, 0);
  7579. }
  7580. #define MCP_TIMEOUT 5000 /* 5 seconds (in ms) */
  7581. #define MCP_ONE_TIMEOUT 100 /* 100 ms */
  7582. /**
  7583. * bnx2x_mcp_wait_one - wait for MCP_ONE_TIMEOUT
  7584. *
  7585. * @bp: driver handle
  7586. */
  7587. static void bnx2x_mcp_wait_one(struct bnx2x *bp)
  7588. {
  7589. /* special handling for emulation and FPGA,
  7590. wait 10 times longer */
  7591. if (CHIP_REV_IS_SLOW(bp))
  7592. msleep(MCP_ONE_TIMEOUT*10);
  7593. else
  7594. msleep(MCP_ONE_TIMEOUT);
  7595. }
  7596. /*
  7597. * initializes bp->common.shmem_base and waits for validity signature to appear
  7598. */
  7599. static int bnx2x_init_shmem(struct bnx2x *bp)
  7600. {
  7601. int cnt = 0;
  7602. u32 val = 0;
  7603. do {
  7604. bp->common.shmem_base = REG_RD(bp, MISC_REG_SHARED_MEM_ADDR);
  7605. if (bp->common.shmem_base) {
  7606. val = SHMEM_RD(bp, validity_map[BP_PORT(bp)]);
  7607. if (val & SHR_MEM_VALIDITY_MB)
  7608. return 0;
  7609. }
  7610. bnx2x_mcp_wait_one(bp);
  7611. } while (cnt++ < (MCP_TIMEOUT / MCP_ONE_TIMEOUT));
  7612. BNX2X_ERR("BAD MCP validity signature\n");
  7613. return -ENODEV;
  7614. }
  7615. static int bnx2x_reset_mcp_comp(struct bnx2x *bp, u32 magic_val)
  7616. {
  7617. int rc = bnx2x_init_shmem(bp);
  7618. /* Restore the `magic' bit value */
  7619. if (!CHIP_IS_E1(bp))
  7620. bnx2x_clp_reset_done(bp, magic_val);
  7621. return rc;
  7622. }
  7623. static void bnx2x_pxp_prep(struct bnx2x *bp)
  7624. {
  7625. if (!CHIP_IS_E1(bp)) {
  7626. REG_WR(bp, PXP2_REG_RD_START_INIT, 0);
  7627. REG_WR(bp, PXP2_REG_RQ_RBC_DONE, 0);
  7628. mmiowb();
  7629. }
  7630. }
  7631. /*
  7632. * Reset the whole chip except for:
  7633. * - PCIE core
  7634. * - PCI Glue, PSWHST, PXP/PXP2 RF (all controlled by
  7635. * one reset bit)
  7636. * - IGU
  7637. * - MISC (including AEU)
  7638. * - GRC
  7639. * - RBCN, RBCP
  7640. */
  7641. static void bnx2x_process_kill_chip_reset(struct bnx2x *bp, bool global)
  7642. {
  7643. u32 not_reset_mask1, reset_mask1, not_reset_mask2, reset_mask2;
  7644. u32 global_bits2, stay_reset2;
  7645. /*
  7646. * Bits that have to be set in reset_mask2 if we want to reset 'global'
  7647. * (per chip) blocks.
  7648. */
  7649. global_bits2 =
  7650. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CPU |
  7651. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_CMN_CORE;
  7652. /* Don't reset the following blocks.
  7653. * Important: per port blocks (such as EMAC, BMAC, UMAC) can't be
  7654. * reset, as in 4 port device they might still be owned
  7655. * by the MCP (there is only one leader per path).
  7656. */
  7657. not_reset_mask1 =
  7658. MISC_REGISTERS_RESET_REG_1_RST_HC |
  7659. MISC_REGISTERS_RESET_REG_1_RST_PXPV |
  7660. MISC_REGISTERS_RESET_REG_1_RST_PXP;
  7661. not_reset_mask2 =
  7662. MISC_REGISTERS_RESET_REG_2_RST_PCI_MDIO |
  7663. MISC_REGISTERS_RESET_REG_2_RST_EMAC0_HARD_CORE |
  7664. MISC_REGISTERS_RESET_REG_2_RST_EMAC1_HARD_CORE |
  7665. MISC_REGISTERS_RESET_REG_2_RST_MISC_CORE |
  7666. MISC_REGISTERS_RESET_REG_2_RST_RBCN |
  7667. MISC_REGISTERS_RESET_REG_2_RST_GRC |
  7668. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_RESET_REG_HARD_CORE |
  7669. MISC_REGISTERS_RESET_REG_2_RST_MCP_N_HARD_CORE_RST_B |
  7670. MISC_REGISTERS_RESET_REG_2_RST_ATC |
  7671. MISC_REGISTERS_RESET_REG_2_PGLC |
  7672. MISC_REGISTERS_RESET_REG_2_RST_BMAC0 |
  7673. MISC_REGISTERS_RESET_REG_2_RST_BMAC1 |
  7674. MISC_REGISTERS_RESET_REG_2_RST_EMAC0 |
  7675. MISC_REGISTERS_RESET_REG_2_RST_EMAC1 |
  7676. MISC_REGISTERS_RESET_REG_2_UMAC0 |
  7677. MISC_REGISTERS_RESET_REG_2_UMAC1;
  7678. /*
  7679. * Keep the following blocks in reset:
  7680. * - all xxMACs are handled by the bnx2x_link code.
  7681. */
  7682. stay_reset2 =
  7683. MISC_REGISTERS_RESET_REG_2_XMAC |
  7684. MISC_REGISTERS_RESET_REG_2_XMAC_SOFT;
  7685. /* Full reset masks according to the chip */
  7686. reset_mask1 = 0xffffffff;
  7687. if (CHIP_IS_E1(bp))
  7688. reset_mask2 = 0xffff;
  7689. else if (CHIP_IS_E1H(bp))
  7690. reset_mask2 = 0x1ffff;
  7691. else if (CHIP_IS_E2(bp))
  7692. reset_mask2 = 0xfffff;
  7693. else /* CHIP_IS_E3 */
  7694. reset_mask2 = 0x3ffffff;
  7695. /* Don't reset global blocks unless we need to */
  7696. if (!global)
  7697. reset_mask2 &= ~global_bits2;
  7698. /*
  7699. * In case of attention in the QM, we need to reset PXP
  7700. * (MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR) before QM
  7701. * because otherwise QM reset would release 'close the gates' shortly
  7702. * before resetting the PXP, then the PSWRQ would send a write
  7703. * request to PGLUE. Then when PXP is reset, PGLUE would try to
  7704. * read the payload data from PSWWR, but PSWWR would not
  7705. * respond. The write queue in PGLUE would stuck, dmae commands
  7706. * would not return. Therefore it's important to reset the second
  7707. * reset register (containing the
  7708. * MISC_REGISTERS_RESET_REG_2_RST_PXP_RQ_RD_WR bit) before the
  7709. * first one (containing the MISC_REGISTERS_RESET_REG_1_RST_QM
  7710. * bit).
  7711. */
  7712. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_CLEAR,
  7713. reset_mask2 & (~not_reset_mask2));
  7714. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_CLEAR,
  7715. reset_mask1 & (~not_reset_mask1));
  7716. barrier();
  7717. mmiowb();
  7718. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_2_SET,
  7719. reset_mask2 & (~stay_reset2));
  7720. barrier();
  7721. mmiowb();
  7722. REG_WR(bp, GRCBASE_MISC + MISC_REGISTERS_RESET_REG_1_SET, reset_mask1);
  7723. mmiowb();
  7724. }
  7725. /**
  7726. * bnx2x_er_poll_igu_vq - poll for pending writes bit.
  7727. * It should get cleared in no more than 1s.
  7728. *
  7729. * @bp: driver handle
  7730. *
  7731. * It should get cleared in no more than 1s. Returns 0 if
  7732. * pending writes bit gets cleared.
  7733. */
  7734. static int bnx2x_er_poll_igu_vq(struct bnx2x *bp)
  7735. {
  7736. u32 cnt = 1000;
  7737. u32 pend_bits = 0;
  7738. do {
  7739. pend_bits = REG_RD(bp, IGU_REG_PENDING_BITS_STATUS);
  7740. if (pend_bits == 0)
  7741. break;
  7742. usleep_range(1000, 2000);
  7743. } while (cnt-- > 0);
  7744. if (cnt <= 0) {
  7745. BNX2X_ERR("Still pending IGU requests pend_bits=%x!\n",
  7746. pend_bits);
  7747. return -EBUSY;
  7748. }
  7749. return 0;
  7750. }
  7751. static int bnx2x_process_kill(struct bnx2x *bp, bool global)
  7752. {
  7753. int cnt = 1000;
  7754. u32 val = 0;
  7755. u32 sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1, pgl_exp_rom2;
  7756. u32 tags_63_32 = 0;
  7757. /* Empty the Tetris buffer, wait for 1s */
  7758. do {
  7759. sr_cnt = REG_RD(bp, PXP2_REG_RD_SR_CNT);
  7760. blk_cnt = REG_RD(bp, PXP2_REG_RD_BLK_CNT);
  7761. port_is_idle_0 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_0);
  7762. port_is_idle_1 = REG_RD(bp, PXP2_REG_RD_PORT_IS_IDLE_1);
  7763. pgl_exp_rom2 = REG_RD(bp, PXP2_REG_PGL_EXP_ROM2);
  7764. if (CHIP_IS_E3(bp))
  7765. tags_63_32 = REG_RD(bp, PGLUE_B_REG_TAGS_63_32);
  7766. if ((sr_cnt == 0x7e) && (blk_cnt == 0xa0) &&
  7767. ((port_is_idle_0 & 0x1) == 0x1) &&
  7768. ((port_is_idle_1 & 0x1) == 0x1) &&
  7769. (pgl_exp_rom2 == 0xffffffff) &&
  7770. (!CHIP_IS_E3(bp) || (tags_63_32 == 0xffffffff)))
  7771. break;
  7772. usleep_range(1000, 2000);
  7773. } while (cnt-- > 0);
  7774. if (cnt <= 0) {
  7775. BNX2X_ERR("Tetris buffer didn't get empty or there are still outstanding read requests after 1s!\n");
  7776. 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",
  7777. sr_cnt, blk_cnt, port_is_idle_0, port_is_idle_1,
  7778. pgl_exp_rom2);
  7779. return -EAGAIN;
  7780. }
  7781. barrier();
  7782. /* Close gates #2, #3 and #4 */
  7783. bnx2x_set_234_gates(bp, true);
  7784. /* Poll for IGU VQs for 57712 and newer chips */
  7785. if (!CHIP_IS_E1x(bp) && bnx2x_er_poll_igu_vq(bp))
  7786. return -EAGAIN;
  7787. /* TBD: Indicate that "process kill" is in progress to MCP */
  7788. /* Clear "unprepared" bit */
  7789. REG_WR(bp, MISC_REG_UNPREPARED, 0);
  7790. barrier();
  7791. /* Make sure all is written to the chip before the reset */
  7792. mmiowb();
  7793. /* Wait for 1ms to empty GLUE and PCI-E core queues,
  7794. * PSWHST, GRC and PSWRD Tetris buffer.
  7795. */
  7796. usleep_range(1000, 2000);
  7797. /* Prepare to chip reset: */
  7798. /* MCP */
  7799. if (global)
  7800. bnx2x_reset_mcp_prep(bp, &val);
  7801. /* PXP */
  7802. bnx2x_pxp_prep(bp);
  7803. barrier();
  7804. /* reset the chip */
  7805. bnx2x_process_kill_chip_reset(bp, global);
  7806. barrier();
  7807. /* Recover after reset: */
  7808. /* MCP */
  7809. if (global && bnx2x_reset_mcp_comp(bp, val))
  7810. return -EAGAIN;
  7811. /* TBD: Add resetting the NO_MCP mode DB here */
  7812. /* Open the gates #2, #3 and #4 */
  7813. bnx2x_set_234_gates(bp, false);
  7814. /* TBD: IGU/AEU preparation bring back the AEU/IGU to a
  7815. * reset state, re-enable attentions. */
  7816. return 0;
  7817. }
  7818. static int bnx2x_leader_reset(struct bnx2x *bp)
  7819. {
  7820. int rc = 0;
  7821. bool global = bnx2x_reset_is_global(bp);
  7822. u32 load_code;
  7823. /* if not going to reset MCP - load "fake" driver to reset HW while
  7824. * driver is owner of the HW
  7825. */
  7826. if (!global && !BP_NOMCP(bp)) {
  7827. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_REQ,
  7828. DRV_MSG_CODE_LOAD_REQ_WITH_LFA);
  7829. if (!load_code) {
  7830. BNX2X_ERR("MCP response failure, aborting\n");
  7831. rc = -EAGAIN;
  7832. goto exit_leader_reset;
  7833. }
  7834. if ((load_code != FW_MSG_CODE_DRV_LOAD_COMMON_CHIP) &&
  7835. (load_code != FW_MSG_CODE_DRV_LOAD_COMMON)) {
  7836. BNX2X_ERR("MCP unexpected resp, aborting\n");
  7837. rc = -EAGAIN;
  7838. goto exit_leader_reset2;
  7839. }
  7840. load_code = bnx2x_fw_command(bp, DRV_MSG_CODE_LOAD_DONE, 0);
  7841. if (!load_code) {
  7842. BNX2X_ERR("MCP response failure, aborting\n");
  7843. rc = -EAGAIN;
  7844. goto exit_leader_reset2;
  7845. }
  7846. }
  7847. /* Try to recover after the failure */
  7848. if (bnx2x_process_kill(bp, global)) {
  7849. BNX2X_ERR("Something bad had happen on engine %d! Aii!\n",
  7850. BP_PATH(bp));
  7851. rc = -EAGAIN;
  7852. goto exit_leader_reset2;
  7853. }
  7854. /*
  7855. * Clear RESET_IN_PROGRES and RESET_GLOBAL bits and update the driver
  7856. * state.
  7857. */
  7858. bnx2x_set_reset_done(bp);
  7859. if (global)
  7860. bnx2x_clear_reset_global(bp);
  7861. exit_leader_reset2:
  7862. /* unload "fake driver" if it was loaded */
  7863. if (!global && !BP_NOMCP(bp)) {
  7864. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_MCP, 0);
  7865. bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE, 0);
  7866. }
  7867. exit_leader_reset:
  7868. bp->is_leader = 0;
  7869. bnx2x_release_leader_lock(bp);
  7870. smp_mb();
  7871. return rc;
  7872. }
  7873. static void bnx2x_recovery_failed(struct bnx2x *bp)
  7874. {
  7875. netdev_err(bp->dev, "Recovery has failed. Power cycle is needed.\n");
  7876. /* Disconnect this device */
  7877. netif_device_detach(bp->dev);
  7878. /*
  7879. * Block ifup for all function on this engine until "process kill"
  7880. * or power cycle.
  7881. */
  7882. bnx2x_set_reset_in_progress(bp);
  7883. /* Shut down the power */
  7884. bnx2x_set_power_state(bp, PCI_D3hot);
  7885. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  7886. smp_mb();
  7887. }
  7888. /*
  7889. * Assumption: runs under rtnl lock. This together with the fact
  7890. * that it's called only from bnx2x_sp_rtnl() ensure that it
  7891. * will never be called when netif_running(bp->dev) is false.
  7892. */
  7893. static void bnx2x_parity_recover(struct bnx2x *bp)
  7894. {
  7895. bool global = false;
  7896. u32 error_recovered, error_unrecovered;
  7897. bool is_parity;
  7898. DP(NETIF_MSG_HW, "Handling parity\n");
  7899. while (1) {
  7900. switch (bp->recovery_state) {
  7901. case BNX2X_RECOVERY_INIT:
  7902. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_INIT\n");
  7903. is_parity = bnx2x_chk_parity_attn(bp, &global, false);
  7904. WARN_ON(!is_parity);
  7905. /* Try to get a LEADER_LOCK HW lock */
  7906. if (bnx2x_trylock_leader_lock(bp)) {
  7907. bnx2x_set_reset_in_progress(bp);
  7908. /*
  7909. * Check if there is a global attention and if
  7910. * there was a global attention, set the global
  7911. * reset bit.
  7912. */
  7913. if (global)
  7914. bnx2x_set_reset_global(bp);
  7915. bp->is_leader = 1;
  7916. }
  7917. /* Stop the driver */
  7918. /* If interface has been removed - break */
  7919. if (bnx2x_nic_unload(bp, UNLOAD_RECOVERY, false))
  7920. return;
  7921. bp->recovery_state = BNX2X_RECOVERY_WAIT;
  7922. /* Ensure "is_leader", MCP command sequence and
  7923. * "recovery_state" update values are seen on other
  7924. * CPUs.
  7925. */
  7926. smp_mb();
  7927. break;
  7928. case BNX2X_RECOVERY_WAIT:
  7929. DP(NETIF_MSG_HW, "State is BNX2X_RECOVERY_WAIT\n");
  7930. if (bp->is_leader) {
  7931. int other_engine = BP_PATH(bp) ? 0 : 1;
  7932. bool other_load_status =
  7933. bnx2x_get_load_status(bp, other_engine);
  7934. bool load_status =
  7935. bnx2x_get_load_status(bp, BP_PATH(bp));
  7936. global = bnx2x_reset_is_global(bp);
  7937. /*
  7938. * In case of a parity in a global block, let
  7939. * the first leader that performs a
  7940. * leader_reset() reset the global blocks in
  7941. * order to clear global attentions. Otherwise
  7942. * the gates will remain closed for that
  7943. * engine.
  7944. */
  7945. if (load_status ||
  7946. (global && other_load_status)) {
  7947. /* Wait until all other functions get
  7948. * down.
  7949. */
  7950. schedule_delayed_work(&bp->sp_rtnl_task,
  7951. HZ/10);
  7952. return;
  7953. } else {
  7954. /* If all other functions got down -
  7955. * try to bring the chip back to
  7956. * normal. In any case it's an exit
  7957. * point for a leader.
  7958. */
  7959. if (bnx2x_leader_reset(bp)) {
  7960. bnx2x_recovery_failed(bp);
  7961. return;
  7962. }
  7963. /* If we are here, means that the
  7964. * leader has succeeded and doesn't
  7965. * want to be a leader any more. Try
  7966. * to continue as a none-leader.
  7967. */
  7968. break;
  7969. }
  7970. } else { /* non-leader */
  7971. if (!bnx2x_reset_is_done(bp, BP_PATH(bp))) {
  7972. /* Try to get a LEADER_LOCK HW lock as
  7973. * long as a former leader may have
  7974. * been unloaded by the user or
  7975. * released a leadership by another
  7976. * reason.
  7977. */
  7978. if (bnx2x_trylock_leader_lock(bp)) {
  7979. /* I'm a leader now! Restart a
  7980. * switch case.
  7981. */
  7982. bp->is_leader = 1;
  7983. break;
  7984. }
  7985. schedule_delayed_work(&bp->sp_rtnl_task,
  7986. HZ/10);
  7987. return;
  7988. } else {
  7989. /*
  7990. * If there was a global attention, wait
  7991. * for it to be cleared.
  7992. */
  7993. if (bnx2x_reset_is_global(bp)) {
  7994. schedule_delayed_work(
  7995. &bp->sp_rtnl_task,
  7996. HZ/10);
  7997. return;
  7998. }
  7999. error_recovered =
  8000. bp->eth_stats.recoverable_error;
  8001. error_unrecovered =
  8002. bp->eth_stats.unrecoverable_error;
  8003. bp->recovery_state =
  8004. BNX2X_RECOVERY_NIC_LOADING;
  8005. if (bnx2x_nic_load(bp, LOAD_NORMAL)) {
  8006. error_unrecovered++;
  8007. netdev_err(bp->dev,
  8008. "Recovery failed. Power cycle needed\n");
  8009. /* Disconnect this device */
  8010. netif_device_detach(bp->dev);
  8011. /* Shut down the power */
  8012. bnx2x_set_power_state(
  8013. bp, PCI_D3hot);
  8014. smp_mb();
  8015. } else {
  8016. bp->recovery_state =
  8017. BNX2X_RECOVERY_DONE;
  8018. error_recovered++;
  8019. smp_mb();
  8020. }
  8021. bp->eth_stats.recoverable_error =
  8022. error_recovered;
  8023. bp->eth_stats.unrecoverable_error =
  8024. error_unrecovered;
  8025. return;
  8026. }
  8027. }
  8028. default:
  8029. return;
  8030. }
  8031. }
  8032. }
  8033. static int bnx2x_close(struct net_device *dev);
  8034. /* bnx2x_nic_unload() flushes the bnx2x_wq, thus reset task is
  8035. * scheduled on a general queue in order to prevent a dead lock.
  8036. */
  8037. static void bnx2x_sp_rtnl_task(struct work_struct *work)
  8038. {
  8039. struct bnx2x *bp = container_of(work, struct bnx2x, sp_rtnl_task.work);
  8040. rtnl_lock();
  8041. if (!netif_running(bp->dev)) {
  8042. rtnl_unlock();
  8043. return;
  8044. }
  8045. if (unlikely(bp->recovery_state != BNX2X_RECOVERY_DONE)) {
  8046. #ifdef BNX2X_STOP_ON_ERROR
  8047. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8048. "you will need to reboot when done\n");
  8049. goto sp_rtnl_not_reset;
  8050. #endif
  8051. /*
  8052. * Clear all pending SP commands as we are going to reset the
  8053. * function anyway.
  8054. */
  8055. bp->sp_rtnl_state = 0;
  8056. smp_mb();
  8057. bnx2x_parity_recover(bp);
  8058. rtnl_unlock();
  8059. return;
  8060. }
  8061. if (test_and_clear_bit(BNX2X_SP_RTNL_TX_TIMEOUT, &bp->sp_rtnl_state)) {
  8062. #ifdef BNX2X_STOP_ON_ERROR
  8063. BNX2X_ERR("recovery flow called but STOP_ON_ERROR defined so reset not done to allow debug dump,\n"
  8064. "you will need to reboot when done\n");
  8065. goto sp_rtnl_not_reset;
  8066. #endif
  8067. /*
  8068. * Clear all pending SP commands as we are going to reset the
  8069. * function anyway.
  8070. */
  8071. bp->sp_rtnl_state = 0;
  8072. smp_mb();
  8073. bnx2x_nic_unload(bp, UNLOAD_NORMAL, true);
  8074. bnx2x_nic_load(bp, LOAD_NORMAL);
  8075. rtnl_unlock();
  8076. return;
  8077. }
  8078. #ifdef BNX2X_STOP_ON_ERROR
  8079. sp_rtnl_not_reset:
  8080. #endif
  8081. if (test_and_clear_bit(BNX2X_SP_RTNL_SETUP_TC, &bp->sp_rtnl_state))
  8082. bnx2x_setup_tc(bp->dev, bp->dcbx_port_params.ets.num_of_cos);
  8083. if (test_and_clear_bit(BNX2X_SP_RTNL_AFEX_F_UPDATE, &bp->sp_rtnl_state))
  8084. bnx2x_after_function_update(bp);
  8085. /*
  8086. * in case of fan failure we need to reset id if the "stop on error"
  8087. * debug flag is set, since we trying to prevent permanent overheating
  8088. * damage
  8089. */
  8090. if (test_and_clear_bit(BNX2X_SP_RTNL_FAN_FAILURE, &bp->sp_rtnl_state)) {
  8091. DP(NETIF_MSG_HW, "fan failure detected. Unloading driver\n");
  8092. netif_device_detach(bp->dev);
  8093. bnx2x_close(bp->dev);
  8094. rtnl_unlock();
  8095. return;
  8096. }
  8097. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_MCAST, &bp->sp_rtnl_state)) {
  8098. DP(BNX2X_MSG_SP,
  8099. "sending set mcast vf pf channel message from rtnl sp-task\n");
  8100. bnx2x_vfpf_set_mcast(bp->dev);
  8101. }
  8102. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_CHANNEL_DOWN,
  8103. &bp->sp_rtnl_state)){
  8104. if (!test_bit(__LINK_STATE_NOCARRIER, &bp->dev->state)) {
  8105. bnx2x_tx_disable(bp);
  8106. BNX2X_ERR("PF indicated channel is not servicable anymore. This means this VF device is no longer operational\n");
  8107. }
  8108. }
  8109. if (test_and_clear_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  8110. &bp->sp_rtnl_state)) {
  8111. DP(BNX2X_MSG_SP,
  8112. "sending set storm rx mode vf pf channel message from rtnl sp-task\n");
  8113. bnx2x_vfpf_storm_rx_mode(bp);
  8114. }
  8115. if (test_and_clear_bit(BNX2X_SP_RTNL_HYPERVISOR_VLAN,
  8116. &bp->sp_rtnl_state))
  8117. bnx2x_pf_set_vfs_vlan(bp);
  8118. /* work which needs rtnl lock not-taken (as it takes the lock itself and
  8119. * can be called from other contexts as well)
  8120. */
  8121. rtnl_unlock();
  8122. /* enable SR-IOV if applicable */
  8123. if (IS_SRIOV(bp) && test_and_clear_bit(BNX2X_SP_RTNL_ENABLE_SRIOV,
  8124. &bp->sp_rtnl_state)) {
  8125. bnx2x_disable_sriov(bp);
  8126. bnx2x_enable_sriov(bp);
  8127. }
  8128. }
  8129. static void bnx2x_period_task(struct work_struct *work)
  8130. {
  8131. struct bnx2x *bp = container_of(work, struct bnx2x, period_task.work);
  8132. if (!netif_running(bp->dev))
  8133. goto period_task_exit;
  8134. if (CHIP_REV_IS_SLOW(bp)) {
  8135. BNX2X_ERR("period task called on emulation, ignoring\n");
  8136. goto period_task_exit;
  8137. }
  8138. bnx2x_acquire_phy_lock(bp);
  8139. /*
  8140. * The barrier is needed to ensure the ordering between the writing to
  8141. * the bp->port.pmf in the bnx2x_nic_load() or bnx2x_pmf_update() and
  8142. * the reading here.
  8143. */
  8144. smp_mb();
  8145. if (bp->port.pmf) {
  8146. bnx2x_period_func(&bp->link_params, &bp->link_vars);
  8147. /* Re-queue task in 1 sec */
  8148. queue_delayed_work(bnx2x_wq, &bp->period_task, 1*HZ);
  8149. }
  8150. bnx2x_release_phy_lock(bp);
  8151. period_task_exit:
  8152. return;
  8153. }
  8154. /*
  8155. * Init service functions
  8156. */
  8157. u32 bnx2x_get_pretend_reg(struct bnx2x *bp)
  8158. {
  8159. u32 base = PXP2_REG_PGL_PRETEND_FUNC_F0;
  8160. u32 stride = PXP2_REG_PGL_PRETEND_FUNC_F1 - base;
  8161. return base + (BP_ABS_FUNC(bp)) * stride;
  8162. }
  8163. static void bnx2x_prev_unload_close_mac(struct bnx2x *bp,
  8164. struct bnx2x_mac_vals *vals)
  8165. {
  8166. u32 val, base_addr, offset, mask, reset_reg;
  8167. bool mac_stopped = false;
  8168. u8 port = BP_PORT(bp);
  8169. /* reset addresses as they also mark which values were changed */
  8170. vals->bmac_addr = 0;
  8171. vals->umac_addr = 0;
  8172. vals->xmac_addr = 0;
  8173. vals->emac_addr = 0;
  8174. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_2);
  8175. if (!CHIP_IS_E3(bp)) {
  8176. val = REG_RD(bp, NIG_REG_BMAC0_REGS_OUT_EN + port * 4);
  8177. mask = MISC_REGISTERS_RESET_REG_2_RST_BMAC0 << port;
  8178. if ((mask & reset_reg) && val) {
  8179. u32 wb_data[2];
  8180. BNX2X_DEV_INFO("Disable bmac Rx\n");
  8181. base_addr = BP_PORT(bp) ? NIG_REG_INGRESS_BMAC1_MEM
  8182. : NIG_REG_INGRESS_BMAC0_MEM;
  8183. offset = CHIP_IS_E2(bp) ? BIGMAC2_REGISTER_BMAC_CONTROL
  8184. : BIGMAC_REGISTER_BMAC_CONTROL;
  8185. /*
  8186. * use rd/wr since we cannot use dmae. This is safe
  8187. * since MCP won't access the bus due to the request
  8188. * to unload, and no function on the path can be
  8189. * loaded at this time.
  8190. */
  8191. wb_data[0] = REG_RD(bp, base_addr + offset);
  8192. wb_data[1] = REG_RD(bp, base_addr + offset + 0x4);
  8193. vals->bmac_addr = base_addr + offset;
  8194. vals->bmac_val[0] = wb_data[0];
  8195. vals->bmac_val[1] = wb_data[1];
  8196. wb_data[0] &= ~BMAC_CONTROL_RX_ENABLE;
  8197. REG_WR(bp, vals->bmac_addr, wb_data[0]);
  8198. REG_WR(bp, vals->bmac_addr + 0x4, wb_data[1]);
  8199. }
  8200. BNX2X_DEV_INFO("Disable emac Rx\n");
  8201. vals->emac_addr = NIG_REG_NIG_EMAC0_EN + BP_PORT(bp)*4;
  8202. vals->emac_val = REG_RD(bp, vals->emac_addr);
  8203. REG_WR(bp, vals->emac_addr, 0);
  8204. mac_stopped = true;
  8205. } else {
  8206. if (reset_reg & MISC_REGISTERS_RESET_REG_2_XMAC) {
  8207. BNX2X_DEV_INFO("Disable xmac Rx\n");
  8208. base_addr = BP_PORT(bp) ? GRCBASE_XMAC1 : GRCBASE_XMAC0;
  8209. val = REG_RD(bp, base_addr + XMAC_REG_PFC_CTRL_HI);
  8210. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8211. val & ~(1 << 1));
  8212. REG_WR(bp, base_addr + XMAC_REG_PFC_CTRL_HI,
  8213. val | (1 << 1));
  8214. vals->xmac_addr = base_addr + XMAC_REG_CTRL;
  8215. vals->xmac_val = REG_RD(bp, vals->xmac_addr);
  8216. REG_WR(bp, vals->xmac_addr, 0);
  8217. mac_stopped = true;
  8218. }
  8219. mask = MISC_REGISTERS_RESET_REG_2_UMAC0 << port;
  8220. if (mask & reset_reg) {
  8221. BNX2X_DEV_INFO("Disable umac Rx\n");
  8222. base_addr = BP_PORT(bp) ? GRCBASE_UMAC1 : GRCBASE_UMAC0;
  8223. vals->umac_addr = base_addr + UMAC_REG_COMMAND_CONFIG;
  8224. vals->umac_val = REG_RD(bp, vals->umac_addr);
  8225. REG_WR(bp, vals->umac_addr, 0);
  8226. mac_stopped = true;
  8227. }
  8228. }
  8229. if (mac_stopped)
  8230. msleep(20);
  8231. }
  8232. #define BNX2X_PREV_UNDI_PROD_ADDR(p) (BAR_TSTRORM_INTMEM + 0x1508 + ((p) << 4))
  8233. #define BNX2X_PREV_UNDI_RCQ(val) ((val) & 0xffff)
  8234. #define BNX2X_PREV_UNDI_BD(val) ((val) >> 16 & 0xffff)
  8235. #define BNX2X_PREV_UNDI_PROD(rcq, bd) ((bd) << 16 | (rcq))
  8236. static void bnx2x_prev_unload_undi_inc(struct bnx2x *bp, u8 port, u8 inc)
  8237. {
  8238. u16 rcq, bd;
  8239. u32 tmp_reg = REG_RD(bp, BNX2X_PREV_UNDI_PROD_ADDR(port));
  8240. rcq = BNX2X_PREV_UNDI_RCQ(tmp_reg) + inc;
  8241. bd = BNX2X_PREV_UNDI_BD(tmp_reg) + inc;
  8242. tmp_reg = BNX2X_PREV_UNDI_PROD(rcq, bd);
  8243. REG_WR(bp, BNX2X_PREV_UNDI_PROD_ADDR(port), tmp_reg);
  8244. BNX2X_DEV_INFO("UNDI producer [%d] rings bd -> 0x%04x, rcq -> 0x%04x\n",
  8245. port, bd, rcq);
  8246. }
  8247. static int bnx2x_prev_mcp_done(struct bnx2x *bp)
  8248. {
  8249. u32 rc = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_DONE,
  8250. DRV_MSG_CODE_UNLOAD_SKIP_LINK_RESET);
  8251. if (!rc) {
  8252. BNX2X_ERR("MCP response failure, aborting\n");
  8253. return -EBUSY;
  8254. }
  8255. return 0;
  8256. }
  8257. static struct bnx2x_prev_path_list *
  8258. bnx2x_prev_path_get_entry(struct bnx2x *bp)
  8259. {
  8260. struct bnx2x_prev_path_list *tmp_list;
  8261. list_for_each_entry(tmp_list, &bnx2x_prev_list, list)
  8262. if (PCI_SLOT(bp->pdev->devfn) == tmp_list->slot &&
  8263. bp->pdev->bus->number == tmp_list->bus &&
  8264. BP_PATH(bp) == tmp_list->path)
  8265. return tmp_list;
  8266. return NULL;
  8267. }
  8268. static int bnx2x_prev_path_mark_eeh(struct bnx2x *bp)
  8269. {
  8270. struct bnx2x_prev_path_list *tmp_list;
  8271. int rc;
  8272. rc = down_interruptible(&bnx2x_prev_sem);
  8273. if (rc) {
  8274. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8275. return rc;
  8276. }
  8277. tmp_list = bnx2x_prev_path_get_entry(bp);
  8278. if (tmp_list) {
  8279. tmp_list->aer = 1;
  8280. rc = 0;
  8281. } else {
  8282. BNX2X_ERR("path %d: Entry does not exist for eeh; Flow occurs before initial insmod is over ?\n",
  8283. BP_PATH(bp));
  8284. }
  8285. up(&bnx2x_prev_sem);
  8286. return rc;
  8287. }
  8288. static bool bnx2x_prev_is_path_marked(struct bnx2x *bp)
  8289. {
  8290. struct bnx2x_prev_path_list *tmp_list;
  8291. int rc = false;
  8292. if (down_trylock(&bnx2x_prev_sem))
  8293. return false;
  8294. tmp_list = bnx2x_prev_path_get_entry(bp);
  8295. if (tmp_list) {
  8296. if (tmp_list->aer) {
  8297. DP(NETIF_MSG_HW, "Path %d was marked by AER\n",
  8298. BP_PATH(bp));
  8299. } else {
  8300. rc = true;
  8301. BNX2X_DEV_INFO("Path %d was already cleaned from previous drivers\n",
  8302. BP_PATH(bp));
  8303. }
  8304. }
  8305. up(&bnx2x_prev_sem);
  8306. return rc;
  8307. }
  8308. bool bnx2x_port_after_undi(struct bnx2x *bp)
  8309. {
  8310. struct bnx2x_prev_path_list *entry;
  8311. bool val;
  8312. down(&bnx2x_prev_sem);
  8313. entry = bnx2x_prev_path_get_entry(bp);
  8314. val = !!(entry && (entry->undi & (1 << BP_PORT(bp))));
  8315. up(&bnx2x_prev_sem);
  8316. return val;
  8317. }
  8318. static int bnx2x_prev_mark_path(struct bnx2x *bp, bool after_undi)
  8319. {
  8320. struct bnx2x_prev_path_list *tmp_list;
  8321. int rc;
  8322. rc = down_interruptible(&bnx2x_prev_sem);
  8323. if (rc) {
  8324. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8325. return rc;
  8326. }
  8327. /* Check whether the entry for this path already exists */
  8328. tmp_list = bnx2x_prev_path_get_entry(bp);
  8329. if (tmp_list) {
  8330. if (!tmp_list->aer) {
  8331. BNX2X_ERR("Re-Marking the path.\n");
  8332. } else {
  8333. DP(NETIF_MSG_HW, "Removing AER indication from path %d\n",
  8334. BP_PATH(bp));
  8335. tmp_list->aer = 0;
  8336. }
  8337. up(&bnx2x_prev_sem);
  8338. return 0;
  8339. }
  8340. up(&bnx2x_prev_sem);
  8341. /* Create an entry for this path and add it */
  8342. tmp_list = kmalloc(sizeof(struct bnx2x_prev_path_list), GFP_KERNEL);
  8343. if (!tmp_list) {
  8344. BNX2X_ERR("Failed to allocate 'bnx2x_prev_path_list'\n");
  8345. return -ENOMEM;
  8346. }
  8347. tmp_list->bus = bp->pdev->bus->number;
  8348. tmp_list->slot = PCI_SLOT(bp->pdev->devfn);
  8349. tmp_list->path = BP_PATH(bp);
  8350. tmp_list->aer = 0;
  8351. tmp_list->undi = after_undi ? (1 << BP_PORT(bp)) : 0;
  8352. rc = down_interruptible(&bnx2x_prev_sem);
  8353. if (rc) {
  8354. BNX2X_ERR("Received %d when tried to take lock\n", rc);
  8355. kfree(tmp_list);
  8356. } else {
  8357. DP(NETIF_MSG_HW, "Marked path [%d] - finished previous unload\n",
  8358. BP_PATH(bp));
  8359. list_add(&tmp_list->list, &bnx2x_prev_list);
  8360. up(&bnx2x_prev_sem);
  8361. }
  8362. return rc;
  8363. }
  8364. static int bnx2x_do_flr(struct bnx2x *bp)
  8365. {
  8366. int i;
  8367. u16 status;
  8368. struct pci_dev *dev = bp->pdev;
  8369. if (CHIP_IS_E1x(bp)) {
  8370. BNX2X_DEV_INFO("FLR not supported in E1/E1H\n");
  8371. return -EINVAL;
  8372. }
  8373. /* only bootcode REQ_BC_VER_4_INITIATE_FLR and onwards support flr */
  8374. if (bp->common.bc_ver < REQ_BC_VER_4_INITIATE_FLR) {
  8375. BNX2X_ERR("FLR not supported by BC_VER: 0x%x\n",
  8376. bp->common.bc_ver);
  8377. return -EINVAL;
  8378. }
  8379. /* Wait for Transaction Pending bit clean */
  8380. for (i = 0; i < 4; i++) {
  8381. if (i)
  8382. msleep((1 << (i - 1)) * 100);
  8383. pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &status);
  8384. if (!(status & PCI_EXP_DEVSTA_TRPND))
  8385. goto clear;
  8386. }
  8387. dev_err(&dev->dev,
  8388. "transaction is not cleared; proceeding with reset anyway\n");
  8389. clear:
  8390. BNX2X_DEV_INFO("Initiating FLR\n");
  8391. bnx2x_fw_command(bp, DRV_MSG_CODE_INITIATE_FLR, 0);
  8392. return 0;
  8393. }
  8394. static int bnx2x_prev_unload_uncommon(struct bnx2x *bp)
  8395. {
  8396. int rc;
  8397. BNX2X_DEV_INFO("Uncommon unload Flow\n");
  8398. /* Test if previous unload process was already finished for this path */
  8399. if (bnx2x_prev_is_path_marked(bp))
  8400. return bnx2x_prev_mcp_done(bp);
  8401. BNX2X_DEV_INFO("Path is unmarked\n");
  8402. /* If function has FLR capabilities, and existing FW version matches
  8403. * the one required, then FLR will be sufficient to clean any residue
  8404. * left by previous driver
  8405. */
  8406. rc = bnx2x_nic_load_analyze_req(bp, FW_MSG_CODE_DRV_LOAD_FUNCTION);
  8407. if (!rc) {
  8408. /* fw version is good */
  8409. BNX2X_DEV_INFO("FW version matches our own. Attempting FLR\n");
  8410. rc = bnx2x_do_flr(bp);
  8411. }
  8412. if (!rc) {
  8413. /* FLR was performed */
  8414. BNX2X_DEV_INFO("FLR successful\n");
  8415. return 0;
  8416. }
  8417. BNX2X_DEV_INFO("Could not FLR\n");
  8418. /* Close the MCP request, return failure*/
  8419. rc = bnx2x_prev_mcp_done(bp);
  8420. if (!rc)
  8421. rc = BNX2X_PREV_WAIT_NEEDED;
  8422. return rc;
  8423. }
  8424. static int bnx2x_prev_unload_common(struct bnx2x *bp)
  8425. {
  8426. u32 reset_reg, tmp_reg = 0, rc;
  8427. bool prev_undi = false;
  8428. struct bnx2x_mac_vals mac_vals;
  8429. /* It is possible a previous function received 'common' answer,
  8430. * but hasn't loaded yet, therefore creating a scenario of
  8431. * multiple functions receiving 'common' on the same path.
  8432. */
  8433. BNX2X_DEV_INFO("Common unload Flow\n");
  8434. memset(&mac_vals, 0, sizeof(mac_vals));
  8435. if (bnx2x_prev_is_path_marked(bp))
  8436. return bnx2x_prev_mcp_done(bp);
  8437. reset_reg = REG_RD(bp, MISC_REG_RESET_REG_1);
  8438. /* Reset should be performed after BRB is emptied */
  8439. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_BRB1) {
  8440. u32 timer_count = 1000;
  8441. /* Close the MAC Rx to prevent BRB from filling up */
  8442. bnx2x_prev_unload_close_mac(bp, &mac_vals);
  8443. /* close LLH filters towards the BRB */
  8444. bnx2x_set_rx_filter(&bp->link_params, 0);
  8445. /* Check if the UNDI driver was previously loaded
  8446. * UNDI driver initializes CID offset for normal bell to 0x7
  8447. */
  8448. if (reset_reg & MISC_REGISTERS_RESET_REG_1_RST_DORQ) {
  8449. tmp_reg = REG_RD(bp, DORQ_REG_NORM_CID_OFST);
  8450. if (tmp_reg == 0x7) {
  8451. BNX2X_DEV_INFO("UNDI previously loaded\n");
  8452. prev_undi = true;
  8453. /* clear the UNDI indication */
  8454. REG_WR(bp, DORQ_REG_NORM_CID_OFST, 0);
  8455. /* clear possible idle check errors */
  8456. REG_RD(bp, NIG_REG_NIG_INT_STS_CLR_0);
  8457. }
  8458. }
  8459. if (!CHIP_IS_E1x(bp))
  8460. /* block FW from writing to host */
  8461. REG_WR(bp, PGLUE_B_REG_INTERNAL_PFID_ENABLE_MASTER, 0);
  8462. /* wait until BRB is empty */
  8463. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8464. while (timer_count) {
  8465. u32 prev_brb = tmp_reg;
  8466. tmp_reg = REG_RD(bp, BRB1_REG_NUM_OF_FULL_BLOCKS);
  8467. if (!tmp_reg)
  8468. break;
  8469. BNX2X_DEV_INFO("BRB still has 0x%08x\n", tmp_reg);
  8470. /* reset timer as long as BRB actually gets emptied */
  8471. if (prev_brb > tmp_reg)
  8472. timer_count = 1000;
  8473. else
  8474. timer_count--;
  8475. /* If UNDI resides in memory, manually increment it */
  8476. if (prev_undi)
  8477. bnx2x_prev_unload_undi_inc(bp, BP_PORT(bp), 1);
  8478. udelay(10);
  8479. }
  8480. if (!timer_count)
  8481. BNX2X_ERR("Failed to empty BRB, hope for the best\n");
  8482. }
  8483. /* No packets are in the pipeline, path is ready for reset */
  8484. bnx2x_reset_common(bp);
  8485. if (mac_vals.xmac_addr)
  8486. REG_WR(bp, mac_vals.xmac_addr, mac_vals.xmac_val);
  8487. if (mac_vals.umac_addr)
  8488. REG_WR(bp, mac_vals.umac_addr, mac_vals.umac_val);
  8489. if (mac_vals.emac_addr)
  8490. REG_WR(bp, mac_vals.emac_addr, mac_vals.emac_val);
  8491. if (mac_vals.bmac_addr) {
  8492. REG_WR(bp, mac_vals.bmac_addr, mac_vals.bmac_val[0]);
  8493. REG_WR(bp, mac_vals.bmac_addr + 4, mac_vals.bmac_val[1]);
  8494. }
  8495. rc = bnx2x_prev_mark_path(bp, prev_undi);
  8496. if (rc) {
  8497. bnx2x_prev_mcp_done(bp);
  8498. return rc;
  8499. }
  8500. return bnx2x_prev_mcp_done(bp);
  8501. }
  8502. /* previous driver DMAE transaction may have occurred when pre-boot stage ended
  8503. * and boot began, or when kdump kernel was loaded. Either case would invalidate
  8504. * the addresses of the transaction, resulting in was-error bit set in the pci
  8505. * causing all hw-to-host pcie transactions to timeout. If this happened we want
  8506. * to clear the interrupt which detected this from the pglueb and the was done
  8507. * bit
  8508. */
  8509. static void bnx2x_prev_interrupted_dmae(struct bnx2x *bp)
  8510. {
  8511. if (!CHIP_IS_E1x(bp)) {
  8512. u32 val = REG_RD(bp, PGLUE_B_REG_PGLUE_B_INT_STS);
  8513. if (val & PGLUE_B_PGLUE_B_INT_STS_REG_WAS_ERROR_ATTN) {
  8514. DP(BNX2X_MSG_SP,
  8515. "'was error' bit was found to be set in pglueb upon startup. Clearing\n");
  8516. REG_WR(bp, PGLUE_B_REG_WAS_ERROR_PF_7_0_CLR,
  8517. 1 << BP_FUNC(bp));
  8518. }
  8519. }
  8520. }
  8521. static int bnx2x_prev_unload(struct bnx2x *bp)
  8522. {
  8523. int time_counter = 10;
  8524. u32 rc, fw, hw_lock_reg, hw_lock_val;
  8525. BNX2X_DEV_INFO("Entering Previous Unload Flow\n");
  8526. /* clear hw from errors which may have resulted from an interrupted
  8527. * dmae transaction.
  8528. */
  8529. bnx2x_prev_interrupted_dmae(bp);
  8530. /* Release previously held locks */
  8531. hw_lock_reg = (BP_FUNC(bp) <= 5) ?
  8532. (MISC_REG_DRIVER_CONTROL_1 + BP_FUNC(bp) * 8) :
  8533. (MISC_REG_DRIVER_CONTROL_7 + (BP_FUNC(bp) - 6) * 8);
  8534. hw_lock_val = REG_RD(bp, hw_lock_reg);
  8535. if (hw_lock_val) {
  8536. if (hw_lock_val & HW_LOCK_RESOURCE_NVRAM) {
  8537. BNX2X_DEV_INFO("Release Previously held NVRAM lock\n");
  8538. REG_WR(bp, MCP_REG_MCPR_NVM_SW_ARB,
  8539. (MCPR_NVM_SW_ARB_ARB_REQ_CLR1 << BP_PORT(bp)));
  8540. }
  8541. BNX2X_DEV_INFO("Release Previously held hw lock\n");
  8542. REG_WR(bp, hw_lock_reg, 0xffffffff);
  8543. } else
  8544. BNX2X_DEV_INFO("No need to release hw/nvram locks\n");
  8545. if (MCPR_ACCESS_LOCK_LOCK & REG_RD(bp, MCP_REG_MCPR_ACCESS_LOCK)) {
  8546. BNX2X_DEV_INFO("Release previously held alr\n");
  8547. bnx2x_release_alr(bp);
  8548. }
  8549. do {
  8550. int aer = 0;
  8551. /* Lock MCP using an unload request */
  8552. fw = bnx2x_fw_command(bp, DRV_MSG_CODE_UNLOAD_REQ_WOL_DIS, 0);
  8553. if (!fw) {
  8554. BNX2X_ERR("MCP response failure, aborting\n");
  8555. rc = -EBUSY;
  8556. break;
  8557. }
  8558. rc = down_interruptible(&bnx2x_prev_sem);
  8559. if (rc) {
  8560. BNX2X_ERR("Cannot check for AER; Received %d when tried to take lock\n",
  8561. rc);
  8562. } else {
  8563. /* If Path is marked by EEH, ignore unload status */
  8564. aer = !!(bnx2x_prev_path_get_entry(bp) &&
  8565. bnx2x_prev_path_get_entry(bp)->aer);
  8566. up(&bnx2x_prev_sem);
  8567. }
  8568. if (fw == FW_MSG_CODE_DRV_UNLOAD_COMMON || aer) {
  8569. rc = bnx2x_prev_unload_common(bp);
  8570. break;
  8571. }
  8572. /* non-common reply from MCP might require looping */
  8573. rc = bnx2x_prev_unload_uncommon(bp);
  8574. if (rc != BNX2X_PREV_WAIT_NEEDED)
  8575. break;
  8576. msleep(20);
  8577. } while (--time_counter);
  8578. if (!time_counter || rc) {
  8579. BNX2X_ERR("Failed unloading previous driver, aborting\n");
  8580. rc = -EBUSY;
  8581. }
  8582. /* Mark function if its port was used to boot from SAN */
  8583. if (bnx2x_port_after_undi(bp))
  8584. bp->link_params.feature_config_flags |=
  8585. FEATURE_CONFIG_BOOT_FROM_SAN;
  8586. BNX2X_DEV_INFO("Finished Previous Unload Flow [%d]\n", rc);
  8587. return rc;
  8588. }
  8589. static void bnx2x_get_common_hwinfo(struct bnx2x *bp)
  8590. {
  8591. u32 val, val2, val3, val4, id, boot_mode;
  8592. u16 pmc;
  8593. /* Get the chip revision id and number. */
  8594. /* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
  8595. val = REG_RD(bp, MISC_REG_CHIP_NUM);
  8596. id = ((val & 0xffff) << 16);
  8597. val = REG_RD(bp, MISC_REG_CHIP_REV);
  8598. id |= ((val & 0xf) << 12);
  8599. /* Metal is read from PCI regs, but we can't access >=0x400 from
  8600. * the configuration space (so we need to reg_rd)
  8601. */
  8602. val = REG_RD(bp, PCICFG_OFFSET + PCI_ID_VAL3);
  8603. id |= (((val >> 24) & 0xf) << 4);
  8604. val = REG_RD(bp, MISC_REG_BOND_ID);
  8605. id |= (val & 0xf);
  8606. bp->common.chip_id = id;
  8607. /* force 57811 according to MISC register */
  8608. if (REG_RD(bp, MISC_REG_CHIP_TYPE) & MISC_REG_CHIP_TYPE_57811_MASK) {
  8609. if (CHIP_IS_57810(bp))
  8610. bp->common.chip_id = (CHIP_NUM_57811 << 16) |
  8611. (bp->common.chip_id & 0x0000FFFF);
  8612. else if (CHIP_IS_57810_MF(bp))
  8613. bp->common.chip_id = (CHIP_NUM_57811_MF << 16) |
  8614. (bp->common.chip_id & 0x0000FFFF);
  8615. bp->common.chip_id |= 0x1;
  8616. }
  8617. /* Set doorbell size */
  8618. bp->db_size = (1 << BNX2X_DB_SHIFT);
  8619. if (!CHIP_IS_E1x(bp)) {
  8620. val = REG_RD(bp, MISC_REG_PORT4MODE_EN_OVWR);
  8621. if ((val & 1) == 0)
  8622. val = REG_RD(bp, MISC_REG_PORT4MODE_EN);
  8623. else
  8624. val = (val >> 1) & 1;
  8625. BNX2X_DEV_INFO("chip is in %s\n", val ? "4_PORT_MODE" :
  8626. "2_PORT_MODE");
  8627. bp->common.chip_port_mode = val ? CHIP_4_PORT_MODE :
  8628. CHIP_2_PORT_MODE;
  8629. if (CHIP_MODE_IS_4_PORT(bp))
  8630. bp->pfid = (bp->pf_num >> 1); /* 0..3 */
  8631. else
  8632. bp->pfid = (bp->pf_num & 0x6); /* 0, 2, 4, 6 */
  8633. } else {
  8634. bp->common.chip_port_mode = CHIP_PORT_MODE_NONE; /* N/A */
  8635. bp->pfid = bp->pf_num; /* 0..7 */
  8636. }
  8637. BNX2X_DEV_INFO("pf_id: %x", bp->pfid);
  8638. bp->link_params.chip_id = bp->common.chip_id;
  8639. BNX2X_DEV_INFO("chip ID is 0x%x\n", id);
  8640. val = (REG_RD(bp, 0x2874) & 0x55);
  8641. if ((bp->common.chip_id & 0x1) ||
  8642. (CHIP_IS_E1(bp) && val) || (CHIP_IS_E1H(bp) && (val == 0x55))) {
  8643. bp->flags |= ONE_PORT_FLAG;
  8644. BNX2X_DEV_INFO("single port device\n");
  8645. }
  8646. val = REG_RD(bp, MCP_REG_MCPR_NVM_CFG4);
  8647. bp->common.flash_size = (BNX2X_NVRAM_1MB_SIZE <<
  8648. (val & MCPR_NVM_CFG4_FLASH_SIZE));
  8649. BNX2X_DEV_INFO("flash_size 0x%x (%d)\n",
  8650. bp->common.flash_size, bp->common.flash_size);
  8651. bnx2x_init_shmem(bp);
  8652. bp->common.shmem2_base = REG_RD(bp, (BP_PATH(bp) ?
  8653. MISC_REG_GENERIC_CR_1 :
  8654. MISC_REG_GENERIC_CR_0));
  8655. bp->link_params.shmem_base = bp->common.shmem_base;
  8656. bp->link_params.shmem2_base = bp->common.shmem2_base;
  8657. if (SHMEM2_RD(bp, size) >
  8658. (u32)offsetof(struct shmem2_region, lfa_host_addr[BP_PORT(bp)]))
  8659. bp->link_params.lfa_base =
  8660. REG_RD(bp, bp->common.shmem2_base +
  8661. (u32)offsetof(struct shmem2_region,
  8662. lfa_host_addr[BP_PORT(bp)]));
  8663. else
  8664. bp->link_params.lfa_base = 0;
  8665. BNX2X_DEV_INFO("shmem offset 0x%x shmem2 offset 0x%x\n",
  8666. bp->common.shmem_base, bp->common.shmem2_base);
  8667. if (!bp->common.shmem_base) {
  8668. BNX2X_DEV_INFO("MCP not active\n");
  8669. bp->flags |= NO_MCP_FLAG;
  8670. return;
  8671. }
  8672. bp->common.hw_config = SHMEM_RD(bp, dev_info.shared_hw_config.config);
  8673. BNX2X_DEV_INFO("hw_config 0x%08x\n", bp->common.hw_config);
  8674. bp->link_params.hw_led_mode = ((bp->common.hw_config &
  8675. SHARED_HW_CFG_LED_MODE_MASK) >>
  8676. SHARED_HW_CFG_LED_MODE_SHIFT);
  8677. bp->link_params.feature_config_flags = 0;
  8678. val = SHMEM_RD(bp, dev_info.shared_feature_config.config);
  8679. if (val & SHARED_FEAT_CFG_OVERRIDE_PREEMPHASIS_CFG_ENABLED)
  8680. bp->link_params.feature_config_flags |=
  8681. FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8682. else
  8683. bp->link_params.feature_config_flags &=
  8684. ~FEATURE_CONFIG_OVERRIDE_PREEMPHASIS_ENABLED;
  8685. val = SHMEM_RD(bp, dev_info.bc_rev) >> 8;
  8686. bp->common.bc_ver = val;
  8687. BNX2X_DEV_INFO("bc_ver %X\n", val);
  8688. if (val < BNX2X_BC_VER) {
  8689. /* for now only warn
  8690. * later we might need to enforce this */
  8691. BNX2X_ERR("This driver needs bc_ver %X but found %X, please upgrade BC\n",
  8692. BNX2X_BC_VER, val);
  8693. }
  8694. bp->link_params.feature_config_flags |=
  8695. (val >= REQ_BC_VER_4_VRFY_FIRST_PHY_OPT_MDL) ?
  8696. FEATURE_CONFIG_BC_SUPPORTS_OPT_MDL_VRFY : 0;
  8697. bp->link_params.feature_config_flags |=
  8698. (val >= REQ_BC_VER_4_VRFY_SPECIFIC_PHY_OPT_MDL) ?
  8699. FEATURE_CONFIG_BC_SUPPORTS_DUAL_PHY_OPT_MDL_VRFY : 0;
  8700. bp->link_params.feature_config_flags |=
  8701. (val >= REQ_BC_VER_4_VRFY_AFEX_SUPPORTED) ?
  8702. FEATURE_CONFIG_BC_SUPPORTS_AFEX : 0;
  8703. bp->link_params.feature_config_flags |=
  8704. (val >= REQ_BC_VER_4_SFP_TX_DISABLE_SUPPORTED) ?
  8705. FEATURE_CONFIG_BC_SUPPORTS_SFP_TX_DISABLED : 0;
  8706. bp->link_params.feature_config_flags |=
  8707. (val >= REQ_BC_VER_4_MT_SUPPORTED) ?
  8708. FEATURE_CONFIG_MT_SUPPORT : 0;
  8709. bp->flags |= (val >= REQ_BC_VER_4_PFC_STATS_SUPPORTED) ?
  8710. BC_SUPPORTS_PFC_STATS : 0;
  8711. bp->flags |= (val >= REQ_BC_VER_4_FCOE_FEATURES) ?
  8712. BC_SUPPORTS_FCOE_FEATURES : 0;
  8713. bp->flags |= (val >= REQ_BC_VER_4_DCBX_ADMIN_MSG_NON_PMF) ?
  8714. BC_SUPPORTS_DCBX_MSG_NON_PMF : 0;
  8715. boot_mode = SHMEM_RD(bp,
  8716. dev_info.port_feature_config[BP_PORT(bp)].mba_config) &
  8717. PORT_FEATURE_MBA_BOOT_AGENT_TYPE_MASK;
  8718. switch (boot_mode) {
  8719. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_PXE:
  8720. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_PXE;
  8721. break;
  8722. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_ISCSIB:
  8723. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_ISCSI;
  8724. break;
  8725. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_FCOE_BOOT:
  8726. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_FCOE;
  8727. break;
  8728. case PORT_FEATURE_MBA_BOOT_AGENT_TYPE_NONE:
  8729. bp->common.boot_mode = FEATURE_ETH_BOOTMODE_NONE;
  8730. break;
  8731. }
  8732. pci_read_config_word(bp->pdev, bp->pm_cap + PCI_PM_PMC, &pmc);
  8733. bp->flags |= (pmc & PCI_PM_CAP_PME_D3cold) ? 0 : NO_WOL_FLAG;
  8734. BNX2X_DEV_INFO("%sWoL capable\n",
  8735. (bp->flags & NO_WOL_FLAG) ? "not " : "");
  8736. val = SHMEM_RD(bp, dev_info.shared_hw_config.part_num);
  8737. val2 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[4]);
  8738. val3 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[8]);
  8739. val4 = SHMEM_RD(bp, dev_info.shared_hw_config.part_num[12]);
  8740. dev_info(&bp->pdev->dev, "part number %X-%X-%X-%X\n",
  8741. val, val2, val3, val4);
  8742. }
  8743. #define IGU_FID(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_FID)
  8744. #define IGU_VEC(val) GET_FIELD((val), IGU_REG_MAPPING_MEMORY_VECTOR)
  8745. static int bnx2x_get_igu_cam_info(struct bnx2x *bp)
  8746. {
  8747. int pfid = BP_FUNC(bp);
  8748. int igu_sb_id;
  8749. u32 val;
  8750. u8 fid, igu_sb_cnt = 0;
  8751. bp->igu_base_sb = 0xff;
  8752. if (CHIP_INT_MODE_IS_BC(bp)) {
  8753. int vn = BP_VN(bp);
  8754. igu_sb_cnt = bp->igu_sb_cnt;
  8755. bp->igu_base_sb = (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn) *
  8756. FP_SB_MAX_E1x;
  8757. bp->igu_dsb_id = E1HVN_MAX * FP_SB_MAX_E1x +
  8758. (CHIP_MODE_IS_4_PORT(bp) ? pfid : vn);
  8759. return 0;
  8760. }
  8761. /* IGU in normal mode - read CAM */
  8762. for (igu_sb_id = 0; igu_sb_id < IGU_REG_MAPPING_MEMORY_SIZE;
  8763. igu_sb_id++) {
  8764. val = REG_RD(bp, IGU_REG_MAPPING_MEMORY + igu_sb_id * 4);
  8765. if (!(val & IGU_REG_MAPPING_MEMORY_VALID))
  8766. continue;
  8767. fid = IGU_FID(val);
  8768. if ((fid & IGU_FID_ENCODE_IS_PF)) {
  8769. if ((fid & IGU_FID_PF_NUM_MASK) != pfid)
  8770. continue;
  8771. if (IGU_VEC(val) == 0)
  8772. /* default status block */
  8773. bp->igu_dsb_id = igu_sb_id;
  8774. else {
  8775. if (bp->igu_base_sb == 0xff)
  8776. bp->igu_base_sb = igu_sb_id;
  8777. igu_sb_cnt++;
  8778. }
  8779. }
  8780. }
  8781. #ifdef CONFIG_PCI_MSI
  8782. /* Due to new PF resource allocation by MFW T7.4 and above, it's
  8783. * optional that number of CAM entries will not be equal to the value
  8784. * advertised in PCI.
  8785. * Driver should use the minimal value of both as the actual status
  8786. * block count
  8787. */
  8788. bp->igu_sb_cnt = min_t(int, bp->igu_sb_cnt, igu_sb_cnt);
  8789. #endif
  8790. if (igu_sb_cnt == 0) {
  8791. BNX2X_ERR("CAM configuration error\n");
  8792. return -EINVAL;
  8793. }
  8794. return 0;
  8795. }
  8796. static void bnx2x_link_settings_supported(struct bnx2x *bp, u32 switch_cfg)
  8797. {
  8798. int cfg_size = 0, idx, port = BP_PORT(bp);
  8799. /* Aggregation of supported attributes of all external phys */
  8800. bp->port.supported[0] = 0;
  8801. bp->port.supported[1] = 0;
  8802. switch (bp->link_params.num_phys) {
  8803. case 1:
  8804. bp->port.supported[0] = bp->link_params.phy[INT_PHY].supported;
  8805. cfg_size = 1;
  8806. break;
  8807. case 2:
  8808. bp->port.supported[0] = bp->link_params.phy[EXT_PHY1].supported;
  8809. cfg_size = 1;
  8810. break;
  8811. case 3:
  8812. if (bp->link_params.multi_phy_config &
  8813. PORT_HW_CFG_PHY_SWAPPED_ENABLED) {
  8814. bp->port.supported[1] =
  8815. bp->link_params.phy[EXT_PHY1].supported;
  8816. bp->port.supported[0] =
  8817. bp->link_params.phy[EXT_PHY2].supported;
  8818. } else {
  8819. bp->port.supported[0] =
  8820. bp->link_params.phy[EXT_PHY1].supported;
  8821. bp->port.supported[1] =
  8822. bp->link_params.phy[EXT_PHY2].supported;
  8823. }
  8824. cfg_size = 2;
  8825. break;
  8826. }
  8827. if (!(bp->port.supported[0] || bp->port.supported[1])) {
  8828. BNX2X_ERR("NVRAM config error. BAD phy config. PHY1 config 0x%x, PHY2 config 0x%x\n",
  8829. SHMEM_RD(bp,
  8830. dev_info.port_hw_config[port].external_phy_config),
  8831. SHMEM_RD(bp,
  8832. dev_info.port_hw_config[port].external_phy_config2));
  8833. return;
  8834. }
  8835. if (CHIP_IS_E3(bp))
  8836. bp->port.phy_addr = REG_RD(bp, MISC_REG_WC0_CTRL_PHY_ADDR);
  8837. else {
  8838. switch (switch_cfg) {
  8839. case SWITCH_CFG_1G:
  8840. bp->port.phy_addr = REG_RD(
  8841. bp, NIG_REG_SERDES0_CTRL_PHY_ADDR + port*0x10);
  8842. break;
  8843. case SWITCH_CFG_10G:
  8844. bp->port.phy_addr = REG_RD(
  8845. bp, NIG_REG_XGXS0_CTRL_PHY_ADDR + port*0x18);
  8846. break;
  8847. default:
  8848. BNX2X_ERR("BAD switch_cfg link_config 0x%x\n",
  8849. bp->port.link_config[0]);
  8850. return;
  8851. }
  8852. }
  8853. BNX2X_DEV_INFO("phy_addr 0x%x\n", bp->port.phy_addr);
  8854. /* mask what we support according to speed_cap_mask per configuration */
  8855. for (idx = 0; idx < cfg_size; idx++) {
  8856. if (!(bp->link_params.speed_cap_mask[idx] &
  8857. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_HALF))
  8858. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Half;
  8859. if (!(bp->link_params.speed_cap_mask[idx] &
  8860. PORT_HW_CFG_SPEED_CAPABILITY_D0_10M_FULL))
  8861. bp->port.supported[idx] &= ~SUPPORTED_10baseT_Full;
  8862. if (!(bp->link_params.speed_cap_mask[idx] &
  8863. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_HALF))
  8864. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Half;
  8865. if (!(bp->link_params.speed_cap_mask[idx] &
  8866. PORT_HW_CFG_SPEED_CAPABILITY_D0_100M_FULL))
  8867. bp->port.supported[idx] &= ~SUPPORTED_100baseT_Full;
  8868. if (!(bp->link_params.speed_cap_mask[idx] &
  8869. PORT_HW_CFG_SPEED_CAPABILITY_D0_1G))
  8870. bp->port.supported[idx] &= ~(SUPPORTED_1000baseT_Half |
  8871. SUPPORTED_1000baseT_Full);
  8872. if (!(bp->link_params.speed_cap_mask[idx] &
  8873. PORT_HW_CFG_SPEED_CAPABILITY_D0_2_5G))
  8874. bp->port.supported[idx] &= ~SUPPORTED_2500baseX_Full;
  8875. if (!(bp->link_params.speed_cap_mask[idx] &
  8876. PORT_HW_CFG_SPEED_CAPABILITY_D0_10G))
  8877. bp->port.supported[idx] &= ~SUPPORTED_10000baseT_Full;
  8878. if (!(bp->link_params.speed_cap_mask[idx] &
  8879. PORT_HW_CFG_SPEED_CAPABILITY_D0_20G))
  8880. bp->port.supported[idx] &= ~SUPPORTED_20000baseKR2_Full;
  8881. }
  8882. BNX2X_DEV_INFO("supported 0x%x 0x%x\n", bp->port.supported[0],
  8883. bp->port.supported[1]);
  8884. }
  8885. static void bnx2x_link_settings_requested(struct bnx2x *bp)
  8886. {
  8887. u32 link_config, idx, cfg_size = 0;
  8888. bp->port.advertising[0] = 0;
  8889. bp->port.advertising[1] = 0;
  8890. switch (bp->link_params.num_phys) {
  8891. case 1:
  8892. case 2:
  8893. cfg_size = 1;
  8894. break;
  8895. case 3:
  8896. cfg_size = 2;
  8897. break;
  8898. }
  8899. for (idx = 0; idx < cfg_size; idx++) {
  8900. bp->link_params.req_duplex[idx] = DUPLEX_FULL;
  8901. link_config = bp->port.link_config[idx];
  8902. switch (link_config & PORT_FEATURE_LINK_SPEED_MASK) {
  8903. case PORT_FEATURE_LINK_SPEED_AUTO:
  8904. if (bp->port.supported[idx] & SUPPORTED_Autoneg) {
  8905. bp->link_params.req_line_speed[idx] =
  8906. SPEED_AUTO_NEG;
  8907. bp->port.advertising[idx] |=
  8908. bp->port.supported[idx];
  8909. if (bp->link_params.phy[EXT_PHY1].type ==
  8910. PORT_HW_CFG_XGXS_EXT_PHY_TYPE_BCM84833)
  8911. bp->port.advertising[idx] |=
  8912. (SUPPORTED_100baseT_Half |
  8913. SUPPORTED_100baseT_Full);
  8914. } else {
  8915. /* force 10G, no AN */
  8916. bp->link_params.req_line_speed[idx] =
  8917. SPEED_10000;
  8918. bp->port.advertising[idx] |=
  8919. (ADVERTISED_10000baseT_Full |
  8920. ADVERTISED_FIBRE);
  8921. continue;
  8922. }
  8923. break;
  8924. case PORT_FEATURE_LINK_SPEED_10M_FULL:
  8925. if (bp->port.supported[idx] & SUPPORTED_10baseT_Full) {
  8926. bp->link_params.req_line_speed[idx] =
  8927. SPEED_10;
  8928. bp->port.advertising[idx] |=
  8929. (ADVERTISED_10baseT_Full |
  8930. ADVERTISED_TP);
  8931. } else {
  8932. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8933. link_config,
  8934. bp->link_params.speed_cap_mask[idx]);
  8935. return;
  8936. }
  8937. break;
  8938. case PORT_FEATURE_LINK_SPEED_10M_HALF:
  8939. if (bp->port.supported[idx] & SUPPORTED_10baseT_Half) {
  8940. bp->link_params.req_line_speed[idx] =
  8941. SPEED_10;
  8942. bp->link_params.req_duplex[idx] =
  8943. DUPLEX_HALF;
  8944. bp->port.advertising[idx] |=
  8945. (ADVERTISED_10baseT_Half |
  8946. ADVERTISED_TP);
  8947. } else {
  8948. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8949. link_config,
  8950. bp->link_params.speed_cap_mask[idx]);
  8951. return;
  8952. }
  8953. break;
  8954. case PORT_FEATURE_LINK_SPEED_100M_FULL:
  8955. if (bp->port.supported[idx] &
  8956. SUPPORTED_100baseT_Full) {
  8957. bp->link_params.req_line_speed[idx] =
  8958. SPEED_100;
  8959. bp->port.advertising[idx] |=
  8960. (ADVERTISED_100baseT_Full |
  8961. ADVERTISED_TP);
  8962. } else {
  8963. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8964. link_config,
  8965. bp->link_params.speed_cap_mask[idx]);
  8966. return;
  8967. }
  8968. break;
  8969. case PORT_FEATURE_LINK_SPEED_100M_HALF:
  8970. if (bp->port.supported[idx] &
  8971. SUPPORTED_100baseT_Half) {
  8972. bp->link_params.req_line_speed[idx] =
  8973. SPEED_100;
  8974. bp->link_params.req_duplex[idx] =
  8975. DUPLEX_HALF;
  8976. bp->port.advertising[idx] |=
  8977. (ADVERTISED_100baseT_Half |
  8978. ADVERTISED_TP);
  8979. } else {
  8980. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8981. link_config,
  8982. bp->link_params.speed_cap_mask[idx]);
  8983. return;
  8984. }
  8985. break;
  8986. case PORT_FEATURE_LINK_SPEED_1G:
  8987. if (bp->port.supported[idx] &
  8988. SUPPORTED_1000baseT_Full) {
  8989. bp->link_params.req_line_speed[idx] =
  8990. SPEED_1000;
  8991. bp->port.advertising[idx] |=
  8992. (ADVERTISED_1000baseT_Full |
  8993. ADVERTISED_TP);
  8994. } else {
  8995. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  8996. link_config,
  8997. bp->link_params.speed_cap_mask[idx]);
  8998. return;
  8999. }
  9000. break;
  9001. case PORT_FEATURE_LINK_SPEED_2_5G:
  9002. if (bp->port.supported[idx] &
  9003. SUPPORTED_2500baseX_Full) {
  9004. bp->link_params.req_line_speed[idx] =
  9005. SPEED_2500;
  9006. bp->port.advertising[idx] |=
  9007. (ADVERTISED_2500baseX_Full |
  9008. ADVERTISED_TP);
  9009. } else {
  9010. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9011. link_config,
  9012. bp->link_params.speed_cap_mask[idx]);
  9013. return;
  9014. }
  9015. break;
  9016. case PORT_FEATURE_LINK_SPEED_10G_CX4:
  9017. if (bp->port.supported[idx] &
  9018. SUPPORTED_10000baseT_Full) {
  9019. bp->link_params.req_line_speed[idx] =
  9020. SPEED_10000;
  9021. bp->port.advertising[idx] |=
  9022. (ADVERTISED_10000baseT_Full |
  9023. ADVERTISED_FIBRE);
  9024. } else {
  9025. BNX2X_ERR("NVRAM config error. Invalid link_config 0x%x speed_cap_mask 0x%x\n",
  9026. link_config,
  9027. bp->link_params.speed_cap_mask[idx]);
  9028. return;
  9029. }
  9030. break;
  9031. case PORT_FEATURE_LINK_SPEED_20G:
  9032. bp->link_params.req_line_speed[idx] = SPEED_20000;
  9033. break;
  9034. default:
  9035. BNX2X_ERR("NVRAM config error. BAD link speed link_config 0x%x\n",
  9036. link_config);
  9037. bp->link_params.req_line_speed[idx] =
  9038. SPEED_AUTO_NEG;
  9039. bp->port.advertising[idx] =
  9040. bp->port.supported[idx];
  9041. break;
  9042. }
  9043. bp->link_params.req_flow_ctrl[idx] = (link_config &
  9044. PORT_FEATURE_FLOW_CONTROL_MASK);
  9045. if (bp->link_params.req_flow_ctrl[idx] ==
  9046. BNX2X_FLOW_CTRL_AUTO) {
  9047. if (!(bp->port.supported[idx] & SUPPORTED_Autoneg))
  9048. bp->link_params.req_flow_ctrl[idx] =
  9049. BNX2X_FLOW_CTRL_NONE;
  9050. else
  9051. bnx2x_set_requested_fc(bp);
  9052. }
  9053. BNX2X_DEV_INFO("req_line_speed %d req_duplex %d req_flow_ctrl 0x%x advertising 0x%x\n",
  9054. bp->link_params.req_line_speed[idx],
  9055. bp->link_params.req_duplex[idx],
  9056. bp->link_params.req_flow_ctrl[idx],
  9057. bp->port.advertising[idx]);
  9058. }
  9059. }
  9060. static void bnx2x_set_mac_buf(u8 *mac_buf, u32 mac_lo, u16 mac_hi)
  9061. {
  9062. __be16 mac_hi_be = cpu_to_be16(mac_hi);
  9063. __be32 mac_lo_be = cpu_to_be32(mac_lo);
  9064. memcpy(mac_buf, &mac_hi_be, sizeof(mac_hi_be));
  9065. memcpy(mac_buf + sizeof(mac_hi_be), &mac_lo_be, sizeof(mac_lo_be));
  9066. }
  9067. static void bnx2x_get_port_hwinfo(struct bnx2x *bp)
  9068. {
  9069. int port = BP_PORT(bp);
  9070. u32 config;
  9071. u32 ext_phy_type, ext_phy_config, eee_mode;
  9072. bp->link_params.bp = bp;
  9073. bp->link_params.port = port;
  9074. bp->link_params.lane_config =
  9075. SHMEM_RD(bp, dev_info.port_hw_config[port].lane_config);
  9076. bp->link_params.speed_cap_mask[0] =
  9077. SHMEM_RD(bp,
  9078. dev_info.port_hw_config[port].speed_capability_mask) &
  9079. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9080. bp->link_params.speed_cap_mask[1] =
  9081. SHMEM_RD(bp,
  9082. dev_info.port_hw_config[port].speed_capability_mask2) &
  9083. PORT_HW_CFG_SPEED_CAPABILITY_D0_MASK;
  9084. bp->port.link_config[0] =
  9085. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config);
  9086. bp->port.link_config[1] =
  9087. SHMEM_RD(bp, dev_info.port_feature_config[port].link_config2);
  9088. bp->link_params.multi_phy_config =
  9089. SHMEM_RD(bp, dev_info.port_hw_config[port].multi_phy_config);
  9090. /* If the device is capable of WoL, set the default state according
  9091. * to the HW
  9092. */
  9093. config = SHMEM_RD(bp, dev_info.port_feature_config[port].config);
  9094. bp->wol = (!(bp->flags & NO_WOL_FLAG) &&
  9095. (config & PORT_FEATURE_WOL_ENABLED));
  9096. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9097. PORT_FEAT_CFG_STORAGE_PERSONALITY_FCOE && !IS_MF(bp))
  9098. bp->flags |= NO_ISCSI_FLAG;
  9099. if ((config & PORT_FEAT_CFG_STORAGE_PERSONALITY_MASK) ==
  9100. PORT_FEAT_CFG_STORAGE_PERSONALITY_ISCSI && !(IS_MF(bp)))
  9101. bp->flags |= NO_FCOE_FLAG;
  9102. BNX2X_DEV_INFO("lane_config 0x%08x speed_cap_mask0 0x%08x link_config0 0x%08x\n",
  9103. bp->link_params.lane_config,
  9104. bp->link_params.speed_cap_mask[0],
  9105. bp->port.link_config[0]);
  9106. bp->link_params.switch_cfg = (bp->port.link_config[0] &
  9107. PORT_FEATURE_CONNECTED_SWITCH_MASK);
  9108. bnx2x_phy_probe(&bp->link_params);
  9109. bnx2x_link_settings_supported(bp, bp->link_params.switch_cfg);
  9110. bnx2x_link_settings_requested(bp);
  9111. /*
  9112. * If connected directly, work with the internal PHY, otherwise, work
  9113. * with the external PHY
  9114. */
  9115. ext_phy_config =
  9116. SHMEM_RD(bp,
  9117. dev_info.port_hw_config[port].external_phy_config);
  9118. ext_phy_type = XGXS_EXT_PHY_TYPE(ext_phy_config);
  9119. if (ext_phy_type == PORT_HW_CFG_XGXS_EXT_PHY_TYPE_DIRECT)
  9120. bp->mdio.prtad = bp->port.phy_addr;
  9121. else if ((ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_FAILURE) &&
  9122. (ext_phy_type != PORT_HW_CFG_XGXS_EXT_PHY_TYPE_NOT_CONN))
  9123. bp->mdio.prtad =
  9124. XGXS_EXT_PHY_ADDR(ext_phy_config);
  9125. /* Configure link feature according to nvram value */
  9126. eee_mode = (((SHMEM_RD(bp, dev_info.
  9127. port_feature_config[port].eee_power_mode)) &
  9128. PORT_FEAT_CFG_EEE_POWER_MODE_MASK) >>
  9129. PORT_FEAT_CFG_EEE_POWER_MODE_SHIFT);
  9130. if (eee_mode != PORT_FEAT_CFG_EEE_POWER_MODE_DISABLED) {
  9131. bp->link_params.eee_mode = EEE_MODE_ADV_LPI |
  9132. EEE_MODE_ENABLE_LPI |
  9133. EEE_MODE_OUTPUT_TIME;
  9134. } else {
  9135. bp->link_params.eee_mode = 0;
  9136. }
  9137. }
  9138. void bnx2x_get_iscsi_info(struct bnx2x *bp)
  9139. {
  9140. u32 no_flags = NO_ISCSI_FLAG;
  9141. int port = BP_PORT(bp);
  9142. u32 max_iscsi_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9143. drv_lic_key[port].max_iscsi_conn);
  9144. if (!CNIC_SUPPORT(bp)) {
  9145. bp->flags |= no_flags;
  9146. return;
  9147. }
  9148. /* Get the number of maximum allowed iSCSI connections */
  9149. bp->cnic_eth_dev.max_iscsi_conn =
  9150. (max_iscsi_conn & BNX2X_MAX_ISCSI_INIT_CONN_MASK) >>
  9151. BNX2X_MAX_ISCSI_INIT_CONN_SHIFT;
  9152. BNX2X_DEV_INFO("max_iscsi_conn 0x%x\n",
  9153. bp->cnic_eth_dev.max_iscsi_conn);
  9154. /*
  9155. * If maximum allowed number of connections is zero -
  9156. * disable the feature.
  9157. */
  9158. if (!bp->cnic_eth_dev.max_iscsi_conn)
  9159. bp->flags |= no_flags;
  9160. }
  9161. static void bnx2x_get_ext_wwn_info(struct bnx2x *bp, int func)
  9162. {
  9163. /* Port info */
  9164. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9165. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_upper);
  9166. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9167. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_port_name_lower);
  9168. /* Node info */
  9169. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9170. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_upper);
  9171. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9172. MF_CFG_RD(bp, func_ext_config[func].fcoe_wwn_node_name_lower);
  9173. }
  9174. static int bnx2x_shared_fcoe_funcs(struct bnx2x *bp)
  9175. {
  9176. u8 count = 0;
  9177. if (IS_MF(bp)) {
  9178. u8 fid;
  9179. /* iterate over absolute function ids for this path: */
  9180. for (fid = BP_PATH(bp); fid < E2_FUNC_MAX * 2; fid += 2) {
  9181. if (IS_MF_SD(bp)) {
  9182. u32 cfg = MF_CFG_RD(bp,
  9183. func_mf_config[fid].config);
  9184. if (!(cfg & FUNC_MF_CFG_FUNC_HIDE) &&
  9185. ((cfg & FUNC_MF_CFG_PROTOCOL_MASK) ==
  9186. FUNC_MF_CFG_PROTOCOL_FCOE))
  9187. count++;
  9188. } else {
  9189. u32 cfg = MF_CFG_RD(bp,
  9190. func_ext_config[fid].
  9191. func_cfg);
  9192. if ((cfg & MACP_FUNC_CFG_FLAGS_ENABLED) &&
  9193. (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD))
  9194. count++;
  9195. }
  9196. }
  9197. } else { /* SF */
  9198. int port, port_cnt = CHIP_MODE_IS_4_PORT(bp) ? 2 : 1;
  9199. for (port = 0; port < port_cnt; port++) {
  9200. u32 lic = SHMEM_RD(bp,
  9201. drv_lic_key[port].max_fcoe_conn) ^
  9202. FW_ENCODE_32BIT_PATTERN;
  9203. if (lic)
  9204. count++;
  9205. }
  9206. }
  9207. return count;
  9208. }
  9209. static void bnx2x_get_fcoe_info(struct bnx2x *bp)
  9210. {
  9211. int port = BP_PORT(bp);
  9212. int func = BP_ABS_FUNC(bp);
  9213. u32 max_fcoe_conn = FW_ENCODE_32BIT_PATTERN ^ SHMEM_RD(bp,
  9214. drv_lic_key[port].max_fcoe_conn);
  9215. u8 num_fcoe_func = bnx2x_shared_fcoe_funcs(bp);
  9216. if (!CNIC_SUPPORT(bp)) {
  9217. bp->flags |= NO_FCOE_FLAG;
  9218. return;
  9219. }
  9220. /* Get the number of maximum allowed FCoE connections */
  9221. bp->cnic_eth_dev.max_fcoe_conn =
  9222. (max_fcoe_conn & BNX2X_MAX_FCOE_INIT_CONN_MASK) >>
  9223. BNX2X_MAX_FCOE_INIT_CONN_SHIFT;
  9224. /* Calculate the number of maximum allowed FCoE tasks */
  9225. bp->cnic_eth_dev.max_fcoe_exchanges = MAX_NUM_FCOE_TASKS_PER_ENGINE;
  9226. /* check if FCoE resources must be shared between different functions */
  9227. if (num_fcoe_func)
  9228. bp->cnic_eth_dev.max_fcoe_exchanges /= num_fcoe_func;
  9229. /* Read the WWN: */
  9230. if (!IS_MF(bp)) {
  9231. /* Port info */
  9232. bp->cnic_eth_dev.fcoe_wwn_port_name_hi =
  9233. SHMEM_RD(bp,
  9234. dev_info.port_hw_config[port].
  9235. fcoe_wwn_port_name_upper);
  9236. bp->cnic_eth_dev.fcoe_wwn_port_name_lo =
  9237. SHMEM_RD(bp,
  9238. dev_info.port_hw_config[port].
  9239. fcoe_wwn_port_name_lower);
  9240. /* Node info */
  9241. bp->cnic_eth_dev.fcoe_wwn_node_name_hi =
  9242. SHMEM_RD(bp,
  9243. dev_info.port_hw_config[port].
  9244. fcoe_wwn_node_name_upper);
  9245. bp->cnic_eth_dev.fcoe_wwn_node_name_lo =
  9246. SHMEM_RD(bp,
  9247. dev_info.port_hw_config[port].
  9248. fcoe_wwn_node_name_lower);
  9249. } else if (!IS_MF_SD(bp)) {
  9250. /*
  9251. * Read the WWN info only if the FCoE feature is enabled for
  9252. * this function.
  9253. */
  9254. if (BNX2X_MF_EXT_PROTOCOL_FCOE(bp) && !CHIP_IS_E1x(bp))
  9255. bnx2x_get_ext_wwn_info(bp, func);
  9256. } else if (IS_MF_FCOE_SD(bp) && !CHIP_IS_E1x(bp)) {
  9257. bnx2x_get_ext_wwn_info(bp, func);
  9258. }
  9259. BNX2X_DEV_INFO("max_fcoe_conn 0x%x\n", bp->cnic_eth_dev.max_fcoe_conn);
  9260. /*
  9261. * If maximum allowed number of connections is zero -
  9262. * disable the feature.
  9263. */
  9264. if (!bp->cnic_eth_dev.max_fcoe_conn)
  9265. bp->flags |= NO_FCOE_FLAG;
  9266. }
  9267. static void bnx2x_get_cnic_info(struct bnx2x *bp)
  9268. {
  9269. /*
  9270. * iSCSI may be dynamically disabled but reading
  9271. * info here we will decrease memory usage by driver
  9272. * if the feature is disabled for good
  9273. */
  9274. bnx2x_get_iscsi_info(bp);
  9275. bnx2x_get_fcoe_info(bp);
  9276. }
  9277. static void bnx2x_get_cnic_mac_hwinfo(struct bnx2x *bp)
  9278. {
  9279. u32 val, val2;
  9280. int func = BP_ABS_FUNC(bp);
  9281. int port = BP_PORT(bp);
  9282. u8 *iscsi_mac = bp->cnic_eth_dev.iscsi_mac;
  9283. u8 *fip_mac = bp->fip_mac;
  9284. if (IS_MF(bp)) {
  9285. /* iSCSI and FCoE NPAR MACs: if there is no either iSCSI or
  9286. * FCoE MAC then the appropriate feature should be disabled.
  9287. * In non SD mode features configuration comes from struct
  9288. * func_ext_config.
  9289. */
  9290. if (!IS_MF_SD(bp) && !CHIP_IS_E1x(bp)) {
  9291. u32 cfg = MF_CFG_RD(bp, func_ext_config[func].func_cfg);
  9292. if (cfg & MACP_FUNC_CFG_FLAGS_ISCSI_OFFLOAD) {
  9293. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9294. iscsi_mac_addr_upper);
  9295. val = MF_CFG_RD(bp, func_ext_config[func].
  9296. iscsi_mac_addr_lower);
  9297. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9298. BNX2X_DEV_INFO
  9299. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9300. } else {
  9301. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9302. }
  9303. if (cfg & MACP_FUNC_CFG_FLAGS_FCOE_OFFLOAD) {
  9304. val2 = MF_CFG_RD(bp, func_ext_config[func].
  9305. fcoe_mac_addr_upper);
  9306. val = MF_CFG_RD(bp, func_ext_config[func].
  9307. fcoe_mac_addr_lower);
  9308. bnx2x_set_mac_buf(fip_mac, val, val2);
  9309. BNX2X_DEV_INFO
  9310. ("Read FCoE L2 MAC: %pM\n", fip_mac);
  9311. } else {
  9312. bp->flags |= NO_FCOE_FLAG;
  9313. }
  9314. bp->mf_ext_config = cfg;
  9315. } else { /* SD MODE */
  9316. if (BNX2X_IS_MF_SD_PROTOCOL_ISCSI(bp)) {
  9317. /* use primary mac as iscsi mac */
  9318. memcpy(iscsi_mac, bp->dev->dev_addr, ETH_ALEN);
  9319. BNX2X_DEV_INFO("SD ISCSI MODE\n");
  9320. BNX2X_DEV_INFO
  9321. ("Read iSCSI MAC: %pM\n", iscsi_mac);
  9322. } else if (BNX2X_IS_MF_SD_PROTOCOL_FCOE(bp)) {
  9323. /* use primary mac as fip mac */
  9324. memcpy(fip_mac, bp->dev->dev_addr, ETH_ALEN);
  9325. BNX2X_DEV_INFO("SD FCoE MODE\n");
  9326. BNX2X_DEV_INFO
  9327. ("Read FIP MAC: %pM\n", fip_mac);
  9328. }
  9329. }
  9330. /* If this is a storage-only interface, use SAN mac as
  9331. * primary MAC. Notice that for SD this is already the case,
  9332. * as the SAN mac was copied from the primary MAC.
  9333. */
  9334. if (IS_MF_FCOE_AFEX(bp))
  9335. memcpy(bp->dev->dev_addr, fip_mac, ETH_ALEN);
  9336. } else {
  9337. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9338. iscsi_mac_upper);
  9339. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9340. iscsi_mac_lower);
  9341. bnx2x_set_mac_buf(iscsi_mac, val, val2);
  9342. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9343. fcoe_fip_mac_upper);
  9344. val = SHMEM_RD(bp, dev_info.port_hw_config[port].
  9345. fcoe_fip_mac_lower);
  9346. bnx2x_set_mac_buf(fip_mac, val, val2);
  9347. }
  9348. /* Disable iSCSI OOO if MAC configuration is invalid. */
  9349. if (!is_valid_ether_addr(iscsi_mac)) {
  9350. bp->flags |= NO_ISCSI_OOO_FLAG | NO_ISCSI_FLAG;
  9351. memset(iscsi_mac, 0, ETH_ALEN);
  9352. }
  9353. /* Disable FCoE if MAC configuration is invalid. */
  9354. if (!is_valid_ether_addr(fip_mac)) {
  9355. bp->flags |= NO_FCOE_FLAG;
  9356. memset(bp->fip_mac, 0, ETH_ALEN);
  9357. }
  9358. }
  9359. static void bnx2x_get_mac_hwinfo(struct bnx2x *bp)
  9360. {
  9361. u32 val, val2;
  9362. int func = BP_ABS_FUNC(bp);
  9363. int port = BP_PORT(bp);
  9364. /* Zero primary MAC configuration */
  9365. memset(bp->dev->dev_addr, 0, ETH_ALEN);
  9366. if (BP_NOMCP(bp)) {
  9367. BNX2X_ERROR("warning: random MAC workaround active\n");
  9368. eth_hw_addr_random(bp->dev);
  9369. } else if (IS_MF(bp)) {
  9370. val2 = MF_CFG_RD(bp, func_mf_config[func].mac_upper);
  9371. val = MF_CFG_RD(bp, func_mf_config[func].mac_lower);
  9372. if ((val2 != FUNC_MF_CFG_UPPERMAC_DEFAULT) &&
  9373. (val != FUNC_MF_CFG_LOWERMAC_DEFAULT))
  9374. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9375. if (CNIC_SUPPORT(bp))
  9376. bnx2x_get_cnic_mac_hwinfo(bp);
  9377. } else {
  9378. /* in SF read MACs from port configuration */
  9379. val2 = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_upper);
  9380. val = SHMEM_RD(bp, dev_info.port_hw_config[port].mac_lower);
  9381. bnx2x_set_mac_buf(bp->dev->dev_addr, val, val2);
  9382. if (CNIC_SUPPORT(bp))
  9383. bnx2x_get_cnic_mac_hwinfo(bp);
  9384. }
  9385. memcpy(bp->link_params.mac_addr, bp->dev->dev_addr, ETH_ALEN);
  9386. if (!bnx2x_is_valid_ether_addr(bp, bp->dev->dev_addr))
  9387. dev_err(&bp->pdev->dev,
  9388. "bad Ethernet MAC address configuration: %pM\n"
  9389. "change it manually before bringing up the appropriate network interface\n",
  9390. bp->dev->dev_addr);
  9391. }
  9392. static bool bnx2x_get_dropless_info(struct bnx2x *bp)
  9393. {
  9394. int tmp;
  9395. u32 cfg;
  9396. if (IS_MF(bp) && !CHIP_IS_E1x(bp)) {
  9397. /* Take function: tmp = func */
  9398. tmp = BP_ABS_FUNC(bp);
  9399. cfg = MF_CFG_RD(bp, func_ext_config[tmp].func_cfg);
  9400. cfg = !!(cfg & MACP_FUNC_CFG_PAUSE_ON_HOST_RING);
  9401. } else {
  9402. /* Take port: tmp = port */
  9403. tmp = BP_PORT(bp);
  9404. cfg = SHMEM_RD(bp,
  9405. dev_info.port_hw_config[tmp].generic_features);
  9406. cfg = !!(cfg & PORT_HW_CFG_PAUSE_ON_HOST_RING_ENABLED);
  9407. }
  9408. return cfg;
  9409. }
  9410. static int bnx2x_get_hwinfo(struct bnx2x *bp)
  9411. {
  9412. int /*abs*/func = BP_ABS_FUNC(bp);
  9413. int vn;
  9414. u32 val = 0;
  9415. int rc = 0;
  9416. bnx2x_get_common_hwinfo(bp);
  9417. /*
  9418. * initialize IGU parameters
  9419. */
  9420. if (CHIP_IS_E1x(bp)) {
  9421. bp->common.int_block = INT_BLOCK_HC;
  9422. bp->igu_dsb_id = DEF_SB_IGU_ID;
  9423. bp->igu_base_sb = 0;
  9424. } else {
  9425. bp->common.int_block = INT_BLOCK_IGU;
  9426. /* do not allow device reset during IGU info processing */
  9427. bnx2x_acquire_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9428. val = REG_RD(bp, IGU_REG_BLOCK_CONFIGURATION);
  9429. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9430. int tout = 5000;
  9431. BNX2X_DEV_INFO("FORCING Normal Mode\n");
  9432. val &= ~(IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN);
  9433. REG_WR(bp, IGU_REG_BLOCK_CONFIGURATION, val);
  9434. REG_WR(bp, IGU_REG_RESET_MEMORIES, 0x7f);
  9435. while (tout && REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9436. tout--;
  9437. usleep_range(1000, 2000);
  9438. }
  9439. if (REG_RD(bp, IGU_REG_RESET_MEMORIES)) {
  9440. dev_err(&bp->pdev->dev,
  9441. "FORCING Normal Mode failed!!!\n");
  9442. bnx2x_release_hw_lock(bp,
  9443. HW_LOCK_RESOURCE_RESET);
  9444. return -EPERM;
  9445. }
  9446. }
  9447. if (val & IGU_BLOCK_CONFIGURATION_REG_BACKWARD_COMP_EN) {
  9448. BNX2X_DEV_INFO("IGU Backward Compatible Mode\n");
  9449. bp->common.int_block |= INT_BLOCK_MODE_BW_COMP;
  9450. } else
  9451. BNX2X_DEV_INFO("IGU Normal Mode\n");
  9452. rc = bnx2x_get_igu_cam_info(bp);
  9453. bnx2x_release_hw_lock(bp, HW_LOCK_RESOURCE_RESET);
  9454. if (rc)
  9455. return rc;
  9456. }
  9457. /*
  9458. * set base FW non-default (fast path) status block id, this value is
  9459. * used to initialize the fw_sb_id saved on the fp/queue structure to
  9460. * determine the id used by the FW.
  9461. */
  9462. if (CHIP_IS_E1x(bp))
  9463. bp->base_fw_ndsb = BP_PORT(bp) * FP_SB_MAX_E1x + BP_L_ID(bp);
  9464. else /*
  9465. * 57712 - we currently use one FW SB per IGU SB (Rx and Tx of
  9466. * the same queue are indicated on the same IGU SB). So we prefer
  9467. * FW and IGU SBs to be the same value.
  9468. */
  9469. bp->base_fw_ndsb = bp->igu_base_sb;
  9470. BNX2X_DEV_INFO("igu_dsb_id %d igu_base_sb %d igu_sb_cnt %d\n"
  9471. "base_fw_ndsb %d\n", bp->igu_dsb_id, bp->igu_base_sb,
  9472. bp->igu_sb_cnt, bp->base_fw_ndsb);
  9473. /*
  9474. * Initialize MF configuration
  9475. */
  9476. bp->mf_ov = 0;
  9477. bp->mf_mode = 0;
  9478. vn = BP_VN(bp);
  9479. if (!CHIP_IS_E1(bp) && !BP_NOMCP(bp)) {
  9480. BNX2X_DEV_INFO("shmem2base 0x%x, size %d, mfcfg offset %d\n",
  9481. bp->common.shmem2_base, SHMEM2_RD(bp, size),
  9482. (u32)offsetof(struct shmem2_region, mf_cfg_addr));
  9483. if (SHMEM2_HAS(bp, mf_cfg_addr))
  9484. bp->common.mf_cfg_base = SHMEM2_RD(bp, mf_cfg_addr);
  9485. else
  9486. bp->common.mf_cfg_base = bp->common.shmem_base +
  9487. offsetof(struct shmem_region, func_mb) +
  9488. E1H_FUNC_MAX * sizeof(struct drv_func_mb);
  9489. /*
  9490. * get mf configuration:
  9491. * 1. Existence of MF configuration
  9492. * 2. MAC address must be legal (check only upper bytes)
  9493. * for Switch-Independent mode;
  9494. * OVLAN must be legal for Switch-Dependent mode
  9495. * 3. SF_MODE configures specific MF mode
  9496. */
  9497. if (bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9498. /* get mf configuration */
  9499. val = SHMEM_RD(bp,
  9500. dev_info.shared_feature_config.config);
  9501. val &= SHARED_FEAT_CFG_FORCE_SF_MODE_MASK;
  9502. switch (val) {
  9503. case SHARED_FEAT_CFG_FORCE_SF_MODE_SWITCH_INDEPT:
  9504. val = MF_CFG_RD(bp, func_mf_config[func].
  9505. mac_upper);
  9506. /* check for legal mac (upper bytes)*/
  9507. if (val != 0xffff) {
  9508. bp->mf_mode = MULTI_FUNCTION_SI;
  9509. bp->mf_config[vn] = MF_CFG_RD(bp,
  9510. func_mf_config[func].config);
  9511. } else
  9512. BNX2X_DEV_INFO("illegal MAC address for SI\n");
  9513. break;
  9514. case SHARED_FEAT_CFG_FORCE_SF_MODE_AFEX_MODE:
  9515. if ((!CHIP_IS_E1x(bp)) &&
  9516. (MF_CFG_RD(bp, func_mf_config[func].
  9517. mac_upper) != 0xffff) &&
  9518. (SHMEM2_HAS(bp,
  9519. afex_driver_support))) {
  9520. bp->mf_mode = MULTI_FUNCTION_AFEX;
  9521. bp->mf_config[vn] = MF_CFG_RD(bp,
  9522. func_mf_config[func].config);
  9523. } else {
  9524. BNX2X_DEV_INFO("can not configure afex mode\n");
  9525. }
  9526. break;
  9527. case SHARED_FEAT_CFG_FORCE_SF_MODE_MF_ALLOWED:
  9528. /* get OV configuration */
  9529. val = MF_CFG_RD(bp,
  9530. func_mf_config[FUNC_0].e1hov_tag);
  9531. val &= FUNC_MF_CFG_E1HOV_TAG_MASK;
  9532. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9533. bp->mf_mode = MULTI_FUNCTION_SD;
  9534. bp->mf_config[vn] = MF_CFG_RD(bp,
  9535. func_mf_config[func].config);
  9536. } else
  9537. BNX2X_DEV_INFO("illegal OV for SD\n");
  9538. break;
  9539. case SHARED_FEAT_CFG_FORCE_SF_MODE_FORCED_SF:
  9540. bp->mf_config[vn] = 0;
  9541. break;
  9542. default:
  9543. /* Unknown configuration: reset mf_config */
  9544. bp->mf_config[vn] = 0;
  9545. BNX2X_DEV_INFO("unknown MF mode 0x%x\n", val);
  9546. }
  9547. }
  9548. BNX2X_DEV_INFO("%s function mode\n",
  9549. IS_MF(bp) ? "multi" : "single");
  9550. switch (bp->mf_mode) {
  9551. case MULTI_FUNCTION_SD:
  9552. val = MF_CFG_RD(bp, func_mf_config[func].e1hov_tag) &
  9553. FUNC_MF_CFG_E1HOV_TAG_MASK;
  9554. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT) {
  9555. bp->mf_ov = val;
  9556. bp->path_has_ovlan = true;
  9557. BNX2X_DEV_INFO("MF OV for func %d is %d (0x%04x)\n",
  9558. func, bp->mf_ov, bp->mf_ov);
  9559. } else {
  9560. dev_err(&bp->pdev->dev,
  9561. "No valid MF OV for func %d, aborting\n",
  9562. func);
  9563. return -EPERM;
  9564. }
  9565. break;
  9566. case MULTI_FUNCTION_AFEX:
  9567. BNX2X_DEV_INFO("func %d is in MF afex mode\n", func);
  9568. break;
  9569. case MULTI_FUNCTION_SI:
  9570. BNX2X_DEV_INFO("func %d is in MF switch-independent mode\n",
  9571. func);
  9572. break;
  9573. default:
  9574. if (vn) {
  9575. dev_err(&bp->pdev->dev,
  9576. "VN %d is in a single function mode, aborting\n",
  9577. vn);
  9578. return -EPERM;
  9579. }
  9580. break;
  9581. }
  9582. /* check if other port on the path needs ovlan:
  9583. * Since MF configuration is shared between ports
  9584. * Possible mixed modes are only
  9585. * {SF, SI} {SF, SD} {SD, SF} {SI, SF}
  9586. */
  9587. if (CHIP_MODE_IS_4_PORT(bp) &&
  9588. !bp->path_has_ovlan &&
  9589. !IS_MF(bp) &&
  9590. bp->common.mf_cfg_base != SHMEM_MF_CFG_ADDR_NONE) {
  9591. u8 other_port = !BP_PORT(bp);
  9592. u8 other_func = BP_PATH(bp) + 2*other_port;
  9593. val = MF_CFG_RD(bp,
  9594. func_mf_config[other_func].e1hov_tag);
  9595. if (val != FUNC_MF_CFG_E1HOV_TAG_DEFAULT)
  9596. bp->path_has_ovlan = true;
  9597. }
  9598. }
  9599. /* adjust igu_sb_cnt to MF for E1x */
  9600. if (CHIP_IS_E1x(bp) && IS_MF(bp))
  9601. bp->igu_sb_cnt /= E1HVN_MAX;
  9602. /* port info */
  9603. bnx2x_get_port_hwinfo(bp);
  9604. /* Get MAC addresses */
  9605. bnx2x_get_mac_hwinfo(bp);
  9606. bnx2x_get_cnic_info(bp);
  9607. return rc;
  9608. }
  9609. static void bnx2x_read_fwinfo(struct bnx2x *bp)
  9610. {
  9611. int cnt, i, block_end, rodi;
  9612. char vpd_start[BNX2X_VPD_LEN+1];
  9613. char str_id_reg[VENDOR_ID_LEN+1];
  9614. char str_id_cap[VENDOR_ID_LEN+1];
  9615. char *vpd_data;
  9616. char *vpd_extended_data = NULL;
  9617. u8 len;
  9618. cnt = pci_read_vpd(bp->pdev, 0, BNX2X_VPD_LEN, vpd_start);
  9619. memset(bp->fw_ver, 0, sizeof(bp->fw_ver));
  9620. if (cnt < BNX2X_VPD_LEN)
  9621. goto out_not_found;
  9622. /* VPD RO tag should be first tag after identifier string, hence
  9623. * we should be able to find it in first BNX2X_VPD_LEN chars
  9624. */
  9625. i = pci_vpd_find_tag(vpd_start, 0, BNX2X_VPD_LEN,
  9626. PCI_VPD_LRDT_RO_DATA);
  9627. if (i < 0)
  9628. goto out_not_found;
  9629. block_end = i + PCI_VPD_LRDT_TAG_SIZE +
  9630. pci_vpd_lrdt_size(&vpd_start[i]);
  9631. i += PCI_VPD_LRDT_TAG_SIZE;
  9632. if (block_end > BNX2X_VPD_LEN) {
  9633. vpd_extended_data = kmalloc(block_end, GFP_KERNEL);
  9634. if (vpd_extended_data == NULL)
  9635. goto out_not_found;
  9636. /* read rest of vpd image into vpd_extended_data */
  9637. memcpy(vpd_extended_data, vpd_start, BNX2X_VPD_LEN);
  9638. cnt = pci_read_vpd(bp->pdev, BNX2X_VPD_LEN,
  9639. block_end - BNX2X_VPD_LEN,
  9640. vpd_extended_data + BNX2X_VPD_LEN);
  9641. if (cnt < (block_end - BNX2X_VPD_LEN))
  9642. goto out_not_found;
  9643. vpd_data = vpd_extended_data;
  9644. } else
  9645. vpd_data = vpd_start;
  9646. /* now vpd_data holds full vpd content in both cases */
  9647. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9648. PCI_VPD_RO_KEYWORD_MFR_ID);
  9649. if (rodi < 0)
  9650. goto out_not_found;
  9651. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9652. if (len != VENDOR_ID_LEN)
  9653. goto out_not_found;
  9654. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9655. /* vendor specific info */
  9656. snprintf(str_id_reg, VENDOR_ID_LEN + 1, "%04x", PCI_VENDOR_ID_DELL);
  9657. snprintf(str_id_cap, VENDOR_ID_LEN + 1, "%04X", PCI_VENDOR_ID_DELL);
  9658. if (!strncmp(str_id_reg, &vpd_data[rodi], VENDOR_ID_LEN) ||
  9659. !strncmp(str_id_cap, &vpd_data[rodi], VENDOR_ID_LEN)) {
  9660. rodi = pci_vpd_find_info_keyword(vpd_data, i, block_end,
  9661. PCI_VPD_RO_KEYWORD_VENDOR0);
  9662. if (rodi >= 0) {
  9663. len = pci_vpd_info_field_size(&vpd_data[rodi]);
  9664. rodi += PCI_VPD_INFO_FLD_HDR_SIZE;
  9665. if (len < 32 && (len + rodi) <= BNX2X_VPD_LEN) {
  9666. memcpy(bp->fw_ver, &vpd_data[rodi], len);
  9667. bp->fw_ver[len] = ' ';
  9668. }
  9669. }
  9670. kfree(vpd_extended_data);
  9671. return;
  9672. }
  9673. out_not_found:
  9674. kfree(vpd_extended_data);
  9675. return;
  9676. }
  9677. static void bnx2x_set_modes_bitmap(struct bnx2x *bp)
  9678. {
  9679. u32 flags = 0;
  9680. if (CHIP_REV_IS_FPGA(bp))
  9681. SET_FLAGS(flags, MODE_FPGA);
  9682. else if (CHIP_REV_IS_EMUL(bp))
  9683. SET_FLAGS(flags, MODE_EMUL);
  9684. else
  9685. SET_FLAGS(flags, MODE_ASIC);
  9686. if (CHIP_MODE_IS_4_PORT(bp))
  9687. SET_FLAGS(flags, MODE_PORT4);
  9688. else
  9689. SET_FLAGS(flags, MODE_PORT2);
  9690. if (CHIP_IS_E2(bp))
  9691. SET_FLAGS(flags, MODE_E2);
  9692. else if (CHIP_IS_E3(bp)) {
  9693. SET_FLAGS(flags, MODE_E3);
  9694. if (CHIP_REV(bp) == CHIP_REV_Ax)
  9695. SET_FLAGS(flags, MODE_E3_A0);
  9696. else /*if (CHIP_REV(bp) == CHIP_REV_Bx)*/
  9697. SET_FLAGS(flags, MODE_E3_B0 | MODE_COS3);
  9698. }
  9699. if (IS_MF(bp)) {
  9700. SET_FLAGS(flags, MODE_MF);
  9701. switch (bp->mf_mode) {
  9702. case MULTI_FUNCTION_SD:
  9703. SET_FLAGS(flags, MODE_MF_SD);
  9704. break;
  9705. case MULTI_FUNCTION_SI:
  9706. SET_FLAGS(flags, MODE_MF_SI);
  9707. break;
  9708. case MULTI_FUNCTION_AFEX:
  9709. SET_FLAGS(flags, MODE_MF_AFEX);
  9710. break;
  9711. }
  9712. } else
  9713. SET_FLAGS(flags, MODE_SF);
  9714. #if defined(__LITTLE_ENDIAN)
  9715. SET_FLAGS(flags, MODE_LITTLE_ENDIAN);
  9716. #else /*(__BIG_ENDIAN)*/
  9717. SET_FLAGS(flags, MODE_BIG_ENDIAN);
  9718. #endif
  9719. INIT_MODE_FLAGS(bp) = flags;
  9720. }
  9721. static int bnx2x_init_bp(struct bnx2x *bp)
  9722. {
  9723. int func;
  9724. int rc;
  9725. mutex_init(&bp->port.phy_mutex);
  9726. mutex_init(&bp->fw_mb_mutex);
  9727. spin_lock_init(&bp->stats_lock);
  9728. INIT_DELAYED_WORK(&bp->sp_task, bnx2x_sp_task);
  9729. INIT_DELAYED_WORK(&bp->sp_rtnl_task, bnx2x_sp_rtnl_task);
  9730. INIT_DELAYED_WORK(&bp->period_task, bnx2x_period_task);
  9731. if (IS_PF(bp)) {
  9732. rc = bnx2x_get_hwinfo(bp);
  9733. if (rc)
  9734. return rc;
  9735. } else {
  9736. eth_zero_addr(bp->dev->dev_addr);
  9737. }
  9738. bnx2x_set_modes_bitmap(bp);
  9739. rc = bnx2x_alloc_mem_bp(bp);
  9740. if (rc)
  9741. return rc;
  9742. bnx2x_read_fwinfo(bp);
  9743. func = BP_FUNC(bp);
  9744. /* need to reset chip if undi was active */
  9745. if (IS_PF(bp) && !BP_NOMCP(bp)) {
  9746. /* init fw_seq */
  9747. bp->fw_seq =
  9748. SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  9749. DRV_MSG_SEQ_NUMBER_MASK;
  9750. BNX2X_DEV_INFO("fw_seq 0x%08x\n", bp->fw_seq);
  9751. bnx2x_prev_unload(bp);
  9752. }
  9753. if (CHIP_REV_IS_FPGA(bp))
  9754. dev_err(&bp->pdev->dev, "FPGA detected\n");
  9755. if (BP_NOMCP(bp) && (func == 0))
  9756. dev_err(&bp->pdev->dev, "MCP disabled, must load devices in order!\n");
  9757. bp->disable_tpa = disable_tpa;
  9758. bp->disable_tpa |= IS_MF_STORAGE_SD(bp) || IS_MF_FCOE_AFEX(bp);
  9759. /* Set TPA flags */
  9760. if (bp->disable_tpa) {
  9761. bp->flags &= ~(TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9762. bp->dev->features &= ~NETIF_F_LRO;
  9763. } else {
  9764. bp->flags |= (TPA_ENABLE_FLAG | GRO_ENABLE_FLAG);
  9765. bp->dev->features |= NETIF_F_LRO;
  9766. }
  9767. if (CHIP_IS_E1(bp))
  9768. bp->dropless_fc = 0;
  9769. else
  9770. bp->dropless_fc = dropless_fc | bnx2x_get_dropless_info(bp);
  9771. bp->mrrs = mrrs;
  9772. bp->tx_ring_size = IS_MF_FCOE_AFEX(bp) ? 0 : MAX_TX_AVAIL;
  9773. if (IS_VF(bp))
  9774. bp->rx_ring_size = MAX_RX_AVAIL;
  9775. /* make sure that the numbers are in the right granularity */
  9776. bp->tx_ticks = (50 / BNX2X_BTR) * BNX2X_BTR;
  9777. bp->rx_ticks = (25 / BNX2X_BTR) * BNX2X_BTR;
  9778. bp->current_interval = CHIP_REV_IS_SLOW(bp) ? 5*HZ : HZ;
  9779. init_timer(&bp->timer);
  9780. bp->timer.expires = jiffies + bp->current_interval;
  9781. bp->timer.data = (unsigned long) bp;
  9782. bp->timer.function = bnx2x_timer;
  9783. if (SHMEM2_HAS(bp, dcbx_lldp_params_offset) &&
  9784. SHMEM2_HAS(bp, dcbx_lldp_dcbx_stat_offset) &&
  9785. SHMEM2_RD(bp, dcbx_lldp_params_offset) &&
  9786. SHMEM2_RD(bp, dcbx_lldp_dcbx_stat_offset)) {
  9787. bnx2x_dcbx_set_state(bp, true, BNX2X_DCBX_ENABLED_ON_NEG_ON);
  9788. bnx2x_dcbx_init_params(bp);
  9789. } else {
  9790. bnx2x_dcbx_set_state(bp, false, BNX2X_DCBX_ENABLED_OFF);
  9791. }
  9792. if (CHIP_IS_E1x(bp))
  9793. bp->cnic_base_cl_id = FP_SB_MAX_E1x;
  9794. else
  9795. bp->cnic_base_cl_id = FP_SB_MAX_E2;
  9796. /* multiple tx priority */
  9797. if (IS_VF(bp))
  9798. bp->max_cos = 1;
  9799. else if (CHIP_IS_E1x(bp))
  9800. bp->max_cos = BNX2X_MULTI_TX_COS_E1X;
  9801. else if (CHIP_IS_E2(bp) || CHIP_IS_E3A0(bp))
  9802. bp->max_cos = BNX2X_MULTI_TX_COS_E2_E3A0;
  9803. else if (CHIP_IS_E3B0(bp))
  9804. bp->max_cos = BNX2X_MULTI_TX_COS_E3B0;
  9805. else
  9806. BNX2X_ERR("unknown chip %x revision %x\n",
  9807. CHIP_NUM(bp), CHIP_REV(bp));
  9808. BNX2X_DEV_INFO("set bp->max_cos to %d\n", bp->max_cos);
  9809. /* We need at least one default status block for slow-path events,
  9810. * second status block for the L2 queue, and a third status block for
  9811. * CNIC if supported.
  9812. */
  9813. if (CNIC_SUPPORT(bp))
  9814. bp->min_msix_vec_cnt = 3;
  9815. else
  9816. bp->min_msix_vec_cnt = 2;
  9817. BNX2X_DEV_INFO("bp->min_msix_vec_cnt %d", bp->min_msix_vec_cnt);
  9818. return rc;
  9819. }
  9820. /****************************************************************************
  9821. * General service functions
  9822. ****************************************************************************/
  9823. /*
  9824. * net_device service functions
  9825. */
  9826. /* called with rtnl_lock */
  9827. static int bnx2x_open(struct net_device *dev)
  9828. {
  9829. struct bnx2x *bp = netdev_priv(dev);
  9830. bool global = false;
  9831. int other_engine = BP_PATH(bp) ? 0 : 1;
  9832. bool other_load_status, load_status;
  9833. int rc;
  9834. bp->stats_init = true;
  9835. netif_carrier_off(dev);
  9836. bnx2x_set_power_state(bp, PCI_D0);
  9837. /* If parity had happen during the unload, then attentions
  9838. * and/or RECOVERY_IN_PROGRES may still be set. In this case we
  9839. * want the first function loaded on the current engine to
  9840. * complete the recovery.
  9841. * Parity recovery is only relevant for PF driver.
  9842. */
  9843. if (IS_PF(bp)) {
  9844. other_load_status = bnx2x_get_load_status(bp, other_engine);
  9845. load_status = bnx2x_get_load_status(bp, BP_PATH(bp));
  9846. if (!bnx2x_reset_is_done(bp, BP_PATH(bp)) ||
  9847. bnx2x_chk_parity_attn(bp, &global, true)) {
  9848. do {
  9849. /* If there are attentions and they are in a
  9850. * global blocks, set the GLOBAL_RESET bit
  9851. * regardless whether it will be this function
  9852. * that will complete the recovery or not.
  9853. */
  9854. if (global)
  9855. bnx2x_set_reset_global(bp);
  9856. /* Only the first function on the current
  9857. * engine should try to recover in open. In case
  9858. * of attentions in global blocks only the first
  9859. * in the chip should try to recover.
  9860. */
  9861. if ((!load_status &&
  9862. (!global || !other_load_status)) &&
  9863. bnx2x_trylock_leader_lock(bp) &&
  9864. !bnx2x_leader_reset(bp)) {
  9865. netdev_info(bp->dev,
  9866. "Recovered in open\n");
  9867. break;
  9868. }
  9869. /* recovery has failed... */
  9870. bnx2x_set_power_state(bp, PCI_D3hot);
  9871. bp->recovery_state = BNX2X_RECOVERY_FAILED;
  9872. BNX2X_ERR("Recovery flow hasn't been properly completed yet. Try again later.\n"
  9873. "If you still see this message after a few retries then power cycle is required.\n");
  9874. return -EAGAIN;
  9875. } while (0);
  9876. }
  9877. }
  9878. bp->recovery_state = BNX2X_RECOVERY_DONE;
  9879. rc = bnx2x_nic_load(bp, LOAD_OPEN);
  9880. if (rc)
  9881. return rc;
  9882. return bnx2x_open_epilog(bp);
  9883. }
  9884. /* called with rtnl_lock */
  9885. static int bnx2x_close(struct net_device *dev)
  9886. {
  9887. struct bnx2x *bp = netdev_priv(dev);
  9888. /* Unload the driver, release IRQs */
  9889. bnx2x_nic_unload(bp, UNLOAD_CLOSE, false);
  9890. return 0;
  9891. }
  9892. static int bnx2x_init_mcast_macs_list(struct bnx2x *bp,
  9893. struct bnx2x_mcast_ramrod_params *p)
  9894. {
  9895. int mc_count = netdev_mc_count(bp->dev);
  9896. struct bnx2x_mcast_list_elem *mc_mac =
  9897. kzalloc(sizeof(*mc_mac) * mc_count, GFP_ATOMIC);
  9898. struct netdev_hw_addr *ha;
  9899. if (!mc_mac)
  9900. return -ENOMEM;
  9901. INIT_LIST_HEAD(&p->mcast_list);
  9902. netdev_for_each_mc_addr(ha, bp->dev) {
  9903. mc_mac->mac = bnx2x_mc_addr(ha);
  9904. list_add_tail(&mc_mac->link, &p->mcast_list);
  9905. mc_mac++;
  9906. }
  9907. p->mcast_list_len = mc_count;
  9908. return 0;
  9909. }
  9910. static void bnx2x_free_mcast_macs_list(
  9911. struct bnx2x_mcast_ramrod_params *p)
  9912. {
  9913. struct bnx2x_mcast_list_elem *mc_mac =
  9914. list_first_entry(&p->mcast_list, struct bnx2x_mcast_list_elem,
  9915. link);
  9916. WARN_ON(!mc_mac);
  9917. kfree(mc_mac);
  9918. }
  9919. /**
  9920. * bnx2x_set_uc_list - configure a new unicast MACs list.
  9921. *
  9922. * @bp: driver handle
  9923. *
  9924. * We will use zero (0) as a MAC type for these MACs.
  9925. */
  9926. static int bnx2x_set_uc_list(struct bnx2x *bp)
  9927. {
  9928. int rc;
  9929. struct net_device *dev = bp->dev;
  9930. struct netdev_hw_addr *ha;
  9931. struct bnx2x_vlan_mac_obj *mac_obj = &bp->sp_objs->mac_obj;
  9932. unsigned long ramrod_flags = 0;
  9933. /* First schedule a cleanup up of old configuration */
  9934. rc = bnx2x_del_all_macs(bp, mac_obj, BNX2X_UC_LIST_MAC, false);
  9935. if (rc < 0) {
  9936. BNX2X_ERR("Failed to schedule DELETE operations: %d\n", rc);
  9937. return rc;
  9938. }
  9939. netdev_for_each_uc_addr(ha, dev) {
  9940. rc = bnx2x_set_mac_one(bp, bnx2x_uc_addr(ha), mac_obj, true,
  9941. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9942. if (rc == -EEXIST) {
  9943. DP(BNX2X_MSG_SP,
  9944. "Failed to schedule ADD operations: %d\n", rc);
  9945. /* do not treat adding same MAC as error */
  9946. rc = 0;
  9947. } else if (rc < 0) {
  9948. BNX2X_ERR("Failed to schedule ADD operations: %d\n",
  9949. rc);
  9950. return rc;
  9951. }
  9952. }
  9953. /* Execute the pending commands */
  9954. __set_bit(RAMROD_CONT, &ramrod_flags);
  9955. return bnx2x_set_mac_one(bp, NULL, mac_obj, false /* don't care */,
  9956. BNX2X_UC_LIST_MAC, &ramrod_flags);
  9957. }
  9958. static int bnx2x_set_mc_list(struct bnx2x *bp)
  9959. {
  9960. struct net_device *dev = bp->dev;
  9961. struct bnx2x_mcast_ramrod_params rparam = {NULL};
  9962. int rc = 0;
  9963. rparam.mcast_obj = &bp->mcast_obj;
  9964. /* first, clear all configured multicast MACs */
  9965. rc = bnx2x_config_mcast(bp, &rparam, BNX2X_MCAST_CMD_DEL);
  9966. if (rc < 0) {
  9967. BNX2X_ERR("Failed to clear multicast configuration: %d\n", rc);
  9968. return rc;
  9969. }
  9970. /* then, configure a new MACs list */
  9971. if (netdev_mc_count(dev)) {
  9972. rc = bnx2x_init_mcast_macs_list(bp, &rparam);
  9973. if (rc) {
  9974. BNX2X_ERR("Failed to create multicast MACs list: %d\n",
  9975. rc);
  9976. return rc;
  9977. }
  9978. /* Now add the new MACs */
  9979. rc = bnx2x_config_mcast(bp, &rparam,
  9980. BNX2X_MCAST_CMD_ADD);
  9981. if (rc < 0)
  9982. BNX2X_ERR("Failed to set a new multicast configuration: %d\n",
  9983. rc);
  9984. bnx2x_free_mcast_macs_list(&rparam);
  9985. }
  9986. return rc;
  9987. }
  9988. /* If bp->state is OPEN, should be called with netif_addr_lock_bh() */
  9989. void bnx2x_set_rx_mode(struct net_device *dev)
  9990. {
  9991. struct bnx2x *bp = netdev_priv(dev);
  9992. u32 rx_mode = BNX2X_RX_MODE_NORMAL;
  9993. if (bp->state != BNX2X_STATE_OPEN) {
  9994. DP(NETIF_MSG_IFUP, "state is %x, returning\n", bp->state);
  9995. return;
  9996. }
  9997. DP(NETIF_MSG_IFUP, "dev->flags = %x\n", bp->dev->flags);
  9998. if (dev->flags & IFF_PROMISC)
  9999. rx_mode = BNX2X_RX_MODE_PROMISC;
  10000. else if ((dev->flags & IFF_ALLMULTI) ||
  10001. ((netdev_mc_count(dev) > BNX2X_MAX_MULTICAST) &&
  10002. CHIP_IS_E1(bp)))
  10003. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10004. else {
  10005. if (IS_PF(bp)) {
  10006. /* some multicasts */
  10007. if (bnx2x_set_mc_list(bp) < 0)
  10008. rx_mode = BNX2X_RX_MODE_ALLMULTI;
  10009. if (bnx2x_set_uc_list(bp) < 0)
  10010. rx_mode = BNX2X_RX_MODE_PROMISC;
  10011. } else {
  10012. /* configuring mcast to a vf involves sleeping (when we
  10013. * wait for the pf's response). Since this function is
  10014. * called from non sleepable context we must schedule
  10015. * a work item for this purpose
  10016. */
  10017. smp_mb__before_clear_bit();
  10018. set_bit(BNX2X_SP_RTNL_VFPF_MCAST,
  10019. &bp->sp_rtnl_state);
  10020. smp_mb__after_clear_bit();
  10021. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10022. }
  10023. }
  10024. bp->rx_mode = rx_mode;
  10025. /* handle ISCSI SD mode */
  10026. if (IS_MF_ISCSI_SD(bp))
  10027. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10028. /* Schedule the rx_mode command */
  10029. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state)) {
  10030. set_bit(BNX2X_FILTER_RX_MODE_SCHED, &bp->sp_state);
  10031. return;
  10032. }
  10033. if (IS_PF(bp)) {
  10034. bnx2x_set_storm_rx_mode(bp);
  10035. } else {
  10036. /* configuring rx mode to storms in a vf involves sleeping (when
  10037. * we wait for the pf's response). Since this function is
  10038. * called from non sleepable context we must schedule
  10039. * a work item for this purpose
  10040. */
  10041. smp_mb__before_clear_bit();
  10042. set_bit(BNX2X_SP_RTNL_VFPF_STORM_RX_MODE,
  10043. &bp->sp_rtnl_state);
  10044. smp_mb__after_clear_bit();
  10045. schedule_delayed_work(&bp->sp_rtnl_task, 0);
  10046. }
  10047. }
  10048. /* called with rtnl_lock */
  10049. static int bnx2x_mdio_read(struct net_device *netdev, int prtad,
  10050. int devad, u16 addr)
  10051. {
  10052. struct bnx2x *bp = netdev_priv(netdev);
  10053. u16 value;
  10054. int rc;
  10055. DP(NETIF_MSG_LINK, "mdio_read: prtad 0x%x, devad 0x%x, addr 0x%x\n",
  10056. prtad, devad, addr);
  10057. /* The HW expects different devad if CL22 is used */
  10058. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10059. bnx2x_acquire_phy_lock(bp);
  10060. rc = bnx2x_phy_read(&bp->link_params, prtad, devad, addr, &value);
  10061. bnx2x_release_phy_lock(bp);
  10062. DP(NETIF_MSG_LINK, "mdio_read_val 0x%x rc = 0x%x\n", value, rc);
  10063. if (!rc)
  10064. rc = value;
  10065. return rc;
  10066. }
  10067. /* called with rtnl_lock */
  10068. static int bnx2x_mdio_write(struct net_device *netdev, int prtad, int devad,
  10069. u16 addr, u16 value)
  10070. {
  10071. struct bnx2x *bp = netdev_priv(netdev);
  10072. int rc;
  10073. DP(NETIF_MSG_LINK,
  10074. "mdio_write: prtad 0x%x, devad 0x%x, addr 0x%x, value 0x%x\n",
  10075. prtad, devad, addr, value);
  10076. /* The HW expects different devad if CL22 is used */
  10077. devad = (devad == MDIO_DEVAD_NONE) ? DEFAULT_PHY_DEV_ADDR : devad;
  10078. bnx2x_acquire_phy_lock(bp);
  10079. rc = bnx2x_phy_write(&bp->link_params, prtad, devad, addr, value);
  10080. bnx2x_release_phy_lock(bp);
  10081. return rc;
  10082. }
  10083. /* called with rtnl_lock */
  10084. static int bnx2x_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
  10085. {
  10086. struct bnx2x *bp = netdev_priv(dev);
  10087. struct mii_ioctl_data *mdio = if_mii(ifr);
  10088. DP(NETIF_MSG_LINK, "ioctl: phy id 0x%x, reg 0x%x, val_in 0x%x\n",
  10089. mdio->phy_id, mdio->reg_num, mdio->val_in);
  10090. if (!netif_running(dev))
  10091. return -EAGAIN;
  10092. return mdio_mii_ioctl(&bp->mdio, mdio, cmd);
  10093. }
  10094. #ifdef CONFIG_NET_POLL_CONTROLLER
  10095. static void poll_bnx2x(struct net_device *dev)
  10096. {
  10097. struct bnx2x *bp = netdev_priv(dev);
  10098. int i;
  10099. for_each_eth_queue(bp, i) {
  10100. struct bnx2x_fastpath *fp = &bp->fp[i];
  10101. napi_schedule(&bnx2x_fp(bp, fp->index, napi));
  10102. }
  10103. }
  10104. #endif
  10105. static int bnx2x_validate_addr(struct net_device *dev)
  10106. {
  10107. struct bnx2x *bp = netdev_priv(dev);
  10108. /* query the bulletin board for mac address configured by the PF */
  10109. if (IS_VF(bp))
  10110. bnx2x_sample_bulletin(bp);
  10111. if (!bnx2x_is_valid_ether_addr(bp, dev->dev_addr)) {
  10112. BNX2X_ERR("Non-valid Ethernet address\n");
  10113. return -EADDRNOTAVAIL;
  10114. }
  10115. return 0;
  10116. }
  10117. static const struct net_device_ops bnx2x_netdev_ops = {
  10118. .ndo_open = bnx2x_open,
  10119. .ndo_stop = bnx2x_close,
  10120. .ndo_start_xmit = bnx2x_start_xmit,
  10121. .ndo_select_queue = bnx2x_select_queue,
  10122. .ndo_set_rx_mode = bnx2x_set_rx_mode,
  10123. .ndo_set_mac_address = bnx2x_change_mac_addr,
  10124. .ndo_validate_addr = bnx2x_validate_addr,
  10125. .ndo_do_ioctl = bnx2x_ioctl,
  10126. .ndo_change_mtu = bnx2x_change_mtu,
  10127. .ndo_fix_features = bnx2x_fix_features,
  10128. .ndo_set_features = bnx2x_set_features,
  10129. .ndo_tx_timeout = bnx2x_tx_timeout,
  10130. #ifdef CONFIG_NET_POLL_CONTROLLER
  10131. .ndo_poll_controller = poll_bnx2x,
  10132. #endif
  10133. .ndo_setup_tc = bnx2x_setup_tc,
  10134. #ifdef CONFIG_BNX2X_SRIOV
  10135. .ndo_set_vf_mac = bnx2x_set_vf_mac,
  10136. .ndo_set_vf_vlan = bnx2x_set_vf_vlan,
  10137. .ndo_get_vf_config = bnx2x_get_vf_config,
  10138. #endif
  10139. #ifdef NETDEV_FCOE_WWNN
  10140. .ndo_fcoe_get_wwn = bnx2x_fcoe_get_wwn,
  10141. #endif
  10142. #ifdef CONFIG_NET_LL_RX_POLL
  10143. .ndo_ll_poll = bnx2x_low_latency_recv,
  10144. #endif
  10145. };
  10146. static int bnx2x_set_coherency_mask(struct bnx2x *bp)
  10147. {
  10148. struct device *dev = &bp->pdev->dev;
  10149. if (dma_set_mask(dev, DMA_BIT_MASK(64)) == 0) {
  10150. bp->flags |= USING_DAC_FLAG;
  10151. if (dma_set_coherent_mask(dev, DMA_BIT_MASK(64)) != 0) {
  10152. dev_err(dev, "dma_set_coherent_mask failed, aborting\n");
  10153. return -EIO;
  10154. }
  10155. } else if (dma_set_mask(dev, DMA_BIT_MASK(32)) != 0) {
  10156. dev_err(dev, "System does not support DMA, aborting\n");
  10157. return -EIO;
  10158. }
  10159. return 0;
  10160. }
  10161. static int bnx2x_init_dev(struct bnx2x *bp, struct pci_dev *pdev,
  10162. struct net_device *dev, unsigned long board_type)
  10163. {
  10164. int rc;
  10165. u32 pci_cfg_dword;
  10166. bool chip_is_e1x = (board_type == BCM57710 ||
  10167. board_type == BCM57711 ||
  10168. board_type == BCM57711E);
  10169. SET_NETDEV_DEV(dev, &pdev->dev);
  10170. bp->dev = dev;
  10171. bp->pdev = pdev;
  10172. rc = pci_enable_device(pdev);
  10173. if (rc) {
  10174. dev_err(&bp->pdev->dev,
  10175. "Cannot enable PCI device, aborting\n");
  10176. goto err_out;
  10177. }
  10178. if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) {
  10179. dev_err(&bp->pdev->dev,
  10180. "Cannot find PCI device base address, aborting\n");
  10181. rc = -ENODEV;
  10182. goto err_out_disable;
  10183. }
  10184. if (IS_PF(bp) && !(pci_resource_flags(pdev, 2) & IORESOURCE_MEM)) {
  10185. dev_err(&bp->pdev->dev, "Cannot find second PCI device base address, aborting\n");
  10186. rc = -ENODEV;
  10187. goto err_out_disable;
  10188. }
  10189. pci_read_config_dword(pdev, PCICFG_REVISION_ID_OFFSET, &pci_cfg_dword);
  10190. if ((pci_cfg_dword & PCICFG_REVESION_ID_MASK) ==
  10191. PCICFG_REVESION_ID_ERROR_VAL) {
  10192. pr_err("PCI device error, probably due to fan failure, aborting\n");
  10193. rc = -ENODEV;
  10194. goto err_out_disable;
  10195. }
  10196. if (atomic_read(&pdev->enable_cnt) == 1) {
  10197. rc = pci_request_regions(pdev, DRV_MODULE_NAME);
  10198. if (rc) {
  10199. dev_err(&bp->pdev->dev,
  10200. "Cannot obtain PCI resources, aborting\n");
  10201. goto err_out_disable;
  10202. }
  10203. pci_set_master(pdev);
  10204. pci_save_state(pdev);
  10205. }
  10206. if (IS_PF(bp)) {
  10207. bp->pm_cap = pdev->pm_cap;
  10208. if (bp->pm_cap == 0) {
  10209. dev_err(&bp->pdev->dev,
  10210. "Cannot find power management capability, aborting\n");
  10211. rc = -EIO;
  10212. goto err_out_release;
  10213. }
  10214. }
  10215. if (!pci_is_pcie(pdev)) {
  10216. dev_err(&bp->pdev->dev, "Not PCI Express, aborting\n");
  10217. rc = -EIO;
  10218. goto err_out_release;
  10219. }
  10220. rc = bnx2x_set_coherency_mask(bp);
  10221. if (rc)
  10222. goto err_out_release;
  10223. dev->mem_start = pci_resource_start(pdev, 0);
  10224. dev->base_addr = dev->mem_start;
  10225. dev->mem_end = pci_resource_end(pdev, 0);
  10226. dev->irq = pdev->irq;
  10227. bp->regview = pci_ioremap_bar(pdev, 0);
  10228. if (!bp->regview) {
  10229. dev_err(&bp->pdev->dev,
  10230. "Cannot map register space, aborting\n");
  10231. rc = -ENOMEM;
  10232. goto err_out_release;
  10233. }
  10234. /* In E1/E1H use pci device function given by kernel.
  10235. * In E2/E3 read physical function from ME register since these chips
  10236. * support Physical Device Assignment where kernel BDF maybe arbitrary
  10237. * (depending on hypervisor).
  10238. */
  10239. if (chip_is_e1x) {
  10240. bp->pf_num = PCI_FUNC(pdev->devfn);
  10241. } else {
  10242. /* chip is E2/3*/
  10243. pci_read_config_dword(bp->pdev,
  10244. PCICFG_ME_REGISTER, &pci_cfg_dword);
  10245. bp->pf_num = (u8)((pci_cfg_dword & ME_REG_ABS_PF_NUM) >>
  10246. ME_REG_ABS_PF_NUM_SHIFT);
  10247. }
  10248. BNX2X_DEV_INFO("me reg PF num: %d\n", bp->pf_num);
  10249. /* clean indirect addresses */
  10250. pci_write_config_dword(bp->pdev, PCICFG_GRC_ADDRESS,
  10251. PCICFG_VENDOR_ID_OFFSET);
  10252. /*
  10253. * Clean the following indirect addresses for all functions since it
  10254. * is not used by the driver.
  10255. */
  10256. if (IS_PF(bp)) {
  10257. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F0, 0);
  10258. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F0, 0);
  10259. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F0, 0);
  10260. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F0, 0);
  10261. if (chip_is_e1x) {
  10262. REG_WR(bp, PXP2_REG_PGL_ADDR_88_F1, 0);
  10263. REG_WR(bp, PXP2_REG_PGL_ADDR_8C_F1, 0);
  10264. REG_WR(bp, PXP2_REG_PGL_ADDR_90_F1, 0);
  10265. REG_WR(bp, PXP2_REG_PGL_ADDR_94_F1, 0);
  10266. }
  10267. /* Enable internal target-read (in case we are probed after PF
  10268. * FLR). Must be done prior to any BAR read access. Only for
  10269. * 57712 and up
  10270. */
  10271. if (!chip_is_e1x)
  10272. REG_WR(bp,
  10273. PGLUE_B_REG_INTERNAL_PFID_ENABLE_TARGET_READ, 1);
  10274. }
  10275. dev->watchdog_timeo = TX_TIMEOUT;
  10276. dev->netdev_ops = &bnx2x_netdev_ops;
  10277. bnx2x_set_ethtool_ops(bp, dev);
  10278. dev->priv_flags |= IFF_UNICAST_FLT;
  10279. dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10280. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10281. NETIF_F_RXCSUM | NETIF_F_LRO | NETIF_F_GRO |
  10282. NETIF_F_RXHASH | NETIF_F_HW_VLAN_CTAG_TX;
  10283. if (!CHIP_IS_E1x(bp)) {
  10284. dev->hw_features |= NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10285. dev->hw_enc_features =
  10286. NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG |
  10287. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 |
  10288. NETIF_F_GSO_GRE | NETIF_F_GSO_UDP_TUNNEL;
  10289. }
  10290. dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  10291. NETIF_F_TSO | NETIF_F_TSO_ECN | NETIF_F_TSO6 | NETIF_F_HIGHDMA;
  10292. dev->features |= dev->hw_features | NETIF_F_HW_VLAN_CTAG_RX;
  10293. if (bp->flags & USING_DAC_FLAG)
  10294. dev->features |= NETIF_F_HIGHDMA;
  10295. /* Add Loopback capability to the device */
  10296. dev->hw_features |= NETIF_F_LOOPBACK;
  10297. #ifdef BCM_DCBNL
  10298. dev->dcbnl_ops = &bnx2x_dcbnl_ops;
  10299. #endif
  10300. /* get_port_hwinfo() will set prtad and mmds properly */
  10301. bp->mdio.prtad = MDIO_PRTAD_NONE;
  10302. bp->mdio.mmds = 0;
  10303. bp->mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
  10304. bp->mdio.dev = dev;
  10305. bp->mdio.mdio_read = bnx2x_mdio_read;
  10306. bp->mdio.mdio_write = bnx2x_mdio_write;
  10307. return 0;
  10308. err_out_release:
  10309. if (atomic_read(&pdev->enable_cnt) == 1)
  10310. pci_release_regions(pdev);
  10311. err_out_disable:
  10312. pci_disable_device(pdev);
  10313. pci_set_drvdata(pdev, NULL);
  10314. err_out:
  10315. return rc;
  10316. }
  10317. static void bnx2x_get_pcie_width_speed(struct bnx2x *bp, int *width,
  10318. enum bnx2x_pci_bus_speed *speed)
  10319. {
  10320. u32 link_speed, val = 0;
  10321. pci_read_config_dword(bp->pdev, PCICFG_LINK_CONTROL, &val);
  10322. *width = (val & PCICFG_LINK_WIDTH) >> PCICFG_LINK_WIDTH_SHIFT;
  10323. link_speed = (val & PCICFG_LINK_SPEED) >> PCICFG_LINK_SPEED_SHIFT;
  10324. switch (link_speed) {
  10325. case 3:
  10326. *speed = BNX2X_PCI_LINK_SPEED_8000;
  10327. break;
  10328. case 2:
  10329. *speed = BNX2X_PCI_LINK_SPEED_5000;
  10330. break;
  10331. default:
  10332. *speed = BNX2X_PCI_LINK_SPEED_2500;
  10333. }
  10334. }
  10335. static int bnx2x_check_firmware(struct bnx2x *bp)
  10336. {
  10337. const struct firmware *firmware = bp->firmware;
  10338. struct bnx2x_fw_file_hdr *fw_hdr;
  10339. struct bnx2x_fw_file_section *sections;
  10340. u32 offset, len, num_ops;
  10341. __be16 *ops_offsets;
  10342. int i;
  10343. const u8 *fw_ver;
  10344. if (firmware->size < sizeof(struct bnx2x_fw_file_hdr)) {
  10345. BNX2X_ERR("Wrong FW size\n");
  10346. return -EINVAL;
  10347. }
  10348. fw_hdr = (struct bnx2x_fw_file_hdr *)firmware->data;
  10349. sections = (struct bnx2x_fw_file_section *)fw_hdr;
  10350. /* Make sure none of the offsets and sizes make us read beyond
  10351. * the end of the firmware data */
  10352. for (i = 0; i < sizeof(*fw_hdr) / sizeof(*sections); i++) {
  10353. offset = be32_to_cpu(sections[i].offset);
  10354. len = be32_to_cpu(sections[i].len);
  10355. if (offset + len > firmware->size) {
  10356. BNX2X_ERR("Section %d length is out of bounds\n", i);
  10357. return -EINVAL;
  10358. }
  10359. }
  10360. /* Likewise for the init_ops offsets */
  10361. offset = be32_to_cpu(fw_hdr->init_ops_offsets.offset);
  10362. ops_offsets = (__force __be16 *)(firmware->data + offset);
  10363. num_ops = be32_to_cpu(fw_hdr->init_ops.len) / sizeof(struct raw_op);
  10364. for (i = 0; i < be32_to_cpu(fw_hdr->init_ops_offsets.len) / 2; i++) {
  10365. if (be16_to_cpu(ops_offsets[i]) > num_ops) {
  10366. BNX2X_ERR("Section offset %d is out of bounds\n", i);
  10367. return -EINVAL;
  10368. }
  10369. }
  10370. /* Check FW version */
  10371. offset = be32_to_cpu(fw_hdr->fw_version.offset);
  10372. fw_ver = firmware->data + offset;
  10373. if ((fw_ver[0] != BCM_5710_FW_MAJOR_VERSION) ||
  10374. (fw_ver[1] != BCM_5710_FW_MINOR_VERSION) ||
  10375. (fw_ver[2] != BCM_5710_FW_REVISION_VERSION) ||
  10376. (fw_ver[3] != BCM_5710_FW_ENGINEERING_VERSION)) {
  10377. BNX2X_ERR("Bad FW version:%d.%d.%d.%d. Should be %d.%d.%d.%d\n",
  10378. fw_ver[0], fw_ver[1], fw_ver[2], fw_ver[3],
  10379. BCM_5710_FW_MAJOR_VERSION,
  10380. BCM_5710_FW_MINOR_VERSION,
  10381. BCM_5710_FW_REVISION_VERSION,
  10382. BCM_5710_FW_ENGINEERING_VERSION);
  10383. return -EINVAL;
  10384. }
  10385. return 0;
  10386. }
  10387. static void be32_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10388. {
  10389. const __be32 *source = (const __be32 *)_source;
  10390. u32 *target = (u32 *)_target;
  10391. u32 i;
  10392. for (i = 0; i < n/4; i++)
  10393. target[i] = be32_to_cpu(source[i]);
  10394. }
  10395. /*
  10396. Ops array is stored in the following format:
  10397. {op(8bit), offset(24bit, big endian), data(32bit, big endian)}
  10398. */
  10399. static void bnx2x_prep_ops(const u8 *_source, u8 *_target, u32 n)
  10400. {
  10401. const __be32 *source = (const __be32 *)_source;
  10402. struct raw_op *target = (struct raw_op *)_target;
  10403. u32 i, j, tmp;
  10404. for (i = 0, j = 0; i < n/8; i++, j += 2) {
  10405. tmp = be32_to_cpu(source[j]);
  10406. target[i].op = (tmp >> 24) & 0xff;
  10407. target[i].offset = tmp & 0xffffff;
  10408. target[i].raw_data = be32_to_cpu(source[j + 1]);
  10409. }
  10410. }
  10411. /* IRO array is stored in the following format:
  10412. * {base(24bit), m1(16bit), m2(16bit), m3(16bit), size(16bit) }
  10413. */
  10414. static void bnx2x_prep_iro(const u8 *_source, u8 *_target, u32 n)
  10415. {
  10416. const __be32 *source = (const __be32 *)_source;
  10417. struct iro *target = (struct iro *)_target;
  10418. u32 i, j, tmp;
  10419. for (i = 0, j = 0; i < n/sizeof(struct iro); i++) {
  10420. target[i].base = be32_to_cpu(source[j]);
  10421. j++;
  10422. tmp = be32_to_cpu(source[j]);
  10423. target[i].m1 = (tmp >> 16) & 0xffff;
  10424. target[i].m2 = tmp & 0xffff;
  10425. j++;
  10426. tmp = be32_to_cpu(source[j]);
  10427. target[i].m3 = (tmp >> 16) & 0xffff;
  10428. target[i].size = tmp & 0xffff;
  10429. j++;
  10430. }
  10431. }
  10432. static void be16_to_cpu_n(const u8 *_source, u8 *_target, u32 n)
  10433. {
  10434. const __be16 *source = (const __be16 *)_source;
  10435. u16 *target = (u16 *)_target;
  10436. u32 i;
  10437. for (i = 0; i < n/2; i++)
  10438. target[i] = be16_to_cpu(source[i]);
  10439. }
  10440. #define BNX2X_ALLOC_AND_SET(arr, lbl, func) \
  10441. do { \
  10442. u32 len = be32_to_cpu(fw_hdr->arr.len); \
  10443. bp->arr = kmalloc(len, GFP_KERNEL); \
  10444. if (!bp->arr) \
  10445. goto lbl; \
  10446. func(bp->firmware->data + be32_to_cpu(fw_hdr->arr.offset), \
  10447. (u8 *)bp->arr, len); \
  10448. } while (0)
  10449. static int bnx2x_init_firmware(struct bnx2x *bp)
  10450. {
  10451. const char *fw_file_name;
  10452. struct bnx2x_fw_file_hdr *fw_hdr;
  10453. int rc;
  10454. if (bp->firmware)
  10455. return 0;
  10456. if (CHIP_IS_E1(bp))
  10457. fw_file_name = FW_FILE_NAME_E1;
  10458. else if (CHIP_IS_E1H(bp))
  10459. fw_file_name = FW_FILE_NAME_E1H;
  10460. else if (!CHIP_IS_E1x(bp))
  10461. fw_file_name = FW_FILE_NAME_E2;
  10462. else {
  10463. BNX2X_ERR("Unsupported chip revision\n");
  10464. return -EINVAL;
  10465. }
  10466. BNX2X_DEV_INFO("Loading %s\n", fw_file_name);
  10467. rc = request_firmware(&bp->firmware, fw_file_name, &bp->pdev->dev);
  10468. if (rc) {
  10469. BNX2X_ERR("Can't load firmware file %s\n",
  10470. fw_file_name);
  10471. goto request_firmware_exit;
  10472. }
  10473. rc = bnx2x_check_firmware(bp);
  10474. if (rc) {
  10475. BNX2X_ERR("Corrupt firmware file %s\n", fw_file_name);
  10476. goto request_firmware_exit;
  10477. }
  10478. fw_hdr = (struct bnx2x_fw_file_hdr *)bp->firmware->data;
  10479. /* Initialize the pointers to the init arrays */
  10480. /* Blob */
  10481. BNX2X_ALLOC_AND_SET(init_data, request_firmware_exit, be32_to_cpu_n);
  10482. /* Opcodes */
  10483. BNX2X_ALLOC_AND_SET(init_ops, init_ops_alloc_err, bnx2x_prep_ops);
  10484. /* Offsets */
  10485. BNX2X_ALLOC_AND_SET(init_ops_offsets, init_offsets_alloc_err,
  10486. be16_to_cpu_n);
  10487. /* STORMs firmware */
  10488. INIT_TSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10489. be32_to_cpu(fw_hdr->tsem_int_table_data.offset);
  10490. INIT_TSEM_PRAM_DATA(bp) = bp->firmware->data +
  10491. be32_to_cpu(fw_hdr->tsem_pram_data.offset);
  10492. INIT_USEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10493. be32_to_cpu(fw_hdr->usem_int_table_data.offset);
  10494. INIT_USEM_PRAM_DATA(bp) = bp->firmware->data +
  10495. be32_to_cpu(fw_hdr->usem_pram_data.offset);
  10496. INIT_XSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10497. be32_to_cpu(fw_hdr->xsem_int_table_data.offset);
  10498. INIT_XSEM_PRAM_DATA(bp) = bp->firmware->data +
  10499. be32_to_cpu(fw_hdr->xsem_pram_data.offset);
  10500. INIT_CSEM_INT_TABLE_DATA(bp) = bp->firmware->data +
  10501. be32_to_cpu(fw_hdr->csem_int_table_data.offset);
  10502. INIT_CSEM_PRAM_DATA(bp) = bp->firmware->data +
  10503. be32_to_cpu(fw_hdr->csem_pram_data.offset);
  10504. /* IRO */
  10505. BNX2X_ALLOC_AND_SET(iro_arr, iro_alloc_err, bnx2x_prep_iro);
  10506. return 0;
  10507. iro_alloc_err:
  10508. kfree(bp->init_ops_offsets);
  10509. init_offsets_alloc_err:
  10510. kfree(bp->init_ops);
  10511. init_ops_alloc_err:
  10512. kfree(bp->init_data);
  10513. request_firmware_exit:
  10514. release_firmware(bp->firmware);
  10515. bp->firmware = NULL;
  10516. return rc;
  10517. }
  10518. static void bnx2x_release_firmware(struct bnx2x *bp)
  10519. {
  10520. kfree(bp->init_ops_offsets);
  10521. kfree(bp->init_ops);
  10522. kfree(bp->init_data);
  10523. release_firmware(bp->firmware);
  10524. bp->firmware = NULL;
  10525. }
  10526. static struct bnx2x_func_sp_drv_ops bnx2x_func_sp_drv = {
  10527. .init_hw_cmn_chip = bnx2x_init_hw_common_chip,
  10528. .init_hw_cmn = bnx2x_init_hw_common,
  10529. .init_hw_port = bnx2x_init_hw_port,
  10530. .init_hw_func = bnx2x_init_hw_func,
  10531. .reset_hw_cmn = bnx2x_reset_common,
  10532. .reset_hw_port = bnx2x_reset_port,
  10533. .reset_hw_func = bnx2x_reset_func,
  10534. .gunzip_init = bnx2x_gunzip_init,
  10535. .gunzip_end = bnx2x_gunzip_end,
  10536. .init_fw = bnx2x_init_firmware,
  10537. .release_fw = bnx2x_release_firmware,
  10538. };
  10539. void bnx2x__init_func_obj(struct bnx2x *bp)
  10540. {
  10541. /* Prepare DMAE related driver resources */
  10542. bnx2x_setup_dmae(bp);
  10543. bnx2x_init_func_obj(bp, &bp->func_obj,
  10544. bnx2x_sp(bp, func_rdata),
  10545. bnx2x_sp_mapping(bp, func_rdata),
  10546. bnx2x_sp(bp, func_afex_rdata),
  10547. bnx2x_sp_mapping(bp, func_afex_rdata),
  10548. &bnx2x_func_sp_drv);
  10549. }
  10550. /* must be called after sriov-enable */
  10551. static int bnx2x_set_qm_cid_count(struct bnx2x *bp)
  10552. {
  10553. int cid_count = BNX2X_L2_MAX_CID(bp);
  10554. if (IS_SRIOV(bp))
  10555. cid_count += BNX2X_VF_CIDS;
  10556. if (CNIC_SUPPORT(bp))
  10557. cid_count += CNIC_CID_MAX;
  10558. return roundup(cid_count, QM_CID_ROUND);
  10559. }
  10560. /**
  10561. * bnx2x_get_num_none_def_sbs - return the number of none default SBs
  10562. *
  10563. * @dev: pci device
  10564. *
  10565. */
  10566. static int bnx2x_get_num_non_def_sbs(struct pci_dev *pdev,
  10567. int cnic_cnt, bool is_vf)
  10568. {
  10569. int pos, index;
  10570. u16 control = 0;
  10571. pos = pci_find_capability(pdev, PCI_CAP_ID_MSIX);
  10572. /*
  10573. * If MSI-X is not supported - return number of SBs needed to support
  10574. * one fast path queue: one FP queue + SB for CNIC
  10575. */
  10576. if (!pos) {
  10577. dev_info(&pdev->dev, "no msix capability found\n");
  10578. return 1 + cnic_cnt;
  10579. }
  10580. dev_info(&pdev->dev, "msix capability found\n");
  10581. /*
  10582. * The value in the PCI configuration space is the index of the last
  10583. * entry, namely one less than the actual size of the table, which is
  10584. * exactly what we want to return from this function: number of all SBs
  10585. * without the default SB.
  10586. * For VFs there is no default SB, then we return (index+1).
  10587. */
  10588. pci_read_config_word(pdev, pos + PCI_MSI_FLAGS, &control);
  10589. index = control & PCI_MSIX_FLAGS_QSIZE;
  10590. return is_vf ? index + 1 : index;
  10591. }
  10592. static int set_max_cos_est(int chip_id)
  10593. {
  10594. switch (chip_id) {
  10595. case BCM57710:
  10596. case BCM57711:
  10597. case BCM57711E:
  10598. return BNX2X_MULTI_TX_COS_E1X;
  10599. case BCM57712:
  10600. case BCM57712_MF:
  10601. case BCM57712_VF:
  10602. return BNX2X_MULTI_TX_COS_E2_E3A0;
  10603. case BCM57800:
  10604. case BCM57800_MF:
  10605. case BCM57800_VF:
  10606. case BCM57810:
  10607. case BCM57810_MF:
  10608. case BCM57840_4_10:
  10609. case BCM57840_2_20:
  10610. case BCM57840_O:
  10611. case BCM57840_MFO:
  10612. case BCM57810_VF:
  10613. case BCM57840_MF:
  10614. case BCM57840_VF:
  10615. case BCM57811:
  10616. case BCM57811_MF:
  10617. case BCM57811_VF:
  10618. return BNX2X_MULTI_TX_COS_E3B0;
  10619. return 1;
  10620. default:
  10621. pr_err("Unknown board_type (%d), aborting\n", chip_id);
  10622. return -ENODEV;
  10623. }
  10624. }
  10625. static int set_is_vf(int chip_id)
  10626. {
  10627. switch (chip_id) {
  10628. case BCM57712_VF:
  10629. case BCM57800_VF:
  10630. case BCM57810_VF:
  10631. case BCM57840_VF:
  10632. case BCM57811_VF:
  10633. return true;
  10634. default:
  10635. return false;
  10636. }
  10637. }
  10638. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev);
  10639. static int bnx2x_init_one(struct pci_dev *pdev,
  10640. const struct pci_device_id *ent)
  10641. {
  10642. struct net_device *dev = NULL;
  10643. struct bnx2x *bp;
  10644. int pcie_width;
  10645. enum bnx2x_pci_bus_speed pcie_speed;
  10646. int rc, max_non_def_sbs;
  10647. int rx_count, tx_count, rss_count, doorbell_size;
  10648. int max_cos_est;
  10649. bool is_vf;
  10650. int cnic_cnt;
  10651. /* An estimated maximum supported CoS number according to the chip
  10652. * version.
  10653. * We will try to roughly estimate the maximum number of CoSes this chip
  10654. * may support in order to minimize the memory allocated for Tx
  10655. * netdev_queue's. This number will be accurately calculated during the
  10656. * initialization of bp->max_cos based on the chip versions AND chip
  10657. * revision in the bnx2x_init_bp().
  10658. */
  10659. max_cos_est = set_max_cos_est(ent->driver_data);
  10660. if (max_cos_est < 0)
  10661. return max_cos_est;
  10662. is_vf = set_is_vf(ent->driver_data);
  10663. cnic_cnt = is_vf ? 0 : 1;
  10664. max_non_def_sbs = bnx2x_get_num_non_def_sbs(pdev, cnic_cnt, is_vf);
  10665. /* Maximum number of RSS queues: one IGU SB goes to CNIC */
  10666. rss_count = is_vf ? 1 : max_non_def_sbs - cnic_cnt;
  10667. if (rss_count < 1)
  10668. return -EINVAL;
  10669. /* Maximum number of netdev Rx queues: RSS + FCoE L2 */
  10670. rx_count = rss_count + cnic_cnt;
  10671. /* Maximum number of netdev Tx queues:
  10672. * Maximum TSS queues * Maximum supported number of CoS + FCoE L2
  10673. */
  10674. tx_count = rss_count * max_cos_est + cnic_cnt;
  10675. /* dev zeroed in init_etherdev */
  10676. dev = alloc_etherdev_mqs(sizeof(*bp), tx_count, rx_count);
  10677. if (!dev)
  10678. return -ENOMEM;
  10679. bp = netdev_priv(dev);
  10680. bp->flags = 0;
  10681. if (is_vf)
  10682. bp->flags |= IS_VF_FLAG;
  10683. bp->igu_sb_cnt = max_non_def_sbs;
  10684. bp->igu_base_addr = IS_VF(bp) ? PXP_VF_ADDR_IGU_START : BAR_IGU_INTMEM;
  10685. bp->msg_enable = debug;
  10686. bp->cnic_support = cnic_cnt;
  10687. bp->cnic_probe = bnx2x_cnic_probe;
  10688. pci_set_drvdata(pdev, dev);
  10689. rc = bnx2x_init_dev(bp, pdev, dev, ent->driver_data);
  10690. if (rc < 0) {
  10691. free_netdev(dev);
  10692. return rc;
  10693. }
  10694. BNX2X_DEV_INFO("This is a %s function\n",
  10695. IS_PF(bp) ? "physical" : "virtual");
  10696. BNX2X_DEV_INFO("Cnic support is %s\n", CNIC_SUPPORT(bp) ? "on" : "off");
  10697. BNX2X_DEV_INFO("Max num of status blocks %d\n", max_non_def_sbs);
  10698. BNX2X_DEV_INFO("Allocated netdev with %d tx and %d rx queues\n",
  10699. tx_count, rx_count);
  10700. rc = bnx2x_init_bp(bp);
  10701. if (rc)
  10702. goto init_one_exit;
  10703. /* Map doorbells here as we need the real value of bp->max_cos which
  10704. * is initialized in bnx2x_init_bp() to determine the number of
  10705. * l2 connections.
  10706. */
  10707. if (IS_VF(bp)) {
  10708. bp->doorbells = bnx2x_vf_doorbells(bp);
  10709. rc = bnx2x_vf_pci_alloc(bp);
  10710. if (rc)
  10711. goto init_one_exit;
  10712. } else {
  10713. doorbell_size = BNX2X_L2_MAX_CID(bp) * (1 << BNX2X_DB_SHIFT);
  10714. if (doorbell_size > pci_resource_len(pdev, 2)) {
  10715. dev_err(&bp->pdev->dev,
  10716. "Cannot map doorbells, bar size too small, aborting\n");
  10717. rc = -ENOMEM;
  10718. goto init_one_exit;
  10719. }
  10720. bp->doorbells = ioremap_nocache(pci_resource_start(pdev, 2),
  10721. doorbell_size);
  10722. }
  10723. if (!bp->doorbells) {
  10724. dev_err(&bp->pdev->dev,
  10725. "Cannot map doorbell space, aborting\n");
  10726. rc = -ENOMEM;
  10727. goto init_one_exit;
  10728. }
  10729. if (IS_VF(bp)) {
  10730. rc = bnx2x_vfpf_acquire(bp, tx_count, rx_count);
  10731. if (rc)
  10732. goto init_one_exit;
  10733. }
  10734. /* Enable SRIOV if capability found in configuration space */
  10735. rc = bnx2x_iov_init_one(bp, int_mode, BNX2X_MAX_NUM_OF_VFS);
  10736. if (rc)
  10737. goto init_one_exit;
  10738. /* calc qm_cid_count */
  10739. bp->qm_cid_count = bnx2x_set_qm_cid_count(bp);
  10740. BNX2X_DEV_INFO("qm_cid_count %d\n", bp->qm_cid_count);
  10741. /* disable FCOE L2 queue for E1x*/
  10742. if (CHIP_IS_E1x(bp))
  10743. bp->flags |= NO_FCOE_FLAG;
  10744. /* Set bp->num_queues for MSI-X mode*/
  10745. bnx2x_set_num_queues(bp);
  10746. /* Configure interrupt mode: try to enable MSI-X/MSI if
  10747. * needed.
  10748. */
  10749. rc = bnx2x_set_int_mode(bp);
  10750. if (rc) {
  10751. dev_err(&pdev->dev, "Cannot set interrupts\n");
  10752. goto init_one_exit;
  10753. }
  10754. BNX2X_DEV_INFO("set interrupts successfully\n");
  10755. /* register the net device */
  10756. rc = register_netdev(dev);
  10757. if (rc) {
  10758. dev_err(&pdev->dev, "Cannot register net device\n");
  10759. goto init_one_exit;
  10760. }
  10761. BNX2X_DEV_INFO("device name after netdev register %s\n", dev->name);
  10762. if (!NO_FCOE(bp)) {
  10763. /* Add storage MAC address */
  10764. rtnl_lock();
  10765. dev_addr_add(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10766. rtnl_unlock();
  10767. }
  10768. bnx2x_get_pcie_width_speed(bp, &pcie_width, &pcie_speed);
  10769. BNX2X_DEV_INFO("got pcie width %d and speed %d\n",
  10770. pcie_width, pcie_speed);
  10771. BNX2X_DEV_INFO("%s (%c%d) PCI-E x%d %s found at mem %lx, IRQ %d, node addr %pM\n",
  10772. board_info[ent->driver_data].name,
  10773. (CHIP_REV(bp) >> 12) + 'A', (CHIP_METAL(bp) >> 4),
  10774. pcie_width,
  10775. pcie_speed == BNX2X_PCI_LINK_SPEED_2500 ? "2.5GHz" :
  10776. pcie_speed == BNX2X_PCI_LINK_SPEED_5000 ? "5.0GHz" :
  10777. pcie_speed == BNX2X_PCI_LINK_SPEED_8000 ? "8.0GHz" :
  10778. "Unknown",
  10779. dev->base_addr, bp->pdev->irq, dev->dev_addr);
  10780. return 0;
  10781. init_one_exit:
  10782. if (bp->regview)
  10783. iounmap(bp->regview);
  10784. if (IS_PF(bp) && bp->doorbells)
  10785. iounmap(bp->doorbells);
  10786. free_netdev(dev);
  10787. if (atomic_read(&pdev->enable_cnt) == 1)
  10788. pci_release_regions(pdev);
  10789. pci_disable_device(pdev);
  10790. pci_set_drvdata(pdev, NULL);
  10791. return rc;
  10792. }
  10793. static void __bnx2x_remove(struct pci_dev *pdev,
  10794. struct net_device *dev,
  10795. struct bnx2x *bp,
  10796. bool remove_netdev)
  10797. {
  10798. /* Delete storage MAC address */
  10799. if (!NO_FCOE(bp)) {
  10800. rtnl_lock();
  10801. dev_addr_del(bp->dev, bp->fip_mac, NETDEV_HW_ADDR_T_SAN);
  10802. rtnl_unlock();
  10803. }
  10804. #ifdef BCM_DCBNL
  10805. /* Delete app tlvs from dcbnl */
  10806. bnx2x_dcbnl_update_applist(bp, true);
  10807. #endif
  10808. /* Close the interface - either directly or implicitly */
  10809. if (remove_netdev) {
  10810. unregister_netdev(dev);
  10811. } else {
  10812. rtnl_lock();
  10813. if (netif_running(dev))
  10814. bnx2x_close(dev);
  10815. rtnl_unlock();
  10816. }
  10817. bnx2x_iov_remove_one(bp);
  10818. /* Power on: we can't let PCI layer write to us while we are in D3 */
  10819. if (IS_PF(bp))
  10820. bnx2x_set_power_state(bp, PCI_D0);
  10821. /* Disable MSI/MSI-X */
  10822. bnx2x_disable_msi(bp);
  10823. /* Power off */
  10824. if (IS_PF(bp))
  10825. bnx2x_set_power_state(bp, PCI_D3hot);
  10826. /* Make sure RESET task is not scheduled before continuing */
  10827. cancel_delayed_work_sync(&bp->sp_rtnl_task);
  10828. /* send message via vfpf channel to release the resources of this vf */
  10829. if (IS_VF(bp))
  10830. bnx2x_vfpf_release(bp);
  10831. /* Assumes no further PCIe PM changes will occur */
  10832. if (system_state == SYSTEM_POWER_OFF) {
  10833. pci_wake_from_d3(pdev, bp->wol);
  10834. pci_set_power_state(pdev, PCI_D3hot);
  10835. }
  10836. if (bp->regview)
  10837. iounmap(bp->regview);
  10838. /* for vf doorbells are part of the regview and were unmapped along with
  10839. * it. FW is only loaded by PF.
  10840. */
  10841. if (IS_PF(bp)) {
  10842. if (bp->doorbells)
  10843. iounmap(bp->doorbells);
  10844. bnx2x_release_firmware(bp);
  10845. }
  10846. bnx2x_free_mem_bp(bp);
  10847. if (remove_netdev)
  10848. free_netdev(dev);
  10849. if (atomic_read(&pdev->enable_cnt) == 1)
  10850. pci_release_regions(pdev);
  10851. pci_disable_device(pdev);
  10852. pci_set_drvdata(pdev, NULL);
  10853. }
  10854. static void bnx2x_remove_one(struct pci_dev *pdev)
  10855. {
  10856. struct net_device *dev = pci_get_drvdata(pdev);
  10857. struct bnx2x *bp;
  10858. if (!dev) {
  10859. dev_err(&pdev->dev, "BAD net device from bnx2x_init_one\n");
  10860. return;
  10861. }
  10862. bp = netdev_priv(dev);
  10863. __bnx2x_remove(pdev, dev, bp, true);
  10864. }
  10865. static int bnx2x_eeh_nic_unload(struct bnx2x *bp)
  10866. {
  10867. bp->state = BNX2X_STATE_CLOSING_WAIT4_HALT;
  10868. bp->rx_mode = BNX2X_RX_MODE_NONE;
  10869. if (CNIC_LOADED(bp))
  10870. bnx2x_cnic_notify(bp, CNIC_CTL_STOP_CMD);
  10871. /* Stop Tx */
  10872. bnx2x_tx_disable(bp);
  10873. /* Delete all NAPI objects */
  10874. bnx2x_del_all_napi(bp);
  10875. if (CNIC_LOADED(bp))
  10876. bnx2x_del_all_napi_cnic(bp);
  10877. netdev_reset_tc(bp->dev);
  10878. del_timer_sync(&bp->timer);
  10879. cancel_delayed_work(&bp->sp_task);
  10880. cancel_delayed_work(&bp->period_task);
  10881. spin_lock_bh(&bp->stats_lock);
  10882. bp->stats_state = STATS_STATE_DISABLED;
  10883. spin_unlock_bh(&bp->stats_lock);
  10884. bnx2x_save_statistics(bp);
  10885. netif_carrier_off(bp->dev);
  10886. return 0;
  10887. }
  10888. /**
  10889. * bnx2x_io_error_detected - called when PCI error is detected
  10890. * @pdev: Pointer to PCI device
  10891. * @state: The current pci connection state
  10892. *
  10893. * This function is called after a PCI bus error affecting
  10894. * this device has been detected.
  10895. */
  10896. static pci_ers_result_t bnx2x_io_error_detected(struct pci_dev *pdev,
  10897. pci_channel_state_t state)
  10898. {
  10899. struct net_device *dev = pci_get_drvdata(pdev);
  10900. struct bnx2x *bp = netdev_priv(dev);
  10901. rtnl_lock();
  10902. BNX2X_ERR("IO error detected\n");
  10903. netif_device_detach(dev);
  10904. if (state == pci_channel_io_perm_failure) {
  10905. rtnl_unlock();
  10906. return PCI_ERS_RESULT_DISCONNECT;
  10907. }
  10908. if (netif_running(dev))
  10909. bnx2x_eeh_nic_unload(bp);
  10910. bnx2x_prev_path_mark_eeh(bp);
  10911. pci_disable_device(pdev);
  10912. rtnl_unlock();
  10913. /* Request a slot reset */
  10914. return PCI_ERS_RESULT_NEED_RESET;
  10915. }
  10916. /**
  10917. * bnx2x_io_slot_reset - called after the PCI bus has been reset
  10918. * @pdev: Pointer to PCI device
  10919. *
  10920. * Restart the card from scratch, as if from a cold-boot.
  10921. */
  10922. static pci_ers_result_t bnx2x_io_slot_reset(struct pci_dev *pdev)
  10923. {
  10924. struct net_device *dev = pci_get_drvdata(pdev);
  10925. struct bnx2x *bp = netdev_priv(dev);
  10926. int i;
  10927. rtnl_lock();
  10928. BNX2X_ERR("IO slot reset initializing...\n");
  10929. if (pci_enable_device(pdev)) {
  10930. dev_err(&pdev->dev,
  10931. "Cannot re-enable PCI device after reset\n");
  10932. rtnl_unlock();
  10933. return PCI_ERS_RESULT_DISCONNECT;
  10934. }
  10935. pci_set_master(pdev);
  10936. pci_restore_state(pdev);
  10937. pci_save_state(pdev);
  10938. if (netif_running(dev))
  10939. bnx2x_set_power_state(bp, PCI_D0);
  10940. if (netif_running(dev)) {
  10941. BNX2X_ERR("IO slot reset --> driver unload\n");
  10942. /* MCP should have been reset; Need to wait for validity */
  10943. bnx2x_init_shmem(bp);
  10944. if (IS_PF(bp) && SHMEM2_HAS(bp, drv_capabilities_flag)) {
  10945. u32 v;
  10946. v = SHMEM2_RD(bp,
  10947. drv_capabilities_flag[BP_FW_MB_IDX(bp)]);
  10948. SHMEM2_WR(bp, drv_capabilities_flag[BP_FW_MB_IDX(bp)],
  10949. v & ~DRV_FLAGS_CAPABILITIES_LOADED_L2);
  10950. }
  10951. bnx2x_drain_tx_queues(bp);
  10952. bnx2x_send_unload_req(bp, UNLOAD_RECOVERY);
  10953. bnx2x_netif_stop(bp, 1);
  10954. bnx2x_free_irq(bp);
  10955. /* Report UNLOAD_DONE to MCP */
  10956. bnx2x_send_unload_done(bp, true);
  10957. bp->sp_state = 0;
  10958. bp->port.pmf = 0;
  10959. bnx2x_prev_unload(bp);
  10960. /* We should have reseted the engine, so It's fair to
  10961. * assume the FW will no longer write to the bnx2x driver.
  10962. */
  10963. bnx2x_squeeze_objects(bp);
  10964. bnx2x_free_skbs(bp);
  10965. for_each_rx_queue(bp, i)
  10966. bnx2x_free_rx_sge_range(bp, bp->fp + i, NUM_RX_SGE);
  10967. bnx2x_free_fp_mem(bp);
  10968. bnx2x_free_mem(bp);
  10969. bp->state = BNX2X_STATE_CLOSED;
  10970. }
  10971. rtnl_unlock();
  10972. return PCI_ERS_RESULT_RECOVERED;
  10973. }
  10974. /**
  10975. * bnx2x_io_resume - called when traffic can start flowing again
  10976. * @pdev: Pointer to PCI device
  10977. *
  10978. * This callback is called when the error recovery driver tells us that
  10979. * its OK to resume normal operation.
  10980. */
  10981. static void bnx2x_io_resume(struct pci_dev *pdev)
  10982. {
  10983. struct net_device *dev = pci_get_drvdata(pdev);
  10984. struct bnx2x *bp = netdev_priv(dev);
  10985. if (bp->recovery_state != BNX2X_RECOVERY_DONE) {
  10986. netdev_err(bp->dev, "Handling parity error recovery. Try again later\n");
  10987. return;
  10988. }
  10989. rtnl_lock();
  10990. bp->fw_seq = SHMEM_RD(bp, func_mb[BP_FW_MB_IDX(bp)].drv_mb_header) &
  10991. DRV_MSG_SEQ_NUMBER_MASK;
  10992. if (netif_running(dev))
  10993. bnx2x_nic_load(bp, LOAD_NORMAL);
  10994. netif_device_attach(dev);
  10995. rtnl_unlock();
  10996. }
  10997. static const struct pci_error_handlers bnx2x_err_handler = {
  10998. .error_detected = bnx2x_io_error_detected,
  10999. .slot_reset = bnx2x_io_slot_reset,
  11000. .resume = bnx2x_io_resume,
  11001. };
  11002. static void bnx2x_shutdown(struct pci_dev *pdev)
  11003. {
  11004. struct net_device *dev = pci_get_drvdata(pdev);
  11005. struct bnx2x *bp;
  11006. if (!dev)
  11007. return;
  11008. bp = netdev_priv(dev);
  11009. if (!bp)
  11010. return;
  11011. rtnl_lock();
  11012. netif_device_detach(dev);
  11013. rtnl_unlock();
  11014. /* Don't remove the netdevice, as there are scenarios which will cause
  11015. * the kernel to hang, e.g., when trying to remove bnx2i while the
  11016. * rootfs is mounted from SAN.
  11017. */
  11018. __bnx2x_remove(pdev, dev, bp, false);
  11019. }
  11020. static struct pci_driver bnx2x_pci_driver = {
  11021. .name = DRV_MODULE_NAME,
  11022. .id_table = bnx2x_pci_tbl,
  11023. .probe = bnx2x_init_one,
  11024. .remove = bnx2x_remove_one,
  11025. .suspend = bnx2x_suspend,
  11026. .resume = bnx2x_resume,
  11027. .err_handler = &bnx2x_err_handler,
  11028. #ifdef CONFIG_BNX2X_SRIOV
  11029. .sriov_configure = bnx2x_sriov_configure,
  11030. #endif
  11031. .shutdown = bnx2x_shutdown,
  11032. };
  11033. static int __init bnx2x_init(void)
  11034. {
  11035. int ret;
  11036. pr_info("%s", version);
  11037. bnx2x_wq = create_singlethread_workqueue("bnx2x");
  11038. if (bnx2x_wq == NULL) {
  11039. pr_err("Cannot create workqueue\n");
  11040. return -ENOMEM;
  11041. }
  11042. ret = pci_register_driver(&bnx2x_pci_driver);
  11043. if (ret) {
  11044. pr_err("Cannot register driver\n");
  11045. destroy_workqueue(bnx2x_wq);
  11046. }
  11047. return ret;
  11048. }
  11049. static void __exit bnx2x_cleanup(void)
  11050. {
  11051. struct list_head *pos, *q;
  11052. pci_unregister_driver(&bnx2x_pci_driver);
  11053. destroy_workqueue(bnx2x_wq);
  11054. /* Free globally allocated resources */
  11055. list_for_each_safe(pos, q, &bnx2x_prev_list) {
  11056. struct bnx2x_prev_path_list *tmp =
  11057. list_entry(pos, struct bnx2x_prev_path_list, list);
  11058. list_del(pos);
  11059. kfree(tmp);
  11060. }
  11061. }
  11062. void bnx2x_notify_link_changed(struct bnx2x *bp)
  11063. {
  11064. REG_WR(bp, MISC_REG_AEU_GENERAL_ATTN_12 + BP_FUNC(bp)*sizeof(u32), 1);
  11065. }
  11066. module_init(bnx2x_init);
  11067. module_exit(bnx2x_cleanup);
  11068. /**
  11069. * bnx2x_set_iscsi_eth_mac_addr - set iSCSI MAC(s).
  11070. *
  11071. * @bp: driver handle
  11072. * @set: set or clear the CAM entry
  11073. *
  11074. * This function will wait until the ramrod completion returns.
  11075. * Return 0 if success, -ENODEV if ramrod doesn't return.
  11076. */
  11077. static int bnx2x_set_iscsi_eth_mac_addr(struct bnx2x *bp)
  11078. {
  11079. unsigned long ramrod_flags = 0;
  11080. __set_bit(RAMROD_COMP_WAIT, &ramrod_flags);
  11081. return bnx2x_set_mac_one(bp, bp->cnic_eth_dev.iscsi_mac,
  11082. &bp->iscsi_l2_mac_obj, true,
  11083. BNX2X_ISCSI_ETH_MAC, &ramrod_flags);
  11084. }
  11085. /* count denotes the number of new completions we have seen */
  11086. static void bnx2x_cnic_sp_post(struct bnx2x *bp, int count)
  11087. {
  11088. struct eth_spe *spe;
  11089. int cxt_index, cxt_offset;
  11090. #ifdef BNX2X_STOP_ON_ERROR
  11091. if (unlikely(bp->panic))
  11092. return;
  11093. #endif
  11094. spin_lock_bh(&bp->spq_lock);
  11095. BUG_ON(bp->cnic_spq_pending < count);
  11096. bp->cnic_spq_pending -= count;
  11097. for (; bp->cnic_kwq_pending; bp->cnic_kwq_pending--) {
  11098. u16 type = (le16_to_cpu(bp->cnic_kwq_cons->hdr.type)
  11099. & SPE_HDR_CONN_TYPE) >>
  11100. SPE_HDR_CONN_TYPE_SHIFT;
  11101. u8 cmd = (le32_to_cpu(bp->cnic_kwq_cons->hdr.conn_and_cmd_data)
  11102. >> SPE_HDR_CMD_ID_SHIFT) & 0xff;
  11103. /* Set validation for iSCSI L2 client before sending SETUP
  11104. * ramrod
  11105. */
  11106. if (type == ETH_CONNECTION_TYPE) {
  11107. if (cmd == RAMROD_CMD_ID_ETH_CLIENT_SETUP) {
  11108. cxt_index = BNX2X_ISCSI_ETH_CID(bp) /
  11109. ILT_PAGE_CIDS;
  11110. cxt_offset = BNX2X_ISCSI_ETH_CID(bp) -
  11111. (cxt_index * ILT_PAGE_CIDS);
  11112. bnx2x_set_ctx_validation(bp,
  11113. &bp->context[cxt_index].
  11114. vcxt[cxt_offset].eth,
  11115. BNX2X_ISCSI_ETH_CID(bp));
  11116. }
  11117. }
  11118. /*
  11119. * There may be not more than 8 L2, not more than 8 L5 SPEs
  11120. * and in the air. We also check that number of outstanding
  11121. * COMMON ramrods is not more than the EQ and SPQ can
  11122. * accommodate.
  11123. */
  11124. if (type == ETH_CONNECTION_TYPE) {
  11125. if (!atomic_read(&bp->cq_spq_left))
  11126. break;
  11127. else
  11128. atomic_dec(&bp->cq_spq_left);
  11129. } else if (type == NONE_CONNECTION_TYPE) {
  11130. if (!atomic_read(&bp->eq_spq_left))
  11131. break;
  11132. else
  11133. atomic_dec(&bp->eq_spq_left);
  11134. } else if ((type == ISCSI_CONNECTION_TYPE) ||
  11135. (type == FCOE_CONNECTION_TYPE)) {
  11136. if (bp->cnic_spq_pending >=
  11137. bp->cnic_eth_dev.max_kwqe_pending)
  11138. break;
  11139. else
  11140. bp->cnic_spq_pending++;
  11141. } else {
  11142. BNX2X_ERR("Unknown SPE type: %d\n", type);
  11143. bnx2x_panic();
  11144. break;
  11145. }
  11146. spe = bnx2x_sp_get_next(bp);
  11147. *spe = *bp->cnic_kwq_cons;
  11148. DP(BNX2X_MSG_SP, "pending on SPQ %d, on KWQ %d count %d\n",
  11149. bp->cnic_spq_pending, bp->cnic_kwq_pending, count);
  11150. if (bp->cnic_kwq_cons == bp->cnic_kwq_last)
  11151. bp->cnic_kwq_cons = bp->cnic_kwq;
  11152. else
  11153. bp->cnic_kwq_cons++;
  11154. }
  11155. bnx2x_sp_prod_update(bp);
  11156. spin_unlock_bh(&bp->spq_lock);
  11157. }
  11158. static int bnx2x_cnic_sp_queue(struct net_device *dev,
  11159. struct kwqe_16 *kwqes[], u32 count)
  11160. {
  11161. struct bnx2x *bp = netdev_priv(dev);
  11162. int i;
  11163. #ifdef BNX2X_STOP_ON_ERROR
  11164. if (unlikely(bp->panic)) {
  11165. BNX2X_ERR("Can't post to SP queue while panic\n");
  11166. return -EIO;
  11167. }
  11168. #endif
  11169. if ((bp->recovery_state != BNX2X_RECOVERY_DONE) &&
  11170. (bp->recovery_state != BNX2X_RECOVERY_NIC_LOADING)) {
  11171. BNX2X_ERR("Handling parity error recovery. Try again later\n");
  11172. return -EAGAIN;
  11173. }
  11174. spin_lock_bh(&bp->spq_lock);
  11175. for (i = 0; i < count; i++) {
  11176. struct eth_spe *spe = (struct eth_spe *)kwqes[i];
  11177. if (bp->cnic_kwq_pending == MAX_SP_DESC_CNT)
  11178. break;
  11179. *bp->cnic_kwq_prod = *spe;
  11180. bp->cnic_kwq_pending++;
  11181. DP(BNX2X_MSG_SP, "L5 SPQE %x %x %x:%x pos %d\n",
  11182. spe->hdr.conn_and_cmd_data, spe->hdr.type,
  11183. spe->data.update_data_addr.hi,
  11184. spe->data.update_data_addr.lo,
  11185. bp->cnic_kwq_pending);
  11186. if (bp->cnic_kwq_prod == bp->cnic_kwq_last)
  11187. bp->cnic_kwq_prod = bp->cnic_kwq;
  11188. else
  11189. bp->cnic_kwq_prod++;
  11190. }
  11191. spin_unlock_bh(&bp->spq_lock);
  11192. if (bp->cnic_spq_pending < bp->cnic_eth_dev.max_kwqe_pending)
  11193. bnx2x_cnic_sp_post(bp, 0);
  11194. return i;
  11195. }
  11196. static int bnx2x_cnic_ctl_send(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11197. {
  11198. struct cnic_ops *c_ops;
  11199. int rc = 0;
  11200. mutex_lock(&bp->cnic_mutex);
  11201. c_ops = rcu_dereference_protected(bp->cnic_ops,
  11202. lockdep_is_held(&bp->cnic_mutex));
  11203. if (c_ops)
  11204. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11205. mutex_unlock(&bp->cnic_mutex);
  11206. return rc;
  11207. }
  11208. static int bnx2x_cnic_ctl_send_bh(struct bnx2x *bp, struct cnic_ctl_info *ctl)
  11209. {
  11210. struct cnic_ops *c_ops;
  11211. int rc = 0;
  11212. rcu_read_lock();
  11213. c_ops = rcu_dereference(bp->cnic_ops);
  11214. if (c_ops)
  11215. rc = c_ops->cnic_ctl(bp->cnic_data, ctl);
  11216. rcu_read_unlock();
  11217. return rc;
  11218. }
  11219. /*
  11220. * for commands that have no data
  11221. */
  11222. int bnx2x_cnic_notify(struct bnx2x *bp, int cmd)
  11223. {
  11224. struct cnic_ctl_info ctl = {0};
  11225. ctl.cmd = cmd;
  11226. return bnx2x_cnic_ctl_send(bp, &ctl);
  11227. }
  11228. static void bnx2x_cnic_cfc_comp(struct bnx2x *bp, int cid, u8 err)
  11229. {
  11230. struct cnic_ctl_info ctl = {0};
  11231. /* first we tell CNIC and only then we count this as a completion */
  11232. ctl.cmd = CNIC_CTL_COMPLETION_CMD;
  11233. ctl.data.comp.cid = cid;
  11234. ctl.data.comp.error = err;
  11235. bnx2x_cnic_ctl_send_bh(bp, &ctl);
  11236. bnx2x_cnic_sp_post(bp, 0);
  11237. }
  11238. /* Called with netif_addr_lock_bh() taken.
  11239. * Sets an rx_mode config for an iSCSI ETH client.
  11240. * Doesn't block.
  11241. * Completion should be checked outside.
  11242. */
  11243. static void bnx2x_set_iscsi_eth_rx_mode(struct bnx2x *bp, bool start)
  11244. {
  11245. unsigned long accept_flags = 0, ramrod_flags = 0;
  11246. u8 cl_id = bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11247. int sched_state = BNX2X_FILTER_ISCSI_ETH_STOP_SCHED;
  11248. if (start) {
  11249. /* Start accepting on iSCSI L2 ring. Accept all multicasts
  11250. * because it's the only way for UIO Queue to accept
  11251. * multicasts (in non-promiscuous mode only one Queue per
  11252. * function will receive multicast packets (leading in our
  11253. * case).
  11254. */
  11255. __set_bit(BNX2X_ACCEPT_UNICAST, &accept_flags);
  11256. __set_bit(BNX2X_ACCEPT_ALL_MULTICAST, &accept_flags);
  11257. __set_bit(BNX2X_ACCEPT_BROADCAST, &accept_flags);
  11258. __set_bit(BNX2X_ACCEPT_ANY_VLAN, &accept_flags);
  11259. /* Clear STOP_PENDING bit if START is requested */
  11260. clear_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &bp->sp_state);
  11261. sched_state = BNX2X_FILTER_ISCSI_ETH_START_SCHED;
  11262. } else
  11263. /* Clear START_PENDING bit if STOP is requested */
  11264. clear_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &bp->sp_state);
  11265. if (test_bit(BNX2X_FILTER_RX_MODE_PENDING, &bp->sp_state))
  11266. set_bit(sched_state, &bp->sp_state);
  11267. else {
  11268. __set_bit(RAMROD_RX, &ramrod_flags);
  11269. bnx2x_set_q_rx_mode(bp, cl_id, 0, accept_flags, 0,
  11270. ramrod_flags);
  11271. }
  11272. }
  11273. static int bnx2x_drv_ctl(struct net_device *dev, struct drv_ctl_info *ctl)
  11274. {
  11275. struct bnx2x *bp = netdev_priv(dev);
  11276. int rc = 0;
  11277. switch (ctl->cmd) {
  11278. case DRV_CTL_CTXTBL_WR_CMD: {
  11279. u32 index = ctl->data.io.offset;
  11280. dma_addr_t addr = ctl->data.io.dma_addr;
  11281. bnx2x_ilt_wr(bp, index, addr);
  11282. break;
  11283. }
  11284. case DRV_CTL_RET_L5_SPQ_CREDIT_CMD: {
  11285. int count = ctl->data.credit.credit_count;
  11286. bnx2x_cnic_sp_post(bp, count);
  11287. break;
  11288. }
  11289. /* rtnl_lock is held. */
  11290. case DRV_CTL_START_L2_CMD: {
  11291. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11292. unsigned long sp_bits = 0;
  11293. /* Configure the iSCSI classification object */
  11294. bnx2x_init_mac_obj(bp, &bp->iscsi_l2_mac_obj,
  11295. cp->iscsi_l2_client_id,
  11296. cp->iscsi_l2_cid, BP_FUNC(bp),
  11297. bnx2x_sp(bp, mac_rdata),
  11298. bnx2x_sp_mapping(bp, mac_rdata),
  11299. BNX2X_FILTER_MAC_PENDING,
  11300. &bp->sp_state, BNX2X_OBJ_TYPE_RX,
  11301. &bp->macs_pool);
  11302. /* Set iSCSI MAC address */
  11303. rc = bnx2x_set_iscsi_eth_mac_addr(bp);
  11304. if (rc)
  11305. break;
  11306. mmiowb();
  11307. barrier();
  11308. /* Start accepting on iSCSI L2 ring */
  11309. netif_addr_lock_bh(dev);
  11310. bnx2x_set_iscsi_eth_rx_mode(bp, true);
  11311. netif_addr_unlock_bh(dev);
  11312. /* bits to wait on */
  11313. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11314. __set_bit(BNX2X_FILTER_ISCSI_ETH_START_SCHED, &sp_bits);
  11315. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11316. BNX2X_ERR("rx_mode completion timed out!\n");
  11317. break;
  11318. }
  11319. /* rtnl_lock is held. */
  11320. case DRV_CTL_STOP_L2_CMD: {
  11321. unsigned long sp_bits = 0;
  11322. /* Stop accepting on iSCSI L2 ring */
  11323. netif_addr_lock_bh(dev);
  11324. bnx2x_set_iscsi_eth_rx_mode(bp, false);
  11325. netif_addr_unlock_bh(dev);
  11326. /* bits to wait on */
  11327. __set_bit(BNX2X_FILTER_RX_MODE_PENDING, &sp_bits);
  11328. __set_bit(BNX2X_FILTER_ISCSI_ETH_STOP_SCHED, &sp_bits);
  11329. if (!bnx2x_wait_sp_comp(bp, sp_bits))
  11330. BNX2X_ERR("rx_mode completion timed out!\n");
  11331. mmiowb();
  11332. barrier();
  11333. /* Unset iSCSI L2 MAC */
  11334. rc = bnx2x_del_all_macs(bp, &bp->iscsi_l2_mac_obj,
  11335. BNX2X_ISCSI_ETH_MAC, true);
  11336. break;
  11337. }
  11338. case DRV_CTL_RET_L2_SPQ_CREDIT_CMD: {
  11339. int count = ctl->data.credit.credit_count;
  11340. smp_mb__before_atomic_inc();
  11341. atomic_add(count, &bp->cq_spq_left);
  11342. smp_mb__after_atomic_inc();
  11343. break;
  11344. }
  11345. case DRV_CTL_ULP_REGISTER_CMD: {
  11346. int ulp_type = ctl->data.register_data.ulp_type;
  11347. if (CHIP_IS_E3(bp)) {
  11348. int idx = BP_FW_MB_IDX(bp);
  11349. u32 cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11350. int path = BP_PATH(bp);
  11351. int port = BP_PORT(bp);
  11352. int i;
  11353. u32 scratch_offset;
  11354. u32 *host_addr;
  11355. /* first write capability to shmem2 */
  11356. if (ulp_type == CNIC_ULP_ISCSI)
  11357. cap |= DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11358. else if (ulp_type == CNIC_ULP_FCOE)
  11359. cap |= DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11360. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11361. if ((ulp_type != CNIC_ULP_FCOE) ||
  11362. (!SHMEM2_HAS(bp, ncsi_oem_data_addr)) ||
  11363. (!(bp->flags & BC_SUPPORTS_FCOE_FEATURES)))
  11364. break;
  11365. /* if reached here - should write fcoe capabilities */
  11366. scratch_offset = SHMEM2_RD(bp, ncsi_oem_data_addr);
  11367. if (!scratch_offset)
  11368. break;
  11369. scratch_offset += offsetof(struct glob_ncsi_oem_data,
  11370. fcoe_features[path][port]);
  11371. host_addr = (u32 *) &(ctl->data.register_data.
  11372. fcoe_features);
  11373. for (i = 0; i < sizeof(struct fcoe_capabilities);
  11374. i += 4)
  11375. REG_WR(bp, scratch_offset + i,
  11376. *(host_addr + i/4));
  11377. }
  11378. break;
  11379. }
  11380. case DRV_CTL_ULP_UNREGISTER_CMD: {
  11381. int ulp_type = ctl->data.ulp_type;
  11382. if (CHIP_IS_E3(bp)) {
  11383. int idx = BP_FW_MB_IDX(bp);
  11384. u32 cap;
  11385. cap = SHMEM2_RD(bp, drv_capabilities_flag[idx]);
  11386. if (ulp_type == CNIC_ULP_ISCSI)
  11387. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_ISCSI;
  11388. else if (ulp_type == CNIC_ULP_FCOE)
  11389. cap &= ~DRV_FLAGS_CAPABILITIES_LOADED_FCOE;
  11390. SHMEM2_WR(bp, drv_capabilities_flag[idx], cap);
  11391. }
  11392. break;
  11393. }
  11394. default:
  11395. BNX2X_ERR("unknown command %x\n", ctl->cmd);
  11396. rc = -EINVAL;
  11397. }
  11398. return rc;
  11399. }
  11400. void bnx2x_setup_cnic_irq_info(struct bnx2x *bp)
  11401. {
  11402. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11403. if (bp->flags & USING_MSIX_FLAG) {
  11404. cp->drv_state |= CNIC_DRV_STATE_USING_MSIX;
  11405. cp->irq_arr[0].irq_flags |= CNIC_IRQ_FL_MSIX;
  11406. cp->irq_arr[0].vector = bp->msix_table[1].vector;
  11407. } else {
  11408. cp->drv_state &= ~CNIC_DRV_STATE_USING_MSIX;
  11409. cp->irq_arr[0].irq_flags &= ~CNIC_IRQ_FL_MSIX;
  11410. }
  11411. if (!CHIP_IS_E1x(bp))
  11412. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e2_sb;
  11413. else
  11414. cp->irq_arr[0].status_blk = (void *)bp->cnic_sb.e1x_sb;
  11415. cp->irq_arr[0].status_blk_num = bnx2x_cnic_fw_sb_id(bp);
  11416. cp->irq_arr[0].status_blk_num2 = bnx2x_cnic_igu_sb_id(bp);
  11417. cp->irq_arr[1].status_blk = bp->def_status_blk;
  11418. cp->irq_arr[1].status_blk_num = DEF_SB_ID;
  11419. cp->irq_arr[1].status_blk_num2 = DEF_SB_IGU_ID;
  11420. cp->num_irq = 2;
  11421. }
  11422. void bnx2x_setup_cnic_info(struct bnx2x *bp)
  11423. {
  11424. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11425. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11426. bnx2x_cid_ilt_lines(bp);
  11427. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11428. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11429. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11430. if (NO_ISCSI_OOO(bp))
  11431. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11432. }
  11433. static int bnx2x_register_cnic(struct net_device *dev, struct cnic_ops *ops,
  11434. void *data)
  11435. {
  11436. struct bnx2x *bp = netdev_priv(dev);
  11437. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11438. int rc;
  11439. DP(NETIF_MSG_IFUP, "Register_cnic called\n");
  11440. if (ops == NULL) {
  11441. BNX2X_ERR("NULL ops received\n");
  11442. return -EINVAL;
  11443. }
  11444. if (!CNIC_SUPPORT(bp)) {
  11445. BNX2X_ERR("Can't register CNIC when not supported\n");
  11446. return -EOPNOTSUPP;
  11447. }
  11448. if (!CNIC_LOADED(bp)) {
  11449. rc = bnx2x_load_cnic(bp);
  11450. if (rc) {
  11451. BNX2X_ERR("CNIC-related load failed\n");
  11452. return rc;
  11453. }
  11454. }
  11455. bp->cnic_enabled = true;
  11456. bp->cnic_kwq = kzalloc(PAGE_SIZE, GFP_KERNEL);
  11457. if (!bp->cnic_kwq)
  11458. return -ENOMEM;
  11459. bp->cnic_kwq_cons = bp->cnic_kwq;
  11460. bp->cnic_kwq_prod = bp->cnic_kwq;
  11461. bp->cnic_kwq_last = bp->cnic_kwq + MAX_SP_DESC_CNT;
  11462. bp->cnic_spq_pending = 0;
  11463. bp->cnic_kwq_pending = 0;
  11464. bp->cnic_data = data;
  11465. cp->num_irq = 0;
  11466. cp->drv_state |= CNIC_DRV_STATE_REGD;
  11467. cp->iro_arr = bp->iro_arr;
  11468. bnx2x_setup_cnic_irq_info(bp);
  11469. rcu_assign_pointer(bp->cnic_ops, ops);
  11470. return 0;
  11471. }
  11472. static int bnx2x_unregister_cnic(struct net_device *dev)
  11473. {
  11474. struct bnx2x *bp = netdev_priv(dev);
  11475. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11476. mutex_lock(&bp->cnic_mutex);
  11477. cp->drv_state = 0;
  11478. RCU_INIT_POINTER(bp->cnic_ops, NULL);
  11479. mutex_unlock(&bp->cnic_mutex);
  11480. synchronize_rcu();
  11481. bp->cnic_enabled = false;
  11482. kfree(bp->cnic_kwq);
  11483. bp->cnic_kwq = NULL;
  11484. return 0;
  11485. }
  11486. struct cnic_eth_dev *bnx2x_cnic_probe(struct net_device *dev)
  11487. {
  11488. struct bnx2x *bp = netdev_priv(dev);
  11489. struct cnic_eth_dev *cp = &bp->cnic_eth_dev;
  11490. /* If both iSCSI and FCoE are disabled - return NULL in
  11491. * order to indicate CNIC that it should not try to work
  11492. * with this device.
  11493. */
  11494. if (NO_ISCSI(bp) && NO_FCOE(bp))
  11495. return NULL;
  11496. cp->drv_owner = THIS_MODULE;
  11497. cp->chip_id = CHIP_ID(bp);
  11498. cp->pdev = bp->pdev;
  11499. cp->io_base = bp->regview;
  11500. cp->io_base2 = bp->doorbells;
  11501. cp->max_kwqe_pending = 8;
  11502. cp->ctx_blk_size = CDU_ILT_PAGE_SZ;
  11503. cp->ctx_tbl_offset = FUNC_ILT_BASE(BP_FUNC(bp)) +
  11504. bnx2x_cid_ilt_lines(bp);
  11505. cp->ctx_tbl_len = CNIC_ILT_LINES;
  11506. cp->starting_cid = bnx2x_cid_ilt_lines(bp) * ILT_PAGE_CIDS;
  11507. cp->drv_submit_kwqes_16 = bnx2x_cnic_sp_queue;
  11508. cp->drv_ctl = bnx2x_drv_ctl;
  11509. cp->drv_register_cnic = bnx2x_register_cnic;
  11510. cp->drv_unregister_cnic = bnx2x_unregister_cnic;
  11511. cp->fcoe_init_cid = BNX2X_FCOE_ETH_CID(bp);
  11512. cp->iscsi_l2_client_id =
  11513. bnx2x_cnic_eth_cl_id(bp, BNX2X_ISCSI_ETH_CL_ID_IDX);
  11514. cp->iscsi_l2_cid = BNX2X_ISCSI_ETH_CID(bp);
  11515. if (NO_ISCSI_OOO(bp))
  11516. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI_OOO;
  11517. if (NO_ISCSI(bp))
  11518. cp->drv_state |= CNIC_DRV_STATE_NO_ISCSI;
  11519. if (NO_FCOE(bp))
  11520. cp->drv_state |= CNIC_DRV_STATE_NO_FCOE;
  11521. BNX2X_DEV_INFO(
  11522. "page_size %d, tbl_offset %d, tbl_lines %d, starting cid %d\n",
  11523. cp->ctx_blk_size,
  11524. cp->ctx_tbl_offset,
  11525. cp->ctx_tbl_len,
  11526. cp->starting_cid);
  11527. return cp;
  11528. }
  11529. u32 bnx2x_rx_ustorm_prods_offset(struct bnx2x_fastpath *fp)
  11530. {
  11531. struct bnx2x *bp = fp->bp;
  11532. u32 offset = BAR_USTRORM_INTMEM;
  11533. if (IS_VF(bp))
  11534. return bnx2x_vf_ustorm_prods_offset(bp, fp);
  11535. else if (!CHIP_IS_E1x(bp))
  11536. offset += USTORM_RX_PRODS_E2_OFFSET(fp->cl_qzone_id);
  11537. else
  11538. offset += USTORM_RX_PRODS_E1X_OFFSET(BP_PORT(bp), fp->cl_id);
  11539. return offset;
  11540. }
  11541. /* called only on E1H or E2.
  11542. * When pretending to be PF, the pretend value is the function number 0...7
  11543. * When pretending to be VF, the pretend val is the PF-num:VF-valid:ABS-VFID
  11544. * combination
  11545. */
  11546. int bnx2x_pretend_func(struct bnx2x *bp, u16 pretend_func_val)
  11547. {
  11548. u32 pretend_reg;
  11549. if (CHIP_IS_E1H(bp) && pretend_func_val >= E1H_FUNC_MAX)
  11550. return -1;
  11551. /* get my own pretend register */
  11552. pretend_reg = bnx2x_get_pretend_reg(bp);
  11553. REG_WR(bp, pretend_reg, pretend_func_val);
  11554. REG_RD(bp, pretend_reg);
  11555. return 0;
  11556. }